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