]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/clipbrd.cpp
28a4b9ef3f793e2311c40ba9c4433c6c8ddfbf47
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 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxClipboard
, wxObject
)
28 IMPLEMENT_ABSTRACT_CLASS(wxClipboardClient
, wxObject
)
31 bool wxOpenClipboard()
36 bool wxCloseClipboard()
41 bool wxEmptyClipboard()
47 bool wxClipboardOpen()
53 bool wxIsClipboardFormatAvailable(int dataFormat
)
59 bool wxSetClipboardData(int dataFormat
, wxObject
*obj
, int width
, int height
)
65 wxObject
*wxGetClipboardData(int dataFormat
, long *len
)
71 int wxEnumClipboardFormats(int dataFormat
)
77 int wxRegisterClipboardFormat(char *formatName
)
83 bool wxGetClipboardFormatName(int dataFormat
, char *formatName
, int maxCount
)
90 * Generalized clipboard implementation by Matthew Flatt
93 wxClipboard
*wxTheClipboard
= NULL
;
95 void wxInitClipboard()
98 wxTheClipboard
= new wxClipboard
;
101 wxClipboard::wxClipboard()
107 wxClipboard::~wxClipboard()
110 clipOwner
->BeingReplaced();
115 static int FormatStringToID(char *str
)
117 if (!strcmp(str
, "TEXT"))
120 return wxRegisterClipboardFormat(str
);
123 void wxClipboard::SetClipboardClient(wxClipboardClient
*client
, long time
)
128 clipOwner
->BeingReplaced();
135 if (wxOpenClipboard()) {
136 char **formats
, *data
;
141 formats
= clipOwner
->formats
.ListToArray(FALSE
);
142 for (i
= clipOwner
->formats
.Number(); i
--; ) {
143 ftype
= FormatStringToID(formats
[i
]);
144 data
= clipOwner
->GetData(formats
[i
], &size
);
145 if (!wxSetClipboardData(ftype
, (wxObject
*)data
, size
, 1)) {
146 got_selection
= FALSE
;
152 got_selection
= wxCloseClipboard();
154 got_selection
= FALSE
;
156 got_selection
= FALSE
; // Assume another process takes over
158 if (!got_selection
) {
159 clipOwner
->BeingReplaced();
164 wxClipboardClient
*wxClipboard::GetClipboardClient()
169 void wxClipboard::SetClipboardString(char *str
, long time
)
174 clipOwner->BeingReplaced();
182 if (wxOpenClipboard()) {
183 if (!wxSetClipboardData(wxDF_TEXT, (wxObject *)str))
184 got_selection = FALSE;
186 got_selection = wxCloseClipboard();
188 got_selection = FALSE;
190 got_selection = FALSE; // Assume another process takes over
192 if (!got_selection) {
199 char *wxClipboard::GetClipboardString(long time
)
204 str
= GetClipboardData("TEXT", &length
, time
);
213 char *wxClipboard::GetClipboardData(char *format
, long *length
, long time
)
216 if (clipOwner
->formats
.Member(format
))
217 return clipOwner
->GetData(format
, length
);
220 } else if (cbString
) {
221 if (!strcmp(format
, "TEXT"))
222 return copystring(cbString
);
226 if (wxOpenClipboard()) {
227 receivedString
= (char *)wxGetClipboardData(FormatStringToID(format
),
231 receivedString
= NULL
;
233 return receivedString
;