]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dataobj.cpp
Revised #ifndef WX_PRECOMP headers, added missing #include wx/wxcrtvararg.h
[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 #include "wx/utils.h"
20 #endif
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 wxString &id )
65 {
66 PrepareFormats();
67 SetId( id );
68 }
69
70 wxDataFormat::wxDataFormat( NativeFormat format )
71 {
72 PrepareFormats();
73 SetId( format );
74 }
75
76 void wxDataFormat::SetType( wxDataFormatId type )
77 {
78 PrepareFormats();
79 m_type = type;
80
81 if (m_type == wxDF_TEXT)
82 m_format = g_textAtom;
83 else
84 if (m_type == wxDF_BITMAP)
85 m_format = g_bitmapAtom;
86 else
87 if (m_type == wxDF_FILENAME)
88 m_format = g_fileAtom;
89 else
90 {
91 wxFAIL_MSG( wxT("invalid dataformat") );
92 }
93 }
94
95 wxDataFormatId wxDataFormat::GetType() const
96 {
97 return m_type;
98 }
99
100 wxString wxDataFormat::GetId() const
101 {
102 char *t = XGetAtomName ((Display*) wxGetDisplay(), m_format);
103 wxString ret( t ); // this will convert from ascii to Unicode
104 if (t)
105 XFree( t );
106 return ret;
107 }
108
109 void wxDataFormat::SetId( NativeFormat format )
110 {
111 PrepareFormats();
112 m_format = format;
113
114 if (m_format == g_textAtom)
115 m_type = wxDF_TEXT;
116 else
117 if (m_format == g_bitmapAtom)
118 m_type = wxDF_BITMAP;
119 else
120 if (m_format == g_fileAtom)
121 m_type = wxDF_FILENAME;
122 else
123 m_type = wxDF_PRIVATE;
124 }
125
126 void wxDataFormat::SetId( const wxString& id )
127 {
128 PrepareFormats();
129 m_type = wxDF_PRIVATE;
130 m_format = XInternAtom( wxGlobalDisplay(),
131 id.mbc_str(), False );
132 }
133
134 void wxDataFormat::PrepareFormats()
135 {
136 if (!g_textAtom)
137 g_textAtom = XInternAtom( wxGlobalDisplay(), "STRING", False );
138 if (!g_bitmapAtom)
139 g_bitmapAtom = XInternAtom( wxGlobalDisplay(), "PIXMAP", False );
140 if (!g_fileAtom)
141 g_fileAtom = XInternAtom( wxGlobalDisplay(), "file:ALL", False );
142 }
143
144 // ----------------------------------------------------------------------------
145 // wxDataObject
146 // ----------------------------------------------------------------------------
147
148 wxDataObject::~wxDataObject()
149 {
150 }
151
152 // ----------------------------------------------------------------------------
153 // wxBitmapDataObject
154 // ----------------------------------------------------------------------------
155
156 size_t wxBitmapDataObject::GetDataSize() const
157 {
158 return sizeof(Pixmap);
159 }
160
161 bool wxBitmapDataObject::GetDataHere(void* buf) const
162 {
163 if( !GetBitmap().Ok() )
164 return false;
165
166 (*(Pixmap*)buf) = (Pixmap)GetBitmap().GetDrawable();
167
168 return true;
169 }
170
171 bool wxBitmapDataObject::SetData(size_t len, const void* buf)
172 {
173 if( len != sizeof(Pixmap) )
174 return false;
175
176 WXPixmap pixmap = (WXPixmap)*(Pixmap*)buf;
177
178 m_bitmap.Create( pixmap );
179
180 return true;
181 }
182
183 #endif // wxUSE_CLIPBOARD