]> git.saurik.com Git - wxWidgets.git/blame - src/motif/dataobj.cpp
added AppleEvent Handler, somehow the standard event handler does not take care of...
[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
1eaf587e
VZ
148// ----------------------------------------------------------------------------
149// wxDataObject
150// ----------------------------------------------------------------------------
151
152wxDataObject::~wxDataObject()
153{
154}
155
12db77ca 156#if 0
dc63c944
JS
157
158// ----------------------------------------------------------------------------
159// wxPrivateDataObject
160// ----------------------------------------------------------------------------
161
162IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
163
da175b2c
RR
164void wxPrivateDataObject::Free()
165{
166 if ( m_data )
167 free(m_data);
dc63c944 168}
da175b2c
RR
169
170wxPrivateDataObject::wxPrivateDataObject()
171{
223d09f6 172 wxString id = wxT("application/");
da175b2c
RR
173 id += wxTheApp->GetAppName();
174
175 m_format.SetId( id );
176
177 m_size = 0;
178 m_data = (void *)NULL;
dc63c944 179}
da175b2c
RR
180
181void wxPrivateDataObject::SetData( const void *data, size_t size )
dc63c944 182{
da175b2c
RR
183 Free();
184
dc63c944 185 m_size = size;
da175b2c 186 m_data = malloc(size);
dc63c944 187
da175b2c
RR
188 memcpy( m_data, data, size );
189}
190
191void wxPrivateDataObject::WriteData( void *dest ) const
192{
193 WriteData( m_data, dest );
194}
195
196size_t wxPrivateDataObject::GetSize() const
197{
198 return m_size;
199}
200
201void wxPrivateDataObject::WriteData( const void *data, void *dest ) const
202{
203 memcpy( dest, data, GetSize() );
dc63c944
JS
204}
205
12db77ca
VZ
206#endif // 0
207
dfe1eee3 208#endif // wxUSE_CLIPBOARD