]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dataobj.cpp
Applied patch [ 654023 ] Enables HtmlHelp (native)
[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 #ifdef __VMS__
22 #pragma message disable nosimpint
23 #endif
24 #include <Xm/Xm.h>
25 #ifdef __VMS__
26 #pragma message enable nosimpint
27 #endif
28 #include "wx/utils.h"
29
30 //-------------------------------------------------------------------------
31 // global data
32 //-------------------------------------------------------------------------
33
34 Atom g_textAtom = 0;
35 Atom g_pngAtom = 0;
36 Atom g_fileAtom = 0;
37
38 //-------------------------------------------------------------------------
39 // wxDataFormat
40 //-------------------------------------------------------------------------
41
42 wxDataFormat::wxDataFormat()
43 {
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
52 m_type = wxDF_INVALID;
53 m_format = (Atom) 0;
54 }
55
56 wxDataFormat::wxDataFormat( wxDataFormatId type )
57 {
58 PrepareFormats();
59 SetType( type );
60 }
61
62 wxDataFormat::wxDataFormat( const wxChar *id )
63 {
64 PrepareFormats();
65 SetId( id );
66 }
67
68 wxDataFormat::wxDataFormat( const wxString &id )
69 {
70 PrepareFormats();
71 SetId( id );
72 }
73
74 wxDataFormat::wxDataFormat( NativeFormat format )
75 {
76 PrepareFormats();
77 SetId( format );
78 }
79
80 void wxDataFormat::SetType( wxDataFormatId type )
81 {
82 PrepareFormats();
83 m_type = type;
84
85 if (m_type == wxDF_TEXT)
86 m_format = g_textAtom;
87 else
88 if (m_type == wxDF_BITMAP)
89 m_format = g_pngAtom;
90 else
91 if (m_type == wxDF_FILENAME)
92 m_format = g_fileAtom;
93 else
94 {
95 wxFAIL_MSG( wxT("invalid dataformat") );
96 }
97 }
98
99 wxDataFormatId wxDataFormat::GetType() const
100 {
101 return m_type;
102 }
103
104 wxString 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
113 void wxDataFormat::SetId( NativeFormat format )
114 {
115 PrepareFormats();
116 m_format = format;
117
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;
128 }
129
130 void wxDataFormat::SetId( const wxChar *id )
131 {
132 PrepareFormats();
133 m_type = wxDF_PRIVATE;
134 wxString tmp( id );
135 m_format = XInternAtom( (Display*) wxGetDisplay(), wxMBSTRINGCAST tmp.mbc_str(), FALSE ); // what is the string cast for?
136 }
137
138 void wxDataFormat::PrepareFormats()
139 {
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 );
146 }
147
148 // ----------------------------------------------------------------------------
149 // wxDataObject
150 // ----------------------------------------------------------------------------
151
152 wxDataObject::~wxDataObject()
153 {
154 }
155
156 #if 0
157
158 // ----------------------------------------------------------------------------
159 // wxPrivateDataObject
160 // ----------------------------------------------------------------------------
161
162 IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
163
164 void wxPrivateDataObject::Free()
165 {
166 if ( m_data )
167 free(m_data);
168 }
169
170 wxPrivateDataObject::wxPrivateDataObject()
171 {
172 wxString id = wxT("application/");
173 id += wxTheApp->GetAppName();
174
175 m_format.SetId( id );
176
177 m_size = 0;
178 m_data = (void *)NULL;
179 }
180
181 void wxPrivateDataObject::SetData( const void *data, size_t size )
182 {
183 Free();
184
185 m_size = size;
186 m_data = malloc(size);
187
188 memcpy( m_data, data, size );
189 }
190
191 void wxPrivateDataObject::WriteData( void *dest ) const
192 {
193 WriteData( m_data, dest );
194 }
195
196 size_t wxPrivateDataObject::GetSize() const
197 {
198 return m_size;
199 }
200
201 void wxPrivateDataObject::WriteData( const void *data, void *dest ) const
202 {
203 memcpy( dest, data, GetSize() );
204 }
205
206 #endif // 0
207
208 #endif // wxUSE_CLIPBOARD