]> git.saurik.com Git - wxWidgets.git/blame - src/motif/dataobj.cpp
Someone need to make the clientdata be void* instead of this char*
[wxWidgets.git] / src / motif / dataobj.cpp
CommitLineData
dc63c944
JS
1///////////////////////////////////////////////////////////////////////////////
2// Name: dataobj.cpp
3// Purpose: wxDataObject class
4// Author: Julian Smart
5// Id: $Id$
6// Copyright: (c) 1998 Julian Smart
dfe1eee3 7// Licence: wxWindows licence
dc63c944
JS
8///////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "dataobj.h"
12#endif
13
dfe1eee3
VZ
14#include "wx/defs.h"
15
16#if wxUSE_CLIPBOARD
17
dc63c944
JS
18#include "wx/dataobj.h"
19#include "wx/app.h"
20
da175b2c
RR
21#include <Xm/Xm.h>
22#include "wx/utils.h"
23
24//-------------------------------------------------------------------------
25// global data
26//-------------------------------------------------------------------------
27
28Atom g_textAtom = 0;
29
30//-------------------------------------------------------------------------
31// wxDataFormat
32//-------------------------------------------------------------------------
33
34IMPLEMENT_CLASS(wxDataFormat, wxObject)
35
36wxDataFormat::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
44wxDataFormat::wxDataFormat( wxDataFormatId type )
45{
46 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
47 SetType( type );
48}
49
50wxDataFormat::wxDataFormat( const wxChar *id )
51{
52 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
53 SetId( id );
54}
55
56wxDataFormat::wxDataFormat( const wxString &id )
57{
58 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
59 SetId( id );
60}
61
62wxDataFormat::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
71wxDataFormat::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
99void 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
125wxDataFormatId wxDataFormat::GetType() const
126{
127 return m_type;
128}
129
130wxString wxDataFormat::GetId() const
131{
132 return m_id;
133}
134
135void wxDataFormat::SetId( const wxChar *id )
136{
137 m_type = wxDF_PRIVATE;
138 m_id = id;
139 m_hasAtom = FALSE;
140}
141
142Atom 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
dc63c944
JS
179//-------------------------------------------------------------------------
180// wxDataObject
181//-------------------------------------------------------------------------
182
183IMPLEMENT_ABSTRACT_CLASS( wxDataObject, wxObject )
184
da175b2c
RR
185wxDataObject::wxDataObject()
186{
187}
188
189wxDataObject::~wxDataObject()
190{
191}
192
193wxDataFormat &wxDataObject::GetFormat()
194{
195 return m_format;
196}
197
198wxDataFormatId wxDataObject::GetFormatType() const
199{
200 return m_format.GetType();
201}
202
203wxString wxDataObject::GetFormatId() const
204{
205 return m_format.GetId();
206}
207
208Atom wxDataObject::GetFormatAtom() const
209{
210 Atom ret = ((wxDataObject*) this)->m_format.GetAtom();
211 return ret;
212}
213
dc63c944
JS
214// ----------------------------------------------------------------------------
215// wxTextDataObject
216// ----------------------------------------------------------------------------
217
218IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject )
219
da175b2c
RR
220wxTextDataObject::wxTextDataObject()
221{
222 m_format.SetType( wxDF_TEXT );
223}
dc63c944 224
da175b2c
RR
225wxTextDataObject::wxTextDataObject( const wxString& data )
226{
227 m_format.SetType( wxDF_TEXT );
dc63c944 228
da175b2c
RR
229 m_data = data;
230}
231
232void wxTextDataObject::SetText( const wxString& data )
233{
234 m_data = data;
235}
236
237wxString wxTextDataObject::GetText() const
238{
239 return m_data;
240}
dc63c944 241
da175b2c
RR
242void wxTextDataObject::WriteData( void *dest ) const
243{
244 WriteString( m_data, dest );
245}
246
247size_t wxTextDataObject::GetSize() const
248{
249 return m_data.Len() + 1;
250}
251
252void wxTextDataObject::WriteString( const wxString &str, void *dest ) const
253{
254 memcpy( dest, str.mb_str(), str.Len()+1 );
255}
dc63c944
JS
256
257// ----------------------------------------------------------------------------
258// wxPrivateDataObject
259// ----------------------------------------------------------------------------
260
261IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
262
da175b2c
RR
263void wxPrivateDataObject::Free()
264{
265 if ( m_data )
266 free(m_data);
dc63c944 267}
da175b2c
RR
268
269wxPrivateDataObject::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;
dc63c944 278}
da175b2c
RR
279
280void wxPrivateDataObject::SetData( const void *data, size_t size )
dc63c944 281{
da175b2c
RR
282 Free();
283
dc63c944 284 m_size = size;
da175b2c 285 m_data = malloc(size);
dc63c944 286
da175b2c
RR
287 memcpy( m_data, data, size );
288}
289
290void wxPrivateDataObject::WriteData( void *dest ) const
291{
292 WriteData( m_data, dest );
293}
294
295size_t wxPrivateDataObject::GetSize() const
296{
297 return m_size;
298}
299
300void wxPrivateDataObject::WriteData( const void *data, void *dest ) const
301{
302 memcpy( dest, data, GetSize() );
dc63c944
JS
303}
304
dfe1eee3 305#endif // wxUSE_CLIPBOARD