]> git.saurik.com Git - wxWidgets.git/blob - src/mac/clipbrd.cpp
bitmap and image updates
[wxWidgets.git] / src / mac / clipbrd.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: clipbrd.cpp
3 // Purpose: Clipboard functionality
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #pragma implementation "clipbrd.h"
15 #endif
16
17 #include "wx/app.h"
18 #include "wx/frame.h"
19 #include "wx/bitmap.h"
20 #include "wx/utils.h"
21 #include "wx/metafile.h"
22 #include "wx/clipbrd.h"
23
24 #include <string.h>
25
26 // open/close
27 bool wxOpenClipboard()
28 {
29 return TRUE;
30 }
31
32 bool wxCloseClipboard()
33 {
34 return TRUE;
35 }
36
37 bool wxIsClipboardOpened()
38 {
39 return TRUE;
40 }
41
42 // get/set data
43
44 bool wxEmptyClipboard()
45 {
46 ZeroScrap() ;
47 return TRUE;
48 }
49
50 bool wxSetClipboardData(wxDataFormat dataFormat,const void *data,int width , int height)
51 {
52 return FALSE;
53 }
54
55 void *wxGetClipboardData(wxDataFormat dataFormat, long *len)
56 {
57 return NULL;
58 }
59
60
61 // clipboard formats
62
63 bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat)
64 {
65 return FALSE;
66 }
67
68 wxDataFormat wxEnumClipboardFormats(wxDataFormat dataFormat)
69 {
70 return wxDataFormat();
71 }
72
73 int wxRegisterClipboardFormat(wxChar *formatName)
74 {
75 return 0;
76 }
77
78 bool wxGetClipboardFormatName(wxDataFormat dataFormat, wxChar *formatName, int maxCount)
79 {
80 return FALSE;
81 }
82
83 /*
84 * Generalized clipboard implementation by Matthew Flatt
85 */
86
87 IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject)
88
89 wxClipboard::wxClipboard()
90 {
91 m_clearOnExit = FALSE;
92 }
93
94 wxClipboard::~wxClipboard()
95 {
96 if ( m_clearOnExit )
97 {
98 Clear();
99 }
100 }
101
102 void wxClipboard::Clear()
103 {
104 }
105
106 bool wxClipboard::Flush()
107 {
108 return FALSE;
109 }
110
111 bool wxClipboard::Open()
112 {
113 return wxOpenClipboard();
114 }
115
116 bool wxClipboard::IsOpened() const
117 {
118 return wxIsClipboardOpened();
119 }
120
121 static int FormatStringToID(char *str)
122 {
123 if (!strcmp(str, "TEXT"))
124 return wxDF_TEXT;
125
126 return wxRegisterClipboardFormat(str);
127 }
128
129 bool wxClipboard::SetData( wxDataObject *data )
130 {
131 (void)wxEmptyClipboard();
132
133 if ( data )
134 return AddData(data);
135 else
136 return TRUE;
137 }
138
139 bool wxClipboard::AddData( wxDataObject *data )
140 {
141 wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
142
143 #if wxUSE_DATAOBJ
144 wxCHECK_MSG( wxIsClipboardOpened(), FALSE, wxT("clipboard not open") );
145
146 wxDataFormat format = data->GetFormat();
147
148 switch ( format )
149 {
150 case wxDF_TEXT:
151 case wxDF_OEMTEXT:
152 {
153 wxTextDataObject* textDataObject = (wxTextDataObject*) data;
154 wxString str(textDataObject->GetText());
155 return wxSetClipboardData(format, str.c_str());
156 }
157
158 case wxDF_BITMAP:
159 case wxDF_DIB:
160 {
161 wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data;
162 wxBitmap bitmap(bitmapDataObject->GetBitmap());
163 return wxSetClipboardData(data->GetFormat(), &bitmap);
164 }
165
166 #if wxUSE_METAFILE
167 case wxDF_METAFILE:
168 {
169 wxMetafileDataObject* metaFileDataObject =
170 (wxMetafileDataObject*) data;
171 wxMetafile metaFile = metaFileDataObject->GetMetafile();
172 return wxSetClipboardData(wxDF_METAFILE, &metaFile,
173 metaFileDataObject->GetWidth(),
174 metaFileDataObject->GetHeight());
175 }
176 #endif // wxUSE_METAFILE
177
178 default:
179 return wxSetClipboardData(data);
180 }
181 #else // !wxUSE_DATAOBJ
182 return FALSE;
183 #endif
184 }
185
186 void wxClipboard::Close()
187 {
188 wxCloseClipboard();
189 }
190
191 bool wxClipboard::IsSupported( wxDataFormat format )
192 {
193 return wxIsClipboardFormatAvailable(format);
194 }
195
196 bool wxClipboard::GetData( wxDataObject& data )
197 {
198 #if wxUSE_DATAOBJ
199 wxCHECK_MSG( wxIsClipboardOpened(), FALSE, wxT("clipboard not open") );
200
201 wxDataFormat format = data.GetFormat();
202 switch ( format )
203 {
204 case wxDF_TEXT:
205 case wxDF_OEMTEXT:
206 {
207 wxTextDataObject& textDataObject = (wxTextDataObject &)data;
208 char* s = (char*)wxGetClipboardData(format);
209 if ( !s )
210 return FALSE;
211
212 textDataObject.SetText(s);
213 delete [] s;
214
215 return TRUE;
216 }
217
218 case wxDF_BITMAP:
219 case wxDF_DIB:
220 {
221 wxBitmapDataObject& bitmapDataObject = (wxBitmapDataObject &)data;
222 wxBitmap* bitmap = (wxBitmap *)wxGetClipboardData(data->GetFormat());
223 if ( !bitmap )
224 return FALSE;
225
226 bitmapDataObject.SetBitmap(*bitmap);
227 delete bitmap;
228
229 return TRUE;
230 }
231 #if wxUSE_METAFILE
232 case wxDF_METAFILE:
233 {
234 wxMetafileDataObject& metaFileDataObject = (wxMetafileDataObject &)data;
235 wxMetafile* metaFile = (wxMetafile *)wxGetClipboardData(wxDF_METAFILE);
236 if ( !metaFile )
237 return FALSE;
238
239 metaFileDataObject.SetMetafile(*metaFile);
240 delete metaFile;
241
242 return TRUE;
243 }
244 #endif // wxUSE_METAFILE
245 }
246 #else // !wxUSE_DATAOBJ
247 wxFAIL_MSG( wxT("no clipboard implementation") );
248 #endif
249 return FALSE;
250 }
251 /*
252 void wxClipboard::SetClipboardClient(wxClipboardClient *client, long time)
253 {
254 bool got_selection;
255
256 if (clipOwner)
257 clipOwner->BeingReplaced();
258 clipOwner = client;
259 if (cbString) {
260 delete[] cbString;
261 cbString = NULL;
262 }
263
264 if (wxOpenClipboard()) {
265 char **formats, *data;
266 int i;
267 int ftype;
268 long size;
269
270 formats = clipOwner->formats.ListToArray(FALSE);
271 for (i = clipOwner->formats.Number(); i--; ) {
272 ftype = FormatStringToID(formats[i]);
273 data = clipOwner->GetData(formats[i], &size);
274 if (!wxSetClipboardData(ftype, (wxObject *)data, size, 1)) {
275 got_selection = FALSE;
276 break;
277 }
278 }
279
280 if (i < 0)
281 got_selection = wxCloseClipboard();
282 } else
283 got_selection = FALSE;
284
285 got_selection = FALSE; // Assume another process takes over
286
287 if (!got_selection) {
288 clipOwner->BeingReplaced();
289 clipOwner = NULL;
290 }
291 }
292
293 wxClipboardClient *wxClipboard::GetClipboardClient()
294 {
295 return clipOwner;
296 }
297
298 void wxClipboard::SetClipboardString(char *str, long time)
299 {
300 bool got_selection;
301
302 if (clipOwner) {
303 clipOwner->BeingReplaced();
304 clipOwner = NULL;
305 }
306 if (cbString)
307 delete[] cbString;
308
309 cbString = str;
310
311 if (wxOpenClipboard()) {
312 if (!wxSetClipboardData(wxDF_TEXT, (wxObject *)str))
313 got_selection = FALSE;
314 else
315 got_selection = wxCloseClipboard();
316 } else
317 got_selection = FALSE;
318
319 got_selection = FALSE; // Assume another process takes over
320
321 if (!got_selection) {
322 delete[] cbString;
323 cbString = NULL;
324 }
325 }
326 char *wxClipboard::GetClipboardString(long time)
327 {
328 char *str;
329 long length;
330
331 str = GetClipboardData("TEXT", &length, time);
332 if (!str) {
333 str = new char[1];
334 *str = 0;
335 }
336
337 return str;
338 }
339
340
341 char *wxClipboard::GetClipboardData(char *format, long *length, long time)
342 {
343 if (clipOwner) {
344 if (clipOwner->formats.Member(format))
345 return clipOwner->GetData(format, length);
346 else
347 return NULL;
348 } else if (cbString) {
349 if (!strcmp(format, "TEXT"))
350 return copystring(cbString);
351 else
352 return NULL;
353 } else {
354 if (wxOpenClipboard()) {
355 receivedString = (char *)wxGetClipboardData(FormatStringToID(format),
356 length);
357 wxCloseClipboard();
358 } else
359 receivedString = NULL;
360
361 return receivedString;
362 }
363 }
364 */
365