Implemented wxBitmapDataObject.

Implemented generic wxDataObject support in wxClipboard.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20534 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mattia Barbon
2003-05-07 17:24:11 +00:00
parent 27c7397611
commit dd38c87578
13 changed files with 376 additions and 424 deletions
+1
View File
@@ -1250,6 +1250,7 @@ control.h MotifH
cursor.h MotifH
dataform.h MotifH
dataobj.h MotifH
dataobj2.h MotifH
dc.h MotifH
dcclient.h MotifH
dcmemory.h MotifH
+3
View File
@@ -137,6 +137,9 @@ wxMotif:
- implemented wxToggleButton
- wxRadioBox and wxStaticBox now use the default shadow (border) style
instead of a sunken border
- implemented wxBitmapDataObject
- finished wxClipboard implementation (it still unconditionally
copies the data)
wxUniv:
-2
View File
@@ -9,8 +9,6 @@ See also: todo.txt.
- No wxToolTip (but see wxToolBar for a way of implementing it).
- Limited clipboard support (text only) and no drag and drop.
- Need a way of specifying default settings for colour/font/etc.
- More optimisation could be done to reduce X server traffic, etc.
+2
View File
@@ -462,6 +462,8 @@ private:
#include "wx/gtk/dataobj2.h"
#elif defined(__WXX11__)
#include "wx/x11/dataobj2.h"
#elif defined(__WXMOTIF__)
#include "wx/motif/dataobj2.h"
#elif defined(__WXMAC__)
#include "wx/mac/dataobj2.h"
#elif defined(__WXPM__)
+1 -1
View File
@@ -68,7 +68,7 @@ public:
// clears wxTheClipboard and the system's clipboard if possible
virtual void Clear();
virtual void UsePrimarySelection(bool primary = TRUE)
virtual void UsePrimarySelection(bool primary = true)
{ m_usePrimary = primary; }
// implementation from now on
+39
View File
@@ -0,0 +1,39 @@
///////////////////////////////////////////////////////////////////////////////
// Name: include/wx/motif/dataobj2.h
// Purpose: declaration of standard wxDataObjectSimple-derived classes
// Author: Mattia Barbon
// Created: 27.04.03
// RCS-ID: $Id$
// Copyright: (c) 2003 Mattia Barbon
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MOTIF_DATAOBJ2_H_
#define _WX_MOTIF_DATAOBJ2_H_
#if defined(__GNUG__) && !defined(__APPLE__)
#pragma interface "dataobj.h"
#endif
// ----------------------------------------------------------------------------
// wxBitmapDataObject is a specialization of wxDataObject for bitmaps
// ----------------------------------------------------------------------------
class wxBitmapDataObject : public wxBitmapDataObjectBase
{
public:
// ctors
wxBitmapDataObject()
: wxBitmapDataObjectBase() { }
wxBitmapDataObject(const wxBitmap& bitmap)
: wxBitmapDataObjectBase(bitmap) { }
// implement base class pure virtuals
// ----------------------------------
virtual size_t GetDataSize() const;
virtual bool GetDataHere(void *buf) const;
virtual bool SetData(size_t len, const void *buf);
};
#endif // _WX_MOTIF_DATAOBJ2_H_
+2
View File
@@ -96,6 +96,8 @@ public:
bool Create(int width, int height, int depth = -1);
bool Create(void* data, wxBitmapType type,
int width, int height, int depth = -1);
// create the wxBitmap using a _copy_ of the pixmap
bool Create(WXPixmap pixmap);
int GetHeight() const;
int GetWidth() const;
+11 -4
View File
@@ -125,7 +125,7 @@ public:
#endif // wxHAVE_RAW_BITMAP
void OnQuit( wxCommandEvent &event );
#if wxUSE_CLIPBOARD && !defined(__WXMOTIF_)
#if wxUSE_CLIPBOARD
void OnCopy(wxCommandEvent& event);
void OnPaste(wxCommandEvent& event);
#endif // wxUSE_CLIPBOARD
@@ -817,7 +817,7 @@ BEGIN_EVENT_TABLE(MyFrame,wxFrame)
EVT_MENU (ID_SHOWRAW, MyFrame::OnTestRawBitmap)
#endif
#if wxUSE_CLIPBOARD && !defined(__WXMOTIF__)
#if wxUSE_CLIPBOARD
EVT_MENU(wxID_COPY, MyFrame::OnCopy)
EVT_MENU(wxID_PASTE, MyFrame::OnPaste)
#endif // wxUSE_CLIPBOARD
@@ -841,7 +841,7 @@ MyFrame::MyFrame()
menuImage->Append( ID_QUIT, _T("E&xit\tCtrl-Q"));
menu_bar->Append(menuImage, _T("&Image"));
#if wxUSE_CLIPBOARD && !defined(__WXMOTIF__)
#if wxUSE_CLIPBOARD
wxMenu *menuClipboard = new wxMenu;
menuClipboard->Append(wxID_COPY, _T("&Copy test image\tCtrl-C"));
menuClipboard->Append(wxID_PASTE, _T("&Paste image\tCtrl-V"));
@@ -898,22 +898,28 @@ void MyFrame::OnTestRawBitmap( wxCommandEvent &event )
#endif // wxHAVE_RAW_BITMAP
#if wxUSE_CLIPBOARD && !defined(__WXMOTIF__)
#if wxUSE_CLIPBOARD
void MyFrame::OnCopy(wxCommandEvent& WXUNUSED(event))
{
wxBitmapDataObject *dobjBmp = new wxBitmapDataObject;
dobjBmp->SetBitmap(*m_canvas->my_horse_png);
wxTheClipboard->Open();
if ( !wxTheClipboard->SetData(dobjBmp) )
{
wxLogError(_T("Failed to copy bitmap to clipboard"));
}
wxTheClipboard->Close();
}
void MyFrame::OnPaste(wxCommandEvent& WXUNUSED(event))
{
wxBitmapDataObject dobjBmp;
wxTheClipboard->Open();
if ( !wxTheClipboard->GetData(dobjBmp) )
{
wxLogMessage(_T("No bitmap data in the clipboard"));
@@ -922,6 +928,7 @@ void MyFrame::OnPaste(wxCommandEvent& WXUNUSED(event))
{
(new MyImageFrame(this, dobjBmp.GetBitmap()))->Show();
}
wxTheClipboard->Close();
}
#endif // wxUSE_CLIPBOARD
+1
View File
@@ -564,6 +564,7 @@ WXWidget wxCreateTopLevelWidget( WXDisplay* display )
applicationShellWidgetClass,
(Display*)display,
NULL, 0 );
XtRealizeWidget( tlw );
XtAddCallback( tlw, XmNdestroyCallback,
(XtCallbackProc)wxTLWidgetDestroyCallback,
+246 -371
View File
File diff suppressed because it is too large Load Diff
+27 -45
View File
@@ -17,6 +17,7 @@
#include "wx/dataobj.h"
#include "wx/app.h"
#include "wx/utils.h"
#ifdef __VMS__
#pragma message disable nosimpint
@@ -25,14 +26,15 @@
#ifdef __VMS__
#pragma message enable nosimpint
#endif
#include "wx/utils.h"
#include "wx/motif/private.h"
//-------------------------------------------------------------------------
// global data
//-------------------------------------------------------------------------
Atom g_textAtom = 0;
Atom g_pngAtom = 0;
Atom g_bitmapAtom = 0;
Atom g_fileAtom = 0;
//-------------------------------------------------------------------------
@@ -86,7 +88,7 @@ void wxDataFormat::SetType( wxDataFormatId type )
m_format = g_textAtom;
else
if (m_type == wxDF_BITMAP)
m_format = g_pngAtom;
m_format = g_bitmapAtom;
else
if (m_type == wxDF_FILENAME)
m_format = g_fileAtom;
@@ -118,7 +120,7 @@ void wxDataFormat::SetId( NativeFormat format )
if (m_format == g_textAtom)
m_type = wxDF_TEXT;
else
if (m_format == g_pngAtom)
if (m_format == g_bitmapAtom)
m_type = wxDF_BITMAP;
else
if (m_format == g_fileAtom)
@@ -132,17 +134,18 @@ void wxDataFormat::SetId( const wxChar *id )
PrepareFormats();
m_type = wxDF_PRIVATE;
wxString tmp( id );
m_format = XInternAtom( (Display*) wxGetDisplay(), wxMBSTRINGCAST tmp.mbc_str(), FALSE ); // what is the string cast for?
m_format = XInternAtom( wxGlobalDisplay(),
tmp.mbc_str(), FALSE );
}
void wxDataFormat::PrepareFormats()
{
if (!g_textAtom)
g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
if (!g_pngAtom)
g_pngAtom = XInternAtom( (Display*) wxGetDisplay(), "image/png", FALSE );
g_textAtom = XInternAtom( wxGlobalDisplay(), "STRING", FALSE );
if (!g_bitmapAtom)
g_bitmapAtom = XInternAtom( wxGlobalDisplay(), "PIXMAP", FALSE );
if (!g_fileAtom)
g_fileAtom = XInternAtom( (Display*) wxGetDisplay(), "file:ALL", FALSE );
g_fileAtom = XInternAtom( wxGlobalDisplay(), "file:ALL", FALSE );
}
// ----------------------------------------------------------------------------
@@ -153,56 +156,35 @@ wxDataObject::~wxDataObject()
{
}
#if 0
// ----------------------------------------------------------------------------
// wxPrivateDataObject
// wxBitmapDataObject
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
void wxPrivateDataObject::Free()
size_t wxBitmapDataObject::GetDataSize() const
{
if ( m_data )
free(m_data);
return sizeof(Pixmap);
}
wxPrivateDataObject::wxPrivateDataObject()
bool wxBitmapDataObject::GetDataHere(void* buf) const
{
wxString id = wxT("application/");
id += wxTheApp->GetAppName();
if( !GetBitmap().Ok() )
return false;
m_format.SetId( id );
(*(Pixmap*)buf) = (Pixmap)GetBitmap().GetDrawable();
m_size = 0;
m_data = (void *)NULL;
return true;
}
void wxPrivateDataObject::SetData( const void *data, size_t size )
bool wxBitmapDataObject::SetData(size_t len, const void* buf)
{
Free();
if( len != sizeof(Pixmap) )
return false;
m_size = size;
m_data = malloc(size);
WXPixmap pixmap = (WXPixmap)*(Pixmap*)buf;
memcpy( m_data, data, size );
m_bitmap.Create( pixmap );
return true;
}
void wxPrivateDataObject::WriteData( void *dest ) const
{
WriteData( m_data, dest );
}
size_t wxPrivateDataObject::GetSize() const
{
return m_size;
}
void wxPrivateDataObject::WriteData( const void *data, void *dest ) const
{
memcpy( dest, data, GetSize() );
}
#endif // 0
#endif // wxUSE_CLIPBOARD
+3 -1
View File
@@ -521,6 +521,7 @@ ALL_HEADERS = \
motif/cursor.h \
motif/dataform.h \
motif/dataobj.h \
motif/dataobj2.h \
motif/dc.h \
motif/dcclient.h \
motif/dcmemory.h \
@@ -625,7 +626,8 @@ ALL_HEADERS = \
protocol/protocol.h \
x11/bitmap.h \
x11/brush.h \
x11/pen.h
x11/pen.h \
x11/privx.h
COMMONOBJS = \
accesscmn.o \
+40
View File
@@ -375,6 +375,46 @@ bool wxBitmap::Create(void *data, wxBitmapType type,
return handler->Create(this, data, type, width, height, depth);
}
bool wxBitmap::Create(WXPixmap pixmap)
{
UnRef();
Pixmap xpixmap = (Pixmap)pixmap;
Display* xdisplay = wxGlobalDisplay();
int xscreen = DefaultScreen( xdisplay );
Window xroot = RootWindow( xdisplay, xscreen );
// make a copy of the Pixmap
Window root;
Pixmap copy;
int x, y;
unsigned width, height, border, depth;
XGetGeometry( xdisplay, (Drawable)xpixmap, &root, &x, &y,
&width, &height, &border, &depth );
copy = XCreatePixmap( xdisplay, xroot, width, height, depth );
GC gc = XCreateGC( xdisplay, copy, 0, NULL );
XCopyArea( xdisplay, xpixmap, copy, gc, 0, 0, width, height, 0, 0 );
XFreeGC( xdisplay, gc );
// fill in ref data
wxBitmapRefData* ref = new wxBitmapRefData();
if( depth == 1 )
ref->m_bitmap = (WXPixmap)copy;
else
ref->m_pixmap = (WXPixmap)copy;
ref->m_display = (WXDisplay*)xdisplay;
ref->m_width = width;
ref->m_height = height;
ref->m_bpp = depth;
m_refData = ref;
return true;
}
bool wxBitmap::CreateFromXpm( const char **bits )
{
wxCHECK_MSG( bits, FALSE, _T("NULL pointer in wxBitmap::CreateFromXpm") );