Qt 4.8
qclipboard_qws.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
58 
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 ) {
74  init = true;
75  }
76 }
77 
79 {
80  char * data;
81  int len;
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 {
97  // qDebug("qwsSetClipboardText( %s )", s.toAscii().data());
98  int len = s.length()*sizeof(QChar);
99  QByteArray ba((const char*)s.unicode(), len);
101  setProperty(0, TextClipboard, QWSPropertyManager::PropReplace, ba);
102 
103 }
104 
106 {
107 public:
108  QClipboardData();
109  ~QClipboardData();
110 
112  {
113  if (s == src)
114  return;
115  delete src;
116  src = s;
117  }
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:
137 
138 #if 0
139  QPixmap transferred[2];
140  int tindex;
141 #endif
142 };
143 
145 {
146  src = 0;
147 #if 0
148  tindex=0;
149 #endif
150 }
151 
153 {
154  delete src;
155 }
156 
158 {
159  delete src;
160  src = 0;
161 }
162 
163 
165 
166 static void cleanupClipboardData()
167 {
168  delete internalCbData;
169  internalCbData = 0;
170 }
171 
173 {
174  if (internalCbData == 0) {
175  internalCbData = new QClipboardData;
177  }
178  return internalCbData;
179 }
180 
181 
182 /*****************************************************************************
183  QClipboard member functions for FB.
184  *****************************************************************************/
185 
186 #if 0
187 
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 
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;
222  if (event && event->simpleData.state == QWSPropertyNotifyEvent::PropertyNewValue) {
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 
238 {
239  if (mode != Clipboard) return 0;
240 
242  // Try and get data from QWSProperty if no mime data has been set on us.
243  if( !d->source() ) {
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 
255 {
256  if (mode != Clipboard) return;
257 
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 ) {
274  } else {
275  qwsSetClipboardText( d->source()->text() );
276  }
277  }
278 
279  emitChanged(QClipboard::Clipboard);
280 }
281 
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 
299 {
300 }
301 
302 #endif // QT_NO_CLIPBOARD
303 
double d
Definition: qnumeric_p.h:62
void clear(Mode mode=Clipboard)
Clear the clipboard contents.
static void qwsSetClipboardText(const QString &s)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
static void qwsInitClipboard()
EventRef event
static const int TextClipboard
static QWSDisplay * qwsDisplay()
bool event(QEvent *)
Reimplemented Function
void ownerDestroyed()
Internal cleanup for Windows.
void qAddPostRoutine(QtCleanUpFunction p)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
bool supportsMode(Mode mode) const
Returns true if the clipboard supports the clipboard mode speacified by mode; otherwise returns false...
void setMimeData(QMimeData *data, Mode mode=Clipboard)
Sets the clipboard data to src.
static QClipboardData * internalCbData
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setText(const QString &, Mode mode=Clipboard)
Copies text into the clipboard as plain text.
Definition: qclipboard.cpp:375
bool ownsMode(Mode mode) const
Returns true if the clipboard supports the clipboard data speacified by mode; otherwise returns false...
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
const QMimeData * mimeData(Mode mode=Clipboard) const
Returns a reference to a QMimeData representation of the current clipboard data.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QString text() const
Returns a plain text (MIME type text/plain) representation of the data.
Definition: qmimedata.cpp:364
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static bool init
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
static QString qwsClipboardText()
void setSource(QMimeData *s)
The QMimeData class provides a container for data that records information about its MIME type...
Definition: qmimedata.h:57
static void cleanupClipboardData()
Mode
Definition: qaudio.h:60
void addProperty(int winId, int property)
QClipboard::Mode mode
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
Definition: qglobal.h:88
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QMimeData * source()
void setText(const QString &text)
Sets text as the plain text (MIME type text/plain) used to represent the data.
Definition: qmimedata.cpp:377
The QClipboardEvent class provides the parameters used in a clipboard event.
Definition: qevent.h:695
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
QString text(Mode mode=Clipboard) const
Returns the clipboard text as plain text, or an empty string if the clipboard does not contain any te...
Definition: qclipboard.cpp:357
static QMimeData * clipboardData
#define text
Definition: qobjectdefs.h:80
void connectNotify(const char *)
Internal optimization for Windows.