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