source: trunk/src/gui/kernel/qclipboard.cpp@ 763

Last change on this file since 763 was 651, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 19.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qclipboard.h"
43
44#ifndef QT_NO_CLIPBOARD
45
46#include "qapplication.h"
47#include "qapplication_p.h"
48#include "qpixmap.h"
49#include "qclipboard_p.h"
50#include "qvariant.h"
51#include "qbuffer.h"
52#include "qimage.h"
53#include "qtextcodec.h"
54
55QT_BEGIN_NAMESPACE
56
57/*!
58 \class QClipboard
59 \brief The QClipboard class provides access to the window system clipboard.
60
61 The clipboard offers a simple mechanism to copy and paste data
62 between applications.
63
64 QClipboard supports the same data types that QDrag does, and uses
65 similar mechanisms. For advanced clipboard usage read \l{Drag and
66 Drop}.
67
68 There is a single QClipboard object in an application, accessible
69 as QApplication::clipboard().
70
71 Example:
72 \snippet doc/src/snippets/code/src_gui_kernel_qclipboard.cpp 0
73
74 QClipboard features some convenience functions to access common
75 data types: setText() allows the exchange of Unicode text and
76 setPixmap() and setImage() allows the exchange of QPixmaps and
77 QImages between applications. The setMimeData() function is the
78 ultimate in flexibility: it allows you to add any QMimeData into
79 the clipboard. There are corresponding getters for each of these,
80 e.g. text(), image() and pixmap(). You can clear the clipboard by
81 calling clear().
82
83 A typical example of the use of these functions follows:
84
85 \snippet doc/src/snippets/droparea.cpp 0
86
87 \section1 Notes for X11 Users
88
89 \list
90
91 \i The X11 Window System has the concept of a separate selection
92 and clipboard. When text is selected, it is immediately available
93 as the global mouse selection. The global mouse selection may
94 later be copied to the clipboard. By convention, the middle mouse
95 button is used to paste the global mouse selection.
96
97 \i X11 also has the concept of ownership; if you change the
98 selection within a window, X11 will only notify the owner and the
99 previous owner of the change, i.e. it will not notify all
100 applications that the selection or clipboard data changed.
101
102 \i Lastly, the X11 clipboard is event driven, i.e. the clipboard
103 will not function properly if the event loop is not running.
104 Similarly, it is recommended that the contents of the clipboard
105 are stored or retrieved in direct response to user-input events,
106 e.g. mouse button or key presses and releases. You should not
107 store or retrieve the clipboard contents in response to timer or
108 non-user-input events.
109
110 \endlist
111
112 \section1 Notes for Mac OS X Users
113
114 Mac OS X supports a separate find buffer that holds the current
115 search string in Find operations. This find clipboard can be accessed
116 by specifying the FindBuffer mode.
117
118 \section1 Notes for Windows and Mac OS X Users
119
120 \list
121
122 \i Windows and Mac OS X do not support the global mouse
123 selection; they only supports the global clipboard, i.e. they
124 only add text to the clipboard when an explicit copy or cut is
125 made.
126
127 \i Windows and Mac OS X does not have the concept of ownership;
128 the clipboard is a fully global resource so all applications are
129 notified of changes.
130
131 \endlist
132
133 \sa QApplication
134*/
135
136#ifndef Q_WS_X11
137// for X11 there is a separate implementation of a constructor.
138/*!
139 \internal
140
141 Constructs a clipboard object.
142
143 Do not call this function.
144
145 Call QApplication::clipboard() instead to get a pointer to the
146 application's global clipboard object.
147
148 There is only one clipboard in the window system, and creating
149 more than one object to represent it is almost certainly an error.
150*/
151
152QClipboard::QClipboard(QObject *parent)
153 : QObject(*new QClipboardPrivate, parent)
154{
155 // nothing
156}
157#endif
158
159#if !defined(Q_WS_WIN32) && !defined(Q_WS_PM)
160/*!
161 \internal
162
163 Destroys the clipboard.
164
165 You should never delete the clipboard. QApplication will do this
166 when the application terminates.
167*/
168QClipboard::~QClipboard()
169{
170}
171#endif
172
173/*!
174 \fn void QClipboard::changed(QClipboard::Mode mode)
175 \since 4.2
176
177 This signal is emitted when the data for the given clipboard \a
178 mode is changed.
179
180 \sa dataChanged(), selectionChanged(), findBufferChanged()
181*/
182
183/*!
184 \fn void QClipboard::dataChanged()
185
186 This signal is emitted when the clipboard data is changed.
187
188 On Mac OS X and with Qt version 4.3 or higher, clipboard
189 changes made by other applications will only be detected
190 when the application is activated.
191
192 \sa findBufferChanged(), selectionChanged(), changed()
193*/
194
195/*!
196 \fn void QClipboard::selectionChanged()
197
198 This signal is emitted when the selection is changed. This only