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