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