|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qclipboard.h" |
|
43 |
|
44 #ifndef QT_NO_CLIPBOARD |
|
45 |
|
46 #include "qapplication.h" |
|
47 #include "qbitmap.h" |
|
48 #include "qdatetime.h" |
|
49 #include "qbuffer.h" |
|
50 #include "qwidget.h" |
|
51 #include "qevent.h" |
|
52 |
|
53 #include <qwsdisplay_qws.h> |
|
54 #include <qwsproperty_qws.h> |
|
55 #include <qwsevent_qws.h> |
|
56 |
|
57 QT_BEGIN_NAMESPACE |
|
58 |
|
59 QT_USE_NAMESPACE |
|
60 |
|
61 |
|
62 /***************************************************************************** |
|
63 Internal QClipboard functions for Qt for Embedded Linux |
|
64 *****************************************************************************/ |
|
65 |
|
66 static const int TextClipboard=424242; |
|
67 static bool init = false; |
|
68 |
|
69 static inline void qwsInitClipboard() |
|
70 { |
|
71 //### this should go into QWSServer; it only needs to happen once. |
|
72 if( !init ) { |
|
73 QPaintDevice::qwsDisplay()->addProperty(0, TextClipboard); |
|
74 init = true; |
|
75 } |
|
76 } |
|
77 |
|
78 static QString qwsClipboardText() |
|
79 { |
|
80 char * data; |
|
81 int len; |
|
82 qwsInitClipboard(); |
|
83 if( !QPaintDevice::qwsDisplay()->getProperty(0, TextClipboard, data, len) ) { |
|
84 // qDebug("Property received: %d bytes", len); |
|
85 } |
|
86 |
|
87 QString s((const QChar*)data, len/sizeof(QChar)); |
|
88 // qDebug("Property received: '%s'", s.toAscii().constData()); |
|
89 delete[] data; |
|
90 return s; |
|
91 } |
|
92 |
|
93 |
|
94 static void qwsSetClipboardText(const QString& s) |
|
95 { |
|
96 qwsInitClipboard(); |
|
97 // qDebug("qwsSetClipboardText( %s )", s.toAscii().data()); |
|
98 int len = s.length()*sizeof(QChar); |
|
99 QByteArray ba((const char*)s.unicode(), len); |
|
100 QPaintDevice::qwsDisplay()-> |
|
101 setProperty(0, TextClipboard, QWSPropertyManager::PropReplace, ba); |
|
102 |
|
103 } |
|
104 |
|
105 class QClipboardData |
|
106 { |
|
107 public: |
|
108 QClipboardData(); |
|
109 ~QClipboardData(); |
|
110 |
|
111 void setSource(QMimeData* s) |
|
112 { |
|
113 if (s == src) |
|
114 return; |
|
115 delete src; |
|
116 src = s; |
|
117 } |
|
118 QMimeData* source() |
|
119 { return src; } |
|
120 #if 0 |
|
121 void addTransferredPixmap(QPixmap pm) |
|
122 { /* TODO: queue them */ |
|
123 transferred[tindex] = pm; |
|
124 tindex=(tindex+1)%2; |
|
125 } |
|
126 void clearTransfers() |
|
127 { |
|
128 transferred[0] = QPixmap(); |
|
129 transferred[1] = QPixmap(); |
|
130 } |
|
131 #endif |
|
132 |
|
133 void clear(); |
|
134 |
|
135 private: |
|
136 QMimeData* src; |
|
137 |
|
138 #if 0 |
|
139 QPixmap transferred[2]; |
|
140 int tindex; |
|
141 #endif |
|
142 }; |
|
143 |
|
144 QClipboardData::QClipboardData() |
|
145 { |
|
146 src = 0; |
|
147 #if 0 |
|
148 tindex=0; |
|
149 #endif |
|
150 } |
|
151 |
|
152 QClipboardData::~QClipboardData() |
|
153 { |
|
154 delete src; |
|
155 } |
|
156 |
|
157 void QClipboardData::clear() |
|
158 { |
|
159 delete src; |
|
160 src = 0; |
|
161 } |
|
162 |
|
163 |
|
164 static QClipboardData *internalCbData = 0; |
|
165 |
|
166 static void cleanupClipboardData() |
|
167 { |
|
168 delete internalCbData; |
|
169 internalCbData = 0; |
|
170 } |
|
171 |
|
172 static QClipboardData *clipboardData() |
|
173 { |
|
174 if (internalCbData == 0) { |
|
175 internalCbData = new QClipboardData; |
|
176 qAddPostRoutine(cleanupClipboardData); |
|
177 } |
|
178 return internalCbData; |
|
179 } |
|
180 |
|
181 |
|
182 /***************************************************************************** |
|
183 QClipboard member functions for FB. |
|
184 *****************************************************************************/ |
|
185 |
|
186 #if 0 |
|
187 |
|
188 QString QClipboard::text() const |
|
189 { |
|
190 return qwsClipboardText(); |
|
191 } |
|
192 |
|
193 void QClipboard::setText(const QString &text) |
|
194 { |
|
195 qwsSetClipboardText(text); |
|
196 } |
|
197 |
|
198 QString QClipboard::text(QString& subtype) const |
|
199 { |
|
200 QString r; |
|
201 if (subtype == "plain") |
|
202 r = text(); |
|
203 return r; |
|
204 } |
|
205 |
|
206 #endif |
|
207 |
|
208 void QClipboard::clear(Mode mode) |
|
209 { |
|
210 setText(QString(), mode); |
|
211 } |
|
212 |
|
213 |
|
214 bool QClipboard::event(QEvent *e) |
|
215 { |
|
216 static bool recursionWatch = false; |
|
217 if (e->type() != QEvent::Clipboard || recursionWatch) |
|
218 return QObject::event(e); |
|
219 |
|
220 recursionWatch = true; |
|
221 QWSPropertyNotifyEvent *event = (QWSPropertyNotifyEvent *)(((QClipboardEvent *)e)->data()); |
|
222 if (event && event->simpleData.state == QWSPropertyNotifyEvent::PropertyNewValue) { |
|
223 QClipboardData *d = clipboardData(); |
|
224 QString t = qwsClipboardText(); |
|
225 if( (d->source() == 0 && !t.isEmpty()) || (d->source() != 0 && d->source()->text() != t) ) { |
|
226 if( !d->source() ) |
|
227 d->setSource(new QMimeData); |
|
228 d->source()->setText( t ); |
|
229 emitChanged(QClipboard::Clipboard); |
|
230 } |
|
231 } |
|
232 |
|
233 recursionWatch = false; |
|
234 return true; |
|
235 } |
|
236 |
|
237 const QMimeData* QClipboard::mimeData(Mode mode) const |
|
238 { |
|
239 if (mode != Clipboard) return 0; |
|
240 |
|
241 QClipboardData *d = clipboardData(); |
|
242 // Try and get data from QWSProperty if no mime data has been set on us. |
|
243 if( !d->source() ) { |
|
244 QString t = qwsClipboardText(); |
|
245 if( !t.isEmpty() ) { |
|
246 QMimeData* nd = new QMimeData; |
|
247 nd->setText( t ); |
|
248 d->setSource( nd ); |
|
249 } |
|
250 } |
|
251 return d->source(); |
|
252 } |
|
253 |
|
254 void QClipboard::setMimeData(QMimeData* src, Mode mode) |
|
255 { |
|
256 if (mode != Clipboard) return; |
|
257 |
|
258 QClipboardData *d = clipboardData(); |
|
259 |
|
260 /* Propagate text data to other QWSClients */ |
|
261 |
|
262 QString newText; |
|
263 if( src != 0 ) |
|
264 newText = src->text(); |
|
265 QString oldText; |
|
266 if( d->source() != 0 ) |
|
267 oldText = d->source()->text(); |
|
268 |
|
269 d->setSource(src); |
|
270 |
|
271 if( oldText != newText ) { |
|
272 if( d->source() == 0 ) { |
|
273 qwsSetClipboardText( QString() ); |
|
274 } else { |
|
275 qwsSetClipboardText( d->source()->text() ); |
|
276 } |
|
277 } |
|
278 |
|
279 emitChanged(QClipboard::Clipboard); |
|
280 } |
|
281 |
|
282 bool QClipboard::supportsMode(Mode mode) const |
|
283 { |
|
284 return (mode == Clipboard); |
|
285 } |
|
286 |
|
287 bool QClipboard::ownsMode(Mode mode) const |
|
288 { |
|
289 if (mode == Clipboard) |
|
290 qWarning("QClipboard::ownsClipboard: UNIMPLEMENTED!"); |
|
291 return false; |
|
292 } |
|
293 |
|
294 void QClipboard::connectNotify( const char * ) |
|
295 { |
|
296 } |
|
297 |
|
298 void QClipboard::ownerDestroyed() |
|
299 { |
|
300 } |
|
301 |
|
302 #endif // QT_NO_CLIPBOARD |
|
303 |
|
304 QT_END_NAMESPACE |