]>
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"
27 bool wxOpenClipboard()
32 bool wxCloseClipboard()
37 bool wxIsClipboardOpened()
44 bool wxEmptyClipboard()
50 bool wxSetClipboardData(wxDataFormat dataFormat
,const void *data
,int width
, int height
)
55 void *wxGetClipboardData(wxDataFormat dataFormat
, long *len
)
63 bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat
)
68 wxDataFormat
wxEnumClipboardFormats(wxDataFormat dataFormat
)
70 return wxDataFormat();
73 int wxRegisterClipboardFormat(wxChar
*formatName
)
78 bool wxGetClipboardFormatName(wxDataFormat dataFormat
, wxChar
*formatName
, int maxCount
)
84 * Generalized clipboard implementation by Matthew Flatt
87 IMPLEMENT_DYNAMIC_CLASS(wxClipboard
, wxObject
)
89 wxClipboard::wxClipboard()
91 m_clearOnExit
= FALSE
;
94 wxClipboard::~wxClipboard()
102 void wxClipboard::Clear()
106 bool wxClipboard::Flush()
111 bool wxClipboard::Open()
113 return wxOpenClipboard();
116 bool wxClipboard::IsOpened() const
118 return wxIsClipboardOpened();
121 static int FormatStringToID(char *str
)
123 if (!strcmp(str
, "TEXT"))
126 return wxRegisterClipboardFormat(str
);
129 bool wxClipboard::SetData( wxDataObject
*data
)
131 (void)wxEmptyClipboard();
134 return AddData(data
);
139 bool wxClipboard::AddData( wxDataObject
*data
)
141 wxCHECK_MSG( data
, FALSE
, wxT("data is invalid") );
144 wxCHECK_MSG( wxIsClipboardOpened(), FALSE
, wxT("clipboard not open") );
146 wxDataFormat format
= data
->GetFormat();
153 wxTextDataObject
* textDataObject
= (wxTextDataObject
*) data
;
154 wxString
str(textDataObject
->GetText());
155 return wxSetClipboardData(format
, str
.c_str());
161 wxBitmapDataObject
* bitmapDataObject
= (wxBitmapDataObject
*) data
;
162 wxBitmap
bitmap(bitmapDataObject
->GetBitmap());
163 return wxSetClipboardData(data
->GetFormat(), &bitmap
);
169 wxMetafileDataObject
* metaFileDataObject
=
170 (wxMetafileDataObject
*) data
;
171 wxMetafile metaFile
= metaFileDataObject
->GetMetafile();
172 return wxSetClipboardData(wxDF_METAFILE
, &metaFile
,
173 metaFileDataObject
->GetWidth(),
174 metaFileDataObject
->GetHeight());
176 #endif // wxUSE_METAFILE
179 return wxSetClipboardData(data
);
181 #else // !wxUSE_DATAOBJ
186 void wxClipboard::Close()
191 bool wxClipboard::IsSupported( wxDataFormat format
)
193 return wxIsClipboardFormatAvailable(format
);
196 bool wxClipboard::GetData( wxDataObject
& data
)
199 wxCHECK_MSG( wxIsClipboardOpened(), FALSE
, wxT("clipboard not open") );
201 wxDataFormat format
= data
.GetFormat();
207 wxTextDataObject
& textDataObject
= (wxTextDataObject
&)data
;
208 char* s
= (char*)wxGetClipboardData(format
);
212 textDataObject
.SetText(s
);
221 wxBitmapDataObject
& bitmapDataObject
= (wxBitmapDataObject
&)data
;
222 wxBitmap
* bitmap
= (wxBitmap
*)wxGetClipboardData(data
->GetFormat());
226 bitmapDataObject
.SetBitmap(*bitmap
);
234 wxMetafileDataObject
& metaFileDataObject
= (wxMetafileDataObject
&)data
;
235 wxMetafile
* metaFile
= (wxMetafile
*)wxGetClipboardData(wxDF_METAFILE
);
239 metaFileDataObject
.SetMetafile(*metaFile
);
244 #endif // wxUSE_METAFILE
246 #else // !wxUSE_DATAOBJ
247 wxFAIL_MSG( wxT("no clipboard implementation") );
252 void wxClipboard::SetClipboardClient(wxClipboardClient *client, long time)
257 clipOwner->BeingReplaced();
264 if (wxOpenClipboard()) {
265 char **formats, *data;
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;
281 got_selection = wxCloseClipboard();
283 got_selection = FALSE;
285 got_selection = FALSE; // Assume another process takes over
287 if (!got_selection) {
288 clipOwner->BeingReplaced();
293 wxClipboardClient *wxClipboard::GetClipboardClient()
298 void wxClipboard::SetClipboardString(char *str, long time)
303 clipOwner->BeingReplaced();
311 if (wxOpenClipboard()) {
312 if (!wxSetClipboardData(wxDF_TEXT, (wxObject *)str))
313 got_selection = FALSE;
315 got_selection = wxCloseClipboard();
317 got_selection = FALSE;
319 got_selection = FALSE; // Assume another process takes over
321 if (!got_selection) {
326 char *wxClipboard::GetClipboardString(long time)
331 str = GetClipboardData("TEXT", &length, time);
341 char *wxClipboard::GetClipboardData(char *format, long *length, long time)
344 if (clipOwner->formats.Member(format))
345 return clipOwner->GetData(format, length);
348 } else if (cbString) {
349 if (!strcmp(format, "TEXT"))
350 return copystring(cbString);
354 if (wxOpenClipboard()) {
355 receivedString = (char *)wxGetClipboardData(FormatStringToID(format),
359 receivedString = NULL;
361 return receivedString;