wxMotif compilation fixes for wxDataObject and PROCESS_EVENTS (wxSocket)
[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 wxDataFormat::wxDataFormat()
35 {
36 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
37 m_type = wxDF_INVALID;
38 m_hasAtom = FALSE;
39 m_atom = (Atom) 0;
40 }
41
42 wxDataFormat::wxDataFormat( wxDataFormatId type )
43 {
44 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
45 SetType( type );
46 }
47
48 wxDataFormat::wxDataFormat( const wxChar *id )
49 {
50 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
51 SetId( id );
52 }
53
54 wxDataFormat::wxDataFormat( const wxString &id )
55 {
56 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
57 SetId( id );
58 }
59
60 wxDataFormat::wxDataFormat( const wxDataFormat &format )
61 {
62 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
63 m_type = format.GetType();
64 m_id = format.GetId();
65 m_hasAtom = TRUE;
66 m_atom = ((wxDataFormat &)format).GetAtom(); // const_cast
67 }
68
69 wxDataFormat::wxDataFormat( const Atom atom )
70 {
71 if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
72 m_hasAtom = TRUE;
73
74 m_atom = atom;
75
76 if (m_atom == g_textAtom)
77 {
78 m_type = wxDF_TEXT;
79 } else
80 /*
81 if (m_atom == GDK_TARGET_BITMAP)
82 {
83 m_type = wxDF_BITMAP;
84 } else
85 */
86 {
87 m_type = wxDF_PRIVATE;
88 m_id = XGetAtomName( (Display*) wxGetDisplay(), m_atom );
89
90 if (m_id == wxT("file:ALL"))
91 {
92 m_type = wxDF_FILENAME;
93 }
94 }
95 }
96
97 void wxDataFormat::SetType( wxDataFormatId type )
98 {
99 m_type = type;
100
101 if (m_type == wxDF_TEXT)
102 {
103 m_id = wxT("STRING");
104 }
105 else
106 if (m_type == wxDF_BITMAP)
107 {
108 m_id = wxT("BITMAP");
109 }
110 else
111 if (m_type == wxDF_FILENAME)
112 {
113 m_id = wxT("file:ALL");
114 }
115 else
116 {
117 wxFAIL_MSG( wxT("invalid dataformat") );
118 }
119
120 m_hasAtom = FALSE;
121 }
122
123 void wxDataFormat::SetId( const wxChar *id )
124 {
125 m_type = wxDF_PRIVATE;
126 m_id = id;
127 m_hasAtom = FALSE;
128 }
129
130 Atom wxDataFormat::GetAtom()
131 {
132 if (!m_hasAtom)
133 {
134 m_hasAtom = TRUE;
135
136 if (m_type == wxDF_TEXT)
137 {
138 m_atom = g_textAtom;
139 }
140 else
141 /*
142 if (m_type == wxDF_BITMAP)
143 {
144 m_atom = GDK_TARGET_BITMAP;
145 }
146 else
147 */
148 if (m_type == wxDF_PRIVATE)
149 {
150 m_atom = XInternAtom( (Display*) wxGetDisplay(), wxMBSTRINGCAST m_id.mbc_str(), FALSE );
151 }
152 else
153 if (m_type == wxDF_FILENAME)
154 {
155 m_atom = XInternAtom( (Display*) wxGetDisplay(), "file:ALL", FALSE );
156 }
157 else
158 {
159 m_hasAtom = FALSE;
160 m_atom = (Atom) 0;
161 }
162 }
163
164 return m_atom;
165 }
166
167 #if 0
168
169 // ----------------------------------------------------------------------------
170 // wxPrivateDataObject
171 // ----------------------------------------------------------------------------
172
173 IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
174
175 void wxPrivateDataObject::Free()
176 {
177 if ( m_data )
178 free(m_data);
179 }
180
181 wxPrivateDataObject::wxPrivateDataObject()
182 {
183 wxString id = wxT("application/");
184 id += wxTheApp->GetAppName();
185
186 m_format.SetId( id );
187
188 m_size = 0;
189 m_data = (void *)NULL;
190 }
191
192 void wxPrivateDataObject::SetData( const void *data, size_t size )
193 {
194 Free();
195
196 m_size = size;
197 m_data = malloc(size);
198
199 memcpy( m_data, data, size );
200 }
201
202 void wxPrivateDataObject::WriteData( void *dest ) const
203 {
204 WriteData( m_data, dest );
205 }
206
207 size_t wxPrivateDataObject::GetSize() const
208 {
209 return m_size;
210 }
211
212 void wxPrivateDataObject::WriteData( const void *data, void *dest ) const
213 {
214 memcpy( dest, data, GetSize() );
215 }
216
217 #endif // 0
218
219 #endif // wxUSE_CLIPBOARD