]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/dataobj.cpp
added and documented wxDir::HasFiles/SubDirs(), use the latter in wxDirDialog - it...
[wxWidgets.git] / src / motif / dataobj.cpp
... / ...
CommitLineData
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
34Atom g_textAtom = 0;
35Atom g_pngAtom = 0;
36Atom g_fileAtom = 0;
37
38//-------------------------------------------------------------------------
39// wxDataFormat
40//-------------------------------------------------------------------------
41
42wxDataFormat::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
56wxDataFormat::wxDataFormat( wxDataFormatId type )
57{
58 PrepareFormats();
59 SetType( type );
60}
61
62wxDataFormat::wxDataFormat( const wxChar *id )
63{
64 PrepareFormats();
65 SetId( id );
66}
67
68wxDataFormat::wxDataFormat( const wxString &id )
69{
70 PrepareFormats();
71 SetId( id );
72}
73
74wxDataFormat::wxDataFormat( NativeFormat format )
75{
76 PrepareFormats();
77 SetId( format );
78}
79
80void 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
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;
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
130void 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
138void 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#if 0
149
150// ----------------------------------------------------------------------------
151// wxPrivateDataObject
152// ----------------------------------------------------------------------------
153
154IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
155
156void wxPrivateDataObject::Free()
157{
158 if ( m_data )
159 free(m_data);
160}
161
162wxPrivateDataObject::wxPrivateDataObject()
163{
164 wxString id = wxT("application/");
165 id += wxTheApp->GetAppName();
166
167 m_format.SetId( id );
168
169 m_size = 0;
170 m_data = (void *)NULL;
171}
172
173void wxPrivateDataObject::SetData( const void *data, size_t size )
174{
175 Free();
176
177 m_size = size;
178 m_data = malloc(size);
179
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() );
196}
197
198#endif // 0
199
200#endif // wxUSE_CLIPBOARD