summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2011-05-04 12:50:14 +0200
committerLars Knoll <lars.knoll@nokia.com>2011-05-04 12:50:14 +0200
commit401f078386a8b5a87a58e237de7be9a2f9a045ba (patch)
tree462d6e4b6b7ca0d79166f34524c1661471bc68eb /src/gui/kernel
parent004700532ab635cf8e5240c5674b2aaeeb601b95 (diff)
split kernel/ up according to the future library split
Create a guikernel/ directory that contains the files that'll go into libQtGui. What remains in kernel/ will go into QtWidgets. In addition to that image/, painting/ and text will end up int QtGui.
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/kernel.pri88
-rw-r--r--src/gui/kernel/qapplication.cpp6
-rw-r--r--src/gui/kernel/qapplication_p.h2
-rw-r--r--src/gui/kernel/qapplication_qpa.cpp8
-rw-r--r--src/gui/kernel/qbackingstore.cpp1665
-rw-r--r--src/gui/kernel/qbackingstore_p.h278
-rw-r--r--src/gui/kernel/qclipboard.cpp667
-rw-r--r--src/gui/kernel/qclipboard.h131
-rw-r--r--src/gui/kernel/qclipboard_mac.cpp634
-rw-r--r--src/gui/kernel/qclipboard_p.h131
-rw-r--r--src/gui/kernel/qclipboard_qpa.cpp105
-rw-r--r--src/gui/kernel/qclipboard_s60.cpp331
-rw-r--r--src/gui/kernel/qclipboard_win.cpp398
-rw-r--r--src/gui/kernel/qclipboard_x11.cpp1539
-rw-r--r--src/gui/kernel/qcursor.cpp573
-rw-r--r--src/gui/kernel/qcursor.h168
-rw-r--r--src/gui/kernel/qcursor_mac.mm689
-rw-r--r--src/gui/kernel/qcursor_p.h134
-rw-r--r--src/gui/kernel/qcursor_qpa.cpp127
-rw-r--r--src/gui/kernel/qcursor_s60.cpp533
-rw-r--r--src/gui/kernel/qcursor_win.cpp492
-rw-r--r--src/gui/kernel/qcursor_x11.cpp637
-rw-r--r--src/gui/kernel/qdnd.cpp491
-rw-r--r--src/gui/kernel/qdnd_mac.mm753
-rw-r--r--src/gui/kernel/qdnd_p.h336
-rw-r--r--src/gui/kernel/qdnd_qpa.cpp426
-rw-r--r--src/gui/kernel/qdnd_s60.cpp359
-rw-r--r--src/gui/kernel/qdnd_win.cpp1027
-rw-r--r--src/gui/kernel/qdnd_x11.cpp2072
-rw-r--r--src/gui/kernel/qdrag.cpp359
-rw-r--r--src/gui/kernel/qdrag.h105
-rw-r--r--src/gui/kernel/qevent.cpp4619
-rw-r--r--src/gui/kernel/qevent.h865
-rw-r--r--src/gui/kernel/qevent_p.h219
-rw-r--r--src/gui/kernel/qeventdispatcher_glib_qpa.cpp147
-rw-r--r--src/gui/kernel/qeventdispatcher_glib_qpa_p.h88
-rw-r--r--src/gui/kernel/qeventdispatcher_mac.mm1200
-rw-r--r--src/gui/kernel/qeventdispatcher_mac_p.h224
-rw-r--r--src/gui/kernel/qeventdispatcher_qpa.cpp334
-rw-r--r--src/gui/kernel/qeventdispatcher_qpa_p.h86
-rw-r--r--src/gui/kernel/qeventdispatcher_s60.cpp196
-rw-r--r--src/gui/kernel/qeventdispatcher_s60_p.h127
-rw-r--r--src/gui/kernel/qeventdispatcher_x11.cpp191
-rw-r--r--src/gui/kernel/qeventdispatcher_x11_p.h86
-rw-r--r--src/gui/kernel/qgenericplugin_qpa.cpp112
-rw-r--r--src/gui/kernel/qgenericplugin_qpa.h84
-rw-r--r--src/gui/kernel/qgenericpluginfactory_qpa.cpp115
-rw-r--r--src/gui/kernel/qgenericpluginfactory_qpa.h67
-rw-r--r--src/gui/kernel/qguiapplication.cpp925
-rw-r--r--src/gui/kernel/qguiapplication.h132
-rw-r--r--src/gui/kernel/qguiapplication_p.h149
-rw-r--r--src/gui/kernel/qguivariant.cpp800
-rw-r--r--src/gui/kernel/qhexstring_p.h98
-rw-r--r--src/gui/kernel/qkeymapper.cpp118
-rw-r--r--src/gui/kernel/qkeymapper_mac.cpp1023
-rw-r--r--src/gui/kernel/qkeymapper_p.h224
-rw-r--r--src/gui/kernel/qkeymapper_qpa.cpp77
-rw-r--r--src/gui/kernel/qkeymapper_s60.cpp258
-rw-r--r--src/gui/kernel/qkeymapper_win.cpp1207
-rw-r--r--src/gui/kernel/qkeymapper_x11.cpp1869
-rw-r--r--src/gui/kernel/qkeymapper_x11_p.cpp489
-rw-r--r--src/gui/kernel/qkeysequence.cpp1726
-rw-r--r--src/gui/kernel/qkeysequence.h237
-rw-r--r--src/gui/kernel/qkeysequence_p.h98
-rw-r--r--src/gui/kernel/qmime.cpp97
-rw-r--r--src/gui/kernel/qmime.h176
-rw-r--r--src/gui/kernel/qmime_mac.cpp1310
-rw-r--r--src/gui/kernel/qmime_win.cpp1556
-rw-r--r--src/gui/kernel/qmotifdnd_x11.cpp1031
-rw-r--r--src/gui/kernel/qole_win.cpp255
-rw-r--r--src/gui/kernel/qplatformclipboard_qpa.cpp105
-rw-r--r--src/gui/kernel/qplatformclipboard_qpa.h73
-rw-r--r--src/gui/kernel/qplatformcursor_qpa.cpp660
-rw-r--r--src/gui/kernel/qplatformcursor_qpa.h103
-rw-r--r--src/gui/kernel/qplatformeventloopintegration_qpa.cpp86
-rw-r--r--src/gui/kernel/qplatformeventloopintegration_qpa.h82
-rw-r--r--src/gui/kernel/qplatformglcontext_qpa.cpp81
-rw-r--r--src/gui/kernel/qplatformglcontext_qpa.h72
-rw-r--r--src/gui/kernel/qplatformintegration_qpa.cpp225
-rw-r--r--src/gui/kernel/qplatformintegration_qpa.h108
-rw-r--r--src/gui/kernel/qplatformintegrationfactory_qpa.cpp109
-rw-r--r--src/gui/kernel/qplatformintegrationfactory_qpa_p.h78
-rw-r--r--src/gui/kernel/qplatformintegrationplugin_qpa.cpp55
-rw-r--r--src/gui/kernel/qplatformintegrationplugin_qpa.h92
-rw-r--r--src/gui/kernel/qplatformnativeinterface_qpa.cpp53
-rw-r--r--src/gui/kernel/qplatformnativeinterface_qpa.h65
-rw-r--r--src/gui/kernel/qplatformscreen_qpa.cpp137
-rw-r--r--src/gui/kernel/qplatformscreen_qpa.h89
-rw-r--r--src/gui/kernel/qplatformwindow_qpa.cpp216
-rw-r--r--src/gui/kernel/qplatformwindow_qpa.h94
-rw-r--r--src/gui/kernel/qsessionmanager.h111
-rw-r--r--src/gui/kernel/qsessionmanager_qpa.cpp175
-rw-r--r--src/gui/kernel/qshortcut.cpp407
-rw-r--r--src/gui/kernel/qshortcut.h107
-rw-r--r--src/gui/kernel/qshortcutmap.cpp897
-rw-r--r--src/gui/kernel/qshortcutmap_p.h123
-rw-r--r--src/gui/kernel/qwindow.cpp458
-rw-r--r--src/gui/kernel/qwindow.h186
-rw-r--r--src/gui/kernel/qwindow_p.h91
-rw-r--r--src/gui/kernel/qwindowcontext_qpa.cpp201
-rw-r--r--src/gui/kernel/qwindowcontext_qpa.h90
-rw-r--r--src/gui/kernel/qwindowdefs.h160
-rw-r--r--src/gui/kernel/qwindowdefs_win.h132
-rw-r--r--src/gui/kernel/qwindowformat_qpa.cpp406
-rw-r--r--src/gui/kernel/qwindowformat_qpa.h155
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa.cpp254
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa.h107
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa_p.h208
108 files changed, 1957 insertions, 42773 deletions
diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri
index 09ef146597..c2559b1225 100644
--- a/src/gui/kernel/kernel.pri
+++ b/src/gui/kernel/kernel.pri
@@ -11,25 +11,15 @@ HEADERS += \
kernel/qactiongroup.h \
kernel/qapplication.h \
kernel/qapplication_p.h \
+ kernel/qbackingstore_p.h \
kernel/qboxlayout.h \
- kernel/qclipboard.h \
- kernel/qcursor.h \
kernel/qdesktopwidget.h \
- kernel/qdrag.h \
- kernel/qdnd_p.h \
- kernel/qevent.h \
- kernel/qevent_p.h \
kernel/qformlayout.h \
kernel/qgridlayout.h \
- kernel/qkeysequence.h \
kernel/qlayout.h \
kernel/qlayout_p.h \
kernel/qlayoutengine_p.h \
kernel/qlayoutitem.h \
- kernel/qmime.h \
- kernel/qsessionmanager.h \
- kernel/qshortcut.h \
- kernel/qshortcutmap_p.h \
kernel/qsizepolicy.h \
kernel/qpalette.h \
kernel/qstackedlayout.h \
@@ -39,8 +29,6 @@ HEADERS += \
kernel/qwidget_p.h \
kernel/qwidgetaction.h \
kernel/qwidgetaction_p.h \
- kernel/qwindowdefs.h \
- kernel/qkeymapper_p.h \
kernel/qgesture.h \
kernel/qgesture_p.h \
kernel/qstandardgestures_p.h \
@@ -48,36 +36,25 @@ HEADERS += \
kernel/qgesturemanager_p.h \
kernel/qsoftkeymanager_p.h \
kernel/qsoftkeymanager_common_p.h \
- kernel/qguiplatformplugin_p.h \
- kernel/qhexstring_p.h
+ kernel/qguiplatformplugin_p.h
SOURCES += \
kernel/qaction.cpp \
kernel/qactiongroup.cpp \
kernel/qapplication.cpp \
- kernel/qboxlayout.cpp \
- kernel/qclipboard.cpp \
- kernel/qcursor.cpp \
- kernel/qdrag.cpp \
- kernel/qdnd.cpp \
- kernel/qevent.cpp \
+ kernel/qbackingstore.cpp \
+ kernel/qboxlayout.cpp \
kernel/qformlayout.cpp \
kernel/qgridlayout.cpp \
- kernel/qkeysequence.cpp \
kernel/qlayout.cpp \
kernel/qlayoutengine.cpp \
kernel/qlayoutitem.cpp \
- kernel/qmime.cpp \
kernel/qpalette.cpp \
- kernel/qshortcut.cpp \
- kernel/qshortcutmap.cpp \
kernel/qstackedlayout.cpp \
kernel/qtooltip.cpp \
- kernel/qguivariant.cpp \
kernel/qwhatsthis.cpp \
kernel/qwidget.cpp \
kernel/qwidgetaction.cpp \
- kernel/qkeymapper.cpp \
kernel/qgesture.cpp \
kernel/qstandardgestures.cpp \
kernel/qgesturerecognizer.cpp \
@@ -184,68 +161,15 @@ unix:x11 {
}
qpa {
- HEADERS += \
- kernel/qgenericpluginfactory_qpa.h \
- kernel/qgenericplugin_qpa.h \
- kernel/qeventdispatcher_qpa_p.h \
- kernel/qwindowsysteminterface_qpa.h \
- kernel/qwindowsysteminterface_qpa_p.h \
- kernel/qplatformintegration_qpa.h \
- kernel/qplatformscreen_qpa.h \
- kernel/qplatformintegrationfactory_qpa_p.h \
- kernel/qplatformintegrationplugin_qpa.h \
- kernel/qplatformwindow_qpa.h \
- kernel/qplatformglcontext_qpa.h \
- kernel/qwindowcontext_qpa.h \
+ HEADERS += \
kernel/qdesktopwidget_qpa_p.h \
- kernel/qplatformeventloopintegration_qpa.h \
- kernel/qplatformcursor_qpa.h \
- kernel/qplatformclipboard_qpa.h \
- kernel/qplatformnativeinterface_qpa.h \
- kernel/qwindowformat_qpa.h \
- kernel/qguiapplication.h \
- kernel/qguiapplication_p.h \
kernel/qwidgetwindow_qpa_p.h \
- kernel/qwindow_p.h \
- kernel/qwindow.h
- SOURCES += \
+ SOURCES += \
kernel/qapplication_qpa.cpp \
- kernel/qclipboard_qpa.cpp \
- kernel/qcursor_qpa.cpp \
- kernel/qdnd_qpa.cpp \
kernel/qdesktopwidget_qpa.cpp \
- kernel/qgenericpluginfactory_qpa.cpp \
- kernel/qgenericplugin_qpa.cpp \
- kernel/qkeymapper_qpa.cpp \
kernel/qwidget_qpa.cpp \
- kernel/qeventdispatcher_qpa.cpp \
- kernel/qwindowsysteminterface_qpa.cpp \
- kernel/qplatformintegration_qpa.cpp \
- kernel/qplatformscreen_qpa.cpp \
- kernel/qplatformintegrationfactory_qpa.cpp \
- kernel/qplatformintegrationplugin_qpa.cpp \
- kernel/qplatformwindow_qpa.cpp \
- kernel/qplatformeventloopintegration_qpa.cpp \
- kernel/qplatformglcontext_qpa.cpp \
- kernel/qwindowcontext_qpa.cpp \
- kernel/qplatformcursor_qpa.cpp \
- kernel/qplatformclipboard_qpa.cpp \
- kernel/qplatformnativeinterface_qpa.cpp \
- kernel/qsessionmanager_qpa.cpp \
- kernel/qwindowformat_qpa.cpp \
- kernel/qguiapplication.cpp \
kernel/qwidgetwindow_qpa.cpp \
- kernel/qwindow.cpp
-
- contains(QT_CONFIG, glib) {
- SOURCES += \
- kernel/qeventdispatcher_glib_qpa.cpp
- HEADERS += \
- kernel/qeventdispatcher_glib_qpa_p.h
- QMAKE_CXXFLAGS += $$QT_CFLAGS_GLIB
- LIBS_PRIVATE +=$$QT_LIBS_GLIB
- }
}
!qpa:!x11:mac {
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp
index 08a6f540a8..d489aaf6bd 100644
--- a/src/gui/kernel/qapplication.cpp
+++ b/src/gui/kernel/qapplication.cpp
@@ -61,7 +61,7 @@
#include "qtranslator.h"
#include "qvariant.h"
#include "qwidget.h"
-#include "qdnd_p.h"
+#include "private/qdnd_p.h"
#include "qcolormap.h"
#include "qdebug.h"
#include "private/qstylesheetstyle_p.h"
@@ -70,7 +70,7 @@
#include <QtGui/qgraphicsproxywidget.h>
#include "qinputcontext.h"
-#include "qkeymapper_p.h"
+#include "private/qkeymapper_p.h"
#ifdef Q_WS_X11
#include <private/qt_x11_p.h>
@@ -94,7 +94,7 @@
#endif
#include "qapplication_p.h"
-#include "qevent_p.h"
+#include "private/qevent_p.h"
#include "qwidget_p.h"
#include "qapplication.h"
diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h
index acad22d4a9..41d05f5978 100644
--- a/src/gui/kernel/qapplication_p.h
+++ b/src/gui/kernel/qapplication_p.h
@@ -74,7 +74,7 @@
#endif
#ifdef Q_WS_QPA
#include <QWindowSystemInterface>
-#include "qwindowsysteminterface_qpa_p.h"
+#include "private/qwindowsysteminterface_qpa_p.h"
#include "QtGui/qplatformintegration_qpa.h"
#include "QtGui/private/qguiapplication_p.h"
#endif
diff --git a/src/gui/kernel/qapplication_qpa.cpp b/src/gui/kernel/qapplication_qpa.cpp
index 1996bdaa13..30ae8cf3f1 100644
--- a/src/gui/kernel/qapplication_qpa.cpp
+++ b/src/gui/kernel/qapplication_qpa.cpp
@@ -43,9 +43,9 @@
#include "qcolormap.h"
#include "qpixmapcache.h"
#if !defined(QT_NO_GLIB)
-#include "qeventdispatcher_glib_qpa_p.h"
+#include "private/qeventdispatcher_glib_qpa_p.h"
#endif
-#include "qeventdispatcher_qpa_p.h"
+#include "private/qeventdispatcher_qpa_p.h"
#ifndef QT_NO_CURSOR
#include "private/qcursor_p.h"
#endif
@@ -54,14 +54,14 @@
#include "private/qevent_p.h"
#include "qgenericpluginfactory_qpa.h"
-#include "qplatformintegrationfactory_qpa_p.h"
+#include "private/qplatformintegrationfactory_qpa_p.h"
#include <qdesktopwidget.h>
#include <qinputcontext.h>
#include <QPlatformCursor>
#include <qdebug.h>
#include <QWindowSystemInterface>
-#include "qwindowsysteminterface_qpa_p.h"
+#include "private/qwindowsysteminterface_qpa_p.h"
#include <QPlatformIntegration>
#include "qdesktopwidget_qpa_p.h"
diff --git a/src/gui/kernel/qbackingstore.cpp b/src/gui/kernel/qbackingstore.cpp
new file mode 100644
index 0000000000..1ee66f09cc
--- /dev/null
+++ b/src/gui/kernel/qbackingstore.cpp
@@ -0,0 +1,1665 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include "qplatformdefs.h"
+
+#include "qbackingstore_p.h"
+
+#include <QtCore/qglobal.h>
+#include <QtCore/qdebug.h>
+#include <QtCore/qvarlengtharray.h>
+#include <QtGui/qevent.h>
+#include <QtGui/qapplication.h>
+#include <QtGui/qpaintengine.h>
+#include <QtGui/qgraphicsproxywidget.h>
+
+#include <private/qwidget_p.h>
+#include <private/qapplication_p.h>
+#include <private/qpaintengine_raster_p.h>
+#include <private/qgraphicseffect_p.h>
+
+#ifdef Q_WS_QWS
+#include <QtGui/qwsmanager_qws.h>
+#include <private/qwsmanager_p.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+extern QRegion qt_dirtyRegion(QWidget *);
+
+/*
+ A version of QRect::intersects() that does not normalize the rects.
+*/
+static inline bool qRectIntersects(const QRect &r1, const QRect &r2)
+{
+ return (qMax(r1.left(), r2.left()) <= qMin(r1.right(), r2.right())
+ && qMax(r1.top(), r2.top()) <= qMin(r1.bottom(), r2.bottom()));
+}
+
+/**
+ * Flushes the contents of the \a windowSurface into the screen area of \a widget.
+ * \a tlwOffset is the position of the top level widget relative to the window surface.
+ * \a region is the region to be updated in \a widget coordinates.
+ */
+static inline void qt_flush(QWidget *widget, const QRegion &region, QWindowSurface *windowSurface,
+ QWidget *tlw, const QPoint &tlwOffset)
+{
+ Q_ASSERT(widget);
+ Q_ASSERT(!region.isEmpty());
+ Q_ASSERT(windowSurface);
+ Q_ASSERT(tlw);
+
+#if !defined(QT_NO_PAINT_DEBUG) && !defined(Q_WS_QWS)
+ // QWS does flush update in QWindowSurface::flush (because it needs to lock the surface etc).
+ static int flushUpdate = qgetenv("QT_FLUSH_UPDATE").toInt();
+ if (flushUpdate > 0)
+ QWidgetBackingStore::showYellowThing(widget, region, flushUpdate * 10, false);
+#endif
+
+ //The performance hit by doing this should be negligible. However, be aware that
+ //using this FPS when you have > 1 windowsurface can give you inaccurate FPS
+ static bool fpsDebug = qgetenv("QT_DEBUG_FPS").toInt();
+ if (fpsDebug) {
+ static QTime time = QTime::currentTime();
+ static int frames = 0;
+
+ frames++;
+
+ if(time.elapsed() > 5000) {
+ double fps = double(frames * 1000) /time.restart();
+ fprintf(stderr,"FPS: %.1f\n",fps);
+ frames = 0;
+ }
+ }
+ if (widget != tlw)
+ windowSurface->flush(widget->windowHandle(), region, tlwOffset + widget->mapTo(tlw, QPoint()));
+ else
+ windowSurface->flush(widget->windowHandle(), region, tlwOffset);
+}
+
+#ifndef QT_NO_PAINT_DEBUG
+#ifdef Q_WS_WIN
+static void showYellowThing_win(QWidget *widget, const QRegion &region, int msec)
+{
+ HBRUSH brush;
+ static int i = 0;
+ switch (i) {
+ case 0:
+ brush = CreateSolidBrush(RGB(255, 255, 0));
+ break;
+ case 1:
+ brush = CreateSolidBrush(RGB(255, 200, 55));
+ break;
+ case 2:
+ brush = CreateSolidBrush(RGB(200, 255, 55));
+ break;
+ case 3:
+ brush = CreateSolidBrush(RGB(200, 200, 0));
+ break;
+ }
+ i = (i + 1) & 3;
+
+ HDC hdc = widget->getDC();
+
+ const QVector<QRect> &rects = region.rects();
+ foreach (QRect rect, rects) {
+ RECT winRect;
+ SetRect(&winRect, rect.left(), rect.top(), rect.right(), rect.bottom());
+ FillRect(hdc, &winRect, brush);
+ }
+
+ widget->releaseDC(hdc);
+ ::Sleep(msec);
+}
+#endif
+
+void QWidgetBackingStore::showYellowThing(QWidget *widget, const QRegion &toBePainted, int msec, bool unclipped)
+{
+#ifdef Q_WS_QWS
+ Q_UNUSED(widget);
+ Q_UNUSED(unclipped);
+ static QWSYellowSurface surface(true);
+ surface.setDelay(msec);
+ surface.flush(widget, toBePainted, QPoint());
+#else
+ QRegion paintRegion = toBePainted;
+ QRect widgetRect = widget->rect();
+
+ if (!widget->internalWinId()) {
+ QWidget *nativeParent = widget->nativeParentWidget();
+ const QPoint offset = widget->mapTo(nativeParent, QPoint(0, 0));
+ paintRegion.translate(offset);
+ widgetRect.translate(offset);
+ widget = nativeParent;
+ }
+
+#ifdef Q_WS_WIN
+ Q_UNUSED(unclipped);
+ showYellowThing_win(widget, paintRegion, msec);
+#else
+ //flags to fool painter
+ bool paintUnclipped = widget->testAttribute(Qt::WA_PaintUnclipped);
+ if (unclipped && !widget->d_func()->paintOnScreen())
+ widget->setAttribute(Qt::WA_PaintUnclipped);
+
+ const bool setFlag = !widget->testAttribute(Qt::WA_WState_InPaintEvent);
+ if (setFlag)
+ widget->setAttribute(Qt::WA_WState_InPaintEvent);
+
+ //setup the engine
+ QPaintEngine *pe = widget->paintEngine();
+ if (pe) {
+ pe->setSystemClip(paintRegion);
+ {
+ QPainter p(widget);
+ p.setClipRegion(paintRegion);
+ static int i = 0;
+ switch (i) {
+ case 0:
+ p.fillRect(widgetRect, QColor(255,255,0));
+ break;
+ case 1:
+ p.fillRect(widgetRect, QColor(255,200,55));
+ break;
+ case 2:
+ p.fillRect(widgetRect, QColor(200,255,55));
+ break;
+ case 3:
+ p.fillRect(widgetRect, QColor(200,200,0));
+ break;
+ }
+ i = (i+1) & 3;
+ p.end();
+ }
+ }
+
+ if (setFlag)
+ widget->setAttribute(Qt::WA_WState_InPaintEvent, false);
+
+ //restore
+ widget->setAttribute(Qt::WA_PaintUnclipped, paintUnclipped);
+
+ if (pe)
+ pe->setSystemClip(QRegion());
+
+ QApplication::syncX();
+
+#if defined(Q_OS_UNIX)
+ ::usleep(1000 * msec);
+#endif
+#endif // Q_WS_WIN
+#endif // Q_WS_QWS
+}
+
+bool QWidgetBackingStore::flushPaint(QWidget *widget, const QRegion &rgn)
+{
+ if (!widget)
+ return false;
+
+ int delay = 0;
+ if (widget->testAttribute(Qt::WA_WState_InPaintEvent)) {
+ static int flushPaintEvent = qgetenv("QT_FLUSH_PAINT_EVENT").toInt();
+ if (!flushPaintEvent)
+ return false;
+ delay = flushPaintEvent;
+ } else {
+ static int flushPaint = qgetenv("QT_FLUSH_PAINT").toInt();
+ if (!flushPaint)
+ return false;
+ delay = flushPaint;
+ }
+
+ QWidgetBackingStore::showYellowThing(widget, rgn, delay * 10, true);
+ return true;
+}
+
+void QWidgetBackingStore::unflushPaint(QWidget *widget, const QRegion &rgn)
+{
+ if (widget->d_func()->paintOnScreen() || rgn.isEmpty())
+ return;
+
+ QWidget *tlw = widget->window();
+ QTLWExtra *tlwExtra = tlw->d_func()->maybeTopData();
+ if (!tlwExtra)
+ return;
+
+ const QPoint offset = widget->mapTo(tlw, QPoint());
+ qt_flush(widget, rgn, tlwExtra->backingStore->windowSurface, tlw, offset);
+}
+#endif // QT_NO_PAINT_DEBUG
+
+/*
+ Moves the whole rect by (dx, dy) in widget's coordinate system.
+ Doesn't generate any updates.
+*/
+bool QWidgetBackingStore::bltRect(const QRect &rect, int dx, int dy, QWidget *widget)
+{
+ const QPoint pos(tlwOffset + widget->mapTo(tlw, rect.topLeft()));
+ const QRect tlwRect(QRect(pos, rect.size()));
+ if (fullUpdatePending || dirty.intersects(tlwRect))
+ return false; // We don't want to scroll junk.
+ return windowSurface->scroll(tlwRect, dx, dy);
+}
+
+void QWidgetBackingStore::releaseBuffer()
+{
+ if (windowSurface)
+#if defined(Q_WS_QPA)
+ windowSurface->resize(QSize());
+#else
+ windowSurface->setGeometry(QRect());
+#endif
+#ifdef Q_BACKINGSTORE_SUBSURFACES
+ for (int i = 0; i < subSurfaces.size(); ++i)
+ subSurfaces.at(i)->setGeometry(QRect());
+#endif
+}
+
+/*!
+ Prepares the window surface to paint a\ toClean region of the \a widget and
+ updates the BeginPaintInfo struct accordingly.
+
+ The \a toClean region might be clipped by the window surface.
+*/
+void QWidgetBackingStore::beginPaint(QRegion &toClean, QWidget *widget, QWindowSurface *windowSurface,
+ BeginPaintInfo *returnInfo, bool toCleanIsInTopLevelCoordinates)
+{
+#ifdef Q_WS_QWS
+ QWSWindowSurface *surface = static_cast<QWSWindowSurface *>(windowSurface);
+ QWidget *surfaceWidget = surface->window();
+
+ if (!surface->isValid()) {
+ // this looks strange but it really just releases the surface
+ surface->releaseSurface();
+ // the old window surface is deleted in setWindowSurface, which is
+ // called from QWindowSurface constructor.
+ windowSurface = tlw->d_func()->createDefaultWindowSurface();
+ surface = static_cast<QWSWindowSurface *>(windowSurface);
+ // createDefaultWindowSurface() will set topdata->windowSurface on the
+ // widget to zero. However, if this is a sub-surface, it should point
+ // to the widget's sub windowSurface, so we set that here:
+ if (!surfaceWidget->isWindow())
+ surfaceWidget->d_func()->topData()->windowSurface = windowSurface;
+ surface->setGeometry(topLevelRect());
+ returnInfo->windowSurfaceRecreated = true;
+ }
+
+ const QRegion toCleanUnclipped(toClean);
+
+ if (surfaceWidget->isWindow())
+ tlwOffset = surface->painterOffset();
+#ifdef Q_BACKINGSTORE_SUBSURFACES
+ else if (toCleanIsInTopLevelCoordinates)
+ toClean &= surface->clipRegion().translated(surfaceWidget->mapTo(tlw, QPoint()));
+ if (!toCleanIsInTopLevelCoordinates && windowSurface == this->windowSurface)
+ toClean &= surface->clipRegion().translated(-widget->mapTo(surfaceWidget, QPoint()));
+#else
+ toClean &= surface->clipRegion();
+#endif
+
+ if (toClean.isEmpty()) {
+ if (surfaceWidget->isWindow()) {
+ dirtyFromPreviousSync += toCleanUnclipped;
+ hasDirtyFromPreviousSync = true;
+ }
+
+ returnInfo->nothingToPaint = true;
+ // Nothing to repaint. However, we might have newly exposed areas on the
+ // screen, so we have to make sure those are flushed.
+ flush();
+ return;
+ }
+
+ if (surfaceWidget->isWindow()) {
+ if (toCleanUnclipped != toClean) {
+ dirtyFromPreviousSync += (toCleanUnclipped - surface->clipRegion());
+ hasDirtyFromPreviousSync = true;
+ }
+ if (hasDirtyFromPreviousSync) {
+ dirtyFromPreviousSync -= toClean;
+ hasDirtyFromPreviousSync = !dirtyFromPreviousSync.isEmpty();
+ }
+ }
+
+#endif // Q_WS_QWS
+
+ Q_UNUSED(widget);
+ Q_UNUSED(toCleanIsInTopLevelCoordinates);
+
+ // Always flush repainted areas.
+ dirtyOnScreen += toClean;
+
+#if defined(Q_WS_QWS) && !defined(Q_BACKINGSTORE_SUBSURFACES)
+ toClean.translate(tlwOffset);
+#endif
+
+#ifdef QT_NO_PAINT_DEBUG
+ windowSurface->beginPaint(toClean);
+#else
+ returnInfo->wasFlushed = QWidgetBackingStore::flushPaint(tlw, toClean);
+ // Avoid deadlock with QT_FLUSH_PAINT: the server will wait for
+ // the BackingStore lock, so if we hold that, the server will
+ // never release the Communication lock that we are waiting for in
+ // sendSynchronousCommand
+ if (!returnInfo->wasFlushed)
+ windowSurface->beginPaint(toClean);
+#endif
+
+ Q_UNUSED(returnInfo);
+}
+
+void QWidgetBackingStore::endPaint(const QRegion &cleaned, QWindowSurface *windowSurface,
+ BeginPaintInfo *beginPaintInfo)
+{
+#ifndef QT_NO_PAINT_DEBUG
+ if (!beginPaintInfo->wasFlushed)
+ windowSurface->endPaint(cleaned);
+ else
+ QWidgetBackingStore::unflushPaint(tlw, cleaned);
+#else
+ Q_UNUSED(beginPaintInfo);
+ windowSurface->endPaint(cleaned);
+#endif
+
+#ifdef Q_BACKINGSTORE_SUBSURFACES
+ flush(static_cast<QWSWindowSurface *>(windowSurface)->window(), windowSurface);
+#else
+ flush();
+#endif
+}
+
+/*!
+ Returns the region (in top-level coordinates) that needs repaint and/or flush.
+
+ If the widget is non-zero, only the dirty region for the widget is returned
+ and the region will be in widget coordinates.
+*/
+QRegion QWidgetBackingStore::dirtyRegion(QWidget *widget) const
+{
+ const bool widgetDirty = widget && widget != tlw;
+ const QRect tlwRect(topLevelRect());
+#if defined(Q_WS_QPA)
+ const QRect surfaceGeometry(tlwRect.topLeft(), windowSurface->size());
+#else
+ const QRect surfaceGeometry(windowSurface->geometry());
+#endif
+ if (fullUpdatePending || (surfaceGeometry != tlwRect && surfaceGeometry.size() != tlwRect.size())) {
+ if (widgetDirty) {
+ const QRect dirtyTlwRect = QRect(QPoint(), tlwRect.size());
+ const QPoint offset(widget->mapTo(tlw, QPoint()));
+ const QRect dirtyWidgetRect(dirtyTlwRect & widget->rect().translated(offset));
+ return dirtyWidgetRect.translated(-offset);
+ }
+ return QRect(QPoint(), tlwRect.size());
+ }
+
+ // Calculate the region that needs repaint.
+ QRegion r(dirty);
+ for (int i = 0; i < dirtyWidgets.size(); ++i) {
+ QWidget *w = dirtyWidgets.at(i);
+ if (widgetDirty && w != widget && !widget->isAncestorOf(w))
+ continue;
+ r += w->d_func()->dirty.translated(w->mapTo(tlw, QPoint()));
+ }
+
+ // Append the region that needs flush.
+ r += dirtyOnScreen;
+
+ if (dirtyOnScreenWidgets) { // Only in use with native child widgets.
+ for (int i = 0; i < dirtyOnScreenWidgets->size(); ++i) {
+ QWidget *w = dirtyOnScreenWidgets->at(i);
+ if (widgetDirty && w != widget && !widget->isAncestorOf(w))
+ continue;
+ QWidgetPrivate *wd = w->d_func();
+ Q_ASSERT(wd->needsFlush);
+ r += wd->needsFlush->translated(w->mapTo(tlw, QPoint()));
+ }
+ }
+
+ if (widgetDirty) {
+ // Intersect with the widget geometry and translate to its coordinates.
+ const QPoint offset(widget->mapTo(tlw, QPoint()));
+ r &= widget->rect().translated(offset);
+ r.translate(-offset);
+ }
+ return r;
+}
+
+/*!
+ Returns the static content inside the \a parent if non-zero; otherwise the static content
+ for the entire backing store is returned. The content will be clipped to \a withinClipRect
+ if non-empty.
+*/
+QRegion QWidgetBackingStore::staticContents(QWidget *parent, const QRect &withinClipRect) const
+{
+ if (!parent && tlw->testAttribute(Qt::WA_StaticContents)) {
+#if defined(Q_WS_QPA)
+ const QSize surfaceGeometry(windowSurface->size());
+#else
+ const QRect surfaceGeometry(windowSurface->geometry());
+#endif
+ QRect surfaceRect(0, 0, surfaceGeometry.width(), surfaceGeometry.height());
+ if (!withinClipRect.isEmpty())
+ surfaceRect &= withinClipRect;
+ return QRegion(surfaceRect);
+ }
+
+ QRegion region;
+ if (parent && parent->d_func()->children.isEmpty())
+ return region;
+
+ const bool clipToRect = !withinClipRect.isEmpty();
+ const int count = staticWidgets.count();
+ for (int i = 0; i < count; ++i) {
+ QWidget *w = staticWidgets.at(i);
+ QWidgetPrivate *wd = w->d_func();
+ if (!wd->isOpaque || !wd->extra || wd->extra->staticContentsSize.isEmpty()
+ || !w->isVisible() || (parent && !parent->isAncestorOf(w))) {
+ continue;
+ }
+
+ QRect rect(0, 0, wd->extra->staticContentsSize.width(), wd->extra->staticContentsSize.height());
+ const QPoint offset = w->mapTo(parent ? parent : tlw, QPoint());
+ if (clipToRect)
+ rect &= withinClipRect.translated(-offset);
+ if (rect.isEmpty())
+ continue;
+
+ rect &= wd->clipRect();
+ if (rect.isEmpty())
+ continue;
+
+ QRegion visible(rect);
+ wd->clipToEffectiveMask(visible);
+ if (visible.isEmpty())
+ continue;
+ wd->subtractOpaqueSiblings(visible, 0, /*alsoNonOpaque=*/true);
+
+ visible.translate(offset);
+ region += visible;
+ }
+
+ return region;
+}
+
+static inline void sendUpdateRequest(QWidget *widget, bool updateImmediately)
+{
+ if (!widget)
+ return;
+
+ if (updateImmediately) {
+ QEvent event(QEvent::UpdateRequest);
+ QApplication::sendEvent(widget, &event);
+ } else {
+ QApplication::postEvent(widget, new QEvent(QEvent::UpdateRequest), Qt::LowEventPriority);
+ }
+}
+
+/*!
+ Marks the region of the widget as dirty (if not already marked as dirty) and
+ posts an UpdateRequest event to the top-level widget (if not already posted).
+
+ If updateImmediately is true, the event is sent immediately instead of posted.
+
+ If invalidateBuffer is true, all widgets intersecting with the region will be dirty.
+
+ If the widget paints directly on screen, the event is sent to the widget
+ instead of the top-level widget, and invalidateBuffer is completely ignored.
+
+ ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
+*/
+void QWidgetBackingStore::markDirty(const QRegion &rgn, QWidget *widget, bool updateImmediately,
+ bool invalidateBuffer)
+{
+ Q_ASSERT(tlw->d_func()->extra);
+ Q_ASSERT(tlw->d_func()->extra->topextra);
+ Q_ASSERT(!tlw->d_func()->extra->topextra->inTopLevelResize);
+ Q_ASSERT(widget->isVisible() && widget->updatesEnabled());
+ Q_ASSERT(widget->window() == tlw);
+ Q_ASSERT(!rgn.isEmpty());
+
+#ifndef QT_NO_GRAPHICSEFFECT
+ widget->d_func()->invalidateGraphicsEffectsRecursively();
+#endif //QT_NO_GRAPHICSEFFECT
+
+ if (widget->d_func()->paintOnScreen()) {
+ if (widget->d_func()->dirty.isEmpty()) {
+ widget->d_func()->dirty = rgn;
+ sendUpdateRequest(widget, updateImmediately);
+ return;
+ } else if (qt_region_strictContains(widget->d_func()->dirty, widget->rect())) {
+ if (updateImmediately)
+ sendUpdateRequest(widget, updateImmediately);
+ return; // Already dirty.
+ }
+
+ const bool eventAlreadyPosted = !widget->d_func()->dirty.isEmpty();
+ widget->d_func()->dirty += rgn;
+ if (!eventAlreadyPosted || updateImmediately)
+ sendUpdateRequest(widget, updateImmediately);
+ return;
+ }
+
+ if (fullUpdatePending) {
+ if (updateImmediately)
+ sendUpdateRequest(tlw, updateImmediately);
+ return;
+ }
+
+ if (!windowSurface->hasFeature(QWindowSurface::PartialUpdates)) {
+ fullUpdatePending = true;
+ sendUpdateRequest(tlw, updateImmediately);
+ return;
+ }
+
+ const QPoint offset = widget->mapTo(tlw, QPoint());
+ const QRect widgetRect = widget->d_func()->effectiveRectFor(widget->rect());
+ if (qt_region_strictContains(dirty, widgetRect.translated(offset))) {
+ if (updateImmediately)
+ sendUpdateRequest(tlw, updateImmediately);
+ return; // Already dirty.
+ }
+
+ if (invalidateBuffer) {
+ const bool eventAlreadyPosted = !dirty.isEmpty();
+#ifndef QT_NO_GRAPHICSEFFECT
+ if (widget->d_func()->graphicsEffect)
+ dirty += widget->d_func()->effectiveRectFor(rgn.boundingRect()).translated(offset);
+ else
+#endif //QT_NO_GRAPHICSEFFECT
+ dirty += rgn.translated(offset);
+ if (!eventAlreadyPosted || updateImmediately)
+ sendUpdateRequest(tlw, updateImmediately);
+ return;
+ }
+
+ if (dirtyWidgets.isEmpty()) {
+ addDirtyWidget(widget, rgn);
+ sendUpdateRequest(tlw, updateImmediately);
+ return;
+ }
+
+ if (widget->d_func()->inDirtyList) {
+ if (!qt_region_strictContains(widget->d_func()->dirty, widgetRect)) {
+#ifndef QT_NO_GRAPHICSEFFECT
+ if (widget->d_func()->graphicsEffect)
+ widget->d_func()->dirty += widget->d_func()->effectiveRectFor(rgn.boundingRect());
+ else
+#endif //QT_NO_GRAPHICSEFFECT
+ widget->d_func()->dirty += rgn;
+ }
+ } else {
+ addDirtyWidget(widget, rgn);
+ }
+
+ if (updateImmediately)
+ sendUpdateRequest(tlw, updateImmediately);
+}
+
+/*!
+ This function is equivalent to calling markDirty(QRegion(rect), ...), but
+ is more efficient as it eliminates QRegion operations/allocations and can
+ use the rect more precisely for additional cut-offs.
+
+ ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
+*/
+void QWidgetBackingStore::markDirty(const QRect &rect, QWidget *widget, bool updateImmediately,
+ bool invalidateBuffer)
+{
+ Q_ASSERT(tlw->d_func()->extra);
+ Q_ASSERT(tlw->d_func()->extra->topextra);
+ Q_ASSERT(!tlw->d_func()->extra->topextra->inTopLevelResize);
+ Q_ASSERT(widget->isVisible() && widget->updatesEnabled());
+ Q_ASSERT(widget->window() == tlw);
+ Q_ASSERT(!rect.isEmpty());
+
+#ifndef QT_NO_GRAPHICSEFFECT
+ widget->d_func()->invalidateGraphicsEffectsRecursively();
+#endif //QT_NO_GRAPHICSEFFECT
+
+ if (widget->d_func()->paintOnScreen()) {
+ if (widget->d_func()->dirty.isEmpty()) {
+ widget->d_func()->dirty = QRegion(rect);
+ sendUpdateRequest(widget, updateImmediately);
+ return;
+ } else if (qt_region_strictContains(widget->d_func()->dirty, rect)) {
+ if (updateImmediately)
+ sendUpdateRequest(widget, updateImmediately);
+ return; // Already dirty.
+ }
+
+ const bool eventAlreadyPosted = !widget->d_func()->dirty.isEmpty();
+ widget->d_func()->dirty += rect;
+ if (!eventAlreadyPosted || updateImmediately)
+ sendUpdateRequest(widget, updateImmediately);
+ return;
+ }
+
+ if (fullUpdatePending) {
+ if (updateImmediately)
+ sendUpdateRequest(tlw, updateImmediately);
+ return;
+ }
+
+ if (!windowSurface->hasFeature(QWindowSurface::PartialUpdates)) {
+ fullUpdatePending = true;
+ sendUpdateRequest(tlw, updateImmediately);
+ return;
+ }
+
+ const QRect widgetRect = widget->d_func()->effectiveRectFor(rect);
+ const QRect translatedRect(widgetRect.translated(widget->mapTo(tlw, QPoint())));
+ if (qt_region_strictContains(dirty, translatedRect)) {
+ if (updateImmediately)
+ sendUpdateRequest(tlw, updateImmediately);
+ return; // Already dirty
+ }
+
+ if (invalidateBuffer) {
+ const bool eventAlreadyPosted = !dirty.isEmpty();
+ dirty += translatedRect;
+ if (!eventAlreadyPosted || updateImmediately)
+ sendUpdateRequest(tlw, updateImmediately);
+ return;
+ }
+
+ if (dirtyWidgets.isEmpty()) {
+ addDirtyWidget(widget, rect);
+ sendUpdateRequest(tlw, updateImmediately);
+ return;
+ }
+
+ if (widget->d_func()->inDirtyList) {
+ if (!qt_region_strictContains(widget->d_func()->dirty, widgetRect))
+ widget->d_func()->dirty += widgetRect;
+ } else {
+ addDirtyWidget(widget, rect);
+ }
+
+ if (updateImmediately)
+ sendUpdateRequest(tlw, updateImmediately);
+}
+
+/*!
+ Marks the \a region of the \a widget as dirty on screen. The \a region will be copied from
+ the backing store to the \a widget's native parent next time flush() is called.
+
+ Paint on screen widgets are ignored.
+*/
+void QWidgetBackingStore::markDirtyOnScreen(const QRegion &region, QWidget *widget, const QPoint &topLevelOffset)
+{
+ if (!widget || widget->d_func()->paintOnScreen() || region.isEmpty())
+ return;
+
+#if defined(Q_WS_QWS) || defined(Q_WS_MAC)
+ if (!widget->testAttribute(Qt::WA_WState_InPaintEvent))
+ dirtyOnScreen += region.translated(topLevelOffset);
+ return;
+#endif
+
+ // Top-level.
+ if (widget == tlw) {
+ if (!widget->testAttribute(Qt::WA_WState_InPaintEvent))
+ dirtyOnScreen += region;
+ return;
+ }
+
+ // Alien widgets.
+ if (!widget->internalWinId() && !widget->isWindow()) {
+ QWidget *nativeParent = widget->nativeParentWidget(); // Alien widgets with the top-level as the native parent (common case).
+ if (nativeParent == tlw) {
+ if (!widget->testAttribute(Qt::WA_WState_InPaintEvent))
+ dirtyOnScreen += region.translated(topLevelOffset);
+ return;
+ }
+
+ // Alien widgets with native parent != tlw.
+ QWidgetPrivate *nativeParentPrivate = nativeParent->d_func();
+ if (!nativeParentPrivate->needsFlush)
+ nativeParentPrivate->needsFlush = new QRegion;
+ const QPoint nativeParentOffset = widget->mapTo(nativeParent, QPoint());
+ *nativeParentPrivate->needsFlush += region.translated(nativeParentOffset);
+ appendDirtyOnScreenWidget(nativeParent);
+ return;
+ }
+
+ // Native child widgets.
+ QWidgetPrivate *widgetPrivate = widget->d_func();
+ if (!widgetPrivate->needsFlush)
+ widgetPrivate->needsFlush = new QRegion;
+ *widgetPrivate->needsFlush += region;
+ appendDirtyOnScreenWidget(widget);
+}
+
+void QWidgetBackingStore::removeDirtyWidget(QWidget *w)
+{
+ if (!w)
+ return;
+
+ dirtyWidgetsRemoveAll(w);
+ dirtyOnScreenWidgetsRemoveAll(w);
+ resetWidget(w);
+
+ QWidgetPrivate *wd = w->d_func();
+ const int n = wd->children.count();
+ for (int i = 0; i < n; ++i) {
+ if (QWidget *child = qobject_cast<QWidget*>(wd->children.at(i)))
+ removeDirtyWidget(child);
+ }
+}
+
+#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
+bool QWidgetBackingStore::hasDirtyWindowDecoration() const
+{
+ QTLWExtra *tlwExtra = tlw->d_func()->maybeTopData();
+ if (tlwExtra && tlwExtra->qwsManager)
+ return !tlwExtra->qwsManager->d_func()->dirtyRegions.isEmpty();
+ return false;
+}
+
+void QWidgetBackingStore::paintWindowDecoration()
+{
+ if (!hasDirtyWindowDecoration())
+ return;
+
+ QDecoration &decoration = QApplication::qwsDecoration();
+ const QRect decorationRect = tlw->rect();
+ QRegion decorationRegion = decoration.region(tlw, decorationRect);
+
+ QWSManagerPrivate *managerPrivate = tlw->d_func()->topData()->qwsManager->d_func();
+ const bool doClipping = !managerPrivate->entireDecorationNeedsRepaint
+ && !managerPrivate->dirtyClip.isEmpty();
+
+ if (doClipping) {
+ decorationRegion &= static_cast<QWSWindowSurface *>(windowSurface)->clipRegion();
+ decorationRegion &= managerPrivate->dirtyClip;
+ }
+
+ if (decorationRegion.isEmpty())
+ return;
+
+ //### The QWS decorations do not always paint the pixels they promise to paint.
+ // This causes painting problems with QWSMemorySurface. Since none of the other
+ // window surfaces actually use the region, passing an empty region is a safe
+ // workaround.
+
+ windowSurface->beginPaint(QRegion());
+
+ QPaintEngine *engine = windowSurface->paintDevice()->paintEngine();
+ Q_ASSERT(engine);
+ const QRegion oldSystemClip(engine->systemClip());
+ engine->setSystemClip(decorationRegion.translated(tlwOffset));
+
+ QPainter painter(windowSurface->paintDevice());
+ painter.setFont(QApplication::font());
+ painter.translate(tlwOffset);
+
+ const int numDirty = managerPrivate->dirtyRegions.size();
+ for (int i = 0; i < numDirty; ++i) {
+ const int area = managerPrivate->dirtyRegions.at(i);
+
+ QRegion clipRegion = decoration.region(tlw, decorationRect, area);
+ if (!clipRegion.isEmpty()) {
+ // Decoration styles changes the clip and assumes the old clip is non-empty,
+ // so we have to set it, but in theory it shouldn't be required.
+ painter.setClipRegion(clipRegion);
+ decoration.paint(&painter, tlw, area, managerPrivate->dirtyStates.at(i));
+ }
+ }
+ markDirtyOnScreen(decorationRegion, tlw, QPoint());
+
+ painter.end();
+ windowSurface->endPaint(decorationRegion);
+ managerPrivate->clearDirtyRegions();
+ engine->setSystemClip(oldSystemClip);
+}
+#endif
+
+void QWidgetBackingStore::updateLists(QWidget *cur)
+{
+ if (!cur)
+ return;
+
+ QList<QObject*> children = cur->children();
+ for (int i = 0; i < children.size(); ++i) {
+ QWidget *child = qobject_cast<QWidget*>(children.at(i));
+ if (!child)
+ continue;
+
+ updateLists(child);
+ }
+
+ if (cur->testAttribute(Qt::WA_StaticContents))
+ addStaticWidget(cur);
+
+#ifdef Q_BACKINGSTORE_SUBSURFACES
+ QTLWExtra *extra = cur->d_func()->maybeTopData();
+ if (extra && extra->windowSurface && cur != tlw)
+ subSurfaces.append(extra->windowSurface);
+#endif
+}
+
+QWidgetBackingStore::QWidgetBackingStore(QWidget *topLevel)
+ : tlw(topLevel), dirtyOnScreenWidgets(0), hasDirtyFromPreviousSync(false)
+ , fullUpdatePending(0)
+{
+ windowSurface = tlw->windowSurface();
+ if (!windowSurface)
+ windowSurface = topLevel->d_func()->createDefaultWindowSurface();
+
+ // The QWindowSurface constructor will call QWidget::setWindowSurface(),
+ // but automatically created surfaces should not be added to the topdata.
+#ifdef Q_BACKINGSTORE_SUBSURFACES
+ Q_ASSERT(topLevel->d_func()->topData()->windowSurface == windowSurface);
+#endif
+ topLevel->d_func()->topData()->windowSurface = 0;
+
+ // Ensure all existing subsurfaces and static widgets are added to their respective lists.
+ updateLists(topLevel);
+}
+
+QWidgetBackingStore::~QWidgetBackingStore()
+{
+ for (int c = 0; c < dirtyWidgets.size(); ++c) {
+ resetWidget(dirtyWidgets.at(c));
+ }
+
+ delete windowSurface;
+ windowSurface = 0;
+ delete dirtyOnScreenWidgets;
+ dirtyOnScreenWidgets = 0;
+}
+
+//parent's coordinates; move whole rect; update parent and widget
+//assume the screen blt has already been done, so we don't need to refresh that part
+void QWidgetPrivate::moveRect(const QRect &rect, int dx, int dy)
+{
+ Q_Q(QWidget);
+ if (!q->isVisible() || (dx == 0 && dy == 0))
+ return;
+
+ QWidget *tlw = q->window();
+ QTLWExtra* x = tlw->d_func()->topData();
+ if (x->inTopLevelResize)
+ return;
+
+ static int accelEnv = -1;
+ if (accelEnv == -1) {
+ accelEnv = qgetenv("QT_NO_FAST_MOVE").toInt() == 0;
+ }
+
+ QWidget *pw = q->parentWidget();
+ QPoint toplevelOffset = pw->mapTo(tlw, QPoint());
+ QWidgetPrivate *pd = pw->d_func();
+ QRect clipR(pd->clipRect());
+#ifdef Q_WS_QWS
+ QWidgetBackingStore *wbs = x->backingStore.data();
+ QWSWindowSurface *surface = static_cast<QWSWindowSurface*>(wbs->windowSurface);
+ clipR = clipR.intersected(surface->clipRegion().translated(-toplevelOffset).boundingRect());
+#endif
+ const QRect newRect(rect.translated(dx, dy));
+ QRect destRect = rect.intersected(clipR);
+ if (destRect.isValid())
+ destRect = destRect.translated(dx, dy).intersected(clipR);
+ const QRect sourceRect(destRect.translated(-dx, -dy));
+ const QRect parentRect(rect & clipR);
+
+ bool accelerateMove = accelEnv && isOpaque
+#ifndef QT_NO_GRAPHICSVIEW
+ // No accelerate move for proxy widgets.
+ && !tlw->d_func()->extra->proxyWidget
+#endif
+ && !isOverlapped(sourceRect) && !isOverlapped(destRect);
+
+ if (!accelerateMove) {
+ QRegion parentR(effectiveRectFor(parentRect));
+ if (!extra || !extra->hasMask) {
+ parentR -= newRect;
+ } else {
+ // invalidateBuffer() excludes anything outside the mask
+ parentR += newRect & clipR;
+ }
+ pd->invalidateBuffer(parentR);
+ invalidateBuffer((newRect & clipR).translated(-data.crect.topLeft()));
+ } else {
+
+ QWidgetBackingStore *wbs = x->backingStore.data();
+ QRegion childExpose(newRect & clipR);
+
+ if (sourceRect.isValid() && wbs->bltRect(sourceRect, dx, dy, pw))
+ childExpose -= destRect;
+
+ if (!pw->updatesEnabled())
+ return;
+
+ const bool childUpdatesEnabled = q->updatesEnabled();
+ if (childUpdatesEnabled && !childExpose.isEmpty()) {
+ childExpose.translate(-data.crect.topLeft());
+ wbs->markDirty(childExpose, q);
+ isMoved = true;
+ }
+
+ QRegion parentExpose(parentRect);
+ parentExpose -= newRect;
+ if (extra && extra->hasMask)
+ parentExpose += QRegion(newRect) - extra->mask.translated(data.crect.topLeft());
+
+ if (!parentExpose.isEmpty()) {
+ wbs->markDirty(parentExpose, pw);
+ pd->isMoved = true;
+ }
+
+ if (childUpdatesEnabled) {
+ QRegion needsFlush(sourceRect);
+ needsFlush += destRect;
+ wbs->markDirtyOnScreen(needsFlush, pw, toplevelOffset);
+ }
+ }
+}
+
+//widget's coordinates; scroll within rect; only update widget
+void QWidgetPrivate::scrollRect(const QRect &rect, int dx, int dy)
+{
+ Q_Q(QWidget);
+ QWidget *tlw = q->window();
+ QTLWExtra* x = tlw->d_func()->topData();
+ if (x->inTopLevelResize)
+ return;
+
+ QWidgetBackingStore *wbs = x->backingStore.data();
+ if (!wbs)
+ return;
+
+ static int accelEnv = -1;
+ if (accelEnv == -1) {
+ accelEnv = qgetenv("QT_NO_FAST_SCROLL").toInt() == 0;
+ }
+
+ QRect scrollRect = rect & clipRect();
+ bool overlapped = false;
+ bool accelerateScroll = accelEnv && isOpaque
+ && !(overlapped = isOverlapped(scrollRect.translated(data.crect.topLeft())));
+
+#if defined(Q_WS_QWS)
+ QWSWindowSurface *surface;
+ surface = static_cast<QWSWindowSurface*>(wbs->windowSurface);
+
+ if (accelerateScroll && !surface->isBuffered()) {
+ const QRegion surfaceClip = surface->clipRegion();
+ const QRegion outsideClip = QRegion(rect) - surfaceClip;
+ if (!outsideClip.isEmpty()) {
+ const QVector<QRect> clipped = (surfaceClip & rect).rects();
+ if (clipped.size() < 8) {
+ for (int i = 0; i < clipped.size(); ++i)
+ this->scrollRect(clipped.at(i), dx, dy);
+ return;
+ } else {
+ accelerateScroll = false;
+ }
+ }
+ }
+#endif // Q_WS_QWS
+
+ if (!accelerateScroll) {
+ if (overlapped) {
+ QRegion region(scrollRect);
+ subtractOpaqueSiblings(region);
+ invalidateBuffer(region);
+ }else {
+ invalidateBuffer(scrollRect);
+ }
+ } else {
+ const QPoint toplevelOffset = q->mapTo(tlw, QPoint());
+#ifdef Q_WS_QWS
+ QWSWindowSurface *surface = static_cast<QWSWindowSurface*>(wbs->windowSurface);
+ const QRegion clip = surface->clipRegion().translated(-toplevelOffset) & scrollRect;
+ const QRect clipBoundingRect = clip.boundingRect();
+ scrollRect &= clipBoundingRect;
+#endif
+ const QRect destRect = scrollRect.translated(dx, dy) & scrollRect;
+ const QRect sourceRect = destRect.translated(-dx, -dy);
+
+ QRegion childExpose(scrollRect);
+ if (sourceRect.isValid()) {
+ if (wbs->bltRect(sourceRect, dx, dy, q))
+ childExpose -= destRect;
+ }
+
+ if (inDirtyList) {
+ if (rect == q->rect()) {
+ dirty.translate(dx, dy);
+ } else {
+ QRegion dirtyScrollRegion = dirty.intersected(scrollRect);
+ if (!dirtyScrollRegion.isEmpty()) {
+ dirty -= dirtyScrollRegion;
+ dirtyScrollRegion.translate(dx, dy);
+ dirty += dirtyScrollRegion;
+ }
+ }
+ }
+
+ if (!q->updatesEnabled())
+ return;
+
+ if (!childExpose.isEmpty()) {
+ wbs->markDirty(childExpose, q);
+ isScrolled = true;
+ }
+
+ // Instead of using native scroll-on-screen, we copy from
+ // backingstore, giving only one screen update for each
+ // scroll, and a solid appearance
+ wbs->markDirtyOnScreen(destRect, q, toplevelOffset);
+ }
+}
+
+static inline bool discardSyncRequest(QWidget *tlw, QTLWExtra *tlwExtra)
+{
+ if (!tlw || !tlwExtra)
+ return true;
+
+#ifdef Q_WS_X11
+ // Delay the sync until we get an Expose event from X11 (initial show).
+ // Qt::WA_Mapped is set to true, but the actual mapping has not yet occurred.
+ // However, we must repaint immediately regardless of the state if someone calls repaint().
+ if (tlwExtra->waitingForMapNotify && !tlwExtra->inRepaint)
+ return true;
+#endif
+
+ if (!tlw->testAttribute(Qt::WA_Mapped))
+ return true;
+
+ if (!tlw->isVisible()
+#ifndef Q_WS_X11
+ // If we're minimized on X11, WA_Mapped will be false and we
+ // will return in the case above. Some window managers on X11
+ // sends us the PropertyNotify to change the minimized state
+ // *AFTER* we've received the expose event, which is baaad.
+ || tlw->isMinimized()
+#endif
+ )
+ return true;
+
+ return false;
+}
+
+/*!
+ Synchronizes the \a exposedRegion of the \a exposedWidget with the backing store.
+
+ If there's nothing to repaint, the area is flushed and painting does not occur;
+ otherwise the area is marked as dirty on screen and will be flushed right after
+ we are done with all painting.
+*/
+void QWidgetBackingStore::sync(QWidget *exposedWidget, const QRegion &exposedRegion)
+{
+ QTLWExtra *tlwExtra = tlw->d_func()->maybeTopData();
+ if (discardSyncRequest(tlw, tlwExtra) || tlwExtra->inTopLevelResize)
+ return;
+
+ if (!exposedWidget || !exposedWidget->internalWinId() || !exposedWidget->isVisible()
+ || !exposedWidget->updatesEnabled() || exposedRegion.isEmpty()) {
+ return;
+ }
+
+ // If there's no preserved contents support we always need
+ // to do a full repaint before flushing
+ if (!windowSurface->hasFeature(QWindowSurface::PreservedContents))
+ fullUpdatePending = true;
+
+ // Nothing to repaint.
+ if (!isDirty()) {
+ qt_flush(exposedWidget, exposedRegion, windowSurface, tlw, tlwOffset);
+ return;
+ }
+
+ if (exposedWidget != tlw)
+ markDirtyOnScreen(exposedRegion, exposedWidget, exposedWidget->mapTo(tlw, QPoint()));
+ else
+ markDirtyOnScreen(exposedRegion, exposedWidget, QPoint());
+ sync();
+}
+
+/*!
+ Synchronizes the backing store, i.e. dirty areas are repainted and flushed.
+*/
+void QWidgetBackingStore::sync()
+{
+ QTLWExtra *tlwExtra = tlw->d_func()->maybeTopData();
+ if (discardSyncRequest(tlw, tlwExtra)) {
+ // If the top-level is minimized, it's not visible on the screen so we can delay the
+ // update until it's shown again. In order to do that we must keep the dirty states.
+ // These will be cleared when we receive the first expose after showNormal().
+ // However, if the widget is not visible (isVisible() returns false), everything will
+ // be invalidated once the widget is shown again, so clear all dirty states.
+ if (!tlw->isVisible()) {
+ dirty = QRegion();
+ for (int i = 0; i < dirtyWidgets.size(); ++i)
+ resetWidget(dirtyWidgets.at(i));
+ dirtyWidgets.clear();
+ fullUpdatePending = false;
+ }
+ return;
+ }
+
+ const bool updatesDisabled = !tlw->updatesEnabled();
+ bool repaintAllWidgets = false;
+
+ const bool inTopLevelResize = tlwExtra->inTopLevelResize;
+ const QRect tlwRect(topLevelRect());
+#ifdef Q_WS_QPA
+ const QRect surfaceGeometry(tlwRect.topLeft(), windowSurface->size());
+#else
+ const QRect surfaceGeometry(windowSurface->geometry());
+#endif
+ if ((fullUpdatePending || inTopLevelResize || surfaceGeometry.size() != tlwRect.size()) && !updatesDisabled) {
+ if (hasStaticContents()) {
+ // Repaint existing dirty area and newly visible area.
+ const QRect clipRect(0, 0, surfaceGeometry.width(), surfaceGeometry.height());
+ const QRegion staticRegion(staticContents(0, clipRect));
+ QRegion newVisible(0, 0, tlwRect.width(), tlwRect.height());
+ newVisible -= staticRegion;
+ dirty += newVisible;
+ windowSurface->setStaticContents(staticRegion);
+ } else {
+ // Repaint everything.
+ dirty = QRegion(0, 0, tlwRect.width(), tlwRect.height());
+ for (int i = 0; i < dirtyWidgets.size(); ++i)
+ resetWidget(dirtyWidgets.at(i));
+ dirtyWidgets.clear();
+ repaintAllWidgets = true;
+ }
+ }
+
+#ifdef Q_WS_QPA
+ if (inTopLevelResize || surfaceGeometry.size() != tlwRect.size())
+ windowSurface->resize(tlwRect.size());
+#else
+ if (inTopLevelResize || surfaceGeometry != tlwRect)
+ windowSurface->setGeometry(tlwRect);
+#endif
+
+ if (updatesDisabled)
+ return;
+
+ if (hasDirtyFromPreviousSync)
+ dirty += dirtyFromPreviousSync;
+
+ // Contains everything that needs repaint.
+ QRegion toClean(dirty);
+
+ // Loop through all update() widgets and remove them from the list before they are
+ // painted (in case someone calls update() in paintEvent). If the widget is opaque
+ // and does not have transparent overlapping siblings, append it to the
+ // opaqueNonOverlappedWidgets list and paint it directly without composition.
+ QVarLengthArray<QWidget *, 32> opaqueNonOverlappedWidgets;
+ for (int i = 0; i < dirtyWidgets.size(); ++i) {
+ QWidget *w = dirtyWidgets.at(i);
+ QWidgetPrivate *wd = w->d_func();
+ if (wd->data.in_destructor)
+ continue;
+
+ // Clip with mask() and clipRect().
+ wd->dirty &= wd->clipRect();
+ wd->clipToEffectiveMask(wd->dirty);
+
+ // Subtract opaque siblings and children.
+ bool hasDirtySiblingsAbove = false;
+ // We know for sure that the widget isn't overlapped if 'isMoved' is true.
+ if (!wd->isMoved)
+ wd->subtractOpaqueSiblings(wd->dirty, &hasDirtySiblingsAbove);
+ // Scrolled and moved widgets must draw all children.
+ if (!wd->isScrolled && !wd->isMoved)
+ wd->subtractOpaqueChildren(wd->dirty, w->rect());
+
+ if (wd->dirty.isEmpty()) {
+ resetWidget(w);
+ continue;
+ }
+
+ const QRegion widgetDirty(w != tlw ? wd->dirty.translated(w->mapTo(tlw, QPoint()))
+ : wd->dirty);
+ toClean += widgetDirty;
+
+#ifndef QT_NO_GRAPHICSVIEW
+ if (tlw->d_func()->extra->proxyWidget) {
+ resetWidget(w);
+ continue;
+ }
+#endif
+
+ if (!hasDirtySiblingsAbove && wd->isOpaque && !dirty.intersects(widgetDirty.boundingRect())) {
+ opaqueNonOverlappedWidgets.append(w);
+ } else {
+ resetWidget(w);
+ dirty += widgetDirty;
+ }
+ }
+ dirtyWidgets.clear();
+
+ fullUpdatePending = false;
+
+ if (toClean.isEmpty()) {
+ // Nothing to repaint. However, we might have newly exposed areas on the
+ // screen if this function was called from sync(QWidget *, QRegion)), so
+ // we have to make sure those are flushed.
+ flush();
+ return;
+ }
+
+#ifndef QT_NO_GRAPHICSVIEW
+ if (tlw->d_func()->extra->proxyWidget) {
+ updateStaticContentsSize();
+ dirty = QRegion();
+ const QVector<QRect> rects(toClean.rects());
+ for (int i = 0; i < rects.size(); ++i)
+ tlw->d_func()->extra->proxyWidget->update(rects.at(i));
+ return;
+ }
+#endif
+
+#ifndef Q_BACKINGSTORE_SUBSURFACES
+ BeginPaintInfo beginPaintInfo;
+ beginPaint(toClean, tlw, windowSurface, &beginPaintInfo);
+ if (beginPaintInfo.nothingToPaint) {
+ for (int i = 0; i < opaqueNonOverlappedWidgets.size(); ++i)
+ resetWidget(opaqueNonOverlappedWidgets[i]);
+ dirty = QRegion();
+ return;
+ }
+#endif
+
+ // Must do this before sending any paint events because
+ // the size may change in the paint event.
+ updateStaticContentsSize();
+ const QRegion dirtyCopy(dirty);
+ dirty = QRegion();
+
+ // Paint opaque non overlapped widgets.
+ for (int i = 0; i < opaqueNonOverlappedWidgets.size(); ++i) {
+ QWidget *w = opaqueNonOverlappedWidgets[i];
+ QWidgetPrivate *wd = w->d_func();
+
+ int flags = QWidgetPrivate::DrawRecursive;
+ // Scrolled and moved widgets must draw all children.
+ if (!wd->isScrolled && !wd->isMoved)
+ flags |= QWidgetPrivate::DontDrawOpaqueChildren;
+ if (w == tlw)
+ flags |= QWidgetPrivate::DrawAsRoot;
+
+ QRegion toBePainted(wd->dirty);
+ resetWidget(w);
+
+#ifdef Q_BACKINGSTORE_SUBSURFACES
+ QWindowSurface *subSurface = w->windowSurface();
+ BeginPaintInfo beginPaintInfo;
+
+ QPoint off = w->mapTo(tlw, QPoint());
+ toBePainted.translate(off);
+ beginPaint(toBePainted, w, subSurface, &beginPaintInfo, true);
+ toBePainted.translate(-off);
+
+ if (beginPaintInfo.nothingToPaint)
+ continue;
+
+ if (beginPaintInfo.windowSurfaceRecreated) {
+ // Eep the window surface has changed. The old one may have been
+ // deleted, in which case we will segfault on the call to
+ // painterOffset() below. Use the new window surface instead.
+ subSurface = w->windowSurface();
+ }
+
+ QPoint offset(tlwOffset);
+ if (subSurface == windowSurface)
+ offset += w->mapTo(tlw, QPoint());
+ else
+ offset = static_cast<QWSWindowSurface*>(subSurface)->painterOffset();
+ wd->drawWidget(subSurface->paintDevice(), toBePainted, offset, flags, 0, this);
+
+ endPaint(toBePainted, subSurface, &beginPaintInfo);
+#else
+ QPoint offset(tlwOffset);
+ if (w != tlw)
+ offset += w->mapTo(tlw, QPoint());
+ wd->drawWidget(windowSurface->paintDevice(), toBePainted, offset, flags, 0, this);
+#endif
+ }
+
+ // Paint the rest with composition.
+#ifndef Q_BACKINGSTORE_SUBSURFACES
+ if (repaintAllWidgets || !dirtyCopy.isEmpty()) {
+ const int flags = QWidgetPrivate::DrawAsRoot | QWidgetPrivate::DrawRecursive;
+ tlw->d_func()->drawWidget(windowSurface->paintDevice(), dirtyCopy, tlwOffset, flags, 0, this);
+ }
+
+ endPaint(toClean, windowSurface, &beginPaintInfo);
+#else
+ if (!repaintAllWidgets && dirtyCopy.isEmpty())
+ return; // Nothing more to paint.
+
+ QList<QWindowSurface *> surfaceList(subSurfaces);
+ surfaceList.prepend(windowSurface);
+ const QRect dirtyBoundingRect(dirtyCopy.boundingRect());
+
+ // Loop through all window surfaces (incl. the top-level surface) and
+ // repaint those intersecting with the bounding rect of the dirty region.
+ for (int i = 0; i < surfaceList.size(); ++i) {
+ QWindowSurface *subSurface = surfaceList.at(i);
+ QWidget *w = subSurface->window();
+ QWidgetPrivate *wd = w->d_func();
+
+ const QRect clipRect = wd->clipRect().translated(w->mapTo(tlw, QPoint()));
+ if (!qRectIntersects(dirtyBoundingRect, clipRect))
+ continue;
+
+ toClean = dirtyCopy;
+ BeginPaintInfo beginPaintInfo;
+ beginPaint(toClean, w, subSurface, &beginPaintInfo);
+ if (beginPaintInfo.nothingToPaint)
+ continue;
+
+ if (beginPaintInfo.windowSurfaceRecreated) {
+ // Eep the window surface has changed. The old one may have been
+ // deleted, in which case we will segfault on the call to
+ // painterOffset() below. Use the new window surface instead.
+ subSurface = w->windowSurface();
+ }
+
+ int flags = QWidgetPrivate::DrawRecursive;
+ if (w == tlw)
+ flags |= QWidgetPrivate::DrawAsRoot;
+ const QPoint painterOffset = static_cast<QWSWindowSurface*>(subSurface)->painterOffset();
+ wd->drawWidget(subSurface->paintDevice(), toClean, painterOffset, flags, 0, this);
+
+ endPaint(toClean, subSurface, &beginPaintInfo);
+ }
+#endif
+}
+
+/*!
+ Flushes the contents of the backing store into the top-level widget.
+ If the \a widget is non-zero, the content is flushed to the \a widget.
+ If the \a surface is non-zero, the content of the \a surface is flushed.
+*/
+void QWidgetBackingStore::flush(QWidget *widget, QWindowSurface *surface)
+{
+#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
+ paintWindowDecoration();
+#endif
+
+ if (!dirtyOnScreen.isEmpty()) {
+ QWidget *target = widget ? widget : tlw;
+ QWindowSurface *source = surface ? surface : windowSurface;
+ qt_flush(target, dirtyOnScreen, source, tlw, tlwOffset);
+ dirtyOnScreen = QRegion();
+ }
+
+ if (!dirtyOnScreenWidgets || dirtyOnScreenWidgets->isEmpty())
+ return;
+
+ for (int i = 0; i < dirtyOnScreenWidgets->size(); ++i) {
+ QWidget *w = dirtyOnScreenWidgets->at(i);
+ QWidgetPrivate *wd = w->d_func();
+ Q_ASSERT(wd->needsFlush);
+ qt_flush(w, *wd->needsFlush, windowSurface, tlw, tlwOffset);
+ *wd->needsFlush = QRegion();
+ }
+ dirtyOnScreenWidgets->clear();
+}
+
+static inline bool discardInvalidateBufferRequest(QWidget *widget, QTLWExtra *tlwExtra)
+{
+ Q_ASSERT(widget);
+ if (QApplication::closingDown())
+ return true;
+
+ if (!tlwExtra || tlwExtra->inTopLevelResize || !tlwExtra->backingStore)
+ return true;
+
+ if (!widget->isVisible() || !widget->updatesEnabled())
+ return true;
+
+ return false;
+}
+
+/*!
+ Invalidates the buffer when the widget is resized.
+ Static areas are never invalidated unless absolutely needed.
+*/
+void QWidgetPrivate::invalidateBuffer_resizeHelper(const QPoint &oldPos, const QSize &oldSize)
+{
+ Q_Q(QWidget);
+ Q_ASSERT(!q->isWindow());
+ Q_ASSERT(q->parentWidget());
+
+ const bool staticContents = q->testAttribute(Qt::WA_StaticContents);
+ const bool sizeDecreased = (data.crect.width() < oldSize.width())
+ || (data.crect.height() < oldSize.height());
+
+ const QPoint offset(data.crect.x() - oldPos.x(), data.crect.y() - oldPos.y());
+ const bool parentAreaExposed = !offset.isNull() || sizeDecreased;
+ const QRect newWidgetRect(q->rect());
+ const QRect oldWidgetRect(0, 0, oldSize.width(), oldSize.height());
+
+ if (!staticContents || graphicsEffect) {
+ QRegion staticChildren;
+ QWidgetBackingStore *bs = 0;
+ if (offset.isNull() && (bs = maybeBackingStore()))
+ staticChildren = bs->staticContents(q, oldWidgetRect);
+ const bool hasStaticChildren = !staticChildren.isEmpty();
+
+ if (hasStaticChildren) {
+ QRegion dirty(newWidgetRect);
+ dirty -= staticChildren;
+ invalidateBuffer(dirty);
+ } else {
+ // Entire widget needs repaint.
+ invalidateBuffer(newWidgetRect);
+ }
+
+ if (!parentAreaExposed)
+ return;
+
+ // Invalidate newly exposed area of the parent.
+ if (!graphicsEffect && extra && extra->hasMask) {
+ QRegion parentExpose(extra->mask.translated(oldPos));
+ parentExpose &= QRect(oldPos, oldSize);
+ if (hasStaticChildren)
+ parentExpose -= data.crect; // Offset is unchanged, safe to do this.
+ q->parentWidget()->d_func()->invalidateBuffer(parentExpose);
+ } else {
+ if (hasStaticChildren && !graphicsEffect) {
+ QRegion parentExpose(QRect(oldPos, oldSize));
+ parentExpose -= data.crect; // Offset is unchanged, safe to do this.
+ q->parentWidget()->d_func()->invalidateBuffer(parentExpose);
+ } else {
+ q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(QRect(oldPos, oldSize)));
+ }
+ }
+ return;
+ }
+
+ // Move static content to its new position.
+ if (!offset.isNull()) {
+ if (sizeDecreased) {
+ const QSize minSize(qMin(oldSize.width(), data.crect.width()),
+ qMin(oldSize.height(), data.crect.height()));
+ moveRect(QRect(oldPos, minSize), offset.x(), offset.y());
+ } else {
+ moveRect(QRect(oldPos, oldSize), offset.x(), offset.y());
+ }
+ }
+
+ // Invalidate newly visible area of the widget.
+ if (!sizeDecreased || !oldWidgetRect.contains(newWidgetRect)) {
+ QRegion newVisible(newWidgetRect);
+ newVisible -= oldWidgetRect;
+ invalidateBuffer(newVisible);
+ }
+
+ if (!parentAreaExposed)
+ return;
+
+ // Invalidate newly exposed area of the parent.
+ const QRect oldRect(oldPos, oldSize);
+ if (extra && extra->hasMask) {
+ QRegion parentExpose(oldRect);
+ parentExpose &= extra->mask.translated(oldPos);
+ parentExpose -= (extra->mask.translated(data.crect.topLeft()) & data.crect);
+ q->parentWidget()->d_func()->invalidateBuffer(parentExpose);
+ } else {
+ QRegion parentExpose(oldRect);
+ parentExpose -= data.crect;
+ q->parentWidget()->d_func()->invalidateBuffer(parentExpose);
+ }
+}
+
+/*!
+ Invalidates the \a rgn (in widget's coordinates) of the backing store, i.e.
+ all widgets intersecting with the region will be repainted when the backing store
+ is synced.
+
+ ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
+*/
+void QWidgetPrivate::invalidateBuffer(const QRegion &rgn)
+{
+ Q_Q(QWidget);
+
+ QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
+ if (discardInvalidateBufferRequest(q, tlwExtra) || rgn.isEmpty())
+ return;
+
+ QRegion wrgn(rgn);
+ wrgn &= clipRect();
+ if (!graphicsEffect && extra && extra->hasMask)
+ wrgn &= extra->mask;
+ if (wrgn.isEmpty())
+ return;
+
+ tlwExtra->backingStore->markDirty(wrgn, q, false, true);
+}
+
+/*!
+ This function is equivalent to calling invalidateBuffer(QRegion(rect), ...), but
+ is more efficient as it eliminates QRegion operations/allocations and can
+ use the rect more precisely for additional cut-offs.
+
+ ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
+*/
+void QWidgetPrivate::invalidateBuffer(const QRect &rect)
+{
+ Q_Q(QWidget);
+
+ QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
+ if (discardInvalidateBufferRequest(q, tlwExtra) || rect.isEmpty())
+ return;
+
+ QRect wRect(rect);
+ wRect &= clipRect();
+ if (wRect.isEmpty())
+ return;
+
+ if (graphicsEffect || !extra || !extra->hasMask) {
+ tlwExtra->backingStore->markDirty(wRect, q, false, true);
+ return;
+ }
+
+ QRegion wRgn(extra->mask);
+ wRgn &= wRect;
+ if (wRgn.isEmpty())
+ return;
+
+ tlwExtra->backingStore->markDirty(wRgn, q, false, true);
+}
+
+void QWidgetPrivate::repaint_sys(const QRegion &rgn)
+{
+ if (data.in_destructor)
+ return;
+
+ Q_Q(QWidget);
+ if (q->testAttribute(Qt::WA_StaticContents)) {
+ if (!extra)
+ createExtra();
+ extra->staticContentsSize = data.crect.size();
+ }
+
+#ifdef Q_WS_QPA //Dont even call q->p
+ QPaintEngine *engine = 0;
+#else
+ QPaintEngine *engine = q->paintEngine();
+#endif
+ // QGLWidget does not support partial updates if:
+ // 1) The context is double buffered
+ // 2) The context is single buffered and auto-fill background is enabled.
+ const bool noPartialUpdateSupport = (engine && (engine->type() == QPaintEngine::OpenGL
+ || engine->type() == QPaintEngine::OpenGL2))
+ && (usesDoubleBufferedGLContext || q->autoFillBackground());
+ QRegion toBePainted(noPartialUpdateSupport ? q->rect() : rgn);
+
+#ifdef Q_WS_MAC
+ // No difference between update() and repaint() on the Mac.
+ update_sys(toBePainted);
+ return;
+#endif
+
+ toBePainted &= clipRect();
+ clipToEffectiveMask(toBePainted);
+ if (toBePainted.isEmpty())
+ return; // Nothing to repaint.
+
+#ifndef QT_NO_PAINT_DEBUG
+ bool flushed = QWidgetBackingStore::flushPaint(q, toBePainted);
+#endif
+
+ drawWidget(q, toBePainted, QPoint(), QWidgetPrivate::DrawAsRoot | QWidgetPrivate::DrawPaintOnScreen, 0);
+
+#ifndef QT_NO_PAINT_DEBUG
+ if (flushed)
+ QWidgetBackingStore::unflushPaint(q, toBePainted);
+#endif
+
+ if (!q->testAttribute(Qt::WA_PaintOutsidePaintEvent) && q->paintingActive())
+ qWarning("QWidget::repaint: It is dangerous to leave painters active on a widget outside of the PaintEvent");
+}
+
+
+QT_END_NAMESPACE
diff --git a/src/gui/kernel/qbackingstore_p.h b/src/gui/kernel/qbackingstore_p.h
new file mode 100644
index 0000000000..05f4bfcb6c
--- /dev/null
+++ b/src/gui/kernel/qbackingstore_p.h
@@ -0,0 +1,278 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QBACKINGSTORE_P_H
+#define QBACKINGSTORE_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QDebug>
+#include <QtGui/qwidget.h>
+#include <private/qwidget_p.h>
+#include <private/qwindowsurface_p.h>
+#ifdef Q_WS_QWS
+#include <private/qwindowsurface_qws_p.h>
+#endif
+
+QT_BEGIN_NAMESPACE
+
+class QWindowSurface;
+
+struct BeginPaintInfo {
+ inline BeginPaintInfo() : wasFlushed(0), nothingToPaint(0), windowSurfaceRecreated(0) {}
+ uint wasFlushed : 1;
+ uint nothingToPaint : 1;
+ uint windowSurfaceRecreated : 1;
+};
+
+class Q_AUTOTEST_EXPORT QWidgetBackingStore
+{
+public:
+ QWidgetBackingStore(QWidget *t);
+ ~QWidgetBackingStore();
+
+ static void showYellowThing(QWidget *widget, const QRegion &rgn, int msec, bool);
+
+ void sync(QWidget *exposedWidget, const QRegion &exposedRegion);
+ void sync();
+ void flush(QWidget *widget = 0, QWindowSurface *surface = 0);
+
+ inline QPoint topLevelOffset() const { return tlwOffset; }
+
+ QWindowSurface *surface() const { return windowSurface; }
+
+ inline bool isDirty() const
+ {
+ return !(dirtyWidgets.isEmpty() && dirty.isEmpty() && !hasDirtyFromPreviousSync
+ && !fullUpdatePending
+#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
+ && !hasDirtyWindowDecoration()
+#endif
+ );
+ }
+
+ // ### Qt 4.6: Merge into a template function (after MSVC isn't supported anymore).
+ void markDirty(const QRegion &rgn, QWidget *widget, bool updateImmediately = false,
+ bool invalidateBuffer = false);
+ void markDirty(const QRect &rect, QWidget *widget, bool updateImmediately = false,
+ bool invalidateBuffer = false);
+
+private:
+ QWidget *tlw;
+ QRegion dirtyOnScreen; // needsFlush
+ QRegion dirty; // needsRepaint
+ QRegion dirtyFromPreviousSync;
+ QVector<QWidget *> dirtyWidgets;
+ QVector<QWidget *> *dirtyOnScreenWidgets;
+ QList<QWidget *> staticWidgets;
+ QWindowSurface *windowSurface;
+#ifdef Q_BACKINGSTORE_SUBSURFACES
+ QList<QWindowSurface*> subSurfaces;
+#endif
+ uint hasDirtyFromPreviousSync : 1;
+ uint fullUpdatePending : 1;
+
+ QPoint tlwOffset;
+
+ static bool flushPaint(QWidget *widget, const QRegion &rgn);
+ static void unflushPaint(QWidget *widget, const QRegion &rgn);
+
+ bool bltRect(const QRect &rect, int dx, int dy, QWidget *widget);
+ void releaseBuffer();
+
+ void beginPaint(QRegion &toClean, QWidget *widget, QWindowSurface *windowSurface,
+ BeginPaintInfo *returnInfo, bool toCleanIsInTopLevelCoordinates = true);
+ void endPaint(const QRegion &cleaned, QWindowSurface *windowSurface, BeginPaintInfo *beginPaintInfo);
+
+ QRegion dirtyRegion(QWidget *widget = 0) const;
+ QRegion staticContents(QWidget *widget = 0, const QRect &withinClipRect = QRect()) const;
+
+ void markDirtyOnScreen(const QRegion &dirtyOnScreen, QWidget *widget, const QPoint &topLevelOffset);
+
+ void removeDirtyWidget(QWidget *w);
+
+#if defined(Q_WS_QWS) && !defined(QT_NO_QWS_MANAGER)
+ bool hasDirtyWindowDecoration() const;
+ void paintWindowDecoration();
+#endif
+ void updateLists(QWidget *widget);
+
+ inline void addDirtyWidget(QWidget *widget, const QRegion &rgn)
+ {
+ if (widget && !widget->d_func()->inDirtyList && !widget->data->in_destructor) {
+ QWidgetPrivate *widgetPrivate = widget->d_func();
+#ifndef QT_NO_GRAPHICSEFFECT
+ if (widgetPrivate->graphicsEffect)
+ widgetPrivate->dirty = widgetPrivate->effectiveRectFor(rgn.boundingRect());
+ else
+#endif //QT_NO_GRAPHICSEFFECT
+ widgetPrivate->dirty = rgn;
+ dirtyWidgets.append(widget);
+ widgetPrivate->inDirtyList = true;
+ }
+ }
+
+ inline void dirtyWidgetsRemoveAll(QWidget *widget)
+ {
+ int i = 0;
+ while (i < dirtyWidgets.size()) {
+ if (dirtyWidgets.at(i) == widget)
+ dirtyWidgets.remove(i);
+ else
+ ++i;
+ }
+ }
+
+ inline void addStaticWidget(QWidget *widget)
+ {
+ if (!widget)
+ return;
+
+ Q_ASSERT(widget->testAttribute(Qt::WA_StaticContents));
+ if (!staticWidgets.contains(widget))
+ staticWidgets.append(widget);
+ }
+
+ inline void removeStaticWidget(QWidget *widget)
+ { staticWidgets.removeAll(widget); }
+
+ // Move the reparented widget and all its static children from this backing store
+ // to the new backing store if reparented into another top-level / backing store.
+ inline void moveStaticWidgets(QWidget *reparented)
+ {
+ Q_ASSERT(reparented);
+ QWidgetBackingStore *newBs = reparented->d_func()->maybeBackingStore();
+ if (newBs == this)
+ return;
+
+ int i = 0;
+ while (i < staticWidgets.size()) {
+ QWidget *w = staticWidgets.at(i);
+ if (reparented == w || reparented->isAncestorOf(w)) {
+ staticWidgets.removeAt(i);
+ if (newBs)
+ newBs->addStaticWidget(w);
+ } else {
+ ++i;
+ }
+ }
+ }
+
+ inline QRect topLevelRect() const
+ {
+#ifdef Q_WS_QWS
+ return tlw->frameGeometry();
+#else
+ return tlw->data->crect;
+#endif
+ }
+
+ inline void appendDirtyOnScreenWidget(QWidget *widget)
+ {
+ if (!widget)
+ return;
+
+ if (!dirtyOnScreenWidgets) {
+ dirtyOnScreenWidgets = new QVector<QWidget *>;
+ dirtyOnScreenWidgets->append(widget);
+ } else if (!dirtyOnScreenWidgets->contains(widget)) {
+ dirtyOnScreenWidgets->append(widget);
+ }
+ }
+
+ inline void dirtyOnScreenWidgetsRemoveAll(QWidget *widget)
+ {
+ if (!widget || !dirtyOnScreenWidgets)
+ return;
+
+ int i = 0;
+ while (i < dirtyOnScreenWidgets->size()) {
+ if (dirtyOnScreenWidgets->at(i) == widget)
+ dirtyOnScreenWidgets->remove(i);
+ else
+ ++i;
+ }
+ }
+
+ inline void resetWidget(QWidget *widget)
+ {
+ if (widget) {
+ widget->d_func()->inDirtyList = false;
+ widget->d_func()->isScrolled = false;
+ widget->d_func()->isMoved = false;
+ widget->d_func()->dirty = QRegion();
+ }
+ }
+
+ inline void updateStaticContentsSize()
+ {
+ for (int i = 0; i < staticWidgets.size(); ++i) {
+ QWidgetPrivate *wd = staticWidgets.at(i)->d_func();
+ if (!wd->extra)
+ wd->createExtra();
+ wd->extra->staticContentsSize = wd->data.crect.size();
+ }
+ }
+
+ inline bool hasStaticContents() const
+ { return !staticWidgets.isEmpty() && windowSurface->hasFeature(QWindowSurface::StaticContents); }
+
+ friend QRegion qt_dirtyRegion(QWidget *);
+ friend class QWidgetPrivate;
+ friend class QWidget;
+ friend class QWSManagerPrivate;
+ friend class QETWidget;
+ friend class QWindowSurface;
+ friend class QWSWindowSurface;
+};
+
+QT_END_NAMESPACE
+
+#endif // QBACKINGSTORE_P_H
diff --git a/src/gui/kernel/qclipboard.cpp b/src/gui/kernel/qclipboard.cpp
deleted file mode 100644
index ba7ad0caac..0000000000
--- a/src/gui/kernel/qclipboard.cpp
+++ /dev/null
@@ -1,667 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qclipboard.h"
-
-#ifndef QT_NO_CLIPBOARD
-
-#include "qapplication.h"
-#include "qapplication_p.h"
-#include "qpixmap.h"
-#include "qclipboard_p.h"
-#include "qvariant.h"
-#include "qbuffer.h"
-#include "qimage.h"
-#include "qtextcodec.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QClipboard
- \brief The QClipboard class provides access to the window system clipboard.
-
- The clipboard offers a simple mechanism to copy and paste data
- between applications.
-
- QClipboard supports the same data types that QDrag does, and uses
- similar mechanisms. For advanced clipboard usage read \l{Drag and
- Drop}.
-
- There is a single QClipboard object in an application, accessible
- as QApplication::clipboard().
-
- Example:
- \snippet doc/src/snippets/code/src_gui_kernel_qclipboard.cpp 0
-
- QClipboard features some convenience functions to access common
- data types: setText() allows the exchange of Unicode text and
- setPixmap() and setImage() allows the exchange of QPixmaps and
- QImages between applications. The setMimeData() function is the
- ultimate in flexibility: it allows you to add any QMimeData into
- the clipboard. There are corresponding getters for each of these,
- e.g. text(), image() and pixmap(). You can clear the clipboard by
- calling clear().
-
- A typical example of the use of these functions follows:
-
- \snippet doc/src/snippets/droparea.cpp 0
-
- \section1 Notes for X11 Users
-
- \list
-
- \i The X11 Window System has the concept of a separate selection
- and clipboard. When text is selected, it is immediately available
- as the global mouse selection. The global mouse selection may
- later be copied to the clipboard. By convention, the middle mouse
- button is used to paste the global mouse selection.
-
- \i X11 also has the concept of ownership; if you change the
- selection within a window, X11 will only notify the owner and the
- previous owner of the change, i.e. it will not notify all
- applications that the selection or clipboard data changed.
-
- \i Lastly, the X11 clipboard is event driven, i.e. the clipboard
- will not function properly if the event loop is not running.
- Similarly, it is recommended that the contents of the clipboard
- are stored or retrieved in direct response to user-input events,
- e.g. mouse button or key presses and releases. You should not
- store or retrieve the clipboard contents in response to timer or
- non-user-input events.
-
- \i Since there is no standard way to copy and paste files between
- applications on X11, various MIME types and conventions are currently
- in use. For instance, Nautilus expects files to be supplied with a
- \c{x-special/gnome-copied-files} MIME type with data beginning with
- the cut/copy action, a newline character, and the URL of the file.
-
- \endlist
-
- \section1 Notes for Mac OS X Users
-
- Mac OS X supports a separate find buffer that holds the current
- search string in Find operations. This find clipboard can be accessed
- by specifying the FindBuffer mode.
-
- \section1 Notes for Windows and Mac OS X Users
-
- \list
-
- \i Windows and Mac OS X do not support the global mouse
- selection; they only supports the global clipboard, i.e. they
- only add text to the clipboard when an explicit copy or cut is
- made.
-
- \i Windows and Mac OS X does not have the concept of ownership;
- the clipboard is a fully global resource so all applications are
- notified of changes.
-
- \endlist
-
- \sa QApplication
-*/
-
-#ifndef Q_WS_X11
-// for X11 there is a separate implementation of a constructor.
-/*!
- \internal
-
- Constructs a clipboard object.
-
- Do not call this function.
-
- Call QApplication::clipboard() instead to get a pointer to the
- application's global clipboard object.
-
- There is only one clipboard in the window system, and creating
- more than one object to represent it is almost certainly an error.
-*/
-
-QClipboard::QClipboard(QObject *parent)
- : QObject(*new QClipboardPrivate, parent)
-{
- // nothing
-}
-#endif
-
-#ifndef Q_WS_WIN32
-/*!
- \internal
-
- Destroys the clipboard.
-
- You should never delete the clipboard. QApplication will do this
- when the application terminates.
-*/
-QClipboard::~QClipboard()
-{
-}
-#endif
-
-/*!
- \fn void QClipboard::changed(QClipboard::Mode mode)
- \since 4.2
-
- This signal is emitted when the data for the given clipboard \a
- mode is changed.
-
- \sa dataChanged(), selectionChanged(), findBufferChanged()
-*/
-
-/*!
- \fn void QClipboard::dataChanged()
-
- This signal is emitted when the clipboard data is changed.
-
- On Mac OS X and with Qt version 4.3 or higher, clipboard
- changes made by other applications will only be detected
- when the application is activated.
-
- \sa findBufferChanged(), selectionChanged(), changed()
-*/
-
-/*!
- \fn void QClipboard::selectionChanged()
-
- This signal is emitted when the selection is changed. This only
- applies to windowing systems that support selections, e.g. X11.
- Windows and Mac OS X don't support selections.
-
- \sa dataChanged(), findBufferChanged(), changed()
-*/
-
-/*!
- \fn void QClipboard::findBufferChanged()
- \since 4.2
-
- This signal is emitted when the find buffer is changed. This only
- applies to Mac OS X.
-
- With Qt version 4.3 or higher, clipboard changes made by other
- applications will only be detected when the application is activated.
-
- \sa dataChanged(), selectionChanged(), changed()
-*/
-
-
-/*! \enum QClipboard::Mode
- \keyword clipboard mode
-
- This enum type is used to control which part of the system clipboard is
- used by QClipboard::mimeData(), QClipboard::setMimeData() and related functions.
-
- \value Clipboard indicates that data should be stored and retrieved from
- the global clipboard.
-
- \value Selection indicates that data should be stored and retrieved from
- the global mouse selection. Support for \c Selection is provided only on
- systems with a global mouse selection (e.g. X11).
-
- \value FindBuffer indicates that data should be stored and retrieved from
- the Find buffer. This mode is used for holding search strings on Mac OS X.
-
- \omitvalue LastMode
-
- \sa QClipboard::supportsSelection()
-*/
-
-
-/*****************************************************************************
- QApplication member functions related to QClipboard.
- *****************************************************************************/
-
-// text handling is done directly in qclipboard_qws, for now
-
-/*!
- \fn bool QClipboard::event(QEvent *e)
- \reimp
-*/
-
-/*!
- \overload
-
- Returns the clipboard text in subtype \a subtype, or an empty string
- if the clipboard does not contain any text. If \a subtype is null,
- any subtype is acceptable, and \a subtype is set to the chosen
- subtype.
-
- The \a mode argument is used to control which part of the system
- clipboard is used. If \a mode is QClipboard::Clipboard, the
- text is retrieved from the global clipboard. If \a mode is
- QClipboard::Selection, the text is retrieved from the global
- mouse selection.
-
- Common values for \a subtype are "plain" and "html".
-
- Note that calling this function repeatedly, for instance from a
- key event handler, may be slow. In such cases, you should use the
- \c dataChanged() signal instead.
-
- \sa setText(), mimeData()
-*/
-QString QClipboard::text(QString &subtype, Mode mode) const
-{
- const QMimeData *const data = mimeData(mode);
- if (!data)
- return QString();
-
- const QStringList formats = data->formats();
- if (subtype.isEmpty()) {
- if (formats.contains(QLatin1String("text/plain")))
- subtype = QLatin1String("plain");
- else {
- for (int i = 0; i < formats.size(); ++i)
- if (formats.at(i).startsWith(QLatin1String("text/"))) {
- subtype = formats.at(i).mid(5);
- break;
- }
- if (subtype.isEmpty())
- return QString();
- }
- } else if (!formats.contains(QLatin1String("text/") + subtype)) {
- return QString();
- }
-
- const QByteArray rawData = data->data(QLatin1String("text/") + subtype);
-
-#ifndef QT_NO_TEXTCODEC
- QTextCodec* codec = QTextCodec::codecForMib(106); // utf-8 is default
- if (subtype == QLatin1String("html"))
- codec = QTextCodec::codecForHtml(rawData, codec);
- else
- codec = QTextCodec::codecForUtfText(rawData, codec);
- return codec->toUnicode(rawData);
-#else //QT_NO_TEXTCODEC
- return rawData;
-#endif //QT_NO_TEXTCODEC
-}
-
-/*!
- Returns the clipboard text as plain text, or an empty string if the
- clipboard does not contain any text.
-
- The \a mode argument is used to control which part of the system
- clipboard is used. If \a mode is QClipboard::Clipboard, the
- text is retrieved from the global clipboard. If \a mode is
- QClipboard::Selection, the text is retrieved from the global
- mouse selection. If \a mode is QClipboard::FindBuffer, the
- text is retrieved from the search string buffer.
-
- \sa setText(), mimeData()
-*/
-QString QClipboard::text(Mode mode) const
-{
- const QMimeData *data = mimeData(mode);
- return data ? data->text() : QString();
-}
-
-/*!
- Copies \a text into the clipboard as plain text.
-
- The \a mode argument is used to control which part of the system
- clipboard is used. If \a mode is QClipboard::Clipboard, the
- text is stored in the global clipboard. If \a mode is
- QClipboard::Selection, the text is stored in the global
- mouse selection. If \a mode is QClipboard::FindBuffer, the
- text is stored in the search string buffer.
-
- \sa text(), setMimeData()
-*/
-void QClipboard::setText(const QString &text, Mode mode)
-{
- QMimeData *data = new QMimeData;
- data->setText(text);
- setMimeData(data, mode);
-}
-
-/*!
- Returns the clipboard image, or returns a null image if the
- clipboard does not contain an image or if it contains an image in
- an unsupported image format.
-
- The \a mode argument is used to control which part of the system
- clipboard is used. If \a mode is QClipboard::Clipboard, the
- image is retrieved from the global clipboard. If \a mode is
- QClipboard::Selection, the image is retrieved from the global
- mouse selection.
-
- \sa setImage() pixmap() mimeData(), QImage::isNull()
-*/
-QImage QClipboard::image(Mode mode) const
-{
- const QMimeData *data = mimeData(mode);
- if (!data)
- return QImage();
- return qvariant_cast<QImage>(data->imageData());
-}
-
-/*!
- Copies the \a image into the clipboard.
-
- The \a mode argument is used to control which part of the system
- clipboard is used. If \a mode is QClipboard::Clipboard, the
- image is stored in the global clipboard. If \a mode is
- QClipboard::Selection, the data is stored in the global
- mouse selection.
-
- This is shorthand for:
-
- \snippet doc/src/snippets/code/src_gui_kernel_qclipboard.cpp 1
-
- \sa image(), setPixmap() setMimeData()
-*/
-void QClipboard::setImage(const QImage &image, Mode mode)
-{
- QMimeData *data = new QMimeData;
- data->setImageData(image);
- setMimeData(data, mode);
-}
-
-/*!
- Returns the clipboard pixmap, or null if the clipboard does not
- contain a pixmap. Note that this can lose information. For
- example, if the image is 24-bit and the display is 8-bit, the
- result is converted to 8 bits, and if the image has an alpha
- channel, the result just has a mask.
-
- The \a mode argument is used to control which part of the system
- clipboard is used. If \a mode is QClipboard::Clipboard, the
- pixmap is retrieved from the global clipboard. If \a mode is
- QClipboard::Selection, the pixmap is retrieved from the global
- mouse selection.
-
- \sa setPixmap() image() mimeData() QPixmap::convertFromImage()
-*/
-QPixmap QClipboard::pixmap(Mode mode) const
-{
- const QMimeData *data = mimeData(mode);
- return data ? qvariant_cast<QPixmap>(data->imageData()) : QPixmap();
-}
-
-/*!
- Copies \a pixmap into the clipboard. Note that this is slower
- than setImage() because it needs to convert the QPixmap to a
- QImage first.
-
- The \a mode argument is used to control which part of the system
- clipboard is used. If \a mode is QClipboard::Clipboard, the
- pixmap is stored in the global clipboard. If \a mode is
- QClipboard::Selection, the pixmap is stored in the global
- mouse selection.
-
- \sa pixmap() setImage() setMimeData()
-*/
-void QClipboard::setPixmap(const QPixmap &pixmap, Mode mode)
-{
- QMimeData *data = new QMimeData;
- data->setImageData(pixmap);
- setMimeData(data, mode);
-}
-
-
-/*!
- \fn QMimeData *QClipboard::mimeData(Mode mode) const
-
- Returns a reference to a QMimeData representation of the current
- clipboard data.
-
- The \a mode argument is used to control which part of the system
- clipboard is used. If \a mode is QClipboard::Clipboard, the
- data is retrieved from the global clipboard. If \a mode is
- QClipboard::Selection, the data is retrieved from the global
- mouse selection. If \a mode is QClipboard::FindBuffer, the
- data is retrieved from the search string buffer.
-
- The text(), image(), and pixmap() functions are simpler
- wrappers for retrieving text, image, and pixmap data.
-
- \sa setMimeData()
-*/
-
-/*!
- \fn void QClipboard::setMimeData(QMimeData *src, Mode mode)
-
- Sets the clipboard data to \a src. Ownership of the data is
- transferred to the clipboard. If you want to remove the data
- either call clear() or call setMimeData() again with new data.
-
- The \a mode argument is used to control which part of the system
- clipboard is used. If \a mode is QClipboard::Clipboard, the
- data is stored in the global clipboard. If \a mode is
- QClipboard::Selection, the data is stored in the global
- mouse selection. If \a mode is QClipboard::FindBuffer, the
- data is stored in the search string buffer.
-
- The setText(), setImage() and setPixmap() functions are simpler
- wrappers for setting text, image and pixmap data respectively.
-
- \sa mimeData()
-*/
-
-/*!
- \fn void QClipboard::clear(Mode mode)
- Clear the clipboard contents.
-
- The \a mode argument is used to control which part of the system
- clipboard is used. If \a mode is QClipboard::Clipboard, this
- function clears the global clipboard contents. If \a mode is
- QClipboard::Selection, this function clears the global mouse
- selection contents. If \a mode is QClipboard::FindBuffer, this
- function clears the search string buffer.
-
- \sa QClipboard::Mode, supportsSelection()
-*/
-
-#ifdef QT3_SUPPORT
-/*!
- \fn QMimeSource *QClipboard::data(Mode mode) const
- \compat
-
- Use mimeData() instead.
-*/
-QMimeSource *QClipboard::data(Mode mode) const
-{
- Q_D(const QClipboard);
-
- if (supportsMode(mode) == false)
- return 0;
-
- if (d->compat_data[mode])
- return d->compat_data[mode];
-
- d->wrapper[mode]->data = mimeData(mode);
- return d->wrapper[mode];
-}
-
-
-/*!
- \fn void QClipboard::setData(QMimeSource *src, Mode mode)
- \compat
-
- Use setMimeData() instead.
-*/
-void QClipboard::setData(QMimeSource *source, Mode mode)
-{
- Q_D(QClipboard);
-
- if (supportsMode(mode) == false)
- return;
-
- d->compat_data[mode] = source;
- setMimeData(new QMimeSourceWrapper(d, mode), mode);
-}
-#endif // QT3_SUPPORT
-
-/*!
- Returns true if the clipboard supports mouse selection; otherwise
- returns false.
-*/
-bool QClipboard::supportsSelection() const
-{
- return supportsMode(Selection);
-}
-
-/*!
- Returns true if the clipboard supports a separate search buffer; otherwise
- returns false.
-*/
-bool QClipboard::supportsFindBuffer() const
-{
- return supportsMode(FindBuffer);
-}
-
-/*!
- Returns true if this clipboard object owns the clipboard data;
- otherwise returns false.
-*/
-bool QClipboard::ownsClipboard() const
-{
- return ownsMode(Clipboard);
-}
-
-/*!
- Returns true if this clipboard object owns the mouse selection
- data; otherwise returns false.
-*/
-bool QClipboard::ownsSelection() const
-{
- return ownsMode(Selection);
-}
-
-/*!
- \since 4.2
-
- Returns true if this clipboard object owns the find buffer data;
- otherwise returns false.
-*/
-bool QClipboard::ownsFindBuffer() const
-{
- return ownsMode(FindBuffer);
-}
-
-/*!
- \internal
- \fn bool QClipboard::supportsMode(Mode mode) const;
- Returns true if the clipboard supports the clipboard mode speacified by \a mode;
- otherwise returns false.
-*/
-
-/*!
- \internal
- \fn bool QClipboard::ownsMode(Mode mode) const;
- Returns true if the clipboard supports the clipboard data speacified by \a mode;
- otherwise returns false.
-*/
-
-/*!
- \internal
- Emits the appropriate changed signal for \a mode.
-*/
-void QClipboard::emitChanged(Mode mode)
-{
- switch (mode) {
- case Clipboard:
- emit dataChanged();
- break;
- case Selection:
- emit selectionChanged();
- break;
- case FindBuffer:
- emit findBufferChanged();
- break;
- default:
- break;
- }
- emit changed(mode);
-}
-
-const char* QMimeDataWrapper::format(int n) const
-{
- if (formats.isEmpty()) {
- QStringList fmts = data->formats();
- for (int i = 0; i < fmts.size(); ++i)
- formats.append(fmts.at(i).toLatin1());
- }
- if (n < 0 || n >= formats.size())
- return 0;
- return formats.at(n).data();
-}
-
-QByteArray QMimeDataWrapper::encodedData(const char *format) const
-{
- if (QLatin1String(format) != QLatin1String("application/x-qt-image")){
- return data->data(QLatin1String(format));
- } else{
- QVariant variant = data->imageData();
- QImage img = qvariant_cast<QImage>(variant);
- QByteArray ba;
- QBuffer buffer(&ba);
- buffer.open(QIODevice::WriteOnly);
- img.save(&buffer, "PNG");
- return ba;
- }
-}
-
-QVariant QMimeSourceWrapper::retrieveData(const QString &mimetype, QVariant::Type) const
-{
- return source->encodedData(mimetype.toLatin1());
-}
-
-bool QMimeSourceWrapper::hasFormat(const QString &mimetype) const
-{
- return source->provides(mimetype.toLatin1());
-}
-
-QStringList QMimeSourceWrapper::formats() const
-{
- QStringList fmts;
- int i = 0;
- const char *fmt;
- while ((fmt = source->format(i))) {
- fmts.append(QLatin1String(fmt));
- ++i;
- }
- return fmts;
-}
-
-#endif // QT_NO_CLIPBOARD
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qclipboard.h b/src/gui/kernel/qclipboard.h
deleted file mode 100644
index 0a9e28ac8c..0000000000
--- a/src/gui/kernel/qclipboard.h
+++ /dev/null
@@ -1,131 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCLIPBOARD_H
-#define QCLIPBOARD_H
-
-#include <QtCore/qobject.h>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Gui)
-
-#ifndef QT_NO_CLIPBOARD
-
-class QMimeSource;
-class QMimeData;
-class QImage;
-class QPixmap;
-
-class QClipboardPrivate;
-
-class Q_GUI_EXPORT QClipboard : public QObject
-{
- Q_OBJECT
- Q_DECLARE_PRIVATE(QClipboard)
-private:
- QClipboard(QObject *parent);
- ~QClipboard();
-
-public:
- enum Mode { Clipboard, Selection, FindBuffer, LastMode = FindBuffer };
-
- void clear(Mode mode = Clipboard);
-
- bool supportsSelection() const;
- bool supportsFindBuffer() const;
-
- bool ownsSelection() const;
- bool ownsClipboard() const;
- bool ownsFindBuffer() const;
-
- QString text(Mode mode = Clipboard) const;
- QString text(QString& subtype, Mode mode = Clipboard) const;
- void setText(const QString &, Mode mode = Clipboard);
-
-#ifdef QT3_SUPPORT
- QT3_SUPPORT QMimeSource *data(Mode mode = Clipboard) const;
- QT3_SUPPORT void setData(QMimeSource*, Mode mode = Clipboard);
-#endif
- const QMimeData *mimeData(Mode mode = Clipboard ) const;
- void setMimeData(QMimeData *data, Mode mode = Clipboard);
-
- QImage image(Mode mode = Clipboard) const;
- QPixmap pixmap(Mode mode = Clipboard) const;
- void setImage(const QImage &, Mode mode = Clipboard);
- void setPixmap(const QPixmap &, Mode mode = Clipboard);
-
-Q_SIGNALS:
- void changed(QClipboard::Mode mode);
- void selectionChanged();
- void findBufferChanged();
- void dataChanged();
-private Q_SLOTS:
- void ownerDestroyed();
-
-protected:
- void connectNotify(const char *);
- bool event(QEvent *);
-
- friend class QApplication;
- friend class QApplicationPrivate;
- friend class QGuiApplication;
- friend class QBaseApplication;
- friend class QDragManager;
- friend class QMimeSource;
-
-private:
- Q_DISABLE_COPY(QClipboard)
-
- bool supportsMode(Mode mode) const;
- bool ownsMode(Mode mode) const;
- void emitChanged(Mode mode);
-};
-
-#endif // QT_NO_CLIPBOARD
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // QCLIPBOARD_H
diff --git a/src/gui/kernel/qclipboard_mac.cpp b/src/gui/kernel/qclipboard_mac.cpp
deleted file mode 100644
index 4a8bc56e41..0000000000
--- a/src/gui/kernel/qclipboard_mac.cpp
+++ /dev/null
@@ -1,634 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qclipboard.h"
-#include "qapplication.h"
-#include "qbitmap.h"
-#include "qdatetime.h"
-#include "qdebug.h"
-#include "qapplication_p.h"
-#include <private/qt_mac_p.h>
-#include "qevent.h"
-#include "qurl.h"
-#include <stdlib.h>
-#include <string.h>
-#include "qt_cocoa_helpers_mac_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QT_USE_NAMESPACE
-
-/*****************************************************************************
- QClipboard debug facilities
- *****************************************************************************/
-//#define DEBUG_PASTEBOARD
-
-#ifndef QT_NO_CLIPBOARD
-
-/*****************************************************************************
- QClipboard member functions for mac.
- *****************************************************************************/
-
-static QMacPasteboard *qt_mac_pasteboards[2] = {0, 0};
-
-static inline QMacPasteboard *qt_mac_pasteboard(QClipboard::Mode mode)
-{
- Q_ASSERT(mode == QClipboard::Clipboard || mode == QClipboard::FindBuffer);
- if (mode == QClipboard::Clipboard)
- return qt_mac_pasteboards[0];
- else
- return qt_mac_pasteboards[1];
-}
-
-static void qt_mac_cleanupPasteboard() {
- delete qt_mac_pasteboards[0];
- delete qt_mac_pasteboards[1];
- qt_mac_pasteboards[0] = 0;
- qt_mac_pasteboards[1] = 0;
-}
-
-static bool qt_mac_updateScrap(QClipboard::Mode mode)
-{
- if(!qt_mac_pasteboards[0]) {
- qt_mac_pasteboards[0] = new QMacPasteboard(kPasteboardClipboard, QMacPasteboardMime::MIME_CLIP);
- qt_mac_pasteboards[1] = new QMacPasteboard(kPasteboardFind, QMacPasteboardMime::MIME_CLIP);
- qAddPostRoutine(qt_mac_cleanupPasteboard);
- return true;
- }
- return qt_mac_pasteboard(mode)->sync();
-}
-
-void QClipboard::clear(Mode mode)
-{
- if (!supportsMode(mode))
- return;
- qt_mac_updateScrap(mode);
- qt_mac_pasteboard(mode)->clear();
- setMimeData(0, mode);
-}
-
-void QClipboard::ownerDestroyed()
-{
-}
-
-
-void QClipboard::connectNotify(const char *signal)
-{
- Q_UNUSED(signal);
-}
-
-bool QClipboard::event(QEvent *e)
-{
- if(e->type() != QEvent::Clipboard)
- return QObject::event(e);
-
- if (qt_mac_updateScrap(QClipboard::Clipboard)) {
- emitChanged(QClipboard::Clipboard);
- }
-
- if (qt_mac_updateScrap(QClipboard::FindBuffer)) {
- emitChanged(QClipboard::FindBuffer);
- }
-
- return QObject::event(e);
-}
-
-const QMimeData *QClipboard::mimeData(Mode mode) const
-{
- if (!supportsMode(mode))
- return 0;
- qt_mac_updateScrap(mode);
- return qt_mac_pasteboard(mode)->mimeData();
-}
-
-void QClipboard::setMimeData(QMimeData *src, Mode mode)
-{
- if (!supportsMode(mode))
- return;
- qt_mac_updateScrap(mode);
- qt_mac_pasteboard(mode)->setMimeData(src);
- emitChanged(mode);
-}
-
-bool QClipboard::supportsMode(Mode mode) const
-{
- return (mode == Clipboard || mode == FindBuffer);
-}
-
-bool QClipboard::ownsMode(Mode mode) const
-{
- Q_UNUSED(mode);
- return false;
-}
-
-#endif // QT_NO_CLIPBOARD
-
-/*****************************************************************************
- QMacPasteboard code
-*****************************************************************************/
-
-QMacPasteboard::QMacPasteboard(PasteboardRef p, uchar mt)
-{
- mac_mime_source = false;
- mime_type = mt ? mt : uchar(QMacPasteboardMime::MIME_ALL);
- paste = p;
- CFRetain(paste);
-}
-
-QMacPasteboard::QMacPasteboard(uchar mt)
-{
- mac_mime_source = false;
- mime_type = mt ? mt : uchar(QMacPasteboardMime::MIME_ALL);
- paste = 0;
- OSStatus err = PasteboardCreate(0, &paste);
- if(err == noErr) {
- PasteboardSetPromiseKeeper(paste, promiseKeeper, this);
- } else {
- qDebug("PasteBoard: Error creating pasteboard: [%d]", (int)err);
- }
-}
-
-QMacPasteboard::QMacPasteboard(CFStringRef name, uchar mt)
-{
- mac_mime_source = false;
- mime_type = mt ? mt : uchar(QMacPasteboardMime::MIME_ALL);
- paste = 0;
- OSStatus err = PasteboardCreate(name, &paste);
- if(err == noErr) {
- PasteboardSetPromiseKeeper(paste, promiseKeeper, this);
- } else {
- qDebug("PasteBoard: Error creating pasteboard: %s [%d]", QCFString::toQString(name).toLatin1().constData(), (int)err);
- }
-}
-
-QMacPasteboard::~QMacPasteboard()
-{
- // commit all promises for paste after exit close
- for (int i = 0; i < promises.count(); ++i) {
- const Promise &promise = promises.at(i);
- QCFString flavor = QCFString(promise.convertor->flavorFor(promise.mime));
- promiseKeeper(paste, (PasteboardItemID)promise.itemId, flavor, this);
- }
-
- if(paste)
- CFRelease(paste);
-}
-
-PasteboardRef
-QMacPasteboard::pasteBoard() const
-{
- return paste;
-}
-
-OSStatus QMacPasteboard::promiseKeeper(PasteboardRef paste, PasteboardItemID id, CFStringRef flavor, void *_qpaste)
-{
- QMacPasteboard *qpaste = (QMacPasteboard*)_qpaste;
- const long promise_id = (long)id;
-
- // Find the kept promise
- const QString flavorAsQString = QCFString::toQString(flavor);
- QMacPasteboard::Promise promise;
- for (int i = 0; i < qpaste->promises.size(); i++){
- QMacPasteboard::Promise tmp = qpaste->promises[i];
- if (tmp.itemId == promise_id && tmp.convertor->canConvert(tmp.mime, flavorAsQString)){
- promise = tmp;
- break;
- }
- }
-
- if (!promise.itemId && flavorAsQString == QLatin1String("com.trolltech.qt.MimeTypeName")) {
- // we have promised this data, but wont be able to convert, so return null data.
- // This helps in making the application/x-qt-mime-type-name hidden from normal use.
- QByteArray ba;
- QCFType<CFDataRef> data = CFDataCreate(0, (UInt8*)ba.constData(), ba.size());
- PasteboardPutItemFlavor(paste, id, flavor, data, kPasteboardFlavorNoFlags);
- return noErr;
- }
-
- if (!promise.itemId) {
- // There was no promise that could deliver data for the
- // given id and flavor. This should not happend.
- qDebug("Pasteboard: %d: Request for %ld, %s, but no promise found!", __LINE__, promise_id, qPrintable(flavorAsQString));
- return cantGetFlavorErr;
- }
-
-#ifdef DEBUG_PASTEBOARD
- qDebug("PasteBoard: Calling in promise for %s[%ld] [%s] (%s) [%d]", qPrintable(promise.mime), promise_id,
- qPrintable(flavorAsQString), qPrintable(promise.convertor->convertorName()), promise.offset);
-#endif
-
- QList<QByteArray> md = promise.convertor->convertFromMime(promise.mime, promise.data, flavorAsQString);
- if (md.size() <= promise.offset)
- return cantGetFlavorErr;
- const QByteArray &ba = md[promise.offset];
- QCFType<CFDataRef> data = CFDataCreate(0, (UInt8*)ba.constData(), ba.size());
- PasteboardPutItemFlavor(paste, id, flavor, data, kPasteboardFlavorNoFlags);
- return noErr;
-}
-
-bool
-QMacPasteboard::hasOSType(int c_flavor) const
-{
- if (!paste)
- return false;
-
- sync();
-
- ItemCount cnt = 0;
- if(PasteboardGetItemCount(paste, &cnt) || !cnt)
- return false;
-
-#ifdef DEBUG_PASTEBOARD
- qDebug("PasteBoard: hasOSType [%c%c%c%c]", (c_flavor>>24)&0xFF, (c_flavor>>16)&0xFF,
- (c_flavor>>8)&0xFF, (c_flavor>>0)&0xFF);
-#endif
- for(uint index = 1; index <= cnt; ++index) {
-
- PasteboardItemID id;
- if(PasteboardGetItemIdentifier(paste, index, &id) != noErr)
- return false;
-
- QCFType<CFArrayRef> types;
- if(PasteboardCopyItemFlavors(paste, id, &types ) != noErr)
- return false;
-
- const int type_count = CFArrayGetCount(types);
- for(int i = 0; i < type_count; ++i) {
- CFStringRef flavor = (CFStringRef)CFArrayGetValueAtIndex(types, i);
- const int os_flavor = UTGetOSTypeFromString(UTTypeCopyPreferredTagWithClass(flavor, kUTTagClassOSType));
- if(os_flavor == c_flavor) {
-#ifdef DEBUG_PASTEBOARD
- qDebug(" - Found!");
-#endif
- return true;
- }
- }
- }
-#ifdef DEBUG_PASTEBOARD
- qDebug(" - NotFound!");
-#endif
- return false;
-}
-
-bool
-QMacPasteboard::hasFlavor(QString c_flavor) const
-{
- if (!paste)
- return false;
-
- sync();
-
- ItemCount cnt = 0;
- if(PasteboardGetItemCount(paste, &cnt) || !cnt)
- return false;
-
-#ifdef DEBUG_PASTEBOARD
- qDebug("PasteBoard: hasFlavor [%s]", qPrintable(c_flavor));
-#endif
- for(uint index = 1; index <= cnt; ++index) {
-
- PasteboardItemID id;
- if(PasteboardGetItemIdentifier(paste, index, &id) != noErr)
- return false;
-
- PasteboardFlavorFlags flags;
- if(PasteboardGetItemFlavorFlags(paste, id, QCFString(c_flavor), &flags) == noErr) {
-#ifdef DEBUG_PASTEBOARD
- qDebug(" - Found!");
-#endif
- return true;
- }
- }
-#ifdef DEBUG_PASTEBOARD
- qDebug(" - NotFound!");
-#endif
- return false;
-}
-
-class QMacPasteboardMimeSource : public QMimeData {
- const QMacPasteboard *paste;
-public:
- QMacPasteboardMimeSource(const QMacPasteboard *p) : QMimeData(), paste(p) { }
- ~QMacPasteboardMimeSource() { }
- virtual QStringList formats() const { return paste->formats(); }
- virtual QVariant retrieveData(const QString &format, QVariant::Type type) const { return paste->retrieveData(format, type); }
-};
-
-QMimeData
-*QMacPasteboard::mimeData() const
-{
- if(!mime) {
- mac_mime_source = true;
- mime = new QMacPasteboardMimeSource(this);
-
- }
- return mime;
-}
-
-class QMacMimeData : public QMimeData
-{
-public:
- QVariant variantData(const QString &mime) { return retrieveData(mime, QVariant::Invalid); }
-private:
- QMacMimeData();
-};
-
-void
-QMacPasteboard::setMimeData(QMimeData *mime_src)
-{
- if (!paste)
- return;
-
- if (mime == mime_src || (!mime_src && mime && mac_mime_source))
- return;
- mac_mime_source = false;
- delete mime;
- mime = mime_src;
-
- QList<QMacPasteboardMime*> availableConverters = QMacPasteboardMime::all(mime_type);
- if (mime != 0) {
- clear_helper();
- QStringList formats = mime_src->formats();
-
-#ifdef QT_MAC_USE_COCOA
- // QMimeData sub classes reimplementing the formats() might not expose the
- // temporary "application/x-qt-mime-type-name" mimetype. So check the existence
- // of this mime type while doing drag and drop.
- QString dummyMimeType(QLatin1String("application/x-qt-mime-type-name"));
- if (!formats.contains(dummyMimeType)) {
- QByteArray dummyType = mime_src->data(dummyMimeType);
- if (!dummyType.isEmpty()) {
- formats.append(dummyMimeType);
- }
- }
-#endif
- for(int f = 0; f < formats.size(); ++f) {
- QString mimeType = formats.at(f);
- for (QList<QMacPasteboardMime *>::Iterator it = availableConverters.begin(); it != availableConverters.end(); ++it) {
- QMacPasteboardMime *c = (*it);
- QString flavor(c->flavorFor(mimeType));
- if(!flavor.isEmpty()) {
- QVariant mimeData = static_cast<QMacMimeData*>(mime_src)->variantData(mimeType);
-#if 0
- //### Grrr, why didn't I put in a virtual int QMacPasteboardMime::count()? --Sam
- const int numItems = c->convertFromMime(mimeType, mimeData, flavor).size();
-#else
- int numItems = 1; //this is a hack but it is much faster than allowing conversion above
- if(c->convertorName() == QLatin1String("FileURL"))
- numItems = mime_src->urls().count();
-#endif
- for(int item = 0; item < numItems; ++item) {
- const int itemID = item+1; //id starts at 1
- promises.append(QMacPasteboard::Promise(itemID, c, mimeType, mimeData, item));
- PasteboardPutItemFlavor(paste, (PasteboardItemID)itemID, QCFString(flavor), 0, kPasteboardFlavorNoFlags);
-#ifdef DEBUG_PASTEBOARD
- qDebug(" - adding %d %s [%s] <%s> [%d]",
- itemID, qPrintable(mimeType), qPrintable(flavor), qPrintable(c->convertorName()), item);
-#endif
- }
- }
- }
- }
- }
-}
-
-QStringList
-QMacPasteboard::formats() const
-{
- if (!paste)
- return QStringList();
-
- sync();
-
- QStringList ret;
- ItemCount cnt = 0;
- if(PasteboardGetItemCount(paste, &cnt) || !cnt)
- return ret;
-
-#ifdef DEBUG_PASTEBOARD
- qDebug("PasteBoard: Formats [%d]", (int)cnt);
-#endif
- for(uint index = 1; index <= cnt; ++index) {
-
- PasteboardItemID id;
- if(PasteboardGetItemIdentifier(paste, index, &id) != noErr)
- continue;
-
- QCFType<CFArrayRef> types;
- if(PasteboardCopyItemFlavors(paste, id, &types ) != noErr)
- continue;
-
- const int type_count = CFArrayGetCount(types);
- for(int i = 0; i < type_count; ++i) {
- const QString flavor = QCFString::toQString((CFStringRef)CFArrayGetValueAtIndex(types, i));
-#ifdef DEBUG_PASTEBOARD
- qDebug(" -%s", qPrintable(QString(flavor)));
-#endif
- QString mimeType = QMacPasteboardMime::flavorToMime(mime_type, flavor);
- if(!mimeType.isEmpty() && !ret.contains(mimeType)) {
-#ifdef DEBUG_PASTEBOARD
- qDebug(" -<%d> %s [%s]", ret.size(), qPrintable(mimeType), qPrintable(QString(flavor)));
-#endif
- ret << mimeType;
- }
- }
- }
- return ret;
-}
-
-bool
-QMacPasteboard::hasFormat(const QString &format) const
-{
- if (!paste)
- return false;
-
- sync();
-
- ItemCount cnt = 0;
- if(PasteboardGetItemCount(paste, &cnt) || !cnt)
- return false;
-
-#ifdef DEBUG_PASTEBOARD
- qDebug("PasteBoard: hasFormat [%s]", qPrintable(format));
-#endif
- for(uint index = 1; index <= cnt; ++index) {
-
- PasteboardItemID id;
- if(PasteboardGetItemIdentifier(paste, index, &id) != noErr)
- continue;
-
- QCFType<CFArrayRef> types;
- if(PasteboardCopyItemFlavors(paste, id, &types ) != noErr)
- continue;
-
- const int type_count = CFArrayGetCount(types);
- for(int i = 0; i < type_count; ++i) {
- const QString flavor = QCFString::toQString((CFStringRef)CFArrayGetValueAtIndex(types, i));
-#ifdef DEBUG_PASTEBOARD
- qDebug(" -%s [0x%x]", qPrintable(QString(flavor)), mime_type);
-#endif
- QString mimeType = QMacPasteboardMime::flavorToMime(mime_type, flavor);
-#ifdef DEBUG_PASTEBOARD
- if(!mimeType.isEmpty())
- qDebug(" - %s", qPrintable(mimeType));
-#endif
- if(mimeType == format)
- return true;
- }
- }
- return false;
-}
-
-QVariant
-QMacPasteboard::retrieveData(const QString &format, QVariant::Type) const
-{
- if (!paste)
- return QVariant();
-
- sync();
-
- ItemCount cnt = 0;
- if(PasteboardGetItemCount(paste, &cnt) || !cnt)
- return QByteArray();
-
-#ifdef DEBUG_PASTEBOARD
- qDebug("Pasteboard: retrieveData [%s]", qPrintable(format));
-#endif
- const QList<QMacPasteboardMime *> mimes = QMacPasteboardMime::all(mime_type);
- for(int mime = 0; mime < mimes.size(); ++mime) {
- QMacPasteboardMime *c = mimes.at(mime);
- QString c_flavor = c->flavorFor(format);
- if(!c_flavor.isEmpty()) {
- // Handle text/plain a little differently. Try handling Unicode first.
- bool checkForUtf16 = (c_flavor == QLatin1String("com.apple.traditional-mac-plain-text")
- || c_flavor == QLatin1String("public.utf8-plain-text"));
- if (checkForUtf16 || c_flavor == QLatin1String("public.utf16-plain-text")) {
- // Try to get the NSStringPboardType from NSPasteboard, newlines are mapped
- // correctly (as '\n') in this data. The 'public.utf16-plain-text' type
- // usually maps newlines to '\r' instead.
- QString str = qt_mac_get_pasteboardString(paste);
- if (!str.isEmpty())
- return str;
- }
- if (checkForUtf16 && hasFlavor(QLatin1String("public.utf16-plain-text")))
- c_flavor = QLatin1String("public.utf16-plain-text");
-
- QVariant ret;
- QList<QByteArray> retList;
- for(uint index = 1; index <= cnt; ++index) {
- PasteboardItemID id;
- if(PasteboardGetItemIdentifier(paste, index, &id) != noErr)
- continue;
-
- QCFType<CFArrayRef> types;
- if(PasteboardCopyItemFlavors(paste, id, &types ) != noErr)
- continue;
-
- const int type_count = CFArrayGetCount(types);
- for(int i = 0; i < type_count; ++i) {
- CFStringRef flavor = static_cast<CFStringRef>(CFArrayGetValueAtIndex(types, i));
- if(c_flavor == QCFString::toQString(flavor)) {
- QCFType<CFDataRef> macBuffer;
- if(PasteboardCopyItemFlavorData(paste, id, flavor, &macBuffer) == noErr) {
- QByteArray buffer((const char *)CFDataGetBytePtr(macBuffer), CFDataGetLength(macBuffer));
- if(!buffer.isEmpty()) {
-#ifdef DEBUG_PASTEBOARD
- qDebug(" - %s [%s] (%s)", qPrintable(format), qPrintable(QCFString::toQString(flavor)), qPrintable(c->convertorName()));
-#endif
- buffer.detach(); //detach since we release the macBuffer
- retList.append(buffer);
- break; //skip to next element
- }
- }
- } else {
-#ifdef DEBUG_PASTEBOARD
- qDebug(" - NoMatch %s [%s] (%s)", qPrintable(c_flavor), qPrintable(QCFString::toQString(flavor)), qPrintable(c->convertorName()));
-#endif
- }
- }
- }
-
- if (!retList.isEmpty()) {
- ret = c->convertToMime(format, retList, c_flavor);
- return ret;
- }
- }
- }
- return QVariant();
-}
-
-void QMacPasteboard::clear_helper()
-{
- if (paste)
- PasteboardClear(paste);
- promises.clear();
-}
-
-void
-QMacPasteboard::clear()
-{
-#ifdef DEBUG_PASTEBOARD
- qDebug("PasteBoard: clear!");
-#endif
- clear_helper();
-}
-
-bool
-QMacPasteboard::sync() const
-{
- if (!paste)
- return false;
- const bool fromGlobal = PasteboardSynchronize(paste) & kPasteboardModified;
-
- if (fromGlobal)
- const_cast<QMacPasteboard *>(this)->setMimeData(0);
-
-#ifdef DEBUG_PASTEBOARD
- if(fromGlobal)
- qDebug("Pasteboard: Synchronize!");
-#endif
- return fromGlobal;
-}
-
-
-
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qclipboard_p.h b/src/gui/kernel/qclipboard_p.h
deleted file mode 100644
index c82694cfb8..0000000000
--- a/src/gui/kernel/qclipboard_p.h
+++ /dev/null
@@ -1,131 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCLIPBOARD_P_H
-#define QCLIPBOARD_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "private/qobject_p.h"
-#include "QtGui/qmime.h"
-#include "QtGui/qclipboard.h"
-
-QT_BEGIN_NAMESPACE
-
-class QClipboardPrivate;
-
-class QMimeDataWrapper : public QMimeSource
-{
-public:
- QMimeDataWrapper() {}
-
- const char* format(int n) const;
- QByteArray encodedData(const char*) const;
-
- mutable QList<QByteArray> formats;
- const QMimeData *data;
-};
-
-class QMimeSourceWrapper : public QMimeData
-{
-public:
- QMimeSourceWrapper(QClipboardPrivate *priv, QClipboard::Mode m);
- ~QMimeSourceWrapper();
-
- bool hasFormat(const QString &mimetype) const;
- QStringList formats() const;
-
-protected:
- QVariant retrieveData(const QString &mimetype, QVariant::Type) const;
-private:
- QClipboardPrivate *d;
- QClipboard::Mode mode;
- QMimeSource *source;
-};
-
-
-class QClipboardPrivate : public QObjectPrivate
-{
-public:
- QClipboardPrivate() : QObjectPrivate() {
- for (int i = 0; i <= QClipboard::LastMode; ++i) {
- compat_data[i] = 0;
- wrapper[i] = new QMimeDataWrapper();
- }
- }
- ~QClipboardPrivate() {
- for (int i = 0; i <= QClipboard::LastMode; ++i) {
- delete wrapper[i];
- delete compat_data[i];
- }
- }
-
- mutable QMimeDataWrapper *wrapper[QClipboard::LastMode + 1];
- mutable QMimeSource *compat_data[QClipboard::LastMode + 1];
-};
-
-inline QMimeSourceWrapper::QMimeSourceWrapper(QClipboardPrivate *priv, QClipboard::Mode m)
- : QMimeData()
-{
- d = priv;
- mode = m;
- source = d->compat_data[mode];
-}
-
-inline QMimeSourceWrapper::~QMimeSourceWrapper()
-{
- if (d->compat_data[mode] == source)
- d->compat_data[mode] = 0;
- delete source;
-}
-
-QT_END_NAMESPACE
-
-#endif // QCLIPBOARD_P_H
diff --git a/src/gui/kernel/qclipboard_qpa.cpp b/src/gui/kernel/qclipboard_qpa.cpp
deleted file mode 100644
index 89c0afa22d..0000000000
--- a/src/gui/kernel/qclipboard_qpa.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qclipboard.h"
-
-#ifndef QT_NO_CLIPBOARD
-
-#include "qmimedata.h"
-#include "private/qapplication_p.h"
-#include "qplatformclipboard_qpa.h"
-
-QT_BEGIN_NAMESPACE
-
-QT_USE_NAMESPACE
-
-void QClipboard::clear(Mode mode)
-{
- setMimeData(0,mode);
-}
-
-
-bool QClipboard::event(QEvent *e)
-{
- return QObject::event(e);
-}
-
-const QMimeData* QClipboard::mimeData(Mode mode) const
-{
- QPlatformClipboard *clipboard = QGuiApplicationPrivate::platformIntegration()->clipboard();
- if (!clipboard->supportsMode(mode)) return 0;
- return clipboard->mimeData(mode);
-}
-
-void QClipboard::setMimeData(QMimeData* src, Mode mode)
-{
- QPlatformClipboard *clipboard = QGuiApplicationPrivate::platformIntegration()->clipboard();
- if (!clipboard->supportsMode(mode)) return;
-
- clipboard->setMimeData(src,mode);
-
- emitChanged(mode);
-}
-
-bool QClipboard::supportsMode(Mode mode) const
-{
- QPlatformClipboard *clipboard = QGuiApplicationPrivate::platformIntegration()->clipboard();
- return clipboard->supportsMode(mode);
-}
-
-bool QClipboard::ownsMode(Mode mode) const
-{
- if (mode == Clipboard)
- qWarning("QClipboard::ownsClipboard: UNIMPLEMENTED!");
- return false;
-}
-
-void QClipboard::connectNotify( const char * )
-{
-}
-
-void QClipboard::ownerDestroyed()
-{
-}
-
-#endif // QT_NO_CLIPBOARD
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qclipboard_s60.cpp b/src/gui/kernel/qclipboard_s60.cpp
deleted file mode 100644
index 0dafae0996..0000000000
--- a/src/gui/kernel/qclipboard_s60.cpp
+++ /dev/null
@@ -1,331 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qclipboard.h"
-
-#ifndef QT_NO_CLIPBOARD
-
-#include "qapplication.h"
-#include "qbitmap.h"
-#include "qdatetime.h"
-#include "qbuffer.h"
-#include "qwidget.h"
-#include "qevent.h"
-#include "private/qcore_symbian_p.h"
-#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
-#include "txtclipboard.h"
-#endif
-#include "txtetext.h"
-#include <QtDebug>
-
-// Symbian's clipboard
-#include <baclipb.h>
-QT_BEGIN_NAMESPACE
-
-const TUid KQtCbDataStream = {0x2001B2DD};
-const TInt KPlainTextBegin = 0;
-
-class QClipboardData
-{
-public:
- QClipboardData();
- ~QClipboardData();
-
- void setSource(QMimeData* s)
- {
- if (s == src)
- return;
- delete src;
- src = s;
- }
- QMimeData* source()
- { return src; }
- bool connected()
- { return connection; }
- void clear();
-
-private:
- QMimeData* src;
- bool connection;
-};
-
-QClipboardData::QClipboardData():src(0),connection(true)
-{
- clear();
-}
-
-QClipboardData::~QClipboardData()
-{
- connection = false;
- delete src;
-}
-
-void QClipboardData::clear()
-{
- QMimeData* newSrc = new QMimeData;
- delete src;
- src = newSrc;
-}
-
-static QClipboardData *internalCbData = 0;
-
-static void cleanupClipboardData()
-{
- delete internalCbData;
- internalCbData = 0;
-}
-
-static QClipboardData *clipboardData()
-{
- if (internalCbData == 0) {
- internalCbData = new QClipboardData;
- if (internalCbData)
- {
- if (!internalCbData->connected())
- {
- delete internalCbData;
- internalCbData = 0;
- }
- else
- {
- qAddPostRoutine(cleanupClipboardData);
- }
- }
- }
- return internalCbData;
-}
-
-void writeToStreamLX(const QMimeData* aData, RWriteStream& aStream)
-{
- // This function both leaves and throws exceptions. There must be no destructor
- // dependencies between cleanup styles, and no cleanup stack dependencies on stacked objects.
- QStringList headers = aData->formats();
- aStream << TCardinality(headers.count());
- for (QStringList::const_iterator iter= headers.constBegin();iter != headers.constEnd();iter++)
- {
- HBufC* stringData = TPtrC(reinterpret_cast<const TUint16*>((*iter).utf16())).AllocLC();
- QByteArray ba = aData->data((*iter));
- // mime type
- aStream << TCardinality(stringData->Size());
- aStream << *(stringData);
- // mime data
- aStream << TCardinality(ba.size());
- aStream.WriteL(reinterpret_cast<const uchar*>(ba.constData()),ba.size());
- CleanupStack::PopAndDestroy(stringData);
- }
-}
-
-void writeToSymbianStoreLX(const QMimeData* aData, CClipboard* clipboard)
-{
- // This function both leaves and throws exceptions. There must be no destructor
- // dependencies between cleanup styles, and no cleanup stack dependencies on stacked objects.
- if (aData->hasText()) {
- CPlainText* text = CPlainText::NewL();
- CleanupStack::PushL(text);
-
- TPtrC textPtr(qt_QString2TPtrC(aData->text()));
- text->InsertL(KPlainTextBegin, textPtr);
- text->CopyToStoreL(clipboard->Store(), clipboard->StreamDictionary(),
- KPlainTextBegin, textPtr.Length());
- CleanupStack::PopAndDestroy(text);
- }
-}
-
-void readSymbianStoreLX(QMimeData* aData, CClipboard* clipboard)
-{
- // This function both leaves and throws exceptions. There must be no destructor
- // dependencies between cleanup styles, and no cleanup stack dependencies on stacked objects.
- CPlainText* text = CPlainText::NewL();
- CleanupStack::PushL(text);
- TInt dataLength = text->PasteFromStoreL(clipboard->Store(), clipboard->StreamDictionary(),
- KPlainTextBegin);
- if (dataLength == 0) {
- User::Leave(KErrNotFound);
- }
- HBufC* hBuf = HBufC::NewL(dataLength);
- TPtr buf = hBuf->Des();
- text->Extract(buf, KPlainTextBegin, dataLength);
-
- QString string = qt_TDesC2QString(buf);
- CleanupStack::PopAndDestroy(text);
-
- aData->setText(string);
-}
-
-void readFromStreamLX(QMimeData* aData,RReadStream& aStream)
-{
- // This function both leaves and throws exceptions. There must be no destructor
- // dependencies between cleanup styles, and no cleanup stack dependencies on stacked objects.
- TCardinality mimeTypeCount;
- aStream >> mimeTypeCount;
- for (int i = 0; i< mimeTypeCount;i++)
- {
- // mime type
- TCardinality mimeTypeSize;
- aStream >> mimeTypeSize;
- HBufC* mimeTypeBuf = HBufC::NewLC(aStream,mimeTypeSize);
- QString mimeType = QString(reinterpret_cast<const QChar *>(mimeTypeBuf->Des().Ptr()),
- mimeTypeBuf->Length());
- CleanupStack::PopAndDestroy(mimeTypeBuf);
- // mime data
- TCardinality dataSize;
- aStream >> dataSize;
- QByteArray ba;
- ba.reserve(dataSize);
- aStream.ReadL(reinterpret_cast<uchar*>(ba.data_ptr()->data),dataSize);
- ba.data_ptr()->size = dataSize;
- aData->setData(mimeType,ba);
- }
-}
-
-
-/*****************************************************************************
- QClipboard member functions
- *****************************************************************************/
-
-void QClipboard::clear(Mode mode)
-{
- setText(QString(), mode);
-}
-const QMimeData* QClipboard::mimeData(Mode mode) const
-{
- if (mode != Clipboard) return 0;
- QClipboardData *d = clipboardData();
- bool dataExists(false);
- if (d)
- {
- TRAPD(err,{
- RFs fs = qt_s60GetRFs();
- CClipboard* cb = CClipboard::NewForReadingLC(fs);
- Q_ASSERT(cb);
- //stream for qt
- RStoreReadStream stream;
- TStreamId stid = (cb->StreamDictionary()).At(KQtCbDataStream);
- if (stid != 0) {
- stream.OpenLC(cb->Store(),stid);
- QT_TRYCATCH_LEAVING(readFromStreamLX(d->source(),stream));
- CleanupStack::PopAndDestroy(&stream);
- dataExists = true;
- }
- else {
- //symbian clipboard
- RStoreReadStream symbianStream;
- TStreamId symbianStId = (cb->StreamDictionary()).At(KClipboardUidTypePlainText);
- if (symbianStId != 0) {
- symbianStream.OpenLC(cb->Store(), symbianStId);
- QT_TRYCATCH_LEAVING(readSymbianStoreLX(d->source(), cb));
- CleanupStack::PopAndDestroy(&symbianStream);
- dataExists = true;
- }
- }
- CleanupStack::PopAndDestroy(cb);
- });
- if (err != KErrNone){
- qDebug()<< "clipboard is empty/err: " << err;
- }
-
- if (dataExists) {
- return d->source();
- }
- }
- return 0;
-}
-
-
-void QClipboard::setMimeData(QMimeData* src, Mode mode)
-{
- if (mode != Clipboard) return;
- QClipboardData *d = clipboardData();
- if (d)
- {
- TRAPD(err,{
- RFs fs = qt_s60GetRFs();
- CClipboard* cb = CClipboard::NewForWritingLC(fs);
- //stream for qt
- RStoreWriteStream stream;
- TStreamId stid = stream.CreateLC(cb->Store());
- QT_TRYCATCH_LEAVING(writeToStreamLX(src,stream));
- d->setSource(src);
- stream.CommitL();
- (cb->StreamDictionary()).AssignL(KQtCbDataStream,stid);
- cb->CommitL();
-
- //stream for symbian
- RStoreWriteStream symbianStream;
- TStreamId symbianStId = symbianStream.CreateLC(cb->Store());
- QT_TRYCATCH_LEAVING(writeToSymbianStoreLX(src, cb));
- (cb->StreamDictionary()).AssignL(KClipboardUidTypePlainText, symbianStId);
- cb->CommitL();
- CleanupStack::PopAndDestroy(3,cb);
- });
- if (err != KErrNone){
- qDebug()<< "clipboard write err :" << err;
- }
- }
- emitChanged(QClipboard::Clipboard);
-}
-
-bool QClipboard::supportsMode(Mode mode) const
-{
- return (mode == Clipboard);
-}
-
-bool QClipboard::ownsMode(Mode mode) const
-{
- if (mode == Clipboard)
- qWarning("QClipboard::ownsClipboard: UNIMPLEMENTED!");
- return false;
-}
-
-bool QClipboard::event(QEvent * /* e */)
-{
- return true;
-}
-
-void QClipboard::connectNotify( const char * )
-{
-}
-
-void QClipboard::ownerDestroyed()
-{
-}
-QT_END_NAMESPACE
-#endif // QT_NO_CLIPBOARD
diff --git a/src/gui/kernel/qclipboard_win.cpp b/src/gui/kernel/qclipboard_win.cpp
deleted file mode 100644
index ea41165b9c..0000000000
--- a/src/gui/kernel/qclipboard_win.cpp
+++ /dev/null
@@ -1,398 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qclipboard.h"
-
-#ifndef QT_NO_CLIPBOARD
-
-#include "qapplication.h"
-#include "qapplication_p.h"
-#include "qeventloop.h"
-#include "qwidget.h"
-#include "qevent.h"
-#include "qmime.h"
-#include "qt_windows.h"
-#include "qdnd_p.h"
-#include <private/qwidget_p.h>
-#include <private/qsystemlibrary_p.h>
-
-QT_BEGIN_NAMESPACE
-
-#if defined(Q_OS_WINCE)
-QT_BEGIN_INCLUDE_NAMESPACE
-#include "qguifunctions_wince.h"
-QT_END_INCLUDE_NAMESPACE
-
-HRESULT QtCeGetClipboard(IDataObject** obj);
-HRESULT QtCeSetClipboard(IDataObject* obj);
-void QtCeFlushClipboard();
-
-#define OleGetClipboard QtCeGetClipboard
-#define OleSetClipboard QtCeSetClipboard
-#define OleFlushClipboard QtCeFlushClipboard
-
-#endif
-
-typedef BOOL (WINAPI *PtrIsHungAppWindow)(HWND);
-
-static PtrIsHungAppWindow ptrIsHungAppWindow = 0;
-
-class QClipboardWatcher : public QInternalMimeData {
-public:
- QClipboardWatcher()
- : QInternalMimeData()
- {
- }
-
- bool hasFormat_sys(const QString &mimetype) const;
- QStringList formats_sys() const;
- QVariant retrieveData_sys(const QString &mimetype, QVariant::Type preferredType) const;
-};
-
-
-bool QClipboardWatcher::hasFormat_sys(const QString &mime) const
-{
- IDataObject * pDataObj = 0;
-
- if (OleGetClipboard(&pDataObj) != S_OK && !pDataObj) // Sanity
- return false;
-
- bool has = QWindowsMime::converterToMime(mime, pDataObj) != 0;
-
- pDataObj->Release();
-
- return has;
-}
-
-QStringList QClipboardWatcher::formats_sys() const
-{
- QStringList fmts;
- IDataObject * pDataObj = 0;
-
- if (OleGetClipboard(&pDataObj) != S_OK && !pDataObj) // Sanity
- return QStringList();
-
- fmts = QWindowsMime::allMimesForFormats(pDataObj);
-
- pDataObj->Release();
-
- return fmts;
-}
-
-QVariant QClipboardWatcher::retrieveData_sys(const QString &mimeType, QVariant::Type type) const
-{
- QVariant result;
- IDataObject * pDataObj = 0;
-
- if (OleGetClipboard(&pDataObj) != S_OK && !pDataObj) // Sanity
- return result;
-
- QWindowsMime *converter = QWindowsMime::converterToMime(mimeType, pDataObj);
-
- if (converter)
- result = converter->convertToMime(mimeType, pDataObj, type);
-
- pDataObj->Release();
-
- return result;
-}
-
-class QClipboardData
-{
-public:
- QClipboardData()
- : iData(0)
- , nextClipboardViewer(0)
- {
- clipBoardViewer = new QWidget();
- clipBoardViewer->createWinId();
- clipBoardViewer->setObjectName(QLatin1String("internal clipboard owner"));
- // We don't need this internal widget to appear in QApplication::topLevelWidgets()
- if (QWidgetPrivate::allWidgets)
- QWidgetPrivate::allWidgets->remove(clipBoardViewer);
- }
-
- ~QClipboardData()
- {
- Q_ASSERT(clipBoardViewer->testAttribute(Qt::WA_WState_Created));
- ChangeClipboardChain(clipBoardViewer->internalWinId(), nextClipboardViewer);
- delete clipBoardViewer;
- releaseIData();
- }
-
- void releaseIData()
- {
- if (iData) {
- delete iData->mimeData();
- iData->releaseQt();
- iData->Release();
- iData = 0;
- }
- }
-
- QOleDataObject * iData;
- QWidget *clipBoardViewer;
- HWND nextClipboardViewer;
- QClipboardWatcher watcher;
-};
-
-static QClipboardData *ptrClipboardData = 0;
-
-static QClipboardData *clipboardData()
-{
- if (ptrClipboardData == 0) {
- ptrClipboardData = new QClipboardData;
- // this needs to be done here to avoid recursion
- Q_ASSERT(ptrClipboardData->clipBoardViewer->testAttribute(Qt::WA_WState_Created));
- ptrClipboardData->nextClipboardViewer = SetClipboardViewer(ptrClipboardData->clipBoardViewer->internalWinId());
- }
- return ptrClipboardData;
-}
-
-static void cleanupClipboardData()
-{
- delete ptrClipboardData;
- ptrClipboardData = 0;
-}
-
-#if defined(Q_OS_WINCE)
-HRESULT QtCeGetClipboard(IDataObject** obj)
-{
- HWND owner = ptrClipboardData->clipBoardViewer->internalWinId();
- if (!OpenClipboard(owner))
- return !S_OK;
-
- if (!IsClipboardFormatAvailable(CF_TEXT) && !IsClipboardFormatAvailable(CF_UNICODETEXT))
- return !S_OK;
-
- HANDLE clipData = GetClipboardData(CF_TEXT);
- QString clipText;
- if (clipData == 0) {
- clipData = GetClipboardData(CF_UNICODETEXT);
- if (clipData != 0)
- clipText = QString::fromWCharArray((wchar_t *)clipData);
- } else {
- clipText = QString::fromLatin1((const char*)clipData);
- }
-
- QMimeData *mimeData = new QMimeData();
- mimeData->setText(clipText);
- QOleDataObject* data = new QOleDataObject(mimeData);
- *obj = data;
- CloseClipboard();
- return S_OK;
-}
-
-HRESULT QtCeSetClipboard(IDataObject* obj)
-{
- HWND owner = ptrClipboardData->clipBoardViewer->internalWinId();
- if (!OpenClipboard(owner))
- return !S_OK;
-
- bool result = false;
- if (obj == 0) {
- result = true;
- EmptyClipboard();
- CloseClipboard();
- } else {
- QOleDataObject* qobj = static_cast<QOleDataObject*>(obj);
-
- const QMimeData* data = qobj->mimeData();
- if (data->hasText()) {
- EmptyClipboard();
- result = SetClipboardData(CF_UNICODETEXT, wcsdup(reinterpret_cast<const wchar_t *> (data->text().utf16()))) != NULL;
- CloseClipboard();
- result = true;
- }
- }
- return result ? S_OK : !S_OK;
-}
-
-void QtCeFlushClipboard() { }
-#endif
-
-
-
-QClipboard::~QClipboard()
-{
- cleanupClipboardData();
-}
-
-void QClipboard::setMimeData(QMimeData *src, Mode mode)
-{
- if (mode != Clipboard)
- return;
- QClipboardData *d = clipboardData();
-
- if (!(d->iData && d->iData->mimeData() == src)) {
- d->releaseIData();
- d->iData = new QOleDataObject(src);
- }
-
- if (OleSetClipboard(d->iData) != S_OK) {
- d->releaseIData();
- qErrnoWarning("QClipboard::setMimeData: Failed to set data on clipboard");
- return;
- }
-#if defined(Q_OS_WINCE)
- // As WinCE does not support notifications we send the signal here
- // We will get no event when the clipboard changes outside...
- emit dataChanged();
- emit changed(Clipboard);
-#endif
-}
-
-void QClipboard::clear(Mode mode)
-{
- if (mode != Clipboard) return;
-
- QClipboardData *d = clipboardData();
-
- d->releaseIData();
-
- if (OleSetClipboard(0) != S_OK) {
- qErrnoWarning("QClipboard::clear: Failed to clear data on clipboard");
- return;
- }
-#if defined(Q_OS_WINCE)
- // As WinCE does not support notifications we send the signal here
- // We will get no event when the clipboard changes outside...
- emit dataChanged();
- emit changed(Clipboard);
-#endif
-}
-
-bool QClipboard::event(QEvent *e)
-{
- if (e->type() != QEvent::Clipboard)
- return QObject::event(e);
-
- QClipboardData *d = clipboardData();
-
- MSG *m = (MSG *)((QClipboardEvent*)e)->data();
- if (!m) {
- // this is sent to render all formats at app shut down
- if (ownsClipboard()) {
- OleFlushClipboard();
- d->releaseIData();
- }
- return true;
- }
-
- bool propagate = false;
-
- if (m->message == WM_CHANGECBCHAIN) {
- if ((HWND)m->wParam == d->nextClipboardViewer)
- d->nextClipboardViewer = (HWND)m->lParam;
- else
- propagate = true;
- } else if (m->message == WM_DRAWCLIPBOARD) {
- emitChanged(QClipboard::Clipboard);
- if (!ownsClipboard() && d->iData)
- // clean up the clipboard object if we no longer own the clipboard
- d->releaseIData();
- propagate = true;
- }
- if (propagate && d->nextClipboardViewer) {
- if (ptrIsHungAppWindow == 0) {
- QSystemLibrary library(QLatin1String("User32"));
- ptrIsHungAppWindow = (PtrIsHungAppWindow)library.resolve("IsHungAppWindow");
- }
- if (ptrIsHungAppWindow && ptrIsHungAppWindow(d->nextClipboardViewer)) {
- qWarning("%s: Cowardly refusing to send clipboard message to hung application...", Q_FUNC_INFO);
- } else {
- SendMessage(d->nextClipboardViewer, m->message, m->wParam, m->lParam);
- }
- }
-
- return true;
-}
-
-void QClipboard::connectNotify(const char *signal)
-{
- if (qstrcmp(signal,SIGNAL(dataChanged())) == 0) {
- // ensure we are up and running but block signals so the dataChange signal
- // is not emitted while being connected to.
- bool blocked = blockSignals(true);
- QClipboardData *d = clipboardData();
- blockSignals(blocked);
- Q_UNUSED(d);
- }
-}
-
-const QMimeData *QClipboard::mimeData(Mode mode) const
-{
- if (mode != Clipboard)
- return 0;
-
- QClipboardData *data = clipboardData();
- // sort cut for local copy / paste
- if (ownsClipboard() && data->iData->mimeData())
- return data->iData->mimeData();
- return &data->watcher;
-}
-
-bool QClipboard::supportsMode(Mode mode) const
-{
- return (mode == Clipboard);
-}
-
-bool QClipboard::ownsMode(Mode mode) const
-{
- if (mode == Clipboard) {
- QClipboardData *d = clipboardData();
-#if !defined(Q_OS_WINCE)
- return d->iData && OleIsCurrentClipboard(d->iData) == S_OK;
-#else
- return d->iData && GetClipboardOwner() == d->clipBoardViewer->internalWinId();
-#endif
- } else {
- return false;
- }
-}
-
-void QClipboard::ownerDestroyed()
-{
-}
-
-QT_END_NAMESPACE
-
-#endif // QT_NO_CLIPBOARD
diff --git a/src/gui/kernel/qclipboard_x11.cpp b/src/gui/kernel/qclipboard_x11.cpp
deleted file mode 100644
index d566c86e04..0000000000
--- a/src/gui/kernel/qclipboard_x11.cpp
+++ /dev/null
@@ -1,1539 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-// #define QCLIPBOARD_DEBUG
-// #define QCLIPBOARD_DEBUG_VERBOSE
-
-#ifdef QCLIPBOARD_DEBUG
-# define DEBUG qDebug
-#else
-# define DEBUG if (false) qDebug
-#endif
-
-#ifdef QCLIPBOARD_DEBUG_VERBOSE
-# define VDEBUG qDebug
-#else
-# define VDEBUG if (false) qDebug
-#endif
-
-#include "qplatformdefs.h"
-
-#include "qclipboard.h"
-#include "qclipboard_p.h"
-
-#ifndef QT_NO_CLIPBOARD
-
-#include "qabstracteventdispatcher.h"
-#include "qapplication.h"
-#include "qdesktopwidget.h"
-#include "qbitmap.h"
-#include "qiodevice.h"
-#include "qbuffer.h"
-#include "qtextcodec.h"
-#include "qlist.h"
-#include "qmap.h"
-#include "qapplication_p.h"
-#include "qevent.h"
-#include "qt_x11_p.h"
-#include "qx11info_x11.h"
-#include "qimagewriter.h"
-#include "qelapsedtimer.h"
-#include "qvariant.h"
-#include "qdnd_p.h"
-#include <private/qwidget_p.h>
-
-#ifndef QT_NO_XFIXES
-#include <X11/extensions/Xfixes.h>
-#endif // QT_NO_XFIXES
-
-QT_BEGIN_NAMESPACE
-
-/*****************************************************************************
- Internal QClipboard functions for X11.
- *****************************************************************************/
-
-static int clipboard_timeout = 5000; // 5s timeout on clipboard operations
-
-static QWidget * owner = 0;
-static QWidget *requestor = 0;
-static bool timer_event_clear = false;
-static int timer_id = 0;
-
-static int pending_timer_id = 0;
-static bool pending_clipboard_changed = false;
-static bool pending_selection_changed = false;
-
-
-// event capture mechanism for qt_xclb_wait_for_event
-static bool waiting_for_data = false;
-static bool has_captured_event = false;
-static Window capture_event_win = XNone;
-static int capture_event_type = -1;
-static XEvent captured_event;
-
-class QClipboardWatcher; // forward decl
-static QClipboardWatcher *selection_watcher = 0;
-static QClipboardWatcher *clipboard_watcher = 0;
-
-static void cleanup()
-{
- delete owner;
- delete requestor;
- owner = 0;
- requestor = 0;
-}
-
-static
-void setupOwner()
-{
- if (owner)
- return;
- owner = new QWidget(0);
- owner->setObjectName(QLatin1String("internal clipboard owner"));
- owner->createWinId();
- requestor = new QWidget(0);
- requestor->createWinId();
- requestor->setObjectName(QLatin1String("internal clipboard requestor"));
- // We don't need this internal widgets to appear in QApplication::topLevelWidgets()
- if (QWidgetPrivate::allWidgets) {
- QWidgetPrivate::allWidgets->remove(owner);
- QWidgetPrivate::allWidgets->remove(requestor);
- }
- qAddPostRoutine(cleanup);
-}
-
-
-class QClipboardWatcher : public QInternalMimeData {
-public:
- QClipboardWatcher(QClipboard::Mode mode);
- ~QClipboardWatcher();
- bool empty() const;
- virtual bool hasFormat_sys(const QString &mimetype) const;
- virtual QStringList formats_sys() const;
-
- QVariant retrieveData_sys(const QString &mimetype, QVariant::Type type) const;
- QByteArray getDataInFormat(Atom fmtatom) const;
-
- Atom atom;
- mutable QStringList formatList;
- mutable QByteArray format_atoms;
-};
-
-class QClipboardData
-{
-private:
- QMimeData *&mimeDataRef() const
- {
- if(mode == QClipboard::Selection)
- return selectionData;
- return clipboardData;
- }
-
-public:
- QClipboardData(QClipboard::Mode mode);
- ~QClipboardData();
-
- void setSource(QMimeData* s)
- {
- if ((mode == QClipboard::Selection && selectionData == s)
- || clipboardData == s) {
- return;
- }
-
- if (selectionData != clipboardData) {
- delete mimeDataRef();
- }
-
- mimeDataRef() = s;
- }
-
- QMimeData *source() const
- {
- return mimeDataRef();
- }
-
- void clear()
- {
- timestamp = CurrentTime;
- if (selectionData == clipboardData) {
- mimeDataRef() = 0;
- } else {
- QMimeData *&src = mimeDataRef();
- delete src;
- src = 0;
- }
- }
-
- static QMimeData *selectionData;
- static QMimeData *clipboardData;
- Time timestamp;
- QClipboard::Mode mode;
-};
-
-QMimeData *QClipboardData::selectionData = 0;
-QMimeData *QClipboardData::clipboardData = 0;
-
-QClipboardData::QClipboardData(QClipboard::Mode clipboardMode)
-{
- timestamp = CurrentTime;
- mode = clipboardMode;
-}
-
-QClipboardData::~QClipboardData()
-{ clear(); }
-
-
-static QClipboardData *internalCbData = 0;
-static QClipboardData *internalSelData = 0;
-
-static void cleanupClipboardData()
-{
- delete internalCbData;
- internalCbData = 0;
-}
-
-static QClipboardData *clipboardData()
-{
- if (internalCbData == 0) {
- internalCbData = new QClipboardData(QClipboard::Clipboard);
- qAddPostRoutine(cleanupClipboardData);
- }
- return internalCbData;
-}
-
-static void cleanupSelectionData()
-{
- delete internalSelData;
- internalSelData = 0;
-}
-
-static QClipboardData *selectionData()
-{
- if (internalSelData == 0) {
- internalSelData = new QClipboardData(QClipboard::Selection);
- qAddPostRoutine(cleanupSelectionData);
- }
- return internalSelData;
-}
-
-class QClipboardINCRTransaction
-{
-public:
- QClipboardINCRTransaction(Window w, Atom p, Atom t, int f, QByteArray d, unsigned int i);
- ~QClipboardINCRTransaction(void);
-
- int x11Event(XEvent *event);
-
- Window window;
- Atom property, target;
- int format;
- QByteArray data;
- unsigned int increment;
- unsigned int offset;
-};
-
-typedef QMap<Window,QClipboardINCRTransaction*> TransactionMap;
-static TransactionMap *transactions = 0;
-static QApplication::EventFilter prev_event_filter = 0;
-static int incr_timer_id = 0;
-
-static bool qt_x11_incr_event_filter(void *message, long *result)
-{
- XEvent *event = reinterpret_cast<XEvent *>(message);
- TransactionMap::Iterator it = transactions->find(event->xany.window);
- if (it != transactions->end()) {
- if ((*it)->x11Event(event) != 0)
- return true;
- }
- if (prev_event_filter)
- return prev_event_filter(event, result);
- return false;
-}
-
-/*
- called when no INCR activity has happened for 'clipboard_timeout'
- milliseconds... we assume that all unfinished transactions have
- timed out and remove everything from the transaction map
-*/
-static void qt_xclb_incr_timeout(void)
-{
- qWarning("QClipboard: Timed out while sending data");
-
- while (transactions)
- delete *transactions->begin();
-}
-
-QClipboardINCRTransaction::QClipboardINCRTransaction(Window w, Atom p, Atom t, int f,
- QByteArray d, unsigned int i)
- : window(w), property(p), target(t), format(f), data(d), increment(i), offset(0u)
-{
- DEBUG("QClipboard: sending %d bytes (INCR transaction %p)", d.size(), this);
-
- XSelectInput(X11->display, window, PropertyChangeMask);
-
- if (! transactions) {
- VDEBUG("QClipboard: created INCR transaction map");
- transactions = new TransactionMap;
- prev_event_filter = qApp->setEventFilter(qt_x11_incr_event_filter);
- incr_timer_id = QApplication::clipboard()->startTimer(clipboard_timeout);
- }
- transactions->insert(window, this);
-}
-
-QClipboardINCRTransaction::~QClipboardINCRTransaction(void)
-{
- VDEBUG("QClipboard: destroyed INCR transacton %p", this);
-
- XSelectInput(X11->display, window, NoEventMask);
-
- transactions->remove(window);
- if (transactions->isEmpty()) {
- VDEBUG("QClipboard: no more INCR transactions");
- delete transactions;
- transactions = 0;
-
- (void)qApp->setEventFilter(prev_event_filter);
-
- if (incr_timer_id != 0) {
- QApplication::clipboard()->killTimer(incr_timer_id);
- incr_timer_id = 0;
- }
- }
-}
-
-int QClipboardINCRTransaction::x11Event(XEvent *event)
-{
- if (event->type != PropertyNotify
- || (event->xproperty.state != PropertyDelete
- || event->xproperty.atom != property))
- return 0;
-
- // restart the INCR timer
- if (incr_timer_id) QApplication::clipboard()->killTimer(incr_timer_id);
- incr_timer_id = QApplication::clipboard()->startTimer(clipboard_timeout);
-
- unsigned int bytes_left = data.size() - offset;
- if (bytes_left > 0) {
- unsigned int xfer = qMin(increment, bytes_left);
- VDEBUG("QClipboard: sending %d bytes, %d remaining (INCR transaction %p)",
- xfer, bytes_left - xfer, this);
-
- XChangeProperty(X11->display, window, property, target, format,
- PropModeReplace, (uchar *) data.data() + offset, xfer);
- offset += xfer;
- } else {
- // INCR transaction finished...
- XChangeProperty(X11->display, window, property, target, format,
- PropModeReplace, (uchar *) data.data(), 0);
- delete this;
- }
-
- return 1;
-}
-
-
-/*****************************************************************************
- QClipboard member functions for X11.
- *****************************************************************************/
-
-struct qt_init_timestamp_data
-{
- Time timestamp;
-};
-
-#if defined(Q_C_CALLBACKS)
-extern "C" {
-#endif
-
-static Bool qt_init_timestamp_scanner(Display*, XEvent *event, XPointer arg)
-{
- qt_init_timestamp_data *data =
- reinterpret_cast<qt_init_timestamp_data*>(arg);
- switch(event->type)
- {
- case ButtonPress:
- case ButtonRelease:
- data->timestamp = event->xbutton.time;
- break;
- case MotionNotify:
- data->timestamp = event->xmotion.time;
- break;
- case XKeyPress:
- case XKeyRelease:
- data->timestamp = event->xkey.time;
- break;
- case PropertyNotify:
- data->timestamp = event->xproperty.time;
- break;
- case EnterNotify:
- case LeaveNotify:
- data->timestamp = event->xcrossing.time;
- break;
- case SelectionClear:
- data->timestamp = event->xselectionclear.time;
- break;
- default:
- break;
- }
-#ifndef QT_NO_XFIXES
- if (X11->use_xfixes && event->type == (X11->xfixes_eventbase + XFixesSelectionNotify)) {
- XFixesSelectionNotifyEvent *req =
- reinterpret_cast<XFixesSelectionNotifyEvent *>(event);
- data->timestamp = req->selection_timestamp;
- }
-#endif
- return false;
-}
-
-#if defined(Q_C_CALLBACKS)
-}
-#endif
-
-QClipboard::QClipboard(QObject *parent)
- : QObject(*new QClipboardPrivate, parent)
-{
- // create desktop widget since we need it to get PropertyNotify or
- // XFixesSelectionNotify events when someone changes the
- // clipboard.
- (void)QApplication::desktop();
-
-#ifndef QT_NO_XFIXES
- if (X11->use_xfixes && X11->ptrXFixesSelectSelectionInput) {
- const unsigned long eventMask =
- XFixesSetSelectionOwnerNotifyMask | XFixesSelectionWindowDestroyNotifyMask | XFixesSelectionClientCloseNotifyMask;
- for (int i = 0; i < X11->screenCount; ++i) {
- X11->ptrXFixesSelectSelectionInput(X11->display, QX11Info::appRootWindow(i),
- XA_PRIMARY, eventMask);
- X11->ptrXFixesSelectSelectionInput(X11->display, QX11Info::appRootWindow(i),
- ATOM(CLIPBOARD), eventMask);
- }
- }
-#endif // QT_NO_XFIXES
-
- if (X11->time == CurrentTime) {
- // send a dummy event to myself to get the timestamp from X11.
- qt_init_timestamp_data data;
- data.timestamp = CurrentTime;
- XEvent ev;
- XCheckIfEvent(X11->display, &ev, &qt_init_timestamp_scanner, (XPointer)&data);
- if (data.timestamp == CurrentTime) {
- setupOwner();
- // We need this value just for completeness, we don't use it.
- long dummy = 0;
- Window ownerId = owner->internalWinId();
- XChangeProperty(X11->display, ownerId,
- ATOM(CLIP_TEMPORARY), XA_INTEGER, 32,
- PropModeReplace, (uchar*)&dummy, 1);
- XWindowEvent(X11->display, ownerId, PropertyChangeMask, &ev);
- data.timestamp = ev.xproperty.time;
- XDeleteProperty(X11->display, ownerId, ATOM(CLIP_TEMPORARY));
- }
- X11->time = data.timestamp;
- }
-}
-
-void QClipboard::clear(Mode mode)
-{
- setMimeData(0, mode);
-}
-
-
-bool QClipboard::supportsMode(Mode mode) const
-{
- return (mode == Clipboard || mode == Selection);
-}
-
-bool QClipboard::ownsMode(Mode mode) const
-{
- if (mode == Clipboard)
- return clipboardData()->timestamp != CurrentTime;
- else if(mode == Selection)
- return selectionData()->timestamp != CurrentTime;
- else
- return false;
-}
-
-
-// event filter function... captures interesting events while
-// qt_xclb_wait_for_event is running the event loop
-static bool qt_x11_clipboard_event_filter(void *message, long *)
-{
- XEvent *event = reinterpret_cast<XEvent *>(message);
- if (event->xany.type == capture_event_type &&
- event->xany.window == capture_event_win) {
- VDEBUG("QClipboard: event_filter(): caught event type %d", event->type);
- has_captured_event = true;
- captured_event = *event;
- return true;
- }
- return false;
-}
-
-static Bool checkForClipboardEvents(Display *, XEvent *e, XPointer)
-{
- return ((e->type == SelectionRequest && (e->xselectionrequest.selection == XA_PRIMARY
- || e->xselectionrequest.selection == ATOM(CLIPBOARD)))
- || (e->type == SelectionClear && (e->xselectionclear.selection == XA_PRIMARY
- || e->xselectionclear.selection == ATOM(CLIPBOARD))));
-}
-
-bool QX11Data::clipboardWaitForEvent(Window win, int type, XEvent *event, int timeout)
-{
- QElapsedTimer started;
- started.start();
- QElapsedTimer now = started;
-
- if (QAbstractEventDispatcher::instance()->inherits("QtMotif")
- || QApplication::clipboard()->property("useEventLoopWhenWaiting").toBool()) {
- if (waiting_for_data) {
- Q_ASSERT(!"QClipboard: internal error, qt_xclb_wait_for_event recursed");
- return false;
- }
- waiting_for_data = true;
-
-
- has_captured_event = false;
- capture_event_win = win;
- capture_event_type = type;
-
- QApplication::EventFilter old_event_filter =
- qApp->setEventFilter(qt_x11_clipboard_event_filter);
-
- do {
- if (XCheckTypedWindowEvent(display, win, type, event)) {
- waiting_for_data = false;
- qApp->setEventFilter(old_event_filter);
- return true;
- }
-
- XSync(X11->display, false);
- usleep(50000);
-
- now.start();
-
- QEventLoop::ProcessEventsFlags flags(QEventLoop::ExcludeUserInputEvents
- | QEventLoop::ExcludeSocketNotifiers
- | QEventLoop::WaitForMoreEvents
- | QEventLoop::X11ExcludeTimers);
- QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
- eventDispatcher->processEvents(flags);
-
- if (has_captured_event) {
- waiting_for_data = false;
- *event = captured_event;
- qApp->setEventFilter(old_event_filter);
- return true;
- }
- } while (started.msecsTo(now) < timeout);
-
- waiting_for_data = false;
- qApp->setEventFilter(old_event_filter);
- } else {
- do {
- if (XCheckTypedWindowEvent(X11->display,win,type,event))
- return true;
-
- // process other clipboard events, since someone is probably requesting data from us
- XEvent e;
- if (XCheckIfEvent(X11->display, &e, checkForClipboardEvents, 0))
- qApp->x11ProcessEvent(&e);
-
- now.start();
-
- XFlush(X11->display);
-
- // sleep 50 ms, so we don't use up CPU cycles all the time.
- struct timeval usleep_tv;
- usleep_tv.tv_sec = 0;
- usleep_tv.tv_usec = 50000;
- select(0, 0, 0, 0, &usleep_tv);
- } while (started.msecsTo(now) < timeout);
- }
- return false;
-}
-
-
-static inline int maxSelectionIncr(Display *dpy)
-{ return XMaxRequestSize(dpy) > 65536 ? 65536*4 : XMaxRequestSize(dpy)*4 - 100; }
-
-bool QX11Data::clipboardReadProperty(Window win, Atom property, bool deleteProperty,
- QByteArray *buffer, int *size, Atom *type, int *format)
-{
- int maxsize = maxSelectionIncr(display);
- ulong bytes_left; // bytes_after
- ulong length; // nitems
- uchar *data;
- Atom dummy_type;
- int dummy_format;
- int r;
-
- if (!type) // allow null args
- type = &dummy_type;
- if (!format)
- format = &dummy_format;
-
- // Don't read anything, just get the size of the property data
- r = XGetWindowProperty(display, win, property, 0, 0, False,
- AnyPropertyType, type, format,
- &length, &bytes_left, &data);
- if (r != Success || (type && *type == XNone)) {
- buffer->resize(0);
- return false;
- }
- XFree((char*)data);
-
- int offset = 0, buffer_offset = 0, format_inc = 1, proplen = bytes_left;
-
- VDEBUG("QClipboard: read_property(): initial property length: %d", proplen);
-
- switch (*format) {
- case 8:
- default:
- format_inc = sizeof(char) / 1;
- break;
-
- case 16:
- format_inc = sizeof(short) / 2;
- proplen *= sizeof(short) / 2;
- break;
-
- case 32:
- format_inc = sizeof(long) / 4;
- proplen *= sizeof(long) / 4;
- break;
- }
-
- int newSize = proplen;
- buffer->resize(newSize);
-
- bool ok = (buffer->size() == newSize);
- VDEBUG("QClipboard: read_property(): buffer resized to %d", buffer->size());
-
- if (ok && newSize) {
- // could allocate buffer
-
- while (bytes_left) {
- // more to read...
-
- r = XGetWindowProperty(display, win, property, offset, maxsize/4,
- False, AnyPropertyType, type, format,
- &length, &bytes_left, &data);
- if (r != Success || (type && *type == XNone))
- break;
-
- offset += length / (32 / *format);
- length *= format_inc * (*format) / 8;
-
- // Here we check if we get a buffer overflow and tries to
- // recover -- this shouldn't normally happen, but it doesn't
- // hurt to be defensive
- if ((int)(buffer_offset + length) > buffer->size()) {
- length = buffer->size() - buffer_offset;
-
- // escape loop
- bytes_left = 0;
- }
-
- memcpy(buffer->data() + buffer_offset, data, length);
- buffer_offset += length;
-
- XFree((char*)data);
- }
-
- if (*format == 8 && *type == ATOM(COMPOUND_TEXT)) {
- // convert COMPOUND_TEXT to a multibyte string
- XTextProperty textprop;
- textprop.encoding = *type;
- textprop.format = *format;
- textprop.nitems = buffer_offset;
- textprop.value = (unsigned char *) buffer->data();
-
- char **list_ret = 0;
- int count;
- if (XmbTextPropertyToTextList(display, &textprop, &list_ret,
- &count) == Success && count && list_ret) {
- offset = buffer_offset = strlen(list_ret[0]);
- buffer->resize(offset);
- memcpy(buffer->data(), list_ret[0], offset);
- }
- if (list_ret) XFreeStringList(list_ret);
- }
- }
-
- // correct size, not 0-term.
- if (size)
- *size = buffer_offset;
-
- VDEBUG("QClipboard: read_property(): buffer size %d, buffer offset %d, offset %d",
- buffer->size(), buffer_offset, offset);
-
- if (deleteProperty)
- XDeleteProperty(display, win, property);
-
- XFlush(display);
-
- return ok;
-}
-
-QByteArray QX11Data::clipboardReadIncrementalProperty(Window win, Atom property, int nbytes, bool nullterm)
-{
- XEvent event;
-
- QByteArray buf;
- QByteArray tmp_buf;
- bool alloc_error = false;
- int length;
- int offset = 0;
-
- if (nbytes > 0) {
- // Reserve buffer + zero-terminator (for text data)
- // We want to complete the INCR transfer even if we cannot
- // allocate more memory
- buf.resize(nbytes+1);
- alloc_error = buf.size() != nbytes+1;
- }
-
- for (;;) {
- XFlush(display);
- if (!clipboardWaitForEvent(win,PropertyNotify,&event,clipboard_timeout))
- break;
- if (event.xproperty.atom != property ||
- event.xproperty.state != PropertyNewValue)
- continue;
- if (X11->clipboardReadProperty(win, property, true, &tmp_buf, &length, 0, 0)) {
- if (length == 0) { // no more data, we're done
- if (nullterm) {
- buf.resize(offset+1);
- buf[offset] = '\0';
- } else {
- buf.resize(offset);
- }
- return buf;
- } else if (!alloc_error) {
- if (offset+length > (int)buf.size()) {
- buf.resize(offset+length+65535);
- if (buf.size() != offset+length+65535) {
- alloc_error = true;
- length = buf.size() - offset;
- }
- }
- memcpy(buf.data()+offset, tmp_buf.constData(), length);
- tmp_buf.resize(0);
- offset += length;
- }
- } else {
- break;
- }
- }
-
- // timed out ... create a new requestor window, otherwise the requestor
- // could consider next request to be still part of this timed out request
- delete requestor;
- requestor = new QWidget(0);
- requestor->setObjectName(QLatin1String("internal clipboard requestor"));
- // We don't need this internal widget to appear in QApplication::topLevelWidgets()
- if (QWidgetPrivate::allWidgets)
- QWidgetPrivate::allWidgets->remove(requestor);
-
- return QByteArray();
-}
-
-static Atom send_targets_selection(QClipboardData *d, Window window, Atom property)
-{
- QVector<Atom> types;
- QStringList formats = QInternalMimeData::formatsHelper(d->source());
- for (int i = 0; i < formats.size(); ++i) {
- QList<Atom> atoms = X11->xdndMimeAtomsForFormat(formats.at(i));
- for (int j = 0; j < atoms.size(); ++j) {
- if (!types.contains(atoms.at(j)))
- types.append(atoms.at(j));
- }
- }
- types.append(ATOM(TARGETS));
- types.append(ATOM(MULTIPLE));
- types.append(ATOM(TIMESTAMP));
- types.append(ATOM(SAVE_TARGETS));
-
- XChangeProperty(X11->display, window, property, XA_ATOM, 32,
- PropModeReplace, (uchar *) types.data(), types.size());
- return property;
-}
-
-static Atom send_selection(QClipboardData *d, Atom target, Window window, Atom property)
-{
- Atom atomFormat = target;
- int dataFormat = 0;
- QByteArray data;
-
- QByteArray fmt = X11->xdndAtomToString(target);
- if (fmt.isEmpty()) { // Not a MIME type we have
- DEBUG("QClipboard: send_selection(): converting to type '%s' is not supported", fmt.data());
- return XNone;
- }
- DEBUG("QClipboard: send_selection(): converting to type '%s'", fmt.data());
-
- if (X11->xdndMimeDataForAtom(target, d->source(), &data, &atomFormat, &dataFormat)) {
-
- VDEBUG("QClipboard: send_selection():\n"
- " property type %lx\n"
- " property name '%s'\n"
- " format %d\n"
- " %d bytes\n",
- target, X11->xdndMimeAtomToString(atomFormat).toLatin1().data(), dataFormat, data.size());
-
- // don't allow INCR transfers when using MULTIPLE or to
- // Motif clients (since Motif doesn't support INCR)
- static Atom motif_clip_temporary = ATOM(CLIP_TEMPORARY);
- bool allow_incr = property != motif_clip_temporary;
-
- // X_ChangeProperty protocol request is 24 bytes
- const int increment = (XMaxRequestSize(X11->display) * 4) - 24;
- if (data.size() > increment && allow_incr) {
- long bytes = data.size();
- XChangeProperty(X11->display, window, property,
- ATOM(INCR), 32, PropModeReplace, (uchar *) &bytes, 1);
-
- (void)new QClipboardINCRTransaction(window, property, atomFormat, dataFormat, data, increment);
- return property;
- }
-
- // make sure we can perform the XChangeProperty in a single request
- if (data.size() > increment)
- return XNone; // ### perhaps use several XChangeProperty calls w/ PropModeAppend?
- int dataSize = data.size() / (dataFormat / 8);
- // use a single request to transfer data
- XChangeProperty(X11->display, window, property, atomFormat,
- dataFormat, PropModeReplace, (uchar *) data.data(),
- dataSize);
- }
- return property;
-}
-
-/*! \internal
- Internal cleanup for Windows.
-*/
-void QClipboard::ownerDestroyed()
-{ }
-
-
-/*! \internal
- Internal optimization for Windows.
-*/
-void QClipboard::connectNotify(const char *)
-{ }
-
-
-bool QClipboard::event(QEvent *e)
-{
- if (e->type() == QEvent::Timer) {
- QTimerEvent *te = (QTimerEvent *) e;
-
- if (waiting_for_data) // should never happen
- return false;
-
- if (te->timerId() == timer_id) {
- killTimer(timer_id);
- timer_id = 0;
-
- timer_event_clear = true;
- if (selection_watcher) // clear selection
- selectionData()->clear();
- if (clipboard_watcher) // clear clipboard
- clipboardData()->clear();
- timer_event_clear = false;
-
- return true;
- } else if (te->timerId() == pending_timer_id) {
- // I hate klipper
- killTimer(pending_timer_id);
- pending_timer_id = 0;
-
- if (pending_clipboard_changed) {
- pending_clipboard_changed = false;
- clipboardData()->clear();
- emitChanged(QClipboard::Clipboard);
- }
- if (pending_selection_changed) {
- pending_selection_changed = false;
- selectionData()->clear();
- emitChanged(QClipboard::Selection);
- }
-
- return true;
- } else if (te->timerId() == incr_timer_id) {
- killTimer(incr_timer_id);
- incr_timer_id = 0;
-
- qt_xclb_incr_timeout();
-
- return true;
- } else {
- return QObject::event(e);
- }
- } else if (e->type() != QEvent::Clipboard) {
- return QObject::event(e);
- }
-
- XEvent *xevent = (XEvent *)(((QClipboardEvent *)e)->data());
- Display *dpy = X11->display;
-
- if (!xevent) {
- // That means application exits and we need to give clipboard
- // content to the clipboard manager.
- // First we check if there is a clipboard manager.
- if (XGetSelectionOwner(X11->display, ATOM(CLIPBOARD_MANAGER)) == XNone
- || !owner)
- return true;
-
- Window ownerId = owner->internalWinId();
- Q_ASSERT(ownerId);
- // we delete the property so the manager saves all TARGETS.
- XDeleteProperty(X11->display, ownerId, ATOM(_QT_SELECTION));
- XConvertSelection(X11->display, ATOM(CLIPBOARD_MANAGER), ATOM(SAVE_TARGETS),
- ATOM(_QT_SELECTION), ownerId, X11->time);
- XSync(dpy, false);
-
- XEvent event;
- // waiting until the clipboard manager fetches the content.
- if (!X11->clipboardWaitForEvent(ownerId, SelectionNotify, &event, 10000)) {
- qWarning("QClipboard: Unable to receive an event from the "
- "clipboard manager in a reasonable time");
- }
-
- return true;
- }
-
- switch (xevent->type) {
-
- case SelectionClear:
- // new selection owner
- if (xevent->xselectionclear.selection == XA_PRIMARY) {
- QClipboardData *d = selectionData();
-
- // ignore the event if it was generated before we gained selection ownership
- if (d->timestamp != CurrentTime && xevent->xselectionclear.time <= d->timestamp)
- break;
-
- DEBUG("QClipboard: new selection owner 0x%lx at time %lx (ours %lx)",
- XGetSelectionOwner(dpy, XA_PRIMARY),
- xevent->xselectionclear.time, d->timestamp);
-
- if (! waiting_for_data) {
- d->clear();
- emitChanged(QClipboard::Selection);
- } else {
- pending_selection_changed = true;
- if (! pending_timer_id)
- pending_timer_id = QApplication::clipboard()->startTimer(0);
- }
- } else if (xevent->xselectionclear.selection == ATOM(CLIPBOARD)) {
- QClipboardData *d = clipboardData();
-
- // ignore the event if it was generated before we gained selection ownership
- if (d->timestamp != CurrentTime && xevent->xselectionclear.time <= d->timestamp)
- break;
-
- DEBUG("QClipboard: new clipboard owner 0x%lx at time %lx (%lx)",
- XGetSelectionOwner(dpy, ATOM(CLIPBOARD)),
- xevent->xselectionclear.time, d->timestamp);
-
- if (! waiting_for_data) {
- d->clear();
- emitChanged(QClipboard::Clipboard);
- } else {
- pending_clipboard_changed = true;
- if (! pending_timer_id)
- pending_timer_id = QApplication::clipboard()->startTimer(0);
- }
- } else {
- qWarning("QClipboard: Unknown SelectionClear event received");
- return false;
- }
- break;
-
- case SelectionNotify:
- /*
- Something has delivered data to us, but this was not caught
- by QClipboardWatcher::getDataInFormat()
-
- Just skip the event to prevent Bad Things (tm) from
- happening later on...
- */
- break;
-
- case SelectionRequest:
- {
- // someone wants our data
- XSelectionRequestEvent *req = &xevent->xselectionrequest;
-
- if (requestor && req->requestor == requestor->internalWinId())
- break;
-
- XEvent event;
- event.xselection.type = SelectionNotify;
- event.xselection.display = req->display;
- event.xselection.requestor = req->requestor;
- event.xselection.selection = req->selection;
- event.xselection.target = req->target;
- event.xselection.property = XNone;
- event.xselection.time = req->time;
-
- DEBUG("QClipboard: SelectionRequest from %lx\n"
- " selection 0x%lx (%s) target 0x%lx (%s)",
- req->requestor,
- req->selection,
- X11->xdndAtomToString(req->selection).data(),
- req->target,
- X11->xdndAtomToString(req->target).data());
-
- QClipboardData *d;
- if (req->selection == XA_PRIMARY) {
- d = selectionData();
- } else if (req->selection == ATOM(CLIPBOARD)) {
- d = clipboardData();
- } else {
- qWarning("QClipboard: Unknown selection '%lx'", req->selection);
- XSendEvent(dpy, req->requestor, False, NoEventMask, &event);
- break;
- }
-
- if (! d->source()) {
- qWarning("QClipboard: Cannot transfer data, no data available");
- XSendEvent(dpy, req->requestor, False, NoEventMask, &event);
- break;
- }
-
- DEBUG("QClipboard: SelectionRequest at time %lx (ours %lx)",
- req->time, d->timestamp);
-
- if (d->timestamp == CurrentTime // we don't own the selection anymore
- || (req->time != CurrentTime && req->time < d->timestamp)) {
- DEBUG("QClipboard: SelectionRequest too old");
- XSendEvent(dpy, req->requestor, False, NoEventMask, &event);
- break;
- }
-
- Atom xa_targets = ATOM(TARGETS);
- Atom xa_multiple = ATOM(MULTIPLE);
- Atom xa_timestamp = ATOM(TIMESTAMP);
-
- struct AtomPair { Atom target; Atom property; } *multi = 0;
- Atom multi_type = XNone;
- int multi_format = 0;
- int nmulti = 0;
- int imulti = -1;
- bool multi_writeback = false;
-
- if (req->target == xa_multiple) {
- QByteArray multi_data;
- if (req->property == XNone
- || !X11->clipboardReadProperty(req->requestor, req->property, false, &multi_data,
- 0, &multi_type, &multi_format)
- || multi_format != 32) {
- // MULTIPLE property not formatted correctly
- XSendEvent(dpy, req->requestor, False, NoEventMask, &event);
- break;
- }
- nmulti = multi_data.size()/sizeof(*multi);
- multi = new AtomPair[nmulti];
- memcpy(multi,multi_data.data(),multi_data.size());
- imulti = 0;
- }
-
- for (; imulti < nmulti; ++imulti) {
- Atom target;
- Atom property;
-
- if (multi) {
- target = multi[imulti].target;
- property = multi[imulti].property;
- } else {
- target = req->target;
- property = req->property;
- if (property == XNone) // obsolete client
- property = target;
- }
-
- Atom ret = XNone;
- if (target == XNone || property == XNone) {
- ;
- } else if (target == xa_timestamp) {
- if (d->timestamp != CurrentTime) {
- XChangeProperty(dpy, req->requestor, property, XA_INTEGER, 32,
- PropModeReplace, (uchar *) &d->timestamp, 1);
- ret = property;
- } else {
- qWarning("QClipboard: Invalid data timestamp");
- }
- } else if (target == xa_targets) {
- ret = send_targets_selection(d, req->requestor, property);
- } else {
- ret = send_selection(d, target, req->requestor, property);
- }
-
- if (nmulti > 0) {
- if (ret == XNone) {
- multi[imulti].property = XNone;
- multi_writeback = true;
- }
- } else {
- event.xselection.property = ret;
- break;
- }
- }
-
- if (nmulti > 0) {
- if (multi_writeback) {
- // according to ICCCM 2.6.2 says to put None back
- // into the original property on the requestor window
- XChangeProperty(dpy, req->requestor, req->property, multi_type, 32,
- PropModeReplace, (uchar *) multi, nmulti * 2);
- }
-
- delete [] multi;
- event.xselection.property = req->property;
- }
-
- // send selection notify to requestor
- XSendEvent(dpy, req->requestor, False, NoEventMask, &event);
-
- DEBUG("QClipboard: SelectionNotify to 0x%lx\n"
- " property 0x%lx (%s)",
- req->requestor, event.xselection.property,
- X11->xdndAtomToString(event.xselection.property).data());
- }
- break;
- }
-
- return true;
-}
-
-
-
-
-
-
-QClipboardWatcher::QClipboardWatcher(QClipboard::Mode mode)
- : QInternalMimeData()
-{
- switch (mode) {
- case QClipboard::Selection:
- atom = XA_PRIMARY;
- break;
-
- case QClipboard::Clipboard:
- atom = ATOM(CLIPBOARD);
- break;
-
- default:
- qWarning("QClipboardWatcher: Internal error: Unsupported clipboard mode");
- break;
- }
-
- setupOwner();
-}
-
-QClipboardWatcher::~QClipboardWatcher()
-{
- if(selection_watcher == this)
- selection_watcher = 0;
- if(clipboard_watcher == this)
- clipboard_watcher = 0;
-}
-
-bool QClipboardWatcher::empty() const
-{
- Display *dpy = X11->display;
- Window win = XGetSelectionOwner(dpy, atom);
-
- if(win == requestor->internalWinId()) {
- qWarning("QClipboardWatcher::empty: Internal error: Application owns the selection");
- return true;
- }
-
- return win == XNone;
-}
-
-QStringList QClipboardWatcher::formats_sys() const
-{
- if (empty())
- return QStringList();
-
- if (!formatList.count()) {
- // get the list of targets from the current clipboard owner - we do this
- // once so that multiple calls to this function don't require multiple
- // server round trips...
-
- format_atoms = getDataInFormat(ATOM(TARGETS));
-
- if (format_atoms.size() > 0) {
- Atom *targets = (Atom *) format_atoms.data();
- int size = format_atoms.size() / sizeof(Atom);
-
- for (int i = 0; i < size; ++i) {
- if (targets[i] == 0)
- continue;
-
- QStringList formatsForAtom = X11->xdndMimeFormatsForAtom(targets[i]);
- for (int j = 0; j < formatsForAtom.size(); ++j) {
- if (!formatList.contains(formatsForAtom.at(j)))
- formatList.append(formatsForAtom.at(j));
- }
- VDEBUG(" format: %s", X11->xdndAtomToString(targets[i]).data());
- VDEBUG(" data:\n%s\n", getDataInFormat(targets[i]).data());
- }
- DEBUG("QClipboardWatcher::format: %d formats available", formatList.count());
- }
- }
-
- return formatList;
-}
-
-bool QClipboardWatcher::hasFormat_sys(const QString &format) const
-{
- QStringList list = formats();
- return list.contains(format);
-}
-
-QVariant QClipboardWatcher::retrieveData_sys(const QString &fmt, QVariant::Type requestedType) const
-{
- if (fmt.isEmpty() || empty())
- return QByteArray();
-
- (void)formats(); // trigger update of format list
- DEBUG("QClipboardWatcher::data: fetching format '%s'", fmt.toLatin1().data());
-
- QList<Atom> atoms;
- Atom *targets = (Atom *) format_atoms.data();
- int size = format_atoms.size() / sizeof(Atom);
- for (int i = 0; i < size; ++i)
- atoms.append(targets[i]);
-
- QByteArray encoding;
- Atom fmtatom = X11->xdndMimeAtomForFormat(fmt, requestedType, atoms, &encoding);
-
- if (fmtatom == 0)
- return QVariant();
-
- return X11->xdndMimeConvertToFormat(fmtatom, getDataInFormat(fmtatom), fmt, requestedType, encoding);
-}
-
-QByteArray QClipboardWatcher::getDataInFormat(Atom fmtatom) const
-{
- QByteArray buf;
-
- Display *dpy = X11->display;
- requestor->createWinId();
- Window win = requestor->internalWinId();
- Q_ASSERT(requestor->testAttribute(Qt::WA_WState_Created));
-
- DEBUG("QClipboardWatcher::getDataInFormat: selection '%s' format '%s'",
- X11->xdndAtomToString(atom).data(), X11->xdndAtomToString(fmtatom).data());
-
- XSelectInput(dpy, win, NoEventMask); // don't listen for any events
-
- XDeleteProperty(dpy, win, ATOM(_QT_SELECTION));
- XConvertSelection(dpy, atom, fmtatom, ATOM(_QT_SELECTION), win, X11->time);
- XSync(dpy, false);
-
- VDEBUG("QClipboardWatcher::getDataInFormat: waiting for SelectionNotify event");
-
- XEvent xevent;
- if (!X11->clipboardWaitForEvent(win,SelectionNotify,&xevent,clipboard_timeout) ||
- xevent.xselection.property == XNone) {
- DEBUG("QClipboardWatcher::getDataInFormat: format not available");
- return buf;
- }
-
- VDEBUG("QClipboardWatcher::getDataInFormat: fetching data...");
-
- Atom type;
- XSelectInput(dpy, win, PropertyChangeMask);
-
- if (X11->clipboardReadProperty(win, ATOM(_QT_SELECTION), true, &buf, 0, &type, 0)) {
- if (type == ATOM(INCR)) {
- int nbytes = buf.size() >= 4 ? *((int*)buf.data()) : 0;
- buf = X11->clipboardReadIncrementalProperty(win, ATOM(_QT_SELECTION), nbytes, false);
- }
- }
-
- XSelectInput(dpy, win, NoEventMask);
-
- DEBUG("QClipboardWatcher::getDataInFormat: %d bytes received", buf.size());
-
- return buf;
-}
-
-
-const QMimeData* QClipboard::mimeData(Mode mode) const
-{
- QClipboardData *d = 0;
- switch (mode) {
- case Selection:
- d = selectionData();
- break;
- case Clipboard:
- d = clipboardData();
- break;
- default:
- qWarning("QClipboard::mimeData: unsupported mode '%d'", mode);
- return 0;
- }
-
- if (! d->source() && ! timer_event_clear) {
- if (mode == Selection) {
- if (! selection_watcher)
- selection_watcher = new QClipboardWatcher(mode);
- d->setSource(selection_watcher);
- } else {
- if (! clipboard_watcher)
- clipboard_watcher = new QClipboardWatcher(mode);
- d->setSource(clipboard_watcher);
- }
-
- if (! timer_id) {
- // start a zero timer - we will clear cached data when the timer
- // times out, which will be the next time we hit the event loop...
- // that way, the data is cached long enough for calls within a single
- // loop/function, but the data doesn't linger around in case the selection
- // changes
- QClipboard *that = ((QClipboard *) this);
- timer_id = that->startTimer(0);
- }
- }
-
- return d->source();
-}
-
-
-void QClipboard::setMimeData(QMimeData* src, Mode mode)
-{
- Atom atom, sentinel_atom;
- QClipboardData *d;
- switch (mode) {
- case Selection:
- atom = XA_PRIMARY;
- sentinel_atom = ATOM(_QT_SELECTION_SENTINEL);
- d = selectionData();
- break;
-
- case Clipboard:
- atom = ATOM(CLIPBOARD);
- sentinel_atom = ATOM(_QT_CLIPBOARD_SENTINEL);
- d = clipboardData();
- break;
-
- default:
- qWarning("QClipboard::setMimeData: unsupported mode '%d'", mode);
- return;
- }
-
- Display *dpy = X11->display;
- Window newOwner;
-
- if (! src) { // no data, clear clipboard contents
- newOwner = XNone;
- d->clear();
- } else {
- setupOwner();
-
- newOwner = owner->internalWinId();
-
- d->setSource(src);
- d->timestamp = X11->time;
- }
-
- Window prevOwner = XGetSelectionOwner(dpy, atom);
- // use X11->time, since d->timestamp == CurrentTime when clearing
- XSetSelectionOwner(dpy, atom, newOwner, X11->time);
-
- if (mode == Selection)
- emitChanged(QClipboard::Selection);
- else
- emitChanged(QClipboard::Clipboard);
-
- if (XGetSelectionOwner(dpy, atom) != newOwner) {
- qWarning("QClipboard::setData: Cannot set X11 selection owner for %s",
- X11->xdndAtomToString(atom).data());
- d->clear();
- return;
- }
-
- // Signal to other Qt processes that the selection has changed
- Window owners[2];
- owners[0] = newOwner;
- owners[1] = prevOwner;
- XChangeProperty(dpy, QApplication::desktop()->screen(0)->internalWinId(),
- sentinel_atom, XA_WINDOW, 32, PropModeReplace,
- (unsigned char*)&owners, 2);
-}
-
-
-/*
- Called by the main event loop in qapplication_x11.cpp when either
- the _QT_SELECTION_SENTINEL property has been changed (i.e. when some
- Qt process has performed QClipboard::setData()) or when Xfixes told
- us that an other application changed the selection. If it returns
- true, the QClipBoard dataChanged() signal should be emitted.
-*/
-
-bool qt_check_selection_sentinel()
-{
- bool doIt = true;
- if (owner && !X11->use_xfixes) {
- /*
- Since the X selection mechanism cannot give any signal when
- the selection has changed, we emulate it (for Qt processes) here.
- The notification should be ignored in case of either
- a) This is the process that did setData (because setData()
- then has already emitted dataChanged())
- b) This is the process that owned the selection when dataChanged()
- was called (because we have then received a SelectionClear event,
- and have already emitted dataChanged() as a result of that)
- */
-
- unsigned char *retval;
- Atom actualType;
- int actualFormat;
- ulong nitems;
- ulong bytesLeft;
-
- if (XGetWindowProperty(X11->display,
- QApplication::desktop()->screen(0)->internalWinId(),
- ATOM(_QT_SELECTION_SENTINEL), 0, 2, False, XA_WINDOW,
- &actualType, &actualFormat, &nitems,
- &bytesLeft, &retval) == Success) {
- Window *owners = (Window *)retval;
- if (actualType == XA_WINDOW && actualFormat == 32 && nitems == 2) {
- Window win = owner->internalWinId();
- if (owners[0] == win || owners[1] == win)
- doIt = false;
- }
-
- XFree(owners);
- }
- }
-
- if (doIt) {
- if (waiting_for_data) {
- pending_selection_changed = true;
- if (! pending_timer_id)
- pending_timer_id = QApplication::clipboard()->startTimer(0);
- doIt = false;
- } else {
- selectionData()->clear();
- }
- }
-
- return doIt;
-}
-
-
-bool qt_check_clipboard_sentinel()
-{
- bool doIt = true;
- if (owner && !X11->use_xfixes) {
- unsigned char *retval;
- Atom actualType;
- int actualFormat;
- unsigned long nitems, bytesLeft;
-
- if (XGetWindowProperty(X11->display,
- QApplication::desktop()->screen(0)->internalWinId(),
- ATOM(_QT_CLIPBOARD_SENTINEL), 0, 2, False, XA_WINDOW,
- &actualType, &actualFormat, &nitems, &bytesLeft,
- &retval) == Success) {
- Window *owners = (Window *)retval;
- if (actualType == XA_WINDOW && actualFormat == 32 && nitems == 2) {
- Window win = owner->internalWinId();
- if (owners[0] == win || owners[1] == win)
- doIt = false;
- }
-
- XFree(owners);
- }
- }
-
- if (doIt) {
- if (waiting_for_data) {
- pending_clipboard_changed = true;
- if (! pending_timer_id)
- pending_timer_id = QApplication::clipboard()->startTimer(0);
- doIt = false;
- } else {
- clipboardData()->clear();
- }
- }
-
- return doIt;
-}
-
-bool qt_xfixes_selection_changed(Window selectionOwner, Time timestamp)
-{
- QClipboardData *d = selectionData();
-#ifdef QCLIPBOARD_DEBUG
- DEBUG("qt_xfixes_selection_changed: owner = %u; selectionOwner = %u; internal timestamp = %u; external timestamp = %u",
- (unsigned int)(owner ? (int)owner->internalWinId() : 0), (unsigned int)selectionOwner,
- (unsigned int)(d ? d->timestamp : 0), (unsigned int)timestamp);
-#endif
- if (!owner || (selectionOwner && selectionOwner != owner->internalWinId()) ||
- (!selectionOwner && (d->timestamp == CurrentTime || d->timestamp < timestamp)))
- return qt_check_selection_sentinel();
- return false;
-}
-
-bool qt_xfixes_clipboard_changed(Window clipboardOwner, Time timestamp)
-{
- QClipboardData *d = clipboardData();
-#ifdef QCLIPBOARD_DEBUG
- DEBUG("qt_xfixes_clipboard_changed: owner = %u; clipboardOwner = %u; internal timestamp = %u; external timestamp = %u",
- (unsigned int)(owner ? (int)owner->internalWinId() : 0), (unsigned int)clipboardOwner,
- (unsigned int)(d ? d->timestamp : 0), (unsigned int)timestamp);
-#endif
- if (!owner || (clipboardOwner && clipboardOwner != owner->internalWinId()) ||
- (!clipboardOwner && (d->timestamp == CurrentTime || d->timestamp < timestamp)))
- return qt_check_clipboard_sentinel();
- return false;
-}
-
-QT_END_NAMESPACE
-
-#endif // QT_NO_CLIPBOARD
diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp
deleted file mode 100644
index 823f6f1e8c..0000000000
--- a/src/gui/kernel/qcursor.cpp
+++ /dev/null
@@ -1,573 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qcursor.h"
-
-#ifndef QT_NO_CURSOR
-
-#include <qapplication.h>
-#include <qbitmap.h>
-#include <qimage.h>
-#include <qdatastream.h>
-#include <qvariant.h>
-#include <private/qcursor_p.h>
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QCursor
-
- \brief The QCursor class provides a mouse cursor with an arbitrary
- shape.
-
- \ingroup appearance
- \ingroup shared
-
-
- This class is mainly used to create mouse cursors that are
- associated with particular widgets and to get and set the position
- of the mouse cursor.
-
- Qt has a number of standard cursor shapes, but you can also make
- custom cursor shapes based on a QBitmap, a mask and a hotspot.
-
- To associate a cursor with a widget, use QWidget::setCursor(). To
- associate a cursor with all widgets (normally for a short period
- of time), use QApplication::setOverrideCursor().
-
- To set a cursor shape use QCursor::setShape() or use the QCursor
- constructor which takes the shape as argument, or you can use one
- of the predefined cursors defined in the \l Qt::CursorShape enum.
-
- If you want to create a cursor with your own bitmap, either use
- the QCursor constructor which takes a bitmap and a mask or the
- constructor which takes a pixmap as arguments.
-
- To set or get the position of the mouse cursor use the static
- methods QCursor::pos() and QCursor::setPos().
-
- \bold{Note:} It is possible to create a QCursor before
- QApplication, but it is not useful except as a place-holder for a
- real QCursor created after QApplication. Attempting to use a
- QCursor that was created before QApplication will result in a
- crash.
-
- \section1 A Note for X11 Users
-
- On X11, Qt supports the \link
- http://www.xfree86.org/4.3.0/Xcursor.3.html Xcursor\endlink
- library, which allows for full color icon themes. The table below
- shows the cursor name used for each Qt::CursorShape value. If a
- cursor cannot be found using the name shown below, a standard X11
- cursor will be used instead. Note: X11 does not provide
- appropriate cursors for all possible Qt::CursorShape values. It
- is possible that some cursors will be taken from the Xcursor
- theme, while others will use an internal bitmap cursor.
-
- \table
- \header \o Shape \o Qt::CursorShape Value \o Cursor Name
- \o Shape \o Qt::CursorShape Value \o Cursor Name
- \row \o \inlineimage cursor-arrow.png
- \o Qt::ArrowCursor \o \c left_ptr
- \o \inlineimage cursor-sizev.png
- \o Qt::SizeVerCursor \o \c size_ver
- \row \o \inlineimage cursor-uparrow.png
- \o Qt::UpArrowCursor \o \c up_arrow
- \o \inlineimage cursor-sizeh.png
- \o Qt::SizeHorCursor \o \c size_hor
- \row \o \inlineimage cursor-cross.png
- \o Qt::CrossCursor \o \c cross
- \o \inlineimage cursor-sizeb.png
- \o Qt::SizeBDiagCursor \o \c size_bdiag
- \row \o \inlineimage cursor-ibeam.png
- \o Qt::IBeamCursor \o \c ibeam
- \o \inlineimage cursor-sizef.png
- \o Qt::SizeFDiagCursor \o \c size_fdiag
- \row \o \inlineimage cursor-wait.png
- \o Qt::WaitCursor \o \c wait
- \o \inlineimage cursor-sizeall.png
- \o Qt::SizeAllCursor \o \c size_all
- \row \o \inlineimage cursor-busy.png
- \o Qt::BusyCursor \o \c left_ptr_watch
- \o \inlineimage cursor-vsplit.png
- \o Qt::SplitVCursor \o \c split_v
- \row \o \inlineimage cursor-forbidden.png
- \o Qt::ForbiddenCursor \o \c forbidden
- \o \inlineimage cursor-hsplit.png
- \o Qt::SplitHCursor \o \c split_h
- \row \o \inlineimage cursor-hand.png
- \o Qt::PointingHandCursor \o \c pointing_hand
- \o \inlineimage cursor-openhand.png
- \o Qt::OpenHandCursor \o \c openhand
- \row \o \inlineimage cursor-whatsthis.png
- \o Qt::WhatsThisCursor \o \c whats_this
- \o \inlineimage cursor-closedhand.png
- \o Qt::ClosedHandCursor \o \c closedhand
- \row \o
- \o Qt::DragMoveCursor \o \c dnd-move or \c move
- \o
- \o Qt::DragCopyCursor \o \c dnd-copy or \c copy
- \row \o
- \o Qt::DragLinkCursor \o \c dnd-link or \c link
- \endtable
-
- \sa QWidget, {fowler}{GUI Design Handbook: Cursors}
-*/
-
-/*!
- \fn HCURSOR_or_HANDLE QCursor::handle() const
-
- Returns a platform-specific cursor handle. The \c
- HCURSOR_or_HANDLE type is \c HCURSOR on Windows and Qt::HANDLE on X11
- and Mac OS X. On \l{Qt for Embedded Linux} it is an integer.
-
- \warning Using the value returned by this function is not
- portable.
-*/
-
-/*!
- \fn QCursor::QCursor(HCURSOR cursor)
-
- Constructs a Qt cursor from the given Windows \a cursor.
-
- \warning This function is only available on Windows.
-
- \sa handle()
-*/
-
-/*!
- \fn QCursor::QCursor(Qt::HANDLE handle)
-
- Constructs a Qt cursor from the given \a handle.
-
- \warning This function is only available on X11.
-
- \sa handle()
-*/
-
-/*!
- \fn QPoint QCursor::pos()
-
- Returns the position of the cursor (hot spot) in global screen
- coordinates.
-
- You can call QWidget::mapFromGlobal() to translate it to widget
- coordinates.
-
- \sa setPos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal()
-*/
-
-/*!
- \fn void QCursor::setPos(int x, int y)
-
- Moves the cursor (hot spot) to the global screen position (\a x,
- \a y).
-
- You can call QWidget::mapToGlobal() to translate widget
- coordinates to global screen coordinates.
-
- \sa pos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal()
-*/
-
-/*!
- \fn void QCursor::setPos (const QPoint &p)
-
- \overload
-
- Moves the cursor (hot spot) to the global screen position at point
- \a p.
-*/
-
-/*****************************************************************************
- QCursor stream functions
- *****************************************************************************/
-
-#ifndef QT_NO_DATASTREAM
-
-
-/*!
- \fn QDataStream &operator<<(QDataStream &stream, const QCursor &cursor)
- \relates QCursor
-
- Writes the \a cursor to the \a stream.
-
- \sa {Serializing Qt Data Types}
-*/
-
-QDataStream &operator<<(QDataStream &s, const QCursor &c)
-{
- s << (qint16)c.shape(); // write shape id to stream
- if (c.shape() == Qt::BitmapCursor) { // bitmap cursor
- bool isPixmap = false;
- if (s.version() >= 7) {
- isPixmap = !c.pixmap().isNull();
- s << isPixmap;
- }
- if (isPixmap)
- s << c.pixmap();
- else
- s << *c.bitmap() << *c.mask();
- s << c.hotSpot();
- }
- return s;
-}
-
-/*!
- \fn QDataStream &operator>>(QDataStream &stream, QCursor &cursor)
- \relates QCursor
-
- Reads the \a cursor from the \a stream.
-
- \sa {Serializing Qt Data Types}
-*/
-
-QDataStream &operator>>(QDataStream &s, QCursor &c)
-{
- qint16 shape;
- s >> shape; // read shape id from stream
- if (shape == Qt::BitmapCursor) { // read bitmap cursor
- bool isPixmap = false;
- if (s.version() >= 7)
- s >> isPixmap;
- if (isPixmap) {
- QPixmap pm;
- QPoint hot;
- s >> pm >> hot;
- c = QCursor(pm, hot.x(), hot.y());
- } else {
- QBitmap bm, bmm;
- QPoint hot;
- s >> bm >> bmm >> hot;
- c = QCursor(bm, bmm, hot.x(), hot.y());
- }
- } else {
- c.setShape((Qt::CursorShape)shape); // create cursor with shape
- }
- return s;
-}
-#endif // QT_NO_DATASTREAM
-
-
-/*!
- Constructs a custom pixmap cursor.
-
- \a pixmap is the image. It is usual to give it a mask (set using
- QPixmap::setMask()). \a hotX and \a hotY define the cursor's hot
- spot.
-
- If \a hotX is negative, it is set to the \c{pixmap().width()/2}.
- If \a hotY is negative, it is set to the \c{pixmap().height()/2}.
-
- Valid cursor sizes depend on the display hardware (or the
- underlying window system). We recommend using 32 x 32 cursors,
- because this size is supported on all platforms. Some platforms
- also support 16 x 16, 48 x 48, and 64 x 64 cursors.
-
- \note On Windows CE, the cursor size is fixed. If the pixmap
- is bigger than the system size, it will be scaled.
-
- \sa QPixmap::QPixmap(), QPixmap::setMask()
-*/
-
-QCursor::QCursor(const QPixmap &pixmap, int hotX, int hotY)
- : d(0)
-{
- QImage img = pixmap.toImage().convertToFormat(QImage::Format_Indexed8, Qt::ThresholdDither|Qt::AvoidDither);
- QBitmap bm = QBitmap::fromImage(img, Qt::ThresholdDither|Qt::AvoidDither);
- QBitmap bmm = pixmap.mask();
- if (!bmm.isNull()) {
- QBitmap nullBm;
- bm.setMask(nullBm);
- }
- else if (!pixmap.mask().isNull()) {
- QImage mimg = pixmap.mask().toImage().convertToFormat(QImage::Format_Indexed8, Qt::ThresholdDither|Qt::AvoidDither);
- bmm = QBitmap::fromImage(mimg, Qt::ThresholdDither|Qt::AvoidDither);
- }
- else {
- bmm = QBitmap(bm.size());
- bmm.fill(Qt::color1);
- }
-
- d = QCursorData::setBitmap(bm, bmm, hotX, hotY);
- d->pixmap = pixmap;
-}
-
-
-
-/*!
- Constructs a custom bitmap cursor.
-
- \a bitmap and
- \a mask make up the bitmap.
- \a hotX and
- \a hotY define the cursor's hot spot.
-
- If \a hotX is negative, it is set to the \c{bitmap().width()/2}.
- If \a hotY is negative, it is set to the \c{bitmap().height()/2}.
-
- The cursor \a bitmap (B) and \a mask (M) bits are combined like this:
- \list
- \o B=1 and M=1 gives black.
- \o B=0 and M=1 gives white.
- \o B=0 and M=0 gives transparent.
- \o B=1 and M=0 gives an XOR'd result under Windows, undefined
- results on all other platforms.
- \endlist
-
- Use the global Qt color Qt::color0 to draw 0-pixels and Qt::color1 to
- draw 1-pixels in the bitmaps.
-
- Valid cursor sizes depend on the display hardware (or the
- underlying window system). We recommend using 32 x 32 cursors,
- because this size is supported on all platforms. Some platforms
- also support 16 x 16, 48 x 48, and 64 x 64 cursors.
-
- \note On Windows CE, the cursor size is fixed. If the pixmap
- is bigger than the system size, it will be scaled.
-
- \sa QBitmap::QBitmap(), QBitmap::setMask()
-*/
-
-QCursor::QCursor(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
- : d(0)
-{
- d = QCursorData::setBitmap(bitmap, mask, hotX, hotY);
-}
-
-QCursorData *qt_cursorTable[Qt::LastCursor + 1];
-bool QCursorData::initialized = false;
-
-/*! \internal */
-void QCursorData::cleanup()
-{
- if(!QCursorData::initialized)
- return;
-
- for (int shape = 0; shape <= Qt::LastCursor; ++shape) {
- // In case someone has a static QCursor defined with this shape
- if (!qt_cursorTable[shape]->ref.deref())
- delete qt_cursorTable[shape];
- qt_cursorTable[shape] = 0;
- }
- QCursorData::initialized = false;
-}
-
-/*! \internal */
-void QCursorData::initialize()
-{
- if (QCursorData::initialized)
- return;
-#ifdef Q_WS_MAC
- // DRSWAT - Not Needed Cocoa or Carbon
- //InitCursor();
-#endif
- for (int shape = 0; shape <= Qt::LastCursor; ++shape)
- qt_cursorTable[shape] = new QCursorData((Qt::CursorShape)shape);
- QCursorData::initialized = true;
-}
-
-/*!
- Constructs a cursor with the default arrow shape.
-*/
-QCursor::QCursor()
-{
- if (!QCursorData::initialized) {
- if (QApplication::startingUp()) {
- d = 0;
- return;
- }
- QCursorData::initialize();
- }
- QCursorData *c = qt_cursorTable[0];
- c->ref.ref();
- d = c;
-}
-
-/*!
- Constructs a cursor with the specified \a shape.
-
- See \l Qt::CursorShape for a list of shapes.
-
- \sa setShape()
-*/
-QCursor::QCursor(Qt::CursorShape shape)
- : d(0)
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- setShape(shape);
-}
-
-
-/*!
- Returns the cursor shape identifier. The return value is one of
- the \l Qt::CursorShape enum values (cast to an int).
-
- \sa setShape()
-*/
-Qt::CursorShape QCursor::shape() const
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- return d->cshape;
-}
-
-/*!
- Sets the cursor to the shape identified by \a shape.
-
- See \l Qt::CursorShape for the list of cursor shapes.
-
- \sa shape()
-*/
-void QCursor::setShape(Qt::CursorShape shape)
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- QCursorData *c = uint(shape) <= Qt::LastCursor ? qt_cursorTable[shape] : 0;
- if (!c)
- c = qt_cursorTable[0];
- c->ref.ref();
- if (!d) {
- d = c;
- } else {
- if (!d->ref.deref())
- delete d;
- d = c;
- }
-}
-
-/*!
- Returns the cursor bitmap, or 0 if it is one of the standard
- cursors.
-*/
-const QBitmap *QCursor::bitmap() const
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- return d->bm;
-}
-
-/*!
- Returns the cursor bitmap mask, or 0 if it is one of the standard
- cursors.
-*/
-
-const QBitmap *QCursor::mask() const
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- return d->bmm;
-}
-
-/*!
- Returns the cursor pixmap. This is only valid if the cursor is a
- pixmap cursor.
-*/
-
-QPixmap QCursor::pixmap() const
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- return d->pixmap;
-}
-
-/*!
- Returns the cursor hot spot, or (0, 0) if it is one of the
- standard cursors.
-*/
-
-QPoint QCursor::hotSpot() const
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- return QPoint(d->hx, d->hy);
-}
-
-/*!
- Constructs a copy of the cursor \a c.
-*/
-
-QCursor::QCursor(const QCursor &c)
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- d = c.d;
- d->ref.ref();
-}
-
-/*!
- Destroys the cursor.
-*/
-
-QCursor::~QCursor()
-{
- if (d && !d->ref.deref())
- delete d;
-}
-
-
-/*!
- Assigns \a c to this cursor and returns a reference to this
- cursor.
-*/
-
-QCursor &QCursor::operator=(const QCursor &c)
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- if (c.d)
- c.d->ref.ref();
- if (d && !d->ref.deref())
- delete d;
- d = c.d;
- return *this;
-}
-
-/*!
- Returns the cursor as a QVariant.
-*/
-QCursor::operator QVariant() const
-{
- return QVariant(QVariant::Cursor, this);
-}
-QT_END_NAMESPACE
-#endif // QT_NO_CURSOR
-
diff --git a/src/gui/kernel/qcursor.h b/src/gui/kernel/qcursor.h
deleted file mode 100644
index b47ec04d66..0000000000
--- a/src/gui/kernel/qcursor.h
+++ /dev/null
@@ -1,168 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCURSOR_H
-#define QCURSOR_H
-
-#include <QtCore/qpoint.h>
-#include <QtGui/qwindowdefs.h>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Gui)
-
-class QVariant;
-
-/*
- ### The fake cursor has to go first with old qdoc.
-*/
-#ifdef QT_NO_CURSOR
-
-class Q_GUI_EXPORT QCursor
-{
-public:
- static QPoint pos();
- static void setPos(int x, int y);
- inline static void setPos(const QPoint &p) { setPos(p.x(), p.y()); }
-private:
- QCursor();
-};
-
-#endif // QT_NO_CURSOR
-
-#ifndef QT_NO_CURSOR
-
-class QCursorData;
-class QBitmap;
-class QPixmap;
-
-#if defined(Q_WS_MAC)
-void qt_mac_set_cursor(const QCursor *c);
-#endif
-#if defined(Q_OS_SYMBIAN)
-extern void qt_symbian_show_pointer_sprite();
-extern void qt_symbian_hide_pointer_sprite();
-extern void qt_symbian_set_pointer_sprite(const QCursor& cursor);
-extern void qt_symbian_move_cursor_sprite();
-#endif
-
-class Q_GUI_EXPORT QCursor
-{
-public:
- QCursor();
- QCursor(Qt::CursorShape shape);
- QCursor(const QBitmap &bitmap, const QBitmap &mask, int hotX=-1, int hotY=-1);
- QCursor(const QPixmap &pixmap, int hotX=-1, int hotY=-1);
- QCursor(const QCursor &cursor);
- ~QCursor();
- QCursor &operator=(const QCursor &cursor);
-#ifdef Q_COMPILER_RVALUE_REFS
- inline QCursor &operator=(QCursor &&other)
- { qSwap(d, other.d); return *this; }
-#endif
- operator QVariant() const;
-
- Qt::CursorShape shape() const;
- void setShape(Qt::CursorShape newShape);
-
- const QBitmap *bitmap() const;
- const QBitmap *mask() const;
- QPixmap pixmap() const;
- QPoint hotSpot() const;
-
- static QPoint pos();
- static void setPos(int x, int y);
- inline static void setPos(const QPoint &p) { setPos(p.x(), p.y()); }
-
-#ifdef qdoc
- HCURSOR_or_HANDLE handle() const;
- QCursor(HCURSOR cursor);
- QCursor(Qt::HANDLE cursor);
-#endif
-
-#ifndef qdoc
-#if defined(Q_WS_WIN)
- HCURSOR handle() const;
- QCursor(HCURSOR cursor);
-#elif defined(Q_WS_X11)
- Qt::HANDLE handle() const;
- QCursor(Qt::HANDLE cursor);
- static int x11Screen();
-#elif defined(Q_WS_MAC)
- Qt::HANDLE handle() const;
-#elif defined(Q_WS_QWS) || defined(Q_WS_QPA)
- int handle() const;
-#elif defined(Q_OS_SYMBIAN)
- Qt::HANDLE handle() const;
-#endif
-#endif
-
-private:
- QCursorData *d;
-#if defined(Q_WS_MAC)
- friend void *qt_mac_nsCursorForQCursor(const QCursor &c);
- friend void qt_mac_set_cursor(const QCursor *c);
- friend void qt_mac_updateCursorWithWidgetUnderMouse(QWidget *widgetUnderMouse);
-#endif
-#if defined(Q_OS_SYMBIAN)
- friend void qt_symbian_show_pointer_sprite();
- friend void qt_symbian_hide_pointer_sprite();
- friend void qt_symbian_set_pointer_sprite(const QCursor& cursor);
- friend void qt_symbian_move_cursor_sprite();
-#endif
-};
-
-/*****************************************************************************
- QCursor stream functions
- *****************************************************************************/
-#ifndef QT_NO_DATASTREAM
-Q_GUI_EXPORT QDataStream &operator<<(QDataStream &outS, const QCursor &cursor);
-Q_GUI_EXPORT QDataStream &operator>>(QDataStream &inS, QCursor &cursor);
-#endif
-#endif // QT_NO_CURSOR
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // QCURSOR_H
diff --git a/src/gui/kernel/qcursor_mac.mm b/src/gui/kernel/qcursor_mac.mm
deleted file mode 100644
index 0afa3ee4f0..0000000000
--- a/src/gui/kernel/qcursor_mac.mm
+++ /dev/null
@@ -1,689 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <private/qcursor_p.h>
-#include <private/qpixmap_mac_p.h>
-#include <qapplication.h>
-#include <qbitmap.h>
-#include <qcursor.h>
-#include <qevent.h>
-#include <string.h>
-#include <unistd.h>
-#include <AppKit/NSCursor.h>
-#include <qpainter.h>
-#include <private/qt_cocoa_helpers_mac_p.h>
-#include <private/qapplication_p.h>
-
-QT_BEGIN_NAMESPACE
-
-/*****************************************************************************
- Externals
- *****************************************************************************/
-extern QCursorData *qt_cursorTable[Qt::LastCursor + 1];
-extern OSWindowRef qt_mac_window_for(const QWidget *); //qwidget_mac.cpp
-extern GrafPtr qt_mac_qd_context(const QPaintDevice *); //qpaintdevice_mac.cpp
-extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); //qapplication_mac.cpp
-extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
-
-/*****************************************************************************
- Internal QCursorData class
- *****************************************************************************/
-
-class QMacAnimateCursor : public QObject
-{
- int timerId, step;
- ThemeCursor curs;
-public:
- QMacAnimateCursor() : QObject(), timerId(-1) { }
- void start(ThemeCursor c) {
- step = 1;
- if(timerId != -1)
- killTimer(timerId);
- timerId = startTimer(300);
- curs = c;
- }
- void stop() {
- if(timerId != -1) {
- killTimer(timerId);
- timerId = -1;
- }
- }
-protected:
- void timerEvent(QTimerEvent *e) {
- if(e->timerId() == timerId) {
- /*
- if(SetAnimatedThemeCursor(curs, step++) == themeBadCursorIndexErr)
- stop();
- */
- }
- }
-};
-
-inline void *qt_mac_nsCursorForQCursor(const QCursor &c)
-{
- c.d->update();
- return [[static_cast<NSCursor *>(c.d->curs.cp.nscursor) retain] autorelease];
-}
-
-static QCursorData *currentCursor = 0; //current cursor
-
-void qt_mac_set_cursor(const QCursor *c)
-{
-#ifdef QT_MAC_USE_COCOA
- QMacCocoaAutoReleasePool pool;
- [static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(*c)) set];
-#else
- if (!c) {
- currentCursor = 0;
- return;
- }
- c->handle(); //force the cursor to get loaded, if it's not
-
- if(currentCursor && currentCursor->type == QCursorData::TYPE_ThemeCursor
- && currentCursor->curs.tc.anim)
- currentCursor->curs.tc.anim->stop();
- if(c->d->type == QCursorData::TYPE_ImageCursor) {
- [static_cast<NSCursor *>(c->d->curs.cp.nscursor) set];
- } else if(c->d->type == QCursorData::TYPE_ThemeCursor) {
- if(SetAnimatedThemeCursor(c->d->curs.tc.curs, 0) == themeBadCursorIndexErr) {
- SetThemeCursor(c->d->curs.tc.curs);
- } else {
- if(!c->d->curs.tc.anim)
- c->d->curs.tc.anim = new QMacAnimateCursor;
- c->d->curs.tc.anim->start(c->d->curs.tc.curs);
- }
- }
-
- currentCursor = c->d;
-#endif
-}
-
-static QPointer<QWidget> lastWidgetUnderMouse = 0;
-static QPointer<QWidget> lastMouseCursorWidget = 0;
-static bool qt_button_down_on_prev_call = false;
-static QCursor *grabCursor = 0;
-
-void qt_mac_updateCursorWithWidgetUnderMouse(QWidget *widgetUnderMouse)
-{
- QCursor cursor(Qt::ArrowCursor);
- if (qt_button_down) {
- // The widget that is currently pressed
- // grabs the mouse cursor:
- widgetUnderMouse = qt_button_down;
- qt_button_down_on_prev_call = true;
- } else if (qt_button_down_on_prev_call) {
- // Grab has been released, so do
- // a full check:
- qt_button_down_on_prev_call = false;
- lastWidgetUnderMouse = 0;
- lastMouseCursorWidget = 0;
- }
-
- if (QApplication::overrideCursor()) {
- cursor = *QApplication::overrideCursor();
- } else if (grabCursor) {
- cursor = *grabCursor;
- } else if (widgetUnderMouse) {
- if (widgetUnderMouse == lastWidgetUnderMouse) {
- // Optimization that should hit when the widget under
- // the mouse does not change as the mouse moves:
- if (lastMouseCursorWidget)
- cursor = lastMouseCursorWidget->cursor();
- } else {
- QWidget *w = widgetUnderMouse;
- for (; w; w = w->parentWidget()) {
- if (w->testAttribute(Qt::WA_SetCursor)) {
- cursor = w->cursor();
- break;
- }
- if (w->isWindow())
- break;
- }
- // One final check in case we ran out of parents in the loop:
- if (w && !w->testAttribute(Qt::WA_SetCursor))
- w = 0;
-
- lastWidgetUnderMouse = widgetUnderMouse;
- lastMouseCursorWidget = w;
- }
- }
-
-#ifdef QT_MAC_USE_COCOA
- cursor.d->update();
- NSCursor *nsCursor = static_cast<NSCursor *>(cursor.d->curs.cp.nscursor);
- if ([NSCursor currentCursor] != nsCursor) {
- QMacCocoaAutoReleasePool pool;
- [nsCursor set];
- }
-#else
- qt_mac_set_cursor(&cursor);
-#endif
-}
-
-void qt_mac_update_cursor()
-{
- // This function is similar to qt_mac_updateCursorWithWidgetUnderMouse
- // except that is clears the optimization cache, and finds the widget
- // under mouse itself. Clearing the cache is useful in cases where the
- // application has been deactivated/activated etc.
- // NB: since we dont have any true native widget, the call to
- // qt_mac_getTargetForMouseEvent will fail when the mouse is over QMacNativeWidgets.
-#ifdef QT_MAC_USE_COCOA
- lastWidgetUnderMouse = 0;
- lastMouseCursorWidget = 0;
- QWidget *widgetUnderMouse = 0;
-
- if (qt_button_down) {
- widgetUnderMouse = qt_button_down;
- } else {
- QPoint localPoint;
- QPoint globalPoint;
- qt_mac_getTargetForMouseEvent(0, QEvent::None, localPoint, globalPoint, 0, &widgetUnderMouse);
- }
- qt_mac_updateCursorWithWidgetUnderMouse(widgetUnderMouse);
-#else
- qt_mac_updateCursorWithWidgetUnderMouse(QApplication::widgetAt(QCursor::pos()));
-#endif
-}
-
-void qt_mac_setMouseGrabCursor(bool set, QCursor *const cursor = 0)
-{
- if (grabCursor) {
- delete grabCursor;
- grabCursor = 0;
- }
- if (set) {
- if (cursor)
- grabCursor = new QCursor(*cursor);
- else if (lastMouseCursorWidget)
- grabCursor = new QCursor(lastMouseCursorWidget->cursor());
- else
- grabCursor = new QCursor(Qt::ArrowCursor);
- }
- qt_mac_update_cursor();
-}
-
-#ifndef QT_MAC_USE_COCOA
-void qt_mac_update_cursor_at_global_pos(const QPoint &globalPos)
-{
- qt_mac_updateCursorWithWidgetUnderMouse(QApplication::widgetAt(globalPos));
-}
-#endif
-
-static int nextCursorId = Qt::BitmapCursor;
-
-QCursorData::QCursorData(Qt::CursorShape s)
- : cshape(s), bm(0), bmm(0), hx(-1), hy(-1), mId(s), type(TYPE_None)
-{
- ref = 1;
- memset(&curs, '\0', sizeof(curs));
-}
-
-QCursorData::~QCursorData()
-{
- if (type == TYPE_ImageCursor) {
- if (curs.cp.my_cursor) {
- QMacCocoaAutoReleasePool pool;
- [static_cast<NSCursor *>(curs.cp.nscursor) release];
- }
- } else if(type == TYPE_ThemeCursor) {
- delete curs.tc.anim;
- }
- type = TYPE_None;
-
- delete bm;
- delete bmm;
- if(currentCursor == this)
- currentCursor = 0;
-}
-
-QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {
- qWarning("Qt: QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
- QCursorData *c = qt_cursorTable[0];
- c->ref.ref();
- return c;
- }
- // This is silly, but this is apparently called outside the constructor, so we have
- // to be ready for that case.
- QCursorData *x = new QCursorData;
- x->ref = 1;
- x->mId = ++nextCursorId;
- x->bm = new QBitmap(bitmap);
- x->bmm = new QBitmap(mask);
- x->cshape = Qt::BitmapCursor;
- x->hx = hotX >= 0 ? hotX : bitmap.width() / 2;
- x->hy = hotY >= 0 ? hotY : bitmap.height() / 2;
- return x;
-}
-
-Qt::HANDLE QCursor::handle() const
-{
- if(!QCursorData::initialized)
- QCursorData::initialize();
- if(d->type == QCursorData::TYPE_None)
- d->update();
- return (Qt::HANDLE)d->mId;
-}
-
-QPoint QCursor::pos()
-{
- return flipPoint([NSEvent mouseLocation]).toPoint();
-}
-
-void QCursor::setPos(int x, int y)
-{
-#ifdef QT_MAC_USE_COCOA
- CGPoint pos;
- pos.x = x;
- pos.y = y;
-
- CGEventRef e = CGEventCreateMouseEvent(0, kCGEventMouseMoved, pos, 0);
- CGEventPost(kCGHIDEventTap, e);
- CFRelease(e);
-#else
- CGWarpMouseCursorPosition(CGPointMake(x, y));
-
- /* I'm not too keen on doing this, but this makes it a lot easier, so I just
- send the event back through the event system and let it get propagated correctly
- ideally this would not really need to be faked --Sam
- */
- QWidget *widget = 0;
- if(QWidget *grb = QWidget::mouseGrabber())
- widget = grb;
- else
- widget = QApplication::widgetAt(QPoint(x, y));
- if(widget) {
- QMouseEvent me(QMouseEvent::MouseMove, widget->mapFromGlobal(QPoint(x, y)), Qt::NoButton,
- QApplication::mouseButtons(), QApplication::keyboardModifiers());
- qt_sendSpontaneousEvent(widget, &me);
- }
-#endif
-}
-
-void QCursorData::initCursorFromBitmap()
-{
- NSImage *nsimage;
- QImage finalCursor(bm->size(), QImage::Format_ARGB32);
- QImage bmi = bm->toImage().convertToFormat(QImage::Format_RGB32);
- QImage bmmi = bmm->toImage().convertToFormat(QImage::Format_RGB32);
- for (int row = 0; row < finalCursor.height(); ++row) {
- QRgb *bmData = reinterpret_cast<QRgb *>(bmi.scanLine(row));
- QRgb *bmmData = reinterpret_cast<QRgb *>(bmmi.scanLine(row));
- QRgb *finalData = reinterpret_cast<QRgb *>(finalCursor.scanLine(row));
- for (int col = 0; col < finalCursor.width(); ++col) {
- if (bmmData[col] == 0xff000000 && bmData[col] == 0xffffffff) {
- finalData[col] = 0xffffffff;
- } else if (bmmData[col] == 0xff000000 && bmData[col] == 0xffffffff) {
- finalData[col] = 0x7f000000;
- } else if (bmmData[col] == 0xffffffff && bmData[col] == 0xffffffff) {
- finalData[col] = 0x00000000;
- } else {
- finalData[col] = 0xff000000;
- }
- }
- }
- type = QCursorData::TYPE_ImageCursor;
- curs.cp.my_cursor = true;
- QPixmap bmCopy = QPixmap::fromImage(finalCursor);
- NSPoint hotSpot = { hx, hy };
- nsimage = static_cast<NSImage*>(qt_mac_create_nsimage(bmCopy));
- curs.cp.nscursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot];
- [nsimage release];
-}
-
-void QCursorData::initCursorFromPixmap()
-{
- type = QCursorData::TYPE_ImageCursor;
- curs.cp.my_cursor = true;
- NSPoint hotSpot = { hx, hy };
- NSImage *nsimage;
- nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(pixmap));
- curs.cp.nscursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot];
- [nsimage release];
-}
-
-void QCursorData::update()
-{
- if(!QCursorData::initialized)
- QCursorData::initialize();
- if(type != QCursorData::TYPE_None)
- return;
-
- /* Note to self... ***
- * mask x data
- * 0xFF x 0x00 == fully opaque white
- * 0x00 x 0xFF == xor'd black
- * 0xFF x 0xFF == fully opaque black
- * 0x00 x 0x00 == fully transparent
- */
-
- if (hx < 0)
- hx = 0;
- if (hy < 0)
- hy = 0;
-
-#define QT_USE_APPROXIMATE_CURSORS
-#ifdef QT_USE_APPROXIMATE_CURSORS
- static const uchar cur_ver_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xf0,
- 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x0f, 0xf0,
- 0x07, 0xe0, 0x03, 0xc0, 0x01, 0x80, 0x00, 0x00 };
- static const uchar mcur_ver_bits[] = {
- 0x00, 0x00, 0x03, 0x80, 0x07, 0xc0, 0x0f, 0xe0, 0x1f, 0xf0, 0x3f, 0xf8,
- 0x7f, 0xfc, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x7f, 0xfc, 0x3f, 0xf8,
- 0x1f, 0xf0, 0x0f, 0xe0, 0x07, 0xc0, 0x03, 0x80 };
-
- static const uchar cur_hor_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x20, 0x18, 0x30,
- 0x38, 0x38, 0x7f, 0xfc, 0x7f, 0xfc, 0x38, 0x38, 0x18, 0x30, 0x08, 0x20,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static const uchar mcur_hor_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x04, 0x40, 0x0c, 0x60, 0x1c, 0x70, 0x3c, 0x78,
- 0x7f, 0xfc, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0x7f, 0xfc, 0x3c, 0x78,
- 0x1c, 0x70, 0x0c, 0x60, 0x04, 0x40, 0x00, 0x00 };
-
- static const uchar cur_fdiag_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xf8, 0x00, 0xf8, 0x00, 0x78,
- 0x00, 0xf8, 0x01, 0xd8, 0x23, 0x88, 0x37, 0x00, 0x3e, 0x00, 0x3c, 0x00,
- 0x3e, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static const uchar mcur_fdiag_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x03, 0xfc, 0x01, 0xfc, 0x00, 0xfc,
- 0x41, 0xfc, 0x63, 0xfc, 0x77, 0xdc, 0x7f, 0x8c, 0x7f, 0x04, 0x7e, 0x00,
- 0x7f, 0x00, 0x7f, 0x80, 0x7f, 0xc0, 0x00, 0x00 };
-
- static const uchar cur_bdiag_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x3e, 0x00,
- 0x37, 0x00, 0x23, 0x88, 0x01, 0xd8, 0x00, 0xf8, 0x00, 0x78, 0x00, 0xf8,
- 0x01, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static const uchar mcur_bdiag_bits[] = {
- 0x00, 0x00, 0x7f, 0xc0, 0x7f, 0x80, 0x7f, 0x00, 0x7e, 0x00, 0x7f, 0x04,
- 0x7f, 0x8c, 0x77, 0xdc, 0x63, 0xfc, 0x41, 0xfc, 0x00, 0xfc, 0x01, 0xfc,
- 0x03, 0xfc, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00 };
-
- static const unsigned char cur_up_arrow_bits[] = {
- 0x00, 0x80, 0x01, 0x40, 0x01, 0x40, 0x02, 0x20, 0x02, 0x20, 0x04, 0x10,
- 0x04, 0x10, 0x08, 0x08, 0x0f, 0x78, 0x01, 0x40, 0x01, 0x40, 0x01, 0x40,
- 0x01, 0x40, 0x01, 0x40, 0x01, 0x40, 0x01, 0xc0 };
- static const unsigned char mcur_up_arrow_bits[] = {
- 0x00, 0x80, 0x01, 0xc0, 0x01, 0xc0, 0x03, 0xe0, 0x03, 0xe0, 0x07, 0xf0,
- 0x07, 0xf0, 0x0f, 0xf8, 0x0f, 0xf8, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0,
- 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0, 0x01, 0xc0 };
-#endif
- const uchar *cursorData = 0;
- const uchar *cursorMaskData = 0;
-#ifdef QT_MAC_USE_COCOA
- switch (cshape) { // map Q cursor to MAC cursor
- case Qt::BitmapCursor: {
- if (pixmap.isNull())
- initCursorFromBitmap();
- else
- initCursorFromPixmap();
- break; }
- case Qt::BlankCursor: {
- pixmap = QPixmap(16, 16);
- pixmap.fill(Qt::transparent);
- initCursorFromPixmap();
- break; }
- case Qt::ArrowCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.cp.nscursor = [NSCursor arrowCursor];
- break; }
- case Qt::CrossCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.cp.nscursor = [NSCursor crosshairCursor];
- break; }
- case Qt::WaitCursor: {
- pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/spincursor.png"));
- initCursorFromPixmap();
- break; }
- case Qt::IBeamCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.cp.nscursor = [NSCursor IBeamCursor];
- break; }
- case Qt::SizeAllCursor: {
- pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/pluscursor.png"));
- initCursorFromPixmap();
- break; }
- case Qt::WhatsThisCursor: { //for now just use the pointing hand
- case Qt::PointingHandCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.cp.nscursor = [NSCursor pointingHandCursor];
- break; }
- case Qt::BusyCursor: {
- pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/waitcursor.png"));
- initCursorFromPixmap();
- break; }
- case Qt::SplitVCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.cp.nscursor = [NSCursor resizeUpDownCursor];
- break; }
- case Qt::SplitHCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.cp.nscursor = [NSCursor resizeLeftRightCursor];
- break; }
- case Qt::ForbiddenCursor: {
- pixmap = QPixmap(QLatin1String(":/trolltech/mac/cursors/images/forbiddencursor.png"));
- initCursorFromPixmap();
- break; }
- case Qt::OpenHandCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.cp.nscursor = [NSCursor openHandCursor];
- break;
- case Qt::ClosedHandCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.cp.nscursor = [NSCursor closedHandCursor];
- break;
- case Qt::DragCopyCursor:
- type = QCursorData::TYPE_ThemeCursor;
- if ([NSCursor respondsToSelector:@selector(dragCopyCursor)])
- curs.cp.nscursor = [NSCursor performSelector:@selector(dragCopyCursor)];
- break;
- case Qt::DragMoveCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.cp.nscursor = [NSCursor arrowCursor];
- break;
- case Qt::DragLinkCursor:
- type = QCursorData::TYPE_ThemeCursor;
- if ([NSCursor respondsToSelector:@selector(dragLinkCursor)])
- curs.cp.nscursor = [NSCursor performSelector:@selector(dragLinkCursor)];
- break;
-#define QT_USE_APPROXIMATE_CURSORS
-#ifdef QT_USE_APPROXIMATE_CURSORS
- case Qt::SizeVerCursor:
- cursorData = cur_ver_bits;
- cursorMaskData = mcur_ver_bits;
- hx = hy = 8;
- break;
- case Qt::SizeHorCursor:
- cursorData = cur_hor_bits;
- cursorMaskData = mcur_hor_bits;
- hx = hy = 8;
- break;
- case Qt::SizeBDiagCursor:
- cursorData = cur_fdiag_bits;
- cursorMaskData = mcur_fdiag_bits;
- hx = hy = 8;
- break;
- case Qt::SizeFDiagCursor:
- cursorData = cur_bdiag_bits;
- cursorMaskData = mcur_bdiag_bits;
- hx = hy = 8;
- break;
- case Qt::UpArrowCursor:
- cursorData = cur_up_arrow_bits;
- cursorMaskData = mcur_up_arrow_bits;
- hx = 8;
- break;
-#endif
- default:
- qWarning("Qt: QCursor::update: Invalid cursor shape %d", cshape);
- return;
- }
-#else
- // Carbon
- switch (cshape) { // map Q cursor to MAC cursor
- case Qt::BitmapCursor: {
- if (pixmap.isNull())
- initCursorFromBitmap();
- else
- initCursorFromPixmap();
- break; }
- case Qt::BlankCursor: {
- pixmap = QPixmap(16, 16);
- pixmap.fill(Qt::transparent);
- initCursorFromPixmap();
- break; }
- case Qt::ArrowCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeArrowCursor;
- break; }
- case Qt::CrossCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeCrossCursor;
- break; }
- case Qt::WaitCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeWatchCursor;
- break; }
- case Qt::IBeamCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeIBeamCursor;
- break; }
- case Qt::SizeAllCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemePlusCursor;
- break; }
- case Qt::WhatsThisCursor: { //for now just use the pointing hand
- case Qt::PointingHandCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemePointingHandCursor;
- break; }
- case Qt::BusyCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeSpinningCursor;
- break; }
- case Qt::SplitVCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeResizeUpDownCursor;
- break; }
- case Qt::SplitHCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeResizeLeftRightCursor;
- break; }
- case Qt::ForbiddenCursor: {
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeNotAllowedCursor;
- break; }
- case Qt::OpenHandCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeOpenHandCursor;
- break;
- case Qt::ClosedHandCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeClosedHandCursor;
- break;
- case Qt::DragMoveCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeArrowCursor;
- break;
- case Qt::DragCopyCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeCopyArrowCursor;
- break;
- case Qt::DragLinkCursor:
- type = QCursorData::TYPE_ThemeCursor;
- curs.tc.curs = kThemeAliasArrowCursor;
- break;
-#define QT_USE_APPROXIMATE_CURSORS
-#ifdef QT_USE_APPROXIMATE_CURSORS
- case Qt::SizeVerCursor:
- cursorData = cur_ver_bits;
- cursorMaskData = mcur_ver_bits;
- hx = hy = 8;
- break;
- case Qt::SizeHorCursor:
- cursorData = cur_hor_bits;
- cursorMaskData = mcur_hor_bits;
- hx = hy = 8;
- break;
- case Qt::SizeBDiagCursor:
- cursorData = cur_fdiag_bits;
- cursorMaskData = mcur_fdiag_bits;
- hx = hy = 8;
- break;
- case Qt::SizeFDiagCursor:
- cursorData = cur_bdiag_bits;
- cursorMaskData = mcur_bdiag_bits;
- hx = hy = 8;
- break;
- case Qt::UpArrowCursor:
- cursorData = cur_up_arrow_bits;
- cursorMaskData = mcur_up_arrow_bits;
- hx = 8;
- break;
-#endif
- default:
- qWarning("Qt: QCursor::update: Invalid cursor shape %d", cshape);
- return;
- }
-#endif
-
- if (cursorData) {
- bm = new QBitmap(QBitmap::fromData(QSize(16, 16), cursorData,
- QImage::Format_Mono));
- bmm = new QBitmap(QBitmap::fromData(QSize(16, 16), cursorMaskData,
- QImage::Format_Mono));
- initCursorFromBitmap();
- }
-
-#if 0
- if(type == QCursorData::TYPE_CursPtr && curs.cp.hcurs && curs.cp.my_cursor) {
- curs.cp.hcurs->hotSpot.h = hx >= 0 ? hx : 8;
- curs.cp.hcurs->hotSpot.v = hy >= 0 ? hy : 8;
- }
-#endif
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qcursor_p.h b/src/gui/kernel/qcursor_p.h
deleted file mode 100644
index 660a2a5e8b..0000000000
--- a/src/gui/kernel/qcursor_p.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCURSOR_P_H
-#define QCURSOR_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of a number of Qt sources files. This header file may change from
-// version to version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "QtCore/qatomic.h"
-#include "QtCore/qglobal.h"
-#include "QtCore/qnamespace.h"
-#include "QtGui/qpixmap.h"
-
-# if defined (Q_WS_MAC)
-# include "private/qt_mac_p.h"
-# elif defined(Q_WS_X11)
-# include "private/qt_x11_p.h"
-# elif defined(Q_WS_WIN)
-# include "QtCore/qt_windows.h"
-# elif defined(Q_OS_SYMBIAN)
-# include "private/qt_s60_p.h"
-#endif
-
-QT_BEGIN_NAMESPACE
-
-#if defined (Q_WS_MAC)
-void *qt_mac_nsCursorForQCursor(const QCursor &c);
-class QMacAnimateCursor;
-#endif
-
-class QBitmap;
-class QCursorData {
-public:
- QCursorData(Qt::CursorShape s = Qt::ArrowCursor);
- ~QCursorData();
-
- static void initialize();
- static void cleanup();
-
- QAtomicInt ref;
- Qt::CursorShape cshape;
- QBitmap *bm, *bmm;
- QPixmap pixmap;
- short hx, hy;
-#if defined (Q_WS_MAC)
- int mId;
-#elif defined(Q_WS_QWS) || defined(Q_WS_QPA)
- int id;
-#endif
-#if defined (Q_WS_WIN)
- HCURSOR hcurs;
-#elif defined (Q_WS_X11)
- XColor fg, bg;
- Cursor hcurs;
- Pixmap pm, pmm;
-#elif defined (Q_WS_MAC)
- enum { TYPE_None, TYPE_ImageCursor, TYPE_ThemeCursor } type;
- union {
- struct {
- uint my_cursor:1;
- void *nscursor;
- } cp;
- struct {
- QMacAnimateCursor *anim;
- ThemeCursor curs;
- } tc;
- } curs;
- void initCursorFromBitmap();
- void initCursorFromPixmap();
-#elif defined Q_OS_SYMBIAN
- void loadShapeFromResource(RWsSpriteBase& target, QString resource, int hx, int hy, int interval=0);
- void constructShapeSprite(RWsSpriteBase& target);
- void constructCursorSprite(RWsSpriteBase& target);
- RWsPointerCursor pcurs;
- RWsSprite scurs;
- RPointerArray<TSpriteMember> nativeSpriteMembers;
-#endif
- static bool initialized;
- void update();
- static QCursorData *setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY);
-};
-
-extern QCursorData *qt_cursorTable[Qt::LastCursor + 1]; // qcursor.cpp
-
-QT_END_NAMESPACE
-
-#endif // QCURSOR_P_H
diff --git a/src/gui/kernel/qcursor_qpa.cpp b/src/gui/kernel/qcursor_qpa.cpp
deleted file mode 100644
index a6ae7d30f5..0000000000
--- a/src/gui/kernel/qcursor_qpa.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qcursor.h>
-#include <private/qcursor_p.h>
-#include <qbitmap.h>
-
-QT_BEGIN_NAMESPACE
-
-QT_USE_NAMESPACE
-
-#ifndef QT_NO_CURSOR
-
-static int nextCursorId = Qt::BitmapCursor;
-
-/*****************************************************************************
- Internal QCursorData class
- *****************************************************************************/
-
-QCursorData::QCursorData(Qt::CursorShape s)
- : cshape(s), bm(0), bmm(0), hx(0), hy(0), id(s)
-{
- ref = 1;
-}
-
-QCursorData::~QCursorData()
-{
- delete bm;
- delete bmm;
-}
-
-
-/*****************************************************************************
- Global cursors
- *****************************************************************************/
-
-extern QCursorData *qt_cursorTable[Qt::LastCursor + 1]; // qcursor.cpp
-
-int QCursor::handle() const
-{
- return d->id;
-}
-
-
-QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {
- qWarning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
- QCursorData *c = qt_cursorTable[0];
- c->ref.ref();
- return c;
- }
- QCursorData *d = new QCursorData;
- d->bm = new QBitmap(bitmap);
- d->bmm = new QBitmap(mask);
- d->cshape = Qt::BitmapCursor;
- d->id = ++nextCursorId;
- d->hx = hotX >= 0 ? hotX : bitmap.width() / 2;
- d->hy = hotY >= 0 ? hotY : bitmap.height() / 2;
-
- return d;
-}
-
-void QCursorData::update()
-{
-}
-
-#endif //QT_NO_CURSOR
-
-extern int qt_last_x,qt_last_y;
-
-QPoint QCursor::pos()
-{
- return QPoint(qt_last_x, qt_last_y);
-}
-
-void QCursor::setPos(int x, int y)
-{
- // Need to check, since some X servers generate null mouse move
- // events, causing looping in applications which call setPos() on
- // every mouse move event.
- //
- if (pos() == QPoint(x, y))
- return;
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qcursor_s60.cpp b/src/gui/kernel/qcursor_s60.cpp
deleted file mode 100644
index 8dfe87ef81..0000000000
--- a/src/gui/kernel/qcursor_s60.cpp
+++ /dev/null
@@ -1,533 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <private/qcursor_p.h>
-#include <private/qwidget_p.h>
-#include <private/qapplication_p.h>
-#include <coecntrl.h>
-#include <qcursor.h>
-#include <private/qt_s60_p.h>
-#include <qbitmap.h>
-#include <w32std.h>
-#include <qapplication.h>
-#include <qwidget.h>
-
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_NO_CURSOR
-static QCursor cursorSprite;
-static int cursorSpriteVisible;
-#endif
-
-//pos and setpos are required whether cursors are configured or not.
-QPoint QCursor::pos()
-{
- return S60->lastCursorPos;
-}
-
-void QCursor::setPos(int x, int y)
-{
- //clip to screen size (window server allows a sprite hotspot to be outside the screen)
- if (x < 0)
- x=0;
- else if (x >= S60->screenWidthInPixels)
- x = S60->screenWidthInPixels - 1;
- if (y < 0)
- y = 0;
- else if (y >= S60->screenHeightInPixels)
- y = S60->screenHeightInPixels - 1;
-
-#ifndef QT_NO_CURSOR
-#ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
- if (S60->brokenPointerCursors && cursorSpriteVisible)
- cursorSprite.d->scurs.SetPosition(TPoint(x,y));
- else
-#endif
- S60->wsSession().SetPointerCursorPosition(TPoint(x, y));
-#endif
- S60->lastCursorPos = QPoint(x, y);
- //send a fake mouse move event, so that enter/leave events go to the widget hierarchy
- QWidget *w = QApplication::topLevelAt(S60->lastCursorPos);
- if (w) {
- CCoeControl* ctrl = w->effectiveWinId();
- TPoint epos(x, y);
- TPoint cpos = epos - ctrl->PositionRelativeToScreen();
- TPointerEvent fakeEvent;
- fakeEvent.iType = TPointerEvent::EMove;
- fakeEvent.iModifiers = 0U;
- fakeEvent.iPosition = cpos;
- fakeEvent.iParentPosition = epos;
- ctrl->HandlePointerEventL(fakeEvent);
- }
-}
-
-#ifndef QT_NO_CURSOR
-/*
- * Request cursor to be turned on or off.
- * Reference counted, so 2 on + 1 off = on, for example
- */
-void qt_symbian_set_cursor_visible(bool visible) {
- if (visible)
- cursorSpriteVisible++;
- else
- cursorSpriteVisible--;
- Q_ASSERT(cursorSpriteVisible >=0);
-
- if (cursorSpriteVisible && !S60->mouseInteractionEnabled) {
-#ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
- if (S60->brokenPointerCursors)
- qt_symbian_show_pointer_sprite();
- else
-#endif
- S60->wsSession().SetPointerCursorMode(EPointerCursorNormal);
- } else if (!cursorSpriteVisible && S60->mouseInteractionEnabled) {
-#ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
- if (S60->brokenPointerCursors)
- qt_symbian_hide_pointer_sprite();
- else
-#endif
- S60->wsSession().SetPointerCursorMode(EPointerCursorNone);
- }
- S60->mouseInteractionEnabled = ((cursorSpriteVisible > 0) ? true : false);
-}
-
-/*
- * Check if the cursor is on or off
- */
-bool qt_symbian_is_cursor_visible() {
- return S60->mouseInteractionEnabled;
-}
-
-QCursorData::QCursorData(Qt::CursorShape s) :
- cshape(s), bm(0), bmm(0), hx(0), hy(0), pcurs()
-{
- ref = 1;
-}
-
-QCursorData::~QCursorData()
-{
- for(int i=0;i<nativeSpriteMembers.Count();i++) {
- delete nativeSpriteMembers[i]->iBitmap;
- delete nativeSpriteMembers[i]->iMaskBitmap;
- }
- nativeSpriteMembers.ResetAndDestroy();
- pcurs.Close();
- delete bm;
- delete bmm;
-}
-
-/* Create a bitmap cursor, this is called by public constructors in the
- * generic QCursor code.
- */
-QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {
- qWarning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
- QCursorData *c = qt_cursorTable[0];
- c->ref.ref();
- return c;
- }
- QCursorData *d = new QCursorData;
- d->bm = new QBitmap(bitmap);
- d->bmm = new QBitmap(mask);
- d->cshape = Qt::BitmapCursor;
- d->hx = hotX >= 0 ? hotX : bitmap.width() / 2;
- d->hy = hotY >= 0 ? hotY : bitmap.height() / 2;
- return d;
-}
-
-/*
- * returns an opaque native handle to a cursor.
- * It happens to be the address of the native handle, as window server handles
- * are not POD types. Note there is no QCursor(HANDLE) constructor on Symbian,
- * Mac or QWS.
- */
-Qt::HANDLE QCursor::handle() const
-{
- if (d->pcurs.WsHandle())
- return reinterpret_cast<Qt::HANDLE> (&(d->pcurs));
-
-#ifdef Q_SYMBIAN_HAS_SYSTEM_CURSORS
- // don't construct shape cursors, QApplication_s60 will use the system cursor instead
- if (!(d->bm))
- return 0;
-#endif
-
- d->pcurs = RWsPointerCursor(S60->wsSession());
- d->pcurs.Construct(0);
- d->constructCursorSprite(d->pcurs);
- d->pcurs.Activate();
-
- return reinterpret_cast<Qt::HANDLE> (&(d->pcurs));
-}
-
-#ifndef Q_SYMBIAN_HAS_SYSTEM_CURSORS
-/*
- * Loads a single cursor shape from resources and appends it to a native sprite.
- * Animated cursors (e.g. the busy cursor) have multiple members.
- */
-void QCursorData::loadShapeFromResource(RWsSpriteBase& target, QString resource, int hx, int hy, int interval)
-{
- QPixmap pix;
- CFbsBitmap* native;
- QScopedPointer<TSpriteMember> member(new TSpriteMember);
- member->iInterval = interval;
- member->iInvertMask = false;
- member->iMaskBitmap = 0; // all shapes are RGBA
- member->iDrawMode = CGraphicsContext::EDrawModePEN;
- member->iOffset = TPoint(-hx, -hy);
- QString res(QLatin1String(":/trolltech/symbian/cursors/images/%1.png"));
- pix.load(res.arg(resource));
- native = pix.toSymbianCFbsBitmap();
- member->iBitmap = native;
- qt_symbian_throwIfError(nativeSpriteMembers.Append(member.data()));
- target.AppendMember(*(member.take()));
-}
-
-//TODO: after 4.6, connect with style & skins?
-/*
- * Constructs the native cursor from resources compiled into QtGui
- * This is needed only when the platform doesn't have system cursors.
- *
- * System cursors are higher performance, since they are constructed once
- * and shared by all applications by specifying the shape number.
- * Due to symbian platform security considerations, and the fact most
- * existing phones have a broken RWsPointerCursor, system cursors are not
- * being used.
- */
-void QCursorData::constructShapeSprite(RWsSpriteBase& target)
-{
- int i;
- switch (cshape) {
- default:
- qWarning("QCursorData::constructShapeSprite unknown shape %d", cshape);
- //fall through and give arrow cursor
- case Qt::ArrowCursor:
- loadShapeFromResource(target, QLatin1String("pointer"), 1, 1);
- break;
- case Qt::UpArrowCursor:
- loadShapeFromResource(target, QLatin1String("uparrow"), 4, 0);
- break;
- case Qt::CrossCursor:
- loadShapeFromResource(target, QLatin1String("cross"), 7, 7);
- break;
- case Qt::WaitCursor:
- for (i = 1; i <= 12; i++) {
- loadShapeFromResource(target, QString(QLatin1String("wait%1")).arg(i), 7, 7, 1000000);
- }
- break;
- case Qt::IBeamCursor:
- loadShapeFromResource(target, QLatin1String("ibeam"), 3, 10);
- break;
- case Qt::SizeVerCursor:
- loadShapeFromResource(target, QLatin1String("sizever"), 4, 8);
- break;
- case Qt::SizeHorCursor:
- loadShapeFromResource(target, QLatin1String("sizehor"), 8, 4);
- break;
- case Qt::SizeBDiagCursor:
- loadShapeFromResource(target, QLatin1String("sizebdiag"), 8, 8);
- break;
- case Qt::SizeFDiagCursor:
- loadShapeFromResource(target, QLatin1String("sizefdiag"), 8, 8);
- break;
- case Qt::SizeAllCursor:
- loadShapeFromResource(target, QLatin1String("sizeall"), 7, 7);
- break;
- case Qt::BlankCursor:
- loadShapeFromResource(target, QLatin1String("blank"), 0, 0);
- break;
- case Qt::SplitVCursor:
- loadShapeFromResource(target, QLatin1String("splitv"), 7, 7);
- break;
- case Qt::SplitHCursor:
- loadShapeFromResource(target, QLatin1String("splith"), 7, 7);
- break;
- case Qt::PointingHandCursor:
- loadShapeFromResource(target, QLatin1String("handpoint"), 5, 0);
- break;
- case Qt::ForbiddenCursor:
- loadShapeFromResource(target, QLatin1String("forbidden"), 7, 7);
- break;
- case Qt::WhatsThisCursor:
- loadShapeFromResource(target, QLatin1String("whatsthis"), 1, 1);
- break;
- case Qt::BusyCursor:
- loadShapeFromResource(target, QLatin1String("busy3"), 1, 1, 1000000);
- loadShapeFromResource(target, QLatin1String("busy6"), 1, 1, 1000000);
- loadShapeFromResource(target, QLatin1String("busy9"), 1, 1, 1000000);
- loadShapeFromResource(target, QLatin1String("busy12"), 1, 1, 1000000);
- break;
- case Qt::OpenHandCursor:
- loadShapeFromResource(target, QLatin1String("openhand"), 7, 7);
- break;
- case Qt::ClosedHandCursor:
- loadShapeFromResource(target, QLatin1String("closehand"), 7, 7);
- break;
- }
-}
-#endif
-
-/*
- * Common code between the sprite workaround and standard modes of operation.
- * RWsSpriteBase is the base class for both RWsSprite and RWsPointerCursor.
- * It is called from both handle() and qt_s60_show_pointer_sprite()
- */
-void QCursorData::constructCursorSprite(RWsSpriteBase& target)
-{
- int count = nativeSpriteMembers.Count();
- if (count) {
- // already constructed
- for (int i = 0; i < count; i++)
- target.AppendMember(*(nativeSpriteMembers[i]));
-
- return;
- }
- if (pixmap.isNull() && !bm) {
-#ifndef Q_SYMBIAN_HAS_SYSTEM_CURSORS
- //shape cursor
- constructShapeSprite(target);
-#endif
- return;
- }
- QScopedPointer<TSpriteMember> member(new TSpriteMember);
- if (pixmap.isNull()) {
- //construct mono cursor
- member->iBitmap = bm->toSymbianCFbsBitmap();
- member->iMaskBitmap = bmm->toSymbianCFbsBitmap();
- }
- else {
- //construct normal cursor
- member->iBitmap = pixmap.toSymbianCFbsBitmap();
- if (pixmap.hasAlphaChannel()) {
- member->iMaskBitmap = 0; //use alpha blending
- }
- else if (pixmap.hasAlpha()) {
- member->iMaskBitmap = pixmap.mask().toSymbianCFbsBitmap();
- }
- else {
- member->iMaskBitmap = 0; //opaque rectangle cursor (due to EDrawModePEN)
- }
- }
-
- member->iDrawMode = CGraphicsContext::EDrawModePEN;
- member->iInvertMask = EFalse;
- member->iInterval = 0;
- member->iOffset = TPoint(-(hx), -(hy)); //Symbian hotspot coordinates are negative
- qt_symbian_throwIfError(nativeSpriteMembers.Append(member.data()));
- target.AppendMember(*(member.take()));
-}
-
-/*
- * shows the pointer sprite by constructing a native handle, and registering
- * it with the window server.
- * Only used when the sprite workaround is in use.
- */
-void qt_symbian_show_pointer_sprite()
-{
- if (cursorSprite.d) {
- if (cursorSprite.d->scurs.WsHandle())
- cursorSprite.d->scurs.Close();
- } else {
- cursorSprite = QCursor(Qt::ArrowCursor);
- }
-
- cursorSprite.d->scurs = RWsSprite(S60->wsSession());
- QPoint pos = QCursor::pos();
- cursorSprite.d->scurs.Construct(S60->windowGroup(), TPoint(pos.x(), pos.y()), ESpriteNoChildClip | ESpriteNoShadows);
-
- cursorSprite.d->constructCursorSprite(cursorSprite.d->scurs);
- cursorSprite.d->scurs.Activate();
-}
-
-/*
- * hides the pointer sprite by closing the native handle.
- * Only used when the sprite workaround is in use.
- */
-void qt_symbian_hide_pointer_sprite()
-{
- if (cursorSprite.d) {
- cursorSprite.d->scurs.Close();
- }
-}
-
-/*
- * Changes the cursor sprite to the cursor specified.
- * Only used when the sprite workaround is in use.
- */
-void qt_symbian_set_pointer_sprite(const QCursor& cursor)
-{
- if (S60->mouseInteractionEnabled)
- qt_symbian_hide_pointer_sprite();
- cursorSprite = cursor;
- if (S60->mouseInteractionEnabled)
- qt_symbian_show_pointer_sprite();
-}
-
-/*
- * When using sprites as a workaround on phones that have a broken
- * RWsPointerCursor, this function is called in response to pointer events
- * and when QCursor::setPos() is called.
- * Performance is worse than a real pointer cursor, due to extra context
- * switches vs. the window server moving the cursor by itself.
- */
-void qt_symbian_move_cursor_sprite()
-{
- if (S60->mouseInteractionEnabled) {
- cursorSprite.d->scurs.SetPosition(TPoint(S60->lastCursorPos.x(), S60->lastCursorPos.y()));
- }
-}
-
-/*
- * Translate from Qt::CursorShape to OS system pointer cursor list index.
- * Currently we control the implementation of the system pointer cursor list,
- * so this function is trivial. That may not always be the case.
- */
-TInt qt_symbian_translate_cursor_shape(Qt::CursorShape shape)
-{
- return (TInt) shape;
-}
-
-/*
- Internal function called from QWidget::setCursor()
- force is true if this function is called from dispatchEnterLeave, it means that the
- mouse is actually directly under this widget.
-*/
-void qt_symbian_set_cursor(QWidget *w, bool force)
-{
- static QPointer<QWidget> lastUnderMouse = 0;
- if (force) {
- lastUnderMouse = w;
- }
- else if (w->testAttribute(Qt::WA_WState_Created) && lastUnderMouse
- && lastUnderMouse->effectiveWinId() == w->effectiveWinId()) {
- w = lastUnderMouse;
- }
-
- if (!S60->curWin && w && w->internalWinId())
- return;
- QWidget* cW = w && !w->internalWinId() ? w : QWidget::find(S60->curWin);
- if (!cW || cW->window() != w->window() || !cW->isVisible() || !cW->underMouse()
- || QApplication::overrideCursor())
- return;
-
-#ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
- if (S60->brokenPointerCursors)
- qt_symbian_set_pointer_sprite(cW->cursor());
- else
-#endif
- qt_symbian_setWindowCursor(cW->cursor(), w->effectiveWinId());
-}
-
-/*
- * Makes the specified cursor appear above a specific native window group
- * Called from QSymbianControl and QApplication::restoreOverrideCursor
- *
- * Window server is needed for this, so there is no equivalent when using
- * the sprite workaround.
- */
-void qt_symbian_setWindowGroupCursor(const QCursor &cursor, RWindowTreeNode &node)
-{
- Qt::HANDLE handle = cursor.handle();
- if (handle) {
- RWsPointerCursor *pcurs = reinterpret_cast<RWsPointerCursor *> (handle);
- node.SetCustomPointerCursor(*pcurs);
- } else
-#ifdef Q_SYMBIAN_HAS_SYSTEM_CURSORS
- {
- TInt shape = qt_symbian_translate_cursor_shape(cursor.shape());
- node.SetPointerCursor(shape);
- }
-#else
- qWarning("qt_s60_setWindowGroupCursor - null handle");
-#endif
-}
-
-/*
- * Makes the specified cursor appear above a specific native window
- * Called from QSymbianControl and QApplication::restoreOverrideCursor
- *
- * Window server is needed for this, so there is no equivalent when using
- * the sprite workaround.
- */
-void qt_symbian_setWindowCursor(const QCursor &cursor, const CCoeControl* wid)
-{
- //find the window for this control
- while (!wid->OwnsWindow()) {
- wid = wid->Parent();
- if (!wid)
- return;
- }
- RWindowTreeNode *node = wid->DrawableWindow();
- qt_symbian_setWindowGroupCursor(cursor, *node);
-}
-
-/*
- * Makes the specified cursor appear everywhere.
- * Called from QApplication::setOverrideCursor
- */
-void qt_symbian_setGlobalCursor(const QCursor &cursor)
-{
-#ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
- if (S60->brokenPointerCursors) {
- qt_symbian_set_pointer_sprite(cursor);
- } else
-#endif
- {
- //because of the internals of window server, we need to force the cursor
- //to be set in all child windows too, otherwise when the cursor is over
- //the child window it may show a widget cursor or arrow cursor instead,
- //depending on construction order.
- QListIterator<WId> iter(QWidgetPrivate::mapper->uniqueKeys());
- while(iter.hasNext())
- {
- CCoeControl *ctrl = iter.next();
- if(ctrl->OwnsWindow()) {
- RWindowTreeNode *node = ctrl->DrawableWindow();
- qt_symbian_setWindowGroupCursor(cursor, *node);
- }
- }
- }
-}
-QT_END_NAMESPACE
-#endif // QT_NO_CURSOR
diff --git a/src/gui/kernel/qcursor_win.cpp b/src/gui/kernel/qcursor_win.cpp
deleted file mode 100644
index 8a9362ebfc..0000000000
--- a/src/gui/kernel/qcursor_win.cpp
+++ /dev/null
@@ -1,492 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <private/qcursor_p.h>
-#include <qbitmap.h>
-#include <qcursor.h>
-
-#ifndef QT_NO_CURSOR
-
-#include <qimage.h>
-#include <qt_windows.h>
-#include <private/qapplication_p.h>
-
-QT_BEGIN_NAMESPACE
-
-/*****************************************************************************
- Internal QCursorData class
- *****************************************************************************/
-
-QCursorData::QCursorData(Qt::CursorShape s)
- : cshape(s), bm(0), bmm(0), hx(0), hy(0), hcurs(0)
-{
- ref = 1;
-}
-
-QCursorData::~QCursorData()
-{
- delete bm;
- delete bmm;
-#if !defined(Q_WS_WINCE) || defined(GWES_ICONCURS)
- if (hcurs)
- DestroyCursor(hcurs);
-#endif
-}
-
-
-QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {
- qWarning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
- QCursorData *c = qt_cursorTable[0];
- c->ref.ref();
- return c;
- }
- QCursorData *d = new QCursorData;
- d->bm = new QBitmap(bitmap);
- d->bmm = new QBitmap(mask);
- d->hcurs = 0;
- d->cshape = Qt::BitmapCursor;
- d->hx = hotX >= 0 ? hotX : bitmap.width()/2;
- d->hy = hotY >= 0 ? hotY : bitmap.height()/2;
- return d;
-}
-
-HCURSOR QCursor::handle() const
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- if (!d->hcurs)
- d->update();
- return d->hcurs;
-}
-
-QCursor::QCursor(HCURSOR handle)
-{
- d = new QCursorData(Qt::CustomCursor);
- d->hcurs = handle;
-}
-
-#endif //QT_NO_CURSOR
-
-QPoint QCursor::pos()
-{
- POINT p;
- GetCursorPos(&p);
- return QPoint(p.x, p.y);
-}
-
-void QCursor::setPos(int x, int y)
-{
- SetCursorPos(x, y);
-}
-
-#ifndef QT_NO_CURSOR
-
-extern HBITMAP qt_createIconMask(const QBitmap &bitmap);
-
-static HCURSOR create32BitCursor(const QPixmap &pixmap, int hx, int hy)
-{
- HCURSOR cur = 0;
-#if !defined(Q_WS_WINCE)
- QBitmap mask = pixmap.mask();
- if (mask.isNull()) {
- mask = QBitmap(pixmap.size());
- mask.fill(Qt::color1);
- }
-
- HBITMAP ic = pixmap.toWinHBITMAP(QPixmap::Alpha);
- HBITMAP im = qt_createIconMask(mask);
-
- ICONINFO ii;
- ii.fIcon = 0;
- ii.xHotspot = hx;
- ii.yHotspot = hy;
- ii.hbmMask = im;
- ii.hbmColor = ic;
-
- cur = CreateIconIndirect(&ii);
-
- DeleteObject(ic);
- DeleteObject(im);
-#elif defined(GWES_ICONCURS)
- QImage bbits, mbits;
- bool invb, invm;
- bbits = pixmap.toImage().convertToFormat(QImage::Format_Mono);
- mbits = pixmap.toImage().convertToFormat(QImage::Format_Mono);
- invb = bbits.colorCount() > 1 && qGray(bbits.color(0)) < qGray(bbits.color(1));
- invm = mbits.colorCount() > 1 && qGray(mbits.color(0)) < qGray(mbits.color(1));
-
- int sysW = GetSystemMetrics(SM_CXCURSOR);
- int sysH = GetSystemMetrics(SM_CYCURSOR);
- int sysN = qMax(1, sysW / 8);
- int n = qMax(1, bbits.width() / 8);
- int h = bbits.height();
-
- uchar* xBits = new uchar[sysH * sysN];
- uchar* xMask = new uchar[sysH * sysN];
- int x = 0;
- for (int i = 0; i < sysH; ++i) {
- if (i >= h) {
- memset(&xBits[x] , 255, sysN);
- memset(&xMask[x] , 0, sysN);
- x += sysN;
- } else {
- int fillWidth = n > sysN ? sysN : n;
- uchar *bits = bbits.scanLine(i);
- uchar *mask = mbits.scanLine(i);
- for (int j = 0; j < fillWidth; ++j) {
- uchar b = bits[j];
- uchar m = mask[j];
- if (invb)
- b ^= 0xFF;
- if (invm)
- m ^= 0xFF;
- xBits[x] = ~m;
- xMask[x] = b ^ m;
- ++x;
- }
- for (int j = fillWidth; j < sysN; ++j ) {
- xBits[x] = 255;
- xMask[x] = 0;
- ++x;
- }
- }
- }
-
- cur = CreateCursor(qWinAppInst(), hx, hy, sysW, sysH,
- xBits, xMask);
-#else
- Q_UNUSED(pixmap);
- Q_UNUSED(hx);
- Q_UNUSED(hy);
-#endif
- return cur;
-}
-
-void QCursorData::update()
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- if (hcurs)
- return;
-
- if (cshape == Qt::BitmapCursor && !pixmap.isNull()) {
- hcurs = create32BitCursor(pixmap, hx, hy);
- if (hcurs)
- return;
- }
-
-
- // Non-standard Windows cursors are created from bitmaps
-
- static const uchar vsplit_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00,
- 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static const uchar vsplitm_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00,
- 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00,
- 0x00, 0xc0, 0x01, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00,
- 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00,
- 0x80, 0xff, 0xff, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00,
- 0x00, 0xc0, 0x01, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00,
- 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static const uchar hsplit_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
- 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
- 0x00, 0x41, 0x82, 0x00, 0x80, 0x41, 0x82, 0x01, 0xc0, 0x7f, 0xfe, 0x03,
- 0x80, 0x41, 0x82, 0x01, 0x00, 0x41, 0x82, 0x00, 0x00, 0x40, 0x02, 0x00,
- 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
- 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static const uchar hsplitm_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
- 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe3, 0xc7, 0x00,
- 0x80, 0xe3, 0xc7, 0x01, 0xc0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x07,
- 0xc0, 0xff, 0xff, 0x03, 0x80, 0xe3, 0xc7, 0x01, 0x00, 0xe3, 0xc7, 0x00,
- 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
- 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static const uchar phand_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00,
- 0x80, 0x04, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00, 0x80, 0x04, 0x00, 0x00,
- 0x80, 0x1c, 0x00, 0x00, 0x80, 0xe4, 0x00, 0x00, 0x80, 0x24, 0x03, 0x00,
- 0x80, 0x24, 0x05, 0x00, 0xb8, 0x24, 0x09, 0x00, 0xc8, 0x00, 0x09, 0x00,
- 0x88, 0x00, 0x08, 0x00, 0x90, 0x00, 0x08, 0x00, 0xa0, 0x00, 0x08, 0x00,
- 0x20, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x04, 0x00,
- 0x80, 0x00, 0x04, 0x00, 0x80, 0x00, 0x04, 0x00, 0x00, 0x01, 0x02, 0x00,
- 0x00, 0x01, 0x02, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
- static const uchar phandm_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00,
- 0x80, 0x07, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00, 0x80, 0x07, 0x00, 0x00,
- 0x80, 0x1f, 0x00, 0x00, 0x80, 0xff, 0x00, 0x00, 0x80, 0xff, 0x03, 0x00,
- 0x80, 0xff, 0x07, 0x00, 0xb8, 0xff, 0x0f, 0x00, 0xf8, 0xff, 0x0f, 0x00,
- 0xf8, 0xff, 0x0f, 0x00, 0xf0, 0xff, 0x0f, 0x00, 0xe0, 0xff, 0x0f, 0x00,
- 0xe0, 0xff, 0x0f, 0x00, 0xc0, 0xff, 0x0f, 0x00, 0xc0, 0xff, 0x07, 0x00,
- 0x80, 0xff, 0x07, 0x00, 0x80, 0xff, 0x07, 0x00, 0x00, 0xff, 0x03, 0x00,
- 0x00, 0xff, 0x03, 0x00, 0x00, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
- static const uchar openhand_bits[] = {
- 0x80,0x01,0x58,0x0e,0x64,0x12,0x64,0x52,0x48,0xb2,0x48,0x92,
- 0x16,0x90,0x19,0x80,0x11,0x40,0x02,0x40,0x04,0x40,0x04,0x20,
- 0x08,0x20,0x10,0x10,0x20,0x10,0x00,0x00};
- static const uchar openhandm_bits[] = {
- 0x80,0x01,0xd8,0x0f,0xfc,0x1f,0xfc,0x5f,0xf8,0xff,0xf8,0xff,
- 0xf6,0xff,0xff,0xff,0xff,0x7f,0xfe,0x7f,0xfc,0x7f,0xfc,0x3f,
- 0xf8,0x3f,0xf0,0x1f,0xe0,0x1f,0x00,0x00};
- static const uchar closedhand_bits[] = {
- 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0x48,0x32,0x08,0x50,
- 0x10,0x40,0x18,0x40,0x04,0x40,0x04,0x20,0x08,0x20,0x10,0x10,
- 0x20,0x10,0x20,0x10,0x00,0x00,0x00,0x00};
- static const uchar closedhandm_bits[] = {
- 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0xf8,0x3f,0xf8,0x7f,
- 0xf0,0x7f,0xf8,0x7f,0xfc,0x7f,0xfc,0x3f,0xf8,0x3f,0xf0,0x1f,
- 0xe0,0x1f,0xe0,0x1f,0x00,0x00,0x00,0x00};
-
- static const uchar * const cursor_bits32[] = {
- vsplit_bits, vsplitm_bits, hsplit_bits, hsplitm_bits,
- phand_bits, phandm_bits
- };
-
- wchar_t *sh = 0;
- switch (cshape) { // map to windows cursor
- case Qt::ArrowCursor:
- sh = IDC_ARROW;
- break;
- case Qt::UpArrowCursor:
- sh = IDC_UPARROW;
- break;
- case Qt::CrossCursor:
- sh = IDC_CROSS;
- break;
- case Qt::WaitCursor:
- sh = IDC_WAIT;
- break;
- case Qt::IBeamCursor:
- sh = IDC_IBEAM;
- break;
- case Qt::SizeVerCursor:
- sh = IDC_SIZENS;
- break;
- case Qt::SizeHorCursor:
- sh = IDC_SIZEWE;
- break;
- case Qt::SizeBDiagCursor:
- sh = IDC_SIZENESW;
- break;
- case Qt::SizeFDiagCursor:
- sh = IDC_SIZENWSE;
- break;
- case Qt::SizeAllCursor:
- sh = IDC_SIZEALL;
- break;
- case Qt::ForbiddenCursor:
- sh = IDC_NO;
- break;
- case Qt::WhatsThisCursor:
- sh = IDC_HELP;
- break;
- case Qt::BusyCursor:
- sh = IDC_APPSTARTING;
- break;
- case Qt::PointingHandCursor:
- sh = IDC_HAND;
- break;
- case Qt::BlankCursor:
- case Qt::SplitVCursor:
- case Qt::SplitHCursor:
- case Qt::OpenHandCursor:
- case Qt::ClosedHandCursor:
- case Qt::BitmapCursor: {
- QImage bbits, mbits;
- bool invb, invm;
- if (cshape == Qt::BlankCursor) {
- bbits = QImage(32, 32, QImage::Format_Mono);
- bbits.fill(0); // ignore color table
- mbits = bbits.copy();
- hx = hy = 16;
- invb = invm = false;
- } else if (cshape == Qt::OpenHandCursor || cshape == Qt::ClosedHandCursor) {
- bool open = cshape == Qt::OpenHandCursor;
- QBitmap cb = QBitmap::fromData(QSize(16, 16), open ? openhand_bits : closedhand_bits);
- QBitmap cm = QBitmap::fromData(QSize(16, 16), open ? openhandm_bits : closedhandm_bits);
- bbits = cb.toImage().convertToFormat(QImage::Format_Mono);
- mbits = cm.toImage().convertToFormat(QImage::Format_Mono);
- hx = hy = 8;
- invb = invm = false;
- } else if (cshape != Qt::BitmapCursor) {
- int i = cshape - Qt::SplitVCursor;
- QBitmap cb = QBitmap::fromData(QSize(32, 32), cursor_bits32[i * 2]);
- QBitmap cm = QBitmap::fromData(QSize(32, 32), cursor_bits32[i * 2 + 1]);
- bbits = cb.toImage().convertToFormat(QImage::Format_Mono);
- mbits = cm.toImage().convertToFormat(QImage::Format_Mono);
- if (cshape == Qt::PointingHandCursor) {
- hx = 7;
- hy = 0;
- } else
- hx = hy = 16;
- invb = invm = false;
- } else {
- bbits = bm->toImage().convertToFormat(QImage::Format_Mono);
- mbits = bmm->toImage().convertToFormat(QImage::Format_Mono);
- invb = bbits.colorCount() > 1 && qGray(bbits.color(0)) < qGray(bbits.color(1));
- invm = mbits.colorCount() > 1 && qGray(mbits.color(0)) < qGray(mbits.color(1));
- }
- int n = qMax(1, bbits.width() / 8);
- int h = bbits.height();
-#if !defined(Q_WS_WINCE)
- uchar* xBits = new uchar[h * n];
- uchar* xMask = new uchar[h * n];
- int x = 0;
- for (int i = 0; i < h; ++i) {
- uchar *bits = bbits.scanLine(i);
- uchar *mask = mbits.scanLine(i);
- for (int j = 0; j < n; ++j) {
- uchar b = bits[j];
- uchar m = mask[j];
- if (invb)
- b ^= 0xff;
- if (invm)
- m ^= 0xff;
- xBits[x] = ~m;
- xMask[x] = b ^ m;
- ++x;
- }
- }
- hcurs = CreateCursor(qWinAppInst(), hx, hy, bbits.width(), bbits.height(),
- xBits, xMask);
- delete [] xBits;
- delete [] xMask;
-#elif defined(GWES_ICONCURS) // Q_WS_WINCE
- // Windows CE only supports fixed cursor size.
- int sysW = GetSystemMetrics(SM_CXCURSOR);
- int sysH = GetSystemMetrics(SM_CYCURSOR);
- int sysN = qMax(1, sysW / 8);
- uchar* xBits = new uchar[sysH * sysN];
- uchar* xMask = new uchar[sysH * sysN];
- int x = 0;
- for (int i = 0; i < sysH; ++i) {
- if (i >= h) {
- memset(&xBits[x] , 255, sysN);
- memset(&xMask[x] , 0, sysN);
- x += sysN;
- } else {
- int fillWidth = n > sysN ? sysN : n;
- uchar *bits = bbits.scanLine(i);
- uchar *mask = mbits.scanLine(i);
- for (int j = 0; j < fillWidth; ++j) {
- uchar b = bits[j];
- uchar m = mask[j];
- if (invb)
- b ^= 0xFF;
- if (invm)
- m ^= 0xFF;
- xBits[x] = ~m;
- xMask[x] = b ^ m;
- ++x;
- }
- for (int j = fillWidth; j < sysN; ++j ) {
- xBits[x] = 255;
- xMask[x] = 0;
- ++x;
- }
- }
- }
-
- hcurs = CreateCursor(qWinAppInst(), hx, hy, sysW, sysH,
- xBits, xMask);
- delete [] xBits;
- delete [] xMask;
-#else
- Q_UNUSED(n);
- Q_UNUSED(h);
-#endif
- return;
- }
- case Qt::DragCopyCursor:
- case Qt::DragMoveCursor:
- case Qt::DragLinkCursor: {
- QPixmap pixmap = QApplicationPrivate::instance()->getPixmapCursor(cshape);
- hcurs = create32BitCursor(pixmap, hx, hy);
- }
- default:
- qWarning("QCursor::update: Invalid cursor shape %d", cshape);
- return;
- }
-#ifdef Q_WS_WINCE
- hcurs = LoadCursor(0, sh);
-#else
- hcurs = (HCURSOR)LoadImage(0, sh, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
-#endif
-}
-
-QT_END_NAMESPACE
-#endif // QT_NO_CURSOR
diff --git a/src/gui/kernel/qcursor_x11.cpp b/src/gui/kernel/qcursor_x11.cpp
deleted file mode 100644
index d0ed98e1fe..0000000000
--- a/src/gui/kernel/qcursor_x11.cpp
+++ /dev/null
@@ -1,637 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qdebug.h>
-#include <qdatastream.h>
-#include <private/qcursor_p.h>
-#include <private/qt_x11_p.h>
-#include <private/qapplication_p.h>
-#include <qbitmap.h>
-#include <qcursor.h>
-#include <X11/cursorfont.h>
-
-#include <qlibrary.h>
-
-#ifndef QT_NO_XCURSOR
-# include <X11/Xcursor/Xcursor.h>
-#endif // QT_NO_XCURSOR
-
-#ifndef QT_NO_XFIXES
-# include <X11/extensions/Xfixes.h>
-#endif // QT_NO_XFIXES
-
-#include "qx11info_x11.h"
-#include <private/qpixmap_x11_p.h>
-
-QT_BEGIN_NAMESPACE
-
-// Define QT_USE_APPROXIMATE_CURSORS when compiling if you REALLY want to
-// use the ugly X11 cursors.
-
-/*****************************************************************************
- Internal QCursorData class
- *****************************************************************************/
-
-QCursorData::QCursorData(Qt::CursorShape s)
- : cshape(s), bm(0), bmm(0), hx(0), hy(0), hcurs(0), pm(0), pmm(0)
-{
- ref = 1;
-}
-
-QCursorData::~QCursorData()
-{
- Display *dpy = X11 ? X11->display : (Display*)0;
-
- // Add in checking for the display too as on HP-UX
- // we seem to get a core dump as the cursor data is
- // deleted again from main() on exit...
- if (hcurs && dpy)
- XFreeCursor(dpy, hcurs);
- if (pm && dpy)
- XFreePixmap(dpy, pm);
- if (pmm && dpy)
- XFreePixmap(dpy, pmm);
- delete bm;
- delete bmm;
-}
-
-#ifndef QT_NO_CURSOR
-QCursor::QCursor(Qt::HANDLE cursor)
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- d = new QCursorData(Qt::CustomCursor);
- d->hcurs = cursor;
-}
-
-#endif
-
-QCursorData *QCursorData::setBitmap(const QBitmap &bitmap, const QBitmap &mask, int hotX, int hotY)
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- if (bitmap.depth() != 1 || mask.depth() != 1 || bitmap.size() != mask.size()) {
- qWarning("QCursor: Cannot create bitmap cursor; invalid bitmap(s)");
- QCursorData *c = qt_cursorTable[0];
- c->ref.ref();
- return c;
- }
- QCursorData *d = new QCursorData;
- d->ref = 1;
-
- extern QPixmap qt_toX11Pixmap(const QPixmap &pixmap); // qpixmap_x11.cpp
- d->bm = new QBitmap(qt_toX11Pixmap(bitmap));
- d->bmm = new QBitmap(qt_toX11Pixmap(mask));
-
- d->hcurs = 0;
- d->cshape = Qt::BitmapCursor;
- d->hx = hotX >= 0 ? hotX : bitmap.width() / 2;
- d->hy = hotY >= 0 ? hotY : bitmap.height() / 2;
- d->fg.red = 0x0000;
- d->fg.green = 0x0000;
- d->fg.blue = 0x0000;
- d->bg.red = 0xffff;
- d->bg.green = 0xffff;
- d->bg.blue = 0xffff;
- return d;
-}
-
-
-
-#ifndef QT_NO_CURSOR
-Qt::HANDLE QCursor::handle() const
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- if (!d->hcurs)
- d->update();
- return d->hcurs;
-}
-#endif
-
-QPoint QCursor::pos()
-{
- Window root;
- Window child;
- int root_x, root_y, win_x, win_y;
- uint buttons;
- Display* dpy = X11->display;
- for (int i = 0; i < ScreenCount(dpy); ++i) {
- if (XQueryPointer(dpy, QX11Info::appRootWindow(i), &root, &child, &root_x, &root_y,
- &win_x, &win_y, &buttons))
-
- return QPoint(root_x, root_y);
- }
- return QPoint();
-}
-
-/*! \internal
-*/
-#ifndef QT_NO_CURSOR
-int QCursor::x11Screen()
-{
- Window root;
- Window child;
- int root_x, root_y, win_x, win_y;
- uint buttons;
- Display* dpy = X11->display;
- for (int i = 0; i < ScreenCount(dpy); ++i) {
- if (XQueryPointer(dpy, QX11Info::appRootWindow(i), &root, &child, &root_x, &root_y,
- &win_x, &win_y, &buttons))
- return i;
- }
- return -1;
-}
-#endif
-
-void QCursor::setPos(int x, int y)
-{
- QPoint current, target(x, y);
-
- // this is copied from pos(), since we need the screen number for the correct
- // root window in the XWarpPointer call
- Window root;
- Window child;
- int root_x, root_y, win_x, win_y;
- uint buttons;
- Display* dpy = X11->display;
- int screen;
- for (screen = 0; screen < ScreenCount(dpy); ++screen) {
- if (XQueryPointer(dpy, QX11Info::appRootWindow(screen), &root, &child, &root_x, &root_y,
- &win_x, &win_y, &buttons)) {
- current = QPoint(root_x, root_y);
- break;
- }
- }
-
- if (screen >= ScreenCount(dpy))
- return;
-
- // Need to check, since some X servers generate null mouse move
- // events, causing looping in applications which call setPos() on
- // every mouse move event.
- //
- if (current == target)
- return;
-
- XWarpPointer(X11->display, XNone, QX11Info::appRootWindow(screen), 0, 0, 0, 0, x, y);
-}
-
-
-/*!
- \internal
-
- Creates the cursor.
-*/
-
-void QCursorData::update()
-{
- if (!QCursorData::initialized)
- QCursorData::initialize();
- if (hcurs)
- return;
-
- Display *dpy = X11->display;
- Window rootwin = QX11Info::appRootWindow();
-
- if (cshape == Qt::BitmapCursor) {
- extern QPixmap qt_toX11Pixmap(const QPixmap &pixmap); // qpixmap_x11.cpp
-#ifndef QT_NO_XRENDER
- if (!pixmap.isNull() && X11->use_xrender) {
- pixmap = qt_toX11Pixmap(pixmap);
- hcurs = XRenderCreateCursor (X11->display, pixmap.x11PictureHandle(), hx, hy);
- } else
-#endif
- {
- hcurs = XCreatePixmapCursor(dpy, bm->handle(), bmm->handle(), &fg, &bg, hx, hy);
- }
- return;
- }
-
- static const char *cursorNames[] = {
- "left_ptr",
- "up_arrow",
- "cross",
- "wait",
- "ibeam",
- "size_ver",
- "size_hor",
- "size_bdiag",
- "size_fdiag",
- "size_all",
- "blank",
- "split_v",
- "split_h",
- "pointing_hand",
- "forbidden",
- "whats_this",
- "left_ptr_watch",
- "openhand",
- "closedhand",
- "copy",
- "move",
- "link"
- };
-
-#ifndef QT_NO_XCURSOR
- if (X11->ptrXcursorLibraryLoadCursor) {
- // special case for non-standard dnd-* cursors
- switch (cshape) {
- case Qt::DragCopyCursor:
- hcurs = X11->ptrXcursorLibraryLoadCursor(dpy, "dnd-copy");
- break;
- case Qt::DragMoveCursor:
- hcurs = X11->ptrXcursorLibraryLoadCursor(dpy, "dnd-move");
- break;
- case Qt::DragLinkCursor:
- hcurs = X11->ptrXcursorLibraryLoadCursor(dpy, "dnd-link");
- break;
- default:
- break;
- }
- if (!hcurs)
- hcurs = X11->ptrXcursorLibraryLoadCursor(dpy, cursorNames[cshape]);
- }
- if (hcurs)
- return;
-#endif // QT_NO_XCURSOR
-
- static const uchar cur_blank_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-
- // Non-standard X11 cursors are created from bitmaps
-
-#ifndef QT_USE_APPROXIMATE_CURSORS
- static const uchar cur_ver_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0xc0, 0x03, 0xe0, 0x07, 0xf0, 0x0f,
- 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xf0, 0x0f,
- 0xe0, 0x07, 0xc0, 0x03, 0x80, 0x01, 0x00, 0x00 };
- static const uchar mcur_ver_bits[] = {
- 0x00, 0x00, 0x80, 0x03, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, 0x1f, 0xf8, 0x3f,
- 0xfc, 0x7f, 0xc0, 0x07, 0xc0, 0x07, 0xc0, 0x07, 0xfc, 0x7f, 0xf8, 0x3f,
- 0xf0, 0x1f, 0xe0, 0x0f, 0xc0, 0x07, 0x80, 0x03 };
- static const uchar cur_hor_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x08, 0x30, 0x18,
- 0x38, 0x38, 0xfc, 0x7f, 0xfc, 0x7f, 0x38, 0x38, 0x30, 0x18, 0x20, 0x08,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static const uchar mcur_hor_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x40, 0x04, 0x60, 0x0c, 0x70, 0x1c, 0x78, 0x3c,
- 0xfc, 0x7f, 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfc, 0x7f, 0x78, 0x3c,
- 0x70, 0x1c, 0x60, 0x0c, 0x40, 0x04, 0x00, 0x00 };
- static const uchar cur_bdiag_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x3e, 0x00, 0x3c, 0x00, 0x3e,
- 0x00, 0x37, 0x88, 0x23, 0xd8, 0x01, 0xf8, 0x00, 0x78, 0x00, 0xf8, 0x00,
- 0xf8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static const uchar mcur_bdiag_bits[] = {
- 0x00, 0x00, 0xc0, 0x7f, 0x80, 0x7f, 0x00, 0x7f, 0x00, 0x7e, 0x04, 0x7f,
- 0x8c, 0x7f, 0xdc, 0x77, 0xfc, 0x63, 0xfc, 0x41, 0xfc, 0x00, 0xfc, 0x01,
- 0xfc, 0x03, 0xfc, 0x07, 0x00, 0x00, 0x00, 0x00 };
- static const uchar cur_fdiag_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x01, 0xf8, 0x00, 0x78, 0x00,
- 0xf8, 0x00, 0xd8, 0x01, 0x88, 0x23, 0x00, 0x37, 0x00, 0x3e, 0x00, 0x3c,
- 0x00, 0x3e, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00 };
- static const uchar mcur_fdiag_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0xfc, 0x07, 0xfc, 0x03, 0xfc, 0x01, 0xfc, 0x00,
- 0xfc, 0x41, 0xfc, 0x63, 0xdc, 0x77, 0x8c, 0x7f, 0x04, 0x7f, 0x00, 0x7e,
- 0x00, 0x7f, 0x80, 0x7f, 0xc0, 0x7f, 0x00, 0x00 };
- static const uchar *cursor_bits16[] = {
- cur_ver_bits, mcur_ver_bits, cur_hor_bits, mcur_hor_bits,
- cur_bdiag_bits, mcur_bdiag_bits, cur_fdiag_bits, mcur_fdiag_bits,
- 0, 0, cur_blank_bits, cur_blank_bits };
-
- static const uchar vsplit_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xe0, 0x03, 0x00,
- 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static const uchar vsplitm_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0xc0, 0x01, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00,
- 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00,
- 0x00, 0xc0, 0x01, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00,
- 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x00,
- 0x80, 0xff, 0xff, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x01, 0x00,
- 0x00, 0xc0, 0x01, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf0, 0x07, 0x00,
- 0x00, 0xe0, 0x03, 0x00, 0x00, 0xc0, 0x01, 0x00, 0x00, 0x80, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static const uchar hsplit_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
- 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
- 0x00, 0x41, 0x82, 0x00, 0x80, 0x41, 0x82, 0x01, 0xc0, 0x7f, 0xfe, 0x03,
- 0x80, 0x41, 0x82, 0x01, 0x00, 0x41, 0x82, 0x00, 0x00, 0x40, 0x02, 0x00,
- 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00,
- 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static const uchar hsplitm_bits[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
- 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe3, 0xc7, 0x00,
- 0x80, 0xe3, 0xc7, 0x01, 0xc0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x07,
- 0xc0, 0xff, 0xff, 0x03, 0x80, 0xe3, 0xc7, 0x01, 0x00, 0xe3, 0xc7, 0x00,
- 0x00, 0xe2, 0x47, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
- 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- static const uchar whatsthis_bits[] = {
- 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0xf0, 0x07, 0x00,
- 0x09, 0x18, 0x0e, 0x00, 0x11, 0x1c, 0x0e, 0x00, 0x21, 0x1c, 0x0e, 0x00,
- 0x41, 0x1c, 0x0e, 0x00, 0x81, 0x1c, 0x0e, 0x00, 0x01, 0x01, 0x07, 0x00,
- 0x01, 0x82, 0x03, 0x00, 0xc1, 0xc7, 0x01, 0x00, 0x49, 0xc0, 0x01, 0x00,
- 0x95, 0xc0, 0x01, 0x00, 0x93, 0xc0, 0x01, 0x00, 0x21, 0x01, 0x00, 0x00,
- 0x20, 0xc1, 0x01, 0x00, 0x40, 0xc2, 0x01, 0x00, 0x40, 0x02, 0x00, 0x00,
- 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
- static const uchar whatsthism_bits[] = {
- 0x01, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x07, 0x00, 0x07, 0xf8, 0x0f, 0x00,
- 0x0f, 0xfc, 0x1f, 0x00, 0x1f, 0x3e, 0x1f, 0x00, 0x3f, 0x3e, 0x1f, 0x00,
- 0x7f, 0x3e, 0x1f, 0x00, 0xff, 0x3e, 0x1f, 0x00, 0xff, 0x9d, 0x0f, 0x00,
- 0xff, 0xc3, 0x07, 0x00, 0xff, 0xe7, 0x03, 0x00, 0x7f, 0xe0, 0x03, 0x00,
- 0xf7, 0xe0, 0x03, 0x00, 0xf3, 0xe0, 0x03, 0x00, 0xe1, 0xe1, 0x03, 0x00,
- 0xe0, 0xe1, 0x03, 0x00, 0xc0, 0xe3, 0x03, 0x00, 0xc0, 0xe3, 0x03, 0x00,
- 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
- static const uchar busy_bits[] = {
- 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00,
- 0x09, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00,
- 0x41, 0xe0, 0xff, 0x00, 0x81, 0x20, 0x80, 0x00, 0x01, 0xe1, 0xff, 0x00,
- 0x01, 0x42, 0x40, 0x00, 0xc1, 0x47, 0x40, 0x00, 0x49, 0x40, 0x55, 0x00,
- 0x95, 0x80, 0x2a, 0x00, 0x93, 0x00, 0x15, 0x00, 0x21, 0x01, 0x0a, 0x00,
- 0x20, 0x01, 0x11, 0x00, 0x40, 0x82, 0x20, 0x00, 0x40, 0x42, 0x44, 0x00,
- 0x80, 0x41, 0x4a, 0x00, 0x00, 0x40, 0x55, 0x00, 0x00, 0xe0, 0xff, 0x00,
- 0x00, 0x20, 0x80, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- static const uchar busym_bits[] = {
- 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
- 0x0f, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00,
- 0x7f, 0xe0, 0xff, 0x00, 0xff, 0xe0, 0xff, 0x00, 0xff, 0xe1, 0xff, 0x00,
- 0xff, 0xc3, 0x7f, 0x00, 0xff, 0xc7, 0x7f, 0x00, 0x7f, 0xc0, 0x7f, 0x00,
- 0xf7, 0x80, 0x3f, 0x00, 0xf3, 0x00, 0x1f, 0x00, 0xe1, 0x01, 0x0e, 0x00,
- 0xe0, 0x01, 0x1f, 0x00, 0xc0, 0x83, 0x3f, 0x00, 0xc0, 0xc3, 0x7f, 0x00,
- 0x80, 0xc1, 0x7f, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, 0xe0, 0xff, 0x00,
- 0x00, 0xe0, 0xff, 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-
- static const uchar * const cursor_bits32[] = {
- vsplit_bits, vsplitm_bits, hsplit_bits, hsplitm_bits,
- 0, 0, 0, 0, whatsthis_bits, whatsthism_bits, busy_bits, busym_bits
- };
-
- static const uchar forbidden_bits[] = {
- 0x00,0x00,0x00,0x80,0x1f,0x00,0xe0,0x7f,0x00,0xf0,0xf0,0x00,0x38,0xc0,0x01,
- 0x7c,0x80,0x03,0xec,0x00,0x03,0xce,0x01,0x07,0x86,0x03,0x06,0x06,0x07,0x06,
- 0x06,0x0e,0x06,0x06,0x1c,0x06,0x0e,0x38,0x07,0x0c,0x70,0x03,0x1c,0xe0,0x03,
- 0x38,0xc0,0x01,0xf0,0xe0,0x00,0xe0,0x7f,0x00,0x80,0x1f,0x00,0x00,0x00,0x00 };
-
- static const uchar forbiddenm_bits[] = {
- 0x80,0x1f,0x00,0xe0,0x7f,0x00,0xf0,0xff,0x00,0xf8,0xff,0x01,0xfc,0xf0,0x03,
- 0xfe,0xc0,0x07,0xfe,0x81,0x07,0xff,0x83,0x0f,0xcf,0x07,0x0f,0x8f,0x0f,0x0f,
- 0x0f,0x1f,0x0f,0x0f,0x3e,0x0f,0x1f,0xfc,0x0f,0x1e,0xf8,0x07,0x3e,0xf0,0x07,
- 0xfc,0xe0,0x03,0xf8,0xff,0x01,0xf0,0xff,0x00,0xe0,0x7f,0x00,0x80,0x1f,0x00};
-
- static const uchar openhand_bits[] = {
- 0x80,0x01,0x58,0x0e,0x64,0x12,0x64,0x52,0x48,0xb2,0x48,0x92,
- 0x16,0x90,0x19,0x80,0x11,0x40,0x02,0x40,0x04,0x40,0x04,0x20,
- 0x08,0x20,0x10,0x10,0x20,0x10,0x00,0x00};
- static const uchar openhandm_bits[] = {
- 0x80,0x01,0xd8,0x0f,0xfc,0x1f,0xfc,0x5f,0xf8,0xff,0xf8,0xff,
- 0xf6,0xff,0xff,0xff,0xff,0x7f,0xfe,0x7f,0xfc,0x7f,0xfc,0x3f,
- 0xf8,0x3f,0xf0,0x1f,0xe0,0x1f,0x00,0x00};
- static const uchar closedhand_bits[] = {
- 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0x48,0x32,0x08,0x50,
- 0x10,0x40,0x18,0x40,0x04,0x40,0x04,0x20,0x08,0x20,0x10,0x10,
- 0x20,0x10,0x20,0x10,0x00,0x00,0x00,0x00};
- static const uchar closedhandm_bits[] = {
- 0x00,0x00,0x00,0x00,0x00,0x00,0xb0,0x0d,0xf8,0x3f,0xf8,0x7f,
- 0xf0,0x7f,0xf8,0x7f,0xfc,0x7f,0xfc,0x3f,0xf8,0x3f,0xf0,0x1f,
- 0xe0,0x1f,0xe0,0x1f,0x00,0x00,0x00,0x00};
-
- static const uchar * const cursor_bits20[] = {
- forbidden_bits, forbiddenm_bits
- };
-
- if ((cshape >= Qt::SizeVerCursor && cshape < Qt::SizeAllCursor)
- || cshape == Qt::BlankCursor) {
- XColor bg, fg;
- bg.red = 255 << 8;
- bg.green = 255 << 8;
- bg.blue = 255 << 8;
- fg.red = 0;
- fg.green = 0;
- fg.blue = 0;
- int i = (cshape - Qt::SizeVerCursor) * 2;
- pm = XCreateBitmapFromData(dpy, rootwin, reinterpret_cast<const char*>(cursor_bits16[i]), 16, 16);
- pmm = XCreateBitmapFromData(dpy, rootwin, reinterpret_cast<const char*>(cursor_bits16[i + 1]), 16, 16);
- hcurs = XCreatePixmapCursor(dpy, pm, pmm, &fg, &bg, 8, 8);
- } else if ((cshape >= Qt::SplitVCursor && cshape <= Qt::SplitHCursor)
- || cshape == Qt::WhatsThisCursor || cshape == Qt::BusyCursor) {
- XColor bg, fg;
- bg.red = 255 << 8;
- bg.green = 255 << 8;
- bg.blue = 255 << 8;
- fg.red = 0;
- fg.green = 0;
- fg.blue = 0;
- int i = (cshape - Qt::SplitVCursor) * 2;
- pm = XCreateBitmapFromData(dpy, rootwin, reinterpret_cast<const char *>(cursor_bits32[i]), 32, 32);
- pmm = XCreateBitmapFromData(dpy, rootwin, reinterpret_cast<const char *>(cursor_bits32[i + 1]), 32, 32);
- int hs = (cshape == Qt::PointingHandCursor || cshape == Qt::WhatsThisCursor
- || cshape == Qt::BusyCursor) ? 0 : 16;
- hcurs = XCreatePixmapCursor(dpy, pm, pmm, &fg, &bg, hs, hs);
- } else if (cshape == Qt::ForbiddenCursor) {
- XColor bg, fg;
- bg.red = 255 << 8;
- bg.green = 255 << 8;
- bg.blue = 255 << 8;
- fg.red = 0;
- fg.green = 0;
- fg.blue = 0;
- int i = (cshape - Qt::ForbiddenCursor) * 2;
- pm = XCreateBitmapFromData(dpy, rootwin, reinterpret_cast<const char *>(cursor_bits20[i]), 20, 20);
- pmm = XCreateBitmapFromData(dpy, rootwin, reinterpret_cast<const char *>(cursor_bits20[i + 1]), 20, 20);
- hcurs = XCreatePixmapCursor(dpy, pm, pmm, &fg, &bg, 10, 10);
- } else if (cshape == Qt::OpenHandCursor || cshape == Qt::ClosedHandCursor) {
- XColor bg, fg;
- bg.red = 255 << 8;
- bg.green = 255 << 8;
- bg.blue = 255 << 8;
- fg.red = 0;
- fg.green = 0;
- fg.blue = 0;
- bool open = cshape == Qt::OpenHandCursor;
- pm = XCreateBitmapFromData(dpy, rootwin, reinterpret_cast<const char *>(open ? openhand_bits : closedhand_bits), 16, 16);
- pmm = XCreateBitmapFromData(dpy, rootwin, reinterpret_cast<const char *>(open ? openhandm_bits : closedhandm_bits), 16, 16);
- hcurs = XCreatePixmapCursor(dpy, pm, pmm, &fg, &bg, 8, 8);
- } else if (cshape == Qt::DragCopyCursor || cshape == Qt::DragMoveCursor
- || cshape == Qt::DragLinkCursor) {
- XColor bg, fg;
- bg.red = 255 << 8;
- bg.green = 255 << 8;
- bg.blue = 255 << 8;
- fg.red = 0;
- fg.green = 0;
- fg.blue = 0;
- QImage image = QApplicationPrivate::instance()->getPixmapCursor(cshape).toImage();
- pm = QX11PixmapData::createBitmapFromImage(image);
- pmm = QX11PixmapData::createBitmapFromImage(image.createAlphaMask().convertToFormat(QImage::Format_MonoLSB));
- hcurs = XCreatePixmapCursor(dpy, pm, pmm, &fg, &bg, 8, 8);
- }
-
- if (hcurs)
- {
-#ifndef QT_NO_XFIXES
- if (X11->use_xfixes && X11->ptrXFixesSetCursorName)
- X11->ptrXFixesSetCursorName(dpy, hcurs, cursorNames[cshape]);
-#endif /* ! QT_NO_XFIXES */
- return;
- }
-
-#endif /* ! QT_USE_APPROXIMATE_CURSORS */
-
- uint sh;
- switch (cshape) { // map Q cursor to X cursor
- case Qt::ArrowCursor:
- sh = XC_left_ptr;
- break;
- case Qt::UpArrowCursor:
- sh = XC_center_ptr;
- break;
- case Qt::CrossCursor:
- sh = XC_crosshair;
- break;
- case Qt::WaitCursor:
- sh = XC_watch;
- break;
- case Qt::IBeamCursor:
- sh = XC_xterm;
- break;
- case Qt::SizeAllCursor:
- sh = XC_fleur;
- break;
- case Qt::PointingHandCursor:
- sh = XC_hand2;
- break;
-#ifdef QT_USE_APPROXIMATE_CURSORS
- case Qt::SizeBDiagCursor:
- sh = XC_top_right_corner;
- break;
- case Qt::SizeFDiagCursor:
- sh = XC_bottom_right_corner;
- break;
- case Qt::BlankCursor:
- XColor bg, fg;
- bg.red = 255 << 8;
- bg.green = 255 << 8;
- bg.blue = 255 << 8;
- fg.red = 0;
- fg.green = 0;
- fg.blue = 0;
- pm = XCreateBitmapFromData(dpy, rootwin, cur_blank_bits, 16, 16);
- pmm = XCreateBitmapFromData(dpy, rootwin, cur_blank_bits, 16, 16);
- hcurs = XCreatePixmapCursor(dpy, pm, pmm, &fg, &bg, 8, 8);
- return;
- break;
- case Qt::SizeVerCursor:
- case Qt::SplitVCursor:
- sh = XC_sb_v_double_arrow;
- break;
- case Qt::SizeHorCursor:
- case Qt::SplitHCursor:
- sh = XC_sb_h_double_arrow;
- break;
- case Qt::WhatsThisCursor:
- sh = XC_question_arrow;
- break;
- case Qt::ForbiddenCursor:
- sh = XC_circle;
- break;
- case Qt::BusyCursor:
- sh = XC_watch;
- break;
- case Qt::DragCopyCursor:
- sh = XC_tcross;
- break;
- case Qt::DragLinkCursor:
- sh = XC_center_ptr;
- break;
- case Qt::DragMoveCursor:
- sh = XC_top_left_arrow;
- break;
-#endif /* QT_USE_APPROXIMATE_CURSORS */
- default:
- qWarning("QCursor::update: Invalid cursor shape %d", cshape);
- return;
- }
- hcurs = XCreateFontCursor(dpy, sh);
-
-#ifndef QT_NO_XFIXES
- if (X11->use_xfixes && X11->ptrXFixesSetCursorName)
- X11->ptrXFixesSetCursorName(dpy, hcurs, cursorNames[cshape]);
-#endif /* ! QT_NO_XFIXES */
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qdnd.cpp b/src/gui/kernel/qdnd.cpp
deleted file mode 100644
index 7063828610..0000000000
--- a/src/gui/kernel/qdnd.cpp
+++ /dev/null
@@ -1,491 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qplatformdefs.h"
-
-#include "qbitmap.h"
-#include "qdrag.h"
-#include "qpixmap.h"
-#include "qevent.h"
-#include "qfile.h"
-#include "qtextcodec.h"
-#include "qapplication.h"
-#include "qpoint.h"
-#include "qwidget.h"
-#include "qbuffer.h"
-#include "qimage.h"
-#include "qregexp.h"
-#include "qdir.h"
-#include "qdnd_p.h"
-#include "qimagereader.h"
-#include "qimagewriter.h"
-#include "qdebug.h"
-#include <ctype.h>
-
-#include <private/qapplication_p.h>
-
-#ifndef QT_NO_DRAGANDDROP
-
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_NO_DRAGANDDROP
-
-//#define QDND_DEBUG
-
-#ifdef QDND_DEBUG
-QString dragActionsToString(Qt::DropActions actions)
-{
- QString str;
- if (actions == Qt::IgnoreAction) {
- if (!str.isEmpty())
- str += " | ";
- str += "IgnoreAction";
- }
- if (actions & Qt::LinkAction) {
- if (!str.isEmpty())
- str += " | ";
- str += "LinkAction";
- }
- if (actions & Qt::CopyAction) {
- if (!str.isEmpty())
- str += " | ";
- str += "CopyAction";
- }
- if (actions & Qt::MoveAction) {
- if (!str.isEmpty())
- str += " | ";
- str += "MoveAction";
- }
- if ((actions & Qt::TargetMoveAction) == Qt::TargetMoveAction ) {
- if (!str.isEmpty())
- str += " | ";
- str += "TargetMoveAction";
- }
- return str;
-}
-
-QString KeyboardModifiersToString(Qt::KeyboardModifiers moderfies)
-{
- QString str;
- if (moderfies & Qt::ControlModifier) {
- if (!str.isEmpty())
- str += " | ";
- str += Qt::ControlModifier;
- }
- if (moderfies & Qt::AltModifier) {
- if (!str.isEmpty())
- str += " | ";
- str += Qt::AltModifier;
- }
- if (moderfies & Qt::ShiftModifier) {
- if (!str.isEmpty())
- str += " | ";
- str += Qt::ShiftModifier;
- }
- return str;
-}
-#endif
-
-
-// the universe's only drag manager
-QDragManager *QDragManager::instance = 0;
-
-
-QDragManager::QDragManager()
- : QObject(qApp)
-{
- Q_ASSERT(!instance);
-
-#ifdef Q_WS_QWS
- currentActionForOverrideCursor = Qt::IgnoreAction;
-#endif
- object = 0;
- beingCancelled = false;
- restoreCursor = false;
- willDrop = false;
- eventLoop = 0;
- dropData = new QDropData();
- currentDropTarget = 0;
-#ifdef Q_WS_X11
- xdndMimeTransferedPixmapIndex = 0;
-#endif
-}
-
-
-QDragManager::~QDragManager()
-{
-#ifndef QT_NO_CURSOR
- if (restoreCursor)
- QApplication::restoreOverrideCursor();
-#endif
- instance = 0;
- delete dropData;
-}
-
-QDragManager *QDragManager::self()
-{
- if (!instance && !QApplication::closingDown())
- instance = new QDragManager;
- return instance;
-}
-
-QPixmap QDragManager::dragCursor(Qt::DropAction action) const
-{
- QDragPrivate * d = dragPrivate();
- if (d && d->customCursors.contains(action))
- return d->customCursors[action];
- else if (action == Qt::MoveAction)
- return QApplicationPrivate::instance()->getPixmapCursor(Qt::DragMoveCursor);
- else if (action == Qt::CopyAction)
- return QApplicationPrivate::instance()->getPixmapCursor(Qt::DragCopyCursor);
- else if (action == Qt::LinkAction)
- return QApplicationPrivate::instance()->getPixmapCursor(Qt::DragLinkCursor);
-#ifdef Q_WS_WIN
- else if (action == Qt::IgnoreAction)
- return QApplicationPrivate::instance()->getPixmapCursor(Qt::ForbiddenCursor);
-#endif
- return QPixmap();
-}
-
-bool QDragManager::hasCustomDragCursors() const
-{
- QDragPrivate * d = dragPrivate();
- return d && !d->customCursors.isEmpty();
-}
-
-Qt::DropAction QDragManager::defaultAction(Qt::DropActions possibleActions,
- Qt::KeyboardModifiers modifiers) const
-{
-#ifdef QDND_DEBUG
- qDebug("QDragManager::defaultAction(Qt::DropActions possibleActions)");
- qDebug("keyboard modifiers : %s", KeyboardModifiersToString(modifiers).latin1());
-#endif
-
- QDragPrivate *d = dragPrivate();
- Qt::DropAction defaultAction = d ? d->defaultDropAction : Qt::IgnoreAction;
-
- if (defaultAction == Qt::IgnoreAction) {
- //This means that the drag was initiated by QDrag::start and we need to
- //preserve the old behavior
-#ifdef Q_WS_MAC
- defaultAction = Qt::MoveAction;
-#else
- defaultAction = Qt::CopyAction;
-#endif
- }
-
-#ifdef Q_WS_MAC
- if (modifiers & Qt::ControlModifier && modifiers & Qt::AltModifier)
- defaultAction = Qt::LinkAction;
- else if (modifiers & Qt::AltModifier)
- defaultAction = Qt::CopyAction;
- else if (modifiers & Qt::ControlModifier)
- defaultAction = Qt::MoveAction;
-#else
- if (modifiers & Qt::ControlModifier && modifiers & Qt::ShiftModifier)
- defaultAction = Qt::LinkAction;
- else if (modifiers & Qt::ControlModifier)
- defaultAction = Qt::CopyAction;
- else if (modifiers & Qt::ShiftModifier)
- defaultAction = Qt::MoveAction;
- else if (modifiers & Qt::AltModifier)
- defaultAction = Qt::LinkAction;
-#endif
-
- // if the object is set take the list of possibles from it
- if (object)
- possibleActions = object->d_func()->possible_actions;
-
-#ifdef QDND_DEBUG
- qDebug("possible actions : %s", dragActionsToString(possibleActions).latin1());
-#endif
-
- // Check if the action determined is allowed
- if (!(possibleActions & defaultAction)) {
- if (possibleActions & Qt::CopyAction)
- defaultAction = Qt::CopyAction;
- else if (possibleActions & Qt::MoveAction)
- defaultAction = Qt::MoveAction;
- else if (possibleActions & Qt::LinkAction)
- defaultAction = Qt::LinkAction;
- else
- defaultAction = Qt::IgnoreAction;
- }
-
-#ifdef QDND_DEBUG
- qDebug("default action : %s", dragActionsToString(defaultAction).latin1());
-#endif
-
- return defaultAction;
-}
-
-void QDragManager::setCurrentTarget(QWidget *target, bool dropped)
-{
- if (currentDropTarget == target)
- return;
-
- currentDropTarget = target;
- if (!dropped && object) {
- object->d_func()->target = target;
- emit object->targetChanged(target);
- }
-
-}
-
-QWidget *QDragManager::currentTarget()
-{
- return currentDropTarget;
-}
-
-#endif
-
-QDropData::QDropData()
- : QInternalMimeData()
-{
-}
-
-QDropData::~QDropData()
-{
-}
-#endif // QT_NO_DRAGANDDROP
-
-#if !(defined(QT_NO_DRAGANDDROP) && defined(QT_NO_CLIPBOARD))
-
-static QStringList imageReadMimeFormats()
-{
- QStringList formats;
- QList<QByteArray> imageFormats = QImageReader::supportedImageFormats();
- for (int i = 0; i < imageFormats.size(); ++i) {
- QString format = QLatin1String("image/");
- format += QString::fromLatin1(imageFormats.at(i).toLower());
- formats.append(format);
- }
-
- //put png at the front because it is best
- int pngIndex = formats.indexOf(QLatin1String("image/png"));
- if (pngIndex != -1 && pngIndex != 0)
- formats.move(pngIndex, 0);
-
- return formats;
-}
-
-
-static QStringList imageWriteMimeFormats()
-{
- QStringList formats;
- QList<QByteArray> imageFormats = QImageWriter::supportedImageFormats();
- for (int i = 0; i < imageFormats.size(); ++i) {
- QString format = QLatin1String("image/");
- format += QString::fromLatin1(imageFormats.at(i).toLower());
- formats.append(format);
- }
-
- //put png at the front because it is best
- int pngIndex = formats.indexOf(QLatin1String("image/png"));
- if (pngIndex != -1 && pngIndex != 0)
- formats.move(pngIndex, 0);
-
- return formats;
-}
-
-QInternalMimeData::QInternalMimeData()
- : QMimeData()
-{
-}
-
-QInternalMimeData::~QInternalMimeData()
-{
-}
-
-bool QInternalMimeData::hasFormat(const QString &mimeType) const
-{
- bool foundFormat = hasFormat_sys(mimeType);
- if (!foundFormat && mimeType == QLatin1String("application/x-qt-image")) {
- QStringList imageFormats = imageReadMimeFormats();
- for (int i = 0; i < imageFormats.size(); ++i) {
- if ((foundFormat = hasFormat_sys(imageFormats.at(i))))
- break;
- }
- }
- return foundFormat;
-}
-
-QStringList QInternalMimeData::formats() const
-{
- QStringList realFormats = formats_sys();
- if (!realFormats.contains(QLatin1String("application/x-qt-image"))) {
- QStringList imageFormats = imageReadMimeFormats();
- for (int i = 0; i < imageFormats.size(); ++i) {
- if (realFormats.contains(imageFormats.at(i))) {
- realFormats += QLatin1String("application/x-qt-image");
- break;
- }
- }
- }
- return realFormats;
-}
-
-QVariant QInternalMimeData::retrieveData(const QString &mimeType, QVariant::Type type) const
-{
- QVariant data = retrieveData_sys(mimeType, type);
- if (mimeType == QLatin1String("application/x-qt-image")) {
- if (data.isNull() || (data.type() == QVariant::ByteArray && data.toByteArray().isEmpty())) {
- // try to find an image
- QStringList imageFormats = imageReadMimeFormats();
- for (int i = 0; i < imageFormats.size(); ++i) {
- data = retrieveData_sys(imageFormats.at(i), type);
- if (data.isNull() || (data.type() == QVariant::ByteArray && data.toByteArray().isEmpty()))
- continue;
- break;
- }
- }
- // we wanted some image type, but all we got was a byte array. Convert it to an image.
- if (data.type() == QVariant::ByteArray
- && (type == QVariant::Image || type == QVariant::Pixmap || type == QVariant::Bitmap))
- data = QImage::fromData(data.toByteArray());
-
- } else if (mimeType == QLatin1String("application/x-color") && data.type() == QVariant::ByteArray) {
- QColor c;
- QByteArray ba = data.toByteArray();
- if (ba.size() == 8) {
- ushort * colBuf = (ushort *)ba.data();
- c.setRgbF(qreal(colBuf[0]) / qreal(0xFFFF),
- qreal(colBuf[1]) / qreal(0xFFFF),
- qreal(colBuf[2]) / qreal(0xFFFF),
- qreal(colBuf[3]) / qreal(0xFFFF));
- data = c;
- } else {
- qWarning("Qt: Invalid color format");
- }
- } else if (data.type() != type && data.type() == QVariant::ByteArray) {
- // try to use mime data's internal conversion stuf.
- QInternalMimeData *that = const_cast<QInternalMimeData *>(this);
- that->setData(mimeType, data.toByteArray());
- data = QMimeData::retrieveData(mimeType, type);
- that->clear();
- }
- return data;
-}
-
-bool QInternalMimeData::canReadData(const QString &mimeType)
-{
- return imageReadMimeFormats().contains(mimeType);
-}
-
-// helper functions for rendering mimedata to the system, this is needed because QMimeData is in core.
-QStringList QInternalMimeData::formatsHelper(const QMimeData *data)
-{
- QStringList realFormats = data->formats();
- if (realFormats.contains(QLatin1String("application/x-qt-image"))) {
- // add all supported image formats
- QStringList imageFormats = imageWriteMimeFormats();
- for (int i = 0; i < imageFormats.size(); ++i) {
- if (!realFormats.contains(imageFormats.at(i)))
- realFormats.append(imageFormats.at(i));
- }
- }
- return realFormats;
-}
-
-bool QInternalMimeData::hasFormatHelper(const QString &mimeType, const QMimeData *data)
-{
-
- bool foundFormat = data->hasFormat(mimeType);
- if (!foundFormat) {
- if (mimeType == QLatin1String("application/x-qt-image")) {
- // check all supported image formats
- QStringList imageFormats = imageWriteMimeFormats();
- for (int i = 0; i < imageFormats.size(); ++i) {
- if ((foundFormat = data->hasFormat(imageFormats.at(i))))
- break;
- }
- } else if (mimeType.startsWith(QLatin1String("image/"))) {
- return data->hasImage() && imageWriteMimeFormats().contains(mimeType);
- }
- }
- return foundFormat;
-}
-
-QByteArray QInternalMimeData::renderDataHelper(const QString &mimeType, const QMimeData *data)
-{
- QByteArray ba;
- if (mimeType == QLatin1String("application/x-color")) {
- /* QMimeData can only provide colors as QColor or the name
- of a color as a QByteArray or a QString. So we need to do
- the conversion to application/x-color here.
- The application/x-color format is :
- type: application/x-color
- format: 16
- data[0]: red
- data[1]: green
- data[2]: blue
- data[3]: opacity
- */
- ba.resize(8);
- ushort * colBuf = (ushort *)ba.data();
- QColor c = qvariant_cast<QColor>(data->colorData());
- colBuf[0] = ushort(c.redF() * 0xFFFF);
- colBuf[1] = ushort(c.greenF() * 0xFFFF);
- colBuf[2] = ushort(c.blueF() * 0xFFFF);
- colBuf[3] = ushort(c.alphaF() * 0xFFFF);
- } else {
- ba = data->data(mimeType);
- if (ba.isEmpty()) {
- if (mimeType == QLatin1String("application/x-qt-image") && data->hasImage()) {
- QImage image = qvariant_cast<QImage>(data->imageData());
- QBuffer buf(&ba);
- buf.open(QBuffer::WriteOnly);
- // would there not be PNG ??
- image.save(&buf, "PNG");
- } else if (mimeType.startsWith(QLatin1String("image/")) && data->hasImage()) {
- QImage image = qvariant_cast<QImage>(data->imageData());
- QBuffer buf(&ba);
- buf.open(QBuffer::WriteOnly);
- image.save(&buf, mimeType.mid(mimeType.indexOf(QLatin1Char('/')) + 1).toLatin1().toUpper());
- }
- }
- }
- return ba;
-}
-
-#endif // QT_NO_DRAGANDDROP && QT_NO_CLIPBOARD
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qdnd_mac.mm b/src/gui/kernel/qdnd_mac.mm
deleted file mode 100644
index 3af2ba007c..0000000000
--- a/src/gui/kernel/qdnd_mac.mm
+++ /dev/null
@@ -1,753 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qapplication.h"
-#ifndef QT_NO_DRAGANDDROP
-#include "qbitmap.h"
-#include "qcursor.h"
-#include "qevent.h"
-#include "qpainter.h"
-#include "qurl.h"
-#include "qwidget.h"
-#include "qfile.h"
-#include "qfileinfo.h"
-#include <stdlib.h>
-#include <string.h>
-#ifndef QT_NO_ACCESSIBILITY
-# include "qaccessible.h"
-#endif
-
-#include <private/qapplication_p.h>
-#include <private/qwidget_p.h>
-#include <private/qdnd_p.h>
-#include <private/qt_mac_p.h>
-
-QT_BEGIN_NAMESPACE
-
-QT_USE_NAMESPACE
-
-QMacDndAnswerRecord qt_mac_dnd_answer_rec;
-
-/*****************************************************************************
- QDnD debug facilities
- *****************************************************************************/
-//#define DEBUG_DRAG_EVENTS
-//#define DEBUG_DRAG_PROMISES
-
-/*****************************************************************************
- QDnD globals
- *****************************************************************************/
-bool qt_mac_in_drag = false;
-#ifndef QT_MAC_USE_COCOA
-static DragReference qt_mac_current_dragRef = 0;
-#endif
-
-/*****************************************************************************
- Externals
- *****************************************************************************/
-extern void qt_mac_send_modifiers_changed(quint32, QObject *); //qapplication_mac.cpp
-extern uint qGlobalPostedEventsCount(); //qapplication.cpp
-extern RgnHandle qt_mac_get_rgn(); // qregion_mac.cpp
-extern void qt_mac_dispose_rgn(RgnHandle); // qregion_mac.cpp
-/*****************************************************************************
- QDnD utility functions
- *****************************************************************************/
-
-//default pixmap
-static const int default_pm_hotx = -2;
-static const int default_pm_hoty = -16;
-#ifndef QT_MAC_USE_COCOA
-static const char * const default_pm[] = {
- "13 9 3 1",
- ". c None",
- " c #000000",
- "X c #FFFFFF",
- "X X X X X X X",
- " X X X X X X ",
- "X ......... X",
- " X.........X ",
- "X ......... X",
- " X.........X ",
- "X ......... X",
- " X X X X X X ",
- "X X X X X X X",
-};
-#endif
-
-//action management
-#ifdef DEBUG_DRAG_EVENTS
-# define MAP_MAC_ENUM(x) x, #x
-#else
-# define MAP_MAC_ENUM(x) x
-#endif
-struct mac_enum_mapper
-{
- int mac_code;
- int qt_code;
-#ifdef DEBUG_DRAG_EVENTS
- char *qt_desc;
-#endif
-};
-#ifndef QT_MAC_USE_COCOA
-static mac_enum_mapper dnd_action_symbols[] = {
- { kDragActionAlias, MAP_MAC_ENUM(Qt::LinkAction) },
- { kDragActionMove, MAP_MAC_ENUM(Qt::MoveAction) },
- { kDragActionGeneric, MAP_MAC_ENUM(Qt::CopyAction) },
- { kDragActionCopy, MAP_MAC_ENUM(Qt::CopyAction) },
- { 0, MAP_MAC_ENUM(0) }
-};
-static DragActions qt_mac_dnd_map_qt_actions(Qt::DropActions qActions)
-{
- DragActions ret = kDragActionNothing;
- for(int i = 0; dnd_action_symbols[i].qt_code; ++i) {
- if(qActions & dnd_action_symbols[i].qt_code)
- ret |= dnd_action_symbols[i].mac_code;
- }
- return ret;
-}
-static Qt::DropActions qt_mac_dnd_map_mac_actions(DragActions macActions)
-{
-#ifdef DEBUG_DRAG_EVENTS
- qDebug("Converting DND ActionList: 0x%lx", macActions);
-#endif
- Qt::DropActions ret = Qt::IgnoreAction;
- for(int i = 0; dnd_action_symbols[i].qt_code; ++i) {
-#ifdef DEBUG_DRAG_EVENTS
- qDebug(" %d) [%s] : %s", i, dnd_action_symbols[i].qt_desc,
- (macActions & dnd_action_symbols[i].mac_code) ? "true" : "false");
-#endif
- if(macActions & dnd_action_symbols[i].mac_code)
- ret |= Qt::DropAction(dnd_action_symbols[i].qt_code);
- }
- return ret;
-}
-static Qt::DropAction qt_mac_dnd_map_mac_default_action(DragActions macActions)
-{
- static Qt::DropAction preferred_actions[] = { Qt::CopyAction, Qt::LinkAction, //in order
- Qt::MoveAction, Qt::IgnoreAction };
- Qt::DropAction ret = Qt::IgnoreAction;
- const Qt::DropActions qtActions = qt_mac_dnd_map_mac_actions(macActions);
- for(int i = 0; preferred_actions[i] != Qt::IgnoreAction; ++i) {
- if(qtActions & preferred_actions[i]) {
- ret = preferred_actions[i];
- break;
- }
- }
-#ifdef DEBUG_DRAG_EVENTS
- for(int i = 0; dnd_action_symbols[i].qt_code; ++i) {
- if(dnd_action_symbols[i].qt_code == ret) {
- qDebug("Got default action: %s [0x%lx]", dnd_action_symbols[i].qt_desc, macActions);
- break;
- }
- }
-#endif
- return ret;
-}
-static void qt_mac_dnd_update_action(DragReference dragRef) {
- SInt16 modifiers;
- GetDragModifiers(dragRef, &modifiers, 0, 0);
- qt_mac_send_modifiers_changed(modifiers, qApp);
-
- Qt::DropAction qtAction = Qt::IgnoreAction;
- {
- DragActions macAllowed = kDragActionNothing;
- GetDragDropAction(dragRef, &macAllowed);
- Qt::DropActions qtAllowed = qt_mac_dnd_map_mac_actions(macAllowed);
- qtAction = QDragManager::self()->defaultAction(qtAllowed, QApplication::keyboardModifiers());
-#if 1
- if(!(qtAllowed & qtAction))
- qtAction = qt_mac_dnd_map_mac_default_action(macAllowed);
-#endif
- }
- DragActions macAction = qt_mac_dnd_map_qt_actions(qtAction);
-
- DragActions currentActions;
- GetDragDropAction(dragRef, &currentActions);
- if(currentActions != macAction) {
- SetDragDropAction(dragRef, macAction);
- QDragManager::self()->emitActionChanged(qtAction);
- }
-}
-#endif // !QT_MAC_USE_COCOA
-
-/*****************************************************************************
- DnD functions
- *****************************************************************************/
-bool QDropData::hasFormat_sys(const QString &mime) const
-{
-#ifndef QT_MAC_USE_COCOA
- OSPasteboardRef board;
- if(GetDragPasteboard(qt_mac_current_dragRef, &board) != noErr) {
- qDebug("DnD: Cannot get PasteBoard!");
- return false;
- }
- return QMacPasteboard(board, QMacPasteboardMime::MIME_DND).hasFormat(mime);
-#else
- Q_UNUSED(mime);
- return false;
-#endif // !QT_MAC_USE_COCOA
-}
-
-QVariant QDropData::retrieveData_sys(const QString &mime, QVariant::Type type) const
-{
-#ifndef QT_MAC_USE_COCOA
- OSPasteboardRef board;
- if(GetDragPasteboard(qt_mac_current_dragRef, &board) != noErr) {
- qDebug("DnD: Cannot get PasteBoard!");
- return QVariant();
- }
- return QMacPasteboard(board, QMacPasteboardMime::MIME_DND).retrieveData(mime, type);
-#else
- Q_UNUSED(mime);
- Q_UNUSED(type);
- return QVariant();
-#endif // !QT_MAC_USE_COCOA
-}
-
-QStringList QDropData::formats_sys() const
-{
-#ifndef QT_MAC_USE_COCOA
- OSPasteboardRef board;
- if(GetDragPasteboard(qt_mac_current_dragRef, &board) != noErr) {
- qDebug("DnD: Cannot get PasteBoard!");
- return QStringList();
- }
- return QMacPasteboard(board, QMacPasteboardMime::MIME_DND).formats();
-#else
- return QStringList();
-#endif
-}
-
-void QDragManager::timerEvent(QTimerEvent*)
-{
-}
-
-bool QDragManager::eventFilter(QObject *, QEvent *)
-{
- return false;
-}
-
-void QDragManager::updateCursor()
-{
-}
-
-void QDragManager::cancel(bool)
-{
- if(object) {
- beingCancelled = true;
- object = 0;
- }
-#ifndef QT_NO_ACCESSIBILITY
- QAccessible::updateAccessibility(this, 0, QAccessible::DragDropEnd);
-#endif
-}
-
-void QDragManager::move(const QPoint &)
-{
-}
-
-void QDragManager::drop()
-{
-}
-
-/**
- If a drop action is already set on the carbon event
- (from e.g. an earlier enter event), we insert the same
- action on the new Qt event that has yet to be sendt.
-*/
-static inline bool qt_mac_set_existing_drop_action(const DragRef &dragRef, QDropEvent &event)
-{
-#ifndef QT_MAC_USE_COCOA
- DragActions currentAction = kDragActionNothing;
- OSStatus err = GetDragDropAction(dragRef, &currentAction);
- if (err == noErr && currentAction != kDragActionNothing) {
- // This looks a bit evil, but we only ever set one action, so it's OK.
- event.setDropAction(Qt::DropAction(int(qt_mac_dnd_map_mac_actions(currentAction))));
- return true;
- }
-#else
- Q_UNUSED(dragRef);
- Q_UNUSED(event);
-#endif
- return false;
-}
-
-/**
- If an answer rect has been set on the event (after being sent
- to the global event processor), we store that rect so we can
- check if the mouse is in the same area upon next drag move event.
-*/
-void qt_mac_copy_answer_rect(const QDragMoveEvent &event)
-{
- if (!event.answerRect().isEmpty()) {
- qt_mac_dnd_answer_rec.rect = event.answerRect();
- qt_mac_dnd_answer_rec.buttons = event.mouseButtons();
- qt_mac_dnd_answer_rec.modifiers = event.keyboardModifiers();
- qt_mac_dnd_answer_rec.lastAction = event.dropAction();
- }
-}
-
-bool qt_mac_mouse_inside_answer_rect(QPoint mouse)
-{
- if (!qt_mac_dnd_answer_rec.rect.isEmpty()
- && qt_mac_dnd_answer_rec.rect.contains(mouse)
- && QApplication::mouseButtons() == qt_mac_dnd_answer_rec.buttons
- && QApplication::keyboardModifiers() == qt_mac_dnd_answer_rec.modifiers)
- return true;
- else
- return false;
-}
-
-bool QWidgetPrivate::qt_mac_dnd_event(uint kind, DragRef dragRef)
-{
-#ifndef QT_MAC_USE_COCOA
- Q_Q(QWidget);
- qt_mac_current_dragRef = dragRef;
- if (kind != kEventControlDragLeave)
- qt_mac_dnd_update_action(dragRef);
-
- Point mouse;
- GetDragMouse(dragRef, &mouse, 0L);
- if(!mouse.h && !mouse.v)
- GetGlobalMouse(&mouse);
-
- if(QApplicationPrivate::modalState()) {
- for(QWidget *modal = q; modal; modal = modal->parentWidget()) {
- if(modal->isWindow()) {
- if(modal != QApplication::activeModalWidget())
- return noErr;
- break;
- }
- }
- }
-
- //lookup the possible actions
- DragActions allowed = kDragActionNothing;
- GetDragAllowableActions(dragRef, &allowed);
- Qt::DropActions qtAllowed = qt_mac_dnd_map_mac_actions(allowed);
-
- //lookup the source dragAccepted
- QMimeData *dropdata = QDragManager::self()->dropData;
- if(QDragManager::self()->source())
- dropdata = QDragManager::self()->dragPrivate()->data;
-
- // 'interrestedInDrag' should end up being 'true' if a later drop
- // will be accepted by the widget for the current mouse position
- bool interrestedInDrag = true;
-
- //Dispatch events
- if (kind == kEventControlDragWithin) {
- if (qt_mac_mouse_inside_answer_rect(q->mapFromGlobal(QPoint(mouse.h, mouse.v))))
- return qt_mac_dnd_answer_rec.lastAction == Qt::IgnoreAction;
- else
- qt_mac_dnd_answer_rec.clear();
-
- QDragMoveEvent qDMEvent(q->mapFromGlobal(QPoint(mouse.h, mouse.v)), qtAllowed, dropdata,
- QApplication::mouseButtons(), QApplication::keyboardModifiers());
-
- // Accept the event by default if a
- // drag action exists on the carbon event
- if (qt_mac_set_existing_drop_action(dragRef, qDMEvent))
- qDMEvent.accept();
-
- QApplication::sendEvent(q, &qDMEvent);
- if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction)
- interrestedInDrag = false;
-
- qt_mac_copy_answer_rect(qDMEvent);
- SetDragDropAction(dragRef, qt_mac_dnd_map_qt_actions(qDMEvent.dropAction()));
-
- } else if (kind == kEventControlDragEnter) {
- qt_mac_dnd_answer_rec.clear();
-
- QDragEnterEvent qDEEvent(q->mapFromGlobal(QPoint(mouse.h, mouse.v)), qtAllowed, dropdata,
- QApplication::mouseButtons(), QApplication::keyboardModifiers());
- qt_mac_set_existing_drop_action(dragRef, qDEEvent);
- QApplication::sendEvent(q, &qDEEvent);
- SetDragDropAction(dragRef, qt_mac_dnd_map_qt_actions(qDEEvent.dropAction()));
-
- if (!qDEEvent.isAccepted())
- // The widget is simply not interested in this
- // drag. So tell carbon this by returning 'false'. We will then
- // not receive any further move, drop or leave events for this widget.
- return false;
- else {
- // Documentation states that a drag move event is sent immediately after
- // a drag enter event. So we do that. This will honor widgets overriding
- // 'dragMoveEvent' only, and not 'dragEnterEvent'
- QDragMoveEvent qDMEvent(q->mapFromGlobal(QPoint(mouse.h, mouse.v)), qtAllowed, dropdata,
- QApplication::mouseButtons(), QApplication::keyboardModifiers());
- qDMEvent.accept(); // accept by default, since enter event was accepted.
- qDMEvent.setDropAction(qDEEvent.dropAction());
- QApplication::sendEvent(q, &qDMEvent);
- if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction)
- interrestedInDrag = false;
-
- qt_mac_copy_answer_rect(qDMEvent);
- SetDragDropAction(dragRef, qt_mac_dnd_map_qt_actions(qDMEvent.dropAction()));
- }
-
- } else if(kind == kEventControlDragLeave) {
- QDragLeaveEvent de;
- QApplication::sendEvent(q, &de);
- } else if(kind == kEventControlDragReceive) {
- QDropEvent de(q->mapFromGlobal(QPoint(mouse.h, mouse.v)), qtAllowed, dropdata,
- QApplication::mouseButtons(), QApplication::keyboardModifiers());
- if(QDragManager::self()->object)
- QDragManager::self()->dragPrivate()->target = q;
- QApplication::sendEvent(q, &de);
- if(!de.isAccepted()) {
- interrestedInDrag = false;
- SetDragDropAction(dragRef, kDragActionNothing);
- } else {
- if(QDragManager::self()->object)
- QDragManager::self()->dragPrivate()->executed_action = de.dropAction();
- SetDragDropAction(dragRef, qt_mac_dnd_map_qt_actions(de.dropAction()));
- }
- }
-
-#ifdef DEBUG_DRAG_EVENTS
- {
- const char *desc = 0;
- switch(kind) {
- case kEventControlDragWithin: desc = "DragMove"; break;
- case kEventControlDragEnter: desc = "DragEnter"; break;
- case kEventControlDragLeave: desc = "DragLeave"; break;
- case kEventControlDragReceive: desc = "DragDrop"; break;
- }
- if(desc) {
- QPoint pos(q->mapFromGlobal(QPoint(mouse.h, mouse.v)));
- qDebug("Sending <%s>(%d, %d) event to %p(%s::%s) [%d] (%p)",
- desc, pos.x(), pos.y(), q, q->metaObject()->className(),
- q->objectName().toLocal8Bit().constData(), ret, dragRef);
- }
- }
-#endif
-
- //set the cursor
- bool found_cursor = false;
- if(kind == kEventControlDragWithin || kind == kEventControlDragEnter) {
- ThemeCursor cursor = kThemeNotAllowedCursor;
- found_cursor = true;
- if (interrestedInDrag) {
- DragActions action = kDragActionNothing;
- GetDragDropAction(dragRef, &action);
- switch(qt_mac_dnd_map_mac_default_action(action)) {
- case Qt::IgnoreAction:
- cursor = kThemeNotAllowedCursor;
- break;
- case Qt::MoveAction:
- cursor = kThemeArrowCursor;
- break;
- case Qt::CopyAction:
- cursor = kThemeCopyArrowCursor;
- break;
- case Qt::LinkAction:
- cursor = kThemeAliasArrowCursor;
- break;
- default:
- cursor = kThemeNotAllowedCursor;
- break;
- }
- }
- SetThemeCursor(cursor);
- }
- if(found_cursor) {
- qt_mac_set_cursor(0); //just use our's
- } else {
- QCursor cursor(Qt::ArrowCursor);
- if(qApp && qApp->overrideCursor()) {
- cursor = *qApp->overrideCursor();
- } else if(q) {
- for(QWidget *p = q; p; p = p->parentWidget()) {
- if(p->isEnabled() && p->testAttribute(Qt::WA_SetCursor)) {
- cursor = p->cursor();
- break;
- }
- }
- }
- qt_mac_set_cursor(&cursor);
- }
-
- //idle things
- if(qGlobalPostedEventsCount()) {
- QApplication::sendPostedEvents();
- QApplication::flush();
- }
-
- // If this was not a drop, tell carbon that we will be interresed in receiving more
- // events for the current drag. We do that by returning true.
- if (kind == kEventControlDragReceive)
- return interrestedInDrag;
- else
- return true;
-#else
- Q_UNUSED(kind);
- Q_UNUSED(dragRef);
- return false;
-#endif // !QT_MAC_USE_COCOA
-}
-
-#ifndef QT_MAC_USE_COCOA
-Qt::DropAction QDragManager::drag(QDrag *o)
-{
-
- if(qt_mac_in_drag) { //just make sure..
- qWarning("Qt: Internal error: WH0A, unexpected condition reached");
- return Qt::IgnoreAction;
- }
- if(object == o)
- return Qt::IgnoreAction;
- /* At the moment it seems clear that Mac OS X does not want to drag with a non-left button
- so we just bail early to prevent it */
- if(!(GetCurrentEventButtonState() & kEventMouseButtonPrimary))
- return Qt::IgnoreAction;
-
- if(object) {
- dragPrivate()->source->removeEventFilter(this);
- cancel();
- beingCancelled = false;
- }
-
- object = o;
- dragPrivate()->target = 0;
-
-#ifndef QT_NO_ACCESSIBILITY
- QAccessible::updateAccessibility(this, 0, QAccessible::DragDropStart);
-#endif
-
- //setup the data
- QMacPasteboard dragBoard(QMacPasteboardMime::MIME_DND);
- dragBoard.setMimeData(dragPrivate()->data);
-
- //create the drag
- OSErr result;
- DragRef dragRef;
- if((result = NewDragWithPasteboard(dragBoard.pasteBoard(), &dragRef)))
- return Qt::IgnoreAction;
- //setup the actions
- DragActions possibleActions = qt_mac_dnd_map_qt_actions(dragPrivate()->possible_actions);
- SetDragAllowableActions(dragRef, //local
- possibleActions,
- true);
- SetDragAllowableActions(dragRef, //remote (same as local)
- possibleActions,
- false);
-
-
- QPoint hotspot;
- QPixmap pix = dragPrivate()->pixmap;
- if(pix.isNull()) {
- if(dragPrivate()->data->hasText() || dragPrivate()->data->hasUrls()) {
- //get the string
- QString s = dragPrivate()->data->hasText() ? dragPrivate()->data->text()
- : dragPrivate()->data->urls().first().toString();
- if(s.length() > 26)
- s = s.left(23) + QChar(0x2026);
- if(!s.isEmpty()) {
- //draw it
- QFont f(qApp->font());
- f.setPointSize(12);
- QFontMetrics fm(f);
- const int width = fm.width(s);
- const int height = fm.height();
- if(width > 0 && height > 0) {
- QPixmap tmp(width, height);
- QPainter p(&tmp);
- p.fillRect(0, 0, tmp.width(), tmp.height(), Qt::color0);
- p.setPen(Qt::color1);
- p.setFont(f);
- p.drawText(0, fm.ascent(), s);
- p.end();
- //save it
- pix = tmp;
- hotspot = QPoint(tmp.width() / 2, tmp.height() / 2);
- }
- }
- } else {
- pix = QPixmap(default_pm);
- hotspot = QPoint(default_pm_hotx, default_pm_hoty);
- }
- } else {
- hotspot = dragPrivate()->hotspot;
- }
-
- //so we must fake an event
- EventRecord fakeEvent;
- GetGlobalMouse(&(fakeEvent.where));
- fakeEvent.message = 0;
- fakeEvent.what = mouseDown;
- fakeEvent.when = EventTimeToTicks(GetCurrentEventTime());
- fakeEvent.modifiers = GetCurrentKeyModifiers();
- if(GetCurrentEventButtonState() & 2)
- fakeEvent.modifiers |= controlKey;
-
- //find the hotspot in relation to the pixmap
- Point boundsPoint;
- boundsPoint.h = fakeEvent.where.h - hotspot.x();
- boundsPoint.v = fakeEvent.where.v - hotspot.y();
- Rect boundsRect;
- SetRect(&boundsRect, boundsPoint.h, boundsPoint.v, boundsPoint.h + pix.width(), boundsPoint.v + pix.height());
-
- //set the drag image
- QRegion dragRegion(boundsPoint.h, boundsPoint.v, pix.width(), pix.height()), pixRegion;
- if(!pix.isNull()) {
- HIPoint hipoint = { -hotspot.x(), -hotspot.y() };
- CGImageRef img = (CGImageRef)pix.macCGHandle();
- SetDragImageWithCGImage(dragRef, img, &hipoint, 0);
- CGImageRelease(img);
- }
-
- SetDragItemBounds(dragRef, (ItemReference)1 , &boundsRect);
- { //do the drag
- qt_mac_in_drag = true;
- qt_mac_dnd_update_action(dragRef);
- result = TrackDrag(dragRef, &fakeEvent, QMacSmartQuickDrawRegion(dragRegion.toQDRgn()));
- qt_mac_in_drag = false;
- }
- object = 0;
- if(result == noErr) {
- // Check if the receiver points us to
- // a file location. If so, we need to do
- // the file copy/move ourselves:
- QCFType<CFURLRef> pasteLocation = 0;
- PasteboardCopyPasteLocation(dragBoard.pasteBoard(), &pasteLocation);
- if (pasteLocation){
- Qt::DropAction action = o->d_func()->defaultDropAction;
- if (action == Qt::IgnoreAction){
- if (o->d_func()->possible_actions & Qt::MoveAction)
- action = Qt::MoveAction;
- else if (o->d_func()->possible_actions & Qt::CopyAction)
- action = Qt::CopyAction;
-
- }
- bool atleastOne = false;
- QList<QUrl> urls = o->mimeData()->urls();
- for (int i = 0; i < urls.size(); ++i){
- QUrl fromUrl = urls.at(i);
- QString filename = QFileInfo(fromUrl.path()).fileName();
- QUrl toUrl(QCFString::toQString(CFURLGetString(pasteLocation)) + filename);
- if (action == Qt::MoveAction){
- if (QFile::rename(fromUrl.path(), toUrl.path()))
- atleastOne = true;
- } else if (action == Qt::CopyAction){
- if (QFile::copy(fromUrl.path(), toUrl.path()))
- atleastOne = true;
- }
- }
- if (atleastOne){
- DisposeDrag(dragRef);
- o->setMimeData(0);
- o->deleteLater();
- return action;
- }
- }
-
- DragActions ret = kDragActionNothing;
- GetDragDropAction(dragRef, &ret);
- DisposeDrag(dragRef); //cleanup
- o->setMimeData(0);
- o->deleteLater();
- return qt_mac_dnd_map_mac_default_action(ret);
- }
- DisposeDrag(dragRef); //cleanup
- return Qt::IgnoreAction;
-}
-#endif
-
-void QDragManager::updatePixmap()
-{
-}
-
-QCocoaDropData::QCocoaDropData(CFStringRef pasteboard)
- : QInternalMimeData()
-{
- NSString* pasteboardName = (NSString*)pasteboard;
- [pasteboardName retain];
- dropPasteboard = pasteboard;
-}
-
-QCocoaDropData::~QCocoaDropData()
-{
- NSString* pasteboardName = (NSString*)dropPasteboard;
- [pasteboardName release];
-}
-
-QStringList QCocoaDropData::formats_sys() const
-{
- QStringList formats;
- OSPasteboardRef board;
- if (PasteboardCreate(dropPasteboard, &board) != noErr) {
- qDebug("DnD: Cannot get PasteBoard!");
- return formats;
- }
- formats = QMacPasteboard(board, QMacPasteboardMime::MIME_DND).formats();
- return formats;
-}
-
-QVariant QCocoaDropData::retrieveData_sys(const QString &mimeType, QVariant::Type type) const
-{
- QVariant data;
- OSPasteboardRef board;
- if (PasteboardCreate(dropPasteboard, &board) != noErr) {
- qDebug("DnD: Cannot get PasteBoard!");
- return data;
- }
- data = QMacPasteboard(board, QMacPasteboardMime::MIME_DND).retrieveData(mimeType, type);
- CFRelease(board);
- return data;
-}
-
-bool QCocoaDropData::hasFormat_sys(const QString &mimeType) const
-{
- bool has = false;
- OSPasteboardRef board;
- if (PasteboardCreate(dropPasteboard, &board) != noErr) {
- qDebug("DnD: Cannot get PasteBoard!");
- return has;
- }
- has = QMacPasteboard(board, QMacPasteboardMime::MIME_DND).hasFormat(mimeType);
- CFRelease(board);
- return has;
-}
-
-#endif // QT_NO_DRAGANDDROP
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qdnd_p.h b/src/gui/kernel/qdnd_p.h
deleted file mode 100644
index 754366637c..0000000000
--- a/src/gui/kernel/qdnd_p.h
+++ /dev/null
@@ -1,336 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDND_P_H
-#define QDND_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "QtCore/qobject.h"
-#include "QtCore/qmap.h"
-#include "QtGui/qmime.h"
-#include "QtGui/qdrag.h"
-#include "QtGui/qpixmap.h"
-#include "QtGui/qcursor.h"
-#include "QtCore/qpoint.h"
-#include "private/qobject_p.h"
-#ifdef Q_WS_MAC
-# include "private/qt_mac_p.h"
-#endif
-
-#if defined(Q_WS_WIN)
-# include <qt_windows.h>
-# include <objidl.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-class QEventLoop;
-
-#if !(defined(QT_NO_DRAGANDDROP) && defined(QT_NO_CLIPBOARD))
-
-class Q_GUI_EXPORT QInternalMimeData : public QMimeData
-{
- Q_OBJECT
-public:
- QInternalMimeData();
- ~QInternalMimeData();
-
- bool hasFormat(const QString &mimeType) const;
- QStringList formats() const;
- static bool canReadData(const QString &mimeType);
-
-
- static QStringList formatsHelper(const QMimeData *data);
- static bool hasFormatHelper(const QString &mimeType, const QMimeData *data);
- static QByteArray renderDataHelper(const QString &mimeType, const QMimeData *data);
-
-protected:
- QVariant retrieveData(const QString &mimeType, QVariant::Type type) const;
-
- virtual bool hasFormat_sys(const QString &mimeType) const = 0;
- virtual QStringList formats_sys() const = 0;
- virtual QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const = 0;
-};
-
-#ifdef Q_WS_WIN
-class QOleDataObject : public IDataObject
-{
-public:
- explicit QOleDataObject(QMimeData *mimeData);
- virtual ~QOleDataObject();
-
- void releaseQt();
- const QMimeData *mimeData() const;
- DWORD reportedPerformedEffect() const;
-
- // IUnknown methods
- STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppvObj);
- STDMETHOD_(ULONG,AddRef)(void);
- STDMETHOD_(ULONG,Release)(void);
-
- // IDataObject methods
- STDMETHOD(GetData)(LPFORMATETC pformatetcIn, LPSTGMEDIUM pmedium);
- STDMETHOD(GetDataHere)(LPFORMATETC pformatetc, LPSTGMEDIUM pmedium);
- STDMETHOD(QueryGetData)(LPFORMATETC pformatetc);
- STDMETHOD(GetCanonicalFormatEtc)(LPFORMATETC pformatetc, LPFORMATETC pformatetcOut);
- STDMETHOD(SetData)(LPFORMATETC pformatetc, STGMEDIUM FAR * pmedium,
- BOOL fRelease);
- STDMETHOD(EnumFormatEtc)(DWORD dwDirection, LPENUMFORMATETC FAR* ppenumFormatEtc);
- STDMETHOD(DAdvise)(FORMATETC FAR* pFormatetc, DWORD advf,
- LPADVISESINK pAdvSink, DWORD FAR* pdwConnection);
- STDMETHOD(DUnadvise)(DWORD dwConnection);
- STDMETHOD(EnumDAdvise)(LPENUMSTATDATA FAR* ppenumAdvise);
-
-private:
- ULONG m_refs;
- QPointer<QMimeData> data;
- int CF_PERFORMEDDROPEFFECT;
- DWORD performedEffect;
-};
-
-class QOleEnumFmtEtc : public IEnumFORMATETC
-{
-public:
- explicit QOleEnumFmtEtc(const QVector<FORMATETC> &fmtetcs);
- explicit QOleEnumFmtEtc(const QVector<LPFORMATETC> &lpfmtetcs);
- virtual ~QOleEnumFmtEtc();
-
- bool isNull() const;
-
- // IUnknown methods
- STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppvObj);
- STDMETHOD_(ULONG,AddRef)(void);
- STDMETHOD_(ULONG,Release)(void);
-
- // IEnumFORMATETC methods
- STDMETHOD(Next)(ULONG celt, LPFORMATETC rgelt, ULONG FAR* pceltFetched);
- STDMETHOD(Skip)(ULONG celt);
- STDMETHOD(Reset)(void);
- STDMETHOD(Clone)(LPENUMFORMATETC FAR* newEnum);
-
-private:
- bool copyFormatEtc(LPFORMATETC dest, LPFORMATETC src) const;
-
- ULONG m_dwRefs;
- ULONG m_nIndex;
- QVector<LPFORMATETC> m_lpfmtetcs;
- bool m_isNull;
-};
-
-#endif
-
-#endif //QT_NO_DRAGANDDROP && QT_NO_CLIPBOARD
-
-#ifndef QT_NO_DRAGANDDROP
-
-class QDragPrivate : public QObjectPrivate
-{
-public:
- QWidget *source;
- QWidget *target;
- QMimeData *data;
- QPixmap pixmap;
- QPoint hotspot;
- Qt::DropActions possible_actions;
- Qt::DropAction executed_action;
- QMap<Qt::DropAction, QPixmap> customCursors;
- Qt::DropAction defaultDropAction;
-};
-
-class QDropData : public QInternalMimeData
-{
- Q_OBJECT
-public:
- QDropData();
- ~QDropData();
-
-protected:
- bool hasFormat_sys(const QString &mimeType) const;
- QStringList formats_sys() const;
- QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const;
-
-#if defined(Q_WS_WIN)
-public:
- LPDATAOBJECT currentDataObject;
-#endif
-};
-
-class QDragManager: public QObject {
- Q_OBJECT
-
- QDragManager();
- ~QDragManager();
- // only friend classes can use QDragManager.
- friend class QDrag;
- friend class QDragMoveEvent;
- friend class QDropEvent;
- friend class QApplication;
-#ifdef Q_WS_MAC
- friend class QWidgetPrivate; //dnd is implemented here
-#endif
-
- bool eventFilter(QObject *, QEvent *);
- void timerEvent(QTimerEvent*);
-
-public:
- Qt::DropAction drag(QDrag *);
-
- void cancel(bool deleteSource = true);
- void move(const QPoint &);
- void drop();
- void updatePixmap();
- QWidget *source() const { return object ? object->d_func()->source : 0; }
- QDragPrivate *dragPrivate() const { return object ? object->d_func() : 0; }
- static QDragPrivate *dragPrivate(QDrag *drag) { return drag ? drag->d_func() : 0; }
-
- static QDragManager *self();
- Qt::DropAction defaultAction(Qt::DropActions possibleActions,
- Qt::KeyboardModifiers modifiers) const;
-
- QDrag *object;
-
- void updateCursor();
-
- bool beingCancelled;
- bool restoreCursor;
- bool willDrop;
- QEventLoop *eventLoop;
-
- QPixmap dragCursor(Qt::DropAction action) const;
-
- bool hasCustomDragCursors() const;
-
- QDropData *dropData;
-
- void emitActionChanged(Qt::DropAction newAction) { if (object) emit object->actionChanged(newAction); }
-
- void setCurrentTarget(QWidget *target, bool dropped = false);
- QWidget *currentTarget();
-
-#ifdef Q_WS_X11
- QPixmap xdndMimeTransferedPixmap[2];
- int xdndMimeTransferedPixmapIndex;
-#endif
-
-private:
-#if defined(Q_WS_QWS) || defined(Q_WS_QPA)
- Qt::DropAction currentActionForOverrideCursor;
-#endif
-#ifdef Q_OS_SYMBIAN
-#ifndef QT_NO_CURSOR
- QCursor overrideCursor;
-#endif
-#endif
- QWidget *currentDropTarget;
-
- static QDragManager *instance;
- Q_DISABLE_COPY(QDragManager)
-};
-
-
-#if defined(Q_WS_WIN)
-
-class QOleDropTarget : public IDropTarget
-{
-public:
- QOleDropTarget(QWidget* w);
- virtual ~QOleDropTarget() {}
-
- void releaseQt();
-
- // IUnknown methods
- STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppvObj);
- STDMETHOD_(ULONG, AddRef)(void);
- STDMETHOD_(ULONG, Release)(void);
-
- // IDropTarget methods
- STDMETHOD(DragEnter)(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
- STDMETHOD(DragOver)(DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
- STDMETHOD(DragLeave)();
- STDMETHOD(Drop)(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
-
-private:
- ULONG m_refs;
- QWidget* widget;
- QPointer<QWidget> currentWidget;
- QRect answerRect;
- QPoint lastPoint;
- DWORD chosenEffect;
- DWORD lastKeyState;
-
- void sendDragEnterEvent(QWidget *to, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect);
-};
-
-#endif
-
-#if defined (Q_WS_MAC)
-class QCocoaDropData : public QInternalMimeData
-{
- Q_OBJECT
-public:
- QCocoaDropData(CFStringRef pasteboard);
- ~QCocoaDropData();
-
-protected:
- bool hasFormat_sys(const QString &mimeType) const;
- QStringList formats_sys() const;
- QVariant retrieveData_sys(const QString &mimeType, QVariant::Type type) const;
-public:
- CFStringRef dropPasteboard;
-};
-#endif
-
-#endif // !QT_NO_DRAGANDDROP
-
-
-QT_END_NAMESPACE
-
-#endif // QDND_P_H
diff --git a/src/gui/kernel/qdnd_qpa.cpp b/src/gui/kernel/qdnd_qpa.cpp
deleted file mode 100644
index b744c2f085..0000000000
--- a/src/gui/kernel/qdnd_qpa.cpp
+++ /dev/null
@@ -1,426 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qapplication.h"
-
-#ifndef QT_NO_DRAGANDDROP
-
-#include "qwidget.h"
-#include "qdatetime.h"
-#include "qbitmap.h"
-#include "qcursor.h"
-#include "qevent.h"
-#include "qpainter.h"
-#include "qdnd_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QT_USE_NAMESPACE
-
-static QPixmap *defaultPm = 0;
-static const int default_pm_hotx = -2;
-static const int default_pm_hoty = -16;
-static const char *const default_pm[] = {
-"13 9 3 1",
-". c None",
-" c #000000",
-"X c #FFFFFF",
-"X X X X X X X",
-" X X X X X X ",
-"X ......... X",
-" X.........X ",
-"X ......... X",
-" X.........X ",
-"X ......... X",
-" X X X X X X ",
-"X X X X X X X",
-};
-
-// Shift/Ctrl handling, and final drop status
-static Qt::DropAction global_accepted_action = Qt::CopyAction;
-static Qt::DropActions possible_actions = Qt::IgnoreAction;
-
-
-// static variables in place of a proper cross-process solution
-static QDrag *drag_object;
-static bool qt_qws_dnd_dragging = false;
-
-
-static Qt::KeyboardModifiers oldstate;
-
-class QShapedPixmapWidget : public QWidget {
- QPixmap pixmap;
-public:
- QShapedPixmapWidget() :
- QWidget(0, Qt::Tool | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint)
- {
- // ### Temporary workaround for 4.2-rc1!!! To prevent flickering when
- // using drag'n drop in a client application. (task 126956)
- // setAttribute() should be done unconditionally!
- if (QApplication::type() == QApplication::GuiServer)
- setAttribute(Qt::WA_TransparentForMouseEvents);
- }
-
- void setPixmap(QPixmap pm)
- {
- pixmap = pm;
- if (!pixmap.mask().isNull()) {
- setMask(pixmap.mask());
- } else {
- clearMask();
- }
- resize(pm.width(),pm.height());
- }
-
- void paintEvent(QPaintEvent*)
- {
- QPainter p(this);
- p.drawPixmap(0,0,pixmap);
- }
-};
-
-
-static QShapedPixmapWidget *qt_qws_dnd_deco = 0;
-
-
-void QDragManager::updatePixmap()
-{
- if (qt_qws_dnd_deco) {
- QPixmap pm;
- QPoint pm_hot(default_pm_hotx,default_pm_hoty);
- if (drag_object) {
- pm = drag_object->pixmap();
- if (!pm.isNull())
- pm_hot = drag_object->hotSpot();
- }
- if (pm.isNull()) {
- if (!defaultPm)
- defaultPm = new QPixmap(default_pm);
- pm = *defaultPm;
- }
- qt_qws_dnd_deco->setPixmap(pm);
- qt_qws_dnd_deco->move(QCursor::pos()-pm_hot);
- if (willDrop) {
- qt_qws_dnd_deco->show();
- } else {
- qt_qws_dnd_deco->hide();
- }
- }
-}
-
-void QDragManager::timerEvent(QTimerEvent *) { }
-
-void QDragManager::move(const QPoint &) { }
-
-void QDragManager::updateCursor()
-{
-#ifndef QT_NO_CURSOR
- if (willDrop) {
- if (qt_qws_dnd_deco)
- qt_qws_dnd_deco->show();
- if (currentActionForOverrideCursor != global_accepted_action) {
- QApplication::changeOverrideCursor(QCursor(dragCursor(global_accepted_action), 0, 0));
- currentActionForOverrideCursor = global_accepted_action;
- }
- } else {
- QCursor *overrideCursor = QApplication::overrideCursor();
- if (!overrideCursor || overrideCursor->shape() != Qt::ForbiddenCursor) {
- QApplication::changeOverrideCursor(QCursor(Qt::ForbiddenCursor));
- currentActionForOverrideCursor = Qt::IgnoreAction;
- }
- if (qt_qws_dnd_deco)
- qt_qws_dnd_deco->hide();
- }
-#endif
-}
-
-
-bool QDragManager::eventFilter(QObject *o, QEvent *e)
-{
- if (beingCancelled) {
- if (e->type() == QEvent::KeyRelease && static_cast<QKeyEvent*>(e)->key() == Qt::Key_Escape) {
- qApp->removeEventFilter(this);
- Q_ASSERT(object == 0);
- beingCancelled = false;
- eventLoop->exit();
- return true; // block the key release
- }
- return false;
- }
-
-
-
- if (!o->isWidgetType())
- return false;
-
- switch(e->type()) {
- case QEvent::ShortcutOverride:
- // prevent accelerators from firing while dragging
- e->accept();
- return true;
-
- case QEvent::KeyPress:
- case QEvent::KeyRelease:
- {
- QKeyEvent *ke = ((QKeyEvent*)e);
- if (ke->key() == Qt::Key_Escape && e->type() == QEvent::KeyPress) {
- cancel();
- qApp->removeEventFilter(this);
- beingCancelled = false;
- eventLoop->exit();
- } else {
- updateCursor();
- }
- return true; // Eat all key events
- }
-
- case QEvent::MouseButtonPress:
- case QEvent::MouseMove:
- {
- if (!object) { //#### this should not happen
- qWarning("QDragManager::eventFilter: No object");
- return true;
- }
-
- QDragManager *manager = QDragManager::self();
- QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData;
- if (manager->object)
- possible_actions = manager->dragPrivate()->possible_actions;
- else
- possible_actions = Qt::IgnoreAction;
-
- QMouseEvent *me = (QMouseEvent *)e;
- if (me->buttons()) {
- Qt::DropAction prevAction = global_accepted_action;
- QWidget *cw = QApplication::widgetAt(me->globalPos());
-
- // Fix for when we move mouse on to the deco widget
- if (qt_qws_dnd_deco && cw == qt_qws_dnd_deco)
- cw = object->target();
-
- while (cw && !cw->acceptDrops() && !cw->isWindow())
- cw = cw->parentWidget();
-
- if (object->target() != cw) {
- if (object->target()) {
- QDragLeaveEvent dle;
- QApplication::sendEvent(object->target(), &dle);
- willDrop = false;
- global_accepted_action = Qt::IgnoreAction;
- updateCursor();
- restoreCursor = true;
- object->d_func()->target = 0;
- }
- if (cw && cw->acceptDrops()) {
- object->d_func()->target = cw;
- QDragEnterEvent dee(cw->mapFromGlobal(me->globalPos()), possible_actions, dropData,
- me->buttons(), me->modifiers());
- QApplication::sendEvent(object->target(), &dee);
- willDrop = dee.isAccepted() && dee.dropAction() != Qt::IgnoreAction;
- global_accepted_action = willDrop ? dee.dropAction() : Qt::IgnoreAction;
- updateCursor();
- restoreCursor = true;
- }
- } else if (cw) {
- QDragMoveEvent dme(cw->mapFromGlobal(me->globalPos()), possible_actions, dropData,
- me->buttons(), me->modifiers());
- if (global_accepted_action != Qt::IgnoreAction) {
- dme.setDropAction(global_accepted_action);
- dme.accept();
- }
- QApplication::sendEvent(cw, &dme);
- willDrop = dme.isAccepted();
- global_accepted_action = willDrop ? dme.dropAction() : Qt::IgnoreAction;
- updatePixmap();
- updateCursor();
- }
- if (global_accepted_action != prevAction)
- emitActionChanged(global_accepted_action);
- }
- return true; // Eat all mouse events
- }
-
- case QEvent::MouseButtonRelease:
- {
- qApp->removeEventFilter(this);
- if (restoreCursor) {
- willDrop = false;
-#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
-#endif
- restoreCursor = false;
- }
- if (object && object->target()) {
- QMouseEvent *me = (QMouseEvent *)e;
-
- QDragManager *manager = QDragManager::self();
- QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData;
-
- QDropEvent de(object->target()->mapFromGlobal(me->globalPos()), possible_actions, dropData,
- me->buttons(), me->modifiers());
- QApplication::sendEvent(object->target(), &de);
- if (de.isAccepted())
- global_accepted_action = de.dropAction();
- else
- global_accepted_action = Qt::IgnoreAction;
-
- if (object)
- object->deleteLater();
- drag_object = object = 0;
- }
- eventLoop->exit();
- return true; // Eat all mouse events
- }
-
- default:
- break;
- }
-
- return false;
-}
-
-Qt::DropAction QDragManager::drag(QDrag *o)
-{
- if (object == o || !o || !o->source())
- return Qt::IgnoreAction;
-
- if (object) {
- cancel();
- qApp->removeEventFilter(this);
- beingCancelled = false;
- }
-
- object = drag_object = o;
- qt_qws_dnd_deco = new QShapedPixmapWidget();
- oldstate = Qt::NoModifier; // #### Should use state that caused the drag
-// drag_mode = mode;
-
- willDrop = false;
- updatePixmap();
- updateCursor();
- restoreCursor = true;
- object->d_func()->target = 0;
- qApp->installEventFilter(this);
-
- global_accepted_action = Qt::CopyAction;
-#ifndef QT_NO_CURSOR
- qApp->setOverrideCursor(Qt::ArrowCursor);
- restoreCursor = true;
- updateCursor();
-#endif
-
- qt_qws_dnd_dragging = true;
-
- eventLoop = new QEventLoop;
- (void) eventLoop->exec();
- delete eventLoop;
- eventLoop = 0;
-
- delete qt_qws_dnd_deco;
- qt_qws_dnd_deco = 0;
- qt_qws_dnd_dragging = false;
-
-
- return global_accepted_action;
-}
-
-
-void QDragManager::cancel(bool deleteSource)
-{
-// qDebug("QDragManager::cancel");
- beingCancelled = true;
-
- if (object->target()) {
- QDragLeaveEvent dle;
- QApplication::sendEvent(object->target(), &dle);
- }
-
-#ifndef QT_NO_CURSOR
- if (restoreCursor) {
- QApplication::restoreOverrideCursor();
- restoreCursor = false;
- }
-#endif
-
- if (drag_object) {
- if (deleteSource)
- object->deleteLater();
- drag_object = object = 0;
- }
-
- delete qt_qws_dnd_deco;
- qt_qws_dnd_deco = 0;
-
- global_accepted_action = Qt::IgnoreAction;
-}
-
-
-void QDragManager::drop()
-{
-}
-
-QVariant QDropData::retrieveData_sys(const QString &mimetype, QVariant::Type type) const
-{
- if (!drag_object)
- return QVariant();
- QByteArray data = drag_object->mimeData()->data(mimetype);
- if (type == QVariant::String)
- return QString::fromUtf8(data);
- return data;
-}
-
-bool QDropData::hasFormat_sys(const QString &format) const
-{
- return formats().contains(format);
-}
-
-QStringList QDropData::formats_sys() const
-{
- if (drag_object)
- return drag_object->mimeData()->formats();
- return QStringList();
-}
-
-
-#endif // QT_NO_DRAGANDDROP
-
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qdnd_s60.cpp b/src/gui/kernel/qdnd_s60.cpp
deleted file mode 100644
index a9847a98f8..0000000000
--- a/src/gui/kernel/qdnd_s60.cpp
+++ /dev/null
@@ -1,359 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qapplication.h"
-
-#ifndef QT_NO_DRAGANDDROP
-
-#include "qwidget.h"
-#include "qdatetime.h"
-#include "qbitmap.h"
-#include "qcursor.h"
-#include "qevent.h"
-#include "qpainter.h"
-#include "qdnd_p.h"
-#include "qt_s60_p.h"
-
-#include <coecntrl.h>
-// pointer cursor
-#include <w32std.h>
-#include <gdi.h>
-#include <QCursor>
-
-QT_BEGIN_NAMESPACE
-//### artistic impression of Symbians default DnD cursor ?
-
-static QPixmap *defaultPm = 0;
-static const int default_pm_hotx = -50;
-static const int default_pm_hoty = -50;
-static const char *const default_pm[] = {
-"13 9 3 1",
-". c None",
-" c #000000",
-"X c #FFFFFF",
-"X X X X X X X",
-" X X X X X X ",
-"X ......... X",
-" X.........X ",
-"X ......... X",
-" X.........X ",
-"X ......... X",
-" X X X X X X ",
-"X X X X X X X",
-};
-//### actions need to be redefined for S60
-// Shift/Ctrl handling, and final drop status
-static Qt::DropAction global_accepted_action = Qt::MoveAction;
-static Qt::DropActions possible_actions = Qt::IgnoreAction;
-
-
-// static variables in place of a proper cross-process solution
-static QDrag *drag_object;
-static bool qt_symbian_dnd_dragging = false;
-
-
-static Qt::KeyboardModifiers oldstate;
-
-void QDragManager::updatePixmap()
-{
- QPixmap pm;
- QPoint pm_hot(default_pm_hotx,default_pm_hoty);
- if (drag_object) {
- pm = drag_object->pixmap();
- if (!pm.isNull())
- pm_hot = drag_object->hotSpot();
- }
- if (pm.isNull()) {
- if (!defaultPm)
- defaultPm = new QPixmap(default_pm);
- pm = *defaultPm;
- }
-#ifndef QT_NO_CURSOR
- QCursor cursor(pm, pm_hot.x(), pm_hot.y());
- overrideCursor = cursor;
-#endif
-}
-
-void QDragManager::timerEvent(QTimerEvent *) { }
-
-void QDragManager::move(const QPoint&) {
-}
-
-void QDragManager::updateCursor()
-{
-#ifndef QT_NO_CURSOR
- QCursor cursor = willDrop ? overrideCursor : Qt::ForbiddenCursor;
- if (!restoreCursor) {
- QApplication::setOverrideCursor(cursor);
- restoreCursor = true;
- }
- else {
- QApplication::changeOverrideCursor(cursor);
- }
-#endif
-}
-
-
-bool QDragManager::eventFilter(QObject *o, QEvent *e)
-{
- if (beingCancelled) {
- return false;
- }
- if (!o->isWidgetType())
- return false;
-
- switch(e->type()) {
- case QEvent::MouseButtonPress:
- {
- }
- case QEvent::MouseMove:
- {
- if (!object) { //#### this should not happen
- qWarning("QDragManager::eventFilter: No object");
- return true;
- }
- QDragManager *manager = QDragManager::self();
- QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData;
- if (manager->object)
- possible_actions = manager->dragPrivate()->possible_actions;
- else
- possible_actions = Qt::IgnoreAction;
-
- QMouseEvent *me = (QMouseEvent *)e;
-
- if (me->buttons()) {
- Qt::DropAction prevAction = global_accepted_action;
- QWidget *cw = QApplication::widgetAt(me->globalPos());
- // map the Coords relative to the window.
- if (!cw)
- return true;
-
- while (cw && !cw->acceptDrops() && !cw->isWindow())
- cw = cw->parentWidget();
-
- bool oldWillDrop = willDrop;
- if (object->target() != cw) {
- if (object->target()) {
- QDragLeaveEvent dle;
- QApplication::sendEvent(object->target(), &dle);
- willDrop = false;
- global_accepted_action = Qt::IgnoreAction;
- if (oldWillDrop != willDrop)
- updateCursor();
- object->d_func()->target = 0;
- }
- if (cw && cw->acceptDrops()) {
- object->d_func()->target = cw;
- QDragEnterEvent dee(cw->mapFromGlobal(me->globalPos()), possible_actions, dropData,
- me->buttons(), me->modifiers());
- QApplication::sendEvent(object->target(), &dee);
- willDrop = dee.isAccepted() && dee.dropAction() != Qt::IgnoreAction;
- global_accepted_action = willDrop ? dee.dropAction() : Qt::IgnoreAction;
- if (oldWillDrop != willDrop)
- updateCursor();
- }
- } else if (cw) {
- QDragMoveEvent dme(cw->mapFromGlobal(me->globalPos()), possible_actions, dropData,
- me->buttons(), me->modifiers());
- if (global_accepted_action != Qt::IgnoreAction) {
- dme.setDropAction(global_accepted_action);
- dme.accept();
- }
- QApplication::sendEvent(cw, &dme);
- willDrop = dme.isAccepted();
- global_accepted_action = willDrop ? dme.dropAction() : Qt::IgnoreAction;
- if (oldWillDrop != willDrop) {
- updatePixmap();
- updateCursor();
- }
- }
- if (global_accepted_action != prevAction)
- emitActionChanged(global_accepted_action);
- }
- return true; // Eat all mouse events
- }
-
- case QEvent::MouseButtonRelease:
- {
- qApp->removeEventFilter(this);
-#ifndef QT_NO_CURSOR
- if (restoreCursor) {
- QApplication::restoreOverrideCursor();
- willDrop = false;
- restoreCursor = false;
- }
-#endif
- if (object && object->target()) {
-
- QMouseEvent *me = (QMouseEvent *)e;
-
- QDragManager *manager = QDragManager::self();
- QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData;
-
- QDropEvent de(object->target()->mapFromGlobal(me->globalPos()), possible_actions, dropData,
- me->buttons(), me->modifiers());
- QApplication::sendEvent(object->target(), &de);
- if (de.isAccepted())
- global_accepted_action = de.dropAction();
- else
- global_accepted_action = Qt::IgnoreAction;
-
- if (object)
- object->deleteLater();
- drag_object = object = 0;
- }
- eventLoop->exit();
- return true; // Eat all mouse events
- }
-
- default:
- break;
- }
- return false;
-}
-
-Qt::DropAction QDragManager::drag(QDrag *o)
-{
- Q_ASSERT(!qt_symbian_dnd_dragging);
- if (object == o || !o || !o->source())
- return Qt::IgnoreAction;
-
- if (object) {
- cancel();
- qApp->removeEventFilter(this);
- beingCancelled = false;
- }
-
- object = drag_object = o;
-
- oldstate = Qt::NoModifier; // #### Should use state that caused the drag
- willDrop = false;
- updatePixmap();
- updateCursor();
-
-#ifndef QT_NO_CURSOR
- qt_symbian_set_cursor_visible(true); //force cursor on even for touch phone
-#endif
-
- object->d_func()->target = 0;
-
- qApp->installEventFilter(this);
-
- global_accepted_action = defaultAction(dragPrivate()->possible_actions, Qt::NoModifier);
- qt_symbian_dnd_dragging = true;
-
- eventLoop = new QEventLoop;
- // block
- (void) eventLoop->exec(QEventLoop::AllEvents);
- delete eventLoop;
- eventLoop = 0;
-
-#ifndef QT_NO_CURSOR
- qt_symbian_set_cursor_visible(false);
-
- overrideCursor = QCursor(); //deref the cursor data
- qt_symbian_dnd_dragging = false;
-#endif
-
- return global_accepted_action;
-}
-
-
-void QDragManager::cancel(bool deleteSource)
-{
- beingCancelled = true;
-
- if (object->target()) {
- QDragLeaveEvent dle;
- QApplication::sendEvent(object->target(), &dle);
- }
-
- if (drag_object) {
- if (deleteSource)
- object->deleteLater();
- drag_object = object = 0;
- }
-
-#ifndef QT_NO_CURSOR
- if (restoreCursor) {
- QApplication::restoreOverrideCursor();
- restoreCursor = false;
- }
-#endif
-
- global_accepted_action = Qt::IgnoreAction;
-}
-
-
-void QDragManager::drop()
-{
-#ifndef QT_NO_CURSOR
- if (restoreCursor) {
- QApplication::restoreOverrideCursor();
- restoreCursor = false;
- }
-#endif
-}
-
-QVariant QDropData::retrieveData_sys(const QString &mimetype, QVariant::Type type) const
-{
- if (!drag_object)
- return QVariant();
- QByteArray data = drag_object->mimeData()->data(mimetype);
- if (type == QVariant::String)
- return QString::fromUtf8(data);
- return data;
-}
-
-bool QDropData::hasFormat_sys(const QString &format) const
-{
- return formats().contains(format);
-}
-
-QStringList QDropData::formats_sys() const
-{
- if (drag_object)
- return drag_object->mimeData()->formats();
- return QStringList();
-}
-
-QT_END_NAMESPACE
-#endif // QT_NO_DRAGANDDROP
diff --git a/src/gui/kernel/qdnd_win.cpp b/src/gui/kernel/qdnd_win.cpp
deleted file mode 100644
index 176e3cef7f..0000000000
--- a/src/gui/kernel/qdnd_win.cpp
+++ /dev/null
@@ -1,1027 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qapplication.h"
-
-#include "qapplication_p.h"
-#include "qevent.h"
-#include "qpainter.h"
-#include "qwidget.h"
-#include "qbuffer.h"
-#include "qdatastream.h"
-#include "qcursor.h"
-#include "qt_windows.h"
-#include <shlobj.h>
-#ifndef QT_NO_ACCESSIBILITY
-#include "qaccessible.h"
-#endif
-#include "qdnd_p.h"
-#include "qdebug.h"
-
-#if defined(Q_OS_WINCE)
-#include "qguifunctions_wince.h"
-#endif
-
-// support for xbuttons
-#ifndef MK_XBUTTON1
-#define MK_XBUTTON1 0x0020
-#define MK_XBUTTON2 0x0040
-#endif
-
-QT_BEGIN_NAMESPACE
-
-#if !(defined(QT_NO_DRAGANDDROP) && defined(QT_NO_CLIPBOARD))
-
-//---------------------------------------------------------------------
-// QOleDataObject Constructor
-//---------------------------------------------------------------------
-
-QOleDataObject::QOleDataObject(QMimeData *mimeData)
-{
- m_refs = 1;
- data = mimeData;
- CF_PERFORMEDDROPEFFECT = RegisterClipboardFormat(CFSTR_PERFORMEDDROPEFFECT);
- performedEffect = DROPEFFECT_NONE;
-}
-
-QOleDataObject::~QOleDataObject()
-{
-}
-
-void QOleDataObject::releaseQt()
-{
- data = 0;
-}
-
-const QMimeData *QOleDataObject::mimeData() const
-{
- return data;
-}
-
-DWORD QOleDataObject::reportedPerformedEffect() const
-{
- return performedEffect;
-}
-
-//---------------------------------------------------------------------
-// IUnknown Methods
-//---------------------------------------------------------------------
-
-STDMETHODIMP
-QOleDataObject::QueryInterface(REFIID iid, void FAR* FAR* ppv)
-{
- if (iid == IID_IUnknown || iid == IID_IDataObject) {
- *ppv = this;
- AddRef();
- return NOERROR;
- }
- *ppv = NULL;
- return ResultFromScode(E_NOINTERFACE);
-}
-
-STDMETHODIMP_(ULONG)
-QOleDataObject::AddRef(void)
-{
- return ++m_refs;
-}
-
-STDMETHODIMP_(ULONG)
-QOleDataObject::Release(void)
-{
- if (--m_refs == 0) {
- releaseQt();
- delete this;
- return 0;
- }
- return m_refs;
-}
-
-//---------------------------------------------------------------------
-// IDataObject Methods
-//
-// The following methods are NOT supported for data transfer using the
-// clipboard or drag-drop:
-//
-// IDataObject::SetData -- return E_NOTIMPL
-// IDataObject::DAdvise -- return OLE_E_ADVISENOTSUPPORTED
-// ::DUnadvise
-// ::EnumDAdvise
-// IDataObject::GetCanonicalFormatEtc -- return E_NOTIMPL
-// (NOTE: must set pformatetcOut->ptd = NULL)
-//---------------------------------------------------------------------
-
-STDMETHODIMP
-QOleDataObject::GetData(LPFORMATETC pformatetc, LPSTGMEDIUM pmedium)
-{
-#ifdef QDND_DEBUG
- qDebug("QOleDataObject::GetData(LPFORMATETC pformatetc, LPSTGMEDIUM pmedium)");
-#ifndef Q_OS_WINCE
- wchar_t buf[256] = {0};
- GetClipboardFormatName(pformatetc->cfFormat, buf, 255);
- qDebug("CF = %d : %s", pformatetc->cfFormat, QString::fromWCharArray(buf));
-#endif
-#endif
-
- if (!data)
- return ResultFromScode(DATA_E_FORMATETC);
-
- QWindowsMime *converter = QWindowsMime::converterFromMime(*pformatetc, data);
-
- if (converter && converter->convertFromMime(*pformatetc, data, pmedium))
- return ResultFromScode(S_OK);
- else
- return ResultFromScode(DATA_E_FORMATETC);
-}
-
-STDMETHODIMP
-QOleDataObject::GetDataHere(LPFORMATETC, LPSTGMEDIUM)
-{
- return ResultFromScode(DATA_E_FORMATETC);
-}
-
-STDMETHODIMP
-QOleDataObject::QueryGetData(LPFORMATETC pformatetc)
-{
-#ifdef QDND_DEBUG
- qDebug("QOleDataObject::QueryGetData(LPFORMATETC pformatetc)");
-#endif
-
- if (!data)
- return ResultFromScode(DATA_E_FORMATETC);
-
- if (QWindowsMime::converterFromMime(*pformatetc, data))
- return ResultFromScode(S_OK);
- return ResultFromScode(S_FALSE);
-}
-
-STDMETHODIMP
-QOleDataObject::GetCanonicalFormatEtc(LPFORMATETC, LPFORMATETC pformatetcOut)
-{
- pformatetcOut->ptd = NULL;
- return ResultFromScode(E_NOTIMPL);
-}
-
-STDMETHODIMP
-QOleDataObject::SetData(LPFORMATETC pFormatetc, STGMEDIUM *pMedium, BOOL fRelease)
-{
- if (pFormatetc->cfFormat == CF_PERFORMEDDROPEFFECT && pMedium->tymed == TYMED_HGLOBAL) {
- DWORD * val = (DWORD*)GlobalLock(pMedium->hGlobal);
- performedEffect = *val;
- GlobalUnlock(pMedium->hGlobal);
- if (fRelease)
- ReleaseStgMedium(pMedium);
- return ResultFromScode(S_OK);
- }
- return ResultFromScode(E_NOTIMPL);
-}
-
-
-STDMETHODIMP
-QOleDataObject::EnumFormatEtc(DWORD dwDirection, LPENUMFORMATETC FAR* ppenumFormatEtc)
-{
-#ifdef QDND_DEBUG
- qDebug("QOleDataObject::EnumFormatEtc(DWORD dwDirection, LPENUMFORMATETC FAR* ppenumFormatEtc)");
-#endif
-
- if (!data)
- return ResultFromScode(DATA_E_FORMATETC);
-
- SCODE sc = S_OK;
-
- QVector<FORMATETC> fmtetcs;
- if (dwDirection == DATADIR_GET) {
- fmtetcs = QWindowsMime::allFormatsForMime(data);
- } else {
- FORMATETC formatetc;
- formatetc.cfFormat = CF_PERFORMEDDROPEFFECT;
- formatetc.dwAspect = DVASPECT_CONTENT;
- formatetc.lindex = -1;
- formatetc.ptd = NULL;
- formatetc.tymed = TYMED_HGLOBAL;
- fmtetcs.append(formatetc);
- }
-
- QOleEnumFmtEtc *enumFmtEtc = new QOleEnumFmtEtc(fmtetcs);
- *ppenumFormatEtc = enumFmtEtc;
- if (enumFmtEtc->isNull()) {
- delete enumFmtEtc;
- *ppenumFormatEtc = NULL;
- sc = E_OUTOFMEMORY;
- }
-
- return ResultFromScode(sc);
-}
-
-STDMETHODIMP
-QOleDataObject::DAdvise(FORMATETC FAR*, DWORD,
- LPADVISESINK, DWORD FAR*)
-{
- return ResultFromScode(OLE_E_ADVISENOTSUPPORTED);
-}
-
-
-STDMETHODIMP
-QOleDataObject::DUnadvise(DWORD)
-{
- return ResultFromScode(OLE_E_ADVISENOTSUPPORTED);
-}
-
-STDMETHODIMP
-QOleDataObject::EnumDAdvise(LPENUMSTATDATA FAR*)
-{
- return ResultFromScode(OLE_E_ADVISENOTSUPPORTED);
-}
-
-#endif // QT_NO_DRAGANDDROP && QT_NO_CLIPBOARD
-
-#ifndef QT_NO_DRAGANDDROP
-
-//#define QDND_DEBUG
-
-#ifdef QDND_DEBUG
-extern QString dragActionsToString(Qt::DropActions actions);
-#endif
-
-Qt::DropActions translateToQDragDropActions(DWORD pdwEffects)
-{
- Qt::DropActions actions = Qt::IgnoreAction;
- if (pdwEffects & DROPEFFECT_LINK)
- actions |= Qt::LinkAction;
- if (pdwEffects & DROPEFFECT_COPY)
- actions |= Qt::CopyAction;
- if (pdwEffects & DROPEFFECT_MOVE)
- actions |= Qt::MoveAction;
- return actions;
-}
-
-Qt::DropAction translateToQDragDropAction(DWORD pdwEffect)
-{
- if (pdwEffect & DROPEFFECT_LINK)
- return Qt::LinkAction;
- if (pdwEffect & DROPEFFECT_COPY)
- return Qt::CopyAction;
- if (pdwEffect & DROPEFFECT_MOVE)
- return Qt::MoveAction;
- return Qt::IgnoreAction;
-}
-
-DWORD translateToWinDragEffects(Qt::DropActions action)
-{
- DWORD effect = DROPEFFECT_NONE;
- if (action & Qt::LinkAction)
- effect |= DROPEFFECT_LINK;
- if (action & Qt::CopyAction)
- effect |= DROPEFFECT_COPY;
- if (action & Qt::MoveAction)
- effect |= DROPEFFECT_MOVE;
- return effect;
-}
-
-Qt::KeyboardModifiers toQtKeyboardModifiers(DWORD keyState)
-{
- Qt::KeyboardModifiers modifiers = Qt::NoModifier;
-
- if (keyState & MK_SHIFT)
- modifiers |= Qt::ShiftModifier;
- if (keyState & MK_CONTROL)
- modifiers |= Qt::ControlModifier;
- if (keyState & MK_ALT)
- modifiers |= Qt::AltModifier;
-
- return modifiers;
-}
-
-Qt::MouseButtons toQtMouseButtons(DWORD keyState)
-{
- Qt::MouseButtons buttons = Qt::NoButton;
-
- if (keyState & MK_LBUTTON)
- buttons |= Qt::LeftButton;
- if (keyState & MK_RBUTTON)
- buttons |= Qt::RightButton;
- if (keyState & MK_MBUTTON)
- buttons |= Qt::MidButton;
-
- return buttons;
-}
-
-class QOleDropSource : public IDropSource
-{
-public:
- QOleDropSource();
- virtual ~QOleDropSource();
-
- void createCursors();
-
- // IUnknown methods
- STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObj);
- STDMETHOD_(ULONG,AddRef)(void);
- STDMETHOD_(ULONG,Release)(void);
-
- // IDropSource methods
- STDMETHOD(QueryContinueDrag)(BOOL fEscapePressed, DWORD grfKeyState);
- STDMETHOD(GiveFeedback)(DWORD dwEffect);
-
-private:
- Qt::MouseButtons currentButtons;
- Qt::DropAction currentAction;
- QMap <Qt::DropAction, QCursor> cursors;
-
- ULONG m_refs;
-};
-
-
-QOleDropSource::QOleDropSource()
-{
- currentButtons = Qt::NoButton;
- m_refs = 1;
- currentAction = Qt::IgnoreAction;
-}
-
-QOleDropSource::~QOleDropSource()
-{
-}
-
-void QOleDropSource::createCursors()
-{
- QDragManager *manager = QDragManager::self();
- if (manager && manager->object
- && (!manager->object->pixmap().isNull()
- || manager->hasCustomDragCursors())) {
- QPixmap pm = manager->object->pixmap();
- QList<Qt::DropAction> actions;
- actions << Qt::MoveAction << Qt::CopyAction << Qt::LinkAction;
- if (!manager->object->pixmap().isNull())
- actions << Qt::IgnoreAction;
- QPoint hotSpot = manager->object->hotSpot();
- for (int cnum = 0; cnum < actions.size(); ++cnum) {
- QPixmap cpm = manager->dragCursor(actions.at(cnum));
- int w = cpm.width();
- int h = cpm.height();
-
- if (!pm.isNull()) {
- int x1 = qMin(-hotSpot.x(), 0);
- int x2 = qMax(pm.width() - hotSpot.x(), cpm.width());
- int y1 = qMin(-hotSpot.y(), 0);
- int y2 = qMax(pm.height() - hotSpot.y(), cpm.height());
-
- w = x2 - x1 + 1;
- h = y2 - y1 + 1;
- }
-
- QRect srcRect = pm.rect();
- QPoint pmDest = QPoint(qMax(0, -hotSpot.x()), qMax(0, -hotSpot.y()));
- QPoint newHotSpot = hotSpot;
-
-#if defined(Q_OS_WINCE)
- // Limited cursor size
- int reqw = GetSystemMetrics(SM_CXCURSOR);
- int reqh = GetSystemMetrics(SM_CYCURSOR);
-
- QPoint hotspotInPM = newHotSpot - pmDest;
- if (reqw < w) {
- // Not wide enough - move objectpm right
- qreal r = qreal(newHotSpot.x()) / w;
- newHotSpot = QPoint(int(r * reqw), newHotSpot.y());
- if (newHotSpot.x() + cpm.width() > reqw)
- newHotSpot.setX(reqw - cpm.width());
-
- srcRect = QRect(QPoint(hotspotInPM.x() - newHotSpot.x(), srcRect.top()), QSize(reqw, srcRect.height()));
- }
- if (reqh < h) {
- qreal r = qreal(newHotSpot.y()) / h;
- newHotSpot = QPoint(newHotSpot.x(), int(r * reqh));
- if (newHotSpot.y() + cpm.height() > reqh)
- newHotSpot.setY(reqh - cpm.height());
-
- srcRect = QRect(QPoint(srcRect.left(), hotspotInPM.y() - newHotSpot.y()), QSize(srcRect.width(), reqh));
- }
- // Always use system cursor size
- w = reqw;
- h = reqh;
-#endif
-
- QPixmap newCursor(w, h);
- if (!pm.isNull()) {
- newCursor.fill(QColor(0, 0, 0, 0));
- QPainter p(&newCursor);
- p.drawPixmap(pmDest, pm, srcRect);
- p.drawPixmap(qMax(0,newHotSpot.x()),qMax(0,newHotSpot.y()),cpm);
- } else {
- newCursor = cpm;
- }
-
-#ifndef QT_NO_CURSOR
- cursors[actions.at(cnum)] = QCursor(newCursor, pm.isNull() ? 0 : qMax(0,newHotSpot.x()),
- pm.isNull() ? 0 : qMax(0,newHotSpot.y()));
-#endif
- }
- }
-}
-
-
-
-//---------------------------------------------------------------------
-// IUnknown Methods
-//---------------------------------------------------------------------
-
-
-STDMETHODIMP
-QOleDropSource::QueryInterface(REFIID iid, void FAR* FAR* ppv)
-{
- if(iid == IID_IUnknown || iid == IID_IDropSource)
- {
- *ppv = this;
- ++m_refs;
- return NOERROR;
- }
- *ppv = NULL;
- return ResultFromScode(E_NOINTERFACE);
-}
-
-
-STDMETHODIMP_(ULONG)
-QOleDropSource::AddRef(void)
-{
- return ++m_refs;
-}
-
-
-STDMETHODIMP_(ULONG)
-QOleDropSource::Release(void)
-{
- if(--m_refs == 0)
- {
- delete this;
- return 0;
- }
- return m_refs;
-}
-
-static inline Qt::MouseButtons keystate_to_mousebutton(DWORD grfKeyState)
-{
- Qt::MouseButtons result;
- if (grfKeyState & MK_LBUTTON)
- result |= Qt::LeftButton;
- if (grfKeyState & MK_MBUTTON)
- result |= Qt::MidButton;
- if (grfKeyState & MK_RBUTTON)
- result |= Qt::RightButton;
- if (grfKeyState & MK_XBUTTON1)
- result |= Qt::XButton1;
- if (grfKeyState & MK_XBUTTON2)
- result |= Qt::XButton2;
- return result;
-}
-
-//---------------------------------------------------------------------
-// IDropSource Methods
-//---------------------------------------------------------------------
-QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP
-QOleDropSource::QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeyState)
-{
-#ifdef QDND_DEBUG
- qDebug("QOleDropSource::QueryContinueDrag(fEscapePressed %d, grfKeyState %d)", fEscapePressed, grfKeyState);
-#endif
-
- if (fEscapePressed) {
- return ResultFromScode(DRAGDROP_S_CANCEL);
- } else if ((GetAsyncKeyState(VK_LBUTTON) == 0)
- && (GetAsyncKeyState(VK_MBUTTON) == 0)
- && (GetAsyncKeyState(VK_RBUTTON) == 0)) {
- // grfKeyState is broken on CE & some Windows XP versions,
- // therefore we need to check the state manually
- return ResultFromScode(DRAGDROP_S_DROP);
- } else {
-#if !defined(Q_OS_WINCE)
- if (currentButtons == Qt::NoButton) {
- currentButtons = keystate_to_mousebutton(grfKeyState);
- } else {
- Qt::MouseButtons buttons = keystate_to_mousebutton(grfKeyState);
- if (!(currentButtons & buttons))
- return ResultFromScode(DRAGDROP_S_DROP);
- }
-#endif
- QApplication::processEvents();
- return NOERROR;
- }
-}
-
-QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP
-QOleDropSource::GiveFeedback(DWORD dwEffect)
-{
- Qt::DropAction action = translateToQDragDropAction(dwEffect);
-
-#ifdef QDND_DEBUG
- qDebug("QOleDropSource::GiveFeedback(DWORD dwEffect)");
- qDebug("dwEffect = %s", dragActionsToString(action).toLatin1().data());
-#endif
-
- if (currentAction != action) {
- currentAction = action;
- QDragManager::self()->emitActionChanged(currentAction);
- }
-
- if (cursors.contains(currentAction)) {
-#ifndef QT_NO_CURSOR
- SetCursor(cursors[currentAction].handle());
-#endif
- return ResultFromScode(S_OK);
- }
-
- return ResultFromScode(DRAGDROP_S_USEDEFAULTCURSORS);
-}
-
-//---------------------------------------------------------------------
-// QOleDropTarget
-//---------------------------------------------------------------------
-
-QOleDropTarget::QOleDropTarget(QWidget* w)
-: widget(w)
-{
- m_refs = 1;
-}
-
-void QOleDropTarget::releaseQt()
-{
- widget = 0;
-}
-
-//---------------------------------------------------------------------
-// IUnknown Methods
-//---------------------------------------------------------------------
-
-
-STDMETHODIMP
-QOleDropTarget::QueryInterface(REFIID iid, void FAR* FAR* ppv)
-{
- if(iid == IID_IUnknown || iid == IID_IDropTarget)
- {
- *ppv = this;
- AddRef();
- return NOERROR;
- }
- *ppv = NULL;
- return ResultFromScode(E_NOINTERFACE);
-}
-
-
-STDMETHODIMP_(ULONG)
-QOleDropTarget::AddRef(void)
-{
- return ++m_refs;
-}
-
-
-STDMETHODIMP_(ULONG)
-QOleDropTarget::Release(void)
-{
- if(--m_refs == 0)
- {
- delete this;
- return 0;
- }
- return m_refs;
-}
-
-//---------------------------------------------------------------------
-// IDropTarget Methods
-//---------------------------------------------------------------------
-
-QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP
-QOleDropTarget::DragEnter(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
-{
-#ifdef QDND_DEBUG
- qDebug("QOleDropTarget::DragEnter(LPDATAOBJECT pDataObj, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)");
-#endif
-
- if (!QApplicationPrivate::tryModalHelper(widget)) {
- *pdwEffect = DROPEFFECT_NONE;
- return NOERROR;
- }
-
- QDragManager *manager = QDragManager::self();
- manager->dropData->currentDataObject = pDataObj;
- manager->dropData->currentDataObject->AddRef();
- sendDragEnterEvent(widget, grfKeyState, pt, pdwEffect);
- *pdwEffect = chosenEffect;
-
- return NOERROR;
-}
-
-void QOleDropTarget::sendDragEnterEvent(QWidget *dragEnterWidget, DWORD grfKeyState,
- POINTL pt, LPDWORD pdwEffect)
-{
- Q_ASSERT(dragEnterWidget);
- lastPoint = dragEnterWidget->mapFromGlobal(QPoint(pt.x,pt.y));
- lastKeyState = grfKeyState;
-
- chosenEffect = DROPEFFECT_NONE;
- currentWidget = dragEnterWidget;
-
- QDragManager *manager = QDragManager::self();
- QMimeData * md = manager->source() ? manager->dragPrivate()->data : manager->dropData;
- QDragEnterEvent enterEvent(lastPoint, translateToQDragDropActions(*pdwEffect), md,
- toQtMouseButtons(grfKeyState), toQtKeyboardModifiers(grfKeyState));
- QApplication::sendEvent(dragEnterWidget, &enterEvent);
- answerRect = enterEvent.answerRect();
-
- if (enterEvent.isAccepted()) {
- chosenEffect = translateToWinDragEffects(enterEvent.dropAction());
- }
-
- // Documentation states that a drag move event is sendt immidiatly after
- // a drag enter event. This will honor widgets overriding dragMoveEvent only:
- if (enterEvent.isAccepted()) {
- QDragMoveEvent moveEvent(lastPoint, translateToQDragDropActions(*pdwEffect), md,
- toQtMouseButtons(grfKeyState), toQtKeyboardModifiers(grfKeyState));
- answerRect = enterEvent.answerRect();
- moveEvent.setDropAction(enterEvent.dropAction());
- moveEvent.accept(); // accept by default, since enter event was accepted.
-
- QApplication::sendEvent(dragEnterWidget, &moveEvent);
- if (moveEvent.isAccepted()) {
- answerRect = moveEvent.answerRect();
- chosenEffect = translateToWinDragEffects(moveEvent.dropAction());
- } else {
- chosenEffect = DROPEFFECT_NONE;
- }
- }
-
-}
-
-QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP
-QOleDropTarget::DragOver(DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
-{
-#ifdef QDND_DEBUG
- qDebug("QOleDropTarget::DragOver(grfKeyState %d, pt (%d,%d), pdwEffect %d)", grfKeyState, pt.x, pt.y, pdwEffect);
-#endif
-
- QWidget *dragOverWidget = widget->childAt(widget->mapFromGlobal(QPoint(pt.x, pt.y)));
- if (!dragOverWidget)
- dragOverWidget = widget;
-
-
- if (!QApplicationPrivate::tryModalHelper(dragOverWidget)
- || !dragOverWidget->testAttribute(Qt::WA_DropSiteRegistered)) {
- *pdwEffect = DROPEFFECT_NONE;
- return NOERROR;
- }
-
- QPoint tmpPoint = dragOverWidget->mapFromGlobal(QPoint(pt.x, pt.y));
- // see if we should compress this event
- if ((tmpPoint == lastPoint || answerRect.contains(tmpPoint)) && lastKeyState == grfKeyState) {
- *pdwEffect = chosenEffect;
- return NOERROR;
- }
-
- if (!dragOverWidget->internalWinId() && dragOverWidget != currentWidget) {
- QPointer<QWidget> dragOverWidgetGuard(dragOverWidget);
- // Send drag leave event to the previous drag widget.
- QDragLeaveEvent dragLeave;
- if (currentWidget)
- QApplication::sendEvent(currentWidget, &dragLeave);
- if (!dragOverWidgetGuard) {
- dragOverWidget = widget->childAt(widget->mapFromGlobal(QPoint(pt.x, pt.y)));
- if (!dragOverWidget)
- dragOverWidget = widget;
- }
- // Send drag enter event to the current drag widget.
- sendDragEnterEvent(dragOverWidget, grfKeyState, pt, pdwEffect);
- }
-
- QDragManager *manager = QDragManager::self();
- QMimeData *md = manager->source() ? manager->dragPrivate()->data : manager->dropData;
-
- QDragMoveEvent oldEvent(lastPoint, translateToQDragDropActions(*pdwEffect), md,
- toQtMouseButtons(lastKeyState), toQtKeyboardModifiers(lastKeyState));
-
-
- lastPoint = tmpPoint;
- lastKeyState = grfKeyState;
-
- QDragMoveEvent e(lastPoint, translateToQDragDropActions(*pdwEffect), md,
- toQtMouseButtons(grfKeyState), toQtKeyboardModifiers(grfKeyState));
- if (chosenEffect != DROPEFFECT_NONE) {
- if (oldEvent.dropAction() == e.dropAction() &&
- oldEvent.keyboardModifiers() == e.keyboardModifiers())
- e.setDropAction(translateToQDragDropAction(chosenEffect));
- e.accept();
- }
- QApplication::sendEvent(dragOverWidget, &e);
-
- answerRect = e.answerRect();
- if (e.isAccepted())
- chosenEffect = translateToWinDragEffects(e.dropAction());
- else
- chosenEffect = DROPEFFECT_NONE;
- *pdwEffect = chosenEffect;
-
- return NOERROR;
-}
-
-QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP
-QOleDropTarget::DragLeave()
-{
-#ifdef QDND_DEBUG
- qDebug("QOleDropTarget::DragLeave()");
-#endif
-
- if (!QApplicationPrivate::tryModalHelper(widget)) {
- return NOERROR;
- }
-
- currentWidget = 0;
- QDragLeaveEvent e;
- QApplication::sendEvent(widget, &e);
-
- QDragManager *manager = QDragManager::self();
-
- if (manager->dropData->currentDataObject) { // Sanity
- manager->dropData->currentDataObject->Release();
- manager->dropData->currentDataObject = 0;
- }
-
- return NOERROR;
-}
-
-#define KEY_STATE_BUTTON_MASK (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)
-
-QT_ENSURE_STACK_ALIGNED_FOR_SSE STDMETHODIMP
-QOleDropTarget::Drop(LPDATAOBJECT /*pDataObj*/, DWORD grfKeyState, POINTL pt, LPDWORD pdwEffect)
-{
-#ifdef QDND_DEBUG
- qDebug("QOleDropTarget::Drop(LPDATAOBJECT /*pDataObj*/, grfKeyState %d, POINTL pt, LPDWORD pdwEffect)", grfKeyState);
-#endif
-
- QWidget *dropWidget = widget->childAt(widget->mapFromGlobal(QPoint(pt.x, pt.y)));
- if (!dropWidget)
- dropWidget = widget;
-
- if (!QApplicationPrivate::tryModalHelper(dropWidget)
- || !dropWidget->testAttribute(Qt::WA_DropSiteRegistered)) {
- *pdwEffect = DROPEFFECT_NONE;
- return NOERROR;
- }
-
- lastPoint = dropWidget->mapFromGlobal(QPoint(pt.x,pt.y));
- // grfKeyState does not all ways contain button state in the drop so if
- // it doesn't then use the last known button state;
- if ((grfKeyState & KEY_STATE_BUTTON_MASK) == 0)
- grfKeyState |= lastKeyState & KEY_STATE_BUTTON_MASK;
- lastKeyState = grfKeyState;
-
- QDragManager *manager = QDragManager::self();
- QMimeData *md = manager->source() ? manager->dragPrivate()->data : manager->dropData;
- QDropEvent e(lastPoint, translateToQDragDropActions(*pdwEffect), md,
- toQtMouseButtons(grfKeyState), toQtKeyboardModifiers(grfKeyState));
- if (chosenEffect != DROPEFFECT_NONE) {
- e.setDropAction(translateToQDragDropAction(chosenEffect));
- }
- QApplication::sendEvent(dropWidget, &e);
-
- if (chosenEffect != DROPEFFECT_NONE) {
- e.accept();
- }
-
-
- if (e.isAccepted()) {
- if (e.dropAction() == Qt::MoveAction || e.dropAction() == Qt::TargetMoveAction) {
- if (e.dropAction() == Qt::MoveAction)
- chosenEffect = DROPEFFECT_MOVE;
- else
- chosenEffect = DROPEFFECT_COPY;
- HGLOBAL hData = GlobalAlloc(0, sizeof(DWORD));
- if (hData) {
- DWORD *moveEffect = (DWORD *)GlobalLock(hData);;
- *moveEffect = DROPEFFECT_MOVE;
- GlobalUnlock(hData);
- STGMEDIUM medium;
- memset(&medium, 0, sizeof(STGMEDIUM));
- medium.tymed = TYMED_HGLOBAL;
- medium.hGlobal = hData;
- FORMATETC format;
- format.cfFormat = RegisterClipboardFormat(CFSTR_PERFORMEDDROPEFFECT);
- format.tymed = TYMED_HGLOBAL;
- format.ptd = 0;
- format.dwAspect = 1;
- format.lindex = -1;
- manager->dropData->currentDataObject->SetData(&format, &medium, true);
- }
- } else {
- chosenEffect = translateToWinDragEffects(e.dropAction());
- }
- } else {
- chosenEffect = DROPEFFECT_NONE;
- }
- *pdwEffect = chosenEffect;
-
-
- if (manager->dropData->currentDataObject) {
- manager->dropData->currentDataObject->Release();
- manager->dropData->currentDataObject = 0;
- }
-
- return NOERROR;
-
- // We won't get any mouserelease-event, so manually adjust qApp state:
-///### test this QApplication::winMouseButtonUp();
-}
-
-//---------------------------------------------------------------------
-// QDropData
-//---------------------------------------------------------------------
-
-bool QDropData::hasFormat_sys(const QString &mimeType) const
-{
- if (!currentDataObject) // Sanity
- return false;
-
- return QWindowsMime::converterToMime(mimeType, currentDataObject) != 0;
-}
-
-QStringList QDropData::formats_sys() const
-{
- QStringList fmts;
- if (!currentDataObject) // Sanity
- return fmts;
-
- fmts = QWindowsMime::allMimesForFormats(currentDataObject);
-
- return fmts;
-}
-
-QVariant QDropData::retrieveData_sys(const QString &mimeType, QVariant::Type type) const
-{
- QVariant result;
-
- if (!currentDataObject) // Sanity
- return result;
-
- QWindowsMime *converter = QWindowsMime::converterToMime(mimeType, currentDataObject);
-
- if (converter)
- result = converter->convertToMime(mimeType, currentDataObject, type);
-
- return result;
-}
-
-Qt::DropAction QDragManager::drag(QDrag *o)
-
-{
-#ifdef QDND_DEBUG
- qDebug("QDragManager::drag(QDrag *drag)");
-#endif
-
- if (object == o || !o || !o->d_func()->source)
- return Qt::IgnoreAction;
-
- if (object) {
- cancel();
- qApp->removeEventFilter(this);
- beingCancelled = false;
- }
-
- object = o;
-
-#ifdef QDND_DEBUG
- qDebug("actions = %s", dragActionsToString(dragPrivate()->possible_actions).toLatin1().data());
-#endif
-
- dragPrivate()->target = 0;
-
-#ifndef QT_NO_ACCESSIBILITY
- QAccessible::updateAccessibility(this, 0, QAccessible::DragDropStart);
-#endif
-
- DWORD resultEffect;
- QOleDropSource *src = new QOleDropSource();
- src->createCursors();
- QOleDataObject *obj = new QOleDataObject(o->mimeData());
- DWORD allowedEffects = translateToWinDragEffects(dragPrivate()->possible_actions);
-
-#if !defined(Q_OS_WINCE) || defined(GWES_ICONCURS)
- HRESULT r = DoDragDrop(obj, src, allowedEffects, &resultEffect);
-#else
- HRESULT r = DRAGDROP_S_CANCEL;
- resultEffect = DROPEFFECT_MOVE;
-#endif
-
- Qt::DropAction ret = Qt::IgnoreAction;
- if (r == DRAGDROP_S_DROP) {
- if (obj->reportedPerformedEffect() == DROPEFFECT_MOVE && resultEffect != DROPEFFECT_MOVE) {
- ret = Qt::TargetMoveAction;
- resultEffect = DROPEFFECT_MOVE;
- } else {
- ret = translateToQDragDropAction(resultEffect);
- }
- // Force it to be a copy if an unsupported operation occurred.
- // This indicates a bug in the drop target.
- if (resultEffect != DROPEFFECT_NONE && !(resultEffect & allowedEffects))
- ret = Qt::CopyAction;
- } else {
- dragPrivate()->target = 0;
- }
-
- // clean up
- obj->releaseQt();
- obj->Release(); // Will delete obj if refcount becomes 0
- src->Release(); // Will delete src if refcount becomes 0
- object = 0;
- o->setMimeData(0);
- o->deleteLater();
-
-#ifndef QT_NO_ACCESSIBILITY
- QAccessible::updateAccessibility(this, 0, QAccessible::DragDropEnd);
-#endif
-
- return ret;
-}
-
-void QDragManager::cancel(bool /* deleteSource */)
-{
- if (object) {
- beingCancelled = true;
- object = 0;
- }
-
-#ifndef QT_NO_CURSOR
- // insert cancel code here ######## todo
-
- if (restoreCursor) {
- QApplication::restoreOverrideCursor();
- restoreCursor = false;
- }
-#endif
-#ifndef QT_NO_ACCESSIBILITY
- QAccessible::updateAccessibility(this, 0, QAccessible::DragDropEnd);
-#endif
-}
-
-void QDragManager::updatePixmap()
-{
- // not used in windows implementation
-}
-
-bool QDragManager::eventFilter(QObject *, QEvent *)
-{
- // not used in windows implementation
- return false;
-}
-
-void QDragManager::timerEvent(QTimerEvent*)
-{
- // not used in windows implementation
-}
-
-void QDragManager::move(const QPoint &)
-{
- // not used in windows implementation
-}
-
-void QDragManager::drop()
-{
- // not used in windows implementation
-}
-
-QT_END_NAMESPACE
-
-#endif // QT_NO_DRAGANDDROP
diff --git a/src/gui/kernel/qdnd_x11.cpp b/src/gui/kernel/qdnd_x11.cpp
deleted file mode 100644
index 9ff1543e51..0000000000
--- a/src/gui/kernel/qdnd_x11.cpp
+++ /dev/null
@@ -1,2072 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qplatformdefs.h"
-
-#include "qapplication.h"
-
-#ifndef QT_NO_DRAGANDDROP
-
-#include "qwidget.h"
-#include "qpainter.h"
-#include "qpixmap.h"
-#include "qbitmap.h"
-#include "qdesktopwidget.h"
-#include "qevent.h"
-#include "qiodevice.h"
-#include "qpointer.h"
-#include "qcursor.h"
-#include "qelapsedtimer.h"
-#include "qvariant.h"
-#include "qvector.h"
-#include "qurl.h"
-#include "qdebug.h"
-#include "qimagewriter.h"
-#include "qbuffer.h"
-#include "qtextcodec.h"
-
-#include "qdnd_p.h"
-#include "qapplication_p.h"
-#include "qt_x11_p.h"
-#include "qx11info_x11.h"
-
-#include "qwidget_p.h"
-#include "qcursor_p.h"
-
-QT_BEGIN_NAMESPACE
-
-// #define DND_DEBUG
-#ifdef DND_DEBUG
-#define DEBUG qDebug
-#else
-#define DEBUG if(0) qDebug
-#endif
-
-#ifdef DND_DEBUG
-#define DNDDEBUG qDebug()
-#else
-#define DNDDEBUG if(0) qDebug()
-#endif
-
-static int findXdndDropTransactionByWindow(Window window)
-{
- int at = -1;
- for (int i = 0; i < X11->dndDropTransactions.count(); ++i) {
- const QXdndDropTransaction &t = X11->dndDropTransactions.at(i);
- if (t.target == window || t.proxy_target == window) {
- at = i;
- break;
- }
- }
- return at;
-}
-
-static int findXdndDropTransactionByTime(Time timestamp)
-{
- int at = -1;
- for (int i = 0; i < X11->dndDropTransactions.count(); ++i) {
- const QXdndDropTransaction &t = X11->dndDropTransactions.at(i);
- if (t.timestamp == timestamp) {
- at = i;
- break;
- }
- }
- return at;
-}
-
-// timer used to discard old XdndDrop transactions
-static int transaction_expiry_timer = -1;
-enum { XdndDropTransactionTimeout = 5000 }; // 5 seconds
-
-static void restartXdndDropExpiryTimer()
-{
- if (transaction_expiry_timer != -1)
- QDragManager::self()->killTimer(transaction_expiry_timer);
- transaction_expiry_timer = QDragManager::self()->startTimer(XdndDropTransactionTimeout);
-}
-
-
-// find an ancestor with XdndAware on it
-static Window findXdndAwareParent(Window window)
-{
- Window target = 0;
- forever {
- // check if window has XdndAware
- Atom type = 0;
- int f;
- unsigned long n, a;
- unsigned char *data = 0;
- if (XGetWindowProperty(X11->display, window, ATOM(XdndAware), 0, 0, False,
- AnyPropertyType, &type, &f,&n,&a,&data) == Success) {
- if (data)
- XFree(data);
- if (type) {
- target = window;
- break;
- }
- }
-
- // try window's parent
- Window root;
- Window parent;
- Window *children;
- uint unused;
- if (!XQueryTree(X11->display, window, &root, &parent, &children, &unused))
- break;
- if (children)
- XFree(children);
- if (window == root)
- break;
- window = parent;
- }
- return target;
-}
-
-
-
-
-// and all this stuff is copied -into- qapp_x11.cpp
-
-static void handle_xdnd_position(QWidget *, const XEvent *, bool);
-static void handle_xdnd_status(QWidget * w, const XEvent * xe, bool /*passive*/);
-
-const int xdnd_version = 5;
-
-static Qt::DropAction xdndaction_to_qtaction(Atom atom)
-{
- if (atom == ATOM(XdndActionCopy) || atom == 0)
- return Qt::CopyAction;
- if (atom == ATOM(XdndActionLink))
- return Qt::LinkAction;
- if (atom == ATOM(XdndActionMove))
- return Qt::MoveAction;
- return Qt::CopyAction;
-}
-
-static int qtaction_to_xdndaction(Qt::DropAction a)
-{
- switch (a) {
- case Qt::CopyAction:
- return ATOM(XdndActionCopy);
- case Qt::LinkAction:
- return ATOM(XdndActionLink);
- case Qt::MoveAction:
- case Qt::TargetMoveAction:
- return ATOM(XdndActionMove);
- case Qt::IgnoreAction:
- return XNone;
- default:
- return ATOM(XdndActionCopy);
- }
-}
-
-// clean up the stuff used.
-static void qt_xdnd_cleanup();
-
-static void qt_xdnd_send_leave();
-
-// real variables:
-// xid of current drag source
-static Atom qt_xdnd_dragsource_xid = 0;
-
-// the types in this drop. 100 is no good, but at least it's big.
-const int qt_xdnd_max_type = 100;
-static Atom qt_xdnd_types[qt_xdnd_max_type + 1];
-
-// timer used when target wants "continuous" move messages (eg. scroll)
-static int heartbeat = -1;
-// rectangle in which the answer will be the same
-static QRect qt_xdnd_source_sameanswer;
-// top-level window we sent position to last.
-static Window qt_xdnd_current_target;
-// window to send events to (always valid if qt_xdnd_current_target)
-static Window qt_xdnd_current_proxy_target;
-static Time qt_xdnd_source_current_time;
-
-// widget we forwarded position to last, and local position
-static QPointer<QWidget> qt_xdnd_current_widget;
-static QPoint qt_xdnd_current_position;
-// timestamp from the XdndPosition and XdndDrop
-static Time qt_xdnd_target_current_time;
-// screen number containing the pointer... -1 means default
-static int qt_xdnd_current_screen = -1;
-// state of dragging... true if dragging, false if not
-bool qt_xdnd_dragging = false;
-
-static bool waiting_for_status = false;
-
-// used to preset each new QDragMoveEvent
-static Qt::DropAction last_target_accepted_action = Qt::IgnoreAction;
-
-// Shift/Ctrl handling, and final drop status
-static Qt::DropAction global_accepted_action = Qt::CopyAction;
-static Qt::DropActions possible_actions = Qt::IgnoreAction;
-
-// for embedding only
-static QWidget* current_embedding_widget = 0;
-static XEvent last_enter_event;
-
-// cursors
-static QCursor *noDropCursor = 0;
-static QCursor *moveCursor = 0;
-static QCursor *copyCursor = 0;
-static QCursor *linkCursor = 0;
-
-static QPixmap *defaultPm = 0;
-
-static const int default_pm_hotx = -2;
-static const int default_pm_hoty = -16;
-static const char* const default_pm[] = {
-"13 9 3 1",
-". c None",
-" c #000000",
-"X c #FFFFFF",
-"X X X X X X X",
-" X X X X X X ",
-"X ......... X",
-" X.........X ",
-"X ......... X",
-" X.........X ",
-"X ......... X",
-" X X X X X X ",
-"X X X X X X X"
-};
-
-class QShapedPixmapWidget : public QWidget
-{
- Q_OBJECT
-public:
- QShapedPixmapWidget(QWidget* w) :
- QWidget(w,
- Qt::Tool | Qt::FramelessWindowHint
- | Qt::X11BypassWindowManagerHint
- | Qt::BypassGraphicsProxyWidget)
- {
- setAttribute(Qt::WA_X11NetWmWindowTypeDND);
- }
-
- void setPixmap(const QPixmap &pm)
- {
- QBitmap mask = pm.mask();
- if (!mask.isNull()) {
- setMask(mask);
- } else {
- clearMask();
- }
- resize(pm.width(),pm.height());
- pixmap = pm;
- update();
- }
- QPoint pm_hot;
-
-protected:
- QPixmap pixmap;
- void paintEvent(QPaintEvent*)
- {
- QPainter p(this);
- p.drawPixmap(0, 0, pixmap);
- }
-};
-
-#include "qdnd_x11.moc"
-
-struct XdndData {
- QShapedPixmapWidget *deco;
- QWidget* desktop_proxy;
-};
-
-static XdndData xdnd_data = { 0, 0 };
-
-class QExtraWidget : public QWidget
-{
- Q_DECLARE_PRIVATE(QWidget)
-public:
- inline QWExtra* extraData();
- inline QTLWExtra* topData();
-};
-
-inline QWExtra* QExtraWidget::extraData() { return d_func()->extraData(); }
-inline QTLWExtra* QExtraWidget::topData() { return d_func()->topData(); }
-
-
-static WId xdndProxy(WId w)
-{
- Atom type = XNone;
- int f;
- unsigned long n, a;
- unsigned char *retval = 0;
- XGetWindowProperty(X11->display, w, ATOM(XdndProxy), 0, 1, False,
- XA_WINDOW, &type, &f,&n,&a,&retval);
- WId *proxy_id_ptr = (WId *)retval;
- WId proxy_id = 0;
- if (type == XA_WINDOW && proxy_id_ptr) {
- proxy_id = *proxy_id_ptr;
- XFree(proxy_id_ptr);
- proxy_id_ptr = 0;
- // Already exists. Real?
- X11->ignoreBadwindow();
- XGetWindowProperty(X11->display, proxy_id, ATOM(XdndProxy), 0, 1, False,
- XA_WINDOW, &type, &f,&n,&a,&retval);
- proxy_id_ptr = (WId *)retval;
- if (X11->badwindow() || type != XA_WINDOW || !proxy_id_ptr || *proxy_id_ptr != proxy_id)
- // Bogus - we will overwrite.
- proxy_id = 0;
- }
- if (proxy_id_ptr)
- XFree(proxy_id_ptr);
- return proxy_id;
-}
-
-static bool xdndEnable(QWidget* w, bool on)
-{
- DNDDEBUG << "xdndEnable" << w << on;
- if (on) {
- QWidget * xdnd_widget = 0;
- if ((w->windowType() == Qt::Desktop)) {
- if (xdnd_data.desktop_proxy) // *WE* already have one.
- return false;
-
- // As per Xdnd4, use XdndProxy
- XGrabServer(X11->display);
- Q_ASSERT(w->testAttribute(Qt::WA_WState_Created));
- WId proxy_id = xdndProxy(w->effectiveWinId());
-
- if (!proxy_id) {
- xdnd_widget = xdnd_data.desktop_proxy = new QWidget;
- proxy_id = xdnd_data.desktop_proxy->effectiveWinId();
- XChangeProperty (X11->display, w->effectiveWinId(), ATOM(XdndProxy),
- XA_WINDOW, 32, PropModeReplace, (unsigned char *)&proxy_id, 1);
- XChangeProperty (X11->display, proxy_id, ATOM(XdndProxy),
- XA_WINDOW, 32, PropModeReplace, (unsigned char *)&proxy_id, 1);
- }
-
- XUngrabServer(X11->display);
- } else {
- xdnd_widget = w->window();
- }
- if (xdnd_widget) {
- DNDDEBUG << "setting XdndAware for" << xdnd_widget << xdnd_widget->effectiveWinId();
- Atom atm = (Atom)xdnd_version;
- Q_ASSERT(xdnd_widget->testAttribute(Qt::WA_WState_Created));
- XChangeProperty(X11->display, xdnd_widget->effectiveWinId(), ATOM(XdndAware),
- XA_ATOM, 32, PropModeReplace, (unsigned char *)&atm, 1);
- return true;
- } else {
- return false;
- }
- } else {
- if ((w->windowType() == Qt::Desktop)) {
- XDeleteProperty(X11->display, w->internalWinId(), ATOM(XdndProxy));
- delete xdnd_data.desktop_proxy;
- xdnd_data.desktop_proxy = 0;
- } else {
- DNDDEBUG << "not deleting XDndAware";
- }
- return true;
- }
-}
-
-QByteArray QX11Data::xdndAtomToString(Atom a)
-{
- if (!a) return 0;
-
- if (a == XA_STRING || a == ATOM(UTF8_STRING)) {
- return "text/plain"; // some Xdnd clients are dumb
- }
- char *atom = XGetAtomName(display, a);
- QByteArray result = atom;
- XFree(atom);
- return result;
-}
-
-Atom QX11Data::xdndStringToAtom(const char *mimeType)
-{
- if (!mimeType || !*mimeType)
- return 0;
- return XInternAtom(display, mimeType, False);
-}
-
-//$$$
-QString QX11Data::xdndMimeAtomToString(Atom a)
-{
- QString atomName;
- if (a) {
- char *atom = XGetAtomName(display, a);
- atomName = QString::fromLatin1(atom);
- XFree(atom);
- }
- return atomName;
-}
-
-//$$$
-Atom QX11Data::xdndMimeStringToAtom(const QString &mimeType)
-{
- if (mimeType.isEmpty())
- return 0;
- return XInternAtom(display, mimeType.toLatin1().constData(), False);
-}
-
-//$$$ replace ccxdndAtomToString()
-QStringList QX11Data::xdndMimeFormatsForAtom(Atom a)
-{
- QStringList formats;
- if (a) {
- QString atomName = xdndMimeAtomToString(a);
- formats.append(atomName);
-
- // special cases for string type
- if (a == ATOM(UTF8_STRING) || a == XA_STRING
- || a == ATOM(TEXT) || a == ATOM(COMPOUND_TEXT))
- formats.append(QLatin1String("text/plain"));
-
- // special cases for uris
- if (atomName == QLatin1String("text/x-moz-url"))
- formats.append(QLatin1String("text/uri-list"));
-
- // special case for images
- if (a == XA_PIXMAP)
- formats.append(QLatin1String("image/ppm"));
- }
- return formats;
-}
-
-//$$$
-bool QX11Data::xdndMimeDataForAtom(Atom a, QMimeData *mimeData, QByteArray *data, Atom *atomFormat, int *dataFormat)
-{
- bool ret = false;
- *atomFormat = a;
- *dataFormat = 8;
- QString atomName = xdndMimeAtomToString(a);
- if (QInternalMimeData::hasFormatHelper(atomName, mimeData)) {
- *data = QInternalMimeData::renderDataHelper(atomName, mimeData);
- if (atomName == QLatin1String("application/x-color"))
- *dataFormat = 16;
- ret = true;
- } else {
- if ((a == ATOM(UTF8_STRING) || a == XA_STRING
- || a == ATOM(TEXT) || a == ATOM(COMPOUND_TEXT))
- && QInternalMimeData::hasFormatHelper(QLatin1String("text/plain"), mimeData)) {
- if (a == ATOM(UTF8_STRING)){
- *data = QInternalMimeData::renderDataHelper(QLatin1String("text/plain"), mimeData);
- ret = true;
- } else if (a == XA_STRING) {
- *data = QString::fromUtf8(QInternalMimeData::renderDataHelper(
- QLatin1String("text/plain"), mimeData)).toLocal8Bit();
- ret = true;
- } else if (a == ATOM(TEXT) || a == ATOM(COMPOUND_TEXT)) {
- // the ICCCM states that TEXT and COMPOUND_TEXT are in the
- // encoding of choice, so we choose the encoding of the locale
- QByteArray strData = QString::fromUtf8(QInternalMimeData::renderDataHelper(
- QLatin1String("text/plain"), mimeData)).toLocal8Bit();
- char *list[] = { strData.data(), NULL };
-
- XICCEncodingStyle style = (a == ATOM(COMPOUND_TEXT))
- ? XCompoundTextStyle : XStdICCTextStyle;
- XTextProperty textprop;
- if (list[0] != NULL
- && XmbTextListToTextProperty(X11->display, list, 1, style,
- &textprop) == Success) {
- *atomFormat = textprop.encoding;
- *dataFormat = textprop.format;
- *data = QByteArray((const char *) textprop.value, textprop.nitems * textprop.format / 8);
- ret = true;
-
- DEBUG(" textprop type %lx\n"
- " textprop name '%s'\n"
- " format %d\n"
- " %ld items\n"
- " %d bytes\n",
- textprop.encoding,
- X11->xdndMimeAtomToString(textprop.encoding).toLatin1().data(),
- textprop.format, textprop.nitems, data->size());
-
- XFree(textprop.value);
- }
- }
- } else if (atomName == QLatin1String("text/x-moz-url") &&
- QInternalMimeData::hasFormatHelper(QLatin1String("text/uri-list"), mimeData)) {
- QByteArray uri = QInternalMimeData::renderDataHelper(
- QLatin1String("text/uri-list"), mimeData).split('\n').first();
- QString mozUri = QString::fromLatin1(uri, uri.size());
- mozUri += QLatin1Char('\n');
- *data = QByteArray(reinterpret_cast<const char *>(mozUri.utf16()), mozUri.length() * 2);
- ret = true;
- } else if ((a == XA_PIXMAP || a == XA_BITMAP) && mimeData->hasImage()) {
- QPixmap pm = qvariant_cast<QPixmap>(mimeData->imageData());
- if (a == XA_BITMAP && pm.depth() != 1) {
- QImage img = pm.toImage();
- img = img.convertToFormat(QImage::Format_MonoLSB);
- pm = QPixmap::fromImage(img);
- }
- QDragManager *dm = QDragManager::self();
- if (dm) {
- Pixmap handle = pm.handle();
- *data = QByteArray((const char *) &handle, sizeof(Pixmap));
- dm->xdndMimeTransferedPixmap[dm->xdndMimeTransferedPixmapIndex] = pm;
- dm->xdndMimeTransferedPixmapIndex =
- (dm->xdndMimeTransferedPixmapIndex + 1) % 2;
- ret = true;
- }
- } else {
- DEBUG("QClipboard: xdndMimeDataForAtom(): converting to type '%s' is not supported", qPrintable(atomName));
- }
- }
- return ret && data != 0;
-}
-
-//$$$
-QList<Atom> QX11Data::xdndMimeAtomsForFormat(const QString &format)
-{
- QList<Atom> atoms;
- atoms.append(xdndMimeStringToAtom(format));
-
- // special cases for strings
- if (format == QLatin1String("text/plain")) {
- atoms.append(ATOM(UTF8_STRING));
- atoms.append(XA_STRING);
- atoms.append(ATOM(TEXT));
- atoms.append(ATOM(COMPOUND_TEXT));
- }
-
- // special cases for uris
- if (format == QLatin1String("text/uri-list")) {
- atoms.append(xdndMimeStringToAtom(QLatin1String("text/x-moz-url")));
- }
-
- //special cases for images
- if (format == QLatin1String("image/ppm"))
- atoms.append(XA_PIXMAP);
- if (format == QLatin1String("image/pbm"))
- atoms.append(XA_BITMAP);
-
- return atoms;
-}
-
-//$$$
-QVariant QX11Data::xdndMimeConvertToFormat(Atom a, const QByteArray &data, const QString &format, QVariant::Type requestedType, const QByteArray &encoding)
-{
- QString atomName = xdndMimeAtomToString(a);
- if (atomName == format)
- return data;
-
- if (!encoding.isEmpty()
- && atomName == format + QLatin1String(";charset=") + QString::fromLatin1(encoding)) {
-
- if (requestedType == QVariant::String) {
- QTextCodec *codec = QTextCodec::codecForName(encoding);
- if (codec)
- return codec->toUnicode(data);
- }
-
- return data;
- }
-
- // special cases for string types
- if (format == QLatin1String("text/plain")) {
- if (a == ATOM(UTF8_STRING))
- return QString::fromUtf8(data);
- if (a == XA_STRING)
- return QString::fromLatin1(data);
- if (a == ATOM(TEXT) || a == ATOM(COMPOUND_TEXT))
- // #### might be wrong for COMPUND_TEXT
- return QString::fromLocal8Bit(data, data.size());
- }
-
- // special case for uri types
- if (format == QLatin1String("text/uri-list")) {
- if (atomName == QLatin1String("text/x-moz-url")) {
- // we expect this as utf16 <url><space><title>
- // the first part is a url that should only contain ascci char
- // so it should be safe to check that the second char is 0
- // to verify that it is utf16
- if (data.size() > 1 && data.at(1) == 0)
- return QString::fromRawData((const QChar *)data.constData(),
- data.size() / 2).split(QLatin1Char('\n')).first().toLatin1();
- }
- }
-
- // special cas for images
- if (format == QLatin1String("image/ppm")) {
- if (a == XA_PIXMAP && data.size() == sizeof(Pixmap)) {
- Pixmap xpm = *((Pixmap*)data.data());
- if (!xpm)
- return QByteArray();
- QPixmap qpm = QPixmap::fromX11Pixmap(xpm);
- QImageWriter imageWriter;
- imageWriter.setFormat("PPMRAW");
- QImage imageToWrite = qpm.toImage();
- QBuffer buf;
- buf.open(QIODevice::WriteOnly);
- imageWriter.setDevice(&buf);
- imageWriter.write(imageToWrite);
- return buf.buffer();
- }
- }
- return QVariant();
-}
-
-//$$$ middle of xdndObtainData
-Atom QX11Data::xdndMimeAtomForFormat(const QString &format, QVariant::Type requestedType, const QList<Atom> &atoms, QByteArray *encoding)
-{
- encoding->clear();
-
- // find matches for string types
- if (format == QLatin1String("text/plain")) {
- if (atoms.contains(ATOM(UTF8_STRING)))
- return ATOM(UTF8_STRING);
- if (atoms.contains(ATOM(COMPOUND_TEXT)))
- return ATOM(COMPOUND_TEXT);
- if (atoms.contains(ATOM(TEXT)))
- return ATOM(TEXT);
- if (atoms.contains(XA_STRING))
- return XA_STRING;
- }
-
- // find matches for uri types
- if (format == QLatin1String("text/uri-list")) {
- Atom a = xdndMimeStringToAtom(format);
- if (a && atoms.contains(a))
- return a;
- a = xdndMimeStringToAtom(QLatin1String("text/x-moz-url"));
- if (a && atoms.contains(a))
- return a;
- }
-
- // find match for image
- if (format == QLatin1String("image/ppm")) {
- if (atoms.contains(XA_PIXMAP))
- return XA_PIXMAP;
- }
-
- // for string/text requests try to use a format with a well-defined charset
- // first to avoid encoding problems
- if (requestedType == QVariant::String
- && format.startsWith(QLatin1String("text/"))
- && !format.contains(QLatin1String("charset="))) {
-
- QString formatWithCharset = format;
- formatWithCharset.append(QLatin1String(";charset=utf-8"));
-
- Atom a = xdndMimeStringToAtom(formatWithCharset);
- if (a && atoms.contains(a)) {
- *encoding = "utf-8";
- return a;
- }
- }
-
- Atom a = xdndMimeStringToAtom(format);
- if (a && atoms.contains(a))
- return a;
-
- return 0;
-}
-
-void QX11Data::xdndSetup() {
- QCursorData::initialize();
- qAddPostRoutine(qt_xdnd_cleanup);
-}
-
-
-void qt_xdnd_cleanup()
-{
- delete noDropCursor;
- noDropCursor = 0;
- delete copyCursor;
- copyCursor = 0;
- delete moveCursor;
- moveCursor = 0;
- delete linkCursor;
- linkCursor = 0;
- delete defaultPm;
- defaultPm = 0;
- delete xdnd_data.desktop_proxy;
- xdnd_data.desktop_proxy = 0;
- delete xdnd_data.deco;
- xdnd_data.deco = 0;
-}
-
-
-static QWidget *find_child(QWidget *tlw, QPoint & p)
-{
- QWidget *widget = tlw;
-
- p = widget->mapFromGlobal(p);
- bool done = false;
- while (!done) {
- done = true;
- if (((QExtraWidget*)widget)->extraData() &&
- ((QExtraWidget*)widget)->extraData()->xDndProxy != 0)
- break; // stop searching for widgets under the mouse cursor if found widget is a proxy.
- QObjectList children = widget->children();
- if (!children.isEmpty()) {
- for(int i = children.size(); i > 0;) {
- --i;
- QWidget *w = qobject_cast<QWidget *>(children.at(i));
- if (!w)
- continue;
- if (w->testAttribute(Qt::WA_TransparentForMouseEvents))
- continue;
- if (w->isVisible() &&
- w->geometry().contains(p) &&
- !w->isWindow()) {
- widget = w;
- done = false;
- p = widget->mapFromParent(p);
- break;
- }
- }
- }
- }
- return widget;
-}
-
-
-static bool checkEmbedded(QWidget* w, const XEvent* xe)
-{
- if (!w)
- return false;
-
- if (current_embedding_widget != 0 && current_embedding_widget != w) {
- qt_xdnd_current_target = ((QExtraWidget*)current_embedding_widget)->extraData()->xDndProxy;
- qt_xdnd_current_proxy_target = qt_xdnd_current_target;
- qt_xdnd_send_leave();
- qt_xdnd_current_target = 0;
- qt_xdnd_current_proxy_target = 0;
- current_embedding_widget = 0;
- }
-
- QWExtra* extra = ((QExtraWidget*)w)->extraData();
- if (extra && extra->xDndProxy != 0) {
-
- if (current_embedding_widget != w) {
-
- last_enter_event.xany.window = extra->xDndProxy;
- XSendEvent(X11->display, extra->xDndProxy, False, NoEventMask, &last_enter_event);
- current_embedding_widget = w;
- }
-
- ((XEvent*)xe)->xany.window = extra->xDndProxy;
- XSendEvent(X11->display, extra->xDndProxy, False, NoEventMask, (XEvent*)xe);
- if (qt_xdnd_current_widget != w) {
- qt_xdnd_current_widget = w;
- }
- return true;
- }
- current_embedding_widget = 0;
- return false;
-}
-
-void QX11Data::xdndHandleEnter(QWidget *, const XEvent * xe, bool /*passive*/)
-{
- motifdnd_active = false;
-
- last_enter_event.xclient = xe->xclient;
-
- const long *l = xe->xclient.data.l;
- int version = (int)(((unsigned long)(l[1])) >> 24);
-
- if (version > xdnd_version)
- return;
-
- qt_xdnd_dragsource_xid = l[0];
-
- int j = 0;
- if (l[1] & 1) {
- // get the types from XdndTypeList
- Atom type = XNone;
- int f;
- unsigned long n, a;
- unsigned char *retval = 0;
- XGetWindowProperty(X11->display, qt_xdnd_dragsource_xid, ATOM(XdndTypelist), 0,
- qt_xdnd_max_type, False, XA_ATOM, &type, &f,&n,&a,&retval);
- if (retval) {
- Atom *data = (Atom *)retval;
- for (; j<qt_xdnd_max_type && j < (int)n; j++) {
- qt_xdnd_types[j] = data[j];
- }
- XFree((uchar*)data);
- }
- } else {
- // get the types from the message
- int i;
- for(i=2; i < 5; i++) {
- qt_xdnd_types[j++] = l[i];
- }
- }
- qt_xdnd_types[j] = 0;
-}
-
-static void handle_xdnd_position(QWidget *w, const XEvent * xe, bool passive)
-{
- const unsigned long *l = (const unsigned long *)xe->xclient.data.l;
-
- QPoint p((l[2] & 0xffff0000) >> 16, l[2] & 0x0000ffff);
- QWidget * c = find_child(w, p); // changes p to to c-local coordinates
-
- if (!passive && checkEmbedded(c, xe))
- return;
-
- if (!c || (!c->acceptDrops() && (c->windowType() == Qt::Desktop)))
- return;
-
- if (l[0] != qt_xdnd_dragsource_xid) {
- DEBUG("xdnd drag position from unexpected source (%08lx not %08lx)", l[0], qt_xdnd_dragsource_xid);
- return;
- }
-
- // timestamp from the source
- if (l[3] != 0) {
- // Some X server/client combination swallow the first 32 bit and
- // interpret a set bit 31 as negative sign.
- qt_xdnd_target_current_time = X11->userTime =
- ((sizeof(Time) == 8 && xe->xclient.data.l[3] < 0)
- ? uint(l[3])
- : l[3]);
- }
-
- QDragManager *manager = QDragManager::self();
- QMimeData *dropData = manager->object ? manager->dragPrivate()->data : manager->dropData;
-
- XClientMessageEvent response;
- response.type = ClientMessage;
- response.window = qt_xdnd_dragsource_xid;
- response.format = 32;
- response.message_type = ATOM(XdndStatus);
- response.data.l[0] = w->effectiveWinId();
- response.data.l[1] = 0; // flags
- response.data.l[2] = 0; // x, y
- response.data.l[3] = 0; // w, h
- response.data.l[4] = 0; // action
-
- if (!passive) { // otherwise just reject
- while (c && !c->acceptDrops() && !c->isWindow()) {
- p = c->mapToParent(p);
- c = c->parentWidget();
- }
- QWidget *target_widget = c && c->acceptDrops() ? c : 0;
-
- QRect answerRect(c->mapToGlobal(p), QSize(1,1));
-
- if (manager->object) {
- possible_actions = manager->dragPrivate()->possible_actions;
- } else {
- possible_actions = Qt::DropActions(xdndaction_to_qtaction(l[4]));
-// possible_actions |= Qt::CopyAction;
- }
- QDragMoveEvent me(p, possible_actions, dropData, QApplication::mouseButtons(), QApplication::keyboardModifiers());
-
- Qt::DropAction accepted_action = Qt::IgnoreAction;
-
-
- if (target_widget != qt_xdnd_current_widget) {
- if (qt_xdnd_current_widget) {
- QDragLeaveEvent e;
- QApplication::sendEvent(qt_xdnd_current_widget, &e);
- }
- if (qt_xdnd_current_widget != target_widget) {
- qt_xdnd_current_widget = target_widget;
- }
- if (target_widget) {
- qt_xdnd_current_position = p;
-
- last_target_accepted_action = Qt::IgnoreAction;
- QDragEnterEvent de(p, possible_actions, dropData, QApplication::mouseButtons(), QApplication::keyboardModifiers());
- QApplication::sendEvent(target_widget, &de);
- if (de.isAccepted() && de.dropAction() != Qt::IgnoreAction)
- last_target_accepted_action = de.dropAction();
- }
- }
-
- DEBUG() << "qt_handle_xdnd_position action=" << X11->xdndAtomToString(l[4]);
- if (!target_widget) {
- answerRect = QRect(p, QSize(1, 1));
- } else {
- qt_xdnd_current_widget = c;
- qt_xdnd_current_position = p;
-
- if (last_target_accepted_action != Qt::IgnoreAction) {
- me.setDropAction(last_target_accepted_action);
- me.accept();
- }
- QApplication::sendEvent(c, &me);
- if (me.isAccepted()) {
- response.data.l[1] = 1; // yes
- accepted_action = me.dropAction();
- last_target_accepted_action = accepted_action;
- } else {
- response.data.l[0] = 0;
- last_target_accepted_action = Qt::IgnoreAction;
- }
- answerRect = me.answerRect().intersected(c->rect());
- }
- answerRect = QRect(c->mapToGlobal(answerRect.topLeft()), answerRect.size());
-
- if (answerRect.left() < 0)
- answerRect.setLeft(0);
- if (answerRect.right() > 4096)
- answerRect.setRight(4096);
- if (answerRect.top() < 0)
- answerRect.setTop(0);
- if (answerRect.bottom() > 4096)
- answerRect.setBottom(4096);
- if (answerRect.width() < 0)
- answerRect.setWidth(0);
- if (answerRect.height() < 0)
- answerRect.setHeight(0);
-
- response.data.l[2] = (answerRect.x() << 16) + answerRect.y();
- response.data.l[3] = (answerRect.width() << 16) + answerRect.height();
- response.data.l[4] = qtaction_to_xdndaction(accepted_action);
- }
-
- // reset
- qt_xdnd_target_current_time = CurrentTime;
-
- QWidget * source = QWidget::find(qt_xdnd_dragsource_xid);
- if (source && (source->windowType() == Qt::Desktop) && !source->acceptDrops())
- source = 0;
-
- DEBUG() << "sending XdndStatus";
- if (source)
- handle_xdnd_status(source, (const XEvent *)&response, passive);
- else
- XSendEvent(X11->display, qt_xdnd_dragsource_xid, False, NoEventMask, (XEvent*)&response);
-}
-
-static Bool xdnd_position_scanner(Display *, XEvent *event, XPointer)
-{
- if (event->type != ClientMessage)
- return false;
- XClientMessageEvent *ev = &event->xclient;
-
- if (ev->message_type == ATOM(XdndPosition))
- return true;
-
- return false;
-}
-
-void QX11Data::xdndHandlePosition(QWidget * w, const XEvent * xe, bool passive)
-{
- DEBUG("xdndHandlePosition");
- while (XCheckIfEvent(X11->display, (XEvent *)xe, xdnd_position_scanner, 0))
- ;
-
- handle_xdnd_position(w, xe, passive);
-}
-
-
-static void handle_xdnd_status(QWidget *, const XEvent * xe, bool)
-{
- const unsigned long *l = (const unsigned long *)xe->xclient.data.l;
- // ignore late status messages
- if (l[0] && l[0] != qt_xdnd_current_proxy_target)
- return;
- Qt::DropAction newAction = (l[1] & 0x1) ? xdndaction_to_qtaction(l[4]) : Qt::IgnoreAction;
-
- if ((int)(l[1] & 2) == 0) {
- QPoint p((l[2] & 0xffff0000) >> 16, l[2] & 0x0000ffff);
- QSize s((l[3] & 0xffff0000) >> 16, l[3] & 0x0000ffff);
- qt_xdnd_source_sameanswer = QRect(p, s);
- } else {
- qt_xdnd_source_sameanswer = QRect();
- }
- QDragManager *manager = QDragManager::self();
- manager->willDrop = (l[1] & 0x1);
- if (global_accepted_action != newAction)
- manager->emitActionChanged(newAction);
- global_accepted_action = newAction;
- manager->updateCursor();
- waiting_for_status = false;
-}
-
-static Bool xdnd_status_scanner(Display *, XEvent *event, XPointer)
-{
- if (event->type != ClientMessage)
- return false;
- XClientMessageEvent *ev = &event->xclient;
-
- if (ev->message_type == ATOM(XdndStatus))
- return true;
-
- return false;
-}
-
-void QX11Data::xdndHandleStatus(QWidget * w, const XEvent * xe, bool passive)
-{
- DEBUG("xdndHandleStatus");
- while (XCheckIfEvent(X11->display, (XEvent *)xe, xdnd_status_scanner, 0))
- ;
-
- handle_xdnd_status(w, xe, passive);
- DEBUG("xdndHandleStatus end");
-}
-
-void QX11Data::xdndHandleLeave(QWidget *w, const XEvent * xe, bool /*passive*/)
-{
- DEBUG("xdnd leave");
- if (!qt_xdnd_current_widget ||
- w->window() != qt_xdnd_current_widget->window()) {
- return; // sanity
- }
-
- if (checkEmbedded(current_embedding_widget, xe)) {
- current_embedding_widget = 0;
- qt_xdnd_current_widget = 0;
- return;
- }
-
- const unsigned long *l = (const unsigned long *)xe->xclient.data.l;
-
- QDragLeaveEvent e;
- QApplication::sendEvent(qt_xdnd_current_widget, &e);
-
- if (l[0] != qt_xdnd_dragsource_xid) {
- // This often happens - leave other-process window quickly
- DEBUG("xdnd drag leave from unexpected source (%08lx not %08lx", l[0], qt_xdnd_dragsource_xid);
- qt_xdnd_current_widget = 0;
- return;
- }
-
- qt_xdnd_dragsource_xid = 0;
- qt_xdnd_types[0] = 0;
- qt_xdnd_current_widget = 0;
-}
-
-
-void qt_xdnd_send_leave()
-{
- if (!qt_xdnd_current_target)
- return;
-
- QDragManager *manager = QDragManager::self();
-
- XClientMessageEvent leave;
- leave.type = ClientMessage;
- leave.window = qt_xdnd_current_target;
- leave.format = 32;
- leave.message_type = ATOM(XdndLeave);
- leave.data.l[0] = manager->dragPrivate()->source->effectiveWinId();
- leave.data.l[1] = 0; // flags
- leave.data.l[2] = 0; // x, y
- leave.data.l[3] = 0; // w, h
- leave.data.l[4] = 0; // just null
-
- QWidget * w = QWidget::find(qt_xdnd_current_proxy_target);
-
- if (w && (w->windowType() == Qt::Desktop) && !w->acceptDrops())
- w = 0;
-
- if (w)
- X11->xdndHandleLeave(w, (const XEvent *)&leave, false);
- else
- XSendEvent(X11->display, qt_xdnd_current_proxy_target, False,
- NoEventMask, (XEvent*)&leave);
-
- // reset the drag manager state
- manager->willDrop = false;
- if (global_accepted_action != Qt::IgnoreAction)
- manager->emitActionChanged(Qt::IgnoreAction);
- global_accepted_action = Qt::IgnoreAction;
- manager->updateCursor();
- qt_xdnd_current_target = 0;
- qt_xdnd_current_proxy_target = 0;
- qt_xdnd_source_current_time = 0;
- waiting_for_status = false;
-}
-
-// TODO: remove and use QApplication::currentKeyboardModifiers() in Qt 4.8.
-static Qt::KeyboardModifiers currentKeyboardModifiers()
-{
- Window root;
- Window child;
- int root_x, root_y, win_x, win_y;
- uint keybstate;
- for (int i = 0; i < ScreenCount(X11->display); ++i) {
- if (XQueryPointer(X11->display, QX11Info::appRootWindow(i), &root, &child,
- &root_x, &root_y, &win_x, &win_y, &keybstate))
- return X11->translateModifiers(keybstate & 0x00ff);
- }
- return 0;
-}
-
-void QX11Data::xdndHandleDrop(QWidget *, const XEvent * xe, bool passive)
-{
- DEBUG("xdndHandleDrop");
- if (!qt_xdnd_current_widget) {
- qt_xdnd_dragsource_xid = 0;
- return; // sanity
- }
-
- if (!passive && checkEmbedded(qt_xdnd_current_widget, xe)){
- current_embedding_widget = 0;
- qt_xdnd_dragsource_xid = 0;
- qt_xdnd_current_widget = 0;
- return;
- }
- const unsigned long *l = (const unsigned long *)xe->xclient.data.l;
-
- QDragManager *manager = QDragManager::self();
- DEBUG("xdnd drop");
-
- if (l[0] != qt_xdnd_dragsource_xid) {
- DEBUG("xdnd drop from unexpected source (%08lx not %08lx", l[0], qt_xdnd_dragsource_xid);
- return;
- }
-
- // update the "user time" from the timestamp in the event.
- if (l[2] != 0) {
- // Some X server/client combination swallow the first 32 bit and
- // interpret a set bit 31 as negative sign.
- qt_xdnd_target_current_time = X11->userTime =
- ((sizeof(Time) == 8 && xe->xclient.data.l[2] < 0)
- ? uint(l[2])
- : l[2]);
- }
-
- if (!passive) {
- // this could be a same-application drop, just proxied due to
- // some XEMBEDding, so try to find the real QMimeData used
- // based on the timestamp for this drop.
- QMimeData *dropData = 0;
- int at = findXdndDropTransactionByTime(qt_xdnd_target_current_time);
- if (at != -1)
- dropData = QDragManager::dragPrivate(X11->dndDropTransactions.at(at).object)->data;
- // if we can't find it, then use the data in the drag manager
- if (!dropData)
- dropData = (manager->object) ? manager->dragPrivate()->data : manager->dropData;
-
- // Drop coming from another app? Update keyboard modifiers.
- if (!qt_xdnd_dragging) {
- QApplicationPrivate::modifier_buttons = currentKeyboardModifiers();
- }
-
- QDropEvent de(qt_xdnd_current_position, possible_actions, dropData,
- QApplication::mouseButtons(), QApplication::keyboardModifiers());
- QApplication::sendEvent(qt_xdnd_current_widget, &de);
- if (!de.isAccepted()) {
- // Ignore a failed drag
- global_accepted_action = Qt::IgnoreAction;
- } else {
- global_accepted_action = de.dropAction();
- }
- XClientMessageEvent finished;
- finished.type = ClientMessage;
- finished.window = qt_xdnd_dragsource_xid;
- finished.format = 32;
- finished.message_type = ATOM(XdndFinished);
- DNDDEBUG << "xdndHandleDrop"
- << "qt_xdnd_current_widget" << qt_xdnd_current_widget
- << (qt_xdnd_current_widget ? qt_xdnd_current_widget->effectiveWinId() : 0)
- << "t_xdnd_current_widget->window()"
- << (qt_xdnd_current_widget ? qt_xdnd_current_widget->window() : 0)
- << (qt_xdnd_current_widget ? qt_xdnd_current_widget->window()->internalWinId() : 0);
- finished.data.l[0] = qt_xdnd_current_widget?qt_xdnd_current_widget->window()->internalWinId():0;
- finished.data.l[1] = de.isAccepted() ? 1 : 0; // flags
- finished.data.l[2] = qtaction_to_xdndaction(global_accepted_action);
- XSendEvent(X11->display, qt_xdnd_dragsource_xid, False,
- NoEventMask, (XEvent*)&finished);
- } else {
- QDragLeaveEvent e;
- QApplication::sendEvent(qt_xdnd_current_widget, &e);
- }
- qt_xdnd_dragsource_xid = 0;
- qt_xdnd_current_widget = 0;
- waiting_for_status = false;
-
- // reset
- qt_xdnd_target_current_time = CurrentTime;
-}
-
-
-void QX11Data::xdndHandleFinished(QWidget *, const XEvent * xe, bool passive)
-{
- DEBUG("xdndHandleFinished");
- const unsigned long *l = (const unsigned long *)xe->xclient.data.l;
-
- DNDDEBUG << "xdndHandleFinished, l[0]" << l[0]
- << "qt_xdnd_current_target" << qt_xdnd_current_target
- << "qt_xdnd_current_proxy_targe" << qt_xdnd_current_proxy_target;
-
- if (l[0]) {
- int at = findXdndDropTransactionByWindow(l[0]);
- if (at != -1) {
- restartXdndDropExpiryTimer();
-
- QXdndDropTransaction t = X11->dndDropTransactions.takeAt(at);
- QDragManager *manager = QDragManager::self();
-
- Window target = qt_xdnd_current_target;
- Window proxy_target = qt_xdnd_current_proxy_target;
- QWidget *embedding_widget = current_embedding_widget;
- QDrag *currentObject = manager->object;
-
- qt_xdnd_current_target = t.target;
- qt_xdnd_current_proxy_target = t.proxy_target;
- current_embedding_widget = t.embedding_widget;
- manager->object = t.object;
-
- if (!passive)
- (void) checkEmbedded(qt_xdnd_current_widget, xe);
-
- current_embedding_widget = 0;
- qt_xdnd_current_target = 0;
- qt_xdnd_current_proxy_target = 0;
-
- if (t.object)
- t.object->deleteLater();
-
- qt_xdnd_current_target = target;
- qt_xdnd_current_proxy_target = proxy_target;
- current_embedding_widget = embedding_widget;
- manager->object = currentObject;
- }
- }
- waiting_for_status = false;
-}
-
-
-void QDragManager::timerEvent(QTimerEvent* e)
-{
- if (e->timerId() == heartbeat && qt_xdnd_source_sameanswer.isNull()) {
- move(QCursor::pos());
- } else if (e->timerId() == transaction_expiry_timer) {
- for (int i = 0; i < X11->dndDropTransactions.count(); ++i) {
- const QXdndDropTransaction &t = X11->dndDropTransactions.at(i);
- if (t.targetWidget) {
- // dnd within the same process, don't delete these
- continue;
- }
- t.object->deleteLater();
- X11->dndDropTransactions.removeAt(i--);
- }
-
- killTimer(transaction_expiry_timer);
- transaction_expiry_timer = -1;
- }
-}
-
-bool QDragManager::eventFilter(QObject * o, QEvent * e)
-{
- if (beingCancelled) {
- if (e->type() == QEvent::KeyRelease && ((QKeyEvent*)e)->key() == Qt::Key_Escape) {
- qApp->removeEventFilter(this);
- Q_ASSERT(object == 0);
- beingCancelled = false;
- eventLoop->exit();
- return true; // block the key release
- }
- return false;
- }
-
- Q_ASSERT(object != 0);
-
- if (!o->isWidgetType())
- return false;
-
- if (e->type() == QEvent::MouseMove) {
- QMouseEvent* me = (QMouseEvent *)e;
- move(me->globalPos());
- return true;
- } else if (e->type() == QEvent::MouseButtonRelease) {
- DEBUG("pre drop");
- qApp->removeEventFilter(this);
- if (willDrop)
- drop();
- else
- cancel();
- DEBUG("drop, resetting object");
- beingCancelled = false;
- eventLoop->exit();
- return true;
- }
-
- if (e->type() == QEvent::ShortcutOverride) {
- // prevent accelerators from firing while dragging
- e->accept();
- return true;
- }
-
- if (e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease) {
- QKeyEvent *ke = ((QKeyEvent*)e);
- if (ke->key() == Qt::Key_Escape && e->type() == QEvent::KeyPress) {
- cancel();
- qApp->removeEventFilter(this);
- beingCancelled = false;
- eventLoop->exit();
- } else {
- qt_xdnd_source_sameanswer = QRect(); // force move
- move(QCursor::pos());
- }
- return true; // Eat all key events
- }
-
- // ### We bind modality to widgets, so we have to do this
- // ### "manually".
- // DnD is modal - eat all other interactive events
- switch (e->type()) {
- case QEvent::MouseButtonPress:
- case QEvent::MouseButtonRelease:
- case QEvent::MouseButtonDblClick:
- case QEvent::MouseMove:
- case QEvent::KeyPress:
- case QEvent::KeyRelease:
- case QEvent::Wheel:
- case QEvent::ShortcutOverride:
- return true;
- default:
- return false;
- }
-}
-
-void QDragManager::updateCursor()
-{
- if (!noDropCursor) {
-#ifndef QT_NO_CURSOR
- noDropCursor = new QCursor(Qt::ForbiddenCursor);
- moveCursor = new QCursor(Qt::DragMoveCursor);
- copyCursor = new QCursor(Qt::DragCopyCursor);
- linkCursor = new QCursor(Qt::DragLinkCursor);
-#endif
- }
-
- QCursor *c;
- if (willDrop) {
- if (global_accepted_action == Qt::CopyAction) {
- c = copyCursor;
- } else if (global_accepted_action == Qt::LinkAction) {
- c = linkCursor;
- } else {
- c = moveCursor;
- }
- if (xdnd_data.deco) {
- xdnd_data.deco->show();
- xdnd_data.deco->raise();
- }
- } else {
- c = noDropCursor;
- //if (qt_xdnd_deco)
- // qt_xdnd_deco->hide();
- }
-#ifndef QT_NO_CURSOR
- if (c)
- qApp->changeOverrideCursor(*c);
-#endif
-}
-
-
-void QDragManager::cancel(bool deleteSource)
-{
- DEBUG("QDragManager::cancel");
- Q_ASSERT(heartbeat != -1);
- killTimer(heartbeat);
- heartbeat = -1;
- beingCancelled = true;
- qt_xdnd_dragging = false;
-
- if (qt_xdnd_current_target)
- qt_xdnd_send_leave();
-
-#ifndef QT_NO_CURSOR
- if (restoreCursor) {
- QApplication::restoreOverrideCursor();
- restoreCursor = false;
- }
-#endif
-
- if (deleteSource && object)
- object->deleteLater();
- object = 0;
- qDeleteInEventHandler(xdnd_data.deco);
- xdnd_data.deco = 0;
-
- global_accepted_action = Qt::IgnoreAction;
-}
-
-static
-Window findRealWindow(const QPoint & pos, Window w, int md)
-{
- if (xdnd_data.deco && w == xdnd_data.deco->effectiveWinId())
- return 0;
-
- if (md) {
- X11->ignoreBadwindow();
- XWindowAttributes attr;
- XGetWindowAttributes(X11->display, w, &attr);
- if (X11->badwindow())
- return 0;
-
- if (attr.map_state == IsViewable
- && QRect(attr.x,attr.y,attr.width,attr.height).contains(pos)) {
- {
- Atom type = XNone;
- int f;
- unsigned long n, a;
- unsigned char *data;
-
- XGetWindowProperty(X11->display, w, ATOM(XdndAware), 0, 0, False,
- AnyPropertyType, &type, &f,&n,&a,&data);
- if (data) XFree(data);
- if (type)
- return w;
- }
-
- Window r, p;
- Window* c;
- uint nc;
- if (XQueryTree(X11->display, w, &r, &p, &c, &nc)) {
- r=0;
- for (uint i=nc; !r && i--;) {
- r = findRealWindow(pos-QPoint(attr.x,attr.y),
- c[i], md-1);
- }
- XFree(c);
- if (r)
- return r;
-
- // We didn't find a client window! Just use the
- // innermost window.
- }
-
- // No children!
- return w;
- }
- }
- return 0;
-}
-
-void QDragManager::move(const QPoint & globalPos)
-{
-#ifdef QT_NO_CURSOR
- Q_UNUSED(globalPos);
- return;
-#else
- DEBUG() << "QDragManager::move enter";
- if (!object) {
- // perhaps the target crashed?
- return;
- }
-
- int screen = QCursor::x11Screen();
- if ((qt_xdnd_current_screen == -1 && screen != X11->defaultScreen) || (screen != qt_xdnd_current_screen)) {
- // recreate the pixmap on the new screen...
- delete xdnd_data.deco;
- QWidget* parent = object->source()->window()->x11Info().screen() == screen
- ? object->source()->window() : QApplication::desktop()->screen(screen);
- xdnd_data.deco = new QShapedPixmapWidget(parent);
- if (!QWidget::mouseGrabber()) {
- updatePixmap();
- xdnd_data.deco->grabMouse();
- }
- }
- xdnd_data.deco->move(QCursor::pos() - xdnd_data.deco->pm_hot);
-
- if (qt_xdnd_source_sameanswer.contains(globalPos) && qt_xdnd_source_sameanswer.isValid())
- return;
-
- qt_xdnd_current_screen = screen;
- Window rootwin = QX11Info::appRootWindow(qt_xdnd_current_screen);
- Window target = 0;
- int lx = 0, ly = 0;
- if (!XTranslateCoordinates(X11->display, rootwin, rootwin, globalPos.x(), globalPos.y(), &lx, &ly, &target))
- // some weird error...
- return;
-
- if (target == rootwin) {
- // Ok.
- } else if (target) {
- //me
- Window src = rootwin;
- while (target != 0) {
- DNDDEBUG << "checking target for XdndAware" << QWidget::find(target) << target;
- int lx2, ly2;
- Window t;
- // translate coordinates
- if (!XTranslateCoordinates(X11->display, src, target, lx, ly, &lx2, &ly2, &t)) {
- target = 0;
- break;
- }
- lx = lx2;
- ly = ly2;
- src = target;
-
- // check if it has XdndAware
- Atom type = 0;
- int f;
- unsigned long n, a;
- unsigned char *data = 0;
- XGetWindowProperty(X11->display, target, ATOM(XdndAware), 0, 0, False,
- AnyPropertyType, &type, &f,&n,&a,&data);
- if (data)
- XFree(data);
- if (type) {
- DNDDEBUG << "Found XdndAware on " << QWidget::find(target) << target;
- break;
- }
-
- // find child at the coordinates
- if (!XTranslateCoordinates(X11->display, src, src, lx, ly, &lx2, &ly2, &target)) {
- target = 0;
- break;
- }
- }
- if (xdnd_data.deco && (!target || target == xdnd_data.deco->effectiveWinId())) {
- DNDDEBUG << "need to find real window";
- target = findRealWindow(globalPos, rootwin, 6);
- DNDDEBUG << "real window found" << QWidget::find(target) << target;
- }
- }
-
- QWidget* w;
- if (target) {
- w = QWidget::find((WId)target);
- if (w && (w->windowType() == Qt::Desktop) && !w->acceptDrops())
- w = 0;
- } else {
- w = 0;
- target = rootwin;
- }
-
- DNDDEBUG << "and the final target is " << QWidget::find(target) << target;
- DNDDEBUG << "the widget w is" << w;
-
- WId proxy_target = xdndProxy(target);
- if (!proxy_target)
- proxy_target = target;
- int target_version = 1;
-
- if (proxy_target) {
- Atom type = XNone;
- int r, f;
- unsigned long n, a;
- unsigned char *retval;
- X11->ignoreBadwindow();
- r = XGetWindowProperty(X11->display, proxy_target, ATOM(XdndAware), 0,
- 1, False, AnyPropertyType, &type, &f,&n,&a,&retval);
- int *tv = (int *)retval;
- if (r != Success || X11->badwindow()) {
- target = 0;
- } else {
- target_version = qMin(xdnd_version,tv ? *tv : 1);
- if (tv)
- XFree(tv);
-// if (!(!X11->badwindow() && type))
-// target = 0;
- }
- }
-
- if (target != qt_xdnd_current_target) {
- if (qt_xdnd_current_target)
- qt_xdnd_send_leave();
-
- qt_xdnd_current_target = target;
- qt_xdnd_current_proxy_target = proxy_target;
- if (target) {
- QVector<Atom> types;
- int flags = target_version << 24;
- QStringList fmts = QInternalMimeData::formatsHelper(dragPrivate()->data);
- for (int i = 0; i < fmts.size(); ++i) {
- QList<Atom> atoms = X11->xdndMimeAtomsForFormat(fmts.at(i));
- for (int j = 0; j < atoms.size(); ++j) {
- if (!types.contains(atoms.at(j)))
- types.append(atoms.at(j));
- }
- }
- if (types.size() > 3) {
- XChangeProperty(X11->display,
- dragPrivate()->source->effectiveWinId(), ATOM(XdndTypelist),
- XA_ATOM, 32, PropModeReplace,
- (unsigned char *)types.data(),
- types.size());
- flags |= 0x0001;
- }
- XClientMessageEvent enter;
- enter.type = ClientMessage;
- enter.window = target;
- enter.format = 32;
- enter.message_type = ATOM(XdndEnter);
- enter.data.l[0] = dragPrivate()->source->effectiveWinId();
- enter.data.l[1] = flags;
- enter.data.l[2] = types.size()>0 ? types.at(0) : 0;
- enter.data.l[3] = types.size()>1 ? types.at(1) : 0;
- enter.data.l[4] = types.size()>2 ? types.at(2) : 0;
- // provisionally set the rectangle to 5x5 pixels...
- qt_xdnd_source_sameanswer = QRect(globalPos.x() - 2,
- globalPos.y() -2 , 5, 5);
-
- DEBUG("sending Xdnd enter");
- if (w)
- X11->xdndHandleEnter(w, (const XEvent *)&enter, false);
- else if (target)
- XSendEvent(X11->display, proxy_target, False, NoEventMask, (XEvent*)&enter);
- waiting_for_status = false;
- }
- }
- if (waiting_for_status)
- return;
-
- if (target) {
- waiting_for_status = true;
-
- XClientMessageEvent move;
- move.type = ClientMessage;
- move.window = target;
- move.format = 32;
- move.message_type = ATOM(XdndPosition);
- move.window = target;
- move.data.l[0] = dragPrivate()->source->effectiveWinId();
- move.data.l[1] = 0; // flags
- move.data.l[2] = (globalPos.x() << 16) + globalPos.y();
- move.data.l[3] = X11->time;
- move.data.l[4] = qtaction_to_xdndaction(defaultAction(dragPrivate()->possible_actions, QApplication::keyboardModifiers()));
- DEBUG("sending Xdnd position");
-
- qt_xdnd_source_current_time = X11->time;
-
- if (w)
- handle_xdnd_position(w, (const XEvent *)&move, false);
- else
- XSendEvent(X11->display, proxy_target, False, NoEventMask,
- (XEvent*)&move);
- } else {
- if (willDrop) {
- willDrop = false;
- updateCursor();
- }
- }
- DEBUG() << "QDragManager::move leave";
-#endif
-}
-
-
-void QDragManager::drop()
-{
- Q_ASSERT(heartbeat != -1);
- killTimer(heartbeat);
- heartbeat = -1;
- qt_xdnd_dragging = false;
-
- if (!qt_xdnd_current_target)
- return;
-
- qDeleteInEventHandler(xdnd_data.deco);
- xdnd_data.deco = 0;
-
- XClientMessageEvent drop;
- drop.type = ClientMessage;
- drop.window = qt_xdnd_current_target;
- drop.format = 32;
- drop.message_type = ATOM(XdndDrop);
- drop.data.l[0] = dragPrivate()->source->effectiveWinId();
- drop.data.l[1] = 0; // flags
- drop.data.l[2] = X11->time;
-
- drop.data.l[3] = 0;
- drop.data.l[4] = 0;
-
- QWidget * w = QWidget::find(qt_xdnd_current_proxy_target);
-
- if (w && (w->windowType() == Qt::Desktop) && !w->acceptDrops())
- w = 0;
-
- QXdndDropTransaction t = {
- X11->time,
- qt_xdnd_current_target,
- qt_xdnd_current_proxy_target,
- w,
- current_embedding_widget,
- object
- };
- X11->dndDropTransactions.append(t);
- restartXdndDropExpiryTimer();
-
- if (w)
- X11->xdndHandleDrop(w, (const XEvent *)&drop, false);
- else
- XSendEvent(X11->display, qt_xdnd_current_proxy_target, False,
- NoEventMask, (XEvent*)&drop);
-
- qt_xdnd_current_target = 0;
- qt_xdnd_current_proxy_target = 0;
- qt_xdnd_source_current_time = 0;
- current_embedding_widget = 0;
- object = 0;
-
-#ifndef QT_NO_CURSOR
- if (restoreCursor) {
- QApplication::restoreOverrideCursor();
- restoreCursor = false;
- }
-#endif
-}
-
-
-
-bool QX11Data::xdndHandleBadwindow()
-{
- if (qt_xdnd_current_target) {
- QDragManager *manager = QDragManager::self();
- if (manager->object) {
- qt_xdnd_current_target = 0;
- qt_xdnd_current_proxy_target = 0;
- manager->object->deleteLater();
- manager->object = 0;
- delete xdnd_data.deco;
- xdnd_data.deco = 0;
- return true;
- }
- }
- if (qt_xdnd_dragsource_xid) {
- qt_xdnd_dragsource_xid = 0;
- if (qt_xdnd_current_widget) {
- QApplication::postEvent(qt_xdnd_current_widget, new QDragLeaveEvent);
- qt_xdnd_current_widget = 0;
- }
- return true;
- }
- return false;
-}
-
-void QX11Data::xdndHandleSelectionRequest(const XSelectionRequestEvent * req)
-{
- if (!req)
- return;
- XEvent evt;
- evt.xselection.type = SelectionNotify;
- evt.xselection.display = req->display;
- evt.xselection.requestor = req->requestor;
- evt.xselection.selection = req->selection;
- evt.xselection.target = XNone;
- evt.xselection.property = XNone;
- evt.xselection.time = req->time;
-
- QDragManager *manager = QDragManager::self();
- QDrag *currentObject = manager->object;
-
- // which transaction do we use? (note: -2 means use current manager->object)
- int at = -1;
-
- // figure out which data the requestor is really interested in
- if (manager->object && req->time == qt_xdnd_source_current_time) {
- // requestor wants the current drag data
- at = -2;
- } else {
- // if someone has requested data in response to XdndDrop, find the corresponding transaction. the
- // spec says to call XConvertSelection() using the timestamp from the XdndDrop
- at = findXdndDropTransactionByTime(req->time);
- if (at == -1) {
- // no dice, perhaps the client was nice enough to use the same window id in XConvertSelection()
- // that we sent the XdndDrop event to.
- at = findXdndDropTransactionByWindow(req->requestor);
- }
- if (at == -1 && req->time == CurrentTime) {
- // previous Qt versions always requested the data on a child of the target window
- // using CurrentTime... but it could be asking for either drop data or the current drag's data
- Window target = findXdndAwareParent(req->requestor);
- if (target) {
- if (qt_xdnd_current_target && qt_xdnd_current_target == target)
- at = -2;
- else
- at = findXdndDropTransactionByWindow(target);
- }
- }
- }
- if (at >= 0) {
- restartXdndDropExpiryTimer();
-
- // use the drag object from an XdndDrop tansaction
- manager->object = X11->dndDropTransactions.at(at).object;
- } else if (at != -2) {
- // no transaction found, we'll have to reject the request
- manager->object = 0;
- }
- if (manager->object) {
- Atom atomFormat = req->target;
- int dataFormat = 0;
- QByteArray data;
- if (X11->xdndMimeDataForAtom(req->target, manager->dragPrivate()->data,
- &data, &atomFormat, &dataFormat)) {
- int dataSize = data.size() / (dataFormat / 8);
- XChangeProperty (X11->display, req->requestor, req->property,
- atomFormat, dataFormat, PropModeReplace,
- (unsigned char *)data.data(), dataSize);
- evt.xselection.property = req->property;
- evt.xselection.target = atomFormat;
- }
- }
-
- // reset manager->object in case we modified it above
- manager->object = currentObject;
-
- // ### this can die if req->requestor crashes at the wrong
- // ### moment
- XSendEvent(X11->display, req->requestor, False, 0, &evt);
-}
-
-static QVariant xdndObtainData(const char *format, QVariant::Type requestedType)
-{
- QByteArray result;
-
- QWidget* w;
- QDragManager *manager = QDragManager::self();
- if (qt_xdnd_dragsource_xid && manager->object &&
- (w=QWidget::find(qt_xdnd_dragsource_xid))
- && (!(w->windowType() == Qt::Desktop) || w->acceptDrops()))
- {
- QDragPrivate * o = QDragManager::self()->dragPrivate();
- if (o->data->hasFormat(QLatin1String(format)))
- result = o->data->data(QLatin1String(format));
- return result;
- }
-
- QList<Atom> atoms;
- int i = 0;
- while ((qt_xdnd_types[i])) {
- atoms.append(qt_xdnd_types[i]);
- ++i;
- }
- QByteArray encoding;
- Atom a = X11->xdndMimeAtomForFormat(QLatin1String(format), requestedType, atoms, &encoding);
- if (!a)
- return result;
-
- if (XGetSelectionOwner(X11->display, ATOM(XdndSelection)) == XNone)
- return result; // should never happen?
-
- QWidget* tw = qt_xdnd_current_widget;
- if (!qt_xdnd_current_widget || (qt_xdnd_current_widget->windowType() == Qt::Desktop))
- tw = new QWidget;
-
- XConvertSelection(X11->display, ATOM(XdndSelection), a, ATOM(XdndSelection), tw->effectiveWinId(),
- qt_xdnd_target_current_time);
- XFlush(X11->display);
-
- XEvent xevent;
- bool got=X11->clipboardWaitForEvent(tw->effectiveWinId(), SelectionNotify, &xevent, 5000);
- if (got) {
- Atom type;
-
- if (X11->clipboardReadProperty(tw->effectiveWinId(), ATOM(XdndSelection), true, &result, 0, &type, 0)) {
- if (type == ATOM(INCR)) {
- int nbytes = result.size() >= 4 ? *((int*)result.data()) : 0;
- result = X11->clipboardReadIncrementalProperty(tw->effectiveWinId(), ATOM(XdndSelection), nbytes, false);
- } else if (type != a && type != XNone) {
- DEBUG("Qt clipboard: unknown atom %ld", type);
- }
- }
- }
- if (!qt_xdnd_current_widget || (qt_xdnd_current_widget->windowType() == Qt::Desktop))
- delete tw;
-
- return X11->xdndMimeConvertToFormat(a, result, QLatin1String(format), requestedType, encoding);
-}
-
-
-/*
- Enable drag and drop for widget w by installing the proper
- properties on w's toplevel widget.
-*/
-bool QX11Data::dndEnable(QWidget* w, bool on)
-{
- w = w->window();
-
- if (bool(((QExtraWidget*)w)->topData()->dnd) == on)
- return true; // been there, done that
- ((QExtraWidget*)w)->topData()->dnd = on ? 1 : 0;
-
- motifdndEnable(w, on);
- return xdndEnable(w, on);
-}
-
-Qt::DropAction QDragManager::drag(QDrag * o)
-{
- if (object == o || !o || !o->d_func()->source)
- return Qt::IgnoreAction;
-
- if (object) {
- cancel();
- qApp->removeEventFilter(this);
- beingCancelled = false;
- }
-
- if (object) {
- // the last drag and drop operation hasn't finished, so we are going to wait
- // for one second to see if it does... if the finish message comes after this,
- // then we could still have problems, but this is highly unlikely
- QApplication::flush();
-
- QElapsedTimer timer;
- timer.start();
- do {
- XEvent event;
- if (XCheckTypedEvent(X11->display, ClientMessage, &event))
- qApp->x11ProcessEvent(&event);
-
- // sleep 50 ms, so we don't use up CPU cycles all the time.
- struct timeval usleep_tv;
- usleep_tv.tv_sec = 0;
- usleep_tv.tv_usec = 50000;
- select(0, 0, 0, 0, &usleep_tv);
- } while (object && timer.hasExpired(1000));
- }
-
- object = o;
- object->d_func()->target = 0;
- xdnd_data.deco = new QShapedPixmapWidget(object->source()->window());
-
- willDrop = false;
-
- updatePixmap();
-
- qApp->installEventFilter(this);
- XSetSelectionOwner(X11->display, ATOM(XdndSelection), dragPrivate()->source->window()->internalWinId(), X11->time);
- global_accepted_action = Qt::CopyAction;
- qt_xdnd_source_sameanswer = QRect();
-#ifndef QT_NO_CURSOR
- // set the override cursor (must be done here, since it is updated
- // in the call to move() below)
- qApp->setOverrideCursor(Qt::ArrowCursor);
- restoreCursor = true;
-#endif
- move(QCursor::pos());
- heartbeat = startTimer(200);
-
- qt_xdnd_dragging = true;
-
- if (!QWidget::mouseGrabber())
- xdnd_data.deco->grabMouse();
-
- eventLoop = new QEventLoop;
- (void) eventLoop->exec();
- delete eventLoop;
- eventLoop = 0;
-
-#ifndef QT_NO_CURSOR
- if (restoreCursor) {
- qApp->restoreOverrideCursor();
- restoreCursor = false;
- }
-#endif
-
- // delete cursors as they may be different next drag.
- delete noDropCursor;
- noDropCursor = 0;
- delete copyCursor;
- copyCursor = 0;
- delete moveCursor;
- moveCursor = 0;
- delete linkCursor;
- linkCursor = 0;
-
- delete xdnd_data.deco;
- xdnd_data.deco = 0;
- if (heartbeat != -1)
- killTimer(heartbeat);
- heartbeat = -1;
- qt_xdnd_current_screen = -1;
- qt_xdnd_dragging = false;
-
- return global_accepted_action;
- // object persists until we get an xdnd_finish message
-}
-
-void QDragManager::updatePixmap()
-{
- if (xdnd_data.deco) {
- QPixmap pm;
- QPoint pm_hot(default_pm_hotx,default_pm_hoty);
- if (object) {
- pm = dragPrivate()->pixmap;
- if (!pm.isNull())
- pm_hot = dragPrivate()->hotspot;
- }
- if (pm.isNull()) {
- if (!defaultPm)
- defaultPm = new QPixmap(default_pm);
- pm = *defaultPm;
- }
- xdnd_data.deco->pm_hot = pm_hot;
- xdnd_data.deco->setPixmap(pm);
- xdnd_data.deco->move(QCursor::pos()-pm_hot);
- xdnd_data.deco->show();
- }
-}
-
-QVariant QDropData::retrieveData_sys(const QString &mimetype, QVariant::Type requestedType) const
-{
- QByteArray mime = mimetype.toLatin1();
- QVariant data = X11->motifdnd_active
- ? X11->motifdndObtainData(mime)
- : xdndObtainData(mime, requestedType);
- return data;
-}
-
-bool QDropData::hasFormat_sys(const QString &format) const
-{
- return formats().contains(format);
-}
-
-QStringList QDropData::formats_sys() const
-{
- QStringList formats;
- if (X11->motifdnd_active) {
- int i = 0;
- QByteArray fmt;
- while (!(fmt = X11->motifdndFormat(i)).isEmpty()) {
- formats.append(QLatin1String(fmt));
- ++i;
- }
- } else {
- int i = 0;
- while ((qt_xdnd_types[i])) {
- QStringList formatsForAtom = X11->xdndMimeFormatsForAtom(qt_xdnd_types[i]);
- for (int j = 0; j < formatsForAtom.size(); ++j) {
- if (!formats.contains(formatsForAtom.at(j)))
- formats.append(formatsForAtom.at(j));
- }
- ++i;
- }
- }
- return formats;
-}
-
-QT_END_NAMESPACE
-
-#endif // QT_NO_DRAGANDDROP
diff --git a/src/gui/kernel/qdrag.cpp b/src/gui/kernel/qdrag.cpp
deleted file mode 100644
index d8d14cb45c..0000000000
--- a/src/gui/kernel/qdrag.cpp
+++ /dev/null
@@ -1,359 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <qwidget.h>
-#include <qdrag.h>
-#include <qpixmap.h>
-#include <qpoint.h>
-#include "qdnd_p.h"
-
-#ifndef QT_NO_DRAGANDDROP
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QDrag
- \brief The QDrag class provides support for MIME-based drag and drop data
- transfer.
-
- Drag and drop is an intuitive way for users to copy or move data around in an
- application, and is used in many desktop environments as a mechanism for copying
- data between applications. Drag and drop support in Qt is centered around the
- QDrag class that handles most of the details of a drag and drop operation.
-
- The data to be transferred by the drag and drop operation is contained in a
- QMimeData object. This is specified with the setMimeData() function in the
- following way:
-
- \snippet doc/src/snippets/dragging/mainwindow.cpp 1
-
- Note that setMimeData() assigns ownership of the QMimeData object to the
- QDrag object. The QDrag must be constructed on the heap with a parent QWidget
- to ensure that Qt can clean up after the drag and drop operation has been
- completed.
-
- A pixmap can be used to represent the data while the drag is in
- progress, and will move with the cursor to the drop target. This
- pixmap typically shows an icon that represents the MIME type of
- the data being transferred, but any pixmap can be set with
- setPixmap(). The cursor's hot spot can be given a position
- relative to the top-left corner of the pixmap with the
- setHotSpot() function. The following code positions the pixmap so
- that the cursor's hot spot points to the center of its bottom
- edge:
-
- \snippet doc/src/snippets/separations/finalwidget.cpp 2
-
- \note On X11, the pixmap may not be able to keep up with the mouse
- movements if the hot spot causes the pixmap to be displayed
- directly under the cursor.
-
- The source and target widgets can be found with source() and target().
- These functions are often used to determine whether drag and drop operations
- started and finished at the same widget, so that special behavior can be
- implemented.
-
- QDrag only deals with the drag and drop operation itself. It is up to the
- developer to decide when a drag operation begins, and how a QDrag object should
- be constructed and used. For a given widget, it is often necessary to
- reimplement \l{QWidget::mousePressEvent()}{mousePressEvent()} to determine
- whether the user has pressed a mouse button, and reimplement
- \l{QWidget::mouseMoveEvent()}{mouseMoveEvent()} to check whether a QDrag is
- required.
-
- \sa {Drag and Drop}, QClipboard, QMimeData, QWindowsMime, QMacPasteboardMime,
- {Draggable Icons Example}, {Draggable Text Example}, {Drop Site Example},
- {Fridge Magnets Example}
-*/
-
-/*!
- Constructs a new drag object for the widget specified by \a dragSource.
-*/
-QDrag::QDrag(QWidget *dragSource)
- : QObject(*new QDragPrivate, dragSource)
-{
- Q_D(QDrag);
- d->source = dragSource;
- d->target = 0;
- d->data = 0;
- d->hotspot = QPoint(-10, -10);
- d->possible_actions = Qt::CopyAction;
- d->executed_action = Qt::IgnoreAction;
- d->defaultDropAction = Qt::IgnoreAction;
-}
-
-/*!
- Destroys the drag object.
-*/
-QDrag::~QDrag()
-{
- Q_D(QDrag);
- delete d->data;
- QDragManager *manager = QDragManager::self();
- if (manager && manager->object == this)
- manager->cancel(false);
-}
-
-/*!
- Sets the data to be sent to the given MIME \a data. Ownership of the data is
- transferred to the QDrag object.
-*/
-void QDrag::setMimeData(QMimeData *data)
-{
- Q_D(QDrag);
- if (d->data == data)
- return;
- if (d->data != 0)
- delete d->data;
- d->data = data;
-}
-
-/*!
- Returns the MIME data that is encapsulated by the drag object.
-*/
-QMimeData *QDrag::mimeData() const
-{
- Q_D(const QDrag);
- return d->data;
-}
-
-/*!
- Sets \a pixmap as the pixmap used to represent the data in a drag
- and drop operation. You can only set a pixmap before the drag is
- started.
-*/
-void QDrag::setPixmap(const QPixmap &pixmap)
-{
- Q_D(QDrag);
- d->pixmap = pixmap;
-}
-
-/*!
- Returns the pixmap used to represent the data in a drag and drop operation.
-*/
-QPixmap QDrag::pixmap() const
-{
- Q_D(const QDrag);
- return d->pixmap;
-}
-
-/*!
- Sets the position of the hot spot relative to the top-left corner of the
- pixmap used to the point specified by \a hotspot.
-
- \bold{Note:} on X11, the pixmap may not be able to keep up with the mouse
- movements if the hot spot causes the pixmap to be displayed
- directly under the cursor.
-*/
-void QDrag::setHotSpot(const QPoint& hotspot)
-{
- Q_D(QDrag);
- d->hotspot = hotspot;
-}
-
-/*!
- Returns the position of the hot spot relative to the top-left corner of the
- cursor.
-*/
-QPoint QDrag::hotSpot() const
-{
- Q_D(const QDrag);
- return d->hotspot;
-}
-
-/*!
- Returns the source of the drag object. This is the widget where the drag
- and drop operation originated.
-*/
-QWidget *QDrag::source() const
-{
- Q_D(const QDrag);
- return d->source;
-}
-
-/*!
- Returns the target of the drag and drop operation. This is the widget where
- the drag object was dropped.
-*/
-QWidget *QDrag::target() const
-{
- Q_D(const QDrag);
- return d->target;
-}
-
-/*!
- \since 4.3
-
- Starts the drag and drop operation and returns a value indicating the requested
- drop action when it is completed. The drop actions that the user can choose
- from are specified in \a supportedActions. The default proposed action will be selected
- among the allowed actions in the following order: Move, Copy and Link.
-
- \bold{Note:} On Linux and Mac OS X, the drag and drop operation
- can take some time, but this function does not block the event
- loop. Other events are still delivered to the application while
- the operation is performed. On Windows, the Qt event loop is
- blocked while during the operation.
-*/
-
-Qt::DropAction QDrag::exec(Qt::DropActions supportedActions)
-{
- return exec(supportedActions, Qt::IgnoreAction);
-}
-
-/*!
- \since 4.3
-
- Starts the drag and drop operation and returns a value indicating the requested
- drop action when it is completed. The drop actions that the user can choose
- from are specified in \a supportedActions.
-
- The \a defaultDropAction determines which action will be proposed when the user performs a
- drag without using modifier keys.
-
- \bold{Note:} On Linux and Mac OS X, the drag and drop operation
- can take some time, but this function does not block the event
- loop. Other events are still delivered to the application while
- the operation is performed. On Windows, the Qt event loop is
- blocked during the operation. However, QDrag::exec() on
- Windows causes processEvents() to be called frequently to keep the GUI responsive.
- If any loops or operations are called while a drag operation is active, it will block the drag operation.
-*/
-
-Qt::DropAction QDrag::exec(Qt::DropActions supportedActions, Qt::DropAction defaultDropAction)
-{
- Q_D(QDrag);
- if (!d->data) {
- qWarning("QDrag: No mimedata set before starting the drag");
- return d->executed_action;
- }
- QDragManager *manager = QDragManager::self();
- d->defaultDropAction = Qt::IgnoreAction;
- d->possible_actions = supportedActions;
-
- if (manager) {
- if (defaultDropAction == Qt::IgnoreAction) {
- if (supportedActions & Qt::MoveAction) {
- d->defaultDropAction = Qt::MoveAction;
- } else if (supportedActions & Qt::CopyAction) {
- d->defaultDropAction = Qt::CopyAction;
- } else if (supportedActions & Qt::LinkAction) {
- d->defaultDropAction = Qt::LinkAction;
- }
- } else {
- d->defaultDropAction = defaultDropAction;
- }
- d->executed_action = manager->drag(this);
- }
-
- return d->executed_action;
-}
-
-/*!
- \obsolete
-
- \bold{Note:} It is recommended to use exec() instead of this function.
-
- Starts the drag and drop operation and returns a value indicating the requested
- drop action when it is completed. The drop actions that the user can choose
- from are specified in \a request. Qt::CopyAction is always allowed.
-
- \bold{Note:} Although the drag and drop operation can take some time, this function
- does not block the event loop. Other events are still delivered to the application
- while the operation is performed.
-
- \sa exec()
-*/
-Qt::DropAction QDrag::start(Qt::DropActions request)
-{
- Q_D(QDrag);
- if (!d->data) {
- qWarning("QDrag: No mimedata set before starting the drag");
- return d->executed_action;
- }
- QDragManager *manager = QDragManager::self();
- d->defaultDropAction = Qt::IgnoreAction;
- d->possible_actions = request | Qt::CopyAction;
- if (manager)
- d->executed_action = manager->drag(this);
- return d->executed_action;
-}
-
-/*!
- Sets the drag \a cursor for the \a action. This allows you
- to override the default native cursors. To revert to using the
- native cursor for \a action pass in a null QPixmap as \a cursor.
-
- The \a action can only be CopyAction, MoveAction or LinkAction.
- All other values of DropAction are ignored.
-*/
-void QDrag::setDragCursor(const QPixmap &cursor, Qt::DropAction action)
-{
- Q_D(QDrag);
- if (action != Qt::CopyAction && action != Qt::MoveAction && action != Qt::LinkAction)
- return;
- if (cursor.isNull())
- d->customCursors.remove(action);
- else
- d->customCursors[action] = cursor;
-}
-
-/*!
- \fn void QDrag::actionChanged(Qt::DropAction action)
-
- This signal is emitted when the \a action associated with the
- drag changes.
-
- \sa targetChanged()
-*/
-
-/*!
- \fn void QDrag::targetChanged(QWidget *newTarget)
-
- This signal is emitted when the target of the drag and drop
- operation changes, with \a newTarget the new target.
-
- \sa target(), actionChanged()
-*/
-
-QT_END_NAMESPACE
-
-#endif // QT_NO_DRAGANDDROP
diff --git a/src/gui/kernel/qdrag.h b/src/gui/kernel/qdrag.h
deleted file mode 100644
index da847898b2..0000000000
--- a/src/gui/kernel/qdrag.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QDRAG_H
-#define QDRAG_H
-
-#include <QtCore/qobject.h>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Gui)
-
-#ifndef QT_NO_DRAGANDDROP
-class QMimeData;
-class QDragPrivate;
-class QWidget;
-class QPixmap;
-class QPoint;
-class QDragManager;
-
-class Q_GUI_EXPORT QDrag : public QObject
-{
- Q_OBJECT
- Q_DECLARE_PRIVATE(QDrag)
-public:
- explicit QDrag(QWidget *dragSource);
- ~QDrag();
-
- void setMimeData(QMimeData *data);
- QMimeData *mimeData() const;
-
- void setPixmap(const QPixmap &);
- QPixmap pixmap() const;
-
- void setHotSpot(const QPoint &hotspot);
- QPoint hotSpot() const;
-
- QWidget *source() const;
- QWidget *target() const;
-
- Qt::DropAction start(Qt::DropActions supportedActions = Qt::CopyAction);
- Qt::DropAction exec(Qt::DropActions supportedActions = Qt::MoveAction);
- Qt::DropAction exec(Qt::DropActions supportedActions, Qt::DropAction defaultAction);
-
- void setDragCursor(const QPixmap &cursor, Qt::DropAction action);
-
-Q_SIGNALS:
- void actionChanged(Qt::DropAction action);
- void targetChanged(QWidget *newTarget);
-
-private:
-#ifdef Q_WS_MAC
- friend class QWidgetPrivate;
-#endif
- friend class QDragManager;
- Q_DISABLE_COPY(QDrag)
-};
-
-#endif // QT_NO_DRAGANDDROP
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // QDRAG_H
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
deleted file mode 100644
index 5f0cfd7d69..0000000000
--- a/src/gui/kernel/qevent.cpp
+++ /dev/null
@@ -1,4619 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the Technology Preview License Agreement accompanying
-** this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-**
-**
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qevent.h"
-#include "qcursor.h"
-#include "qapplication.h"
-#include "private/qapplication_p.h"
-#include "private/qevent_p.h"
-#include "private/qkeysequence_p.h"
-#include "qwidget.h"
-#include "qgraphicsview.h"
-#include "qdebug.h"
-#include "qmime.h"
-#include "qdnd_p.h"
-#include "qevent_p.h"
-#include "qgesture.h"
-#include "qgesture_p.h"
-
-#ifdef Q_OS_SYMBIAN
-#include "private/qcore_symbian_p.h"
-#endif
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QInputEvent
- \ingroup events
-
- \brief The QInputEvent class is the base class for events that
- describe user input.
-*/
-
-/*!
- \internal
-*/
-QInputEvent::QInputEvent(Type type, Qt::KeyboardModifiers modifiers)
- : QEvent(type), modState(modifiers)
-{}
-
-/*!
- \internal
-*/
-QInputEvent::~QInputEvent()
-{
-}
-
-/*!
- \fn Qt::KeyboardModifiers QInputEvent::modifiers() const
-
- Returns the keyboard modifier flags that existed immediately
- before the event occurred.
-
- \sa QApplication::keyboardModifiers()
-*/
-
-/*! \fn void QInputEvent::setModifiers(Qt::KeyboardModifiers modifiers)
-
- \internal
-
- Sets the keyboard modifiers flags for this event.
-*/
-
-/*!
- \class QMouseEvent
- \ingroup events
-
- \brief The QMouseEvent class contains parameters that describe a mouse event.
-
- Mouse events occur when a mouse button is pressed or released
- inside a widget, or when the mouse cursor is moved.
-
- Mouse move events will occur only when a mouse button is pressed
- down, unless mouse tracking has been enabled with
- QWidget::setMouseTracking().
-
- Qt automatically grabs the mouse when a mouse button is pressed
- inside a widget; the widget will continue to receive mouse events
- until the last mouse button is released.
-
- A mouse event contains a special accept flag that indicates
- whether the receiver wants the event. You should call ignore() if
- the mouse event is not handled by your widget. A mouse event is
- propagated up the parent widget chain until a widget accepts it
- with accept(), or an event filter consumes it.
-
- \note If a mouse event is propagated to a \l{QWidget}{widget} for
- which Qt::WA_NoMousePropagation has been set, that mouse event
- will not be propagated further up the parent widget chain.
-
- The state of the keyboard modifier keys can be found by calling the
- \l{QInputEvent::modifiers()}{modifiers()} function, inherited from
- QInputEvent.
-
- The functions pos(), x(), and y() give the cursor position
- relative to the widget that receives the mouse event. If you
- move the widget as a result of the mouse event, use the global
- position returned by globalPos() to avoid a shaking motion.
-
- The QWidget::setEnabled() function can be used to enable or
- disable mouse and keyboard events for a widget.
-
- Reimplement the QWidget event handlers, QWidget::mousePressEvent(),
- QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(),
- and QWidget::mouseMoveEvent() to receive mouse events in your own
- widgets.
-
- \sa QWidget::setMouseTracking() QWidget::grabMouse()
- QCursor::pos()
-*/
-
-/*!
- Constructs a mouse event object.
-
- The \a type parameter must be one of QEvent::MouseButtonPress,
- QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
- or QEvent::MouseMove.
-
- The \a position is the mouse cursor's position relative to the
- receiving widget.
- The \a button that caused the event is given as a value from
- the Qt::MouseButton enum. If the event \a type is
- \l MouseMove, the appropriate button for this event is Qt::NoButton.
- The mouse and keyboard states at the time of the event are specified by
- \a buttons and \a modifiers.
-
- The globalPos() is initialized to QCursor::pos(), which may not
- be appropriate. Use the other constructor to specify the global
- position explicitly.
-*/
-
-QMouseEvent::QMouseEvent(Type type, const QPoint &position, Qt::MouseButton button,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
- : QInputEvent(type, modifiers), p(position), b(button), mouseState(buttons)
-{
- g = QCursor::pos();
-}
-
-/*!
- \internal
-*/
-QMouseEvent::~QMouseEvent()
-{
-}
-
-
-/*!
- Constructs a mouse event object.
-
- The \a type parameter must be QEvent::MouseButtonPress,
- QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
- or QEvent::MouseMove.
-
- The \a pos is the mouse cursor's position relative to the
- receiving widget. The cursor's position in global coordinates is
- specified by \a globalPos. The \a button that caused the event is
- given as a value from the \l Qt::MouseButton enum. If the event \a
- type is \l MouseMove, the appropriate button for this event is
- Qt::NoButton. \a buttons is the state of all buttons at the
- time of the event, \a modifiers the state of all keyboard
- modifiers.
-
-*/
-QMouseEvent::QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos,
- Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers)
- : QInputEvent(type, modifiers), p(pos), g(globalPos), b(button), mouseState(buttons)
-{}
-
-/*!
- \internal
-*/
-QMouseEvent *QMouseEvent::createExtendedMouseEvent(Type type, const QPointF &pos,
- const QPoint &globalPos, Qt::MouseButton button,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
-{
- return new QMouseEventEx(type, pos, globalPos, button, buttons, modifiers);
-}
-
-/*!
- \fn bool QMouseEvent::hasExtendedInfo() const
- \internal
-*/
-
-/*!
- \since 4.4
-
- Returns the position of the mouse cursor as a QPointF, relative to the
- widget that received the event.
-
- If you move the widget as a result of the mouse event, use the
- global position returned by globalPos() to avoid a shaking
- motion.
-
- \sa x() y() pos() globalPos()
-*/
-QPointF QMouseEvent::posF() const
-{
- return hasExtendedInfo() ? reinterpret_cast<const QMouseEventEx *>(this)->posF : QPointF(pos());
-}
-
-/*!
- \internal
-*/
-QMouseEventEx::QMouseEventEx(Type type, const QPointF &pos, const QPoint &globalPos,
- Qt::MouseButton button, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers)
- : QMouseEvent(type, pos.toPoint(), globalPos, button, buttons, modifiers), posF(pos)
-{
- d = reinterpret_cast<QEventPrivate *>(this);
-}
-
-/*!
- \internal
-*/
-QMouseEventEx::~QMouseEventEx()
-{
-}
-
-/*!
- \fn const QPoint &QMouseEvent::pos() const
-
- Returns the position of the mouse cursor, relative to the widget
- that received the event.
-
- If you move the widget as a result of the mouse event, use the
- global position returned by globalPos() to avoid a shaking
- motion.
-
- \sa x() y() globalPos()
-*/
-
-/*!
- \fn const QPoint &QMouseEvent::globalPos() const
-
- Returns the global position of the mouse cursor \e{at the time
- of the event}. This is important on asynchronous window systems
- like X11. Whenever you move your widgets around in response to
- mouse events, globalPos() may differ a lot from the current
- pointer position QCursor::pos(), and from
- QWidget::mapToGlobal(pos()).
-
- \sa globalX() globalY()
-*/
-
-/*!
- \fn int QMouseEvent::x() const
-
- Returns the x position of the mouse cursor, relative to the
- widget that received the event.
-
- \sa y() pos()
-*/
-
-/*!
- \fn int QMouseEvent::y() const
-
- Returns the y position of the mouse cursor, relative to the
- widget that received the event.
-
- \sa x() pos()
-*/
-
-/*!
- \fn int QMouseEvent::globalX() const
-
- Returns the global x position of the mouse cursor at the time of
- the event.
-
- \sa globalY() globalPos()
-*/
-
-/*!
- \fn int QMouseEvent::globalY() const
-
- Returns the global y position of the mouse cursor at the time of
- the event.
-
- \sa globalX() globalPos()
-*/
-
-/*!
- \fn Qt::MouseButton QMouseEvent::button() const
-
- Returns the button that caused the event.
-
- Note that the returned value is always Qt::NoButton for mouse
- move events.
-
- \sa buttons() Qt::MouseButton
-*/
-
-/*!
- \fn Qt::MouseButton QMouseEvent::buttons() const
-
- Returns the button state when the event was generated. The button
- state is a combination of Qt::LeftButton, Qt::RightButton,
- Qt::MidButton using the OR operator. For mouse move events,
- this is all buttons that are pressed down. For mouse press and
- double click events this includes the button that caused the
- event. For mouse release events this excludes the button that
- caused the event.
-
- \sa button() Qt::MouseButton
-*/
-
-
-/*!
- \fn Qt::ButtonState QMouseEvent::state() const
-
- Returns the button state immediately before the event was
- generated. The button state is a combination of mouse buttons
- (see Qt::ButtonState) and keyboard modifiers (Qt::MouseButtons).
-
- Use buttons() and/or modifiers() instead. Be aware that buttons()
- return the state immediately \e after the event was generated.
-*/
-
-/*!
- \fn Qt::ButtonState QMouseEvent::stateAfter() const
-
- Returns the button state immediately after the event was
- generated. The button state is a combination of mouse buttons
- (see Qt::ButtonState) and keyboard modifiers (Qt::MouseButtons).
-
- Use buttons() and/or modifiers() instead.
-*/
-
-/*!
- \class QHoverEvent
- \ingroup events
-
- \brief The QHoverEvent class contains parameters that describe a mouse event.
-
- Mouse events occur when a mouse cursor is moved into, out of, or within a
- widget, and if the widget has the Qt::WA_Hover attribute.
-
- The function pos() gives the current cursor position, while oldPos() gives
- the old mouse position.
-
- There are a few similarities between the events QEvent::HoverEnter
- and QEvent::HoverLeave, and the events QEvent::Enter and QEvent::Leave.
- However, they are slightly different because we do an update() in the event
- handler of HoverEnter and HoverLeave.
-
- QEvent::HoverMove is also slightly different from QEvent::MouseMove. Let us
- consider a top-level window A containing a child B which in turn contains a
- child C (all with mouse tracking enabled):
-
- \image hoverevents.png
-
- Now, if you move the cursor from the top to the bottom in the middle of A,
- you will get the following QEvent::MouseMove events:
-
- \list 1
- \o A::MouseMove
- \o B::MouseMove
- \o C::MouseMove
- \endlist
-
- You will get the same events for QEvent::HoverMove, except that the event
- always propagates to the top-level regardless whether the event is accepted
- or not. It will only stop propagating with the Qt::WA_NoMousePropagation
- attribute.
-
- In this case the events will occur in the following way:
-
- \list 1
- \o A::HoverMove
- \o A::HoverMove, B::HoverMove
- \o A::HoverMove, B::HoverMove, C::HoverMove
- \endlist
-
-*/
-
-/*!
- \fn const QPoint &QHoverEvent::pos() const
-
- Returns the position of the mouse cursor, relative to the widget
- that received the event.
-
- On QEvent::HoverLeave events, this position will always be
- QPoint(-1, -1).
-
- \sa oldPos()
-*/
-
-/*!
- \fn const QPoint &QHoverEvent::oldPos() const
-
- Returns the previous position of the mouse cursor, relative to the widget
- that received the event. If there is no previous position, oldPos() will
- return the same position as pos().
-
- On QEvent::HoverEnter events, this position will always be
- QPoint(-1, -1).
-
- \sa pos()
-*/
-
-/*!
- Constructs a hover event object.
-
- The \a type parameter must be QEvent::HoverEnter,
- QEvent::HoverLeave, or QEvent::HoverMove.
-
- The \a pos is the current mouse cursor's position relative to the
- receiving widget, while \a oldPos is the previous mouse cursor's
- position relative to the receiving widget.
-*/
-QHoverEvent::QHoverEvent(Type type, const QPoint &pos, const QPoint &oldPos)
- : QEvent(type), p(pos), op(oldPos)
-{
-}
-
-/*!
- \internal
-*/
-QHoverEvent::~QHoverEvent()
-{
-}
-
-
-/*!
- \class QWheelEvent
- \brief The QWheelEvent class contains parameters that describe a wheel event.
-
- \ingroup events
-
- Wheel events are sent to the widget under the mouse cursor, but
- if that widget does not handle the event they are sent to the
- focus widget. The rotation distance is provided by delta().
- The functions pos() and globalPos() return the mouse cursor's
- location at the time of the event.
-
- A wheel event contains a special accept flag that indicates
- whether the receiver wants the event. You should call ignore() if
- you do not handle the wheel event; this ensures that it will be
- sent to the parent widget.
-
- The QWidget::setEnabled() function can be used to enable or
- disable mouse and keyboard events for a widget.
-
- The event handler QWidget::wheelEvent() receives wheel events.
-
- \sa QMouseEvent QWidget::grabMouse()
-*/
-
-/*!
- \fn Qt::MouseButtons QWheelEvent::buttons() const
-
- Returns the mouse state when the event occurred.
-*/
-
-/*!
- \fn Qt::Orientation QWheelEvent::orientation() const
-
- Returns the wheel's orientation.
-*/
-
-/*!
- Constructs a wheel event object.
-
- The position, \a pos, is the location of the mouse cursor within
- the widget. The globalPos() is initialized to QCursor::pos()
- which is usually, but not always, correct.
- Use the other constructor if you need to specify the global
- position explicitly.
-
- The \a buttons describe the state of the mouse buttons at the time
- of the event, \a delta contains the rotation distance,
- \a modifiers holds the keyboard modifier flags at the time of the
- event, and \a orient holds the wheel's orientation.
-
- \sa pos() delta() state()
-*/
-#ifndef QT_NO_WHEELEVENT
-QWheelEvent::QWheelEvent(const QPoint &pos, int delta,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
- Qt::Orientation orient)
- : QInputEvent(Wheel, modifiers), p(pos), d(delta), mouseState(buttons), o(orient)
-{
- g = QCursor::pos();
-}
-
-/*!
- \internal
-*/
-QWheelEvent::~QWheelEvent()
-{
-}
-
-/*!
- Constructs a wheel event object.
-
- The \a pos provides the location of the mouse cursor
- within the widget. The position in global coordinates is specified
- by \a globalPos. \a delta contains the rotation distance, \a modifiers
- holds the keyboard modifier flags at the time of the event, and
- \a orient holds the wheel's orientation.
-
- \sa pos() globalPos() delta() state()
-*/
-QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
- Qt::Orientation orient)
- : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), d(delta), mouseState(buttons), o(orient)
-{}
-
-#endif // QT_NO_WHEELEVENT
-
-/*!
- \fn int QWheelEvent::delta() const
-
- Returns the distance that the wheel is rotated, in eighths of a
- degree. A positive value indicates that the wheel was rotated
- forwards away from the user; a negative value indicates that the
- wheel was rotated backwards toward the user.
-
- Most mouse types work in steps of 15 degrees, in which case the
- delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.
-
- However, some mice have finer-resolution wheels and send delta values
- that are less than 120 units (less than 15 degrees). To support this
- possibility, you can either cumulatively add the delta values from events
- until the value of 120 is reached, then scroll the widget, or you can
- partially scroll the widget in response to each wheel event.
-
- Example:
-
- \snippet doc/src/snippets/code/src_gui_kernel_qevent.cpp 0
-*/
-
-/*!
- \fn const QPoint &QWheelEvent::pos() const
-
- Returns the position of the mouse cursor relative to the widget
- that received the event.
-
- If you move your widgets around in response to mouse events,
- use globalPos() instead of this function.
-
- \sa x() y() globalPos()
-*/
-
-/*!
- \fn int QWheelEvent::x() const
-
- Returns the x position of the mouse cursor, relative to the
- widget that received the event.
-
- \sa y() pos()
-*/
-
-/*!
- \fn int QWheelEvent::y() const
-
- Returns the y position of the mouse cursor, relative to the
- widget that received the event.
-
- \sa x() pos()
-*/
-
-
-/*!
- \fn const QPoint &QWheelEvent::globalPos() const
-
- Returns the global position of the mouse pointer \e{at the time
- of the event}. This is important on asynchronous window systems
- such as X11; whenever you move your widgets around in response to
- mouse events, globalPos() can differ a lot from the current
- cursor position returned by QCursor::pos().
-
- \sa globalX() globalY()
-*/
-
-/*!
- \fn int QWheelEvent::globalX() const
-
- Returns the global x position of the mouse cursor at the time of
- the event.
-
- \sa globalY() globalPos()
-*/
-
-/*!
- \fn int QWheelEvent::globalY() const
-
- Returns the global y position of the mouse cursor at the time of
- the event.
-
- \sa globalX() globalPos()
-*/
-
-
-/*! \obsolete
- \fn Qt::ButtonState QWheelEvent::state() const
-
- Returns the keyboard modifier flags at the time of the event.
-
- The returned value is a selection of the following values,
- combined using the OR operator: Qt::ShiftButton,
- Qt::ControlButton, and Qt::AltButton.
-*/
-
-
-/*!
- \class QKeyEvent
- \brief The QKeyEvent class describes a key event.
-
- \ingroup events
-
- Key events are sent to the widget with keyboard input focus
- when keys are pressed or released.
-
- A key event contains a special accept flag that indicates whether
- the receiver will handle the key event. You should call ignore()
- if the key press or release event is not handled by your widget.
- A key event is propagated up the parent widget chain until a
- widget accepts it with accept() or an event filter consumes it.
- Key events for multimedia keys are ignored by default. You should
- call accept() if your widget handles those events.
-
- The QWidget::setEnable() function can be used to enable or disable
- mouse and keyboard events for a widget.
-
- The event handlers QWidget::keyPressEvent(), QWidget::keyReleaseEvent(),
- QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent()
- receive key events.
-
- \sa QFocusEvent, QWidget::grabKeyboard()
-*/
-
-/*!
- Constructs a key event object.
-
- The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease,
- or QEvent::ShortcutOverride.
-
- Int \a key is the code for the Qt::Key that the event loop should listen
- for. If \a key is 0, the event is not a result of a known key; for
- example, it may be the result of a compose sequence or keyboard macro.
- The \a modifiers holds the keyboard modifiers, and the given \a text
- is the Unicode text that the key generated. If \a autorep is true,
- isAutoRepeat() will be true. \a count is the number of keys involved
- in the event.
-*/
-QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text,
- bool autorep, ushort count)
- : QInputEvent(type, modifiers), txt(text), k(key), c(count), autor(autorep)
-{
-}
-
-/*!
- \internal
-*/
-QKeyEvent::~QKeyEvent()
-{
-}
-
-/*!
- \internal
-*/
-QKeyEvent *QKeyEvent::createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
- quint32 nativeScanCode, quint32 nativeVirtualKey,
- quint32 nativeModifiers,
- const QString& text, bool autorep, ushort count)
-{
- return new QKeyEventEx(type, key, modifiers, text, autorep, count,
- nativeScanCode, nativeVirtualKey, nativeModifiers);
-}
-
-/*!
- \fn bool QKeyEvent::hasExtendedInfo() const
- \internal
-*/
-
-/*!
- \since 4.2
-
- Returns the native scan code of the key event. If the key event
- does not contain this data 0 is returned.
-
- Note: The native scan code may be 0, even if the key event contains
- extended information.
-
- Note: On Mac OS/X, this function is not useful, because there is no
- way to get the scan code from Carbon or Cocoa. The function always
- returns 1 (or 0 in the case explained above).
-*/
-quint32 QKeyEvent::nativeScanCode() const
-{
- return (reinterpret_cast<const QKeyEvent*>(d) != this
- ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nScanCode);
-}
-
-/*!
- \since 4.2
-
- Returns the native virtual key, or key sym of the key event.
- If the key event does not contain this data 0 is returned.
-
- Note: The native virtual key may be 0, even if the key event contains extended information.
-*/
-quint32 QKeyEvent::nativeVirtualKey() const
-{
- return (reinterpret_cast<const QKeyEvent*>(d) != this
- ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nVirtualKey);
-}
-
-/*!
- \since 4.2
-
- Returns the native modifiers of a key event.
- If the key event does not contain this data 0 is returned.
-
- Note: The native modifiers may be 0, even if the key event contains extended information.
-*/
-quint32 QKeyEvent::nativeModifiers() const
-{
- return (reinterpret_cast<const QKeyEvent*>(d) != this
- ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nModifiers);
-}
-
-/*!
- \internal
- Creates an extended key event object, which in addition to the normal key event data, also
- contains the native scan code, virtual key and modifiers. This extra data is used by the
- shortcut system, to determine which shortcuts to trigger.
-*/
-QKeyEventEx::QKeyEventEx(Type type, int key, Qt::KeyboardModifiers modifiers,
- const QString &text, bool autorep, ushort count,
- quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers)
- : QKeyEvent(type, key, modifiers, text, autorep, count),
- nScanCode(nativeScanCode), nVirtualKey(nativeVirtualKey), nModifiers(nativeModifiers)
-{
- d = reinterpret_cast<QEventPrivate*>(this);
-}
-
-/*!
- \internal
- Creates a copy of an other extended key event.
-*/
-QKeyEventEx::QKeyEventEx(const QKeyEventEx &other)
- : QKeyEvent(QEvent::Type(other.t), other.k, other.modState, other.txt, other.autor, other.c),
- nScanCode(other.nScanCode), nVirtualKey(other.nVirtualKey), nModifiers(other.nModifiers)
-{
- d = reinterpret_cast<QEventPrivate*>(this);
-}
-
-/*!
- \internal
-*/
-QKeyEventEx::~QKeyEventEx()
-{
-}
-
-/*!
- \fn int QKeyEvent::key() const
-
- Returns the code of the key that was pressed or released.
-
- See \l Qt::Key for the list of keyboard codes. These codes are
- independent of the underlying window system. Note that this
- function does not distinguish between capital and non-capital
- letters, use the text() function (returning the Unicode text the
- key generated) for this purpose.
-
- A value of either 0 or Qt::Key_unknown means that the event is not
- the result of a known key; for example, it may be the result of
- a compose sequence, a keyboard macro, or due to key event
- compression.
-
- \sa Qt::WA_KeyCompression
-*/
-
-/*!
- \fn QString QKeyEvent::text() const
-
- Returns the Unicode text that this key generated. The text
- returned can be an empty string in cases
- where modifier keys, such as Shift, Control, Alt, and Meta,
- are being pressed or released. In such cases key() will contain
- a valid value.
-
- \sa Qt::WA_KeyCompression
-*/
-
-/*!
- Returns the keyboard modifier flags that existed immediately
- after the event occurred.
-
- \warning This function cannot always be trusted. The user can
- confuse it by pressing both \key{Shift} keys simultaneously and
- releasing one of them, for example.
-
- \sa QApplication::keyboardModifiers()
-*/
-//###### We must check with XGetModifierMapping
-Qt::KeyboardModifiers QKeyEvent::modifiers() const
-{
- if (key() == Qt::Key_Shift)
- return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ShiftModifier);
- if (key() == Qt::Key_Control)
- return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ControlModifier);
- if (key() == Qt::Key_Alt)
- return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::AltModifier);
- if (key() == Qt::Key_Meta)
- return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::MetaModifier);
- return QInputEvent::modifiers();
-}
-
-#ifndef QT_NO_SHORTCUT
-/*!
- \fn bool QKeyEvent::matches(QKeySequence::StandardKey key) const
- \since 4.2
-
- Returns true if the key event matches the given standard \a key;
- otherwise returns false.
-*/
-bool QKeyEvent::matches(QKeySequence::StandardKey matchKey) const
-{
- uint searchkey = (modifiers() | key()) & ~(Qt::KeypadModifier); //The keypad modifier should not make a difference
- uint platform = QApplicationPrivate::currentPlatform();
-
-#ifdef Q_WS_MAC
- if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
- uint oldSearchKey = searchkey;
- searchkey &= ~(Qt::ControlModifier | Qt::MetaModifier);
- if (oldSearchKey & Qt::ControlModifier)
- searchkey |= Qt::MetaModifier;
- if (oldSearchKey & Qt::MetaModifier)
- searchkey |= Qt::ControlModifier;
- }
-#endif
-
- uint N = QKeySequencePrivate::numberOfKeyBindings;
- int first = 0;
- int last = N - 1;
-
- while (first <= last) {
- int mid = (first + last) / 2;
- QKeyBinding midVal = QKeySequencePrivate::keyBindings[mid];
-
- if (searchkey > midVal.shortcut){
- first = mid + 1; // Search in top half
- }
- else if (searchkey < midVal.shortcut){
- last = mid - 1; // Search in bottom half
- }
- else {
- //found correct shortcut value, now we must check for platform match
- if ((midVal.platform & platform) && (midVal.standardKey == matchKey)) {
- return true;
- } else { //We may have several equal values for different platforms, so we must search in both directions
-
- //search forward
- for ( unsigned int i = mid + 1 ; i < N - 1 ; ++i) {
- QKeyBinding current = QKeySequencePrivate::keyBindings[i];
- if (current.shortcut != searchkey)
- break;
- else if (current.platform & platform && current.standardKey == matchKey)
- return true;
- }
-
- //search back
- for ( int i = mid - 1 ; i >= 0 ; --i) {
- QKeyBinding current = QKeySequencePrivate::keyBindings[i];
- if (current.shortcut != searchkey)
- break;
- else if (current.platform & platform && current.standardKey == matchKey)
- return true;
- }
- return false; //we could not find it among the matching keySequences
- }
- }
- }
- return false; //we could not find matching keySequences at all
-}
-#endif // QT_NO_SHORTCUT
-
-
-/*!
- \fn bool QKeyEvent::isAutoRepeat() const
-
- Returns true if this event comes from an auto-repeating key;
- returns false if it comes from an initial key press.
-
- Note that if the event is a multiple-key compressed event that is
- partly due to auto-repeat, this function could return either true
- or false indeterminately.
-*/
-
-/*!
- \fn int QKeyEvent::count() const
-
- Returns the number of keys involved in this event. If text()
- is not empty, this is simply the length of the string.
-
- \sa Qt::WA_KeyCompression
-*/
-
-/*!
- \class QFocusEvent
- \brief The QFocusEvent class contains event parameters for widget focus
- events.
-
- \ingroup events
-
- Focus events are sent to widgets when the keyboard input focus
- changes. Focus events occur due to mouse actions, key presses
- (such as \gui{Tab} or \gui{Backtab}), the window system, popup
- menus, keyboard shortcuts, or other application-specific reasons.
- The reason for a particular focus event is returned by reason()
- in the appropriate event handler.
-
- The event handlers QWidget::focusInEvent(),
- QWidget::focusOutEvent(), QGraphicsItem::focusInEvent and
- QGraphicsItem::focusOutEvent() receive focus events.
-
- \sa QWidget::setFocus(), QWidget::setFocusPolicy(), {Keyboard Focus}
-*/
-
-/*!
- Constructs a focus event object.
-
- The \a type parameter must be either QEvent::FocusIn or
- QEvent::FocusOut. The \a reason describes the cause of the change
- in focus.
-*/
-QFocusEvent::QFocusEvent(Type type, Qt::FocusReason reason)
- : QEvent(type), m_reason(reason)
-{}
-
-/*!
- \internal
-*/
-QFocusEvent::~QFocusEvent()
-{
-}
-
-// ### Qt 5: remove
-/*!
- \internal
- */
-Qt::FocusReason QFocusEvent::reason()
-{
- return m_reason;
-}
-
-/*!
- Returns the reason for this focus event.
- */
-Qt::FocusReason QFocusEvent::reason() const
-{
- return m_reason;
-}
-
-/*!
- \fn bool QFocusEvent::gotFocus() const
-
- Returns true if type() is QEvent::FocusIn; otherwise returns
- false.
-*/
-
-/*!
- \fn bool QFocusEvent::lostFocus() const
-
- Returns true if type() is QEvent::FocusOut; otherwise returns
- false.
-*/
-
-
-/*!
- \class QPaintEvent
- \brief The QPaintEvent class contains event parameters for paint events.
-
- \ingroup events
-
- Paint events are sent to widgets that need to update themselves,
- for instance when part of a widget is exposed because a covering
- widget was moved.
-
- The event contains a region() that needs to be updated, and a
- rect() that is the bounding rectangle of that region. Both are
- provided because many widgets can't make much use of region(),
- and rect() can be much faster than region().boundingRect().
-
- \section1 Automatic Clipping
-
- Painting is clipped to region() during the processing of a paint
- event. This clipping is performed by Qt's paint system and is
- independent of any clipping that may be applied to a QPainter used to
- draw on the paint device.
-
- As a result, the value returned by QPainter::clipRegion() on
- a newly-constructed QPainter will not reflect the clip region that is
- used by the paint system.
-
- \sa QPainter, QWidget::update(), QWidget::repaint(),
- QWidget::paintEvent()
-*/
-
-/*!
- \fn bool QPaintEvent::erased() const
- \compat
-
- Returns true if the paint event region (or rectangle) has been
- erased with the widget's background; otherwise returns false.
-
- Qt 4 \e always erases regions that require painting. The exception
- to this rule is if the widget sets the Qt::WA_OpaquePaintEvent or
- Qt::WA_NoSystemBackground attributes. If either one of those
- attributes is set \e and the window system does not make use of
- subwidget alpha composition (currently X11 and Windows, but this
- may change), then the region is not erased.
-*/
-
-/*!
- \fn void QPaintEvent::setErased(bool b) { m_erased = b; }
- \internal
-*/
-
-/*!
- Constructs a paint event object with the region that needs to
- be updated. The region is specified by \a paintRegion.
-*/
-QPaintEvent::QPaintEvent(const QRegion& paintRegion)
- : QEvent(Paint), m_rect(paintRegion.boundingRect()), m_region(paintRegion), m_erased(false)
-{}
-
-/*!
- Constructs a paint event object with the rectangle that needs
- to be updated. The region is specified by \a paintRect.
-*/
-QPaintEvent::QPaintEvent(const QRect &paintRect)
- : QEvent(Paint), m_rect(paintRect),m_region(paintRect), m_erased(false)
-{}
-
-
-/*!
- \internal
-*/
-QPaintEvent::~QPaintEvent()
-{
-}
-
-/*!
- \fn const QRect &QPaintEvent::rect() const
-
- Returns the rectangle that needs to be updated.
-
- \sa region() QPainter::setClipRect()
-*/
-
-/*!
- \fn const QRegion &QPaintEvent::region() const
-
- Returns the region that needs to be updated.
-
- \sa rect() QPainter::setClipRegion()
-*/
-
-
-QUpdateLaterEvent::QUpdateLaterEvent(const QRegion& paintRegion)
- : QEvent(UpdateLater), m_region(paintRegion)
-{
-}
-
-QUpdateLaterEvent::~QUpdateLaterEvent()
-{
-}
-
-/*!
- \class QMoveEvent
- \brief The QMoveEvent class contains event parameters for move events.
-
- \ingroup events
-
- Move events are sent to widgets that have been moved to a new
- position relative to their parent.
-
- The event handler QWidget::moveEvent() receives move events.
-
- \sa QWidget::move(), QWidget::setGeometry()
-*/
-
-/*!
- Constructs a move event with the new and old widget positions,
- \a pos and \a oldPos respectively.
-*/
-QMoveEvent::QMoveEvent(const QPoint &pos, const QPoint &oldPos)
- : QEvent(Move), p(pos), oldp(oldPos)
-{}
-
-/*!
- \internal
-*/
-QMoveEvent::~QMoveEvent()
-{
-}
-
-/*!
- \fn const QPoint &QMoveEvent::pos() const
-
- Returns the new position of the widget. This excludes the window
- frame for top level widgets.
-*/
-
-/*!
- \fn const QPoint &QMoveEvent::oldPos() const
-
- Returns the old position of the widget.
-*/
-
-
-/*!
- \class QResizeEvent
- \brief The QResizeEvent class contains event parameters for resize events.
-
- \ingroup events
-
- Resize events are sent to widgets that have been resized.
-
- The event handler QWidget::resizeEvent() receives resize events.
-
- \sa QWidget::resize() QWidget::setGeometry()
-*/
-
-/*!
- Constructs a resize event with the new and old widget sizes, \a
- size and \a oldSize respectively.
-*/
-QResizeEvent::QResizeEvent(const QSize &size, const QSize &oldSize)
- : QEvent(Resize), s(size), olds(oldSize)
-{}
-
-/*!
- \internal
-*/
-QResizeEvent::~QResizeEvent()
-{
-}
-
-/*!
- \fn const QSize &QResizeEvent::size() const
-
- Returns the new size of the widget. This is the same as
- QWidget::size().
-*/
-
-/*!
- \fn const QSize &QResizeEvent::oldSize() const
-
- Returns the old size of the widget.
-*/
-
-
-/*!
- \class QCloseEvent
- \brief The QCloseEvent class contains parameters that describe a close event.
-
- \ingroup events
-
- Close events are sent to widgets that the user wants to close,
- usually by choosing "Close" from the window menu, or by clicking
- the \gui{X} title bar button. They are also sent when you call
- QWidget::close() to close a widget programmatically.
-
- Close events contain a flag that indicates whether the receiver
- wants the widget to be closed or not. When a widget accepts the
- close event, it is hidden (and destroyed if it was created with
- the Qt::WA_DeleteOnClose flag). If it refuses to accept the close
- event nothing happens. (Under X11 it is possible that the window
- manager will forcibly close the window; but at the time of writing
- we are not aware of any window manager that does this.)
-
- The event handler QWidget::closeEvent() receives close events. The
- default implementation of this event handler accepts the close
- event. If you do not want your widget to be hidden, or want some
- special handing, you should reimplement the event handler and
- ignore() the event.
-
- The \l{mainwindows/application#close event handler}{closeEvent() in the
- Application example} shows a close event handler that
- asks whether to save a document before closing.
-
- If you want the widget to be deleted when it is closed, create it
- with the Qt::WA_DeleteOnClose flag. This is very useful for
- independent top-level windows in a multi-window application.
-
- \l{QObject}s emits the \l{QObject::destroyed()}{destroyed()}
- signal when they are deleted.
-
- If the last top-level window is closed, the
- QApplication::lastWindowClosed() signal is emitted.
-
- The isAccepted() function returns true if the event's receiver has
- agreed to close the widget; call accept() to agree to close the
- widget and call ignore() if the receiver of this event does not
- want the widget to be closed.
-
- \sa QWidget::close(), QWidget::hide(), QObject::destroyed(),
- QCoreApplication::exec(), QCoreApplication::quit(),
- QApplication::lastWindowClosed()
-*/
-
-/*!
- Constructs a close event object.
-
- \sa accept()
-*/
-QCloseEvent::QCloseEvent()
- : QEvent(Close)
-{}
-
-/*! \internal
-*/
-QCloseEvent::~QCloseEvent()
-{
-}
-
-/*!
- \class QIconDragEvent
- \brief The QIconDragEvent class indicates that a main icon drag has begun.
-
- \ingroup events
-
- Icon drag events are sent to widgets when the main icon of a window
- has been dragged away. On Mac OS X, this happens when the proxy
- icon of a window is dragged off the title bar.
-
- It is normal to begin using drag and drop in response to this
- event.
-
- \sa {Drag and Drop}, QMimeData, QDrag
-*/
-
-/*!
- Constructs an icon drag event object with the accept flag set to
- false.
-
- \sa accept()
-*/
-QIconDragEvent::QIconDragEvent()
- : QEvent(IconDrag)
-{ ignore(); }
-
-/*! \internal */
-QIconDragEvent::~QIconDragEvent()
-{
-}
-
-/*!
- \class QContextMenuEvent
- \brief The QContextMenuEvent class contains parameters that describe a context menu event.
-
- \ingroup events
-
- Context menu events are sent to widgets when a user performs
- an action associated with opening a context menu.
- The actions required to open context menus vary between platforms;
- for example, on Windows, pressing the menu button or clicking the
- right mouse button will cause this event to be sent.
-
- When this event occurs it is customary to show a QMenu with a
- context menu, if this is relevant to the context.
-
- Context menu events contain a special accept flag that indicates
- whether the receiver accepted the event. If the event handler does
- not accept the event then, if possible, whatever triggered the event will be
- handled as a regular input event.
-*/
-
-#ifndef QT_NO_CONTEXTMENU
-/*!
- Constructs a context menu event object with the accept parameter
- flag set to false.
-
- The \a reason parameter must be QContextMenuEvent::Mouse or
- QContextMenuEvent::Keyboard.
-
- The \a pos parameter specifies the mouse position relative to the
- receiving widget. \a globalPos is the mouse position in absolute
- coordinates.
-*/
-QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos)
- : QInputEvent(ContextMenu), p(pos), gp(globalPos), reas(reason)
-{}
-
-/*!
- Constructs a context menu event object with the accept parameter
- flag set to false.
-
- The \a reason parameter must be QContextMenuEvent::Mouse or
- QContextMenuEvent::Keyboard.
-
- The \a pos parameter specifies the mouse position relative to the
- receiving widget. \a globalPos is the mouse position in absolute
- coordinates. The \a modifiers holds the keyboard modifiers.
-*/
-QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
- Qt::KeyboardModifiers modifiers)
- : QInputEvent(ContextMenu, modifiers), p(pos), gp(globalPos), reas(reason)
-{}
-
-
-/*! \internal */
-QContextMenuEvent::~QContextMenuEvent()
-{
-}
-/*!
- Constructs a context menu event object with the accept parameter
- flag set to false.
-
- The \a reason parameter must be QContextMenuEvent::Mouse or
- QContextMenuEvent::Keyboard.
-
- The \a pos parameter specifies the mouse position relative to the
- receiving widget.
-
- The globalPos() is initialized to QCursor::pos(), which may not be
- appropriate. Use the other constructor to specify the global
- position explicitly.
-*/
-QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
- : QInputEvent(ContextMenu), p(pos), reas(reason)
-{
- gp = QCursor::pos();
-}
-
-/*!
- \fn const QPoint &QContextMenuEvent::pos() const
-
- Returns the position of the mouse pointer relative to the widget
- that received the event.
-
- \sa x(), y(), globalPos()
-*/
-
-/*!
- \fn int QContextMenuEvent::x() const
-
- Returns the x position of the mouse pointer, relative to the
- widget that received the event.
-
- \sa y(), pos()
-*/
-
-/*!
- \fn int QContextMenuEvent::y() const
-
- Returns the y position of the mouse pointer, relative to the
- widget that received the event.
-
- \sa x(), pos()
-*/
-
-/*!
- \fn const QPoint &QContextMenuEvent::globalPos() const
-
- Returns the global position of the mouse pointer at the time of
- the event.
-
- \sa x(), y(), pos()
-*/
-
-/*!
- \fn int QContextMenuEvent::globalX() const
-
- Returns the global x position of the mouse pointer at the time of
- the event.
-
- \sa globalY(), globalPos()
-*/
-
-/*!
- \fn int QContextMenuEvent::globalY() const
-
- Returns the global y position of the mouse pointer at the time of
- the event.
-
- \sa globalX(), globalPos()
-*/
-#endif // QT_NO_CONTEXTMENU
-
-/*!
- \fn Qt::ButtonState QContextMenuEvent::state() const
-
- Returns the button state (a combination of mouse buttons
- and keyboard modifiers) immediately before the event was
- generated.
-
- The returned value is a selection of the following values,
- combined with the OR operator:
- Qt::LeftButton, Qt::RightButton, Qt::MidButton,
- Qt::ShiftButton, Qt::ControlButton, and Qt::AltButton.
-*/
-
-/*!
- \enum QContextMenuEvent::Reason
-
- This enum describes the reason why the event was sent.
-
- \value Mouse The mouse caused the event to be sent. Normally this
- means the right mouse button was clicked, but this is platform
- dependent.
-
- \value Keyboard The keyboard caused this event to be sent. On
- Windows, this means the menu button was pressed.
-
- \value Other The event was sent by some other means (i.e. not by
- the mouse or keyboard).
-*/
-
-
-/*!
- \fn QContextMenuEvent::Reason QContextMenuEvent::reason() const
-
- Returns the reason for this context event.
-*/
-
-
-/*!
- \class QInputMethodEvent
- \brief The QInputMethodEvent class provides parameters for input method events.
-
- \ingroup events
-
- Input method events are sent to widgets when an input method is
- used to enter text into a widget. Input methods are widely used
- to enter text for languages with non-Latin alphabets.
-
- Note that when creating custom text editing widgets, the
- Qt::WA_InputMethodEnabled window attribute must be set explicitly
- (using the QWidget::setAttribute() function) in order to receive
- input method events.
-
- The events are of interest to authors of keyboard entry widgets
- who want to be able to correctly handle languages with complex
- character input. Text input in such languages is usually a three
- step process:
-
- \list 1
- \o \bold{Starting to Compose}
-
- When the user presses the first key on a keyboard, an input
- context is created. This input context will contain a string
- of the typed characters.
-
- \o \bold{Composing}
-
- With every new key pressed, the input method will try to create a
- matching string for the text typed so far called preedit
- string. While the input context is active, the user can only move
- the cursor inside the string belonging to this input context.
-
- \o \bold{Completing}
-
- At some point, the user will activate a user interface component
- (perhaps using a particular key) where they can choose from a
- number of strings matching the text they have typed so far. The
- user can either confirm their choice cancel the input; in either
- case the input context will be closed.
- \endlist
-
- QInputMethodEvent models these three stages, and transfers the
- information needed to correctly render the intermediate result. A
- QInputMethodEvent has two main parameters: preeditString() and
- commitString(). The preeditString() parameter gives the currently
- active preedit string. The commitString() parameter gives a text
- that should get added to (or replace parts of) the text of the
- editor widget. It usually is a result of the input operations and
- has to be inserted to the widgets text directly before the preedit
- string.
-
- If the commitString() should replace parts of the of the text in
- the editor, replacementLength() will contain the number of
- characters to be replaced. replacementStart() contains the position
- at which characters are to be replaced relative from the start of
- the preedit string.
-
- A number of attributes control the visual appearance of the
- preedit string (the visual appearance of text outside the preedit
- string is controlled by the widget only). The AttributeType enum
- describes the different attributes that can be set.
-
- A class implementing QWidget::inputMethodEvent() or
- QGraphicsItem::inputMethodEvent() should at least understand and
- honor the \l TextFormat and \l Cursor attributes.
-
- Since input methods need to be able to query certain properties
- from the widget or graphics item, subclasses must also implement
- QWidget::inputMethodQuery() and QGraphicsItem::inputMethodQuery(),
- respectively.
-
- When receiving an input method event, the text widget has to performs the
- following steps:
-
- \list 1
- \o If the widget has selected text, the selected text should get
- removed.
-
- \o Remove the text starting at replacementStart() with length
- replacementLength() and replace it by the commitString(). If
- replacementLength() is 0, replacementStart() gives the insertion
- position for the commitString().
-
- When doing replacement the area of the preedit
- string is ignored, thus a replacement starting at -1 with a length
- of 2 will remove the last character before the preedit string and
- the first character afterwards, and insert the commit string
- directly before the preedit string.
-
- If the widget implements undo/redo, this operation gets added to
- the undo stack.
-
- \o If there is no current preedit string, insert the
- preeditString() at the current cursor position; otherwise replace
- the previous preeditString with the one received from this event.
-
- If the widget implements undo/redo, the preeditString() should not
- influence the undo/redo stack in any way.
-
- The widget should examine the list of attributes to apply to the
- preedit string. It has to understand at least the TextFormat and
- Cursor attributes and render them as specified.
- \endlist
-
- \sa QInputContext
-*/
-
-/*!
- \enum QInputMethodEvent::AttributeType
-
- \value TextFormat
- A QTextCharFormat for the part of the preedit string specified by
- start and length. value contains a QVariant of type QTextFormat
- specifying rendering of this part of the preedit string. There
- should be at most one format for every part of the preedit
- string. If several are specified for any character in the string the
- behaviour is undefined. A conforming implementation has to at least
- honor the backgroundColor, textColor and fontUnderline properties
- of the format.
-
- \value Cursor If set, a cursor should be shown inside the preedit
- string at position start. The length variable determines whether
- the cursor is visible or not. If the length is 0 the cursor is
- invisible. If value is a QVariant of type QColor this color will
- be used for rendering the cursor, otherwise the color of the
- surrounding text will be used. There should be at most one Cursor
- attribute per event. If several are specified the behaviour is
- undefined.
-
- \value Language
- The variant contains a QLocale object specifying the language of a
- certain part of the preedit string. There should be at most one
- language set for every part of the preedit string. If several are
- specified for any character in the string the behavior is undefined.
-
- \value Ruby
- The ruby text for a part of the preedit string. There should be at
- most one ruby text set for every part of the preedit string. If
- several are specified for any character in the string the behaviour
- is undefined.
-
- \value Selection
- If set, the edit cursor should be moved to the specified position
- in the editor text contents. In contrast with \c Cursor, this
- attribute does not work on the preedit text, but on the surrounding
- text. The cursor will be moved after the commit string has been
- committed, and the preedit string will be located at the new edit
- position.
- The start position specifies the new position and the length
- variable can be used to set a selection starting from that point.
- The value is unused.
-
- \sa Attribute
-*/
-
-/*!
- \class QInputMethodEvent::Attribute
- \brief The QInputMethodEvent::Attribute class stores an input method attribute.
-*/
-
-/*!
- \fn QInputMethodEvent::Attribute::Attribute(AttributeType type, int start, int length, QVariant value)
-
- Constructs an input method attribute. \a type specifies the type
- of attribute, \a start and \a length the position of the
- attribute, and \a value the value of the attribute.
-*/
-
-/*!
- Constructs an event of type QEvent::InputMethod. The
- attributes(), preeditString(), commitString(), replacementStart(),
- and replacementLength() are initialized to default values.
-
- \sa setCommitString()
-*/
-QInputMethodEvent::QInputMethodEvent()
- : QEvent(QEvent::InputMethod), replace_from(0), replace_length(0)
-{
-}
-
-/*!
- Construcs an event of type QEvent::InputMethod. The
- preedit text is set to \a preeditText, the attributes to
- \a attributes.
-
- The commitString(), replacementStart(), and replacementLength()
- values can be set using setCommitString().
-
- \sa preeditString(), attributes()
-*/
-QInputMethodEvent::QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes)
- : QEvent(QEvent::InputMethod), preedit(preeditText), attrs(attributes),
- replace_from(0), replace_length(0)
-{
-}
-
-/*!
- Constructs a copy of \a other.
-*/
-QInputMethodEvent::QInputMethodEvent(const QInputMethodEvent &other)
- : QEvent(QEvent::InputMethod), preedit(other.preedit), attrs(other.attrs),
- commit(other.commit), replace_from(other.replace_from), replace_length(other.replace_length)
-{
-}
-
-/*!
- Sets the commit string to \a commitString.
-
- The commit string is the text that should get added to (or
- replace parts of) the text of the editor widget. It usually is a
- result of the input operations and has to be inserted to the
- widgets text directly before the preedit string.
-
- If the commit string should replace parts of the of the text in
- the editor, \a replaceLength specifies the number of
- characters to be replaced. \a replaceFrom specifies the position
- at which characters are to be replaced relative from the start of
- the preedit string.
-
- \sa commitString(), replacementStart(), replacementLength()
-*/
-void QInputMethodEvent::setCommitString(const QString &commitString, int replaceFrom, int replaceLength)
-{
- commit = commitString;
- replace_from = replaceFrom;
- replace_length = replaceLength;
-}
-
-/*!
- \fn const QList<Attribute> &QInputMethodEvent::attributes() const
-
- Returns the list of attributes passed to the QInputMethodEvent
- constructor. The attributes control the visual appearance of the
- preedit string (the visual appearance of text outside the preedit
- string is controlled by the widget only).
-
- \sa preeditString(), Attribute
-*/
-
-/*!
- \fn const QString &QInputMethodEvent::preeditString() const
-
- Returns the preedit text, i.e. the text before the user started
- editing it.
-
- \sa commitString(), attributes()
-*/
-
-/*!
- \fn const QString &QInputMethodEvent::commitString() const
-
- Returns the text that should get added to (or replace parts of)
- the text of the editor widget. It usually is a result of the
- input operations and has to be inserted to the widgets text
- directly before the preedit string.
-
- \sa setCommitString(), preeditString(), replacementStart(), replacementLength()
-*/
-
-/*!
- \fn int QInputMethodEvent::replacementStart() const
-
- Returns the position at which characters are to be replaced relative
- from the start of the preedit string.
-
- \sa replacementLength(), setCommitString()
-*/
-
-/*!
- \fn int QInputMethodEvent::replacementLength() const
-
- Returns the number of characters to be replaced in the preedit
- string.
-
- \sa replacementStart(), setCommitString()
-*/
-
-#ifndef QT_NO_TABLETEVENT
-
-/*!
- \class QTabletEvent
- \brief The QTabletEvent class contains parameters that describe a Tablet event.
-
- \ingroup events
-
- Tablet Events are generated from a Wacom tablet. Most of the time you will
- want to deal with events from the tablet as if they were events from a
- mouse; for example, you would retrieve the cursor position with x(), y(),
- pos(), globalX(), globalY(), and globalPos(). In some situations you may
- wish to retrieve the extra information provided by the tablet device
- driver; for example, you might want to do subpixeling with higher
- resolution coordinates or you may want to adjust color brightness based on
- pressure. QTabletEvent allows you to read the pressure(), the xTilt(), and
- yTilt(), as well as the type of device being used with device() (see
- \l{TabletDevice}). It can also give you the minimum and maximum values for
- each device's pressure and high resolution coordinates.
-
- A tablet event contains a special accept flag that indicates whether the
- receiver wants the event. You should call QTabletEvent::accept() if you
- handle the tablet event; otherwise it will be sent to the parent widget.
- The exception are TabletEnterProximity and TabletLeaveProximity events,
- these are only sent to QApplication and don't check whether or not they are
- accepted.
-
- The QWidget::setEnabled() function can be used to enable or
- disable mouse and keyboard events for a widget.
-
- The event handler QWidget::tabletEvent() receives all three types of
- tablet events. Qt will first send a tabletEvent then, if it is not
- accepted, it will send a mouse event. This allows applications that
- don't utilize tablets to use a tablet like a mouse, while also
- enabling those who want to use both tablets and mouses differently.
-
- \section1 Notes for X11 Users
-
- Qt uses the following hard-coded names to identify tablet
- devices from the xorg.conf file on X11 (apart from IRIX):
- 'stylus', 'pen', and 'eraser'. If the devices have other names,
- they will not be picked up Qt.
-*/
-
-/*!
- \enum QTabletEvent::TabletDevice
-
- This enum defines what type of device is generating the event.
-
- \value NoDevice No device, or an unknown device.
- \value Puck A Puck (a device that is similar to a flat mouse with
- a transparent circle with cross-hairs).
- \value Stylus A Stylus.
- \value Airbrush An airbrush
- \value FourDMouse A 4D Mouse.
- \value RotationStylus A special stylus that also knows about rotation
- (a 6D stylus). \since 4.1
- \omitvalue XFreeEraser
-*/
-
-/*!
- \enum QTabletEvent::PointerType
-
- This enum defines what type of point is generating the event.
-
- \value UnknownPointer An unknown device.
- \value Pen Tip end of a stylus-like device (the narrow end of the pen).
- \value Cursor Any puck-like device.
- \value Eraser Eraser end of a stylus-like device (the broad end of the pen).
-
- \sa pointerType()
-*/
-
-/*!
- Construct a tablet event of the given \a type.
-
- The \a pos parameter indicates where the event occurred in the
- widget; \a globalPos is the corresponding position in absolute
- coordinates. The \a hiResGlobalPos contains a high resolution
- measurement of the position.
-
- \a pressure contains the pressure exerted on the \a device.
-
- \a pointerType describes the type of pen that is being used.
-
- \a xTilt and \a yTilt contain the device's degree of tilt from the
- x and y axes respectively.
-
- \a keyState specifies which keyboard modifiers are pressed (e.g.,
- \key{Ctrl}).
-
- The \a uniqueID parameter contains the unique ID for the current device.
-
- The \a z parameter contains the coordinate of the device on the tablet, this
- is usually given by a wheel on 4D mouse. If the device does not support a
- Z-axis, pass zero here.
-
- The \a tangentialPressure parameter contins the tangential pressure of an air
- brush. If the device does not support tangential pressure, pass 0 here.
-
- \a rotation contains the device's rotation in degrees. 4D mice support
- rotation. If the device does not support rotation, pass 0 here.
-
- \sa pos() globalPos() device() pressure() xTilt() yTilt() uniqueId(), rotation(), tangentialPressure(), z()
-*/
-
-QTabletEvent::QTabletEvent(Type type, const QPoint &pos, const QPoint &globalPos,
- const QPointF &hiResGlobalPos, int device, int pointerType,
- qreal pressure, int xTilt, int yTilt, qreal tangentialPressure,
- qreal rotation, int z, Qt::KeyboardModifiers keyState, qint64 uniqueID)
- : QInputEvent(type, keyState),
- mPos(pos),
- mGPos(globalPos),
- mHiResGlobalPos(hiResGlobalPos),
- mDev(device),
- mPointerType(pointerType),
- mXT(xTilt),
- mYT(yTilt),
- mZ(z),
- mPress(pressure),
- mTangential(tangentialPressure),
- mRot(rotation),
- mUnique(uniqueID),
- mExtra(0)
-{
-}
-
-/*!
- \internal
-*/
-QTabletEvent::~QTabletEvent()
-{
-}
-
-/*!
- \fn TabletDevices QTabletEvent::device() const
-
- Returns the type of device that generated the event.
-
- \sa TabletDevice
-*/
-
-/*!
- \fn PointerType QTabletEvent::pointerType() const
-
- Returns the type of point that generated the event.
-*/
-
-/*!
- \fn qreal QTabletEvent::tangentialPressure() const
-
- Returns the tangential pressure for the device. This is typically given by a finger
- wheel on an airbrush tool. The range is from -1.0 to 1.0. 0.0 indicates a
- neutral position. Current airbrushes can only move in the positive
- direction from the neutrual position. If the device does not support
- tangential pressure, this value is always 0.0.
-
- \sa pressure()
-*/
-
-/*!
- \fn qreal QTabletEvent::rotation() const
-
- Returns the rotation of the current device in degress. This is usually
- given by a 4D Mouse. If the device doesn't support rotation this value is
- always 0.0.
-
-*/
-
-/*!
- \fn qreal QTabletEvent::pressure() const
-
- Returns the pressure for the device. 0.0 indicates that the stylus is not
- on the tablet, 1.0 indicates the maximum amount of pressure for the stylus.
-
- \sa tangentialPressure()
-*/
-
-/*!
- \fn int QTabletEvent::xTilt() const
-
- Returns the angle between the device (a pen, for example) and the
- perpendicular in the direction of the x axis.
- Positive values are towards the tablet's physical right. The angle
- is in the range -60 to +60 degrees.
-
- \img qtabletevent-tilt.png
-
- \sa yTilt()
-*/
-
-/*!
- \fn int QTabletEvent::yTilt() const
-
- Returns the angle between the device (a pen, for example) and the
- perpendicular in the direction of the y axis.
- Positive values are towards the bottom of the tablet. The angle is
- within the range -60 to +60 degrees.
-
- \sa xTilt()
-*/
-
-/*!
- \fn const QPoint &QTabletEvent::pos() const
-
- Returns the position of the device, relative to the widget that
- received the event.
-
- If you move widgets around in response to mouse events, use
- globalPos() instead of this function.
-
- \sa x() y() globalPos()
-*/
-
-/*!
- \fn int QTabletEvent::x() const
-
- Returns the x position of the device, relative to the widget that
- received the event.
-
- \sa y() pos()
-*/
-
-/*!
- \fn int QTabletEvent::y() const
-
- Returns the y position of the device, relative to the widget that
- received the event.
-
- \sa x() pos()
-*/
-
-/*!
- \fn int QTabletEvent::z() const
-
- Returns the z position of the device. Typically this is represented by a
- wheel on a 4D Mouse. If the device does not support a Z-axis, this value is
- always zero. This is \bold not the same as pressure.
-
- \sa pressure()
-*/
-
-/*!
- \fn const QPoint &QTabletEvent::globalPos() const
-
- Returns the global position of the device \e{at the time of the
- event}. This is important on asynchronous windows systems like X11;
- whenever you move your widgets around in response to mouse events,
- globalPos() can differ significantly from the current position
- QCursor::pos().
-
- \sa globalX() globalY() hiResGlobalPos()
-*/
-
-/*!
- \fn int QTabletEvent::globalX() const
-
- Returns the global x position of the mouse pointer at the time of
- the event.
-
- \sa globalY() globalPos() hiResGlobalX()
-*/
-
-/*!
- \fn int QTabletEvent::globalY() const
-
- Returns the global y position of the tablet device at the time of
- the event.
-
- \sa globalX() globalPos() hiResGlobalY()
-*/
-
-/*!
- \fn qint64 QTabletEvent::uniqueId() const
-
- Returns a unique ID for the current device, making it possible
- to differentiate between multiple devices being used at the same
- time on the tablet.
-
- Support of this feature is dependent on the tablet.
-
- Values for the same device may vary from OS to OS.
-
- Later versions of the Wacom driver for Linux will now report
- the ID information. If you have a tablet that supports unique ID
- and are not getting the information on Linux, consider upgrading
- your driver.
-
- As of Qt 4.2, the unique ID is the same regardless of the orientation
- of the pen. Earlier versions would report a different value when using
- the eraser-end versus the pen-end of the stylus on some OS's.
-
- \sa pointerType()
-*/
-
-/*!
- \fn const QPointF &QTabletEvent::hiResGlobalPos() const
-
- The high precision coordinates delivered from the tablet expressed.
- Sub pixeling information is in the fractional part of the QPointF.
-
- \sa globalPos() hiResGlobalX() hiResGlobalY()
-*/
-
-/*!
- \fn qreal &QTabletEvent::hiResGlobalX() const
-
- The high precision x position of the tablet device.
-*/
-
-/*!
- \fn qreal &QTabletEvent::hiResGlobalY() const
-
- The high precision y position of the tablet device.
-*/
-
-#endif // QT_NO_TABLETEVENT
-
-#ifndef QT_NO_DRAGANDDROP
-/*!
- Creates a QDragMoveEvent of the required \a type indicating
- that the mouse is at position \a pos given within a widget.
-
- The mouse and keyboard states are specified by \a buttons and
- \a modifiers, and the \a actions describe the types of drag
- and drop operation that are possible.
- The drag data is passed as MIME-encoded information in \a data.
-
- \warning Do not attempt to create a QDragMoveEvent yourself.
- These objects rely on Qt's internal state.
-*/
-QDragMoveEvent::QDragMoveEvent(const QPoint& pos, Qt::DropActions actions, const QMimeData *data,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
- : QDropEvent(pos, actions, data, buttons, modifiers, type)
- , rect(pos, QSize(1, 1))
-{}
-
-/*!
- Destroys the event.
-*/
-QDragMoveEvent::~QDragMoveEvent()
-{
-}
-
-/*!
- \fn void QDragMoveEvent::accept(bool y)
-
- Calls setAccepted(\a y) instead.
-*/
-
-/*!
- \fn void QDragMoveEvent::accept(const QRect &rectangle)
-
- The same as accept(), but also notifies that future moves will
- also be acceptable if they remain within the \a rectangle
- given on the widget. This can improve performance, but may
- also be ignored by the underlying system.
-
- If the rectangle is empty, drag move events will be sent
- continuously. This is useful if the source is scrolling in a
- timer event.
-*/
-
-/*!
- \fn void QDragMoveEvent::accept()
-
- \overload
-
- Calls QDropEvent::accept().
-*/
-
-/*!
- \fn void QDragMoveEvent::ignore()
-
- \overload
-
- Calls QDropEvent::ignore().
-*/
-
-/*!
- \fn void QDragMoveEvent::ignore(const QRect &rectangle)
-
- The opposite of the accept(const QRect&) function.
- Moves within the \a rectangle are not acceptable, and will be
- ignored.
-*/
-
-/*!
- \fn QRect QDragMoveEvent::answerRect() const
-
- Returns the rectangle in the widget where the drop will occur if accepted.
- You can use this information to restrict drops to certain places on the
- widget.
-*/
-
-
-/*!
- \class QDropEvent
- \ingroup events
- \ingroup draganddrop
-
- \brief The QDropEvent class provides an event which is sent when a
- drag and drop action is completed.
-
- When a widget \l{QWidget::setAcceptDrops()}{accepts drop events}, it will
- receive this event if it has accepted the most recent QDragEnterEvent or
- QDragMoveEvent sent to it.
-
- The drop event contains a proposed action, available from proposedAction(), for
- the widget to either accept or ignore. If the action can be handled by the
- widget, you should call the acceptProposedAction() function. Since the
- proposed action can be a combination of \l Qt::DropAction values, it may be
- useful to either select one of these values as a default action or ask
- the user to select their preferred action.
-
- If the proposed drop action is not suitable, perhaps because your custom
- widget does not support that action, you can replace it with any of the
- \l{possibleActions()}{possible drop actions} by calling setDropAction()
- with your preferred action. If you set a value that is not present in the
- bitwise OR combination of values returned by possibleActions(), the default
- copy action will be used. Once a replacement drop action has been set, call
- accept() instead of acceptProposedAction() to complete the drop operation.
-
- The mimeData() function provides the data dropped on the widget in a QMimeData
- object. This contains information about the MIME type of the data in addition to
- the data itself.
-
- \sa QMimeData, QDrag, {Drag and Drop}
-*/
-
-/*!
- \fn const QMimeData *QDropEvent::mimeData() const
-
- Returns the data that was dropped on the widget and its associated MIME
- type information.
-*/
-
-/*!
- Constructs a drop event of a certain \a type corresponding to a
- drop at the point specified by \a pos in the destination widget's
- coordinate system.
-
- The \a actions indicate which types of drag and drop operation can
- be performed, and the drag data is stored as MIME-encoded data in \a data.
-
- The states of the mouse buttons and keyboard modifiers at the time of
- the drop are specified by \a buttons and \a modifiers.
-*/ // ### pos is in which coordinate system?
-QDropEvent::QDropEvent(const QPoint& pos, Qt::DropActions actions, const QMimeData *data,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
- : QEvent(type), p(pos), mouseState(buttons),
- modState(modifiers), act(actions),
- mdata(data)
-{
- default_action = QDragManager::self()->defaultAction(act, modifiers);
- drop_action = default_action;
- ignore();
-}
-
-/*! \internal */
-QDropEvent::~QDropEvent()
-{
-}
-
-/*!
- \compat
- Returns a byte array containing the drag's data, in \a format.
-
- data() normally needs to get the data from the drag source, which
- is potentially very slow, so it's advisable to call this function
- only if you're sure that you will need the data in that
- particular \a format.
-
- The resulting data will have a size of 0 if the format was not
- available.
-
- \sa format() QByteArray::size()
-*/
-
-QByteArray QDropEvent::encodedData(const char *format) const
-{
- return mdata->data(QLatin1String(format));
-}
-
-/*!
- \compat
- Returns a string describing one of the available data types for
- this drag. Common examples are "text/plain" and "image/gif".
- If \a n is less than zero or greater than the number of available
- data types, format() returns 0.
-
- This function is provided mainly for debugging. Most drop targets
- will use provides().
-
- \sa data() provides()
-*/
-
-const char* QDropEvent::format(int n) const
-{
- if (fmts.isEmpty()) {
- QStringList formats = mdata->formats();
- for (int i = 0; i < formats.size(); ++i)
- fmts.append(formats.at(i).toLatin1());
- }
- if (n < 0 || n >= fmts.size())
- return 0;
- return fmts.at(n).constData();
-}
-
-/*!
- \compat
- Returns true if this event provides format \a mimeType; otherwise
- returns false.
-
- \sa data()
-*/
-
-bool QDropEvent::provides(const char *mimeType) const
-{
- return mdata->formats().contains(QLatin1String(mimeType));
-}
-
-/*!
- If the source of the drag operation is a widget in this
- application, this function returns that source; otherwise it
- returns 0. The source of the operation is the first parameter to
- the QDrag object used instantiate the drag.
-
- This is useful if your widget needs special behavior when dragging
- to itself.
-
- \sa QDrag::QDrag()
-*/
-QWidget* QDropEvent::source() const
-{
- QDragManager *manager = QDragManager::self();
- return manager ? manager->source() : 0;
-}
-
-
-void QDropEvent::setDropAction(Qt::DropAction action)
-{
- if (!(action & act) && action != Qt::IgnoreAction)
- action = default_action;
- drop_action = action;
-}
-
-/*!
- \fn const QPoint& QDropEvent::pos() const
-
- Returns the position where the drop was made.
-*/
-
-/*!
- \fn Qt::MouseButtons QDropEvent::mouseButtons() const
-
- Returns the mouse buttons that are pressed..
-*/
-
-/*!
- \fn Qt::KeyboardModifiers QDropEvent::keyboardModifiers() const
-
- Returns the modifier keys that are pressed.
-*/
-
-/*!
- \fn void QDropEvent::accept()
- \internal
-*/
-
-/*!
- \fn void QDropEvent::accept(bool accept)
-
- Call setAccepted(\a accept) instead.
-*/
-
-/*!
- \fn void QDropEvent::acceptAction(bool accept = true)
-
- Call this to indicate that the action described by action() is
- accepted (i.e. if \a accept is true, which is the default), not merely
- the default copy action. If you call acceptAction(true), there is
- no need to also call accept(true).
-*/
-
-/*!
- \enum QDropEvent::Action
- \compat
-
- When a drag and drop action is completed, the target is expected
- to perform an action on the data provided by the source. This