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