]> git.saurik.com Git - wxWidgets.git/blob - src/mac/clipbrd.cpp
28a4b9ef3f793e2311c40ba9c4433c6c8ddfbf47
[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 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject)
28 IMPLEMENT_ABSTRACT_CLASS(wxClipboardClient, wxObject)
29 #endif
30
31 bool wxOpenClipboard()
32 {
33 return TRUE;
34 }
35
36 bool wxCloseClipboard()
37 {
38 return FALSE;
39 }
40
41 bool wxEmptyClipboard()
42 {
43 ZeroScrap() ;
44 return FALSE;
45 }
46
47 bool wxClipboardOpen()
48 {
49 // TODO
50 return FALSE;
51 }
52
53 bool wxIsClipboardFormatAvailable(int dataFormat)
54 {
55 // TODO
56 return FALSE;
57 }
58
59 bool wxSetClipboardData(int dataFormat, wxObject *obj, int width, int height)
60 {
61 // TODO
62 return FALSE;
63 }
64
65 wxObject *wxGetClipboardData(int dataFormat, long *len)
66 {
67 // TODO
68 return NULL;
69 }
70
71 int wxEnumClipboardFormats(int dataFormat)
72 {
73 // TODO
74 return 0;
75 }
76
77 int wxRegisterClipboardFormat(char *formatName)
78 {
79 // TODO
80 return 0;
81 }
82
83 bool wxGetClipboardFormatName(int dataFormat, char *formatName, int maxCount)
84 {
85 // TODO
86 return FALSE;
87 }
88
89 /*
90 * Generalized clipboard implementation by Matthew Flatt
91 */
92
93 wxClipboard *wxTheClipboard = NULL;
94
95 void wxInitClipboard()
96 {
97 if (!wxTheClipboard)
98 wxTheClipboard = new wxClipboard;
99 }
100
101 wxClipboard::wxClipboard()
102 {
103 clipOwner = NULL;
104 cbString = NULL;
105 }
106
107 wxClipboard::~wxClipboard()
108 {
109 if (clipOwner)
110 clipOwner->BeingReplaced();
111 if (cbString)
112 delete[] cbString;
113 }
114
115 static int FormatStringToID(char *str)
116 {
117 if (!strcmp(str, "TEXT"))
118 return wxDF_TEXT;
119
120 return wxRegisterClipboardFormat(str);
121 }
122
123 void wxClipboard::SetClipboardClient(wxClipboardClient *client, long time)
124 {
125 bool got_selection;
126
127 if (clipOwner)
128 clipOwner->BeingReplaced();
129 clipOwner = client;
130 if (cbString) {
131 delete[] cbString;
132 cbString = NULL;
133 }
134
135 if (wxOpenClipboard()) {
136 char **formats, *data;
137 int i;
138 int ftype;
139 long size;
140
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;
147 break;
148 }
149 }
150
151 if (i < 0)
152 got_selection = wxCloseClipboard();
153 } else
154 got_selection = FALSE;
155
156 got_selection = FALSE; // Assume another process takes over
157
158 if (!got_selection) {
159 clipOwner->BeingReplaced();
160 clipOwner = NULL;
161 }
162 }
163
164 wxClipboardClient *wxClipboard::GetClipboardClient()
165 {
166 return clipOwner;
167 }
168
169 void wxClipboard::SetClipboardString(char *str, long time)
170 {/*
171 bool got_selection;
172
173 if (clipOwner) {
174 clipOwner->BeingReplaced();
175 clipOwner = NULL;
176 }
177 if (cbString)
178 delete[] cbString;
179
180 cbString = str;
181
182 if (wxOpenClipboard()) {
183 if (!wxSetClipboardData(wxDF_TEXT, (wxObject *)str))
184 got_selection = FALSE;
185 else
186 got_selection = wxCloseClipboard();
187 } else
188 got_selection = FALSE;
189
190 got_selection = FALSE; // Assume another process takes over
191
192 if (!got_selection) {
193 delete[] cbString;
194 cbString = NULL;
195 }
196 */
197 }
198
199 char *wxClipboard::GetClipboardString(long time)
200 {
201 char *str;
202 long length;
203
204 str = GetClipboardData("TEXT", &length, time);
205 if (!str) {
206 str = new char[1];
207 *str = 0;
208 }
209
210 return str;
211 }
212
213 char *wxClipboard::GetClipboardData(char *format, long *length, long time)
214 {
215 if (clipOwner) {
216 if (clipOwner->formats.Member(format))
217 return clipOwner->GetData(format, length);
218 else
219 return NULL;
220 } else if (cbString) {
221 if (!strcmp(format, "TEXT"))
222 return copystring(cbString);
223 else
224 return NULL;
225 } else {
226 if (wxOpenClipboard()) {
227 receivedString = (char *)wxGetClipboardData(FormatStringToID(format),
228 length);
229 wxCloseClipboard();
230 } else
231 receivedString = NULL;
232
233 return receivedString;
234 }
235 }
236