]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dataobj.cpp
why cvs thinks that I modified these files?
[wxWidgets.git] / src / motif / dataobj.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: dataobj.cpp
3 // Purpose: wxDataObject class
4 // Author: Julian Smart
5 // Id: $Id$
6 // Copyright: (c) 1998 Julian Smart
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation "dataobj.h"
12 #endif
13
14 #include "wx/dataobj.h"
15 #include "wx/app.h"
16
17 #include <Xm/Xm.h>
18 #include "wx/utils.h"
19
20 //-------------------------------------------------------------------------
21 // global data
22 //-------------------------------------------------------------------------
23
24 Atom g_textAtom = 0;
25
26 //-------------------------------------------------------------------------
27 // wxDataFormat
28 //-------------------------------------------------------------------------
29
30 IMPLEMENT_CLASS(wxDataFormat, wxObject)
31
32 wxDataFormat::wxDataFormat()
33 {
34 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
35 m_type = wxDF_INVALID;
36 m_hasAtom = FALSE;
37 m_atom = (Atom) 0;
38 }
39
40 wxDataFormat::wxDataFormat( wxDataFormatId type )
41 {
42 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
43 SetType( type );
44 }
45
46 wxDataFormat::wxDataFormat( const wxChar *id )
47 {
48 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
49 SetId( id );
50 }
51
52 wxDataFormat::wxDataFormat( const wxString &id )
53 {
54 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
55 SetId( id );
56 }
57
58 wxDataFormat::wxDataFormat( const wxDataFormat &format )
59 {
60 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
61 m_type = format.GetType();
62 m_id = format.GetId();
63 m_hasAtom = TRUE;
64 m_atom = ((wxDataFormat &)format).GetAtom(); // const_cast
65 }
66
67 wxDataFormat::wxDataFormat( const Atom atom )
68 {
69 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
70 m_hasAtom = TRUE;
71
72 m_atom = atom;
73
74 if (m_atom == g_textAtom)
75 {
76 m_type = wxDF_TEXT;
77 } else
78 /*
79 if (m_atom == GDK_TARGET_BITMAP)
80 {
81 m_type = wxDF_BITMAP;
82 } else
83 */
84 {
85 m_type = wxDF_PRIVATE;
86 m_id = XGetAtomName( (Display*) wxGetDisplay(), m_atom );
87
88 if (m_id == _T("file:ALL"))
89 {
90 m_type = wxDF_FILENAME;
91 }
92 }
93 }
94
95 void wxDataFormat::SetType( wxDataFormatId type )
96 {
97 m_type = type;
98
99 if (m_type == wxDF_TEXT)
100 {
101 m_id = _T("STRING");
102 }
103 else
104 if (m_type == wxDF_BITMAP)
105 {
106 m_id = _T("BITMAP");
107 }
108 else
109 if (m_type == wxDF_FILENAME)
110 {
111 m_id = _T("file:ALL");
112 }
113 else
114 {
115 wxFAIL_MSG( _T("invalid dataformat") );
116 }
117
118 m_hasAtom = FALSE;
119 }
120
121 wxDataFormatId wxDataFormat::GetType() const
122 {
123 return m_type;
124 }
125
126 wxString wxDataFormat::GetId() const
127 {
128 return m_id;
129 }
130
131 void wxDataFormat::SetId( const wxChar *id )
132 {
133 m_type = wxDF_PRIVATE;
134 m_id = id;
135 m_hasAtom = FALSE;
136 }
137
138 Atom wxDataFormat::GetAtom()
139 {
140 if (!m_hasAtom)
141 {
142 m_hasAtom = TRUE;
143
144 if (m_type == wxDF_TEXT)
145 {
146 m_atom = g_textAtom;
147 }
148 else
149 /*
150 if (m_type == wxDF_BITMAP)
151 {
152 m_atom = GDK_TARGET_BITMAP;
153 }
154 else
155 */
156 if (m_type == wxDF_PRIVATE)
157 {
158 m_atom = XInternAtom( (Display*) wxGetDisplay(), MBSTRINGCAST m_id.mbc_str(), FALSE );
159 }
160 else
161 if (m_type == wxDF_FILENAME)
162 {
163 m_atom = XInternAtom( (Display*) wxGetDisplay(), "file:ALL", FALSE );
164 }
165 else
166 {
167 m_hasAtom = FALSE;
168 m_atom = (Atom) 0;
169 }
170 }
171
172 return m_atom;
173 }
174
175 //-------------------------------------------------------------------------
176 // wxDataObject
177 //-------------------------------------------------------------------------
178
179 IMPLEMENT_ABSTRACT_CLASS( wxDataObject, wxObject )
180
181 wxDataObject::wxDataObject()
182 {
183 }
184
185 wxDataObject::~wxDataObject()
186 {
187 }
188
189 wxDataFormat &wxDataObject::GetFormat()
190 {
191 return m_format;
192 }
193
194 wxDataFormatId wxDataObject::GetFormatType() const
195 {
196 return m_format.GetType();
197 }
198
199 wxString wxDataObject::GetFormatId() const
200 {
201 return m_format.GetId();
202 }
203
204 Atom wxDataObject::GetFormatAtom() const
205 {
206 Atom ret = ((wxDataObject*) this)->m_format.GetAtom();
207 return ret;
208 }
209
210 // ----------------------------------------------------------------------------
211 // wxTextDataObject
212 // ----------------------------------------------------------------------------
213
214 IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject )
215
216 wxTextDataObject::wxTextDataObject()
217 {
218 m_format.SetType( wxDF_TEXT );
219 }
220
221 wxTextDataObject::wxTextDataObject( const wxString& data )
222 {
223 m_format.SetType( wxDF_TEXT );
224
225 m_data = data;
226 }
227
228 void wxTextDataObject::SetText( const wxString& data )
229 {
230 m_data = data;
231 }
232
233 wxString wxTextDataObject::GetText() const
234 {
235 return m_data;
236 }
237
238 void wxTextDataObject::WriteData( void *dest ) const
239 {
240 WriteString( m_data, dest );
241 }
242
243 size_t wxTextDataObject::GetSize() const
244 {
245 return m_data.Len() + 1;
246 }
247
248 void wxTextDataObject::WriteString( const wxString &str, void *dest ) const
249 {
250 memcpy( dest, str.mb_str(), str.Len()+1 );
251 }
252
253 // ----------------------------------------------------------------------------
254 // wxPrivateDataObject
255 // ----------------------------------------------------------------------------
256
257 IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
258
259 void wxPrivateDataObject::Free()
260 {
261 if ( m_data )
262 free(m_data);
263 }
264
265 wxPrivateDataObject::wxPrivateDataObject()
266 {
267 wxString id = _T("application/");
268 id += wxTheApp->GetAppName();
269
270 m_format.SetId( id );
271
272 m_size = 0;
273 m_data = (void *)NULL;
274 }
275
276 void wxPrivateDataObject::SetData( const void *data, size_t size )
277 {
278 Free();
279
280 m_size = size;
281 m_data = malloc(size);
282
283 memcpy( m_data, data, size );
284 }
285
286 void wxPrivateDataObject::WriteData( void *dest ) const
287 {
288 WriteData( m_data, dest );
289 }
290
291 size_t wxPrivateDataObject::GetSize() const
292 {
293 return m_size;
294 }
295
296 void wxPrivateDataObject::WriteData( const void *data, void *dest ) const
297 {
298 memcpy( dest, data, GetSize() );
299 }
300