]>
git.saurik.com Git - wxWidgets.git/blob - src/x11/dataobj.cpp
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDataObject class
4 // Author: Julian Smart
6 // Copyright: (c) 1998 Julian Smart
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "dataobj.h"
18 #include "wx/dataobj.h"
22 #pragma message disable nosimpint
25 #pragma message enable nosimpint
28 #include "wx/x11/private.h"
30 //-------------------------------------------------------------------------
32 //-------------------------------------------------------------------------
38 //-------------------------------------------------------------------------
40 //-------------------------------------------------------------------------
42 wxDataFormat::wxDataFormat()
44 // do *not* call PrepareFormats() from here for 2 reasons:
46 // 1. we will have time to do it later because some other Set function
47 // must be called before we really need them
49 // 2. doing so prevents us from declaring global wxDataFormats because
50 // calling PrepareFormats (and thus gdk_atom_intern) before GDK is
51 // initialised will result in a crash
52 m_type
= wxDF_INVALID
;
56 wxDataFormat::wxDataFormat( wxDataFormatId type
)
62 wxDataFormat::wxDataFormat( const wxChar
*id
)
68 wxDataFormat::wxDataFormat( const wxString
&id
)
74 wxDataFormat::wxDataFormat( NativeFormat format
)
80 void wxDataFormat::SetType( wxDataFormatId type
)
85 if (m_type
== wxDF_TEXT
)
86 m_format
= g_textAtom
;
88 if (m_type
== wxDF_BITMAP
)
91 if (m_type
== wxDF_FILENAME
)
92 m_format
= g_fileAtom
;
95 wxFAIL_MSG( wxT("invalid dataformat") );
99 wxDataFormatId
wxDataFormat::GetType() const
104 wxString
wxDataFormat::GetId() const
106 char *t
= XGetAtomName ((Display
*) wxGetDisplay(), m_format
);
107 wxString
ret( t
); // this will convert from ascii to Unicode
113 void wxDataFormat::SetId( NativeFormat format
)
118 if (m_format
== g_textAtom
)
121 if (m_format
== g_pngAtom
)
122 m_type
= wxDF_BITMAP
;
124 if (m_format
== g_fileAtom
)
125 m_type
= wxDF_FILENAME
;
127 m_type
= wxDF_PRIVATE
;
130 void wxDataFormat::SetId( const wxChar
*id
)
133 m_type
= wxDF_PRIVATE
;
135 m_format
= XInternAtom( (Display
*) wxGetDisplay(), wxMBSTRINGCAST tmp
.mbc_str(), FALSE
); // what is the string cast for?
138 void wxDataFormat::PrepareFormats()
141 g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
143 g_pngAtom
= XInternAtom( (Display
*) wxGetDisplay(), "image/png", FALSE
);
145 g_fileAtom
= XInternAtom( (Display
*) wxGetDisplay(), "file:ALL", FALSE
);
150 // ----------------------------------------------------------------------------
151 // wxPrivateDataObject
152 // ----------------------------------------------------------------------------
154 IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject
, wxDataObject
)
156 void wxPrivateDataObject::Free()
162 wxPrivateDataObject::wxPrivateDataObject()
164 wxString id
= wxT("application/");
165 id
+= wxTheApp
->GetAppName();
167 m_format
.SetId( id
);
170 m_data
= (void *)NULL
;
173 void wxPrivateDataObject::SetData( const void *data
, size_t size
)
178 m_data
= malloc(size
);
180 memcpy( m_data
, data
, size
);
183 void wxPrivateDataObject::WriteData( void *dest
) const
185 WriteData( m_data
, dest
);
188 size_t wxPrivateDataObject::GetSize() const
193 void wxPrivateDataObject::WriteData( const void *data
, void *dest
) const
195 memcpy( dest
, data
, GetSize() );
200 #endif // wxUSE_CLIPBOARD