]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/dataobj.cpp
applying OSAF patch for "toolbar selection not correct on Mac after calling Realize...
[wxWidgets.git] / src / motif / dataobj.cpp
... / ...
CommitLineData
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
39Atom g_textAtom = 0;
40Atom g_bitmapAtom = 0;
41Atom g_fileAtom = 0;
42
43//-------------------------------------------------------------------------
44// wxDataFormat
45//-------------------------------------------------------------------------
46
47wxDataFormat::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
61wxDataFormat::wxDataFormat( wxDataFormatId type )
62{
63 PrepareFormats();
64 SetType( type );
65}
66
67wxDataFormat::wxDataFormat( const wxChar *id )
68{
69 PrepareFormats();
70 SetId( id );
71}
72
73wxDataFormat::wxDataFormat( const wxString &id )
74{
75 PrepareFormats();
76 SetId( id );
77}
78
79wxDataFormat::wxDataFormat( NativeFormat format )
80{
81 PrepareFormats();
82 SetId( format );
83}
84
85void 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
104wxDataFormatId wxDataFormat::GetType() const
105{
106 return m_type;
107}
108
109wxString 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
118void 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
135void 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
144void 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
158wxDataObject::~wxDataObject()
159{
160}
161
162// ----------------------------------------------------------------------------
163// wxBitmapDataObject
164// ----------------------------------------------------------------------------
165
166size_t wxBitmapDataObject::GetDataSize() const
167{
168 return sizeof(Pixmap);
169}
170
171bool 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
181bool 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