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