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