]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dataobj.cpp
VTK wrapper of vtkRenderWindow for wxPython. Tested on MSW so far.
[wxWidgets.git] / src / motif / dataobj.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: dataobj.cpp
3 // Purpose: wxDataObject class
4 // Author: Julian Smart
5 // Id: $Id$
6 // Copyright: (c) 1998 Julian Smart
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation "dataobj.h"
12 #endif
13
14 #include "wx/defs.h"
15
16 #if wxUSE_CLIPBOARD
17
18 #include "wx/dataobj.h"
19 #include "wx/app.h"
20
21 #include <Xm/Xm.h>
22 #include "wx/utils.h"
23
24 //-------------------------------------------------------------------------
25 // global data
26 //-------------------------------------------------------------------------
27
28 Atom g_textAtom = 0;
29 Atom g_pngAtom = 0;
30 Atom g_fileAtom = 0;
31
32 //-------------------------------------------------------------------------
33 // wxDataFormat
34 //-------------------------------------------------------------------------
35
36 wxDataFormat::wxDataFormat()
37 {
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
46 m_type = wxDF_INVALID;
47 m_format = (Atom) 0;
48 }
49
50 wxDataFormat::wxDataFormat( wxDataFormatId type )
51 {
52 PrepareFormats();
53 SetType( type );
54 }
55
56 wxDataFormat::wxDataFormat( const wxChar *id )
57 {
58 PrepareFormats();
59 SetId( id );
60 }
61
62 wxDataFormat::wxDataFormat( const wxString &id )
63 {
64 PrepareFormats();
65 SetId( id );
66 }
67
68 wxDataFormat::wxDataFormat( NativeFormat format )
69 {
70 PrepareFormats();
71 SetId( format );
72 }
73
74 void wxDataFormat::SetType( wxDataFormatId type )
75 {
76 PrepareFormats();
77 m_type = type;
78
79 if (m_type == wxDF_TEXT)
80 m_format = g_textAtom;
81 else
82 if (m_type == wxDF_BITMAP)
83 m_format = g_pngAtom;
84 else
85 if (m_type == wxDF_FILENAME)
86 m_format = g_fileAtom;
87 else
88 {
89 wxFAIL_MSG( wxT("invalid dataformat") );
90 }
91 }
92
93 wxDataFormatId wxDataFormat::GetType() const
94 {
95 return m_type;
96 }
97
98 wxString 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
107 void wxDataFormat::SetId( NativeFormat format )
108 {
109 PrepareFormats();
110 m_format = format;
111
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;
122 }
123
124 void wxDataFormat::SetId( const wxChar *id )
125 {
126 PrepareFormats();
127 m_type = wxDF_PRIVATE;
128 wxString tmp( id );
129 m_format = XInternAtom( (Display*) wxGetDisplay(), wxMBSTRINGCAST tmp.mbc_str(), FALSE ); // what is the string cast for?
130 }
131
132 void wxDataFormat::PrepareFormats()
133 {
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 );
140 }
141
142 #if 0
143
144 // ----------------------------------------------------------------------------
145 // wxPrivateDataObject
146 // ----------------------------------------------------------------------------
147
148 IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
149
150 void wxPrivateDataObject::Free()
151 {
152 if ( m_data )
153 free(m_data);
154 }
155
156 wxPrivateDataObject::wxPrivateDataObject()
157 {
158 wxString id = wxT("application/");
159 id += wxTheApp->GetAppName();
160
161 m_format.SetId( id );
162
163 m_size = 0;
164 m_data = (void *)NULL;
165 }
166
167 void wxPrivateDataObject::SetData( const void *data, size_t size )
168 {
169 Free();
170
171 m_size = size;
172 m_data = malloc(size);
173
174 memcpy( m_data, data, size );
175 }
176
177 void wxPrivateDataObject::WriteData( void *dest ) const
178 {
179 WriteData( m_data, dest );
180 }
181
182 size_t wxPrivateDataObject::GetSize() const
183 {
184 return m_size;
185 }
186
187 void wxPrivateDataObject::WriteData( const void *data, void *dest ) const
188 {
189 memcpy( dest, data, GetSize() );
190 }
191
192 #endif // 0
193
194 #endif // wxUSE_CLIPBOARD