]>
git.saurik.com Git - wxWidgets.git/blob - src/motif/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"
24 //-------------------------------------------------------------------------
26 //-------------------------------------------------------------------------
32 //-------------------------------------------------------------------------
34 //-------------------------------------------------------------------------
36 wxDataFormat::wxDataFormat()
38 // do *not* call PrepareFormats() from here for 2 reasons:
40 // 1. we will have time to do it later because some other Set function
41 // must be called before we really need them
43 // 2. doing so prevents us from declaring global wxDataFormats because
44 // calling PrepareFormats (and thus gdk_atom_intern) before GDK is
45 // initialised will result in a crash
46 m_type
= wxDF_INVALID
;
50 wxDataFormat::wxDataFormat( wxDataFormatId type
)
56 wxDataFormat::wxDataFormat( const wxChar
*id
)
62 wxDataFormat::wxDataFormat( const wxString
&id
)
68 wxDataFormat::wxDataFormat( NativeFormat format
)
74 void wxDataFormat::SetType( wxDataFormatId type
)
79 if (m_type
== wxDF_TEXT
)
80 m_format
= g_textAtom
;
82 if (m_type
== wxDF_BITMAP
)
85 if (m_type
== wxDF_FILENAME
)
86 m_format
= g_fileAtom
;
89 wxFAIL_MSG( wxT("invalid dataformat") );
93 wxDataFormatId
wxDataFormat::GetType() const
98 wxString
wxDataFormat::GetId() const
100 char *t
= XGetAtomName ((Display
*) wxGetDisplay(), m_format
);
101 wxString
ret( t
); // this will convert from ascii to Unicode
107 void wxDataFormat::SetId( NativeFormat format
)
112 if (m_format
== g_textAtom
)
115 if (m_format
== g_pngAtom
)
116 m_type
= wxDF_BITMAP
;
118 if (m_format
== g_fileAtom
)
119 m_type
= wxDF_FILENAME
;
121 m_type
= wxDF_PRIVATE
;
124 void wxDataFormat::SetId( const wxChar
*id
)
127 m_type
= wxDF_PRIVATE
;
129 m_format
= XInternAtom( (Display
*) wxGetDisplay(), wxMBSTRINGCAST tmp
.mbc_str(), FALSE
); // what is the string cast for?
132 void wxDataFormat::PrepareFormats()
135 g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
137 g_pngAtom
= XInternAtom( (Display
*) wxGetDisplay(), "image/png", FALSE
);
139 g_fileAtom
= XInternAtom( (Display
*) wxGetDisplay(), "file:ALL", FALSE
);
144 // ----------------------------------------------------------------------------
145 // wxPrivateDataObject
146 // ----------------------------------------------------------------------------
148 IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject
, wxDataObject
)
150 void wxPrivateDataObject::Free()
156 wxPrivateDataObject::wxPrivateDataObject()
158 wxString id
= wxT("application/");
159 id
+= wxTheApp
->GetAppName();
161 m_format
.SetId( id
);
164 m_data
= (void *)NULL
;
167 void wxPrivateDataObject::SetData( const void *data
, size_t size
)
172 m_data
= malloc(size
);
174 memcpy( m_data
, data
, size
);
177 void wxPrivateDataObject::WriteData( void *dest
) const
179 WriteData( m_data
, dest
);
182 size_t wxPrivateDataObject::GetSize() const
187 void wxPrivateDataObject::WriteData( const void *data
, void *dest
) const
189 memcpy( dest
, data
, GetSize() );
194 #endif // wxUSE_CLIPBOARD