X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/da175b2ce4dc35cc4c0baa8bbdc16bf4de6c7684..f968da288ee04ec5c0265861bb7a18182c0fb22e:/src/motif/dataobj.cpp diff --git a/src/motif/dataobj.cpp b/src/motif/dataobj.cpp index b41b06164e..c96ec26e15 100644 --- a/src/motif/dataobj.cpp +++ b/src/motif/dataobj.cpp @@ -1,121 +1,95 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: dataobj.cpp +// Name: src/motif/dataobj.cpp // Purpose: wxDataObject class // Author: Julian Smart // Id: $Id$ // Copyright: (c) 1998 Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "dataobj.h" -#endif +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#if wxUSE_CLIPBOARD #include "wx/dataobj.h" -#include "wx/app.h" +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/utils.h" +#endif + +#ifdef __VMS__ +#pragma message disable nosimpint +#endif #include -#include "wx/utils.h" +#ifdef __VMS__ +#pragma message enable nosimpint +#endif + +#include "wx/motif/private.h" //------------------------------------------------------------------------- // global data //------------------------------------------------------------------------- Atom g_textAtom = 0; +Atom g_bitmapAtom = 0; +Atom g_fileAtom = 0; //------------------------------------------------------------------------- // wxDataFormat //------------------------------------------------------------------------- -IMPLEMENT_CLASS(wxDataFormat, wxObject) - wxDataFormat::wxDataFormat() { - if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE ); + // 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_hasAtom = FALSE; - m_atom = (Atom) 0; + m_format = (Atom) 0; } wxDataFormat::wxDataFormat( wxDataFormatId type ) { - if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE ); + PrepareFormats(); SetType( type ); } -wxDataFormat::wxDataFormat( const wxChar *id ) -{ - if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE ); - SetId( id ); -} - wxDataFormat::wxDataFormat( const wxString &id ) { - if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE ); + PrepareFormats(); SetId( id ); } -wxDataFormat::wxDataFormat( const wxDataFormat &format ) +wxDataFormat::wxDataFormat( NativeFormat format ) { - if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE ); - m_type = format.GetType(); - m_id = format.GetId(); - m_hasAtom = TRUE; - m_atom = ((wxDataFormat &)format).GetAtom(); // const_cast -} - -wxDataFormat::wxDataFormat( const Atom atom ) -{ - if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE ); - m_hasAtom = TRUE; - - m_atom = atom; - - if (m_atom == g_textAtom) - { - m_type = wxDF_TEXT; - } else -/* - if (m_atom == GDK_TARGET_BITMAP) - { - m_type = wxDF_BITMAP; - } else -*/ - { - m_type = wxDF_PRIVATE; - m_id = XGetAtomName( (Display*) wxGetDisplay(), m_atom ); - - if (m_id == _T("file:ALL")) - { - m_type = wxDF_FILENAME; - } - } + PrepareFormats(); + SetId( format ); } void wxDataFormat::SetType( wxDataFormatId type ) { + PrepareFormats(); m_type = type; if (m_type == wxDF_TEXT) - { - m_id = _T("STRING"); - } + m_format = g_textAtom; else if (m_type == wxDF_BITMAP) - { - m_id = _T("BITMAP"); - } + m_format = g_bitmapAtom; else if (m_type == wxDF_FILENAME) - { - m_id = _T("file:ALL"); - } + m_format = g_fileAtom; else { - wxFAIL_MSG( _T("invalid dataformat") ); + wxFAIL_MSG( wxT("invalid dataformat") ); } - - m_hasAtom = FALSE; } wxDataFormatId wxDataFormat::GetType() const @@ -125,176 +99,85 @@ wxDataFormatId wxDataFormat::GetType() const wxString wxDataFormat::GetId() const { - return m_id; -} - -void wxDataFormat::SetId( const wxChar *id ) -{ - m_type = wxDF_PRIVATE; - m_id = id; - m_hasAtom = FALSE; -} - -Atom wxDataFormat::GetAtom() -{ - if (!m_hasAtom) - { - m_hasAtom = TRUE; - - if (m_type == wxDF_TEXT) - { - m_atom = g_textAtom; - } - else -/* - if (m_type == wxDF_BITMAP) - { - m_atom = GDK_TARGET_BITMAP; - } - else -*/ - if (m_type == wxDF_PRIVATE) - { - m_atom = XInternAtom( (Display*) wxGetDisplay(), MBSTRINGCAST m_id.mbc_str(), FALSE ); - } - else - if (m_type == wxDF_FILENAME) - { - m_atom = XInternAtom( (Display*) wxGetDisplay(), "file:ALL", FALSE ); - } - else - { - m_hasAtom = FALSE; - m_atom = (Atom) 0; - } - } - - return m_atom; -} - -//------------------------------------------------------------------------- -// wxDataObject -//------------------------------------------------------------------------- - -IMPLEMENT_ABSTRACT_CLASS( wxDataObject, wxObject ) - -wxDataObject::wxDataObject() -{ -} - -wxDataObject::~wxDataObject() -{ + char *t = XGetAtomName ((Display*) wxGetDisplay(), m_format); + wxString ret( t ); // this will convert from ascii to Unicode + if (t) + XFree( t ); + return ret; } -wxDataFormat &wxDataObject::GetFormat() +void wxDataFormat::SetId( NativeFormat format ) { - return m_format; -} + PrepareFormats(); + m_format = format; -wxDataFormatId wxDataObject::GetFormatType() const -{ - return m_format.GetType(); + 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; } -wxString wxDataObject::GetFormatId() const +void wxDataFormat::SetId( const wxString& id ) { - return m_format.GetId(); + PrepareFormats(); + m_type = wxDF_PRIVATE; + m_format = XInternAtom( wxGlobalDisplay(), + id.mbc_str(), False ); } -Atom wxDataObject::GetFormatAtom() const +void wxDataFormat::PrepareFormats() { - Atom ret = ((wxDataObject*) this)->m_format.GetAtom(); - return ret; + 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 ); } // ---------------------------------------------------------------------------- -// wxTextDataObject +// wxDataObject // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject ) - -wxTextDataObject::wxTextDataObject() -{ - m_format.SetType( wxDF_TEXT ); -} - -wxTextDataObject::wxTextDataObject( const wxString& data ) -{ - m_format.SetType( wxDF_TEXT ); - - m_data = data; -} - -void wxTextDataObject::SetText( const wxString& data ) -{ - m_data = data; -} - -wxString wxTextDataObject::GetText() const -{ - return m_data; -} - -void wxTextDataObject::WriteData( void *dest ) const -{ - WriteString( m_data, dest ); -} - -size_t wxTextDataObject::GetSize() const -{ - return m_data.Len() + 1; -} - -void wxTextDataObject::WriteString( const wxString &str, void *dest ) const +wxDataObject::~wxDataObject() { - memcpy( dest, str.mb_str(), str.Len()+1 ); } // ---------------------------------------------------------------------------- -// 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 = _T("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(); - - m_size = size; - m_data = malloc(size); - - memcpy( m_data, data, size ); -} + if( len != sizeof(Pixmap) ) + return false; -void wxPrivateDataObject::WriteData( void *dest ) const -{ - WriteData( m_data, dest ); -} + WXPixmap pixmap = (WXPixmap)*(Pixmap*)buf; -size_t wxPrivateDataObject::GetSize() const -{ - return m_size; -} + m_bitmap.Create( pixmap ); -void wxPrivateDataObject::WriteData( const void *data, void *dest ) const -{ - memcpy( dest, data, GetSize() ); + return true; } +#endif // wxUSE_CLIPBOARD