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