]> git.saurik.com Git - wxWidgets.git/blame - src/motif/dataobj.cpp
[ 1216436 ] cleanup 'shadow variable' warnings from gcc in headers.
[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
65571936 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
1248b41f
MB
14// For compilers that support precompilation, includes "wx.h".
15#include "wx/wxprec.h"
16
dfe1eee3
VZ
17#include "wx/defs.h"
18
19#if wxUSE_CLIPBOARD
20
dc63c944
JS
21#include "wx/dataobj.h"
22#include "wx/app.h"
dd38c875 23#include "wx/utils.h"
dc63c944 24
338dd992
JJ
25#ifdef __VMS__
26#pragma message disable nosimpint
27#endif
da175b2c 28#include <Xm/Xm.h>
338dd992
JJ
29#ifdef __VMS__
30#pragma message enable nosimpint
31#endif
dd38c875
MB
32
33#include "wx/motif/private.h"
da175b2c
RR
34
35//-------------------------------------------------------------------------
36// global data
37//-------------------------------------------------------------------------
38
76db86e7 39Atom g_textAtom = 0;
dd38c875 40Atom g_bitmapAtom = 0;
76db86e7 41Atom g_fileAtom = 0;
da175b2c
RR
42
43//-------------------------------------------------------------------------
44// wxDataFormat
45//-------------------------------------------------------------------------
46
da175b2c
RR
47wxDataFormat::wxDataFormat()
48{
76db86e7
RR
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
da175b2c 57 m_type = wxDF_INVALID;
76db86e7 58 m_format = (Atom) 0;
da175b2c
RR
59}
60
61wxDataFormat::wxDataFormat( wxDataFormatId type )
62{
76db86e7 63 PrepareFormats();
da175b2c
RR
64 SetType( type );
65}
66
67wxDataFormat::wxDataFormat( const wxChar *id )
68{
76db86e7 69 PrepareFormats();
da175b2c
RR
70 SetId( id );
71}
72
73wxDataFormat::wxDataFormat( const wxString &id )
74{
76db86e7 75 PrepareFormats();
da175b2c
RR
76 SetId( id );
77}
78
76db86e7 79wxDataFormat::wxDataFormat( NativeFormat format )
da175b2c 80{
76db86e7
RR
81 PrepareFormats();
82 SetId( format );
da175b2c
RR
83}
84
85void wxDataFormat::SetType( wxDataFormatId type )
86{
76db86e7 87 PrepareFormats();
da175b2c
RR
88 m_type = type;
89
90 if (m_type == wxDF_TEXT)
76db86e7 91 m_format = g_textAtom;
da175b2c
RR
92 else
93 if (m_type == wxDF_BITMAP)
dd38c875 94 m_format = g_bitmapAtom;
da175b2c
RR
95 else
96 if (m_type == wxDF_FILENAME)
76db86e7 97 m_format = g_fileAtom;
da175b2c
RR
98 else
99 {
223d09f6 100 wxFAIL_MSG( wxT("invalid dataformat") );
da175b2c 101 }
76db86e7
RR
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;
da175b2c 122
76db86e7
RR
123 if (m_format == g_textAtom)
124 m_type = wxDF_TEXT;
125 else
dd38c875 126 if (m_format == g_bitmapAtom)
76db86e7
RR
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;
da175b2c
RR
133}
134
da175b2c
RR
135void wxDataFormat::SetId( const wxChar *id )
136{
76db86e7 137 PrepareFormats();
da175b2c 138 m_type = wxDF_PRIVATE;
76db86e7 139 wxString tmp( id );
dd38c875 140 m_format = XInternAtom( wxGlobalDisplay(),
96be256b 141 tmp.mbc_str(), False );
da175b2c
RR
142}
143
76db86e7 144void wxDataFormat::PrepareFormats()
da175b2c 145{
76db86e7 146 if (!g_textAtom)
96be256b 147 g_textAtom = XInternAtom( wxGlobalDisplay(), "STRING", False );
dd38c875 148 if (!g_bitmapAtom)
96be256b 149 g_bitmapAtom = XInternAtom( wxGlobalDisplay(), "PIXMAP", False );
76db86e7 150 if (!g_fileAtom)
96be256b 151 g_fileAtom = XInternAtom( wxGlobalDisplay(), "file:ALL", False );
da175b2c
RR
152}
153
1eaf587e
VZ
154// ----------------------------------------------------------------------------
155// wxDataObject
156// ----------------------------------------------------------------------------
157
158wxDataObject::~wxDataObject()
159{
160}
161
dc63c944 162// ----------------------------------------------------------------------------
dd38c875 163// wxBitmapDataObject
dc63c944
JS
164// ----------------------------------------------------------------------------
165
dd38c875 166size_t wxBitmapDataObject::GetDataSize() const
da175b2c 167{
dd38c875 168 return sizeof(Pixmap);
dc63c944 169}
da175b2c 170
dd38c875 171bool wxBitmapDataObject::GetDataHere(void* buf) const
da175b2c 172{
dd38c875
MB
173 if( !GetBitmap().Ok() )
174 return false;
da175b2c 175
dd38c875 176 (*(Pixmap*)buf) = (Pixmap)GetBitmap().GetDrawable();
da175b2c 177
dd38c875 178 return true;
dc63c944 179}
da175b2c 180
dd38c875 181bool wxBitmapDataObject::SetData(size_t len, const void* buf)
dc63c944 182{
dd38c875
MB
183 if( len != sizeof(Pixmap) )
184 return false;
da175b2c 185
dd38c875 186 WXPixmap pixmap = (WXPixmap)*(Pixmap*)buf;
da175b2c 187
dd38c875 188 m_bitmap.Create( pixmap );
da175b2c 189
dd38c875 190 return true;
dc63c944
JS
191}
192
dfe1eee3 193#endif // wxUSE_CLIPBOARD