+static int FormatStringToID(char *str)
+{
+ if (!strcmp(str, "TEXT"))
+ return wxDF_TEXT;
+
+ return wxRegisterClipboardFormat(str);
+}
+
+void wxClipboard::SetClipboardClient(wxClipboardClient *client, long time)
+{
+ bool got_selection;
+
+ if (clipOwner)
+ clipOwner->BeingReplaced();
+ clipOwner = client;
+ if (cbString) {
+ delete[] cbString;
+ cbString = NULL;
+ }
+
+ if (wxOpenClipboard()) {
+ char **formats, *data;
+ int i;
+ int ftype;
+ long size;
+
+ formats = clipOwner->formats.ListToArray(FALSE);
+ for (i = clipOwner->formats.Number(); i--; ) {
+ ftype = FormatStringToID(formats[i]);
+ data = clipOwner->GetData(formats[i], &size);
+ if (!wxSetClipboardData(ftype, (wxObject *)data, size, 1)) {
+ got_selection = FALSE;
+ break;
+ }
+ }
+
+ if (i < 0)
+ got_selection = wxCloseClipboard();
+ } else
+ got_selection = FALSE;
+
+ got_selection = FALSE; // Assume another process takes over
+
+ if (!got_selection) {
+ clipOwner->BeingReplaced();
+ clipOwner = NULL;
+ }
+}