]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dataobj.cpp
attempt to work around SDK specific problems
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 #include "wx/utils.h"
21
22 #ifdef __VMS__
23 #pragma message disable nosimpint
24 #endif
25 #include <Xm/Xm.h>
26 #ifdef __VMS__
27 #pragma message enable nosimpint
28 #endif
29
30 #include "wx/motif/private.h"
31
32 //-------------------------------------------------------------------------
33 // global data
34 //-------------------------------------------------------------------------
35
36 Atom g_textAtom = 0;
37 Atom g_bitmapAtom = 0;
38 Atom g_fileAtom = 0;
39
40 //-------------------------------------------------------------------------
41 // wxDataFormat
42 //-------------------------------------------------------------------------
43
44 wxDataFormat::wxDataFormat()
45 {
46 // do *not* call PrepareFormats() from here for 2 reasons:
47 //
48 // 1. we will have time to do it later because some other Set function
49 // must be called before we really need them
50 //
51 // 2. doing so prevents us from declaring global wxDataFormats because
52 // calling PrepareFormats (and thus gdk_atom_intern) before GDK is
53 // initialised will result in a crash
54 m_type = wxDF_INVALID;
55 m_format = (Atom) 0;
56 }
57
58 wxDataFormat::wxDataFormat( wxDataFormatId type )
59 {
60 PrepareFormats();
61 SetType( type );
62 }
63
64 wxDataFormat::wxDataFormat( const wxChar *id )
65 {
66 PrepareFormats();
67 SetId( id );
68 }
69
70 wxDataFormat::wxDataFormat( const wxString &id )
71 {
72 PrepareFormats();
73 SetId( id );
74 }
75
76 wxDataFormat::wxDataFormat( NativeFormat format )
77 {
78 PrepareFormats();
79 SetId( format );
80 }
81
82 void wxDataFormat::SetType( wxDataFormatId type )
83 {
84 PrepareFormats();
85 m_type = type;
86
87 if (m_type == wxDF_TEXT)
88 m_format = g_textAtom;
89 else
90 if (m_type == wxDF_BITMAP)
91 m_format = g_bitmapAtom;
92 else
93 if (m_type == wxDF_FILENAME)
94 m_format = g_fileAtom;
95 else
96 {
97 wxFAIL_MSG( wxT("invalid dataformat") );
98 }
99 }
100
101 wxDataFormatId wxDataFormat::GetType() const
102 {
103 return m_type;
104 }
105
106 wxString wxDataFormat::GetId() const
107 {
108 char *t = XGetAtomName ((Display*) wxGetDisplay(), m_format);
109 wxString ret( t ); // this will convert from ascii to Unicode
110 if (t)
111 XFree( t );
112 return ret;
113 }
114
115 void wxDataFormat::SetId( NativeFormat format )
116 {
117 PrepareFormats();
118 m_format = format;
119
120 if (m_format == g_textAtom)
121 m_type = wxDF_TEXT;
122 else
123 if (m_format == g_bitmapAtom)
124 m_type = wxDF_BITMAP;
125 else
126 if (m_format == g_fileAtom)
127 m_type = wxDF_FILENAME;
128 else
129 m_type = wxDF_PRIVATE;
130 }
131
132 void wxDataFormat::SetId( const wxChar *id )
133 {
134 PrepareFormats();
135 m_type = wxDF_PRIVATE;
136 wxString tmp( id );
137 m_format = XInternAtom( wxGlobalDisplay(),
138 tmp.mbc_str(), FALSE );
139 }
140
141 void wxDataFormat::PrepareFormats()
142 {
143 if (!g_textAtom)
144 g_textAtom = XInternAtom( wxGlobalDisplay(), "STRING", FALSE );
145 if (!g_bitmapAtom)
146 g_bitmapAtom = XInternAtom( wxGlobalDisplay(), "PIXMAP", FALSE );
147 if (!g_fileAtom)
148 g_fileAtom = XInternAtom( wxGlobalDisplay(), "file:ALL", FALSE );
149 }
150
151 // ----------------------------------------------------------------------------
152 // wxDataObject
153 // ----------------------------------------------------------------------------
154
155 wxDataObject::~wxDataObject()
156 {
157 }
158
159 // ----------------------------------------------------------------------------
160 // wxBitmapDataObject
161 // ----------------------------------------------------------------------------
162
163 size_t wxBitmapDataObject::GetDataSize() const
164 {
165 return sizeof(Pixmap);
166 }
167
168 bool wxBitmapDataObject::GetDataHere(void* buf) const
169 {
170 if( !GetBitmap().Ok() )
171 return false;
172
173 (*(Pixmap*)buf) = (Pixmap)GetBitmap().GetDrawable();
174
175 return true;
176 }
177
178 bool wxBitmapDataObject::SetData(size_t len, const void* buf)
179 {
180 if( len != sizeof(Pixmap) )
181 return false;
182
183 WXPixmap pixmap = (WXPixmap)*(Pixmap*)buf;
184
185 m_bitmap.Create( pixmap );
186
187 return true;
188 }
189
190 #endif // wxUSE_CLIPBOARD