]>
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 //-------------------------------------------------------------------------
30 //-------------------------------------------------------------------------
32 //-------------------------------------------------------------------------
34 IMPLEMENT_CLASS(wxDataFormat
, wxObject
)
36 wxDataFormat::wxDataFormat()
38 if (!g_textAtom
) g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
39 m_type
= wxDF_INVALID
;
44 wxDataFormat::wxDataFormat( wxDataFormatId type
)
46 if (!g_textAtom
) g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
50 wxDataFormat::wxDataFormat( const wxChar
*id
)
52 if (!g_textAtom
) g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
56 wxDataFormat::wxDataFormat( const wxString
&id
)
58 if (!g_textAtom
) g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
62 wxDataFormat::wxDataFormat( const wxDataFormat
&format
)
64 if (!g_textAtom
) g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
65 m_type
= format
.GetType();
66 m_id
= format
.GetId();
68 m_atom
= ((wxDataFormat
&)format
).GetAtom(); // const_cast
71 wxDataFormat::wxDataFormat( const Atom atom
)
73 if (!g_textAtom
) g_textAtom
= XInternAtom( (Display
*) wxGetDisplay(), "STRING", FALSE
);
78 if (m_atom
== g_textAtom
)
83 if (m_atom == GDK_TARGET_BITMAP)
89 m_type
= wxDF_PRIVATE
;
90 m_id
= XGetAtomName( (Display
*) wxGetDisplay(), m_atom
);
92 if (m_id
== _T("file:ALL"))
94 m_type
= wxDF_FILENAME
;
99 void wxDataFormat::SetType( wxDataFormatId type
)
103 if (m_type
== wxDF_TEXT
)
108 if (m_type
== wxDF_BITMAP
)
113 if (m_type
== wxDF_FILENAME
)
115 m_id
= _T("file:ALL");
119 wxFAIL_MSG( _T("invalid dataformat") );
125 wxDataFormatId
wxDataFormat::GetType() const
130 wxString
wxDataFormat::GetId() const
135 void wxDataFormat::SetId( const wxChar
*id
)
137 m_type
= wxDF_PRIVATE
;
142 Atom
wxDataFormat::GetAtom()
148 if (m_type
== wxDF_TEXT
)
154 if (m_type == wxDF_BITMAP)
156 m_atom = GDK_TARGET_BITMAP;
160 if (m_type
== wxDF_PRIVATE
)
162 m_atom
= XInternAtom( (Display
*) wxGetDisplay(), MBSTRINGCAST m_id
.mbc_str(), FALSE
);
165 if (m_type
== wxDF_FILENAME
)
167 m_atom
= XInternAtom( (Display
*) wxGetDisplay(), "file:ALL", FALSE
);
179 //-------------------------------------------------------------------------
181 //-------------------------------------------------------------------------
183 IMPLEMENT_ABSTRACT_CLASS( wxDataObject
, wxObject
)
185 wxDataObject::wxDataObject()
189 wxDataObject::~wxDataObject()
193 wxDataFormat
&wxDataObject::GetFormat()
198 wxDataFormatId
wxDataObject::GetFormatType() const
200 return m_format
.GetType();
203 wxString
wxDataObject::GetFormatId() const
205 return m_format
.GetId();
208 Atom
wxDataObject::GetFormatAtom() const
210 Atom ret
= ((wxDataObject
*) this)->m_format
.GetAtom();
214 // ----------------------------------------------------------------------------
216 // ----------------------------------------------------------------------------
218 IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject
, wxDataObject
)
220 wxTextDataObject::wxTextDataObject()
222 m_format
.SetType( wxDF_TEXT
);
225 wxTextDataObject::wxTextDataObject( const wxString
& data
)
227 m_format
.SetType( wxDF_TEXT
);
232 void wxTextDataObject::SetText( const wxString
& data
)
237 wxString
wxTextDataObject::GetText() const
242 void wxTextDataObject::WriteData( void *dest
) const
244 WriteString( m_data
, dest
);
247 size_t wxTextDataObject::GetSize() const
249 return m_data
.Len() + 1;
252 void wxTextDataObject::WriteString( const wxString
&str
, void *dest
) const
254 memcpy( dest
, str
.mb_str(), str
.Len()+1 );
257 // ----------------------------------------------------------------------------
258 // wxPrivateDataObject
259 // ----------------------------------------------------------------------------
261 IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject
, wxDataObject
)
263 void wxPrivateDataObject::Free()
269 wxPrivateDataObject::wxPrivateDataObject()
271 wxString id
= _T("application/");
272 id
+= wxTheApp
->GetAppName();
274 m_format
.SetId( id
);
277 m_data
= (void *)NULL
;
280 void wxPrivateDataObject::SetData( const void *data
, size_t size
)
285 m_data
= malloc(size
);
287 memcpy( m_data
, data
, size
);
290 void wxPrivateDataObject::WriteData( void *dest
) const
292 WriteData( m_data
, dest
);
295 size_t wxPrivateDataObject::GetSize() const
300 void wxPrivateDataObject::WriteData( const void *data
, void *dest
) const
302 memcpy( dest
, data
, GetSize() );
305 #endif // wxUSE_CLIPBOARD