]>
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"
14 #include "wx/dataobj.h"
20 //-------------------------------------------------------------------------
22 //-------------------------------------------------------------------------
26 //-------------------------------------------------------------------------
28 //-------------------------------------------------------------------------
30 IMPLEMENT_CLASS(wxDataFormat
, wxObject
)
32 wxDataFormat::wxDataFormat()
34 if (!g_textAtom
) g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
35 m_type
= wxDF_INVALID
;
40 wxDataFormat::wxDataFormat( wxDataFormatId type
)
42 if (!g_textAtom
) g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
46 wxDataFormat::wxDataFormat( const wxChar
*id
)
48 if (!g_textAtom
) g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
52 wxDataFormat::wxDataFormat( const wxString
&id
)
54 if (!g_textAtom
) g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
58 wxDataFormat::wxDataFormat( const wxDataFormat
&format
)
60 if (!g_textAtom
) g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
61 m_type
= format
.GetType();
62 m_id
= format
.GetId();
64 m_atom
= ((wxDataFormat
&)format
).GetAtom(); // const_cast
67 wxDataFormat::wxDataFormat( const Atom atom
)
69 if (!g_textAtom
) g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
74 if (m_atom
== g_textAtom
)
79 if (m_atom == GDK_TARGET_BITMAP)
85 m_type
= wxDF_PRIVATE
;
86 m_id
= XGetAtomName( (Display
*) wxGetDisplay(), m_atom
);
88 if (m_id
== _T("file:ALL"))
90 m_type
= wxDF_FILENAME
;
95 void wxDataFormat::SetType( wxDataFormatId type
)
99 if (m_type
== wxDF_TEXT
)
104 if (m_type
== wxDF_BITMAP
)
109 if (m_type
== wxDF_FILENAME
)
111 m_id
= _T("file:ALL");
115 wxFAIL_MSG( _T("invalid dataformat") );
121 wxDataFormatId
wxDataFormat::GetType() const
126 wxString
wxDataFormat::GetId() const
131 void wxDataFormat::SetId( const wxChar
*id
)
133 m_type
= wxDF_PRIVATE
;
138 Atom
wxDataFormat::GetAtom()
144 if (m_type
== wxDF_TEXT
)
150 if (m_type == wxDF_BITMAP)
152 m_atom = GDK_TARGET_BITMAP;
156 if (m_type
== wxDF_PRIVATE
)
158 m_atom
= XInternAtom( (Display
*) wxGetDisplay(), MBSTRINGCAST m_id
.mbc_str(), FALSE
);
161 if (m_type
== wxDF_FILENAME
)
163 m_atom
= XInternAtom( (Display
*) wxGetDisplay(), "file:ALL", FALSE
);
175 //-------------------------------------------------------------------------
177 //-------------------------------------------------------------------------
179 IMPLEMENT_ABSTRACT_CLASS( wxDataObject
, wxObject
)
181 wxDataObject::wxDataObject()
185 wxDataObject::~wxDataObject()
189 wxDataFormat
&wxDataObject::GetFormat()
194 wxDataFormatId
wxDataObject::GetFormatType() const
196 return m_format
.GetType();
199 wxString
wxDataObject::GetFormatId() const
201 return m_format
.GetId();
204 Atom
wxDataObject::GetFormatAtom() const
206 Atom ret
= ((wxDataObject
*) this)->m_format
.GetAtom();
210 // ----------------------------------------------------------------------------
212 // ----------------------------------------------------------------------------
214 IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject
, wxDataObject
)
216 wxTextDataObject::wxTextDataObject()
218 m_format
.SetType( wxDF_TEXT
);
221 wxTextDataObject::wxTextDataObject( const wxString
& data
)
223 m_format
.SetType( wxDF_TEXT
);
228 void wxTextDataObject::SetText( const wxString
& data
)
233 wxString
wxTextDataObject::GetText() const
238 void wxTextDataObject::WriteData( void *dest
) const
240 WriteString( m_data
, dest
);
243 size_t wxTextDataObject::GetSize() const
245 return m_data
.Len() + 1;
248 void wxTextDataObject::WriteString( const wxString
&str
, void *dest
) const
250 memcpy( dest
, str
.mb_str(), str
.Len()+1 );
253 // ----------------------------------------------------------------------------
254 // wxPrivateDataObject
255 // ----------------------------------------------------------------------------
257 IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject
, wxDataObject
)
259 void wxPrivateDataObject::Free()
265 wxPrivateDataObject::wxPrivateDataObject()
267 wxString id
= _T("application/");
268 id
+= wxTheApp
->GetAppName();
270 m_format
.SetId( id
);
273 m_data
= (void *)NULL
;
276 void wxPrivateDataObject::SetData( const void *data
, size_t size
)
281 m_data
= malloc(size
);
283 memcpy( m_data
, data
, size
);
286 void wxPrivateDataObject::WriteData( void *dest
) const
288 WriteData( m_data
, dest
);
291 size_t wxPrivateDataObject::GetSize() const
296 void wxPrivateDataObject::WriteData( const void *data
, void *dest
) const
298 memcpy( dest
, data
, GetSize() );