]> git.saurik.com Git - wxWidgets.git/blame - src/mac/clipbrd.cpp
mingw32 compilation fixes
[wxWidgets.git] / src / mac / clipbrd.cpp
CommitLineData
e9576ca5
SC
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
7c74e7fe 26// open/close
e9576ca5
SC
27bool wxOpenClipboard()
28{
519cb848 29 return TRUE;
e9576ca5
SC
30}
31
32bool wxCloseClipboard()
33{
7c74e7fe 34 return TRUE;
e9576ca5
SC
35}
36
7c74e7fe 37bool wxIsClipboardOpened()
e9576ca5 38{
7c74e7fe 39 return TRUE;
e9576ca5
SC
40}
41
7c74e7fe
SC
42// get/set data
43
44bool wxEmptyClipboard()
e9576ca5 45{
7c74e7fe
SC
46 ZeroScrap() ;
47 return TRUE;
e9576ca5
SC
48}
49
7c74e7fe 50bool wxSetClipboardData(wxDataFormat dataFormat,const void *data,int width , int height)
e9576ca5 51{
e9576ca5
SC
52 return FALSE;
53}
54
7c74e7fe 55void *wxGetClipboardData(wxDataFormat dataFormat, long *len)
e9576ca5 56{
7c74e7fe 57 return NULL;
e9576ca5
SC
58}
59
7c74e7fe
SC
60
61// clipboard formats
62
63bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat)
e9576ca5 64{
7c74e7fe 65 return FALSE;
e9576ca5
SC
66}
67
7c74e7fe 68wxDataFormat wxEnumClipboardFormats(wxDataFormat dataFormat)
e9576ca5 69{
7c74e7fe 70 return wxDataFormat();
e9576ca5
SC
71}
72
7c74e7fe 73int wxRegisterClipboardFormat(wxChar *formatName)
e9576ca5 74{
e9576ca5
SC
75 return 0;
76}
77
7c74e7fe 78bool wxGetClipboardFormatName(wxDataFormat dataFormat, wxChar *formatName, int maxCount)
e9576ca5 79{
e9576ca5
SC
80 return FALSE;
81}
82
83/*
84 * Generalized clipboard implementation by Matthew Flatt
85 */
86
7c74e7fe
SC
87IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject)
88
e7549107
SC
89wxClipboard::wxClipboard()
90{
91 m_clearOnExit = FALSE;
92}
e9576ca5 93
e7549107 94wxClipboard::~wxClipboard()
e9576ca5 95{
e7549107
SC
96 if ( m_clearOnExit )
97 {
98 Clear();
99 }
e9576ca5
SC
100}
101
e7549107 102void wxClipboard::Clear()
e9576ca5 103{
e9576ca5
SC
104}
105
e7549107 106bool wxClipboard::Flush()
e9576ca5 107{
e7549107
SC
108 return FALSE;
109}
110
111bool wxClipboard::Open()
112{
113 return wxOpenClipboard();
114}
115
116bool wxClipboard::IsOpened() const
117{
118 return wxIsClipboardOpened();
e9576ca5
SC
119}
120
121static int FormatStringToID(char *str)
122{
123 if (!strcmp(str, "TEXT"))
124 return wxDF_TEXT;
125
126 return wxRegisterClipboardFormat(str);
127}
128
e7549107
SC
129bool wxClipboard::SetData( wxDataObject *data )
130{
131 (void)wxEmptyClipboard();
132
133 if ( data )
134 return AddData(data);
135 else
136 return TRUE;
137}
138
139bool 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
186void wxClipboard::Close()
187{
188 wxCloseClipboard();
189}
190
191bool wxClipboard::IsSupported( wxDataFormat format )
192{
193 return wxIsClipboardFormatAvailable(format);
194}
195
196bool 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/*
e9576ca5
SC
252void 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
293wxClipboardClient *wxClipboard::GetClipboardClient()
294{
295 return clipOwner;
296}
297
298void wxClipboard::SetClipboardString(char *str, long time)
e7549107 299{
e9576ca5
SC
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}
e9576ca5
SC
326char *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
e7549107 340
e9576ca5
SC
341char *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}
e7549107 364*/
e9576ca5 365