]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/clipbrd.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Clipboard functionality
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
14 #pragma implementation "clipbrd.h"
19 #include "wx/bitmap.h"
21 #include "wx/metafile.h"
22 #include "wx/clipbrd.h"
26 bool wxOpenClipboard()
31 bool wxCloseClipboard()
36 bool wxEmptyClipboard()
42 bool wxClipboardOpen()
48 bool wxIsClipboardFormatAvailable(int dataFormat
)
54 bool wxSetClipboardData(int dataFormat
, wxObject
*obj
, int width
, int height
)
60 wxObject
*wxGetClipboardData(int dataFormat
, long *len
)
66 int wxEnumClipboardFormats(int dataFormat
)
72 int wxRegisterClipboardFormat(char *formatName
)
78 bool wxGetClipboardFormatName(int dataFormat
, char *formatName
, int maxCount
)
85 * Generalized clipboard implementation by Matthew Flatt
88 wxClipboard::wxClipboard()
90 m_clearOnExit
= FALSE
;
93 wxClipboard::~wxClipboard()
101 void wxClipboard::Clear()
105 bool wxClipboard::Flush()
110 bool wxClipboard::Open()
112 return wxOpenClipboard();
115 bool wxClipboard::IsOpened() const
117 return wxIsClipboardOpened();
120 static int FormatStringToID(char *str
)
122 if (!strcmp(str
, "TEXT"))
125 return wxRegisterClipboardFormat(str
);
128 bool wxClipboard::SetData( wxDataObject
*data
)
130 (void)wxEmptyClipboard();
133 return AddData(data
);
138 bool wxClipboard::AddData( wxDataObject
*data
)
140 wxCHECK_MSG( data
, FALSE
, wxT("data is invalid") );
143 wxCHECK_MSG( wxIsClipboardOpened(), FALSE
, wxT("clipboard not open") );
145 wxDataFormat format
= data
->GetFormat();
152 wxTextDataObject
* textDataObject
= (wxTextDataObject
*) data
;
153 wxString
str(textDataObject
->GetText());
154 return wxSetClipboardData(format
, str
.c_str());
160 wxBitmapDataObject
* bitmapDataObject
= (wxBitmapDataObject
*) data
;
161 wxBitmap
bitmap(bitmapDataObject
->GetBitmap());
162 return wxSetClipboardData(data
->GetFormat(), &bitmap
);
168 wxMetafileDataObject
* metaFileDataObject
=
169 (wxMetafileDataObject
*) data
;
170 wxMetafile metaFile
= metaFileDataObject
->GetMetafile();
171 return wxSetClipboardData(wxDF_METAFILE
, &metaFile
,
172 metaFileDataObject
->GetWidth(),
173 metaFileDataObject
->GetHeight());
175 #endif // wxUSE_METAFILE
178 return wxSetClipboardData(data
);
180 #else // !wxUSE_DATAOBJ
185 void wxClipboard::Close()
190 bool wxClipboard::IsSupported( wxDataFormat format
)
192 return wxIsClipboardFormatAvailable(format
);
195 bool wxClipboard::GetData( wxDataObject
& data
)
198 wxCHECK_MSG( wxIsClipboardOpened(), FALSE
, wxT("clipboard not open") );
200 wxDataFormat format
= data
.GetFormat();
206 wxTextDataObject
& textDataObject
= (wxTextDataObject
&)data
;
207 char* s
= (char*)wxGetClipboardData(format
);
211 textDataObject
.SetText(s
);
220 wxBitmapDataObject
& bitmapDataObject
= (wxBitmapDataObject
&)data
;
221 wxBitmap
* bitmap
= (wxBitmap
*)wxGetClipboardData(data
->GetFormat());
225 bitmapDataObject
.SetBitmap(*bitmap
);
233 wxMetafileDataObject
& metaFileDataObject
= (wxMetafileDataObject
&)data
;
234 wxMetafile
* metaFile
= (wxMetafile
*)wxGetClipboardData(wxDF_METAFILE
);
238 metaFileDataObject
.SetMetafile(*metaFile
);
243 #endif // wxUSE_METAFILE
245 #else // !wxUSE_DATAOBJ
246 wxFAIL_MSG( wxT("no clipboard implementation") );
251 void wxClipboard::SetClipboardClient(wxClipboardClient *client, long time)
256 clipOwner->BeingReplaced();
263 if (wxOpenClipboard()) {
264 char **formats, *data;
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;
280 got_selection = wxCloseClipboard();
282 got_selection = FALSE;
284 got_selection = FALSE; // Assume another process takes over
286 if (!got_selection) {
287 clipOwner->BeingReplaced();
292 wxClipboardClient *wxClipboard::GetClipboardClient()
297 void wxClipboard::SetClipboardString(char *str, long time)
302 clipOwner->BeingReplaced();
310 if (wxOpenClipboard()) {
311 if (!wxSetClipboardData(wxDF_TEXT, (wxObject *)str))
312 got_selection = FALSE;
314 got_selection = wxCloseClipboard();
316 got_selection = FALSE;
318 got_selection = FALSE; // Assume another process takes over
320 if (!got_selection) {
325 char *wxClipboard::GetClipboardString(long time)
330 str = GetClipboardData("TEXT", &length, time);
340 char *wxClipboard::GetClipboardData(char *format, long *length, long time)
343 if (clipOwner->formats.Member(format))
344 return clipOwner->GetData(format, length);
347 } else if (cbString) {
348 if (!strcmp(format, "TEXT"))
349 return copystring(cbString);
353 if (wxOpenClipboard()) {
354 receivedString = (char *)wxGetClipboardData(FormatStringToID(format),
358 receivedString = NULL;
360 return receivedString;