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