X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dfe1eee3bb9ecde8c4490ea69c07b5030d69530c..31e39e3c51f0a14a49ba86a5326e1461ad60dfee:/src/motif/dataobj.cpp diff --git a/src/motif/dataobj.cpp b/src/motif/dataobj.cpp index 2fdd9dd815..90e41f267a 100644 --- a/src/motif/dataobj.cpp +++ b/src/motif/dataobj.cpp @@ -18,7 +18,13 @@ #include "wx/dataobj.h" #include "wx/app.h" +#ifdef __VMS__ +#pragma message disable nosimpint +#endif #include +#ifdef __VMS__ +#pragma message enable nosimpint +#endif #include "wx/utils.h" //------------------------------------------------------------------------- @@ -26,100 +32,68 @@ //------------------------------------------------------------------------- Atom g_textAtom = 0; +Atom g_pngAtom = 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 ); + PrepareFormats(); 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 ) -{ - 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 ) +wxDataFormat::wxDataFormat( NativeFormat format ) { - 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_pngAtom; 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 @@ -129,130 +103,49 @@ 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() -{ -} - -wxDataFormat &wxDataObject::GetFormat() -{ - return m_format; -} - -wxDataFormatId wxDataObject::GetFormatType() const -{ - return m_format.GetType(); -} - -wxString wxDataObject::GetFormatId() const -{ - return m_format.GetId(); -} - -Atom wxDataObject::GetFormatAtom() const -{ - Atom ret = ((wxDataObject*) this)->m_format.GetAtom(); + char *t = XGetAtomName ((Display*) wxGetDisplay(), m_format); + wxString ret( t ); // this will convert from ascii to Unicode + if (t) + XFree( t ); return ret; } -// ---------------------------------------------------------------------------- -// wxTextDataObject -// ---------------------------------------------------------------------------- - -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 ) +void wxDataFormat::SetId( NativeFormat format ) { - m_data = data; -} + PrepareFormats(); + m_format = format; -wxString wxTextDataObject::GetText() const -{ - return m_data; + if (m_format == g_textAtom) + m_type = wxDF_TEXT; + else + if (m_format == g_pngAtom) + m_type = wxDF_BITMAP; + else + if (m_format == g_fileAtom) + m_type = wxDF_FILENAME; + else + m_type = wxDF_PRIVATE; } -void wxTextDataObject::WriteData( void *dest ) const +void wxDataFormat::SetId( const wxChar *id ) { - WriteString( m_data, dest ); + PrepareFormats(); + m_type = wxDF_PRIVATE; + wxString tmp( id ); + m_format = XInternAtom( (Display*) wxGetDisplay(), wxMBSTRINGCAST tmp.mbc_str(), FALSE ); // what is the string cast for? } -size_t wxTextDataObject::GetSize() const +void wxDataFormat::PrepareFormats() { - return m_data.Len() + 1; + if (!g_textAtom) + g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE ); + if (!g_pngAtom) + g_pngAtom = XInternAtom( (Display*) wxGetDisplay(), "image/png", FALSE ); + if (!g_fileAtom) + g_fileAtom = XInternAtom( (Display*) wxGetDisplay(), "file:ALL", FALSE ); } -void wxTextDataObject::WriteString( const wxString &str, void *dest ) const -{ - memcpy( dest, str.mb_str(), str.Len()+1 ); -} +#if 0 // ---------------------------------------------------------------------------- // wxPrivateDataObject @@ -268,7 +161,7 @@ void wxPrivateDataObject::Free() wxPrivateDataObject::wxPrivateDataObject() { - wxString id = _T("application/"); + wxString id = wxT("application/"); id += wxTheApp->GetAppName(); m_format.SetId( id ); @@ -302,4 +195,6 @@ void wxPrivateDataObject::WriteData( const void *data, void *dest ) const memcpy( dest, data, GetSize() ); } +#endif // 0 + #endif // wxUSE_CLIPBOARD