]> git.saurik.com Git - wxWidgets.git/blame - src/stubs/clipbrd.cpp
forgot to check in wxHtmlProcessor::IsEnabled test in wxHtmlWindow::SetPage
[wxWidgets.git] / src / stubs / clipbrd.cpp
CommitLineData
93cf77c0
JS
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
93cf77c0
JS
26IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject)
27IMPLEMENT_ABSTRACT_CLASS(wxClipboardClient, wxObject)
93cf77c0
JS
28
29bool wxOpenClipboard()
30{
31 // TODO
32 return FALSE;
33}
34
35bool wxCloseClipboard()
36{
37 // TODO
38 return FALSE;
39}
40
41bool wxEmptyClipboard()
42{
43 // TODO
44 return FALSE;
45}
46
47bool wxClipboardOpen()
48{
49 // TODO
50 return FALSE;
51}
52
53bool wxIsClipboardFormatAvailable(int dataFormat)
54{
55 // TODO
56 return FALSE;
57}
58
59bool wxSetClipboardData(int dataFormat, wxObject *obj, int width, int height)
60{
61 // TODO
62 return FALSE;
63}
64
65wxObject *wxGetClipboardData(int dataFormat, long *len)
66{
67 // TODO
68 return NULL;
69}
70
71int wxEnumClipboardFormats(int dataFormat)
72{
73 // TODO
74 return 0;
75}
76
77int wxRegisterClipboardFormat(char *formatName)
78{
79 // TODO
80 return 0;
81}
82
83bool 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
93wxClipboard *wxTheClipboard = NULL;
94
95void wxInitClipboard()
96{
97 if (!wxTheClipboard)
98 wxTheClipboard = new wxClipboard;
99}
100
101wxClipboard::wxClipboard()
102{
103 clipOwner = NULL;
104 cbString = NULL;
105}
106
107wxClipboard::~wxClipboard()
108{
109 if (clipOwner)
110 clipOwner->BeingReplaced();
111 if (cbString)
112 delete[] cbString;
113}
114
115static int FormatStringToID(char *str)
116{
117 if (!strcmp(str, "TEXT"))
118 return wxDF_TEXT;
119
120 return wxRegisterClipboardFormat(str);
121}
122
123void 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
164wxClipboardClient *wxClipboard::GetClipboardClient()
165{
166 return clipOwner;
167}
168
169void 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
198char *wxClipboard::GetClipboardString(long time)
199{
200 char *str;
201 long length;
202
203 str = GetClipboardData("TEXT", &length, time);
204 if (!str) {
205 str = new char[1];
206 *str = 0;
207 }
208
209 return str;
210}
211
212char *wxClipboard::GetClipboardData(char *format, long *length, long time)
213{
214 if (clipOwner) {
215 if (clipOwner->formats.Member(format))
216 return clipOwner->GetData(format, length);
217 else
218 return NULL;
219 } else if (cbString) {
220 if (!strcmp(format, "TEXT"))
221 return copystring(cbString);
222 else
223 return NULL;
224 } else {
225 if (wxOpenClipboard()) {
226 receivedString = (char *)wxGetClipboardData(FormatStringToID(format),
227 length);
228 wxCloseClipboard();
229 } else
230 receivedString = NULL;
231
232 return receivedString;
233 }
234}
235