]> git.saurik.com Git - wxWidgets.git/blame - src/motif/dataobj.cpp
more combobox appearance fixes
[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
10#ifdef __GNUG__
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"
20
338dd992
JJ
21#ifdef __VMS__
22#pragma message disable nosimpint
23#endif
da175b2c 24#include <Xm/Xm.h>
338dd992
JJ
25#ifdef __VMS__
26#pragma message enable nosimpint
27#endif
da175b2c
RR
28#include "wx/utils.h"
29
30//-------------------------------------------------------------------------
31// global data
32//-------------------------------------------------------------------------
33
76db86e7
RR
34Atom g_textAtom = 0;
35Atom g_pngAtom = 0;
36Atom g_fileAtom = 0;
da175b2c
RR
37
38//-------------------------------------------------------------------------
39// wxDataFormat
40//-------------------------------------------------------------------------
41
da175b2c
RR
42wxDataFormat::wxDataFormat()
43{
76db86e7
RR
44 // do *not* call PrepareFormats() from here for 2 reasons:
45 //
46 // 1. we will have time to do it later because some other Set function
47 // must be called before we really need them
48 //
49 // 2. doing so prevents us from declaring global wxDataFormats because
50 // calling PrepareFormats (and thus gdk_atom_intern) before GDK is
51 // initialised will result in a crash
da175b2c 52 m_type = wxDF_INVALID;
76db86e7 53 m_format = (Atom) 0;
da175b2c
RR
54}
55
56wxDataFormat::wxDataFormat( wxDataFormatId type )
57{
76db86e7 58 PrepareFormats();
da175b2c
RR
59 SetType( type );
60}
61
62wxDataFormat::wxDataFormat( const wxChar *id )
63{
76db86e7 64 PrepareFormats();
da175b2c
RR
65 SetId( id );
66}
67
68wxDataFormat::wxDataFormat( const wxString &id )
69{
76db86e7 70 PrepareFormats();
da175b2c
RR
71 SetId( id );
72}
73
76db86e7 74wxDataFormat::wxDataFormat( NativeFormat format )
da175b2c 75{
76db86e7
RR
76 PrepareFormats();
77 SetId( format );
da175b2c
RR
78}
79
80void wxDataFormat::SetType( wxDataFormatId type )
81{
76db86e7 82 PrepareFormats();
da175b2c
RR
83 m_type = type;
84
85 if (m_type == wxDF_TEXT)
76db86e7 86 m_format = g_textAtom;
da175b2c
RR
87 else
88 if (m_type == wxDF_BITMAP)
76db86e7 89 m_format = g_pngAtom;
da175b2c
RR
90 else
91 if (m_type == wxDF_FILENAME)
76db86e7 92 m_format = g_fileAtom;
da175b2c
RR
93 else
94 {
223d09f6 95 wxFAIL_MSG( wxT("invalid dataformat") );
da175b2c 96 }
76db86e7
RR
97}
98
99wxDataFormatId wxDataFormat::GetType() const
100{
101 return m_type;
102}
103
104wxString wxDataFormat::GetId() const
105{
106 char *t = XGetAtomName ((Display*) wxGetDisplay(), m_format);
107 wxString ret( t ); // this will convert from ascii to Unicode
108 if (t)
109 XFree( t );
110 return ret;
111}
112
113void wxDataFormat::SetId( NativeFormat format )
114{
115 PrepareFormats();
116 m_format = format;
da175b2c 117
76db86e7
RR
118 if (m_format == g_textAtom)
119 m_type = wxDF_TEXT;
120 else
121 if (m_format == g_pngAtom)
122 m_type = wxDF_BITMAP;
123 else
124 if (m_format == g_fileAtom)
125 m_type = wxDF_FILENAME;
126 else
127 m_type = wxDF_PRIVATE;
da175b2c
RR
128}
129
da175b2c
RR
130void wxDataFormat::SetId( const wxChar *id )
131{
76db86e7 132 PrepareFormats();
da175b2c 133 m_type = wxDF_PRIVATE;
76db86e7
RR
134 wxString tmp( id );
135 m_format = XInternAtom( (Display*) wxGetDisplay(), wxMBSTRINGCAST tmp.mbc_str(), FALSE ); // what is the string cast for?
da175b2c
RR
136}
137
76db86e7 138void wxDataFormat::PrepareFormats()
da175b2c 139{
76db86e7
RR
140 if (!g_textAtom)
141 g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
142 if (!g_pngAtom)
143 g_pngAtom = XInternAtom( (Display*) wxGetDisplay(), "image/png", FALSE );
144 if (!g_fileAtom)
145 g_fileAtom = XInternAtom( (Display*) wxGetDisplay(), "file:ALL", FALSE );
da175b2c
RR
146}
147
12db77ca 148#if 0
dc63c944
JS
149
150// ----------------------------------------------------------------------------
151// wxPrivateDataObject
152// ----------------------------------------------------------------------------
153
154IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
155
da175b2c
RR
156void wxPrivateDataObject::Free()
157{
158 if ( m_data )
159 free(m_data);
dc63c944 160}
da175b2c
RR
161
162wxPrivateDataObject::wxPrivateDataObject()
163{
223d09f6 164 wxString id = wxT("application/");
da175b2c
RR
165 id += wxTheApp->GetAppName();
166
167 m_format.SetId( id );
168
169 m_size = 0;
170 m_data = (void *)NULL;
dc63c944 171}
da175b2c
RR
172
173void wxPrivateDataObject::SetData( const void *data, size_t size )
dc63c944 174{
da175b2c
RR
175 Free();
176
dc63c944 177 m_size = size;
da175b2c 178 m_data = malloc(size);
dc63c944 179
da175b2c
RR
180 memcpy( m_data, data, size );
181}
182
183void wxPrivateDataObject::WriteData( void *dest ) const
184{
185 WriteData( m_data, dest );
186}
187
188size_t wxPrivateDataObject::GetSize() const
189{
190 return m_size;
191}
192
193void wxPrivateDataObject::WriteData( const void *data, void *dest ) const
194{
195 memcpy( dest, data, GetSize() );
dc63c944
JS
196}
197
12db77ca
VZ
198#endif // 0
199
dfe1eee3 200#endif // wxUSE_CLIPBOARD