]>
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"
22 #pragma message disable nosimpint
26 #pragma message enable nosimpint
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
);
148 // ----------------------------------------------------------------------------
150 // ----------------------------------------------------------------------------
152 wxDataObject::~wxDataObject()
158 // ----------------------------------------------------------------------------
159 // wxPrivateDataObject
160 // ----------------------------------------------------------------------------
162 IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject
, wxDataObject
)
164 void wxPrivateDataObject::Free()
170 wxPrivateDataObject::wxPrivateDataObject()
172 wxString id
= wxT("application/");
173 id
+= wxTheApp
->GetAppName();
175 m_format
.SetId( id
);
178 m_data
= (void *)NULL
;
181 void wxPrivateDataObject::SetData( const void *data
, size_t size
)
186 m_data
= malloc(size
);
188 memcpy( m_data
, data
, size
);
191 void wxPrivateDataObject::WriteData( void *dest
) const
193 WriteData( m_data
, dest
);
196 size_t wxPrivateDataObject::GetSize() const
201 void wxPrivateDataObject::WriteData( const void *data
, void *dest
) const
203 memcpy( dest
, data
, GetSize() );
208 #endif // wxUSE_CLIPBOARD