X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dc63c944b3193e35fd1f49aceabc010c070ae53f..222702b112dcc7bebe018d6f4d66fe469fefd02c:/src/motif/dataobj.cpp?ds=sidebyside diff --git a/src/motif/dataobj.cpp b/src/motif/dataobj.cpp index 465bc56741..6078e4b710 100644 --- a/src/motif/dataobj.cpp +++ b/src/motif/dataobj.cpp @@ -4,66 +4,190 @@ // Author: Julian Smart // Id: $Id$ // Copyright: (c) 1998 Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "dataobj.h" #endif +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#include "wx/defs.h" + +#if wxUSE_CLIPBOARD + #include "wx/dataobj.h" #include "wx/app.h" +#include "wx/utils.h" + +#ifdef __VMS__ +#pragma message disable nosimpint +#endif +#include +#ifdef __VMS__ +#pragma message enable nosimpint +#endif + +#include "wx/motif/private.h" //------------------------------------------------------------------------- -// wxDataObject +// global data //------------------------------------------------------------------------- -IMPLEMENT_ABSTRACT_CLASS( wxDataObject, wxObject ) +Atom g_textAtom = 0; +Atom g_bitmapAtom = 0; +Atom g_fileAtom = 0; -// ---------------------------------------------------------------------------- -// wxTextDataObject -// ---------------------------------------------------------------------------- +//------------------------------------------------------------------------- +// wxDataFormat +//------------------------------------------------------------------------- + +wxDataFormat::wxDataFormat() +{ + // do *not* call PrepareFormats() from here for 2 reasons: + // + // 1. we will have time to do it later because some other Set function + // must be called before we really need them + // + // 2. doing so prevents us from declaring global wxDataFormats because + // calling PrepareFormats (and thus gdk_atom_intern) before GDK is + // initialised will result in a crash + m_type = wxDF_INVALID; + m_format = (Atom) 0; +} + +wxDataFormat::wxDataFormat( wxDataFormatId type ) +{ + PrepareFormats(); + SetType( type ); +} + +wxDataFormat::wxDataFormat( const wxChar *id ) +{ + PrepareFormats(); + SetId( id ); +} + +wxDataFormat::wxDataFormat( const wxString &id ) +{ + PrepareFormats(); + SetId( id ); +} + +wxDataFormat::wxDataFormat( NativeFormat format ) +{ + PrepareFormats(); + SetId( format ); +} + +void wxDataFormat::SetType( wxDataFormatId type ) +{ + PrepareFormats(); + m_type = type; -IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject ) + if (m_type == wxDF_TEXT) + m_format = g_textAtom; + else + if (m_type == wxDF_BITMAP) + m_format = g_bitmapAtom; + else + if (m_type == wxDF_FILENAME) + m_format = g_fileAtom; + else + { + wxFAIL_MSG( wxT("invalid dataformat") ); + } +} + +wxDataFormatId wxDataFormat::GetType() const +{ + return m_type; +} + +wxString wxDataFormat::GetId() const +{ + char *t = XGetAtomName ((Display*) wxGetDisplay(), m_format); + wxString ret( t ); // this will convert from ascii to Unicode + if (t) + XFree( t ); + return ret; +} + +void wxDataFormat::SetId( NativeFormat format ) +{ + PrepareFormats(); + m_format = format; + + if (m_format == g_textAtom) + m_type = wxDF_TEXT; + else + if (m_format == g_bitmapAtom) + m_type = wxDF_BITMAP; + else + if (m_format == g_fileAtom) + m_type = wxDF_FILENAME; + else + m_type = wxDF_PRIVATE; +} + +void wxDataFormat::SetId( const wxChar *id ) +{ + PrepareFormats(); + m_type = wxDF_PRIVATE; + wxString tmp( id ); + m_format = XInternAtom( wxGlobalDisplay(), + tmp.mbc_str(), False ); +} + +void wxDataFormat::PrepareFormats() +{ + if (!g_textAtom) + g_textAtom = XInternAtom( wxGlobalDisplay(), "STRING", False ); + if (!g_bitmapAtom) + g_bitmapAtom = XInternAtom( wxGlobalDisplay(), "PIXMAP", False ); + if (!g_fileAtom) + g_fileAtom = XInternAtom( wxGlobalDisplay(), "file:ALL", False ); +} // ---------------------------------------------------------------------------- -// wxFileDataObject +// wxDataObject // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS( wxFileDataObject, wxDataObject ) +wxDataObject::~wxDataObject() +{ +} // ---------------------------------------------------------------------------- // wxBitmapDataObject // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject ) +size_t wxBitmapDataObject::GetDataSize() const +{ + return sizeof(Pixmap); +} -// ---------------------------------------------------------------------------- -// wxPrivateDataObject -// ---------------------------------------------------------------------------- +bool wxBitmapDataObject::GetDataHere(void* buf) const +{ + if( !GetBitmap().Ok() ) + return false; -IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject ) + (*(Pixmap*)buf) = (Pixmap)GetBitmap().GetDrawable(); -wxPrivateDataObject::wxPrivateDataObject() -{ - m_size = 0; - m_data = (char*) NULL; - m_id = wxTheApp->GetAppName(); -} - -wxPrivateDataObject::~wxPrivateDataObject() -{ - if (m_data) delete[] m_data; + return true; } - -void wxPrivateDataObject::SetData( const char *data, size_t size ) + +bool wxBitmapDataObject::SetData(size_t len, const void* buf) { - m_size = size; - - if (m_data) delete[] m_data; - - m_data = new char[size]; + if( len != sizeof(Pixmap) ) + return false; + + WXPixmap pixmap = (WXPixmap)*(Pixmap*)buf; + + m_bitmap.Create( pixmap ); - memcpy( m_data, data, size ); + return true; } +#endif // wxUSE_CLIPBOARD