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