]> git.saurik.com Git - wxWidgets.git/blame - src/motif/dataobj.cpp
Added wxToggleBitmapButton (it compiles).
[wxWidgets.git] / src / motif / dataobj.cpp
CommitLineData
dc63c944
JS
1///////////////////////////////////////////////////////////////////////////////
2// Name: dataobj.cpp
3// Purpose: wxDataObject class
4// Author: Julian Smart
5// Id: $Id$
6// Copyright: (c) 1998 Julian Smart
dfe1eee3 7// Licence: wxWindows licence
dc63c944
JS
8///////////////////////////////////////////////////////////////////////////////
9
14f355c2 10#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
dc63c944
JS
11#pragma implementation "dataobj.h"
12#endif
13
dfe1eee3
VZ
14#include "wx/defs.h"
15
16#if wxUSE_CLIPBOARD
17
dc63c944
JS
18#include "wx/dataobj.h"
19#include "wx/app.h"
dd38c875 20#include "wx/utils.h"
dc63c944 21
338dd992
JJ
22#ifdef __VMS__
23#pragma message disable nosimpint
24#endif
da175b2c 25#include <Xm/Xm.h>
338dd992
JJ
26#ifdef __VMS__
27#pragma message enable nosimpint
28#endif
dd38c875
MB
29
30#include "wx/motif/private.h"
da175b2c
RR
31
32//-------------------------------------------------------------------------
33// global data
34//-------------------------------------------------------------------------
35
76db86e7 36Atom g_textAtom = 0;
dd38c875 37Atom g_bitmapAtom = 0;
76db86e7 38Atom g_fileAtom = 0;
da175b2c
RR
39
40//-------------------------------------------------------------------------
41// wxDataFormat
42//-------------------------------------------------------------------------
43
da175b2c
RR
44wxDataFormat::wxDataFormat()
45{
76db86e7
RR
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
da175b2c 54 m_type = wxDF_INVALID;
76db86e7 55 m_format = (Atom) 0;
da175b2c
RR
56}
57
58wxDataFormat::wxDataFormat( wxDataFormatId type )
59{
76db86e7 60 PrepareFormats();
da175b2c
RR
61 SetType( type );
62}
63
64wxDataFormat::wxDataFormat( const wxChar *id )
65{
76db86e7 66 PrepareFormats();
da175b2c
RR
67 SetId( id );
68}
69
70wxDataFormat::wxDataFormat( const wxString &id )
71{
76db86e7 72 PrepareFormats();
da175b2c
RR
73 SetId( id );
74}
75
76db86e7 76wxDataFormat::wxDataFormat( NativeFormat format )
da175b2c 77{
76db86e7
RR
78 PrepareFormats();
79 SetId( format );
da175b2c
RR
80}
81
82void wxDataFormat::SetType( wxDataFormatId type )
83{
76db86e7 84 PrepareFormats();
da175b2c
RR
85 m_type = type;
86
87 if (m_type == wxDF_TEXT)
76db86e7 88 m_format = g_textAtom;
da175b2c
RR
89 else
90 if (m_type == wxDF_BITMAP)
dd38c875 91 m_format = g_bitmapAtom;
da175b2c
RR
92 else
93 if (m_type == wxDF_FILENAME)
76db86e7 94 m_format = g_fileAtom;
da175b2c
RR
95 else
96 {
223d09f6 97 wxFAIL_MSG( wxT("invalid dataformat") );
da175b2c 98 }
76db86e7
RR
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;
da175b2c 119
76db86e7
RR
120 if (m_format == g_textAtom)
121 m_type = wxDF_TEXT;
122 else
dd38c875 123 if (m_format == g_bitmapAtom)
76db86e7
RR
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;
da175b2c
RR
130}
131
da175b2c
RR
132void wxDataFormat::SetId( const wxChar *id )
133{
76db86e7 134 PrepareFormats();
da175b2c 135 m_type = wxDF_PRIVATE;
76db86e7 136 wxString tmp( id );
dd38c875
MB
137 m_format = XInternAtom( wxGlobalDisplay(),
138 tmp.mbc_str(), FALSE );
da175b2c
RR
139}
140
76db86e7 141void wxDataFormat::PrepareFormats()
da175b2c 142{
76db86e7 143 if (!g_textAtom)
dd38c875
MB
144 g_textAtom = XInternAtom( wxGlobalDisplay(), "STRING", FALSE );
145 if (!g_bitmapAtom)
146 g_bitmapAtom = XInternAtom( wxGlobalDisplay(), "PIXMAP", FALSE );
76db86e7 147 if (!g_fileAtom)
dd38c875 148 g_fileAtom = XInternAtom( wxGlobalDisplay(), "file:ALL", FALSE );
da175b2c
RR
149}
150
1eaf587e
VZ
151// ----------------------------------------------------------------------------
152// wxDataObject
153// ----------------------------------------------------------------------------
154
155wxDataObject::~wxDataObject()
156{
157}
158
dc63c944 159// ----------------------------------------------------------------------------
dd38c875 160// wxBitmapDataObject
dc63c944
JS
161// ----------------------------------------------------------------------------
162
dd38c875 163size_t wxBitmapDataObject::GetDataSize() const
da175b2c 164{
dd38c875 165 return sizeof(Pixmap);
dc63c944 166}
da175b2c 167
dd38c875 168bool wxBitmapDataObject::GetDataHere(void* buf) const
da175b2c 169{
dd38c875
MB
170 if( !GetBitmap().Ok() )
171 return false;
da175b2c 172
dd38c875 173 (*(Pixmap*)buf) = (Pixmap)GetBitmap().GetDrawable();
da175b2c 174
dd38c875 175 return true;
dc63c944 176}
da175b2c 177
dd38c875 178bool wxBitmapDataObject::SetData(size_t len, const void* buf)
dc63c944 179{
dd38c875
MB
180 if( len != sizeof(Pixmap) )
181 return false;
da175b2c 182
dd38c875 183 WXPixmap pixmap = (WXPixmap)*(Pixmap*)buf;
da175b2c 184
dd38c875 185 m_bitmap.Create( pixmap );
da175b2c 186
dd38c875 187 return true;
dc63c944
JS
188}
189
dfe1eee3 190#endif // wxUSE_CLIPBOARD