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