summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2011-05-04 14:37:50 +0200
committerLars Knoll <lars.knoll@nokia.com>2011-05-04 14:39:19 +0200
commitbd8d12b7f68ea8aa05a86cc9ed65dd660a6b075d (patch)
treea2da73cfac60aa2b86fee223b5c28d813dcc69cd /src/gui/kernel
parentdc0f9f02a5c390f4a7919db4c32d22cebaf71d1c (diff)
move platform specific files out of the way
Keep the files as reference to implement the lighthouse plugins, but move them away from the main directory hierachy as they won't be part of Qt5 in any case.
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qapplication_mac.mm3134
-rw-r--r--src/gui/kernel/qapplication_s60.cpp2712
-rw-r--r--src/gui/kernel/qapplication_win.cpp4243
-rw-r--r--src/gui/kernel/qapplication_x11.cpp6239
-rw-r--r--src/gui/kernel/qcocoaapplication_mac.mm222
-rw-r--r--src/gui/kernel/qcocoaapplication_mac_p.h117
-rw-r--r--src/gui/kernel/qcocoaapplicationdelegate_mac.mm354
-rw-r--r--src/gui/kernel/qcocoaapplicationdelegate_mac_p.h128
-rw-r--r--src/gui/kernel/qcocoaintrospection_mac.mm125
-rw-r--r--src/gui/kernel/qcocoaintrospection_p.h84
-rw-r--r--src/gui/kernel/qcocoamenuloader_mac.mm264
-rw-r--r--src/gui/kernel/qcocoamenuloader_mac_p.h95
-rw-r--r--src/gui/kernel/qcocoapanel_mac.mm70
-rw-r--r--src/gui/kernel/qcocoapanel_mac_p.h83
-rw-r--r--src/gui/kernel/qcocoasharedwindowmethods_mac_p.h610
-rw-r--r--src/gui/kernel/qcocoaview_mac.mm1388
-rw-r--r--src/gui/kernel/qcocoaview_mac_p.h87
-rw-r--r--src/gui/kernel/qcocoawindow_mac.mm90
-rw-r--r--src/gui/kernel/qcocoawindow_mac_p.h97
-rw-r--r--src/gui/kernel/qcocoawindowcustomthemeframe_mac.mm62
-rw-r--r--src/gui/kernel/qcocoawindowcustomthemeframe_mac_p.h61
-rw-r--r--src/gui/kernel/qcocoawindowdelegate_mac.mm439
-rw-r--r--src/gui/kernel/qcocoawindowdelegate_mac_p.h110
-rw-r--r--src/gui/kernel/qdesktopwidget_mac.mm257
-rw-r--r--src/gui/kernel/qdesktopwidget_mac_p.h75
-rw-r--r--src/gui/kernel/qdesktopwidget_s60.cpp316
-rw-r--r--src/gui/kernel/qdesktopwidget_win.cpp387
-rw-r--r--src/gui/kernel/qdesktopwidget_x11.cpp406
-rw-r--r--src/gui/kernel/qguifunctions_wince.cpp408
-rw-r--r--src/gui/kernel/qguifunctions_wince.h151
-rw-r--r--src/gui/kernel/qkde.cpp176
-rw-r--r--src/gui/kernel/qkde_p.h81
-rw-r--r--src/gui/kernel/qmacdefines_mac.h180
-rw-r--r--src/gui/kernel/qmacgesturerecognizer_mac.mm272
-rw-r--r--src/gui/kernel/qmacgesturerecognizer_mac_p.h106
-rw-r--r--src/gui/kernel/qmultitouch_mac.mm218
-rw-r--r--src/gui/kernel/qmultitouch_mac_p.h102
-rw-r--r--src/gui/kernel/qnsframeview_mac_p.h154
-rw-r--r--src/gui/kernel/qnsthemeframe_mac_p.h246
-rw-r--r--src/gui/kernel/qnstitledframe_mac_p.h205
-rw-r--r--src/gui/kernel/qsoftkeymanager_s60.cpp440
-rw-r--r--src/gui/kernel/qsoftkeymanager_s60_p.h113
-rw-r--r--src/gui/kernel/qsound_mac.mm190
-rw-r--r--src/gui/kernel/qsound_s60.cpp224
-rw-r--r--src/gui/kernel/qsound_win.cpp205
-rw-r--r--src/gui/kernel/qsound_x11.cpp296
-rw-r--r--src/gui/kernel/qt_cocoa_helpers_mac.mm1824
-rw-r--r--src/gui/kernel/qt_cocoa_helpers_mac_p.h340
-rw-r--r--src/gui/kernel/qt_mac.cpp174
-rw-r--r--src/gui/kernel/qt_mac_p.h286
-rw-r--r--src/gui/kernel/qt_s60_p.h625
-rw-r--r--src/gui/kernel/qt_x11_p.h757
-rw-r--r--src/gui/kernel/qwidget_mac.mm5420
-rw-r--r--src/gui/kernel/qwidget_s60.cpp1450
-rw-r--r--src/gui/kernel/qwidget_win.cpp2139
-rw-r--r--src/gui/kernel/qwidget_wince.cpp675
-rw-r--r--src/gui/kernel/qwidget_x11.cpp3146
-rw-r--r--src/gui/kernel/qwidgetcreate_x11.cpp79
-rw-r--r--src/gui/kernel/qwinnativepangesturerecognizer_win.cpp133
-rw-r--r--src/gui/kernel/qwinnativepangesturerecognizer_win_p.h80
-rw-r--r--src/gui/kernel/qx11embed_x11.cpp1808
-rw-r--r--src/gui/kernel/qx11embed_x11.h132
-rw-r--r--src/gui/kernel/qx11info_x11.cpp543
-rw-r--r--src/gui/kernel/qx11info_x11.h123
64 files changed, 0 insertions, 45756 deletions
diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm
deleted file mode 100644
index f607a72e92..0000000000
--- a/src/gui/kernel/qapplication_mac.mm
+++ /dev/null
@@ -1,3134 +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$
-**
-****************************************************************************/
-
-/****************************************************************************
-**
-** Copyright (c) 2007-2008, Apple, Inc.
-**
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-**
-** * Redistributions of source code must retain the above copyright notice,
-** this list of conditions and the following disclaimer.
-**
-** * Redistributions in binary form must reproduce the above copyright notice,
-** this list of conditions and the following disclaimer in the documentation
-** and/or other materials provided with the distribution.
-**
-** * Neither the name of Apple, Inc. nor the names of its contributors
-** may be used to endorse or promote products derived from this software
-** without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-****************************************************************************/
-
-#include <Cocoa/Cocoa.h>
-
-#include "qapplication.h"
-#include "qbitarray.h"
-#include "qclipboard.h"
-#include "qcursor.h"
-#include "qdatastream.h"
-#include "qdatetime.h"
-#include "qdesktopwidget.h"
-#include "qdockwidget.h"
-#include "qevent.h"
-#include "qhash.h"
-#include "qlayout.h"
-#include "qmenubar.h"
-#include "qmessagebox.h"
-#include "qmime.h"
-#include "qpixmapcache.h"
-#include "qpointer.h"
-#include "qsessionmanager.h"
-#include "qsettings.h"
-#include "qsocketnotifier.h"
-#include "qstyle.h"
-#include "qstylefactory.h"
-#include "qtextcodec.h"
-#include "qtoolbar.h"
-#include "qvariant.h"
-#include "qwidget.h"
-#include "qcolormap.h"
-#include "qdir.h"
-#include "qdebug.h"
-#include "qtimer.h"
-#include "qurl.h"
-#include "private/qmacinputcontext_p.h"
-#include "private/qpaintengine_mac_p.h"
-#include "private/qcursor_p.h"
-#include "private/qapplication_p.h"
-#include "private/qcolor_p.h"
-#include "private/qwidget_p.h"
-#include "private/qkeymapper_p.h"
-#include "private/qeventdispatcher_mac_p.h"
-#include "private/qeventdispatcher_unix_p.h"
-#include <private/qcocoamenuloader_mac_p.h>
-#include <private/qcocoaapplication_mac_p.h>
-#include <private/qcocoaapplicationdelegate_mac_p.h>
-#include <private/qt_cocoa_helpers_mac_p.h>
-#include <private/qcocoawindow_mac_p.h>
-#include <private/qpixmap_mac_p.h>
-#include <private/qdesktopwidget_mac_p.h>
-#include <private/qeventdispatcher_mac_p.h>
-#include <qvarlengtharray.h>
-
-#ifndef QT_NO_ACCESSIBILITY
-# include "qaccessible.h"
-#endif
-
-#ifndef QT_NO_THREAD
-# include "qmutex.h"
-#endif
-
-#include <unistd.h>
-#include <string.h>
-#include <sys/time.h>
-#include <sys/select.h>
-
-/*****************************************************************************
- QApplication debug facilities
- *****************************************************************************/
-//#define DEBUG_EVENTS //like EventDebug but more specific to Qt
-//#define DEBUG_DROPPED_EVENTS
-//#define DEBUG_MOUSE_MAPS
-//#define DEBUG_MODAL_EVENTS
-//#define DEBUG_PLATFORM_SETTINGS
-
-#define QMAC_SPEAK_TO_ME
-#ifdef QMAC_SPEAK_TO_ME
-#include "qregexp.h"
-#endif
-
-#ifndef kThemeBrushAlternatePrimaryHighlightColor
-#define kThemeBrushAlternatePrimaryHighlightColor -5
-#endif
-
-#define kCMDeviceUnregisteredNotification CFSTR("CMDeviceUnregisteredNotification")
-#define kCMDefaultDeviceNotification CFSTR("CMDefaultDeviceNotification")
-#define kCMDeviceProfilesNotification CFSTR("CMDeviceProfilesNotification")
-#define kCMDefaultDeviceProfileNotification CFSTR("CMDefaultDeviceProfileNotification")
-
-QT_BEGIN_NAMESPACE
-
-//for qt_mac.h
-QPaintDevice *qt_mac_safe_pdev = 0;
-QList<QMacWindowChangeEvent*> *QMacWindowChangeEvent::change_events = 0;
-QPointer<QWidget> topLevelAt_cache = 0;
-
-/*****************************************************************************
- Internal variables and functions
- *****************************************************************************/
-static struct {
- bool use_qt_time_limit;
- QPointer<QWidget> last_widget;
- int last_x, last_y;
- int last_modifiers, last_button;
- EventTime last_time;
-} qt_mac_dblclick = { false, 0, -1, -1, 0, 0, -2 };
-
-static bool app_do_modal = false; // modal mode
-extern QWidgetList *qt_modal_stack; // stack of modal widgets
-extern bool qt_tab_all_widgets; // from qapplication.cpp
-bool qt_mac_app_fullscreen = false;
-bool qt_scrollbar_jump_to_pos = false;
-static bool qt_mac_collapse_on_dblclick = true;
-extern int qt_antialiasing_threshold; // from qapplication.cpp
-QWidget * qt_button_down; // widget got last button-down
-QPointer<QWidget> qt_last_mouse_receiver;
-#ifndef QT_MAC_USE_COCOA
-static bool qt_button_down_in_content; // whether the button_down was in the content area.
-static bool qt_mac_previous_press_in_popup_mode = false;
-static bool qt_mac_no_click_through_mode = false;
-static int tablet_button_state = 0;
-#endif
-#if defined(QT_DEBUG)
-static bool appNoGrab = false; // mouse/keyboard grabbing
-#endif
-#ifndef QT_MAC_USE_COCOA
-static EventHandlerRef app_proc_handler = 0;
-static EventHandlerUPP app_proc_handlerUPP = 0;
-#endif
-static AEEventHandlerUPP app_proc_ae_handlerUPP = NULL;
-static EventHandlerRef tablet_proximity_handler = 0;
-static EventHandlerUPP tablet_proximity_UPP = 0;
-bool QApplicationPrivate::native_modal_dialog_active;
-
-Q_GUI_EXPORT bool qt_applefontsmoothing_enabled;
-
-/*****************************************************************************
- External functions
- *****************************************************************************/
-extern void qt_mac_beep(); //qsound_mac.mm
-extern Qt::KeyboardModifiers qt_mac_get_modifiers(int keys); //qkeymapper_mac.cpp
-extern bool qt_mac_can_clickThrough(const QWidget *); //qwidget_mac.cpp
-extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp
-extern OSWindowRef qt_mac_window_for(const QWidget*); //qwidget_mac.cpp
-extern QWidget *qt_mac_find_window(OSWindowRef); //qwidget_mac.cpp
-extern void qt_mac_set_cursor(const QCursor *); //qcursor_mac.cpp
-extern bool qt_mac_is_macsheet(const QWidget *); //qwidget_mac.cpp
-extern QString qt_mac_from_pascal_string(const Str255); //qglobal.cpp
-extern void qt_mac_command_set_enabled(MenuRef, UInt32, bool); //qmenu_mac.cpp
-extern bool qt_sendSpontaneousEvent(QObject *obj, QEvent *event); // qapplication.cpp
-extern void qt_mac_update_cursor(); // qcursor_mac.mm
-
-// Forward Decls
-void onApplicationWindowChangedActivation( QWidget*widget, bool activated );
-void onApplicationChangedActivation( bool activated );
-
-static void qt_mac_read_fontsmoothing_settings()
-{
- qt_applefontsmoothing_enabled = true;
- int w = 10, h = 10;
- QImage image(w, h, QImage::Format_RGB32);
- image.fill(0xffffffff);
- QPainter p(&image);
- p.drawText(0, h, "X\\");
- p.end();
-
- const int *bits = (const int *) ((const QImage &) image).bits();
- int bpl = image.bytesPerLine() / 4;
- for (int y=0; y<w; ++y) {
- for (int x=0; x<h; ++x) {
- int r = qRed(bits[x]);
- int g = qGreen(bits[x]);
- int b = qBlue(bits[x]);
- if (r != g || r != b) {
- qt_applefontsmoothing_enabled = true;
- return;
- }
- }
- bits += bpl;
- }
- qt_applefontsmoothing_enabled = false;
-}
-
-Q_GUI_EXPORT bool qt_mac_execute_apple_script(const char *script, long script_len, AEDesc *ret) {
- OSStatus err;
- AEDesc scriptTextDesc;
- ComponentInstance theComponent = 0;
- OSAID scriptID = kOSANullScript, resultID = kOSANullScript;
-
- // set up locals to a known state
- AECreateDesc(typeNull, 0, 0, &scriptTextDesc);
- scriptID = kOSANullScript;
- resultID = kOSANullScript;
-
- // open the scripting component
- theComponent = OpenDefaultComponent(kOSAComponentType, typeAppleScript);
- if (!theComponent) {
- err = paramErr;
- goto bail;
- }
-
- // put the script text into an aedesc
- err = AECreateDesc(typeUTF8Text, script, script_len, &scriptTextDesc);
- if (err != noErr)
- goto bail;
-
- // compile the script
- err = OSACompile(theComponent, &scriptTextDesc, kOSAModeNull, &scriptID);
- if (err != noErr)
- goto bail;
-
- // run the script
- err = OSAExecute(theComponent, scriptID, kOSANullScript, kOSAModeNull, &resultID);
-
- // collect the results - if any
- if (ret) {
- AECreateDesc(typeNull, 0, 0, ret);
- if (err == errOSAScriptError)
- OSAScriptError(theComponent, kOSAErrorMessage, typeChar, ret);
- else if (err == noErr && resultID != kOSANullScript)
- OSADisplay(theComponent, resultID, typeChar, kOSAModeNull, ret);
- }
-bail:
- AEDisposeDesc(&scriptTextDesc);
- if (scriptID != kOSANullScript)
- OSADispose(theComponent, scriptID);
- if (resultID != kOSANullScript)
- OSADispose(theComponent, resultID);
- if (theComponent)
- CloseComponent(theComponent);
- return err == noErr;
-}
-
-Q_GUI_EXPORT bool qt_mac_execute_apple_script(const char *script, AEDesc *ret)
-{
- return qt_mac_execute_apple_script(script, qstrlen(script), ret);
-}
-
-Q_GUI_EXPORT bool qt_mac_execute_apple_script(const QString &script, AEDesc *ret)
-{
- const QByteArray l = script.toUtf8(); return qt_mac_execute_apple_script(l.constData(), l.size(), ret);
-}
-
-/* Resolution change magic */
-void qt_mac_display_change_callbk(CGDirectDisplayID, CGDisplayChangeSummaryFlags flags, void *)
-{
-#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
- const bool resized = flags & kCGDisplayDesktopShapeChangedFlag;
-#else
- Q_UNUSED(flags);
- const bool resized = true;
-#endif
- if (resized && qApp) {
- if (QDesktopWidget *dw = qApp->desktop()) {
- QResizeEvent *re = new QResizeEvent(dw->size(), dw->size());
- QApplication::postEvent(dw, re);
- QCoreGraphicsPaintEngine::cleanUpMacColorSpaces();
- }
- }
-}
-
-#ifdef DEBUG_PLATFORM_SETTINGS
-static void qt_mac_debug_palette(const QPalette &pal, const QPalette &pal2, const QString &where)
-{
- const char *const groups[] = {"Active", "Disabled", "Inactive" };
- const char *const roles[] = { "WindowText", "Button", "Light", "Midlight", "Dark", "Mid",
- "Text", "BrightText", "ButtonText", "Base", "Window", "Shadow",
- "Highlight", "HighlightedText", "Link", "LinkVisited" };
- if (!where.isNull())
- qDebug("qt-internal: %s", where.toLatin1().constData());
- for(int grp = 0; grp < QPalette::NColorGroups; grp++) {
- for(int role = 0; role < QPalette::NColorRoles; role++) {
- QBrush b = pal.brush((QPalette::ColorGroup)grp, (QPalette::ColorRole)role);
- QPixmap pm = b.texture();
- qDebug(" %s::%s %d::%d::%d [%p]%s", groups[grp], roles[role], b.color().red(),
- b.color().green(), b.color().blue(), pm.isNull() ? 0 : &pm,
- pal2.brush((QPalette::ColorGroup)grp, (QPalette::ColorRole)role) != b ? " (*)" : "");
- }
- }
-
-}
-#else
-#define qt_mac_debug_palette(x, y, z)
-#endif
-
-//raise a notification
-#ifndef QT_MAC_USE_COCOA
-static NMRec qt_mac_notification = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-#endif
-void qt_mac_send_notification()
-{
-#ifndef QT_MAC_USE_COCOA
- //send it
- qt_mac_notification.nmMark = 1; //non-zero magic number
- qt_mac_notification.qType = nmType;
- NMInstall(&qt_mac_notification);
-#else
- QMacCocoaAutoReleasePool pool;
- [[NSApplication sharedApplication] requestUserAttention:NSInformationalRequest];
-#endif
-}
-
-void qt_mac_cancel_notification()
-{
-#ifndef QT_MAC_USE_COCOA
- NMRemove(&qt_mac_notification);
-#else
- QMacCocoaAutoReleasePool pool;
- [[NSApplication sharedApplication] cancelUserAttentionRequest:NSInformationalRequest];
-#endif
-}
-
-#ifndef QT_MAC_USE_COCOA
-//find widget (and part) at a given point
-static short qt_mac_window_at(int x, int y, QWidget **w=0)
-{
- Point p;
- p.h = x;
- p.v = y;
- OSWindowRef wp;
- WindowPartCode wpc;
- OSStatus err = FindWindowOfClass(&p, kAllWindowClasses, &wp, &wpc);
- if(err != noErr) {
- if(w)
- (*w) = 0;
- return wpc;
- }
- if(w) {
- if(wp) {
- *w = qt_mac_find_window(wp);
-#if 0
- if(!*w)
- qWarning("QApplication: qt_mac_window_at: Couldn't find %d",(int)wp);
-#endif
- } else {
- *w = 0;
- }
- }
- return wpc;
-}
-
-#endif
-
-void qt_mac_set_app_icon(const QPixmap &pixmap)
-{
-#ifndef QT_MAC_USE_COCOA
- if(pixmap.isNull()) {
- RestoreApplicationDockTileImage();
- } else {
- CGImageRef img = (CGImageRef)pixmap.macCGHandle();
- SetApplicationDockTileImage(img);
- CGImageRelease(img);
- }
-#else
- QMacCocoaAutoReleasePool pool;
- NSImage *image = NULL;
- if (pixmap.isNull()) {
- // Get Application icon from bundle
- image = [[NSImage imageNamed:@"NSApplicationIcon"] retain]; // released below
- } else {
- image = static_cast<NSImage *>(qt_mac_create_nsimage(pixmap));
- }
-
- [NSApp setApplicationIconImage:image];
- [image release];
-#endif
-}
-
-Q_GUI_EXPORT void qt_mac_set_press_and_hold_context(bool b)
-{
- Q_UNUSED(b);
- qWarning("qt_mac_set_press_and_hold_context: This functionality is no longer available");
-}
-
-bool qt_nograb() // application no-grab option
-{
-#if defined(QT_DEBUG)
- return appNoGrab;
-#else
- return false;
-#endif
-}
-
-void qt_mac_update_os_settings()
-{
- if (!qApp)
- return;
- if (!QApplication::startingUp()) {
- static bool needToPolish = true;
- if (needToPolish) {
- QApplication::style()->polish(qApp);
- needToPolish = false;
- }
- }
- //focus mode
- /* First worked as of 10.2.3 */
- QSettings appleSettings(QLatin1String("apple.com"));
- QVariant appleValue = appleSettings.value(QLatin1String("AppleKeyboardUIMode"), 0);
- qt_tab_all_widgets = (appleValue.toInt() & 0x2);
- //paging mode
- /* First worked as of 10.2.3 */
- appleValue = appleSettings.value(QLatin1String("AppleScrollerPagingBehavior"), false);
- qt_scrollbar_jump_to_pos = appleValue.toBool();
- //collapse
- /* First worked as of 10.3.3 */
- appleValue = appleSettings.value(QLatin1String("AppleMiniaturizeOnDoubleClick"), true);
- qt_mac_collapse_on_dblclick = appleValue.toBool();
-
- // Anti-aliasing threshold
- appleValue = appleSettings.value(QLatin1String("AppleAntiAliasingThreshold"));
- if (appleValue.isValid())
- qt_antialiasing_threshold = appleValue.toInt();
-
-#ifdef DEBUG_PLATFORM_SETTINGS
- qDebug("qt_mac_update_os_settings *********************************************************************");
-#endif
- { // setup the global palette
- QColor qc;
- (void) QApplication::style(); // trigger creation of application style and system palettes
- QPalette pal = *QApplicationPrivate::sys_pal;
-
- pal.setBrush( QPalette::Active, QPalette::Highlight, qcolorForTheme(kThemeBrushPrimaryHighlightColor) );
- pal.setBrush( QPalette::Inactive, QPalette::Highlight, qcolorForTheme(kThemeBrushSecondaryHighlightColor) );
-
- pal.setBrush( QPalette::Disabled, QPalette::Highlight, qcolorForTheme(kThemeBrushSecondaryHighlightColor) );
- pal.setBrush( QPalette::Active, QPalette::Shadow, qcolorForTheme(kThemeBrushButtonActiveDarkShadow) );
-
- pal.setBrush( QPalette::Inactive, QPalette::Shadow, qcolorForTheme(kThemeBrushButtonInactiveDarkShadow) );
- pal.setBrush( QPalette::Disabled, QPalette::Shadow, qcolorForTheme(kThemeBrushButtonInactiveDarkShadow) );
-
- qc = qcolorForThemeTextColor(kThemeTextColorDialogActive);
- pal.setColor(QPalette::Active, QPalette::Text, qc);
- pal.setColor(QPalette::Active, QPalette::WindowText, qc);
- pal.setColor(QPalette::Active, QPalette::HighlightedText, qc);
-
- qc = qcolorForThemeTextColor(kThemeTextColorDialogInactive);
- pal.setColor(QPalette::Inactive, QPalette::Text, qc);
- pal.setColor(QPalette::Inactive, QPalette::WindowText, qc);
- pal.setColor(QPalette::Inactive, QPalette::HighlightedText, qc);
- pal.setColor(QPalette::Disabled, QPalette::Text, qc);
- pal.setColor(QPalette::Disabled, QPalette::WindowText, qc);
- pal.setColor(QPalette::Disabled, QPalette::HighlightedText, qc);
- pal.setBrush(QPalette::ToolTipBase, QColor(255, 255, 199));
-
- if (!QApplicationPrivate::sys_pal || *QApplicationPrivate::sys_pal != pal) {
- QApplicationPrivate::setSystemPalette(pal);
- QApplication::setPalette(pal);
- }
-#ifdef DEBUG_PLATFORM_SETTINGS
- qt_mac_debug_palette(pal, QApplication::palette(), "Global Palette");
-#endif
- }
-
- QFont fnt = qfontForThemeFont(kThemeApplicationFont);
-#ifdef DEBUG_PLATFORM_SETTINGS
- qDebug("qt-internal: Font for Application [%s::%d::%d::%d]",
- fnt.family().toLatin1().constData(), fnt.pointSize(), fnt.bold(), fnt.italic());
-#endif
- if (!QApplicationPrivate::sys_font || *QApplicationPrivate::sys_font != fnt)
- QApplicationPrivate::setSystemFont(fnt);
-
- { //setup the fonts
- struct FontMap {
- FontMap(const char *qc, short fk) : qt_class(qc), font_key(fk) { }
- const char *const qt_class;
- short font_key;
- } mac_widget_fonts[] = {
- FontMap("QPushButton", kThemePushButtonFont),
- FontMap("QListView", kThemeViewsFont),
- FontMap("QListBox", kThemeViewsFont),
- FontMap("QTitleBar", kThemeWindowTitleFont),
- FontMap("QMenuBar", kThemeMenuTitleFont),
- FontMap("QMenu", kThemeMenuItemFont),
- FontMap("QComboMenuItem", kThemeSystemFont),
- FontMap("QHeaderView", kThemeSmallSystemFont),
- FontMap("Q3Header", kThemeSmallSystemFont),
- FontMap("QTipLabel", kThemeSmallSystemFont),
- FontMap("QLabel", kThemeSystemFont),
- FontMap("QToolButton", kThemeSmallSystemFont),
- FontMap("QMenuItem", kThemeMenuItemFont), // It doesn't exist, but its unique.
- FontMap("QComboLineEdit", kThemeViewsFont), // It doesn't exist, but its unique.
- FontMap("QSmallFont", kThemeSmallSystemFont), // It doesn't exist, but its unique.
- FontMap("QMiniFont", kThemeMiniSystemFont), // It doesn't exist, but its unique.
- FontMap(0, 0) };
- for(int i = 0; mac_widget_fonts[i].qt_class; i++) {
- QFont fnt = qfontForThemeFont(mac_widget_fonts[i].font_key);
- bool set_font = true;
- FontHash *hash = qt_app_fonts_hash();
- if (!hash->isEmpty()) {
- FontHash::const_iterator it
- = hash->constFind(mac_widget_fonts[i].qt_class);
- if (it != hash->constEnd())
- set_font = (fnt != *it);
- }
- if (set_font) {
- QApplication::setFont(fnt, mac_widget_fonts[i].qt_class);
-#ifdef DEBUG_PLATFORM_SETTINGS
- qDebug("qt-internal: Font for %s [%s::%d::%d::%d]", mac_widget_fonts[i].qt_class,
- fnt.family().toLatin1().constData(), fnt.pointSize(), fnt.bold(), fnt.italic());
-#endif
- }
- }
- }
- QApplicationPrivate::initializeWidgetPaletteHash();
-#ifdef DEBUG_PLATFORM_SETTINGS
- qDebug("qt_mac_update_os_settings END !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-#endif
-}
-
-void QApplicationPrivate::initializeWidgetPaletteHash()
-{
- { //setup the palette
- struct PaletteMap {
- inline PaletteMap(const char *qc, ThemeBrush a, ThemeBrush i) :
- qt_class(qc), active(a), inactive(i) { }
- const char *const qt_class;
- ThemeBrush active, inactive;
- } mac_widget_colors[] = {
- PaletteMap("QToolButton", kThemeTextColorBevelButtonActive, kThemeTextColorBevelButtonInactive),
- PaletteMap("QAbstractButton", kThemeTextColorPushButtonActive, kThemeTextColorPushButtonInactive),
- PaletteMap("QHeaderView", kThemeTextColorPushButtonActive, kThemeTextColorPushButtonInactive),
- PaletteMap("Q3Header", kThemeTextColorPushButtonActive, kThemeTextColorPushButtonInactive),
- PaletteMap("QComboBox", kThemeTextColorPopupButtonActive, kThemeTextColorPopupButtonInactive),
- PaletteMap("QAbstractItemView", kThemeTextColorListView, kThemeTextColorDialogInactive),
- PaletteMap("QMessageBoxLabel", kThemeTextColorAlertActive, kThemeTextColorAlertInactive),
- PaletteMap("QTabBar", kThemeTextColorTabFrontActive, kThemeTextColorTabFrontInactive),
- PaletteMap("QLabel", kThemeTextColorPlacardActive, kThemeTextColorPlacardInactive),
- PaletteMap("QGroupBox", kThemeTextColorPlacardActive, kThemeTextColorPlacardInactive),
- PaletteMap("QMenu", kThemeTextColorPopupLabelActive, kThemeTextColorPopupLabelInactive),
- PaletteMap("QTextEdit", 0, 0),
- PaletteMap("QTextControl", 0, 0),
- PaletteMap("QLineEdit", 0, 0),
- PaletteMap(0, 0, 0) };
- QColor qc;
- for(int i = 0; mac_widget_colors[i].qt_class; i++) {
- QPalette pal;
- if (mac_widget_colors[i].active != 0) {
- qc = qcolorForThemeTextColor(mac_widget_colors[i].active);
- pal.setColor(QPalette::Active, QPalette::Text, qc);
- pal.setColor(QPalette::Active, QPalette::WindowText, qc);
- pal.setColor(QPalette::Active, QPalette::HighlightedText, qc);
- qc = qcolorForThemeTextColor(mac_widget_colors[i].inactive);
- pal.setColor(QPalette::Inactive, QPalette::Text, qc);
- pal.setColor(QPalette::Disabled, QPalette::Text, qc);
- pal.setColor(QPalette::Inactive, QPalette::WindowText, qc);
- pal.setColor(QPalette::Disabled, QPalette::WindowText, qc);
- pal.setColor(QPalette::Inactive, QPalette::HighlightedText, qc);
- pal.setColor(QPalette::Disabled, QPalette::HighlightedText, qc);
- }
- if (!strcmp(mac_widget_colors[i].qt_class, "QMenu")) {
- qc = qcolorForThemeTextColor(kThemeTextColorMenuItemActive);
- pal.setBrush(QPalette::ButtonText, qc);
- qc = qcolorForThemeTextColor(kThemeTextColorMenuItemSelected);
- pal.setBrush(QPalette::HighlightedText, qc);
- qc = qcolorForThemeTextColor(kThemeTextColorMenuItemDisabled);
- pal.setBrush(QPalette::Disabled, QPalette::Text, qc);
- } else if (!strcmp(mac_widget_colors[i].qt_class, "QAbstractButton")
- || !strcmp(mac_widget_colors[i].qt_class, "QHeaderView")
- || !strcmp(mac_widget_colors[i].qt_class, "Q3Header")) { //special
- pal.setColor(QPalette::Disabled, QPalette::ButtonText,
- pal.color(QPalette::Disabled, QPalette::Text));
- pal.setColor(QPalette::Inactive, QPalette::ButtonText,
- pal.color(QPalette::Inactive, QPalette::Text));
- pal.setColor(QPalette::Active, QPalette::ButtonText,
- pal.color(QPalette::Active, QPalette::Text));
- } else if (!strcmp(mac_widget_colors[i].qt_class, "QAbstractItemView")) {
- pal.setBrush(QPalette::Active, QPalette::Highlight,
- qcolorForTheme(kThemeBrushAlternatePrimaryHighlightColor));
- qc = qcolorForThemeTextColor(kThemeTextColorMenuItemSelected);
- pal.setBrush(QPalette::Active, QPalette::HighlightedText, qc);
-#if 1
- pal.setBrush(QPalette::Inactive, QPalette::Text,
- pal.brush(QPalette::Active, QPalette::Text));
- pal.setBrush(QPalette::Inactive, QPalette::HighlightedText,
- pal.brush(QPalette::Active, QPalette::Text));
-#endif
- } else if (!strcmp(mac_widget_colors[i].qt_class, "QTextEdit")
- || !strcmp(mac_widget_colors[i].qt_class, "QTextControl")) {
- pal.setBrush(QPalette::Inactive, QPalette::Text,
- pal.brush(QPalette::Active, QPalette::Text));
- pal.setBrush(QPalette::Inactive, QPalette::HighlightedText,
- pal.brush(QPalette::Active, QPalette::Text));
- } else if (!strcmp(mac_widget_colors[i].qt_class, "QLineEdit")) {
- pal.setBrush(QPalette::Disabled, QPalette::Base,
- pal.brush(QPalette::Active, QPalette::Base));
- }
-
- bool set_palette = true;
- PaletteHash *phash = qt_app_palettes_hash();
- if (!phash->isEmpty()) {
- PaletteHash::const_iterator it
- = phash->constFind(mac_widget_colors[i].qt_class);
- if (it != phash->constEnd())
- set_palette = (pal != *it);
- }
- if (set_palette) {
- QApplication::setPalette(pal, mac_widget_colors[i].qt_class);
-#ifdef DEBUG_PLATFORM_SETTINGS
- qt_mac_debug_palette(pal, QApplication::palette(), QLatin1String("Palette for ") + QString::fromLatin1(mac_widget_colors[i].qt_class));
-#endif
- }
- }
- }
-}
-
-static void qt_mac_event_release(EventRef &event)
-{
- ReleaseEvent(event);
- event = 0;
-}
-#ifndef QT_MAC_USE_COCOA
-static void qt_mac_event_release(QWidget *w, EventRef &event)
-{
- if (event) {
- QWidget *widget = 0;
- if (GetEventParameter(event, kEventParamQWidget, typeQWidget, 0, sizeof(widget), 0, &widget) == noErr
- && w == widget) {
- if (IsEventInQueue(GetMainEventQueue(), event))
- RemoveEventFromQueue(GetMainEventQueue(), event);
- qt_mac_event_release(event);
- }
- }
-}
-
-static bool qt_mac_event_remove(EventRef &event)
-{
- if (event) {
- if (IsEventInQueue(GetMainEventQueue(), event))
- RemoveEventFromQueue(GetMainEventQueue(), event);
- qt_mac_event_release(event);
- return true;
- }
- return false;
-}
-#endif
-
-/* sheets */
-#ifndef QT_MAC_USE_COCOA
-static EventRef request_showsheet_pending = 0;
-#endif
-void qt_event_request_showsheet(QWidget *w)
-{
- Q_ASSERT(qt_mac_is_macsheet(w));
-#ifdef QT_MAC_USE_COCOA
- [NSApp beginSheet:qt_mac_window_for(w) modalForWindow:qt_mac_window_for(w->parentWidget())
- modalDelegate:nil didEndSelector:nil contextInfo:0];
-#else
- qt_mac_event_remove(request_showsheet_pending);
- CreateEvent(0, kEventClassQt, kEventQtRequestShowSheet, GetCurrentEventTime(),
- kEventAttributeUserEvent, &request_showsheet_pending);
- SetEventParameter(request_showsheet_pending, kEventParamQWidget, typeQWidget, sizeof(w), &w);
- PostEventToQueue(GetMainEventQueue(), request_showsheet_pending, kEventPriorityStandard);
-#endif
-}
-
-static void qt_post_window_change_event(QWidget *widget)
-{
- qt_widget_private(widget)->needWindowChange = true;
- QEvent *glWindowChangeEvent = new QEvent(QEvent::MacGLWindowChange);
- QApplication::postEvent(widget, glWindowChangeEvent);
-}
-
-/*
- Posts updates to all child and grandchild OpenGL widgets for the given widget.
-*/
-static void qt_mac_update_child_gl_widgets(QWidget *widget)
-{
- // Update all OpenGL child widgets for the given widget.
- QList<QWidgetPrivate::GlWidgetInfo> &glWidgets = qt_widget_private(widget)->glWidgets;
- QList<QWidgetPrivate::GlWidgetInfo>::iterator end = glWidgets.end();
- QList<QWidgetPrivate::GlWidgetInfo>::iterator it = glWidgets.begin();
-
- for (;it != end; ++it) {
- qt_post_window_change_event(it->widget);
- }
-}
-
-/*
- Sends updates to all child and grandchild gl widgets that have updates pending.
-*/
-void qt_mac_send_posted_gl_updates(QWidget *widget)
-{
- QList<QWidgetPrivate::GlWidgetInfo> &glWidgets = qt_widget_private(widget)->glWidgets;
- QList<QWidgetPrivate::GlWidgetInfo>::iterator end = glWidgets.end();
- QList<QWidgetPrivate::GlWidgetInfo>::iterator it = glWidgets.begin();
-
- for (;it != end; ++it) {
- QWidget *glWidget = it->widget;
- if (qt_widget_private(glWidget)->needWindowChange) {
- QEvent glChangeEvent(QEvent::MacGLWindowChange);
- QApplication::sendEvent(glWidget, &glChangeEvent);
- }
- }
-}
-
-/*
- Posts updates to all OpenGL widgets within the window that the given widget intersects.
-*/
-static void qt_mac_update_intersected_gl_widgets(QWidget *widget)
-{
-#ifndef QT_MAC_USE_COCOA
- QList<QWidgetPrivate::GlWidgetInfo> &glWidgets = qt_widget_private(widget->window())->glWidgets;
- if (glWidgets.isEmpty())
- return;
-
- // Exit if the window has not been created yet (mapToGlobal/size will force create it)
- if (widget->testAttribute(Qt::WA_WState_Created) == false || HIViewGetWindow(qt_mac_nativeview_for(widget)) == 0)
- return;
-
- const QRect globalWidgetRect = QRect(widget->mapToGlobal(QPoint(0, 0)), widget->size());
-
- QList<QWidgetPrivate::GlWidgetInfo>::iterator end = glWidgets.end();
- QList<QWidgetPrivate::GlWidgetInfo>::iterator it = glWidgets.begin();
-
- for (;it != end; ++it){
- QWidget *glWidget = it->widget;
- const QRect globalGlWidgetRect = QRect(glWidget->mapToGlobal(QPoint(0, 0)), glWidget->size());
- if (globalWidgetRect.intersects(globalGlWidgetRect)) {
- qt_post_window_change_event(glWidget);
- it->lastUpdateWidget = widget;
- } else if (it->lastUpdateWidget == widget) {
- // Update the gl wigets that the widget intersected the last time around,
- // and that we are not intersecting now. This prevents paint errors when the
- // intersecting widget leaves a gl widget.
- qt_post_window_change_event(glWidget);
- it->lastUpdateWidget = 0;
- }
- }
-#else
- Q_UNUSED(widget);
-#endif
-}
-
-/*
- Posts a kEventQtRequestWindowChange event to the main Carbon event queue.
-*/
-static EventRef request_window_change_pending = 0;
-Q_GUI_EXPORT void qt_event_request_window_change()
-{
- if(request_window_change_pending)
- return;
-
- CreateEvent(0, kEventClassQt, kEventQtRequestWindowChange, GetCurrentEventTime(),
- kEventAttributeUserEvent, &request_window_change_pending);
- PostEventToQueue(GetMainEventQueue(), request_window_change_pending, kEventPriorityHigh);
-}
-
-/* window changing. This is a hack around Apple's missing functionality, pending the toolbox
- team fix. --Sam */
-Q_GUI_EXPORT void qt_event_request_window_change(QWidget *widget)
-{
- if (!widget)
- return;
-
- // Post a kEventQtRequestWindowChange event. This event is semi-public,
- // don't remove this line!
- qt_event_request_window_change();
-
- // Post update request on gl widgets unconditionally.
- if (qt_widget_private(widget)->isGLWidget == true) {
- qt_post_window_change_event(widget);
- return;
- }
-
- qt_mac_update_child_gl_widgets(widget);
- qt_mac_update_intersected_gl_widgets(widget);
-}
-
-/* activation */
-static struct {
- QPointer<QWidget> widget;
- EventRef event;
- EventLoopTimerRef timer;
- EventLoopTimerUPP timerUPP;
-} request_activate_pending = { 0, 0, 0, 0 };
-bool qt_event_remove_activate()
-{
- if (request_activate_pending.timer) {
- RemoveEventLoopTimer(request_activate_pending.timer);
- request_activate_pending.timer = 0;
- }
- if (request_activate_pending.event)
- qt_mac_event_release(request_activate_pending.event);
- return true;
-}
-
-void qt_event_activate_timer_callbk(EventLoopTimerRef r, void *)
-{
- EventLoopTimerRef otc = request_activate_pending.timer;
- qt_event_remove_activate();
- if (r == otc && !request_activate_pending.widget.isNull()) {
- const QWidget *tlw = request_activate_pending.widget->window();
- Qt::WindowType wt = tlw->windowType();
- if (tlw->isVisible()
- && ((wt != Qt::Desktop && wt != Qt::Popup && wt != Qt::Tool) || tlw->isModal())) {
- CreateEvent(0, kEventClassQt, kEventQtRequestActivate, GetCurrentEventTime(),
- kEventAttributeUserEvent, &request_activate_pending.event);
- PostEventToQueue(GetMainEventQueue(), request_activate_pending.event, kEventPriorityHigh);
- }
- }
-}
-
-void qt_event_request_activate(QWidget *w)
-{
- if (w == request_activate_pending.widget)
- return;
-
- /* We put these into a timer because due to order of events being sent we need to be sure this
- comes from inside of the event loop */
- qt_event_remove_activate();
- if (!request_activate_pending.timerUPP)
- request_activate_pending.timerUPP = NewEventLoopTimerUPP(qt_event_activate_timer_callbk);
- request_activate_pending.widget = w;
- InstallEventLoopTimer(GetMainEventLoop(), 0, 0, request_activate_pending.timerUPP, 0, &request_activate_pending.timer);
-}
-
-
-/* menubars */
-#ifndef QT_MAC_USE_COCOA
-static EventRef request_menubarupdate_pending = 0;
-#endif
-void qt_event_request_menubarupdate()
-{
-#ifndef QT_MAC_USE_COCOA
- if (request_menubarupdate_pending) {
- if (IsEventInQueue(GetMainEventQueue(), request_menubarupdate_pending))
- return;
-#ifdef DEBUG_DROPPED_EVENTS
- qDebug("%s:%d Whoa, we dropped an event on the floor!", __FILE__, __LINE__);
-#endif
- }
-
- CreateEvent(0, kEventClassQt, kEventQtRequestMenubarUpdate, GetCurrentEventTime(),
- kEventAttributeUserEvent, &request_menubarupdate_pending);
- PostEventToQueue(GetMainEventQueue(), request_menubarupdate_pending, kEventPriorityHigh);
-#else
- // Just call this. The request has the benefit that we don't call this multiple times, but
- // we can optimize this.
- QMenuBar::macUpdateMenuBar();
-#endif
-}
-
-#ifndef QT_MAC_USE_COCOA
-//context menu
-static EventRef request_context_pending = 0;
-static void qt_event_request_context(QWidget *w=0, EventRef *where=0)
-{
- if (!where)
- where = &request_context_pending;
- if (*where)
- return;
- CreateEvent(0, kEventClassQt, kEventQtRequestContext, GetCurrentEventTime(),
- kEventAttributeUserEvent, where);
- if (w)
- SetEventParameter(*where, kEventParamQWidget, typeQWidget, sizeof(w), &w);
- PostEventToQueue(GetMainEventQueue(), *where, kEventPriorityStandard);
-}
-#endif
-
-void QApplicationPrivate::createEventDispatcher()
-{
- Q_Q(QApplication);
- if (q->type() != QApplication::Tty)
- eventDispatcher = new QEventDispatcherMac(q);
- else
- eventDispatcher = new QEventDispatcherUNIX(q);
-}
-
-/* clipboard */
-void qt_event_send_clipboard_changed()
-{
-#ifndef QT_MAC_USE_COCOA
- AppleEvent ae;
- if (AECreateAppleEvent(kEventClassQt, typeAEClipboardChanged, 0, kAutoGenerateReturnID, kAnyTransactionID, &ae) != noErr)
- qDebug("Can't happen!!");
- AppleEvent reply;
- AESend(&ae, &reply, kAENoReply, kAENormalPriority, kAEDefaultTimeout, 0, 0);
-#endif
-}
-
-/* app menu */
-static QMenu *qt_mac_dock_menu = 0;
-Q_GUI_EXPORT void qt_mac_set_dock_menu(QMenu *menu)
-{
- qt_mac_dock_menu = menu;
-#ifdef QT_MAC_USE_COCOA
- [NSApp setDockMenu:menu->macMenu()];
-#else
- SetApplicationDockTileMenu(menu->macMenu());
-#endif
-}
-
-/* events that hold pointers to widgets, must be cleaned up like this */
-void qt_mac_event_release(QWidget *w)
-{
- if (w) {
-#ifndef QT_MAC_USE_COCOA
- qt_mac_event_release(w, request_showsheet_pending);
- qt_mac_event_release(w, request_context_pending);
-#endif
- if (w == qt_mac_dock_menu) {
- qt_mac_dock_menu = 0;
-#ifndef QT_MAC_USE_COCOA
- SetApplicationDockTileMenu(0);
-#else
- [NSApp setDockMenu:0];
-#endif
- }
- }
-}
-
-struct QMacAppleEventTypeSpec {
- AEEventClass mac_class;
- AEEventID mac_id;
-} app_apple_events[] = {
- { kCoreEventClass, kAEQuitApplication },
- { kCoreEventClass, kAEOpenDocuments },
- { kInternetEventClass, kAEGetURL },
-};
-
-#ifndef QT_MAC_USE_COCOA
-
-#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5)
-enum
-{
- kEventMouseScroll = 11,
- kEventParamMouseWheelSmoothVerticalDelta = 'saxy',
- kEventParamMouseWheelSmoothHorizontalDelta = 'saxx',
-};
-#endif
-
-/* watched events */
-static EventTypeSpec app_events[] = {
- { kEventClassQt, kEventQtRequestWindowChange },
- { kEventClassQt, kEventQtRequestShowSheet },
- { kEventClassQt, kEventQtRequestContext },
- { kEventClassQt, kEventQtRequestActivate },
- { kEventClassQt, kEventQtRequestMenubarUpdate },
-
- { kEventClassWindow, kEventWindowActivated },
- { kEventClassWindow, kEventWindowDeactivated },
-
- { kEventClassMouse, kEventMouseScroll },
- { kEventClassMouse, kEventMouseWheelMoved },
- { kEventClassMouse, kEventMouseDown },
- { kEventClassMouse, kEventMouseUp },
- { kEventClassMouse, kEventMouseDragged },
- { kEventClassMouse, kEventMouseMoved },
-
- { kEventClassTablet, kEventTabletProximity },
-
- { kEventClassApplication, kEventAppActivated },
- { kEventClassApplication, kEventAppDeactivated },
- { kEventClassApplication, kEventAppAvailableWindowBoundsChanged },
-
- // { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent },
- { kEventClassKeyboard, kEventRawKeyModifiersChanged },
- { kEventClassKeyboard, kEventRawKeyRepeat },
- { kEventClassKeyboard, kEventRawKeyUp },
- { kEventClassKeyboard, kEventRawKeyDown },
-
- { kEventClassCommand, kEventCommandProcess },
-
- { kEventClassAppleEvent, kEventAppleEvent },
-
- { kAppearanceEventClass, kAEAppearanceChanged }
-};
-
-void qt_init_app_proc_handler()
-{
- InstallEventHandler(GetApplicationEventTarget(), app_proc_handlerUPP,
- GetEventTypeCount(app_events), app_events, (void *)qApp,
- &app_proc_handler);
-}
-#endif // QT_MAC_USE_COCOA
-
-static void qt_init_tablet_proximity_handler()
-{
- EventTypeSpec tabletProximityEvent = { kEventClassTablet, kEventTabletProximity };
- InstallEventHandler(GetEventMonitorTarget(), tablet_proximity_UPP,
- 1, &tabletProximityEvent, qApp, &tablet_proximity_handler);
-}
-
-static void qt_release_tablet_proximity_handler()
-{
- RemoveEventHandler(tablet_proximity_handler);
-}
-
-QString QApplicationPrivate::appName() const
-{
- static QString applName;
- if (applName.isEmpty()) {
- applName = QCoreApplicationPrivate::macMenuBarName();
- ProcessSerialNumber psn;
- if (applName.isEmpty() && qt_is_gui_used && GetCurrentProcess(&psn) == noErr) {
- QCFString cfstr;
- CopyProcessName(&psn, &cfstr);
- applName = cfstr;
- }
- }
- return applName;
-}
-
-void qt_release_app_proc_handler()
-{
-#ifndef QT_MAC_USE_COCOA
- if (app_proc_handler) {
- RemoveEventHandler(app_proc_handler);
- app_proc_handler = 0;
- }
-#endif
-}
-
-void qt_color_profile_changed(CFNotificationCenterRef, void *, CFStringRef, const void *,
- CFDictionaryRef)
-{
- QCoreGraphicsPaintEngine::cleanUpMacColorSpaces();
-}
-/* platform specific implementations */
-void qt_init(QApplicationPrivate *priv, int)
-{
- if (qt_is_gui_used) {
- CGDisplayRegisterReconfigurationCallback(qt_mac_display_change_callbk, 0);
- CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
- CFNotificationCenterAddObserver(center, qApp, qt_color_profile_changed,
- kCMDeviceUnregisteredNotification, 0,
- CFNotificationSuspensionBehaviorDeliverImmediately);
- CFNotificationCenterAddObserver(center, qApp, qt_color_profile_changed,
- kCMDefaultDeviceNotification, 0,
- CFNotificationSuspensionBehaviorDeliverImmediately);
- CFNotificationCenterAddObserver(center, qApp, qt_color_profile_changed,
- kCMDeviceProfilesNotification, 0,
- CFNotificationSuspensionBehaviorDeliverImmediately);
- CFNotificationCenterAddObserver(center, qApp, qt_color_profile_changed,
- kCMDefaultDeviceProfileNotification, 0,
- CFNotificationSuspensionBehaviorDeliverImmediately);
- ProcessSerialNumber psn;
- if (GetCurrentProcess(&psn) == noErr) {
- // Jambi needs to transform itself since most people aren't "used"
- // to putting things in bundles, but other people may actually not
- // want to tranform the process (running as a helper or something)
- // so don't do that for them. This means checking both LSUIElement
- // and LSBackgroundOnly. If you set them both... well, you
- // shouldn't do that.
-
- bool forceTransform = true;
- CFTypeRef value = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(),
- CFSTR("LSUIElement"));
- if (value) {
- CFTypeID valueType = CFGetTypeID(value);
- // Officially it's supposed to be a string, a boolean makes sense, so we'll check.
- // A number less so, but OK.
- if (valueType == CFStringGetTypeID())
- forceTransform = !(QCFString::toQString(static_cast<CFStringRef>(value)).toInt());
- else if (valueType == CFBooleanGetTypeID())
- forceTransform = !CFBooleanGetValue(static_cast<CFBooleanRef>(value));
- else if (valueType == CFNumberGetTypeID()) {
- int valueAsInt;
- CFNumberGetValue(static_cast<CFNumberRef>(value), kCFNumberIntType, &valueAsInt);
- forceTransform = !valueAsInt;
- }
- }
-
- if (forceTransform) {
- value = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(),
- CFSTR("LSBackgroundOnly"));
- if (value) {
- CFTypeID valueType = CFGetTypeID(value);
- if (valueType == CFBooleanGetTypeID())
- forceTransform = !CFBooleanGetValue(static_cast<CFBooleanRef>(value));
- else if (valueType == CFStringGetTypeID())
- forceTransform = !(QCFString::toQString(static_cast<CFStringRef>(value)).toInt());
- else if (valueType == CFNumberGetTypeID()) {
- int valueAsInt;
- CFNumberGetValue(static_cast<CFNumberRef>(value), kCFNumberIntType, &valueAsInt);
- forceTransform = !valueAsInt;
- }
- }
- }
-
-
- if (forceTransform) {
- TransformProcessType(&psn, kProcessTransformToForegroundApplication);
- }
- }
- }
-
- char **argv = priv->argv;
-
- // Get command line params
- if (int argc = priv->argc) {
- int i, j = 1;
- QString passed_psn;
- for(i=1; i < argc; i++) {
- if (argv[i] && *argv[i] != '-') {
- argv[j++] = argv[i];
- continue;
- }
- QByteArray arg(argv[i]);
-#if defined(QT_DEBUG)
- if (arg == "-nograb")
- appNoGrab = !appNoGrab;
- else
-#endif // QT_DEBUG
- if (arg.left(5) == "-psn_") {
- passed_psn = QString::fromLatin1(arg.mid(6));
- } else {
- argv[j++] = argv[i];
- }
- }
- if (j < priv->argc) {
- priv->argv[j] = 0;
- priv->argc = j;
- }
-
- //special hack to change working directory (for an app bundle) when running from finder
- if (!passed_psn.isNull() && QDir::currentPath() == QLatin1String("/")) {
- QCFType<CFURLRef> bundleURL(CFBundleCopyBundleURL(CFBundleGetMainBundle()));
- QString qbundlePath = QCFString(CFURLCopyFileSystemPath(bundleURL,
- kCFURLPOSIXPathStyle));
- if (qbundlePath.endsWith(QLatin1String(".app")))
- QDir::setCurrent(qbundlePath.section(QLatin1Char('/'), 0, -2));
- }
- }
-
- QMacPasteboardMime::initialize();
-
- qApp->setObjectName(priv->appName());
- if (qt_is_gui_used) {
- QColormap::initialize();
- QFont::initialize();
- QCursorData::initialize();
- QCoreGraphicsPaintEngine::initialize();
-#ifndef QT_NO_ACCESSIBILITY
- QAccessible::initialize();
-#endif
- QMacInputContext::initialize();
- QApplicationPrivate::inputContext = new QMacInputContext;
-
- if (QApplication::desktopSettingsAware())
- qt_mac_update_os_settings();
-#ifndef QT_MAC_USE_COCOA
- if (!app_proc_handler) {
- app_proc_handlerUPP = NewEventHandlerUPP(QApplicationPrivate::globalEventProcessor);
- qt_init_app_proc_handler();
- }
-
-#endif
- if (!app_proc_ae_handlerUPP && !QApplication::testAttribute(Qt::AA_MacPluginApplication)) {
- app_proc_ae_handlerUPP = AEEventHandlerUPP(QApplicationPrivate::globalAppleEventProcessor);
- for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i) {
- // Install apple event handler, but avoid overwriting an already
- // existing handler (it means a 3rd party application has installed one):
- SRefCon refCon = 0;
- AEEventHandlerUPP current_handler = NULL;
- AEGetEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id, &current_handler, &refCon, false);
- if (!current_handler)
- AEInstallEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id,
- app_proc_ae_handlerUPP, SRefCon(qApp), false);
- }
- }
-
- if (QApplicationPrivate::app_style) {
- QEvent ev(QEvent::Style);
- qt_sendSpontaneousEvent(QApplicationPrivate::app_style, &ev);
- }
- }
- if (QApplication::desktopSettingsAware())
- QApplicationPrivate::qt_mac_apply_settings();
-
- // Cocoa application delegate
-#ifdef QT_MAC_USE_COCOA
- NSApplication *cocoaApp = [QNSApplication sharedApplication];
- qt_redirectNSApplicationSendEvent();
-
- QMacCocoaAutoReleasePool pool;
- id oldDelegate = [cocoaApp delegate];
- QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) *newDelegate = [QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate];
- Q_ASSERT(newDelegate);
- [newDelegate setQtPrivate:priv];
- // Only do things that make sense to do once, otherwise we crash.
- if (oldDelegate != newDelegate && !QApplication::testAttribute(Qt::AA_MacPluginApplication)) {
- [newDelegate setReflectionDelegate:oldDelegate];
- [cocoaApp setDelegate:newDelegate];
-
- QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader = [[QT_MANGLE_NAMESPACE(QCocoaMenuLoader) alloc] init];
- if ([NSBundle loadNibNamed:@"qt_menu" owner:qtMenuLoader] == false) {
- qFatal("Qt internal error: qt_menu.nib could not be loaded. The .nib file"
- " should be placed in QtGui.framework/Versions/Current/Resources/ "
- " or in the resources directory of your application bundle.");
- }
-
- [cocoaApp setMenu:[qtMenuLoader menu]];
- [newDelegate setMenuLoader:qtMenuLoader];
- [qtMenuLoader release];
- }
-#endif
- // Register for Carbon tablet proximity events on the event monitor target.
- // This means that we should receive proximity events even when we aren't the active application.
- if (!tablet_proximity_handler) {
- tablet_proximity_UPP = NewEventHandlerUPP(QApplicationPrivate::tabletProximityCallback);
- qt_init_tablet_proximity_handler();
- }
- priv->native_modal_dialog_active = false;
-
- qt_mac_read_fontsmoothing_settings();
-}
-
-void qt_release_apple_event_handler()
-{
- if(app_proc_ae_handlerUPP) {
- for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i)
- AERemoveEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id,
- app_proc_ae_handlerUPP, true);
- DisposeAEEventHandlerUPP(app_proc_ae_handlerUPP);
- app_proc_ae_handlerUPP = 0;
- }
-}
-
-/*****************************************************************************
- qt_cleanup() - cleans up when the application is finished
- *****************************************************************************/
-
-void qt_cleanup()
-{
- CGDisplayRemoveReconfigurationCallback(qt_mac_display_change_callbk, 0);
- CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
- CFNotificationCenterRemoveObserver(center, qApp, kCMDeviceUnregisteredNotification, 0);
- CFNotificationCenterRemoveObserver(center, qApp, kCMDefaultDeviceNotification, 0);
- CFNotificationCenterRemoveObserver(center, qApp, kCMDeviceProfilesNotification, 0);
- CFNotificationCenterRemoveObserver(center, qApp, kCMDefaultDeviceProfileNotification, 0);
-
-#ifndef QT_MAC_USE_COCOA
- qt_release_app_proc_handler();
- if (app_proc_handlerUPP) {
- DisposeEventHandlerUPP(app_proc_handlerUPP);
- app_proc_handlerUPP = 0;
- }
-#endif
- qt_release_apple_event_handler();
- qt_release_tablet_proximity_handler();
- if (tablet_proximity_UPP)
- DisposeEventHandlerUPP(tablet_proximity_UPP);
-
- QPixmapCache::clear();
- if (qt_is_gui_used) {
-#ifndef QT_NO_ACCESSIBILITY
- QAccessible::cleanup();
-#endif
- QMacInputContext::cleanup();
- QCursorData::cleanup();
- QFont::cleanup();
- QColormap::cleanup();
- if (qt_mac_safe_pdev) {
- delete qt_mac_safe_pdev;
- qt_mac_safe_pdev = 0;
- }
- extern void qt_mac_unregister_widget(); // qapplication_mac.cpp
- qt_mac_unregister_widget();
- }
-}
-
-/*****************************************************************************
- Platform specific global and internal functions
- *****************************************************************************/
-void qt_updated_rootinfo()
-{
-}
-
-bool qt_wstate_iconified(WId)
-{
- return false;
-}
-
-/*****************************************************************************
- Platform specific QApplication members
- *****************************************************************************/
-extern QWidget * mac_mouse_grabber;
-extern QWidget * mac_keyboard_grabber;
-
-#ifdef QT3_SUPPORT
-void QApplication::setMainWidget(QWidget *mainWidget)
-{
- QApplicationPrivate::main_widget = mainWidget;
- if (QApplicationPrivate::main_widget && windowIcon().isNull()
- && QApplicationPrivate::main_widget->testAttribute(Qt::WA_SetWindowIcon))
- setWindowIcon(QApplicationPrivate::main_widget->windowIcon());
-}
-#endif
-#ifndef QT_NO_CURSOR
-
-/*****************************************************************************
- QApplication cursor stack
- *****************************************************************************/
-
-void QApplication::setOverrideCursor(const QCursor &cursor)
-{
- qApp->d_func()->cursor_list.prepend(cursor);
-
-#ifdef QT_MAC_USE_COCOA
- qt_mac_update_cursor();
-#else
- if (qApp && qApp->activeWindow())
- qt_mac_set_cursor(&qApp->d_func()->cursor_list.first());
-#endif
-}
-
-void QApplication::restoreOverrideCursor()
-{
- if (qApp->d_func()->cursor_list.isEmpty())
- return;
- qApp->d_func()->cursor_list.removeFirst();
-
-#ifdef QT_MAC_USE_COCOA
- qt_mac_update_cursor();
-#else
- if (qApp && qApp->activeWindow()) {
- const QCursor def(Qt::ArrowCursor);
- qt_mac_set_cursor(qApp->d_func()->cursor_list.isEmpty() ? &def : &qApp->d_func()->cursor_list.first());
- }
-#endif
-}
-#endif // QT_NO_CURSOR
-
-QWidget *QApplication::topLevelAt(const QPoint &p)
-{
-#ifndef QT_MAC_USE_COCOA
- QWidget *widget;
- qt_mac_window_at(p.x(), p.y(), &widget);
- return widget;
-#else
- // Use a cache to avoid iterate through the whole list of windows for all
- // calls to to topLevelAt. We e.g. do this for each and every mouse
- // move since we need to find the widget under mouse:
- if (topLevelAt_cache && topLevelAt_cache->frameGeometry().contains(p))
- return topLevelAt_cache;
-
- // INVARIANT: Cache miss. Go through the list if windows instead:
- QMacCocoaAutoReleasePool pool;
- NSPoint cocoaPoint = flipPoint(p);
- NSInteger windowCount;
- NSCountWindows(&windowCount);
- if (windowCount <= 0)
- return 0; // There's no window to find!
-
- QVarLengthArray<NSInteger> windowList(windowCount);
- NSWindowList(windowCount, windowList.data());
- int firstQtWindowFound = -1;
- for (int i = 0; i < windowCount; ++i) {
- NSWindow *window = [NSApp windowWithWindowNumber:windowList[i]];
- if (window) {
- QWidget *candidateWindow = [window QT_MANGLE_NAMESPACE(qt_qwidget)];
- if (candidateWindow && firstQtWindowFound == -1)
- firstQtWindowFound = i;
-
- if (NSPointInRect(cocoaPoint, [window frame])) {
- // Check to see if there's a hole in the window where the mask is.
- // If there is, we should just continue to see if there is a window below.
- if (candidateWindow && !candidateWindow->mask().isEmpty()) {
- QPoint localPoint = candidateWindow->mapFromGlobal(p);
- if (!candidateWindow->mask().contains(localPoint))
- continue;
- else
- return candidateWindow;
- } else {
- if (i == firstQtWindowFound) {
- // The cache will only work when the window under mouse is
- // top most (that is, not partially obscured by other windows.
- // And we only set it if no mask is present to optimize for the common case:
- topLevelAt_cache = candidateWindow;
- }
- return candidateWindow;
- }
- }
- }
- }
-
- topLevelAt_cache = 0;
- return 0;
-#endif
-}
-
-/*****************************************************************************
- Main event loop
- *****************************************************************************/
-
-bool QApplicationPrivate::modalState()
-{
- return app_do_modal;
-}
-
-#ifdef QT_MAC_USE_COCOA
-#endif
-
-void QApplicationPrivate::enterModal_sys(QWidget *widget)
-{
-#ifdef DEBUG_MODAL_EVENTS
- Q_ASSERT(widget);
- qDebug("Entering modal state with %s::%s::%p (%d)", widget->metaObject()->className(), widget->objectName().toLocal8Bit().constData(),
- widget, qt_modal_stack ? (int)qt_modal_stack->count() : -1);
-#endif
- if (!qt_modal_stack)
- qt_modal_stack = new QWidgetList;
-
- dispatchEnterLeave(0, qt_last_mouse_receiver);
- qt_last_mouse_receiver = 0;
-
- qt_modal_stack->insert(0, widget);
- if (!app_do_modal)
- qt_event_request_menubarupdate();
- app_do_modal = true;
- qt_button_down = 0;
-
-#ifdef QT_MAC_USE_COCOA
- if (!qt_mac_is_macsheet(widget))
- QEventDispatcherMacPrivate::beginModalSession(widget);
-#endif
-}
-
-void QApplicationPrivate::leaveModal_sys(QWidget *widget)
-{
- if (qt_modal_stack && qt_modal_stack->removeAll(widget)) {
-#ifdef DEBUG_MODAL_EVENTS
- qDebug("Leaving modal state with %s::%s::%p (%d)", widget->metaObject()->className(), widget->objectName().toLocal8Bit().constData(),
- widget, qt_modal_stack->count());
-#endif
- if (qt_modal_stack->isEmpty()) {
- delete qt_modal_stack;
- qt_modal_stack = 0;
- QPoint p(QCursor::pos());
- app_do_modal = false;
- QWidget* w = 0;
- if (QWidget *grabber = QWidget::mouseGrabber())
- w = grabber;
- else
- w = QApplication::widgetAt(p.x(), p.y());
- dispatchEnterLeave(w, qt_last_mouse_receiver); // send synthetic enter event
- qt_last_mouse_receiver = w;
- }
-#ifdef QT_MAC_USE_COCOA
- if (!qt_mac_is_macsheet(widget))
- QEventDispatcherMacPrivate::endModalSession(widget);
-#endif
- }
-#ifdef DEBUG_MODAL_EVENTS
- else qDebug("Failure to remove %s::%s::%p -- %p", widget->metaObject()->className(), widget->objectName().toLocal8Bit().constData(), widget, qt_modal_stack);
-#endif
- app_do_modal = (qt_modal_stack != 0);
- if (!app_do_modal)
- qt_event_request_menubarupdate();
-}
-
-QWidget *QApplicationPrivate::tryModalHelper_sys(QWidget *top)
-{
-#ifndef QT_MAC_USE_COCOA
- if(top && qt_mac_is_macsheet(top) && !IsWindowVisible(qt_mac_window_for(top))) {
- if(OSWindowRef wp = GetFrontWindowOfClass(kSheetWindowClass, true)) {
- if(QWidget *sheet = qt_mac_find_window(wp))
- top = sheet;
- }
- }
-#endif
- return top;
-}
-
-#ifndef QT_MAC_USE_COCOA
-static bool qt_try_modal(QWidget *widget, EventRef event)
-{
- QWidget * top = 0;
-
- if (QApplicationPrivate::tryModalHelper(widget, &top))
- return true;
-
- // INVARIANT: widget is modally shaddowed within its
- // window, and should therefore not handle the event.
- // However, if the window is not active, the event
- // might suggest that we should bring it to front:
-
- bool block_event = false;
-
- if (event) {
- switch (GetEventClass(event)) {
- case kEventClassMouse:
- case kEventClassKeyboard:
- block_event = true;
- break;
- }
- }
-
- QWidget *activeWidget = QApplication::activeWindow();
- if ((!activeWidget || QApplicationPrivate::isBlockedByModal(activeWidget)) &&
- top->isWindow() && block_event && !QApplicationPrivate::native_modal_dialog_active)
- top->raise();
-
-#ifdef DEBUG_MODAL_EVENTS
- qDebug("%s:%d -- final decision! (%s)", __FILE__, __LINE__, block_event ? "false" : "true");
-#endif
- return !block_event;
-}
-#endif
-
-OSStatus QApplicationPrivate::tabletProximityCallback(EventHandlerCallRef, EventRef carbonEvent,
- void *)
-{
- OSType eventClass = GetEventClass(carbonEvent);
- UInt32 eventKind = GetEventKind(carbonEvent);
- if (eventClass != kEventClassTablet || eventKind != kEventTabletProximity)
- return eventNotHandledErr;
-
- // Get the current point of the device and its unique ID.
- ::TabletProximityRec proxRec;
- GetEventParameter(carbonEvent, kEventParamTabletProximityRec, typeTabletProximityRec, 0,
- sizeof(proxRec), 0, &proxRec);
- qt_dispatchTabletProximityEvent(proxRec);
- return noErr;
-}
-
-OSStatus
-QApplicationPrivate::globalEventProcessor(EventHandlerCallRef er, EventRef event, void *data)
-{
-#ifndef QT_MAC_USE_COCOA
- QApplication *app = (QApplication *)data;
- QScopedLoopLevelCounter loopLevelCounter(app->d_func()->threadData);
- long result;
- if (app->filterEvent(&event, &result))
- return result;
- if(app->macEventFilter(er, event)) //someone else ate it
- return noErr;
- QPointer<QWidget> widget;
-
- /*We assume all events are handled and in
- the code below we set it to false when we know we didn't handle it, this
- will let rogue events through (shouldn't really happen, but better safe
- than sorry) */
- bool handled_event=true;
- UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event);
- switch(eclass)
- {
- case kEventClassQt:
- if(ekind == kEventQtRequestShowSheet) {
- request_showsheet_pending = 0;
- QWidget *widget = 0;
- GetEventParameter(event, kEventParamQWidget, typeQWidget, 0,
- sizeof(widget), 0, &widget);
- if(widget) {
- if (widget->macEvent(er, event))
- return noErr;
- WindowPtr window = qt_mac_window_for(widget);
- bool just_show = !qt_mac_is_macsheet(widget);
- if(!just_show) {
- OSStatus err = ShowSheetWindow(window, qt_mac_window_for(widget->parentWidget()));
- if(err != noErr)
- qWarning("Qt: QWidget: Unable to show as sheet %s::%s [%ld]", widget->metaObject()->className(),
- widget->objectName().toLocal8Bit().constData(), long(err));
- just_show = true;
- }
- if(just_show) //at least the window will be visible, but the sheet flag doesn't work sadly (probalby too many sheets)
- ShowHide(window, true);
- }
- } else if(ekind == kEventQtRequestWindowChange) {
- qt_mac_event_release(request_window_change_pending);
- } else if(ekind == kEventQtRequestMenubarUpdate) {
- qt_mac_event_release(request_menubarupdate_pending);
- QMenuBar::macUpdateMenuBar();
- } else if(ekind == kEventQtRequestActivate) {
- qt_mac_event_release(request_activate_pending.event);
- if(request_activate_pending.widget) {
- QWidget *tlw = request_activate_pending.widget->window();
- if (tlw->macEvent(er, event))
- return noErr;
- request_activate_pending.widget = 0;
- tlw->activateWindow();
- SelectWindow(qt_mac_window_for(tlw));
- }
- } else if(ekind == kEventQtRequestContext) {
- bool send = false;
- if ((send = (event == request_context_pending)))
- qt_mac_event_release(request_context_pending);
- if(send) {
- //figure out which widget to send it to
- QPoint where = QCursor::pos();
- QWidget *widget = 0;
- GetEventParameter(event, kEventParamQWidget, typeQWidget, 0,
- sizeof(widget), 0, &widget);
- if(!widget) {
- if(qt_button_down)
- widget = qt_button_down;
- else
- widget = QApplication::widgetAt(where.x(), where.y());
- }
- if(widget && !isBlockedByModal(widget)) {
- if (widget->macEvent(er, event))
- return noErr;
- QPoint plocal(widget->mapFromGlobal(where));
- const Qt::KeyboardModifiers keyboardModifiers = qt_mac_get_modifiers(GetCurrentEventKeyModifiers());
- QContextMenuEvent qme(QContextMenuEvent::Mouse, plocal, where, keyboardModifiers);
- QApplication::sendEvent(widget, &qme);
- if(qme.isAccepted()) { //once this happens the events before are pitched
- qt_button_down = 0;
- qt_mac_dblclick.last_widget = 0;
- }
- } else {
- handled_event = false;
- }
- }
- } else {
- handled_event = false;
- }
- break;
- case kEventClassTablet:
- switch (ekind) {
- case kEventTabletProximity:
- // Get the current point of the device and its unique ID.
- ::TabletProximityRec proxRec;
- GetEventParameter(event, kEventParamTabletProximityRec, typeTabletProximityRec, 0,
- sizeof(proxRec), 0, &proxRec);
- qt_dispatchTabletProximityEvent(proxRec);
- }
- break;
- case kEventClassMouse:
- {
- static const int kEventParamQAppSeenMouseEvent = 'QASM';
- // Check if we've seen the event, if we have we shouldn't process
- // it again as it may lead to spurious "double events"
- bool seenEvent;
- if (GetEventParameter(event, kEventParamQAppSeenMouseEvent,
- typeBoolean, 0, sizeof(bool), 0, &seenEvent) == noErr) {
- if (seenEvent)
- return eventNotHandledErr;
- }
- seenEvent = true;
- SetEventParameter(event, kEventParamQAppSeenMouseEvent, typeBoolean,
- sizeof(bool), &seenEvent);
-
- Point where;
- bool inNonClientArea = false;
- GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, 0,
- sizeof(where), 0, &where);
-#if defined(DEBUG_MOUSE_MAPS)
- const char *edesc = 0;
- switch(ekind) {
- case kEventMouseDown: edesc = "MouseButtonPress"; break;
- case kEventMouseUp: edesc = "MouseButtonRelease"; break;
- case kEventMouseDragged: case kEventMouseMoved: edesc = "MouseMove"; break;
- case kEventMouseScroll: edesc = "MouseWheelScroll"; break;
- case kEventMouseWheelMoved: edesc = "MouseWheelMove"; break;
- }
- if(ekind == kEventMouseDown || ekind == kEventMouseUp)
- qDebug("Handling mouse: %s", edesc);
-#endif
- QEvent::Type etype = QEvent::None;
- Qt::KeyboardModifiers modifiers;
- {
- UInt32 mac_modifiers = 0;
- GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, 0,
- sizeof(mac_modifiers), 0, &mac_modifiers);
- modifiers = qt_mac_get_modifiers(mac_modifiers);
- }
- Qt::MouseButtons buttons;
- {
- UInt32 mac_buttons = 0;
- GetEventParameter(event, kEventParamMouseChord, typeUInt32, 0,
- sizeof(mac_buttons), 0, &mac_buttons);
- if (ekind != kEventMouseWheelMoved)
- buttons = qt_mac_get_buttons(mac_buttons);
- else
- buttons = QApplication::mouseButtons();
- }
-
- int wheel_deltaX = 0;
- int wheel_deltaY = 0;
- static EventRef compatibilityEvent = 0;
-
- if (ekind == kEventMouseScroll) {
- // kEventMouseScroll is the new way of dealing with mouse wheel
- // events (kEventMouseWheelMoved was the old). kEventMouseScroll results
- // in much smoother scrolling when using Mighty Mouse or TrackPad. For
- // compatibility with older applications, carbon will also send us
- // kEventMouseWheelMoved events if we dont eat this event
- // (actually two events; one for horizontal and one for vertical).
- // As a results of this, and to make sure we dont't receive duplicate events,
- // we try to detect when this happend by checking the 'compatibilityEvent'.
- // Since delta is delivered as pixels rather than degrees, we need to
- // convert from pixels to degrees in a sensible manner.
- // It looks like 1/4 degrees per pixel behaves most native.
- // (NB: Qt expects the unit for delta to be 8 per degree):
- const int pixelsToDegrees = 2;
- SInt32 mdelt = 0;
- GetEventParameter(event, kEventParamMouseWheelSmoothHorizontalDelta, typeSInt32, 0,
- sizeof(mdelt), 0, &mdelt);
- wheel_deltaX = mdelt * pixelsToDegrees;
- mdelt = 0;
- GetEventParameter(event, kEventParamMouseWheelSmoothVerticalDelta, typeSInt32, 0,
- sizeof(mdelt), 0, &mdelt);
- wheel_deltaY = mdelt * pixelsToDegrees;
- GetEventParameter(event, kEventParamEventRef, typeEventRef, 0,
- sizeof(compatibilityEvent), 0, &compatibilityEvent);
- } else if (ekind == kEventMouseWheelMoved) {
- if (event != compatibilityEvent) {
- compatibilityEvent = 0;
- int mdelt = 0;
- GetEventParameter(event, kEventParamMouseWheelDelta, typeSInt32, 0,
- sizeof(mdelt), 0, &mdelt);
- EventMouseWheelAxis axis;
- GetEventParameter(event, kEventParamMouseWheelAxis, typeMouseWheelAxis, 0,
- sizeof(axis), 0, &axis);
-
- // Remove acceleration, and use either -120 or 120 as delta:
- if (axis == kEventMouseWheelAxisX)
- wheel_deltaX = qBound(-120, int(mdelt * 10000), 120);
- else
- wheel_deltaY = qBound(-120, int(mdelt * 10000), 120);
- }
- }
-
- Qt::MouseButton button = Qt::NoButton;
- if(ekind == kEventMouseDown || ekind == kEventMouseUp) {
- EventMouseButton mac_button = 0;
- GetEventParameter(event, kEventParamMouseButton, typeMouseButton, 0,
- sizeof(mac_button), 0, &mac_button);
- button = qt_mac_get_button(mac_button);
- }
-
- switch(ekind) {
- case kEventMouseDown:
- etype = QEvent::MouseButtonPress;
- break;
- case kEventMouseUp:
- etype = QEvent::MouseButtonRelease;
- break;
- case kEventMouseDragged:
- case kEventMouseMoved:
- etype = QEvent::MouseMove;
- break;
- }
-
- const bool inPopupMode = app->d_func()->inPopupMode();
-
- // A click outside a popup closes the popup. Make sure
- // that no events are generated for the release part of that click.
- // (The press goes to the popup and closes it.)
- if (etype == QEvent::MouseButtonPress) {
- qt_mac_previous_press_in_popup_mode = inPopupMode;
- } else if (qt_mac_previous_press_in_popup_mode && !inPopupMode && etype == QEvent::MouseButtonRelease) {
- qt_mac_previous_press_in_popup_mode = false;
- handled_event = true;
-#if defined(DEBUG_MOUSE_MAPS)
- qDebug("Bail out early due to qt_mac_previous_press_in_popup_mode");
-#endif
- break; // break from case kEventClassMouse
- }
-
- //figure out which widget to send it to
- if(inPopupMode) {
- QWidget *popup = qApp->activePopupWidget();
- if (qt_button_down && qt_button_down->window() == popup) {
- widget = qt_button_down;
- } else {
- QPoint pos = popup->mapFromGlobal(QPoint(where.h, where.v));
- widget = popup->childAt(pos);
- }
- if(!widget)
- widget = popup;
- } else {
- if(mac_mouse_grabber) {
- widget = mac_mouse_grabber;
- } else if (qt_button_down) {
- widget = qt_button_down;
- } else {
- {
- WindowPtr window = 0;
- if(GetEventParameter(event, kEventParamWindowRef, typeWindowRef, 0,
- sizeof(window), 0, &window) != noErr)
- FindWindowOfClass(&where, kAllWindowClasses, &window, 0);
- if(window) {
- HIViewRef hiview;
- if(HIViewGetViewForMouseEvent(HIViewGetRoot(window), event, &hiview) == noErr) {
- widget = QWidget::find((WId)hiview);
- if (widget) {
- // Make sure we didn't pass over a widget with a "fake hole" in it.
- QWidget *otherWidget = QApplication::widgetAt(where.h, where.v);
- if (otherWidget && otherWidget->testAttribute(Qt::WA_MouseNoMask))
- widget = otherWidget;
- }
- }
- }
- }
- if(!widget) //fallback
- widget = QApplication::widgetAt(where.h, where.v);
- if(ekind == kEventMouseUp && widget) {
- short part = qt_mac_window_at(where.h, where.v);
- if(part == inDrag) {
- UInt32 count = 0;
- GetEventParameter(event, kEventParamClickCount, typeUInt32, NULL,
- sizeof(count), NULL, &count);
- if(count == 2 && qt_mac_collapse_on_dblclick) {
- if (widget->macEvent(er, event))
- return noErr;
- widget->setWindowState(widget->windowState() | Qt::WindowMinimized);
- //we send a hide to be like X11/Windows
- QEvent e(QEvent::Hide);
- QApplication::sendSpontaneousEvent(widget, &e);
- break;
- }
- }
- }
- }
- }
- if (widget && widget->macEvent(er, event))
- return noErr;
- WindowPartCode wpc = qt_mac_window_at(where.h, where.v, 0);
- if (wpc == inProxyIcon && modifiers == Qt::ControlModifier && buttons != Qt::NoButton) {
- QIconDragEvent e;
- QApplication::sendSpontaneousEvent(widget, &e);
- if (e.isAccepted()) {
- return noErr; // IconDrag ate it.
- }
- }
- if (inPopupMode == false
- && (qt_button_down == 0 || qt_button_down_in_content == false)
- && (wpc != inContent && wpc != inStructure)) {
- inNonClientArea = true;
- switch (etype) {
- case QEvent::MouseButtonPress: {
- UInt32 count = 0;
- GetEventParameter(event, kEventParamClickCount, typeUInt32, 0,
- sizeof(count), 0, &count);
- if(count % 2 || count == 0) {
- etype = QEvent::NonClientAreaMouseButtonPress;
- } else {
- etype = QEvent::NonClientAreaMouseButtonDblClick;
- }} break;
- case QEvent::MouseButtonRelease:
- etype = QEvent::NonClientAreaMouseButtonRelease;
- break;
- case QEvent::MouseMove:
- if (widget == 0 || widget->hasMouseTracking())
- etype = QEvent::NonClientAreaMouseMove;
- break;
- default:
- break;
- }
- }
-
- if(qt_mac_find_window((FrontWindow()))) { //set the cursor up
- QCursor cursor(Qt::ArrowCursor);
- QWidget *cursor_widget = widget;
- if(cursor_widget && cursor_widget == qt_button_down && ekind == kEventMouseUp)
- cursor_widget = QApplication::widgetAt(where.h, where.v);
- if(cursor_widget) { //only over the app, do we set a cursor..
- if(!qApp->d_func()->cursor_list.isEmpty()) {
- cursor = qApp->d_func()->cursor_list.first();
- } else {
- for(; cursor_widget; cursor_widget = cursor_widget->parentWidget()) {
- QWExtra *extra = cursor_widget->d_func()->extraData();
- if(extra && extra->curs && cursor_widget->isEnabled()) {
- cursor = *extra->curs;
- break;
- }
- }
- }
- }
- qt_mac_set_cursor(&cursor);
- }
-
- //This mouse button state stuff looks like this on purpose
- //although it looks hacky it is VERY intentional..
- if(widget && app_do_modal && !qt_try_modal(widget, event)) {
- if(ekind == kEventMouseDown && qt_mac_is_macsheet(QApplication::activeModalWidget()))
- QApplication::activeModalWidget()->parentWidget()->activateWindow(); //sheets have a parent
- handled_event = false;
-#if defined(DEBUG_MOUSE_MAPS)
- qDebug("Bail out early due to qt_try_modal");
-#endif
- break;
- }
-
- UInt32 tabletEventType = 0;
- GetEventParameter(event, kEventParamTabletEventType, typeUInt32, 0,
- sizeof(tabletEventType), 0, &tabletEventType);
- if (tabletEventType == kEventTabletPoint) {
- TabletPointRec tabletPointRec;
- GetEventParameter(event, kEventParamTabletPointRec, typeTabletPointRec, 0,
- sizeof(tabletPointRec), 0, &tabletPointRec);
- QEvent::Type t = QEvent::TabletMove; //default
- int new_tablet_button_state = tabletPointRec.buttons ? 1 : 0;
- if (new_tablet_button_state != tablet_button_state)
- if (new_tablet_button_state)
- t = QEvent::TabletPress;
- else
- t = QEvent::TabletRelease;
- tablet_button_state = new_tablet_button_state;
-
- QMacTabletHash *tabletHash = qt_mac_tablet_hash();
- if (!tabletHash->contains(tabletPointRec.deviceID) && t != QEvent::TabletRelease) {
- // Never discard TabletRelease events as they may be delivered *after* TabletLeaveProximity events
- qWarning("handleTabletEvent: This tablet device is unknown"
- " (received no proximity event for it). Discarding event.");
- return false;
- }
- QTabletDeviceData &deviceData = tabletHash->operator[](tabletPointRec.deviceID);
- if (t == QEvent::TabletPress) {
- deviceData.widgetToGetPress = widget;
- } else if (t == QEvent::TabletRelease && deviceData.widgetToGetPress) {
- widget = deviceData.widgetToGetPress;
- deviceData.widgetToGetPress = 0;
- }
-
- if (widget) {
- int tiltX = ((int)tabletPointRec.tiltX)/(32767/64); // 32K -> 60
- int tiltY = ((int)tabletPointRec.tiltY)/(-32767/64); // 32K -> 60
- HIPoint hiPoint;
- GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, 0, sizeof(HIPoint), 0, &hiPoint);
- QPointF hiRes(hiPoint.x, hiPoint.y);
- QPoint global(where.h, where.v);
-
-
-
- QPoint local(widget->mapFromGlobal(global));
- int z = 0;
- qreal rotation = 0.0;
- qreal tp = 0.0;
- // Again from the Wacom.h header
-
- if (deviceData.capabilityMask & 0x0200) // Z-axis
- z = tabletPointRec.absZ;
-
- if (deviceData.capabilityMask & 0x0800) // Tangential pressure
- tp = tabletPointRec.tangentialPressure / 32767.0;
-
- if (deviceData.capabilityMask & 0x2000) // Rotation
- rotation = qreal(tabletPointRec.rotation) / 64.0;
-
- QTabletEvent e(t, local, global, hiRes, deviceData.tabletDeviceType,
- deviceData.tabletPointerType,
- qreal(tabletPointRec.pressure / qreal(0xffff)), tiltX, tiltY,
- tp, rotation, z, modifiers, deviceData.tabletUniqueID);
- QApplication::sendSpontaneousEvent(widget, &e);
- if (e.isAccepted()) {
- if (t == QEvent::TabletPress) {
- qt_button_down = widget;
- } else if (t == QEvent::TabletRelease) {
- qt_button_down = 0;
- }
-#if defined(DEBUG_MOUSE_MAPS)
- qDebug("Bail out early due to tablet acceptance");
-#endif
- break;
- }
- }
- }
-
- if(ekind == kEventMouseDown) {
- qt_mac_no_click_through_mode = false;
- const short windowPart = qt_mac_window_at(where.h, where.v, 0);
- // Menubar almost always wins.
- if (!inPopupMode && windowPart == inMenuBar) {
- MenuSelect(where); //allow menu tracking
- return noErr;
- }
-
- if (widget && !(GetCurrentKeyModifiers() & cmdKey)) {
- extern bool qt_isGenuineQWidget(const QWidget *); // qwidget_mac.cpp
- QWidget *window = widget->window();
- bool genuineQtWidget = qt_isGenuineQWidget(widget); // the widget, not the window.
- window->raise();
-
- bool needActivate = (window->windowType() != Qt::Desktop)
- && (window->windowType() != Qt::Popup)
- && !qt_mac_is_macsheet(window);
- if (needActivate && (!window->isModal() && qobject_cast<QDockWidget *>(window)))
- needActivate = false;
-
- if (genuineQtWidget && needActivate)
- needActivate = !window->isActiveWindow()
- || !IsWindowActive(qt_mac_window_for(window));
-
- if (needActivate) {
- window->activateWindow();
- if (!qt_mac_can_clickThrough(widget)) {
- qt_mac_no_click_through_mode = true;
- handled_event = false;
-#if defined(DEBUG_MOUSE_MAPS)
- qDebug("Bail out early due to qt_mac_canClickThrough %s::%s", widget->metaObject()->className(),
- widget->objectName().toLocal8Bit().constData());
-#endif
- break;
- }
- }
- }
-
- if(qt_mac_dblclick.last_widget &&
- qt_mac_dblclick.last_x != -1 && qt_mac_dblclick.last_y != -1 &&
- QRect(qt_mac_dblclick.last_x-2, qt_mac_dblclick.last_y-2, 4, 4).contains(QPoint(where.h, where.v))) {
- if(qt_mac_dblclick.use_qt_time_limit) {
- EventTime now = GetEventTime(event);
- if(qt_mac_dblclick.last_time != -2 && qt_mac_dblclick.last_widget == widget &&
- now - qt_mac_dblclick.last_time <= ((double)QApplicationPrivate::mouse_double_click_time)/1000 &&
- qt_mac_dblclick.last_button == button)
- etype = QEvent::MouseButtonDblClick;
- } else {
- UInt32 count = 0;
- GetEventParameter(event, kEventParamClickCount, typeUInt32, 0,
- sizeof(count), 0, &count);
- if(!(count % 2) && qt_mac_dblclick.last_modifiers == modifiers &&
- qt_mac_dblclick.last_widget == widget && qt_mac_dblclick.last_button == button)
- etype = QEvent::MouseButtonDblClick;
- }
- if(etype == QEvent::MouseButtonDblClick)
- qt_mac_dblclick.last_widget = 0;
- }
- if(etype != QEvent::MouseButtonDblClick) {
- qt_mac_dblclick.last_x = where.h;
- qt_mac_dblclick.last_y = where.v;
- } else {
- qt_mac_dblclick.last_x = qt_mac_dblclick.last_y = -1;
- }
- } else if(qt_mac_no_click_through_mode) {
- if(ekind == kEventMouseUp)
- qt_mac_no_click_through_mode = false;
- handled_event = false;
-#if defined(DEBUG_MOUSE_MAPS)
- qDebug("Bail out early due to qt_mac_no_click_through_mode");
-#endif
- break;
- }
-
- QPointer<QWidget> leaveAfterRelease = 0;
- switch(ekind) {
- case kEventMouseUp:
- if (!buttons) {
- if (!inPopupMode && !QWidget::mouseGrabber())
- leaveAfterRelease = qt_button_down;
- qt_button_down = 0;
- }
- break;
- case kEventMouseDown: {
- if (!qt_button_down)
- qt_button_down = widget;
- WindowPartCode wpc = qt_mac_window_at(where.h, where.v, 0);
- qt_button_down_in_content = (wpc == inContent || wpc == inStructure);
- break; }
- }
-
- // Check if we should send enter/leave events:
- switch(ekind) {
- case kEventMouseDragged:
- case kEventMouseMoved:
- case kEventMouseUp:
- case kEventMouseDown: {
- // If we are in popup mode, widget will point to the current popup no matter
- // where the mouse cursor is. In that case find out if the mouse cursor is
- // really over the popup in order to send correct enter / leave envents.
- QWidget * const enterLeaveWidget = (inPopupMode || ekind == kEventMouseUp) ?
- QApplication::widgetAt(where.h, where.v) : static_cast<QWidget*>(widget);
-
- if ((QWidget *) qt_last_mouse_receiver != enterLeaveWidget || inNonClientArea) {
-#ifdef DEBUG_MOUSE_MAPS
- qDebug("Entering: %p - %s (%s), Leaving %s (%s)", (QWidget*)enterLeaveWidget,
- enterLeaveWidget ? enterLeaveWidget->metaObject()->className() : "none",
- enterLeaveWidget ? enterLeaveWidget->objectName().toLocal8Bit().constData() : "",
- qt_last_mouse_receiver ? qt_last_mouse_receiver->metaObject()->className() : "none",
- qt_last_mouse_receiver ? qt_last_mouse_receiver->objectName().toLocal8Bit().constData() : "");
-#endif
-
- QWidget * const mouseGrabber = QWidget::mouseGrabber();
-
- if (inPopupMode) {
- QWidget *enter = enterLeaveWidget;
- QWidget *leave = qt_last_mouse_receiver;
- if (mouseGrabber) {
- QWidget * const popupWidget = qApp->activePopupWidget();
- if (leave == popupWidget)
- enter = mouseGrabber;
- if (enter == popupWidget)
- leave = mouseGrabber;
- if ((enter == mouseGrabber && leave == popupWidget)
- || (leave == mouseGrabber && enter == popupWidget)) {
- QApplicationPrivate::dispatchEnterLeave(enter, leave);
- qt_last_mouse_receiver = enter;
- }
- } else {
- QApplicationPrivate::dispatchEnterLeave(enter, leave);
- qt_last_mouse_receiver = enter;
- }
- } else if ((!qt_button_down || !qt_last_mouse_receiver) && !mouseGrabber && !leaveAfterRelease) {
- QApplicationPrivate::dispatchEnterLeave(enterLeaveWidget, qt_last_mouse_receiver);
- qt_last_mouse_receiver = enterLeaveWidget;
- }
- }
- break; }
- }
-
- if(widget) {
- QPoint p(where.h, where.v);
- QPoint plocal(widget->mapFromGlobal(p));
- if(etype == QEvent::MouseButtonPress) {
- qt_mac_dblclick.last_widget = widget;
- qt_mac_dblclick.last_modifiers = modifiers;
- qt_mac_dblclick.last_button = button;
- qt_mac_dblclick.last_time = GetEventTime(event);
- }
-
- if (wheel_deltaX || wheel_deltaY) {
-#ifndef QT_NO_WHEELEVENT
- if (wheel_deltaX) {
- QWheelEvent qwe(plocal, p, wheel_deltaX, buttons, modifiers, Qt::Horizontal);
- QApplication::sendSpontaneousEvent(widget, &qwe);
- if (!qwe.isAccepted() && QApplicationPrivate::focus_widget && QApplicationPrivate::focus_widget != widget) {
- QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(p), p,
- wheel_deltaX, buttons, modifiers, Qt::Horizontal);
- QApplication::sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2);
- if (!qwe2.isAccepted())
- handled_event = false;
- }
- }
- if (wheel_deltaY) {
- QWheelEvent qwe(plocal, p, wheel_deltaY, buttons, modifiers, Qt::Vertical);
- QApplication::sendSpontaneousEvent(widget, &qwe);
- if (!qwe.isAccepted() && QApplicationPrivate::focus_widget && QApplicationPrivate::focus_widget != widget) {
- QWheelEvent qwe2(QApplicationPrivate::focus_widget->mapFromGlobal(p), p,
- wheel_deltaY, buttons, modifiers, Qt::Vertical);
- QApplication::sendSpontaneousEvent(QApplicationPrivate::focus_widget, &qwe2);
- if (!qwe2.isAccepted())
- handled_event = false;
- }
- }
-#endif // QT_NO_WHEELEVENT
- } else {
-#ifdef QMAC_SPEAK_TO_ME
- const int speak_keys = Qt::AltModifier | Qt::ShiftModifier;
- if(etype == QMouseEvent::MouseButtonDblClick && ((modifiers & speak_keys) == speak_keys)) {
- QVariant v = widget->property("displayText");
- if(!v.isValid()) v = widget->property("text");
- if(!v.isValid()) v = widget->property("windowTitle");
- if(v.isValid()) {
- QString s = v.toString();
- s.replace(QRegExp(QString::fromLatin1("(\\&|\\<[^\\>]*\\>)")), QLatin1String(""));
- SpeechChannel ch;
- NewSpeechChannel(0, &ch);
- SpeakText(ch, s.toLatin1().constData(), s.length());
- DisposeSpeechChannel(ch);
- }
- }
-#endif
- Qt::MouseButton buttonToSend = button;
- static bool lastButtonTranslated = false;
- if(ekind == kEventMouseDown &&
- button == Qt::LeftButton && (modifiers & Qt::MetaModifier)) {
- buttonToSend = Qt::RightButton;
- lastButtonTranslated = true;
- } else if(ekind == kEventMouseUp && lastButtonTranslated) {
- buttonToSend = Qt::RightButton;
- lastButtonTranslated = false;
- }
- QMouseEvent qme(etype, plocal, p, buttonToSend, buttons, modifiers);
- QApplication::sendSpontaneousEvent(widget, &qme);
- if(!qme.isAccepted() || inNonClientArea)
- handled_event = false;
- }
-
- if (leaveAfterRelease) {
- QWidget *enter = QApplication::widgetAt(where.h, where.v);
- QApplicationPrivate::dispatchEnterLeave(enter, leaveAfterRelease);
- qt_last_mouse_receiver = enter;
- leaveAfterRelease = 0;
- }
-
- if(ekind == kEventMouseDown &&
- ((button == Qt::RightButton) ||
- (button == Qt::LeftButton && (modifiers & Qt::MetaModifier))))
- qt_event_request_context();
-
-#ifdef DEBUG_MOUSE_MAPS
- const char *event_desc = edesc;
- if(etype == QEvent::MouseButtonDblClick)
- event_desc = "Double Click";
- else if(etype == QEvent::NonClientAreaMouseButtonPress)
- event_desc = "NonClientMousePress";
- else if(etype == QEvent::NonClientAreaMouseButtonRelease)
- event_desc = "NonClientMouseRelease";
- else if(etype == QEvent::NonClientAreaMouseMove)
- event_desc = "NonClientMouseMove";
- else if(etype == QEvent::NonClientAreaMouseButtonDblClick)
- event_desc = "NonClientMouseDblClick";
- qDebug("%d %d (%d %d) - Would send (%s) event to %p %s %s (%d 0x%08x 0x%08x %d)", p.x(), p.y(),
- plocal.x(), plocal.y(), event_desc, (QWidget*)widget,
- widget ? widget->objectName().toLocal8Bit().constData() : "*Unknown*",
- widget ? widget->metaObject()->className() : "*Unknown*",
- button, (int)buttons, (int)modifiers, wheel_deltaX);
-#endif
- } else {
- handled_event = false;
- }
- break;
- }
- case kEventClassTextInput:
- case kEventClassKeyboard: {
- EventRef key_event = event;
- if(eclass == kEventClassTextInput) {
- Q_ASSERT(ekind == kEventTextInputUnicodeForKeyEvent);
- OSStatus err = GetEventParameter(event, kEventParamTextInputSendKeyboardEvent, typeEventRef, 0,
- sizeof(key_event), 0, &key_event);
- Q_ASSERT(err == noErr);
- Q_UNUSED(err);
- }
- const UInt32 key_ekind = GetEventKind(key_event);
- Q_ASSERT(GetEventClass(key_event) == kEventClassKeyboard);
-
- if(key_ekind == kEventRawKeyDown)
- qt_keymapper_private()->updateKeyMap(er, key_event, data);
- if(mac_keyboard_grabber)
- widget = mac_keyboard_grabber;
- else if (app->activePopupWidget())
- widget = (app->activePopupWidget()->focusWidget() ?
- app->activePopupWidget()->focusWidget() : app->activePopupWidget());
- else if(QApplication::focusWidget())
- widget = QApplication::focusWidget();
- else
- widget = app->activeWindow();
-
- if (widget) {
- if (widget->macEvent(er, event))
- return noErr;
- } else {
- // Darn, I need to update tho modifier state, even though
- // Qt itself isn't getting them, otherwise the keyboard state get inconsistent.
- if (key_ekind == kEventRawKeyModifiersChanged) {
- UInt32 modifiers = 0;
- GetEventParameter(key_event, kEventParamKeyModifiers, typeUInt32, 0,
- sizeof(modifiers), 0, &modifiers);
- extern void qt_mac_send_modifiers_changed(quint32 modifiers, QObject *object); // qkeymapper_mac.cpp
- // Just send it to the qApp for the time being.
- qt_mac_send_modifiers_changed(modifiers, qApp);
- }
- handled_event = false;
- break;
- }
-
- if(app_do_modal && !qt_try_modal(widget, key_event))
- break;
- if (eclass == kEventClassTextInput) {
- handled_event = false;
- } else {
- handled_event = qt_keymapper_private()->translateKeyEvent(widget, er, key_event, data,
- widget == mac_keyboard_grabber);
- }
- break; }
- case kEventClassWindow: {
- WindowRef wid = 0;
- GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 0,
- sizeof(WindowRef), 0, &wid);
- widget = qt_mac_find_window(wid);
- if (widget && widget->macEvent(er, event))
- return noErr;
- if(ekind == kEventWindowActivated) {
- if(QApplicationPrivate::app_style) {
- QEvent ev(QEvent::Style);
- QApplication::sendSpontaneousEvent(QApplicationPrivate::app_style, &ev);
- }
-
- if(widget && app_do_modal && !qt_try_modal(widget, event))
- break;
-
- if(widget && widget->window()->isVisible()) {
- QWidget *tlw = widget->window();
- if(tlw->isWindow() && !(tlw->windowType() == Qt::Popup)
- && !qt_mac_is_macdrawer(tlw)
- && (!tlw->parentWidget() || tlw->isModal()
- || !(tlw->windowType() == Qt::Tool))) {
- bool just_send_event = false;
- {
- WindowActivationScope scope;
- if(GetWindowActivationScope((WindowRef)wid, &scope) == noErr &&
- scope == kWindowActivationScopeIndependent) {
- if(GetFrontWindowOfClass(kAllWindowClasses, true) != wid)
- just_send_event = true;
- }
- }
- if(just_send_event) {
- QEvent e(QEvent::WindowActivate);
- QApplication::sendSpontaneousEvent(widget, &e);
- } else {
- app->setActiveWindow(tlw);
- }
- }
- QMenuBar::macUpdateMenuBar();
- }
- } else if(ekind == kEventWindowDeactivated) {
- if(widget && QApplicationPrivate::active_window == widget)
- app->setActiveWindow(0);
- } else {
- handled_event = false;
- }
- break; }
- case kEventClassApplication:
- if(ekind == kEventAppActivated) {
- if(QApplication::desktopSettingsAware())
- qt_mac_update_os_settings();
- if(qt_clipboard) { //manufacture an event so the clipboard can see if it has changed
- QEvent ev(QEvent::Clipboard);
- QApplication::sendSpontaneousEvent(qt_clipboard, &ev);
- }
- if(app) {
- QEvent ev(QEvent::ApplicationActivate);
- QApplication::sendSpontaneousEvent(app, &ev);
- }
- if(!app->activeWindow()) {
- WindowPtr wp = ActiveNonFloatingWindow();
- if(QWidget *tmp_w = qt_mac_find_window(wp))
- app->setActiveWindow(tmp_w);
- }
- QMenuBar::macUpdateMenuBar();
- } else if(ekind == kEventAppDeactivated) {
- //qt_mac_no_click_through_mode = false;
- while(app->d_func()->inPopupMode())
- app->activePopupWidget()->close();
- if(app) {
- QEvent ev(QEvent::ApplicationDeactivate);
- QApplication::sendSpontaneousEvent(app, &ev);
- }
- app->setActiveWindow(0);
- } else if(ekind == kEventAppAvailableWindowBoundsChanged) {
- QDesktopWidgetImplementation::instance()->onResize();
- } else {
- handled_event = false;
- }
- break;
- case kAppearanceEventClass:
- if(ekind == kAEAppearanceChanged) {
- if(QApplication::desktopSettingsAware())
- qt_mac_update_os_settings();
- if(QApplicationPrivate::app_style) {
- QEvent ev(QEvent::Style);
- QApplication::sendSpontaneousEvent(QApplicationPrivate::app_style, &ev);
- }
- } else {
- handled_event = false;
- }
- break;
- case kEventClassAppleEvent:
- if(ekind == kEventAppleEvent) {
- EventRecord erec;
- if(!ConvertEventRefToEventRecord(event, &erec))
- qDebug("Qt: internal: WH0A, unexpected condition reached. %s:%d", __FILE__, __LINE__);
- else if(AEProcessAppleEvent(&erec) != noErr)
- handled_event = false;
- } else {
- handled_event = false;
- }
- break;
- case kEventClassCommand:
- if(ekind == kEventCommandProcess) {
- HICommand cmd;
- GetEventParameter(event, kEventParamDirectObject, typeHICommand,
- 0, sizeof(cmd), 0, &cmd);
- handled_event = false;
- if(!cmd.menu.menuRef && GetApplicationDockTileMenu()) {
- EventRef copy = CopyEvent(event);
- HICommand copy_cmd;
- GetEventParameter(event, kEventParamDirectObject, typeHICommand,
- 0, sizeof(copy_cmd), 0, &copy_cmd);
- copy_cmd.menu.menuRef = GetApplicationDockTileMenu();
- SetEventParameter(copy, kEventParamDirectObject, typeHICommand, sizeof(copy_cmd), &copy_cmd);
- if(SendEventToMenu(copy, copy_cmd.menu.menuRef) == noErr)
- handled_event = true;
- }
- if(!handled_event) {
- if(cmd.commandID == kHICommandQuit) {
- // Quitting the application is not Qt's responsibility if
- // used in a plugin or just embedded into a native application.
- // In that case, let the event pass down to the native apps event handler.
- if (!QApplication::testAttribute(Qt::AA_MacPluginApplication)) {
- handled_event = true;
- HiliteMenu(0);
- bool handle_quit = true;
- if(QApplicationPrivate::modalState()) {
- int visible = 0;
- const QWidgetList tlws = QApplication::topLevelWidgets();
- for(int i = 0; i < tlws.size(); ++i) {
- if(tlws.at(i)->isVisible())
- ++visible;
- }
- handle_quit = (visible <= 1);
- }
- if(handle_quit) {
- QCloseEvent ev;
- QApplication::sendSpontaneousEvent(app, &ev);
- if(ev.isAccepted())
- app->quit();
- } else {
- QApplication::beep();
- }
- }
- } else if(cmd.commandID == kHICommandSelectWindow) {
- if((GetCurrentKeyModifiers() & cmdKey))
- handled_event = true;
- } else if(cmd.commandID == kHICommandAbout) {
- QMessageBox::aboutQt(0);
- HiliteMenu(0);
- handled_event = true;
- }
- }
- }
- break;
- }
-
-#ifdef DEBUG_EVENTS
- qDebug("%shandled event %c%c%c%c %d", handled_event ? "(*) " : "",
- char(eclass >> 24), char((eclass >> 16) & 255), char((eclass >> 8) & 255),
- char(eclass & 255), (int)ekind);
-#endif
- if(!handled_event) //let the event go through
- return eventNotHandledErr;
- return noErr; //we eat the event
-#else
- Q_UNUSED(er);
- Q_UNUSED(event);
- Q_UNUSED(data);
- return eventNotHandledErr;
-#endif
-}
-
-#ifdef QT_MAC_USE_COCOA
-void QApplicationPrivate::qt_initAfterNSAppStarted()
-{
- setupAppleEvents();
- qt_mac_update_cursor();
-}
-
-void QApplicationPrivate::setupAppleEvents()
-{
- // This function is called from the event dispatcher when NSApplication has
- // finished initialization, which appears to be just after [NSApplication run] has
- // started to execute. By setting up our apple events handlers this late, we override
- // the ones set up by NSApplication.
-
- // If Qt is used as a plugin, we let the 3rd party application handle events
- // like quit and open file events. Otherwise, if we install our own handlers, we
- // easily end up breaking functionallity the 3rd party application depend on:
- if (QApplication::testAttribute(Qt::AA_MacPluginApplication))
- return;
-
- QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) *newDelegate = [QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate];
- NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager];
- [eventManager setEventHandler:newDelegate andSelector:@selector(appleEventQuit:withReplyEvent:)
- forEventClass:kCoreEventClass andEventID:kAEQuitApplication];
- [eventManager setEventHandler:newDelegate andSelector:@selector(getUrl:withReplyEvent:)
- forEventClass:kInternetEventClass andEventID:kAEGetURL];
-}
-#endif
-
-// In Carbon this is your one stop for apple events.
-// In Cocoa, it ISN'T. This is the catch-all Apple Event handler that exists
-// for the time between instantiating the NSApplication, but before the
-// NSApplication has installed it's OWN Apple Event handler. When Cocoa has
-// that set up, we remove this. So, if you are debugging problems, you likely
-// want to check out QCocoaApplicationDelegate instead.
-OSStatus QApplicationPrivate::globalAppleEventProcessor(const AppleEvent *ae, AppleEvent *, long handlerRefcon)
-{
- QApplication *app = (QApplication *)handlerRefcon;
- bool handled_event=false;
- OSType aeID=typeWildCard, aeClass=typeWildCard;
- AEGetAttributePtr(ae, keyEventClassAttr, typeType, 0, &aeClass, sizeof(aeClass), 0);
- AEGetAttributePtr(ae, keyEventIDAttr, typeType, 0, &aeID, sizeof(aeID), 0);
- if(aeClass == kCoreEventClass) {
- switch(aeID) {
- case kAEQuitApplication: {
- extern bool qt_mac_quit_menu_item_enabled; // qmenu_mac.cpp
- if (qt_mac_quit_menu_item_enabled) {
- QCloseEvent ev;
- QApplication::sendSpontaneousEvent(app, &ev);
- if(ev.isAccepted()) {
- handled_event = true;
- app->quit();
- }
- } else {
- QApplication::beep(); // Sorry, you can't quit right now.
- }
- break; }
- case kAEOpenDocuments: {
- AEDescList docs;
- if(AEGetParamDesc(ae, keyDirectObject, typeAEList, &docs) == noErr) {
- long cnt = 0;
- AECountItems(&docs, &cnt);
- UInt8 *str_buffer = NULL;
- for(int i = 0; i < cnt; i++) {
- FSRef ref;
- if(AEGetNthPtr(&docs, i+1, typeFSRef, 0, 0, &ref, sizeof(ref), 0) != noErr)
- continue;
- if(!str_buffer)
- str_buffer = (UInt8 *)malloc(1024);
- FSRefMakePath(&ref, str_buffer, 1024);
- QFileOpenEvent ev(QString::fromUtf8((const char *)str_buffer));
- QApplication::sendSpontaneousEvent(app, &ev);
- }
- if(str_buffer)
- free(str_buffer);
- }
- break; }
- default:
- break;
- }
- } else if (aeClass == kInternetEventClass) {
- switch (aeID) {
- case kAEGetURL: {
- char urlData[1024];
- Size actualSize;
- if (AEGetParamPtr(ae, keyDirectObject, typeChar, 0, urlData,
- sizeof(urlData) - 1, &actualSize) == noErr) {
- urlData[actualSize] = 0;
- QFileOpenEvent ev(QUrl(QString::fromUtf8(urlData)));
- QApplication::sendSpontaneousEvent(app, &ev);
- }
- break;
- }
- default:
- break;
- }
- }
-#ifdef DEBUG_EVENTS
- qDebug("Qt: internal: %shandled Apple event! %c%c%c%c %c%c%c%c", handled_event ? "(*)" : "",
- char(aeID >> 24), char((aeID >> 16) & 255), char((aeID >> 8) & 255),char(aeID & 255),
- char(aeClass >> 24), char((aeClass >> 16) & 255), char((aeClass >> 8) & 255),char(aeClass & 255));
-#else
- if(!handled_event) //let the event go through
- return eventNotHandledErr;
- return noErr; //we eat the event
-#endif
-}
-
-/*!
- \fn bool QApplication::macEventFilter(EventHandlerCallRef caller, EventRef event)
-
- \warning This virtual function is only used under Mac OS X, and behaves different
- depending on if Qt is based on Carbon or Cocoa.
-
- For the Carbon port, If you create an application that inherits QApplication and reimplement
- this function, you get direct access to all Carbon Events that Qt registers
- for from Mac OS X with this function being called with the \a caller and
- the \a event.
-
- For the Cocoa port, If you create an application that inherits QApplication and reimplement
- this function, you get direct access to all Cocoa Events that Qt receives
- from Mac OS X with this function being called with the \a caller being 0 and
- the \a event being an NSEvent pointer:
-
- NSEvent *e = reinterpret_cast<NSEvent *>(event);
-
- Return true if you want to stop the event from being processed.
- Return false for normal event dispatching. The default
- implementation returns false.
-
- \sa macEventFilter(void *nsevent)
-*/
-bool QApplication::macEventFilter(EventHandlerCallRef, EventRef)
-{
- return false;
-}
-
-/*!
- \internal
-*/
-void QApplicationPrivate::openPopup(QWidget *popup)
-{
- if (!QApplicationPrivate::popupWidgets) // create list
- QApplicationPrivate::popupWidgets = new QWidgetList;
- QApplicationPrivate::popupWidgets->append(popup); // add to end of list
-
- // popups are not focus-handled by the window system (the first
- // popup grabbed the keyboard), so we have to do that manually: A
- // new popup gets the focus
- if (popup->focusWidget()) {
- popup->focusWidget()->setFocus(Qt::PopupFocusReason);
- } else if (QApplicationPrivate::popupWidgets->count() == 1) { // this was the first popup
- popup->setFocus(Qt::PopupFocusReason);
- }
-}
-
-/*!
- \internal
-*/
-void QApplicationPrivate::closePopup(QWidget *popup)
-{
- Q_Q(QApplication);
- if (!QApplicationPrivate::popupWidgets)
- return;
-
- QApplicationPrivate::popupWidgets->removeAll(popup);
- if (popup == qt_button_down)
- qt_button_down = 0;
- if (QApplicationPrivate::popupWidgets->isEmpty()) { // this was the last popup
- delete QApplicationPrivate::popupWidgets;
- QApplicationPrivate::popupWidgets = 0;
-
- // Special case for Tool windows: since they are activated and deactived together
- // with a normal window they never become the QApplicationPrivate::active_window.
- QWidget *appFocusWidget = QApplication::focusWidget();
- if (appFocusWidget && appFocusWidget->window()->windowType() == Qt::Tool) {
- appFocusWidget->setFocus(Qt::PopupFocusReason);
- } else if (QApplicationPrivate::active_window) {
- if (QWidget *fw = QApplicationPrivate::active_window->focusWidget()) {
- if (fw != QApplication::focusWidget()) {
- fw->setFocus(Qt::PopupFocusReason);
- } else {
- QFocusEvent e(QEvent::FocusIn, Qt::PopupFocusReason);
- q->sendEvent(fw, &e);
- }
- }
- }
- } else {
- // popups are not focus-handled by the window system (the
- // first popup grabbed the keyboard), so we have to do that
- // manually: A popup was closed, so the previous popup gets
- // the focus.
- QWidget* aw = QApplicationPrivate::popupWidgets->last();
- if (QWidget *fw = aw->focusWidget())
- fw->setFocus(Qt::PopupFocusReason);
- }
-}
-
-void QApplication::beep()
-{
- qt_mac_beep();
-}
-
-void QApplication::alert(QWidget *widget, int duration)
-{
- if (!QApplicationPrivate::checkInstance("alert"))
- return;
-
- QWidgetList windowsToMark;
- if (!widget)
- windowsToMark += topLevelWidgets();
- else
- windowsToMark.append(widget->window());
-
- bool needNotification = false;
- for (int i = 0; i < windowsToMark.size(); ++i) {
- QWidget *window = windowsToMark.at(i);
- if (!window->isActiveWindow() && window->isVisible()) {
- needNotification = true; // yeah, we may set it multiple times, but that's OK.
- if (duration != 0) {
- QTimer *timer = new QTimer(qApp);
- timer->setSingleShot(true);
- connect(timer, SIGNAL(timeout()), qApp, SLOT(_q_alertTimeOut()));
- if (QTimer *oldTimer = qApp->d_func()->alertTimerHash.value(widget)) {
- qApp->d_func()->alertTimerHash.remove(widget);
- delete oldTimer;
- }
- qApp->d_func()->alertTimerHash.insert(widget, timer);
- timer->start(duration);
- }
- }
- }
- if (needNotification)
- qt_mac_send_notification();
-}
-
-void QApplicationPrivate::_q_alertTimeOut()
-{
- if (QTimer *timer = qobject_cast<QTimer *>(q_func()->sender())) {
- QHash<QWidget *, QTimer *>::iterator it = alertTimerHash.begin();
- while (it != alertTimerHash.end()) {
- if (it.value() == timer) {
- alertTimerHash.erase(it);
- timer->deleteLater();
- break;
- }
- ++it;
- }
- if (alertTimerHash.isEmpty()) {
- qt_mac_cancel_notification();
- }
- }
-}
-
-void QApplication::setCursorFlashTime(int msecs)
-{
- QApplicationPrivate::cursor_flash_time = msecs;
-}
-
-int QApplication::cursorFlashTime()
-{
- return QApplicationPrivate::cursor_flash_time;
-}
-
-void QApplication::setDoubleClickInterval(int ms)
-{
- qt_mac_dblclick.use_qt_time_limit = true;
- QApplicationPrivate::mouse_double_click_time = ms;
-}
-
-int QApplication::doubleClickInterval()
-{
- if (!qt_mac_dblclick.use_qt_time_limit) { //get it from the system
- QSettings appleSettings(QLatin1String("apple.com"));
- /* First worked as of 10.3.3 */
- double dci = appleSettings.value(QLatin1String("com/apple/mouse/doubleClickThreshold"), 0.5).toDouble();
- return int(dci * 1000);
- }
- return QApplicationPrivate::mouse_double_click_time;
-}
-
-void QApplication::setKeyboardInputInterval(int ms)
-{
- QApplicationPrivate::keyboard_input_time = ms;
-}
-
-int QApplication::keyboardInputInterval()
-{
- // FIXME: get from the system
- return QApplicationPrivate::keyboard_input_time;
-}
-
-#ifndef QT_NO_WHEELEVENT
-void QApplication::setWheelScrollLines(int n)
-{
- QApplicationPrivate::wheel_scroll_lines = n;
-}
-
-int QApplication::wheelScrollLines()
-{
- return QApplicationPrivate::wheel_scroll_lines;
-}
-#endif
-
-void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable)
-{
- switch (effect) {
- case Qt::UI_FadeMenu:
- QApplicationPrivate::fade_menu = enable;
- break;
- case Qt::UI_AnimateMenu:
- QApplicationPrivate::animate_menu = enable;
- break;
- case Qt::UI_FadeTooltip:
- QApplicationPrivate::fade_tooltip = enable;
- break;
- case Qt::UI_AnimateTooltip:
- QApplicationPrivate::animate_tooltip = enable;
- break;
- case Qt::UI_AnimateCombo:
- QApplicationPrivate::animate_combo = enable;
- break;
- case Qt::UI_AnimateToolBox:
- QApplicationPrivate::animate_toolbox = enable;
- break;
- case Qt::UI_General:
- QApplicationPrivate::fade_tooltip = true;
- break;
- default:
- QApplicationPrivate::animate_ui = enable;
- break;
- }
-
- if (enable)
- QApplicationPrivate::animate_ui = true;
-}
-
-bool QApplication::isEffectEnabled(Qt::UIEffect effect)
-{
- if (QColormap::instance().depth() < 16 || !QApplicationPrivate::animate_ui)
- return false;
-
- switch(effect) {
- case Qt::UI_AnimateMenu:
- return QApplicationPrivate::animate_menu;
- case Qt::UI_FadeMenu:
- return QApplicationPrivate::fade_menu;
- case Qt::UI_AnimateCombo:
- return QApplicationPrivate::animate_combo;
- case Qt::UI_AnimateTooltip:
- return QApplicationPrivate::animate_tooltip;
- case Qt::UI_FadeTooltip:
- return QApplicationPrivate::fade_tooltip;
- case Qt::UI_AnimateToolBox:
- return QApplicationPrivate::animate_toolbox;
- default:
- break;
- }
- return QApplicationPrivate::animate_ui;
-}
-
-/*!
- \internal
-*/
-bool QApplicationPrivate::qt_mac_apply_settings()
-{
- QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
- settings.beginGroup(QLatin1String("Qt"));
-
- /*
- Qt settings. This is how they are written into the datastream.
- Palette/ * - QPalette
- font - QFont
- libraryPath - QStringList
- style - QString
- doubleClickInterval - int
- cursorFlashTime - int
- wheelScrollLines - int
- colorSpec - QString
- defaultCodec - QString
- globalStrut/width - int
- globalStrut/height - int
- GUIEffects - QStringList
- Font Substitutions/ * - QStringList
- Font Substitutions/... - QStringList
- */
-
- // read library (ie. plugin) path list
- QString libpathkey =
- QString::fromLatin1("%1.%2/libraryPath")
- .arg(QT_VERSION >> 16)
- .arg((QT_VERSION & 0xff00) >> 8);
- QStringList pathlist = settings.value(libpathkey).toString().split(QLatin1Char(':'));
- if (!pathlist.isEmpty()) {
- QStringList::ConstIterator it = pathlist.begin();
- while(it != pathlist.end())
- QApplication::addLibraryPath(*it++);
- }
-
- QString defaultcodec = settings.value(QLatin1String("defaultCodec"), QVariant(QLatin1String("none"))).toString();
- if (defaultcodec != QLatin1String("none")) {
- QTextCodec *codec = QTextCodec::codecForName(defaultcodec.toLatin1().constData());
- if (codec)
- QTextCodec::setCodecForTr(codec);
- }
-
- if (qt_is_gui_used) {
- QString str;
- QStringList strlist;
- int num;
-
- // read new palette
- int i;
- QPalette pal(QApplication::palette());
- strlist = settings.value(QLatin1String("Palette/active")).toStringList();
- if (strlist.count() == QPalette::NColorRoles) {
- for (i = 0; i < QPalette::NColorRoles; i++)
- pal.setColor(QPalette::Active, (QPalette::ColorRole) i,
- QColor(strlist[i]));
- }
- strlist = settings.value(QLatin1String("Palette/inactive")).toStringList();
- if (strlist.count() == QPalette::NColorRoles) {
- for (i = 0; i < QPalette::NColorRoles; i++)
- pal.setColor(QPalette::Inactive, (QPalette::ColorRole) i,
- QColor(strlist[i]));
- }
- strlist = settings.value(QLatin1String("Palette/disabled")).toStringList();
- if (strlist.count() == QPalette::NColorRoles) {
- for (i = 0; i < QPalette::NColorRoles; i++)
- pal.setColor(QPalette::Disabled, (QPalette::ColorRole) i,
- QColor(strlist[i]));
- }
-
- if (pal != QApplication::palette())
- QApplication::setPalette(pal);
-
- // read new font
- QFont font(QApplication::font());
- str = settings.value(QLatin1String("font")).toString();
- if (!str.isEmpty()) {
- font.fromString(str);
- if (font != QApplication::font())
- QApplication::setFont(font);
- }
-
- // read new QStyle
- QString stylename = settings.value(QLatin1String("style")).toString();
- if (! stylename.isNull() && ! stylename.isEmpty()) {
- QStyle *style = QStyleFactory::create(stylename);
- if (style)
- QApplication::setStyle(style);
- else
- stylename = QLatin1String("default");
- } else {
- stylename = QLatin1String("default");
- }
-
- num = settings.value(QLatin1String("doubleClickInterval"),
- QApplication::doubleClickInterval()).toInt();
- QApplication::setDoubleClickInterval(num);
-
- num = settings.value(QLatin1String("cursorFlashTime"),
- QApplication::cursorFlashTime()).toInt();
- QApplication::setCursorFlashTime(num);
-
-#ifndef QT_NO_WHEELEVENT
- num = settings.value(QLatin1String("wheelScrollLines"),
- QApplication::wheelScrollLines()).toInt();
- QApplication::setWheelScrollLines(num);
-#endif
-
- QString colorspec = settings.value(QLatin1String("colorSpec"),
- QVariant(QLatin1String("default"))).toString();
- if (colorspec == QLatin1String("normal"))
- QApplication::setColorSpec(QApplication::NormalColor);
- else if (colorspec == QLatin1String("custom"))
- QApplication::setColorSpec(QApplication::CustomColor);
- else if (colorspec == QLatin1String("many"))
- QApplication::setColorSpec(QApplication::ManyColor);
- else if (colorspec != QLatin1String("default"))
- colorspec = QLatin1String("default");
-
- int w = settings.value(QLatin1String("globalStrut/width")).toInt();
- int h = settings.value(QLatin1String("globalStrut/height")).toInt();
- QSize strut(w, h);
- if (strut.isValid())
- QApplication::setGlobalStrut(strut);
-
- QStringList effects = settings.value(QLatin1String("GUIEffects")).toStringList();
- if (!effects.isEmpty()) {
- if (effects.contains(QLatin1String("none")))
- QApplication::setEffectEnabled(Qt::UI_General, false);
- if (effects.contains(QLatin1String("general")))
- QApplication::setEffectEnabled(Qt::UI_General, true);
- if (effects.contains(QLatin1String("animatemenu")))
- QApplication::setEffectEnabled(Qt::UI_AnimateMenu, true);
- if (effects.contains(QLatin1String("fademenu")))
- QApplication::setEffectEnabled(Qt::UI_FadeMenu, true);
- if (effects.contains(QLatin1String("animatecombo")))
- QApplication::setEffectEnabled(Qt::UI_AnimateCombo, true);
- if (effects.contains(QLatin1String("animatetooltip")))
- QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, true);
- if (effects.contains(QLatin1String("fadetooltip")))
- QApplication::setEffectEnabled(Qt::UI_FadeTooltip, true);
- if (effects.contains(QLatin1String("animatetoolbox")))
- QApplication::setEffectEnabled(Qt::UI_AnimateToolBox, true);
- } else {
- QApplication::setEffectEnabled(Qt::UI_General, true);
- }
-
- settings.beginGroup(QLatin1String("Font Substitutions"));
- QStringList fontsubs = settings.childKeys();
- if (!fontsubs.isEmpty()) {
- QStringList::Iterator it = fontsubs.begin();
- for (; it != fontsubs.end(); ++it) {
- QString fam = QString::fromLatin1((*it).toLatin1().constData());
- QStringList subs = settings.value(fam).toStringList();
- QFont::insertSubstitutions(fam, subs);
- }
- }
- settings.endGroup();
- }
-
- settings.endGroup();
- return true;
-}
-
-// DRSWAT
-
-bool QApplicationPrivate::canQuit()
-{
-#ifndef QT_MAC_USE_COCOA
- return true;
-#else
- Q_Q(QApplication);
-#ifdef QT_MAC_USE_COCOA
- [[NSApp mainMenu] cancelTracking];
-#else
- HiliteMenu(0);
-#endif
-
- bool handle_quit = true;
- if (QApplicationPrivate::modalState() && [[[[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate]
- menuLoader] quitMenuItem] isEnabled]) {
- int visible = 0;
- const QWidgetList tlws = QApplication::topLevelWidgets();
- for(int i = 0; i < tlws.size(); ++i) {
- if (tlws.at(i)->isVisible())
- ++visible;
- }
- handle_quit = (visible <= 1);
- }
- if (handle_quit) {
- QCloseEvent ev;
- QApplication::sendSpontaneousEvent(q, &ev);
- if (ev.isAccepted()) {
- return true;
- }
- }
- return false;
-#endif
-}
-
-void onApplicationWindowChangedActivation(QWidget *widget, bool activated)
-{
-#if QT_MAC_USE_COCOA
- if (!widget)
- return;
-
- if (activated) {
- if (QApplicationPrivate::app_style) {
- QEvent ev(QEvent::Style);
- qt_sendSpontaneousEvent(QApplicationPrivate::app_style, &ev);
- }
- qApp->setActiveWindow(widget);
- } else { // deactivated
- if (QApplicationPrivate::active_window == widget)
- qApp->setActiveWindow(0);
- }
-
- QMenuBar::macUpdateMenuBar();
- qt_mac_update_cursor();
-#else
- Q_UNUSED(widget);
- Q_UNUSED(activated);
-#endif
-}
-
-
-void onApplicationChangedActivation( bool activated )
-{
-#if QT_MAC_USE_COCOA
- QApplication *app = qApp;
-
-//NSLog(@"App Changed Activation\n");
-
- if ( activated ) {
- if (QApplication::desktopSettingsAware())
- qt_mac_update_os_settings();
-
- if (qt_clipboard) { //manufacture an event so the clipboard can see if it has changed
- QEvent ev(QEvent::Clipboard);
- qt_sendSpontaneousEvent(qt_clipboard, &ev);
- }
-
- if (app) {
- QEvent ev(QEvent::ApplicationActivate);
- qt_sendSpontaneousEvent(app, &ev);
- }
-
- if (!app->activeWindow()) {
- OSWindowRef wp = [NSApp keyWindow];
- if (QWidget *tmp_w = qt_mac_find_window(wp))
- app->setActiveWindow(tmp_w);
- }
- QMenuBar::macUpdateMenuBar();
- qt_mac_update_cursor();
- } else { // de-activated
- QApplicationPrivate *priv = [[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate] qAppPrivate];
- while (priv->inPopupMode())
- app->activePopupWidget()->close();
- if (app) {
- QEvent ev(QEvent::ApplicationDeactivate);
- qt_sendSpontaneousEvent(app, &ev);
- }
- app->setActiveWindow(0);
- }
-#else
- Q_UNUSED(activated);
-#endif
-}
-
-void QApplicationPrivate::initializeMultitouch_sys()
-{ }
-void QApplicationPrivate::cleanupMultitouch_sys()
-{ }
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp
deleted file mode 100644
index 408c3b5883..0000000000
--- a/src/gui/kernel/qapplication_s60.cpp
+++ /dev/null
@@ -1,2712 +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_p.h"
-#include "qsessionmanager.h"
-#include "qevent.h"
-#include "qsymbianevent.h"
-#include "qeventdispatcher_s60_p.h"
-#include "qwidget.h"
-#include "qdesktopwidget.h"
-#include "private/qbackingstore_p.h"
-#include "qt_s60_p.h"
-#include "private/qevent_p.h"
-#include "qstring.h"
-#include "qdebug.h"
-#include "qimage.h"
-#include "qcombobox.h"
-#include "private/qkeymapper_p.h"
-#include "private/qfont_p.h"
-#ifndef QT_NO_STYLE_S60
-#include "private/qs60style_p.h"
-#endif
-#include "private/qwindowsurface_s60_p.h"
-#include "qpaintengine.h"
-#include "private/qmenubar_p.h"
-#include "private/qsoftkeymanager_p.h"
-#ifdef QT_GRAPHICSSYSTEM_RUNTIME
-#include "private/qgraphicssystem_runtime_p.h"
-#endif
-
-#include "apgwgnam.h" // For CApaWindowGroupName
-#include <mdaaudiotoneplayer.h> // For CMdaAudioToneUtility
-
-#if defined(Q_OS_SYMBIAN)
-# include <private/qs60mainapplication_p.h>
-# include <centralrepository.h>
-# include "qs60mainappui.h"
-# include "qinputcontext.h"
-#endif
-
-#if defined(Q_WS_S60)
-# if !defined(QT_NO_IM)
-# include <private/qcoefepinputcontext_p.h>
-# endif
-#endif
-
-#include "private/qstylesheetstyle_p.h"
-
-#include <hal.h>
-#include <hal_data.h>
-
-#ifdef Q_SYMBIAN_TRANSITION_EFFECTS
-#include <graphics/wstfxconst.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-// Goom Events through Window Server
-static const int KGoomMemoryLowEvent = 0x10282DBF;
-static const int KGoomMemoryGoodEvent = 0x20026790;
-// Split view open/close events from AVKON
-static const int KSplitViewOpenEvent = 0x2001E2C0;
-static const int KSplitViewCloseEvent = 0x2001E2C1;
-
-#if defined(QT_DEBUG)
-static bool appNoGrab = false; // Grabbing enabled
-#endif
-static bool app_do_modal = false; // modal mode
-Q_GLOBAL_STATIC(QS60Data, qt_s60Data);
-
-extern bool qt_sendSpontaneousEvent(QObject*,QEvent*);
-extern QWidgetList *qt_modal_stack; // stack of modal widgets
-extern QDesktopWidget *qt_desktopWidget; // qapplication.cpp
-
-QWidget *qt_button_down = 0; // widget got last button-down
-
-QSymbianControl *QSymbianControl::lastFocusedControl = 0;
-
-QS60Data* qGlobalS60Data()
-{
- return qt_s60Data();
-}
-
-#ifdef Q_WS_S60
-void QS60Data::setStatusPaneAndButtonGroupVisibility(bool statusPaneVisible, bool buttonGroupVisible)
-{
- bool buttonGroupVisibilityChanged = false;
- if (CEikButtonGroupContainer *const b = buttonGroupContainer()) {
- buttonGroupVisibilityChanged = (b->IsVisible() != buttonGroupVisible);
- b->MakeVisible(buttonGroupVisible);
- }
- bool statusPaneVisibilityChanged = false;
- if (CEikStatusPane *const s = statusPane()) {
- statusPaneVisibilityChanged = (s->IsVisible() != statusPaneVisible);
- s->MakeVisible(statusPaneVisible);
- }
- if (buttonGroupVisibilityChanged || statusPaneVisibilityChanged) {
- const QSize size = qt_TRect2QRect(static_cast<CEikAppUi*>(S60->appUi())->ClientRect()).size();
- const QSize oldSize; // note that QDesktopWidget::resizeEvent ignores the QResizeEvent contents
- QResizeEvent event(size, oldSize);
- QApplication::instance()->sendEvent(QApplication::desktop(), &event);
- }
- if (buttonGroupVisibilityChanged && !statusPaneVisibilityChanged && QApplication::activeWindow())
- // Ensure that control rectangle is updated
- static_cast<QSymbianControl *>(QApplication::activeWindow()->winId())->handleClientAreaChange();
-}
-
-bool QS60Data::setRecursiveDecorationsVisibility(QWidget *window, Qt::WindowStates newState)
-{
- // Show statusbar:
- // Topmost parent: Show unless fullscreen/minimized.
- // Child windows: Follow topmost parent, unless fullscreen, in which case do not show statusbar
- // Show CBA:
- // Topmost parent: Show unless fullscreen/minimized.
- // Exception: Show if fullscreen with Qt::WindowSoftkeysVisibleHint.
- // Child windows:
- // Minimized: Unclear if there is an use case for having focused minimized window at all.
- // Always follow topmost parent just to be safe.
- // Maximized and normal: follow topmost parent.
- // Exception: If topmost parent is not showing CBA, show CBA if any softkey actions are
- // defined.
- // Fullscreen: Show only if Qt::WindowSoftkeysVisibleHint set.
-
- Qt::WindowStates comparisonState = newState;
- QWidget *parentWindow = window->parentWidget();
- if (parentWindow) {
- while (parentWindow->parentWidget())
- parentWindow = parentWindow->parentWidget();
- comparisonState = parentWindow->windowState();
- } else {
- parentWindow = window;
- }
-
- bool decorationsVisible = !(comparisonState & (Qt::WindowFullScreen | Qt::WindowMinimized));
- const bool parentIsFullscreen = comparisonState & Qt::WindowFullScreen;
- const bool parentCbaVisibilityHint = parentWindow->windowFlags() & Qt::WindowSoftkeysVisibleHint;
- bool buttonGroupVisibility = (decorationsVisible || (parentIsFullscreen && parentCbaVisibilityHint));
-
- // Do extra checking for child windows
- if (window->parentWidget()) {
- if (newState & Qt::WindowFullScreen) {
- decorationsVisible = false;
- if (window->windowFlags() & Qt::WindowSoftkeysVisibleHint)
- buttonGroupVisibility = true;
- else
- buttonGroupVisibility = false;
- } else if (!(newState & Qt::WindowMinimized) && !buttonGroupVisibility) {
- for (int i = 0; i < window->actions().size(); ++i) {
- if (window->actions().at(i)->softKeyRole() != QAction::NoSoftKey) {
- buttonGroupVisibility = true;
- break;
- }
- }
- }
- }
-
- S60->setStatusPaneAndButtonGroupVisibility(decorationsVisible, buttonGroupVisibility);
-
- return decorationsVisible;
-}
-#endif
-
-void QS60Data::controlVisibilityChanged(CCoeControl *control, bool visible)
-{
- if (QWidgetPrivate::mapper && QWidgetPrivate::mapper->contains(control)) {
- QWidget *const widget = QWidgetPrivate::mapper->value(control);
- QWidget *const window = widget->window();
- if (QTLWExtra *topData = qt_widget_private(window)->maybeTopData()) {
- QWidgetBackingStoreTracker &backingStore = topData->backingStore;
- if (visible) {
- if (backingStore.data()) {
- backingStore.registerWidget(widget);
- } else {
- backingStore.create(window);
- backingStore.registerWidget(widget);
- qt_widget_private(widget)->invalidateBuffer(widget->rect());
- widget->repaint();
- }
- } else {
- // In certain special scenarios we may get an ENotVisible event
- // without a previous EPartiallyVisible. The backingstore must
- // still be destroyed, hence the registerWidget() call below.
- if (backingStore.data() && widget->internalWinId()
- && qt_widget_private(widget)->maybeBackingStore() == backingStore.data())
- backingStore.registerWidget(widget);
- backingStore.unregisterWidget(widget);
- // In order to ensure that any resources used by the window surface
- // are immediately freed, we flush the WSERV command buffer.
- S60->wsSession().Flush();
- }
- }
- }
-}
-
-bool qt_nograb() // application no-grab option
-{
-#if defined(QT_DEBUG)
- return appNoGrab;
-#else
- return false;
-#endif
-}
-
-// Modified from http://www3.symbian.com/faq.nsf/0/0F1464EE96E737E780256D5E00503DD1?OpenDocument
-class QS60Beep : public CBase, public MMdaAudioToneObserver
-{
-public:
- static QS60Beep* NewL(TInt aFrequency, TTimeIntervalMicroSeconds iDuration);
- void Play();
- ~QS60Beep();
-private:
- void ConstructL(TInt aFrequency, TTimeIntervalMicroSeconds iDuration);
- void MatoPrepareComplete(TInt aError);
- void MatoPlayComplete(TInt aError);
-private:
- typedef enum
- {
- EBeepNotPrepared,
- EBeepPrepared,
- EBeepPlaying
- } TBeepState;
-private:
- CMdaAudioToneUtility* iToneUtil;
- TBeepState iState;
- TInt iFrequency;
- TTimeIntervalMicroSeconds iDuration;
-};
-
-static QS60Beep* qt_S60Beep = 0;
-
-QS60Beep::~QS60Beep()
-{
- if (iToneUtil) {
- switch (iState) {
- case EBeepPlaying:
- iToneUtil->CancelPlay();
- break;
- case EBeepNotPrepared:
- iToneUtil->CancelPrepare();
- break;
- }
- }
- delete iToneUtil;
-}
-
-QS60Beep* QS60Beep::NewL(TInt aFrequency, TTimeIntervalMicroSeconds aDuration)
-{
- QS60Beep* self = new (ELeave) QS60Beep();
- CleanupStack::PushL(self);
- self->ConstructL(aFrequency, aDuration);
- CleanupStack::Pop();
- return self;
-}
-
-void QS60Beep::ConstructL(TInt aFrequency, TTimeIntervalMicroSeconds aDuration)
-{
- iToneUtil = CMdaAudioToneUtility::NewL(*this);
- iState = EBeepNotPrepared;
- iFrequency = aFrequency;
- iDuration = aDuration;
- iToneUtil->PrepareToPlayTone(iFrequency, iDuration);
-}
-
-void QS60Beep::Play()
-{
- if (iState == EBeepPlaying) {
- iToneUtil->CancelPlay();
- iState = EBeepPrepared;
- }
-
- iToneUtil->Play();
- iState = EBeepPlaying;
-}
-
-void QS60Beep::MatoPrepareComplete(TInt aError)
-{
- if (aError == KErrNone) {
- iState = EBeepPrepared;
- Play();
- }
-}
-
-void QS60Beep::MatoPlayComplete(TInt aError)
-{
- Q_UNUSED(aError);
- iState = EBeepPrepared;
-}
-
-
-static Qt::KeyboardModifiers mapToQtModifiers(TUint s60Modifiers)
-{
- Qt::KeyboardModifiers result = Qt::NoModifier;
-
- if (s60Modifiers & EModifierKeypad)
- result |= Qt::KeypadModifier;
- if (s60Modifiers & EModifierShift || s60Modifiers & EModifierLeftShift
- || s60Modifiers & EModifierRightShift)
- result |= Qt::ShiftModifier;
- if (s60Modifiers & EModifierCtrl || s60Modifiers & EModifierLeftCtrl
- || s60Modifiers & EModifierRightCtrl)
- result |= Qt::ControlModifier;
- if (s60Modifiers & EModifierAlt || s60Modifiers & EModifierLeftAlt
- || s60Modifiers & EModifierRightAlt)
- result |= Qt::AltModifier;
-
- return result;
-}
-
-static void mapS60MouseEventTypeToQt(QEvent::Type *type, Qt::MouseButton *button, const TPointerEvent *pEvent)
-{
- switch (pEvent->iType) {
- case TPointerEvent::EButton1Down:
- *type = QEvent::MouseButtonPress;
- *button = Qt::LeftButton;
- break;
- case TPointerEvent::EButton1Up:
- *type = QEvent::MouseButtonRelease;
- *button = Qt::LeftButton;
- break;
- case TPointerEvent::EButton2Down:
- *type = QEvent::MouseButtonPress;
- *button = Qt::MidButton;
- break;
- case TPointerEvent::EButton2Up:
- *type = QEvent::MouseButtonRelease;
- *button = Qt::MidButton;
- break;
- case TPointerEvent::EButton3Down:
- *type = QEvent::MouseButtonPress;
- *button = Qt::RightButton;
- break;
- case TPointerEvent::EButton3Up:
- *type = QEvent::MouseButtonRelease;
- *button = Qt::RightButton;
- break;
- case TPointerEvent::EDrag:
- *type = QEvent::MouseMove;
- *button = Qt::NoButton;
- break;
- case TPointerEvent::EMove:
- // Qt makes no distinction between move and drag
- *type = QEvent::MouseMove;
- *button = Qt::NoButton;
- break;
- default:
- *type = QEvent::None;
- *button = Qt::NoButton;
- break;
- }
- if (pEvent->iModifiers & EModifierDoubleClick){
- *type = QEvent::MouseButtonDblClick;
- }
-
- if (*type == QEvent::MouseButtonPress || *type == QEvent::MouseButtonDblClick)
- QApplicationPrivate::mouse_buttons = QApplicationPrivate::mouse_buttons | (*button);
- else if (*type == QEvent::MouseButtonRelease)
- QApplicationPrivate::mouse_buttons = QApplicationPrivate::mouse_buttons &(~(*button));
-
- QApplicationPrivate::mouse_buttons = QApplicationPrivate::mouse_buttons & Qt::MouseButtonMask;
-}
-
-//### Can be replaced with CAknLongTapDetector if animation is required.
-//NOTE: if CAknLongTapDetector is used make sure it gets variated out of 3.1 and 3.2,.
-//also MLongTapObserver needs to be changed to MAknLongTapDetectorCallBack if CAknLongTapDetector is used.
-class QLongTapTimer : public CTimer
-{
-public:
- static QLongTapTimer* NewL(QAbstractLongTapObserver *observer);
- QLongTapTimer(QAbstractLongTapObserver *observer);
- void ConstructL();
-public:
- void PointerEventL(const TPointerEvent &event);
- void RunL();
-protected:
-private:
- QAbstractLongTapObserver *m_observer;
- TPointerEvent m_event;
- QPoint m_pressedCoordinates;
- int m_dragDistance;
-};
-
-QLongTapTimer* QLongTapTimer::NewL(QAbstractLongTapObserver *observer)
-{
- QLongTapTimer* self = new QLongTapTimer(observer);
- self->ConstructL();
- return self;
-}
-void QLongTapTimer::ConstructL()
-{
- CTimer::ConstructL();
-}
-
-QLongTapTimer::QLongTapTimer(QAbstractLongTapObserver *observer):CTimer(CActive::EPriorityHigh)
-{
- m_observer = observer;
- m_dragDistance = qApp->startDragDistance();
- CActiveScheduler::Add(this);
-}
-
-void QLongTapTimer::PointerEventL(const TPointerEvent& event)
-{
- if ( event.iType == TPointerEvent::EDrag || event.iType == TPointerEvent::EButtonRepeat)
- {
- QPoint diff(QPoint(event.iPosition.iX,event.iPosition.iY) - m_pressedCoordinates);
- if (diff.manhattanLength() < m_dragDistance)
- return;
- }
- Cancel();
- m_event = event;
- if (event.iType == TPointerEvent::EButton1Down)
- {
- m_pressedCoordinates = QPoint(event.iPosition.iX,event.iPosition.iY);
- // must be same as KLongTapDelay in aknlongtapdetector.h
- After(800000);
- }
-}
-void QLongTapTimer::RunL()
-{
- if (m_observer)
- m_observer->HandleLongTapEventL(m_event.iPosition, m_event.iParentPosition);
-}
-
-QSymbianControl::QSymbianControl(QWidget *w)
- : CCoeControl()
- , qwidget(w)
- , m_longTapDetector(0)
- , m_ignoreFocusChanged(0)
- , m_symbianPopupIsOpen(0)
- , m_inExternalScreenOverride(false)
- , m_lastStatusPaneVisibility(0)
-{
-}
-
-void QSymbianControl::ConstructL(bool isWindowOwning, bool desktop)
-{
- if (!desktop)
- {
- if (isWindowOwning || !qwidget->parentWidget()
- || qwidget->parentWidget()->windowType() == Qt::Desktop) {
- RWindowGroup &wg(S60->windowGroup(qwidget));
- CreateWindowL(wg);
- } else {
- /**
- * TODO: in order to avoid creating windows for all ancestors of
- * this widget up to the root window, the parameter passed to
- * CreateWindowL should be
- * qwidget->parentWidget()->effectiveWinId(). However, if we do
- * this, then we need to take care of re-parenting when a window
- * is created for a widget between this one and the root window.
- */
- CreateWindowL(qwidget->parentWidget()->winId());
- }
-
- // Necessary in order to be able to track the activation status of
- // the control's window
- qwidget->d_func()->createExtra();
-
- SetFocusing(true);
- m_longTapDetector = QLongTapTimer::NewL(this);
- m_doubleClickTimer.invalidate();
-
- DrawableWindow()->SetPointerGrab(ETrue);
- }
-
-#ifdef Q_SYMBIAN_TRANSITION_EFFECTS
- if (OwnsWindow()) {
- TTfxWindowPurpose windowPurpose(ETfxPurposeNone);
- switch (qwidget->windowType()) {
- case Qt::Dialog:
- windowPurpose = ETfxPurposeDialogWindow;
- break;
- case Qt::Popup:
- windowPurpose = ETfxPurposePopupWindow;
- break;
- case Qt::Tool:
- windowPurpose = ETfxPurposeToolWindow;
- break;
- case Qt::ToolTip:
- windowPurpose = ETfxPurposeToolTipWindow;
- break;
- case Qt::SplashScreen:
- windowPurpose = ETfxPurposeSplashScreenWindow;
- break;
- default:
- windowPurpose = (isWindowOwning || !qwidget->parentWidget() || qwidget->parentWidget()->windowType() == Qt::Desktop)
- ? ETfxPurposeWindow : ETfxPurposeChildWindow;
- break;
- }
- Window().SetPurpose(windowPurpose);
- }
-#endif
-}
-
-QSymbianControl::~QSymbianControl()
-{
- // Ensure backing store is deleted before the top-level
- // window is destroyed
- qt_widget_private(qwidget)->topData()->backingStore.destroy();
-
- if (S60->curWin == this)
- S60->curWin = 0;
- if (!QApplicationPrivate::is_app_closing) {
- QT_TRY {
- setFocusSafely(false);
- } QT_CATCH(const std::exception&) {
- // ignore exceptions, nothing can be done
- }
- }
- S60->appUi()->RemoveFromStack(this);
- delete m_longTapDetector;
-}
-
-void QSymbianControl::setWidget(QWidget *w)
-{
- qwidget = w;
-}
-
-QPoint QSymbianControl::translatePointForFixedNativeOrientation(const TPoint &pointerEventPos) const
-{
- QPoint pos(pointerEventPos.iX, pointerEventPos.iY);
- if (qwidget->d_func()->fixNativeOrientationCalled) {
- QSize wsize = qwidget->size();
- TSize size = Size();
- if (size.iWidth == wsize.height() && size.iHeight == wsize.width()) {
- qreal x = pos.x();
- qreal y = pos.y();
- pos.setX(size.iHeight - y);
- pos.setY(x);
- }
- }
- return pos;
-}
-
-TRect QSymbianControl::translateRectForFixedNativeOrientation(const TRect &controlRect) const
-{
- TRect rect = controlRect;
- if (qwidget->d_func()->fixNativeOrientationCalled) {
- QPoint a = translatePointForFixedNativeOrientation(rect.iTl);
- QPoint b = translatePointForFixedNativeOrientation(rect.iBr);
- if (a.x() < b.x()) {
- rect.iTl.iX = a.x();
- rect.iBr.iX = b.x();
- } else {
- rect.iTl.iX = b.x();
- rect.iBr.iX = a.x();
- }
- if (a.y() < b.y()) {
- rect.iTl.iY = a.y();
- rect.iBr.iY = b.y();
- } else {
- rect.iTl.iY = b.y();
- rect.iBr.iY = a.y();
- }
- }
- return rect;
-}
-
-void QSymbianControl::HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation )
-{
- QWidget *alienWidget;
- QPoint widgetPos = translatePointForFixedNativeOrientation(aPenEventLocation);
- QPoint globalPos = translatePointForFixedNativeOrientation(aPenEventScreenLocation);
- alienWidget = qwidget->childAt(widgetPos);
- if (!alienWidget)
- alienWidget = qwidget;
-
-#if !defined(QT_NO_CONTEXTMENU)
- QContextMenuEvent contextMenuEvent(QContextMenuEvent::Mouse, widgetPos, globalPos, Qt::NoModifier);
- qt_sendSpontaneousEvent(alienWidget, &contextMenuEvent);
-#endif
-}
-
-#ifdef QT_SYMBIAN_SUPPORTS_ADVANCED_POINTER
-void QSymbianControl::translateAdvancedPointerEvent(const TAdvancedPointerEvent *event)
-{
- QApplicationPrivate *d = QApplicationPrivate::instance();
- QPointF screenPos = qwidget->mapToGlobal(translatePointForFixedNativeOrientation(event->iPosition));
- qreal pressure;
- if(d->pressureSupported
- && event->Pressure() > 0) //workaround for misconfigured HAL
- pressure = event->Pressure() / qreal(d->maxTouchPressure);
- else
- pressure = qreal(1.0);
- processTouchEvent(event->PointerNumber(), event->iType, screenPos, pressure);
-}
-#endif
-
-void QSymbianControl::processTouchEvent(int pointerNumber, TPointerEvent::TType type, QPointF screenPos, qreal pressure)
-{
- QRect screenGeometry = qApp->desktop()->screenGeometry(qwidget);
-
- QApplicationPrivate *d = QApplicationPrivate::instance();
-
- QList<QTouchEvent::TouchPoint> points = d->appAllTouchPoints;
- while (points.count() <= pointerNumber)
- points.append(QTouchEvent::TouchPoint(points.count()));
-
- Qt::TouchPointStates allStates = 0;
- for (int i = 0; i < points.count(); ++i) {
- QTouchEvent::TouchPoint &touchPoint = points[i];
-
- if (touchPoint.id() == pointerNumber) {
- Qt::TouchPointStates state;
- switch (type) {
- case TPointerEvent::EButton1Down:
-#ifdef QT_SYMBIAN_SUPPORTS_ADVANCED_POINTER
- case TPointerEvent::EEnterHighPressure:
-#endif
- state = Qt::TouchPointPressed;
- break;
- case TPointerEvent::EButton1Up:
-#ifdef QT_SYMBIAN_SUPPORTS_ADVANCED_POINTER
- case TPointerEvent::EExitCloseProximity:
-#endif
- state = Qt::TouchPointReleased;
- break;
- case TPointerEvent::EDrag:
- state = Qt::TouchPointMoved;
- break;
- default:
- // how likely is this to happen?
- state = Qt::TouchPointStationary;
- break;
- }
- if (pointerNumber == 0)
- state |= Qt::TouchPointPrimary;
- touchPoint.setState(state);
-
- touchPoint.setScreenPos(screenPos);
- touchPoint.setNormalizedPos(QPointF(screenPos.x() / screenGeometry.width(),
- screenPos.y() / screenGeometry.height()));
-
- touchPoint.setPressure(pressure);
- } else if (touchPoint.state() != Qt::TouchPointReleased) {
- // all other active touch points should be marked as stationary
- touchPoint.setState(Qt::TouchPointStationary);
- }
-
- allStates |= touchPoint.state();
- }
-
- if ((allStates & Qt::TouchPointStateMask) == Qt::TouchPointReleased) {
- // all touch points released
- d->appAllTouchPoints.clear();
- } else {
- d->appAllTouchPoints = points;
- }
-
- QApplicationPrivate::translateRawTouchEvent(qwidget,
- QTouchEvent::TouchScreen,
- points);
-}
-
-void QSymbianControl::HandlePointerEventL(const TPointerEvent& pEvent)
-{
-#ifdef QT_SYMBIAN_SUPPORTS_ADVANCED_POINTER
- if (pEvent.IsAdvancedPointerEvent()) {
- const TAdvancedPointerEvent *advancedPointerEvent = pEvent.AdvancedPointerEvent();
- translateAdvancedPointerEvent(advancedPointerEvent);
- if (advancedPointerEvent->PointerNumber() != 0) {
- // only send mouse events for the first touch point
- return;
- }
- }
-#endif
-
- m_longTapDetector->PointerEventL(pEvent);
- QT_TRYCATCH_LEAVING(HandlePointerEvent(pEvent));
-}
-
-void QSymbianControl::HandlePointerEvent(const TPointerEvent& pEvent)
-{
- QMouseEvent::Type type;
- Qt::MouseButton button;
- mapS60MouseEventTypeToQt(&type, &button, &pEvent);
- Qt::KeyboardModifiers modifiers = mapToQtModifiers(pEvent.iModifiers);
-
- QPoint widgetPos = translatePointForFixedNativeOrientation(pEvent.iPosition);
- TPoint controlScreenPos = PositionRelativeToScreen();
- QPoint globalPos = QPoint(controlScreenPos.iX, controlScreenPos.iY) + widgetPos;
- S60->lastCursorPos = globalPos;
- S60->lastPointerEventPos = widgetPos;
-
- QWidget *mouseGrabber = QWidget::mouseGrabber();
-
- QWidget *popupWidget = qApp->activePopupWidget();
- QWidget *popupReceiver = 0;
- if (popupWidget) {
- QWidget *popupChild = popupWidget->childAt(popupWidget->mapFromGlobal(globalPos));
- popupReceiver = popupChild ? popupChild : popupWidget;
- }
-
- if (mouseGrabber) {
- if (popupReceiver) {
- sendMouseEvent(popupReceiver, type, globalPos, button, modifiers);
- } else {
- sendMouseEvent(mouseGrabber, type, globalPos, button, modifiers);
- }
- // No Enter/Leave events in grabbing mode.
- return;
- }
-
- QWidget *widgetUnderPointer = qwidget->childAt(widgetPos);
- if (!widgetUnderPointer)
- widgetUnderPointer = qwidget;
-
- QApplicationPrivate::dispatchEnterLeave(widgetUnderPointer, S60->lastPointerEventTarget);
- S60->lastPointerEventTarget = widgetUnderPointer;
-
- QWidget *receiver;
- if (!popupReceiver && S60->mousePressTarget && type != QEvent::MouseButtonPress) {
- receiver = S60->mousePressTarget;
- if (type == QEvent::MouseButtonRelease)
- S60->mousePressTarget = 0;
- } else {
- receiver = popupReceiver ? popupReceiver : widgetUnderPointer;
- if (type == QEvent::MouseButtonPress)
- S60->mousePressTarget = receiver;
- }
-
-#if !defined(QT_NO_CURSOR) && !defined(Q_SYMBIAN_FIXED_POINTER_CURSORS)
- if (S60->brokenPointerCursors)
- qt_symbian_move_cursor_sprite();
-#endif
-
-//Generate single touch event for S60 5.0 (has touchscreen, does not have advanced pointers)
-#ifndef QT_SYMBIAN_SUPPORTS_ADVANCED_POINTER
- if (S60->hasTouchscreen) {
- processTouchEvent(0, pEvent.iType, QPointF(globalPos), 1.0);
- }
-#endif
-
- sendMouseEvent(receiver, type, globalPos, button, modifiers);
-}
-
-#ifdef Q_WS_S60
-void QSymbianControl::HandleStatusPaneSizeChange()
-{
- QS60MainAppUi *s60AppUi = static_cast<QS60MainAppUi *>(S60->appUi());
- s60AppUi->HandleStatusPaneSizeChange();
-}
-#endif
-
-void QSymbianControl::sendMouseEvent(
- QWidget *receiver,
- QEvent::Type type,
- const QPoint &globalPos,
- Qt::MouseButton button,
- Qt::KeyboardModifiers modifiers)
-{
- Q_ASSERT(receiver);
- QMouseEvent mEvent(type, receiver->mapFromGlobal(globalPos), globalPos,
- button, QApplicationPrivate::mouse_buttons, modifiers);
- QEventDispatcherS60 *dispatcher;
- // It is theoretically possible for someone to install a different event dispatcher.
- if ((dispatcher = qobject_cast<QEventDispatcherS60 *>(receiver->d_func()->threadData->eventDispatcher)) != 0) {
- if (dispatcher->excludeUserInputEvents()) {
- dispatcher->saveInputEvent(this, receiver, new QMouseEvent(mEvent));
- return;
- }
- }
-
- sendMouseEvent(receiver, &mEvent);
-}
-
-bool QSymbianControl::sendMouseEvent(QWidget *widget, QMouseEvent *mEvent)
-{
- return qt_sendSpontaneousEvent(widget, mEvent);
-}
-
-TKeyResponse QSymbianControl::OfferKeyEventL(const TKeyEvent& keyEvent, TEventCode type)
-{
- TKeyResponse r = EKeyWasNotConsumed;
- QT_TRYCATCH_LEAVING(r = OfferKeyEvent(keyEvent, type));
- return r;
-}
-
-TKeyResponse QSymbianControl::OfferKeyEvent(const TKeyEvent& keyEvent, TEventCode type)
-{
- /*
- S60 has a confusing way of delivering key events. There are three types of
- events: EEventKey, EEventKeyDown and EEventKeyUp. When a key is pressed,
- EEventKeyDown is first generated, followed by EEventKey. Then, when the key is
- released, EEventKeyUp is generated.
- However, it is possible that only the EEventKey is generated alone, typically
- in relation to virtual keyboards. In that case we need to take care to
- generate both press and release events in Qt, since applications expect that.
- We do this by having three states for each used scan code, depending on the
- events received. See the switch below for what happens in each state
- transition.
- */
-
- if (type != EEventKeyDown)
- if (handleVirtualMouse(keyEvent, type) == EKeyWasConsumed)
- return EKeyWasConsumed;
-
- TKeyResponse ret = EKeyWasNotConsumed;
-#define GET_RETURN(x) (ret = ((x) == EKeyWasConsumed) ? EKeyWasConsumed : ret)
-
- // This top level switch corresponds to the states, and the inner switches
- // correspond to the transitions.
- QS60Data::ScanCodeState &scanCodeState = S60->scanCodeStates[keyEvent.iScanCode];
- switch (scanCodeState) {
- case QS60Data::Unpressed:
- switch (type) {
- case EEventKeyDown:
- scanCodeState = QS60Data::KeyDown;
- break;
- case EEventKey:
- GET_RETURN(sendSymbianKeyEvent(keyEvent, QEvent::KeyPress));
- GET_RETURN(sendSymbianKeyEvent(keyEvent, QEvent::KeyRelease));
- break;
- case EEventKeyUp:
- // No action.
- break;
- }
- break;
- case QS60Data::KeyDown:
- switch (type) {
- case EEventKeyDown:
- // This should never happen, just stay in this state to be safe.
- break;
- case EEventKey:
- GET_RETURN(sendSymbianKeyEvent(keyEvent, QEvent::KeyPress));
- scanCodeState = QS60Data::KeyDownAndKey;
- break;
- case EEventKeyUp:
- scanCodeState = QS60Data::Unpressed;
- break;
- }
- break;
- case QS60Data::KeyDownAndKey:
- switch (type) {
- case EEventKeyDown:
- // This should never happen, just stay in this state to be safe.
- break;
- case EEventKey:
- GET_RETURN(sendSymbianKeyEvent(keyEvent, QEvent::KeyRelease));
- GET_RETURN(sendSymbianKeyEvent(keyEvent, QEvent::KeyPress));
- break;
- case EEventKeyUp:
- GET_RETURN(sendSymbianKeyEvent(keyEvent, QEvent::KeyRelease));
- scanCodeState = QS60Data::Unpressed;
- break;
- }
- break;
- }
- return ret;
-
-#undef GET_RETURN
-}
-
-TKeyResponse QSymbianControl::sendSymbianKeyEvent(const TKeyEvent &keyEvent, QEvent::Type type)
-{
- // Because S60 does not generate keysyms for EKeyEventDown and EKeyEventUp
- // events, we need to cache the keysyms from the EKeyEvent events. This is what
- // resolveS60ScanCode does.
- TUint s60Keysym = QApplicationPrivate::resolveS60ScanCode(keyEvent.iScanCode,
- keyEvent.iCode);
- int keyCode;
- if (s60Keysym == EKeyNull){ //some key events have 0 in iCode, for them iScanCode should be used
- keyCode = qt_keymapper_private()->mapS60ScanCodesToQt(keyEvent.iScanCode);
- } else if (s60Keysym >= 0x20 && s60Keysym < ENonCharacterKeyBase) {
- // Normal characters keys.
- keyCode = s60Keysym;
- } else {
- // Special S60 keys.
- keyCode = qt_keymapper_private()->mapS60KeyToQt(s60Keysym);
- }
-
- Qt::KeyboardModifiers mods = mapToQtModifiers(keyEvent.iModifiers);
- QKeyEventEx qKeyEvent(type, keyCode, mods, qt_keymapper_private()->translateKeyEvent(keyCode, mods),
- (keyEvent.iRepeats != 0), 1, keyEvent.iScanCode, s60Keysym, keyEvent.iModifiers);
- QWidget *widget;
- widget = QWidget::keyboardGrabber();
- if (!widget) {
- if (QApplicationPrivate::popupWidgets != 0) {
- widget = QApplication::activePopupWidget()->focusWidget();
- if (!widget) {
- widget = QApplication::activePopupWidget();
- }
- } else {
- widget = QApplicationPrivate::focus_widget;
- if (!widget) {
- widget = qwidget;
- }
- }
- }
-
- QEventDispatcherS60 *dispatcher;
- // It is theoretically possible for someone to install a different event dispatcher.
- if ((dispatcher = qobject_cast<QEventDispatcherS60 *>(widget->d_func()->threadData->eventDispatcher)) != 0) {
- if (dispatcher->excludeUserInputEvents()) {
- dispatcher->saveInputEvent(this, widget, new QKeyEventEx(qKeyEvent));
- return EKeyWasConsumed;
- }
- }
- return sendKeyEvent(widget, &qKeyEvent);
-}
-
-TKeyResponse QSymbianControl::handleVirtualMouse(const TKeyEvent& keyEvent,TEventCode type)
-{
-#ifndef QT_NO_CURSOR
- if (S60->mouseInteractionEnabled && S60->virtualMouseRequired) {
- //translate keys to pointer
- if ((keyEvent.iScanCode >= EStdKeyLeftArrow && keyEvent.iScanCode <= EStdKeyDownArrow) ||
- (keyEvent.iScanCode >= EStdKeyDevice10 && keyEvent.iScanCode <= EStdKeyDevice13) ||
- keyEvent.iScanCode == EStdKeyDevice3) {
- QPoint pos = QCursor::pos();
- TPointerEvent fakeEvent;
- fakeEvent.iType = (TPointerEvent::TType)(-1);
- fakeEvent.iModifiers = keyEvent.iModifiers;
- TInt x = pos.x();
- TInt y = pos.y();
- if (type == EEventKeyUp) {
- S60->virtualMouseAccelTimeout.start();
- switch (keyEvent.iScanCode) {
- case EStdKeyLeftArrow:
- S60->virtualMousePressedKeys &= ~QS60Data::Left;
- break;
- case EStdKeyRightArrow:
- S60->virtualMousePressedKeys &= ~QS60Data::Right;
- break;
- case EStdKeyUpArrow:
- S60->virtualMousePressedKeys &= ~QS60Data::Up;
- break;
- case EStdKeyDownArrow:
- S60->virtualMousePressedKeys &= ~QS60Data::Down;
- break;
- // diagonal keys (named aliases don't exist in 3.1 SDK)
- case EStdKeyDevice10:
- S60->virtualMousePressedKeys &= ~QS60Data::LeftUp;
- break;
- case EStdKeyDevice11:
- S60->virtualMousePressedKeys &= ~QS60Data::RightUp;
- break;
- case EStdKeyDevice12:
- S60->virtualMousePressedKeys &= ~QS60Data::RightDown;
- break;
- case EStdKeyDevice13:
- S60->virtualMousePressedKeys &= ~QS60Data::LeftDown;
- break;
- case EStdKeyDevice3: //select
- if (S60->virtualMousePressedKeys & QS60Data::Select)
- fakeEvent.iType = TPointerEvent::EButton1Up;
- S60->virtualMousePressedKeys &= ~QS60Data::Select;
- break;
- }
- }
- else if (type == EEventKey) {
- int dx = 0;
- int dy = 0;
- if (keyEvent.iScanCode != EStdKeyDevice3) {
- m_doubleClickTimer.invalidate();
- //reset mouse accelleration after a short time with no moves
- const int maxTimeBetweenKeyEventsMs = 500;
- if (S60->virtualMouseAccelTimeout.isValid() &&
- S60->virtualMouseAccelTimeout.hasExpired(maxTimeBetweenKeyEventsMs)) {
- S60->virtualMouseAccelDX = 0;
- S60->virtualMouseAccelDY = 0;
- }
- S60->virtualMouseAccelTimeout.invalidate();
- }
- switch (keyEvent.iScanCode) {
- case EStdKeyLeftArrow:
- S60->virtualMousePressedKeys |= QS60Data::Left;
- dx = -1;
- fakeEvent.iType = TPointerEvent::EMove;
- break;
- case EStdKeyRightArrow:
- S60->virtualMousePressedKeys |= QS60Data::Right;
- dx = 1;
- fakeEvent.iType = TPointerEvent::EMove;
- break;
- case EStdKeyUpArrow:
- S60->virtualMousePressedKeys |= QS60Data::Up;
- dy = -1;
- fakeEvent.iType = TPointerEvent::EMove;
- break;
- case EStdKeyDownArrow:
- S60->virtualMousePressedKeys |= QS60Data::Down;
- dy = 1;
- fakeEvent.iType = TPointerEvent::EMove;
- break;
- case EStdKeyDevice10:
- S60->virtualMousePressedKeys |= QS60Data::LeftUp;
- dx = -1;
- dy = -1;
- fakeEvent.iType = TPointerEvent::EMove;
- break;
- case EStdKeyDevice11:
- S60->virtualMousePressedKeys |= QS60Data::RightUp;
- dx = 1;
- dy = -1;
- fakeEvent.iType = TPointerEvent::EMove;
- break;
- case EStdKeyDevice12:
- S60->virtualMousePressedKeys |= QS60Data::RightDown;
- dx = 1;
- dy = 1;
- fakeEvent.iType = TPointerEvent::EMove;
- break;
- case EStdKeyDevice13:
- S60->virtualMousePressedKeys |= QS60Data::LeftDown;
- dx = -1;
- dy = 1;
- fakeEvent.iType = TPointerEvent::EMove;
- break;
- case EStdKeyDevice3:
- // Platform bug. If you start pressing several keys simultaneously (for
- // example for drag'n'drop), Symbian starts producing spurious up and
- // down messages for some keys. Therefore, make sure we have a clean slate
- // of pressed keys before starting a new button press.
- if (S60->virtualMousePressedKeys & QS60Data::Select) {
- return EKeyWasConsumed;
- } else {
- S60->virtualMousePressedKeys |= QS60Data::Select;
- fakeEvent.iType = TPointerEvent::EButton1Down;
- if (m_doubleClickTimer.isValid()
- && !m_doubleClickTimer.hasExpired(QApplication::doubleClickInterval())) {
- fakeEvent.iModifiers |= EModifierDoubleClick;
- m_doubleClickTimer.invalidate();
- } else {
- m_doubleClickTimer.start();
- }
- }
- break;
- }
- if (dx) {
- int cdx = S60->virtualMouseAccelDX;
- //reset accel on change of sign, else double accel
- if (dx * cdx <= 0)
- cdx = dx;
- else
- cdx *= 4;
- //cap accelleration
- if (dx * cdx > S60->virtualMouseMaxAccel)
- cdx = dx * S60->virtualMouseMaxAccel;
- //move mouse position
- x += cdx;
- S60->virtualMouseAccelDX = cdx;
- }
-
- if (dy) {
- int cdy = S60->virtualMouseAccelDY;
- if (dy * cdy <= 0)
- cdy = dy;
- else
- cdy *= 4;
- if (dy * cdy > S60->virtualMouseMaxAccel)
- cdy = dy * S60->virtualMouseMaxAccel;
- y += cdy;
- S60->virtualMouseAccelDY = cdy;
- }
- }
- //clip to screen size (window server allows a sprite hotspot to be outside the screen)
- int screenNumber = S60->screenNumberForWidget(qwidget);
- if (x < 0)
- x = 0;
- else if (x >= S60->screenWidthInPixelsForScreen[screenNumber])
- x = S60->screenWidthInPixelsForScreen[screenNumber] - 1;
- if (y < 0)
- y = 0;
- else if (y >= S60->screenHeightInPixelsForScreen[screenNumber])
- y = S60->screenHeightInPixelsForScreen[screenNumber] - 1;
- TPoint epos(x, y);
- TPoint cpos = epos - PositionRelativeToScreen();
- fakeEvent.iPosition = cpos;
- fakeEvent.iParentPosition = epos;
- if(fakeEvent.iType != -1)
- HandlePointerEvent(fakeEvent);
- return EKeyWasConsumed;
- }
- }
-#endif
-
- return EKeyWasNotConsumed;
-}
-
-void QSymbianControl::sendInputEvent(QWidget *widget, QInputEvent *inputEvent)
-{
- switch (inputEvent->type()) {
- case QEvent::KeyPress:
- case QEvent::KeyRelease:
- sendKeyEvent(widget, static_cast<QKeyEvent *>(inputEvent));
- break;
- case QEvent::MouseButtonDblClick:
- case QEvent::MouseButtonPress:
- case QEvent::MouseButtonRelease:
- case QEvent::MouseMove:
- sendMouseEvent(widget, static_cast<QMouseEvent *>(inputEvent));
- break;
- default:
- // Shouldn't get here.
- Q_ASSERT_X(0 == 1, "QSymbianControl::sendInputEvent()", "inputEvent->type() is unknown");
- break;
- }
-}
-
-TKeyResponse QSymbianControl::sendKeyEvent(QWidget *widget, QKeyEvent *keyEvent)
-{
-#if !defined(QT_NO_IM) && defined(Q_WS_S60)
- if (widget && widget->isEnabled() && widget->testAttribute(Qt::WA_InputMethodEnabled)) {
- QInputContext *qic = widget->inputContext();
- if (qic && qic->filterEvent(keyEvent))
- return EKeyWasConsumed;
- }
-#endif // !defined(QT_NO_IM) && defined(Q_OS_SYMBIAN)
-
- if (widget && qt_sendSpontaneousEvent(widget, keyEvent))
- if (keyEvent->isAccepted())
- return EKeyWasConsumed;
-
- return EKeyWasNotConsumed;
-}
-
-#if !defined(QT_NO_IM) && defined(Q_WS_S60)
-TCoeInputCapabilities QSymbianControl::InputCapabilities() const
-{
- QWidget *w = 0;
-
- if (qwidget->hasFocus())
- w = qwidget;
- else
- w = qwidget->focusWidget();
-
- QCoeFepInputContext *ic;
- if (w && w->isEnabled() && w->testAttribute(Qt::WA_InputMethodEnabled)
- && (ic = qobject_cast<QCoeFepInputContext *>(w->inputContext()))) {
- return ic->inputCapabilities();
- } else {
- return TCoeInputCapabilities(TCoeInputCapabilities::ENone, 0, 0);
- }
-}
-#endif
-
-void QSymbianControl::Draw(const TRect& controlRect) const
-{
- // Set flag to avoid calling DrawNow in window surface
- QWidget *window = qwidget->window();
- Q_ASSERT(window);
- QTLWExtra *topExtra = window->d_func()->maybeTopData();
- Q_ASSERT(topExtra);
-
- TRect wcontrolRect = translateRectForFixedNativeOrientation(controlRect);
-
- if (!topExtra->inExpose) {
- topExtra->inExpose = true;
- if (!qwidget->isWindow()) {
- // If we get here, then it means we have a native child window
- // Since no content should ever be painted to these windows, we
- // erase them with a transparent brush when they get an expose.
- CWindowGc &gc = SystemGc();
- gc.SetBrushColor(TRgb(0, 0, 0, 0));
- gc.Clear(controlRect);
- }
- QRect exposeRect = qt_TRect2QRect(wcontrolRect);
- qwidget->d_func()->syncBackingStore(exposeRect);
- topExtra->inExpose = false;
- }
-
- QWindowSurface *surface = qwidget->windowSurface();
- QPaintEngine *engine = surface ? surface->paintDevice()->paintEngine() : NULL;
-
- if (!engine)
- return;
-
- const bool sendNativePaintEvents = qwidget->d_func()->extraData()->receiveNativePaintEvents;
- if (sendNativePaintEvents) {
- const QRect r = qt_TRect2QRect(wcontrolRect);
- QMetaObject::invokeMethod(qwidget, "beginNativePaintEvent", Qt::DirectConnection, Q_ARG(QRect, r));
- }
-
- // Map source rectangle into coordinates of the backing store.
- const QPoint controlBase(controlRect.iTl.iX, controlRect.iTl.iY);
- const QPoint backingStoreBase = qwidget->mapTo(qwidget->window(), controlBase);
- const TRect backingStoreRect(TPoint(backingStoreBase.x(), backingStoreBase.y()), controlRect.Size());
-
- if (engine->type() == QPaintEngine::Raster) {
- QS60WindowSurface *s60Surface;
-#ifdef QT_GRAPHICSSYSTEM_RUNTIME
- if (QApplicationPrivate::runtime_graphics_system) {
- QRuntimeWindowSurface *rtSurface =
- static_cast<QRuntimeWindowSurface*>(qwidget->windowSurface());
- s60Surface = static_cast<QS60WindowSurface *>(rtSurface->m_windowSurface.data());
- } else
-#endif
- s60Surface = static_cast<QS60WindowSurface *>(qwidget->windowSurface());
-
- CFbsBitmap *bitmap = s60Surface->symbianBitmap();
- CWindowGc &gc = SystemGc();
-
- QWExtra::NativePaintMode nativePaintMode = qwidget->d_func()->extraData()->nativePaintMode;
- if(qwidget->d_func()->paintOnScreen())
- nativePaintMode = QWExtra::Disable;
-
- switch(nativePaintMode) {
- case QWExtra::Disable:
- // Do nothing
- break;
- case QWExtra::Blit:
- case QWExtra::BlitWriteAlpha:
- if (qwidget->d_func()->isOpaque || nativePaintMode == QWExtra::BlitWriteAlpha)
- gc.SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
- gc.BitBlt(controlRect.iTl, bitmap, backingStoreRect);
- break;
- case QWExtra::ZeroFill:
- if (Window().DisplayMode() == EColor16MA
- || Window().DisplayMode() == Q_SYMBIAN_ECOLOR16MAP) {
- gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
- gc.SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
- gc.SetBrushColor(TRgb::Color16MA(0));
- gc.Clear(controlRect);
- } else {
- gc.SetBrushColor(TRgb(0x000000));
- gc.Clear(controlRect);
- };
- break;
- default:
- Q_ASSERT(false);
- }
- }
-
- if (sendNativePaintEvents) {
- const QRect r = qt_TRect2QRect(wcontrolRect);
- // The draw ops aren't actually sent to WSERV until the graphics
- // context is deactivated, which happens in the function calling
- // this one. We therefore delay the delivery of endNativePaintEvent,
- // to ensure that drawing has completed by the time the widget
- // receives the event. Note that, if the widget needs to ensure
- // that the draw ops have actually been executed into the output
- // framebuffer, a call to RWsSession::Flush is required in the
- // endNativePaintEvent implementation.
- QMetaObject::invokeMethod(qwidget, "endNativePaintEvent", Qt::QueuedConnection, Q_ARG(QRect, r));
- }
-}
-
-void QSymbianControl::qwidgetResize_helper(const QSize &newSize)
-{
- QRect cr = qwidget->geometry();
- QSize oldSize(cr.size());
- cr.setSize(newSize);
- qwidget->data->crect = cr;
- if (qwidget->isVisible()) {
- QTLWExtra *tlwExtra = qwidget->d_func()->maybeTopData();
- bool slowResize = qgetenv("QT_SLOW_TOPLEVEL_RESIZE").toInt();
- if (!slowResize && tlwExtra)
- tlwExtra->inTopLevelResize = true;
- QResizeEvent e(newSize, oldSize);
- qt_sendSpontaneousEvent(qwidget, &e);
- if (!qwidget->testAttribute(Qt::WA_StaticContents))
- qwidget->d_func()->syncBackingStore();
- if (!slowResize && tlwExtra)
- tlwExtra->inTopLevelResize = false;
- } else {
- if (!qwidget->testAttribute(Qt::WA_PendingResizeEvent)) {
- QResizeEvent *e = new QResizeEvent(newSize, oldSize);
- QApplication::postEvent(qwidget, e);
- }
- }
-}
-
-void QSymbianControl::SizeChanged()
-{
- CCoeControl::SizeChanged();
-
- // When FixNativeOrientation had been called, the RWindow/CCoeControl size
- // and the surface/QWidget size have nothing to do with each other.
- if (qwidget->d_func()->fixNativeOrientationCalled)
- return;
-
- QSize oldSize = qwidget->size();
- QSize newSize(Size().iWidth, Size().iHeight);
-
- if (oldSize != newSize) {
- // Enforce the proper size for fullscreen widgets on the secondary screen.
- const bool isFullscreen = qwidget->windowState() & Qt::WindowFullScreen;
- const int screenNumber = S60->screenNumberForWidget(qwidget);
- if (!m_inExternalScreenOverride && isFullscreen && screenNumber > 0) {
- int screenWidth = S60->screenWidthInPixelsForScreen[screenNumber];
- int screenHeight = S60->screenHeightInPixelsForScreen[screenNumber];
- TSize screenSize(screenWidth, screenHeight);
- if (screenWidth > 0 && screenHeight > 0 && screenSize != Size()) {
- m_inExternalScreenOverride = true;
- SetExtent(TPoint(0, 0), screenSize);
- return;
- }
- }
-
- qwidgetResize_helper(newSize);
- }
-
- m_inExternalScreenOverride = false;
-
- // CCoeControl::SetExtent calls SizeChanged, but does not call
- // PositionChanged, so we call it here to ensure that the widget's
- // position is updated.
- PositionChanged();
-}
-
-void QSymbianControl::PositionChanged()
-{
- CCoeControl::PositionChanged();
-
- QPoint oldPos = qwidget->geometry().topLeft();
- QPoint newPos(Position().iX, Position().iY);
-
- if (oldPos != newPos) {
- QRect cr = qwidget->geometry();
- cr.moveTopLeft(newPos);
- qwidget->data->crect = cr;
- QTLWExtra *top = qwidget->d_func()->maybeTopData();
- if (top && (qwidget->windowState() & (~Qt::WindowActive)) == Qt::WindowNoState)
- top->normalGeometry.moveTopLeft(newPos);
- if (qwidget->isVisible()) {
- QMoveEvent e(newPos, oldPos);
- qt_sendSpontaneousEvent(qwidget, &e);
- } else {
- QMoveEvent * e = new QMoveEvent(newPos, oldPos);
- QApplication::postEvent(qwidget, e);
- }
- }
-}
-
-void QSymbianControl::FocusChanged(TDrawNow /* aDrawNow */)
-{
- if (m_ignoreFocusChanged || (qwidget->windowType() & Qt::WindowType_Mask) == Qt::Desktop)
- return;
-
-#ifdef Q_WS_S60
- if (S60->splitViewLastWidget)
- return;
-#endif
-
- // Popups never get focused, but still receive the FocusChanged when they are hidden.
- if (QApplicationPrivate::popupWidgets != 0
- || (qwidget->windowType() & Qt::Popup) == Qt::Popup)
- return;
-
- if (IsFocused() && IsVisible()) {
- if (m_symbianPopupIsOpen) {
- QWidget *fw = QApplication::focusWidget();
- if (fw) {
- QFocusEvent event(QEvent::FocusIn, Qt::PopupFocusReason);
- QCoreApplication::sendEvent(fw, &event);
- }
- m_symbianPopupIsOpen = false;
- }
-
- QApplication::setActiveWindow(qwidget->window());
- qwidget->d_func()->setWindowIcon_sys(true);
- qwidget->d_func()->setWindowTitle_sys(qwidget->windowTitle());
-#ifdef Q_WS_S60
- if (qwidget->isWindow())
- S60->setRecursiveDecorationsVisibility(qwidget, qwidget->windowState());
-#endif
- } else if (QApplication::activeWindow() == qwidget->window()) {
- bool focusedControlFound = false;
- WId winId = 0;
- for (QWidget *w = qwidget->parentWidget(); w && (winId = w->internalWinId()); w = w->parentWidget()) {
- if (winId->IsFocused() && winId->IsVisible()) {
- focusedControlFound = true;
- break;
- } else if (w->isWindow())
- break;
- }
- if (!focusedControlFound) {
- if (CCoeEnv::Static()->AppUi()->IsDisplayingMenuOrDialog() || S60->menuBeingConstructed) {
- QWidget *fw = QApplication::focusWidget();
- if (fw) {
- QFocusEvent event(QEvent::FocusOut, Qt::PopupFocusReason);
- QCoreApplication::sendEvent(fw, &event);
- }
- m_symbianPopupIsOpen = true;
- return;
- }
-
- QApplication::setActiveWindow(0);
- }
- }
- // else { We don't touch the active window unless we were explicitly activated or deactivated }
-}
-
-void QSymbianControl::handleClientAreaChange()
-{
- const bool cbaVisibilityHint = qwidget->windowFlags() & Qt::WindowSoftkeysVisibleHint;
- if (qwidget->isFullScreen() && !cbaVisibilityHint) {
- SetExtentToWholeScreen();
- } else if (qwidget->isMaximized() || (qwidget->isFullScreen() && cbaVisibilityHint)) {
- TRect r = static_cast<CEikAppUi*>(S60->appUi())->ClientRect();
- SetExtent(r.iTl, r.Size());
- } else if (!qwidget->isMinimized()) { // Normal geometry
- if (!qwidget->testAttribute(Qt::WA_Resized)) {
- qwidget->adjustSize();
- qwidget->setAttribute(Qt::WA_Resized, false); //not a user resize
- }
- if (!qwidget->testAttribute(Qt::WA_Moved) && qwidget->windowType() != Qt::Dialog) {
- TRect r = static_cast<CEikAppUi*>(S60->appUi())->ClientRect();
- SetPosition(r.iTl);
- qwidget->setAttribute(Qt::WA_Moved, false); // not really an explicit position
- }
- }
-}
-
-bool QSymbianControl::isSplitViewWidget(QWidget *widget) {
- bool returnValue = true;
- //Ignore events sent to non-active windows, not visible widgets and not parents of input widget.
- if (!qwidget->isActiveWindow()
- || !qwidget->isVisible()
- || !qwidget->isAncestorOf(widget)) {
-
- returnValue = false;
- }
- return returnValue;
-}
-
-void QSymbianControl::HandleResourceChange(int resourceType)
-{
- switch (resourceType) {
- case KSplitViewCloseEvent: //intentional fall-through
- case KSplitViewOpenEvent: {
-#if !defined(QT_NO_IM) && defined(Q_WS_S60)
-
- //Fetch widget getting the text input
- QWidget *widget = QWidget::keyboardGrabber();
- if (!widget) {
- if (QApplicationPrivate::popupWidgets) {
- widget = QApplication::activePopupWidget()->focusWidget();
- if (!widget) {
- widget = QApplication::activePopupWidget();
- }
- } else {
- widget = QApplicationPrivate::focus_widget;
- if (!widget) {
- widget = qwidget;
- }
- }
- }
- if (widget) {
- QCoeFepInputContext *ic = qobject_cast<QCoeFepInputContext *>(widget->inputContext());
- if (!ic) {
- ic = qobject_cast<QCoeFepInputContext *>(qApp->inputContext());
- }
- if (ic && isSplitViewWidget(widget)) {
- if (resourceType == KSplitViewCloseEvent) {
- ic->resetSplitViewWidget();
- } else {
- ic->ensureFocusWidgetVisible(widget);
- }
- }
- }
-#endif // !defined(QT_NO_IM) && defined(Q_WS_S60)
- }
- break;
- case KInternalStatusPaneChange:
- // When status pane is not visible, only handle client area change if status pane was
- // previously visible, as size changes to hidden status pane should not affect
- // client area.
- if (S60->statusPane() && (S60->statusPane()->IsVisible() || m_lastStatusPaneVisibility)) {
- m_lastStatusPaneVisibility = S60->statusPane()->IsVisible();
- handleClientAreaChange();
- }
- if (IsFocused() && IsVisible()) {
- qwidget->d_func()->setWindowIcon_sys(true);
- qwidget->d_func()->setWindowTitle_sys(qwidget->windowTitle());
- }
- break;
- case KUidValueCoeFontChangeEvent:
- // font change event
- break;
-#ifdef Q_WS_S60
- case KEikDynamicLayoutVariantSwitch:
- {
- handleClientAreaChange();
- // Send resize event to trigger desktopwidget workAreaResized signal
- if (qt_desktopWidget) {
- QResizeEvent e(qt_desktopWidget->size(), qt_desktopWidget->size());
- QApplication::sendEvent(qt_desktopWidget, &e);
- }
- break;
- }
-#endif
- default:
- break;
- }
-
- CCoeControl::HandleResourceChange(resourceType);
-
-}
-void QSymbianControl::CancelLongTapTimer()
-{
- m_longTapDetector->Cancel();
-}
-
-TTypeUid::Ptr QSymbianControl::MopSupplyObject(TTypeUid id)
-{
- if (id.iUid == ETypeId)
- return id.MakePtr(this);
-
- return CCoeControl::MopSupplyObject(id);
-}
-
-void QSymbianControl::setFocusSafely(bool focus)
-{
- // The stack hack in here is very unfortunate, but it is the only way to ensure proper
- // focus in Symbian. If this is not executed, the control which happens to be on
- // the top of the stack may randomly be assigned focus by Symbian, for example
- // when creating new windows (specifically in CCoeAppUi::HandleStackChanged()).
-
- // Close any popups.
- CEikonEnv::Static()->EikAppUi()->StopDisplayingMenuBar();
-
- if (focus) {
- S60->appUi()->RemoveFromStack(this);
- // Symbian doesn't automatically remove focus from the last focused control, so we need to
- // remember it and clear focus ourselves.
- if (lastFocusedControl && lastFocusedControl != this)
- lastFocusedControl->SetFocus(false);
- QT_TRAP_THROWING(S60->appUi()->AddToStackL(this,
- ECoeStackPriorityDefault + 1, ECoeStackFlagStandard)); // Note the + 1
- lastFocusedControl = this;
- this->SetFocus(true);
- } else {
- S60->appUi()->RemoveFromStack(this);
- QT_TRAP_THROWING(S60->appUi()->AddToStackL(this,
- ECoeStackPriorityDefault, ECoeStackFlagStandard));
- if(this == lastFocusedControl)
- lastFocusedControl = 0;
- this->SetFocus(false);
- }
-}
-
-bool QSymbianControl::isControlActive()
-{
- return IsActivated() ? true : false;
-}
-
-void QSymbianControl::ensureFixNativeOrientation()
-{
-#if defined(Q_SYMBIAN_SUPPORTS_FIXNATIVEORIENTATION)
- if (!qwidget->isWindow() || qwidget->windowType() == Qt::Desktop)
- return;
- if (S60->screenNumberForWidget(qwidget) > 0)
- return;
- const bool isFixed = qwidget->d_func()->fixNativeOrientationCalled;
- const bool isFixEnabled = qwidget->testAttribute(Qt::WA_SymbianNoSystemRotation);
- const bool isFullScreen = qwidget->windowState().testFlag(Qt::WindowFullScreen);
- if (isFullScreen && isFixEnabled) {
- const bool surfaceBasedGs =
- QApplicationPrivate::graphics_system_name == QLatin1String("openvg")
- || QApplicationPrivate::graphics_system_name == QLatin1String("opengl");
- if (!surfaceBasedGs)
- qwidget->setAttribute(Qt::WA_SymbianNoSystemRotation, false);
- if (!isFixed && surfaceBasedGs) {
- if (Window().FixNativeOrientation() == KErrNone) {
- qwidget->d_func()->fixNativeOrientationCalled = true;
- // The EGL window surface is now fixed to the native orientation
- // of the device, no matter what size we pass when creating it.
- // Enforce the same size for the QWidget too. For the underlying
- // CCoeControl and RWindow it is up to the system to resize them
- // when the standard auto-rotation mechanism is in use, we must not
- // change that behavior by forcing any size for those. In practice
- // this means that the QWidget and the underlying native control
- // dimensions will be out of sync when FixNativeOrientation was
- // called and the device is turned to the non-native (typically
- // landscape) orientation. The pointer event handling and certain
- // functions like Draw() will need to compensate for this.
- QSize newSize(S60->nativeScreenWidthInPixels, S60->nativeScreenHeightInPixels);
- if (qwidget->size() != newSize)
- qwidgetResize_helper(newSize);
- } else {
- qwidget->setAttribute(Qt::WA_SymbianNoSystemRotation, false);
- }
- }
- } else if (isFixed) {
- qwidget->setAttribute(Qt::WA_SymbianNoSystemRotation, false);
- qwidget->d_func()->fixNativeOrientationCalled = false;
- qwidget->hide();
- qwidget->d_func()->create_sys(0, false, true);
- qwidget->show();
- }
-#else
- qwidget->setAttribute(Qt::WA_SymbianNoSystemRotation, false);
-#endif
-}
-
-/*!
- \typedef QApplication::QS60MainApplicationFactory
- \since 4.6
-
- This is a typedef for a pointer to a function with the following
- signature:
-
- \snippet doc/src/snippets/code/src_corelib_global_qglobal.cpp 47
-
- \sa QApplication::QApplication()
-*/
-
-/*!
- \since 4.6
-
- Creates an application using the application factory given in
- \a factory, and using \a argc command line arguments in \a argv.
- \a factory can be leaving, but the error will be converted to a
- standard exception.
-
- This function is only available on S60.
-*/
-QApplication::QApplication(QApplication::QS60MainApplicationFactory factory, int &argc, char **argv)
- : QCoreApplication(*new QApplicationPrivate(argc, argv, GuiClient, 0x040000))
-{
- Q_D(QApplication);
- S60->s60ApplicationFactory = factory;
- d->construct();
-}
-
-QApplication::QApplication(QApplication::QS60MainApplicationFactory factory, int &argc, char **argv, int _internal)
- : QCoreApplication(*new QApplicationPrivate(argc, argv, GuiClient, _internal))
-{
- Q_D(QApplication);
- S60->s60ApplicationFactory = factory;
- d->construct();
- QApplicationPrivate::app_compile_version = _internal;
-}
-
-void qt_init(QApplicationPrivate * /* priv */, int)
-{
- if (!CCoeEnv::Static()) {
- // The S60 framework creates a new trap handler which will render any existing traps
- // invalid as long as it is active. This means that all code in main() that occurs after
- // the QApplication construction needs to be surrounded by a new trap, despite having
- // an outer one already. To avoid this, we save the original trap handler here, and set
- // it back after the S60 framework is constructed. Then we restore it right before the S60
- // framework destruction.
- TTrapHandler *origTrapHandler = User::TrapHandler();
-
- // The S60 framework has not been initialized. We need to do it.
- TApaApplicationFactory factory(S60->s60ApplicationFactory ?
- S60->s60ApplicationFactory : newS60Application);
- CApaCommandLine* commandLine = q_check_ptr(QCoreApplicationPrivate::symbianCommandLine());
- if (commandLine) {
- // After this construction, CEikonEnv will be available from CEikonEnv::Static().
- // (much like our qApp).
- QtEikonEnv* coe = new QtEikonEnv;
- //not using QT_TRAP_THROWING, because coe owns the cleanupstack so it can't be pushed there.
- TRAPD(err, coe->ConstructAppFromCommandLineL(factory, *commandLine));
- if(err != KErrNone) {
- qWarning() << "qt_init: Eikon application construct failed ("
- << err
- << "), maybe missing resource file on S60 3.1?";
- delete coe;
- qt_symbian_throwIfError(err);
- }
- }
-
- S60->s60InstalledTrapHandler = User::SetTrapHandler(origTrapHandler);
-
- S60->qtOwnsS60Environment = true;
- } else {
- S60->qtOwnsS60Environment = false;
- }
-
-#ifdef QT_NO_DEBUG
- if (!qgetenv("QT_S60_AUTO_FLUSH_WSERV").isEmpty())
-#endif
- S60->wsSession().SetAutoFlush(ETrue);
-
-#ifdef Q_SYMBIAN_WINDOW_SIZE_CACHE
- TRAP_IGNORE(S60->wsSession().EnableWindowSizeCacheL());
-#endif
-
- S60->updateScreenSize();
-
-
- TDisplayMode mode = S60->screenDevice()->DisplayMode();
- S60->screenDepth = TDisplayModeUtils::NumDisplayModeBitsPerPixel(mode);
-
- //NB: RWsSession::GetColorModeList tells you what window modes are supported,
- //not what bitmap formats.
- if(QSysInfo::symbianVersion() == QSysInfo::SV_9_2)
- S60->supportsPremultipliedAlpha = 0;
- else
- S60->supportsPremultipliedAlpha = 1;
-
- RProcess me;
- TSecureId securId = me.SecureId();
- S60->uid = securId.operator TUid();
-
- // enable focus events - used to re-enable mouse after focus changed between mouse and non mouse app,
- // and for dimming behind modal windows
- S60->windowGroup().EnableFocusChangeEvents();
-
- //Check if mouse interaction is supported (either EMouse=1 in the HAL, or EMachineUID is one of the phones known to support this)
- const TInt KMachineUidSamsungI8510 = 0x2000C51E;
- // HAL::Get(HALData::EPen, TInt& result) may set 'result' to 1 on some 3.1 systems (e.g. N95).
- // But we know that S60 systems below 5.0 did not support touch.
- static const bool touchIsUnsupportedOnSystem =
- QSysInfo::s60Version() == QSysInfo::SV_S60_3_1
- || QSysInfo::s60Version() == QSysInfo::SV_S60_3_2;
- TInt machineUID;
- TInt mouse;
- TInt touch;
- TInt err;
- err = HAL::Get(HALData::EMouse, mouse);
- if (err != KErrNone)
- mouse = 0;
- err = HAL::Get(HALData::EMachineUid, machineUID);
- if (err != KErrNone)
- machineUID = 0;
- err = HAL::Get(HALData::EPen, touch);
- if (err != KErrNone || touchIsUnsupportedOnSystem)
- touch = 0;
-#ifdef __WINS__
- if(QSysInfo::symbianVersion() <= QSysInfo::SV_9_4) {
- //for symbian SDK emulator, force values to match typical devices.
- mouse = 0;
- touch = touchIsUnsupportedOnSystem ? 0 : 1;
- }
-#endif
- if (mouse || machineUID == KMachineUidSamsungI8510) {
- S60->hasTouchscreen = false;
- S60->virtualMouseRequired = false;
- }
- else if (!touch) {
- S60->hasTouchscreen = false;
- S60->virtualMouseRequired = true;
- }
- else {
- S60->hasTouchscreen = true;
- S60->virtualMouseRequired = false;
- }
-
- S60->avkonComponentsSupportTransparency = false;
- S60->menuBeingConstructed = false;
-
-#ifdef Q_WS_S60
- TUid KCRUidAvkon = { 0x101F876E };
- TUint32 KAknAvkonTransparencyEnabled = 0x0000000D;
-
- CRepository* repository = 0;
- TRAP(err, repository = CRepository::NewL(KCRUidAvkon));
-
- if(err == KErrNone) {
- TInt value = 0;
- err = repository->Get(KAknAvkonTransparencyEnabled, value);
- if(err == KErrNone) {
- S60->avkonComponentsSupportTransparency = (value==1) ? true : false;
- }
- }
- delete repository;
- repository = 0;
-#endif
-
- qt_keymapper_private()->updateInputLanguage();
-
-#ifdef QT_KEYPAD_NAVIGATION
- if (touch) {
- QApplicationPrivate::navigationMode = Qt::NavigationModeNone;
- } else {
- QApplicationPrivate::navigationMode = Qt::NavigationModeKeypadDirectional;
- }
-#endif
-
-#ifndef QT_NO_CURSOR
- //Check if window server pointer cursors are supported or not
-#ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
- //In generic binary, use the HAL and OS version
- //Any other known good phones should be added here.
- if (machineUID == KMachineUidSamsungI8510 || (QSysInfo::symbianVersion() != QSysInfo::SV_9_4
- && QSysInfo::symbianVersion() != QSysInfo::SV_9_3 && QSysInfo::symbianVersion()
- != QSysInfo::SV_9_2)) {
- S60->brokenPointerCursors = false;
- qt_symbian_setWindowGroupCursor(Qt::ArrowCursor, S60->windowGroup());
- }
- else
- S60->brokenPointerCursors = true;
-#endif
-
- if (S60->mouseInteractionEnabled) {
-#ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
- if (S60->brokenPointerCursors) {
- qt_symbian_set_pointer_sprite(Qt::ArrowCursor);
- qt_symbian_show_pointer_sprite();
- }
- else
-#endif
- S60->wsSession().SetPointerCursorMode(EPointerCursorNormal);
- }
-#endif
-
- QFont systemFont;
- systemFont.setFamily(systemFont.defaultFamily());
- QApplicationPrivate::setSystemFont(systemFont);
-
- QObject::connect(qApp, SIGNAL(aboutToQuit()), qApp, SLOT(_q_aboutToQuit()));
-
-#ifdef Q_SYMBIAN_SEMITRANSPARENT_BG_SURFACE
- QApplicationPrivate::instance()->useTranslucentEGLSurfaces = true;
-
- const TUid KIvePropertyCat = {0x2726beef};
- enum TIvePropertyChipType {
- EVCBCM2727B1 = 0x00000000,
- EVCBCM2763A0 = 0x04000100,
- EVCBCM2763B0 = 0x04000102,
- EVCBCM2763C0 = 0x04000103,
- EVCBCM2763C1 = 0x04000104,
- EVCBCMUnknown = 0x7fffffff
- };
-
- TInt chipType = EVCBCMUnknown;
- if (RProperty::Get(KIvePropertyCat, 0 /*chip type*/, chipType) == KErrNone) {
- if (chipType == EVCBCM2727B1) {
- // We have only 32MB GPU memory. Use raster surfaces
- // for transparent TLWs.
- QApplicationPrivate::instance()->useTranslucentEGLSurfaces = false;
- }
- } else {
- QApplicationPrivate::instance()->useTranslucentEGLSurfaces = false;
- }
- if (QApplicationPrivate::graphics_system_name == QLatin1String("raster"))
- QApplicationPrivate::instance()->useTranslucentEGLSurfaces = false;
-#else
- QApplicationPrivate::instance()->useTranslucentEGLSurfaces = false;
-#endif
-/*
- ### Commented out for now as parameter handling not needed in SOS(yet). Code below will break testlib with -o flag
- int argc = priv->argc;
- char **argv = priv->argv;
-
- // Get command line params
- int j = argc ? 1 : 0;
- for (int i=1; i<argc; i++) {
- if (argv[i] && *argv[i] != '-') {
- argv[j++] = argv[i];
- continue;
- }
-
-#if defined(QT_DEBUG)
- if (qstrcmp(argv[i], "-nograb") == 0)
- appNoGrab = !appNoGrab;
- else
-#endif // QT_DEBUG
- ;
- }
-*/
-
- // Register WId with the metatype system. This is to enable
- // QWidgetPrivate::create_sys to used delayed slot invocation in order
- // to destroy WId objects during reparenting.
- qRegisterMetaType<WId>("WId");
-}
-
-#ifdef QT_NO_FREETYPE
-extern void qt_cleanup_symbianFontDatabase(); // qfontdatabase_s60.cpp
-#endif
-
-/*****************************************************************************
- qt_cleanup() - cleans up when the application is finished
- *****************************************************************************/
-void qt_cleanup()
-{
-#ifdef Q_WS_S60
- S60->setButtonGroupContainer(0);
-#endif
- if(qt_S60Beep) {
- delete qt_S60Beep;
- qt_S60Beep = 0;
- }
- QFontCache::cleanup(); // Has to happen now, since QFontEngineS60 has FBS handles
- QPixmapCache::clear(); // Has to happen now, since QS60PixmapData has FBS handles
-
-#ifdef QT_NO_FREETYPE
- qt_cleanup_symbianFontDatabase();
-#endif
-// S60 structure and window server session are freed in eventdispatcher destructor as they are needed there
-
- // It's important that this happens here, before the event dispatcher gets
- // deleted, because the input context needs the event loop one last time before
- // it dies.
- delete QApplicationPrivate::inputContext;
- QApplicationPrivate::inputContext = 0;
-
- //Change mouse pointer back
- S60->wsSession().SetPointerCursorMode(EPointerCursorNone);
-
-#ifdef Q_WS_S60
- // Clear CBA
- CEikonEnv::Static()->AppUiFactory()->SwapButtonGroup(0);
- delete S60->buttonGroupContainer();
- S60->setButtonGroupContainer(0);
-#endif
-
- // Call EndFullScreen() to prevent confusing the system effect state machine.
- qt_endFullScreenEffect();
-
- if (S60->qtOwnsS60Environment) {
- // Restore the S60 framework trap handler. See qt_init().
- User::SetTrapHandler(S60->s60InstalledTrapHandler);
-
- CEikonEnv* coe = CEikonEnv::Static();
- coe->PrepareToExit();
- // The CEikonEnv itself is destroyed in here.
- coe->DestroyEnvironment();
- }
-}
-
-void QApplicationPrivate::initializeWidgetPaletteHash()
-{
- // TODO: Implement QApplicationPrivate::initializeWidgetPaletteHash()
- // Possibly a task fot the S60Style guys
-}
-
-void QApplicationPrivate::createEventDispatcher()
-{
- Q_Q(QApplication);
- eventDispatcher = new QEventDispatcherS60(q);
-}
-
-QString QApplicationPrivate::appName() const
-{
- return QCoreApplicationPrivate::appName();
-}
-
-bool QApplicationPrivate::modalState()
-{
- return app_do_modal;
-}
-
-void QApplicationPrivate::enterModal_sys(QWidget *widget)
-{
-#ifdef Q_SYMBIAN_TRANSITION_EFFECTS
- S60->wsSession().SendEffectCommand(ETfxCmdAppModalModeEnter);
-#endif
- if (widget) {
- static_cast<QSymbianControl *>(widget->effectiveWinId())->FadeBehindPopup(ETrue);
- // Modal partial screen dialogs (like queries) capture pointer events.
- // ### FixMe: Add specialized behaviour for fullscreen modal dialogs
- widget->effectiveWinId()->SetGloballyCapturing(ETrue);
- widget->effectiveWinId()->SetPointerCapture(ETrue);
- }
- if (!qt_modal_stack)
- qt_modal_stack = new QWidgetList;
- qt_modal_stack->insert(0, widget);
- app_do_modal = true;
-}
-
-void QApplicationPrivate::leaveModal_sys(QWidget *widget)
-{
-#ifdef Q_SYMBIAN_TRANSITION_EFFECTS
- S60->wsSession().SendEffectCommand(ETfxCmdAppModalModeExit);
-#endif
- if (widget) {
- static_cast<QSymbianControl *>(widget->effectiveWinId())->FadeBehindPopup(EFalse);
- // ### FixMe: Add specialized behaviour for fullscreen modal dialogs
- widget->effectiveWinId()->SetGloballyCapturing(EFalse);
- widget->effectiveWinId()->SetPointerCapture(EFalse);
- }
- if (qt_modal_stack && qt_modal_stack->removeAll(widget)) {
- if (qt_modal_stack->isEmpty()) {
- delete qt_modal_stack;
- qt_modal_stack = 0;
- }
- }
- app_do_modal = qt_modal_stack != 0;
-}
-
-void QApplicationPrivate::openPopup(QWidget *popup)
-{
- if (popup && qobject_cast<QComboBox *>(popup->parentWidget()))
- static_cast<QSymbianControl *>(popup->effectiveWinId())->FadeBehindPopup(ETrue);
-
- if (!QApplicationPrivate::popupWidgets)
- QApplicationPrivate::popupWidgets = new QWidgetList;
- QApplicationPrivate::popupWidgets->append(popup);
-
- // Cancel focus widget pointer capture and long tap timer
- if (QApplication::focusWidget()) {
- static_cast<QSymbianControl*>(QApplication::focusWidget()->effectiveWinId())->CancelLongTapTimer();
- QApplication::focusWidget()->effectiveWinId()->SetPointerCapture(false);
- }
-
- if (!qt_nograb()) {
- // Cancel pointer capture and long tap timer for earlier popup
- int popupCount = QApplicationPrivate::popupWidgets->count();
- if (popupCount > 1) {
- QWidget* prevPopup = QApplicationPrivate::popupWidgets->at(popupCount-2);
- static_cast<QSymbianControl*>(prevPopup->effectiveWinId())->CancelLongTapTimer();
- prevPopup->effectiveWinId()->SetPointerCapture(false);
- }
-
- // Enable pointer capture for this (topmost) popup
- Q_ASSERT(popup->testAttribute(Qt::WA_WState_Created));
- WId id = popup->effectiveWinId();
- id->SetPointerCapture(true);
- }
-
- // popups are not focus-handled by the window system (the first
- // popup grabbed the keyboard), so we have to do that manually: A
- // new popup gets the focus
- QWidget *fw = popup->focusWidget();
- if (fw) {
- fw->setFocus(Qt::PopupFocusReason);
- } else if (QApplicationPrivate::popupWidgets->count() == 1) { // this was the first popup
- fw = QApplication::focusWidget();
- if (fw) {
- QFocusEvent e(QEvent::FocusOut, Qt::PopupFocusReason);
- q_func()->sendEvent(fw, &e);
- }
- }
-}
-
-void QApplicationPrivate::closePopup(QWidget *popup)
-{
- if (popup && qobject_cast<QComboBox *>(popup->parentWidget()))
- static_cast<QSymbianControl *>(popup->effectiveWinId())->FadeBehindPopup(EFalse);
-
- if (!QApplicationPrivate::popupWidgets)
- return;
- QApplicationPrivate::popupWidgets->removeAll(popup);
-
- // Cancel pointer capture and long tap for this popup
- WId id = popup->effectiveWinId();
- id->SetPointerCapture(false);
- static_cast<QSymbianControl*>(id)->CancelLongTapTimer();
-
- if (QApplicationPrivate::popupWidgets->isEmpty()) { // this was the last popup
- delete QApplicationPrivate::popupWidgets;
- QApplicationPrivate::popupWidgets = 0;
- if (!qt_nograb()) { // grabbing not disabled
- Q_ASSERT(popup->testAttribute(Qt::WA_WState_Created));
- if (QWidgetPrivate::mouseGrabber != 0)
- QWidgetPrivate::mouseGrabber->grabMouse();
-
- if (QWidgetPrivate::keyboardGrabber != 0)
- QWidgetPrivate::keyboardGrabber->grabKeyboard();
-
- QWidget *fw = QApplicationPrivate::active_window ? QApplicationPrivate::active_window->focusWidget()
- : q_func()->focusWidget();
- if (fw) {
- if(fw->window()->isModal()) // restore pointer capture for modal window
- fw->effectiveWinId()->SetPointerCapture(true);
-
- if (fw != q_func()->focusWidget()) {
- fw->setFocus(Qt::PopupFocusReason);
- } else {
- QFocusEvent e(QEvent::FocusIn, Qt::PopupFocusReason);
- q_func()->sendEvent(fw, &e);
- }
- }
- }
- } else {
-
- // popups are not focus-handled by the window system (the
- // first popup grabbed the keyboard), so we have to do that
- // manually: A popup was closed, so the previous popup gets
- // the focus.
- QWidget* aw = QApplicationPrivate::popupWidgets->last();
- if (QWidget *fw = QApplication::focusWidget()) {
- QFocusEvent e(QEvent::FocusOut, Qt::PopupFocusReason);
- q_func()->sendEvent(fw, &e);
- }
-
- // Enable pointer capture for previous popup
- if (aw) {
- aw->effectiveWinId()->SetPointerCapture(true);
- }
- }
-}
-
-QWidget * QApplication::topLevelAt(QPoint const& point)
-{
- QWidget *found = 0;
- int lowestZ = INT_MAX;
- QWidgetList list = QApplication::topLevelWidgets();
- for (int i = 0; i < list.count(); ++i) {
- QWidget *widget = list.at(i);
- if (widget->isVisible() && !(widget->windowType() == Qt::Desktop)) {
- Q_ASSERT(widget->testAttribute(Qt::WA_WState_Created));
- if (widget->geometry().adjusted(0,0,1,1).contains(point)) {
- // At this point we know there is a Qt widget under the point.
- // Now we need to make sure it is the top most in the z-order.
- RDrawableWindow *const window = widget->effectiveWinId()->DrawableWindow();
- int z = window->OrdinalPosition();
- if (z < lowestZ) {
- lowestZ = z;
- found = widget;
- }
- }
- }
- }
- return found;
-}
-
-void QApplication::alert(QWidget * /* widget */, int /* duration */)
-{
- // TODO: Implement QApplication::alert(QWidget *widget, int duration)
-}
-
-int QApplication::doubleClickInterval()
-{
- TTimeIntervalMicroSeconds32 us;
- TInt distance;
- S60->wsSession().GetDoubleClickSettings(us, distance);
- return (us.Int() / 1000);
-}
-
-void QApplication::setDoubleClickInterval(int ms)
-{
- TTimeIntervalMicroSeconds32 newUs( ms * 1000);
- TTimeIntervalMicroSeconds32 us;
- TInt distance;
- S60->wsSession().GetDoubleClickSettings(us, distance);
- if (us != newUs)
- S60->wsSession().SetDoubleClick(newUs, distance);
-}
-
-int QApplication::keyboardInputInterval()
-{
- return QApplicationPrivate::keyboard_input_time;
-}
-
-void QApplication::setKeyboardInputInterval(int ms)
-{
- QApplicationPrivate::keyboard_input_time = ms;
-}
-
-int QApplication::cursorFlashTime()
-{
- return QApplicationPrivate::cursor_flash_time;
-}
-
-void QApplication::setCursorFlashTime(int msecs)
-{
- QApplicationPrivate::cursor_flash_time = msecs;
-}
-
-void QApplication::beep()
-{
- if (!qt_S60Beep) {
- TInt frequency = 880;
- TTimeIntervalMicroSeconds duration(500000);
- TRAP_IGNORE(qt_S60Beep=QS60Beep::NewL(frequency, duration));
- }
- if (qt_S60Beep)
- qt_S60Beep->Play();
-}
-
-static inline bool callSymbianEventFilters(const QSymbianEvent *event)
-{
- long unused;
- return qApp->filterEvent(const_cast<QSymbianEvent *>(event), &unused);
-}
-
-/*!
- \warning This function is only available on Symbian.
- \since 4.6
-
- This function processes an individual Symbian event
- \a event. It returns 1 if the event was handled, 0 if
- the \a event was not handled, and -1 if the event was
- not handled because the event is not known to Qt.
- */
-
-int QApplication::symbianProcessEvent(const QSymbianEvent *event)
-{
- Q_D(QApplication);
-
- QScopedLoopLevelCounter counter(d->threadData);
-
- if (d->eventDispatcher->filterEvent(const_cast<QSymbianEvent *>(event)))
- return 1;
-
- QWidget *w = qApp ? qApp->focusWidget() : 0;
- if (w) {
- QInputContext *ic = w->inputContext();
- if (ic && ic->symbianFilterEvent(w, event))
- return 1;
- }
-
- if (symbianEventFilter(event))
- return 1;
-
- switch (event->type()) {
- case QSymbianEvent::WindowServerEvent:
- return d->symbianProcessWsEvent(event);
- case QSymbianEvent::CommandEvent:
- return d->symbianHandleCommand(event);
- case QSymbianEvent::ResourceChangeEvent:
- return d->symbianResourceChange(event);
- default:
- return -1;
- }
-}
-
-int QApplicationPrivate::symbianProcessWsEvent(const QSymbianEvent *symbianEvent)
-{
- // Qt event handling. Handle some events regardless of if the handle is in our
- // widget map or not.
- const TWsEvent *event = symbianEvent->windowServerEvent();
- CCoeControl* control = reinterpret_cast<CCoeControl*>(event->Handle());
- const bool controlInMap = QWidgetPrivate::mapper && QWidgetPrivate::mapper->contains(control);
- switch (event->Type()) {
- case EEventPointerEnter:
- if (controlInMap) {
- callSymbianEventFilters(symbianEvent);
- return 1; // Qt::Enter will be generated in HandlePointerL
- }
- break;
- case EEventPointerExit:
- if (controlInMap) {
- if (callSymbianEventFilters(symbianEvent))
- return 1;
- if (S60) {
- // mouseEvent outside our window, send leave event to last focused widget
- QMouseEvent mEvent(QEvent::Leave, S60->lastPointerEventPos, S60->lastCursorPos,
- Qt::NoButton, QApplicationPrivate::mouse_buttons, Qt::NoModifier);
- if (S60->lastPointerEventTarget)
- qt_sendSpontaneousEvent(S60->lastPointerEventTarget,&mEvent);
- S60->lastPointerEventTarget = 0;
- }
- return 1;
- }
- break;
- case EEventScreenDeviceChanged: // fallthrough
-#if defined(Q_SYMBIAN_SUPPORTS_MULTIPLE_SCREENS)
- case EEventDisplayChanged:
-#endif
- if (callSymbianEventFilters(symbianEvent))
- return 1;
- if (S60)
- S60->updateScreenSize();
- if (qt_desktopWidget) {
- QSize oldSize = qt_desktopWidget->size();
- qt_desktopWidget->data->crect.setWidth(S60->screenWidthInPixels);
- qt_desktopWidget->data->crect.setHeight(S60->screenHeightInPixels);
- QResizeEvent e(qt_desktopWidget->size(), oldSize);
- QApplication::sendEvent(qt_desktopWidget, &e);
- }
- return 0; // Propagate to CONE
- case EEventWindowVisibilityChanged:
- if (controlInMap) {
- if (callSymbianEventFilters(symbianEvent))
- return 1;
- const TWsVisibilityChangedEvent *visChangedEvent = event->VisibilityChanged();
- if (visChangedEvent->iFlags & TWsVisibilityChangedEvent::ENotVisible)
- S60->controlVisibilityChanged(control, false);
- else if (visChangedEvent->iFlags & TWsVisibilityChangedEvent::EPartiallyVisible)
- S60->controlVisibilityChanged(control, true);
- return 1;
- }
- break;
- case EEventFocusGained:
- if (callSymbianEventFilters(symbianEvent))
- return 1;
-#ifndef QT_NO_CURSOR
- //re-enable mouse interaction
- if (S60->mouseInteractionEnabled) {
-#ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
- if (S60->brokenPointerCursors)
- qt_symbian_show_pointer_sprite();
- else
-#endif
- S60->wsSession().SetPointerCursorMode(EPointerCursorNormal);
- }
-#endif
-#ifdef QT_SOFTKEYS_ENABLED
- if (!CEikonEnv::Static()->EikAppUi()->IsDisplayingMenuOrDialog())
- QSoftKeyManager::updateSoftKeys();
-#endif
- break;
- case EEventFocusLost:
- if (callSymbianEventFilters(symbianEvent))
- return 1;
-#ifndef QT_NO_CURSOR
- //disable mouse as may be moving to application that does not support it
- if (S60->mouseInteractionEnabled) {
-#ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
- if (S60->brokenPointerCursors)
- qt_symbian_hide_pointer_sprite();
- else
-#endif
- S60->wsSession().SetPointerCursorMode(EPointerCursorNone);
- }
-#endif
- break;
- case KGoomMemoryLowEvent:
-#ifdef QT_DEBUG
- qDebug() << "QApplicationPrivate::symbianProcessWsEvent - KGoomMemoryLowEvent";
-#endif
- if (callSymbianEventFilters(symbianEvent))
- return 1;
-#ifdef QT_GRAPHICSSYSTEM_RUNTIME
- if(QApplicationPrivate::runtime_graphics_system) {
- bool switchToSwRendering(false);
-
- foreach (QWidget *w, QApplication::topLevelWidgets()) {
- if(w->d_func()->topData()->backingStore) {
- switchToSwRendering = true;
- break;
- }
- }
-
- if (switchToSwRendering) {
- QRuntimeGraphicsSystem *gs =
- static_cast<QRuntimeGraphicsSystem*>(QApplicationPrivate::graphics_system);
- gs->setGraphicsSystem(QLatin1String("raster"));
- }
- }
-#endif
- break;
- case KGoomMemoryGoodEvent:
-#ifdef QT_DEBUG
- qDebug() << "QApplicationPrivate::symbianProcessWsEvent - KGoomMemoryGoodEvent";
-#endif
- if (callSymbianEventFilters(symbianEvent))
- return 1;
-#ifdef QT_GRAPHICSSYSTEM_RUNTIME
- if(QApplicationPrivate::runtime_graphics_system) {
- QRuntimeGraphicsSystem *gs =
- static_cast<QRuntimeGraphicsSystem*>(QApplicationPrivate::graphics_system);
- gs->setGraphicsSystem(QLatin1String("openvg"));
- }
-#endif
- break;
-#ifdef Q_SYMBIAN_SUPPORTS_SURFACES
- case EEventUser:
- {
- // GOOM is looking for candidates to kill so indicate that we are
- // capable of cleaning up by handling this event
- TInt32 *data = reinterpret_cast<TInt32 *>(event->EventData());
- if (data[0] == EApaSystemEventShutdown && data[1] == KGoomMemoryLowEvent)
- return 1;
- }
- break;
-#endif
-
-#ifdef Q_WS_S60
- case KEikInputLanguageChange:
- qt_keymapper_private()->updateInputLanguage();
- break;
-#endif
-
- default:
- break;
- }
-
- if (!controlInMap)
- return -1;
-
- return 0;
-}
-
-/*!
- \warning This virtual function is only available on Symbian.
- \since 4.6
-
- If you create an application that inherits QApplication and reimplement
- this function, you get direct access to events that the are received
- from Symbian. The events are passed in the \a event parameter.
-
- Return true if you want to stop the event from being processed. Return
- false for normal event dispatching. The default implementation returns
- false, and does nothing with \a event.
- */
-bool QApplication::symbianEventFilter(const QSymbianEvent *event)
-{
- Q_UNUSED(event);
- return false;
-}
-
-/*!
- \warning This function is only available on Symbian.
- \since 4.6
-
- Handles \a{command}s which are typically handled by
- CAknAppUi::HandleCommandL(). Qts Ui integration into Symbian is
- partially achieved by deriving from CAknAppUi. Currently, exit,
- menu and softkey commands are handled.
-
- \sa s60EventFilter(), s60ProcessEvent()
-*/
-int QApplicationPrivate::symbianHandleCommand(const QSymbianEvent *symbianEvent)
-{
- Q_Q(QApplication);
- int ret = 0;
-
- if (callSymbianEventFilters(symbianEvent))
- return 1;
-
- int command = symbianEvent->command();
-
- switch (command) {
-#ifdef Q_WS_S60
- case EAknSoftkeyExit: {
- QCloseEvent ev;
- QApplication::sendSpontaneousEvent(q, &ev);
- if (ev.isAccepted()) {
- q->quit();
- ret = 1;
- }
- break;
- }
-#endif
- case EEikCmdExit:
- q->quit();
- ret = 1;
- break;
- default:
-#ifdef Q_WS_S60
- bool handled = QSoftKeyManager::handleCommand(command);
- if (handled)
- ret = 1;
- else
- ret = QMenuBarPrivate::symbianCommands(command);
-#endif
- break;
- }
-
- return ret;
-}
-
-/*!
- \warning This function is only available on Symbian.
- \since 4.6
-
- Handles the resource change specified by \a type.
-
- Currently, KEikDynamicLayoutVariantSwitch and
- KAknsMessageSkinChange are handled.
- */
-int QApplicationPrivate::symbianResourceChange(const QSymbianEvent *symbianEvent)
-{
- int ret = 0;
-
- int type = symbianEvent->resourceChangeType();
-
- switch (type) {
-#ifdef Q_WS_S60
- case KEikDynamicLayoutVariantSwitch:
- {
- if (callSymbianEventFilters(symbianEvent))
- return 1;
- if (S60)
- S60->updateScreenSize();
-
-#ifndef QT_NO_STYLE_S60
- QS60Style *s60Style = 0;
-
-#ifndef QT_NO_STYLE_STYLESHEET
- QStyleSheetStyle *proxy = qobject_cast<QStyleSheetStyle*>(QApplication::style());
- if (proxy)
- s60Style = qobject_cast<QS60Style*>(proxy->baseStyle());
- else
-#endif
- s60Style = qobject_cast<QS60Style*>(QApplication::style());
-
- if (s60Style) {
- s60Style->d_func()->handleDynamicLayoutVariantSwitch();
- ret = 1;
- }
-#endif
- }
- break;
-
-#ifndef QT_NO_STYLE_S60
- case KAknsMessageSkinChange:
- if (callSymbianEventFilters(symbianEvent))
- return 1;
- if (QS60Style *s60Style = qobject_cast<QS60Style*>(QApplication::style())) {
- s60Style->d_func()->handleSkinChange();
- ret = 1;
- }
- break;
-#endif
-#endif // Q_WS_S60
- default:
- break;
- }
-
- return ret;
-}
-
-#ifndef QT_NO_WHEELEVENT
-int QApplication::wheelScrollLines()
-{
- return QApplicationPrivate::wheel_scroll_lines;
-}
-
-void QApplication::setWheelScrollLines(int n)
-{
- QApplicationPrivate::wheel_scroll_lines = n;
-}
-#endif //QT_NO_WHEELEVENT
-
-bool QApplication::isEffectEnabled(Qt::UIEffect /* effect */)
-{
- // TODO: Implement QApplication::isEffectEnabled(Qt::UIEffect effect)
- return false;
-}
-
-void QApplication::setEffectEnabled(Qt::UIEffect /* effect */, bool /* enable */)
-{
- // TODO: Implement QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable)
-}
-
-TUint QApplicationPrivate::resolveS60ScanCode(TInt scanCode, TUint keysym)
-{
- if (!scanCode)
- return keysym;
-
- QApplicationPrivate *d = QApplicationPrivate::instance();
-
- if (keysym) {
- // If keysym is specified, cache it.
- d->scanCodeCache.insert(scanCode, keysym);
- return keysym;
- } else {
- // If not, retrieve the cached version.
- return d->scanCodeCache[scanCode];
- }
-}
-
-void QApplicationPrivate::initializeMultitouch_sys()
-{
-#ifdef QT_SYMBIAN_SUPPORTS_ADVANCED_POINTER
- if (HAL::Get(HALData::EPointer3DPressureSupported, pressureSupported) != KErrNone)
- pressureSupported = 0;
- if (HAL::Get(HALData::EPointer3DMaxPressure, maxTouchPressure) != KErrNone)
- maxTouchPressure = KMaxTInt;
-#else
- pressureSupported = 0;
- maxTouchPressure = KMaxTInt;
-#endif
-}
-
-void QApplicationPrivate::cleanupMultitouch_sys()
-{ }
-
-#ifndef QT_NO_SESSIONMANAGER
-QSessionManager::QSessionManager(QApplication * /* app */, QString & /* id */, QString& /* key */)
-{
-
-}
-
-QSessionManager::~QSessionManager()
-{
-
-}
-
-bool QSessionManager::allowsInteraction()
-{
- return false;
-}
-
-void QSessionManager::cancel()
-{
-
-}
-#endif //QT_NO_SESSIONMANAGER
-
-#ifdef QT_KEYPAD_NAVIGATION
-/*
- * Show/Hide the mouse cursor depending on phone type and chosen mode
- */
-void QApplicationPrivate::setNavigationMode(Qt::NavigationMode mode)
-{
-#ifndef QT_NO_CURSOR
- const bool wasCursorOn = (QApplicationPrivate::navigationMode == Qt::NavigationModeCursorAuto
- && !S60->hasTouchscreen)
- || QApplicationPrivate::navigationMode == Qt::NavigationModeCursorForceVisible;
- const bool isCursorOn = (mode == Qt::NavigationModeCursorAuto
- && !S60->hasTouchscreen)
- || mode == Qt::NavigationModeCursorForceVisible;
-
- if (!wasCursorOn && isCursorOn) {
- //Show the cursor, when changing from another mode to cursor mode
- qt_symbian_set_cursor_visible(true);
- }
- else if (wasCursorOn && !isCursorOn) {
- //Hide the cursor, when leaving cursor mode
- qt_symbian_set_cursor_visible(false);
- }
-#endif
- QApplicationPrivate::navigationMode = mode;
-}
-#endif
-
-#ifndef QT_NO_CURSOR
-/*****************************************************************************
- QApplication cursor stack
- *****************************************************************************/
-
-void QApplication::setOverrideCursor(const QCursor &cursor)
-{
- qApp->d_func()->cursor_list.prepend(cursor);
- qt_symbian_setGlobalCursor(cursor);
-}
-
-void QApplication::restoreOverrideCursor()
-{
- if (qApp->d_func()->cursor_list.isEmpty())
- return;
- qApp->d_func()->cursor_list.removeFirst();
-
- if (!qApp->d_func()->cursor_list.isEmpty()) {
- qt_symbian_setGlobalCursor(qApp->d_func()->cursor_list.first());
- }
- else {
- //determine which widget has focus
- QWidget *w = QApplication::widgetAt(QCursor::pos());
-#ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
- if (S60->brokenPointerCursors) {
- qt_symbian_set_pointer_sprite(w ? w->cursor() : Qt::ArrowCursor);
- }
- 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()) {
- ctrl->DrawableWindow()->ClearPointerCursor();
- }
- }
- if (w)
- qt_symbian_setWindowCursor(w->cursor(), w->effectiveWinId());
- else
- qt_symbian_setWindowGroupCursor(Qt::ArrowCursor, S60->windowGroup());
- }
- }
-}
-
-#endif // QT_NO_CURSOR
-
-void QApplicationPrivate::_q_aboutToQuit()
-{
- qt_beginFullScreenEffect();
-
-#ifdef Q_SYMBIAN_TRANSITION_EFFECTS
- // Send the shutdown tfx command
- S60->wsSession().SendEffectCommand(ETfxCmdAppShutDown);
-#endif
-}
-
-QS60ThreadLocalData::QS60ThreadLocalData()
-{
- CCoeEnv *env = CCoeEnv::Static();
- if (env) {
- //if this is the UI thread, share objects owned by CONE
- usingCONEinstances = true;
- wsSession = env->WsSession();
- screenDevice = env->ScreenDevice();
- }
- else {
- usingCONEinstances = false;
- qt_symbian_throwIfError(wsSession.Connect(qt_s60GetRFs()));
- screenDevice = new CWsScreenDevice(wsSession);
- screenDevice->Construct();
- }
-}
-
-QS60ThreadLocalData::~QS60ThreadLocalData()
-{
- if (!usingCONEinstances) {
- delete screenDevice;
- wsSession.Close();
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp
deleted file mode 100644
index 72a05afbd0..0000000000
--- a/src/gui/kernel/qapplication_win.cpp
+++ /dev/null
@@ -1,4243 +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$
-**
-****************************************************************************/
-
-#ifdef Q_WS_WINCE
-#include "qguifunctions_wince.h"
-#include "qmenubar.h"
-extern bool qt_wince_is_mobile(); //defined in qguifunctions_wince.cpp
-extern bool qt_wince_is_high_dpi(); //defined in qguifunctions_wince.cpp
-extern bool qt_wince_is_smartphone(); //defined in qguifunctions_wince.cpp
-extern bool qt_wince_is_pocket_pc(); //defined in qguifunctions_wince.cpp
-extern void qt_wince_hide_taskbar(HWND hwnd); //defined in qguifunctions_wince.cpp
-#endif
-#ifdef Q_WS_WINCE_WM
-#include <windowsm.h>
-#include <tpcshell.h>
-#ifdef QT_WINCE_GESTURES
-#ifndef QT_NO_GESTURES
-#include <gesture.h>
-#endif
-#endif
-#endif
-
-#include "qapplication.h"
-#include "qdesktopwidget.h"
-#include "qevent.h"
-#include "private/qeventdispatcher_win_p.h"
-#include "qeventloop.h"
-#include "qclipboard.h"
-#include "qcursor.h"
-#include "qdatetime.h"
-#include "qpointer.h"
-#include "qhash.h"
-#include "qmetaobject.h"
-#include "qmime.h"
-#include "qpainter.h"
-#include "qpixmapcache.h"
-#include "qsessionmanager.h"
-#include "qstyle.h"
-#include "qwhatsthis.h" // ######## dependency
-#include "qwidget.h"
-#include "qcolormap.h"
-#include "qlayout.h"
-#include "qtooltip.h"
-#include "qt_windows.h"
-#include "qscrollbar.h"
-#if defined(QT_NON_COMMERCIAL)
-#include "qnc_win.h"
-#endif
-#include "private/qwininputcontext_p.h"
-#include "private/qcursor_p.h"
-#include "private/qmath_p.h"
-#include "private/qapplication_p.h"
-#include "private/qbackingstore_p.h"
-#include "private/qwindowsurface_raster_p.h"
-#include "qdebug.h"
-#include <private/qkeymapper_p.h>
-#include <private/qlocale_p.h>
-#include <private/qsystemlibrary_p.h>
-#include "qevent_p.h"
-
-//#define ALIEN_DEBUG
-
-#ifndef QT_NO_THREAD
-#include "qmutex.h"
-#endif
-
-#ifndef QT_NO_ACCESSIBILITY
-#include "qaccessible.h"
-
-#include <oleacc.h>
-#ifndef WM_GETOBJECT
-#define WM_GETOBJECT 0x003D
-#endif
-#endif // QT_NO_ACCESSIBILITY
-
-#if !defined(WINABLEAPI)
-# if defined(Q_WS_WINCE)
-# include <bldver.h>
-# endif
-# if !defined(Q_WS_WINCE)
-# include <winable.h>
-# endif
-#endif
-
-#ifndef QT_NO_GESTURES
-# ifndef GID_ZOOM
-# define GID_ZOOM 3
-# define GID_TWOFINGERTAP 6
-# define GID_PRESSANDTAP 7
-# define GID_ROLLOVER GID_PRESSANDTAP
-# endif
-#endif
-
-#ifndef WM_TOUCH
-# define WM_TOUCH 0x0240
-#endif
-
-#ifndef TOUCHEVENTF_MOVE
-# define TOUCHEVENTF_MOVE 0x0001
-# define TOUCHEVENTF_DOWN 0x0002
-# define TOUCHEVENTF_UP 0x0004
-# define TOUCHEVENTF_INRANGE 0x0008
-# define TOUCHEVENTF_PRIMARY 0x0010
-# define TOUCHEVENTF_NOCOALESCE 0x0020
-# define TOUCHEVENTF_PEN 0x0040
-# define TOUCHEVENTF_PALM 0x0080
-
-# define TOUCHINPUTMASKF_TIMEFROMSYSTEM 0x0001
-# define TOUCHINPUTMASKF_EXTRAINFO 0x0002
-# define TOUCHINPUTMASKF_CONTACTAREA 0x0004
-
-typedef struct tagTOUCHINPUT
-{
- LONG x;
- LONG y;
- HANDLE hSource;
- DWORD dwID;
- DWORD dwFlags;
- DWORD dwMask;
- DWORD dwTime;
- ULONG_PTR dwExtraInfo;
- DWORD cxContact;
- DWORD cyContact;
-} TOUCHINPUT, *PTOUCHINPUT;
-
-#endif
-
-#include <windowsx.h>
-#include <limits.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <math.h>
-
-#define PACKETDATA (PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE \
- | PK_ORIENTATION | PK_CURSOR | PK_Z)
-#define PACKETMODE 0
-
-#include <wintab.h>
-#ifndef CSR_TYPE
-#define CSR_TYPE 20 // Some old Wacom wintab.h may not provide this constant.
-#endif
-#include <pktdef.h>
-
-#if defined(__CYGWIN32__)
-#define __INSIDE_CYGWIN32__
-#include <mywinsock.h>
-#endif
-
-#ifndef IMR_RECONVERTSTRING
-#define IMR_RECONVERTSTRING 4
-#endif
-
-#ifndef IMR_CONFIRMRECONVERTSTRING
-#define IMR_CONFIRMRECONVERTSTRING 0x0005
-#endif
-QT_BEGIN_NAMESPACE
-
-#ifdef Q_WS_WINCE
-#ifndef SHRG_RETURNCMD
-struct SHRGINFO {
- DWORD cbSize;
- HWND hwndClient;
- POINT ptDown;
- DWORD dwFlags;
-};
-#define GN_CONTEXTMENU 1000
-#define SHRG_RETURNCMD 0x00000001
-#define SHRG_NOANIMATION 0x00000010
-#endif
-
-#ifndef SPI_SETSIPINFO
-#define SPI_SETSIPINFO 224
-#endif
-
-#ifndef QT_NO_GESTURES
-typedef DWORD (API *AygRecognizeGesture)(SHRGINFO*);
-static AygRecognizeGesture ptrRecognizeGesture = 0;
-static bool aygResolved = false;
-static void resolveAygLibs()
-{
- if (!aygResolved) {
- aygResolved = true;
- QSystemLibrary ayglib(QLatin1String("aygshell"));
- ptrRecognizeGesture = (AygRecognizeGesture) ayglib.resolve("SHRecognizeGesture");
- }
-}
-#endif // QT_NO_GESTURES
-
-#endif
-
-#ifndef SPI_SETFONTSMOOTHINGTYPE
-# define SPI_SETFONTSMOOTHINGTYPE 0x200B
-#endif
-#ifndef SPI_GETFONTSMOOTHINGTYPE
-# define SPI_GETFONTSMOOTHINGTYPE 0x200A
-#endif
-#ifndef FE_FONTSMOOTHINGCLEARTYPE
-# define FE_FONTSMOOTHINGCLEARTYPE 0x0002
-#endif
-
-Q_GUI_EXPORT qreal qt_fontsmoothing_gamma;
-Q_GUI_EXPORT bool qt_cleartype_enabled;
-Q_GUI_EXPORT bool qt_win_owndc_required; // CS_OWNDC is required if we use the GL graphicssystem as default
-
-typedef HCTX (API *PtrWTOpen)(HWND, LPLOGCONTEXT, BOOL);
-typedef BOOL (API *PtrWTClose)(HCTX);
-typedef UINT (API *PtrWTInfo)(UINT, UINT, LPVOID);
-typedef BOOL (API *PtrWTEnable)(HCTX, BOOL);
-typedef BOOL (API *PtrWTOverlap)(HCTX, BOOL);
-typedef int (API *PtrWTPacketsGet)(HCTX, int, LPVOID);
-typedef BOOL (API *PtrWTGet)(HCTX, LPLOGCONTEXT);
-typedef int (API *PtrWTQueueSizeGet)(HCTX);
-typedef BOOL (API *PtrWTQueueSizeSet)(HCTX, int);
-
-static PtrWTInfo ptrWTInfo = 0;
-static PtrWTEnable ptrWTEnable = 0;
-static PtrWTOverlap ptrWTOverlap = 0;
-static PtrWTPacketsGet ptrWTPacketsGet = 0;
-static PtrWTGet ptrWTGet = 0;
-
-static PACKET localPacketBuf[QT_TABLET_NPACKETQSIZE]; // our own tablet packet queue.
-HCTX qt_tablet_context; // the hardware context for the tablet (like a window handle)
-bool qt_tablet_tilt_support;
-
-#ifndef QT_NO_TABLETEVENT
-static void tabletInit(const quint64 uniqueId, const UINT csr_type, HCTX hTab);
-static void tabletUpdateCursor(QTabletDeviceData &tdd, const UINT currentCursor);
-static void initWinTabFunctions(); // resolve the WINTAB api functions
-#endif // QT_NO_TABLETEVENT
-
-
-#ifndef QT_NO_ACCESSIBILITY
-extern IAccessible *qt_createWindowsAccessible(QAccessibleInterface *object);
-#endif // QT_NO_ACCESSIBILITY
-
-extern bool qt_tabletChokeMouse;
-extern QWidget* qt_get_tablet_widget();
-extern bool qt_sendSpontaneousEvent(QObject*, QEvent*);
-extern QRegion qt_dirtyRegion(QWidget *);
-
-typedef QHash<quint64, QTabletDeviceData> QTabletCursorInfo;
-Q_GLOBAL_STATIC(QTabletCursorInfo, tCursorInfo)
-QTabletDeviceData currentTabletPointer;
-
-// from qregion_win.cpp
-extern HRGN qt_tryCreateRegion(QRegion::RegionType type, int left, int top, int right, int bottom);
-
-// support for on-the-fly changes of the XP theme engine
-#ifndef WM_THEMECHANGED
-#define WM_THEMECHANGED 0x031A
-#endif
-#ifndef COLOR_MENUHILIGHT
-#define COLOR_MENUHILIGHT 29
-#define COLOR_MENUBAR 30
-#endif
-
-// support for xbuttons
-#ifndef WM_XBUTTONDOWN
-#define WM_XBUTTONDOWN 0x020B
-#define WM_XBUTTONUP 0x020C
-#define WM_XBUTTONDBLCLK 0x020D
-#endif
-#ifndef GET_KEYSTATE_WPARAM
-#define GET_KEYSTATE_WPARAM(wParam) (LOWORD(wParam))
-#define GET_XBUTTON_WPARAM(wParam) (HIWORD(wParam))
-#define XBUTTON1 0x0001
-#define XBUTTON2 0x0002
-#endif
-#ifndef MK_XBUTTON1
-#define MK_XBUTTON1 0x0020
-#define MK_XBUTTON2 0x0040
-#endif
-
-// support for multi-media-keys
-#ifndef WM_APPCOMMAND
-#define WM_APPCOMMAND 0x0319
-#endif
-
-#ifndef FAPPCOMMAND_MOUSE
-#define FAPPCOMMAND_MOUSE 0x8000
-#define FAPPCOMMAND_KEY 0
-#define FAPPCOMMAND_OEM 0x1000
-#define FAPPCOMMAND_MASK 0xF000
-#define GET_APPCOMMAND_LPARAM(lParam) ((short)(HIWORD(lParam) & ~FAPPCOMMAND_MASK))
-#define GET_DEVICE_LPARAM(lParam) ((WORD)(HIWORD(lParam) & FAPPCOMMAND_MASK))
-#define GET_MOUSEORKEY_LPARAM GET_DEVICE_LPARAM
-#define GET_FLAGS_LPARAM(lParam) (LOWORD(lParam))
-#define GET_KEYSTATE_LPARAM(lParam) GET_FLAGS_LPARAM(lParam)
-
-#define APPCOMMAND_BROWSER_BACKWARD 1
-#define APPCOMMAND_BROWSER_FORWARD 2
-#define APPCOMMAND_BROWSER_REFRESH 3
-#define APPCOMMAND_BROWSER_STOP 4
-#define APPCOMMAND_BROWSER_SEARCH 5
-#define APPCOMMAND_BROWSER_FAVORITES 6
-#define APPCOMMAND_BROWSER_HOME 7
-#define APPCOMMAND_VOLUME_MUTE 8
-#define APPCOMMAND_VOLUME_DOWN 9
-#define APPCOMMAND_VOLUME_UP 10
-#define APPCOMMAND_MEDIA_NEXTTRACK 11
-#define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
-#define APPCOMMAND_MEDIA_STOP 13
-#define APPCOMMAND_MEDIA_PLAY_PAUSE 14
-#define APPCOMMAND_LAUNCH_MAIL 15
-#define APPCOMMAND_LAUNCH_MEDIA_SELECT 16
-#define APPCOMMAND_LAUNCH_APP1 17
-#define APPCOMMAND_LAUNCH_APP2 18
-#define APPCOMMAND_BASS_DOWN 19
-#define APPCOMMAND_BASS_BOOST 20
-#define APPCOMMAND_BASS_UP 21
-#define APPCOMMAND_TREBLE_DOWN 22
-#define APPCOMMAND_TREBLE_UP 23
-#endif // FAPPCOMMAND_MOUSE
-
-// New commands from Windows XP (some even Sp1)
-#ifndef APPCOMMAND_MICROPHONE_VOLUME_MUTE
-#define APPCOMMAND_MICROPHONE_VOLUME_MUTE 24
-#define APPCOMMAND_MICROPHONE_VOLUME_DOWN 25
-#define APPCOMMAND_MICROPHONE_VOLUME_UP 26
-#define APPCOMMAND_HELP 27
-#define APPCOMMAND_FIND 28
-#define APPCOMMAND_NEW 29
-#define APPCOMMAND_OPEN 30
-#define APPCOMMAND_CLOSE 31
-#define APPCOMMAND_SAVE 32
-#define APPCOMMAND_PRINT 33
-#define APPCOMMAND_UNDO 34
-#define APPCOMMAND_REDO 35
-#define APPCOMMAND_COPY 36
-#define APPCOMMAND_CUT 37
-#define APPCOMMAND_PASTE 38
-#define APPCOMMAND_REPLY_TO_MAIL 39
-#define APPCOMMAND_FORWARD_MAIL 40
-#define APPCOMMAND_SEND_MAIL 41
-#define APPCOMMAND_SPELL_CHECK 42
-#define APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE 43
-#define APPCOMMAND_MIC_ON_OFF_TOGGLE 44
-#define APPCOMMAND_CORRECTION_LIST 45
-#define APPCOMMAND_MEDIA_PLAY 46
-#define APPCOMMAND_MEDIA_PAUSE 47
-#define APPCOMMAND_MEDIA_RECORD 48
-#define APPCOMMAND_MEDIA_FAST_FORWARD 49
-#define APPCOMMAND_MEDIA_REWIND 50
-#define APPCOMMAND_MEDIA_CHANNEL_UP 51
-#define APPCOMMAND_MEDIA_CHANNEL_DOWN 52
-#endif // APPCOMMAND_MICROPHONE_VOLUME_MUTE
-
-#if (_WIN32_WINNT < 0x0400)
-// This struct is defined in winuser.h if the _WIN32_WINNT >= 0x0400 -- in the
-// other cases we have to define it on our own.
-typedef struct tagTRACKMOUSEEVENT {
- DWORD cbSize;
- DWORD dwFlags;
- HWND hwndTrack;
- DWORD dwHoverTime;
-} TRACKMOUSEEVENT, *LPTRACKMOUSEEVENT;
-#endif
-#ifndef WM_MOUSELEAVE
-#define WM_MOUSELEAVE 0x02A3
-#endif
-
-QT_BEGIN_INCLUDE_NAMESPACE
-#include "private/qwidget_p.h"
-QT_END_INCLUDE_NAMESPACE
-
-static int translateButtonState(int s, int type, int button);
-
-// ##### get rid of this!
-QRgb qt_colorref2qrgb(COLORREF col)
-{
- return qRgb(GetRValue(col),GetGValue(col),GetBValue(col));
-}
-
-
-/*****************************************************************************
- Internal variables and functions
- *****************************************************************************/
-
-static HWND curWin = 0; // current window
-static HDC displayDC = 0; // display device context
-
-// Session management
-static bool sm_blockUserInput = false;
-static bool sm_smActive = false;
-extern QSessionManager* qt_session_manager_self;
-static bool sm_cancel;
-
-static bool replayPopupMouseEvent = false; // replay handling when popups close
-
-// ignore the next release event if return from a modal widget
-Q_GUI_EXPORT bool qt_win_ignoreNextMouseReleaseEvent = false;
-
-
-#if defined(QT_DEBUG)
-static bool appNoGrab = false; // mouse/keyboard grabbing
-#endif
-
-static bool app_do_modal = false; // modal mode
-extern QWidgetList *qt_modal_stack;
-extern QDesktopWidget *qt_desktopWidget;
-static QPointer<QWidget> popupButtonFocus;
-static bool qt_try_modal(QWidget *, MSG *, int& ret);
-
-QWidget *qt_button_down = 0; // widget got last button-down
-QPointer<QWidget> qt_last_mouse_receiver = 0;
-
-static HWND autoCaptureWnd = 0;
-static HWND imeParentWnd = 0;
-static void setAutoCapture(HWND); // automatic capture
-static void releaseAutoCapture();
-
-static void unregWinClasses();
-
-extern QCursor *qt_grab_cursor();
-
-#if defined(Q_WS_WIN)
-#define __export
-#endif
-
-extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND, UINT, WPARAM, LPARAM);
-
-class QETWidget : public QWidget // event translator widget
-{
-public:
- QWExtra *xtra() { return d_func()->extraData(); }
- QTLWExtra *topData() { return d_func()->topData(); }
- QTLWExtra *maybeTopData() { return d_func()->maybeTopData(); }
- void syncBackingStore(const QRegion &rgn) { d_func()->syncBackingStore(rgn); }
- void syncBackingStore() { d_func()->syncBackingStore(); }
- QWidgetData *dataPtr() { return data; }
- QWidgetPrivate *dptr() { return d_func(); }
- QRect frameStrut() const { return d_func()->frameStrut(); }
- bool winEvent(MSG *m, long *r) { return QWidget::winEvent(m, r); }
- void markFrameStrutDirty() { data->fstrut_dirty = 1; }
- bool translateMouseEvent(const MSG &msg);
- bool translateWheelEvent(const MSG &msg);
- bool translatePaintEvent(const MSG &msg);
- bool translateConfigEvent(const MSG &msg);
- bool translateCloseEvent(const MSG &msg);
- bool translateTabletEvent(const MSG &msg, PACKET *localPacketBuf, int numPackets);
-#ifndef QT_NO_GESTURES
- bool translateGestureEvent(const MSG &msg, const GESTUREINFO &gi);
-#endif
- void repolishStyle(QStyle &style);
- inline void showChildren(bool spontaneous) { d_func()->showChildren(spontaneous); }
- inline void hideChildren(bool spontaneous) { d_func()->hideChildren(spontaneous); }
- inline uint testWindowState(uint teststate){ return dataPtr()->window_state & teststate; }
- inline void setWindowTitle_helper(const QString &title) { d_func()->setWindowTitle_helper(title); }
- inline void forceUpdate() {
- QTLWExtra *tlwExtra = window()->d_func()->maybeTopData();
- if (tlwExtra && tlwExtra->backingStore)
- tlwExtra->backingStore->markDirty(rect(), this, true, true);
- }
-};
-
-// need to get default font?
-extern bool qt_app_has_font;
-
-extern QFont qt_LOGFONTtoQFont(LOGFONT& lf,bool scale);
-
-static void qt_set_windows_color_resources()
-{
- // Do the color settings
- QPalette pal;
- pal.setColor(QPalette::WindowText,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_WINDOWTEXT))));
- pal.setColor(QPalette::Button,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_BTNFACE))));
- pal.setColor(QPalette::Light,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_BTNHIGHLIGHT))));
- pal.setColor(QPalette::Dark,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_BTNSHADOW))));
- pal.setColor(QPalette::Mid, pal.button().color().darker(150));
- pal.setColor(QPalette::Text,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_WINDOWTEXT))));
- pal.setColor(QPalette::BrightText,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_BTNHIGHLIGHT))));
- pal.setColor(QPalette::Base,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_WINDOW))));
- pal.setColor(QPalette::Window,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_BTNFACE))));
- pal.setColor(QPalette::ButtonText,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_BTNTEXT))));
- pal.setColor(QPalette::Midlight,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_3DLIGHT))));
- pal.setColor(QPalette::Shadow,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_3DDKSHADOW))));
- pal.setColor(QPalette::Highlight,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_HIGHLIGHT))));
- pal.setColor(QPalette::HighlightedText,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_HIGHLIGHTTEXT))));
-
-#if defined(Q_WS_WINCE)
- // ### hardcoded until I find out how to get it from the system settings.
- pal.setColor(QPalette::LinkVisited, pal.highlight().color().dark(150));
- pal.setColor(QPalette::Link, pal.highlight().color().light(130));
- // Background == Base on Windows CE
- if (qt_wince_is_smartphone() || qt_wince_is_pocket_pc())
- pal.setColor(QPalette::Background, pal.base().color());
-#else
- pal.setColor(QPalette::Link, Qt::blue);
- pal.setColor(QPalette::LinkVisited, Qt::magenta);
-#endif
-
-
-
- pal.setColor(QPalette::Inactive, QPalette::Button, pal.button().color());
- pal.setColor(QPalette::Inactive, QPalette::Window, pal.background().color());
- pal.setColor(QPalette::Inactive, QPalette::Light, pal.light().color());
- pal.setColor(QPalette::Inactive, QPalette::Dark, pal.dark().color());
-
- if (pal.midlight() == pal.button())
- pal.setColor(QPalette::Midlight, pal.button().color().lighter(110));
- if (pal.background() != pal.base()) {
- pal.setColor(QPalette::Inactive, QPalette::Highlight, pal.color(QPalette::Inactive, QPalette::Window));
- pal.setColor(QPalette::Inactive, QPalette::HighlightedText, pal.color(QPalette::Inactive, QPalette::Text));
- }
-
- const QColor bg = pal.background().color();
- const QColor fg = pal.foreground().color(), btn = pal.button().color();
- QColor disabled((fg.red()+btn.red())/2,(fg.green()+btn.green())/2,
- (fg.blue()+btn.blue())/2);
- pal.setColorGroup(QPalette::Disabled, pal.foreground(), pal.button(), pal.light(),
- pal.dark(), pal.mid(), pal.text(), pal.brightText(), pal.base(), pal.background() );
- pal.setColor(QPalette::Disabled, QPalette::WindowText, disabled);
- pal.setColor(QPalette::Disabled, QPalette::Text, disabled);
- pal.setColor(QPalette::Disabled, QPalette::ButtonText, disabled);
- pal.setColor(QPalette::Disabled, QPalette::Highlight,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_HIGHLIGHT))));
- pal.setColor(QPalette::Disabled, QPalette::HighlightedText,
- QColor(qt_colorref2qrgb(GetSysColor(COLOR_HIGHLIGHTTEXT))));
- pal.setColor(QPalette::Disabled, QPalette::Base, bg);
-
- QApplicationPrivate::setSystemPalette(pal);
-
- QApplicationPrivate::initializeWidgetPaletteHash();
-
- QColor ttip(qt_colorref2qrgb(GetSysColor(COLOR_INFOBK)));
-
- QColor ttipText(qt_colorref2qrgb(GetSysColor(COLOR_INFOTEXT)));
- {
-#ifndef QT_NO_TOOLTIP
- QPalette tiplabel(pal);
- tiplabel.setColor(QPalette::All, QPalette::Button, ttip);
- tiplabel.setColor(QPalette::All, QPalette::Window, ttip);
- tiplabel.setColor(QPalette::All, QPalette::Text, ttipText);
- tiplabel.setColor(QPalette::All, QPalette::WindowText, ttipText);
- tiplabel.setColor(QPalette::All, QPalette::ButtonText, ttipText);
- tiplabel.setColor(QPalette::All, QPalette::Button, ttip);
- tiplabel.setColor(QPalette::All, QPalette::Window, ttip);
- tiplabel.setColor(QPalette::All, QPalette::Text, ttipText);
- tiplabel.setColor(QPalette::All, QPalette::WindowText, ttipText);
- tiplabel.setColor(QPalette::All, QPalette::ButtonText, ttipText);
- const QColor fg = tiplabel.foreground().color(), btn = tiplabel.button().color();
- QColor disabled((fg.red()+btn.red())/2,(fg.green()+btn.green())/2,
- (fg.blue()+btn.blue())/2);
- tiplabel.setColor(QPalette::Disabled, QPalette::WindowText, disabled);
- tiplabel.setColor(QPalette::Disabled, QPalette::Text, disabled);
- tiplabel.setColor(QPalette::Disabled, QPalette::Base, Qt::white);
- tiplabel.setColor(QPalette::Disabled, QPalette::BrightText, Qt::white);
- QToolTip::setPalette(tiplabel);
-#endif //QT_NO_TOOLTIP
- }
-}
-
-static void qt_set_windows_font_resources()
-{
-#ifndef Q_WS_WINCE
- NONCLIENTMETRICS ncm;
- ncm.cbSize = FIELD_OFFSET(NONCLIENTMETRICS, lfMessageFont) + sizeof(LOGFONT);
- SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncm.cbSize , &ncm, 0);
-
- QFont menuFont = qt_LOGFONTtoQFont(ncm.lfMenuFont, true);
- QFont messageFont = qt_LOGFONTtoQFont(ncm.lfMessageFont, true);
- QFont statusFont = qt_LOGFONTtoQFont(ncm.lfStatusFont, true);
- QFont titleFont = qt_LOGFONTtoQFont(ncm.lfCaptionFont, true);
-
- LOGFONT lfIconTitleFont;
- SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lfIconTitleFont), &lfIconTitleFont, 0);
- QFont iconTitleFont = qt_LOGFONTtoQFont(lfIconTitleFont, true);
-
- QApplication::setFont(menuFont, "QMenu");
- QApplication::setFont(menuFont, "QMenuBar");
- QApplication::setFont(messageFont, "QMessageBox");
- QApplication::setFont(statusFont, "QTipLabel");
- QApplication::setFont(statusFont, "QStatusBar");
- QApplication::setFont(titleFont, "Q3TitleBar");
- QApplication::setFont(titleFont, "QWorkspaceTitleBar");
- QApplication::setFont(iconTitleFont, "QAbstractItemView");
- QApplication::setFont(iconTitleFont, "QDockWidgetTitle");
-
-#else
- LOGFONT lf;
- HGDIOBJ stockFont = GetStockObject(SYSTEM_FONT);
- GetObject(stockFont, sizeof(lf), &lf);
- QFont systemFont = qt_LOGFONTtoQFont(lf, true);
- QApplicationPrivate::setSystemFont(systemFont);
- QFont smallerFont = systemFont;
- if (qt_wince_is_mobile()) {
- smallerFont.setPointSize(systemFont.pointSize()-1);
- QApplication::setFont(smallerFont, "QTabBar");
- smallerFont.setBold(true);
- QApplication::setFont(smallerFont, "QAbstractButton");
- }
-#endif// Q_WS_WINCE
-}
-
-static void qt_win_read_cleartype_settings()
-{
- UINT result = 0;
-#ifdef Q_OS_WINCE
- if (SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &result, 0))
- qt_cleartype_enabled = result;
-#else
- if (SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &result, 0))
- qt_cleartype_enabled = (result == FE_FONTSMOOTHINGCLEARTYPE);
-#endif
-
- int winSmooth;
- if (SystemParametersInfo(0x200C /* SPI_GETFONTSMOOTHINGCONTRAST */, 0, &winSmooth, 0)) {
- qt_fontsmoothing_gamma = winSmooth / qreal(1000.0);
- } else {
- qt_fontsmoothing_gamma = 1.0;
- }
-
- // Safeguard ourselves against corrupt registry values...
- if (qt_fontsmoothing_gamma > 5 || qt_fontsmoothing_gamma < 1)
- qt_fontsmoothing_gamma = qreal(1.4);
-}
-
-static void qt_set_windows_resources()
-{
- if (QApplication::type() != QApplication::Tty)
- (void) QApplication::style(); // trigger creation of application style
- qt_set_windows_font_resources();
- qt_set_windows_color_resources();
-}
-
-void QApplicationPrivate::initializeWidgetPaletteHash()
-{
- QPalette pal = *QApplicationPrivate::sys_pal;
- QColor menuCol(qt_colorref2qrgb(GetSysColor(COLOR_MENU)));
- QColor menuText(qt_colorref2qrgb(GetSysColor(COLOR_MENUTEXT)));
- BOOL isFlat = false;
- if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
- && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
- SystemParametersInfo(SPI_GETFLATMENU, 0, &isFlat, 0);
- QPalette menu(pal);
- // we might need a special color group for the menu.
- menu.setColor(QPalette::Active, QPalette::Button, menuCol);
- menu.setColor(QPalette::Active, QPalette::Text, menuText);
- menu.setColor(QPalette::Active, QPalette::WindowText, menuText);
- menu.setColor(QPalette::Active, QPalette::ButtonText, menuText);
- const QColor fg = menu.foreground().color(), btn = menu.button().color();
- QColor disabled(qt_colorref2qrgb(GetSysColor(COLOR_GRAYTEXT)));
- menu.setColor(QPalette::Disabled, QPalette::WindowText, disabled);
- menu.setColor(QPalette::Disabled, QPalette::Text, disabled);
- menu.setColor(QPalette::Disabled, QPalette::Highlight,
- QColor(qt_colorref2qrgb(GetSysColor(
- (QSysInfo::WindowsVersion >= QSysInfo::WV_XP
- && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)
- && isFlat ? COLOR_MENUHILIGHT : COLOR_HIGHLIGHT))));
- menu.setColor(QPalette::Disabled, QPalette::HighlightedText, disabled);
- menu.setColor(QPalette::Disabled, QPalette::Button,
- menu.color(QPalette::Active, QPalette::Button));
- menu.setColor(QPalette::Inactive, QPalette::Button,
- menu.color(QPalette::Active, QPalette::Button));
- menu.setColor(QPalette::Inactive, QPalette::Text,
- menu.color(QPalette::Active, QPalette::Text));
- menu.setColor(QPalette::Inactive, QPalette::WindowText,
- menu.color(QPalette::Active, QPalette::WindowText));
- menu.setColor(QPalette::Inactive, QPalette::ButtonText,
- menu.color(QPalette::Active, QPalette::ButtonText));
- menu.setColor(QPalette::Inactive, QPalette::Highlight,
- menu.color(QPalette::Active, QPalette::Highlight));
- menu.setColor(QPalette::Inactive, QPalette::HighlightedText,
- menu.color(QPalette::Active, QPalette::HighlightedText));
- menu.setColor(QPalette::Inactive, QPalette::ButtonText,
- pal.color(QPalette::Inactive, QPalette::Dark));
- QApplication::setPalette(menu, "QMenu");
-
- if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
- && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based) && isFlat) {
- QColor menubar(qt_colorref2qrgb(GetSysColor(COLOR_MENUBAR)));
- menu.setColor(QPalette::Active, QPalette::Button, menubar);
- menu.setColor(QPalette::Disabled, QPalette::Button, menubar);
- menu.setColor(QPalette::Inactive, QPalette::Button, menubar);
- }
- QApplication::setPalette(menu, "QMenuBar");
-}
-
-static void qt_set_windows_updateScrollBar(QWidget *widget)
-{
- QList<QObject*> children = widget->children();
- for (int i = 0; i < children.size(); ++i) {
- QObject *o = children.at(i);
- if(!o->isWidgetType())
- continue;
- if (QWidget *w = static_cast<QWidget *>(o))
- qt_set_windows_updateScrollBar(w);
- }
-#ifndef QT_NO_SCROLLBAR
- if (qobject_cast<QScrollBar*>(widget))
- widget->updateGeometry();
-#endif
-}
-
-
-/*****************************************************************************
- qt_init() - initializes Qt for Windows
- *****************************************************************************/
-
-typedef BOOL (WINAPI *PtrSetProcessDPIAware) (VOID);
-static PtrSetProcessDPIAware ptrSetProcessDPIAware = 0;
-PtrUpdateLayeredWindow ptrUpdateLayeredWindow = 0;
-PtrUpdateLayeredWindowIndirect ptrUpdateLayeredWindowIndirect = 0;
-static BOOL WINAPI qt_updateLayeredWindowIndirect(HWND hwnd, const Q_UPDATELAYEREDWINDOWINFO *info)
-{
- return (*ptrUpdateLayeredWindow)(hwnd, info->hdcDst, info->pptDst, info->psize, info->hdcSrc,
- info->pptSrc, info->crKey, info->pblend, info->dwFlags);
-}
-
-void qt_init(QApplicationPrivate *priv, int)
-{
-
- int argc = priv->argc;
- char **argv = priv->argv;
- int i, j;
-
- // Get command line params
-
- j = argc ? 1 : 0;
- for (i=1; i<argc; i++) {
- if (argv[i] && *argv[i] != '-') {
- argv[j++] = argv[i];
- continue;
- }
-#if defined(QT_DEBUG)
- if (qstrcmp(argv[i], "-nograb") == 0)
- appNoGrab = !appNoGrab;
- else
-#endif // QT_DEBUG
- argv[j++] = argv[i];
- }
- if(j < priv->argc) {
- priv->argv[j] = 0;
- priv->argc = j;
- }
-
-#ifndef Q_WS_WINCE
- // No message boxes but important ones
- SetErrorMode(SetErrorMode(0) | SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
-#endif
-
-#ifndef Q_WS_WINCE
- // Initialize OLE/COM
- // S_OK means success and S_FALSE means that it has already
- // been initialized
- HRESULT r;
- r = OleInitialize(0);
- if (r != S_OK && r != S_FALSE) {
- qWarning("Qt: Could not initialize OLE (error %x)", (unsigned int)r);
- }
-#endif
-
- // Misc. initialization
-#if defined(QT_DEBUG) && !defined(Q_WS_WINCE)
- GdiSetBatchLimit(1);
-#endif
-
- // initialize key mapper
- QKeyMapper::changeKeyboard();
-
- QColormap::initialize();
- QFont::initialize();
-#ifndef QT_NO_CURSOR
- QCursorData::initialize();
-#endif
- qApp->setObjectName(priv->appName());
-
- // default font
-#ifndef Q_WS_WINCE
- HGDIOBJ stockFont = GetStockObject(DEFAULT_GUI_FONT);
-#else
- HGDIOBJ stockFont = GetStockObject(SYSTEM_FONT);
-#endif
-
- LOGFONT lf;
- GetObject(stockFont, sizeof(lf), &lf);
- QFont systemFont = qt_LOGFONTtoQFont(lf, true);
-
-#ifndef Q_WS_WINCE
- if (systemFont.family() == QLatin1String("MS Shell Dlg")) {
- systemFont.setFamily(QLatin1String("MS Shell Dlg 2"));
- }
-#endif
-
- QApplicationPrivate::setSystemFont(systemFont);
-
- // QFont::locale_init(); ### Uncomment when it does something on Windows
-
- if (QApplication::desktopSettingsAware())
- qt_set_windows_resources();
-
-#ifndef QT_NO_TABLETEVENT
- initWinTabFunctions();
-#endif // QT_NO_TABLETEVENT
- QApplicationPrivate::inputContext = new QWinInputContext(0);
-
- // Read the initial cleartype settings...
- qt_win_read_cleartype_settings();
- qt_win_owndc_required = false;
-
- extern void qt_win_initialize_directdraw();
- qt_win_initialize_directdraw();
-
-#ifndef Q_OS_WINCE
- ptrUpdateLayeredWindowIndirect =
- (PtrUpdateLayeredWindowIndirect) QSystemLibrary::resolve(QLatin1String("user32"),
- "UpdateLayeredWindowIndirect");
- ptrUpdateLayeredWindow =
- (PtrUpdateLayeredWindow) QSystemLibrary::resolve(QLatin1String("user32"),
- "UpdateLayeredWindow");
-
- if (ptrUpdateLayeredWindow && !ptrUpdateLayeredWindowIndirect)
- ptrUpdateLayeredWindowIndirect = qt_updateLayeredWindowIndirect;
-
- // Notify Vista and Windows 7 that we support highter DPI settings
- ptrSetProcessDPIAware = (PtrSetProcessDPIAware)
- QSystemLibrary::resolve(QLatin1String("user32"), "SetProcessDPIAware");
- if (ptrSetProcessDPIAware)
- ptrSetProcessDPIAware();
-#endif
-
-#ifndef QT_NO_GESTURES
- priv->GetGestureInfo = 0;
- priv->GetGestureExtraArgs = 0;
- priv->CloseGestureInfoHandle = 0;
- priv->SetGestureConfig = 0;
- priv->GetGestureConfig = 0;
- priv->BeginPanningFeedback = 0;
- priv->UpdatePanningFeedback = 0;
- priv->EndPanningFeedback = 0;
-
-#if defined(Q_WS_WINCE_WM) && defined(QT_WINCE_GESTURES)
- priv->GetGestureInfo = (PtrGetGestureInfo) &TKGetGestureInfo;
- priv->GetGestureExtraArgs = (PtrGetGestureExtraArgs) &TKGetGestureExtraArguments;
-#elif !defined(Q_WS_WINCE)
- #if !defined(QT_NO_NATIVE_GESTURES)
- priv->GetGestureInfo =
- (PtrGetGestureInfo)QSystemLibrary::resolve(QLatin1String("user32"),
- "GetGestureInfo");
- priv->GetGestureExtraArgs =
- (PtrGetGestureExtraArgs)QSystemLibrary::resolve(QLatin1String("user32"),
- "GetGestureExtraArgs");
- priv->CloseGestureInfoHandle =
- (PtrCloseGestureInfoHandle)QSystemLibrary::resolve(QLatin1String("user32"),
- "CloseGestureInfoHandle");
- priv->SetGestureConfig =
- (PtrSetGestureConfig)QSystemLibrary::resolve(QLatin1String("user32"),
- "SetGestureConfig");
- priv->GetGestureConfig =
- (PtrGetGestureConfig)QSystemLibrary::resolve(QLatin1String("user32"),
- "GetGestureConfig");
- #endif // QT_NO_NATIVE_GESTURES
- QSystemLibrary libTheme(QLatin1String("uxtheme"));
- priv->BeginPanningFeedback =
- (PtrBeginPanningFeedback)libTheme.resolve("BeginPanningFeedback");
- priv->UpdatePanningFeedback =
- (PtrUpdatePanningFeedback)libTheme.resolve("UpdatePanningFeedback");
- priv->EndPanningFeedback =
- (PtrEndPanningFeedback)libTheme.resolve("EndPanningFeedback");
-#endif
-#endif // QT_NO_GESTURES
-}
-
-/*****************************************************************************
- qt_cleanup() - cleans up when the application is finished
- *****************************************************************************/
-
-void qt_cleanup()
-{
- unregWinClasses();
- QPixmapCache::clear();
-
-#ifndef QT_NO_CURSOR
- QCursorData::cleanup();
-#endif
- QFont::cleanup();
- QColormap::cleanup();
- if (displayDC) {
- ReleaseDC(0, displayDC);
- displayDC = 0;
- }
-
- delete QApplicationPrivate::inputContext;
- QApplicationPrivate::inputContext = 0;
-
-#ifndef Q_WS_WINCE
- // Deinitialize OLE/COM
- OleUninitialize();
-#endif
-}
-
-
-/*****************************************************************************
- Platform specific global and internal functions
- *****************************************************************************/
-
-Q_GUI_EXPORT HDC qt_win_display_dc() // get display DC
-{
- Q_ASSERT(qApp && qApp->thread() == QThread::currentThread());
- if (!displayDC)
- displayDC = GetDC(0);
- return displayDC;
-}
-
-bool qt_nograb() // application no-grab option
-{
-#if defined(QT_DEBUG)
- return appNoGrab;
-#else
- return false;
-#endif
-}
-
-typedef QHash<QString, int> WinClassNameHash;
-Q_GLOBAL_STATIC(WinClassNameHash, winclassNames)
-
-//
-// If 0 is passed as the widget pointer, register a window class
-// for QWidget as default. This is used in QGLTemporaryContext
-// during GL initialization, where we don't want to use temporary
-// QWidgets or QGLWidgets, neither do we want to have separate code
-// to register window classes.
-//
-const QString qt_reg_winclass(QWidget *w) // register window class
-{
- Qt::WindowFlags flags = w ? w->windowFlags() : (Qt::WindowFlags)0;
- Qt::WindowFlags type = flags & Qt::WindowType_Mask;
-
- uint style;
- bool icon;
- QString cname;
- if (w && qt_widget_private(w)->isGLWidget) {
- cname = QLatin1String("QGLWidget");
- style = CS_DBLCLKS;
-#ifndef Q_WS_WINCE
- style |= CS_OWNDC;
-#endif
- icon = true;
- } else if (w && (flags & Qt::MSWindowsOwnDC)) {
- cname = QLatin1String("QWidgetOwnDC");
- style = CS_DBLCLKS;
-#ifndef Q_WS_WINCE
- style |= CS_OWNDC;
-#endif
- icon = true;
- } else if (w && (type == Qt::Tool || type == Qt::ToolTip)) {
- style = CS_DBLCLKS;
- if (w->inherits("QTipLabel") || w->inherits("QAlphaWidget")) {
- if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
- && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based)) {
- style |= CS_DROPSHADOW;
- }
- cname = QLatin1String("QToolTip");
- } else {
- cname = QLatin1String("QTool");
- }
-#ifndef Q_WS_WINCE
- style |= CS_SAVEBITS;
-#endif
- icon = false;
- } else if (w && (type == Qt::Popup)) {
- cname = QLatin1String("QPopup");
- style = CS_DBLCLKS;
-#ifndef Q_WS_WINCE
- style |= CS_SAVEBITS;
-#endif
- if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
- && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
- style |= CS_DROPSHADOW;
- icon = false;
- } else {
- cname = QLatin1String("QWidget");
- style = CS_DBLCLKS;
- icon = true;
- }
-
-#ifndef Q_WS_WINCE
- // force CS_OWNDC when the GL graphics system is
- // used as the default renderer
- if (qt_win_owndc_required)
- style |= CS_OWNDC;
-#endif
-
-#ifdef Q_OS_WINCE
- // We need to register the classes with the
- // unique ID on WinCE to make sure we can
- // move the windows to the front when starting
- // a second instance.
- wchar_t uniqueAppID[MAX_PATH];
- GetModuleFileName(0, uniqueAppID, MAX_PATH);
- cname = QString::number(RegisterWindowMessage(
- (const wchar_t *) QString::fromWCharArray(uniqueAppID).toLower().replace(QLatin1Char('\\'),
- QLatin1Char('_')).utf16()));
-#endif
-
- // since multiple Qt versions can be used in one process
- // each one has to have window class names with a unique name
- // The first instance gets the unmodified name; if the class
- // has already been registered by another instance of Qt then
- // add an instance-specific ID, the address of the window proc.
- static int classExists = -1;
-
- if (classExists == -1) {
- WNDCLASS wcinfo;
- classExists = GetClassInfo((HINSTANCE)qWinAppInst(), (wchar_t*)cname.utf16(), &wcinfo);
- classExists = classExists && wcinfo.lpfnWndProc != QtWndProc;
- }
-
- if (classExists)
- cname += QString::number((quintptr)QtWndProc);
-
- if (winclassNames()->contains(cname)) // already registered in our list
- return cname;
-
-#ifndef Q_WS_WINCE
- WNDCLASSEX wc;
- wc.cbSize = sizeof(WNDCLASSEX);
-#else
- WNDCLASS wc;
-#endif
- wc.style = style;
- wc.lpfnWndProc = (WNDPROC)QtWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = qWinAppInst();
- if (icon) {
- wc.hIcon = (HICON)LoadImage(qWinAppInst(), L"IDI_ICON1", IMAGE_ICON, 0, 0, LR_DEFAULTSIZE);
-#ifndef Q_WS_WINCE
- if (wc.hIcon) {
- int sw = GetSystemMetrics(SM_CXSMICON);
- int sh = GetSystemMetrics(SM_CYSMICON);
- wc.hIconSm = (HICON)LoadImage(qWinAppInst(), L"IDI_ICON1", IMAGE_ICON, sw, sh, 0);
- } else {
- wc.hIcon = (HICON)LoadImage(0, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
- wc.hIconSm = 0;
- }
-#endif
- } else {
- wc.hIcon = 0;
-#ifndef Q_WS_WINCE
- wc.hIconSm = 0;
-#endif
- }
- wc.hCursor = 0;
-#ifndef Q_WS_WINCE
- HBRUSH brush = 0;
- if (w && !qt_widget_private(w)->isGLWidget)
- brush = (HBRUSH)GetSysColorBrush(COLOR_WINDOW);
- wc.hbrBackground = brush;
-#else
- wc.hbrBackground = 0;
-#endif
- wc.lpszMenuName = 0;
- wc.lpszClassName = (wchar_t*)cname.utf16();
-
-#ifndef Q_WS_WINCE
- ATOM atom = RegisterClassEx(&wc);
-#else
- ATOM atom = RegisterClass(&wc);
-#endif
-
-#ifndef QT_NO_DEBUG
- if (!atom)
- qErrnoWarning("QApplication::regClass: Registering window class failed.");
-#else
- Q_UNUSED(atom);
-#endif
-
- winclassNames()->insert(cname, 1);
- return cname;
-}
-
-Q_GUI_EXPORT const QString qt_getRegisteredWndClass()
-{
- return qt_reg_winclass(0);
-}
-
-static void unregWinClasses()
-{
- WinClassNameHash *hash = winclassNames();
- QHash<QString, int>::ConstIterator it = hash->constBegin();
- while (it != hash->constEnd()) {
- UnregisterClass((wchar_t*)it.key().utf16(), qWinAppInst());
- ++it;
- }
- hash->clear();
-}
-
-
-/*****************************************************************************
- Safe configuration (move,resize,setGeometry) mechanism to avoid
- recursion when processing messages.
- *****************************************************************************/
-
-struct QWinConfigRequest {
- WId id; // widget to be configured
- int req; // 0=move, 1=resize, 2=setGeo
- int x, y, w, h; // request parameters
-};
-
-static QList<QWinConfigRequest*> *configRequests = 0;
-
-void qWinRequestConfig(WId id, int req, int x, int y, int w, int h)
-{
- if (!configRequests) // create queue
- configRequests = new QList<QWinConfigRequest*>;
- QWinConfigRequest *r = new QWinConfigRequest;
- r->id = id; // create new request
- r->req = req;
- r->x = x;
- r->y = y;
- r->w = w;
- r->h = h;
- configRequests->append(r); // store request in queue
-}
-
-static void qWinProcessConfigRequests() // perform requests in queue
-{
- if (!configRequests)
- return;
- QWinConfigRequest *r;
- for (;;) {
- if (configRequests->isEmpty())
- break;
- r = configRequests->takeLast();
- QWidget *w = QWidget::find(r->id);
- QRect rect(r->x, r->y, r->w, r->h);
- int req = r->req;
- delete r;
-
- if ( w ) { // widget exists
- if (w->testAttribute(Qt::WA_WState_ConfigPending))
- return; // biting our tail
- if (req == 0)
- w->move(rect.topLeft());
- else if (req == 1)
- w->resize(rect.size());
- else
- w->setGeometry(rect);
- }
- }
- delete configRequests;
- configRequests = 0;
-}
-
-
-/*****************************************************************************
- GUI event dispatcher
- *****************************************************************************/
-
-class QGuiEventDispatcherWin32 : public QEventDispatcherWin32
-{
- Q_DECLARE_PRIVATE(QEventDispatcherWin32)
-public:
- QGuiEventDispatcherWin32(QObject *parent = 0);
- bool processEvents(QEventLoop::ProcessEventsFlags flags);
-};
-
-QGuiEventDispatcherWin32::QGuiEventDispatcherWin32(QObject *parent)
- : QEventDispatcherWin32(parent)
-{
- createInternalHwnd();
-}
-
-bool QGuiEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags)
-{
- if (!QEventDispatcherWin32::processEvents(flags))
- return false;
-
- if (configRequests) // any pending configs?
- qWinProcessConfigRequests();
-
- return true;
-}
-
-void QApplicationPrivate::createEventDispatcher()
-{
- Q_Q(QApplication);
- if (q->type() != QApplication::Tty)
- eventDispatcher = new QGuiEventDispatcherWin32(q);
- else
- eventDispatcher = new QEventDispatcherWin32(q);
-}
-
-/*****************************************************************************
- Platform specific QApplication members
- *****************************************************************************/
-
-#ifdef QT3_SUPPORT
-void QApplication::setMainWidget(QWidget *mainWidget)
-{
- QApplicationPrivate::main_widget = mainWidget;
- if (QApplicationPrivate::main_widget && windowIcon().isNull()
- && QApplicationPrivate::main_widget->testAttribute(Qt::WA_SetWindowIcon))
- setWindowIcon(QApplicationPrivate::main_widget->windowIcon());
-}
-#endif
-
-#ifndef QT_NO_CURSOR
-
-/*****************************************************************************
- QApplication cursor stack
- *****************************************************************************/
-
-void QApplication::setOverrideCursor(const QCursor &cursor)
-{
- qApp->d_func()->cursor_list.prepend(cursor);
- SetCursor(qApp->d_func()->cursor_list.first().handle());
-}
-
-void QApplication::restoreOverrideCursor()
-{
- if (qApp->d_func()->cursor_list.isEmpty())
- return;
- qApp->d_func()->cursor_list.removeFirst();
-
- if (!qApp->d_func()->cursor_list.isEmpty()) {
- SetCursor(qApp->d_func()->cursor_list.first().handle());
- } else {
- QWidget *w = QWidget::find(curWin);
- if (w)
- SetCursor(w->cursor().handle());
- else
- SetCursor(QCursor(Qt::ArrowCursor).handle());
- }
-}
-
-#endif
-
-/*
- 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.
-*/
-
-#ifndef QT_NO_CURSOR
-void qt_win_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 (!curWin && w && w->internalWinId())
- return;
- QWidget* cW = w && !w->internalWinId() ? w : QWidget::find(curWin);
- if (!cW || cW->window() != w->window() ||
- !cW->isVisible() || !cW->underMouse() || QApplication::overrideCursor())
- return;
-
- SetCursor(cW->cursor().handle());
-}
-#endif // QT_NO_CURSOR
-
-Qt::KeyboardModifiers qt_win_getKeyboardModifiers()
-{
- Qt::KeyboardModifiers modifiers = Qt::NoModifier;
- if (GetKeyState(VK_SHIFT) < 0)
- modifiers |= Qt::ShiftModifier;
- if (GetKeyState(VK_CONTROL) < 0)
- modifiers |= Qt::ControlModifier;
- if (GetKeyState(VK_MENU) < 0)
- modifiers |= Qt::AltModifier;
- return modifiers;
-}
-
-/*****************************************************************************
- Routines to find a Qt widget from a screen position
- *****************************************************************************/
-
-QWidget *QApplication::topLevelAt(const QPoint &pos)
-{
- POINT p;
- HWND win;
- QWidget *w;
- p.x = pos.x();
- p.y = pos.y();
- win = WindowFromPoint(p);
- if (!win)
- return 0;
-
- w = QWidget::find(win);
- while (!w && win) {
- win = GetParent(win);
- w = QWidget::find(win);
- }
- return w ? w->window() : 0;
-}
-
-void QApplication::beep()
-{
- MessageBeep(MB_OK);
-}
-
-static void alert_widget(QWidget *widget, int duration)
-{
-#ifdef Q_OS_WINCE
- Q_UNUSED(widget);
- Q_UNUSED(duration);
-#else
- bool stopFlash = duration < 0;
-
- if (widget && (!widget->isActiveWindow() || stopFlash)) {
- DWORD timeOut = GetCaretBlinkTime();
- if (timeOut <= 0)
- timeOut = 250;
-
- UINT flashCount;
- if (duration == 0)
- flashCount = 10;
- else
- flashCount = duration/timeOut;
-
- FLASHWINFO info;
- info.cbSize = sizeof(info);
- info.hwnd = widget->window()->winId();
- info.dwFlags = stopFlash ? FLASHW_STOP : FLASHW_TRAY;
- info.dwTimeout = stopFlash ? 0 : timeOut;
- info.uCount = stopFlash ? 0 : flashCount;
-
- FlashWindowEx(&info);
- }
-#endif
-}
-
-void QApplication::alert(QWidget *widget, int duration)
-{
- if (!QApplicationPrivate::checkInstance("alert"))
- return;
-
- if (widget) {
- alert_widget(widget, duration);
- } else {
- const QWidgetList toplevels(topLevelWidgets());
- for (int i = 0; i < toplevels.count(); ++i) {
- QWidget *topLevel = toplevels.at(i);
- alert_widget(topLevel, duration);
- }
- }
-}
-
-QString QApplicationPrivate::appName() const
-{
- return QCoreApplicationPrivate::appName();
-}
-
-
-/*****************************************************************************
- Main event loop
- *****************************************************************************/
-
-extern uint qGlobalPostedEventsCount();
-
-void QApplication::winFocus(QWidget *widget, bool gotFocus)
-{
- if (d_func()->inPopupMode()) // some delayed focus event to ignore
- return;
- if (gotFocus) {
- setActiveWindow(widget);
- if (QApplicationPrivate::active_window
- && (QApplicationPrivate::active_window->windowType() == Qt::Dialog)) {
- // raise the entire application, not just the dialog
- QWidget* mw = QApplicationPrivate::active_window;
-#ifndef Q_WS_WINCE
- while(mw->parentWidget() && (mw->windowType() == Qt::Dialog))
- mw = mw->parentWidget()->window();
- if (mw->testAttribute(Qt::WA_WState_Created) && mw != QApplicationPrivate::active_window)
- SetWindowPos(mw->internalWinId(), HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
-#else
- // On Desktop Windows, we set the first parent of the dialog on top
- // Child windows will be automatically set above again.
- // On Windows CE we pass no parent in CreateWindowEx as otherwise
- // dialogs get embedded into the parent window. Thus we need to
- // manually iterate and reactivate all windows from bottom up.
- QList<QWidget*> raiseList;
- raiseList.push_back(mw);
- while(mw->parentWidget() && (mw->windowType() == Qt::Dialog)) {
- mw = mw->parentWidget()->window();
- raiseList.push_back(mw);
- }
- while(!raiseList.isEmpty()) {
- mw = raiseList.takeLast();
- if (mw->testAttribute(Qt::WA_WState_Created)) {
- HWND state = HWND_TOP;
- if (mw->windowFlags() & Qt::WindowStaysOnBottomHint)
- state = HWND_BOTTOM;
- else if (mw->windowFlags() & Qt::WindowStaysOnTopHint)
- state = HWND_TOPMOST;
- SetWindowPos(mw->internalWinId(), state, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
- }
- }
-#endif
- }
- } else {
- setActiveWindow(0);
- }
-}
-
-
-//
-// QtWndProc() receives all messages from the main event loop
-//
-
-static bool inLoop = false;
-static int inputcharset = CP_ACP;
-
-#define RETURN(x) { inLoop=false;return x; }
-
-static bool qt_is_translatable_mouse_event(UINT message)
-{
- return (((message >= WM_MOUSEFIRST && message <= WM_MOUSELAST) ||
- (message >= WM_XBUTTONDOWN && message <= WM_XBUTTONDBLCLK))
- && message != WM_MOUSEWHEEL
- && message != WM_MOUSEHWHEEL)
-
-#ifndef Q_WS_WINCE
- || (message >= WM_NCMOUSEMOVE && message <= WM_NCMBUTTONDBLCLK)
-#endif
- ;
-}
-
-extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
-{
- bool result = true;
- QEvent::Type evt_type = QEvent::None;
- QETWidget *widget = 0;
-
- // there is no need to process pakcets from tablet unless
- // it is actually on the tablet, a flag to let us know...
- int nPackets; // the number of packets we get from the queue
-
- long res = 0;
- if (!qApp) // unstable app state
- RETURN(QWinInputContext::DefWindowProc(hwnd,message,wParam,lParam))
-
- QScopedLoopLevelCounter loopLevelCounter(QThreadData::get2(qApp->thread()));
-
-#if 0
- // make sure we update widgets also when the user resizes
- if (inLoop && qApp->loopLevel())
- qApp->sendPostedEvents(0, QEvent::Paint);
-#endif
-
- inLoop = true;
-
- MSG msg;
- msg.hwnd = hwnd; // create MSG structure
- msg.message = message; // time and pt fields ignored
- msg.wParam = wParam;
- msg.lParam = lParam;
- msg.pt.x = GET_X_LPARAM(lParam);
- msg.pt.y = GET_Y_LPARAM(lParam);
- // If it's a non-client-area message the coords are screen coords, otherwise they are
- // client coords.
-#ifndef Q_WS_WINCE
- if (message < WM_NCMOUSEMOVE || message > WM_NCMBUTTONDBLCLK)
-#endif
- ClientToScreen(msg.hwnd, &msg.pt);
-
- /*
- // sometimes the autograb is not released, so the clickevent is sent
- // to the wrong window. We ignore this for now, because it doesn't
- // cause any problems.
- if (msg.message == WM_LBUTTONDOWN || msg.message == WM_RBUTTONDOWN || msg.message == WM_MBUTTONDOWN) {
- HWND handle = WindowFromPoint(msg.pt);
- if (msg.hwnd != handle) {
- msg.hwnd = handle;
- hwnd = handle;
- }
- }
- */
-
-#if defined(QT_NON_COMMERCIAL)
- QT_NC_WNDPROC
-#endif
-
- // send through app filter
- if (qApp->filterEvent(&msg, &res))
- return res;
-
- // close any opened ime candidate window (enabled only on a popup widget)
- if (imeParentWnd && QApplication::activePopupWidget()
- && (message == WM_MBUTTONDOWN || message == WM_XBUTTONDOWN
- || message == WM_LBUTTONDOWN || message == WM_RBUTTONDOWN
-#ifndef Q_WS_WINCE
- || message == WM_NCMBUTTONDOWN || message == WM_NCLBUTTONDOWN
- || message == WM_NCRBUTTONDOWN)) {
-#else
- )) {
-#endif
- ::SendMessage(imeParentWnd, WM_IME_ENDCOMPOSITION, 0, 0);
- }
-
- switch (message) {
-#ifndef Q_WS_WINCE
-#ifndef QT_NO_SESSIONMANAGER
- case WM_QUERYENDSESSION: {
- if (sm_smActive) // bogus message from windows
- RETURN(true);
-
- sm_smActive = true;
- sm_blockUserInput = true; // prevent user-interaction outside interaction windows
- sm_cancel = false;
- if (qt_session_manager_self)
- qApp->commitData(*qt_session_manager_self);
- if (lParam & ENDSESSION_LOGOFF) {
- _flushall();
- }
- RETURN(!sm_cancel);
- }
- case WM_ENDSESSION: {
- sm_smActive = false;
- sm_blockUserInput = false;
- bool endsession = (bool) wParam;
-
- // we receive the message for each toplevel window included internal hidden ones,
- // but the aboutToQuit signal should be emitted only once.
- QApplicationPrivate *qAppPriv = QApplicationPrivate::instance();
- if (endsession && !qAppPriv->aboutToQuitEmitted) {
- qAppPriv->aboutToQuitEmitted = true;
- int index = QApplication::staticMetaObject.indexOfSignal("aboutToQuit()");
- qApp->qt_metacall(QMetaObject::InvokeMetaMethod, index,0);
- // since the process will be killed immediately quit() has no real effect
- QApplication::quit();
- }
-
- RETURN(0);
- }
-#endif
- case WM_DISPLAYCHANGE:
- if (QApplication::type() == QApplication::Tty)
- break;
- if (qt_desktopWidget) {
- qt_desktopWidget->move(GetSystemMetrics(76), GetSystemMetrics(77));
- QSize sz(GetSystemMetrics(78), GetSystemMetrics(79));
- if (sz == qt_desktopWidget->size()) {
- // a screen resized without changing size of the virtual desktop
- QResizeEvent rs(sz, qt_desktopWidget->size());
- QApplication::sendEvent(qt_desktopWidget, &rs);
- } else {
- qt_desktopWidget->resize(sz);
- }
- }
- break;
-#endif
-
- case WM_SETTINGCHANGE:
-#ifdef Q_WS_WINCE
- // CE SIP hide/show
- if (qt_desktopWidget && wParam == SPI_SETSIPINFO) {
- QResizeEvent re(QSize(0, 0), QSize(0, 0)); // Calculated by QDesktopWidget
- QApplication::sendEvent(qt_desktopWidget, &re);
- break;
- }
-#endif
- // ignore spurious XP message when user logs in again after locking
- if (QApplication::type() == QApplication::Tty)
- break;
- if (QApplication::desktopSettingsAware() && wParam != SPI_SETWORKAREA) {
- widget = (QETWidget*)QWidget::find(hwnd);
- if (widget) {
- if (wParam == SPI_SETNONCLIENTMETRICS)
- widget->markFrameStrutDirty();
- }
- }
- else if (qt_desktopWidget && wParam == SPI_SETWORKAREA) {
- qt_desktopWidget->move(GetSystemMetrics(76), GetSystemMetrics(77));
- QSize sz(GetSystemMetrics(78), GetSystemMetrics(79));
- if (sz == qt_desktopWidget->size()) {
- // a screen resized without changing size of the virtual desktop
- QResizeEvent rs(sz, qt_desktopWidget->size());
- QApplication::sendEvent(qt_desktopWidget, &rs);
- } else {
- qt_desktopWidget->resize(sz);
- }
- }
-
- if (wParam == SPI_SETFONTSMOOTHINGTYPE) {
- qt_win_read_cleartype_settings();
- foreach (QWidget *w, QApplication::topLevelWidgets()) {
- if (!w->isVisible())
- continue;
- ((QETWidget *) w)->forceUpdate();
- }
- }
-
- break;
- case WM_SYSCOLORCHANGE:
- if (QApplication::type() == QApplication::Tty)
- break;
- if (QApplication::desktopSettingsAware()) {
- widget = (QETWidget*)QWidget::find(hwnd);
- if (widget && !widget->parentWidget())
- qt_set_windows_color_resources();
- }
- break;
-
- case WM_LBUTTONDOWN:
- case WM_MBUTTONDOWN:
- case WM_RBUTTONDOWN:
- case WM_XBUTTONDOWN:
- case WM_LBUTTONDBLCLK:
- case WM_RBUTTONDBLCLK:
- case WM_MBUTTONDBLCLK:
- case WM_XBUTTONDBLCLK:
- if (qt_win_ignoreNextMouseReleaseEvent)
- qt_win_ignoreNextMouseReleaseEvent = false;
- break;
-
- case WM_LBUTTONUP:
- case WM_MBUTTONUP:
- case WM_RBUTTONUP:
- case WM_XBUTTONUP:
- if (qt_win_ignoreNextMouseReleaseEvent) {
- qt_win_ignoreNextMouseReleaseEvent = false;
- if (qt_button_down && qt_button_down->internalWinId() == autoCaptureWnd) {
- releaseAutoCapture();
- qt_button_down = 0;
- }
-
- RETURN(0);
- }
- break;
-
- default:
- break;
- }
-
- if (!widget)
- widget = (QETWidget*)QWidget::find(hwnd);
- if (!widget) // don't know this widget
- goto do_default;
-
- if (app_do_modal) { // modal event handling
- int ret = 0;
- if (!qt_try_modal(widget, &msg, ret))
- RETURN(ret);
- }
-
- res = 0;
- if (widget->winEvent(&msg, &res)) // send through widget filter
- RETURN(res);
-
- if (qt_is_translatable_mouse_event(message)) {
- if (QApplication::activePopupWidget() != 0) { // in popup mode
- POINT curPos = msg.pt;
- QWidget* w = QApplication::widgetAt(curPos.x, curPos.y);
- if (w)
- widget = (QETWidget*)w;
- }
-
- if (!qt_tabletChokeMouse) {
- result = widget->translateMouseEvent(msg); // mouse event
-#if defined(Q_WS_WINCE) && !defined(QT_NO_CONTEXTMENU)
- if (message == WM_LBUTTONDOWN && widget != QApplication::activePopupWidget()) {
- QWidget* alienWidget = widget;
- if ((alienWidget != QApplication::activePopupWidget()) && (alienWidget->contextMenuPolicy() != Qt::PreventContextMenu)) {
- QPoint pos(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
- QPoint globalPos(msg.pt.x, msg.pt.y);
- // In case we are using Alien, then the widget to
- // send the context menu event is a different one
- if (!alienWidget->testAttribute(Qt::WA_NativeWindow) && !alienWidget->testAttribute(Qt::WA_PaintOnScreen)) {
- alienWidget = QApplication::widgetAt(globalPos);
- if (alienWidget)
- pos = alienWidget->mapFromGlobal(globalPos);
- }
- if (alienWidget) {
- SHRGINFO shrg;
- shrg.cbSize = sizeof(shrg);
- shrg.hwndClient = hwnd;
- shrg.ptDown.x = GET_X_LPARAM(lParam);
- shrg.ptDown.y = GET_Y_LPARAM(lParam);
- shrg.dwFlags = SHRG_RETURNCMD | SHRG_NOANIMATION;
- resolveAygLibs();
-#ifndef QT_NO_GESTURES
- if (ptrRecognizeGesture && (ptrRecognizeGesture(&shrg) == GN_CONTEXTMENU)) {
- if (QApplication::activePopupWidget())
- QApplication::activePopupWidget()->close();
- QContextMenuEvent e(QContextMenuEvent::Mouse, pos, globalPos);
- result = qt_sendSpontaneousEvent(alienWidget, &e);
- }
-#endif // QT_NO_GESTURES
- }
- }
- }
-#endif
- } else {
- // Sometimes we only get a WM_MOUSEMOVE message
- // and sometimes we get both a WM_MOUSEMOVE and
- // a WM_LBUTTONDOWN/UP, this creates a spurious mouse
- // press/release event, using the PeekMessage
- // will help us fix this. This leaves us with a
- // question:
- // This effectively kills using the mouse AND the
- // tablet simultaneously, well creates wacky input.
- // Is this going to be a problem? (probably not)
- bool next_is_button = false;
- bool is_mouse_move = (message == WM_MOUSEMOVE);
- if (is_mouse_move) {
- MSG msg1;
- if (PeekMessage(&msg1, msg.hwnd, WM_MOUSEFIRST,
- WM_MOUSELAST, PM_NOREMOVE))
- next_is_button = (msg1.message == WM_LBUTTONUP
- || msg1.message == WM_LBUTTONDOWN);
- }
- if (!is_mouse_move || (is_mouse_move && !next_is_button))
- qt_tabletChokeMouse = false;
- }
- } else {
- switch (message) {
- case WM_TOUCH:
- result = QApplicationPrivate::instance()->translateTouchEvent(msg);
- break;
- case WM_KEYDOWN: // keyboard event
- case WM_SYSKEYDOWN:
- qt_keymapper_private()->updateKeyMap(msg);
- // fall-through intended
- case WM_KEYUP:
- case WM_SYSKEYUP:
-#if Q_OS_WINCE_WM
- case WM_HOTKEY:
- if(HIWORD(msg.lParam) == VK_TBACK) {
- const bool hotKeyDown = !(LOWORD(msg.lParam) & MOD_KEYUP);
- msg.lParam = 0x69 << 16;
- msg.wParam = VK_BACK;
- if (hotKeyDown) {
- msg.message = WM_KEYDOWN;
- qt_keymapper_private()->updateKeyMap(msg);
- } else {
- msg.message = WM_KEYUP;
- }
- }
- // fall-through intended
-#endif
- case WM_IME_CHAR:
- case WM_IME_KEYDOWN:
- case WM_CHAR: {
- MSG msg1;
- bool anyMsg = PeekMessage(&msg1, msg.hwnd, 0, 0, PM_NOREMOVE);
- if (anyMsg && msg1.message == WM_DEADCHAR) {
- result = true; // consume event since there is a dead char next
- break;
- }
- QWidget *g = QWidget::keyboardGrabber();
- if (g && qt_get_tablet_widget() && hwnd == qt_get_tablet_widget()->winId()) {
- // if we get an event for the internal tablet widget,
- // then don't send it to the keyboard grabber, but
- // send it to the widget itself (we don't use it right
- // now, just in case).
- g = 0;
- }
- if (g)
- widget = (QETWidget*)g;
- else if (QApplication::activePopupWidget())
- widget = (QETWidget*)QApplication::activePopupWidget()->focusWidget()
- ? (QETWidget*)QApplication::activePopupWidget()->focusWidget()
- : (QETWidget*)QApplication::activePopupWidget();
- else if (QApplication::focusWidget())
- widget = (QETWidget*)QApplication::focusWidget();
- else if (!widget || widget->internalWinId() == GetFocus()) // We faked the message to go to exactly that widget.
- widget = (QETWidget*)widget->window();
- if (widget->isEnabled())
- result = sm_blockUserInput
- ? true
- : qt_keymapper_private()->translateKeyEvent(widget, msg, g != 0);
- break;
- }
- case WM_SYSCHAR:
- result = true; // consume event
- break;
-
- case WM_MOUSEWHEEL:
- case WM_MOUSEHWHEEL:
- result = widget->translateWheelEvent(msg);
- break;
-
- case WM_APPCOMMAND:
- {
- uint cmd = GET_APPCOMMAND_LPARAM(lParam);
- uint uDevice = GET_DEVICE_LPARAM(lParam);
- uint dwKeys = GET_KEYSTATE_LPARAM(lParam);
-
- int state = translateButtonState(dwKeys, QEvent::KeyPress, 0);
-
- switch (uDevice) {
- case FAPPCOMMAND_KEY:
- {
- int key = 0;
-
- switch(cmd) {
- case APPCOMMAND_BASS_BOOST:
- key = Qt::Key_BassBoost;
- break;
- case APPCOMMAND_BASS_DOWN:
- key = Qt::Key_BassDown;
- break;
- case APPCOMMAND_BASS_UP:
- key = Qt::Key_BassUp;
- break;
- case APPCOMMAND_TREBLE_DOWN:
- key = Qt::Key_TrebleDown;
- break;
- case APPCOMMAND_TREBLE_UP:
- key = Qt::Key_TrebleUp;
- break;
- case APPCOMMAND_HELP:
- key = Qt::Key_Help;
- break;
- case APPCOMMAND_FIND:
- key = Qt::Key_Search;
- break;
- default:
- break;
- }
- if (key) {
- bool res = false;
- QWidget *g = QWidget::keyboardGrabber();
- if (g)
- widget = (QETWidget*)g;
- else if (QApplication::focusWidget())
- widget = (QETWidget*)QApplication::focusWidget();
- else
- widget = (QETWidget*)widget->window();
- if (widget->isEnabled()) {
- res = QKeyMapper::sendKeyEvent(widget, g != 0, QEvent::KeyPress, key,
- Qt::KeyboardModifier(state),
- QString(), false, 0, 0, 0, 0);
- }
- if (res)
- return true;
- }
- }
- break;
-
- default:
- break;
- }
-
- result = false;
- }
- break;
-
-#ifndef Q_WS_WINCE
- case WM_NCHITTEST:
- if (widget->isWindow()) {
- QPoint pos = widget->mapFromGlobal(QPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
- // don't show resize-cursors for fixed-size widgets
- QRect fs = widget->frameStrut();
- if (!widget->isMinimized()) {
- if (widget->minimumHeight() == widget->maximumHeight()) {
- if (pos.y() < -(fs.top() - fs.left()))
- return HTCAPTION;
- if (pos.y() >= widget->height())
- return HTBORDER;
- }
- if (widget->minimumWidth() == widget->maximumWidth() && (pos.x() < 0 || pos.x() >= widget->width()))
- return HTBORDER;
- }
- }
-
- result = false;
- break;
-#endif
-
- case WM_SYSCOMMAND: {
-#ifndef Q_WS_WINCE
- bool window_state_change = false;
- Qt::WindowStates oldstate = Qt::WindowStates(widget->dataPtr()->window_state);
- // MSDN:In WM_SYSCOMMAND messages, the four low-order bits of the wParam parameter are
- // used internally by the system. To obtain the correct result when testing the value of
- // wParam, an application must combine the value 0xFFF0 with the wParam value by using
- // the bitwise AND operator.
- switch(0xfff0 & wParam) {
- case SC_CONTEXTHELP:
-#ifndef QT_NO_WHATSTHIS
- QWhatsThis::enterWhatsThisMode();
-#endif
- DefWindowProc(hwnd, WM_NCPAINT, 1, 0);
- break;
-#if defined(QT_NON_COMMERCIAL)
- QT_NC_SYSCOMMAND
-#endif
- case SC_MINIMIZE:
- window_state_change = true;
- widget->dataPtr()->window_state |= Qt::WindowMinimized;
- if (widget->isVisible()) {
- QHideEvent e;
- qt_sendSpontaneousEvent(widget, &e);
- widget->hideChildren(true);
- const QString title = widget->windowIconText();
- if (!title.isEmpty())
- widget->setWindowTitle_helper(title);
- }
- result = false;
- break;
- case SC_MAXIMIZE:
- if(widget->isWindow())
- widget->topData()->normalGeometry = widget->geometry();
- case SC_RESTORE:
- window_state_change = true;
- if ((0xfff0 & wParam) == SC_MAXIMIZE)
- widget->dataPtr()->window_state |= Qt::WindowMaximized;
- else if (!widget->isMinimized())
- widget->dataPtr()->window_state &= ~Qt::WindowMaximized;
-
- if (widget->isMinimized()) {
- widget->dataPtr()->window_state &= ~Qt::WindowMinimized;
- widget->showChildren(true);
- QShowEvent e;
- qt_sendSpontaneousEvent(widget, &e);
- const QString title = widget->windowTitle();
- if (!title.isEmpty())
- widget->setWindowTitle_helper(title);
- }
- result = false;
- break;
- default:
- result = false;
- break;
- }
-
- if (window_state_change) {
- QWindowStateChangeEvent e(oldstate);
- qt_sendSpontaneousEvent(widget, &e);
- }
-#endif // #ifndef Q_OS_WINCE
-
- break;
- }
-
- case WM_SETTINGCHANGE:
- if ( QApplication::type() == QApplication::Tty )
- break;
-
- if (!msg.wParam) {
-#ifdef Q_WS_WINCE
- // On Windows CE, lParam parameter is a constant, not a char pointer.
- if (msg.lParam == INI_INTL) {
-#else
- QString area = QString::fromWCharArray((wchar_t*)msg.lParam);
- if (area == QLatin1String("intl")) {
-#endif
- QLocalePrivate::updateSystemPrivate();
- if (!widget->testAttribute(Qt::WA_SetLocale))
- widget->dptr()->setLocale_helper(QLocale(), true);
- QEvent e(QEvent::LocaleChange);
- QApplication::sendEvent(qApp, &e);
- }
- }
- else if (msg.wParam == SPI_SETICONTITLELOGFONT) {
- if (QApplication::desktopSettingsAware()) {
- widget = (QETWidget*)QWidget::find(hwnd);
- if (widget && !widget->parentWidget()) {
- qt_set_windows_font_resources();
- }
- }
- }
- else if (msg.wParam == SPI_SETNONCLIENTMETRICS) {
- widget = (QETWidget*)QWidget::find(hwnd);
- if (widget && !widget->parentWidget()) {
- qt_set_windows_updateScrollBar(widget);
- QEvent e(QEvent::LayoutRequest);
- QApplication::sendEvent(widget, &e);
- }
- }
-
- break;
-
- case WM_PAINT: // paint event
- case WM_ERASEBKGND: // erase window background
- result = widget->translatePaintEvent(msg);
- break;
-
-#ifndef Q_WS_WINCE
- case WM_ENTERSIZEMOVE:
- autoCaptureWnd = hwnd;
- break;
- case WM_EXITSIZEMOVE:
- autoCaptureWnd = 0;
- break;
-#endif
- case WM_MOVE: // move window
- case WM_SIZE: // resize window
- result = widget->translateConfigEvent(msg);
- break;
-
- case WM_ACTIVATEAPP:
- if (wParam == FALSE) {
- QApplication::setActiveWindow(0);
- // Another application was activated while our popups are open,
- // then close all popups. In case some popup refuses to close,
- // we give up after 1024 attempts (to avoid an infinite loop).
- int maxiter = 1024;
- QWidget *popup;
- while ((popup=QApplication::activePopupWidget()) && maxiter--)
- popup->close();
- }
- break;
-
- case WM_ACTIVATE:
- if ( QApplication::type() == QApplication::Tty )
- break;
-
- if (ptrWTOverlap && ptrWTEnable) {
- // cooperate with other tablet applications, but when
- // we get focus, I want to use the tablet...
- if (qt_tablet_context && GET_WM_ACTIVATE_STATE(wParam, lParam)) {
- if (ptrWTEnable(qt_tablet_context, true))
- ptrWTOverlap(qt_tablet_context, true);
- }
- }
- if (QApplication::activePopupWidget() && LOWORD(wParam) == WA_INACTIVE &&
- QWidget::find((HWND)lParam) == 0) {
- // Another application was activated while our popups are open,
- // then close all popups. In case some popup refuses to close,
- // we give up after 1024 attempts (to avoid an infinite loop).
- int maxiter = 1024;
- QWidget *popup;
- while ((popup=QApplication::activePopupWidget()) && maxiter--)
- popup->close();
- }
-
- if (LOWORD(wParam) != WA_INACTIVE) {
- // WM_ACTIVATEAPP handles the "true" false case, as this is only when the application
- // loses focus. Doing it here would result in the widget getting focus to not know
- // where it got it from; it would simply get a 0 value as the old focus widget.
-#ifdef Q_WS_WINCE
- {
-#ifdef Q_WS_WINCE_WM
- // On Windows mobile we do not receive WM_SYSCOMMAND / SC_MINIMIZE messages.
- // Thus we have to unset the minimized state explicitly. We must do this for all
- // top-level widgets, because we get the HWND of a random widget here.
- foreach (QWidget* tlw, QApplication::topLevelWidgets()) {
- if (tlw->isMinimized())
- tlw->setWindowState(tlw->windowState() & ~Qt::WindowMinimized);
- }
-#else
- // On Windows CE we do not receive WM_SYSCOMMAND / SC_MINIMIZE messages.
- // Thus we have to unset the minimized state explicitly.
- if (widget->windowState() & Qt::WindowMinimized)
- widget->setWindowState(widget->windowState() & ~Qt::WindowMinimized);
-#endif // Q_WS_WINCE_WM
-
-#else
- if (!(widget->windowState() & Qt::WindowMinimized)) {
-#endif
- // Ignore the activate message send by WindowsXP to a minimized window
-#ifdef Q_WS_WINCE_WM
- if (widget->windowState() & Qt::WindowFullScreen)
- qt_wince_hide_taskbar(widget->winId());
-#endif
- qApp->winFocus(widget, true);
- // reset any window alert flashes
- alert_widget(widget, -1);
- }
- }
-
- // Windows tries to activate a modally blocked window.
- // This happens when restoring an application after "Show Desktop"
- if (app_do_modal && LOWORD(wParam) == WA_ACTIVE) {
- QWidget *top = 0;
- if (!QApplicationPrivate::tryModalHelper(widget, &top) && top && widget != top) {
- if (top->isVisible()) {
- top->activateWindow();
- } else {
- // This is the case when native file dialogs are shown
- QWidget *p = (top->parentWidget() ? top->parentWidget()->window() : 0);
- if (p && p->isVisible())
- p->activateWindow();
- }
- }
- }
- break;
-
-#ifndef Q_WS_WINCE
- case WM_MOUSEACTIVATE:
- if (widget->window()->windowType() == Qt::Tool) {
- QWidget *w = widget;
- if (!w->window()->focusWidget()) {
- while (w && (w->focusPolicy() & Qt::ClickFocus) == 0) {
- if (w->isWindow()) {
- QWidget *fw = w;
- while ((fw = fw->nextInFocusChain()) != w && fw->focusPolicy() == Qt::NoFocus)
- ;
- if (fw != w)
- break;
- QWidget *pw = w->parentWidget();
- while (pw) {
- pw = pw->window();
- if (pw && pw->isVisible() && pw->focusWidget()) {
- Q_ASSERT(pw->testAttribute(Qt::WA_WState_Created));
- SetWindowPos(pw->internalWinId(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
- break;
- }
- pw = pw->parentWidget();
- }
- RETURN(MA_NOACTIVATE);
- }
- w = w->parentWidget();
- }
- }
- }
- RETURN(MA_ACTIVATE);
- break;
-#endif
- case WM_SHOWWINDOW:
- if (lParam == SW_PARENTOPENING) {
- if (widget->testAttribute(Qt::WA_WState_Hidden))
- RETURN(0);
- }
- if (widget->isWindow() && widget->testAttribute(Qt::WA_WState_Visible)
- && !widget->testWindowState(Qt::WindowMinimized)) {
- if (lParam == SW_PARENTOPENING) {
- QShowEvent e;
- qt_sendSpontaneousEvent(widget, &e);
- widget->showChildren(true);
- } else if (lParam == SW_PARENTCLOSING) {
- QHideEvent e;
- qt_sendSpontaneousEvent(widget, &e);
- widget->hideChildren(true);
- }
- }
- if (!wParam && autoCaptureWnd == widget->internalWinId())
- releaseAutoCapture();
- result = false;
- break;
-
- case WM_PALETTECHANGED: // our window changed palette
- if (QColormap::hPal() && (WId)wParam == widget->internalWinId())
- RETURN(0); // otherwise: FALL THROUGH!
- // FALL THROUGH
- case WM_QUERYNEWPALETTE: // realize own palette
- if (QColormap::hPal()) {
- Q_ASSERT(widget->testAttribute(Qt::WA_WState_Created));
- HDC hdc = GetDC(widget->internalWinId());
- HPALETTE hpalOld = SelectPalette(hdc, QColormap::hPal(), FALSE);
- uint n = RealizePalette(hdc);
- if (n)
- InvalidateRect(widget->internalWinId(), 0, TRUE);
- SelectPalette(hdc, hpalOld, TRUE);
- RealizePalette(hdc);
- ReleaseDC(widget->internalWinId(), hdc);
- RETURN(n);
- }
- break;
- case WM_CLOSE: // close window
- widget->translateCloseEvent(msg);
- RETURN(0); // always handled
-
- case WM_DESTROY: // destroy window
- if (hwnd == curWin) {
- QWidget *enter = QWidget::mouseGrabber();
- if (enter == widget)
- enter = 0;
- QApplicationPrivate::dispatchEnterLeave(enter, widget);
- curWin = enter ? enter->effectiveWinId() : 0;
- qt_last_mouse_receiver = enter;
- }
- if (widget == popupButtonFocus)
- popupButtonFocus = 0;
- result = false;
- break;
-
-#ifndef Q_WS_WINCE
- case WM_WINDOWPOSCHANGING:
- {
- result = false;
- if (widget->isWindow()) {
- WINDOWPOS *winPos = (WINDOWPOS *)lParam;
- if (widget->layout() && widget->layout()->hasHeightForWidth()
- && !(winPos->flags & (SWP_NOCOPYBITS | SWP_NOSIZE))) {
- QRect fs = widget->frameStrut();
- QRect rect = widget->geometry();
- QRect newRect = QRect(winPos->x + fs.left(),
- winPos->y + fs.top(),
- winPos->cx - fs.left() - fs.right(),
- winPos->cy - fs.top() - fs.bottom());
-
- QSize newSize = QLayout::closestAcceptableSize(widget, newRect.size());
-
- int dh = newSize.height() - newRect.height();
- int dw = newSize.width() - newRect.width();
- if (!dw && ! dh)
- break; // Size OK
-
- if (rect.y() != newRect.y()) {
- newRect.setTop(newRect.top() - dh);
- } else {
- newRect.setBottom(newRect.bottom() + dh);
- }
-
- if (rect.x() != newRect.x()) {
- newRect.setLeft(newRect.left() - dw);
- } else {
- newRect.setRight(newRect.right() + dw);
- }
-
- winPos->x = newRect.x() - fs.left();
- winPos->y = newRect.y() - fs.top();
- winPos->cx = newRect.width() + fs.left() + fs.right();
- winPos->cy = newRect.height() + fs.top() + fs.bottom();
-
- RETURN(0);
- }
- if (widget->windowFlags() & Qt::WindowStaysOnBottomHint) {
- winPos->hwndInsertAfter = HWND_BOTTOM;
- }
- }
- }
- break;
-
- case WM_GETMINMAXINFO:
- if (widget->xtra()) {
- MINMAXINFO *mmi = (MINMAXINFO *)lParam;
- QWExtra *x = widget->xtra();
- QRect fs = widget->frameStrut();
- if ( x->minw > 0 )
- mmi->ptMinTrackSize.x = x->minw + fs.right() + fs.left();
- if ( x->minh > 0 )
- mmi->ptMinTrackSize.y = x->minh + fs.top() + fs.bottom();
- qint32 maxw = (x->maxw >= x->minw) ? x->maxw : x->minw;
- qint32 maxh = (x->maxh >= x->minh) ? x->maxh : x->minh;
- if ( maxw < QWIDGETSIZE_MAX ) {
- mmi->ptMaxTrackSize.x = maxw + fs.right() + fs.left();
- // windows with title bar have an implicit size limit of 112 pixels
- if (widget->windowFlags() & Qt::WindowTitleHint)
- mmi->ptMaxTrackSize.x = qMax<long>(mmi->ptMaxTrackSize.x, 112);
- }
- if ( maxh < QWIDGETSIZE_MAX )
- mmi->ptMaxTrackSize.y = maxh + fs.top() + fs.bottom();
- RETURN(0);
- }
- break;
-
-#ifndef QT_NO_CONTEXTMENU
- case WM_CONTEXTMENU:
- {
- // it's not VK_APPS or Shift+F10, but a click in the NC area
- if (lParam != (int)0xffffffff) {
- result = false;
- break;
- }
-
- QWidget *fw = QWidget::keyboardGrabber();
- if (!fw) {
- if (QApplication::activePopupWidget())
- fw = (QApplication::activePopupWidget()->focusWidget()
- ? QApplication::activePopupWidget()->focusWidget()
- : QApplication::activePopupWidget());
- else if (QApplication::focusWidget())
- fw = QApplication::focusWidget();
- else if (widget)
- fw = widget->window();
- }
- if (fw && fw->isEnabled()) {
- QPoint pos = fw->inputMethodQuery(Qt::ImMicroFocus).toRect().center();
- QContextMenuEvent e(QContextMenuEvent::Keyboard, pos, fw->mapToGlobal(pos),
- qt_win_getKeyboardModifiers());
- result = qt_sendSpontaneousEvent(fw, &e);
- }
- }
- break;
-#endif
-#endif
-
- case WM_IME_STARTCOMPOSITION:
- case WM_IME_ENDCOMPOSITION:
- case WM_IME_COMPOSITION: {
- QWidget *fw = QApplication::focusWidget();
- QWinInputContext *im = fw ? qobject_cast<QWinInputContext *>(fw->inputContext()) : 0;
- if (fw && im) {
- if(message == WM_IME_STARTCOMPOSITION)
- result = im->startComposition();
- else if (message == WM_IME_ENDCOMPOSITION)
- result = im->endComposition();
- else if (message == WM_IME_COMPOSITION)
- result = im->composition(lParam);
- }
- break;
- }
- case WM_IME_REQUEST: {
- QWidget *fw = QApplication::focusWidget();
- QWinInputContext *im = fw ? qobject_cast<QWinInputContext *>(fw->inputContext()) : 0;
- if (fw && im) {
- if(wParam == IMR_RECONVERTSTRING) {
- int ret = im->reconvertString((RECONVERTSTRING *)lParam);
- if (ret == -1) {
- result = false;
- } else {
- return ret;
- }
- } else if (wParam == IMR_CONFIRMRECONVERTSTRING) {
- RETURN(TRUE);
- } else {
- // in all other cases, call DefWindowProc()
- result = false;
- }
- }
- break;
- }
-#ifndef Q_WS_WINCE
- case WM_CHANGECBCHAIN:
- case WM_DRAWCLIPBOARD:
-#endif
- case WM_RENDERFORMAT:
- case WM_RENDERALLFORMATS:
-#ifndef QT_NO_CLIPBOARD
- case WM_DESTROYCLIPBOARD:
- if (qt_clipboard) {
- QClipboardEvent e(reinterpret_cast<QEventPrivate *>(&msg));
- qt_sendSpontaneousEvent(qt_clipboard, &e);
- RETURN(0);
- }
- result = false;
- break;
-#endif //QT_NO_CLIPBOARD
-#ifndef QT_NO_ACCESSIBILITY
- case WM_GETOBJECT:
- {
- // Ignoring all requests while starting up
- if (QApplication::startingUp() || QApplication::closingDown() || lParam != (LPARAM)OBJID_CLIENT) {
- result = false;
- break;
- }
-
- typedef LRESULT (WINAPI *PtrLresultFromObject)(REFIID, WPARAM, LPUNKNOWN);
- static PtrLresultFromObject ptrLresultFromObject = 0;
- static bool oleaccChecked = false;
-
- if (!oleaccChecked) {
- oleaccChecked = true;
-#if !defined(Q_OS_WINCE)
- ptrLresultFromObject = (PtrLresultFromObject)QSystemLibrary::resolve(QLatin1String("oleacc"), "LresultFromObject");
-#endif
- }
- if (ptrLresultFromObject) {
- QAccessibleInterface *acc = QAccessible::queryAccessibleInterface(widget);
- if (!acc) {
- result = false;
- break;
- }
-
- // and get an instance of the IAccessibile implementation
- IAccessible *iface = qt_createWindowsAccessible(acc);
- res = ptrLresultFromObject(IID_IAccessible, wParam, iface); // ref == 2
- iface->Release(); // the client will release the object again, and then it will destroy itself
-
- if (res > 0)
- RETURN(res);
- }
- }
- result = false;
- break;
- case WM_GETTEXT:
- if (!widget->isWindow()) {
- int ret = 0;
- QAccessibleInterface *acc = QAccessible::queryAccessibleInterface(widget);
- if (acc) {
- QString text = acc->text(QAccessible::Name, 0);
- if (text.isEmpty())
- text = widget->objectName();
- ret = qMin<int>(wParam - 1, text.size());
- text.resize(ret);
- memcpy((void *)lParam, text.utf16(), (text.size() + 1) * sizeof(ushort));
- delete acc;
- }
- if (!ret) {
- result = false;
- break;
- }
- RETURN(ret);
- }
- result = false;
- break;
-#endif
- case WT_PACKET:
- if (ptrWTPacketsGet) {
- if ((nPackets = ptrWTPacketsGet(qt_tablet_context, QT_TABLET_NPACKETQSIZE, &localPacketBuf))) {
- result = widget->translateTabletEvent(msg, localPacketBuf, nPackets);
- }
- }
- break;
- case WT_PROXIMITY:
-
- #ifndef QT_NO_TABLETEVENT
- if (ptrWTPacketsGet && ptrWTInfo) {
- const bool enteredProximity = LOWORD(lParam) != 0;
- PACKET proximityBuffer[1]; // we are only interested in the first packet in this case
- const int totalPacks = ptrWTPacketsGet(qt_tablet_context, 1, proximityBuffer);
- if (totalPacks > 0) {
- const UINT currentCursor = proximityBuffer[0].pkCursor;
-
- UINT csr_physid;
- ptrWTInfo(WTI_CURSORS + currentCursor, CSR_PHYSID, &csr_physid);
- UINT csr_type;
- ptrWTInfo(WTI_CURSORS + currentCursor, CSR_TYPE, &csr_type);
- const UINT deviceIdMask = 0xFF6; // device type mask && device color mask
- quint64 uniqueId = (csr_type & deviceIdMask);
- uniqueId = (uniqueId << 32) | csr_physid;
-
- // initialising and updating the cursor should be done in response to
- // WT_CSRCHANGE. We do it in WT_PROXIMITY because some wintab never send
- // the event WT_CSRCHANGE even if asked with CXO_CSRMESSAGES
- const QTabletCursorInfo *const globalCursorInfo = tCursorInfo();
- if (!globalCursorInfo->contains(uniqueId))
- tabletInit(uniqueId, csr_type, qt_tablet_context);
-
- currentTabletPointer = globalCursorInfo->value(uniqueId);
- tabletUpdateCursor(currentTabletPointer, currentCursor);
- }
- qt_tabletChokeMouse = false;
-
- QTabletEvent tabletProximity(enteredProximity ? QEvent::TabletEnterProximity
- : QEvent::TabletLeaveProximity,
- QPoint(), QPoint(), QPointF(), currentTabletPointer.currentDevice, currentTabletPointer.currentPointerType, 0, 0,
- 0, 0, 0, 0, 0, currentTabletPointer.llId);
- QApplication::sendEvent(qApp, &tabletProximity);
- }
- #endif // QT_NO_TABLETEVENT
-
- break;
-#ifdef Q_WS_WINCE_WM
- case WM_SETFOCUS: {
- HIMC hC;
- hC = ImmGetContext(hwnd);
- ImmSetOpenStatus(hC, TRUE);
- ImmEscape(NULL, hC, IME_ESC_SET_MODE, (LPVOID)IM_SPELL);
- result = false;
- }
- break;
-#endif
- case WM_KILLFOCUS:
- if (!QWidget::find((HWND)wParam)) { // we don't get focus, so unset it now
- if (!widget->hasFocus()) // work around Windows bug after minimizing/restoring
- widget = (QETWidget*)QApplication::focusWidget();
- HWND focus = ::GetFocus();
- //if there is a current widget and the new widget belongs to the same toplevel window
- //or if the current widget was embedded into non-qt window (i.e. we won't get WM_ACTIVATEAPP)
- //then we clear the focus on the widget
- //in case the new widget belongs to a different widget hierarchy, clearing the focus
- //will be handled because the active window will change
- const bool embedded = widget && ((QETWidget*)widget->window())->topData()->embedded;
- if (widget && (embedded || ::IsChild(widget->window()->internalWinId(), focus))) {
- widget->clearFocus();
- result = true;
- } else {
- result = false;
- }
- } else {
- result = false;
- }
- break;
- case WM_THEMECHANGED:
- if ((widget->windowType() == Qt::Desktop) || !qApp || QApplication::closingDown()
- || QApplication::type() == QApplication::Tty)
- break;
-
- if (widget->testAttribute(Qt::WA_WState_Polished))
- QApplication::style()->unpolish(widget);
-
- if (widget->testAttribute(Qt::WA_WState_Polished))
- QApplication::style()->polish(widget);
- widget->repolishStyle(*QApplication::style());
- if (widget->isVisible())
- widget->update();
- break;
-
-#ifndef Q_WS_WINCE
- case WM_INPUTLANGCHANGE: {
- wchar_t info[7];
- if (!GetLocaleInfo(MAKELCID(lParam, SORT_DEFAULT), LOCALE_IDEFAULTANSICODEPAGE, info, 6)) {
- inputcharset = CP_ACP;
- } else {
- inputcharset = QString::fromWCharArray(info).toInt();
- }
- QKeyMapper::changeKeyboard();
- break;
- }
-#else
- case WM_COMMAND: {
- bool OkCommand = (LOWORD(wParam) == 0x1);
- bool CancelCommand = (LOWORD(wParam) == 0x2);
- if (OkCommand)
- QApplication::postEvent(widget, new QEvent(QEvent::OkRequest));
- if (CancelCommand)
- widget->showMinimized();
- else
-#ifndef QT_NO_MENUBAR
- QMenuBar::wceCommands(LOWORD(wParam));
-#endif
- result = true;
- }
- break;
- case WM_HELP:
- QApplication::postEvent(widget, new QEvent(QEvent::HelpRequest));
- result = true;
- break;
-#endif
-
- case WM_MOUSELEAVE:
- // We receive a mouse leave for curWin, meaning
- // the mouse was moved outside our widgets
- if (widget->internalWinId() == curWin) {
- bool dispatch = !widget->underMouse();
- // hasMouse is updated when dispatching enter/leave,
- // so test if it is actually up-to-date
- if (!dispatch) {
- QRect geom = widget->geometry();
- if (widget->parentWidget() && !widget->isWindow()) {
- QPoint gp = widget->parentWidget()->mapToGlobal(widget->pos());
- geom.setX(gp.x());
- geom.setY(gp.y());
- }
- QPoint cpos = QCursor::pos();
- dispatch = !geom.contains(cpos);
- if ( !dispatch && !QWidget::mouseGrabber()) {
- QWidget *hittest = QApplication::widgetAt(cpos);
- dispatch = !hittest || hittest->internalWinId() != curWin;
- }
- if (!dispatch) {
- HRGN hrgn = qt_tryCreateRegion(QRegion::Rectangle, 0,0,0,0);
- if (GetWindowRgn(curWin, hrgn) != ERROR) {
- QPoint lcpos = widget->mapFromGlobal(cpos);
- dispatch = !PtInRegion(hrgn, lcpos.x(), lcpos.y());
- }
- DeleteObject(hrgn);
- }
- }
- if (dispatch) {
- if (qt_last_mouse_receiver && !qt_last_mouse_receiver->internalWinId())
- QApplicationPrivate::dispatchEnterLeave(0, qt_last_mouse_receiver);
- else
- QApplicationPrivate::dispatchEnterLeave(0, QWidget::find((WId)curWin));
- curWin = 0;
- qt_last_mouse_receiver = 0;
- }
- }
- break;
-
- case WM_CANCELMODE:
- {
- // this goes through QMenuBar's event filter
- QEvent e(QEvent::ActivationChange);
- QApplication::sendEvent(qApp, &e);
- }
- break;
-
- case WM_IME_NOTIFY:
- // special handling for ime, only for widgets in a popup
- if (wParam == IMN_OPENCANDIDATE) {
- imeParentWnd = hwnd;
- if (QApplication::activePopupWidget()) {
- // temporarily disable the mouse grab to allow mouse input in
- // the ime candidate window. The actual handle is untouched
- if (autoCaptureWnd)
- ReleaseCapture();
- }
- } else if (wParam == IMN_CLOSECANDIDATE) {
- imeParentWnd = 0;
- if (QApplication::activePopupWidget()) {
- // undo the action above, when candidate window is closed
- if (autoCaptureWnd)
- SetCapture(autoCaptureWnd);
- }
- }
- result = false;
- break;
-#ifndef QT_NO_GESTURES
-#if !defined(Q_WS_WINCE) || defined(QT_WINCE_GESTURES)
- case WM_GESTURE: {
- GESTUREINFO gi;
- memset(&gi, 0, sizeof(GESTUREINFO));
- gi.cbSize = sizeof(GESTUREINFO);
-
- QApplicationPrivate *qAppPriv = QApplicationPrivate::instance();
- BOOL bResult = false;
- if (qAppPriv->GetGestureInfo)
- bResult = qAppPriv->GetGestureInfo((HANDLE)msg.lParam, &gi);
- if (bResult) {
- if (gi.dwID == GID_BEGIN) {
- // find the alien widget for the gesture position.
- // This might not be accurate as the position is the center
- // point of two fingers for multi-finger gestures.
- QPoint pt(gi.ptsLocation.x, gi.ptsLocation.y);
- QWidget *w = widget->childAt(widget->mapFromGlobal(pt));
- qAppPriv->gestureWidget = w ? w : widget;
- }
- if (qAppPriv->gestureWidget)
- static_cast<QETWidget*>(qAppPriv->gestureWidget)->translateGestureEvent(msg, gi);
- if (qAppPriv->CloseGestureInfoHandle)
- qAppPriv->CloseGestureInfoHandle((HANDLE)msg.lParam);
- if (gi.dwID == GID_END)
- qAppPriv->gestureWidget = 0;
- } else {
- DWORD dwErr = GetLastError();
- if (dwErr > 0)
- qWarning() << "translateGestureEvent: error = " << dwErr;
- }
- result = true;
- break;
- }
-#endif // !defined(Q_WS_WINCE) || defined(QT_WINCE_GESTURES)
-#endif // QT_NO_GESTURES
-#ifndef QT_NO_CURSOR
- case WM_SETCURSOR: {
- QCursor *ovr = QApplication::overrideCursor();
- if (ovr) {
- SetCursor(ovr->handle());
- RETURN(TRUE);
- }
- result = false;
- break;
- }
-#endif
- default:
- result = false; // event was not processed
- break;
- }
- }
-
- if (evt_type != QEvent::None) { // simple event
- QEvent e(evt_type);
- result = qt_sendSpontaneousEvent(widget, &e);
- }
-
- if (result)
- RETURN(false);
-
-do_default:
- RETURN(QWinInputContext::DefWindowProc(hwnd,message,wParam,lParam))
-}
-
-
-/*****************************************************************************
- Modal widgets; We have implemented our own modal widget mechanism
- to get total control.
- A modal widget without a parent becomes application-modal.
- A modal widget with a parent becomes modal to its parent and grandparents..
-
- QApplicationPrivate::enterModal()
- Enters modal state
- Arguments:
- QWidget *widget A modal widget
-
- QApplicationPrivate::leaveModal()
- Leaves modal state for a widget
- Arguments:
- QWidget *widget A modal widget
- *****************************************************************************/
-
-bool QApplicationPrivate::modalState()
-{
- return app_do_modal;
-}
-
-void QApplicationPrivate::enterModal_sys(QWidget *widget)
-{
- if (!qt_modal_stack)
- qt_modal_stack = new QWidgetList;
-
- releaseAutoCapture();
- ClipCursor(0);
- QWidget *leave = qt_last_mouse_receiver;
- if (!leave)
- leave = QWidget::find((WId)curWin);
- QApplicationPrivate::dispatchEnterLeave(0, leave);
- qt_modal_stack->insert(0, widget);
- app_do_modal = true;
- curWin = 0;
- qt_last_mouse_receiver = 0;
- qt_win_ignoreNextMouseReleaseEvent = false;
-}
-
-void QApplicationPrivate::leaveModal_sys(QWidget *widget)
-{
- if (qt_modal_stack && qt_modal_stack->removeAll(widget)) {
- if (qt_modal_stack->isEmpty()) {
- delete qt_modal_stack;
- qt_modal_stack = 0;
- QPoint p(QCursor::pos());
- app_do_modal = false; // necessary, we may get recursively into qt_try_modal below
- QWidget* w = QApplication::widgetAt(p.x(), p.y());
- QWidget *leave = qt_last_mouse_receiver;
- if (!leave)
- leave = QWidget::find((WId)curWin);
- if (QWidget *grabber = QWidget::mouseGrabber()) {
- w = grabber;
- if (leave == w)
- leave = 0;
- }
- QApplicationPrivate::dispatchEnterLeave(w, leave); // send synthetic enter event
- curWin = w ? w->effectiveWinId() : 0;
- qt_last_mouse_receiver = w;
- }
- qt_win_ignoreNextMouseReleaseEvent = true;
- }
- app_do_modal = qt_modal_stack != 0;
-}
-
-bool qt_try_modal(QWidget *widget, MSG *msg, int& ret)
-{
-#if defined(Q_OS_WINCE)
- Q_UNUSED(ret);
-#endif
- QWidget * top = 0;
-
- if (QApplicationPrivate::tryModalHelper(widget, &top))
- return true;
-
- int type = msg->message;
-
- bool block_event = false;
-#ifndef Q_WS_WINCE
- if (type != WM_NCHITTEST) {
-#endif
- if ((type >= WM_MOUSEFIRST && type <= WM_MOUSELAST) ||
- type == WM_MOUSEWHEEL || type == WM_MOUSEHWHEEL ||
- type == WM_MOUSELEAVE ||
- (type >= WM_KEYFIRST && type <= WM_KEYLAST)
-#ifndef Q_WS_WINCE
- || type == WM_NCMOUSEMOVE
-#endif
- ) {
- if (type == WM_MOUSEMOVE
-#ifndef Q_WS_WINCE
- || type == WM_NCMOUSEMOVE
-#endif
- ) {
-#ifndef QT_NO_CURSOR
- QCursor *c = qt_grab_cursor();
- if (!c)
- c = QApplication::overrideCursor();
- if (c) // application cursor defined
- SetCursor(c->handle());
- else
- SetCursor(QCursor(Qt::ArrowCursor).handle());
-#endif // QT_NO_CURSOR
- }
- block_event = true;
- } else if (type == WM_CLOSE) {
- block_event = true;
- }
-#ifndef Q_WS_WINCE
- else if (type == WM_MOUSEACTIVATE || type == WM_NCLBUTTONDOWN){
- if (!top->isActiveWindow()) {
- top->activateWindow();
- } else {
- QApplication::beep();
- }
- block_event = true;
- ret = MA_NOACTIVATEANDEAT;
- } else if (type == WM_SYSCOMMAND) {
- if (!(msg->wParam == SC_RESTORE && widget->isMinimized()))
- block_event = true;
- }
- }
-#endif
-
- return !block_event;
-}
-
-
-/*****************************************************************************
- Popup widget mechanism
-
- openPopup()
- Adds a widget to the list of popup widgets
- Arguments:
- QWidget *widget The popup widget to be added
-
- closePopup()
- Removes a widget from the list of popup widgets
- Arguments:
- QWidget *widget The popup widget to be removed
- *****************************************************************************/
-
-void QApplicationPrivate::openPopup(QWidget *popup)
-{
- if (!QApplicationPrivate::popupWidgets)
- QApplicationPrivate::popupWidgets = new QWidgetList;
- QApplicationPrivate::popupWidgets->append(popup);
- if (!popup->isEnabled())
- return;
-
- // close any opened 'ime candidate window'
- if (imeParentWnd)
- ::SendMessage(imeParentWnd, WM_IME_ENDCOMPOSITION, 0, 0);
-
- if (QApplicationPrivate::popupWidgets->count() == 1 && !qt_nograb()) {
- Q_ASSERT(popup->testAttribute(Qt::WA_WState_Created));
- setAutoCapture(popup->internalWinId()); // grab mouse/keyboard
- }
- // Popups are not focus-handled by the window system (the first
- // popup grabbed the keyboard), so we have to do that manually: A
- // new popup gets the focus
- if (popup->focusWidget()) {
- popup->focusWidget()->setFocus(Qt::PopupFocusReason);
- } else if (QApplicationPrivate::popupWidgets->count() == 1) { // this was the first popup
- if (QWidget *fw = QApplication::focusWidget()) {
- QFocusEvent e(QEvent::FocusOut, Qt::PopupFocusReason);
- QApplication::sendEvent(fw, &e);
- }
- }
-}
-
-void QApplicationPrivate::closePopup(QWidget *popup)
-{
- if (!QApplicationPrivate::popupWidgets)
- return;
- QApplicationPrivate::popupWidgets->removeAll(popup);
- POINT curPos;
- GetCursorPos(&curPos);
-
- // close any opened 'ime candidate window'
- if (imeParentWnd)
- ::SendMessage(imeParentWnd, WM_IME_ENDCOMPOSITION, 0, 0);
-
- if (QApplicationPrivate::popupWidgets->isEmpty()) { // this was the last popup
- delete QApplicationPrivate::popupWidgets;
- QApplicationPrivate::popupWidgets = 0;
- replayPopupMouseEvent = (!popup->geometry().contains(QPoint(curPos.x, curPos.y))
- && !popup->testAttribute(Qt::WA_NoMouseReplay));
- if (!popup->isEnabled())
- return;
- if (!qt_nograb()) // grabbing not disabled
- releaseAutoCapture();
- QWidget *fw = QApplicationPrivate::active_window ? QApplicationPrivate::active_window->focusWidget()
- : QApplication::focusWidget();
- if (fw) {
- if (fw != QApplication::focusWidget()) {
- fw->setFocus(Qt::PopupFocusReason);
- } else {
- QFocusEvent e(QEvent::FocusIn, Qt::PopupFocusReason);
- QApplication::sendEvent(fw, &e);
- }
- }
- } else {
- // Popups are not focus-handled by the window system (the
- // first popup grabbed the keyboard), so we have to do that
- // manually: A popup was closed, so the previous popup gets
- // the focus.
- QWidget* aw = QApplicationPrivate::popupWidgets->last();
- if (QApplicationPrivate::popupWidgets->count() == 1) {
- Q_ASSERT(aw->testAttribute(Qt::WA_WState_Created));
- setAutoCapture(aw->internalWinId());
- }
- if (QWidget *fw = aw->focusWidget())
- fw->setFocus(Qt::PopupFocusReason);
- }
-}
-
-
-
-
-/*****************************************************************************
- Event translation; translates Windows events to Qt events
- *****************************************************************************/
-
-//
-// Auto-capturing for mouse press and mouse release
-//
-
-static void setAutoCapture(HWND h)
-{
- if (autoCaptureWnd)
- releaseAutoCapture();
- autoCaptureWnd = h;
- SetCapture(h);
-}
-
-static void releaseAutoCapture()
-{
- if (autoCaptureWnd) {
- ReleaseCapture();
- autoCaptureWnd = 0;
- }
-}
-
-
-//
-// Mouse event translation
-//
-// Non-client mouse messages are not translated
-//
-
-static const ushort mouseTbl[] = {
- WM_MOUSEMOVE, QEvent::MouseMove, 0,
- WM_LBUTTONDOWN, QEvent::MouseButtonPress, Qt::LeftButton,
- WM_LBUTTONUP, QEvent::MouseButtonRelease, Qt::LeftButton,
- WM_LBUTTONDBLCLK, QEvent::MouseButtonDblClick, Qt::LeftButton,
- WM_RBUTTONDOWN, QEvent::MouseButtonPress, Qt::RightButton,
- WM_RBUTTONUP, QEvent::MouseButtonRelease, Qt::RightButton,
- WM_RBUTTONDBLCLK, QEvent::MouseButtonDblClick, Qt::RightButton,
- WM_MBUTTONDOWN, QEvent::MouseButtonPress, Qt::MidButton,
- WM_MBUTTONUP, QEvent::MouseButtonRelease, Qt::MidButton,
- WM_MBUTTONDBLCLK, QEvent::MouseButtonDblClick, Qt::MidButton,
- // use XButton1 for now, the real X button is decided later
- WM_XBUTTONDOWN, QEvent::MouseButtonPress, Qt::XButton1,
- WM_XBUTTONUP, QEvent::MouseButtonRelease, Qt::XButton1,
- WM_XBUTTONDBLCLK, QEvent::MouseButtonDblClick, Qt::XButton1,
-
-#ifndef Q_WS_WINCE
- WM_NCMOUSEMOVE, QEvent::NonClientAreaMouseMove, 0,
- WM_NCLBUTTONDOWN, QEvent::NonClientAreaMouseButtonPress, Qt::LeftButton,
- WM_NCLBUTTONUP, QEvent::NonClientAreaMouseButtonRelease, Qt::LeftButton,
- WM_NCLBUTTONDBLCLK, QEvent::NonClientAreaMouseButtonDblClick, Qt::LeftButton,
- WM_NCRBUTTONDOWN, QEvent::NonClientAreaMouseButtonPress, Qt::RightButton,
- WM_NCRBUTTONUP, QEvent::NonClientAreaMouseButtonRelease, Qt::RightButton,
- WM_NCRBUTTONDBLCLK, QEvent::NonClientAreaMouseButtonDblClick, Qt::RightButton,
- WM_NCMBUTTONDOWN, QEvent::NonClientAreaMouseButtonPress, Qt::MidButton,
- WM_NCMBUTTONUP, QEvent::NonClientAreaMouseButtonRelease, Qt::MidButton,
- WM_NCMBUTTONDBLCLK, QEvent::NonClientAreaMouseButtonDblClick, Qt::MidButton,
-#endif
-
- 0, 0, 0
-};
-
-static int translateButtonState(int s, int type, int button)
-{
- Q_UNUSED(type);
- Q_UNUSED(button);
- int bst = 0;
- if (s & MK_LBUTTON)
- bst |= Qt::LeftButton;
- if (s & MK_MBUTTON)
- bst |= Qt::MidButton;
- if (s & MK_RBUTTON)
- bst |= Qt::RightButton;
- if (s & MK_SHIFT)
- bst |= Qt::ShiftModifier;
- if (s & MK_CONTROL)
- bst |= Qt::ControlModifier;
-
- if (s & MK_XBUTTON1)
- bst |= Qt::XButton1;
- if (s & MK_XBUTTON2)
- bst |= Qt::XButton2;
-
- if (GetKeyState(VK_MENU) < 0)
- bst |= Qt::AltModifier;
-
- if ((GetKeyState(VK_LWIN) < 0) ||
- (GetKeyState(VK_RWIN) < 0))
- bst |= Qt::MetaModifier;
-
- return bst;
-}
-
-void qt_win_eatMouseMove()
-{
- // after closing a windows dialog with a double click (i.e. open a file)
- // the message queue still contains a dubious WM_MOUSEMOVE message where
- // the left button is reported to be down (wParam != 0).
- // remove all those messages (usually 1) and post the last one with a
- // reset button state
-
- MSG msg = {0, 0, 0, 0, 0, {0, 0} };
- while (PeekMessage(&msg, 0, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE))
- ;
- if (msg.message == WM_MOUSEMOVE)
- PostMessage(msg.hwnd, msg.message, 0, msg.lParam);
-}
-
-// In DnD, the mouse release event never appears, so the
-// mouse button state machine must be manually reset
-void QApplication::winMouseButtonUp()
-{
- qt_button_down = 0;
- releaseAutoCapture();
-}
-
-void QETWidget::repolishStyle(QStyle &)
-{
- QEvent e(QEvent::StyleChange);
- QApplication::sendEvent(this, &e);
-}
-
-bool QETWidget::translateMouseEvent(const MSG &msg)
-{
- if (!isWindow() && testAttribute(Qt::WA_NativeWindow))
- Q_ASSERT(internalWinId());
-
- static QPoint pos;
- static POINT gpos={-1,-1};
- QEvent::Type type; // event parameters
- int button;
- int state;
- int i;
-
- if (sm_blockUserInput) //block user interaction during session management
- return true;
-
- // Compress mouse move events
- if (msg.message == WM_MOUSEMOVE) {
- MSG mouseMsg;
- while (PeekMessage(&mouseMsg, msg.hwnd, WM_MOUSEFIRST,
- WM_MOUSELAST, PM_NOREMOVE)) {
- if (mouseMsg.message == WM_MOUSEMOVE) {
-#define PEEKMESSAGE_IS_BROKEN 1
-#ifdef PEEKMESSAGE_IS_BROKEN
- // Since the Windows PeekMessage() function doesn't
- // correctly return the wParam for WM_MOUSEMOVE events
- // if there is a key release event in the queue
- // _before_ the mouse event, we have to also consider
- // key release events (kls 2003-05-13):
- MSG keyMsg;
- bool done = false;
- while (PeekMessage(&keyMsg, 0, WM_KEYFIRST, WM_KEYLAST,
- PM_NOREMOVE)) {
- if (keyMsg.time < mouseMsg.time) {
- if ((keyMsg.lParam & 0xC0000000) == 0x40000000) {
- PeekMessage(&keyMsg, 0, keyMsg.message,
- keyMsg.message, PM_REMOVE);
- } else {
- done = true;
- break;
- }
- } else {
- break; // no key event before the WM_MOUSEMOVE event
- }
- }
- if (done)
- break;
-#else
- // Actually the following 'if' should work instead of
- // the above key event checking, but apparently
- // PeekMessage() is broken :-(
- if (mouseMsg.wParam != msg.wParam)
- break; // leave the message in the queue because
- // the key state has changed
-#endif
- MSG *msgPtr = (MSG *)(&msg);
- // Update the passed in MSG structure with the
- // most recent one.
- msgPtr->lParam = mouseMsg.lParam;
- msgPtr->wParam = mouseMsg.wParam;
- // Extract the x,y coordinates from the lParam as we do in the WndProc
- msgPtr->pt.x = GET_X_LPARAM(mouseMsg.lParam);
- msgPtr->pt.y = GET_Y_LPARAM(mouseMsg.lParam);
- ClientToScreen(msg.hwnd, &(msgPtr->pt));
- // Remove the mouse move message
- PeekMessage(&mouseMsg, msg.hwnd, WM_MOUSEMOVE,
- WM_MOUSEMOVE, PM_REMOVE);
- } else {
- break; // there was no more WM_MOUSEMOVE event
- }
- }
- }
-
- for (i=0; (UINT)mouseTbl[i] != msg.message && mouseTbl[i]; i += 3)
- ;
- if (!mouseTbl[i])
- return false;
- type = (QEvent::Type)mouseTbl[++i]; // event type
- button = mouseTbl[++i]; // which button
- if (button == Qt::XButton1) {
- switch(GET_XBUTTON_WPARAM(msg.wParam)) {
- case XBUTTON1:
- button = Qt::XButton1;
- break;
- case XBUTTON2:
- button = Qt::XButton2;
- break;
- }
- }
-#ifndef Q_OS_WINCE
- static bool trackMouseEventLookup = false;
- typedef BOOL (WINAPI *PtrTrackMouseEvent)(LPTRACKMOUSEEVENT);
- static PtrTrackMouseEvent ptrTrackMouseEvent = 0;
-#endif
- state = translateButtonState(msg.wParam, type, button); // button state
- const QPoint widgetPos = mapFromGlobal(QPoint(msg.pt.x, msg.pt.y));
- QWidget *alienWidget = !internalWinId() ? this : childAt(widgetPos);
- if (alienWidget && alienWidget->internalWinId())
- alienWidget = 0;
-
- if (type == QEvent::MouseMove || type == QEvent::NonClientAreaMouseMove
- || type == QEvent::TabletMove) {
-
- if (!(state & Qt::MouseButtonMask))
- qt_button_down = 0;
-#ifndef QT_NO_CURSOR
- QCursor *c = qt_grab_cursor();
- if (!c)
- c = QApplication::overrideCursor();
- if (c) // application cursor defined
- SetCursor(c->handle());
- else if (type != QEvent::NonClientAreaMouseMove && !qt_button_down) {
- // use widget cursor if widget is enabled
- QWidget *w = alienWidget ? alienWidget : this;
- while (!w->isWindow() && !w->isEnabled())
- w = w->parentWidget();
- SetCursor(w->cursor().handle());
- }
-#endif // QT_NO_CURSOR
-
- HWND id = effectiveWinId();
- QWidget *mouseGrabber = QWidget::mouseGrabber();
- QWidget *activePopupWidget = QApplication::activePopupWidget();
- if (mouseGrabber) {
- if (!activePopupWidget || (activePopupWidget == this && !rect().contains(widgetPos)))
- id = mouseGrabber->effectiveWinId();
- } else if (type == QEvent::NonClientAreaMouseMove) {
- id = 0;
- }
-
- if (curWin != id) { // new current window
- if (id == 0) {
- QWidget *leave = qt_last_mouse_receiver;
- if (!leave)
- leave = QWidget::find(curWin);
- QApplicationPrivate::dispatchEnterLeave(0, leave);
- qt_last_mouse_receiver = 0;
- curWin = 0;
- } else {
- QWidget *leave = 0;
- if (curWin && qt_last_mouse_receiver)
- leave = qt_last_mouse_receiver;
- else
- leave = QWidget::find(curWin);
- QWidget *enter = alienWidget ? alienWidget : this;
- if (mouseGrabber && activePopupWidget) {
- if (leave != mouseGrabber)
- enter = mouseGrabber;
- else
- enter = activePopupWidget == this ? this : mouseGrabber;
- }
- QApplicationPrivate::dispatchEnterLeave(enter, leave);
- qt_last_mouse_receiver = enter;
- curWin = enter ? enter->effectiveWinId() : 0;
- }
-#ifndef Q_OS_WINCE
-
- if (curWin != 0) {
- if (!trackMouseEventLookup) {
- trackMouseEventLookup = true;
- ptrTrackMouseEvent = (PtrTrackMouseEvent)QSystemLibrary::resolve(QLatin1String("comctl32"), "_TrackMouseEvent");
- }
- if (ptrTrackMouseEvent && !qApp->d_func()->inPopupMode()) {
- // We always have to set the tracking, since
- // Windows detects more leaves than we do..
- TRACKMOUSEEVENT tme;
- tme.cbSize = sizeof(TRACKMOUSEEVENT);
- tme.dwFlags = 0x00000002; // TME_LEAVE
- tme.hwndTrack = curWin; // Track on window receiving msgs
- tme.dwHoverTime = (DWORD)-1; // HOVER_DEFAULT
- ptrTrackMouseEvent(&tme);
- }
- }
-#endif // Q_OS_WINCE
- }
-
- POINT curPos = msg.pt;
- if (curPos.x == gpos.x && curPos.y == gpos.y)
- return true; // same global position
- gpos = curPos;
-
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
- ScreenToClient(internalWinId(), &curPos);
-
- pos.rx() = curPos.x;
- pos.ry() = curPos.y;
- pos = d_func()->mapFromWS(pos);
- } else {
- gpos = msg.pt;
- pos = mapFromGlobal(QPoint(gpos.x, gpos.y));
-
- // mouse button pressed
- if (!qt_button_down && (type == QEvent::MouseButtonPress || type == QEvent::MouseButtonDblClick)) {
- QWidget *tlw = window();
- if (QWidget *child = tlw->childAt(mapTo(tlw, pos)))
- qt_button_down = child;
- else
- qt_button_down = this;
- }
- }
-
- bool res = false;
-
- bool nonClientAreaEvent = type >= QEvent::NonClientAreaMouseMove
- && type <= QEvent::NonClientAreaMouseButtonDblClick;
-
- if (qApp->d_func()->inPopupMode()) { // in popup mode
-
- if (nonClientAreaEvent)
- return false;
-
- replayPopupMouseEvent = false;
- QWidget* activePopupWidget = QApplication::activePopupWidget();
- QWidget *target = activePopupWidget;
- const QPoint globalPos(gpos.x, gpos.y);
-
- if (target != this) {
- if ((windowType() == Qt::Popup) && rect().contains(pos) && 0)
- target = this;
- else // send to last popup
- pos = target->mapFromGlobal(globalPos);
- }
- QWidget *popupChild = target->childAt(pos);
- bool releaseAfter = false;
- switch (type) {
- case QEvent::MouseButtonPress:
- case QEvent::MouseButtonDblClick:
- popupButtonFocus = popupChild;
- break;
- case QEvent::MouseButtonRelease:
- case QEvent::TabletRelease:
-
- releaseAfter = true;
- break;
- default:
- break; // nothing for mouse move
- }
-
- if (target->isEnabled()) {
- if (popupButtonFocus) {
- target = popupButtonFocus;
- } else if (popupChild) {
- target = popupChild;
- }
-
- pos = target->mapFromGlobal(globalPos);
- QMouseEvent e(type, pos, globalPos,
- Qt::MouseButton(button),
- Qt::MouseButtons(state & Qt::MouseButtonMask),
- Qt::KeyboardModifiers(state & Qt::KeyboardModifierMask));
- res = QApplicationPrivate::sendMouseEvent(target, &e, alienWidget, this, &qt_button_down,
- qt_last_mouse_receiver);
- res = res && e.isAccepted();
- } else {
- // close disabled popups when a mouse button is pressed or released
- switch (type) {
- case QEvent::MouseButtonPress:
- case QEvent::MouseButtonDblClick:
- case QEvent::MouseButtonRelease:
- target->close();
- break;
- default:
- break;
- }
- }
-
- if (releaseAfter) {
- popupButtonFocus = 0;
- qt_button_down = 0;
- }
-
-#ifndef Q_OS_WINCE
- if (type == QEvent::MouseButtonPress
- && QApplication::activePopupWidget() != activePopupWidget
- && ptrTrackMouseEvent
- && curWin) {
- // Since curWin is already the window we clicked on,
- // we have to setup the mouse tracking here.
- TRACKMOUSEEVENT tme;
- tme.cbSize = sizeof(TRACKMOUSEEVENT);
- tme.dwFlags = 0x00000002; // TME_LEAVE
- tme.hwndTrack = curWin; // Track on window receiving msgs
- tme.dwHoverTime = (DWORD)-1; // HOVER_DEFAULT
- ptrTrackMouseEvent(&tme);
- }
-#endif
- if (type == QEvent::MouseButtonPress
- && QApplication::activePopupWidget() != activePopupWidget
- && replayPopupMouseEvent) {
- // the popup disappeared. Replay the event
- QWidget* w = QApplication::widgetAt(gpos.x, gpos.y);
- if (w && !QApplicationPrivate::isBlockedByModal(w)) {
- Q_ASSERT(w->testAttribute(Qt::WA_WState_Created));
- HWND hwndTarget = w->effectiveWinId();
- if (QWidget::mouseGrabber() == 0)
- setAutoCapture(hwndTarget);
- if (!w->isActiveWindow())
- w->activateWindow();
- POINT widgetpt = gpos;
- ScreenToClient(hwndTarget, &widgetpt);
- LPARAM lParam = MAKELPARAM(widgetpt.x, widgetpt.y);
- PostMessage(hwndTarget, msg.message, msg.wParam, lParam);
- }
- } else if (type == QEvent::MouseButtonRelease && button == Qt::RightButton
- && QApplication::activePopupWidget() == activePopupWidget) {
- // popup still alive and received right-button-release
-#if !defined(QT_NO_CONTEXTMENU)
- QContextMenuEvent e2(QContextMenuEvent::Mouse, pos, globalPos,
- qt_win_getKeyboardModifiers());
- bool res2 = QApplication::sendSpontaneousEvent( target, &e2 );
- if (!res) // RMB not accepted
- res = res2 && e2.isAccepted();
-#endif
- }
- } else { // not popup mode
- int bs = state & Qt::MouseButtonMask;
- if ((type == QEvent::MouseButtonPress ||
- type == QEvent::MouseButtonDblClick) && bs == button) {
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
- if (QWidget::mouseGrabber() == 0)
- setAutoCapture(internalWinId());
- } else if (type == QEvent::MouseButtonRelease && bs == 0) {
- if (QWidget::mouseGrabber() == 0)
- releaseAutoCapture();
- }
-
- const QPoint globalPos(gpos.x,gpos.y);
- QWidget *widget = QApplicationPrivate::pickMouseReceiver(this, globalPos, pos, type,
- Qt::MouseButtons(bs),
- qt_button_down, alienWidget);
- if (!widget)
- return false; // don't send event
-
- QMouseEvent e(type, pos, globalPos, Qt::MouseButton(button),
- Qt::MouseButtons(state & Qt::MouseButtonMask),
- Qt::KeyboardModifiers(state & Qt::KeyboardModifierMask));
-
- res = QApplicationPrivate::sendMouseEvent(widget, &e, alienWidget, this, &qt_button_down,
- qt_last_mouse_receiver);
-
- // non client area events are only informational, you cannot "handle" them
- res = res && e.isAccepted() && !nonClientAreaEvent;
-#if !defined(QT_NO_CONTEXTMENU)
- if (type == QEvent::MouseButtonRelease && button == Qt::RightButton) {
- QContextMenuEvent e2(QContextMenuEvent::Mouse, pos, globalPos,
- qt_win_getKeyboardModifiers());
- bool res2 = QApplication::sendSpontaneousEvent(widget, &e2);
- if (!res)
- res = res2 && e2.isAccepted();
- }
-#endif
-
- if (type != QEvent::MouseMove)
- pos.rx() = pos.ry() = -9999; // init for move compression
- }
- return res;
-}
-
-bool QETWidget::translateWheelEvent(const MSG &msg)
-{
- int state = 0;
-
- if (sm_blockUserInput) // block user interaction during session management
- return true;
-
- state = translateButtonState(GET_KEYSTATE_WPARAM(msg.wParam), 0, 0);
-
- int delta;
- if (msg.message == WM_MOUSEWHEEL || msg.message == WM_MOUSEHWHEEL)
- delta = (short) HIWORD (msg.wParam);
- else
- delta = (int) msg.wParam;
-
- Qt::Orientation orient = (msg.message == WM_MOUSEHWHEEL || state&Qt::AltModifier
-#if 0
- // disabled for now - Trenton's one-wheel mouse makes trouble...
- // "delta" for usual wheels is +-120. +-240 seems to indicate
- // the second wheel see more recent MSDN for WM_MOUSEWHEEL
-
- ( // <- parantheses added to make update happy, remove if the
- // #if 0 is removed
- || delta == 240 || delta == -240)?Qt::Horizontal:Vertical;
- if (delta == 240 || delta == -240)
- delta /= 2;
-#endif
- ) ? Qt::Horizontal : Qt::Vertical;
-
- // according to the MSDN documentation on WM_MOUSEHWHEEL:
- // a positive value indicates that the wheel was rotated to the right;
- // a negative value indicates that the wheel was rotated to the left.
- // Qt defines this value as the exact opposite, so we have to flip the value!
- if (msg.message == WM_MOUSEHWHEEL)
- delta = -delta;
-
- QPoint globalPos;
-
- globalPos.rx() = (short)LOWORD (msg.lParam);
- globalPos.ry() = (short)HIWORD (msg.lParam);
-
-
- // if there is a widget under the mouse and it is not shadowed
- // by modality, we send the event to it first
- int ret = 0;
- QWidget* w = QApplication::widgetAt(globalPos);
- if (!w || !qt_try_modal(w, (MSG*)&msg, ret)) {
- //synaptics touchpad shows its own widget at this position
- //so widgetAt() will fail with that HWND, try child of this widget
- w = this->childAt(this->mapFromGlobal(globalPos));
- if (!w)
- w = this;
- }
-
- // send the event to the widget or its ancestors
- {
- QWidget* popup = QApplication::activePopupWidget();
- if (popup && w->window() != popup)
- popup->close();
-#ifndef QT_NO_WHEELEVENT
- QWheelEvent e(w->mapFromGlobal(globalPos), globalPos, delta,
- Qt::MouseButtons(state & Qt::MouseButtonMask),
- Qt::KeyboardModifier(state & Qt::KeyboardModifierMask), orient);
-
- if (QApplication::sendSpontaneousEvent(w, &e))
-#else
- Q_UNUSED(orient);
-#endif //QT_NO_WHEELEVENT
- return true;
- }
-
- // send the event to the widget that has the focus or its ancestors, if different
- if (w != QApplication::focusWidget() && (w = QApplication::focusWidget())) {
- QWidget* popup = QApplication::activePopupWidget();
- if (popup && w->window() != popup)
- popup->close();
-#ifndef QT_NO_WHEELEVENT
- QWheelEvent e(w->mapFromGlobal(globalPos), globalPos, delta,
- Qt::MouseButtons(state & Qt::MouseButtonMask),
- Qt::KeyboardModifier(state & Qt::KeyboardModifierMask), orient);
- if (QApplication::sendSpontaneousEvent(w, &e))
-#endif //QT_NO_WHEELEVENT
- return true;
- }
- return false;
-}
-
-
-//
-// Windows Wintab to QTabletEvent translation
-//
-
-// the following is adapted from the wintab syspress example (public domain)
-/* -------------------------------------------------------------------------- */
-// Initialize the "static" information of a cursor device (pen, airbrush, etc).
-// The QTabletDeviceData is initialized with the data that do not change in time
-// (number of button, type of device, etc) but do not initialize the variable data
-// (e.g.: pen or eraser)
-#ifndef QT_NO_TABLETEVENT
-
-static void tabletInit(const quint64 uniqueId, const UINT csr_type, HCTX hTab)
-{
- Q_ASSERT(ptrWTInfo);
- Q_ASSERT(ptrWTGet);
-
- Q_ASSERT(!tCursorInfo()->contains(uniqueId));
-
- /* browse WinTab's many info items to discover pressure handling. */
- AXIS np;
- LOGCONTEXT lc;
-
- /* get the current context for its device variable. */
- ptrWTGet(hTab, &lc);
-
- /* get the size of the pressure axis. */
- QTabletDeviceData tdd;
- tdd.llId = uniqueId;
-
- ptrWTInfo(WTI_DEVICES + lc.lcDevice, DVC_NPRESSURE, &np);
- tdd.minPressure = int(np.axMin);
- tdd.maxPressure = int(np.axMax);
-
- ptrWTInfo(WTI_DEVICES + lc.lcDevice, DVC_TPRESSURE, &np);
- tdd.minTanPressure = int(np.axMin);
- tdd.maxTanPressure = int(np.axMax);
-
- LOGCONTEXT lcMine;
-
- /* get default region */
- ptrWTInfo(WTI_DEFCONTEXT, 0, &lcMine);
-
- tdd.minX = 0;
- tdd.maxX = int(lcMine.lcInExtX) - int(lcMine.lcInOrgX);
-
- tdd.minY = 0;
- tdd.maxY = int(lcMine.lcInExtY) - int(lcMine.lcInOrgY);
-
- tdd.minZ = 0;
- tdd.maxZ = int(lcMine.lcInExtZ) - int(lcMine.lcInOrgZ);
-
- const uint cursorTypeBitMask = 0x0F06; // bitmask to find the specific cursor type (see Wacom FAQ)
- if (((csr_type & 0x0006) == 0x0002) && ((csr_type & cursorTypeBitMask) != 0x0902)) {
- tdd.currentDevice = QTabletEvent::Stylus;
- } else {
- switch (csr_type & cursorTypeBitMask) {
- case 0x0802:
- tdd.currentDevice = QTabletEvent::Stylus;
- break;
- case 0x0902:
- tdd.currentDevice = QTabletEvent::Airbrush;
- break;
- case 0x0004:
- tdd.currentDevice = QTabletEvent::FourDMouse;
- break;
- case 0x0006:
- tdd.currentDevice = QTabletEvent::Puck;
- break;
- case 0x0804:
- tdd.currentDevice = QTabletEvent::RotationStylus;
- break;
- default:
- tdd.currentDevice = QTabletEvent::NoDevice;
- }
- }
- tCursorInfo()->insert(uniqueId, tdd);
-}
-#endif // QT_NO_TABLETEVENT
-
-// Update the "dynamic" information of a cursor device (pen, airbrush, etc).
-// The dynamic information is the information of QTabletDeviceData that can change
-// in time (eraser or pen if a device is turned around).
-#ifndef QT_NO_TABLETEVENT
-
-static void tabletUpdateCursor(QTabletDeviceData &tdd, const UINT currentCursor)
-{
- switch (currentCursor % 3) { // %3 for dual track
- case 0:
- tdd.currentPointerType = QTabletEvent::Cursor;
- break;
- case 1:
- tdd.currentPointerType = QTabletEvent::Pen;
- break;
- case 2:
- tdd.currentPointerType = QTabletEvent::Eraser;
- break;
- default:
- tdd.currentPointerType = QTabletEvent::UnknownPointer;
- }
-}
-#endif // QT_NO_TABLETEVENT
-
-bool QETWidget::translateTabletEvent(const MSG &msg, PACKET *localPacketBuf,
- int numPackets)
-{
- Q_UNUSED(msg);
- POINT ptNew;
- static DWORD btnNew, btnOld, btnChange;
- qreal prsNew;
- ORIENTATION ort;
- static bool button_pressed = false;
- int i,
- tiltX,
- tiltY;
- bool sendEvent = false;
- QEvent::Type t;
- int z = 0;
- qreal rotation = 0.0;
- qreal tangentialPressure;
-
- // the most common event that we get...
- t = QEvent::TabletMove;
- for (i = 0; i < numPackets; i++) {
- // get the unique ID of the device...
- btnOld = btnNew;
- btnNew = localPacketBuf[i].pkButtons;
- btnChange = btnOld ^ btnNew;
-
- if (btnNew & btnChange) {
- button_pressed = true;
- t = QEvent::TabletPress;
- }
- ptNew.x = UINT(localPacketBuf[i].pkX);
- ptNew.y = UINT(localPacketBuf[i].pkY);
-#ifndef QT_NO_TABLETEVENT
- z = (currentTabletPointer.currentDevice == QTabletEvent::FourDMouse) ? UINT(localPacketBuf[i].pkZ) : 0;
-#else
- Q_UNUSED(z);
-#endif // QT_NO_TABLETEVENT
- prsNew = 0.0;
- QRect desktopArea = QApplication::desktop()->geometry();
- QPointF hiResGlobal = currentTabletPointer.scaleCoord(ptNew.x, ptNew.y, desktopArea.left(),
- desktopArea.width(), desktopArea.top(),
- desktopArea.height());
-
- if (btnNew) {
-#ifndef QT_NO_TABLETEVENT
- if (currentTabletPointer.currentPointerType == QTabletEvent::Pen || currentTabletPointer.currentPointerType == QTabletEvent::Eraser)
- prsNew = localPacketBuf[i].pkNormalPressure
- / qreal(currentTabletPointer.maxPressure
- - currentTabletPointer.minPressure);
- else
-#endif // QT_NO_TABLETEVENT
- prsNew = 0;
- } else if (button_pressed) {
- // One button press, should only give one button release
- t = QEvent::TabletRelease;
- button_pressed = false;
- }
- QPoint globalPos(qRound(hiResGlobal.x()), qRound(hiResGlobal.y()));
-
- if (t == QEvent::TabletPress)
- {
- qt_button_down = QApplication::widgetAt(globalPos);
- }
-
- // make sure the tablet event get's sent to the proper widget...
- QWidget *w = 0;
-
- if (qt_button_down)
- w = qt_button_down; // Pass it to the thing that's grabbed it.
- else
- w = QApplication::widgetAt(globalPos);
-
- if (!w)
- w = this;
-
- if (t == QEvent::TabletRelease)
- {
- if (qt_win_ignoreNextMouseReleaseEvent) {
- qt_win_ignoreNextMouseReleaseEvent = false;
- if (qt_button_down && qt_button_down->internalWinId() == autoCaptureWnd) {
- releaseAutoCapture();
- qt_button_down = 0;
- }
- }
-
- }
-
- QPoint localPos = w->mapFromGlobal(globalPos);
-#ifndef QT_NO_TABLETEVENT
- if (currentTabletPointer.currentDevice == QTabletEvent::Airbrush) {
- tangentialPressure = localPacketBuf[i].pkTangentPressure
- / qreal(currentTabletPointer.maxTanPressure
- - currentTabletPointer.minTanPressure);
- } else {
- tangentialPressure = 0.0;
- }
-#else
- tangentialPressure = 0.0;
-#endif // QT_NO_TABLETEVENT
-
- if (!qt_tablet_tilt_support) {
- tiltX = tiltY = 0;
- rotation = 0.0;
- } else {
- ort = localPacketBuf[i].pkOrientation;
- // convert from azimuth and altitude to x tilt and y tilt
- // what follows is the optimized version. Here are the equations
- // I used to get to this point (in case things change :)
- // X = sin(azimuth) * cos(altitude)
- // Y = cos(azimuth) * cos(altitude)
- // Z = sin(altitude)
- // X Tilt = arctan(X / Z)
- // Y Tilt = arctan(Y / Z)
- double radAzim = (ort.orAzimuth / 10) * (Q_PI / 180);
- //double radAlt = abs(ort.orAltitude / 10) * (Q_PI / 180);
- double tanAlt = tan((abs(ort.orAltitude / 10)) * (Q_PI / 180));
-
- double degX = atan(sin(radAzim) / tanAlt);
- double degY = atan(cos(radAzim) / tanAlt);
- tiltX = int(degX * (180 / Q_PI));
- tiltY = int(-degY * (180 / Q_PI));
- rotation = ort.orTwist;
- }
-#ifndef QT_NO_TABLETEVENT
- QTabletEvent e(t, localPos, globalPos, hiResGlobal, currentTabletPointer.currentDevice,
- currentTabletPointer.currentPointerType, prsNew, tiltX, tiltY,
- tangentialPressure, rotation, z, QApplication::keyboardModifiers(), currentTabletPointer.llId);
- sendEvent = QApplication::sendSpontaneousEvent(w, &e);
-#endif // QT_NO_TABLETEVENT
- }
- return sendEvent;
-}
-
-extern bool qt_is_gui_used;
-
-
-#ifndef QT_NO_TABLETEVENT
-
-static void initWinTabFunctions()
-{
-#if defined(Q_OS_WINCE)
- return;
-#else
- if (!qt_is_gui_used)
- return;
-
- QSystemLibrary library(QLatin1String("wintab32"));
- ptrWTInfo = (PtrWTInfo)library.resolve("WTInfoW");
- ptrWTGet = (PtrWTGet)library.resolve("WTGetW");
- ptrWTEnable = (PtrWTEnable)library.resolve("WTEnable");
- ptrWTOverlap = (PtrWTEnable)library.resolve("WTOverlap");
- ptrWTPacketsGet = (PtrWTPacketsGet)library.resolve("WTPacketsGet");
-#endif // Q_OS_WINCE
-}
-#endif // QT_NO_TABLETEVENT
-
-
-//
-// Paint event translation
-//
-bool QETWidget::translatePaintEvent(const MSG &msg)
-{
- if (!isWindow() && testAttribute(Qt::WA_NativeWindow))
- Q_ASSERT(internalWinId());
-
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
- if (!GetUpdateRect(internalWinId(), 0, FALSE)) { // The update bounding rect is invalid
- d_func()->hd = 0;
- setAttribute(Qt::WA_PendingUpdate, false);
- return false;
- }
-
- if (msg.message == WM_ERASEBKGND)
- return true;
-
- setAttribute(Qt::WA_PendingUpdate, false);
-
- if (d_func()->isGLWidget) {
- if (d_func()->usesDoubleBufferedGLContext)
- InvalidateRect(internalWinId(), 0, false);
- } else {
- const QRegion dirtyInBackingStore(qt_dirtyRegion(this));
- // Make sure the invalidated region contains the region we're about to repaint.
- // BeginPaint will set the clip to the invalidated region and it is impossible
- // to enlarge it afterwards (only shrink it). Using GetDCEx is not suffient
- // as it may return an invalid context (especially on Windows Vista).
- if (!dirtyInBackingStore.isEmpty())
- InvalidateRgn(internalWinId(), dirtyInBackingStore.handle(), false);
- }
- PAINTSTRUCT ps;
- d_func()->hd = BeginPaint(internalWinId(), &ps);
-
- const QRect updateRect(QPoint(ps.rcPaint.left, ps.rcPaint.top),
- QPoint(ps.rcPaint.right, ps.rcPaint.bottom));
-
- // Mapping region from system to qt (32 bit) coordinate system.
- d_func()->syncBackingStore(updateRect.translated(data->wrect.topLeft()));
-
- d_func()->hd = 0;
- EndPaint(internalWinId(), &ps);
-
- return true;
-}
-
-//
-// Window move and resize (configure) events
-//
-
-bool QETWidget::translateConfigEvent(const MSG &msg)
-{
- if (!testAttribute(Qt::WA_WState_Created)) // in QWidget::create()
- return true;
- if (testAttribute(Qt::WA_WState_ConfigPending))
- return true;
- if (testAttribute(Qt::WA_DontShowOnScreen))
- return true;
- if (!isWindow())
- return true;
- setAttribute(Qt::WA_WState_ConfigPending); // set config flag
- QRect cr = geometry();
- if (msg.message == WM_SIZE) { // resize event
- WORD a = LOWORD(msg.lParam);
- WORD b = HIWORD(msg.lParam);
- QSize oldSize = size();
- QSize newSize(a, b);
-#ifdef Q_WS_WINCE_WM
- if (isFullScreen() && (oldSize.width() == newSize.height()) && (oldSize.height() == newSize.width()))
- qt_wince_hide_taskbar(internalWinId());
-#endif
- cr.setSize(newSize);
- if (msg.wParam != SIZE_MINIMIZED)
- data->crect = cr;
- if (isWindow()) { // update title/icon text
- d_func()->createTLExtra();
- // Capture SIZE_MINIMIZED without preceding WM_SYSCOMMAND
- // (like Windows+M)
- if (msg.wParam == SIZE_MINIMIZED && !isMinimized()) {
-#ifndef Q_WS_WINCE
- const QString title = windowIconText();
- if (!title.isEmpty())
- d_func()->setWindowTitle_helper(title);
-#endif
- data->window_state |= Qt::WindowMinimized;
- if (isVisible()) {
- QHideEvent e;
- QApplication::sendSpontaneousEvent(this, &e);
- hideChildren(true);
- }
- } else if (msg.wParam != SIZE_MINIMIZED) {
- bool window_state_changed = false;
- Qt::WindowStates oldstate = Qt::WindowStates(dataPtr()->window_state);
- if (isMinimized()) {
-#ifndef Q_WS_WINCE
- const QString title = windowTitle();
- if (!title.isEmpty())
- d_func()->setWindowTitle_helper(title);
-#endif
- data->window_state &= ~Qt::WindowMinimized;
- showChildren(true);
- QShowEvent e;
- QApplication::sendSpontaneousEvent(this, &e);
- // Capture SIZE_MAXIMIZED and SIZE_RESTORED without preceding WM_SYSCOMMAND
- // (Aero Snap on Win7)
- } else if (msg.wParam == SIZE_MAXIMIZED && !isMaximized()) {
- data->window_state |= Qt::WindowMaximized;
- window_state_changed = true;
- } else if (msg.wParam == SIZE_RESTORED && isMaximized()) {
- data->window_state &= ~(Qt::WindowMaximized);
- window_state_changed = true;
- }
- if (window_state_changed) {
- QWindowStateChangeEvent e(oldstate);
- QApplication::sendSpontaneousEvent(this, &e);
- }
- }
- }
- if (msg.wParam != SIZE_MINIMIZED && oldSize != newSize) {
- if (isVisible()) {
- QTLWExtra *tlwExtra = maybeTopData();
- static bool slowResize = qgetenv("QT_SLOW_TOPLEVEL_RESIZE").toInt();
- const bool hasStaticContents = tlwExtra && tlwExtra->backingStore
- && tlwExtra->backingStore->hasStaticContents();
- // If we have a backing store with static contents, we have to disable the top-level
- // resize optimization in order to get invalidated regions for resized widgets.
- // The optimization discards all invalidateBuffer() calls since we're going to
- // repaint everything anyways, but that's not the case with static contents.
- if (!slowResize && tlwExtra && !hasStaticContents)
- tlwExtra->inTopLevelResize = true;
- QResizeEvent e(newSize, oldSize);
- QApplication::sendSpontaneousEvent(this, &e);
- if (d_func()->paintOnScreen()) {
- QRegion updateRegion(rect());
- if (testAttribute(Qt::WA_StaticContents))
- updateRegion -= QRect(0, 0, oldSize.width(), oldSize.height());
- d_func()->syncBackingStore(updateRegion);
- } else {
- d_func()->syncBackingStore();
- }
- if (!slowResize && tlwExtra)
- tlwExtra->inTopLevelResize = false;
- } else {
- QResizeEvent *e = new QResizeEvent(newSize, oldSize);
- QApplication::postEvent(this, e);
- }
- }
- } else if (msg.message == WM_MOVE) { // move event
- int a = (int) (short) LOWORD(msg.lParam);
- int b = (int) (short) HIWORD(msg.lParam);
- QPoint oldPos = geometry().topLeft();
- QPoint newCPos(a, b);
- // Ignore silly Windows move event to wild pos after iconify.
-#if !defined(Q_WS_WINCE)
- if (!IsIconic(internalWinId()) && newCPos != oldPos) {
-#endif
- cr.moveTopLeft(newCPos);
- data->crect = cr;
- if (isVisible()) {
- QMoveEvent e(newCPos, oldPos); // cpos (client position)
- QApplication::sendSpontaneousEvent(this, &e);
- } else {
- QMoveEvent * e = new QMoveEvent(newCPos, oldPos);
- QApplication::postEvent(this, e);
- }
-#if !defined(Q_WS_WINCE)
- }
-#endif
- }
- setAttribute(Qt::WA_WState_ConfigPending, false); // clear config flag
- return true;
-}
-
-
-//
-// Close window event translation.
-//
-// This class is a friend of QApplication because it needs to emit the
-// lastWindowClosed() signal when the last top level widget is closed.
-//
-
-bool QETWidget::translateCloseEvent(const MSG &)
-{
- return d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent);
-}
-
-#ifndef QT_NO_GESTURES
-bool QETWidget::translateGestureEvent(const MSG &, const GESTUREINFO &gi)
-{
- const QPoint widgetPos = QPoint(gi.ptsLocation.x, gi.ptsLocation.y);
- QWidget *alienWidget = !internalWinId() ? this : childAt(widgetPos);
- if (alienWidget && alienWidget->internalWinId())
- alienWidget = 0;
- QWidget *widget = alienWidget ? alienWidget : this;
-
- QNativeGestureEvent event;
- event.sequenceId = gi.dwSequenceID;
- event.position = QPoint(gi.ptsLocation.x, gi.ptsLocation.y);
- event.argument = gi.ullArguments;
-
- switch (gi.dwID) {
- case GID_BEGIN:
- event.gestureType = QNativeGestureEvent::GestureBegin;
- break;
- case GID_END:
- event.gestureType = QNativeGestureEvent::GestureEnd;
- break;
- case GID_ZOOM:
- event.gestureType = QNativeGestureEvent::Zoom;
- break;
- case GID_PAN:
- event.gestureType = QNativeGestureEvent::Pan;
- break;
- case GID_ROTATE:
- event.gestureType = QNativeGestureEvent::Rotate;
- break;
- case GID_TWOFINGERTAP:
- case GID_ROLLOVER:
- default:
- break;
- }
- if (event.gestureType != QNativeGestureEvent::None)
- qt_sendSpontaneousEvent(widget, &event);
- return true;
-}
-#endif // QT_NO_GESTURES
-
-void QApplication::setCursorFlashTime(int msecs)
-{
- SetCaretBlinkTime(msecs / 2);
- QApplicationPrivate::cursor_flash_time = msecs;
-}
-
-
-int QApplication::cursorFlashTime()
-{
- int blink = (int)GetCaretBlinkTime();
- if (!blink)
- return QApplicationPrivate::cursor_flash_time;
- if (blink > 0)
- return 2*blink;
- return 0;
-}
-
-
-void QApplication::setDoubleClickInterval(int ms)
-{
-#ifndef Q_WS_WINCE
- SetDoubleClickTime(ms);
-#endif
- QApplicationPrivate::mouse_double_click_time = ms;
-}
-
-int QApplication::doubleClickInterval()
-{
- int ms = GetDoubleClickTime();
- if (ms != 0)
- return ms;
- return QApplicationPrivate::mouse_double_click_time;
-}
-
-
-void QApplication::setKeyboardInputInterval(int ms)
-{
- QApplicationPrivate::keyboard_input_time = ms;
-}
-
-int QApplication::keyboardInputInterval()
-{
- // FIXME: get from the system
- return QApplicationPrivate::keyboard_input_time;
-}
-
-#ifndef QT_NO_WHEELEVENT
-void QApplication::setWheelScrollLines(int n)
-{
-#ifdef SPI_SETWHEELSCROLLLINES
- if (n < 0)
- n = 0;
- SystemParametersInfo(SPI_SETWHEELSCROLLLINES, (uint)n, 0, 0);
-#else
- QApplicationPrivate::wheel_scroll_lines = n;
-#endif
-}
-
-int QApplication::wheelScrollLines()
-{
-#ifdef SPI_GETWHEELSCROLLLINES
- uint i = 3;
- SystemParametersInfo(SPI_GETWHEELSCROLLLINES, sizeof(uint), &i, 0);
- if (i > INT_MAX)
- i = INT_MAX;
- return i;
-#else
- return QApplicationPrivate::wheel_scroll_lines;
-#endif
-}
-#endif //QT_NO_WHEELEVENT
-
-static bool effect_override = false;
-
-void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable)
-{
- effect_override = true;
- switch (effect) {
- case Qt::UI_AnimateMenu:
- QApplicationPrivate::animate_menu = enable;
- break;
- case Qt::UI_FadeMenu:
- QApplicationPrivate::fade_menu = enable;
- break;
- case Qt::UI_AnimateCombo:
- QApplicationPrivate::animate_combo = enable;
- break;
- case Qt::UI_AnimateTooltip:
- QApplicationPrivate::animate_tooltip = enable;
- break;
- case Qt::UI_FadeTooltip:
- QApplicationPrivate::fade_tooltip = enable;
- break;
- case Qt::UI_AnimateToolBox:
- QApplicationPrivate::animate_toolbox = enable;
- break;
- default:
- QApplicationPrivate::animate_ui = enable;
- break;
- }
-}
-
-bool QApplication::isEffectEnabled(Qt::UIEffect effect)
-{
- if (QColormap::instance().depth() < 16)
- return false;
-
- if (!effect_override && desktopSettingsAware()) {
- // we know that they can be used when we are here
- BOOL enabled = false;
- UINT api;
- switch (effect) {
- case Qt::UI_AnimateMenu:
- api = SPI_GETMENUANIMATION;
- break;
- case Qt::UI_FadeMenu:
- api = SPI_GETMENUFADE;
- break;
- case Qt::UI_AnimateCombo:
- api = SPI_GETCOMBOBOXANIMATION;
- break;
- case Qt::UI_AnimateTooltip:
- api = SPI_GETTOOLTIPANIMATION;
- break;
- case Qt::UI_FadeTooltip:
- api = SPI_GETTOOLTIPFADE;
- break;
- default:
- api = SPI_GETUIEFFECTS;
- break;
- }
- SystemParametersInfo(api, 0, &enabled, 0);
- return enabled;
- }
-
- switch(effect) {
- case Qt::UI_AnimateMenu:
- return QApplicationPrivate::animate_menu;
- case Qt::UI_FadeMenu:
- return QApplicationPrivate::fade_menu;
- case Qt::UI_AnimateCombo:
- return QApplicationPrivate::animate_combo;
- case Qt::UI_AnimateTooltip:
- return QApplicationPrivate::animate_tooltip;
- case Qt::UI_FadeTooltip:
- return QApplicationPrivate::fade_tooltip;
- case Qt::UI_AnimateToolBox:
- return QApplicationPrivate::animate_toolbox;
- default:
- return QApplicationPrivate::animate_ui;
- }
-}
-
-#ifndef QT_NO_SESSIONMANAGER
-
-bool QSessionManager::allowsInteraction()
-{
- sm_blockUserInput = false;
- return true;
-}
-
-bool QSessionManager::allowsErrorInteraction()
-{
- sm_blockUserInput = false;
- return true;
-}
-
-void QSessionManager::release()
-{
- if (sm_smActive)
- sm_blockUserInput = true;
-}
-
-void QSessionManager::cancel()
-{
- sm_cancel = true;
-}
-
-#endif //QT_NO_SESSIONMANAGER
-
-
-bool QApplicationPrivate::HasTouchSupport = false;
-PtrRegisterTouchWindow QApplicationPrivate::RegisterTouchWindow = 0;
-PtrGetTouchInputInfo QApplicationPrivate::GetTouchInputInfo = 0;
-PtrCloseTouchInputHandle QApplicationPrivate::CloseTouchInputHandle = 0;
-
-void QApplicationPrivate::initializeMultitouch_sys()
-{
- if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7) {
- static const int QT_SM_DIGITIZER = 94;
- int value = GetSystemMetrics(QT_SM_DIGITIZER);
- static const int QT_NID_INTEGRATED_TOUCH = 0x01;
- static const int QT_NID_EXTERNAL_TOUCH = 0x02;
- static const int QT_NID_MULTI_INPUT = 0x40;
- QApplicationPrivate::HasTouchSupport =
- value & (QT_NID_INTEGRATED_TOUCH | QT_NID_EXTERNAL_TOUCH | QT_NID_MULTI_INPUT);
- }
-
- QSystemLibrary library(QLatin1String("user32"));
- // MinGW (g++ 3.4.5) accepts only C casts.
- RegisterTouchWindow = (PtrRegisterTouchWindow)(library.resolve("RegisterTouchWindow"));
- GetTouchInputInfo = (PtrGetTouchInputInfo)(library.resolve("GetTouchInputInfo"));
- CloseTouchInputHandle = (PtrCloseTouchInputHandle)(library.resolve("CloseTouchInputHandle"));
-
- touchInputIDToTouchPointID.clear();
-}
-
-void QApplicationPrivate::cleanupMultitouch_sys()
-{
- touchInputIDToTouchPointID.clear();
-}
-
-bool QApplicationPrivate::translateTouchEvent(const MSG &msg)
-{
- QWidget *widgetForHwnd = QWidget::find(msg.hwnd);
- if (!widgetForHwnd)
- return false;
-
- QRect screenGeometry = QApplication::desktop()->screenGeometry(widgetForHwnd);
-
- QList<QTouchEvent::TouchPoint> touchPoints;
-
- QVector<TOUCHINPUT> winTouchInputs(msg.wParam);
- memset(winTouchInputs.data(), 0, sizeof(TOUCHINPUT) * winTouchInputs.count());
- Qt::TouchPointStates allStates = 0;
- QApplicationPrivate::GetTouchInputInfo((HANDLE) msg.lParam, msg.wParam, winTouchInputs.data(), sizeof(TOUCHINPUT));
- for (int i = 0; i < winTouchInputs.count(); ++i) {
- const TOUCHINPUT &touchInput = winTouchInputs.at(i);
-
- int touchPointID = touchInputIDToTouchPointID.value(touchInput.dwID, -1);
- if (touchPointID == -1) {
- touchPointID = touchInputIDToTouchPointID.count();
- touchInputIDToTouchPointID.insert(touchInput.dwID, touchPointID);
- }
-
- QTouchEvent::TouchPoint touchPoint(touchPointID);
-
- // update state
- QPointF screenPos(qreal(touchInput.x) / qreal(100.), qreal(touchInput.y) / qreal(100.));
- QRectF screenRect;
- if (touchInput.dwMask & TOUCHINPUTMASKF_CONTACTAREA)
- screenRect.setSize(QSizeF(qreal(touchInput.cxContact) / qreal(100.),
- qreal(touchInput.cyContact) / qreal(100.)));
- screenRect.moveCenter(screenPos);
-
- Qt::TouchPointStates state;
- if (touchInput.dwFlags & TOUCHEVENTF_DOWN) {
- state = Qt::TouchPointPressed;
- } else if (touchInput.dwFlags & TOUCHEVENTF_UP) {
- state = Qt::TouchPointReleased;
- } else {
- state = (screenPos == touchPoint.screenPos()
- ? Qt::TouchPointStationary
- : Qt::TouchPointMoved);
- }
- if (touchInput.dwFlags & TOUCHEVENTF_PRIMARY)
- state |= Qt::TouchPointPrimary;
- touchPoint.setState(state);
- touchPoint.setScreenRect(screenRect);
- touchPoint.setNormalizedPos(QPointF(screenPos.x() / screenGeometry.width(),
- screenPos.y() / screenGeometry.height()));
-
- allStates |= state;
-
- touchPoints.append(touchPoint);
- }
- QApplicationPrivate::CloseTouchInputHandle((HANDLE) msg.lParam);
-
- if ((allStates & Qt::TouchPointStateMask) == Qt::TouchPointReleased) {
- // all touch points released, forget the ids we've seen, they may not be reused
- touchInputIDToTouchPointID.clear();
- }
-
- translateRawTouchEvent(widgetForHwnd, QTouchEvent::TouchScreen, touchPoints);
- return true;
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp
deleted file mode 100644
index 20542ea328..0000000000
--- a/src/gui/kernel/qapplication_x11.cpp
+++ /dev/null
@@ -1,6239 +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$
-**
-****************************************************************************/
-
-// ### 4.0: examine Q_EXPORT's below. The respective symbols had all
-// been in use (e.g. in the KDE wm) before the introduction of a version
-// map. One might want to turn some of them into proper public API and
-// provide a proper alternative for others. See also the exports in
-// qapplication_win.cpp, which suggest a unification.
-
-#include "qplatformdefs.h"
-
-#include "qcolormap.h"
-#include "qdesktopwidget.h"
-#include "qapplication.h"
-#include "qapplication_p.h"
-#include "qcursor.h"
-#include "qwidget.h"
-#include "qbitarray.h"
-#include "qpainter.h"
-#include "qfile.h"
-#include "qpixmapcache.h"
-#include "qdatetime.h"
-#include "qtextcodec.h"
-#include "qdatastream.h"
-#include "qbuffer.h"
-#include "qsocketnotifier.h"
-#include "qsessionmanager.h"
-#include "qclipboard.h"
-#include "qwhatsthis.h"
-#include "qsettings.h"
-#include "qstylefactory.h"
-#include "qfileinfo.h"
-#include "qdir.h"
-#include "qhash.h"
-#include "qevent.h"
-#include "qevent_p.h"
-#include "qvarlengtharray.h"
-#include "qdebug.h"
-#include <private/qcrashhandler_p.h>
-#include <private/qcolor_p.h>
-#include <private/qcursor_p.h>
-#include <private/qiconloader_p.h>
-#include <qgtkstyle.h>
-#include "qstyle.h"
-#include "qmetaobject.h"
-#include "qtimer.h"
-#include "qlibrary.h"
-#include <private/qgraphicssystemfactory_p.h>
-#include "qguiplatformplugin_p.h"
-#include "qkde_p.h"
-
-#if !defined (QT_NO_TABLET)
-extern "C" {
-# define class c_class //XIproto.h has a name member named 'class' which the c++ compiler doesn't like
-# include <wacomcfg.h>
-# undef class
-}
-#endif
-
-#ifndef QT_GUI_DOUBLE_CLICK_RADIUS
-#define QT_GUI_DOUBLE_CLICK_RADIUS 5
-#endif
-
-
-//#define ALIEN_DEBUG
-
-#if !defined(QT_NO_GLIB)
-# include "qguieventdispatcher_glib_p.h"
-#endif
-#include "qeventdispatcher_x11_p.h"
-#include <private/qpaintengine_x11_p.h>
-
-#include <private/qkeymapper_p.h>
-
-// Input method stuff
-#ifndef QT_NO_IM
-#include "qinputcontext.h"
-#include "qinputcontextfactory.h"
-#endif // QT_NO_IM
-
-#ifndef QT_NO_XFIXES
-#include <X11/extensions/Xfixes.h>
-#endif // QT_NO_XFIXES
-
-#include "qt_x11_p.h"
-#include "qx11info_x11.h"
-
-#define XK_MISCELLANY
-#include <X11/keysymdef.h>
-#if !defined(QT_NO_XINPUT)
-#include <X11/extensions/XI.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <locale.h>
-
-#include "qwidget_p.h"
-
-#include <private/qbackingstore_p.h>
-
-#ifdef QT_RX71_MULTITOUCH
-# include <qsocketnotifier.h>
-# include <linux/input.h>
-# include <errno.h>
-#endif
-
-#if _POSIX_VERSION+0 < 200112L && !defined(Q_OS_BSD4)
-# define QT_NO_UNSETENV
-#endif
-
-QT_BEGIN_NAMESPACE
-
-//#define X_NOT_BROKEN
-#ifdef X_NOT_BROKEN
-// Some X libraries are built with setlocale #defined to _Xsetlocale,
-// even though library users are then built WITHOUT such a definition.
-// This creates a problem - Qt might setlocale() one value, but then
-// X looks and doesn't see the value Qt set. The solution here is to
-// implement _Xsetlocale just in case X calls it - redirecting it to
-// the real libC version.
-//
-# ifndef setlocale
-extern "C" char *_Xsetlocale(int category, const char *locale);
-char *_Xsetlocale(int category, const char *locale)
-{
- //qDebug("_Xsetlocale(%d,%s),category,locale");
- return setlocale(category,locale);
-}
-# endif // setlocale
-#endif // X_NOT_BROKEN
-
-/* Warning: if you modify this string, modify the list of atoms in qt_x11_p.h as well! */
-static const char * x11_atomnames = {
- // window-manager <-> client protocols
- "WM_PROTOCOLS\0"
- "WM_DELETE_WINDOW\0"
- "WM_TAKE_FOCUS\0"
- "_NET_WM_PING\0"
- "_NET_WM_CONTEXT_HELP\0"
- "_NET_WM_SYNC_REQUEST\0"
- "_NET_WM_SYNC_REQUEST_COUNTER\0"
-
- // ICCCM window state
- "WM_STATE\0"
- "WM_CHANGE_STATE\0"
-
- // Session management
- "WM_CLIENT_LEADER\0"
- "WM_WINDOW_ROLE\0"
- "SM_CLIENT_ID\0"
-
- // Clipboard
- "CLIPBOARD\0"
- "INCR\0"
- "TARGETS\0"
- "MULTIPLE\0"
- "TIMESTAMP\0"
- "SAVE_TARGETS\0"
- "CLIP_TEMPORARY\0"
- "_QT_SELECTION\0"
- "_QT_CLIPBOARD_SENTINEL\0"
- "_QT_SELECTION_SENTINEL\0"
- "CLIPBOARD_MANAGER\0"
-
- "RESOURCE_MANAGER\0"
-
- "_XSETROOT_ID\0"
-
- "_QT_SCROLL_DONE\0"
- "_QT_INPUT_ENCODING\0"
-
- "_MOTIF_WM_HINTS\0"
-
- "DTWM_IS_RUNNING\0"
- "ENLIGHTENMENT_DESKTOP\0"
- "_DT_SAVE_MODE\0"
- "_SGI_DESKS_MANAGER\0"
-
- // EWMH (aka NETWM)
- "_NET_SUPPORTED\0"
- "_NET_VIRTUAL_ROOTS\0"
- "_NET_WORKAREA\0"
-
- "_NET_MOVERESIZE_WINDOW\0"
- "_NET_WM_MOVERESIZE\0"
-
- "_NET_WM_NAME\0"
- "_NET_WM_ICON_NAME\0"
- "_NET_WM_ICON\0"
-
- "_NET_WM_PID\0"
-
- "_NET_WM_WINDOW_OPACITY\0"
-
- "_NET_WM_STATE\0"
- "_NET_WM_STATE_ABOVE\0"
- "_NET_WM_STATE_BELOW\0"
- "_NET_WM_STATE_FULLSCREEN\0"
- "_NET_WM_STATE_MAXIMIZED_HORZ\0"
- "_NET_WM_STATE_MAXIMIZED_VERT\0"
- "_NET_WM_STATE_MODAL\0"
- "_NET_WM_STATE_STAYS_ON_TOP\0"
- "_NET_WM_STATE_DEMANDS_ATTENTION\0"
-
- "_NET_WM_USER_TIME\0"
- "_NET_WM_USER_TIME_WINDOW\0"
- "_NET_WM_FULL_PLACEMENT\0"
-
- "_NET_WM_WINDOW_TYPE\0"
- "_NET_WM_WINDOW_TYPE_DESKTOP\0"
- "_NET_WM_WINDOW_TYPE_DOCK\0"
- "_NET_WM_WINDOW_TYPE_TOOLBAR\0"
- "_NET_WM_WINDOW_TYPE_MENU\0"
- "_NET_WM_WINDOW_TYPE_UTILITY\0"
- "_NET_WM_WINDOW_TYPE_SPLASH\0"
- "_NET_WM_WINDOW_TYPE_DIALOG\0"
- "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU\0"
- "_NET_WM_WINDOW_TYPE_POPUP_MENU\0"
- "_NET_WM_WINDOW_TYPE_TOOLTIP\0"
- "_NET_WM_WINDOW_TYPE_NOTIFICATION\0"
- "_NET_WM_WINDOW_TYPE_COMBO\0"
- "_NET_WM_WINDOW_TYPE_DND\0"
- "_NET_WM_WINDOW_TYPE_NORMAL\0"
- "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE\0"
-
- "_KDE_NET_WM_FRAME_STRUT\0"
-
- "_NET_STARTUP_INFO\0"
- "_NET_STARTUP_INFO_BEGIN\0"
-
- "_NET_SUPPORTING_WM_CHECK\0"
-
- "_NET_WM_CM_S0\0"
-
- "_NET_SYSTEM_TRAY_VISUAL\0"
-
- "_NET_ACTIVE_WINDOW\0"
-
- // Property formats
- "COMPOUND_TEXT\0"
- "TEXT\0"
- "UTF8_STRING\0"
-
- // xdnd
- "XdndEnter\0"
- "XdndPosition\0"
- "XdndStatus\0"
- "XdndLeave\0"
- "XdndDrop\0"
- "XdndFinished\0"
- "XdndTypeList\0"
- "XdndActionList\0"
-
- "XdndSelection\0"
-
- "XdndAware\0"
- "XdndProxy\0"
-
- "XdndActionCopy\0"
- "XdndActionLink\0"
- "XdndActionMove\0"
- "XdndActionPrivate\0"
-
- // Motif DND
- "_MOTIF_DRAG_AND_DROP_MESSAGE\0"
- "_MOTIF_DRAG_INITIATOR_INFO\0"
- "_MOTIF_DRAG_RECEIVER_INFO\0"
- "_MOTIF_DRAG_WINDOW\0"
- "_MOTIF_DRAG_TARGETS\0"
-
- "XmTRANSFER_SUCCESS\0"
- "XmTRANSFER_FAILURE\0"
-
- // Xkb
- "_XKB_RULES_NAMES\0"
-
- // XEMBED
- "_XEMBED\0"
- "_XEMBED_INFO\0"
-
- // Wacom old. (before version 0.10)
- "Wacom Stylus\0"
- "Wacom Cursor\0"
- "Wacom Eraser\0"
-
- // Tablet
- "STYLUS\0"
- "ERASER\0"
-};
-
-Q_GUI_EXPORT QX11Data *qt_x11Data = 0;
-
-/*****************************************************************************
- Internal variables and functions
- *****************************************************************************/
-static const char *appName = 0; // application name
-static const char *appClass = 0; // application class
-static const char *appFont = 0; // application font
-static const char *appBGCol = 0; // application bg color
-static const char *appFGCol = 0; // application fg color
-static const char *appBTNCol = 0; // application btn color
-static const char *mwGeometry = 0; // main widget geometry
-static const char *mwTitle = 0; // main widget title
-char *qt_ximServer = 0; // XIM Server will connect to
-static bool appSync = false; // X11 synchronization
-#if defined(QT_DEBUG)
-static bool appNoGrab = false; // X11 grabbing enabled
-static bool appDoGrab = false; // X11 grabbing override (gdb)
-#endif
-static bool app_save_rootinfo = false; // save root info
-static bool app_do_modal = false; // modal mode
-static Window curWin = 0; // current window
-
-
-// function to update the workarea of the screen - in qdesktopwidget_x11.cpp
-extern void qt_desktopwidget_update_workarea();
-
-// Function to change the window manager state (from qwidget_x11.cpp)
-extern void qt_change_net_wm_state(const QWidget *w, bool set, Atom one, Atom two = 0);
-
-// modifier masks for alt, meta, super, hyper, and mode_switch - detected when the application starts
-// and/or keyboard layout changes
-uchar qt_alt_mask = 0;
-uchar qt_meta_mask = 0;
-uchar qt_super_mask = 0;
-uchar qt_hyper_mask = 0;
-uchar qt_mode_switch_mask = 0;
-
-// flags for extensions for special Languages, currently only for RTL languages
-bool qt_use_rtl_extensions = false;
-
-static Window mouseActWindow = 0; // window where mouse is
-static Qt::MouseButton mouseButtonPressed = Qt::NoButton; // last mouse button pressed
-static Qt::MouseButtons mouseButtonState = Qt::NoButton; // mouse button state
-static Time mouseButtonPressTime = 0; // when was a button pressed
-static short mouseXPos, mouseYPos; // mouse pres position in act window
-static short mouseGlobalXPos, mouseGlobalYPos; // global mouse press position
-
-extern QWidgetList *qt_modal_stack; // stack of modal widgets
-
-// window where mouse buttons have been pressed
-static Window pressed_window = XNone;
-
-// popup control
-static bool replayPopupMouseEvent = false;
-static bool popupGrabOk;
-
-bool qt_sm_blockUserInput = false; // session management
-
-Q_GUI_EXPORT int qt_xfocusout_grab_counter = 0;
-
-#if !defined (QT_NO_TABLET)
-Q_GLOBAL_STATIC(QTabletDeviceDataList, tablet_devices)
-QTabletDeviceDataList *qt_tablet_devices()
-{
- return tablet_devices();
-}
-
-extern bool qt_tabletChokeMouse;
-#endif
-
-typedef bool(*QX11FilterFunction)(XEvent *event);
-
-Q_GLOBAL_STATIC(QList<QX11FilterFunction>, x11Filters)
-
-Q_GUI_EXPORT void qt_installX11EventFilter(QX11FilterFunction func)
-{
- Q_ASSERT(func);
-
- if (QList<QX11FilterFunction> *list = x11Filters())
- list->append(func);
-}
-
-Q_GUI_EXPORT void qt_removeX11EventFilter(QX11FilterFunction func)
-{
- Q_ASSERT(func);
-
- if (QList<QX11FilterFunction> *list = x11Filters())
- list->removeOne(func);
-}
-
-
-static bool qt_x11EventFilter(XEvent* ev)
-{
- long unused;
- if (qApp->filterEvent(ev, &unused))
- return true;
- if (const QList<QX11FilterFunction> *list = x11Filters()) {
- for (QList<QX11FilterFunction>::const_iterator it = list->constBegin(); it != list->constEnd(); ++it) {
- if ((*it)(ev))
- return true;
- }
- }
-
- return qApp->x11EventFilter(ev);
-}
-
-#if !defined(QT_NO_XIM)
-XIMStyle qt_xim_preferred_style = 0;
-#endif
-int qt_ximComposingKeycode=0;
-QTextCodec * qt_input_mapper = 0;
-
-extern bool qt_check_clipboard_sentinel(); //def in qclipboard_x11.cpp
-extern bool qt_check_selection_sentinel(); //def in qclipboard_x11.cpp
-extern bool qt_xfixes_clipboard_changed(Window clipboardOwner, Time timestamp); //def in qclipboard_x11.cpp
-extern bool qt_xfixes_selection_changed(Window selectionOwner, Time timestamp); //def in qclipboard_x11.cpp
-
-static void qt_save_rootinfo();
-Q_GUI_EXPORT bool qt_try_modal(QWidget *, XEvent *);
-
-QWidget *qt_button_down = 0; // last widget to be pressed with the mouse
-QPointer<QWidget> qt_last_mouse_receiver = 0;
-static QWidget *qt_popup_down = 0; // popup that contains the pressed widget
-
-extern bool qt_xdnd_dragging;
-
-// gui or non-gui from qapplication.cpp
-extern bool qt_is_gui_used;
-
-/*!
- \internal
- Try to resolve a \a symbol from \a library with the version specified
- by \a vernum.
-
- Note that, in the case of the Xfixes library, \a vernum is not the same as
- \c XFIXES_MAJOR - it is a part of soname and may differ from the Xfixes
- version.
-*/
-static void* qt_load_library_runtime(const char *library, int vernum,
- int highestVernum, const char *symbol)
-{
- QList<int> versions;
- // we try to load in the following order:
- // explicit version -> the default one -> (from the highest (highestVernum) to the lowest (vernum) )
- if (vernum != -1)
- versions << vernum;
- versions << -1;
- if (vernum != -1) {
- for(int i = highestVernum; i > vernum; --i)
- versions << i;
- }
- Q_FOREACH(int version, versions) {
- QLatin1String libName(library);
- QLibrary xfixesLib(libName, version);
- void *ptr = xfixesLib.resolve(symbol);
- if (ptr)
- return ptr;
- }
- return 0;
-}
-
-#ifndef QT_NO_XINPUT
-# ifdef QT_RUNTIME_XINPUT
-# define XINPUT_LOAD_RUNTIME(vernum, symbol, symbol_type) \
- (symbol_type)qt_load_library_runtime("libXi", vernum, 6, #symbol);
-# define XINPUT_LOAD(symbol) \
- XINPUT_LOAD_RUNTIME(1, symbol, Ptr##symbol)
-# else // not runtime XInput
-# define XINPUT_LOAD(symbol) symbol
-# endif // QT_RUNTIME_XINPUT
-#else // not using Xinput at all
-# define XINPUT_LOAD(symbol) 0
-#endif // QT_NO_XINPUT
-
-#ifndef QT_NO_XFIXES
-# ifdef QT_RUNTIME_XFIXES
-# define XFIXES_LOAD_RUNTIME(vernum, symbol, symbol_type) \
- (symbol_type)qt_load_library_runtime("libXfixes", vernum, 4, #symbol);
-# define XFIXES_LOAD_V1(symbol) \
- XFIXES_LOAD_RUNTIME(1, symbol, Ptr##symbol)
-# define XFIXES_LOAD_V2(symbol) \
- XFIXES_LOAD_RUNTIME(2, symbol, Ptr##symbol)
-
-# else // not runtime Xfixes
-
-# if XFIXES_MAJOR >= 2
-# define XFIXES_LOAD_V1(symbol) symbol
-# define XFIXES_LOAD_V2(symbol) symbol
-# elif XFIXES_MAJOR >= 1
-# define XFIXES_LOAD_V1(symbol) symbol
-# define XFIXES_LOAD_V2(symbol) 0
-# else
-# error Unsupported version of Xfixes
-# endif
-# endif // QT_RUNTIME_XFIXES
-#else // not using Xfixes at all
-# define XFIXES_LOAD_V1(symbol) 0
-# define XFIXES_LOAD_V2(symbol) 0
-#endif // QT_NO_XFIXES
-
-#ifndef QT_NO_XFIXES
-
-struct qt_xfixes_selection_event_data
-{
- // which selection to filter out.
- Atom selection;
-};
-
-#if defined(Q_C_CALLBACKS)
-extern "C" {
-#endif
-
-static Bool qt_xfixes_scanner(Display*, XEvent *event, XPointer arg)
-{
- qt_xfixes_selection_event_data *data =
- reinterpret_cast<qt_xfixes_selection_event_data*>(arg);
- if (event->type == X11->xfixes_eventbase + XFixesSelectionNotify) {
- XFixesSelectionNotifyEvent *xfixes_event = reinterpret_cast<XFixesSelectionNotifyEvent*>(event);
- if (xfixes_event->selection == data->selection)
- return true;
- }
- return false;
-}
-
-#if defined(Q_C_CALLBACKS)
-}
-#endif
-
-#endif // QT_NO_XFIXES
-
-class QETWidget : public QWidget // event translator widget
-{
-public:
- QWidgetPrivate* d_func() { return QWidget::d_func(); }
- bool translateMouseEvent(const XEvent *);
- void translatePaintEvent(const XEvent *);
- bool translateConfigEvent(const XEvent *);
- bool translateCloseEvent(const XEvent *);
- bool translateScrollDoneEvent(const XEvent *);
- bool translateWheelEvent(int global_x, int global_y, int delta, Qt::MouseButtons buttons,
- Qt::KeyboardModifiers modifiers, Qt::Orientation orient);
-#if !defined (QT_NO_TABLET)
- bool translateXinputEvent(const XEvent*, QTabletDeviceData *tablet);
-#endif
- bool translatePropertyEvent(const XEvent *);
-
- void doDeferredMap()
- {
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
- if (!testAttribute(Qt::WA_Resized)) {
- adjustSize();
- setAttribute(Qt::WA_Resized, false);
- }
-
- /*
- workaround for WM's that throw away ConfigureRequests from the following:
-
- window->hide();
- window->move(x, y); // could also be resize(), move()+resize(), or setGeometry()
- window->show();
- */
- QRect r = geometry();
-
- XMoveResizeWindow(X11->display,
- internalWinId(),
- r.x(),
- r.y(),
- r.width(),
- r.height());
-
- // static gravity!
- XSizeHints sh;
- long unused;
- XGetWMNormalHints(X11->display, internalWinId(), &sh, &unused);
- sh.flags |= USPosition | PPosition | USSize | PSize | PWinGravity;
- sh.x = r.x();
- sh.y = r.y();
- sh.width = r.width();
- sh.height = r.height();
- sh.win_gravity = StaticGravity;
- XSetWMNormalHints(X11->display, internalWinId(), &sh);
-
- setAttribute(Qt::WA_Mapped);
- if (testAttribute(Qt::WA_DontShowOnScreen))
- return;
- d_func()->topData()->waitingForMapNotify = 1;
- XMapWindow(X11->display, internalWinId());
- }
-};
-
-
-void QApplicationPrivate::createEventDispatcher()
-{
- Q_Q(QApplication);
-#if !defined(QT_NO_GLIB)
- if (qgetenv("QT_NO_GLIB").isEmpty() && QEventDispatcherGlib::versionSupported())
- eventDispatcher = (q->type() != QApplication::Tty
- ? new QGuiEventDispatcherGlib(q)
- : new QEventDispatcherGlib(q));
- else
-#endif
- eventDispatcher = (q->type() != QApplication::Tty
- ? new QEventDispatcherX11(q)
- : new QEventDispatcherUNIX(q));
-}
-
-/*****************************************************************************
- Default X error handlers
- *****************************************************************************/
-
-#if defined(Q_C_CALLBACKS)
-extern "C" {
-#endif
-
-static int (*original_x_errhandler)(Display *dpy, XErrorEvent *);
-static int (*original_xio_errhandler)(Display *dpy);
-
-static int qt_x_errhandler(Display *dpy, XErrorEvent *err)
-{
- if (X11->display != dpy) {
- // only handle X errors for our display
- return 0;
- }
-
- switch (err->error_code) {
- case BadAtom:
- if (err->request_code == 20 /* X_GetProperty */
- && (err->resourceid == XA_RESOURCE_MANAGER
- || err->resourceid == XA_RGB_DEFAULT_MAP
- || err->resourceid == ATOM(_NET_SUPPORTED)
- || err->resourceid == ATOM(_NET_SUPPORTING_WM_CHECK)
- || err->resourceid == ATOM(XdndProxy)
- || err->resourceid == ATOM(XdndAware))) {
- // Perhaps we're running under SECURITY reduction? :/
- return 0;
- }
- break;
-
- case BadWindow:
- if (err->request_code == 2 /* X_ChangeWindowAttributes */
- || err->request_code == 38 /* X_QueryPointer */) {
- for (int i = 0; i < ScreenCount(dpy); ++i) {
- if (err->resourceid == RootWindow(dpy, i)) {
- // Perhaps we're running under SECURITY reduction? :/
- return 0;
- }
- }
- }
- X11->seen_badwindow = true;
- if (err->request_code == 25 /* X_SendEvent */) {
- for (int i = 0; i < ScreenCount(dpy); ++i) {
- if (err->resourceid == RootWindow(dpy, i)) {
- // Perhaps we're running under SECURITY reduction? :/
- return 0;
- }
- }
- if (X11->xdndHandleBadwindow()) {
- qDebug("xdndHandleBadwindow returned true");
- return 0;
- }
- }
- if (X11->ignore_badwindow)
- return 0;
- break;
-
- default:
-#if !defined(QT_NO_XINPUT)
- if (err->request_code == X11->xinput_major
- && err->error_code == (X11->xinput_errorbase + XI_BadDevice)
- && err->minor_code == 3 /* X_OpenDevice */) {
- return 0;
- }
-#endif
- break;
- }
-
- char errstr[256];
- XGetErrorText( dpy, err->error_code, errstr, 256 );
- char buffer[256];
- char request_str[256];
- qsnprintf(buffer, 256, "%d", err->request_code);
- XGetErrorDatabaseText(dpy, "XRequest", buffer, "", request_str, 256);
- if (err->request_code < 128) {
- // X error for a normal protocol request
- qWarning( "X Error: %s %d\n"
- " Major opcode: %d (%s)\n"
- " Resource id: 0x%lx",
- errstr, err->error_code,
- err->request_code,
- request_str,
- err->resourceid );
- } else {
- // X error for an extension request
- const char *extensionName = 0;
- if (err->request_code == X11->xrender_major)
- extensionName = "RENDER";
- else if (err->request_code == X11->xrandr_major)
- extensionName = "RANDR";
- else if (err->request_code == X11->xinput_major)
- extensionName = "XInputExtension";
- else if (err->request_code == X11->mitshm_major)
- extensionName = "MIT-SHM";
-#ifndef QT_NO_XKB
- else if(err->request_code == X11->xkb_major)
- extensionName = "XKEYBOARD";
-#endif
-
- char minor_str[256];
- if (extensionName) {
- qsnprintf(buffer, 256, "%s.%d", extensionName, err->minor_code);
- XGetErrorDatabaseText(dpy, "XRequest", buffer, "", minor_str, 256);
- } else {
- extensionName = "Uknown extension";
- qsnprintf(minor_str, 256, "Unknown request");
- }
- qWarning( "X Error: %s %d\n"
- " Extension: %d (%s)\n"
- " Minor opcode: %d (%s)\n"
- " Resource id: 0x%lx",
- errstr, err->error_code,
- err->request_code,
- extensionName,
- err->minor_code,
- minor_str,
- err->resourceid );
- }
-
- // ### we really should distinguish between severe, non-severe and
- // ### application specific errors
-
- return 0;
-}
-
-
-static int qt_xio_errhandler(Display *)
-{
- qWarning("%s: Fatal IO error: client killed", appName);
- QApplicationPrivate::reset_instance_pointer();
- exit(1);
- //### give the application a chance for a proper shutdown instead,
- //### exit(1) doesn't help.
- return 0;
-}
-
-#if defined(Q_C_CALLBACKS)
-}
-#endif
-
-#ifndef QT_NO_XSYNC
-struct qt_sync_request_event_data
-{
- WId window;
-};
-
-#if defined(Q_C_CALLBACKS)
-extern "C" {
-#endif
-
-static Bool qt_sync_request_scanner(Display*, XEvent *event, XPointer arg)
-{
- qt_sync_request_event_data *data =
- reinterpret_cast<qt_sync_request_event_data*>(arg);
- if (event->type == ClientMessage &&
- event->xany.window == data->window &&
- event->xclient.message_type == ATOM(WM_PROTOCOLS) &&
- (Atom)event->xclient.data.l[0] == ATOM(_NET_WM_SYNC_REQUEST)) {
- QWidget *w = QWidget::find(event->xany.window);
- if (QTLWExtra *tlw = ((QETWidget*)w)->d_func()->maybeTopData()) {
- const ulong timestamp = (const ulong) event->xclient.data.l[1];
- if (timestamp > X11->time)
- X11->time = timestamp;
- if (timestamp == CurrentTime || timestamp > tlw->syncRequestTimestamp) {
- tlw->syncRequestTimestamp = timestamp;
- tlw->newCounterValueLo = event->xclient.data.l[2];
- tlw->newCounterValueHi = event->xclient.data.l[3];
- }
- }
- return true;
- }
- return false;
-}
-
-#if defined(Q_C_CALLBACKS)
-}
-#endif
-#endif // QT_NO_XSYNC
-
-static void qt_x11_create_intern_atoms()
-{
- const char *names[QX11Data::NAtoms];
- const char *ptr = x11_atomnames;
-
- int i = 0;
- while (*ptr) {
- names[i++] = ptr;
- while (*ptr)
- ++ptr;
- ++ptr;
- }
-
- Q_ASSERT(i == QX11Data::NPredefinedAtoms);
-
- QByteArray settings_atom_name("_QT_SETTINGS_TIMESTAMP_");
- settings_atom_name += XDisplayName(X11->displayName);
- names[i++] = settings_atom_name;
-
- Q_ASSERT(i == QX11Data::NAtoms);
-#if defined(XlibSpecificationRelease) && (XlibSpecificationRelease >= 6)
- XInternAtoms(X11->display, (char **)names, i, False, X11->atoms);
-#else
- for (i = 0; i < QX11Data::NAtoms; ++i)
- X11->atoms[i] = XInternAtom(X11->display, (char *)names[i], False);
-#endif
-}
-
-Q_GUI_EXPORT void qt_x11_apply_settings_in_all_apps()
-{
- QByteArray stamp;
- QDataStream s(&stamp, QIODevice::WriteOnly);
- s << QDateTime::currentDateTime();
-
- XChangeProperty(QX11Info::display(), QX11Info::appRootWindow(0),
- ATOM(_QT_SETTINGS_TIMESTAMP), ATOM(_QT_SETTINGS_TIMESTAMP), 8,
- PropModeReplace, (unsigned char *)stamp.data(), stamp.size());
-}
-
-/*! \internal
- apply the settings to the application
-*/
-bool QApplicationPrivate::x11_apply_settings()
-{
- QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
-
- settings.beginGroup(QLatin1String("Qt"));
-
- /*
- Qt settings. This is now they are written into the datastream.
-
- Palette / * - QPalette
- font - QFont
- libraryPath - QStringList
- style - QString
- doubleClickInterval - int
- keyboardInputInterval - int
- cursorFlashTime - int
- wheelScrollLines - int
- colorSpec - QString
- defaultCodec - QString
- globalStrut/width - int
- globalStrut/height - int
- GUIEffects - QStringList
- Font Substitutions/ * - QStringList
- Font Substitutions/... - QStringList
- */
-
- QStringList strlist;
- int i;
- QPalette pal(Qt::black);
- int groupCount = 0;
- strlist = settings.value(QLatin1String("Palette/active")).toStringList();
- if (!strlist.isEmpty()) {
- ++groupCount;
- for (i = 0; i < qMin(strlist.count(), int(QPalette::NColorRoles)); i++)
- pal.setColor(QPalette::Active, (QPalette::ColorRole) i,
- QColor(strlist[i]));
- }
- strlist = settings.value(QLatin1String("Palette/inactive")).toStringList();
- if (!strlist.isEmpty()) {
- ++groupCount;
- for (i = 0; i < qMin(strlist.count(), int(QPalette::NColorRoles)); i++)
- pal.setColor(QPalette::Inactive, (QPalette::ColorRole) i,
- QColor(strlist[i]));
- }
- strlist = settings.value(QLatin1String("Palette/disabled")).toStringList();
- if (!strlist.isEmpty()) {
- ++groupCount;
- for (i = 0; i < qMin(strlist.count(), int(QPalette::NColorRoles)); i++)
- pal.setColor(QPalette::Disabled, (QPalette::ColorRole) i,
- QColor(strlist[i]));
- }
-
- // ### Fix properly for 4.6
- bool usingGtkSettings = QApplicationPrivate::app_style && QApplicationPrivate::app_style->inherits("QGtkStyle");
- if (!usingGtkSettings) {
- if (groupCount == QPalette::NColorGroups)
- QApplicationPrivate::setSystemPalette(pal);
- }
-
- if (!appFont) {
- // ### Fix properly for 4.6
- if (!usingGtkSettings) {
- QFont font(QApplication::font());
- QString fontDescription;
- // Override Qt font if KDE4 settings can be used
- if (X11->desktopVersion == 4) {
- QSettings kdeSettings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat);
- fontDescription = kdeSettings.value(QLatin1String("font")).toString();
- if (fontDescription.isEmpty()) {
- // KDE stores fonts without quotes
- fontDescription = kdeSettings.value(QLatin1String("font")).toStringList().join(QLatin1String(","));
- }
- }
- if (fontDescription.isEmpty())
- fontDescription = settings.value(QLatin1String("font")).toString();
- if (!fontDescription .isEmpty()) {
- font.fromString(fontDescription );
- QApplicationPrivate::setSystemFont(font);
- }
- }
- }
-
- // read library (ie. plugin) path list
- QString libpathkey =
- QString::fromLatin1("%1.%2/libraryPath")
- .arg(QT_VERSION >> 16)
- .arg((QT_VERSION & 0xff00) >> 8);
- QStringList pathlist = settings.value(libpathkey).toString().split(QLatin1Char(':'));
- if (! pathlist.isEmpty()) {
- QStringList::ConstIterator it = pathlist.constBegin();
- while (it != pathlist.constEnd())
- QApplication::addLibraryPath(*it++);
- }
-
- // read new QStyle
- QString stylename = settings.value(QLatin1String("style")).toString();
-
- if (stylename.isEmpty() && QApplicationPrivate::styleOverride.isNull() && X11->use_xrender) {
- stylename = qt_guiPlatformPlugin()->styleName();
- }
-
- static QString currentStyleName = stylename;
- if (QCoreApplication::startingUp()) {
- if (!stylename.isEmpty() && QApplicationPrivate::styleOverride.isNull())
- QApplicationPrivate::styleOverride = stylename;
- } else {
- if (currentStyleName != stylename) {
- currentStyleName = stylename;
- QApplication::setStyle(stylename);
- }
- }
-
- int num =
- settings.value(QLatin1String("doubleClickInterval"),
- QApplication::doubleClickInterval()).toInt();
- QApplication::setDoubleClickInterval(num);
-
- num =
- settings.value(QLatin1String("cursorFlashTime"),
- QApplication::cursorFlashTime()).toInt();
- QApplication::setCursorFlashTime(num);
-
-#ifndef QT_NO_WHEELEVENT
- num =
- settings.value(QLatin1String("wheelScrollLines"),
- QApplication::wheelScrollLines()).toInt();
- QApplication::setWheelScrollLines(num);
-#endif
-
- QString colorspec = settings.value(QLatin1String("colorSpec"),
- QVariant(QLatin1String("default"))).toString();
- if (colorspec == QLatin1String("normal"))
- QApplication::setColorSpec(QApplication::NormalColor);
- else if (colorspec == QLatin1String("custom"))
- QApplication::setColorSpec(QApplication::CustomColor);
- else if (colorspec == QLatin1String("many"))
- QApplication::setColorSpec(QApplication::ManyColor);
- else if (colorspec != QLatin1String("default"))
- colorspec = QLatin1String("default");
-
- QString defaultcodec = settings.value(QLatin1String("defaultCodec"),
- QVariant(QLatin1String("none"))).toString();
- if (defaultcodec != QLatin1String("none")) {
- QTextCodec *codec = QTextCodec::codecForName(defaultcodec.toLatin1());
- if (codec)
- QTextCodec::setCodecForTr(codec);
- }
-
- int w = settings.value(QLatin1String("globalStrut/width")).toInt();
- int h = settings.value(QLatin1String("globalStrut/height")).toInt();
- QSize strut(w, h);
- if (strut.isValid())
- QApplication::setGlobalStrut(strut);
-
- QStringList effects = settings.value(QLatin1String("GUIEffects")).toStringList();
- QApplication::setEffectEnabled(Qt::UI_General,
- effects.contains(QLatin1String("general")));
- QApplication::setEffectEnabled(Qt::UI_AnimateMenu,
- effects.contains(QLatin1String("animatemenu")));
- QApplication::setEffectEnabled(Qt::UI_FadeMenu,
- effects.contains(QLatin1String("fademenu")));
- QApplication::setEffectEnabled(Qt::UI_AnimateCombo,
- effects.contains(QLatin1String("animatecombo")));
- QApplication::setEffectEnabled(Qt::UI_AnimateTooltip,
- effects.contains(QLatin1String("animatetooltip")));
- QApplication::setEffectEnabled(Qt::UI_FadeTooltip,
- effects.contains(QLatin1String("fadetooltip")));
- QApplication::setEffectEnabled(Qt::UI_AnimateToolBox,
- effects.contains(QLatin1String("animatetoolbox")));
-
- if (!X11->has_fontconfig) {
- settings.beginGroup(QLatin1String("Font Substitutions"));
- QStringList fontsubs = settings.childKeys();
- if (!fontsubs.isEmpty()) {
- QStringList::Iterator it = fontsubs.begin();
- for (; it != fontsubs.end(); ++it) {
- QString fam = *it;
- QStringList subs = settings.value(fam).toStringList();
- QFont::insertSubstitutions(fam, subs);
- }
- }
- settings.endGroup();
- }
-
- qt_use_rtl_extensions =
- settings.value(QLatin1String("useRtlExtensions"), false).toBool();
-
-#ifndef QT_NO_XIM
- if (qt_xim_preferred_style == 0) {
- QString ximInputStyle = settings.value(QLatin1String("XIMInputStyle"),
- QVariant(QLatin1String("on the spot"))).toString().toLower();
- if (ximInputStyle == QLatin1String("on the spot"))
- qt_xim_preferred_style = XIMPreeditCallbacks | XIMStatusNothing;
- else if (ximInputStyle == QLatin1String("over the spot"))
- qt_xim_preferred_style = XIMPreeditPosition | XIMStatusNothing;
- else if (ximInputStyle == QLatin1String("off the spot"))
- qt_xim_preferred_style = XIMPreeditArea | XIMStatusArea;
- else if (ximInputStyle == QLatin1String("root"))
- qt_xim_preferred_style = XIMPreeditNothing | XIMStatusNothing;
- }
-#endif
- QStringList inputMethods = QInputContextFactory::keys();
- if (inputMethods.size() > 2 && inputMethods.contains(QLatin1String("imsw-multi"))) {
- X11->default_im = QLatin1String("imsw-multi");
- } else {
- X11->default_im = settings.value(QLatin1String("DefaultInputMethod"),
- QLatin1String("xim")).toString();
- }
-
- settings.endGroup(); // Qt
-
- return true;
-}
-
-
-/*! \internal
- Resets the QApplication::instance() pointer to zero
-*/
-void QApplicationPrivate::reset_instance_pointer()
-{ QApplication::self = 0; }
-
-
-// read the _QT_INPUT_ENCODING property and apply the settings to
-// the application
-static void qt_set_input_encoding()
-{
- Atom type;
- int format;
- ulong nitems, after = 1;
- unsigned char *data = 0;
-
- int e = XGetWindowProperty(X11->display, QX11Info::appRootWindow(),
- ATOM(_QT_INPUT_ENCODING), 0, 1024,
- False, XA_STRING, &type, &format, &nitems,
- &after, &data);
- if (e != Success || !nitems || type == XNone) {
- // Always use the locale codec, since we have no examples of non-local
- // XIMs, and since we cannot get a sensible answer about the encoding
- // from the XIM.
- qt_input_mapper = QTextCodec::codecForLocale();
-
- } else {
- if (!qstricmp((char *)data, "locale"))
- qt_input_mapper = QTextCodec::codecForLocale();
- else
- qt_input_mapper = QTextCodec::codecForName((char *)data);
- // make sure we have an input codec
- if(!qt_input_mapper)
- qt_input_mapper = QTextCodec::codecForName("ISO 8859-1");
- }
- if (qt_input_mapper && qt_input_mapper->mibEnum() == 11) // 8859-8
- qt_input_mapper = QTextCodec::codecForName("ISO 8859-8-I");
- if(data)
- XFree((char *)data);
-}
-
-// set font, foreground and background from x11 resources. The
-// arguments may override the resource settings.
-static void qt_set_x11_resources(const char* font = 0, const char* fg = 0,
- const char* bg = 0, const char* button = 0)
-{
-
- QString resFont, resFG, resBG, resButton, resEF, sysFont, selectBackground, selectForeground;
-
- QApplication::setEffectEnabled(Qt::UI_General, false);
- QApplication::setEffectEnabled(Qt::UI_AnimateMenu, false);
- QApplication::setEffectEnabled(Qt::UI_FadeMenu, false);
- QApplication::setEffectEnabled(Qt::UI_AnimateCombo, false);
- QApplication::setEffectEnabled(Qt::UI_AnimateTooltip, false);
- QApplication::setEffectEnabled(Qt::UI_FadeTooltip, false);
- QApplication::setEffectEnabled(Qt::UI_AnimateToolBox, false);
-
- bool paletteAlreadySet = false;
- if (QApplication::desktopSettingsAware()) {
- // first, read from settings
- QApplicationPrivate::x11_apply_settings();
- // the call to QApplication::style() below creates the system
- // palette, which breaks the logic after the RESOURCE_MANAGER
- // loop... so I have to save this value to be able to use it later
- paletteAlreadySet = (QApplicationPrivate::sys_pal != 0);
-
- // second, parse the RESOURCE_MANAGER property
- int format;
- ulong nitems, after = 1;
- QString res;
- long offset = 0;
- Atom type = XNone;
-
- while (after > 0) {
- uchar *data = 0;
- if (XGetWindowProperty(X11->display, QX11Info::appRootWindow(0),
- ATOM(RESOURCE_MANAGER),
- offset, 8192, False, AnyPropertyType,
- &type, &format, &nitems, &after,
- &data) != Success) {
- res = QString();
- break;
- }
- if (type == XA_STRING)
- res += QString::fromLatin1((char*)data);
- else
- res += QString::fromLocal8Bit((char*)data);
- offset += 2048; // offset is in 32bit quantities... 8192/4 == 2048
- if (data)
- XFree((char *)data);
- }
-
- QString key, value;
- int l = 0, r;
- QString apn = QString::fromLocal8Bit(appName);
- QString apc = QString::fromLocal8Bit(appClass);
- int apnl = apn.length();
- int apcl = apc.length();
- int resl = res.length();
-
- while (l < resl) {
- r = res.indexOf(QLatin1Char('\n'), l);
- if (r < 0)
- r = resl;
- while (res.at(l).isSpace())
- l++;
- bool mine = false;
- QChar sc = res.at(l + 1);
- if (res.at(l) == QLatin1Char('*') &&
- (sc == QLatin1Char('f') || sc == QLatin1Char('b') || sc == QLatin1Char('g') ||
- sc == QLatin1Char('F') || sc == QLatin1Char('B') || sc == QLatin1Char('G') ||
- sc == QLatin1Char('s') || sc == QLatin1Char('S')
- // capital T only, since we're looking for "Text.selectSomething"
- || sc == QLatin1Char('T'))) {
- // OPTIMIZED, since we only want "*[fbgsT].."
- QString item = res.mid(l, r - l).simplified();
- int i = item.indexOf(QLatin1Char(':'));
- key = item.left(i).trimmed().mid(1).toLower();
- value = item.right(item.length() - i - 1).trimmed();
- mine = true;
- } else if ((apnl && res.at(l) == apn.at(0)) || (appClass && apcl && res.at(l) == apc.at(0))) {
- if (res.mid(l,apnl) == apn && (res.at(l+apnl) == QLatin1Char('.')
- || res.at(l+apnl) == QLatin1Char('*'))) {
- QString item = res.mid(l, r - l).simplified();
- int i = item.indexOf(QLatin1Char(':'));
- key = item.left(i).trimmed().mid(apnl+1).toLower();
- value = item.right(item.length() - i - 1).trimmed();
- mine = true;
- } else if (res.mid(l,apcl) == apc && (res.at(l+apcl) == QLatin1Char('.')
- || res.at(l+apcl) == QLatin1Char('*'))) {
- QString item = res.mid(l, r - l).simplified();
- int i = item.indexOf(QLatin1Char(':'));
- key = item.left(i).trimmed().mid(apcl+1).toLower();
- value = item.right(item.length() - i - 1).trimmed();
- mine = true;
- }
- }
-
- if (mine) {
- if (!font && key == QLatin1String("systemfont"))
- sysFont = value.left(value.lastIndexOf(QLatin1Char(':')));
- if (!font && key == QLatin1String("font"))
- resFont = value;
- else if (!fg && !paletteAlreadySet) {
- if (key == QLatin1String("foreground"))
- resFG = value;
- else if (!bg && key == QLatin1String("background"))
- resBG = value;
- else if (!bg && !button && key == QLatin1String("button.background"))
- resButton = value;
- else if (key == QLatin1String("text.selectbackground")) {
- selectBackground = value;
- } else if (key == QLatin1String("text.selectforeground")) {
- selectForeground = value;
- }
- } else if (key == QLatin1String("guieffects"))
- resEF = value;
- // NOTE: if you add more, change the [fbg] stuff above
- }
-
- l = r + 1;
- }
- }
- if (!sysFont.isEmpty())
- resFont = sysFont;
- if (resFont.isEmpty())
- resFont = QString::fromLocal8Bit(font);
- if (resFG.isEmpty())
- resFG = QString::fromLocal8Bit(fg);
- if (resBG.isEmpty())
- resBG = QString::fromLocal8Bit(bg);
- if (resButton.isEmpty())
- resButton = QString::fromLocal8Bit(button);
- if (!resFont.isEmpty()
- && !X11->has_fontconfig
- && !QApplicationPrivate::sys_font) {
- // set application font
- QFont fnt;
- fnt.setRawName(resFont);
-
- // the font we get may actually be an alias for another font,
- // so we reset the application font to the real font info.
- if (! fnt.exactMatch()) {
- QFontInfo fontinfo(fnt);
- fnt.setFamily(fontinfo.family());
- fnt.setRawMode(fontinfo.rawMode());
-
- if (! fnt.rawMode()) {
- fnt.setItalic(fontinfo.italic());
- fnt.setWeight(fontinfo.weight());
- fnt.setUnderline(fontinfo.underline());
- fnt.setStrikeOut(fontinfo.strikeOut());
- fnt.setStyleHint(fontinfo.styleHint());
-
- if (fnt.pointSize() <= 0 && fnt.pixelSize() <= 0) {
- // size is all wrong... fix it
- qreal pointSize = fontinfo.pixelSize() * 72. / (float) QX11Info::appDpiY();
- if (pointSize <= 0)
- pointSize = 12;
- fnt.setPointSize(qRound(pointSize));
- }
- }
- }
-
- QApplicationPrivate::setSystemFont(fnt);
- }
- // QGtkStyle sets it's own system palette
- bool gtkStyle = QApplicationPrivate::app_style && QApplicationPrivate::app_style->inherits("QGtkStyle");
- bool kdeColors = (QApplication::desktopSettingsAware() && X11->desktopEnvironment == DE_KDE);
- if (!gtkStyle && (kdeColors || (button || !resBG.isEmpty() || !resFG.isEmpty()))) {// set app colors
- bool allowX11ColorNames = QColor::allowX11ColorNames();
- QColor::setAllowX11ColorNames(true);
-
- (void) QApplication::style(); // trigger creation of application style and system palettes
- QColor btn;
- QColor bg;
- QColor fg;
- QColor bfg;
- QColor wfg;
- if (!resBG.isEmpty())
- bg = QColor(resBG);
- if (!bg.isValid())
- bg = QApplicationPrivate::sys_pal->color(QPalette::Active, QPalette::Window);
-
- if (!resFG.isEmpty())
- fg = QColor(resFG);
- if (!fg.isValid())
- fg = QApplicationPrivate::sys_pal->color(QPalette::Active, QPalette::WindowText);
-
- if (!resButton.isEmpty())
- btn = QColor(resButton);
- else if (!resBG.isEmpty())
- btn = bg;
- if (!btn.isValid())
- btn = QApplicationPrivate::sys_pal->color(QPalette::Active, QPalette::Button);
-
- int h,s,v;
- fg.getHsv(&h,&s,&v);
- QColor base = Qt::white;
- bool bright_mode = false;
- if (v >= 255 - 50) {
- base = btn.darker(150);
- bright_mode = true;
- }
-
- QPalette pal(fg, btn, btn.lighter(125), btn.darker(130), btn.darker(120), wfg.isValid() ? wfg : fg, Qt::white, base, bg);
- QColor disabled((fg.red() + btn.red()) / 2,
- (fg.green() + btn.green())/ 2,
- (fg.blue() + btn.blue()) / 2);
- pal.setColorGroup(QPalette::Disabled, disabled, btn, btn.lighter(125),
- btn.darker(130), btn.darker(150), disabled, Qt::white, Qt::white, bg);
-
- QColor highlight, highlightText;
- if (!selectBackground.isEmpty() && !selectForeground.isEmpty()) {
- highlight = QColor(selectBackground);
- highlightText = QColor(selectForeground);
- }
-
- if (highlight.isValid() && highlightText.isValid()) {
- pal.setColor(QPalette::Highlight, highlight);
- pal.setColor(QPalette::HighlightedText, highlightText);
-
- // calculate disabled colors by removing saturation
- highlight.setHsv(highlight.hue(), 0, highlight.value(), highlight.alpha());
- highlightText.setHsv(highlightText.hue(), 0, highlightText.value(), highlightText.alpha());
- pal.setColor(QPalette::Disabled, QPalette::Highlight, highlight);
- pal.setColor(QPalette::Disabled, QPalette::HighlightedText, highlightText);
- } else if (bright_mode) {
- pal.setColor(QPalette::HighlightedText, base);
- pal.setColor(QPalette::Highlight, Qt::white);
- pal.setColor(QPalette::Disabled, QPalette::HighlightedText, base);
- pal.setColor(QPalette::Disabled, QPalette::Highlight, Qt::white);
- } else {
- pal.setColor(QPalette::HighlightedText, Qt::white);
- pal.setColor(QPalette::Highlight, Qt::darkBlue);
- pal.setColor(QPalette::Disabled, QPalette::HighlightedText, Qt::white);
- pal.setColor(QPalette::Disabled, QPalette::Highlight, Qt::darkBlue);
- }
-
- pal = qt_guiPlatformPlugin()->palette().resolve(pal);
- QApplicationPrivate::setSystemPalette(pal);
- QColor::setAllowX11ColorNames(allowX11ColorNames);
- }
-
- if (!resEF.isEmpty()) {
- QStringList effects = resEF.split(QLatin1Char(' '));
- QApplication::setEffectEnabled(Qt::UI_General, effects.contains(QLatin1String("general")));
- QApplication::setEffectEnabled(Qt::UI_AnimateMenu,
- effects.contains(QLatin1String("animatemenu")));
- QApplication::setEffectEnabled(Qt::UI_FadeMenu,
- effects.contains(QLatin1String("fademenu")));
- QApplication::setEffectEnabled(Qt::UI_AnimateCombo,
- effects.contains(QLatin1String("animatecombo")));
- QApplication::setEffectEnabled(Qt::UI_AnimateTooltip,
- effects.contains(QLatin1String("animatetooltip")));
- QApplication::setEffectEnabled(Qt::UI_FadeTooltip,
- effects.contains(QLatin1String("fadetooltip")));
- QApplication::setEffectEnabled(Qt::UI_AnimateToolBox,
- effects.contains(QLatin1String("animatetoolbox")));
- }
-
- QIconLoader::instance()->updateSystemTheme();
-}
-
-
-// update the supported array
-static void qt_get_net_supported()
-{
- Atom type;
- int format;
- long offset = 0;
- unsigned long nitems, after;
- unsigned char *data = 0;
-
- int e = XGetWindowProperty(X11->display, QX11Info::appRootWindow(),
- ATOM(_NET_SUPPORTED), 0, 0,
- False, XA_ATOM, &type, &format, &nitems, &after, &data);
- if (data)
- XFree(data);
-
- if (X11->net_supported_list)
- delete [] X11->net_supported_list;
- X11->net_supported_list = 0;
-
- if (e == Success && type == XA_ATOM && format == 32) {
- QBuffer ts;
- ts.open(QIODevice::WriteOnly);
-
- while (after > 0) {
- XGetWindowProperty(X11->display, QX11Info::appRootWindow(),
- ATOM(_NET_SUPPORTED), offset, 1024,
- False, XA_ATOM, &type, &format, &nitems, &after, &data);
-
- if (type == XA_ATOM && format == 32) {
- ts.write(reinterpret_cast<char *>(data), nitems * sizeof(long));
- offset += nitems;
- } else
- after = 0;
- if (data)
- XFree(data);
- }
-
- // compute nitems
- QByteArray buffer(ts.buffer());
- nitems = buffer.size() / sizeof(Atom);
- X11->net_supported_list = new Atom[nitems + 1];
- Atom *a = (Atom *) buffer.data();
- uint i;
- for (i = 0; i < nitems; i++)
- X11->net_supported_list[i] = a[i];
- X11->net_supported_list[nitems] = 0;
- }
-}
-
-
-bool QX11Data::isSupportedByWM(Atom atom)
-{
- if (!X11->net_supported_list)
- return false;
-
- bool supported = false;
- int i = 0;
- while (X11->net_supported_list[i] != 0) {
- if (X11->net_supported_list[i++] == atom) {
- supported = true;
- break;
- }
- }
-
- return supported;
-}
-
-
-// update the virtual roots array
-static void qt_get_net_virtual_roots()
-{
- if (X11->net_virtual_root_list)
- delete [] X11->net_virtual_root_list;
- X11->net_virtual_root_list = 0;
-
- if (!X11->isSupportedByWM(ATOM(_NET_VIRTUAL_ROOTS)))
- return;
-
- Atom type;
- int format;
- long offset = 0;
- unsigned long nitems, after;
- unsigned char *data;
-
- int e = XGetWindowProperty(X11->display, QX11Info::appRootWindow(),
- ATOM(_NET_VIRTUAL_ROOTS), 0, 0,
- False, XA_ATOM, &type, &format, &nitems, &after, &data);
- if (data)
- XFree(data);
-
- if (e == Success && type == XA_ATOM && format == 32) {
- QBuffer ts;
- ts.open(QIODevice::WriteOnly);
-
- while (after > 0) {
- XGetWindowProperty(X11->display, QX11Info::appRootWindow(),
- ATOM(_NET_VIRTUAL_ROOTS), offset, 1024,
- False, XA_ATOM, &type, &format, &nitems, &after, &data);
-
- if (type == XA_ATOM && format == 32) {
- ts.write(reinterpret_cast<char *>(data), nitems * 4);
- offset += nitems;
- } else
- after = 0;
- if (data)
- XFree(data);
- }
-
- // compute nitems
- QByteArray buffer(ts.buffer());
- nitems = buffer.size() / sizeof(Window);
- X11->net_virtual_root_list = new Window[nitems + 1];
- Window *a = (Window *) buffer.data();
- uint i;
- for (i = 0; i < nitems; i++)
- X11->net_virtual_root_list[i] = a[i];
- X11->net_virtual_root_list[nitems] = 0;
- }
-}
-
-void qt_net_remove_user_time(QWidget *tlw)
-{
- Q_ASSERT(tlw);
- QTLWExtra *extra = tlw->d_func()->maybeTopData();
- if (extra && extra->userTimeWindow) {
- Q_ASSERT(tlw->internalWinId());
- XDeleteProperty(X11->display, tlw->internalWinId(), ATOM(_NET_WM_USER_TIME_WINDOW));
- XDestroyWindow(X11->display, extra->userTimeWindow);
- extra->userTimeWindow = 0;
- }
-}
-
-void qt_net_update_user_time(QWidget *tlw, unsigned long timestamp)
-{
- Q_ASSERT(tlw);
- Q_ASSERT(tlw->isWindow());
- Q_ASSERT(tlw->testAttribute(Qt::WA_WState_Created));
- QTLWExtra *extra = tlw->d_func()->topData();
- WId wid = tlw->internalWinId();
- const bool isSupportedByWM = X11->isSupportedByWM(ATOM(_NET_WM_USER_TIME_WINDOW));
- if (extra->userTimeWindow || isSupportedByWM) {
- if (!extra->userTimeWindow) {
- extra->userTimeWindow = XCreateSimpleWindow(X11->display,
- tlw->internalWinId(),
- -1, -1, 1, 1, 0, 0, 0);
- wid = extra->userTimeWindow;
- XChangeProperty(X11->display, tlw->internalWinId(), ATOM(_NET_WM_USER_TIME_WINDOW),
- XA_WINDOW, 32, PropModeReplace,
- (unsigned char *)&wid, 1);
- XDeleteProperty(X11->display, tlw->internalWinId(), ATOM(_NET_WM_USER_TIME));
- } else if (!isSupportedByWM) {
- // WM no longer supports it, then we should remove the
- // _NET_WM_USER_TIME_WINDOW atom.
- qt_net_remove_user_time(tlw);
- } else {
- wid = extra->userTimeWindow;
- }
- }
- XChangeProperty(X11->display, wid, ATOM(_NET_WM_USER_TIME),
- XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &timestamp, 1);
-}
-
-static void qt_check_focus_model()
-{
- Window fw = XNone;
- int unused;
- XGetInputFocus(X11->display, &fw, &unused);
- if (fw == PointerRoot)
- X11->focus_model = QX11Data::FM_PointerRoot;
- else
- X11->focus_model = QX11Data::FM_Other;
-}
-
-#ifndef QT_NO_TABLET
-
-#if !defined (Q_OS_IRIX)
-// from include/Xwacom.h
-# define XWACOM_PARAM_TOOLID 322
-# define XWACOM_PARAM_TOOLSERIAL 323
-
-typedef WACOMCONFIG * (*PtrWacomConfigInit) (Display*, WACOMERRORFUNC);
-typedef WACOMDEVICE * (*PtrWacomConfigOpenDevice) (WACOMCONFIG*, const char*);
-typedef int *(*PtrWacomConfigGetRawParam) (WACOMDEVICE*, int, int*, int, unsigned*);
-typedef int (*PtrWacomConfigCloseDevice) (WACOMDEVICE *);
-typedef void (*PtrWacomConfigTerm) (WACOMCONFIG *);
-
-static PtrWacomConfigInit ptrWacomConfigInit = 0;
-static PtrWacomConfigOpenDevice ptrWacomConfigOpenDevice = 0;
-static PtrWacomConfigGetRawParam ptrWacomConfigGetRawParam = 0;
-static PtrWacomConfigCloseDevice ptrWacomConfigCloseDevice = 0;
-static PtrWacomConfigTerm ptrWacomConfigTerm = 0;
-Q_GLOBAL_STATIC(QByteArray, wacomDeviceName)
-#endif
-
-#endif
-
-/*****************************************************************************
- qt_init() - initializes Qt for X11
- *****************************************************************************/
-
-#if !defined(QT_NO_FONTCONFIG)
-static void getXDefault(const char *group, const char *key, int *val)
-{
- char *str = XGetDefault(X11->display, group, key);
- if (str) {
- char *end = 0;
- int v = strtol(str, &end, 0);
- if (str != end)
- *val = v;
- // otherwise use fontconfig to convert the string to integer
- else
- FcNameConstant((FcChar8 *) str, val);
- }
-}
-
-static void getXDefault(const char *group, const char *key, double *val)
-{
- char *str = XGetDefault(X11->display, group, key);
- if (str) {
- bool ok;
- double v = QByteArray(str).toDouble(&ok);
- if (ok)
- *val = v;
- }
-}
-
-static void getXDefault(const char *group, const char *key, bool *val)
-{
- char *str = XGetDefault(X11->display, group, key);
- if (str) {
- char c = str[0];
- if (isupper((int)c))
- c = tolower(c);
- if (c == 't' || c == 'y' || c == '1')
- *val = true;
- else if (c == 'f' || c == 'n' || c == '0')
- *val = false;
- if (c == 'o') {
- c = str[1];
- if (isupper((int)c))
- c = tolower(c);
- if (c == 'n')
- *val = true;
- if (c == 'f')
- *val = false;
- }
- }
-}
-#endif
-
-// ### This should be static but it isn't because of the friend declaration
-// ### in qpaintdevice.h which then should have a static too but can't have
-// ### it because "storage class specifiers invalid in friend function
-// ### declarations" :-) Ideas anyone?
-void qt_init(QApplicationPrivate *priv, int,
- Display *display, Qt::HANDLE visual, Qt::HANDLE colormap)
-{
- X11 = new QX11Data;
- X11->display = display;
- X11->displayName = 0;
- X11->foreignDisplay = (display != 0);
- X11->focus_model = -1;
-
- // RANDR
- X11->use_xrandr = false;
- X11->xrandr_major = 0;
- X11->xrandr_eventbase = 0;
- X11->xrandr_errorbase = 0;
-
- // RENDER
- X11->use_xrender = false;
- X11->xrender_major = 0;
- X11->xrender_version = 0;
-
- // XFIXES
- X11->use_xfixes = false;
- X11->xfixes_major = 0;
- X11->xfixes_eventbase = 0;
- X11->xfixes_errorbase = 0;
-
- // XInputExtension
- X11->use_xinput = false;
- X11->xinput_major = 0;
- X11->xinput_eventbase = 0;
- X11->xinput_errorbase = 0;
-
- X11->use_xkb = false;
- X11->xkb_major = 0;
- X11->xkb_eventbase = 0;
- X11->xkb_errorbase = 0;
-
- // MIT-SHM
- X11->use_mitshm = false;
- X11->use_mitshm_pixmaps = false;
- X11->mitshm_major = 0;
-
- X11->sip_serial = 0;
- X11->net_supported_list = 0;
- X11->net_virtual_root_list = 0;
- X11->wm_client_leader = 0;
- X11->screens = 0;
- X11->argbVisuals = 0;
- X11->argbColormaps = 0;
- X11->screenCount = 0;
- X11->time = CurrentTime;
- X11->userTime = CurrentTime;
- X11->ignore_badwindow = false;
- X11->seen_badwindow = false;
-
- X11->motifdnd_active = false;
-
- X11->default_im = QLatin1String("imsw-multi");
- priv->inputContext = 0;
-
- // colormap control
- X11->visual_class = -1;
- X11->visual_id = -1;
- X11->color_count = 0;
- X11->custom_cmap = false;
-
- // outside visual/colormap
- X11->visual = reinterpret_cast<Visual *>(visual);
- X11->colormap = colormap;
-
- // Fontconfig
- X11->has_fontconfig = false;
-#if !defined(QT_NO_FONTCONFIG)
- if (qgetenv("QT_X11_NO_FONTCONFIG").isNull())
- X11->has_fontconfig = FcInit();
- X11->fc_antialias = true;
-#endif
-
-#ifndef QT_NO_XRENDER
- memset(X11->solid_fills, 0, sizeof(X11->solid_fills));
- for (int i = 0; i < X11->solid_fill_count; ++i)
- X11->solid_fills[i].screen = -1;
- memset(X11->pattern_fills, 0, sizeof(X11->pattern_fills));
- for (int i = 0; i < X11->pattern_fill_count; ++i)
- X11->pattern_fills[i].screen = -1;
-#endif
-
- X11->startupId = 0;
-
- int argc = priv->argc;
- char **argv = priv->argv;
-
- if (X11->display) {
- // Qt part of other application
-
- // Set application name and class
- appName = qstrdup("Qt-subapplication");
- char *app_class = 0;
- if (argv) {
- const char* p = strrchr(argv[0], '/');
- app_class = qstrdup(p ? p + 1 : argv[0]);
- if (app_class[0])
- app_class[0] = toupper(app_class[0]);
- }
- appClass = app_class;
- } else {
- // Qt controls everything (default)
-
- if (QApplication::testAttribute(Qt::AA_X11InitThreads))
- XInitThreads();
-
- // Set application name and class
- char *app_class = 0;
- if (argv && argv[0]) {
- const char *p = strrchr(argv[0], '/');
- appName = p ? p + 1 : argv[0];
- app_class = qstrdup(appName);
- if (app_class[0])
- app_class[0] = toupper(app_class[0]);
- }
- appClass = app_class;
- }
-
- // Install default error handlers
- original_x_errhandler = XSetErrorHandler(qt_x_errhandler);
- original_xio_errhandler = XSetIOErrorHandler(qt_xio_errhandler);
-
- // Get command line params
- int j = argc ? 1 : 0;
- for (int i=1; i<argc; i++) {
- if (argv[i] && *argv[i] != '-') {
- argv[j++] = argv[i];
- continue;
- }
- QByteArray arg(argv[i]);
- if (arg == "-display") {
- if (++i < argc && !X11->display)
- X11->displayName = argv[i];
- } else if (arg == "-fn" || arg == "-font") {
- if (++i < argc)
- appFont = argv[i];
- } else if (arg == "-bg" || arg == "-background") {
- if (++i < argc)
- appBGCol = argv[i];
- } else if (arg == "-btn" || arg == "-button") {
- if (++i < argc)
- appBTNCol = argv[i];
- } else if (arg == "-fg" || arg == "-foreground") {
- if (++i < argc)
- appFGCol = argv[i];
- } else if (arg == "-name") {
- if (++i < argc)
- appName = argv[i];
- } else if (arg == "-title") {
- if (++i < argc)
- mwTitle = argv[i];
- } else if (arg == "-geometry") {
- if (++i < argc)
- mwGeometry = argv[i];
- } else if (arg == "-im") {
- if (++i < argc)
- qt_ximServer = argv[i];
- } else if (arg == "-ncols") { // xv and netscape use this name
- if (++i < argc)
- X11->color_count = qMax(0,atoi(argv[i]));
- } else if (arg == "-visual") { // xv and netscape use this name
- if (++i < argc && !X11->visual) {
- QString s = QString::fromLocal8Bit(argv[i]).toLower();
- if (s == QLatin1String("staticgray"))
- X11->visual_class = StaticGray;
- else if (s == QLatin1String("grayscale"))
- X11->visual_class = XGrayScale;
- else if (s == QLatin1String("staticcolor"))
- X11->visual_class = StaticColor;
- else if (s == QLatin1String("pseudocolor"))
- X11->visual_class = PseudoColor;
- else if (s == QLatin1String("truecolor"))
- X11->visual_class = TrueColor;
- else if (s == QLatin1String("directcolor"))
- X11->visual_class = DirectColor;
- else
- X11->visual_id = static_cast<int>(strtol(argv[i], 0, 0));
- }
-#ifndef QT_NO_XIM
- } else if (arg == "-inputstyle") {
- if (++i < argc) {
- QString s = QString::fromLocal8Bit(argv[i]).toLower();
- if (s == QLatin1String("onthespot"))
- qt_xim_preferred_style = XIMPreeditCallbacks |
- XIMStatusNothing;
- else if (s == QLatin1String("overthespot"))
- qt_xim_preferred_style = XIMPreeditPosition |
- XIMStatusNothing;
- else if (s == QLatin1String("offthespot"))
- qt_xim_preferred_style = XIMPreeditArea |
- XIMStatusArea;
- else if (s == QLatin1String("root"))
- qt_xim_preferred_style = XIMPreeditNothing |
- XIMStatusNothing;
- }
-#endif
- } else if (arg == "-cmap") { // xv uses this name
- if (!X11->colormap)
- X11->custom_cmap = true;
- }
- else if (arg == "-sync")
- appSync = !appSync;
-#if defined(QT_DEBUG)
- else if (arg == "-nograb")
- appNoGrab = !appNoGrab;
- else if (arg == "-dograb")
- appDoGrab = !appDoGrab;
-#endif
- else
- argv[j++] = argv[i];
- }
-
- priv->argc = j;
-
-#if defined(QT_DEBUG) && defined(Q_OS_LINUX)
- if (!appNoGrab && !appDoGrab) {
- QString s;
- s.sprintf("/proc/%d/cmdline", getppid());
- QFile f(s);
- if (f.open(QIODevice::ReadOnly)) {
- s.clear();
- char c;
- while (f.getChar(&c) && c) {
- if (c == '/')
- s.clear();
- else
- s += QLatin1Char(c);
- }
- if (s == QLatin1String("gdb")) {
- appNoGrab = true;
- qDebug("Qt: gdb: -nograb added to command-line options.\n"
- "\t Use the -dograb option to enforce grabbing.");
- }
- f.close();
- }
- }
-#endif
-
- // Connect to X server
- if (qt_is_gui_used && !X11->display) {
- if ((X11->display = XOpenDisplay(X11->displayName)) == 0) {
- qWarning("%s: cannot connect to X server %s", appName,
- XDisplayName(X11->displayName));
- QApplicationPrivate::reset_instance_pointer();
- exit(1);
- }
-
- if (appSync) // if "-sync" argument
- XSynchronize(X11->display, true);
- }
-
- // Common code, regardless of whether display is foreign.
-
- // Get X parameters
-
- if (qt_is_gui_used) {
- X11->defaultScreen = DefaultScreen(X11->display);
- X11->screenCount = ScreenCount(X11->display);
-
- X11->screens = new QX11InfoData[X11->screenCount];
- X11->argbVisuals = new Visual *[X11->screenCount];
- X11->argbColormaps = new Colormap[X11->screenCount];
-
- for (int s = 0; s < X11->screenCount; s++) {
- QX11InfoData *screen = X11->screens + s;
- screen->ref = 1; // ensures it doesn't get deleted
- screen->screen = s;
-
- int widthMM = DisplayWidthMM(X11->display, s);
- if (widthMM != 0) {
- screen->dpiX = (DisplayWidth(X11->display, s) * 254 + widthMM * 5) / (widthMM * 10);
- } else {
- screen->dpiX = 72;
- }
-
- int heightMM = DisplayHeightMM(X11->display, s);
- if (heightMM != 0) {
- screen->dpiY = (DisplayHeight(X11->display, s) * 254 + heightMM * 5) / (heightMM * 10);
- } else {
- screen->dpiY = 72;
- }
-
- X11->argbVisuals[s] = 0;
- X11->argbColormaps[s] = 0;
- }
-
-
-#ifndef QT_NO_XRENDER
- int xrender_eventbase, xrender_errorbase;
- // See if XRender is supported on the connected display
- if (XQueryExtension(X11->display, "RENDER", &X11->xrender_major,
- &xrender_eventbase, &xrender_errorbase)
- && XRenderQueryExtension(X11->display, &xrender_eventbase,
- &xrender_errorbase)) {
- // Check the version as well - we need v0.4 or higher
- int major = 0;
- int minor = 0;
- XRenderQueryVersion(X11->display, &major, &minor);
- if (qgetenv("QT_X11_NO_XRENDER").isNull()) {
- X11->use_xrender = (major >= 0 && minor >= 5);
- X11->xrender_version = major*100+minor;
- // workaround for broken XServer on Ubuntu Breezy (6.8 compiled with 7.0
- // protocol headers)
- if (X11->xrender_version == 10
- && VendorRelease(X11->display) < 60900000
- && QByteArray(ServerVendor(X11->display)).contains("X.Org"))
- X11->xrender_version = 9;
- }
- }
-#endif // QT_NO_XRENDER
-
-#ifndef QT_NO_MITSHM
- int mitshm_minor;
- int mitshm_major;
- int mitshm_eventbase;
- int mitshm_errorbase;
- int mitshm_pixmaps;
- if (XQueryExtension(X11->display, "MIT-SHM", &X11->mitshm_major,
- &mitshm_eventbase, &mitshm_errorbase)
- && XShmQueryVersion(X11->display, &mitshm_major, &mitshm_minor,
- &mitshm_pixmaps))
- {
- QString displayName = QLatin1String(XDisplayName(NULL));
-
- // MITSHM only works for local displays, so do a quick check here
- // to determine whether the display is local or not (not 100 % accurate).
- // BGR server layouts are not supported either, since it requires the raster
- // engine to work on a QImage with BGR layout.
- bool local = displayName.isEmpty() || displayName.lastIndexOf(QLatin1Char(':')) == 0;
- if (local && (qgetenv("QT_X11_NO_MITSHM").toInt() == 0)) {
- Visual *defaultVisual = DefaultVisual(X11->display, DefaultScreen(X11->display));
- X11->use_mitshm = ((defaultVisual->red_mask == 0xff0000
- || defaultVisual->red_mask == 0xf800)
- && (defaultVisual->green_mask == 0xff00
- || defaultVisual->green_mask == 0x7e0)
- && (defaultVisual->blue_mask == 0xff
- || defaultVisual->blue_mask == 0x1f));
- X11->use_mitshm_pixmaps = X11->use_mitshm && mitshm_pixmaps;
- }
- }
-#endif // QT_NO_MITSHM
-
- // initialize the graphics system - order is imporant here - it must be done before
- // the QColormap::initialize() call
- QApplicationPrivate::graphics_system = QGraphicsSystemFactory::create(QApplicationPrivate::graphics_system_name);
- QColormap::initialize();
-
- // Support protocols
- X11->xdndSetup();
-
- // Finally create all atoms
- qt_x11_create_intern_atoms();
-
- // initialize NET lists
- qt_get_net_supported();
- qt_get_net_virtual_roots();
-
-#ifndef QT_NO_XRANDR
- // See if XRandR is supported on the connected display
- if (XQueryExtension(X11->display, "RANDR", &X11->xrandr_major,
- &X11->xrandr_eventbase, &X11->xrandr_errorbase)) {
-
-# ifdef QT_RUNTIME_XRANDR
- X11->ptrXRRSelectInput = 0;
- X11->ptrXRRUpdateConfiguration = 0;
- X11->ptrXRRRootToScreen = 0;
- X11->ptrXRRQueryExtension = 0;
- QLibrary xrandrLib(QLatin1String("Xrandr"), 2);
- if (!xrandrLib.load()) { // try without the version number
- xrandrLib.setFileName(QLatin1String("Xrandr"));
- xrandrLib.load();
- }
- if (xrandrLib.isLoaded()) {
- X11->ptrXRRSelectInput =
- (PtrXRRSelectInput) xrandrLib.resolve("XRRSelectInput");
- X11->ptrXRRUpdateConfiguration =
- (PtrXRRUpdateConfiguration) xrandrLib.resolve("XRRUpdateConfiguration");
- X11->ptrXRRRootToScreen =
- (PtrXRRRootToScreen) xrandrLib.resolve("XRRRootToScreen");
- X11->ptrXRRQueryExtension =
- (PtrXRRQueryExtension) xrandrLib.resolve("XRRQueryExtension");
- X11->ptrXRRSizes =
- (PtrXRRSizes) xrandrLib.resolve("XRRSizes");
- }
-# else
- X11->ptrXRRSelectInput = XRRSelectInput;
- X11->ptrXRRUpdateConfiguration = XRRUpdateConfiguration;
- X11->ptrXRRRootToScreen = XRRRootToScreen;
- X11->ptrXRRQueryExtension = XRRQueryExtension;
- X11->ptrXRRSizes = XRRSizes;
-# endif
-
- if (X11->ptrXRRQueryExtension
- && X11->ptrXRRQueryExtension(X11->display, &X11->xrandr_eventbase, &X11->xrandr_errorbase)) {
- // XRandR is supported
- X11->use_xrandr = true;
- }
- }
-#endif // QT_NO_XRANDR
-
-#ifndef QT_NO_XRENDER
- if (X11->use_xrender) {
- // XRender is supported, let's see if we have a PictFormat for the
- // default visual
- XRenderPictFormat *format =
- XRenderFindVisualFormat(X11->display,
- (Visual *) QX11Info::appVisual(X11->defaultScreen));
-
- if (!format) {
- X11->use_xrender = false;
- }
- }
-#endif // QT_NO_XRENDER
-
-#ifndef QT_NO_XFIXES
- // See if Xfixes is supported on the connected display
- if (XQueryExtension(X11->display, "XFIXES", &X11->xfixes_major,
- &X11->xfixes_eventbase, &X11->xfixes_errorbase)) {
- X11->ptrXFixesQueryExtension = XFIXES_LOAD_V1(XFixesQueryExtension);
- X11->ptrXFixesQueryVersion = XFIXES_LOAD_V1(XFixesQueryVersion);
- X11->ptrXFixesSetCursorName = XFIXES_LOAD_V2(XFixesSetCursorName);
- X11->ptrXFixesSelectSelectionInput = XFIXES_LOAD_V2(XFixesSelectSelectionInput);
-
- if(X11->ptrXFixesQueryExtension && X11->ptrXFixesQueryVersion
- && X11->ptrXFixesQueryExtension(X11->display, &X11->xfixes_eventbase,
- &X11->xfixes_errorbase)) {
- // Xfixes is supported.
- // Note: the XFixes protocol version is negotiated using QueryVersion.
- // We supply the highest version we support, the X server replies with
- // the highest version it supports, but no higher than the version we
- // asked for. The version sent back is the protocol version the X server
- // will use to talk us. If this call is removed, the behavior of the
- // X server when it receives an XFixes request is undefined.
- int major = 3;
- int minor = 0;
- X11->ptrXFixesQueryVersion(X11->display, &major, &minor);
- X11->use_xfixes = (major >= 1);
- X11->xfixes_major = major;
- }
- }
-#endif // QT_NO_XFIXES
-
-#ifndef QT_NO_XCURSOR
-#ifdef QT_RUNTIME_XCURSOR
- X11->ptrXcursorLibraryLoadCursor = 0;
- QLibrary xcursorLib(QLatin1String("Xcursor"), 1);
- bool xcursorFound = xcursorLib.load();
- if (!xcursorFound) { //try without the version number
- xcursorLib.setFileName(QLatin1String("Xcursor"));
- xcursorFound = xcursorLib.load();
- }
- if (xcursorFound) {
- X11->ptrXcursorLibraryLoadCursor =
- (PtrXcursorLibraryLoadCursor) xcursorLib.resolve("XcursorLibraryLoadCursor");
- }
-#else
- X11->ptrXcursorLibraryLoadCursor = XcursorLibraryLoadCursor;
-#endif // QT_RUNTIME_XCURSOR
-#endif // QT_NO_XCURSOR
-
-#ifndef QT_NO_XSYNC
- int xsync_evbase, xsync_errbase;
- int major, minor;
- if (XSyncQueryExtension(X11->display, &xsync_evbase, &xsync_errbase))
- XSyncInitialize(X11->display, &major, &minor);
-#endif // QT_NO_XSYNC
-
-#ifndef QT_NO_XINERAMA
-#ifdef QT_RUNTIME_XINERAMA
- X11->ptrXineramaQueryExtension = 0;
- X11->ptrXineramaIsActive = 0;
- X11->ptrXineramaQueryScreens = 0;
- QLibrary xineramaLib(QLatin1String("Xinerama"), 1);
- bool xineramaFound = xineramaLib.load();
- if (!xineramaFound) { //try without the version number
- xineramaLib.setFileName(QLatin1String("Xinerama"));
- xineramaFound = xineramaLib.load();
- }
- if (xineramaFound) {
- X11->ptrXineramaQueryExtension =
- (PtrXineramaQueryExtension) xineramaLib.resolve("XineramaQueryExtension");
- X11->ptrXineramaIsActive =
- (PtrXineramaIsActive) xineramaLib.resolve("XineramaIsActive");
- X11->ptrXineramaQueryScreens =
- (PtrXineramaQueryScreens) xineramaLib.resolve("XineramaQueryScreens");
- }
-#else
- X11->ptrXineramaQueryScreens = XineramaQueryScreens;
- X11->ptrXineramaIsActive = XineramaIsActive;
- X11->ptrXineramaQueryExtension = XineramaQueryExtension;
-#endif // QT_RUNTIME_XINERAMA
-#endif // QT_NO_XINERAMA
-
-#ifndef QT_NO_XINPUT
- // See if Xinput is supported on the connected display
- X11->ptrXCloseDevice = 0;
- X11->ptrXListInputDevices = 0;
- X11->ptrXOpenDevice = 0;
- X11->ptrXFreeDeviceList = 0;
- X11->ptrXSelectExtensionEvent = 0;
- X11->use_xinput = XQueryExtension(X11->display, "XInputExtension", &X11->xinput_major,
- &X11->xinput_eventbase, &X11->xinput_errorbase);
- if (X11->use_xinput) {
- X11->ptrXCloseDevice = XINPUT_LOAD(XCloseDevice);
- X11->ptrXListInputDevices = XINPUT_LOAD(XListInputDevices);
- X11->ptrXOpenDevice = XINPUT_LOAD(XOpenDevice);
- X11->ptrXFreeDeviceList = XINPUT_LOAD(XFreeDeviceList);
- X11->ptrXSelectExtensionEvent = XINPUT_LOAD(XSelectExtensionEvent);
- }
-#endif // QT_NO_XINPUT
-
-#ifndef QT_NO_XKB
- int xkblibMajor = XkbMajorVersion;
- int xkblibMinor = XkbMinorVersion;
- X11->use_xkb = XkbQueryExtension(X11->display,
- &X11->xkb_major,
- &X11->xkb_eventbase,
- &X11->xkb_errorbase,
- &xkblibMajor,
- &xkblibMinor);
- if (X11->use_xkb) {
- // If XKB is detected, set the GrabsUseXKBState option so input method
- // compositions continue to work (ie. deadkeys)
- unsigned int state = XkbPCF_GrabsUseXKBStateMask;
- (void) XkbSetPerClientControls(X11->display, state, &state);
-
- // select for group change events
- XkbSelectEventDetails(X11->display,
- XkbUseCoreKbd,
- XkbStateNotify,
- XkbAllStateComponentsMask,
- XkbGroupStateMask);
-
- // current group state is queried when creating the keymapper, no need to do it here
- }
-#endif
-
-
-#if !defined(QT_NO_FONTCONFIG)
- int dpi = 0;
- getXDefault("Xft", FC_DPI, &dpi);
- if (dpi) {
- for (int s = 0; s < ScreenCount(X11->display); ++s) {
- QX11Info::setAppDpiX(s, dpi);
- QX11Info::setAppDpiY(s, dpi);
- }
- }
- double fc_scale = 1.;
- getXDefault("Xft", FC_SCALE, &fc_scale);
- X11->fc_scale = fc_scale;
- for (int s = 0; s < ScreenCount(X11->display); ++s) {
- int subpixel = FC_RGBA_UNKNOWN;
-#if !defined(QT_NO_XRENDER) && (RENDER_MAJOR > 0 || RENDER_MINOR >= 6)
- if (X11->use_xrender) {
- int rsp = XRenderQuerySubpixelOrder(X11->display, s);
- switch (rsp) {
- default:
- case SubPixelUnknown:
- subpixel = FC_RGBA_UNKNOWN;
- break;
- case SubPixelHorizontalRGB:
- subpixel = FC_RGBA_RGB;
- break;
- case SubPixelHorizontalBGR:
- subpixel = FC_RGBA_BGR;
- break;
- case SubPixelVerticalRGB:
- subpixel = FC_RGBA_VRGB;
- break;
- case SubPixelVerticalBGR:
- subpixel = FC_RGBA_VBGR;
- break;
- case SubPixelNone:
- subpixel = FC_RGBA_NONE;
- break;
- }
- }
-#endif
-
- char *rgba = XGetDefault(X11->display, "Xft", FC_RGBA);
- if (rgba) {
- char *end = 0;
- int v = strtol(rgba, &end, 0);
- if (rgba != end) {
- subpixel = v;
- } else if (qstrncmp(rgba, "unknown", 7) == 0) {
- subpixel = FC_RGBA_UNKNOWN;
- } else if (qstrncmp(rgba, "rgb", 3) == 0) {
- subpixel = FC_RGBA_RGB;
- } else if (qstrncmp(rgba, "bgr", 3) == 0) {
- subpixel = FC_RGBA_BGR;
- } else if (qstrncmp(rgba, "vrgb", 4) == 0) {
- subpixel = FC_RGBA_VRGB;
- } else if (qstrncmp(rgba, "vbgr", 4) == 0) {
- subpixel = FC_RGBA_VBGR;
- } else if (qstrncmp(rgba, "none", 4) == 0) {
- subpixel = FC_RGBA_NONE;
- }
- }
- X11->screens[s].subpixel = subpixel;
- }
- getXDefault("Xft", FC_ANTIALIAS, &X11->fc_antialias);
-#ifdef FC_HINT_STYLE
- X11->fc_hint_style = -1;
- getXDefault("Xft", FC_HINT_STYLE, &X11->fc_hint_style);
-#endif
-#if 0
- // ###### these are implemented by Xft, not sure we need them
- getXDefault("Xft", FC_AUTOHINT, &X11->fc_autohint);
- getXDefault("Xft", FC_HINTING, &X11->fc_autohint);
- getXDefault("Xft", FC_MINSPACE, &X11->fc_autohint);
-#endif
-#endif // QT_NO_XRENDER
-
- // initialize key mapper
- QKeyMapper::changeKeyboard();
-
- // Misc. initialization
-#if 0 //disabled for now..
- QSegfaultHandler::initialize(priv->argv, priv->argc);
-#endif
- QCursorData::initialize();
- }
- QFont::initialize();
-
- if(qt_is_gui_used) {
- qApp->setObjectName(QString::fromLocal8Bit(appName));
-
- int screen;
- for (screen = 0; screen < X11->screenCount; ++screen) {
- XSelectInput(X11->display, QX11Info::appRootWindow(screen),
- KeymapStateMask | EnterWindowMask | LeaveWindowMask | PropertyChangeMask);
-
-#ifndef QT_NO_XRANDR
- if (X11->use_xrandr)
- X11->ptrXRRSelectInput(X11->display, QX11Info::appRootWindow(screen), True);
-#endif // QT_NO_XRANDR
- }
- }
-
- if (qt_is_gui_used) {
- // Attempt to determine the current running X11 Desktop Enviornment
- // Use dbus if/when we can, but fall back to using windowManagerName() for now
-
-#ifndef QT_NO_XFIXES
- if (X11->ptrXFixesSelectSelectionInput)
- X11->ptrXFixesSelectSelectionInput(X11->display, QX11Info::appRootWindow(), ATOM(_NET_WM_CM_S0),
- XFixesSetSelectionOwnerNotifyMask
- | XFixesSelectionWindowDestroyNotifyMask
- | XFixesSelectionClientCloseNotifyMask);
-#endif // QT_NO_XFIXES
- X11->compositingManagerRunning = XGetSelectionOwner(X11->display,
- ATOM(_NET_WM_CM_S0));
- X11->desktopEnvironment = DE_UNKNOWN;
- X11->desktopVersion = 0;
-
- Atom type;
- int format;
- unsigned long length, after;
- uchar *data = 0;
- int rc;
-
- do {
- if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
- X11->desktopEnvironment = DE_KDE;
- X11->desktopVersion = qgetenv("KDE_SESSION_VERSION").toInt();
- break;
- }
-
- if (qgetenv("DESKTOP_SESSION") == "gnome") {
- X11->desktopEnvironment = DE_GNOME;
- break;
- }
-
- // GNOME_DESKTOP_SESSION_ID is deprecated for some reason, but still check it
- if (!qgetenv("GNOME_DESKTOP_SESSION_ID").isEmpty()) {
- X11->desktopEnvironment = DE_GNOME;
- break;
- }
-
- rc = XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(_DT_SAVE_MODE),
- 0, 2, False, XA_STRING, &type, &format, &length,
- &after, &data);
- if (rc == Success && length) {
- if (!strcmp(reinterpret_cast<char *>(data), "xfce4")) {
- // Pretend that xfce4 is gnome, as it uses the same libraries.
- // The detection above is stolen from xdg-open.
- X11->desktopEnvironment = DE_GNOME;
- break;
- }
-
- // We got the property but it wasn't xfce4. Free data before it gets overwritten.
- XFree(data);
- data = 0;
- }
-
- rc = XGetWindowProperty(X11->display, QX11Info::appRootWindow(), ATOM(DTWM_IS_RUNNING),
- 0, 1, False, AnyPropertyType, &type, &format, &length,
- &after, &data);
- if (rc == Success && length) {
- // DTWM is running, meaning most likely CDE is running...
- X11->desktopEnvironment = DE_CDE;
- break;
- }
-
- rc = XGetWindowProperty(X11->display, QX11Info::appRootWindow(),
- ATOM(_SGI_DESKS_MANAGER), 0, 1, False, XA_WINDOW,
- &type, &format, &length, &after, &data);
- if (rc == Success && length) {
- X11->desktopEnvironment = DE_4DWM;
- break;
- }
-
- if (XGetWindowProperty(X11->display, QX11Info::appRootWindow(),
- ATOM(_NET_SUPPORTING_WM_CHECK),
- 0, 1024, False, XA_WINDOW, &type,
- &format, &length, &after, &data) == Success) {
- if (type == XA_WINDOW && format == 32) {
- Window windowManagerWindow = *((Window*) data);
- XFree(data);
- data = 0;
-
- if (windowManagerWindow != XNone) {
- Atom utf8atom = ATOM(UTF8_STRING);
- if (XGetWindowProperty(QX11Info::display(), windowManagerWindow, ATOM(_NET_WM_NAME),
- 0, 1024, False, utf8atom, &type,
- &format, &length, &after, &data) == Success) {
- if (type == utf8atom && format == 8) {
- if (qstrcmp((const char *)data, "MCompositor") == 0)
- X11->desktopEnvironment = DE_MEEGO_COMPOSITOR;
- }
- }
- }
- }
- }
-
- } while(0);
-
- if (data)
- XFree((char *)data);
-
-#if !defined(QT_NO_STYLE_GTK)
- if (X11->desktopEnvironment == DE_GNOME) {
- static bool menusHaveIcons = QGtkStyle::getGConfBool(QLatin1String("/desktop/gnome/interface/menus_have_icons"), true);
- QApplication::setAttribute(Qt::AA_DontShowIconsInMenus, !menusHaveIcons);
- }
-#endif
- qt_set_input_encoding();
-
- qt_set_x11_resources(appFont, appFGCol, appBGCol, appBTNCol);
-
- // be smart about the size of the default font. most X servers have helvetica
- // 12 point available at 2 resolutions:
- // 75dpi (12 pixels) and 100dpi (17 pixels).
- // At 95 DPI, a 12 point font should be 16 pixels tall - in which case a 17
- // pixel font is a closer match than a 12 pixel font
- int ptsz = (X11->use_xrender
- ? 9
- : (int) (((QX11Info::appDpiY() >= 95 ? 17. : 12.) *
- 72. / (float) QX11Info::appDpiY()) + 0.5));
-
- if (!QApplicationPrivate::sys_font) {
- // no font from settings or RESOURCE_MANAGER, provide a fallback
- QFont f(X11->has_fontconfig ? QLatin1String("Sans Serif") : QLatin1String("Helvetica"),
- ptsz);
- QApplicationPrivate::setSystemFont(f);
- }
-
-#if !defined (QT_NO_TABLET)
- if (X11->use_xinput) {
- int ndev,
- i,
- j;
- bool gotStylus,
- gotEraser;
- XDeviceInfo *devices = 0, *devs;
- XInputClassInfo *ip;
- XAnyClassPtr any;
- XValuatorInfoPtr v;
- XAxisInfoPtr a;
- XDevice *dev = 0;
-
- if (X11->ptrXListInputDevices) {
- devices = X11->ptrXListInputDevices(X11->display, &ndev);
- if (!devices)
- qWarning("QApplication: Failed to get list of tablet devices");
- }
- if (!devices)
- ndev = -1;
- QTabletEvent::TabletDevice deviceType;
- for (devs = devices, i = 0; i < ndev && devs; i++, devs++) {
- dev = 0;
- deviceType = QTabletEvent::NoDevice;
- gotStylus = false;
- gotEraser = false;
-
-#if defined(Q_OS_IRIX)
- QString devName = QString::fromLocal8Bit(devs->name).toLower();
- if (devName == QLatin1String(WACOM_NAME)) {
- deviceType = QTabletEvent::Stylus;
- gotStylus = true;
- }
-#else
- if (devs->type == ATOM(XWacomStylus) || devs->type == ATOM(XTabletStylus)) {
- deviceType = QTabletEvent::Stylus;
- if (wacomDeviceName()->isEmpty())
- wacomDeviceName()->append(devs->name);
- gotStylus = true;
- } else if (devs->type == ATOM(XWacomEraser) || devs->type == ATOM(XTabletEraser)) {
- deviceType = QTabletEvent::XFreeEraser;
- gotEraser = true;
- }
-#endif
- if (deviceType == QTabletEvent::NoDevice)
- continue;
-
- if (gotStylus || gotEraser) {
- if (X11->ptrXOpenDevice)
- dev = X11->ptrXOpenDevice(X11->display, devs->id);
-
- if (!dev)
- continue;
-
- QTabletDeviceData device_data;
- device_data.deviceType = deviceType;
- device_data.eventCount = 0;
- device_data.device = dev;
- device_data.xinput_motion = -1;
- device_data.xinput_key_press = -1;
- device_data.xinput_key_release = -1;
- device_data.xinput_button_press = -1;
- device_data.xinput_button_release = -1;
- device_data.xinput_proximity_in = -1;
- device_data.xinput_proximity_out = -1;
- device_data.widgetToGetPress = 0;
-
- if (dev->num_classes > 0) {
- for (ip = dev->classes, j = 0; j < dev->num_classes;
- ip++, j++) {
- switch (ip->input_class) {
- case KeyClass:
- DeviceKeyPress(dev, device_data.xinput_key_press,
- device_data.eventList[device_data.eventCount]);
- if (device_data.eventList[device_data.eventCount])
- ++device_data.eventCount;
- DeviceKeyRelease(dev, device_data.xinput_key_release,
- device_data.eventList[device_data.eventCount]);
- if (device_data.eventList[device_data.eventCount])
- ++device_data.eventCount;
- break;
- case ButtonClass:
- DeviceButtonPress(dev, device_data.xinput_button_press,
- device_data.eventList[device_data.eventCount]);
- if (device_data.eventList[device_data.eventCount])
- ++device_data.eventCount;
- DeviceButtonRelease(dev, device_data.xinput_button_release,
- device_data.eventList[device_data.eventCount]);
- if (device_data.eventList[device_data.eventCount])
- ++device_data.eventCount;
- break;
- case ValuatorClass:
- // I'm only going to be interested in motion when the
- // stylus is already down anyway!
- DeviceMotionNotify(dev, device_data.xinput_motion,
- device_data.eventList[device_data.eventCount]);
- if (device_data.eventList[device_data.eventCount])
- ++device_data.eventCount;
- ProximityIn(dev, device_data.xinput_proximity_in, device_data.eventList[device_data.eventCount]);
- if (device_data.eventList[device_data.eventCount])
- ++device_data.eventCount;
- ProximityOut(dev, device_data.xinput_proximity_out, device_data.eventList[device_data.eventCount]);
- if (device_data.eventList[device_data.eventCount])
- ++device_data.eventCount;
- default:
- break;
- }
- }
- }
-
- // get the min/max value for pressure!
- any = (XAnyClassPtr) (devs->inputclassinfo);
- for (j = 0; j < devs->num_classes; j++) {
- if (any->c_class == ValuatorClass) {
- v = (XValuatorInfoPtr) any;
- a = (XAxisInfoPtr) ((char *) v +
- sizeof (XValuatorInfo));
-#if defined (Q_OS_IRIX)
- // I'm not exaclty wild about this, but the
- // dimensions of the tablet are more relevant here
- // than the min and max values from the axis
- // (actually it seems to be 2/3 or what is in the
- // axis. So we'll try to parse it from this
- // string. --tws
- char returnString[SGIDeviceRtrnLen];
- int tmp;
- if (XSGIMiscQueryExtension(X11->display, &tmp, &tmp)
- && XSGIDeviceQuery(X11->display, devs->id,
- "dimensions", returnString)) {
- QString str = QLatin1String(returnString);
- int comma = str.indexOf(',');
- device_data.minX = 0;
- device_data.minY = 0;
- device_data.maxX = str.left(comma).toInt();
- device_data.maxY = str.mid(comma + 1).toInt();
- } else {
- device_data.minX = a[WAC_XCOORD_I].min_value;
- device_data.maxX = a[WAC_XCOORD_I].max_value;
- device_data.minY = a[WAC_YCOORD_I].min_value;
- device_data.maxY = a[WAC_YCOORD_I].max_value;
- }
- device_data.minPressure = a[WAC_PRESSURE_I].min_value;
- device_data.maxPressure = a[WAC_PRESSURE_I].max_value;
- device_data.minTanPressure = a[WAC_TAN_PRESSURE_I].min_value;
- device_data.maxTanPressure = a[WAC_TAN_PRESSURE_I].max_value;
- device_data.minZ = a[WAC_ZCOORD_I].min_value;
- device_data.maxZ = a[WAC_ZCOORD_I].max_value;
-#else
- device_data.minX = a[0].min_value;
- device_data.maxX = a[0].max_value;
- device_data.minY = a[1].min_value;
- device_data.maxY = a[1].max_value;
- device_data.minPressure = a[2].min_value;
- device_data.maxPressure = a[2].max_value;
- device_data.minTanPressure = 0;
- device_data.maxTanPressure = 0;
- device_data.minZ = 0;
- device_data.maxZ = 0;
-#endif
-
- // got the max pressure no need to go further...
- break;
- }
- any = (XAnyClassPtr) ((char *) any + any->length);
- } // end of for loop
-
- tablet_devices()->append(device_data);
- } // if (gotStylus || gotEraser)
- }
- if (X11->ptrXFreeDeviceList)
- X11->ptrXFreeDeviceList(devices);
- }
-#endif // QT_NO_TABLET
-
- X11->startupId = getenv("DESKTOP_STARTUP_ID");
- if (X11->startupId) {
-#ifndef QT_NO_UNSETENV
- unsetenv("DESKTOP_STARTUP_ID");
-#else
- // it's a small memory leak, however we won't crash if Qt is
- // unloaded and someones tries to use the envoriment.
- putenv(strdup("DESKTOP_STARTUP_ID="));
-#endif
- }
- } else {
- // read some non-GUI settings when not using the X server...
-
- if (QApplication::desktopSettingsAware()) {
- QSettings settings(QSettings::UserScope, QLatin1String("Trolltech"));
- settings.beginGroup(QLatin1String("Qt"));
-
- // read library (ie. plugin) path list
- QString libpathkey = QString::fromLatin1("%1.%2/libraryPath")
- .arg(QT_VERSION >> 16)
- .arg((QT_VERSION & 0xff00) >> 8);
- QStringList pathlist =
- settings.value(libpathkey).toString().split(QLatin1Char(':'));
- if (! pathlist.isEmpty()) {
- QStringList::ConstIterator it = pathlist.constBegin();
- while (it != pathlist.constEnd())
- QApplication::addLibraryPath(*it++);
- }
-
- QString defaultcodec = settings.value(QLatin1String("defaultCodec"),
- QVariant(QLatin1String("none"))).toString();
- if (defaultcodec != QLatin1String("none")) {
- QTextCodec *codec = QTextCodec::codecForName(defaultcodec.toLatin1());
- if (codec)
- QTextCodec::setCodecForTr(codec);
- }
-
- settings.endGroup(); // Qt
- }
- }
-
-#if !defined (Q_OS_IRIX) && !defined (QT_NO_TABLET)
- QLibrary wacom(QString::fromLatin1("wacomcfg"), 0); // version 0 is the latest release at time of writing this.
- // NOTE: C casts instead of reinterpret_cast for GCC 3.3.x
- ptrWacomConfigInit = (PtrWacomConfigInit)wacom.resolve("WacomConfigInit");
- ptrWacomConfigOpenDevice = (PtrWacomConfigOpenDevice)wacom.resolve("WacomConfigOpenDevice");
- ptrWacomConfigGetRawParam = (PtrWacomConfigGetRawParam)wacom.resolve("WacomConfigGetRawParam");
- ptrWacomConfigCloseDevice = (PtrWacomConfigCloseDevice)wacom.resolve("WacomConfigCloseDevice");
- ptrWacomConfigTerm = (PtrWacomConfigTerm)wacom.resolve("WacomConfigTerm");
-
- if (ptrWacomConfigInit == 0 || ptrWacomConfigOpenDevice == 0 || ptrWacomConfigGetRawParam == 0
- || ptrWacomConfigCloseDevice == 0 || ptrWacomConfigTerm == 0) { // either we have all, or we have none.
- ptrWacomConfigInit = 0;
- ptrWacomConfigOpenDevice = 0;
- ptrWacomConfigGetRawParam = 0;
- ptrWacomConfigCloseDevice = 0;
- ptrWacomConfigTerm = 0;
- }
-#endif
-}
-
-void QApplicationPrivate::initializeWidgetPaletteHash()
-{
-}
-
-/*****************************************************************************
- qt_cleanup() - cleans up when the application is finished
- *****************************************************************************/
-
-void qt_cleanup()
-{
- if (app_save_rootinfo) // root window must keep state
- qt_save_rootinfo();
-
- if (qt_is_gui_used) {
- QPixmapCache::clear();
- QCursorData::cleanup();
- QFont::cleanup();
- QColormap::cleanup();
-
-#if !defined (QT_NO_TABLET)
- QTabletDeviceDataList *devices = qt_tablet_devices();
- if (X11->ptrXCloseDevice)
- for (int i = 0; i < devices->size(); ++i)
- X11->ptrXCloseDevice(X11->display, (XDevice*)devices->at(i).device);
- devices->clear();
-#endif
- }
-
-#ifndef QT_NO_XRENDER
- for (int i = 0; i < X11->solid_fill_count; ++i) {
- if (X11->solid_fills[i].picture)
- XRenderFreePicture(X11->display, X11->solid_fills[i].picture);
- }
- for (int i = 0; i < X11->pattern_fill_count; ++i) {
- if (X11->pattern_fills[i].picture)
- XRenderFreePicture(X11->display, X11->pattern_fills[i].picture);
- }
-#endif
-
-#if !defined(QT_NO_IM)
- delete QApplicationPrivate::inputContext;
- QApplicationPrivate::inputContext = 0;
-#endif
-
- // Reset the error handlers
- if (qt_is_gui_used)
- XSync(X11->display, False); // sync first to process all possible errors
- XSetErrorHandler(original_x_errhandler);
- XSetIOErrorHandler(original_xio_errhandler);
-
- if (X11->argbColormaps) {
- for (int s = 0; s < X11->screenCount; s++) {
- if (X11->argbColormaps[s])
- XFreeColormap(X11->display, X11->argbColormaps[s]);
- }
- }
-
- if (qt_is_gui_used && !X11->foreignDisplay)
- XCloseDisplay(X11->display); // close X display
- X11->display = 0;
-
- delete [] X11->screens;
- delete [] X11->argbVisuals;
- delete [] X11->argbColormaps;
-
- if (X11->foreignDisplay) {
- delete [] (char *)appName;
- appName = 0;
- }
-
- delete [] (char *)appClass;
- appClass = 0;
-
- if (X11->net_supported_list)
- delete [] X11->net_supported_list;
- X11->net_supported_list = 0;
-
- if (X11->net_virtual_root_list)
- delete [] X11->net_virtual_root_list;
- X11->net_virtual_root_list = 0;
-
- delete X11;
- X11 = 0;
-}
-
-
-/*****************************************************************************
- Platform specific global and internal functions
- *****************************************************************************/
-
-void qt_save_rootinfo() // save new root info
-{
- Atom type;
- int format;
- unsigned long length, after;
- uchar *data = 0;
-
- if (ATOM(_XSETROOT_ID)) { // kill old pixmap
- if (XGetWindowProperty(X11->display, QX11Info::appRootWindow(),
- ATOM(_XSETROOT_ID), 0, 1,
- True, AnyPropertyType, &type, &format,
- &length, &after, &data) == Success) {
- if (type == XA_PIXMAP && format == 32 && length == 1 &&
- after == 0 && data) {
- XKillClient(X11->display, *((Pixmap*)data));
- }
- Pixmap dummy = XCreatePixmap(X11->display, QX11Info::appRootWindow(),
- 1, 1, 1);
- XChangeProperty(X11->display, QX11Info::appRootWindow(),
- ATOM(_XSETROOT_ID), XA_PIXMAP, 32,
- PropModeReplace, (uchar *)&dummy, 1);
- XSetCloseDownMode(X11->display, RetainPermanent);
- }
- }
- if (data)
- XFree((char *)data);
-}
-
-void qt_updated_rootinfo()
-{
- app_save_rootinfo = true;
-}
-
-// ### Cleanup, this function is not in use!
-bool qt_wstate_iconified(WId winid)
-{
- Atom type;
- int format;
- unsigned long length, after;
- uchar *data = 0;
- int r = XGetWindowProperty(X11->display, winid, ATOM(WM_STATE), 0, 2,
- False, AnyPropertyType, &type, &format,
- &length, &after, &data);
- bool iconic = false;
- if (r == Success && data && format == 32) {
- // quint32 *wstate = (quint32*)data;
- unsigned long *wstate = (unsigned long *) data;
- iconic = (*wstate == IconicState);
- XFree((char *)data);
- }
- return iconic;
-}
-
-QString QApplicationPrivate::appName() const
-{
- return QString::fromLocal8Bit(QT_PREPEND_NAMESPACE(appName));
-}
-
-const char *QX11Info::appClass() // get application class
-{
- return QT_PREPEND_NAMESPACE(appClass);
-}
-
-bool qt_nograb() // application no-grab option
-{
-#if defined(QT_DEBUG)
- return appNoGrab;
-#else
- return false;
-#endif
-}
-
-
-/*****************************************************************************
- Platform specific QApplication members
- *****************************************************************************/
-
-#ifdef QT3_SUPPORT
-void QApplication::setMainWidget(QWidget *mainWidget)
-{
-#ifndef QT_NO_DEBUG
- if (mainWidget && mainWidget->parentWidget() && mainWidget->isWindow())
- qWarning("QApplication::setMainWidget: New main widget (%s/%s) "
- "has a parent",
- mainWidget->metaObject()->className(), mainWidget->objectName().toLocal8Bit().constData());
-#endif
- if (mainWidget)
- mainWidget->d_func()->createWinId();
- QApplicationPrivate::main_widget = mainWidget;
- if (QApplicationPrivate::main_widget) // give WM command line
- QApplicationPrivate::applyX11SpecificCommandLineArguments(QApplicationPrivate::main_widget);
-}
-#endif
-
-void QApplicationPrivate::applyX11SpecificCommandLineArguments(QWidget *main_widget)
-{
- static bool beenHereDoneThat = false;
- if (beenHereDoneThat)
- return;
- beenHereDoneThat = true;
- Q_ASSERT(main_widget->testAttribute(Qt::WA_WState_Created));
- if (mwTitle) {
- XStoreName(X11->display, main_widget->effectiveWinId(), (char*)mwTitle);
- QByteArray net_wm_name = QString::fromLocal8Bit(mwTitle).toUtf8();
- XChangeProperty(X11->display, main_widget->effectiveWinId(), ATOM(_NET_WM_NAME), ATOM(UTF8_STRING), 8,
- PropModeReplace, (unsigned char *)net_wm_name.data(), net_wm_name.size());
- }
- if (mwGeometry) { // parse geometry
- int x, y;
- int w, h;
- int m = XParseGeometry((char*)mwGeometry, &x, &y, (uint*)&w, (uint*)&h);
- QSize minSize = main_widget->minimumSize();
- QSize maxSize = main_widget->maximumSize();
- if ((m & XValue) == 0)
- x = main_widget->geometry().x();
- if ((m & YValue) == 0)
- y = main_widget->geometry().y();
- if ((m & WidthValue) == 0)
- w = main_widget->width();
- if ((m & HeightValue) == 0)
- h = main_widget->height();
- w = qMin(w,maxSize.width());
- h = qMin(h,maxSize.height());
- w = qMax(w,minSize.width());
- h = qMax(h,minSize.height());
- if ((m & XNegative)) {
- x = QApplication::desktop()->width() + x - w;
- }
- if ((m & YNegative)) {
- y = QApplication::desktop()->height() + y - h;
- }
- main_widget->setGeometry(x, y, w, h);
- }
-}
-
-#ifndef QT_NO_CURSOR
-
-/*****************************************************************************
- QApplication cursor stack
- *****************************************************************************/
-
-void QApplication::setOverrideCursor(const QCursor &cursor)
-{
- qApp->d_func()->cursor_list.prepend(cursor);
-
- QWidgetList all = allWidgets();
- for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) {
- register QWidget *w = *it;
- if ((w->testAttribute(Qt::WA_SetCursor) || w->isWindow()) && (w->windowType() != Qt::Desktop))
- qt_x11_enforce_cursor(w);
- }
- XFlush(X11->display); // make X execute it NOW
-}
-
-void QApplication::restoreOverrideCursor()
-{
- if (qApp->d_func()->cursor_list.isEmpty())
- return;
- qApp->d_func()->cursor_list.removeFirst();
-
- if (QWidgetPrivate::mapper != 0 && !closingDown()) {
- QWidgetList all = allWidgets();
- for (QWidgetList::ConstIterator it = all.constBegin(); it != all.constEnd(); ++it) {
- register QWidget *w = *it;
- if ((w->testAttribute(Qt::WA_SetCursor) || w->isWindow()) && (w->windowType() != Qt::Desktop))
- qt_x11_enforce_cursor(w);
- }
- XFlush(X11->display);
- }
-}
-
-#endif
-
-
-/*****************************************************************************
- Routines to find a Qt widget from a screen position
- *****************************************************************************/
-
-Window QX11Data::findClientWindow(Window win, Atom property, bool leaf)
-{
- Atom type = XNone;
- int format, i;
- ulong nitems, after;
- uchar *data = 0;
- Window root, parent, target=0, *children=0;
- uint nchildren;
- if (XGetWindowProperty(X11->display, win, property, 0, 0, false, AnyPropertyType,
- &type, &format, &nitems, &after, &data) == Success) {
- if (data)
- XFree((char *)data);
- if (type)
- return win;
- }
- if (!XQueryTree(X11->display,win,&root,&parent,&children,&nchildren)) {
- if (children)
- XFree((char *)children);
- return 0;
- }
- for (i=nchildren-1; !target && i >= 0; i--)
- target = X11->findClientWindow(children[i], property, leaf);
- if (children)
- XFree((char *)children);
- return target;
-}
-
-QWidget *QApplication::topLevelAt(const QPoint &p)
-{
-#ifdef QT_NO_CURSOR
- Q_UNUSED(p);
- return 0;
-#else
- int screen = QCursor::x11Screen();
- int unused;
-
- int x = p.x();
- int y = p.y();
- Window target;
- if (!XTranslateCoordinates(X11->display,
- QX11Info::appRootWindow(screen),
- QX11Info::appRootWindow(screen),
- x, y, &unused, &unused, &target)) {
- return 0;
- }
- if (!target || target == QX11Info::appRootWindow(screen))
- return 0;
- QWidget *w;
- w = QWidget::find((WId)target);
-
- if (!w) {
- X11->ignoreBadwindow();
- target = X11->findClientWindow(target, ATOM(WM_STATE), true);
- if (X11->badwindow())
- return 0;
- w = QWidget::find((WId)target);
- if (!w) {
- // Perhaps the widget at (x,y) is inside a foreign application?
- // Search all toplevel widgets to see if one is within target
- QWidgetList list = QApplication::topLevelWidgets();
- for (int i = 0; i < list.count(); ++i) {
- QWidget *widget = list.at(i);
- Window ctarget = target;
- if (widget->isVisible() && !(widget->windowType() == Qt::Desktop)) {
- Q_ASSERT(widget->testAttribute(Qt::WA_WState_Created));
- Window wid = widget->internalWinId();
- while (ctarget && !w) {
- X11->ignoreBadwindow();
- if (!XTranslateCoordinates(X11->display,
- QX11Info::appRootWindow(screen),
- ctarget, x, y, &unused, &unused, &ctarget)
- || X11->badwindow())
- break;
- if (ctarget == wid) {
- // Found!
- w = widget;
- break;
- }
- }
- }
- if (w)
- break;
- }
- }
- }
- return w ? w->window() : 0;
-#endif
-}
-
-void QApplication::syncX()
-{
- if (X11->display)
- XSync(X11->display, False); // don't discard events
-}
-
-
-void QApplication::beep()
-{
- if (X11->display)
- XBell(X11->display, 0);
- else
- printf("\7");
-}
-
-void QApplication::alert(QWidget *widget, int msec)
-{
- if (!QApplicationPrivate::checkInstance("alert"))
- return;
-
- QWidgetList windowsToMark;
- if (!widget) {
- windowsToMark += topLevelWidgets();
- } else {
- windowsToMark.append(widget->window());
- }
-
- for (int i = 0; i < windowsToMark.size(); ++i) {
- QWidget *window = windowsToMark.at(i);
- if (!window->isActiveWindow()) {
- qt_change_net_wm_state(window, true, ATOM(_NET_WM_STATE_DEMANDS_ATTENTION));
- if (msec != 0) {
- QTimer *timer = new QTimer(qApp);
- timer->setSingleShot(true);
- connect(timer, SIGNAL(timeout()), qApp, SLOT(_q_alertTimeOut()));
- if (QTimer *oldTimer = qApp->d_func()->alertTimerHash.value(window)) {
- qApp->d_func()->alertTimerHash.remove(window);
- delete oldTimer;
- }
- qApp->d_func()->alertTimerHash.insert(window, timer);
- timer->start(msec);
- }
- }
- }
-}
-
-void QApplicationPrivate::_q_alertTimeOut()
-{
- if (QTimer *timer = qobject_cast<QTimer *>(q_func()->sender())) {
- QHash<QWidget *, QTimer *>::iterator it = alertTimerHash.begin();
- while (it != alertTimerHash.end()) {
- if (it.value() == timer) {
- QWidget *window = it.key();
- qt_change_net_wm_state(window, false, ATOM(_NET_WM_STATE_DEMANDS_ATTENTION));
- alertTimerHash.erase(it);
- timer->deleteLater();
- break;
- }
- ++it;
- }
- }
-}
-
-/*****************************************************************************
- Special lookup functions for windows that have been reparented recently
- *****************************************************************************/
-
-static QWidgetMapper *wPRmapper = 0; // alternative widget mapper
-
-void qPRCreate(const QWidget *widget, Window oldwin)
-{ // QWidget::reparent mechanism
- if (!wPRmapper)
- wPRmapper = new QWidgetMapper;
-
- QETWidget *w = static_cast<QETWidget *>(const_cast<QWidget *>(widget));
- wPRmapper->insert((int)oldwin, w); // add old window to mapper
- w->setAttribute(Qt::WA_WState_Reparented); // set reparented flag
-}
-
-void qPRCleanup(QWidget *widget)
-{
- QETWidget *etw = static_cast<QETWidget *>(const_cast<QWidget *>(widget));
- if (!(wPRmapper && widget->testAttribute(Qt::WA_WState_Reparented)))
- return; // not a reparented widget
- QWidgetMapper::Iterator it = wPRmapper->begin();
- while (it != wPRmapper->constEnd()) {
- QWidget *w = *it;
- if (w == etw) { // found widget
- etw->setAttribute(Qt::WA_WState_Reparented, false); // clear flag
- it = wPRmapper->erase(it);// old window no longer needed
- } else {
- ++it;
- }
- }
- if (wPRmapper->size() == 0) { // became empty
- delete wPRmapper; // then reset alt mapper
- wPRmapper = 0;
- }
-}
-
-static QETWidget *qPRFindWidget(Window oldwin)
-{
- return wPRmapper ? (QETWidget*)wPRmapper->value((int)oldwin, 0) : 0;
-}
-
-int QApplication::x11ClientMessage(QWidget* w, XEvent* event, bool passive_only)
-{
- if (w && !w->internalWinId())
- return 0;
- QETWidget *widget = (QETWidget*)w;
- if (event->xclient.format == 32 && event->xclient.message_type) {
- if (event->xclient.message_type == ATOM(WM_PROTOCOLS)) {
- Atom a = event->xclient.data.l[0];
- if (a == ATOM(WM_DELETE_WINDOW)) {
- if (passive_only) return 0;
- widget->translateCloseEvent(event);
- }
- else if (a == ATOM(WM_TAKE_FOCUS)) {
- if ((ulong) event->xclient.data.l[1] > X11->time)
- X11->time = event->xclient.data.l[1];
- QWidget *amw = activeModalWidget();
- if (amw && amw->testAttribute(Qt::WA_X11DoNotAcceptFocus))
- amw = 0;
- if (amw && !QApplicationPrivate::tryModalHelper(widget, 0)) {
- QWidget *p = amw->parentWidget();
- while (p && p != widget)
- p = p->parentWidget();
- if (!p || !X11->net_supported_list)
- amw->raise(); // help broken window managers
- amw->activateWindow();
- }
-#ifndef QT_NO_WHATSTHIS
- } else if (a == ATOM(_NET_WM_CONTEXT_HELP)) {
- QWhatsThis::enterWhatsThisMode();
-#endif // QT_NO_WHATSTHIS
- } else if (a == ATOM(_NET_WM_PING)) {
- // avoid send/reply loops
- Window root = RootWindow(X11->display, w->x11Info().screen());
- if (event->xclient.window != root) {
- event->xclient.window = root;
- XSendEvent(event->xclient.display, event->xclient.window,
- False, SubstructureNotifyMask|SubstructureRedirectMask, event);
- }
-#ifndef QT_NO_XSYNC
- } else if (a == ATOM(_NET_WM_SYNC_REQUEST)) {
- const ulong timestamp = (const ulong) event->xclient.data.l[1];
- if (timestamp > X11->time)
- X11->time = timestamp;
- if (QTLWExtra *tlw = w->d_func()->maybeTopData()) {
- if (timestamp == CurrentTime || timestamp > tlw->syncRequestTimestamp) {
- tlw->syncRequestTimestamp = timestamp;
- tlw->newCounterValueLo = event->xclient.data.l[2];
- tlw->newCounterValueHi = event->xclient.data.l[3];
- }
- }
-#endif
- }
- } else if (event->xclient.message_type == ATOM(_QT_SCROLL_DONE)) {
- widget->translateScrollDoneEvent(event);
- } else if (event->xclient.message_type == ATOM(XdndPosition)) {
- X11->xdndHandlePosition(widget, event, passive_only);
- } else if (event->xclient.message_type == ATOM(XdndEnter)) {
- X11->xdndHandleEnter(widget, event, passive_only);
- } else if (event->xclient.message_type == ATOM(XdndStatus)) {
- X11->xdndHandleStatus(widget, event, passive_only);
- } else if (event->xclient.message_type == ATOM(XdndLeave)) {
- X11->xdndHandleLeave(widget, event, passive_only);
- } else if (event->xclient.message_type == ATOM(XdndDrop)) {
- X11->xdndHandleDrop(widget, event, passive_only);
- } else if (event->xclient.message_type == ATOM(XdndFinished)) {
- X11->xdndHandleFinished(widget, event, passive_only);
- } else {
- if (passive_only) return 0;
- // All other are interactions
- }
- } else {
- X11->motifdndHandle(widget, event, passive_only);
- }
-
- return 0;
-}
-
-int QApplication::x11ProcessEvent(XEvent* event)
-{
- Q_D(QApplication);
- QScopedLoopLevelCounter loopLevelCounter(d->threadData);
-
-#ifdef ALIEN_DEBUG
- //qDebug() << "QApplication::x11ProcessEvent:" << event->type;
-#endif
- switch (event->type) {
- case ButtonPress:
- pressed_window = event->xbutton.window;
- X11->userTime = event->xbutton.time;
- // fallthrough intended
- case ButtonRelease:
- X11->time = event->xbutton.time;
- break;
- case MotionNotify:
- X11->time = event->xmotion.time;
- break;
- case XKeyPress:
- X11->userTime = event->xkey.time;
- // fallthrough intended
- case XKeyRelease:
- X11->time = event->xkey.time;
- break;
- case PropertyNotify:
- X11->time = event->xproperty.time;
- break;
- case EnterNotify:
- case LeaveNotify:
- X11->time = event->xcrossing.time;
- break;
- case SelectionClear:
- X11->time = 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);
- X11->time = req->selection_timestamp;
- if (req->selection == ATOM(_NET_WM_CM_S0))
- X11->compositingManagerRunning = req->owner;
- }
-#endif
-
- QETWidget *widget = (QETWidget*)QWidget::find((WId)event->xany.window);
-
- if (wPRmapper) { // just did a widget reparent?
- if (widget == 0) { // not in std widget mapper
- switch (event->type) { // only for mouse/key events
- case ButtonPress:
- case ButtonRelease:
- case MotionNotify:
- case XKeyPress:
- case XKeyRelease:
- widget = qPRFindWidget(event->xany.window);
- break;
- }
- }
- else if (widget->testAttribute(Qt::WA_WState_Reparented))
- qPRCleanup(widget); // remove from alt mapper
- }
-
- QETWidget *keywidget=0;
- bool grabbed=false;
- if (event->type==XKeyPress || event->type==XKeyRelease) {
- keywidget = (QETWidget*)QWidget::keyboardGrabber();
- if (keywidget) {
- grabbed = true;
- } else if (!keywidget) {
- if (d->inPopupMode()) // no focus widget, see if we have a popup
- keywidget = (QETWidget*) (activePopupWidget()->focusWidget() ? activePopupWidget()->focusWidget() : activePopupWidget());
- else if (QApplicationPrivate::focus_widget)
- keywidget = (QETWidget*)QApplicationPrivate::focus_widget;
- else if (widget)
- keywidget = (QETWidget*)widget->window();
- }
- }
-
-#ifndef QT_NO_IM
- // Filtering input events by the input context. It has to be taken
- // place before any other key event consumers such as eventfilters
- // and accelerators because some input methods require quite
- // various key combination and sequences. It often conflicts with
- // accelerators and so on, so we must give the input context the
- // filtering opportunity first to ensure all input methods work
- // properly regardless of application design.
-
- if(keywidget && keywidget->isEnabled() && keywidget->testAttribute(Qt::WA_InputMethodEnabled)) {
- // block user interaction during session management
- if((event->type==XKeyPress || event->type==XKeyRelease) && qt_sm_blockUserInput)
- return true;
-
- // for XIM handling
- QInputContext *qic = keywidget->inputContext();
- if(qic && qic->x11FilterEvent(keywidget, event))
- return true;
-
- // filterEvent() accepts QEvent *event rather than preexpanded
- // key event attribute values. This is intended to pass other
- // QInputEvent in future. Other non IM-related events should
- // not be forwarded to input contexts to prevent weird event
- // handling.
- if ((event->type == XKeyPress || event->type == XKeyRelease)) {
- int code = -1;
- int count = 0;
- Qt::KeyboardModifiers modifiers;
- QEvent::Type type;
- QString text;
- KeySym keySym;
-
- qt_keymapper_private()->translateKeyEventInternal(keywidget, event, keySym, count,
- text, modifiers, code, type, false);
-
- // both key press/release is required for some complex
- // input methods. don't eliminate anything.
- QKeyEventEx keyevent(type, code, modifiers, text, false, qMax(qMax(count, 1), text.length()),
- event->xkey.keycode, keySym, event->xkey.state);
- if(qic && qic->filterEvent(&keyevent))
- return true;
- }
- } else
-#endif // QT_NO_IM
- {
- if (XFilterEvent(event, XNone))
- return true;
- }
-
- if (qt_x11EventFilter(event)) // send through app filter
- return 1;
-
- if (event->type == MappingNotify) {
- // keyboard mapping changed
- XRefreshKeyboardMapping(&event->xmapping);
-
- QKeyMapper::changeKeyboard();
- return 0;
- }
-#ifndef QT_NO_XKB
- else if (X11->use_xkb && event->type == X11->xkb_eventbase) {
- XkbAnyEvent *xkbevent = (XkbAnyEvent *) event;
- switch (xkbevent->xkb_type) {
- case XkbStateNotify:
- {
- XkbStateNotifyEvent *xkbstateevent = (XkbStateNotifyEvent *) xkbevent;
- if ((xkbstateevent->changed & XkbGroupStateMask) != 0) {
- qt_keymapper_private()->xkb_currentGroup = xkbstateevent->group;
- QKeyMapper::changeKeyboard();
- }
- break;
- }
- default:
- break;
- }
- }
-#endif
-
- if (!widget) { // don't know this windows
- QWidget* popup = QApplication::activePopupWidget();
- if (popup) {
-
- /*
- That is more than suboptimal. The real solution should
- do some keyevent and buttonevent translation, so that
- the popup still continues to work as the user expects.
- Unfortunately this translation is currently only
- possible with a known widget. I'll change that soon
- (Matthias).
- */
-
- // Danger - make sure we don't lock the server
- switch (event->type) {
- case ButtonPress:
- case ButtonRelease:
- case XKeyPress:
- case XKeyRelease:
- do {
- popup->close();
- } while ((popup = qApp->activePopupWidget()));
- return 1;
- }
- }
- return -1;
- }
-
- if (event->type == XKeyPress || event->type == XKeyRelease)
- widget = keywidget; // send XKeyEvents through keywidget->x11Event()
-
- if (app_do_modal) // modal event handling
- if (!qt_try_modal(widget, event)) {
- if (event->type == ClientMessage && !widget->x11Event(event))
- x11ClientMessage(widget, event, true);
- return 1;
- }
-
-
- if (widget->x11Event(event)) // send through widget filter
- return 1;
-#if !defined (QT_NO_TABLET)
- if (!qt_xdnd_dragging) {
- QTabletDeviceDataList *tablets = qt_tablet_devices();
- for (int i = 0; i < tablets->size(); ++i) {
- QTabletDeviceData &tab = tablets->operator [](i);
- if (event->type == tab.xinput_motion
- || event->type == tab.xinput_button_release
- || event->type == tab.xinput_button_press
- || event->type == tab.xinput_proximity_in
- || event->type == tab.xinput_proximity_out) {
- widget->translateXinputEvent(event, &tab);
- return 0;
- }
- }
- }
-#endif
-
-#ifndef QT_NO_XRANDR
- if (X11->use_xrandr && event->type == (X11->xrandr_eventbase + RRScreenChangeNotify)) {
- // update Xlib internals with the latest screen configuration
- X11->ptrXRRUpdateConfiguration(event);
-
- // update the size for desktop widget
- int scr = X11->ptrXRRRootToScreen(X11->display, event->xany.window);
- QDesktopWidget *desktop = QApplication::desktop();
- QWidget *w = desktop->screen(scr);
- QSize oldSize(w->size());
- w->data->crect.setWidth(DisplayWidth(X11->display, scr));
- w->data->crect.setHeight(DisplayHeight(X11->display, scr));
- QResizeEvent e(w->size(), oldSize);
- QApplication::sendEvent(w, &e);
- if (w != desktop)
- QApplication::sendEvent(desktop, &e);
- }
-#endif // QT_NO_XRANDR
-
-#ifndef QT_NO_XFIXES
- if (X11->use_xfixes && event->type == (X11->xfixes_eventbase + XFixesSelectionNotify)) {
- XFixesSelectionNotifyEvent *req = reinterpret_cast<XFixesSelectionNotifyEvent *>(event);
-
- // compress all XFixes events related to this selection
- // we don't want to handle old SelectionNotify events.
- qt_xfixes_selection_event_data xfixes_event;
- xfixes_event.selection = req->selection;
- for (XEvent ev;;) {
- if (!XCheckIfEvent(X11->display, &ev, &qt_xfixes_scanner, (XPointer)&xfixes_event))
- break;
- }
-
- if (req->selection == ATOM(CLIPBOARD)) {
- if (qt_xfixes_clipboard_changed(req->owner, req->selection_timestamp)) {
- emit clipboard()->changed(QClipboard::Clipboard);
- emit clipboard()->dataChanged();
- }
- } else if (req->selection == XA_PRIMARY) {
- if (qt_xfixes_selection_changed(req->owner, req->selection_timestamp)) {
- emit clipboard()->changed(QClipboard::Selection);
- emit clipboard()->selectionChanged();
- }
- }
- }
-#endif // QT_NO_XFIXES
-
- switch (event->type) {
-
- case ButtonRelease: // mouse event
- if (!d->inPopupMode() && !QWidget::mouseGrabber() && pressed_window != widget->internalWinId()
- && (widget = (QETWidget*) QWidget::find((WId)pressed_window)) == 0)
- break;
- // fall through intended
- case ButtonPress:
- if (event->xbutton.root != RootWindow(X11->display, widget->x11Info().screen())
- && ! qt_xdnd_dragging) {
- while (activePopupWidget())
- activePopupWidget()->close();
- return 1;
- }
- if (event->type == ButtonPress)
- qt_net_update_user_time(widget->window(), X11->userTime);
- // fall through intended
- case MotionNotify:
-#if !defined(QT_NO_TABLET)
- if (!qt_tabletChokeMouse) {
-#endif
- if (widget->testAttribute(Qt::WA_TransparentForMouseEvents)) {
- QPoint pos(event->xbutton.x, event->xbutton.y);
- pos = widget->d_func()->mapFromWS(pos);
- QWidget *window = widget->window();
- pos = widget->mapTo(window, pos);
- if (QWidget *child = window->childAt(pos)) {
- widget = static_cast<QETWidget *>(child);
- pos = child->mapFrom(window, pos);
- event->xbutton.x = pos.x();
- event->xbutton.y = pos.y();
- }
- }
- widget->translateMouseEvent(event);
-#if !defined(QT_NO_TABLET)
- } else {
- qt_tabletChokeMouse = false;
- }
-#endif
- break;
-
- case XKeyPress: // keyboard event
- qt_net_update_user_time(widget->window(), X11->userTime);
- // fallthrough intended
- case XKeyRelease:
- {
- if (keywidget && keywidget->isEnabled()) { // should always exist
- // qDebug("sending key event");
- qt_keymapper_private()->translateKeyEvent(keywidget, event, grabbed);
- }
- break;
- }
-
- case GraphicsExpose:
- case Expose: // paint event
- widget->translatePaintEvent(event);
- break;
-
- case ConfigureNotify: // window move/resize event
- if (event->xconfigure.event == event->xconfigure.window)
- widget->translateConfigEvent(event);
- break;
-
- case XFocusIn: { // got focus
- if ((widget->windowType() == Qt::Desktop))
- break;
- if (d->inPopupMode()) // some delayed focus event to ignore
- break;
- if (!widget->isWindow())
- break;
- if (event->xfocus.detail != NotifyAncestor &&
- event->xfocus.detail != NotifyInferior &&
- event->xfocus.detail != NotifyNonlinear)
- break;
- setActiveWindow(widget);
- if (X11->focus_model == QX11Data::FM_PointerRoot) {
- // We got real input focus from somewhere, but we were in PointerRoot
- // mode, so we don't trust this event. Check the focus model to make
- // sure we know what focus mode we are using...
- qt_check_focus_model();
- }
- }
- break;
-
- case XFocusOut: // lost focus
- if ((widget->windowType() == Qt::Desktop))
- break;
- if (!widget->isWindow())
- break;
- if (event->xfocus.mode == NotifyGrab) {
- qt_xfocusout_grab_counter++;
- break;
- }
- if (event->xfocus.detail != NotifyAncestor &&
- event->xfocus.detail != NotifyNonlinearVirtual &&
- event->xfocus.detail != NotifyNonlinear)
- break;
- if (!d->inPopupMode() && widget == QApplicationPrivate::active_window) {
- XEvent ev;
- bool focus_will_change = false;
- if (XCheckTypedEvent(X11->display, XFocusIn, &ev)) {
- // we're about to get an XFocusIn, if we know we will
- // get a new active window, we don't want to set the
- // active window to 0 now
- QWidget *w2 = QWidget::find(ev.xany.window);
- if (w2
- && w2->windowType() != Qt::Desktop
- && !d->inPopupMode() // some delayed focus event to ignore
- && w2->isWindow()
- && (ev.xfocus.detail == NotifyAncestor
- || ev.xfocus.detail == NotifyInferior
- || ev.xfocus.detail == NotifyNonlinear))
- focus_will_change = true;
-
- XPutBackEvent(X11->display, &ev);
- }
- if (!focus_will_change)
- setActiveWindow(0);
- }
- break;
-
- case EnterNotify: { // enter window
- if (QWidget::mouseGrabber() && (!d->inPopupMode() || widget->window() != activePopupWidget()))
- break;
- if ((event->xcrossing.mode != NotifyNormal
- && event->xcrossing.mode != NotifyUngrab)
- || event->xcrossing.detail == NotifyVirtual
- || event->xcrossing.detail == NotifyNonlinearVirtual)
- break;
- if (event->xcrossing.focus &&
- !(widget->windowType() == Qt::Desktop) && !widget->isActiveWindow()) {
- if (X11->focus_model == QX11Data::FM_Unknown) // check focus model
- qt_check_focus_model();
- if (X11->focus_model == QX11Data::FM_PointerRoot) // PointerRoot mode
- setActiveWindow(widget);
- }
-
- if (qt_button_down && !d->inPopupMode())
- break;
-
- QWidget *alien = widget->childAt(widget->d_func()->mapFromWS(QPoint(event->xcrossing.x,
- event->xcrossing.y)));
- QWidget *enter = alien ? alien : widget;
- QWidget *leave = 0;
- if (qt_last_mouse_receiver && !qt_last_mouse_receiver->internalWinId())
- leave = qt_last_mouse_receiver;
- else
- leave = QWidget::find(curWin);
-
- // ### Alien: enter/leave might be wrong here with overlapping siblings
- // if the enter widget is native and stacked under a non-native widget.
- QApplicationPrivate::dispatchEnterLeave(enter, leave);
- curWin = widget->internalWinId();
- qt_last_mouse_receiver = enter;
- if (!d->inPopupMode() || widget->window() == activePopupWidget())
- widget->translateMouseEvent(event); //we don't get MotionNotify, emulate it
- }
- break;
- case LeaveNotify: { // leave window
- QWidget *mouseGrabber = QWidget::mouseGrabber();
- if (mouseGrabber && !d->inPopupMode())
- break;
- if (curWin && widget->internalWinId() != curWin)
- break;
- if ((event->xcrossing.mode != NotifyNormal
- && event->xcrossing.mode != NotifyUngrab)
- || event->xcrossing.detail == NotifyInferior)
- break;
- if (!(widget->windowType() == Qt::Desktop))
- widget->translateMouseEvent(event); //we don't get MotionNotify, emulate it
-
- QWidget* enter = 0;
- QPoint enterPoint;
- XEvent ev;
- while (XCheckMaskEvent(X11->display, EnterWindowMask | LeaveWindowMask , &ev)
- && !qt_x11EventFilter(&ev)) {
- QWidget* event_widget = QWidget::find(ev.xcrossing.window);
- if(event_widget && event_widget->x11Event(&ev))
- break;
- if (ev.type == LeaveNotify
- || (ev.xcrossing.mode != NotifyNormal
- && ev.xcrossing.mode != NotifyUngrab)
- || ev.xcrossing.detail == NotifyVirtual
- || ev.xcrossing.detail == NotifyNonlinearVirtual)
- continue;
- enter = event_widget;
- if (enter)
- enterPoint = enter->d_func()->mapFromWS(QPoint(ev.xcrossing.x, ev.xcrossing.y));
- if (ev.xcrossing.focus &&
- enter && !(enter->windowType() == Qt::Desktop) && !enter->isActiveWindow()) {
- if (X11->focus_model == QX11Data::FM_Unknown) // check focus model
- qt_check_focus_model();
- if (X11->focus_model == QX11Data::FM_PointerRoot) // PointerRoot mode
- setActiveWindow(enter);
- }
- break;
- }
-
- if ((! enter || (enter->windowType() == Qt::Desktop)) &&
- event->xcrossing.focus && widget == QApplicationPrivate::active_window &&
- X11->focus_model == QX11Data::FM_PointerRoot // PointerRoot mode
- ) {
- setActiveWindow(0);
- }
-
- if (qt_button_down && !d->inPopupMode())
- break;
-
- if (!curWin)
- QApplicationPrivate::dispatchEnterLeave(widget, 0);
-
- if (enter) {
- QWidget *alienEnter = enter->childAt(enterPoint);
- if (alienEnter)
- enter = alienEnter;
- }
-
- QWidget *leave = qt_last_mouse_receiver ? qt_last_mouse_receiver : widget;
- QWidget *activePopupWidget = qApp->activePopupWidget();
-
- if (mouseGrabber && activePopupWidget && leave == activePopupWidget)
- enter = mouseGrabber;
- else if (enter != widget && mouseGrabber) {
- if (!widget->rect().contains(widget->d_func()->mapFromWS(QPoint(event->xcrossing.x,
- event->xcrossing.y))))
- break;
- }
-
- QApplicationPrivate::dispatchEnterLeave(enter, leave);
- qt_last_mouse_receiver = enter;
-
- if (enter && QApplicationPrivate::tryModalHelper(enter, 0)) {
- QWidget *nativeEnter = enter->internalWinId() ? enter : enter->nativeParentWidget();
- curWin = nativeEnter->internalWinId();
- static_cast<QETWidget *>(nativeEnter)->translateMouseEvent(&ev); //we don't get MotionNotify, emulate it
- } else {
- curWin = 0;
- qt_last_mouse_receiver = 0;
- }
- }
- break;
-
- case UnmapNotify: // window hidden
- if (widget->isWindow()) {
- Q_ASSERT(widget->testAttribute(Qt::WA_WState_Created));
- widget->d_func()->topData()->waitingForMapNotify = 0;
-
- if (widget->windowType() != Qt::Popup && !widget->testAttribute(Qt::WA_DontShowOnScreen)) {
- widget->setAttribute(Qt::WA_Mapped, false);
- if (widget->isVisible()) {
- widget->d_func()->topData()->spont_unmapped = 1;
- QHideEvent e;
- QApplication::sendSpontaneousEvent(widget, &e);
- widget->d_func()->hideChildren(true);
- }
- }
-
- if (!widget->d_func()->topData()->validWMState && X11->deferred_map.removeAll(widget))
- widget->doDeferredMap();
- }
- break;
-
- case MapNotify: // window shown
- if (widget->isWindow()) {
- // if we got a MapNotify when we were not waiting for it, it most
- // likely means the user has already asked to hide the window before
- // it ever being shown, so we try to withdraw a window after sending
- // the QShowEvent.
- bool pendingHide = widget->testAttribute(Qt::WA_WState_ExplicitShowHide) && widget->testAttribute(Qt::WA_WState_Hidden);
- widget->d_func()->topData()->waitingForMapNotify = 0;
-
- if (widget->windowType() != Qt::Popup) {
- widget->setAttribute(Qt::WA_Mapped);
- if (widget->d_func()->topData()->spont_unmapped) {
- widget->d_func()->topData()->spont_unmapped = 0;
- widget->d_func()->showChildren(true);
- QShowEvent e;
- QApplication::sendSpontaneousEvent(widget, &e);
-
- // show() must have been called on this widget in
- // order to reach this point, but we could have
- // cleared these 2 attributes in case something
- // previously forced us into WithdrawnState
- // (e.g. kdocker)
- widget->setAttribute(Qt::WA_WState_ExplicitShowHide, true);
- widget->setAttribute(Qt::WA_WState_Visible, true);
- }
- }
- if (pendingHide) // hide the window
- XWithdrawWindow(X11->display, widget->internalWinId(), widget->x11Info().screen());
- }
- break;
-
- case ClientMessage: // client message
- return x11ClientMessage(widget,event,False);
-
- case ReparentNotify: { // window manager reparents
- // compress old reparent events to self
- XEvent ev;
- while (XCheckTypedWindowEvent(X11->display,
- widget->effectiveWinId(),
- ReparentNotify,
- &ev)) {
- if (ev.xreparent.window != ev.xreparent.event) {
- XPutBackEvent(X11->display, &ev);
- break;
- }
- }
- if (widget->isWindow()) {
- QTLWExtra *topData = widget->d_func()->topData();
-
- // store the parent. Useful for many things, embedding for instance.
- topData->parentWinId = event->xreparent.parent;
-
- // the widget frame strut should also be invalidated
- widget->data->fstrut_dirty = 1;
-
- // work around broken window managers... if we get a
- // ReparentNotify before the MapNotify, we assume that
- // we're being managed by a reparenting window
- // manager.
- //
- // however, the WM_STATE property may not have been set
- // yet, but we are going to assume that it will
- // be... otherwise we could try to map again after getting
- // an UnmapNotify... which could then, in turn, trigger a
- // race in the window manager which causes the window to
- // disappear when it really should be hidden.
- if (topData->waitingForMapNotify && !topData->validWMState) {
- topData->waitingForMapNotify = 0;
- topData->validWMState = 1;
- }
-
- if (X11->focus_model != QX11Data::FM_Unknown) {
- // toplevel reparented...
- QWidget *newparent = QWidget::find(event->xreparent.parent);
- if (! newparent || (newparent->windowType() == Qt::Desktop)) {
- // we don't know about the new parent (or we've been
- // reparented to root), perhaps a window manager
- // has been (re)started? reset the focus model to unknown
- X11->focus_model = QX11Data::FM_Unknown;
- }
- }
- }
- break;
- }
- case SelectionRequest: {
- XSelectionRequestEvent *req = &event->xselectionrequest;
- if (! req)
- break;
-
- if (ATOM(XdndSelection) && req->selection == ATOM(XdndSelection)) {
- X11->xdndHandleSelectionRequest(req);
-
- } else if (qt_clipboard) {
- QClipboardEvent e(reinterpret_cast<QEventPrivate*>(event));
- QApplication::sendSpontaneousEvent(qt_clipboard, &e);
- }
- break;
- }
- case SelectionClear: {
- XSelectionClearEvent *req = &event->xselectionclear;
- // don't deliver dnd events to the clipboard, it gets confused
- if (! req || (ATOM(XdndSelection) && req->selection == ATOM(XdndSelection)))
- break;
-
- if (qt_clipboard && !X11->use_xfixes) {
- QClipboardEvent e(reinterpret_cast<QEventPrivate*>(event));
- QApplication::sendSpontaneousEvent(qt_clipboard, &e);
- }
- break;
- }
-
- case SelectionNotify: {
- XSelectionEvent *req = &event->xselection;
- // don't deliver dnd events to the clipboard, it gets confused
- if (! req || (ATOM(XdndSelection) && req->selection == ATOM(XdndSelection)))
- break;
-
- if (qt_clipboard) {
- QClipboardEvent e(reinterpret_cast<QEventPrivate*>(event));
- QApplication::sendSpontaneousEvent(qt_clipboard, &e);
- }
- break;
- }
- case PropertyNotify:
- // some properties changed
- if (event->xproperty.window == QX11Info::appRootWindow(0)) {
- // root properties for the first screen
- if (!X11->use_xfixes && event->xproperty.atom == ATOM(_QT_CLIPBOARD_SENTINEL)) {
- if (qt_check_clipboard_sentinel()) {
- emit clipboard()->changed(QClipboard::Clipboard);
- emit clipboard()->dataChanged();
- }
- } else if (!X11->use_xfixes && event->xproperty.atom == ATOM(_QT_SELECTION_SENTINEL)) {
- if (qt_check_selection_sentinel()) {
- emit clipboard()->changed(QClipboard::Selection);
- emit clipboard()->selectionChanged();
- }
- } else if (QApplicationPrivate::obey_desktop_settings) {
- if (event->xproperty.atom == ATOM(RESOURCE_MANAGER))
- qt_set_x11_resources();
- else if (event->xproperty.atom == ATOM(_QT_SETTINGS_TIMESTAMP))
- qt_set_x11_resources();
- }
- }
- if (event->xproperty.window == QX11Info::appRootWindow()) {
- // root properties for the default screen
- if (event->xproperty.atom == ATOM(_QT_INPUT_ENCODING)) {
- qt_set_input_encoding();
- } else if (event->xproperty.atom == ATOM(_NET_SUPPORTED)) {
- qt_get_net_supported();
- } else if (event->xproperty.atom == ATOM(_NET_VIRTUAL_ROOTS)) {
- qt_get_net_virtual_roots();
- } else if (event->xproperty.atom == ATOM(_NET_WORKAREA)) {
- qt_desktopwidget_update_workarea();
-
- // emit the workAreaResized() signal
- QDesktopWidget *desktop = QApplication::desktop();
- int numScreens = desktop->numScreens();
- for (int i = 0; i < numScreens; ++i)
- emit desktop->workAreaResized(i);
- }
- } else if (widget) {
- widget->translatePropertyEvent(event);
- } else {
- return -1; // don't know this window
- }
- break;
-
- default:
- break;
- }
-
- return 0;
-}
-
-bool QApplication::x11EventFilter(XEvent *)
-{
- return false;
-}
-
-
-
-/*****************************************************************************
- Modal widgets; Since Xlib has little support for this we roll our own
- modal widget mechanism.
- A modal widget without a parent becomes application-modal.
- A modal widget with a parent becomes modal to its parent and grandparents..
-
- QApplicationPrivate::enterModal()
- Enters modal state
- Arguments:
- QWidget *widget A modal widget
-
- QApplicationPrivate::leaveModal()
- Leaves modal state for a widget
- Arguments:
- QWidget *widget A modal widget
- *****************************************************************************/
-
-bool QApplicationPrivate::modalState()
-{
- return app_do_modal;
-}
-
-void QApplicationPrivate::enterModal_sys(QWidget *widget)
-{
- if (!qt_modal_stack)
- qt_modal_stack = new QWidgetList;
-
- QWidget *leave = qt_last_mouse_receiver;
- if (!leave)
- leave = QWidget::find((WId)curWin);
- QApplicationPrivate::dispatchEnterLeave(0, leave);
- qt_modal_stack->insert(0, widget);
- app_do_modal = true;
- curWin = 0;
- qt_last_mouse_receiver = 0;
-}
-
-void QApplicationPrivate::leaveModal_sys(QWidget *widget)
-{
- if (qt_modal_stack && qt_modal_stack->removeAll(widget)) {
- if (qt_modal_stack->isEmpty()) {
- delete qt_modal_stack;
- qt_modal_stack = 0;
- QPoint p(QCursor::pos());
- QWidget* w = QApplication::widgetAt(p.x(), p.y());
- QWidget *leave = qt_last_mouse_receiver;
- if (!leave)
- leave = QWidget::find((WId)curWin);
- if (QWidget *grabber = QWidget::mouseGrabber()) {
- w = grabber;
- if (leave == w)
- leave = 0;
- }
- QApplicationPrivate::dispatchEnterLeave(w, leave); // send synthetic enter event
- curWin = w ? w->effectiveWinId() : 0;
- qt_last_mouse_receiver = w;
- }
- }
- app_do_modal = qt_modal_stack != 0;
-}
-
-bool qt_try_modal(QWidget *widget, XEvent *event)
-{
- if (qt_xdnd_dragging) {
- // allow mouse events while DnD is active
- switch (event->type) {
- case ButtonPress:
- case ButtonRelease:
- case MotionNotify:
- return true;
- default:
- break;
- }
- }
-
- // allow mouse release events to be sent to widgets that have been pressed
- if (event->type == ButtonRelease) {
- QWidget *alienWidget = widget->childAt(widget->mapFromGlobal(QPoint(event->xbutton.x_root,
- event->xbutton.y_root)));
- if (widget == qt_button_down || (alienWidget && alienWidget == qt_button_down))
- return true;
- }
-
- if (QApplicationPrivate::tryModalHelper(widget))
- return true;
-
- // disallow mouse/key events
- switch (event->type) {
- case ButtonPress:
- case ButtonRelease:
- case MotionNotify:
- case XKeyPress:
- case XKeyRelease:
- case EnterNotify:
- case LeaveNotify:
- case ClientMessage:
- return false;
- default:
- break;
- }
-
- return true;
-}
-
-
-/*****************************************************************************
- Popup widget mechanism
-
- openPopup()
- Adds a widget to the list of popup widgets
- Arguments:
- QWidget *widget The popup widget to be added
-
- closePopup()
- Removes a widget from the list of popup widgets
- Arguments:
- QWidget *widget The popup widget to be removed
- *****************************************************************************/
-
-
-static int openPopupCount = 0;
-void QApplicationPrivate::openPopup(QWidget *popup)
-{
- Q_Q(QApplication);
- openPopupCount++;
- if (!QApplicationPrivate::popupWidgets) { // create list
- QApplicationPrivate::popupWidgets = new QWidgetList;
- }
- QApplicationPrivate::popupWidgets->append(popup); // add to end of list
- Display *dpy = X11->display;
- if (QApplicationPrivate::popupWidgets->count() == 1 && !qt_nograb()){ // grab mouse/keyboard
- Q_ASSERT(popup->testAttribute(Qt::WA_WState_Created));
- int r = XGrabKeyboard(dpy, popup->effectiveWinId(), false,
- GrabModeAsync, GrabModeAsync, X11->time);
- if ((popupGrabOk = (r == GrabSuccess))) {
- r = XGrabPointer(dpy, popup->effectiveWinId(), true,
- (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
- | EnterWindowMask | LeaveWindowMask | PointerMotionMask),
- GrabModeAsync, GrabModeAsync, XNone, XNone, X11->time);
- if (!(popupGrabOk = (r == GrabSuccess))) {
- // transfer grab back to the keyboard grabber if any
- if (QWidgetPrivate::keyboardGrabber != 0)
- QWidgetPrivate::keyboardGrabber->grabKeyboard();
- else
- XUngrabKeyboard(dpy, X11->time);
- }
- }
- }
-
- // popups are not focus-handled by the window system (the first
- // popup grabbed the keyboard), so we have to do that manually: A
- // new popup gets the focus
- if (popup->focusWidget()) {
- popup->focusWidget()->setFocus(Qt::PopupFocusReason);
- } else if (QApplicationPrivate::popupWidgets->count() == 1) { // this was the first popup
- if (QWidget *fw = QApplication::focusWidget()) {
- QFocusEvent e(QEvent::FocusOut, Qt::PopupFocusReason);
- q->sendEvent(fw, &e);
- }
- }
-}
-
-void QApplicationPrivate::closePopup(QWidget *popup)
-{
- Q_Q(QApplication);
- if (!QApplicationPrivate::popupWidgets)
- return;
- QApplicationPrivate::popupWidgets->removeAll(popup);
- if (popup == qt_popup_down) {
- qt_button_down = 0;
- qt_popup_down = 0;
- }
- if (QApplicationPrivate::popupWidgets->count() == 0) { // this was the last popup
- delete QApplicationPrivate::popupWidgets;
- QApplicationPrivate::popupWidgets = 0;
- if (!qt_nograb() && popupGrabOk) { // grabbing not disabled
- Display *dpy = X11->display;
- if (popup->geometry().contains(QPoint(mouseGlobalXPos, mouseGlobalYPos))
- || popup->testAttribute(Qt::WA_NoMouseReplay)) {
- // mouse release event or inside
- replayPopupMouseEvent = false;
- } else { // mouse press event
- mouseButtonPressTime -= 10000; // avoid double click
- replayPopupMouseEvent = true;
- }
- // transfer grab back to mouse grabber if any, otherwise release the grab
- if (QWidgetPrivate::mouseGrabber != 0)
- QWidgetPrivate::mouseGrabber->grabMouse();
- else
- XUngrabPointer(dpy, X11->time);
-
- // transfer grab back to keyboard grabber if any, otherwise release the grab
- if (QWidgetPrivate::keyboardGrabber != 0)
- QWidgetPrivate::keyboardGrabber->grabKeyboard();
- else
- XUngrabKeyboard(dpy, X11->time);
-
- XFlush(dpy);
- }
- if (QApplicationPrivate::active_window) {
- if (QWidget *fw = QApplicationPrivate::active_window->focusWidget()) {
- if (fw != QApplication::focusWidget()) {
- fw->setFocus(Qt::PopupFocusReason);
- } else {
- QFocusEvent e(QEvent::FocusIn, Qt::PopupFocusReason);
- q->sendEvent(fw, &e);
- }
- }
- }
- } else {
- // popups are not focus-handled by the window system (the
- // first popup grabbed the keyboard), so we have to do that
- // manually: A popup was closed, so the previous popup gets
- // the focus.
- QWidget* aw = QApplicationPrivate::popupWidgets->last();
- if (QWidget *fw = aw->focusWidget())
- fw->setFocus(Qt::PopupFocusReason);
-
- // regrab the keyboard and mouse in case 'popup' lost the grab
- if (QApplicationPrivate::popupWidgets->count() == 1 && !qt_nograb()){ // grab mouse/keyboard
- Display *dpy = X11->display;
- Q_ASSERT(aw->testAttribute(Qt::WA_WState_Created));
- int r = XGrabKeyboard(dpy, aw->effectiveWinId(), false,
- GrabModeAsync, GrabModeAsync, X11->time);
- if ((popupGrabOk = (r == GrabSuccess))) {
- r = XGrabPointer(dpy, aw->effectiveWinId(), true,
- (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
- | EnterWindowMask | LeaveWindowMask | PointerMotionMask),
- GrabModeAsync, GrabModeAsync, XNone, XNone, X11->time);
- if (!(popupGrabOk = (r == GrabSuccess))) {
- // transfer grab back to keyboard grabber
- if (QWidgetPrivate::keyboardGrabber != 0)
- QWidgetPrivate::keyboardGrabber->grabKeyboard();
- else
- XUngrabKeyboard(dpy, X11->time);
- }
- }
- }
- }
-}
-
-/*****************************************************************************
- Event translation; translates X11 events to Qt events
- *****************************************************************************/
-
-//
-// Mouse event translation
-//
-// Xlib doesn't give mouse double click events, so we generate them by
-// comparing window, time and position between two mouse press events.
-//
-
-static Qt::MouseButtons translateMouseButtons(int s)
-{
- Qt::MouseButtons ret = 0;
- if (s & Button1Mask)
- ret |= Qt::LeftButton;
- if (s & Button2Mask)
- ret |= Qt::MidButton;
- if (s & Button3Mask)
- ret |= Qt::RightButton;
- return ret;
-}
-
-Qt::KeyboardModifiers QX11Data::translateModifiers(int s)
-{
- Qt::KeyboardModifiers ret = 0;
- if (s & ShiftMask)
- ret |= Qt::ShiftModifier;
- if (s & ControlMask)
- ret |= Qt::ControlModifier;
- if (s & qt_alt_mask)
- ret |= Qt::AltModifier;
- if (s & qt_meta_mask)
- ret |= Qt::MetaModifier;
- if (s & qt_mode_switch_mask)
- ret |= Qt::GroupSwitchModifier;
- return ret;
-}
-
-bool QETWidget::translateMouseEvent(const XEvent *event)
-{
- if (!isWindow() && testAttribute(Qt::WA_NativeWindow))
- Q_ASSERT(internalWinId());
-
- Q_D(QWidget);
- QEvent::Type type; // event parameters
- QPoint pos;
- QPoint globalPos;
- Qt::MouseButton button = Qt::NoButton;
- Qt::MouseButtons buttons;
- Qt::KeyboardModifiers modifiers;
- XEvent nextEvent;
-
- if (qt_sm_blockUserInput) // block user interaction during session management
- return true;
-
- if (event->type == MotionNotify) { // mouse move
- if (event->xmotion.root != RootWindow(X11->display, x11Info().screen()) &&
- ! qt_xdnd_dragging)
- return false;
-
- XMotionEvent lastMotion = event->xmotion;
- while(XPending(X11->display)) { // compress mouse moves
- XNextEvent(X11->display, &nextEvent);
- if (nextEvent.type == ConfigureNotify
- || nextEvent.type == PropertyNotify
- || nextEvent.type == Expose
- || nextEvent.type == GraphicsExpose
- || nextEvent.type == NoExpose
- || nextEvent.type == KeymapNotify
- || ((nextEvent.type == EnterNotify || nextEvent.type == LeaveNotify)
- && qt_button_down == this)
- || (nextEvent.type == ClientMessage
- && (nextEvent.xclient.message_type == ATOM(_QT_SCROLL_DONE) ||
- (nextEvent.xclient.message_type == ATOM(WM_PROTOCOLS) &&
- (Atom)nextEvent.xclient.data.l[0] == ATOM(_NET_WM_SYNC_REQUEST))))) {
- qApp->x11ProcessEvent(&nextEvent);
- continue;
- } else if (nextEvent.type != MotionNotify ||
- nextEvent.xmotion.window != event->xmotion.window ||
- nextEvent.xmotion.state != event->xmotion.state) {
- XPutBackEvent(X11->display, &nextEvent);
- break;
- }
- if (!qt_x11EventFilter(&nextEvent)
- && !x11Event(&nextEvent)) // send event through filter
- lastMotion = nextEvent.xmotion;
- else
- break;
- }
- type = QEvent::MouseMove;
- pos.rx() = lastMotion.x;
- pos.ry() = lastMotion.y;
- pos = d->mapFromWS(pos);
- globalPos.rx() = lastMotion.x_root;
- globalPos.ry() = lastMotion.y_root;
- buttons = translateMouseButtons(lastMotion.state);
- modifiers = X11->translateModifiers(lastMotion.state);
- if (qt_button_down && !buttons)
- qt_button_down = 0;
- } else if (event->type == EnterNotify || event->type == LeaveNotify) {
- XEvent *xevent = (XEvent *)event;
- //unsigned int xstate = event->xcrossing.state;
- type = QEvent::MouseMove;
- pos.rx() = xevent->xcrossing.x;
- pos.ry() = xevent->xcrossing.y;
- pos = d->mapFromWS(pos);
- globalPos.rx() = xevent->xcrossing.x_root;
- globalPos.ry() = xevent->xcrossing.y_root;
- buttons = translateMouseButtons(xevent->xcrossing.state);
- modifiers = X11->translateModifiers(xevent->xcrossing.state);
- if (qt_button_down && !buttons)
- qt_button_down = 0;
- if (qt_button_down)
- return true;
- } else { // button press or release
- pos.rx() = event->xbutton.x;
- pos.ry() = event->xbutton.y;
- pos = d->mapFromWS(pos);
- globalPos.rx() = event->xbutton.x_root;
- globalPos.ry() = event->xbutton.y_root;
- buttons = translateMouseButtons(event->xbutton.state);
- modifiers = X11->translateModifiers(event->xbutton.state);
- switch (event->xbutton.button) {
- case Button1: button = Qt::LeftButton; break;
- case Button2: button = Qt::MidButton; break;
- case Button3: button = Qt::RightButton; break;
- case Button4:
- case Button5:
- case 6:
- case 7:
- // the fancy mouse wheel.
-
- // We are only interested in ButtonPress.
- if (event->type == ButtonPress){
- // compress wheel events (the X Server will simply
- // send a button press for each single notch,
- // regardless whether the application can catch up
- // or not)
- int delta = 1;
- XEvent xevent;
- while (XCheckTypedWindowEvent(X11->display, effectiveWinId(), ButtonPress, &xevent)){
- if (xevent.xbutton.button != event->xbutton.button){
- XPutBackEvent(X11->display, &xevent);
- break;
- }
- delta++;
- }
-
- // the delta is defined as multiples of
- // WHEEL_DELTA, which is set to 120. Future wheels
- // may offer a finer-resolution. A positive delta
- // indicates forward rotation, a negative one
- // backward rotation respectively.
- int btn = event->xbutton.button;
- delta *= 120 * ((btn == Button4 || btn == 6) ? 1 : -1);
- bool hor = (((btn == Button4 || btn == Button5) && (modifiers & Qt::AltModifier)) ||
- (btn == 6 || btn == 7));
- translateWheelEvent(globalPos.x(), globalPos.y(), delta, buttons,
- modifiers, (hor) ? Qt::Horizontal: Qt::Vertical);
- }
- return true;
- case 8: button = Qt::XButton1; break;
- case 9: button = Qt::XButton2; break;
- }
- if (event->type == ButtonPress) { // mouse button pressed
- buttons |= button;
-#if defined(Q_OS_IRIX) && !defined(QT_NO_TABLET)
- QTabletDeviceDataList *tablets = qt_tablet_devices();
- for (int i = 0; i < tablets->size(); ++i) {
- QTabletDeviceData &tab = tablets->operator[](i);
- XEvent myEv;
- if (XCheckTypedEvent(X11->display, tab.xinput_button_press, &myEv)) {
- if (translateXinputEvent(&myEv, &tab)) {
- //Spontaneous event sent. Check if we need to continue.
- if (qt_tabletChokeMouse) {
- qt_tabletChokeMouse = false;
- return false;
- }
- }
- }
- }
-#endif
- if (!qt_button_down) {
- qt_button_down = childAt(pos); //magic for masked widgets
- if (!qt_button_down)
- qt_button_down = this;
- }
- if (mouseActWindow == event->xbutton.window &&
- mouseButtonPressed == button &&
- (long)event->xbutton.time -(long)mouseButtonPressTime
- < QApplication::doubleClickInterval() &&
- qAbs(event->xbutton.x - mouseXPos) < QT_GUI_DOUBLE_CLICK_RADIUS &&
- qAbs(event->xbutton.y - mouseYPos) < QT_GUI_DOUBLE_CLICK_RADIUS) {
- type = QEvent::MouseButtonDblClick;
- mouseButtonPressTime -= 2000; // no double-click next time
- } else {
- type = QEvent::MouseButtonPress;
- mouseButtonPressTime = event->xbutton.time;
- }
- mouseButtonPressed = button; // save event params for
- mouseXPos = event->xbutton.x; // future double click tests
- mouseYPos = event->xbutton.y;
- mouseGlobalXPos = globalPos.x();
- mouseGlobalYPos = globalPos.y();
- } else { // mouse button released
- buttons &= ~button;
-#if defined(Q_OS_IRIX) && !defined(QT_NO_TABLET)
- QTabletDeviceDataList *tablets = qt_tablet_devices();
- for (int i = 0; i < tablets->size(); ++i) {
- QTabletDeviceData &tab = tablets->operator[](i);
- XEvent myEv;
- if (XCheckTypedEvent(X11->display, tab.xinput_button_press, &myEv)) {
- if (translateXinputEvent(&myEv, &tab)) {
- //Spontaneous event sent. Check if we need to continue.
- if (qt_tabletChokeMouse) {
- qt_tabletChokeMouse = false;
- return false;
- }
- }
- }
- }
-#endif
- type = QEvent::MouseButtonRelease;
- }
- }
- mouseActWindow = effectiveWinId(); // save some event params
- mouseButtonState = buttons;
- if (type == 0) // don't send event
- return false;
-
- if (qApp->d_func()->inPopupMode()) { // in popup mode
- QWidget *activePopupWidget = qApp->activePopupWidget();
- QWidget *popup = qApp->activePopupWidget();
- if (popup != this) {
- if (event->type == LeaveNotify)
- return false;
- if ((windowType() == Qt::Popup) && rect().contains(pos) && 0)
- popup = this;
- else // send to last popup
- pos = popup->mapFromGlobal(globalPos);
- }
- bool releaseAfter = false;
- QWidget *popupChild = popup->childAt(pos);
-
- if (popup != qt_popup_down){
- qt_button_down = 0;
- qt_popup_down = 0;
- }
-
- switch (type) {
- case QEvent::MouseButtonPress:
- case QEvent::MouseButtonDblClick:
- qt_button_down = popupChild;
- qt_popup_down = popup;
- break;
- case QEvent::MouseButtonRelease:
- releaseAfter = true;
- break;
- default:
- break; // nothing for mouse move
- }
-
- int oldOpenPopupCount = openPopupCount;
-
- if (popup->isEnabled()) {
- // deliver event
- replayPopupMouseEvent = false;
- QWidget *receiver = popup;
- QPoint widgetPos = pos;
- if (qt_button_down)
- receiver = qt_button_down;
- else if (popupChild)
- receiver = popupChild;
- if (receiver != popup)
- widgetPos = receiver->mapFromGlobal(globalPos);
- QWidget *alien = childAt(mapFromGlobal(globalPos));
- QMouseEvent e(type, widgetPos, globalPos, button, buttons, modifiers);
- QApplicationPrivate::sendMouseEvent(receiver, &e, alien, this, &qt_button_down, qt_last_mouse_receiver);
- } else {
- // close disabled popups when a mouse button is pressed or released
- switch (type) {
- case QEvent::MouseButtonPress:
- case QEvent::MouseButtonDblClick:
- case QEvent::MouseButtonRelease:
- popup->close();
- break;
- default:
- break;
- }
- }
-
- if (qApp->activePopupWidget() != activePopupWidget
- && replayPopupMouseEvent) {
- // the active popup was closed, replay the mouse event
- if (!(windowType() == Qt::Popup)) {
-#if 1
- qt_button_down = 0;
-#else
- if (buttons == button)
- qt_button_down = this;
- QMouseEvent e(type, mapFromGlobal(globalPos), globalPos, button,
- buttons, modifiers);
- QApplication::sendSpontaneousEvent(this, &e);
-
- if (type == QEvent::MouseButtonPress
- && button == Qt::RightButton
- && (openPopupCount == oldOpenPopupCount)) {
- QContextMenuEvent e(QContextMenuEvent::Mouse, mapFromGlobal(globalPos),
- globalPos, modifiers);
- QApplication::sendSpontaneousEvent(this, &e);
- }
-#endif
- }
- replayPopupMouseEvent = false;
- } else if (type == QEvent::MouseButtonPress
- && button == Qt::RightButton
- && (openPopupCount == oldOpenPopupCount)) {
- QWidget *popupEvent = popup;
- if (qt_button_down)
- popupEvent = qt_button_down;
- else if(popupChild)
- popupEvent = popupChild;
- QContextMenuEvent e(QContextMenuEvent::Mouse, pos, globalPos, modifiers);
- QApplication::sendSpontaneousEvent(popupEvent, &e);
- }
-
- if (releaseAfter) {
- qt_button_down = 0;
- qt_popup_down = 0;
- }
- } else {
- QWidget *alienWidget = childAt(pos);
- QWidget *widget = QApplicationPrivate::pickMouseReceiver(this, globalPos, pos, type, buttons,
- qt_button_down, alienWidget);
- if (!widget) {
- if (type == QEvent::MouseButtonRelease)
- QApplicationPrivate::mouse_buttons &= ~button;
- return false; // don't send event
- }
-
- int oldOpenPopupCount = openPopupCount;
- QMouseEvent e(type, pos, globalPos, button, buttons, modifiers);
- QApplicationPrivate::sendMouseEvent(widget, &e, alienWidget, this, &qt_button_down,
- qt_last_mouse_receiver);
- if (type == QEvent::MouseButtonPress
- && button == Qt::RightButton
- && (openPopupCount == oldOpenPopupCount)) {
- QContextMenuEvent e(QContextMenuEvent::Mouse, pos, globalPos, modifiers);
- QApplication::sendSpontaneousEvent(widget, &e);
- }
- }
- return true;
-}
-
-
-//
-// Wheel event translation
-//
-bool QETWidget::translateWheelEvent(int global_x, int global_y, int delta,
- Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
- Qt::Orientation orient)
-{
- const QPoint globalPos = QPoint(global_x, global_y);
- QPoint pos = mapFromGlobal(globalPos);
- QWidget *widget = childAt(pos);
- if (!widget)
- widget = this;
- else if (!widget->internalWinId())
- pos = widget->mapFromGlobal(globalPos);
-
-#ifdef ALIEN_DEBUG
- qDebug() << "QETWidget::translateWheelEvent: receiver:" << widget << "pos:" << pos;
-#endif
-
- // send the event to the widget or its ancestors
- {
- QWidget* popup = qApp->activePopupWidget();
- if (popup && window() != popup)
- popup->close();
-#ifndef QT_NO_WHEELEVENT
- QWheelEvent e(pos, globalPos, delta, buttons, modifiers, orient);
- if (QApplication::sendSpontaneousEvent(widget, &e))
-#endif
- return true;
- }
-
- // send the event to the widget that has the focus or its ancestors, if different
- if (widget != qApp->focusWidget() && (widget = qApp->focusWidget())) {
- if (widget && !widget->internalWinId())
- pos = widget->mapFromGlobal(globalPos);
- QWidget* popup = qApp->activePopupWidget();
- if (popup && widget != popup)
- popup->hide();
-#ifndef QT_NO_WHEELEVENT
- QWheelEvent e(pos, globalPos, delta, buttons, modifiers, orient);
- if (QApplication::sendSpontaneousEvent(widget, &e))
-#endif
- return true;
- }
- return false;
-}
-
-
-//
-// XInput Translation Event
-//
-#if !defined (QT_NO_TABLET)
-
-#if !defined (Q_OS_IRIX)
-void fetchWacomToolId(int &deviceType, qint64 &serialId)
-{
- if (ptrWacomConfigInit == 0) // we actually have the lib
- return;
- WACOMCONFIG *config = ptrWacomConfigInit(X11->display, 0);
- if (config == 0)
- return;
- WACOMDEVICE *device = ptrWacomConfigOpenDevice (config, wacomDeviceName()->constData());
- if (device == 0)
- return;
- unsigned keys[1];
- int serialInt;
- ptrWacomConfigGetRawParam (device, XWACOM_PARAM_TOOLSERIAL, &serialInt, 1, keys);
- serialId = serialInt;
- int toolId;
- ptrWacomConfigGetRawParam (device, XWACOM_PARAM_TOOLID, &toolId, 1, keys);
- switch(toolId) {
- case 0x007: /* Mouse 4D and 2D */
- case 0x017: /* Intuos3 2D Mouse */
- case 0x094:
- case 0x09c:
- deviceType = QTabletEvent::FourDMouse;
- break;
- case 0x096: /* Lens cursor */
- case 0x097: /* Intuos3 Lens cursor */
- deviceType = QTabletEvent::Puck;
- break;
- case 0x0fa:
- case 0x81b: /* Intuos3 Classic Pen Eraser */
- case 0x82a: /* Eraser */
- case 0x82b: /* Intuos3 Grip Pen Eraser */
- case 0x85a:
- case 0x91a:
- case 0x91b: /* Intuos3 Airbrush Eraser */
- case 0xd1a:
- deviceType = QTabletEvent::XFreeEraser;
- break;
- case 0x112:
- case 0x912:
- case 0x913: /* Intuos3 Airbrush */
- case 0xd12:
- deviceType = QTabletEvent::Airbrush;
- break;
- case 0x012:
- case 0x022:
- case 0x032:
- case 0x801: /* Intuos3 Inking pen */
- case 0x812: /* Inking pen */
- case 0x813: /* Intuos3 Classic Pen */
- case 0x822: /* Pen */
- case 0x823: /* Intuos3 Grip Pen */
- case 0x832: /* Stroke pen */
- case 0x842:
- case 0x852:
- case 0x885: /* Intuos3 Marker Pen */
- default: /* Unknown tool */
- deviceType = QTabletEvent::Stylus;
- }
-
- /* Close device and return */
- ptrWacomConfigCloseDevice (device);
- ptrWacomConfigTerm(config);
-}
-#endif
-
-struct qt_tablet_motion_data
-{
- bool filterByWidget;
- const QWidget *widget;
- const QWidget *etWidget;
- int tabletMotionType;
- bool error; // found a reason to stop searching
-};
-
-static Bool qt_mouseMotion_scanner(Display *, XEvent *event, XPointer arg)
-{
- qt_tablet_motion_data *data = (qt_tablet_motion_data *) arg;
- if (data->error)
- return false;
-
- if (event->type == MotionNotify)
- return true;
-
- data->error = event->type != data->tabletMotionType; // we stop compression when another event gets in between.
- return false;
-}
-
-static Bool qt_tabletMotion_scanner(Display *, XEvent *event, XPointer arg)
-{
- qt_tablet_motion_data *data = (qt_tablet_motion_data *) arg;
- if (data->error)
- return false;
- if (event->type == data->tabletMotionType) {
- const XDeviceMotionEvent *const motion = reinterpret_cast<const XDeviceMotionEvent*>(event);
- if (data->filterByWidget) {
- const QPoint curr(motion->x, motion->y);
- const QWidget *w = data->etWidget;
- const QWidget *const child = w->childAt(curr);
- if (child) {
- w = child;
- }
- if (w == data->widget)
- return true;
- } else {
- return true;
- }
- }
-
- data->error = event->type != MotionNotify; // we stop compression when another event gets in between.
- return false;
-}
-
-bool QETWidget::translateXinputEvent(const XEvent *ev, QTabletDeviceData *tablet)
-{
-#if defined (Q_OS_IRIX)
- // Wacom has put defines in their wacom.h file so it would be quite wise
- // to use them, need to think of a decent way of not using
- // it when it doesn't exist...
- XDeviceState *s;
- XInputClass *iClass;
- XValuatorState *vs;
- int j;
-#endif
-
- Q_ASSERT(tablet != 0);
-
- QWidget *w = this;
- QPoint global,
- curr;
- QPointF hiRes;
- qreal pressure = 0;
- int xTilt = 0,
- yTilt = 0,
- z = 0;
- qreal tangentialPressure = 0;
- qreal rotation = 0;
- int deviceType = QTabletEvent::NoDevice;
- int pointerType = QTabletEvent::UnknownPointer;
- const XDeviceMotionEvent *motion = 0;
- XDeviceButtonEvent *button = 0;
- const XProximityNotifyEvent *proximity = 0;
- QEvent::Type t;
- Qt::KeyboardModifiers modifiers = 0;
-#if !defined (Q_OS_IRIX)
- XID device_id;
-#endif
-
- if (ev->type == tablet->xinput_motion) {
- motion = reinterpret_cast<const XDeviceMotionEvent*>(ev);
- t = QEvent::TabletMove;
- global = QPoint(motion->x_root, motion->y_root);
- curr = QPoint(motion->x, motion->y);
-#if !defined (Q_OS_IRIX)
- device_id = motion->deviceid;
-#endif
- } else if (ev->type == tablet->xinput_button_press || ev->type == tablet->xinput_button_release) {
- if (ev->type == tablet->xinput_button_press) {
- t = QEvent::TabletPress;
- } else {
- t = QEvent::TabletRelease;
- }
- button = (XDeviceButtonEvent*)ev;
-
- global = QPoint(button->x_root, button->y_root);
- curr = QPoint(button->x, button->y);
-#if !defined (Q_OS_IRIX)
- device_id = button->deviceid;
-#endif
- } else { // Proximity
- if (ev->type == tablet->xinput_proximity_in)
- t = QEvent::TabletEnterProximity;
- else
- t = QEvent::TabletLeaveProximity;
- proximity = (const XProximityNotifyEvent*)ev;
-#if !defined (Q_OS_IRIX)
- device_id = proximity->deviceid;
-#endif
- }
-
- qint64 uid = 0;
-#if defined (Q_OS_IRIX)
- QRect screenArea = qApp->desktop()->screenGeometry(this);
- s = XQueryDeviceState(X11->display, static_cast<XDevice *>(tablet->device));
- if (!s)
- return false;
- iClass = s->data;
- for (j = 0; j < s->num_classes; j++) {
- if (iClass->c_class == ValuatorClass) {
- vs = reinterpret_cast<XValuatorState *>(iClass);
- // figure out what device we have, based on bitmasking...
- if (vs->valuators[WAC_TRANSDUCER_I]
- & WAC_TRANSDUCER_PROX_MSK) {
- switch (vs->valuators[WAC_TRANSDUCER_I]
- & WAC_TRANSDUCER_MSK) {
- case WAC_PUCK_ID:
- pointerType = QTabletEvent::Puck;
- break;
- case WAC_STYLUS_ID:
- pointerType = QTabletEvent::Pen;
- break;
- case WAC_ERASER_ID:
- pointerType = QTabletEvent::Eraser;
- break;
- }
- // Get a Unique Id for the device, Wacom gives us this ability
- uid = vs->valuators[WAC_TRANSDUCER_I] & WAC_TRANSDUCER_ID_MSK;
- uid = (uid << 24) | vs->valuators[WAC_SERIAL_NUM_I];
- switch (WAC_TRANSDUCER_I & 0x0F0600) {
- case 0x080200:
- deviceType = QTabletEvent::Stylus;
- break;
- case 0x090200:
- deviceType = QTabletEvent::Airbrush;
- break;
- case 0x000400:
- deviceType = QTabletEvent::FourDMouse;
- break;
- case 0x000600:
- deviceType = QTabletEvent::Puck;
- break;
- case 0x080400:
- deviceType = QTabletEvent::RotationStylus;
- break;
- }
- } else {
- pointerType = QTabletEvent::UnknownPointer;
- deviceType = QTabletEvent::NoDevice;
- uid = 0;
- }
-
- if (!proximity) {
- // apparently Wacom needs a cast for the +/- values to make sense
- xTilt = short(vs->valuators[WAC_XTILT_I]);
- yTilt = short(vs->valuators[WAC_YTILT_I]);
- pressure = vs->valuators[WAC_PRESSURE_I];
- if (deviceType == QTabletEvent::FourDMouse
- || deviceType == QTabletEvent::RotationStylus) {
- rotation = vs->valuators[WAC_ROTATION_I] / 64.0;
- if (deviceType == QTabletEvent::FourDMouse)
- z = vs->valuators[WAC_ZCOORD_I];
- } else if (deviceType == QTabletEvent::Airbrush) {
- tangentialPressure = vs->valuators[WAC_TAN_PRESSURE_I]
- / qreal(tablet->maxTanPressure - tablet->minTanPressure);
- }
-
- hiRes = tablet->scaleCoord(vs->valuators[WAC_XCOORD_I], vs->valuators[WAC_YCOORD_I],
- screenArea.x(), screenArea.width(),
- screenArea.y(), screenArea.height());
- }
- break;
- }
- iClass = reinterpret_cast<XInputClass*>(reinterpret_cast<char*>(iClass) + iClass->length);
- }
- XFreeDeviceState(s);
-#else
- QTabletDeviceDataList *tablet_list = qt_tablet_devices();
- for (int i = 0; i < tablet_list->size(); ++i) {
- const QTabletDeviceData &t = tablet_list->at(i);
- if (device_id == static_cast<XDevice *>(t.device)->device_id) {
- deviceType = t.deviceType;
- if (t.deviceType == QTabletEvent::XFreeEraser) {
- deviceType = QTabletEvent::Stylus;
- pointerType = QTabletEvent::Eraser;
- } else if (t.deviceType == QTabletEvent::Stylus) {
- pointerType = QTabletEvent::Pen;
- }
- break;
- }
- }
-
- fetchWacomToolId(deviceType, uid);
-
- QRect screenArea = qApp->desktop()->rect();
- if (motion) {
- xTilt = (short) motion->axis_data[3];
- yTilt = (short) motion->axis_data[4];
- rotation = ((short) motion->axis_data[5]) / 64.0;
- pressure = (short) motion->axis_data[2];
- modifiers = X11->translateModifiers(motion->state);
- hiRes = tablet->scaleCoord(motion->axis_data[0], motion->axis_data[1],
- screenArea.x(), screenArea.width(),
- screenArea.y(), screenArea.height());
- } else if (button) {
- xTilt = (short) button->axis_data[3];
- yTilt = (short) button->axis_data[4];
- rotation = ((short) button->axis_data[5]) / 64.0;
- pressure = (short) button->axis_data[2];
- modifiers = X11->translateModifiers(button->state);
- hiRes = tablet->scaleCoord(button->axis_data[0], button->axis_data[1],
- screenArea.x(), screenArea.width(),
- screenArea.y(), screenArea.height());
- } else if (proximity) {
- pressure = 0;
- modifiers = 0;
- }
- if (deviceType == QTabletEvent::Airbrush) {
- tangentialPressure = rotation;
- rotation = 0.;
- }
-#endif
-
- if (tablet->widgetToGetPress) {
- w = tablet->widgetToGetPress;
- } else {
- QWidget *child = w->childAt(curr);
- if (child)
- w = child;
- }
- curr = w->mapFromGlobal(global);
-
- if (t == QEvent::TabletPress) {
- tablet->widgetToGetPress = w;
- } else if (t == QEvent::TabletRelease && tablet->widgetToGetPress) {
- w = tablet->widgetToGetPress;
- curr = w->mapFromGlobal(global);
- tablet->widgetToGetPress = 0;
- }
-
- QTabletEvent e(t, curr, global, hiRes,
- deviceType, pointerType,
- qreal(pressure / qreal(tablet->maxPressure - tablet->minPressure)),
- xTilt, yTilt, tangentialPressure, rotation, z, modifiers, uid);
- if (proximity) {
- QApplication::sendSpontaneousEvent(qApp, &e);
- } else {
- QApplication::sendSpontaneousEvent(w, &e);
- const bool accepted = e.isAccepted();
- if (!accepted && ev->type == tablet->xinput_motion) {
- // If the widget does not accept tablet events, we drop the next ones from the event queue
- // for this widget so it is not overloaded with the numerous tablet events.
- qt_tablet_motion_data tabletMotionData;
- tabletMotionData.tabletMotionType = tablet->xinput_motion;
- tabletMotionData.widget = w;
- tabletMotionData.etWidget = this;
- // if nothing is pressed, the events are filtered by position
- tabletMotionData.filterByWidget = (tablet->widgetToGetPress == 0);
-
- bool reinsertMouseEvent = false;
- XEvent mouseMotionEvent;
- while (true) {
- // Find first mouse event since we expect them in pairs inside Qt
- tabletMotionData.error =false;
- if (XCheckIfEvent(X11->display, &mouseMotionEvent, &qt_mouseMotion_scanner, (XPointer) &tabletMotionData)) {
- reinsertMouseEvent = true;
- } else {
- break;
- }
-
- // Now discard any duplicate tablet events.
- tabletMotionData.error = false;
- XEvent dummy;
- while (XCheckIfEvent(X11->display, &dummy, &qt_tabletMotion_scanner, (XPointer) &tabletMotionData)) {
- // just discard the event
- }
- }
-
- if (reinsertMouseEvent) {
- XPutBackEvent(X11->display, &mouseMotionEvent);
- }
- }
- }
- return true;
-}
-#endif
-
-bool QETWidget::translatePropertyEvent(const XEvent *event)
-{
- Q_D(QWidget);
- if (!isWindow()) return true;
-
- Atom ret;
- int format, e;
- unsigned char *data = 0;
- unsigned long nitems, after;
-
- if (event->xproperty.atom == ATOM(_KDE_NET_WM_FRAME_STRUT)) {
- this->data->fstrut_dirty = 1;
-
- if (event->xproperty.state == PropertyNewValue) {
- e = XGetWindowProperty(X11->display, event->xproperty.window, ATOM(_KDE_NET_WM_FRAME_STRUT),
- 0, 4, // struts are 4 longs
- False, XA_CARDINAL, &ret, &format, &nitems, &after, &data);
-
- if (e == Success && ret == XA_CARDINAL &&
- format == 32 && nitems == 4) {
- long *strut = (long *) data;
- d->topData()->frameStrut.setCoords(strut[0], strut[2], strut[1], strut[3]);
- this->data->fstrut_dirty = 0;
- }
- }
- } else if (event->xproperty.atom == ATOM(_NET_WM_STATE)) {
- bool max = false;
- bool full = false;
- Qt::WindowStates oldState = Qt::WindowStates(this->data->window_state);
-
- if (event->xproperty.state == PropertyNewValue) {
- // using length of 1024 should be safe for all current and
- // possible NET states...
- e = XGetWindowProperty(X11->display, event->xproperty.window, ATOM(_NET_WM_STATE), 0, 1024,
- False, XA_ATOM, &ret, &format, &nitems, &after, &data);
-
- if (e == Success && ret == XA_ATOM && format == 32 && nitems > 0) {
- Atom *states = (Atom *) data;
-
- unsigned long i;
- uint maximized = 0;
- for (i = 0; i < nitems; i++) {
- if (states[i] == ATOM(_NET_WM_STATE_MAXIMIZED_VERT))
- maximized |= 1;
- else if (states[i] == ATOM(_NET_WM_STATE_MAXIMIZED_HORZ))
- maximized |= 2;
- else if (states[i] == ATOM(_NET_WM_STATE_FULLSCREEN))
- full = true;
- }
- if (maximized == 3) {
- // only set maximized if both horizontal and vertical properties are set
- max = true;
- }
- }
- }
-
- bool send_event = false;
-
- if (X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_VERT))
- && X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ))) {
- if (max && !isMaximized()) {
- this->data->window_state = this->data->window_state | Qt::WindowMaximized;
- send_event = true;
- } else if (!max && isMaximized()) {
- this->data->window_state &= ~Qt::WindowMaximized;
- send_event = true;
- }
- }
-
- if (X11->isSupportedByWM(ATOM(_NET_WM_STATE_FULLSCREEN))) {
- if (full && !isFullScreen()) {
- this->data->window_state = this->data->window_state | Qt::WindowFullScreen;
- send_event = true;
- } else if (!full && isFullScreen()) {
- this->data->window_state &= ~Qt::WindowFullScreen;
- send_event = true;
- }
- }
-
- if (send_event) {
- QWindowStateChangeEvent e(oldState);
- QApplication::sendSpontaneousEvent(this, &e);
- }
- } else if (event->xproperty.atom == ATOM(WM_STATE)) {
- // the widget frame strut should also be invalidated
- this->data->fstrut_dirty = 1;
-
- if (event->xproperty.state == PropertyDelete) {
- // the window manager has removed the WM State property,
- // so it is now in the withdrawn state (ICCCM 4.1.3.1) and
- // we are free to reuse this window
- d->topData()->parentWinId = 0;
- d->topData()->validWMState = 0;
- // map the window if we were waiting for a transition to
- // withdrawn
- if (X11->deferred_map.removeAll(this)) {
- doDeferredMap();
- } else if (isVisible()
- && !testAttribute(Qt::WA_Mapped)
- && !testAttribute(Qt::WA_OutsideWSRange)) {
- // so that show() will work again. As stated in the
- // ICCCM section 4.1.4: "Only the client can effect a
- // transition into or out of the Withdrawn state.",
- // but apparently this particular window manager
- // doesn't seem to care
- setAttribute(Qt::WA_WState_ExplicitShowHide, false);
- setAttribute(Qt::WA_WState_Visible, false);
- }
- } else {
- // the window manager has changed the WM State property...
- // we are wanting to see if we are withdrawn so that we
- // can reuse this window...
- e = XGetWindowProperty(X11->display, internalWinId(), ATOM(WM_STATE), 0, 2, False,
- ATOM(WM_STATE), &ret, &format, &nitems, &after, &data);
-
- if (e == Success && ret == ATOM(WM_STATE) && format == 32 && nitems > 0) {
- long *state = (long *) data;
- switch (state[0]) {
- case WithdrawnState:
- // if we are in the withdrawn state, we are free
- // to reuse this window provided we remove the
- // WM_STATE property (ICCCM 4.1.3.1)
- XDeleteProperty(X11->display, internalWinId(), ATOM(WM_STATE));
-
- // set the parent id to zero, so that show() will
- // work again
- d->topData()->parentWinId = 0;
- d->topData()->validWMState = 0;
- // map the window if we were waiting for a
- // transition to withdrawn
- if (X11->deferred_map.removeAll(this)) {
- doDeferredMap();
- } else if (isVisible()
- && !testAttribute(Qt::WA_Mapped)
- && !testAttribute(Qt::WA_OutsideWSRange)) {
- // so that show() will work again. As stated
- // in the ICCCM section 4.1.4: "Only the
- // client can effect a transition into or out
- // of the Withdrawn state.", but apparently
- // this particular window manager doesn't seem
- // to care
- setAttribute(Qt::WA_WState_ExplicitShowHide, false);
- setAttribute(Qt::WA_WState_Visible, false);
- }
- break;
-
- case IconicState:
- d->topData()->validWMState = 1;
- if (!isMinimized()) {
- // window was minimized
- this->data->window_state = this->data->window_state | Qt::WindowMinimized;
- QWindowStateChangeEvent e(Qt::WindowStates(this->data->window_state & ~Qt::WindowMinimized));
- QApplication::sendSpontaneousEvent(this, &e);
- }
- break;
-
- default:
- d->topData()->validWMState = 1;
- if (isMinimized()) {
- // window was un-minimized
- this->data->window_state &= ~Qt::WindowMinimized;
- QWindowStateChangeEvent e(Qt::WindowStates(this->data->window_state | Qt::WindowMinimized));
- QApplication::sendSpontaneousEvent(this, &e);
- }
- break;
- }
- }
- }
- } else if (event->xproperty.atom == ATOM(_NET_WM_WINDOW_OPACITY)) {
- // the window opacity was changed
- if (event->xproperty.state == PropertyNewValue) {
- e = XGetWindowProperty(event->xclient.display,
- event->xclient.window,
- ATOM(_NET_WM_WINDOW_OPACITY),
- 0, 1, False, XA_CARDINAL,
- &ret, &format, &nitems, &after, &data);
-
- if (e == Success && ret == XA_CARDINAL && format == 32 && nitems == 1
- && after == 0 && data) {
- ulong value = *(ulong*)(data);
- d->topData()->opacity = uint(value >> 24);
- }
- } else
- d->topData()->opacity = 255;
- }
-
- if (data)
- XFree(data);
-
- return true;
-}
-
-
-//
-// Paint event translation
-//
-// When receiving many expose events, we compress them (union of all expose
-// rectangles) into one event which is sent to the widget.
-
-struct PaintEventInfo {
- Window window;
-};
-
-#if defined(Q_C_CALLBACKS)
-extern "C" {
-#endif
-
-static Bool isPaintOrScrollDoneEvent(Display *, XEvent *ev, XPointer a)
-{
- PaintEventInfo *info = (PaintEventInfo *)a;
- if (ev->type == Expose || ev->type == GraphicsExpose
- || (ev->type == ClientMessage && ev->xclient.message_type == ATOM(_QT_SCROLL_DONE)))
- {
- if (ev->xexpose.window == info->window)
- return True;
- }
- return False;
-}
-
-#if defined(Q_C_CALLBACKS)
-}
-#endif
-
-
-
-static
-bool translateBySips(QWidget* that, QRect& paintRect)
-{
- int dx=0, dy=0;
- int sips=0;
- for (int i = 0; i < X11->sip_list.size(); ++i) {
- const QX11Data::ScrollInProgress &sip = X11->sip_list.at(i);
- if (sip.scrolled_widget == that) {
- if (sips) {
- dx += sip.dx;
- dy += sip.dy;
- }
- sips++;
- }
- }
- if (sips > 1) {
- paintRect.translate(dx, dy);
- return true;
- }
- return false;
-}
-
-void QETWidget::translatePaintEvent(const XEvent *event)
-{
- if (!isWindow() && testAttribute(Qt::WA_NativeWindow))
- Q_ASSERT(internalWinId());
-
- Q_D(QWidget);
- QRect paintRect(event->xexpose.x, event->xexpose.y,
- event->xexpose.width, event->xexpose.height);
- XEvent xevent;
- PaintEventInfo info;
- info.window = internalWinId();
- translateBySips(this, paintRect);
- paintRect = d->mapFromWS(paintRect);
-
- QRegion paintRegion = paintRect;
-
- // WARNING: this is O(number_of_events * number_of_matching_events)
- while (XCheckIfEvent(X11->display,&xevent,isPaintOrScrollDoneEvent,
- (XPointer)&info) &&
- !qt_x11EventFilter(&xevent) &&
- !x11Event(&xevent)) // send event through filter
- {
- if (xevent.type == Expose || xevent.type == GraphicsExpose) {
- QRect exposure(xevent.xexpose.x,
- xevent.xexpose.y,
- xevent.xexpose.width,
- xevent.xexpose.height);
- translateBySips(this, exposure);
- exposure = d->mapFromWS(exposure);
- paintRegion |= exposure;
- } else {
- translateScrollDoneEvent(&xevent);
- }
- }
-
- if (!paintRegion.isEmpty() && !testAttribute(Qt::WA_WState_ConfigPending))
- d->syncBackingStore(paintRegion);
-}
-
-//
-// Scroll-done event translation.
-//
-
-bool QETWidget::translateScrollDoneEvent(const XEvent *event)
-{
- long id = event->xclient.data.l[0];
-
- // Remove any scroll-in-progress record for the given id.
- for (int i = 0; i < X11->sip_list.size(); ++i) {
- const QX11Data::ScrollInProgress &sip = X11->sip_list.at(i);
- if (sip.id == id) {
- X11->sip_list.removeAt(i);
- return true;
- }
- }
-
- return false;
-}
-
-//
-// ConfigureNotify (window move and resize) event translation
-
-bool QETWidget::translateConfigEvent(const XEvent *event)
-{
- Q_ASSERT((!isWindow() && !testAttribute(Qt::WA_NativeWindow)) ? internalWinId() : true);
-
- Q_D(QWidget);
- bool wasResize = testAttribute(Qt::WA_WState_ConfigPending); // set in QWidget::setGeometry_sys()
- setAttribute(Qt::WA_WState_ConfigPending, false);
-
- if (testAttribute(Qt::WA_OutsideWSRange)) {
- // discard events for windows that have a geometry X can't handle
- XEvent xevent;
- while (XCheckTypedWindowEvent(X11->display,internalWinId(), ConfigureNotify,&xevent) &&
- !qt_x11EventFilter(&xevent) &&
- !x11Event(&xevent)) // send event through filter
- ;
- return true;
- }
-
- const QSize oldSize = size();
-
- if (isWindow()) {
- QPoint newCPos(geometry().topLeft());
- QSize newSize(event->xconfigure.width, event->xconfigure.height);
-
- bool trust = isVisible()
- && (d->topData()->parentWinId == XNone ||
- d->topData()->parentWinId == QX11Info::appRootWindow());
- bool isCPos = false;
-
- if (event->xconfigure.send_event || trust) {
- // if a ConfigureNotify comes from a real sendevent request, we can
- // trust its values.
- newCPos.rx() = event->xconfigure.x + event->xconfigure.border_width;
- newCPos.ry() = event->xconfigure.y + event->xconfigure.border_width;
- isCPos = true;
- }
- if (isVisible())
- QApplication::syncX();
-
- if (d->extra->compress_events) {
- // ConfigureNotify compression for faster opaque resizing
- XEvent otherEvent;
- while (XCheckTypedWindowEvent(X11->display, internalWinId(), ConfigureNotify,
- &otherEvent)) {
- if (qt_x11EventFilter(&otherEvent))
- continue;
-
- if (x11Event(&otherEvent))
- continue;
-
- if (otherEvent.xconfigure.event != otherEvent.xconfigure.window)
- continue;
-
- newSize.setWidth(otherEvent.xconfigure.width);
- newSize.setHeight(otherEvent.xconfigure.height);
-
- if (otherEvent.xconfigure.send_event || trust) {
- newCPos.rx() = otherEvent.xconfigure.x +
- otherEvent.xconfigure.border_width;
- newCPos.ry() = otherEvent.xconfigure.y +
- otherEvent.xconfigure.border_width;
- isCPos = true;
- }
- }
-#ifndef QT_NO_XSYNC
- qt_sync_request_event_data sync_event;
- sync_event.window = internalWinId();
- for (XEvent ev;;) {
- if (!XCheckIfEvent(X11->display, &ev, &qt_sync_request_scanner, (XPointer)&sync_event))
- break;
- }
-#endif // QT_NO_XSYNC
- }
-
- if (!isCPos) {
- // we didn't get an updated position of the toplevel.
- // either we haven't moved or there is a bug in the window manager.
- // anyway, let's query the position to be certain.
- int x, y;
- Window child;
- XTranslateCoordinates(X11->display, internalWinId(),
- QApplication::desktop()->screen(d->xinfo.screen())->internalWinId(),
- 0, 0, &x, &y, &child);
- newCPos.rx() = x;
- newCPos.ry() = y;
- }
-
- QRect cr (geometry());
- if (newCPos != cr.topLeft()) { // compare with cpos (exluding frame)
- QPoint oldPos = geometry().topLeft();
- cr.moveTopLeft(newCPos);
- data->crect = cr;
- if (isVisible()) {
- QMoveEvent e(newCPos, oldPos); // pos (including frame), not cpos
- QApplication::sendSpontaneousEvent(this, &e);
- } else {
- setAttribute(Qt::WA_PendingMoveEvent, true);
- }
- }
- if (newSize != cr.size()) { // size changed
- cr.setSize(newSize);
- data->crect = cr;
-
- uint old_state = data->window_state;
- if (!X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_VERT))
- && !X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ)))
- data->window_state &= ~Qt::WindowMaximized;
- if (!X11->isSupportedByWM(ATOM(_NET_WM_STATE_FULLSCREEN)))
- data->window_state &= ~Qt::WindowFullScreen;
-
- if (old_state != data->window_state) {
- QWindowStateChangeEvent e((Qt::WindowStates) old_state);
- QApplication::sendEvent(this, &e);
- }
-
- if (!isVisible())
- setAttribute(Qt::WA_PendingResizeEvent, true);
- wasResize = true;
- }
-
- } else {
- XEvent xevent;
- while (XCheckTypedWindowEvent(X11->display,internalWinId(), ConfigureNotify,&xevent) &&
- !qt_x11EventFilter(&xevent) &&
- !x11Event(&xevent)) // send event through filter
- ;
- }
-
- if (wasResize) {
- if (isVisible() && data->crect.size() != oldSize) {
- Q_ASSERT(d->extra->topextra);
- QWidgetBackingStore *bs = d->extra->topextra->backingStore.data();
- const bool hasStaticContents = bs && bs->hasStaticContents();
- // If we have a backing store with static contents, we have to disable the top-level
- // resize optimization in order to get invalidated regions for resized widgets.
- // The optimization discards all invalidateBuffer() calls since we're going to
- // repaint everything anyways, but that's not the case with static contents.
- if (!hasStaticContents)
- d->extra->topextra->inTopLevelResize = true;
- QResizeEvent e(data->crect.size(), oldSize);
- QApplication::sendSpontaneousEvent(this, &e);
- }
-
- const bool waitingForMapNotify = d->extra->topextra && d->extra->topextra->waitingForMapNotify;
- if (!waitingForMapNotify) {
- if (d->paintOnScreen()) {
- QRegion updateRegion(rect());
- if (testAttribute(Qt::WA_StaticContents))
- updateRegion -= QRect(0, 0, oldSize.width(), oldSize.height());
- d->syncBackingStore(updateRegion);
- } else {
- d->syncBackingStore();
- }
- }
-
- if (d->extra && d->extra->topextra)
- d->extra->topextra->inTopLevelResize = false;
- }
-#ifndef QT_NO_XSYNC
- if (QTLWExtra *tlwExtra = d->maybeTopData()) {
- if (tlwExtra->newCounterValueLo != 0 || tlwExtra->newCounterValueHi != 0) {
- XSyncValue value;
- XSyncIntsToValue(&value,
- tlwExtra->newCounterValueLo,
- tlwExtra->newCounterValueHi);
-
- XSyncSetCounter(X11->display, tlwExtra->syncUpdateCounter, value);
- tlwExtra->newCounterValueHi = 0;
- tlwExtra->newCounterValueLo = 0;
- }
- }
-#endif
- return true;
-}
-
-//
-// Close window event translation.
-//
-bool QETWidget::translateCloseEvent(const XEvent *)
-{
- Q_D(QWidget);
- return d->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent);
-}
-
-
-void QApplication::setCursorFlashTime(int msecs)
-{
- QApplicationPrivate::cursor_flash_time = msecs;
-}
-
-int QApplication::cursorFlashTime()
-{
- return QApplicationPrivate::cursor_flash_time;
-}
-
-void QApplication::setDoubleClickInterval(int ms)
-{
- QApplicationPrivate::mouse_double_click_time = ms;
-}
-
-int QApplication::doubleClickInterval()
-{
- return QApplicationPrivate::mouse_double_click_time;
-}
-
-void QApplication::setKeyboardInputInterval(int ms)
-{
- QApplicationPrivate::keyboard_input_time = ms;
-}
-
-int QApplication::keyboardInputInterval()
-{
- return QApplicationPrivate::keyboard_input_time;
-}
-
-#ifndef QT_NO_WHEELEVENT
-void QApplication::setWheelScrollLines(int n)
-{
- QApplicationPrivate::wheel_scroll_lines = n;
-}
-
-int QApplication::wheelScrollLines()
-{
- return QApplicationPrivate::wheel_scroll_lines;
-}
-#endif
-
-void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable)
-{
- switch (effect) {
- case Qt::UI_AnimateMenu:
- if (enable) QApplicationPrivate::fade_menu = false;
- QApplicationPrivate::animate_menu = enable;
- break;
- case Qt::UI_FadeMenu:
- if (enable)
- QApplicationPrivate::animate_menu = true;
- QApplicationPrivate::fade_menu = enable;
- break;
- case Qt::UI_AnimateCombo:
- QApplicationPrivate::animate_combo = enable;
- break;
- case Qt::UI_AnimateTooltip:
- if (enable) QApplicationPrivate::fade_tooltip = false;
- QApplicationPrivate::animate_tooltip = enable;
- break;
- case Qt::UI_FadeTooltip:
- if (enable)
- QApplicationPrivate::animate_tooltip = true;
- QApplicationPrivate::fade_tooltip = enable;
- break;
- case Qt::UI_AnimateToolBox:
- QApplicationPrivate::animate_toolbox = enable;
- break;
- default:
- QApplicationPrivate::animate_ui = enable;
- break;
- }
-}
-
-bool QApplication::isEffectEnabled(Qt::UIEffect effect)
-{
- if (QColormap::instance().depth() < 16 || !QApplicationPrivate::animate_ui)
- return false;
-
- switch(effect) {
- case Qt::UI_AnimateMenu:
- return QApplicationPrivate::animate_menu;
- case Qt::UI_FadeMenu:
- return QApplicationPrivate::fade_menu;
- case Qt::UI_AnimateCombo:
- return QApplicationPrivate::animate_combo;
- case Qt::UI_AnimateTooltip:
- return QApplicationPrivate::animate_tooltip;
- case Qt::UI_FadeTooltip:
- return QApplicationPrivate::fade_tooltip;
- case Qt::UI_AnimateToolBox:
- return QApplicationPrivate::animate_toolbox;
- default:
- return QApplicationPrivate::animate_ui;
- }
-}
-
-/*****************************************************************************
- Session management support
- *****************************************************************************/
-
-#ifndef QT_NO_SESSIONMANAGER
-
-QT_BEGIN_INCLUDE_NAMESPACE
-#include <X11/SM/SMlib.h>
-QT_END_INCLUDE_NAMESPACE
-
-class QSessionManagerPrivate : public QObjectPrivate
-{
-public:
- QSessionManagerPrivate(QSessionManager* mgr, QString& id, QString& key)
- : QObjectPrivate(), sm(mgr), sessionId(id), sessionKey(key),
- restartHint(QSessionManager::RestartIfRunning), eventLoop(0) {}
- QSessionManager* sm;
- QStringList restartCommand;
- QStringList discardCommand;
- QString& sessionId;
- QString& sessionKey;
- QSessionManager::RestartHint restartHint;
- QEventLoop *eventLoop;
-};
-
-class QSmSocketReceiver : public QObject
-{
- Q_OBJECT
-public:
- QSmSocketReceiver(int socket)
- {
- QSocketNotifier* sn = new QSocketNotifier(socket, QSocketNotifier::Read, this);
- connect(sn, SIGNAL(activated(int)), this, SLOT(socketActivated(int)));
- }
-
-public slots:
- void socketActivated(int);
-};
-
-
-static SmcConn smcConnection = 0;
-static bool sm_interactionActive;
-static bool sm_smActive;
-static int sm_interactStyle;
-static int sm_saveType;
-static bool sm_cancel;
-// static bool sm_waitingForPhase2; ### never used?!?
-static bool sm_waitingForInteraction;
-static bool sm_isshutdown;
-// static bool sm_shouldbefast; ### never used?!?
-static bool sm_phase2;
-static bool sm_in_phase2;
-
-static QSmSocketReceiver* sm_receiver = 0;
-
-static void resetSmState();
-static void sm_setProperty(const char* name, const char* type,
- int num_vals, SmPropValue* vals);
-static void sm_saveYourselfCallback(SmcConn smcConn, SmPointer clientData,
- int saveType, Bool shutdown , int interactStyle, Bool fast);
-static void sm_saveYourselfPhase2Callback(SmcConn smcConn, SmPointer clientData) ;
-static void sm_dieCallback(SmcConn smcConn, SmPointer clientData) ;
-static void sm_shutdownCancelledCallback(SmcConn smcConn, SmPointer clientData);
-static void sm_saveCompleteCallback(SmcConn smcConn, SmPointer clientData);
-static void sm_interactCallback(SmcConn smcConn, SmPointer clientData);
-static void sm_performSaveYourself(QSessionManagerPrivate*);
-
-static void resetSmState()
-{
-// sm_waitingForPhase2 = false; ### never used?!?
- sm_waitingForInteraction = false;
- sm_interactionActive = false;
- sm_interactStyle = SmInteractStyleNone;
- sm_smActive = false;
- qt_sm_blockUserInput = false;
- sm_isshutdown = false;
-// sm_shouldbefast = false; ### never used?!?
- sm_phase2 = false;
- sm_in_phase2 = false;
-}
-
-
-// theoretically it's possible to set several properties at once. For
-// simplicity, however, we do just one property at a time
-static void sm_setProperty(const char* name, const char* type,
- int num_vals, SmPropValue* vals)
-{
- if (num_vals) {
- SmProp prop;
- prop.name = (char*)name;
- prop.type = (char*)type;
- prop.num_vals = num_vals;
- prop.vals = vals;
-
- SmProp* props[1];
- props[0] = &prop;
- SmcSetProperties(smcConnection, 1, props);
- }
- else {
- char* names[1];
- names[0] = (char*) name;
- SmcDeleteProperties(smcConnection, 1, names);
- }
-}
-
-static void sm_setProperty(const QString& name, const QString& value)
-{
- QByteArray v = value.toUtf8();
- SmPropValue prop;
- prop.length = v.length();
- prop.value = (SmPointer) v.constData();
- sm_setProperty(name.toLatin1().data(), SmARRAY8, 1, &prop);
-}
-
-static void sm_setProperty(const QString& name, const QStringList& value)
-{
- SmPropValue *prop = new SmPropValue[value.count()];
- int count = 0;
- QList<QByteArray> vl;
- for (QStringList::ConstIterator it = value.begin(); it != value.end(); ++it) {
- prop[count].length = (*it).length();
- vl.append((*it).toUtf8());
- prop[count].value = (char*)vl.last().data();
- ++count;
- }
- sm_setProperty(name.toLatin1().data(), SmLISTofARRAY8, count, prop);
- delete [] prop;
-}
-
-
-// workaround for broken libsm, see below
-struct QT_smcConn {
- unsigned int save_yourself_in_progress : 1;
- unsigned int shutdown_in_progress : 1;
-};
-
-static void sm_saveYourselfCallback(SmcConn smcConn, SmPointer clientData,
- int saveType, Bool shutdown , int interactStyle, Bool /*fast*/)
-{
- if (smcConn != smcConnection)
- return;
- sm_cancel = false;
- sm_smActive = true;
- sm_isshutdown = shutdown;
- sm_saveType = saveType;
- sm_interactStyle = interactStyle;
-// sm_shouldbefast = fast; ### never used?!?
-
- // ugly workaround for broken libSM. libSM should do that _before_
- // actually invoking the callback in sm_process.c
- ((QT_smcConn*)smcConn)->save_yourself_in_progress = true;
- if (sm_isshutdown)
- ((QT_smcConn*)smcConn)->shutdown_in_progress = true;
-
- sm_performSaveYourself((QSessionManagerPrivate*) clientData);
- if (!sm_isshutdown) // we cannot expect a confirmation message in that case
- resetSmState();
-}
-
-static void sm_performSaveYourself(QSessionManagerPrivate* smd)
-{
- if (sm_isshutdown)
- qt_sm_blockUserInput = true;
-
- QSessionManager* sm = smd->sm;
-
- // generate a new session key
- timeval tv;
- gettimeofday(&tv, 0);
- smd->sessionKey = QString::number(qulonglong(tv.tv_sec)) + QLatin1Char('_') + QString::number(qulonglong(tv.tv_usec));
-
- QStringList arguments = qApp->arguments();
- QString argument0 = arguments.isEmpty() ? qApp->applicationFilePath() : arguments.at(0);
-
- // tell the session manager about our program in best POSIX style
- sm_setProperty(QString::fromLatin1(SmProgram), argument0);
- // tell the session manager about our user as well.
- struct passwd *entryPtr = 0;
-#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) && (_POSIX_THREAD_SAFE_FUNCTIONS - 0 > 0)
- QVarLengthArray<char, 1024> buf(qMax<long>(sysconf(_SC_GETPW_R_SIZE_MAX), 1024L));
- struct passwd entry;
- while (getpwuid_r(geteuid(), &entry, buf.data(), buf.size(), &entryPtr) == ERANGE) {
- if (buf.size() >= 32768) {
- // too big already, fail
- static char badusername[] = "";
- entryPtr = &entry;
- entry.pw_name = badusername;
- break;
- }
-
- // retry with a bigger buffer
- buf.resize(buf.size() * 2);
- }
-#else
- entryPtr = getpwuid(geteuid());
-#endif
- if (entryPtr)
- sm_setProperty(QString::fromLatin1(SmUserID), QString::fromLatin1(entryPtr->pw_name));
-
- // generate a restart and discard command that makes sense
- QStringList restart;
- restart << argument0 << QLatin1String("-session")
- << smd->sessionId + QLatin1Char('_') + smd->sessionKey;
- if (qstricmp(appName, QX11Info::appClass()) != 0)
- restart << QLatin1String("-name") << qAppName();
- sm->setRestartCommand(restart);
- QStringList discard;
- sm->setDiscardCommand(discard);
-
- switch (sm_saveType) {
- case SmSaveBoth:
- qApp->commitData(*sm);
- if (sm_isshutdown && sm_cancel)
- break; // we cancelled the shutdown, no need to save state
- // fall through
- case SmSaveLocal:
- qApp->saveState(*sm);
- break;
- case SmSaveGlobal:
- qApp->commitData(*sm);
- break;
- default:
- break;
- }
-
- if (sm_phase2 && !sm_in_phase2) {
- SmcRequestSaveYourselfPhase2(smcConnection, sm_saveYourselfPhase2Callback, (SmPointer*) smd);
- qt_sm_blockUserInput = false;
- }
- else {
- // close eventual interaction monitors and cancel the
- // shutdown, if required. Note that we can only cancel when
- // performing a shutdown, it does not work for checkpoints
- if (sm_interactionActive) {
- SmcInteractDone(smcConnection, sm_isshutdown && sm_cancel);
- sm_interactionActive = false;
- }
- else if (sm_cancel && sm_isshutdown) {
- if (sm->allowsErrorInteraction()) {
- SmcInteractDone(smcConnection, True);
- sm_interactionActive = false;
- }
- }
-
- // set restart and discard command in session manager
- sm_setProperty(QString::fromLatin1(SmRestartCommand), sm->restartCommand());
- sm_setProperty(QString::fromLatin1(SmDiscardCommand), sm->discardCommand());
-
- // set the restart hint
- SmPropValue prop;
- prop.length = sizeof(int);
- int value = sm->restartHint();
- prop.value = (SmPointer) &value;
- sm_setProperty(SmRestartStyleHint, SmCARD8, 1, &prop);
-
- // we are done
- SmcSaveYourselfDone(smcConnection, !sm_cancel);
- }
-}
-
-static void sm_dieCallback(SmcConn smcConn, SmPointer /* clientData */)
-{
- if (smcConn != smcConnection)
- return;
- resetSmState();
- QEvent quitEvent(QEvent::Quit);
- QApplication::sendEvent(qApp, &quitEvent);
-}
-
-static void sm_shutdownCancelledCallback(SmcConn smcConn, SmPointer clientData)
-{
- if (smcConn != smcConnection)
- return;
- if (sm_waitingForInteraction)
- ((QSessionManagerPrivate *) clientData)->eventLoop->exit();
- resetSmState();
-}
-
-static void sm_saveCompleteCallback(SmcConn smcConn, SmPointer /*clientData */)
-{
- if (smcConn != smcConnection)
- return;
- resetSmState();
-}
-
-static void sm_interactCallback(SmcConn smcConn, SmPointer clientData)
-{
- if (smcConn != smcConnection)
- return;
- if (sm_waitingForInteraction)
- ((QSessionManagerPrivate *) clientData)->eventLoop->exit();
-}
-
-static void sm_saveYourselfPhase2Callback(SmcConn smcConn, SmPointer clientData)
-{
- if (smcConn != smcConnection)
- return;
- sm_in_phase2 = true;
- sm_performSaveYourself((QSessionManagerPrivate*) clientData);
-}
-
-
-void QSmSocketReceiver::socketActivated(int)
-{
- IceProcessMessages(SmcGetIceConnection(smcConnection), 0, 0);
-}
-
-
-#undef Bool
-QT_BEGIN_INCLUDE_NAMESPACE
-#include "qapplication_x11.moc"
-QT_END_INCLUDE_NAMESPACE
-
-QSessionManager::QSessionManager(QApplication * app, QString &id, QString& key)
- : QObject(*new QSessionManagerPrivate(this, id, key), app)
-{
- Q_D(QSessionManager);
- d->restartHint = RestartIfRunning;
-
- resetSmState();
- char cerror[256];
- char* myId = 0;
- QByteArray b_id = id.toLatin1();
- char* prevId = b_id.data();
-
- SmcCallbacks cb;
- cb.save_yourself.callback = sm_saveYourselfCallback;
- cb.save_yourself.client_data = (SmPointer) d;
- cb.die.callback = sm_dieCallback;
- cb.die.client_data = (SmPointer) d;
- cb.save_complete.callback = sm_saveCompleteCallback;
- cb.save_complete.client_data = (SmPointer) d;
- cb.shutdown_cancelled.callback = sm_shutdownCancelledCallback;
- cb.shutdown_cancelled.client_data = (SmPointer) d;
-
- // avoid showing a warning message below
- if (qgetenv("SESSION_MANAGER").isEmpty())
- return;
-
- smcConnection = SmcOpenConnection(0, 0, 1, 0,
- SmcSaveYourselfProcMask |
- SmcDieProcMask |
- SmcSaveCompleteProcMask |
- SmcShutdownCancelledProcMask,
- &cb,
- prevId,
- &myId,
- 256, cerror);
-
- id = QString::fromLatin1(myId);
- ::free(myId); // it was allocated by C
-
- QString error = QString::fromLocal8Bit(cerror);
- if (!smcConnection) {
- qWarning("Qt: Session management error: %s", qPrintable(error));
- }
- else {
- sm_receiver = new QSmSocketReceiver(IceConnectionNumber(SmcGetIceConnection(smcConnection)));
- }
-}
-
-QSessionManager::~QSessionManager()
-{
- if (smcConnection)
- SmcCloseConnection(smcConnection, 0, 0);
- smcConnection = 0;
- delete sm_receiver;
-}
-
-QString QSessionManager::sessionId() const
-{
- Q_D(const QSessionManager);
- return d->sessionId;
-}
-
-QString QSessionManager::sessionKey() const
-{
- Q_D(const QSessionManager);
- return d->sessionKey;
-}
-
-
-void* QSessionManager::handle() const
-{
- return (void*) smcConnection;
-}
-
-
-bool QSessionManager::allowsInteraction()
-{
- Q_D(QSessionManager);
- if (sm_interactionActive)
- return true;
-
- if (sm_waitingForInteraction)
- return false;
-
- if (sm_interactStyle == SmInteractStyleAny) {
- sm_waitingForInteraction = SmcInteractRequest(smcConnection, SmDialogNormal,
- sm_interactCallback, (SmPointer*) d);
- }
- if (sm_waitingForInteraction) {
- QEventLoop eventLoop;
- d->eventLoop = &eventLoop;
- (void) eventLoop.exec();
- d->eventLoop = 0;
-
- sm_waitingForInteraction = false;
- if (sm_smActive) { // not cancelled
- sm_interactionActive = true;
- qt_sm_blockUserInput = false;
- return true;
- }
- }
- return false;
-}
-
-bool QSessionManager::allowsErrorInteraction()
-{
- Q_D(QSessionManager);
- if (sm_interactionActive)
- return true;
-
- if (sm_waitingForInteraction)
- return false;
-
- if (sm_interactStyle == SmInteractStyleAny || sm_interactStyle == SmInteractStyleErrors) {
- sm_waitingForInteraction = SmcInteractRequest(smcConnection, SmDialogError,
- sm_interactCallback, (SmPointer*) d);
- }
- if (sm_waitingForInteraction) {
- QEventLoop eventLoop;
- d->eventLoop = &eventLoop;
- (void) eventLoop.exec();
- d->eventLoop = 0;
-
- sm_waitingForInteraction = false;
- if (sm_smActive) { // not cancelled
- sm_interactionActive = true;
- qt_sm_blockUserInput = false;
- return true;
- }
- }
- return false;
-}
-
-void QSessionManager::release()
-{
- if (sm_interactionActive) {
- SmcInteractDone(smcConnection, False);
- sm_interactionActive = false;
- if (sm_smActive && sm_isshutdown)
- qt_sm_blockUserInput = true;
- }
-}
-
-void QSessionManager::cancel()
-{
- sm_cancel = true;
-}
-
-void QSessionManager::setRestartHint(QSessionManager::RestartHint hint)
-{
- Q_D(QSessionManager);
- d->restartHint = hint;
-}
-
-QSessionManager::RestartHint QSessionManager::restartHint() const
-{
- Q_D(const QSessionManager);
- return d->restartHint;
-}
-
-void QSessionManager::setRestartCommand(const QStringList& command)
-{
- Q_D(QSessionManager);
- d->restartCommand = command;
-}
-
-QStringList QSessionManager::restartCommand() const
-{
- Q_D(const QSessionManager);
- return d->restartCommand;
-}
-
-void QSessionManager::setDiscardCommand(const QStringList& command)
-{
- Q_D(QSessionManager);
- d->discardCommand = command;
-}
-
-QStringList QSessionManager::discardCommand() const
-{
- Q_D(const QSessionManager);
- return d->discardCommand;
-}
-
-void QSessionManager::setManagerProperty(const QString& name, const QString& value)
-{
- sm_setProperty(name, value);
-}
-
-void QSessionManager::setManagerProperty(const QString& name, const QStringList& value)
-{
- sm_setProperty(name, value);
-}
-
-bool QSessionManager::isPhase2() const
-{
- return sm_in_phase2;
-}
-
-void QSessionManager::requestPhase2()
-{
- sm_phase2 = true;
-}
-
-#endif // QT_NO_SESSIONMANAGER
-
-#if defined(QT_RX71_MULTITOUCH)
-
-static inline int testBit(const char *array, int bit)
-{
- return (array[bit/8] & (1<<(bit%8)));
-}
-
-static int openRX71Device(const QByteArray &deviceName)
-{
- int fd = open(deviceName, O_RDONLY | O_NONBLOCK);
- if (fd == -1) {
- fd = -errno;
- return fd;
- }
-
- // fetch the event type mask and check that the device reports absolute coordinates
- char eventTypeMask[(EV_MAX + sizeof(char) - 1) * sizeof(char) + 1];
- memset(eventTypeMask, 0, sizeof(eventTypeMask));
- if (ioctl(fd, EVIOCGBIT(0, sizeof(eventTypeMask)), eventTypeMask) < 0) {
- close(fd);
- return -1;
- }
- if (!testBit(eventTypeMask, EV_ABS)) {
- close(fd);
- return -1;
- }
-
- // make sure that we can get the absolute X and Y positions from the device
- char absMask[(ABS_MAX + sizeof(char) - 1) * sizeof(char) + 1];
- memset(absMask, 0, sizeof(absMask));
- if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absMask)), absMask) < 0) {
- close(fd);
- return -1;
- }
- if (!testBit(absMask, ABS_X) || !testBit(absMask, ABS_Y)) {
- close(fd);
- return -1;
- }
-
- return fd;
-}
-
-void QApplicationPrivate::initializeMultitouch_sys()
-{
- Q_Q(QApplication);
-
- QByteArray deviceName = QByteArray("/dev/input/event");
- int currentDeviceNumber = 0;
- for (;;) {
- int fd = openRX71Device(QByteArray(deviceName + QByteArray::number(currentDeviceNumber++)));
- if (fd == -ENOENT) {
- // no more devices
- break;
- }
- if (fd < 0) {
- // not a touch device
- continue;
- }
-
- struct input_absinfo abs_x, abs_y, abs_z;
- ioctl(fd, EVIOCGABS(ABS_X), &abs_x);
- ioctl(fd, EVIOCGABS(ABS_Y), &abs_y);
- ioctl(fd, EVIOCGABS(ABS_Z), &abs_z);
-
- int deviceNumber = allRX71TouchPoints.count();
-
- QSocketNotifier *socketNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, q);
- QObject::connect(socketNotifier, SIGNAL(activated(int)), q, SLOT(_q_readRX71MultiTouchEvents()));
-
- RX71TouchPointState touchPointState = {
- socketNotifier,
- QTouchEvent::TouchPoint(deviceNumber),
-
- abs_x.minimum, abs_x.maximum, q->desktop()->screenGeometry().width(),
- abs_y.minimum, abs_y.maximum, q->desktop()->screenGeometry().height(),
- abs_z.minimum, abs_z.maximum
- };
- allRX71TouchPoints.append(touchPointState);
- }
-
- hasRX71MultiTouch = allRX71TouchPoints.count() > 1;
- if (!hasRX71MultiTouch) {
- for (int i = 0; i < allRX71TouchPoints.count(); ++i) {
- QSocketNotifier *socketNotifier = allRX71TouchPoints.at(i).socketNotifier;
- close(socketNotifier->socket());
- delete socketNotifier;
- }
- allRX71TouchPoints.clear();
- }
-}
-
-void QApplicationPrivate::cleanupMultitouch_sys()
-{
- hasRX71MultiTouch = false;
- for (int i = 0; i < allRX71TouchPoints.count(); ++i) {
- QSocketNotifier *socketNotifier = allRX71TouchPoints.at(i).socketNotifier;
- close(socketNotifier->socket());
- delete socketNotifier;
- }
- allRX71TouchPoints.clear();
-}
-
-bool QApplicationPrivate::readRX71MultiTouchEvents(int deviceNumber)
-{
- RX71TouchPointState &touchPointState = allRX71TouchPoints[deviceNumber];
- QSocketNotifier *socketNotifier = touchPointState.socketNotifier;
- int fd = socketNotifier->socket();
-
- QTouchEvent::TouchPoint &touchPoint = touchPointState.touchPoint;
-
- bool down = touchPoint.state() != Qt::TouchPointReleased;
- if (down)
- touchPoint.setState(Qt::TouchPointStationary);
-
- bool changed = false;
- for (;;) {
- struct input_event inputEvent;
- int bytesRead = read(fd, &inputEvent, sizeof(inputEvent));
- if (bytesRead <= 0)
- break;
- if (bytesRead != sizeof(inputEvent)) {
- qWarning("Qt: INTERNAL ERROR: short read in readRX71MultiTouchEvents()");
- return false;
- }
-
- switch (inputEvent.type) {
- case EV_SYN:
- changed = true;
- switch (touchPoint.state()) {
- case Qt::TouchPointPressed:
- case Qt::TouchPointReleased:
- // make sure we don't compress pressed and releases with any other events
- return changed;
- default:
- break;
- }
- continue;
- case EV_KEY:
- case EV_ABS:
- break;
- default:
- qWarning("Qt: WARNING: unknown event type %d on multitouch device", inputEvent.type);
- continue;
- }
-
- QPointF screenPos = touchPoint.screenPos();
- switch (inputEvent.code) {
- case BTN_TOUCH:
- if (!down && inputEvent.value != 0)
- touchPoint.setState(Qt::TouchPointPressed);
- else if (down && inputEvent.value == 0)
- touchPoint.setState(Qt::TouchPointReleased);
- break;
- case ABS_TOOL_WIDTH:
- case ABS_VOLUME:
- case ABS_PRESSURE:
- // ignore for now
- break;
- case ABS_X:
- {
- qreal newValue = ((qreal(inputEvent.value - touchPointState.minX)
- / qreal(touchPointState.maxX - touchPointState.minX))
- * touchPointState.scaleX);
- screenPos.rx() = newValue;
- touchPoint.setScreenPos(screenPos);
- break;
- }
- case ABS_Y:
- {
- qreal newValue = ((qreal(inputEvent.value - touchPointState.minY)
- / qreal(touchPointState.maxY - touchPointState.minY))
- * touchPointState.scaleY);
- screenPos.ry() = newValue;
- touchPoint.setScreenPos(screenPos);
- break;
- }
- case ABS_Z:
- {
- // map Z (signal strength) to pressure for now
- qreal newValue = (qreal(inputEvent.value - touchPointState.minZ)
- / qreal(touchPointState.maxZ - touchPointState.minZ));
- touchPoint.setPressure(newValue);
- break;
- }
- default:
- qWarning("Qt: WARNING: unknown event code %d on multitouch device", inputEvent.code);
- continue;
- }
- }
-
- if (down && touchPoint.state() != Qt::TouchPointReleased)
- touchPoint.setState(changed ? Qt::TouchPointMoved : Qt::TouchPointStationary);
-
- return changed;
-}
-
-void QApplicationPrivate::_q_readRX71MultiTouchEvents()
-{
- // read touch events from all devices
- bool changed = false;
- for (int i = 0; i < allRX71TouchPoints.count(); ++i)
- changed = readRX71MultiTouchEvents(i) || changed;
- if (!changed)
- return;
-
- QList<QTouchEvent::TouchPoint> touchPoints;
- for (int i = 0; i < allRX71TouchPoints.count(); ++i)
- touchPoints.append(allRX71TouchPoints.at(i).touchPoint);
-
- translateRawTouchEvent(0, QTouchEvent::TouchScreen, touchPoints);
-}
-
-#else // !QT_RX71_MULTITOUCH
-
-void QApplicationPrivate::initializeMultitouch_sys()
-{ }
-void QApplicationPrivate::cleanupMultitouch_sys()
-{ }
-
-#endif // QT_RX71_MULTITOUCH
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qcocoaapplication_mac.mm b/src/gui/kernel/qcocoaapplication_mac.mm
deleted file mode 100644
index 872f31dec7..0000000000
--- a/src/gui/kernel/qcocoaapplication_mac.mm
+++ /dev/null
@@ -1,222 +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$
-**
-****************************************************************************/
-
-/****************************************************************************
-**
-** Copyright (c) 2007-2008, Apple, Inc.
-**
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-**
-** * Redistributions of source code must retain the above copyright notice,
-** this list of conditions and the following disclaimer.
-**
-** * Redistributions in binary form must reproduce the above copyright notice,
-** this list of conditions and the following disclaimer in the documentation
-** and/or other materials provided with the distribution.
-**
-** * Neither the name of Apple, Inc. nor the names of its contributors
-** may be used to endorse or promote products derived from this software
-** without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-****************************************************************************/
-
-#include <qglobal.h>
-#ifdef QT_MAC_USE_COCOA
-#include <private/qcocoaapplication_mac_p.h>
-#include <private/qcocoaapplicationdelegate_mac_p.h>
-#include <private/qt_cocoa_helpers_mac_p.h>
-#include <private/qcocoaintrospection_p.h>
-
-QT_USE_NAMESPACE
-
-@implementation NSApplication (QT_MANGLE_NAMESPACE(QApplicationIntegration))
-
-- (void)QT_MANGLE_NAMESPACE(qt_setDockMenu):(NSMenu *)newMenu
-{
- [[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate] setDockMenu:newMenu];
-}
-
-- (QApplicationPrivate *)QT_MANGLE_NAMESPACE(qt_qappPrivate)
-{
- return [[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate] qAppPrivate];
-}
-
-- (QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)
-{
- return [[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate] menuLoader];
-}
-
-- (int)QT_MANGLE_NAMESPACE(qt_validModesForFontPanel):(NSFontPanel *)fontPanel
-{
- Q_UNUSED(fontPanel);
- // only display those things that QFont can handle
- return NSFontPanelFaceModeMask
- | NSFontPanelSizeModeMask
- | NSFontPanelCollectionModeMask
- | NSFontPanelUnderlineEffectModeMask
- | NSFontPanelStrikethroughEffectModeMask;
-}
-
-- (void)qt_sendPostedMessage:(NSEvent *)event
-{
- // WARNING: data1 and data2 is truncated to from 64-bit to 32-bit on OS 10.5!
- // That is why we need to split the address in two parts:
- quint64 lower = [event data1];
- quint64 upper = [event data2];
- QCocoaPostMessageArgs *args = reinterpret_cast<QCocoaPostMessageArgs *>(lower | (upper << 32));
- // Special case for convenience: if the argument is an NSNumber, we unbox it directly.
- // Use NSValue instead if this behaviour is unwanted.
- id a1 = ([args->arg1 isKindOfClass:[NSNumber class]]) ? (id)[args->arg1 intValue] : args->arg1;
- id a2 = ([args->arg2 isKindOfClass:[NSNumber class]]) ? (id)[args->arg2 intValue] : args->arg2;
- switch (args->argCount) {
- case 0:
- [args->target performSelector:args->selector];
- break;
- case 1:
- [args->target performSelector:args->selector withObject:a1];
- break;
- case 3:
- [args->target performSelector:args->selector withObject:a1 withObject:a2];
- break;
- }
-
- delete args;
-}
-
-- (BOOL)qt_filterEvent:(NSEvent *)event
-{
- if (qApp->macEventFilter(0, reinterpret_cast<EventRef>(event)))
- return true;
-
- if ([event type] == NSApplicationDefined) {
- switch ([event subtype]) {
- case QtCocoaEventSubTypePostMessage:
- [NSApp qt_sendPostedMessage:event];
- return true;
- default:
- break;
- }
- }
- return false;
-}
-
-@end
-
-@implementation QNSApplication
-
-- (void)qt_sendEvent_original:(NSEvent *)event
-{
- Q_UNUSED(event);
- // This method will only be used as a signature
- // template for the method we add into NSApplication
- // containing the original [NSApplication sendEvent:] implementation
-}
-
-- (void)qt_sendEvent_replacement:(NSEvent *)event
-{
- // This method (or its implementation to be precise) will
- // be called instead of sendEvent if redirection occurs.
- // 'self' will then be an instance of NSApplication
- // (and not QNSApplication)
- if (![NSApp qt_filterEvent:event])
- [self qt_sendEvent_original:event];
-}
-
-- (void)sendEvent:(NSEvent *)event
-{
- // This method will be called if
- // no redirection occurs
- if (![NSApp qt_filterEvent:event])
- [super sendEvent:event];
-}
-
-- (void)qtDispatcherToQAction:(id)sender
-{
- // Forward actions sendt from the menu bar (e.g. quit) to the menu loader.
- // Having this method here means that we are the last stop in the responder
- // chain, and that we are able to handle menu actions even when no window is
- // visible on screen. Note: If Qt is used as a plugin, Qt will not use a
- // native menu bar. Hence, we will also not need to do any redirection etc. as
- // we do with sendEvent.
- [[NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)] qtDispatcherToQAction:sender];
-}
-
-@end
-
-QT_BEGIN_NAMESPACE
-
-void qt_redirectNSApplicationSendEvent()
-{
- if ([NSApp isMemberOfClass:[QNSApplication class]]) {
- // No need to change implementation since Qt
- // already controls a subclass of NSApplication
- return;
- }
-
- // Change the implementation of [NSApplication sendEvent] to the
- // implementation of qt_sendEvent_replacement found in QNSApplication.
- // And keep the old implementation that gets overwritten inside a new
- // method 'qt_sendEvent_original' that we add to NSApplication
- qt_cocoa_change_implementation(
- [NSApplication class],
- @selector(sendEvent:),
- [QNSApplication class],
- @selector(qt_sendEvent_replacement:),
- @selector(qt_sendEvent_original:));
- }
-
-QT_END_NAMESPACE
-#endif
diff --git a/src/gui/kernel/qcocoaapplication_mac_p.h b/src/gui/kernel/qcocoaapplication_mac_p.h
deleted file mode 100644
index 0c3f5e442d..0000000000
--- a/src/gui/kernel/qcocoaapplication_mac_p.h
+++ /dev/null
@@ -1,117 +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$
-**
-****************************************************************************/
-
-/****************************************************************************
-**
-** Copyright (c) 2007-2008, Apple, Inc.
-**
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-**
-** * Redistributions of source code must retain the above copyright notice,
-** this list of conditions and the following disclaimer.
-**
-** * Redistributions in binary form must reproduce the above copyright notice,
-** this list of conditions and the following disclaimer in the documentation
-** and/or other materials provided with the distribution.
-**
-** * Neither the name of Apple, Inc. nor the names of its contributors
-** may be used to endorse or promote products derived from this software
-** without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp
-// and many other. This header file may change from version to version
-// without notice, or even be removed.
-//
-// We mean it.
-//
-
-/*
- Cocoa Application Categories
-*/
-#include "qmacdefines_mac.h"
-#ifdef QT_MAC_USE_COCOA
-#import <AppKit/AppKit.h>
-QT_FORWARD_DECLARE_CLASS(QApplicationPrivate)
-@class QT_MANGLE_NAMESPACE(QCocoaMenuLoader);
-
-@interface NSApplication (QT_MANGLE_NAMESPACE(QApplicationIntegration))
-- (void)QT_MANGLE_NAMESPACE(qt_setDockMenu):(NSMenu *)newMenu;
-- (QApplicationPrivate *)QT_MANGLE_NAMESPACE(qt_qappPrivate);
-- (QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader);
-- (int)QT_MANGLE_NAMESPACE(qt_validModesForFontPanel):(NSFontPanel *)fontPanel;
-
-- (void)qt_sendPostedMessage:(NSEvent *)event;
-- (BOOL)qt_filterEvent:(NSEvent *)event;
-@end
-
-@interface QNSApplication : NSApplication {
-}
-@end
-
-QT_BEGIN_NAMESPACE
-
-void qt_redirectNSApplicationSendEvent();
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm
deleted file mode 100644
index 77cd8902c3..0000000000
--- a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm
+++ /dev/null
@@ -1,354 +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$
-**
-****************************************************************************/
-
-/****************************************************************************
- **
- ** Copyright (c) 2007-2008, Apple, Inc.
- **
- ** All rights reserved.
- **
- ** Redistribution and use in source and binary forms, with or without
- ** modification, are permitted provided that the following conditions are met:
- **
- ** * Redistributions of source code must retain the above copyright notice,
- ** this list of conditions and the following disclaimer.
- **
- ** * Redistributions in binary form must reproduce the above copyright notice,
- ** this list of conditions and the following disclaimer in the documentation
- ** and/or other materials provided with the distribution.
- **
- ** * Neither the name of Apple, Inc. nor the names of its contributors
- ** may be used to endorse or promote products derived from this software
- ** without specific prior written permission.
- **
- ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- **
- ****************************************************************************/
-
-#include "qmacdefines_mac.h"
-#ifdef QT_MAC_USE_COCOA
-
-#import <private/qcocoaapplicationdelegate_mac_p.h>
-#import <private/qcocoamenuloader_mac_p.h>
-#import <private/qcocoaapplication_mac_p.h>
-#include <private/qapplication_p.h>
-#include <private/qt_mac_p.h>
-#include <private/qt_cocoa_helpers_mac_p.h>
-#include <private/qdesktopwidget_mac_p.h>
-#include <qevent.h>
-#include <qurl.h>
-#include <qapplication.h>
-
-QT_BEGIN_NAMESPACE
-extern void onApplicationChangedActivation(bool); // qapplication_mac.mm
-extern void qt_release_apple_event_handler(); //qapplication_mac.mm
-extern QPointer<QWidget> qt_last_mouse_receiver; // qapplication_mac.cpp
-extern QPointer<QWidget> qt_last_native_mouse_receiver; // qt_cocoa_helpers_mac.mm
-extern QPointer<QWidget> qt_button_down; // qapplication_mac.cpp
-
-QT_END_NAMESPACE
-
-QT_FORWARD_DECLARE_CLASS(QDesktopWidgetImplementation)
-QT_USE_NAMESPACE
-
-static QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) *sharedCocoaApplicationDelegate = nil;
-
-static void cleanupCocoaApplicationDelegate()
-{
- [sharedCocoaApplicationDelegate release];
-}
-
-@implementation QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate)
-
-- (id)init
-{
- self = [super init];
- if (self)
- inLaunch = true;
- return self;
-}
-
-- (void)dealloc
-{
- sharedCocoaApplicationDelegate = nil;
- [dockMenu release];
- [qtMenuLoader release];
- if (reflectionDelegate) {
- [NSApp setDelegate:reflectionDelegate];
- [reflectionDelegate release];
- }
- [super dealloc];
-}
-
-+ (id)allocWithZone:(NSZone *)zone
-{
- @synchronized(self) {
- if (sharedCocoaApplicationDelegate == nil) {
- sharedCocoaApplicationDelegate = [super allocWithZone:zone];
- return sharedCocoaApplicationDelegate;
- qAddPostRoutine(cleanupCocoaApplicationDelegate);
- }
- }
- return nil;
-}
-
-+ (QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate)*)sharedDelegate
-{
- @synchronized(self) {
- if (sharedCocoaApplicationDelegate == nil)
- [[self alloc] init];
- }
- return [[sharedCocoaApplicationDelegate retain] autorelease];
-}
-
-- (void)setDockMenu:(NSMenu*)newMenu
-{
- [newMenu retain];
- [dockMenu release];
- dockMenu = newMenu;
-}
-
-- (NSMenu *)applicationDockMenu
-{
- return [[dockMenu retain] autorelease];
-}
-
-- (QApplicationPrivate *)qAppPrivate
-{
- return qtPrivate;
-}
-
-- (void)setQtPrivate:(QApplicationPrivate *)value
-{
- qtPrivate = value;
-}
-
-- (void)setMenuLoader:(QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)menuLoader
-{
- [menuLoader retain];
- [qtMenuLoader release];
- qtMenuLoader = menuLoader;
-}
-
-- (QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)menuLoader
-{
- return [[qtMenuLoader retain] autorelease];
-}
-
-// This function will only be called when NSApp is actually running. Before
-// that, the kAEQuitApplication Apple event will be sent to
-// QApplicationPrivate::globalAppleEventProcessor in qapplication_mac.mm
-- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
-{
- Q_UNUSED(sender);
- // The reflection delegate gets precedence
- if (reflectionDelegate
- && [reflectionDelegate respondsToSelector:@selector(applicationShouldTerminate:)]) {
- return [reflectionDelegate applicationShouldTerminate:sender];
- }
-
- if (qtPrivate->canQuit()) {
- if (!startedQuit) {
- startedQuit = true;
- qAppInstance()->quit();
- startedQuit = false;
- }
- }
-
- if (qtPrivate->threadData->eventLoops.size() == 0) {
- // INVARIANT: No event loop is executing. This probably
- // means that Qt is used as a plugin, or as a part of a native
- // Cocoa application. In any case it should be fine to
- // terminate now:
- return NSTerminateNow;
- }
-
- return NSTerminateCancel;
-}
-
-- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
-{
- Q_UNUSED(aNotification);
- inLaunch = false;
- qt_release_apple_event_handler();
-}
-
-- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames
-{
- for (NSString *fileName in filenames) {
- QString qtFileName = qt_mac_NSStringToQString(fileName);
- if (inLaunch) {
- // We need to be careful because Cocoa will be nice enough to take
- // command line arguments and send them to us as events. Given the history
- // of Qt Applications, this will result in behavior people don't want, as
- // they might be doing the opening themselves with the command line parsing.
- if (qApp->arguments().contains(qtFileName))
- continue;
- }
- QFileOpenEvent foe(qtFileName);
- qt_sendSpontaneousEvent(qAppInstance(), &foe);
- }
-
- if (reflectionDelegate &&
- [reflectionDelegate respondsToSelector:@selector(application:openFiles:)])
- [reflectionDelegate application:sender openFiles:filenames];
-}
-
-- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
-{
- // If we have a reflection delegate, that will get to call the shots.
- if (reflectionDelegate
- && [reflectionDelegate respondsToSelector:
- @selector(applicationShouldTerminateAfterLastWindowClosed:)])
- return [reflectionDelegate applicationShouldTerminateAfterLastWindowClosed:sender];
- return NO; // Someday qApp->quitOnLastWindowClosed(); when QApp and NSApp work closer together.
-}
-
-
-- (void)applicationDidBecomeActive:(NSNotification *)notification
-{
- if (reflectionDelegate
- && [reflectionDelegate respondsToSelector:@selector(applicationDidBecomeActive:)])
- [reflectionDelegate applicationDidBecomeActive:notification];
-
- onApplicationChangedActivation(true);
-
- if (!QWidget::mouseGrabber()){
- // Update enter/leave immidiatly, don't wait for a move event. But only
- // if no grab exists (even if the grab points to this widget, it seems, ref X11)
- QPoint qlocal, qglobal;
- QWidget *widgetUnderMouse = 0;
- qt_mac_getTargetForMouseEvent(0, QEvent::Enter, qlocal, qglobal, 0, &widgetUnderMouse);
- QApplicationPrivate::dispatchEnterLeave(widgetUnderMouse, 0);
- qt_last_mouse_receiver = widgetUnderMouse;
- qt_last_native_mouse_receiver = widgetUnderMouse ?
- (widgetUnderMouse->internalWinId() ? widgetUnderMouse : widgetUnderMouse->nativeParentWidget()) : 0;
- }
-}
-
-- (void)applicationDidResignActive:(NSNotification *)notification
-{
- if (reflectionDelegate
- && [reflectionDelegate respondsToSelector:@selector(applicationDidResignActive:)])
- [reflectionDelegate applicationDidResignActive:notification];
-
- onApplicationChangedActivation(false);
-
- if (!QWidget::mouseGrabber())
- QApplicationPrivate::dispatchEnterLeave(0, qt_last_mouse_receiver);
- qt_last_mouse_receiver = 0;
- qt_last_native_mouse_receiver = 0;
- qt_button_down = 0;
-}
-
-- (void)applicationDidChangeScreenParameters:(NSNotification *)notification
-{
- Q_UNUSED(notification);
- QDesktopWidgetImplementation::instance()->onResize();
-}
-
-- (void)setReflectionDelegate:(NSObject <NSApplicationDelegate> *)oldDelegate
-{
- [oldDelegate retain];
- [reflectionDelegate release];
- reflectionDelegate = oldDelegate;
-}
-
-- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
-{
- NSMethodSignature *result = [super methodSignatureForSelector:aSelector];
- if (!result && reflectionDelegate) {
- result = [reflectionDelegate methodSignatureForSelector:aSelector];
- }
- return result;
-}
-
-- (BOOL)respondsToSelector:(SEL)aSelector
-{
- BOOL result = [super respondsToSelector:aSelector];
- if (!result && reflectionDelegate)
- result = [reflectionDelegate respondsToSelector:aSelector];
- return result;
-}
-
-- (void)forwardInvocation:(NSInvocation *)invocation
-{
- SEL invocationSelector = [invocation selector];
- if (reflectionDelegate && [reflectionDelegate respondsToSelector:invocationSelector])
- [invocation invokeWithTarget:reflectionDelegate];
- else
- [self doesNotRecognizeSelector:invocationSelector];
-}
-
-- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
-{
- Q_UNUSED(replyEvent);
-
- NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
- QUrl url(qt_mac_NSStringToQString(urlString));
- QFileOpenEvent qtEvent(url);
- qt_sendSpontaneousEvent(qAppInstance(), &qtEvent);
-}
-
-- (void)appleEventQuit:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
-{
- Q_UNUSED(event);
- Q_UNUSED(replyEvent);
- [NSApp terminate:self];
-}
-
-- (void)qtDispatcherToQAction:(id)sender
-{
- [[NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)] qtDispatcherToQAction:sender];
-}
-
-@end
-#endif
diff --git a/src/gui/kernel/qcocoaapplicationdelegate_mac_p.h b/src/gui/kernel/qcocoaapplicationdelegate_mac_p.h
deleted file mode 100644
index 714c046f48..0000000000
--- a/src/gui/kernel/qcocoaapplicationdelegate_mac_p.h
+++ /dev/null
@@ -1,128 +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$
-**
-****************************************************************************/
-
-
-/****************************************************************************
- **
- ** Copyright (c) 2007-2008, Apple, Inc.
- **
- ** All rights reserved.
- **
- ** Redistribution and use in source and binary forms, with or without
- ** modification, are permitted provided that the following conditions are met:
- **
- ** * Redistributions of source code must retain the above copyright notice,
- ** this list of conditions and the following disclaimer.
- **
- ** * Redistributions in binary form must reproduce the above copyright notice,
- ** this list of conditions and the following disclaimer in the documentation
- ** and/or other materials provided with the distribution.
- **
- ** * Neither the name of Apple, Inc. nor the names of its contributors
- ** may be used to endorse or promote products derived from this software
- ** without specific prior written permission.
- **
- ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- **
- ****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp
-// and many other. This header file may change from version to version
-// without notice, or even be removed.
-//
-// We mean it.
-//
-
-
-#include "qmacdefines_mac.h"
-#ifdef QT_MAC_USE_COCOA
-#import <Cocoa/Cocoa.h>
-
-QT_FORWARD_DECLARE_CLASS(QApplicationPrivate);
-
-@class QT_MANGLE_NAMESPACE(QCocoaMenuLoader);
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5
-
-@protocol NSApplicationDelegate <NSObject>
-- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
-- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
-- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames;
-- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender;
-- (void)applicationDidBecomeActive:(NSNotification *)notification;
-- (void)applicationDidResignActive:(NSNotification *)notification;
-@end
-
-#endif
-
-@interface QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) : NSObject <NSApplicationDelegate> {
- bool startedQuit;
- QApplicationPrivate *qtPrivate;
- NSMenu *dockMenu;
- QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader;
- NSObject <NSApplicationDelegate> *reflectionDelegate;
- bool inLaunch;
-}
-+ (QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate)*)sharedDelegate;
-- (void)setDockMenu:(NSMenu *)newMenu;
-- (void)setQtPrivate:(QApplicationPrivate *)value;
-- (QApplicationPrivate *)qAppPrivate;
-- (void)setMenuLoader:(QT_MANGLE_NAMESPACE(QCocoaMenuLoader)*)menuLoader;
-- (QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)menuLoader;
-- (void)setReflectionDelegate:(NSObject <NSApplicationDelegate> *)oldDelegate;
-- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
-@end
-#endif
diff --git a/src/gui/kernel/qcocoaintrospection_mac.mm b/src/gui/kernel/qcocoaintrospection_mac.mm
deleted file mode 100644
index 70c893aeec..0000000000
--- a/src/gui/kernel/qcocoaintrospection_mac.mm
+++ /dev/null
@@ -1,125 +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$
-**
-****************************************************************************/
-
-/****************************************************************************
-**
-** Copyright (c) 2007-2008, Apple, Inc.
-**
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-**
-** * Redistributions of source code must retain the above copyright notice,
-** this list of conditions and the following disclaimer.
-**
-** * Redistributions in binary form must reproduce the above copyright notice,
-** this list of conditions and the following disclaimer in the documentation
-** and/or other materials provided with the distribution.
-**
-** * Neither the name of Apple, Inc. nor the names of its contributors
-** may be used to endorse or promote products derived from this software
-** without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-****************************************************************************/
-
-#include <private/qcocoaintrospection_p.h>
-
-QT_BEGIN_NAMESPACE
-
-void qt_cocoa_change_implementation(Class baseClass, SEL originalSel, Class proxyClass, SEL replacementSel, SEL backupSel)
-{
-#ifndef QT_MAC_USE_COCOA
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5)
-#endif
- {
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
- // The following code replaces the _implementation_ for the selector we want to hack
- // (originalSel) with the implementation found in proxyClass. Then it creates
- // a new 'backup' method inside baseClass containing the old, original,
- // implementation (fakeSel). You can let the proxy implementation of originalSel
- // call fakeSel if needed (similar approach to calling a super class implementation).
- // fakeSel must also be implemented in proxyClass, as the signature is used
- // as template for the method one we add into baseClass.
- // NB: You will typically never create any instances of proxyClass; we use it
- // only for stealing its contents and put it into baseClass.
- if (!replacementSel)
- replacementSel = originalSel;
-
- Method originalMethod = class_getInstanceMethod(baseClass, originalSel);
- Method replacementMethod = class_getInstanceMethod(proxyClass, replacementSel);
- IMP originalImp = method_setImplementation(originalMethod, method_getImplementation(replacementMethod));
-
- if (backupSel) {
- Method backupMethod = class_getInstanceMethod(proxyClass, backupSel);
- class_addMethod(baseClass, backupSel, originalImp, method_getTypeEncoding(backupMethod));
- }
-#endif
- }
-}
-
-void qt_cocoa_change_back_implementation(Class baseClass, SEL originalSel, SEL backupSel)
-{
-#ifndef QT_MAC_USE_COCOA
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5)
-#endif
- {
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
- Method originalMethod = class_getInstanceMethod(baseClass, originalSel);
- Method backupMethodInBaseClass = class_getInstanceMethod(baseClass, backupSel);
- method_setImplementation(originalMethod, method_getImplementation(backupMethodInBaseClass));
-#endif
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qcocoaintrospection_p.h b/src/gui/kernel/qcocoaintrospection_p.h
deleted file mode 100644
index 1c7d6ac13c..0000000000
--- a/src/gui/kernel/qcocoaintrospection_p.h
+++ /dev/null
@@ -1,84 +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$
-**
-****************************************************************************/
-
-/****************************************************************************
-**
-** Copyright (c) 2007-2008, Apple, Inc.
-**
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-**
-** * Redistributions of source code must retain the above copyright notice,
-** this list of conditions and the following disclaimer.
-**
-** * Redistributions in binary form must reproduce the above copyright notice,
-** this list of conditions and the following disclaimer in the documentation
-** and/or other materials provided with the distribution.
-**
-** * Neither the name of Apple, Inc. nor the names of its contributors
-** may be used to endorse or promote products derived from this software
-** without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-****************************************************************************/
-
-#include <qglobal.h>
-#import <objc/objc-class.h>
-
-QT_BEGIN_NAMESPACE
-
-void qt_cocoa_change_implementation(Class baseClass, SEL originalSel, Class proxyClass, SEL replacementSel = 0, SEL backupSel = 0);
-void qt_cocoa_change_back_implementation(Class baseClass, SEL originalSel, SEL backupSel);
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qcocoamenuloader_mac.mm b/src/gui/kernel/qcocoamenuloader_mac.mm
deleted file mode 100644
index 71ff011069..0000000000
--- a/src/gui/kernel/qcocoamenuloader_mac.mm
+++ /dev/null
@@ -1,264 +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 "qmacdefines_mac.h"
-#ifdef QT_MAC_USE_COCOA
-#include <qaction.h>
-#include <qcoreapplication.h>
-#include <private/qcocoamenuloader_mac_p.h>
-#include <private/qapplication_p.h>
-#include <private/qt_mac_p.h>
-#include <private/qmenubar_p.h>
-#include <qmenubar.h>
-#include <private/qt_cocoa_helpers_mac_p.h>
-
-QT_FORWARD_DECLARE_CLASS(QCFString)
-QT_FORWARD_DECLARE_CLASS(QString)
-
-#ifndef QT_NO_TRANSLATION
- QT_BEGIN_NAMESPACE
- extern QString qt_mac_applicationmenu_string(int type);
- QT_END_NAMESPACE
-#endif
-
-QT_USE_NAMESPACE
-
-@implementation QT_MANGLE_NAMESPACE(QCocoaMenuLoader)
-
-- (void)awakeFromNib
-{
- servicesItem = [[appMenu itemWithTitle:@"Services"] retain];
- hideAllOthersItem = [[appMenu itemWithTitle:@"Hide Others"] retain];
- showAllItem = [[appMenu itemWithTitle:@"Show All"] retain];
-
- // Get the names in the nib to match the app name set by Qt.
- const NSString *appName = reinterpret_cast<const NSString*>(QCFString::toCFStringRef(qAppName()));
- [quitItem setTitle:[[quitItem title] stringByReplacingOccurrencesOfString:@"NewApplication"
- withString:const_cast<NSString *>(appName)]];
- [hideItem setTitle:[[hideItem title] stringByReplacingOccurrencesOfString:@"NewApplication"
- withString:const_cast<NSString *>(appName)]];
- [aboutItem setTitle:[[aboutItem title] stringByReplacingOccurrencesOfString:@"NewApplication"
- withString:const_cast<NSString *>(appName)]];
- [appName release];
- // Disable the items that don't do anything. If someone associates a QAction with them
- // They should get synced back in.
- [preferencesItem setEnabled:NO];
- [preferencesItem setHidden:YES];
- [aboutItem setEnabled:NO];
- [aboutItem setHidden:YES];
-}
-
-- (void)ensureAppMenuInMenu:(NSMenu *)menu
-{
- // The application menu is the menu in the menu bar that contains the
- // 'Quit' item. When changing menu bar (e.g when switching between
- // windows with different menu bars), we never recreate this menu, but
- // instead pull it out the current menu bar and place into the new one:
- NSMenu *mainMenu = [NSApp mainMenu];
- if ([NSApp mainMenu] == menu)
- return; // nothing to do (menu is the current menu bar)!
-
-#ifndef QT_NAMESPACE
- Q_ASSERT(mainMenu);
-#endif
- // Grab the app menu out of the current menu.
- int numItems = [mainMenu numberOfItems];
- NSMenuItem *oldAppMenuItem = 0;
- for (int i = 0; i < numItems; ++i) {
- NSMenuItem *item = [mainMenu itemAtIndex:i];
- if ([item submenu] == appMenu) {
- oldAppMenuItem = item;
- [oldAppMenuItem retain];
- [mainMenu removeItemAtIndex:i];
- break;
- }
- }
-
- if (oldAppMenuItem) {
- [oldAppMenuItem setSubmenu:nil];
- [oldAppMenuItem release];
- NSMenuItem *appMenuItem = [[NSMenuItem alloc] initWithTitle:@"Apple"
- action:nil keyEquivalent:@""];
- [appMenuItem setSubmenu:appMenu];
- [menu insertItem:appMenuItem atIndex:0];
- }
-}
-
-- (void)removeActionsFromAppMenu
-{
- for (NSMenuItem *item in [appMenu itemArray])
- [item setTag:nil];
-}
-
-- (void)dealloc
-{
- [servicesItem release];
- [hideAllOthersItem release];
- [showAllItem release];
-
- [lastAppSpecificItem release];
- [theMenu release];
- [appMenu release];
- [super dealloc];
-}
-
-- (NSMenu *)menu
-{
- return [[theMenu retain] autorelease];
-}
-
-- (NSMenu *)applicationMenu
-{
- return [[appMenu retain] autorelease];
-}
-
-- (NSMenuItem *)quitMenuItem
-{
- return [[quitItem retain] autorelease];
-}
-
-- (NSMenuItem *)preferencesMenuItem
-{
- return [[preferencesItem retain] autorelease];
-}
-
-- (NSMenuItem *)aboutMenuItem
-{
- return [[aboutItem retain] autorelease];
-}
-
-- (NSMenuItem *)aboutQtMenuItem
-{
- return [[aboutQtItem retain] autorelease];
-}
-
-- (NSMenuItem *)hideMenuItem
-{
- return [[hideItem retain] autorelease];
-}
-
-- (NSMenuItem *)appSpecificMenuItem
-{
- // Create an App-Specific menu item, insert it into the menu and return
- // it as an autorelease item.
- NSMenuItem *item = [[NSMenuItem alloc] init];
-
- NSInteger location;
- if (lastAppSpecificItem == nil) {
- location = [appMenu indexOfItem:aboutQtItem];
- } else {
- location = [appMenu indexOfItem:lastAppSpecificItem];
- [lastAppSpecificItem release];
- }
- lastAppSpecificItem = item; // Keep track of this for later (i.e., don't release it)
- [appMenu insertItem:item atIndex:location + 1];
-
- return [[item retain] autorelease];
-}
-
-- (BOOL) acceptsFirstResponder
-{
- return YES;
-}
-
-- (void)terminate:(id)sender
-{
- [NSApp terminate:sender];
-}
-
-- (void)orderFrontStandardAboutPanel:(id)sender
-{
- [NSApp orderFrontStandardAboutPanel:sender];
-}
-
-- (void)hideOtherApplications:(id)sender
-{
- [NSApp hideOtherApplications:sender];
-}
-
-- (void)unhideAllApplications:(id)sender
-{
- [NSApp unhideAllApplications:sender];
-}
-
-- (void)hide:(id)sender
-{
- [NSApp hide:sender];
-}
-
-- (void)qtUpdateMenubar
-{
- QMenuBarPrivate::macUpdateMenuBarImmediatly();
-}
-
-- (void)qtTranslateApplicationMenu
-{
-#ifndef QT_NO_TRANSLATION
- [servicesItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(0))];
- [hideItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(1).arg(qAppName()))];
- [hideAllOthersItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(2))];
- [showAllItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(3))];
- [preferencesItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(4))];
- [quitItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(5).arg(qAppName()))];
- [aboutItem setTitle: qt_mac_QStringToNSString(qt_mac_applicationmenu_string(6).arg(qAppName()))];
-#endif
-}
-
-- (IBAction)qtDispatcherToQAction:(id)sender
-{
- QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData);
- NSMenuItem *item = static_cast<NSMenuItem *>(sender);
- if (QAction *action = reinterpret_cast<QAction *>([item tag])) {
- action->trigger();
- } else if (item == quitItem) {
- // We got here because someone was once the quitItem, but it has been
- // abandoned (e.g., the menubar was deleted). In the meantime, just do
- // normal QApplication::quit().
- qApp->quit();
- }
-}
-
- - (void)orderFrontCharacterPalette:(id)sender
- {
- [NSApp orderFrontCharacterPalette:sender];
- }
-@end
-#endif // QT_MAC_USE_COCOA
diff --git a/src/gui/kernel/qcocoamenuloader_mac_p.h b/src/gui/kernel/qcocoamenuloader_mac_p.h
deleted file mode 100644
index cfcc7e00c6..0000000000
--- a/src/gui/kernel/qcocoamenuloader_mac_p.h
+++ /dev/null
@@ -1,95 +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 QCOCOAMENULOADER_P_H
-#define QCOCOAMENULOADER_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header
-// file may change from version to version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "qmacdefines_mac.h"
-#ifdef QT_MAC_USE_COCOA
-#import <Cocoa/Cocoa.h>
-
-@interface QT_MANGLE_NAMESPACE(QCocoaMenuLoader) : NSResponder
-{
- IBOutlet NSMenu *theMenu;
- IBOutlet NSMenu *appMenu;
- IBOutlet NSMenuItem *quitItem;
- IBOutlet NSMenuItem *preferencesItem;
- IBOutlet NSMenuItem *aboutItem;
- IBOutlet NSMenuItem *aboutQtItem;
- IBOutlet NSMenuItem *hideItem;
- NSMenuItem *lastAppSpecificItem;
- NSMenuItem *servicesItem;
- NSMenuItem *hideAllOthersItem;
- NSMenuItem *showAllItem;
-}
-- (void)ensureAppMenuInMenu:(NSMenu *)menu;
-- (void)removeActionsFromAppMenu;
-- (NSMenu *)applicationMenu;
-- (NSMenu *)menu;
-- (NSMenuItem *)quitMenuItem;
-- (NSMenuItem *)preferencesMenuItem;
-- (NSMenuItem *)aboutMenuItem;
-- (NSMenuItem *)aboutQtMenuItem;
-- (NSMenuItem *)hideMenuItem;
-- (NSMenuItem *)appSpecificMenuItem;
-- (IBAction)terminate:(id)sender;
-- (IBAction)orderFrontStandardAboutPanel:(id)sender;
-- (IBAction)hideOtherApplications:(id)sender;
-- (IBAction)unhideAllApplications:(id)sender;
-- (IBAction)hide:(id)sender;
-- (IBAction)qtDispatcherToQAction:(id)sender;
-- (void)qtUpdateMenubar;
-- (void)orderFrontCharacterPalette:(id)sender;
-@end
-
-#endif // QT_MAC_USE_COCOA
-#endif // QCOCOAMENULOADER_P_H
diff --git a/src/gui/kernel/qcocoapanel_mac.mm b/src/gui/kernel/qcocoapanel_mac.mm
deleted file mode 100644
index 67a12e25f8..0000000000
--- a/src/gui/kernel/qcocoapanel_mac.mm
+++ /dev/null
@@ -1,70 +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$
-**
-****************************************************************************/
-
-#import <private/qcocoapanel_mac_p.h>
-#ifdef QT_MAC_USE_COCOA
-#import <private/qt_cocoa_helpers_mac_p.h>
-#import <private/qcocoawindow_mac_p.h>
-#import <private/qcocoawindowdelegate_mac_p.h>
-#import <private/qcocoaview_mac_p.h>
-#import <private/qcocoawindowcustomthemeframe_mac_p.h>
-#import <private/qcocoaapplication_mac_p.h>
-#import <private/qmultitouch_mac_p.h>
-#import <private/qapplication_p.h>
-#import <private/qbackingstore_p.h>
-#import <private/qdnd_p.h>
-
-#include <QtGui/QWidget>
-
-QT_FORWARD_DECLARE_CLASS(QWidget);
-QT_USE_NAMESPACE
-
-@implementation QT_MANGLE_NAMESPACE(QCocoaPanel)
-
-/***********************************************************************
- Copy and Paste between QCocoaWindow and QCocoaPanel
- This is a bit unfortunate, but thanks to the dynamic dispatch we
- have to duplicate this code or resort to really silly forwarding methods
-**************************************************************************/
-#include "qcocoasharedwindowmethods_mac_p.h"
-
-@end
-#endif
diff --git a/src/gui/kernel/qcocoapanel_mac_p.h b/src/gui/kernel/qcocoapanel_mac_p.h
deleted file mode 100644
index 542615903e..0000000000
--- a/src/gui/kernel/qcocoapanel_mac_p.h
+++ /dev/null
@@ -1,83 +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$
-**
-****************************************************************************/
-
-//
-// 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.
-//
-
-#ifndef QCOCOAPANEL_MAC_P
-#define QCOCOAPANEL_MAC_P
-
-#include "qmacdefines_mac.h"
-#ifdef QT_MAC_USE_COCOA
-#import <Cocoa/Cocoa.h>
-
-QT_FORWARD_DECLARE_CLASS(QStringList);
-QT_FORWARD_DECLARE_CLASS(QCocoaDropData);
-
-@interface NSPanel (QtIntegration)
-- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
-- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender;
-- (void)draggingExited:(id <NSDraggingInfo>)sender;
-- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
-@end
-
-@interface QT_MANGLE_NAMESPACE(QCocoaPanel) : NSPanel {
- QStringList *currentCustomDragTypes;
- QCocoaDropData *dropData;
- NSInteger dragEnterSequence;
-}
-
-+ (Class)frameViewClassForStyleMask:(NSUInteger)styleMask;
-- (void)registerDragTypes;
-- (void)drawRectOriginal:(NSRect)rect;
-
-@end
-#endif
-
-#endif
diff --git a/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h b/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h
deleted file mode 100644
index ee1115bd4e..0000000000
--- a/src/gui/kernel/qcocoasharedwindowmethods_mac_p.h
+++ /dev/null
@@ -1,610 +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$
-**
-****************************************************************************/
-
-/****************************************************************************
- NB: This is not a header file, dispite the file name suffix. This file is
- included directly into the source code of qcocoawindow_mac.mm and
- qcocoapanel_mac.mm to avoid manually doing copy and paste of the exact
- same code needed at both places. This solution makes it more difficult
- to e.g fix a bug in qcocoawindow_mac.mm, but forget to do the same in
- qcocoapanel_mac.mm.
- The reason we need to do copy and paste in the first place, rather than
- resolve to method overriding, is that QCocoaPanel needs to inherit from
- NSPanel, while QCocoaWindow needs to inherit NSWindow rather than NSPanel).
-****************************************************************************/
-
-// WARNING: Don't include any header files from within this file. Put them
-// directly into qcocoawindow_mac_p.h and qcocoapanel_mac_p.h
-
-QT_BEGIN_NAMESPACE
-extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm
-extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
-extern const QStringList& qEnabledDraggedTypes(); // qmime_mac.cpp
-extern void qt_event_request_window_change(QWidget *); // qapplication_mac.mm
-extern void qt_mac_send_posted_gl_updates(QWidget *widget); // qapplication_mac.mm
-
-Q_GLOBAL_STATIC(QPointer<QWidget>, currentDragTarget);
-QT_END_NAMESPACE
-
-- (id)initWithContentRect:(NSRect)contentRect
- styleMask:(NSUInteger)windowStyle
- backing:(NSBackingStoreType)bufferingType
- defer:(BOOL)deferCreation
-{
- self = [super initWithContentRect:contentRect styleMask:windowStyle
- backing:bufferingType defer:deferCreation];
- if (self) {
- currentCustomDragTypes = 0;
- }
- return self;
-}
-
-- (void)dealloc
-{
- delete currentCustomDragTypes;
- [super dealloc];
-}
-
-- (BOOL)canBecomeKeyWindow
-{
- QWidget *widget = [self QT_MANGLE_NAMESPACE(qt_qwidget)];
- if (!widget)
- return NO; // This should happen only for qt_root_win
- if (QApplicationPrivate::isBlockedByModal(widget))
- return NO;
-
- bool isToolTip = (widget->windowType() == Qt::ToolTip);
- bool isPopup = (widget->windowType() == Qt::Popup);
- return !(isPopup || isToolTip);
-}
-
-- (BOOL)canBecomeMainWindow
-{
- QWidget *widget = [self QT_MANGLE_NAMESPACE(qt_qwidget)];
- if (!widget)
- return NO; // This should happen only for qt_root_win
- if ([self isSheet])
- return NO;
-
- bool isToolTip = (widget->windowType() == Qt::ToolTip);
- bool isPopup = (widget->windowType() == Qt::Popup);
- bool isTool = (widget->windowType() == Qt::Tool);
- return !(isPopup || isToolTip || isTool);
-}
-
-- (void)becomeMainWindow
-{
- [super becomeMainWindow];
- // Cocoa sometimes tell a hidden window to become the
- // main window (and as such, show it). This can e.g
- // happend when the application gets activated. If
- // this is the case, we tell it to hide again:
- if (![self isVisible])
- [self orderOut:self];
-}
-
-- (void)toggleToolbarShown:(id)sender
-{
- macSendToolbarChangeEvent([self QT_MANGLE_NAMESPACE(qt_qwidget)]);
- [super toggleToolbarShown:sender];
-}
-
-- (void)flagsChanged:(NSEvent *)theEvent
-{
- qt_dispatchModifiersChanged(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]);
- [super flagsChanged:theEvent];
-}
-
-
-- (void)tabletProximity:(NSEvent *)tabletEvent
-{
- qt_dispatchTabletProximityEvent(tabletEvent);
-}
-
-- (void)terminate:(id)sender
-{
- // This function is called from the quit item in the menubar when this window
- // is in the first responder chain (see also qtDispatcherToQAction above)
- [NSApp terminate:sender];
-}
-
-- (void)setLevel:(NSInteger)windowLevel
-{
- // Cocoa will upon activating/deactivating applications level modal
- // windows up and down, regardsless of any explicit set window level.
- // To ensure that modal stays-on-top dialogs actually stays on top after
- // the application is activated (and therefore stacks in front of
- // other stays-on-top windows), we need to add this little special-case override:
- QWidget *widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self];
- if (widget && widget->isModal() && (widget->windowFlags() & Qt::WindowStaysOnTopHint))
- [super setLevel:NSPopUpMenuWindowLevel];
- else
- [super setLevel:windowLevel];
-}
-
-- (void)sendEvent:(NSEvent *)event
-{
- [self retain];
-
- bool handled = false;
- switch([event type]) {
- case NSMouseMoved:
- // Cocoa sends move events to a parent and all its children under the mouse, much
- // like Qt handles hover events. But we only want to handle the move event once, so
- // to optimize a bit (since we subscribe for move event for all views), we handle it
- // here before this logic happends. Note: it might be tempting to do this shortcut for
- // all mouse events. The problem is that Cocoa does more than just find the correct view
- // when sending the event, like raising windows etc. So avoid it as much as possible:
- handled = qt_mac_handleMouseEvent(event, QEvent::MouseMove, Qt::NoButton, 0);
- break;
- default:
- break;
- }
-
- if (!handled) {
- [super sendEvent:event];
- qt_mac_handleNonClientAreaMouseEvent(self, event);
- }
- [self release];
-}
-
-- (void)setInitialFirstResponder:(NSView *)view
-{
- // This method is called the first time the window is placed on screen and
- // is the earliest point in time we can connect OpenGL contexts to NSViews.
- QWidget *qwidget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self];
- if (qwidget) {
- qt_event_request_window_change(qwidget);
- qt_mac_send_posted_gl_updates(qwidget);
- }
-
- [super setInitialFirstResponder:view];
-}
-
-- (BOOL)makeFirstResponder:(NSResponder *)responder
-{
- // For some reason Cocoa wants to flip the first responder
- // when Qt doesn't want to, sorry, but "No" :-)
- if (responder == nil && qApp->focusWidget())
- return NO;
- return [super makeFirstResponder:responder];
-}
-
-+ (Class)frameViewClassForStyleMask:(NSUInteger)styleMask
-{
- if (styleMask & QtMacCustomizeWindow)
- return [QT_MANGLE_NAMESPACE(QCocoaWindowCustomThemeFrame) class];
- return [super frameViewClassForStyleMask:styleMask];
-}
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
-- (void)touchesBeganWithEvent:(NSEvent *)event;
-{
- QPoint qlocal, qglobal;
- QWidget *widgetToGetTouch = 0;
- qt_mac_getTargetForMouseEvent(event, QEvent::Gesture, qlocal, qglobal, 0, &widgetToGetTouch);
- if (!widgetToGetTouch)
- return;
-
- bool all = widgetToGetTouch->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents);
- qt_translateRawTouchEvent(widgetToGetTouch, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all));
-}
-
-- (void)touchesMovedWithEvent:(NSEvent *)event;
-{
- QPoint qlocal, qglobal;
- QWidget *widgetToGetTouch = 0;
- qt_mac_getTargetForMouseEvent(event, QEvent::Gesture, qlocal, qglobal, 0, &widgetToGetTouch);
- if (!widgetToGetTouch)
- return;
-
- bool all = widgetToGetTouch->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents);
- qt_translateRawTouchEvent(widgetToGetTouch, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all));
-}
-
-- (void)touchesEndedWithEvent:(NSEvent *)event;
-{
- QPoint qlocal, qglobal;
- QWidget *widgetToGetTouch = 0;
- qt_mac_getTargetForMouseEvent(event, QEvent::Gesture, qlocal, qglobal, 0, &widgetToGetTouch);
- if (!widgetToGetTouch)
- return;
-
- bool all = widgetToGetTouch->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents);
- qt_translateRawTouchEvent(widgetToGetTouch, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all));
-}
-
-- (void)touchesCancelledWithEvent:(NSEvent *)event;
-{
- QPoint qlocal, qglobal;
- QWidget *widgetToGetTouch = 0;
- qt_mac_getTargetForMouseEvent(event, QEvent::Gesture, qlocal, qglobal, 0, &widgetToGetTouch);
- if (!widgetToGetTouch)
- return;
-
- bool all = widgetToGetTouch->testAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents);
- qt_translateRawTouchEvent(widgetToGetTouch, QTouchEvent::TouchPad, QCocoaTouch::getCurrentTouchPointList(event, all));
-}
-#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
-
--(void)registerDragTypes
-{
- // Calling registerForDraggedTypes below is slow, so only do
- // it once for each window, or when the custom types change.
- QMacCocoaAutoReleasePool pool;
- const QStringList& customTypes = qEnabledDraggedTypes();
- if (currentCustomDragTypes == 0 || *currentCustomDragTypes != customTypes) {
- if (currentCustomDragTypes == 0)
- currentCustomDragTypes = new QStringList();
- *currentCustomDragTypes = customTypes;
- const NSString* mimeTypeGeneric = @"com.trolltech.qt.MimeTypeName";
- NSMutableArray *supportedTypes = [NSMutableArray arrayWithObjects:NSColorPboardType,
- NSFilenamesPboardType, NSStringPboardType,
- NSFilenamesPboardType, NSPostScriptPboardType, NSTIFFPboardType,
- NSRTFPboardType, NSTabularTextPboardType, NSFontPboardType,
- NSRulerPboardType, NSFileContentsPboardType, NSColorPboardType,
- NSRTFDPboardType, NSHTMLPboardType, NSPICTPboardType,
- NSURLPboardType, NSPDFPboardType, NSVCardPboardType,
- NSFilesPromisePboardType, NSInkTextPboardType,
- NSMultipleTextSelectionPboardType, mimeTypeGeneric, nil];
- // Add custom types supported by the application.
- for (int i = 0; i < customTypes.size(); i++) {
- [supportedTypes addObject:qt_mac_QStringToNSString(customTypes[i])];
- }
- [self registerForDraggedTypes:supportedTypes];
- }
-}
-
-- (void)removeDropData
-{
- if (dropData) {
- delete dropData;
- dropData = 0;
- }
-}
-
-- (void)addDropData:(id <NSDraggingInfo>)sender
-{
- [self removeDropData];
- CFStringRef dropPasteboard = (CFStringRef) [[sender draggingPasteboard] name];
- dropData = new QCocoaDropData(dropPasteboard);
-}
-
-- (void)changeDraggingCursor:(NSDragOperation)newOperation
-{
- static SEL action = nil;
- static bool operationSupported = false;
- if (action == nil) {
- action = NSSelectorFromString(@"operationNotAllowedCursor");
- if ([NSCursor respondsToSelector:action]) {
- operationSupported = true;
- }
- }
- if (operationSupported) {
- NSCursor *notAllowedCursor = [NSCursor performSelector:action];
- bool isNotAllowedCursor = ([NSCursor currentCursor] == notAllowedCursor);
- if (newOperation == NSDragOperationNone && !isNotAllowedCursor) {
- [notAllowedCursor push];
- } else if (newOperation != NSDragOperationNone && isNotAllowedCursor) {
- [notAllowedCursor pop];
- }
-
- }
-}
-
-- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
-{
- // The user dragged something into the window. Send a draggingEntered message
- // to the QWidget under the mouse. As the drag moves over the window, and over
- // different widgets, we will handle enter and leave events from within
- // draggingUpdated below. The reason why we handle this ourselves rather than
- // subscribing for drag events directly in QCocoaView is that calling
- // registerForDraggedTypes on the views will severly degrade initialization time
- // for an application that uses a lot of drag subscribing widgets.
-
- NSPoint nswindowPoint = [sender draggingLocation];
- NSPoint nsglobalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:nswindowPoint];
- QPoint globalPoint = flipPoint(nsglobalPoint).toPoint();
-
- QWidget *qwidget = QApplication::widgetAt(globalPoint);
- *currentDragTarget() = qwidget;
- if (!qwidget)
- return [super draggingEntered:sender];
- if (qwidget->testAttribute(Qt::WA_DropSiteRegistered) == false)
- return NSDragOperationNone;
-
- [self addDropData:sender];
-
- QMimeData *mimeData = dropData;
- if (QDragManager::self()->source())
- mimeData = QDragManager::self()->dragPrivate()->data;
-
- NSDragOperation nsActions = [sender draggingSourceOperationMask];
- Qt::DropActions qtAllowed = qt_mac_mapNSDragOperations(nsActions);
- QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastOperation) = nsActions;
- Qt::KeyboardModifiers modifiers = Qt::NoModifier;
-
- if ([sender draggingSource] != nil) {
- // modifier flags might have changed, update it here since we don't send any input events.
- QApplicationPrivate::modifier_buttons = qt_cocoaModifiers2QtModifiers([[NSApp currentEvent] modifierFlags]);
- modifiers = QApplication::keyboardModifiers();
- } else {
- // when the source is from another application the above technique will not work.
- modifiers = qt_cocoaDragOperation2QtModifiers(nsActions);
- }
-
- // send the drag enter event to the widget.
- QPoint localPoint(qwidget->mapFromGlobal(globalPoint));
- QDragEnterEvent qDEEvent(localPoint, qtAllowed, mimeData, QApplication::mouseButtons(), modifiers);
- QApplication::sendEvent(qwidget, &qDEEvent);
-
- if (!qDEEvent.isAccepted()) {
- // The enter event was not accepted. We mark this by removing
- // the drop data so we don't send subsequent drag move events:
- [self removeDropData];
- [self changeDraggingCursor:NSDragOperationNone];
- return NSDragOperationNone;
- } else {
- // Send a drag move event immediately after a drag enter event (as per documentation).
- QDragMoveEvent qDMEvent(localPoint, qtAllowed, mimeData, QApplication::mouseButtons(), modifiers);
- qDMEvent.setDropAction(qDEEvent.dropAction());
- qDMEvent.accept(); // accept by default, since enter event was accepted.
- QApplication::sendEvent(qwidget, &qDMEvent);
-
- if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction) {
- // Since we accepted the drag enter event, the widget expects
- // future drage move events.
- nsActions = NSDragOperationNone;
- // Save as ignored in the answer rect.
- qDMEvent.setDropAction(Qt::IgnoreAction);
- } else {
- nsActions = QT_PREPEND_NAMESPACE(qt_mac_mapDropAction)(qDMEvent.dropAction());
- }
-
- QT_PREPEND_NAMESPACE(qt_mac_copy_answer_rect)(qDMEvent);
- [self changeDraggingCursor:nsActions];
- return nsActions;
- }
- }
-
-- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
-{
- NSPoint nswindowPoint = [sender draggingLocation];
- NSPoint nsglobalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:nswindowPoint];
- QPoint globalPoint = flipPoint(nsglobalPoint).toPoint();
-
- QWidget *qwidget = QApplication::widgetAt(globalPoint);
- if (!qwidget)
- return [super draggingEntered:sender];
-
- // First, check if the widget under the mouse has changed since the
- // last drag move events. If so, we need to change target, and dispatch
- // syntetic drag enter/leave events:
- if (qwidget != *currentDragTarget()) {
- if (*currentDragTarget() && dropData) {
- QDragLeaveEvent de;
- QApplication::sendEvent(*currentDragTarget(), &de);
- [self removeDropData];
- }
- return [self draggingEntered:sender];
- }
-
- if (qwidget->testAttribute(Qt::WA_DropSiteRegistered) == false)
- return NSDragOperationNone;
-
- // If we have no drop data (which will be assigned inside draggingEntered), it means
- // that the current drag target did not accept the enter event. If so, we ignore
- // subsequent move events as well:
- if (dropData == 0) {
- [self changeDraggingCursor:NSDragOperationNone];
- return NSDragOperationNone;
- }
-
- // If the mouse is still within the accepted rect (provided by
- // the application on a previous event), we follow the optimization
- // and just return the answer given at that point:
- NSDragOperation nsActions = [sender draggingSourceOperationMask];
- QPoint localPoint(qwidget->mapFromGlobal(globalPoint));
- if (qt_mac_mouse_inside_answer_rect(localPoint)
- && QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastOperation) == nsActions) {
- NSDragOperation operation = QT_PREPEND_NAMESPACE(qt_mac_mapDropActions)(QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastAction));
- [self changeDraggingCursor:operation];
- return operation;
- }
-
- QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec.lastOperation) = nsActions;
- Qt::DropActions qtAllowed = QT_PREPEND_NAMESPACE(qt_mac_mapNSDragOperations)(nsActions);
- Qt::KeyboardModifiers modifiers = Qt::NoModifier;
-
- // Update modifiers:
- if ([sender draggingSource] != nil) {
- QApplicationPrivate::modifier_buttons = qt_cocoaModifiers2QtModifiers([[NSApp currentEvent] modifierFlags]);
- modifiers = QApplication::keyboardModifiers();
- } else {
- modifiers = qt_cocoaDragOperation2QtModifiers(nsActions);
- }
-
- QMimeData *mimeData = dropData;
- if (QDragManager::self()->source())
- mimeData = QDragManager::self()->dragPrivate()->data;
-
- // Insert the same drop action on the event according to
- // what the application told us it should be on the previous event:
- QDragMoveEvent qDMEvent(localPoint, qtAllowed, mimeData, QApplication::mouseButtons(), modifiers);
- if (QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec).lastAction != Qt::IgnoreAction
- && QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec).buttons == qDMEvent.mouseButtons()
- && QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec).modifiers == qDMEvent.keyboardModifiers())
- qDMEvent.setDropAction(QT_PREPEND_NAMESPACE(qt_mac_dnd_answer_rec).lastAction);
-
- // Now, end the drag move event to the widget:
- qDMEvent.accept();
- QApplication::sendEvent(qwidget, &qDMEvent);
-
- NSDragOperation operation = qt_mac_mapDropAction(qDMEvent.dropAction());
- if (!qDMEvent.isAccepted() || qDMEvent.dropAction() == Qt::IgnoreAction) {
- // Ignore this event (we will still receive further
- // notifications), save as ignored in the answer rect:
- operation = NSDragOperationNone;
- qDMEvent.setDropAction(Qt::IgnoreAction);
- }
-
- qt_mac_copy_answer_rect(qDMEvent);
- [self changeDraggingCursor:operation];
-
- return operation;
-}
-
-- (void)draggingExited:(id <NSDraggingInfo>)sender
-{
- NSPoint nswindowPoint = [sender draggingLocation];
- NSPoint nsglobalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:nswindowPoint];
- QPoint globalPoint = flipPoint(nsglobalPoint).toPoint();
-
- QWidget *qwidget = *currentDragTarget();
- if (!qwidget)
- return [super draggingExited:sender];
-
- if (dropData) {
- QDragLeaveEvent de;
- QApplication::sendEvent(qwidget, &de);
- [self removeDropData];
- }
-
- // Clean-up:
- [self removeDropData];
- *currentDragTarget() = 0;
- [self changeDraggingCursor:NSDragOperationEvery];
-}
-
-- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
-{
- QWidget *qwidget = *currentDragTarget();
- if (!qwidget)
- return NO;
-
- *currentDragTarget() = 0;
- NSPoint nswindowPoint = [sender draggingLocation];
- NSPoint nsglobalPoint = [[sender draggingDestinationWindow] convertBaseToScreen:nswindowPoint];
- QPoint globalPoint = flipPoint(nsglobalPoint).toPoint();
-
- [self addDropData:sender];
-
- NSDragOperation nsActions = [sender draggingSourceOperationMask];
- Qt::DropActions qtAllowed = qt_mac_mapNSDragOperations(nsActions);
- QMimeData *mimeData = dropData;
-
- if (QDragManager::self()->source())
- mimeData = QDragManager::self()->dragPrivate()->data;
- if (QDragManager::self()->object)
- QDragManager::self()->dragPrivate()->target = qwidget;
-
- QPoint localPoint(qwidget->mapFromGlobal(globalPoint));
- QDropEvent de(localPoint, qtAllowed, mimeData,
- QApplication::mouseButtons(), QApplication::keyboardModifiers());
- QApplication::sendEvent(qwidget, &de);
-
- if (QDragManager::self()->object)
- QDragManager::self()->dragPrivate()->executed_action = de.dropAction();
-
- return de.isAccepted();
-}
-
-// This is a hack and it should be removed once we find the real cause for
-// the painting problems.
-// We have a static variable that signals if we have been called before or not.
-static bool firstDrawingInvocation = true;
-
-// The method below exists only as a workaround to draw/not draw the baseline
-// in the title bar. This is to support unifiedToolbar look.
-
-// This method is very special. To begin with, it is a
-// method that will get called only if we enable documentMode.
-// Furthermore, it won't get called as a normal method, we swap
-// this method with the normal implementation of drawRect in
-// _NSThemeFrame. When this method is active, its mission is to
-// first call the original drawRect implementation so the widget
-// gets proper painting. After that, it needs to detect if there
-// is a toolbar or not, in order to decide how to handle the unified
-// look. The distinction is important since the presence and
-// visibility of a toolbar change the way we enter into unified mode.
-// When there is a toolbar and that toolbar is visible, the problem
-// is as simple as to tell the toolbar not to draw its baseline.
-// However when there is not toolbar or the toolbar is not visible,
-// we need to draw a line on top of the baseline, because the baseline
-// in that case will belong to the title. For this case we need to draw
-// a line on top of the baseline.
-// As usual, there is a special case. When we first are called, we might
-// need to repaint ourselves one more time. We only need that if we
-// didn't get the activation, i.e. when we are launched via the command
-// line. And this only if the toolbar is visible from the beginning,
-// so we have a special flag that signals if we need to repaint or not.
-- (void)drawRectSpecial:(NSRect)rect
-{
- // Call the original drawing method.
- [id(self) drawRectOriginal:rect];
- NSWindow *window = [id(self) window];
- NSToolbar *toolbar = [window toolbar];
- if(!toolbar) {
- // There is no toolbar, we have to draw a line on top of the line drawn by Cocoa.
- macDrawRectOnTop((void *)window);
- } else {
- if([toolbar isVisible]) {
- // We tell Cocoa to avoid drawing the line at the end.
- if(firstDrawingInvocation) {
- firstDrawingInvocation = false;
- macSyncDrawingOnFirstInvocation((void *)window);
- } else
- [toolbar setShowsBaselineSeparator:NO];
- } else {
- // There is a toolbar but it is not visible so
- // we have to draw a line on top of the line drawn by Cocoa.
- macDrawRectOnTop((void *)window);
- }
- }
-}
-
-- (void)drawRectOriginal:(NSRect)rect
-{
- Q_UNUSED(rect)
- // This method implementation is here to silenct the compiler.
- // See drawRectSpecial for information.
-}
-
diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm
deleted file mode 100644
index e885d1552c..0000000000
--- a/src/gui/kernel/qcocoaview_mac.mm
+++ /dev/null
@@ -1,1388 +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$
-**
-****************************************************************************/
-
-#import <private/qcocoaview_mac_p.h>
-#ifdef QT_MAC_USE_COCOA
-
-#include <private/qwidget_p.h>
-#include <private/qt_mac_p.h>
-#include <private/qapplication_p.h>
-#include <private/qabstractscrollarea_p.h>
-#include <private/qt_cocoa_helpers_mac_p.h>
-#include <private/qdnd_p.h>
-#include <private/qmacinputcontext_p.h>
-#include <private/qevent_p.h>
-#include <private/qbackingstore_p.h>
-#include <private/qwindowsurface_raster_p.h>
-#include <private/qunifiedtoolbarsurface_mac_p.h>
-
-#include <qscrollarea.h>
-#include <qhash.h>
-#include <qtextformat.h>
-#include <qpaintengine.h>
-#include <QUrl>
-#include <QAccessible>
-#include <QFileInfo>
-#include <QFile>
-
-#include <qdebug.h>
-
-@interface NSEvent (Qt_Compile_Leopard_DeviceDelta)
- - (CGFloat)deviceDeltaX;
- - (CGFloat)deviceDeltaY;
- - (CGFloat)deviceDeltaZ;
-@end
-
-@interface NSEvent (Qt_Compile_Leopard_Gestures)
- - (CGFloat)magnification;
-@end
-
-QT_BEGIN_NAMESPACE
-
-extern void qt_mac_update_cursor(); // qcursor_mac.mm
-extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); // qapplication.cpp
-extern QPointer<QWidget> qt_last_mouse_receiver; // qapplication_mac.cpp
-extern QPointer<QWidget> qt_last_native_mouse_receiver; // qt_cocoa_helpers_mac.mm
-extern OSViewRef qt_mac_nativeview_for(const QWidget *w); // qwidget_mac.mm
-extern OSViewRef qt_mac_effectiveview_for(const QWidget *w); // qwidget_mac.mm
-extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
-extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum);
-extern QWidget *mac_mouse_grabber;
-extern bool qt_mac_clearDirtyOnWidgetInsideDrawWidget; // qwidget.cpp
-
-static QColor colorFrom(NSColor *color)
-{
- QColor qtColor;
- NSString *colorSpace = [color colorSpaceName];
- if (colorSpace == NSDeviceCMYKColorSpace) {
- CGFloat cyan, magenta, yellow, black, alpha;
- [color getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
- qtColor.setCmykF(cyan, magenta, yellow, black, alpha);
- } else {
- NSColor *tmpColor;
- tmpColor = [color colorUsingColorSpaceName:NSDeviceRGBColorSpace];
- CGFloat red, green, blue, alpha;
- [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha];
- qtColor.setRgbF(red, green, blue, alpha);
- }
- return qtColor;
-}
-
-QT_END_NAMESPACE
-
-QT_FORWARD_DECLARE_CLASS(QMacCocoaAutoReleasePool)
-QT_FORWARD_DECLARE_CLASS(QCFString)
-QT_FORWARD_DECLARE_CLASS(QDragManager)
-QT_FORWARD_DECLARE_CLASS(QMimeData)
-QT_FORWARD_DECLARE_CLASS(QPoint)
-QT_FORWARD_DECLARE_CLASS(QApplication)
-QT_FORWARD_DECLARE_CLASS(QApplicationPrivate)
-QT_FORWARD_DECLARE_CLASS(QDragEnterEvent)
-QT_FORWARD_DECLARE_CLASS(QDragMoveEvent)
-QT_FORWARD_DECLARE_CLASS(QStringList)
-QT_FORWARD_DECLARE_CLASS(QString)
-QT_FORWARD_DECLARE_CLASS(QRect)
-QT_FORWARD_DECLARE_CLASS(QRegion)
-QT_FORWARD_DECLARE_CLASS(QAbstractScrollArea)
-QT_FORWARD_DECLARE_CLASS(QAbstractScrollAreaPrivate)
-QT_FORWARD_DECLARE_CLASS(QPaintEvent)
-QT_FORWARD_DECLARE_CLASS(QPainter)
-QT_FORWARD_DECLARE_CLASS(QHoverEvent)
-QT_FORWARD_DECLARE_CLASS(QCursor)
-QT_USE_NAMESPACE
-extern "C" {
- extern NSString *NSTextInputReplacementRangeAttributeName;
-}
-
-//#define ALIEN_DEBUG 1
-#ifdef ALIEN_DEBUG
-static int qCocoaViewCount = 0;
-#endif
-
-@implementation QT_MANGLE_NAMESPACE(QCocoaView)
-
-- (id)initWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate
-{
- self = [super init];
- if (self) {
- [self finishInitWithQWidget:widget widgetPrivate:widgetprivate];
- }
- [self setFocusRingType:NSFocusRingTypeNone];
- composingText = new QString();
-
-#ifdef ALIEN_DEBUG
- ++qCocoaViewCount;
- qDebug() << "Alien: create native view for" << widget << ". qCocoaViewCount is:" << qCocoaViewCount;
-#endif
-
- composing = false;
- sendKeyEvents = true;
- fromKeyDownEvent = false;
- alienTouchCount = 0;
-
- [self setHidden:YES];
- return self;
-}
-
-- (void) finishInitWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate
-{
- qwidget = widget;
- qwidgetprivate = widgetprivate;
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(frameDidChange:)
- name:@"NSViewFrameDidChangeNotification"
- object:self];
-}
-
-- (void)dealloc
-{
- QMacCocoaAutoReleasePool pool;
- delete composingText;
- [[NSNotificationCenter defaultCenter] removeObserver:self];
-
-#ifdef ALIEN_DEBUG
- --qCocoaViewCount;
- qDebug() << "Alien: widget deallocated. qCocoaViewCount is:" << qCocoaViewCount;
-#endif
-
- [super dealloc];
-}
-
-- (BOOL)isOpaque
-{
- if (!qwidgetprivate)
- return [super isOpaque];
- return qwidgetprivate->isOpaque;
-}
-
-- (BOOL)isFlipped
-{
- return YES;
-}
-
-// We preserve the content of the view if WA_StaticContents is defined.
-//
-// More info in the Cocoa documentation:
-// http://developer.apple.com/mac/library/documentation/cocoa/conceptual/CocoaViewsGuide/Optimizing/Optimizing.html
-- (BOOL) preservesContentDuringLiveResize
-{
- return qwidget->testAttribute(Qt::WA_StaticContents);
-}
-
-- (void) setFrameSize:(NSSize)newSize
-{
- [super setFrameSize:newSize];
-
- // A change in size has required the view to be invalidated.
- if ([self inLiveResize]) {
- NSRect rects[4];
- NSInteger count;
- [self getRectsExposedDuringLiveResize:rects count:&count];
- while (count-- > 0)
- {
- [self setNeedsDisplayInRect:rects[count]];
- }
- } else {
- [self setNeedsDisplay:YES];
- }
-
- // Make sure the opengl context is updated on resize.
- if (qwidgetprivate && qwidgetprivate->isGLWidget && [self window]) {
- qwidgetprivate->needWindowChange = true;
- QEvent event(QEvent::MacGLWindowChange);
- qApp->sendEvent(qwidget, &event);
- }
-}
-
-// We catch the 'setNeedsDisplay:' message in order to avoid a useless full repaint.
-// During the resize, the top of the widget is repainted, probably because of the
-// change of coordinate space (Quartz vs Qt). This is then followed by this message:
-// -[NSView _setNeedsDisplayIfTopLeftChanged]
-// which force a full repaint by sending the message 'setNeedsDisplay:'.
-// That is what we are preventing here.
-- (void)setNeedsDisplay:(BOOL)flag {
- if (![self inLiveResize] || !(qwidget->testAttribute(Qt::WA_StaticContents))) {
- [super setNeedsDisplay:flag];
- }
-}
-
-- (void)drawRect:(NSRect)aRect
-{
- if (!qwidget)
- return;
-
- // Getting context.
- CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
- qt_mac_retain_graphics_context(context);
-
- // We use a different graphics system.
- //
- // Widgets that are set to paint on screen, specifically QGLWidget,
- // requires the native engine to execute in order to be drawn.
- if (QApplicationPrivate::graphicsSystem() != 0 && !qwidget->testAttribute(Qt::WA_PaintOnScreen)) {
-
- // Raster engine.
- if (QApplicationPrivate::graphics_system_name == QLatin1String("raster")) {
-
- if (!qwidgetprivate->isInUnifiedToolbar) {
-
- // Qt handles the painting occuring inside the window.
- // Cocoa also keeps track of all widgets as NSView and therefore might
- // ask for a repainting of a widget even if Qt is already taking care of it.
- //
- // The only valid reason for Cocoa to call drawRect: is for window manipulation
- // (ie. resize, ...).
- //
- // Qt will then forward the update to the children.
- if (!qwidget->isWindow()) {
- qt_mac_release_graphics_context(context);
- return;
- }
-
- QRasterWindowSurface *winSurface = dynamic_cast<QRasterWindowSurface *>(qwidget->windowSurface());
- if (!winSurface || !winSurface->needsFlush) {
- qt_mac_release_graphics_context(context);
- return;
- }
-
- // Clip to region.
- const QVector<QRect> &rects = winSurface->regionToFlush.rects();
- for (int i = 0; i < rects.size(); ++i) {
- const QRect &rect = rects.at(i);
- CGContextAddRect(context, CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()));
- }
- CGContextClip(context);
-
- QRect r = winSurface->regionToFlush.boundingRect();
- const CGRect area = CGRectMake(r.x(), r.y(), r.width(), r.height());
-
- qt_mac_draw_image(context, winSurface->imageContext(), area, area);
-
- winSurface->needsFlush = false;
- winSurface->regionToFlush = QRegion();
-
- } else {
-
- QUnifiedToolbarSurface *unifiedSurface = qwidgetprivate->unifiedSurface;
- if (!unifiedSurface) {
- qt_mac_release_graphics_context(context);
- return;
- }
-
- int areaX = qwidgetprivate->toolbar_offset.x();
- int areaY = qwidgetprivate->toolbar_offset.y();
- int areaWidth = qwidget->geometry().width();
- int areaHeight = qwidget->geometry().height();
- const CGRect area = CGRectMake(areaX, areaY, areaWidth, areaHeight);
- const CGRect drawingArea = CGRectMake(0, 0, areaWidth, areaHeight);
-
- qt_mac_draw_image(context, unifiedSurface->imageContext(), area, drawingArea);
-
- qwidgetprivate->flushRequested = false;
-
- }
-
- CGContextFlush(context);
- qt_mac_release_graphics_context(context);
- return;
- }
-
- // Qt handles the painting occuring inside the window.
- // Cocoa also keeps track of all widgets as NSView and therefore might
- // ask for a repainting of a widget even if Qt is already taking care of it.
- //
- // The only valid reason for Cocoa to call drawRect: is for window manipulation
- // (ie. resize, ...).
- //
- // Qt will then forward the update to the children.
- if (qwidget->isWindow()) {
- qwidgetprivate->syncBackingStore(qwidget->rect());
- }
- }
-
- // Native engine.
- qwidgetprivate->hd = context;
-
- if (qwidget->isVisible() && qwidget->updatesEnabled()) { //process the actual paint event.
- if (qwidget->testAttribute(Qt::WA_WState_InPaintEvent))
- qWarning("QWidget::repaint: Recursive repaint detected");
-
- const QRect qrect = QRect(aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height);
- QRegion qrgn;
-
- const NSRect *rects;
- NSInteger count;
- [self getRectsBeingDrawn:&rects count:&count];
- for (int i = 0; i < count; ++i) {
- QRect tmpRect = QRect(rects[i].origin.x, rects[i].origin.y, rects[i].size.width, rects[i].size.height);
- qrgn += tmpRect;
- }
-
- if (!qwidget->isWindow() && !qobject_cast<QAbstractScrollArea *>(qwidget->parent())) {
- const QRegion &parentMask = qwidget->window()->mask();
- if (!parentMask.isEmpty()) {
- const QPoint mappedPoint = qwidget->mapTo(qwidget->window(), qrect.topLeft());
- qrgn.translate(mappedPoint);
- qrgn &= parentMask;
- qrgn.translate(-mappedPoint.x(), -mappedPoint.y());
- }
- }
-
- QPoint redirectionOffset(0, 0);
- //setup the context
- qwidget->setAttribute(Qt::WA_WState_InPaintEvent);
- QPaintEngine *engine = qwidget->paintEngine();
- if (engine)
- engine->setSystemClip(qrgn);
- if (qwidgetprivate->extra && qwidgetprivate->extra->hasMask) {
- CGRect widgetRect = CGRectMake(0, 0, qwidget->width(), qwidget->height());
- CGContextTranslateCTM (context, 0, widgetRect.size.height);
- CGContextScaleCTM(context, 1, -1);
- if (qwidget->isWindow())
- CGContextClearRect(context, widgetRect);
- CGContextClipToMask(context, widgetRect, qwidgetprivate->extra->imageMask);
- CGContextScaleCTM(context, 1, -1);
- CGContextTranslateCTM (context, 0, -widgetRect.size.height);
- }
-
- if (qwidget->isWindow() && !qwidgetprivate->isOpaque
- && !qwidget->testAttribute(Qt::WA_MacBrushedMetal)) {
- CGContextClearRect(context, NSRectToCGRect(aRect));
- }
-
- qwidget->setAttribute(Qt::WA_WState_InPaintEvent, false);
- QWidgetPrivate *qwidgetPrivate = qt_widget_private(qwidget);
-
- // We specify that we want to draw the widget itself, and
- // all its children recursive. But we skip native children, because
- // they will receive drawRect calls by themselves as needed:
- int flags = QWidgetPrivate::DrawPaintOnScreen
- | QWidgetPrivate::DrawRecursive
- | QWidgetPrivate::DontDrawNativeChildren;
-
- if (qwidget->isWindow())
- flags |= QWidgetPrivate::DrawAsRoot;
-
- // Start to draw:
- qt_mac_clearDirtyOnWidgetInsideDrawWidget = true;
- qwidgetPrivate->drawWidget(qwidget, qrgn, QPoint(), flags, 0);
- qt_mac_clearDirtyOnWidgetInsideDrawWidget = false;
-
- if (!redirectionOffset.isNull())
- QPainter::restoreRedirected(qwidget);
- if (engine)
- engine->setSystemClip(QRegion());
- qwidget->setAttribute(Qt::WA_WState_InPaintEvent, false);
- if(!qwidget->testAttribute(Qt::WA_PaintOutsidePaintEvent) && qwidget->paintingActive())
- qWarning("QWidget: It is dangerous to leave painters active on a"
- " widget outside of the PaintEvent");
- }
- qwidgetprivate->hd = 0;
- qt_mac_release_graphics_context(context);
-}
-
-- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
-{
- // Find the widget that should receive the event:
- QPoint qlocal, qglobal;
- QWidget *widgetToGetMouse = qt_mac_getTargetForMouseEvent(theEvent, QEvent::MouseButtonPress, qlocal, qglobal, qwidget, 0);
- if (!widgetToGetMouse)
- return NO;
-
- return !widgetToGetMouse->testAttribute(Qt::WA_MacNoClickThrough);
-}
-
-- (NSView *)hitTest:(NSPoint)aPoint
-{
- if (!qwidget)
- return [super hitTest:aPoint];
-
- if (qwidget->testAttribute(Qt::WA_TransparentForMouseEvents))
- return nil; // You cannot hit a transparent for mouse event widget.
- return [super hitTest:aPoint];
-}
-
-- (void)updateTrackingAreas
-{
- if (!qwidget)
- return;
-
- // [NSView addTrackingArea] is slow, so bail out early if we can:
- if (NSIsEmptyRect([self visibleRect]))
- return;
-
- QMacCocoaAutoReleasePool pool;
- if (NSArray *trackingArray = [self trackingAreas]) {
- NSUInteger size = [trackingArray count];
- for (NSUInteger i = 0; i < size; ++i) {
- NSTrackingArea *t = [trackingArray objectAtIndex:i];
- [self removeTrackingArea:t];
- }
- }
-
- // Ideally, we shouldn't have NSTrackingMouseMoved events included below, it should
- // only be turned on if mouseTracking, hover is on or a tool tip is set.
- // Unfortunately, Qt will send "tooltip" events on mouse moves, so we need to
- // turn it on in ALL case. That means EVERY QCocoaView gets to pay the cost of
- // mouse moves delivered to it (Apple recommends keeping it OFF because there
- // is a performance hit). So it goes.
- NSUInteger trackingOptions = NSTrackingMouseEnteredAndExited | NSTrackingActiveInActiveApp
- | NSTrackingInVisibleRect | NSTrackingMouseMoved;
- NSTrackingArea *ta = [[NSTrackingArea alloc] initWithRect:NSMakeRect(0, 0,
- qwidget->width(),
- qwidget->height())
- options:trackingOptions
- owner:self
- userInfo:nil];
- [self addTrackingArea:ta];
- [ta release];
-}
-
-- (void)mouseEntered:(NSEvent *)event
-{
- // Cocoa will not send a move event on mouseEnter. But since
- // Qt expect this, we fake one now. See also mouseExited below
- // for info about enter/leave event handling
- NSEvent *nsmoveEvent = [NSEvent
- mouseEventWithType:NSMouseMoved
- location:[[self window] mouseLocationOutsideOfEventStream]
- modifierFlags: [event modifierFlags]
- timestamp: [event timestamp]
- windowNumber: [event windowNumber]
- context: [event context]
- eventNumber: [event eventNumber]
- clickCount: 0
- pressure: 0];
-
- // Important: Cocoa sends us mouseEnter on all views under the mouse
- // and not just the one on top. Therefore, to we cannot use qwidget
- // as native widget for this case. Instead, we let qt_mac_handleMouseEvent
- // resolve it (last argument set to 0):
- qt_mac_handleMouseEvent(nsmoveEvent, QEvent::MouseMove, Qt::NoButton, 0);
-}
-
-- (void)mouseExited:(NSEvent *)event
-{
- // Note: normal enter/leave handling is done from within mouseMove. This handler
- // catches the case when the mouse moves out of the window (which mouseMove do not).
- // Updating the mouse cursor follows the same logic as enter/leave. And we update
- // neither if a grab exists (even if the grab points to this widget, it seems, ref X11)
- Q_UNUSED(event);
- if (self == [[self window] contentView] && !qt_button_down && !QWidget::mouseGrabber()) {
- qt_mac_update_cursor();
- // If the mouse exits the content view, but qt_mac_getTargetForMouseEvent still
- // reports a target, it means that either there is a grab involved, or the mouse
- // hovered over another window in the application. In both cases, move events will
- // cause qt_mac_handleMouseEvent to be called, which will handle enter/leave.
- QPoint qlocal, qglobal;
- QWidget *widgetUnderMouse = 0;
- qt_mac_getTargetForMouseEvent(event, QEvent::Leave, qlocal, qglobal, qwidget, &widgetUnderMouse);
-
- if (widgetUnderMouse == 0) {
- QApplicationPrivate::dispatchEnterLeave(0, qt_last_mouse_receiver);
- qt_last_mouse_receiver = 0;
- qt_last_native_mouse_receiver = 0;
- }
- }
-}
-
-- (void)flagsChanged:(NSEvent *)theEvent
-{
- QWidget *widgetToGetKey = qt_mac_getTargetForKeyEvent(qwidget);
- if (!widgetToGetKey)
- return;
-
- qt_dispatchModifiersChanged(theEvent, widgetToGetKey);
- [super flagsChanged:theEvent];
-}
-
-- (void)mouseMoved:(NSEvent *)theEvent
-{
- // Important: this method will only be called when the view's window is _not_ inside
- // QCocoaWindow/QCocoaPanel. Otherwise, [QCocoaWindow sendEvent] will handle the event
- // before it ends up here. So, this method is added for supporting QMacNativeWidget.
- // TODO: Cocoa send move events to all views under the mouse. So make sure we only
- // handle the event for the widget on top when using QMacNativeWidget.
- qt_mac_handleMouseEvent(theEvent, QEvent::MouseMove, Qt::NoButton, qwidget);
-}
-
-- (void)mouseDown:(NSEvent *)theEvent
-{
- qt_mac_handleMouseEvent(theEvent, QEvent::MouseButtonPress, Qt::LeftButton, qwidget);
- // Don't call super here. This prevents us from getting the mouseUp event,
- // which we need to send even if the mouseDown event was not accepted.
- // (this is standard Qt behavior.)
-}
-
-- (void)mouseUp:(NSEvent *)theEvent
-{
- qt_mac_handleMouseEvent(theEvent, QEvent::MouseButtonRelease, Qt::LeftButton, qwidget);
-}
-
-- (void)rightMouseDown:(NSEvent *)theEvent
-{
- qt_mac_handleMouseEvent(theEvent, QEvent::MouseButtonPress, Qt::RightButton, qwidget);
-}
-
-- (void)rightMouseUp:(NSEvent *)theEvent
-{
- qt_mac_handleMouseEvent(theEvent, QEvent::MouseButtonRelease, Qt::RightButton, qwidget);
-}
-
-- (void)otherMouseDown:(NSEvent *)theEvent
-{
- Qt::MouseButton mouseButton = cocoaButton2QtButton([theEvent buttonNumber]);
- qt_mac_handleMouseEvent(theEvent, QEvent::MouseButtonPress, mouseButton, qwidget);
-}
-
-- (void)otherMouseUp:(NSEvent *)theEvent
-{
- Qt::MouseButton mouseButton = cocoaButton2QtButton([theEvent buttonNumber]);
- qt_mac_handleMouseEvent(theEvent, QEvent::MouseButtonRelease, mouseButton, qwidget);
-}
-
-- (void)mouseDragged:(NSEvent *)theEvent
-{
- qt_mac_handleMouseEvent(theEvent, QEvent::MouseMove, Qt::NoButton, qwidget);
-}
-
-- (void)rightMouseDragged:(NSEvent *)theEvent
-{
- qt_mac_handleMouseEvent(theEvent, QEvent::MouseMove, Qt::NoButton, qwidget);
-}
-
-- (void)otherMouseDragged:(NSEvent *)theEvent
-{
- qt_mac_handleMouseEvent(theEvent, QEvent::MouseMove, Qt::NoButton, qwidget);
-}
-
-- (void)scrollWheel:(NSEvent *)theEvent
-{
- // Give the Input Manager a chance to process the wheel event.
- NSInputManager *currentIManager = [NSInputManager currentInputManager];
- if (currentIManager && [currentIManager wantsToHandleMouseEvents]) {
- [currentIManager handleMouseEvent:theEvent];
- }
-
- Qt::MouseButtons buttons = QApplication::mouseButtons();
- Qt::KeyboardModifiers keyMods = qt_cocoaModifiers2QtModifiers([theEvent modifierFlags]);
-
- // Find the widget that should receive the event:
- QPoint qlocal, qglobal;
- QWidget *widgetToGetMouse = qt_mac_getTargetForMouseEvent(theEvent, QEvent::Wheel, qlocal, qglobal, qwidget, 0);
- if (!widgetToGetMouse)
- return;
-
- int deltaX = 0;
- int deltaY = 0;
- int deltaZ = 0;
-
- const EventRef carbonEvent = (EventRef)[theEvent eventRef];
- const UInt32 carbonEventKind = carbonEvent ? ::GetEventKind(carbonEvent) : 0;
- const bool scrollEvent = carbonEventKind == kEventMouseScroll;
-
- if (scrollEvent) {
- // The mouse device containts pixel scroll wheel support (Mighty Mouse, Trackpad).
- // Since deviceDelta is delivered as pixels rather than degrees, we need to
- // convert from pixels to degrees in a sensible manner.
- // It looks like 1/4 degrees per pixel behaves most native.
- // (NB: Qt expects the unit for delta to be 8 per degree):
- const int pixelsToDegrees = 2; // 8 * 1/4
- deltaX = [theEvent deviceDeltaX] * pixelsToDegrees;
- deltaY = [theEvent deviceDeltaY] * pixelsToDegrees;
- deltaZ = [theEvent deviceDeltaZ] * pixelsToDegrees;
- } else {
- // carbonEventKind == kEventMouseWheelMoved
- // Remove acceleration, and use either -120 or 120 as delta:
- deltaX = qBound(-120, int([theEvent deltaX] * 10000), 120);
- deltaY = qBound(-120, int([theEvent deltaY] * 10000), 120);
- deltaZ = qBound(-120, int([theEvent deltaZ] * 10000), 120);
- }
-
-#ifndef QT_NO_WHEELEVENT
- // ### Qt 5: Send one QWheelEvent with dx, dy and dz
-
- if (deltaX != 0 && deltaY != 0)
- QMacScrollOptimization::initDelayedScroll();
-
- if (deltaX != 0) {
- QWheelEvent qwe(qlocal, qglobal, deltaX, buttons, keyMods, Qt::Horizontal);
- qt_sendSpontaneousEvent(widgetToGetMouse, &qwe);
- }
-
- if (deltaY != 0) {
- QWheelEvent qwe(qlocal, qglobal, deltaY, buttons, keyMods, Qt::Vertical);
- qt_sendSpontaneousEvent(widgetToGetMouse, &qwe);
- }
-
- if (deltaZ != 0) {
- // Qt doesn't explicitly support wheels with a Z component. In a misguided attempt to
- // try to be ahead of the pack, I'm adding this extra value.
- QWheelEvent qwe(qlocal, qglobal, deltaZ, buttons, keyMods, (Qt::Orientation)3);
- qt_sendSpontaneousEvent(widgetToGetMouse, &qwe);
- }
-
- if (deltaX != 0 && deltaY != 0)
- QMacScrollOptimization::performDelayedScroll();
-#endif //QT_NO_WHEELEVENT
-}
-
-- (void)tabletProximity:(NSEvent *)tabletEvent
-{
- qt_dispatchTabletProximityEvent(tabletEvent);
-}
-
-- (void)tabletPoint:(NSEvent *)tabletEvent
-{
- if (!qt_mac_handleTabletEvent(self, tabletEvent))
- [super tabletPoint:tabletEvent];
-}
-
-- (void)magnifyWithEvent:(NSEvent *)event
-{
- QPoint qlocal, qglobal;
- QWidget *widgetToGetGesture = 0;
- qt_mac_getTargetForMouseEvent(event, QEvent::Gesture, qlocal, qglobal, qwidget, &widgetToGetGesture);
- if (!widgetToGetGesture)
- return;
- if (!QApplicationPrivate::tryModalHelper(widgetToGetGesture, 0))
- return;
-
-#ifndef QT_NO_GESTURES
- QNativeGestureEvent qNGEvent;
- qNGEvent.gestureType = QNativeGestureEvent::Zoom;
- NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]];
- qNGEvent.position = flipPoint(p).toPoint();
- qNGEvent.percentage = [event magnification];
- qt_sendSpontaneousEvent(widgetToGetGesture, &qNGEvent);
-#endif // QT_NO_GESTURES
-}
-
-- (void)rotateWithEvent:(NSEvent *)event
-{
- QPoint qlocal, qglobal;
- QWidget *widgetToGetGesture = 0;
- qt_mac_getTargetForMouseEvent(event, QEvent::Gesture, qlocal, qglobal, qwidget, &widgetToGetGesture);
- if (!widgetToGetGesture)
- return;
- if (!QApplicationPrivate::tryModalHelper(widgetToGetGesture, 0))
- return;
-
-#ifndef QT_NO_GESTURES
- QNativeGestureEvent qNGEvent;
- qNGEvent.gestureType = QNativeGestureEvent::Rotate;
- NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]];
- qNGEvent.position = flipPoint(p).toPoint();
- qNGEvent.percentage = -[event rotation];
- qt_sendSpontaneousEvent(widgetToGetGesture, &qNGEvent);
-#endif // QT_NO_GESTURES
-}
-
-- (void)swipeWithEvent:(NSEvent *)event
-{
- QPoint qlocal, qglobal;
- QWidget *widgetToGetGesture = 0;
- qt_mac_getTargetForMouseEvent(event, QEvent::Gesture, qlocal, qglobal, qwidget, &widgetToGetGesture);
- if (!widgetToGetGesture)
- return;
- if (!QApplicationPrivate::tryModalHelper(widgetToGetGesture, 0))
- return;
-
-#ifndef QT_NO_GESTURES
- QNativeGestureEvent qNGEvent;
- qNGEvent.gestureType = QNativeGestureEvent::Swipe;
- NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]];
- qNGEvent.position = flipPoint(p).toPoint();
- if ([event deltaX] == 1)
- qNGEvent.angle = 180.0f;
- else if ([event deltaX] == -1)
- qNGEvent.angle = 0.0f;
- else if ([event deltaY] == 1)
- qNGEvent.angle = 90.0f;
- else if ([event deltaY] == -1)
- qNGEvent.angle = 270.0f;
- qt_sendSpontaneousEvent(widgetToGetGesture, &qNGEvent);
-#endif // QT_NO_GESTURES
-}
-
-- (void)beginGestureWithEvent:(NSEvent *)event
-{
- QPoint qlocal, qglobal;
- QWidget *widgetToGetGesture = 0;
- qt_mac_getTargetForMouseEvent(event, QEvent::Gesture, qlocal, qglobal, qwidget, &widgetToGetGesture);
- if (!widgetToGetGesture)
- return;
- if (!QApplicationPrivate::tryModalHelper(widgetToGetGesture, 0))
- return;
-
-#ifndef QT_NO_GESTURES
- QNativeGestureEvent qNGEvent;
- qNGEvent.gestureType = QNativeGestureEvent::GestureBegin;
- NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]];
- qNGEvent.position = flipPoint(p).toPoint();
- qt_sendSpontaneousEvent(widgetToGetGesture, &qNGEvent);
-#endif // QT_NO_GESTURES
-}
-
-- (void)endGestureWithEvent:(NSEvent *)event
-{
- QPoint qlocal, qglobal;
- QWidget *widgetToGetGesture = 0;
- qt_mac_getTargetForMouseEvent(event, QEvent::Gesture, qlocal, qglobal, qwidget, &widgetToGetGesture);
- if (!widgetToGetGesture)
- return;
- if (!QApplicationPrivate::tryModalHelper(widgetToGetGesture, 0))
- return;
-
-#ifndef QT_NO_GESTURES
- QNativeGestureEvent qNGEvent;
- qNGEvent.gestureType = QNativeGestureEvent::GestureEnd;
- NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]];
- qNGEvent.position = flipPoint(p).toPoint();
- qt_sendSpontaneousEvent(widgetToGetGesture, &qNGEvent);
-}
-#endif // QT_NO_GESTURES
-
-- (void)frameDidChange:(NSNotification *)note
-{
- Q_UNUSED(note);
- if (!qwidget)
- return;
- if (qwidget->isWindow())
- return;
- NSRect newFrame = [self frame];
- QRect newGeo(newFrame.origin.x, newFrame.origin.y, newFrame.size.width, newFrame.size.height);
- bool moved = qwidget->testAttribute(Qt::WA_Moved);
- bool resized = qwidget->testAttribute(Qt::WA_Resized);
- qwidget->setGeometry(newGeo);
- qwidget->setAttribute(Qt::WA_Moved, moved);
- qwidget->setAttribute(Qt::WA_Resized, resized);
- qwidgetprivate->syncCocoaMask();
-}
-
-- (BOOL)isEnabled
-{
- if (!qwidget)
- return [super isEnabled];
- return [super isEnabled] && qwidget->isEnabled();
-}
-
-- (void)setEnabled:(BOOL)flag
-{
- QMacCocoaAutoReleasePool pool;
- [super setEnabled:flag];
- if (qwidget && qwidget->isEnabled() != flag)
- qwidget->setEnabled(flag);
-}
-
-+ (Class)cellClass
-{
- return [NSActionCell class];
-}
-
-- (BOOL)acceptsFirstResponder
-{
- if (!qwidget)
- return NO;
-
- // Disabled widget shouldn't get focus even if it's a window.
- // hence disabled windows will not get any key or mouse events.
- if (!qwidget->isEnabled())
- return NO;
-
- if (qwidget->isWindow() && !qt_widget_private(qwidget)->topData()->embedded) {
- QWidget *focusWidget = qApp->focusWidget();
- if (!focusWidget) {
- // There is no focus widget, but we still want to receive key events
- // for shortcut handling etc. So we accept first responer for the
- // content view as a last resort:
- return YES;
- }
- if (!focusWidget->internalWinId() && focusWidget->nativeParentWidget() == qwidget) {
- // The current focus widget is alien, and hence, cannot get acceptsFirstResponder
- // calls. Since the focus widget is a child of qwidget, we let this view say YES:
- return YES;
- }
- if (focusWidget->window() != qwidget) {
- // The current focus widget is in another window. Since cocoa
- // suggest that this window should be key now, we accept:
- return YES;
- }
- }
-
- return qwidget->focusPolicy() != Qt::NoFocus;
-}
-
-- (BOOL)resignFirstResponder
-{
- if (!qwidget)
- return YES;
-
- // Seems like the following test only triggers if this
- // view is inside a QMacNativeWidget:
-// if (QWidget *fw = QApplication::focusWidget()) {
-// if (qwidget == fw || qwidget == fw->nativeParentWidget())
-// fw->clearFocus();
-// }
- return YES;
-}
-
-- (BOOL)becomeFirstResponder
-{
- // see the comment in the acceptsFirstResponder - if the window "stole" focus
- // let it become the responder, but don't tell Qt
- if (qwidget && qt_widget_private(qwidget->window())->topData()->embedded
- && !QApplication::focusWidget() && qwidget->focusPolicy() != Qt::NoFocus)
- qwidget->setFocus(Qt::OtherFocusReason);
- return YES;
-}
-
-- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal
-{
- Q_UNUSED(isLocal);
- return supportedActions;
-}
-
-- (void)setSupportedActions:(NSDragOperation)actions
-{
- supportedActions = actions;
-}
-
-- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
-{
- Q_UNUSED(anImage);
- Q_UNUSED(aPoint);
- macCurrentDnDParameters()->performedAction = operation;
- if (QDragManager::self()->object
- && QDragManager::self()->dragPrivate()->executed_action != Qt::ActionMask) {
- macCurrentDnDParameters()->performedAction =
- qt_mac_mapDropAction(QDragManager::self()->dragPrivate()->executed_action);
- }
-}
-
-- (QWidget *)qt_qwidget
-{
- return qwidget;
-}
-
-- (void) qt_clearQWidget
-{
- qwidget = 0;
- qwidgetprivate = 0;
-}
-
-- (void)keyDown:(NSEvent *)theEvent
-{
- if (!qwidget)
- return;
- QWidget *widgetToGetKey = qt_mac_getTargetForKeyEvent(qwidget);
- if (!widgetToGetKey)
- return;
-
- sendKeyEvents = true;
-
- if (widgetToGetKey->testAttribute(Qt::WA_InputMethodEnabled)
- && !(widgetToGetKey->inputMethodHints() & Qt::ImhDigitsOnly
- || widgetToGetKey->inputMethodHints() & Qt::ImhFormattedNumbersOnly
- || widgetToGetKey->inputMethodHints() & Qt::ImhHiddenText)) {
- fromKeyDownEvent = true;
- [qt_mac_nativeview_for(qwidget) interpretKeyEvents:[NSArray arrayWithObject: theEvent]];
- fromKeyDownEvent = false;
- }
-
- if (sendKeyEvents && !composing) {
- bool keyEventEaten = qt_dispatchKeyEvent(theEvent, widgetToGetKey);
- if (!keyEventEaten && qwidget) {
- // The event is not yet eaten, and if Qt is embedded inside a native
- // cocoa application, send it to first responder not owned by Qt.
- // The exception is if widgetToGetKey was redirected to a popup.
- QWidget *toplevel = qwidget->window();
- if (toplevel == widgetToGetKey->window()) {
- if (qt_widget_private(toplevel)->topData()->embedded) {
- if (NSResponder *w = [qt_mac_nativeview_for(toplevel) superview])
- [w keyDown:theEvent];
- }
- }
- }
- }
-}
-
-
-- (void)keyUp:(NSEvent *)theEvent
-{
- if (sendKeyEvents) {
- QWidget *widgetToGetKey = qt_mac_getTargetForKeyEvent(qwidget);
- if (!widgetToGetKey)
- return;
-
- bool keyEventEaten = qt_dispatchKeyEvent(theEvent, widgetToGetKey);
- if (!keyEventEaten && qwidget) {
- // The event is not yet eaten, and if Qt is embedded inside a native
- // cocoa application, send it to first responder not owned by Qt.
- // The exception is if widgetToGetKey was redirected to a popup.
- QWidget *toplevel = qwidget->window();
- if (toplevel == widgetToGetKey->window()) {
- if (qt_widget_private(toplevel)->topData()->embedded) {
- if (NSResponder *w = [qt_mac_nativeview_for(toplevel) superview])
- [w keyUp:theEvent];
- }
- }
- }
- }
-}
-
-- (void)viewWillMoveToWindow:(NSWindow *)window
-{
- if (qwidget == 0)
- return;
-
- if (qwidget->windowFlags() & Qt::MSWindowsOwnDC
- && (window != [self window])) { // OpenGL Widget
- QEvent event(QEvent::MacGLClearDrawable);
- qApp->sendEvent(qwidget, &event);
- }
-}
-
-- (void)viewDidMoveToWindow
-{
- if (qwidget == 0)
- return;
-
- if (qwidget->windowFlags() & Qt::MSWindowsOwnDC && [self window]) {
- // call update paint event
- qwidgetprivate->needWindowChange = true;
- QEvent event(QEvent::MacGLWindowChange);
- qApp->sendEvent(qwidget, &event);
- }
-}
-
-
-// NSTextInput Protocol implementation
-
-- (void) insertText:(id)aString
-{
- QString commitText;
- if ([aString length]) {
- if ([aString isKindOfClass:[NSAttributedString class]]) {
- commitText = QCFString::toQString(reinterpret_cast<CFStringRef>([aString string]));
- } else {
- commitText = QCFString::toQString(reinterpret_cast<CFStringRef>(aString));
- };
- }
-
- // When entering characters through Character Viewer or Keyboard Viewer, the text is passed
- // through this insertText method. Since we dont receive a keyDown Event in such cases, the
- // composing flag will be false.
- if (([aString length] && composing) || !fromKeyDownEvent) {
- // Send the commit string to the widget.
- composing = false;
- sendKeyEvents = false;
- QInputMethodEvent e;
- e.setCommitString(commitText);
- if (QWidget *widgetToGetKey = qt_mac_getTargetForKeyEvent(qwidget))
- qt_sendSpontaneousEvent(widgetToGetKey, &e);
- } else {
- // The key sequence "`q" on a French Keyboard will generate two calls to insertText before
- // it returns from interpretKeyEvents. The first call will turn off 'composing' and accept
- // the "`" key. The last keyDown event needs to be processed by the widget to get the
- // character "q". The string parameter is ignored for the second call.
- sendKeyEvents = true;
- }
-
- composingText->clear();
-}
-
-- (void) setMarkedText:(id)aString selectedRange:(NSRange)selRange
-{
- // Generate the QInputMethodEvent with preedit string and the attributes
- // for rendering it. The attributes handled here are 'underline',
- // 'underline color' and 'cursor position'.
- sendKeyEvents = false;
- composing = true;
- QString qtText;
- // Cursor position is retrived from the range.
- QList<QInputMethodEvent::Attribute> attrs;
- attrs<<QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, selRange.location + selRange.length, 1, QVariant());
- if ([aString isKindOfClass:[NSAttributedString class]]) {
- qtText = QCFString::toQString(reinterpret_cast<CFStringRef>([aString string]));
- composingLength = qtText.length();
- int index = 0;
- // Create attributes for individual sections of preedit text
- while (index < composingLength) {
- NSRange effectiveRange;
- NSRange range = NSMakeRange(index, composingLength-index);
- NSDictionary *attributes = [aString attributesAtIndex:index
- longestEffectiveRange:&effectiveRange
- inRange:range];
- NSNumber *underlineStyle = [attributes objectForKey:NSUnderlineStyleAttributeName];
- if (underlineStyle) {
- QColor clr (Qt::black);
- NSColor *color = [attributes objectForKey:NSUnderlineColorAttributeName];
- if (color) {
- clr = colorFrom(color);
- }
- QTextCharFormat format;
- format.setFontUnderline(true);
- format.setUnderlineColor(clr);
- attrs<<QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,
- effectiveRange.location,
- effectiveRange.length,
- format);
- }
- index = effectiveRange.location + effectiveRange.length;
- }
- } else {
- // No attributes specified, take only the preedit text.
- qtText = QCFString::toQString(reinterpret_cast<CFStringRef>(aString));
- composingLength = qtText.length();
- }
- // Make sure that we have at least one text format.
- if (attrs.size() <= 1) {
- QTextCharFormat format;
- format.setFontUnderline(true);
- attrs<<QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat,
- 0, composingLength, format);
- }
- *composingText = qtText;
-
- QInputMethodEvent e(qtText, attrs);
- if (QWidget *widgetToGetKey = qt_mac_getTargetForKeyEvent(qwidget))
- qt_sendSpontaneousEvent(widgetToGetKey, &e);
-
- if (!composingLength)
- composing = false;
-}
-
-- (void) unmarkText
-{
- if (composing) {
- QInputMethodEvent e;
- e.setCommitString(*composingText);
- if (QWidget *widgetToGetKey = qt_mac_getTargetForKeyEvent(qwidget))
- qt_sendSpontaneousEvent(widgetToGetKey, &e);
- }
- composingText->clear();
- composing = false;
-}
-
-- (BOOL) hasMarkedText
-{
- return (composing ? YES: NO);
-}
-
-- (void) doCommandBySelector:(SEL)aSelector
-{
- Q_UNUSED(aSelector);
-}
-
-- (BOOL)isComposing
-{
- return composing;
-}
-
-- (NSInteger) conversationIdentifier
-{
- // Return a unique identifier fot this ime conversation
- return (NSInteger)self;
-}
-
-- (NSAttributedString *) attributedSubstringFromRange:(NSRange)theRange
-{
- QString selectedText(qwidget->inputMethodQuery(Qt::ImCurrentSelection).toString());
- if (!selectedText.isEmpty()) {
- QCFString string(selectedText.mid(theRange.location, theRange.length));
- const NSString *tmpString = reinterpret_cast<const NSString *>((CFStringRef)string);
- return [[[NSAttributedString alloc] initWithString:const_cast<NSString *>(tmpString)] autorelease];
- } else {
- return nil;
- }
-}
-
-- (NSRange) markedRange
-{
- NSRange range;
- if (composing) {
- range.location = 0;
- range.length = composingLength;
- } else {
- range.location = NSNotFound;
- range.length = 0;
- }
- return range;
-}
-
-- (NSRange) selectedRange
-{
- NSRange selRange;
- QString selectedText(qwidget->inputMethodQuery(Qt::ImCurrentSelection).toString());
- if (!selectedText.isEmpty()) {
- // Consider only the selected text.
- selRange.location = 0;
- selRange.length = selectedText.length();
- } else {
- // No selected text.
- selRange.location = NSNotFound;
- selRange.length = 0;
- }
- return selRange;
-
-}
-
-- (NSRect) firstRectForCharacterRange:(NSRange)theRange
-{
- Q_UNUSED(theRange);
- // The returned rect is always based on the internal cursor.
- QWidget *widgetToGetKey = qt_mac_getTargetForKeyEvent(qwidget);
- if (!widgetToGetKey)
- return NSZeroRect;
-
- QRect mr(widgetToGetKey->inputMethodQuery(Qt::ImMicroFocus).toRect());
- QPoint mp(widgetToGetKey->mapToGlobal(QPoint(mr.bottomLeft())));
- NSRect rect ;
- rect.origin.x = mp.x();
- rect.origin.y = flipYCoordinate(mp.y());
- rect.size.width = mr.width();
- rect.size.height = mr.height();
- return rect;
-}
-
-- (NSUInteger)characterIndexForPoint:(NSPoint)thePoint
-{
- // We dont support cursor movements using mouse while composing.
- Q_UNUSED(thePoint);
- return NSNotFound;
-}
-
-- (NSArray*) validAttributesForMarkedText
-{
- QWidget *widgetToGetKey = qt_mac_getTargetForKeyEvent(qwidget);
- if (!widgetToGetKey)
- return nil;
-
- if (!widgetToGetKey->testAttribute(Qt::WA_InputMethodEnabled))
- return nil; // Not sure if that's correct, but it's saves a malloc.
-
- // Support only underline color/style.
- return [NSArray arrayWithObjects:NSUnderlineColorAttributeName,
- NSUnderlineStyleAttributeName, nil];
-}
-@end
-
-QT_BEGIN_NAMESPACE
-void QMacInputContext::reset()
-{
- QWidget *w = QInputContext::focusWidget();
- if (w) {
- NSView *view = qt_mac_effectiveview_for(w);
- if ([view isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]]) {
- QMacCocoaAutoReleasePool pool;
- QT_MANGLE_NAMESPACE(QCocoaView) *qc = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view);
- NSInputManager *currentIManager = [NSInputManager currentInputManager];
- if (currentIManager) {
- [currentIManager markedTextAbandoned:view];
- [qc unmarkText];
- }
- }
- }
-}
-
-bool QMacInputContext::isComposing() const
-{
- QWidget *w = QInputContext::focusWidget();
- if (w) {
- NSView *view = qt_mac_effectiveview_for(w);
- if ([view isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]]) {
- return [static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view) isComposing];
- }
- }
- return false;
-}
-
-extern bool qt_mac_in_drag;
-void * /*NSImage */qt_mac_create_nsimage(const QPixmap &pm);
-static const int default_pm_hotx = -2;
-static const int default_pm_hoty = -16;
-static const char* 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",
-};
-
-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((CFStringRef) NSDragPboard, QMacPasteboardMime::MIME_DND);
- dragPrivate()->data->setData(QLatin1String("application/x-qt-mime-type-name"), QByteArray("dummy"));
- dragBoard.setMimeData(dragPrivate()->data);
-
- // create the image
- 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);
- QPixmap tmp(fm.width(s), fm.height());
- if(!tmp.isNull()) {
- 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);
- // 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;
- }
-
- // Convert the image to NSImage:
- NSImage *image = (NSImage *)qt_mac_create_nsimage(pix);
- [image retain];
-
- DnDParams *dndParams = macCurrentDnDParameters();
- QT_MANGLE_NAMESPACE(QCocoaView) *theView = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(dndParams->view);
-
- // Save supported actions:
- [theView setSupportedActions: qt_mac_mapDropActions(dragPrivate()->possible_actions)];
- QPoint pointInView = [theView qt_qwidget]->mapFromGlobal(dndParams->globalPoint);
- NSPoint imageLoc = {pointInView.x() - hotspot.x(), pointInView.y() + pix.height() - hotspot.y()};
- NSSize mouseOffset = {0.0, 0.0};
- NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
- dragPrivate()->executed_action = Qt::ActionMask;
-
- // Execute the drag:
- [theView retain];
- [theView dragImage:image
- at:imageLoc
- offset:mouseOffset
- event:dndParams->theEvent
- pasteboard:pboard
- source:theView
- slideBack:YES];
-
- // Reset the implicit grab widget when drag ends because we will not
- // receive the mouse release event when DND is active:
- qt_button_down = 0;
- [theView release];
- [image release];
- if (dragPrivate())
- dragPrivate()->executed_action = Qt::IgnoreAction;
- object = 0;
- Qt::DropAction performedAction(qt_mac_mapNSDragOperation(dndParams->performedAction));
-
- // Do post drag processing, if required.
- if (performedAction != Qt::IgnoreAction) {
- // 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) {
- 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 (performedAction == Qt::MoveAction)
- QFile::rename(fromUrl.path(), toUrl.path());
- else if (performedAction == Qt::CopyAction)
- QFile::copy(fromUrl.path(), toUrl.path());
- }
- }
- }
-
- // Clean-up:
- o->setMimeData(0);
- o->deleteLater();
- return performedAction;
-}
-
-QT_END_NAMESPACE
-
-#endif // QT_MAC_USE_COCOA
diff --git a/src/gui/kernel/qcocoaview_mac_p.h b/src/gui/kernel/qcocoaview_mac_p.h
deleted file mode 100644
index cc79b6705b..0000000000
--- a/src/gui/kernel/qcocoaview_mac_p.h
+++ /dev/null
@@ -1,87 +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$
-**
-****************************************************************************/
-
-//
-// 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 <qevent.h>
-#ifdef QT_MAC_USE_COCOA
-#import <Cocoa/Cocoa.h>
-
-@class QT_MANGLE_NAMESPACE(QCocoaView);
-QT_FORWARD_DECLARE_CLASS(QWidgetPrivate);
-QT_FORWARD_DECLARE_CLASS(QWidget);
-QT_FORWARD_DECLARE_CLASS(QEvent);
-QT_FORWARD_DECLARE_CLASS(QString);
-QT_FORWARD_DECLARE_CLASS(QStringList);
-
-Q_GUI_EXPORT
-@interface QT_MANGLE_NAMESPACE(QCocoaView) : NSControl <NSTextInput> {
- QWidget *qwidget;
- QWidgetPrivate *qwidgetprivate;
- NSDragOperation supportedActions;
- bool composing;
- int composingLength;
- bool sendKeyEvents;
- bool fromKeyDownEvent;
- QString *composingText;
- @public int alienTouchCount;
-}
-- (id)initWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate;
-- (void) finishInitWithQWidget:(QWidget *)widget widgetPrivate:(QWidgetPrivate *)widgetprivate;
-- (void)frameDidChange:(NSNotification *)note;
-- (void)setSupportedActions:(NSDragOperation)actions;
-- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal;
-- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation;
-- (BOOL)isComposing;
-- (QWidget *)qt_qwidget;
-- (void) qt_clearQWidget;
-
-@end
-#endif
diff --git a/src/gui/kernel/qcocoawindow_mac.mm b/src/gui/kernel/qcocoawindow_mac.mm
deleted file mode 100644
index 6e5023aaca..0000000000
--- a/src/gui/kernel/qcocoawindow_mac.mm
+++ /dev/null
@@ -1,90 +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 "qmacdefines_mac.h"
-#ifdef QT_MAC_USE_COCOA
-#import <private/qcocoawindow_mac_p.h>
-#import <private/qcocoawindowdelegate_mac_p.h>
-#import <private/qcocoaview_mac_p.h>
-#import <private/qt_cocoa_helpers_mac_p.h>
-#import <private/qcocoawindowcustomthemeframe_mac_p.h>
-#import <private/qcocoaapplication_mac_p.h>
-#import <private/qdnd_p.h>
-#import <private/qmultitouch_mac_p.h>
-
-#include <QtGui/QWidget>
-
-QT_FORWARD_DECLARE_CLASS(QWidget);
-QT_USE_NAMESPACE
-
-@implementation NSWindow (QT_MANGLE_NAMESPACE(QWidgetIntegration))
-
-- (id)QT_MANGLE_NAMESPACE(qt_initWithQWidget):(QWidget*)widget contentRect:(NSRect)rect styleMask:(NSUInteger)mask
-{
- self = [self initWithContentRect:rect styleMask:mask backing:NSBackingStoreBuffered defer:YES];
- if (self) {
- [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] becomeDelegteForWindow:self widget:widget];
- [self setReleasedWhenClosed:NO];
- }
- return self;
-}
-
-- (QWidget *)QT_MANGLE_NAMESPACE(qt_qwidget)
-{
- QWidget *widget = 0;
- if ([self delegate] == [QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate])
- widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self];
- return widget;
-}
-
-@end
-
-@implementation QT_MANGLE_NAMESPACE(QCocoaWindow)
-
-/***********************************************************************
- Copy and Paste between QCocoaWindow and QCocoaPanel
- This is a bit unfortunate, but thanks to the dynamic dispatch we
- have to duplicate this code or resort to really silly forwarding methods
-**************************************************************************/
-#include "qcocoasharedwindowmethods_mac_p.h"
-
-@end
-#endif
diff --git a/src/gui/kernel/qcocoawindow_mac_p.h b/src/gui/kernel/qcocoawindow_mac_p.h
deleted file mode 100644
index d567cab244..0000000000
--- a/src/gui/kernel/qcocoawindow_mac_p.h
+++ /dev/null
@@ -1,97 +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$
-**
-****************************************************************************/
-
-//
-// 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.
-//
-
-#ifndef QCOCOAWINDOW_MAC_P
-#define QCOCOAWINDOW_MAC_P
-
-#ifdef QT_MAC_USE_COCOA
-#include "qmacdefines_mac.h"
-#import <Cocoa/Cocoa.h>
-#include <private/qapplication_p.h>
-#include <private/qbackingstore_p.h>
-
-enum { QtMacCustomizeWindow = 1 << 21 }; // This will one day be run over by
-
-QT_FORWARD_DECLARE_CLASS(QWidget);
-QT_FORWARD_DECLARE_CLASS(QStringList);
-QT_FORWARD_DECLARE_CLASS(QCocoaDropData);
-
-@interface NSWindow (QtCoverForHackWithCategory)
-+ (Class)frameViewClassForStyleMask:(NSUInteger)styleMask;
-@end
-
-@interface NSWindow (QT_MANGLE_NAMESPACE(QWidgetIntegration))
-- (id)QT_MANGLE_NAMESPACE(qt_initWithQWidget):(QWidget *)widget contentRect:(NSRect)rect styleMask:(NSUInteger)mask;
-- (QWidget *)QT_MANGLE_NAMESPACE(qt_qwidget);
-@end
-
-@interface NSWindow (QtIntegration)
-- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
-- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender;
-- (void)draggingExited:(id <NSDraggingInfo>)sender;
-- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
-@end
-
-@interface QT_MANGLE_NAMESPACE(QCocoaWindow) : NSWindow {
- QStringList *currentCustomDragTypes;
- QCocoaDropData *dropData;
- NSInteger dragEnterSequence;
-}
-
-+ (Class)frameViewClassForStyleMask:(NSUInteger)styleMask;
-- (void)registerDragTypes;
-- (void)drawRectOriginal:(NSRect)rect;
-
-@end
-#endif
-
-#endif
diff --git a/src/gui/kernel/qcocoawindowcustomthemeframe_mac.mm b/src/gui/kernel/qcocoawindowcustomthemeframe_mac.mm
deleted file mode 100644
index b761934c01..0000000000
--- a/src/gui/kernel/qcocoawindowcustomthemeframe_mac.mm
+++ /dev/null
@@ -1,62 +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 "qmacdefines_mac.h"
-
-#ifdef QT_MAC_USE_COCOA
-
-#import "private/qcocoawindowcustomthemeframe_mac_p.h"
-#import "private/qcocoawindow_mac_p.h"
-#include "private/qt_cocoa_helpers_mac_p.h"
-#include "qwidget.h"
-
-@implementation QT_MANGLE_NAMESPACE(QCocoaWindowCustomThemeFrame)
-
-- (void)_updateButtons
-{
- [super _updateButtons];
- NSWindow *window = [self window];
- qt_syncCocoaTitleBarButtons(window, [window QT_MANGLE_NAMESPACE(qt_qwidget)]);
-}
-
-@end
-
-#endif
diff --git a/src/gui/kernel/qcocoawindowcustomthemeframe_mac_p.h b/src/gui/kernel/qcocoawindowcustomthemeframe_mac_p.h
deleted file mode 100644
index 09b40875f6..0000000000
--- a/src/gui/kernel/qcocoawindowcustomthemeframe_mac_p.h
+++ /dev/null
@@ -1,61 +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$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp
-// and many other. This header file may change from version to version
-// without notice, or even be removed.
-//
-// We mean it.
-//
-#import <Cocoa/Cocoa.h>
-#include "qmacdefines_mac.h"
-#import "qnsthemeframe_mac_p.h"
-
-@interface QT_MANGLE_NAMESPACE(QCocoaWindowCustomThemeFrame) : NSThemeFrame
-{
-}
-
-@end
diff --git a/src/gui/kernel/qcocoawindowdelegate_mac.mm b/src/gui/kernel/qcocoawindowdelegate_mac.mm
deleted file mode 100644
index 1faf068a12..0000000000
--- a/src/gui/kernel/qcocoawindowdelegate_mac.mm
+++ /dev/null
@@ -1,439 +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$
-**
-****************************************************************************/
-
-#import "private/qcocoawindowdelegate_mac_p.h"
-#ifdef QT_MAC_USE_COCOA
-#include <private/qwidget_p.h>
-#include <private/qapplication_p.h>
-#include <private/qt_cocoa_helpers_mac_p.h>
-#include <qevent.h>
-#include <qlayout.h>
-#include <qcoreapplication.h>
-#include <qmenubar.h>
-#include <QMainWindow>
-#include <QToolBar>
-#include <private/qmainwindowlayout_p.h>
-
-QT_BEGIN_NAMESPACE
-extern QWidgetData *qt_qwidget_data(QWidget *); // qwidget.cpp
-extern void onApplicationWindowChangedActivation(QWidget *, bool); //qapplication_mac.mm
-extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); // qapplication.cpp
-QT_END_NAMESPACE
-
-QT_USE_NAMESPACE
-
-static QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) *sharedCocoaWindowDelegate = nil;
-
-// This is a singleton, but unlike most Cocoa singletons, it lives in a library and could be
-// pontentially loaded and unloaded. This means we should at least attempt to do the
-// memory management correctly.
-
-static void cleanupCocoaWindowDelegate()
-{
- [sharedCocoaWindowDelegate release];
-}
-
-@implementation QT_MANGLE_NAMESPACE(QCocoaWindowDelegate)
-
-- (id)init
-{
- self = [super init];
- if (self != nil) {
- m_windowHash = new QHash<NSWindow *, QWidget *>();
- m_drawerHash = new QHash<NSDrawer *, QWidget *>();
- }
- return self;
-}
-
-- (void)dealloc
-{
- sharedCocoaWindowDelegate = nil;
- QHash<NSWindow *, QWidget *>::const_iterator windowIt = m_windowHash->constBegin();
- while (windowIt != m_windowHash->constEnd()) {
- [windowIt.key() setDelegate:nil];
- ++windowIt;
- }
- delete m_windowHash;
- QHash<NSDrawer *, QWidget *>::const_iterator drawerIt = m_drawerHash->constBegin();
- while (drawerIt != m_drawerHash->constEnd()) {
- [drawerIt.key() setDelegate:nil];
- ++drawerIt;
- }
- delete m_drawerHash;
- [super dealloc];
-}
-
-+ (id)allocWithZone:(NSZone *)zone
-{
- @synchronized(self) {
- if (sharedCocoaWindowDelegate == nil) {
- sharedCocoaWindowDelegate = [super allocWithZone:zone];
- return sharedCocoaWindowDelegate;
- qAddPostRoutine(cleanupCocoaWindowDelegate);
- }
- }
- return nil;
-}
-
-+ (QT_MANGLE_NAMESPACE(QCocoaWindowDelegate)*)sharedDelegate
-{
- @synchronized(self) {
- if (sharedCocoaWindowDelegate == nil)
- [[self alloc] init];
- }
- return [[sharedCocoaWindowDelegate retain] autorelease];
-}
-
--(void)syncSizeForWidget:(QWidget *)qwidget toSize:(const QSize &)newSize fromSize:(const QSize &)oldSize
-{
- qt_qwidget_data(qwidget)->crect.setSize(newSize);
- // ### static contents optimization needs to go here
- const OSViewRef view = qt_mac_nativeview_for(qwidget);
- [view setFrameSize:NSMakeSize(newSize.width(), newSize.height())];
- if (!qwidget->isVisible()) {
- qwidget->setAttribute(Qt::WA_PendingResizeEvent, true);
- } else {
- QResizeEvent qre(newSize, oldSize);
- if (qwidget->testAttribute(Qt::WA_PendingResizeEvent)) {
- qwidget->setAttribute(Qt::WA_PendingResizeEvent, false);
- QApplication::sendEvent(qwidget, &qre);
- } else {
- qt_sendSpontaneousEvent(qwidget, &qre);
- }
- }
-}
-
-- (void)dumpMaximizedStateforWidget:(QWidget*)qwidget window:(NSWindow *)window
-{
- if (!window)
- return; // Nothing to do.
- QWidgetData *widgetData = qt_qwidget_data(qwidget);
- if ((widgetData->window_state & Qt::WindowMaximized) && ![window isZoomed]) {
- widgetData->window_state &= ~Qt::WindowMaximized;
- QWindowStateChangeEvent e(Qt::WindowState(widgetData->window_state | Qt::WindowMaximized));
- qt_sendSpontaneousEvent(qwidget, &e);
- }
-}
-
-- (NSSize)closestAcceptableSizeForWidget:(QWidget *)qwidget window:(NSWindow *)window
- withNewSize:(NSSize)proposedSize
-{
- [self dumpMaximizedStateforWidget:qwidget window:window];
- QSize newSize = QLayout::closestAcceptableSize(qwidget,
- QSize(proposedSize.width, proposedSize.height));
- return [NSWindow frameRectForContentRect:
- NSMakeRect(0., 0., newSize.width(), newSize.height())
- styleMask:[window styleMask]].size;
-}
-
-- (NSSize)windowWillResize:(NSWindow *)windowToResize toSize:(NSSize)proposedFrameSize
-{
- QWidget *qwidget = m_windowHash->value(windowToResize);
- return [self closestAcceptableSizeForWidget:qwidget window:windowToResize
- withNewSize:[NSWindow contentRectForFrameRect:
- NSMakeRect(0, 0,
- proposedFrameSize.width,
- proposedFrameSize.height)
- styleMask:[windowToResize styleMask]].size];
-}
-
-- (NSSize)drawerWillResizeContents:(NSDrawer *)sender toSize:(NSSize)contentSize
-{
- QWidget *qwidget = m_drawerHash->value(sender);
- return [self closestAcceptableSizeForWidget:qwidget window:nil withNewSize:contentSize];
-}
-
--(void)windowDidMiniaturize:(NSNotification*)notification
-{
- QWidget *qwidget = m_windowHash->value([notification object]);
- if (!qwidget->isMinimized()) {
- QWidgetData *widgetData = qt_qwidget_data(qwidget);
- widgetData->window_state = widgetData->window_state | Qt::WindowMinimized;
- QWindowStateChangeEvent e(Qt::WindowStates(widgetData->window_state & ~Qt::WindowMinimized));
- qt_sendSpontaneousEvent(qwidget, &e);
- }
- // Send hide to match Qt on X11 and Windows
- QEvent e(QEvent::Hide);
- qt_sendSpontaneousEvent(qwidget, &e);
-}
-
-- (void)windowDidResize:(NSNotification *)notification
-{
- NSWindow *window = [notification object];
- QWidget *qwidget = m_windowHash->value(window);
- QWidgetData *widgetData = qt_qwidget_data(qwidget);
- if (!(qwidget->windowState() & (Qt::WindowMaximized | Qt::WindowFullScreen)) && [window isZoomed]) {
- widgetData->window_state = widgetData->window_state | Qt::WindowMaximized;
- QWindowStateChangeEvent e(Qt::WindowStates(widgetData->window_state
- & ~Qt::WindowMaximized));
- qt_sendSpontaneousEvent(qwidget, &e);
- } else {
- widgetData->window_state = widgetData->window_state & ~Qt::WindowMaximized;
- QWindowStateChangeEvent e(Qt::WindowStates(widgetData->window_state
- | Qt::WindowMaximized));
- qt_sendSpontaneousEvent(qwidget, &e);
- }
- NSRect rect = [[window contentView] frame];
- const QSize newSize(rect.size.width, rect.size.height);
- const QSize &oldSize = widgetData->crect.size();
- if (newSize != oldSize) {
- QWidgetPrivate::qt_mac_update_sizer(qwidget);
- [self syncSizeForWidget:qwidget toSize:newSize fromSize:oldSize];
- }
-
- // We force the repaint to be synchronized with the resize of the window.
- // Otherwise, the resize looks sluggish because we paint one event loop later.
- if ([[window contentView] inLiveResize]) {
- qwidget->repaint();
-
- // We need to repaint the toolbar as well.
- QMainWindow* mWindow = qobject_cast<QMainWindow*>(qwidget->window());
- if (mWindow) {
- QMainWindowLayout *mLayout = qobject_cast<QMainWindowLayout*>(mWindow->layout());
- QList<QToolBar *> toolbarList = mLayout->qtoolbarsInUnifiedToolbarList;
-
- for (int i = 0; i < toolbarList.size(); ++i) {
- QToolBar* toolbar = toolbarList.at(i);
- toolbar->repaint();
- }
- }
- }
-}
-
-- (void)windowDidMove:(NSNotification *)notification
-{
- // The code underneath needs to translate the window location
- // from bottom left (which is the origin used by Cocoa) to
- // upper left (which is the origin used by Qt):
- NSWindow *window = [notification object];
- NSRect newRect = [window frame];
- QWidget *qwidget = m_windowHash->value(window);
- QPoint qtPoint = flipPoint(NSMakePoint(newRect.origin.x,
- newRect.origin.y + newRect.size.height)).toPoint();
- const QRect &oldRect = qwidget->frameGeometry();
-
- if (qtPoint.x() != oldRect.x() || qtPoint.y() != oldRect.y()) {
- QWidgetData *widgetData = qt_qwidget_data(qwidget);
- QRect oldCRect = widgetData->crect;
- QWidgetPrivate *widgetPrivate = qt_widget_private(qwidget);
- const QRect &fStrut = widgetPrivate->frameStrut();
- widgetData->crect.moveTo(qtPoint.x() + fStrut.left(), qtPoint.y() + fStrut.top());
- if (!qwidget->isVisible()) {
- qwidget->setAttribute(Qt::WA_PendingMoveEvent, true);
- } else {
- QMoveEvent qme(qtPoint, oldRect.topLeft());
- qt_sendSpontaneousEvent(qwidget, &qme);
- }
- }
-}
-
--(BOOL)windowShouldClose:(id)windowThatWantsToClose
-{
- QWidget *qwidget = m_windowHash->value(windowThatWantsToClose);
- QScopedLoopLevelCounter counter(qt_widget_private(qwidget)->threadData);
- return qt_widget_private(qwidget)->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent);
-}
-
--(void)windowDidDeminiaturize:(NSNotification *)notification
-{
- QWidget *qwidget = m_windowHash->value([notification object]);
- QWidgetData *widgetData = qt_qwidget_data(qwidget);
- Qt::WindowStates currState = Qt::WindowStates(widgetData->window_state);
- Qt::WindowStates newState = currState;
- if (currState & Qt::WindowMinimized)
- newState &= ~Qt::WindowMinimized;
- if (!(currState & Qt::WindowActive))
- newState |= Qt::WindowActive;
- if (newState != currState) {
- widgetData->window_state = newState;
- QWindowStateChangeEvent e(currState);
- qt_sendSpontaneousEvent(qwidget, &e);
- }
- QShowEvent qse;
- qt_sendSpontaneousEvent(qwidget, &qse);
-}
-
--(void)windowDidBecomeMain:(NSNotification*)notification
-{
- QWidget *qwidget = m_windowHash->value([notification object]);
- Q_ASSERT(qwidget);
- onApplicationWindowChangedActivation(qwidget, true);
-}
-
--(void)windowDidResignMain:(NSNotification*)notification
-{
- QWidget *qwidget = m_windowHash->value([notification object]);
- Q_ASSERT(qwidget);
- onApplicationWindowChangedActivation(qwidget, false);
-}
-
-// These are the same as main, but they are probably better to keep separate since there is a
-// tiny difference between main and key windows.
--(void)windowDidBecomeKey:(NSNotification*)notification
-{
- QWidget *qwidget = m_windowHash->value([notification object]);
- Q_ASSERT(qwidget);
- onApplicationWindowChangedActivation(qwidget, true);
-}
-
--(void)windowDidResignKey:(NSNotification*)notification
-{
- QWidget *qwidget = m_windowHash->value([notification object]);
- Q_ASSERT(qwidget);
- onApplicationWindowChangedActivation(qwidget, false);
-}
-
--(QWidget *)qt_qwidgetForWindow:(NSWindow *)window
-{
- return m_windowHash->value(window);
-}
-
-- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame
-{
- Q_UNUSED(newFrame);
- // saving the current window geometry before the window is maximized
- QWidget *qwidget = m_windowHash->value(window);
- QWidgetPrivate *widgetPrivate = qt_widget_private(qwidget);
- if (qwidget->isWindow()) {
- if(qwidget->windowState() & Qt::WindowMaximized) {
- // Restoring
- widgetPrivate->topData()->wasMaximized = false;
- } else {
- // Maximizing
- widgetPrivate->topData()->normalGeometry = qwidget->geometry();
- // If the window was maximized we need to update the coordinates since now it will start at 0,0.
- // We do this in a special field that is only used when not restoring but manually resizing the window.
- // Since the coordinates are fixed we just set a boolean flag.
- widgetPrivate->topData()->wasMaximized = true;
- }
- }
- return YES;
-}
-
-- (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)defaultFrame
-{
- NSRect frameToReturn = defaultFrame;
- QWidget *qwidget = m_windowHash->value(window);
- QSizeF size = qwidget->maximumSize();
- NSRect windowFrameRect = [window frame];
- NSRect viewFrameRect = [[window contentView] frame];
- // consider additional size required for titlebar & frame
- frameToReturn.size.width = qMin<CGFloat>(frameToReturn.size.width,
- size.width()+(windowFrameRect.size.width - viewFrameRect.size.width));
- frameToReturn.size.height = qMin<CGFloat>(frameToReturn.size.height,
- size.height()+(windowFrameRect.size.height - viewFrameRect.size.height));
- return frameToReturn;
-}
-
-- (void)becomeDelegteForWindow:(NSWindow *)window widget:(QWidget *)widget
-{
- m_windowHash->insert(window, widget);
- [window setDelegate:self];
-}
-
-- (void)resignDelegateForWindow:(NSWindow *)window
-{
- [window setDelegate:nil];
- m_windowHash->remove(window);
-}
-
-- (void)becomeDelegateForDrawer:(NSDrawer *)drawer widget:(QWidget *)widget
-{
- m_drawerHash->insert(drawer, widget);
- [drawer setDelegate:self];
- NSWindow *window = [[drawer contentView] window];
- [self becomeDelegteForWindow:window widget:widget];
-}
-
-- (void)resignDelegateForDrawer:(NSDrawer *)drawer
-{
- QWidget *widget = m_drawerHash->value(drawer);
- [drawer setDelegate:nil];
- if (widget)
- [self resignDelegateForWindow:[[drawer contentView] window]];
- m_drawerHash->remove(drawer);
-}
-
-- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu
-{
- Q_UNUSED(menu);
- QWidget *qwidget = m_windowHash->value(window);
- if (qwidget && !qwidget->windowFilePath().isEmpty()) {
- return YES;
- }
- return NO;
-}
-
-- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event
- from:(NSPoint)dragImageLocation
- withPasteboard:(NSPasteboard *)pasteboard
-{
- Q_UNUSED(event);
- Q_UNUSED(dragImageLocation);
- Q_UNUSED(pasteboard);
- QWidget *qwidget = m_windowHash->value(window);
- if (qwidget && !qwidget->windowFilePath().isEmpty()) {
- return YES;
- }
- return NO;
-}
-
-- (void)syncContentViewFrame: (NSNotification *)notification
-{
- NSView *cView = [notification object];
- if (cView) {
- NSWindow *window = [cView window];
- QWidget *qwidget = m_windowHash->value(window);
- if (qwidget) {
- QWidgetData *widgetData = qt_qwidget_data(qwidget);
- NSRect rect = [cView frame];
- const QSize newSize(rect.size.width, rect.size.height);
- const QSize &oldSize = widgetData->crect.size();
- if (newSize != oldSize) {
- [self syncSizeForWidget:qwidget toSize:newSize fromSize:oldSize];
- }
- }
-
- }
-}
-
-@end
-#endif// QT_MAC_USE_COCOA
diff --git a/src/gui/kernel/qcocoawindowdelegate_mac_p.h b/src/gui/kernel/qcocoawindowdelegate_mac_p.h
deleted file mode 100644
index 638ce2df9a..0000000000
--- a/src/gui/kernel/qcocoawindowdelegate_mac_p.h
+++ /dev/null
@@ -1,110 +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$
-**
-****************************************************************************/
-
-//
-// 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 "qmacdefines_mac.h"
-
-#ifdef QT_MAC_USE_COCOA
-#import <Cocoa/Cocoa.h>
-
-QT_BEGIN_NAMESPACE
-template <class Key, class T> class QHash;
-QT_END_NAMESPACE
-using QT_PREPEND_NAMESPACE(QHash);
-QT_FORWARD_DECLARE_CLASS(QWidget)
-QT_FORWARD_DECLARE_CLASS(QSize)
-QT_FORWARD_DECLARE_CLASS(QWidgetData)
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5
-@protocol NSWindowDelegate <NSObject>
-- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize;
-- (void)windowDidMiniaturize:(NSNotification*)notification;
-- (void)windowDidResize:(NSNotification *)notification;
-- (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)defaultFrame;
-- (void)windowDidMove:(NSNotification *)notification;
-- (BOOL)windowShouldClose:(id)window;
-- (void)windowDidDeminiaturize:(NSNotification *)notification;
-- (void)windowDidBecomeMain:(NSNotification*)notification;
-- (void)windowDidResignMain:(NSNotification*)notification;
-- (void)windowDidBecomeKey:(NSNotification*)notification;
-- (void)windowDidResignKey:(NSNotification*)notification;
-- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu;
-- (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event from:(NSPoint)dragImageLocation withPasteboard:(NSPasteboard *)pasteboard;
-- (BOOL)windowShouldZoom:(NSWindow *)window toFrame:(NSRect)newFrame;
-@end
-
-@protocol NSDrawerDelegate <NSObject>
-- (NSSize)drawerWillResizeContents:(NSDrawer *)sender toSize:(NSSize)contentSize;
-@end
-
-#endif
-
-
-
-@interface QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) : NSObject<NSWindowDelegate, NSDrawerDelegate> {
- QHash<NSWindow *, QWidget *> *m_windowHash;
- QHash<NSDrawer *, QWidget *> *m_drawerHash;
-}
-+ (QT_MANGLE_NAMESPACE(QCocoaWindowDelegate)*)sharedDelegate;
-- (void)becomeDelegteForWindow:(NSWindow *)window widget:(QWidget *)widget;
-- (void)resignDelegateForWindow:(NSWindow *)window;
-- (void)becomeDelegateForDrawer:(NSDrawer *)drawer widget:(QWidget *)widget;
-- (void)resignDelegateForDrawer:(NSDrawer *)drawer;
-- (void)dumpMaximizedStateforWidget:(QWidget*)qwidget window:(NSWindow *)window;
-- (void)syncSizeForWidget:(QWidget *)qwidget
- toSize:(const QSize &)newSize
- fromSize:(const QSize &)oldSize;
-- (NSSize)closestAcceptableSizeForWidget:(QWidget *)qwidget
- window:(NSWindow *)window withNewSize:(NSSize)proposedSize;
-- (QWidget *)qt_qwidgetForWindow:(NSWindow *)window;
-- (void)syncContentViewFrame: (NSNotification *)notification;
-@end
-#endif
diff --git a/src/gui/kernel/qdesktopwidget_mac.mm b/src/gui/kernel/qdesktopwidget_mac.mm
deleted file mode 100644
index 0b529c9843..0000000000
--- a/src/gui/kernel/qdesktopwidget_mac.mm
+++ /dev/null
@@ -1,257 +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$
-**
-****************************************************************************/
-
-/****************************************************************************
-**
-** Copyright (c) 2007-2008, Apple, Inc.
-**
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-**
-** * Redistributions of source code must retain the above copyright notice,
-** this list of conditions and the following disclaimer.
-**
-** * Redistributions in binary form must reproduce the above copyright notice,
-** this list of conditions and the following disclaimer in the documentation
-** and/or other materials provided with the distribution.
-**
-** * Neither the name of Apple, Inc. nor the names of its contributors
-** may be used to endorse or promote products derived from this software
-** without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-****************************************************************************/
-
-#import <Cocoa/Cocoa.h>
-
-#include "qapplication.h"
-#include "qdesktopwidget.h"
-#include <private/qt_mac_p.h>
-#include "qwidget_p.h"
-#include <private/qt_cocoa_helpers_mac_p.h>
-#include <private/qdesktopwidget_mac_p.h>
-
-QT_BEGIN_NAMESPACE
-
-QT_USE_NAMESPACE
-
-/*****************************************************************************
- Externals
- *****************************************************************************/
-
-/*****************************************************************************
- QDesktopWidget member functions
- *****************************************************************************/
-
-Q_GLOBAL_STATIC(QDesktopWidgetImplementation, qdesktopWidgetImplementation)
-
-QDesktopWidgetImplementation::QDesktopWidgetImplementation()
- : appScreen(0)
-{
- onResize();
-}
-
-QDesktopWidgetImplementation::~QDesktopWidgetImplementation()
-{
-}
-
-QDesktopWidgetImplementation *QDesktopWidgetImplementation::instance()
-{
- return qdesktopWidgetImplementation();
-}
-
-QRect QDesktopWidgetImplementation::availableRect(int screenIndex) const
-{
- if (screenIndex < 0 || screenIndex >= screenCount)
- screenIndex = appScreen;
-
- return availableRects[screenIndex].toRect();
-}
-
-QRect QDesktopWidgetImplementation::screenRect(int screenIndex) const
-{
- if (screenIndex < 0 || screenIndex >= screenCount)
- screenIndex = appScreen;
-
- return screenRects[screenIndex].toRect();
-}
-
-void QDesktopWidgetImplementation::onResize()
-{
- QMacCocoaAutoReleasePool pool;
- NSArray *displays = [NSScreen screens];
- screenCount = [displays count];
-
- screenRects.clear();
- availableRects.clear();
- NSRect primaryRect = [[displays objectAtIndex:0] frame];
- for (int i = 0; i<screenCount; i++) {
- NSRect r = [[displays objectAtIndex:i] frame];
- int flippedY = - r.origin.y + // account for position offset and
- primaryRect.size.height - r.size.height; // height difference.
- screenRects.append(QRectF(r.origin.x, flippedY,
- r.size.width, r.size.height));
-
- r = [[displays objectAtIndex:i] visibleFrame];
- flippedY = - r.origin.y + // account for position offset and
- primaryRect.size.height - r.size.height; // height difference.
- availableRects.append(QRectF(r.origin.x, flippedY,
- r.size.width, r.size.height));
- }
-}
-
-
-
-QDesktopWidget::QDesktopWidget()
- : QWidget(0, Qt::Desktop)
-{
- setObjectName(QLatin1String("desktop"));
- setAttribute(Qt::WA_WState_Visible);
-}
-
-QDesktopWidget::~QDesktopWidget()
-{
-}
-
-bool QDesktopWidget::isVirtualDesktop() const
-{
- return true;
-}
-
-int QDesktopWidget::primaryScreen() const
-{
- return qdesktopWidgetImplementation()->appScreen;
-}
-
-int QDesktopWidget::numScreens() const
-{
- return qdesktopWidgetImplementation()->screenCount;
-}
-
-QWidget *QDesktopWidget::screen(int)
-{
- return this;
-}
-
-const QRect QDesktopWidget::availableGeometry(int screen) const
-{
- return qdesktopWidgetImplementation()->availableRect(screen);
-}
-
-const QRect QDesktopWidget::screenGeometry(int screen) const
-{
- return qdesktopWidgetImplementation()->screenRect(screen);
-}
-
-int QDesktopWidget::screenNumber(const QWidget *widget) const
-{
- QDesktopWidgetImplementation *d = qdesktopWidgetImplementation();
- if (!widget)
- return d->appScreen;
- QRect frame = widget->frameGeometry();
- if (!widget->isWindow())
- frame.moveTopLeft(widget->mapToGlobal(QPoint(0,0)));
- int maxSize = -1, maxScreen = -1;
- for (int i = 0; i < d->screenCount; ++i) {
- QRect rr = d->screenRect(i);
- QRect sect = rr.intersected(frame);
- int size = sect.width() * sect.height();
- if (size > maxSize && sect.width() > 0 && sect.height() > 0) {
- maxSize = size;
- maxScreen = i;
- }
- }
- return maxScreen;
-}
-
-int QDesktopWidget::screenNumber(const QPoint &point) const
-{
- QDesktopWidgetImplementation *d = qdesktopWidgetImplementation();
- int closestScreen = -1;
- int shortestDistance = INT_MAX;
- for (int i = 0; i < d->screenCount; ++i) {
- QRect rr = d->screenRect(i);
- int thisDistance = QWidgetPrivate::pointToRect(point, rr);
- if (thisDistance < shortestDistance) {
- shortestDistance = thisDistance;
- closestScreen = i;
- }
- }
- return closestScreen;
-}
-
-void QDesktopWidget::resizeEvent(QResizeEvent *)
-{
- QDesktopWidgetImplementation *d = qdesktopWidgetImplementation();
-
- const int oldScreenCount = d->screenCount;
- const QVector<QRectF> oldRects(d->screenRects);
- const QVector<QRectF> oldWorks(d->availableRects);
-
- d->onResize();
-
- for (int i = 0; i < qMin(oldScreenCount, d->screenCount); ++i) {
- if (oldRects.at(i) != d->screenRects.at(i))
- emit resized(i);
- }
- for (int i = 0; i < qMin(oldScreenCount, d->screenCount); ++i) {
- if (oldWorks.at(i) != d->availableRects.at(i))
- emit workAreaResized(i);
- }
-
- if (oldScreenCount != d->screenCount)
- emit screenCountChanged(d->screenCount);
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qdesktopwidget_mac_p.h b/src/gui/kernel/qdesktopwidget_mac_p.h
deleted file mode 100644
index ac638ea7d8..0000000000
--- a/src/gui/kernel/qdesktopwidget_mac_p.h
+++ /dev/null
@@ -1,75 +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$
-**
-****************************************************************************/
-
-//
-// 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 <qrect.h>
-
-QT_BEGIN_NAMESPACE
-
-class QDesktopWidgetImplementation
-{
-public:
- QDesktopWidgetImplementation();
- ~QDesktopWidgetImplementation();
- static QDesktopWidgetImplementation *instance();
-
- int appScreen;
- int screenCount;
-
- QVector<QRectF> availableRects;
- QVector<QRectF> screenRects;
-
- QRect availableRect(int screenIndex) const;
- QRect screenRect(int screenIndex) const;
- void onResize();
-};
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qdesktopwidget_s60.cpp b/src/gui/kernel/qdesktopwidget_s60.cpp
deleted file mode 100644
index 62a4d40eba..0000000000
--- a/src/gui/kernel/qdesktopwidget_s60.cpp
+++ /dev/null
@@ -1,316 +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 "qdesktopwidget.h"
-#include "qapplication_p.h"
-#include "qwidget_p.h"
-#include "qt_s60_p.h"
-#include <w32std.h>
-#if defined(Q_SYMBIAN_SUPPORTS_MULTIPLE_SCREENS)
-#include <graphics/displaycontrol.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-extern int qt_symbian_create_desktop_on_screen;
-
-class QSingleDesktopWidget : public QWidget
-{
-public:
- QSingleDesktopWidget();
- ~QSingleDesktopWidget();
-};
-
-QSingleDesktopWidget::QSingleDesktopWidget()
- : QWidget(0, Qt::Desktop)
-{
-}
-
-QSingleDesktopWidget::~QSingleDesktopWidget()
-{
- const QObjectList &childList = children();
- for (int i = childList.size(); i > 0 ;) {
- --i;
- childList.at(i)->setParent(0);
- }
-}
-
-class QDesktopWidgetPrivate : public QWidgetPrivate
-{
-public:
- QDesktopWidgetPrivate();
- ~QDesktopWidgetPrivate();
- static void init(QDesktopWidget *that);
- static void cleanup();
- static void init_sys();
-
- static int screenCount;
- static int primaryScreen;
-
- static QVector<QRect> *rects;
- static QVector<QRect> *workrects;
- static QVector<QWidget *> *screens;
-
- static int refcount;
-
-#if defined(Q_SYMBIAN_SUPPORTS_MULTIPLE_SCREENS)
- static MDisplayControl *displayControl;
-#endif
-};
-
-int QDesktopWidgetPrivate::screenCount = 1;
-int QDesktopWidgetPrivate::primaryScreen = 0;
-QVector<QRect> *QDesktopWidgetPrivate::rects = 0;
-QVector<QRect> *QDesktopWidgetPrivate::workrects = 0;
-QVector<QWidget *> *QDesktopWidgetPrivate::screens = 0;
-int QDesktopWidgetPrivate::refcount = 0;
-#if defined(Q_SYMBIAN_SUPPORTS_MULTIPLE_SCREENS)
-MDisplayControl *QDesktopWidgetPrivate::displayControl = 0;
-#endif
-
-QDesktopWidgetPrivate::QDesktopWidgetPrivate()
-{
- ++refcount;
-}
-
-QDesktopWidgetPrivate::~QDesktopWidgetPrivate()
-{
- if (!--refcount)
- cleanup();
-}
-
-void QDesktopWidgetPrivate::init(QDesktopWidget *that)
-{
- // Note that on S^3 devices the screen count retrieved via RWsSession
- // will always be 2 but the width and height for screen number 1 will
- // be 0 as long as TV-out is not connected.
- //
- // On the other hand a valid size for screen 1 will be reported even
- // after the cable is disconnected. In order to overcome this, we use
- // MDisplayControl::NumberOfResolutions() to check if the display is
- // valid or not.
-
- screenCount = S60->screenCount();
-#if defined(Q_SYMBIAN_SUPPORTS_MULTIPLE_SCREENS)
- if (displayControl) {
- if (displayControl->NumberOfResolutions() < 1)
- screenCount = 1;
- }
-#endif
- if (screenCount < 1) {
- qWarning("No screen available");
- screenCount = 1;
- }
-
- rects = new QVector<QRect>();
- workrects = new QVector<QRect>();
- screens = new QVector<QWidget *>();
-
- rects->resize(screenCount);
- workrects->resize(screenCount);
- screens->resize(screenCount);
-
- for (int i = 0; i < screenCount; ++i) {
- // All screens will have a position of (0, 0) as there is no true virtual desktop
- // or pointer event support for multiple screens on Symbian.
- QRect r(0, 0,
- S60->screenWidthInPixelsForScreen[i], S60->screenHeightInPixelsForScreen[i]);
- // Stop here if empty and ignore this screen.
- if (r.isEmpty()) {
- screenCount = i;
- break;
- }
- (*rects)[i] = r;
- QRect wr;
- if (i == 0)
- wr = qt_TRect2QRect(static_cast<CEikAppUi*>(S60->appUi())->ClientRect());
- else
- wr = rects->at(i);
- (*workrects)[i].setRect(wr.x(), wr.y(), wr.width(), wr.height());
- (*screens)[i] = 0;
- }
- (*screens)[0] = that;
-}
-
-void QDesktopWidgetPrivate::cleanup()
-{
- delete rects;
- rects = 0;
- delete workrects;
- workrects = 0;
- if (screens) {
- // First item is the QDesktopWidget so skip it.
- for (int i = 1; i < screens->count(); ++i)
- delete screens->at(i);
- }
- delete screens;
- screens = 0;
-}
-
-void QDesktopWidgetPrivate::init_sys()
-{
-#if defined(Q_SYMBIAN_SUPPORTS_MULTIPLE_SCREENS)
- if (S60->screenCount() > 1) {
- CWsScreenDevice *dev = S60->screenDevice(1);
- if (dev) {
- displayControl = static_cast<MDisplayControl *>(
- dev->GetInterface(MDisplayControl::ETypeId));
- if (displayControl) {
- displayControl->EnableDisplayChangeEvents(ETrue);
- }
- }
- }
-#endif
-}
-
-
-QDesktopWidget::QDesktopWidget()
- : QWidget(*new QDesktopWidgetPrivate, 0, Qt::Desktop)
-{
- setObjectName(QLatin1String("desktop"));
- QDesktopWidgetPrivate::init_sys();
- QDesktopWidgetPrivate::init(this);
-}
-
-QDesktopWidget::~QDesktopWidget()
-{
-}
-
-bool QDesktopWidget::isVirtualDesktop() const
-{
- return false;
-}
-
-int QDesktopWidget::primaryScreen() const
-{
- return QDesktopWidgetPrivate::primaryScreen;
-}
-
-int QDesktopWidget::numScreens() const
-{
- Q_D(const QDesktopWidget);
- return QDesktopWidgetPrivate::screenCount;
-}
-
-static inline QWidget *newSingleDesktopWidget(int screen)
-{
- qt_symbian_create_desktop_on_screen = screen;
- QWidget *w = new QSingleDesktopWidget;
- qt_symbian_create_desktop_on_screen = -1;
- return w;
-}
-
-QWidget *QDesktopWidget::screen(int screen)
-{
- Q_D(QDesktopWidget);
- if (screen < 0 || screen >= d->screenCount)
- screen = d->primaryScreen;
- if (!d->screens->at(screen)
- || d->screens->at(screen)->windowType() != Qt::Desktop)
- (*d->screens)[screen] = newSingleDesktopWidget(screen);
- return (*d->screens)[screen];
-}
-
-const QRect QDesktopWidget::availableGeometry(int screen) const
-{
- Q_D(const QDesktopWidget);
- if (screen < 0 || screen >= d->screenCount)
- screen = d->primaryScreen;
-
- return d->workrects->at(screen);
-}
-
-const QRect QDesktopWidget::screenGeometry(int screen) const
-{
- Q_D(const QDesktopWidget);
- if (screen < 0 || screen >= d->screenCount)
- screen = d->primaryScreen;
-
- return d->rects->at(screen);
-}
-
-int QDesktopWidget::screenNumber(const QWidget *widget) const
-{
- Q_D(const QDesktopWidget);
- return widget
- ? S60->screenNumberForWidget(widget)
- : d->primaryScreen;
-}
-
-int QDesktopWidget::screenNumber(const QPoint &point) const
-{
- Q_UNUSED(point);
- Q_D(const QDesktopWidget);
- return d->primaryScreen;
-}
-
-void QDesktopWidget::resizeEvent(QResizeEvent *)
-{
- Q_D(QDesktopWidget);
- QVector<QRect> oldrects;
- oldrects = *d->rects;
- QVector<QRect> oldworkrects;
- oldworkrects = *d->workrects;
- int oldscreencount = d->screenCount;
-
- QDesktopWidgetPrivate::cleanup();
- QDesktopWidgetPrivate::init(this);
-
- for (int i = 0; i < qMin(oldscreencount, d->screenCount); ++i) {
- QRect oldrect = oldrects[i];
- QRect newrect = d->rects->at(i);
- if (oldrect != newrect)
- emit resized(i);
- }
-
- for (int j = 0; j < qMin(oldscreencount, d->screenCount); ++j) {
- QRect oldrect = oldworkrects[j];
- QRect newrect = d->workrects->at(j);
- if (oldrect != newrect)
- emit workAreaResized(j);
- }
-
- if (oldscreencount != d->screenCount) {
- emit screenCountChanged(d->screenCount);
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qdesktopwidget_win.cpp b/src/gui/kernel/qdesktopwidget_win.cpp
deleted file mode 100644
index d57b355ef4..0000000000
--- a/src/gui/kernel/qdesktopwidget_win.cpp
+++ /dev/null
@@ -1,387 +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 "qdesktopwidget.h"
-#include "qt_windows.h"
-#include "qapplication_p.h"
-#include <private/qsystemlibrary_p.h>
-#include <qvector.h>
-#include <limits.h>
-#ifdef Q_WS_WINCE
-#include <sipapi.h>
-#endif
-#include "qwidget_p.h"
-#include "qdebug.h"
-
-QT_BEGIN_NAMESPACE
-
-class QDesktopWidgetPrivate : public QWidgetPrivate
-{
-public:
- QDesktopWidgetPrivate();
- ~QDesktopWidgetPrivate();
-
- static void init(QDesktopWidget *that);
- static void cleanup();
- static int screenCount;
- static int primaryScreen;
-
- static QVector<QRect> *rects;
- static QVector<QRect> *workrects;
-
- struct MONITORINFO
- {
- DWORD cbSize;
- RECT rcMonitor;
- RECT rcWork;
- DWORD dwFlags;
- };
-
- typedef BOOL (WINAPI *InfoFunc)(HMONITOR, MONITORINFO*);
- typedef BOOL (QT_WIN_CALLBACK *EnumProc)(HMONITOR, HDC, LPRECT, LPARAM);
- typedef BOOL (WINAPI *EnumFunc)(HDC, LPCRECT, EnumProc, LPARAM);
-
- static EnumFunc enumDisplayMonitors;
- static InfoFunc getMonitorInfo;
- static int refcount;
-};
-
-int QDesktopWidgetPrivate::screenCount = 1;
-int QDesktopWidgetPrivate::primaryScreen = 0;
-QDesktopWidgetPrivate::EnumFunc QDesktopWidgetPrivate::enumDisplayMonitors = 0;
-QDesktopWidgetPrivate::InfoFunc QDesktopWidgetPrivate::getMonitorInfo = 0;
-QVector<QRect> *QDesktopWidgetPrivate::rects = 0;
-QVector<QRect> *QDesktopWidgetPrivate::workrects = 0;
-static int screen_number = 0;
-int QDesktopWidgetPrivate::refcount = 0;
-#ifdef Q_WS_WINCE_WM
-// Use SIP information, if available
-// SipGetInfo is not supported by SSDK (no definition!).
-static inline void qt_get_sip_info(QRect &rect)
-{
- SIPINFO sip;
- memset(&sip, 0, sizeof(SIPINFO));
- sip.cbSize = sizeof(SIPINFO);
- if (SipGetInfo(&sip))
- rect = QRect(QPoint(sip.rcVisibleDesktop.left, sip.rcVisibleDesktop.top),
- QPoint(sip.rcVisibleDesktop.right - 1, sip.rcVisibleDesktop.bottom - 1));
-}
-#endif
-
-
-BOOL QT_WIN_CALLBACK enumCallback(HMONITOR hMonitor, HDC, LPRECT, LPARAM)
-{
- QDesktopWidgetPrivate::screenCount++;
- QDesktopWidgetPrivate::rects->resize(QDesktopWidgetPrivate::screenCount);
- QDesktopWidgetPrivate::workrects->resize(QDesktopWidgetPrivate::screenCount);
- // Get the MONITORINFO block
- QDesktopWidgetPrivate::MONITORINFO info;
- memset(&info, 0, sizeof(QDesktopWidgetPrivate::MONITORINFO));
- info.cbSize = sizeof(QDesktopWidgetPrivate::MONITORINFO);
- BOOL res = QDesktopWidgetPrivate::getMonitorInfo(hMonitor, &info);
- if (!res) {
- (*QDesktopWidgetPrivate::rects)[screen_number] = QRect();
- (*QDesktopWidgetPrivate::workrects)[screen_number] = QRect();
- return true;
- }
-
- // Fill list of rects
- RECT r = info.rcMonitor;
- QRect qr(QPoint(r.left, r.top), QPoint(r.right - 1, r.bottom - 1));
- (*QDesktopWidgetPrivate::rects)[screen_number] = qr;
-
- r = info.rcWork;
- qr = QRect(QPoint(r.left, r.top), QPoint(r.right - 1, r.bottom - 1));
- (*QDesktopWidgetPrivate::workrects)[screen_number] = qr;
-
- if (info.dwFlags & 0x00000001) //MONITORINFOF_PRIMARY
- QDesktopWidgetPrivate::primaryScreen = screen_number;
-
- ++screen_number;
- // Stop the enumeration if we have them all
- return true;
-}
-
-QDesktopWidgetPrivate::QDesktopWidgetPrivate()
-{
- ++refcount;
-}
-
-void QDesktopWidgetPrivate::init(QDesktopWidget *that)
-{
- if (rects)
- return;
-
- rects = new QVector<QRect>();
- workrects = new QVector<QRect>();
- screenCount = 0;
-
-#ifndef Q_OS_WINCE
- QSystemLibrary user32Lib(QLatin1String("user32"));
- enumDisplayMonitors = (EnumFunc)user32Lib.resolve("EnumDisplayMonitors");
- getMonitorInfo = (InfoFunc)user32Lib.resolve("GetMonitorInfoW");
-
- if (!enumDisplayMonitors || !getMonitorInfo) {
- screenCount = GetSystemMetrics(80); // SM_CMONITORS
- rects->resize(screenCount);
- for (int i = 0; i < screenCount; ++i)
- rects->replace(i, that->rect());
- return;
- }
- // Calls enumCallback
- enumDisplayMonitors(0, 0, enumCallback, 0);
- enumDisplayMonitors = 0;
- getMonitorInfo = 0;
-#else
- QSystemLibrary coreLib(QLatin1String("coredll"));
- // CE >= 4.0 case
- enumDisplayMonitors = (EnumFunc)coreLib.resolve("EnumDisplayMonitors");
- getMonitorInfo = (InfoFunc)coreLib.resolve("GetMonitorInfo");
-
- if ((!enumDisplayMonitors || !getMonitorInfo)) {
- screenCount = GetSystemMetrics(SM_CMONITORS);
- return;
- }
-
- if (!coreLib.isLoaded() || !enumDisplayMonitors || !getMonitorInfo) {
- rects->resize(screenCount);
- for (int i = 0; i < screenCount; ++i)
- (*rects)[i] = that->rect();
-
- RECT r;
- SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
- QRect qr = QRect(QPoint(r.left, r.top), QPoint(r.right - 1, r.bottom - 1));
-
-#if defined(Q_WS_WINCE_WM)
- qt_get_sip_info(qr);
-#endif
-
- workrects->resize(screenCount);
- for (int j = 0; j < screenCount; ++j)
- (*workrects)[j] = qr;
- return;
- }
-
- // Calls enumCallback
- enumDisplayMonitors(0, 0, enumCallback, 0);
- enumDisplayMonitors = 0;
- getMonitorInfo = 0;
-#endif // Q_WS_WINCE
-}
-
-QDesktopWidgetPrivate::~QDesktopWidgetPrivate()
-{
- if (!--refcount)
- cleanup();
-}
-
-void QDesktopWidgetPrivate::cleanup()
-{
- screen_number = 0;
- screenCount = 1;
- primaryScreen = 0;
- enumDisplayMonitors = 0;
- getMonitorInfo = 0;
- delete rects;
- rects = 0;
- delete workrects;
- workrects = 0;
-}
-
-/*
- \omit
- Function is commented out in header
- \fn void *QDesktopWidget::handle(int screen) const
-
- Returns the window system handle of the display device with the
- index \a screen, for low-level access. Using this function is not
- portable.
-
- The return type varies with platform; see qwindowdefs.h for details.
-
- \sa x11Display(), QPaintDevice::handle()
- \endomit
-*/
-
-QDesktopWidget::QDesktopWidget()
- : QWidget(*new QDesktopWidgetPrivate, 0, Qt::Desktop)
-{
- setObjectName(QLatin1String("desktop"));
- QDesktopWidgetPrivate::init(this);
-}
-
-QDesktopWidget::~QDesktopWidget()
-{
-}
-
-bool QDesktopWidget::isVirtualDesktop() const
-{
- return true;
-}
-
-int QDesktopWidget::primaryScreen() const
-{
- return d_func()->primaryScreen;
-}
-
-int QDesktopWidget::numScreens() const
-{
- return d_func()->screenCount;
-}
-
-QWidget *QDesktopWidget::screen(int /* screen */)
-{
- // It seems that a Qt::WType_Desktop cannot be moved?
- return this;
-}
-
-//
-// MSVC 7.10 warns that d (the result of the expanded Q_D macro) as a local variable that is not referenced.
-// Therefore, we ignore that warning with the following pragmas
-// I've also tried to eliminate the macro, but to no use...
-// We pop it further down
-#ifdef Q_CC_MSVC
-# pragma warning(push)
-# pragma warning(disable : 4189)
-#endif
-const QRect QDesktopWidget::availableGeometry(int screen) const
-{
- Q_D(const QDesktopWidget);
-#ifdef Q_WS_WINCE_WM
- for(int i=0; i < d->workrects->size(); ++i)
- qt_get_sip_info((*d->workrects)[i]);
-#endif
- if (screen < 0 || screen >= d->screenCount)
- screen = d->primaryScreen;
-
- return d->workrects->at(screen);
-}
-
-const QRect QDesktopWidget::screenGeometry(int screen) const
-{
- const QDesktopWidgetPrivate *d = d_func();
- if (screen < 0 || screen >= d->screenCount)
- screen = d->primaryScreen;
-
- return d->rects->at(screen);
-}
-
-int QDesktopWidget::screenNumber(const QWidget *widget) const
-{
- Q_D(const QDesktopWidget);
- if (!widget)
- return d->primaryScreen;
-
- QRect frame = widget->frameGeometry();
- if (!widget->isWindow())
- frame.moveTopLeft(widget->mapToGlobal(QPoint(0,0)));
-
- int maxSize = -1;
- int maxScreen = -1;
-
- for (int i = 0; i < d->screenCount; ++i) {
- QRect sect = d->rects->at(i).intersected(frame);
- int size = sect.width() * sect.height();
- if (size > maxSize && sect.width() > 0 && sect.height() > 0) {
- maxSize = size;
- maxScreen = i;
- }
- }
-
- return maxScreen;
-}
-
-int QDesktopWidget::screenNumber(const QPoint &point) const
-{
- Q_D(const QDesktopWidget);
-
- int closestScreen = -1;
- int shortestDistance = INT_MAX;
-
- for (int i = 0; i < d->screenCount; ++i) {
- int thisDistance = d->pointToRect(point, d->rects->at(i));
- if (thisDistance < shortestDistance) {
- shortestDistance = thisDistance;
- closestScreen = i;
- }
- }
-
- return closestScreen;
-}
-
-void QDesktopWidget::resizeEvent(QResizeEvent *)
-{
- Q_D(QDesktopWidget);
- const QVector<QRect> oldrects(*d->rects);
- const QVector<QRect> oldworkrects(*d->workrects);
- int oldscreencount = d->screenCount;
-
- QDesktopWidgetPrivate::cleanup();
- QDesktopWidgetPrivate::init(this);
-#ifdef Q_WS_WINCE_WM
- for(int i=0; i < d->workrects->size(); ++i)
- qt_get_sip_info((*d->workrects)[i]);
-#endif
-
- for (int i = 0; i < qMin(oldscreencount, d->screenCount); ++i) {
- const QRect oldrect = oldrects[i];
- const QRect newrect = d->rects->at(i);
- if (oldrect != newrect)
- emit resized(i);
- }
-
- for (int j = 0; j < qMin(oldscreencount, d->screenCount); ++j) {
- const QRect oldrect = oldworkrects[j];
- const QRect newrect = d->workrects->at(j);
- if (oldrect != newrect)
- emit workAreaResized(j);
- }
-
- if (oldscreencount != d->screenCount) {
- emit screenCountChanged(d->screenCount);
- }
-}
-
-#ifdef Q_CC_MSVC
-# pragma warning(pop)
-#endif
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qdesktopwidget_x11.cpp b/src/gui/kernel/qdesktopwidget_x11.cpp
deleted file mode 100644
index b0f12903a1..0000000000
--- a/src/gui/kernel/qdesktopwidget_x11.cpp
+++ /dev/null
@@ -1,406 +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 "qdesktopwidget.h"
-#include "qlibrary.h"
-#include "qt_x11_p.h"
-#include "qvariant.h"
-#include "qwidget_p.h"
-#include "qx11info_x11.h"
-#include <limits.h>
-
-QT_BEGIN_NAMESPACE
-
-// defined in qwidget_x11.cpp
-extern int qt_x11_create_desktop_on_screen;
-
-
-// function to update the workarea of the screen
-static bool qt_desktopwidget_workarea_dirty = true;
-void qt_desktopwidget_update_workarea()
-{
- qt_desktopwidget_workarea_dirty = true;
-}
-
-
-class QSingleDesktopWidget : public QWidget
-{
-public:
- QSingleDesktopWidget();
- ~QSingleDesktopWidget();
-};
-
-QSingleDesktopWidget::QSingleDesktopWidget()
- : QWidget(0, Qt::Desktop)
-{
-}
-
-QSingleDesktopWidget::~QSingleDesktopWidget()
-{
- const QObjectList &childList = children();
- for (int i = childList.size(); i > 0 ;) {
- --i;
- childList.at(i)->setParent(0);
- }
-}
-
-
-class QDesktopWidgetPrivate : public QWidgetPrivate
-{
-public:
- QDesktopWidgetPrivate();
- ~QDesktopWidgetPrivate();
-
- void init();
-
- bool use_xinerama;
- int defaultScreen;
- int screenCount;
-
- QWidget **screens;
- QRect *rects;
- QRect *workareas;
-};
-
-QDesktopWidgetPrivate::QDesktopWidgetPrivate()
- : use_xinerama(false), defaultScreen(0), screenCount(1),
- screens(0), rects(0), workareas(0)
-{
-}
-
-QDesktopWidgetPrivate::~QDesktopWidgetPrivate()
-{
- if (screens) {
- for (int i = 0; i < screenCount; ++i) {
- if (i == defaultScreen) continue;
- delete screens[i];
- screens[i] = 0;
- }
-
- free (screens);
- }
-
- if (rects) delete [] rects;
- if (workareas) delete [] workareas;
-}
-
-void QDesktopWidgetPrivate::init()
-{
- // get the screen count
- int newScreenCount = ScreenCount(X11->display);
-#ifndef QT_NO_XINERAMA
-
- XineramaScreenInfo *xinerama_screeninfo = 0;
-
- // we ignore the Xinerama extension when using the display is
- // using traditional multi-screen (with multiple root windows)
- if (newScreenCount == 1
- && X11->ptrXineramaQueryExtension
- && X11->ptrXineramaIsActive
- && X11->ptrXineramaQueryScreens) {
- int unused;
- use_xinerama = (X11->ptrXineramaQueryExtension(X11->display, &unused, &unused)
- && X11->ptrXineramaIsActive(X11->display));
- }
-
- if (use_xinerama) {
- xinerama_screeninfo =
- X11->ptrXineramaQueryScreens(X11->display, &newScreenCount);
- }
-
- if (xinerama_screeninfo) {
- defaultScreen = 0;
- } else
-#endif // QT_NO_XINERAMA
- {
- defaultScreen = DefaultScreen(X11->display);
- newScreenCount = ScreenCount(X11->display);
- use_xinerama = false;
- }
-
- delete [] rects;
- rects = new QRect[newScreenCount];
- delete [] workareas;
- workareas = new QRect[newScreenCount];
-
- // get the geometry of each screen
- int i, j, x, y, w, h;
- for (i = 0, j = 0; i < newScreenCount; i++, j++) {
-
-#ifndef QT_NO_XINERAMA
- if (use_xinerama) {
- x = xinerama_screeninfo[i].x_org;
- y = xinerama_screeninfo[i].y_org;
- w = xinerama_screeninfo[i].width;
- h = xinerama_screeninfo[i].height;
- } else
-#endif // QT_NO_XINERAMA
- {
- x = 0;
- y = 0;
- w = WidthOfScreen(ScreenOfDisplay(X11->display, i));
- h = HeightOfScreen(ScreenOfDisplay(X11->display, i));
- }
-
- rects[j].setRect(x, y, w, h);
-
- if (use_xinerama && j > 0 && rects[j-1].intersects(rects[j])) {
- // merge a "cloned" screen with the previous, hiding all crtcs
- // that are currently showing a sub-rect of the previous screen
- if ((rects[j].width()*rects[j].height()) >
- (rects[j-1].width()*rects[j-1].height()))
- rects[j-1] = rects[j];
- j--;
- }
-
- workareas[i] = QRect();
- }
-
- if (screens) {
- // leaks QWidget* pointers on purpose, can't delete them as pointer escapes
- screens = q_check_ptr((QWidget**) realloc(screens, j * sizeof(QWidget*)));
- if (j > screenCount)
- memset(&screens[screenCount], 0, (j-screenCount) * sizeof(QWidget*));
- }
-
- screenCount = j;
-
-#ifndef QT_NO_XINERAMA
- if (use_xinerama && screenCount == 1)
- use_xinerama = false;
-
- if (xinerama_screeninfo)
- XFree(xinerama_screeninfo);
-#endif // QT_NO_XINERAMA
-
-}
-
-// the QDesktopWidget itself will be created on the default screen
-// as qt_x11_create_desktop_on_screen defaults to -1
-QDesktopWidget::QDesktopWidget()
- : QWidget(*new QDesktopWidgetPrivate, 0, Qt::Desktop)
-{
- Q_D(QDesktopWidget);
- d->init();
-}
-
-QDesktopWidget::~QDesktopWidget()
-{
-}
-
-bool QDesktopWidget::isVirtualDesktop() const
-{
- Q_D(const QDesktopWidget);
- return d->use_xinerama;
-}
-
-int QDesktopWidget::primaryScreen() const
-{
- Q_D(const QDesktopWidget);
- return d->defaultScreen;
-}
-
-int QDesktopWidget::numScreens() const
-{
- Q_D(const QDesktopWidget);
- return d->screenCount;
-}
-
-QWidget *QDesktopWidget::screen(int screen)
-{
- Q_D(QDesktopWidget);
- if (d->use_xinerama)
- return this;
-
- if (screen < 0 || screen >= d->screenCount)
- screen = d->defaultScreen;
-
- if (! d->screens) {
- d->screens = (QWidget**) calloc( d->screenCount, sizeof(QWidget*));
- d->screens[d->defaultScreen] = this;
- }
-
- if (! d->screens[screen] || // not created yet
- ! (d->screens[screen]->windowType() == Qt::Desktop)) { // reparented away
- qt_x11_create_desktop_on_screen = screen;
- d->screens[screen] = new QSingleDesktopWidget;
- qt_x11_create_desktop_on_screen = -1;
- }
-
- return d->screens[screen];
-}
-
-const QRect QDesktopWidget::availableGeometry(int screen) const
-{
- Q_D(const QDesktopWidget);
- if (qt_desktopwidget_workarea_dirty) {
- // the workareas are dirty, invalidate them
- for (int i = 0; i < d->screenCount; ++i)
- d->workareas[i] = QRect();
- qt_desktopwidget_workarea_dirty = false;
- }
-
- if (screen < 0 || screen >= d->screenCount)
- screen = d->defaultScreen;
-
- if (d->workareas[screen].isValid())
- return d->workareas[screen];
-
- if (X11->isSupportedByWM(ATOM(_NET_WORKAREA))) {
- int x11Screen = isVirtualDesktop() ? DefaultScreen(X11->display) : screen;
-
- Atom ret;
- int format, e;
- unsigned char *data = 0;
- unsigned long nitems, after;
-
- e = XGetWindowProperty(X11->display,
- QX11Info::appRootWindow(x11Screen),
- ATOM(_NET_WORKAREA), 0, 4, False, XA_CARDINAL,
- &ret, &format, &nitems, &after, &data);
-
- QRect workArea;
- if (e == Success && ret == XA_CARDINAL &&
- format == 32 && nitems == 4) {
- long *workarea = (long *) data;
- workArea = QRect(workarea[0], workarea[1], workarea[2], workarea[3]);
- } else {
- workArea = screenGeometry(screen);
- }
-
- if (isVirtualDesktop()) {
- // intersect the workarea (which spawns all Xinerama screens) with the rect for the
- // requested screen
- workArea &= screenGeometry(screen);
- }
-
- d->workareas[screen] = workArea;
-
- if (data)
- XFree(data);
- } else {
- d->workareas[screen] = screenGeometry(screen);
- }
-
- return d->workareas[screen];
-}
-
-const QRect QDesktopWidget::screenGeometry(int screen) const
-{
- Q_D(const QDesktopWidget);
- if (screen < 0 || screen >= d->screenCount)
- screen = d->defaultScreen;
-
- return d->rects[screen];
-}
-
-int QDesktopWidget::screenNumber(const QWidget *widget) const
-{
- Q_D(const QDesktopWidget);
- if (!widget)
- return d->defaultScreen;
-
-#ifndef QT_NO_XINERAMA
- if (d->use_xinerama) {
- // this is how we do it for xinerama
- QRect frame = widget->frameGeometry();
- if (!widget->isWindow())
- frame.moveTopLeft(widget->mapToGlobal(QPoint(0, 0)));
-
- int maxSize = -1;
- int maxScreen = -1;
-
- for (int i = 0; i < d->screenCount; ++i) {
- QRect sect = d->rects[i].intersected(frame);
- int size = sect.width() * sect.height();
- if (size > maxSize && sect.width() > 0 && sect.height() > 0) {
- maxSize = size;
- maxScreen = i;
- }
- }
- return maxScreen;
- }
-#endif // QT_NO_XINERAMA
-
- return widget->x11Info().screen();
-}
-
-int QDesktopWidget::screenNumber(const QPoint &point) const
-{
- Q_D(const QDesktopWidget);
- int closestScreen = -1;
- int shortestDistance = INT_MAX;
- for (int i = 0; i < d->screenCount; ++i) {
- int thisDistance = d->pointToRect(point, d->rects[i]);
- if (thisDistance < shortestDistance) {
- shortestDistance = thisDistance;
- closestScreen = i;
- }
- }
- return closestScreen;
-}
-
-void QDesktopWidget::resizeEvent(QResizeEvent *event)
-{
- Q_D(QDesktopWidget);
- int oldScreenCount = d->screenCount;
- QVector<QRect> oldRects(oldScreenCount);
- for (int i = 0; i < oldScreenCount; ++i) {
- oldRects[i] = d->rects[i];
- }
-
- d->init();
-
- for (int i = 0; i < qMin(oldScreenCount, d->screenCount); ++i) {
- if (oldRects.at(i) != d->rects[i])
- emit resized(i);
- }
-
- if (oldScreenCount != d->screenCount) {
- emit screenCountChanged(d->screenCount);
- }
-
- qt_desktopwidget_workarea_dirty = true;
- QWidget::resizeEvent(event);
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qguifunctions_wince.cpp b/src/gui/kernel/qguifunctions_wince.cpp
deleted file mode 100644
index bb4ed11589..0000000000
--- a/src/gui/kernel/qguifunctions_wince.cpp
+++ /dev/null
@@ -1,408 +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 "qguifunctions_wince.h"
-#include <shellapi.h>
-#include <QtCore/qlibrary.h>
-
-QT_USE_NAMESPACE
-
-struct AygSHINITDLGINFO
-{
- DWORD dwMask;
- HWND hDlg;
- DWORD dwFlags;
-};
-
-struct AygSIPINFO
-{
- DWORD cbSize;
- DWORD fdwFlags;
- RECT rcVisibleDesktop;
- RECT rcSipRect;
- DWORD dwImDataSize;
- void *pvImData;
-};
-
-#ifndef SHIDIF_CANCELBUTTON
-#define SHIDIF_CANCELBUTTON 0x0080
-#endif
-
-#ifndef SHIDIM_FLAGS
-#define SHIDIM_FLAGS 0x0001
-#endif
-
-#ifndef SHIDIF_DONEBUTTON
-#define SHIDIF_DONEBUTTON 0x0001
-#endif
-#ifndef SHIDIF_SIZEDLGFULLSCREEN
-#define SHIDIF_SIZEDLGFULLSCREEN 0x0004
-#endif
-
-#ifndef SHDB_HIDE
-#define SHDB_HIDE 0x0002
-#endif
-
-#ifndef SHFS_SHOWTASKBAR
-#define SHFS_SHOWTASKBAR 0x0001
-#endif
-#ifndef SHFS_HIDETASKBAR
-#define SHFS_HIDETASKBAR 0x0002
-#endif
-#ifndef SHFS_SHOWSIPBUTTON
-#define SHFS_SHOWSIPBUTTON 0x0004
-#endif
-#ifndef SHFS_HIDESIPBUTTON
-#define SHFS_HIDESIPBUTTON 0x0008
-#endif
-#ifndef SHFS_SHOWSTARTICON
-#define SHFS_SHOWSTARTICON 0x0010
-#endif
-#ifndef SHFS_HIDESTARTICON
-#define SHFS_HIDESTARTICON 0x0020
-#endif
-
-#ifndef SIPF_OFF
-#define SIPF_OFF 0x00000000
-#endif
-#ifndef SIPF_ON
-#define SIPF_ON 0x00000001
-#endif
-
-#ifndef SPI_SETSIPINFO
-#define SPI_SETSIPINFO 224
-#endif
-#ifndef SPI_GETSIPINFO
-#define SPI_GETSIPINFO 225
-#endif
-#ifndef SPI_GETPLATFORMTYPE
-#define SPI_GETPLATFORMTYPE 257
-#endif
-
-typedef BOOL (*AygInitDialog)(AygSHINITDLGINFO*);
-typedef BOOL (*AygFullScreen)(HWND, DWORD);
-typedef BOOL (*AygSHSipInfo)(UINT, UINT, PVOID, UINT);
-typedef BOOL (*AygSHDoneButton)(HWND, DWORD);
-
-static AygInitDialog ptrAygInitDialog = 0;
-static AygFullScreen ptrAygFullScreen = 0;
-static AygSHSipInfo ptrAygSHSipInfo = 0;
-static AygSHDoneButton ptrAygSHDoneButton = 0;
-static bool aygResolved = false;
-
-static void resolveAygLibs()
-{
- if (!aygResolved) {
- aygResolved = true;
- QLibrary ayglib(QLatin1String("aygshell"));
- ptrAygInitDialog = (AygInitDialog) ayglib.resolve("SHInitDialog");
- ptrAygFullScreen = (AygFullScreen) ayglib.resolve("SHFullScreen");
- ptrAygSHSipInfo = (AygSHSipInfo) ayglib.resolve("SHSipInfo");
- ptrAygSHDoneButton = (AygSHDoneButton) ayglib.resolve("SHDoneButton");
- }
-}
-
-int qt_wince_GetDIBits(HDC /*hdc*/ , HBITMAP hSourceBitmap, uint, uint, LPVOID lpvBits, LPBITMAPINFO, uint)
-{
- if (!lpvBits) {
- qWarning("::GetDIBits(), lpvBits NULL");
- return 0;
- }
- BITMAP bm;
- GetObject(hSourceBitmap, sizeof(BITMAP), &bm);
- bm.bmHeight = qAbs(bm.bmHeight);
-
- HBITMAP hTargetBitmap;
- void *pixels;
-
- BITMAPINFO dibInfo;
- memset(&dibInfo, 0, sizeof(dibInfo));
- dibInfo.bmiHeader.biBitCount = 32;
- dibInfo.bmiHeader.biClrImportant = 0;
- dibInfo.bmiHeader.biClrUsed = 0;
- dibInfo.bmiHeader.biCompression = BI_RGB;;
- dibInfo.bmiHeader.biHeight = -bm.bmHeight;
- dibInfo.bmiHeader.biWidth = bm.bmWidth;
- dibInfo.bmiHeader.biPlanes = 1;
- dibInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- dibInfo.bmiHeader.biSizeImage = bm.bmWidth * bm.bmHeight * 4;
-
- HDC displayDC = GetDC(NULL);
- if (!displayDC) {
- qWarning("::GetDIBits(), failed to GetDC");
- return 0;
- }
-
- int ret = bm.bmHeight;
-
- hTargetBitmap = CreateDIBSection(displayDC, (const BITMAPINFO*) &dibInfo, DIB_RGB_COLORS,
- (void**)&pixels, NULL, 0);
- if (!hTargetBitmap) {
- qWarning("::GetDIBits(), failed to CreateDIBSection");
- return 0;
- }
-
- HDC hdcSrc = CreateCompatibleDC(displayDC);
- HDC hdcDst = CreateCompatibleDC(displayDC);
-
- if (!(hdcDst && hdcSrc)) {
- qWarning("::GetDIBits(), failed to CreateCompatibleDC");
- ret = 0;
- }
-
- HBITMAP hOldBitmap1 = (HBITMAP) SelectObject(hdcSrc, hSourceBitmap);
- HBITMAP hOldBitmap2 = (HBITMAP) SelectObject(hdcDst, hTargetBitmap);
-
- if (!(hOldBitmap1 && hOldBitmap2)) {
- qWarning("::GetDIBits(), failed to SelectObject for bitmaps");
- ret = 0;
- }
-
- if (!BitBlt(hdcDst, 0, 0, bm.bmWidth, bm.bmHeight, hdcSrc, 0, 0, SRCCOPY)) {
- qWarning("::GetDIBits(), BitBlt failed");
- ret = 0;
- }
-
- SelectObject(hdcSrc, hOldBitmap1);
- SelectObject(hdcDst, hOldBitmap2);
-
- DeleteDC(hdcSrc);
- DeleteDC(hdcDst);
-
- ReleaseDC(NULL, displayDC);
-
- memcpy(lpvBits, pixels, dibInfo.bmiHeader.biSizeImage);
-
- DeleteObject(hTargetBitmap);
- return ret;
-}
-
-HINSTANCE qt_wince_ShellExecute(HWND hwnd, LPCWSTR, LPCWSTR file, LPCWSTR params, LPCWSTR dir, int showCmd)
-{
- SHELLEXECUTEINFO info;
- info.hwnd = hwnd;
- info.lpVerb = L"Open";
- info.lpFile = file;
- info.lpParameters = params;
- info.lpDirectory = dir;
- info.nShow = showCmd;
- info.cbSize = sizeof(info);
- ShellExecuteEx(&info);
- return info.hInstApp;
-}
-
-// Clipboard --------------------------------------------------------
-BOOL qt_wince_ChangeClipboardChain( HWND /*hWndRemove*/, HWND /*hWndNewNext*/ )
-{
- return FALSE;
-}
-
-HWND qt_wince_SetClipboardViewer( HWND /*hWndNewViewer*/ )
-{
- return NULL;
-}
-
-
-// Graphics ---------------------------------------------------------
-COLORREF qt_wince_PALETTEINDEX( WORD /*wPaletteIndex*/)
-{
- return 0;
-}
-
-// Internal Qt -----------------------------------------------------
-bool qt_wince_is_platform(const QString &platformString) {
- wchar_t tszPlatform[64];
- if (SystemParametersInfo(SPI_GETPLATFORMTYPE, sizeof(tszPlatform) / sizeof(wchar_t), tszPlatform, 0))
- if (0 == _tcsicmp(reinterpret_cast<const wchar_t *> (platformString.utf16()), tszPlatform))
- return true;
- return false;
-}
-
-int qt_wince_get_build()
-{
- OSVERSIONINFO osvi;
- osvi.dwOSVersionInfoSize = sizeof(osvi);
- if (GetVersionEx(&osvi)) {
- return osvi.dwBuildNumber;
- }
- return 0;
-}
-
-int qt_wince_get_version()
-{
- OSVERSIONINFO osvi;
- osvi.dwOSVersionInfoSize = sizeof(osvi);
- if (GetVersionEx(&osvi)) {
- return (osvi.dwMajorVersion * 10 + osvi.dwMinorVersion);
- }
- return 0;
-}
-
-bool qt_wince_is_windows_mobile_65()
-{
- const DWORD dwFirstWM65BuildNumber = 21139;
- OSVERSIONINFO osvi;
- osvi.dwOSVersionInfoSize = sizeof(osvi);
- if (!GetVersionEx(&osvi))
- return false;
- return osvi.dwMajorVersion > 5
- || (osvi.dwMajorVersion == 5 && (osvi.dwMinorVersion > 2 ||
- (osvi.dwMinorVersion == 2 && osvi.dwBuildNumber >= dwFirstWM65BuildNumber)));
-}
-
-bool qt_wince_is_pocket_pc() {
- return qt_wince_is_platform(QString::fromLatin1("PocketPC"));
-}
-
-bool qt_wince_is_smartphone() {
- return qt_wince_is_platform(QString::fromLatin1("Smartphone"));
-}
-bool qt_wince_is_mobile() {
- return (qt_wince_is_smartphone() || qt_wince_is_pocket_pc());
-}
-
-bool qt_wince_is_high_dpi() {
- if (!qt_wince_is_pocket_pc())
- return false;
- HDC deviceContext = GetDC(0);
- int dpi = GetDeviceCaps(deviceContext, LOGPIXELSX);
- ReleaseDC(0, deviceContext);
- if ((dpi < 1000) && (dpi > 0))
- return dpi > 96;
- else
- return false;
-}
-
-void qt_wince_maximize(QWidget *widget)
-{
- HWND hwnd = widget->winId();
- if (qt_wince_is_mobile()) {
- AygSHINITDLGINFO shidi;
- shidi.dwMask = SHIDIM_FLAGS;
- shidi.hDlg = hwnd;
- shidi.dwFlags = SHIDIF_SIZEDLGFULLSCREEN;
- if (widget->windowFlags() & Qt::WindowCancelButtonHint)
- shidi.dwFlags |= SHIDIF_CANCELBUTTON;
- if (widget->windowFlags() & Qt::WindowOkButtonHint)
- shidi.dwFlags |= SHIDIF_DONEBUTTON;
- if (!(widget->windowFlags() & (Qt::WindowCancelButtonHint | Qt::WindowOkButtonHint)))
- shidi.dwFlags |= SHIDIF_CANCELBUTTON;
- resolveAygLibs();
- if (ptrAygInitDialog)
- ptrAygInitDialog(&shidi);
- } else {
- RECT r;
- SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
- MoveWindow(hwnd, r.top, r.left, r.right - r.left, r.bottom - r.top, true);
- SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong (hwnd, GWL_EXSTYLE) | WS_EX_NODRAG);
- }
-}
-
-void qt_wince_unmaximize(QWidget *widget)
-{
- if (ptrAygSHDoneButton && qt_wince_is_mobile()
- && !(widget->windowFlags() & (Qt::WindowCancelButtonHint | Qt::WindowOkButtonHint)))
- {
- // Hide the [X] button, we've added in qt_wince_maximize.
- ptrAygSHDoneButton(widget->winId(), SHDB_HIDE);
- }
-}
-
-void qt_wince_minimize(HWND hwnd)
-{
-#ifdef Q_OS_WINCE_WM
- ShowWindow(hwnd, SW_HIDE);
-#else
- if (!IsWindowVisible(hwnd)) {
- // Hack for an initial showMinimized.
- // Without it, our widget doesn't appear in the task bar.
- ShowWindow(hwnd, SW_SHOW);
- }
- ShowWindow(hwnd, SW_MINIMIZE);
-#endif
-}
-
-void qt_wince_hide_taskbar(HWND hwnd) {
- if (ptrAygFullScreen)
- ptrAygFullScreen(hwnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON);
-}
-
-void qt_wince_full_screen(HWND hwnd, bool fullScreen, UINT swpf) {
- resolveAygLibs();
- if (fullScreen) {
- QRect r = qApp->desktop()->screenGeometry(QWidget::find(hwnd));
- SetWindowPos(hwnd, HWND_TOP, r.left(), r.top(), r.width(), r.height(), swpf);
- if (ptrAygFullScreen)
- ptrAygFullScreen(hwnd, SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON | SHFS_HIDESTARTICON);
- if (!qt_wince_is_mobile()) {
- HWND handle = FindWindow(L"HHTaskBar", L"");
- if (handle) {
- ShowWindow(handle, 0);
- EnableWindow(handle, false);
- }
- }
- } else {
- if (ptrAygFullScreen)
- ptrAygFullScreen(hwnd, SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON | SHFS_SHOWSTARTICON);
- SetWindowPos(hwnd, 0, 0, 0, 0, 0, swpf);
- if (!qt_wince_is_mobile()) {
- HWND handle = FindWindow(L"HHTaskBar", L"");
- if (handle) {
- ShowWindow(handle, 1);
- EnableWindow(handle, true);
- }
- }
- }
-}
-
-void qt_wince_show_SIP(bool show)
-{
- resolveAygLibs();
- if (!ptrAygSHSipInfo)
- return;
-
- AygSIPINFO si;
- memset(&si, 0, sizeof(si));
- si.cbSize = sizeof(si);
- ptrAygSHSipInfo(SPI_GETSIPINFO, 0, &si, 0);
- si.cbSize = sizeof(si);
- si.fdwFlags = (show ? SIPF_ON : SIPF_OFF);
- ptrAygSHSipInfo(SPI_SETSIPINFO, 0, &si, 0);
-}
diff --git a/src/gui/kernel/qguifunctions_wince.h b/src/gui/kernel/qguifunctions_wince.h
deleted file mode 100644
index 2e14de0693..0000000000
--- a/src/gui/kernel/qguifunctions_wince.h
+++ /dev/null
@@ -1,151 +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 QGUIFUNCTIONS_WCE_H
-#define QGUIFUNCTIONS_WCE_H
-#ifdef Q_OS_WINCE
-#include <QtCore/qfunctions_wince.h>
-#define UNDER_NT
-#include <wingdi.h>
-
-#ifdef QT_BUILD_GUI_LIB
-QT_BEGIN_HEADER
-QT_BEGIN_NAMESPACE
-QT_MODULE(Gui)
-QT_END_NAMESPACE
-QT_END_HEADER
-#endif
-
-// application defines
-#define SPI_SETNONCLIENTMETRICS 72
-#define SPI_SETICONTITLELOGFONT 0x0022
-#define WM_ACTIVATEAPP 0x001c
-#define SW_PARENTCLOSING 1
-#define SW_OTHERMAXIMIZED 2
-#define SW_PARENTOPENING 3
-#define SW_OTHERRESTORED 4
-#define GET_XBUTTON_WPARAM(wParam) (HIWORD(wParam))
-
-// drag n drop
-#ifndef CFSTR_PERFORMEDDROPEFFECT
-#define CFSTR_PERFORMEDDROPEFFECT TEXT("Performed DropEffect")
-#endif
-int qt_wince_GetDIBits(HDC, HBITMAP, uint, uint, void*, LPBITMAPINFO, uint);
-#define GetDIBits(a,b,c,d,e,f,g) qt_wince_GetDIBits(a,b,c,d,e,f,g)
-
-// QWidget
-#define SW_SHOWMINIMIZED SW_MINIMIZE
-
-// QRegion
-#define ALTERNATE 0
-#define WINDING 1
-
-// QFontEngine
-typedef struct _FIXED {
- WORD fract;
- short value;
-} FIXED;
-
-typedef struct tagPOINTFX {
- FIXED x;
- FIXED y;
-} POINTFX;
-
-typedef struct _MAT2 {
- FIXED eM11;
- FIXED eM12;
- FIXED eM21;
- FIXED eM22;
-} MAT2;
-
-typedef struct _GLYPHMETRICS {
- UINT gmBlackBoxX;
- UINT gmBlackBoxY;
- POINT gmptGlyphOrigin;
- short gmCellIncX;
- short gmCellIncY;
-} GLYPHMETRICS;
-
-typedef struct tagTTPOLYGONHEADER
-{
- DWORD cb;
- DWORD dwType;
- POINTFX pfxStart;
-} TTPOLYGONHEADER;
-
-typedef struct tagTTPOLYCURVE
-{
- WORD wType;
- WORD cpfx;
- POINTFX apfx[1];
-} TTPOLYCURVE;
-
-#define GGO_NATIVE 2
-#define GGO_GLYPH_INDEX 0x0080
-#define TT_PRIM_LINE 1
-#define TT_PRIM_QSPLINE 2
-#define TT_PRIM_CSPLINE 3
-#define ANSI_VAR_FONT 12
-
-HINSTANCE qt_wince_ShellExecute(HWND hwnd, LPCWSTR operation, LPCWSTR file, LPCWSTR params, LPCWSTR dir, int showCmd);
-#define ShellExecute(a,b,c,d,e,f) qt_wince_ShellExecute(a,b,c,d,e,f)
-
-
-// Clipboard --------------------------------------------------------
-#define WM_CHANGECBCHAIN 1
-#define WM_DRAWCLIPBOARD 2
-
-BOOL qt_wince_ChangeClipboardChain(
- HWND hWndRemove, // handle to window to remove
- HWND hWndNewNext // handle to next window
-);
-#define ChangeClipboardChain(a,b) qt_wince_ChangeClipboardChain(a,b);
-
-HWND qt_wince_SetClipboardViewer(
- HWND hWndNewViewer // handle to clipboard viewer window
-);
-#define SetClipboardViewer(a) qt_wince_SetClipboardViewer(a)
-
-// Graphics ---------------------------------------------------------
-COLORREF qt_wince_PALETTEINDEX( WORD wPaletteIndex );
-#define PALETTEINDEX(a) qt_wince_PALETTEINDEX(a)
-
-#endif // Q_OS_WINCE
-#endif // QGUIFUNCTIONS_WCE_H
diff --git a/src/gui/kernel/qkde.cpp b/src/gui/kernel/qkde.cpp
deleted file mode 100644
index 7d333feb9a..0000000000
--- a/src/gui/kernel/qkde.cpp
+++ /dev/null
@@ -1,176 +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 "qkde_p.h"
-#include <QtCore/QLibrary>
-#include <QtCore/QDir>
-#include <QtCore/qdebug.h>
-#include <QtCore/QSettings>
-#include "QtGui/qstylefactory.h"
-#include "qt_x11_p.h"
-
-#if defined(Q_WS_X11)
-
-QT_BEGIN_NAMESPACE
-
-/*! \internal
-Gets the current KDE home path
-like "/home/troll/.kde"
-*/
-QString QKde::kdeHome()
-{
- static QString kdeHomePath;
- if (kdeHomePath.isEmpty()) {
- kdeHomePath = QString::fromLocal8Bit(qgetenv("KDEHOME"));
- if (kdeHomePath.isEmpty()) {
- QDir homeDir(QDir::homePath());
- QString kdeConfDir(QLatin1String("/.kde"));
- if (4 == X11->desktopVersion && homeDir.exists(QLatin1String(".kde4")))
- kdeConfDir = QLatin1String("/.kde4");
- kdeHomePath = QDir::homePath() + kdeConfDir;
- }
- }
- return kdeHomePath;
-}
-
-/*!\internal
- Reads the color from the config, and store it in the palette with the given color role if found
- */
-static bool kdeColor(QPalette *pal, QPalette::ColorRole role, const QSettings &kdeSettings, const QString &kde4Key, const QString &kde3Key = QString())
-{
- QVariant variant = kdeSettings.value(kde4Key);
- if (!variant.isValid())
- QVariant variant = kdeSettings.value(kde3Key);
- if (variant.isValid()) {
- QStringList values = variant.toStringList();
- if (values.size() == 3) {
- int r = values[0].toInt();
- int g = values[1].toInt();
- int b = values[2].toInt();
- pal->setBrush(role, QColor(r, g, b));
- return true;
- }
- }
- return false;
-}
-
-
-/*!\internal
- Returns the KDE palette
-*/
-QPalette QKde::kdePalette()
-{
- const QSettings theKdeSettings(QKde::kdeHome() +
- QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat);
- QPalette pal;
-
- // Setup KDE palette
- kdeColor(&pal, QPalette::Button, theKdeSettings, QLatin1String("Colors:Button/BackgroundNormal"), QLatin1String("buttonBackground"));
- kdeColor(&pal, QPalette::Window, theKdeSettings, QLatin1String("Colors:Window/BackgroundNormal"), QLatin1String("background"));
- kdeColor(&pal, QPalette::Text, theKdeSettings, QLatin1String("Colors:View/ForegroundNormal"), QLatin1String("foreground"));
- kdeColor(&pal, QPalette::WindowText, theKdeSettings, QLatin1String("Colors:Window/ForegroundNormal"), QLatin1String("windowForeground"));
- kdeColor(&pal, QPalette::Base, theKdeSettings, QLatin1String("Colors:View/BackgroundNormal"), QLatin1String("windowBackground"));
- kdeColor(&pal, QPalette::Highlight, theKdeSettings, QLatin1String("Colors:Selection/BackgroundNormal"), QLatin1String("selectBackground"));
- kdeColor(&pal, QPalette::HighlightedText, theKdeSettings, QLatin1String("Colors:Selection/ForegroundNormal"), QLatin1String("selectForeground"));
- kdeColor(&pal, QPalette::AlternateBase, theKdeSettings, QLatin1String("Colors:View/BackgroundAlternate"), QLatin1String("alternateBackground"));
- kdeColor(&pal, QPalette::ButtonText, theKdeSettings, QLatin1String("Colors:Button/ForegroundNormal"), QLatin1String("buttonForeground"));
- kdeColor(&pal, QPalette::Link, theKdeSettings, QLatin1String("Colors:View/ForegroundLink"), QLatin1String("linkColor"));
- kdeColor(&pal, QPalette::LinkVisited, theKdeSettings, QLatin1String("Colors:View/ForegroundVisited"), QLatin1String("visitedLinkColor"));
- //## TODO tooltip color
-
- return pal;
-}
-
-/*!\internal
- Returns the name of the QStyle to use.
- (read from the kde config if needed)
-*/
-QString QKde::kdeStyle()
-{
- if (X11->desktopVersion >= 4) {
- QSettings kdeSettings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat);
- QString style = kdeSettings.value(QLatin1String("widgetStyle"), QLatin1String("Oxygen")).toString();
-
- QStringList availableStyles = QStyleFactory::keys();
- if(availableStyles.contains(style, Qt::CaseInsensitive))
- return style;
- }
-
- if (X11->use_xrender)
- return QLatin1String("plastique");
- else
- return QLatin1String("windows");
-}
-
-
-int QKde::kdeToolButtonStyle()
-{
- QSettings settings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"),
- QSettings::IniFormat);
- settings.beginGroup(QLatin1String("Toolbar style"));
- QString toolbarStyle = settings.value(QLatin1String("ToolButtonStyle"), QLatin1String("TextBesideIcon")).toString();
- if (toolbarStyle == QLatin1String("TextBesideIcon"))
- return Qt::ToolButtonTextBesideIcon;
- else if (toolbarStyle == QLatin1String("TextOnly"))
- return Qt::ToolButtonTextOnly;
- else if (toolbarStyle == QLatin1String("TextUnderIcon"))
- return Qt::ToolButtonTextUnderIcon;
-
- return Qt::ToolButtonTextBesideIcon;
-}
-
-int QKde::kdeToolBarIconSize()
-{
- static int iconSize = -1;
- if (iconSize == -1) {
- QSettings settings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"),
- QSettings::IniFormat);
- settings.beginGroup(QLatin1String("ToolbarIcons"));
- iconSize = settings.value(QLatin1String("Size")).toInt();
- }
- return iconSize;
-}
-
-QT_END_NAMESPACE
-
-#endif //Q_WS_X11
-
diff --git a/src/gui/kernel/qkde_p.h b/src/gui/kernel/qkde_p.h
deleted file mode 100644
index 4e108f6e9e..0000000000
--- a/src/gui/kernel/qkde_p.h
+++ /dev/null
@@ -1,81 +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 QKDE_H
-#define QKDE_H
-
-#include <QtCore/qglobal.h>
-#include <QtGui/QPalette>
-#include <QtGui/QIcon>
-
-//
-// 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.
-//
-#if defined(Q_WS_X11)
-
-
-QT_BEGIN_NAMESPACE
-
-/*!\internal
- This namespace contains helper function to help KDE integration
- They are only used if we detect the use of KDE and the KDE platform plugin is not found (old KDE version)
- Or if the detected KDE version is KDE3
-*/
-namespace QKde {
- QString kdeHome();
- QString kdeStyle();
- QPalette kdePalette();
- int kdeToolButtonStyle();
- int kdeToolBarIconSize();
-}
-
-
-QT_END_NAMESPACE
-
-#endif // Q_WS_X11
-#endif // QKDE_H
diff --git a/src/gui/kernel/qmacdefines_mac.h b/src/gui/kernel/qmacdefines_mac.h
deleted file mode 100644
index d6ccb93593..0000000000
--- a/src/gui/kernel/qmacdefines_mac.h
+++ /dev/null
@@ -1,180 +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$
-**
-****************************************************************************/
-
-/****************************************************************************
-**
-** Copyright (c) 2007-2008, Apple, Inc.
-**
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-**
-** * Redistributions of source code must retain the above copyright notice,
-** this list of conditions and the following disclaimer.
-**
-** * Redistributions in binary form must reproduce the above copyright notice,
-** this list of conditions and the following disclaimer in the documentation
-** and/or other materials provided with the distribution.
-**
-** * Neither the name of Apple, Inc. nor the names of its contributors
-** may be used to endorse or promote products derived from this software
-** without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-****************************************************************************/
-
-/*
- * qmacdefines_mac_p.h
- * All the defines you'll ever need for Qt/Mac :-)
- */
-
-/* This is just many defines. Therefore it doesn't need things like:
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Gui)
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-Yes, it is an informative comment ;-)
-*/
-
-#include <QtCore/qglobal.h>
-
-#ifdef qDebug
-# define old_qDebug qDebug
-# undef qDebug
-#endif
-
-#ifdef __LP64__
-typedef signed int OSStatus;
-#else
-typedef signed long OSStatus;
-#endif
-
-#ifdef __OBJC__
-# ifdef slots
-# define old_slots slots
-# undef slots
-# endif
-#include <Cocoa/Cocoa.h>
-# ifdef old_slots
-# undef slots
-# define slots
-# undef old_slots
-# endif
-#endif
-#ifdef QT_MAC_USE_COCOA
- typedef struct OpaqueEventHandlerCallRef * EventHandlerCallRef;
- typedef struct OpaqueEventRef * EventRef;
- typedef struct OpaqueMenuRef * MenuRef;
- typedef struct OpaquePasteboardRef* PasteboardRef;
- typedef struct OpaqueRgnHandle * RgnHandle;
- typedef const struct __HIShape *HIShapeRef;
- typedef struct __HIShape *HIMutableShapeRef;
- typedef struct CGRect CGRect;
- typedef struct CGImage *CGImageRef;
- typedef struct CGContext *CGContextRef;
- typedef struct GDevice * GDPtr;
- typedef GDPtr * GDHandle;
- typedef struct OpaqueIconRef * IconRef;
-# ifdef __OBJC__
- typedef NSWindow* OSWindowRef;
- typedef NSView *OSViewRef;
- typedef NSMenu *OSMenuRef;
- typedef NSEvent *OSEventRef;
-# else
- typedef void *OSWindowRef;
- typedef void *OSViewRef;
- typedef void *OSMenuRef;
- typedef void *OSEventRef;
-# endif
-#else // Carbon
- typedef struct OpaqueEventHandlerCallRef * EventHandlerCallRef;
- typedef struct OpaqueEventRef * EventRef;
- typedef struct OpaqueMenuRef * MenuRef;
- typedef struct OpaquePasteboardRef* PasteboardRef;
- typedef struct OpaqueRgnHandle * RgnHandle;
- typedef const struct __HIShape *HIShapeRef;
- typedef struct __HIShape *HIMutableShapeRef;
- typedef struct CGRect CGRect;
- typedef struct CGImage *CGImageRef;
- typedef struct CGContext *CGContextRef;
- typedef struct GDevice * GDPtr;
- typedef GDPtr * GDHandle;
- typedef struct OpaqueIconRef * IconRef;
- typedef struct OpaqueWindowPtr * WindowRef;
- typedef struct OpaqueControlRef * HIViewRef;
- typedef WindowRef OSWindowRef;
- typedef HIViewRef OSViewRef;
- typedef MenuRef OSMenuRef;
- typedef EventRef OSEventRef;
-#endif // QT_MAC_USE_COCOA
-
-typedef PasteboardRef OSPasteboardRef;
-typedef struct AEDesc AEDescList;
-typedef AEDescList AERecord;
-typedef AERecord AppleEvent;
-
-#ifdef check
-#undef check
-#endif
-
-#ifdef old_qDebug
-# undef qDebug
-# define qDebug QT_NO_QDEBUG_MACRO
-# undef old_qDebug
-#endif
diff --git a/src/gui/kernel/qmacgesturerecognizer_mac.mm b/src/gui/kernel/qmacgesturerecognizer_mac.mm
deleted file mode 100644
index 6a4f0bb445..0000000000
--- a/src/gui/kernel/qmacgesturerecognizer_mac.mm
+++ /dev/null
@@ -1,272 +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 "qmacgesturerecognizer_mac_p.h"
-#include "qgesture.h"
-#include "qgesture_p.h"
-#include "qevent.h"
-#include "qevent_p.h"
-#include "qwidget.h"
-#include "qdebug.h"
-
-#ifndef QT_NO_GESTURES
-
-QT_BEGIN_NAMESPACE
-
-QMacSwipeGestureRecognizer::QMacSwipeGestureRecognizer()
-{
-}
-
-QGesture *QMacSwipeGestureRecognizer::create(QObject * /*target*/)
-{
- return new QSwipeGesture;
-}
-
-QGestureRecognizer::Result
-QMacSwipeGestureRecognizer::recognize(QGesture *gesture, QObject *obj, QEvent *event)
-{
- if (event->type() == QEvent::NativeGesture && obj->isWidgetType()) {
- QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event);
- switch (ev->gestureType) {
- case QNativeGestureEvent::Swipe: {
- QSwipeGesture *g = static_cast<QSwipeGesture *>(gesture);
- g->setSwipeAngle(ev->angle);
- g->setHotSpot(ev->position);
- return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
- break; }
- default:
- break;
- }
- }
-
- return QGestureRecognizer::Ignore;
-}
-
-void QMacSwipeGestureRecognizer::reset(QGesture *gesture)
-{
- QSwipeGesture *g = static_cast<QSwipeGesture *>(gesture);
- g->setSwipeAngle(0);
- QGestureRecognizer::reset(gesture);
-}
-
-////////////////////////////////////////////////////////////////////////
-
-QMacPinchGestureRecognizer::QMacPinchGestureRecognizer()
-{
-}
-
-QGesture *QMacPinchGestureRecognizer::create(QObject * /*target*/)
-{
- return new QPinchGesture;
-}
-
-QGestureRecognizer::Result
-QMacPinchGestureRecognizer::recognize(QGesture *gesture, QObject *obj, QEvent *event)
-{
- if (event->type() == QEvent::NativeGesture && obj->isWidgetType()) {
- QPinchGesture *g = static_cast<QPinchGesture *>(gesture);
- QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event);
- switch(ev->gestureType) {
- case QNativeGestureEvent::GestureBegin:
- reset(gesture);
- g->setStartCenterPoint(static_cast<QWidget*>(obj)->mapFromGlobal(ev->position));
- g->setCenterPoint(g->startCenterPoint());
- g->setChangeFlags(QPinchGesture::CenterPointChanged);
- g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags());
- g->setHotSpot(ev->position);
- return QGestureRecognizer::MayBeGesture | QGestureRecognizer::ConsumeEventHint;
- case QNativeGestureEvent::Rotate: {
- g->setLastScaleFactor(g->scaleFactor());
- g->setLastRotationAngle(g->rotationAngle());
- g->setRotationAngle(g->rotationAngle() + ev->percentage);
- g->setChangeFlags(QPinchGesture::RotationAngleChanged);
- g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags());
- g->setHotSpot(ev->position);
- return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
- }
- case QNativeGestureEvent::Zoom:
- g->setLastScaleFactor(g->scaleFactor());
- g->setLastRotationAngle(g->rotationAngle());
- g->setScaleFactor(g->scaleFactor() * (1 + ev->percentage));
- g->setChangeFlags(QPinchGesture::ScaleFactorChanged);
- g->setTotalChangeFlags(g->totalChangeFlags() | g->changeFlags());
- g->setHotSpot(ev->position);
- return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
- case QNativeGestureEvent::GestureEnd:
- return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
- default:
- break;
- }
- }
-
- return QGestureRecognizer::Ignore;
-}
-
-void QMacPinchGestureRecognizer::reset(QGesture *gesture)
-{
- QPinchGesture *g = static_cast<QPinchGesture *>(gesture);
- g->setChangeFlags(0);
- g->setTotalChangeFlags(0);
- g->setScaleFactor(1.0f);
- g->setTotalScaleFactor(1.0f);
- g->setLastScaleFactor(1.0f);
- g->setRotationAngle(0.0f);
- g->setTotalRotationAngle(0.0f);
- g->setLastRotationAngle(0.0f);
- g->setCenterPoint(QPointF());
- g->setStartCenterPoint(QPointF());
- g->setLastCenterPoint(QPointF());
- QGestureRecognizer::reset(gesture);
-}
-
-////////////////////////////////////////////////////////////////////////
-
-#if defined(QT_MAC_USE_COCOA)
-
-QMacPanGestureRecognizer::QMacPanGestureRecognizer() : _panCanceled(true)
-{
-}
-
-QGesture *QMacPanGestureRecognizer::create(QObject *target)
-{
- if (!target)
- return new QPanGesture;
-
- if (QWidget *w = qobject_cast<QWidget *>(target)) {
- w->setAttribute(Qt::WA_AcceptTouchEvents);
- w->setAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents);
- return new QPanGesture;
- }
- return 0;
-}
-
-QGestureRecognizer::Result
-QMacPanGestureRecognizer::recognize(QGesture *gesture, QObject *target, QEvent *event)
-{
- const int panBeginDelay = 300;
- const int panBeginRadius = 3;
-
- QPanGesture *g = static_cast<QPanGesture *>(gesture);
-
- switch (event->type()) {
- case QEvent::TouchBegin: {
- const QTouchEvent *ev = static_cast<const QTouchEvent*>(event);
- if (ev->touchPoints().size() == 1) {
- reset(gesture);
- _startPos = QCursor::pos();
- _panTimer.start(panBeginDelay, target);
- _panCanceled = false;
- return QGestureRecognizer::MayBeGesture;
- }
- break;}
- case QEvent::TouchEnd: {
- if (_panCanceled)
- break;
-
- const QTouchEvent *ev = static_cast<const QTouchEvent*>(event);
- if (ev->touchPoints().size() == 1)
- return QGestureRecognizer::FinishGesture;
- break;}
- case QEvent::TouchUpdate: {
- if (_panCanceled)
- break;
-
- const QTouchEvent *ev = static_cast<const QTouchEvent*>(event);
- if (ev->touchPoints().size() == 1) {
- if (_panTimer.isActive()) {
- // INVARIANT: Still in maybeGesture. Check if the user
- // moved his finger so much that it makes sense to cancel the pan:
- const QPointF p = QCursor::pos();
- if ((p - _startPos).manhattanLength() > panBeginRadius) {
- _panCanceled = true;
- _panTimer.stop();
- return QGestureRecognizer::CancelGesture;
- }
- } else {
- const QPointF p = QCursor::pos();
- const QPointF posOffset = p - _startPos;
- g->setLastOffset(g->offset());
- g->setOffset(QPointF(posOffset.x(), posOffset.y()));
- g->setHotSpot(_startPos);
- return QGestureRecognizer::TriggerGesture;
- }
- } else if (_panTimer.isActive()) {
- // I only want to cancel the pan if the user is pressing
- // more than one finger, and the pan hasn't started yet:
- _panCanceled = true;
- _panTimer.stop();
- return QGestureRecognizer::CancelGesture;
- }
- break;}
- case QEvent::Timer: {
- QTimerEvent *ev = static_cast<QTimerEvent *>(event);
- if (ev->timerId() == _panTimer.timerId()) {
- _panTimer.stop();
- if (_panCanceled)
- break;
- // Begin new pan session!
- _startPos = QCursor::pos();
- g->setHotSpot(_startPos);
- return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
- }
- break; }
- default:
- break;
- }
-
- return QGestureRecognizer::Ignore;
-}
-
-void QMacPanGestureRecognizer::reset(QGesture *gesture)
-{
- QPanGesture *g = static_cast<QPanGesture *>(gesture);
- _startPos = QPointF();
- _panCanceled = true;
- g->setOffset(QPointF(0, 0));
- g->setLastOffset(QPointF(0, 0));
- g->setAcceleration(qreal(1));
- QGestureRecognizer::reset(gesture);
-}
-#endif // QT_MAC_USE_COCOA
-
-QT_END_NAMESPACE
-
-#endif // QT_NO_GESTURES
diff --git a/src/gui/kernel/qmacgesturerecognizer_mac_p.h b/src/gui/kernel/qmacgesturerecognizer_mac_p.h
deleted file mode 100644
index 465f6a2ac8..0000000000
--- a/src/gui/kernel/qmacgesturerecognizer_mac_p.h
+++ /dev/null
@@ -1,106 +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 QMACSWIPEGESTURERECOGNIZER_MAC_P_H
-#define QMACSWIPEGESTURERECOGNIZER_MAC_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 "qtimer.h"
-#include "qpoint.h"
-#include "qgesturerecognizer.h"
-
-#ifndef QT_NO_GESTURES
-
-QT_BEGIN_NAMESPACE
-
-class QMacSwipeGestureRecognizer : public QGestureRecognizer
-{
-public:
- QMacSwipeGestureRecognizer();
-
- QGesture *create(QObject *target);
- QGestureRecognizer::Result recognize(QGesture *gesture, QObject *watched, QEvent *event);
- void reset(QGesture *gesture);
-};
-
-class QMacPinchGestureRecognizer : public QGestureRecognizer
-{
-public:
- QMacPinchGestureRecognizer();
-
- QGesture *create(QObject *target);
- QGestureRecognizer::Result recognize(QGesture *gesture, QObject *watched, QEvent *event);
- void reset(QGesture *gesture);
-};
-
-#if defined(QT_MAC_USE_COCOA)
-
-class QMacPanGestureRecognizer : public QObject, public QGestureRecognizer
-{
-public:
- QMacPanGestureRecognizer();
-
- QGesture *create(QObject *target);
- QGestureRecognizer::Result recognize(QGesture *gesture, QObject *watched, QEvent *event);
- void reset(QGesture *gesture);
-private:
- QPointF _startPos;
- QBasicTimer _panTimer;
- bool _panCanceled;
-};
-
-#endif
-
-QT_END_NAMESPACE
-
-#endif // QT_NO_GESTURES
-
-#endif // QMACSWIPEGESTURERECOGNIZER_MAC_P_H
diff --git a/src/gui/kernel/qmultitouch_mac.mm b/src/gui/kernel/qmultitouch_mac.mm
deleted file mode 100644
index d9e845a01c..0000000000
--- a/src/gui/kernel/qmultitouch_mac.mm
+++ /dev/null
@@ -1,218 +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/qmultitouch_mac_p.h>
-#include <qcursor.h>
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
-
-QT_BEGIN_NAMESPACE
-
-#ifdef QT_MAC_USE_COCOA
-
-QHash<qint64, QCocoaTouch*> QCocoaTouch::_currentTouches;
-QPointF QCocoaTouch::_screenReferencePos;
-QPointF QCocoaTouch::_trackpadReferencePos;
-int QCocoaTouch::_idAssignmentCount = 0;
-int QCocoaTouch::_touchCount = 0;
-bool QCocoaTouch::_updateInternalStateOnly = true;
-
-QCocoaTouch::QCocoaTouch(NSTouch *nstouch)
-{
- if (_currentTouches.size() == 0)
- _idAssignmentCount = 0;
-
- _touchPoint.setId(_idAssignmentCount++);
- _touchPoint.setPressure(1.0);
- _identity = qint64([nstouch identity]);
- _currentTouches.insert(_identity, this);
- updateTouchData(nstouch, NSTouchPhaseBegan);
-}
-
-QCocoaTouch::~QCocoaTouch()
-{
- _currentTouches.remove(_identity);
-}
-
-void QCocoaTouch::updateTouchData(NSTouch *nstouch, NSTouchPhase phase)
-{
- if (_touchCount == 1)
- _touchPoint.setState(toTouchPointState(phase) | Qt::TouchPointPrimary);
- else
- _touchPoint.setState(toTouchPointState(phase));
-
- // From the normalized position on the trackpad, calculate
- // where on screen the touchpoint should be according to the
- // reference position:
- NSPoint npos = [nstouch normalizedPosition];
- QPointF qnpos = QPointF(npos.x, 1 - npos.y);
- _touchPoint.setNormalizedPos(qnpos);
-
- if (_touchPoint.id() == 0 && phase == NSTouchPhaseBegan) {
- _trackpadReferencePos = qnpos;
- _screenReferencePos = QCursor::pos();
- }
-
- NSSize dsize = [nstouch deviceSize];
- float ppiX = (qnpos.x() - _trackpadReferencePos.x()) * dsize.width;
- float ppiY = (qnpos.y() - _trackpadReferencePos.y()) * dsize.height;
- QPointF relativePos = _trackpadReferencePos - QPointF(ppiX, ppiY);
- _touchPoint.setScreenPos(_screenReferencePos - relativePos);
-}
-
-QCocoaTouch *QCocoaTouch::findQCocoaTouch(NSTouch *nstouch)
-{
- qint64 identity = qint64([nstouch identity]);
- if (_currentTouches.contains(identity))
- return _currentTouches.value(identity);
- return 0;
-}
-
-Qt::TouchPointState QCocoaTouch::toTouchPointState(NSTouchPhase nsState)
-{
- Qt::TouchPointState qtState = Qt::TouchPointReleased;
- switch (nsState) {
- case NSTouchPhaseBegan:
- qtState = Qt::TouchPointPressed;
- break;
- case NSTouchPhaseMoved:
- qtState = Qt::TouchPointMoved;
- break;
- case NSTouchPhaseStationary:
- qtState = Qt::TouchPointStationary;
- break;
- case NSTouchPhaseEnded:
- case NSTouchPhaseCancelled:
- qtState = Qt::TouchPointReleased;
- break;
- default:
- break;
- }
- return qtState;
-}
-
-QList<QTouchEvent::TouchPoint>
-QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch)
-{
- QMap<int, QTouchEvent::TouchPoint> touchPoints;
- NSSet *ended = [event touchesMatchingPhase:NSTouchPhaseEnded | NSTouchPhaseCancelled inView:nil];
- NSSet *active = [event
- touchesMatchingPhase:NSTouchPhaseBegan | NSTouchPhaseMoved | NSTouchPhaseStationary
- inView:nil];
- _touchCount = [active count];
-
- // First: remove touches that were ended by the user. If we are
- // currently not accepting single touches, a corresponding 'begin'
- // has never been send to the app for these events.
- // So should therefore not send the following removes either.
-
- for (int i=0; i<int([ended count]); ++i) {
- NSTouch *touch = [[ended allObjects] objectAtIndex:i];
- QCocoaTouch *qcocoaTouch = findQCocoaTouch(touch);
- if (qcocoaTouch) {
- qcocoaTouch->updateTouchData(touch, [touch phase]);
- if (!_updateInternalStateOnly)
- touchPoints.insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint);
- delete qcocoaTouch;
- }
- }
-
- bool wasUpdateInternalStateOnly = _updateInternalStateOnly;
- _updateInternalStateOnly = !acceptSingleTouch && _touchCount < 2;
-
- // Next: update, or create, existing touches.
- // We always keep track of all touch points, even
- // when not accepting single touches.
-
- for (int i=0; i<int([active count]); ++i) {
- NSTouch *touch = [[active allObjects] objectAtIndex:i];
- QCocoaTouch *qcocoaTouch = findQCocoaTouch(touch);
- if (!qcocoaTouch)
- qcocoaTouch = new QCocoaTouch(touch);
- else
- qcocoaTouch->updateTouchData(touch, wasUpdateInternalStateOnly ? NSTouchPhaseBegan : [touch phase]);
- if (!_updateInternalStateOnly)
- touchPoints.insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint);
- }
-
- // Next: sadly, we need to check that our touch hash is in
- // sync with cocoa. This is typically not the case after a system
- // gesture happend (like a four-finger-swipe to show expose).
-
- if (_touchCount != _currentTouches.size()) {
- // Remove all instances, and basically start from scratch:
- touchPoints.clear();
- foreach (QCocoaTouch *qcocoaTouch, _currentTouches.values()) {
- if (!_updateInternalStateOnly) {
- qcocoaTouch->_touchPoint.setState(Qt::TouchPointReleased);
- touchPoints.insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint);
- }
- delete qcocoaTouch;
- }
- _currentTouches.clear();
- _updateInternalStateOnly = !acceptSingleTouch;
- return touchPoints.values();
- }
-
- // Finally: If this call _started_ to reject single
- // touches, we need to fake a relase for the remaining
- // touch now (and refake a begin for it later, if needed).
-
- if (_updateInternalStateOnly && !wasUpdateInternalStateOnly && !_currentTouches.isEmpty()) {
- QCocoaTouch *qcocoaTouch = _currentTouches.values().first();
- qcocoaTouch->_touchPoint.setState(Qt::TouchPointReleased);
- touchPoints.insert(qcocoaTouch->_touchPoint.id(), qcocoaTouch->_touchPoint);
- // Since this last touch also will end up beeing the first
- // touch (if the user adds a second finger without lifting
- // the first), we promote it to be the primary touch:
- qcocoaTouch->_touchPoint.setId(0);
- _idAssignmentCount = 1;
- }
-
- return touchPoints.values();
-}
-
-#endif
-
-QT_END_NAMESPACE
-
-#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
-
diff --git a/src/gui/kernel/qmultitouch_mac_p.h b/src/gui/kernel/qmultitouch_mac_p.h
deleted file mode 100644
index 16be930d0a..0000000000
--- a/src/gui/kernel/qmultitouch_mac_p.h
+++ /dev/null
@@ -1,102 +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$
-**
-****************************************************************************/
-
-//
-// 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.
-//
-
-#ifndef QMULTITOUCH_MAC_P_H
-#define QMULTITOUCH_MAC_P_H
-
-#ifdef QT_MAC_USE_COCOA
-#import <Cocoa/Cocoa.h>
-#endif
-
-#include <qevent.h>
-#include <qhash.h>
-#include <QtCore>
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
-
-QT_BEGIN_NAMESPACE
-
-#ifdef QT_MAC_USE_COCOA
-
-class QCocoaTouch
-{
- public:
- static QList<QTouchEvent::TouchPoint> getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch);
- static void setMouseInDraggingState(bool inDraggingState);
-
- private:
- static QHash<qint64, QCocoaTouch*> _currentTouches;
- static QPointF _screenReferencePos;
- static QPointF _trackpadReferencePos;
- static int _idAssignmentCount;
- static int _touchCount;
- static bool _updateInternalStateOnly;
-
- QTouchEvent::TouchPoint _touchPoint;
- qint64 _identity;
-
- QCocoaTouch(NSTouch *nstouch);
- ~QCocoaTouch();
-
- void updateTouchData(NSTouch *nstouch, NSTouchPhase phase);
- static QCocoaTouch *findQCocoaTouch(NSTouch *nstouch);
- static Qt::TouchPointState toTouchPointState(NSTouchPhase nsState);
-};
-
-#endif // QT_MAC_USE_COCOA
-
-QT_END_NAMESPACE
-
-#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
-
-#endif // QMULTITOUCH_MAC_P_H
-
diff --git a/src/gui/kernel/qnsframeview_mac_p.h b/src/gui/kernel/qnsframeview_mac_p.h
deleted file mode 100644
index 6ec3f64efa..0000000000
--- a/src/gui/kernel/qnsframeview_mac_p.h
+++ /dev/null
@@ -1,154 +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$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp
-// and many other. This header file may change from version to version
-// without notice, or even be removed.
-//
-// We mean it.
-//
-
-// Private AppKit class (dumped from classdump).
-
-#import <Cocoa/Cocoa.h>
-
-@interface NSFrameView : NSView
-{
- unsigned int styleMask;
- NSString *_title;
- NSCell *titleCell;
- NSButton *closeButton;
- NSButton *zoomButton;
- NSButton *minimizeButton;
- char resizeByIncrement;
- char frameNeedsDisplay;
- unsigned char tabViewCount;
- NSSize resizeParameter;
- int shadowState;
-}
-
-+ (void)initialize;
-+ (void)initTitleCell:fp8 styleMask:(unsigned int)fp12;
-+ (struct _NSRect)frameRectForContentRect:(struct _NSRect)fp8 styleMask:(unsigned int)fp24;
-+ (struct _NSRect)contentRectForFrameRect:(struct _NSRect)fp8 styleMask:(unsigned int)fp24;
-+ (struct _NSSize)minFrameSizeForMinContentSize:(struct _NSSize)fp8 styleMask:(unsigned int)fp16;
-+ (struct _NSSize)minContentSizeForMinFrameSize:(struct _NSSize)fp8 styleMask:(unsigned int)fp16;
-+ (float)minFrameWidthWithTitle:fp8 styleMask:(unsigned int)fp12;
-+ (unsigned int)_validateStyleMask:(unsigned int)fp8;
-- initWithFrame:(struct _NSRect)fp8 styleMask:(unsigned int)fp24 owner:fp28;
-- initWithFrame:(struct _NSRect)fp8;
-- (void)dealloc;
-- (void)shapeWindow;
-- (void)tileAndSetWindowShape:(char)fp8;
-- (void)tile;
-- (void)drawRect:(struct _NSRect)fp8;
-- (void)_drawFrameRects:(struct _NSRect)fp8;
-- (void)drawFrame:(struct _NSRect)fp8;
-- (void)drawThemeContentFill:(struct _NSRect)fp8 inView:fp24;
-- (void)drawWindowBackgroundRect:(struct _NSRect)fp8;
-- (void)drawWindowBackgroundRegion:(void *)fp8;
-- (float)contentAlpha;
-- (void)_windowChangedKeyState;
-- (void)_updateButtonState;
-- (char)_isSheet;
-- (char)_isUtility;
-- (void)setShadowState:(int)fp8;
-- (int)shadowState;
-- (char)_canHaveToolbar;
-- (char)_toolbarIsInTransition;
-- (char)_toolbarIsShown;
-- (char)_toolbarIsHidden;
-- (void)_showToolbarWithAnimation:(char)fp8;
-- (void)_hideToolbarWithAnimation:(char)fp8;
-- (float)_distanceFromToolbarBaseToTitlebar;
-- (int)_shadowType;
-- (unsigned int)_shadowFlags;
-- (void)_setShadowParameters;
-- (void)_drawFrameShadowAndFlushContext:fp8;
-- (void)setUpGState;
-- (void)adjustHalftonePhase;
-- (void)systemColorsDidChange:fp8;
-- frameColor;
-- contentFill;
-- (void)tabViewAdded;
-- (void)tabViewRemoved;
-- title;
-- (void)setTitle:fp8;
-- titleCell;
-- (void)initTitleCell:fp8;
-- (void)setResizeIncrements:(struct _NSSize)fp8;
-- (struct _NSSize)resizeIncrements;
-- (void)setAspectRatio:(struct _NSSize)fp8;
-- (struct _NSSize)aspectRatio;
-- (unsigned int)styleMask;
-- representedFilename;
-- (void)setRepresentedFilename:fp8;
-- (void)setDocumentEdited:(char)fp8;
-- (void)_setFrameNeedsDisplay:(char)fp8;
-- (char)frameNeedsDisplay;
-- titleFont;
-- (struct _NSRect)_maxTitlebarTitleRect;
-- (struct _NSRect)titlebarRect;
-- (void)_setUtilityWindow:(char)fp8;
-- (void)_setNonactivatingPanel:(char)fp8;
-- (void)setIsClosable:(char)fp8;
-- (void)setIsResizable:(char)fp8;
-- closeButton;
-- minimizeButton;
-- zoomButton;
-- (struct _NSSize)miniaturizedSize;
-- (void)_clearDragMargins;
-- (void)_resetDragMargins;
-- (void)setTitle:fp8 andDefeatWrap:(char)fp12;
-- (struct _NSRect)frameRectForContentRect:(struct _NSRect)fp8 styleMask:(unsigned int)fp24;
-- (struct _NSRect)contentRectForFrameRect:(struct _NSRect)fp8 styleMask:(unsigned int)fp24;
-- (struct _NSSize)minFrameSizeForMinContentSize:(struct _NSSize)fp8 styleMask:(unsigned int)fp16;
-- (struct _NSRect)dragRectForFrameRect:(struct _NSRect)fp8;
-- (struct _NSRect)contentRect;
-- (struct _NSSize)minFrameSize;
-- (void)_recursiveDisplayRectIfNeededIgnoringOpacity:(struct _NSRect)fp8 isVisibleRect:(char)fp24 rectIsVisibleRectForView:fp28 topView:(char)fp32;
-
-@end
diff --git a/src/gui/kernel/qnsthemeframe_mac_p.h b/src/gui/kernel/qnsthemeframe_mac_p.h
deleted file mode 100644
index 2cb4916c06..0000000000
--- a/src/gui/kernel/qnsthemeframe_mac_p.h
+++ /dev/null
@@ -1,246 +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$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp
-// and many other. This header file may change from version to version
-// without notice, or even be removed.
-//
-// We mean it.
-//
-
-// Private AppKit class (dumped from classdump).
-
-#import <Cocoa/Cocoa.h>
-#import "qnstitledframe_mac_p.h"
-
-@interface NSThemeFrame : NSTitledFrame
-{
- NSButton *toolbarButton;
- int toolbarVisibleStatus;
- NSImage *showToolbarTransitionImage;
- NSSize showToolbarPreWindowSize;
- NSButton *modeButton;
- int leftGroupTrackingTagNum;
- int rightGroupTrackingTagNum;
- char mouseInsideLeftGroup;
- char mouseInsideRightGroup;
- int widgetState;
- NSString *displayName;
-}
-
-+ (void)initialize;
-+ (float)_windowBorderThickness:(unsigned int)fp8;
-+ (float)_minXWindowBorderWidth:(unsigned int)fp8;
-+ (float)_maxXWindowBorderWidth:(unsigned int)fp8;
-+ (float)_minYWindowBorderHeight:(unsigned int)fp8;
-+ (float)_windowTitlebarButtonSpacingWidth:(unsigned int)fp8;
-+ (float)_windowFileButtonSpacingWidth:(unsigned int)fp8;
-+ (float)_minXTitlebarWidgetInset:(unsigned int)fp8;
-+ (float)_maxXTitlebarWidgetInset:(unsigned int)fp8;
-+ (float)minFrameWidthWithTitle:fp8 styleMask:(unsigned int)fp12;
-+ (float)_windowSideTitlebarTitleMinWidth:(unsigned int)fp8;
-+ (float)_windowTitlebarTitleMinHeight:(unsigned int)fp8;
-+ (float)_sideTitlebarWidth:(unsigned int)fp8;
-+ (float)_titlebarHeight:(unsigned int)fp8;
-+ (float)_resizeHeight:(unsigned int)fp8;
-+ (char)_resizeFromEdge;
-+ (struct _NSSize)sizeOfTitlebarButtons:(unsigned int)fp8;
-+ (float)_contentToFrameMinXWidth:(unsigned int)fp8;
-+ (float)_contentToFrameMaxXWidth:(unsigned int)fp8;
-+ (float)_contentToFrameMinYHeight:(unsigned int)fp8;
-+ (float)_contentToFrameMaxYHeight:(unsigned int)fp8;
-+ (unsigned int)_validateStyleMask:(unsigned int)fp8;
-- (struct _NSSize)_topCornerSize;
-- (struct _NSSize)_bottomCornerSize;
-- (void *)_createWindowOpaqueShape;
-- (void)shapeWindow;
-- (void)_recursiveDisplayRectIfNeededIgnoringOpacity:(NSRect)fp8 isVisibleRect:(char)fp24 rectIsVisibleRectForView:fp28 topView:(char)fp32;
-- (void *)_regionForOpaqueDescendants:(NSRect)fp8 forMove:(char)fp24;
-- (void)_drawFrameInterior:(NSRect *)fp8 clip:(NSRect)fp12;
-- (void)_setTextShadow:(char)fp8;
-- (void)_drawTitleBar:(NSRect)fp8;
-- (void)_drawResizeIndicators:(NSRect)fp8;
-- (void)_drawFrameRects:(NSRect)fp8;
-- (void)drawFrame:(NSRect)fp8;
-- contentFill;
-- (void)viewDidEndLiveResize;
-- (float)contentAlpha;
-- (void)setThemeFrameWidgetState:(int)fp8;
-- (char)constrainResizeEdge:(int *)fp8 withDelta:(struct _NSSize)fp12 elapsedTime:(float)fp20;
-- (void)addFileButton:fp8;
-- (void)_updateButtons;
-- (void)_updateButtonState;
-- newCloseButton;
-- newZoomButton;
-- newMiniaturizeButton;
-- newToolbarButton;
-- newFileButton;
-- (void)_resetTitleBarButtons;
-- (void)setDocumentEdited:(char)fp8;
-- toolbarButton;
-- modeButton;
-- initWithFrame:(NSRect)fp8 styleMask:(unsigned int)fp24 owner:fp28;
-- (void)dealloc;
-- (void)setFrameSize:(struct _NSSize)fp8;
-- (char)_canHaveToolbar;
-- (char)_toolbarIsInTransition;
-- (char)_toolbarIsShown;
-- (char)_toolbarIsHidden;
-- _toolbarView;
-- _toolbar;
-- (float)_distanceFromToolbarBaseToTitlebar;
-- (unsigned int)_shadowFlags;
-- (NSRect)frameRectForContentRect:(NSRect)fp8 styleMask:(unsigned int)fp24;
-- (NSRect)contentRectForFrameRect:(NSRect)fp8 styleMask:(unsigned int)fp24;
-- (struct _NSSize)minFrameSizeForMinContentSize:(struct _NSSize)fp8 styleMask:(unsigned int)fp16;
-- (NSRect)contentRect;
-- (NSRect)_contentRectExcludingToolbar;
-- (NSRect)_contentRectIncludingToolbarAtHome;
-- (void)_setToolbarShowHideResizeWeightingOptimizationOn:(char)fp8;
-- (char)_usingToolbarShowHideWeightingOptimization;
-- (void)handleSetFrameCommonRedisplay;
-- (void)_startLiveResizeAsTopLevel;
-- (void)_endLiveResizeAsTopLevel;
-- (void)_growContentReshapeContentAndToolbarView:(int)fp8 animate:(char)fp12;
-- (char)_growWindowReshapeContentAndToolbarView:(int)fp8 animate:(char)fp12;
-- (void)_reshapeContentAndToolbarView:(int)fp8 resizeWindow:(char)fp12 animate:(char)fp16;
-- (void)_toolbarFrameSizeChanged:fp8 oldSize:(struct _NSSize)fp12;
-- (void)_syncToolbarPosition;
-- (void)_showHideToolbar:(int)fp8 resizeWindow:(char)fp12 animate:(char)fp16;
-- (void)_showToolbarWithAnimation:(char)fp8;
-- (void)_hideToolbarWithAnimation:(char)fp8;
-- (void)_drawToolbarTransitionIfNecessary;
-- (void)drawRect:(NSRect)fp8;
-- (void)resetCursorRects;
-- (char)shouldBeTreatedAsInkEvent:fp8;
-- (char)_shouldBeTreatedAsInkEventInInactiveWindow:fp8;
-//- hitTest:(struct _NSPoint)fp8; // collides with hittest in qcocoasharedwindowmethods_mac_p.h
-- (NSRect)_leftGroupRect;
-- (NSRect)_rightGroupRect;
-- (void)_updateWidgets;
-- (void)_updateMouseTracking;
-- (void)mouseEntered:fp8;
-- (void)mouseExited:fp8;
-- (void)_setMouseEnteredGroup:(char)fp8 entered:(char)fp12;
-- (char)_mouseInGroup:fp8;
-- (struct _NSSize)miniaturizedSize;
-- (float)_minXTitlebarDecorationMinWidth;
-- (float)_maxXTitlebarDecorationMinWidth;
-- (struct _NSSize)minFrameSize;
-- (float)_windowBorderThickness;
-- (float)_windowTitlebarXResizeBorderThickness;
-- (float)_windowTitlebarYResizeBorderThickness;
-- (float)_windowResizeBorderThickness;
-- (float)_minXWindowBorderWidth;
-- (float)_maxXWindowBorderWidth;
-- (float)_minYWindowBorderHeight;
-- (float)_maxYWindowBorderHeight;
-- (float)_minYTitlebarButtonsOffset;
-- (float)_minYTitlebarTitleOffset;
-- (float)_sideTitlebarWidth;
-- (float)_titlebarHeight;
-- (NSRect)_titlebarTitleRect;
-- (NSRect)titlebarRect;
-- (float)_windowTitlebarTitleMinHeight;
-- (struct _NSSize)_sizeOfTitlebarFileButton;
-- (struct _NSSize)sizeOfTitlebarToolbarButton;
-- (float)_windowTitlebarButtonSpacingWidth;
-- (float)_windowFileButtonSpacingWidth;
-- (float)_minXTitlebarWidgetInset;
-- (float)_maxXTitlebarWidgetInset;
-- (float)_minXTitlebarButtonsWidth;
-- (float)_maxXTitlebarButtonsWidth;
-- (struct _NSPoint)_closeButtonOrigin;
-- (struct _NSPoint)_zoomButtonOrigin;
-- (struct _NSPoint)_collapseButtonOrigin;
-- (struct _NSPoint)_toolbarButtonOrigin;
-- (struct _NSPoint)_fileButtonOrigin;
-- (void)_tileTitlebar;
-- (NSRect)_commandPopupRect;
-- (void)_resetDragMargins;
-- (float)_maxYTitlebarDragHeight;
-- (float)_minXTitlebarDragWidth;
-- (float)_maxXTitlebarDragWidth;
-- (float)_contentToFrameMinXWidth;
-- (float)_contentToFrameMaxXWidth;
-- (float)_contentToFrameMinYHeight;
-- (float)_contentToFrameMaxYHeight;
-- (float)_windowResizeCornerThickness;
-- (NSRect)_minYResizeRect;
-- (NSRect)_minYminXResizeRect;
-- (NSRect)_minYmaxXResizeRect;
-- (NSRect)_minXResizeRect;
-- (NSRect)_minXminYResizeRect;
-- (NSRect)_minXmaxYResizeRect;
-- (NSRect)_maxYResizeRect;
-- (NSRect)_maxYminXResizeRect;
-- (NSRect)_maxYmaxXResizeRect;
-- (NSRect)_maxXResizeRect;
-- (NSRect)_maxXminYResizeRect;
-- (NSRect)_maxXmaxYResizeRect;
-- (NSRect)_minXTitlebarResizeRect;
-- (NSRect)_maxXTitlebarResizeRect;
-- (NSRect)_minXBorderRect;
-- (NSRect)_maxXBorderRect;
-- (NSRect)_maxYBorderRect;
-- (NSRect)_minYBorderRect;
-- (void)_setUtilityWindow:(char)fp8;
-- (char)_isUtility;
-- (float)_sheetHeightAdjustment;
-- (void)_setSheet:(char)fp8;
-- (char)_isSheet;
-- (char)_isResizable;
-- (char)_isClosable;
-- (char)_isMiniaturizable;
-- (char)_hasToolbar;
-- (NSRect)_growBoxRect;
-- (void)_drawGrowBoxWithClip:(NSRect)fp8;
-- (char)_inactiveButtonsNeedMask;
-- (void)mouseDown:fp8;
-- _displayName;
-- (void)_setDisplayName:fp8;
-
-@end
diff --git a/src/gui/kernel/qnstitledframe_mac_p.h b/src/gui/kernel/qnstitledframe_mac_p.h
deleted file mode 100644
index 4eb5332194..0000000000
--- a/src/gui/kernel/qnstitledframe_mac_p.h
+++ /dev/null
@@ -1,205 +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$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp
-// and many other. This header file may change from version to version
-// without notice, or even be removed.
-//
-// We mean it.
-//
-
-// Private AppKit class (dumped from classdump).
-
-#import <Cocoa/Cocoa.h>
-#import "qnsframeview_mac_p.h"
-
-
-@interface NSTitledFrame : NSFrameView
-{
- int resizeFlags;
- id fileButton; /* NSDocumentDragButton* */
- NSSize titleCellSize;
-}
-
-+ (float)_windowBorderThickness:(unsigned int)fp8;
-+ (float)_minXWindowBorderWidth:(unsigned int)fp8;
-+ (float)_maxXWindowBorderWidth:(unsigned int)fp8;
-+ (float)_minYWindowBorderHeight:(unsigned int)fp8;
-+ (char)_resizeFromEdge;
-+ (NSRect)frameRectForContentRect:(NSRect)fp8 styleMask:(unsigned int)fp24;
-+ (NSRect)contentRectForFrameRect:(NSRect)fp8 styleMask:(unsigned int)fp24;
-+ (struct _NSSize)minFrameSizeForMinContentSize:(struct _NSSize)fp8 styleMask:(unsigned int)fp16;
-+ (struct _NSSize)minContentSizeForMinFrameSize:(struct _NSSize)fp8 styleMask:(unsigned int)fp16;
-+ (float)minFrameWidthWithTitle:fp8 styleMask:(unsigned int)fp12;
-+ (struct _NSSize)_titleCellSizeForTitle:fp8 styleMask:(unsigned int)fp12;
-+ (float)_titleCellHeight:(unsigned int)fp8;
-+ (float)_windowTitlebarTitleMinHeight:(unsigned int)fp8;
-+ (float)_titlebarHeight:(unsigned int)fp8;
-+ (struct _NSSize)sizeOfTitlebarButtons:(unsigned int)fp8;
-+ (float)windowTitlebarLinesSpacingWidth:(unsigned int)fp8;
-+ (float)windowTitlebarTitleLinesSpacingWidth:(unsigned int)fp8;
-+ (float)_contentToFrameMinXWidth:(unsigned int)fp8;
-+ (float)_contentToFrameMaxXWidth:(unsigned int)fp8;
-+ (float)_contentToFrameMinYHeight:(unsigned int)fp8;
-+ (float)_contentToFrameMaxYHeight:(unsigned int)fp8;
-- initWithFrame:(NSRect)fp8 styleMask:(unsigned int)fp24 owner:fp28;
-- (void)dealloc;
-- (void)setIsClosable:(char)fp8;
-- (void)setIsResizable:(char)fp8;
-- (void)_resetTitleFont;
-- (void)_setUtilityWindow:(char)fp8;
-- (char)isOpaque;
-- (char)worksWhenModal;
-- (void)propagateFrameDirtyRects:(NSRect)fp8;
-- (void)_showDrawRect:(NSRect)fp8;
-- (void)_drawFrameInterior:(NSRect *)fp8 clip:(NSRect)fp12;
-- (void)drawFrame:(NSRect)fp8;
-- (void)_drawFrameRects:(NSRect)fp8;
-- (void)_drawTitlebar:(NSRect)fp8;
-- (void)_drawTitlebarPattern:(int)fp8 inRect:(NSRect)fp12 clippedByRect:(NSRect)fp28 forKey:(char)fp44 alignment:(int)fp48;
-- (void)_drawTitlebarLines:(int)fp8 inRect:(NSRect)fp12 clippedByRect:(NSRect)fp28;
-- frameHighlightColor;
-- frameShadowColor;
-- (void)setFrameSize:(struct _NSSize)fp8;
-- (void)setFrameOrigin:(struct _NSPoint)fp8;
-- (void)tileAndSetWindowShape:(char)fp8;
-- (void)tile;
-- (void)_tileTitlebar;
-- (void)setTitle:fp8;
-- (char)_shouldRepresentFilename;
-- (void)setRepresentedFilename:fp8;
-- (void)_drawTitleStringIn:(NSRect)fp8 withColor:fp24;
-- titleFont;
-- (void)_drawResizeIndicators:(NSRect)fp8;
-- titleButtonOfClass:(Class)fp8;
-- initTitleButton:fp8;
-- newCloseButton;
-- newZoomButton;
-- newMiniaturizeButton;
-- newFileButton;
-- fileButton;
-- (void)_removeButtons;
-- (void)_updateButtons;
-- (char)_eventInTitlebar:fp8;
-- (char)acceptsFirstMouse:fp8;
-- (void)mouseDown:fp8;
-- (void)mouseUp:fp8;
-- (void)rightMouseDown:fp8;
-- (void)rightMouseUp:fp8;
-- (int)resizeEdgeForEvent:fp8;
-- (struct _NSSize)_resizeDeltaFromPoint:(struct _NSPoint)fp8 toEvent:fp16;
-- (NSRect)_validFrameForResizeFrame:(NSRect)fp8 fromResizeEdge:(int)fp24;
-- (NSRect)frame:(NSRect)fp8 resizedFromEdge:(int)fp24 withDelta:(struct _NSSize)fp28;
-- (char)constrainResizeEdge:(int *)fp8 withDelta:(struct _NSSize)fp12 elapsedTime:(float)fp20;
-- (void)resizeWithEvent:fp8;
-- (int)resizeFlags;
-- (void)resetCursorRects;
-- (void)setDocumentEdited:(char)fp8;
-- (struct _NSSize)miniaturizedSize;
-- (struct _NSSize)minFrameSize;
-- (float)_windowBorderThickness;
-- (float)_windowTitlebarXResizeBorderThickness;
-- (float)_windowTitlebarYResizeBorderThickness;
-- (float)_windowResizeBorderThickness;
-- (float)_minXWindowBorderWidth;
-- (float)_maxXWindowBorderWidth;
-- (float)_minYWindowBorderHeight;
-- (void)_invalidateTitleCellSize;
-- (void)_invalidateTitleCellWidth;
-- (float)_titleCellHeight;
-- (struct _NSSize)_titleCellSize;
-- (float)_titlebarHeight;
-- (NSRect)titlebarRect;
-- (NSRect)_maxTitlebarTitleRect;
-- (NSRect)_titlebarTitleRect;
-- (float)_windowTitlebarTitleMinHeight;
-- (NSRect)dragRectForFrameRect:(NSRect)fp8;
-- (struct _NSSize)sizeOfTitlebarButtons;
-- (struct _NSSize)_sizeOfTitlebarFileButton;
-- (float)_windowTitlebarButtonSpacingWidth;
-- (float)_minXTitlebarButtonsWidth;
-- (float)_maxXTitlebarButtonsWidth;
-- (int)_numberOfTitlebarLines;
-- (float)windowTitlebarLinesSpacingWidth;
-- (float)windowTitlebarTitleLinesSpacingWidth;
-- (float)_minLinesWidthWithSpace;
-- (NSRect)_minXTitlebarLinesRectWithTitleCellRect:(NSRect)fp8;
-- (NSRect)_maxXTitlebarLinesRectWithTitleCellRect:(NSRect)fp8;
-- (float)_minXTitlebarDecorationMinWidth;
-- (float)_maxXTitlebarDecorationMinWidth;
-- (struct _NSPoint)_closeButtonOrigin;
-- (struct _NSPoint)_zoomButtonOrigin;
-- (struct _NSPoint)_collapseButtonOrigin;
-- (struct _NSPoint)_fileButtonOrigin;
-- (float)_maxYTitlebarDragHeight;
-- (float)_minXTitlebarDragWidth;
-- (float)_maxXTitlebarDragWidth;
-- (float)_contentToFrameMinXWidth;
-- (float)_contentToFrameMaxXWidth;
-- (float)_contentToFrameMinYHeight;
-- (float)_contentToFrameMaxYHeight;
-- (NSRect)contentRect;
-- (float)_windowResizeCornerThickness;
-- (NSRect)_minYResizeRect;
-- (NSRect)_minYminXResizeRect;
-- (NSRect)_minYmaxXResizeRect;
-- (NSRect)_minXResizeRect;
-- (NSRect)_minXminYResizeRect;
-- (NSRect)_minXmaxYResizeRect;
-- (NSRect)_maxYResizeRect;
-- (NSRect)_maxYminXResizeRect;
-- (NSRect)_maxYmaxXResizeRect;
-- (NSRect)_maxXResizeRect;
-- (NSRect)_maxXminYResizeRect;
-- (NSRect)_maxXmaxYResizeRect;
-- (NSRect)_minXTitlebarResizeRect;
-- (NSRect)_maxXTitlebarResizeRect;
-- (NSRect)_minXBorderRect;
-- (NSRect)_maxXBorderRect;
-- (NSRect)_maxYBorderRect;
-- (NSRect)_minYBorderRect;
-
-@end
diff --git a/src/gui/kernel/qsoftkeymanager_s60.cpp b/src/gui/kernel/qsoftkeymanager_s60.cpp
deleted file mode 100644
index 79ed91af5b..0000000000
--- a/src/gui/kernel/qsoftkeymanager_s60.cpp
+++ /dev/null
@@ -1,440 +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 "qevent.h"
-#include "qbitmap.h"
-#include "qstyle.h"
-#include "qmenubar.h"
-#include "private/qt_s60_p.h"
-#include "private/qmenu_p.h"
-#include "private/qaction_p.h"
-#include "private/qsoftkeymanager_p.h"
-#include "private/qsoftkeymanager_s60_p.h"
-#include "private/qobject_p.h"
-#include <eiksoftkeyimage.h>
-#include <eikcmbut.h>
-
-#ifndef QT_NO_SOFTKEYMANAGER
-QT_BEGIN_NAMESPACE
-
-const int S60_COMMAND_START = 6000;
-const int LSK_POSITION = 0;
-const int MSK_POSITION = 3;
-const int RSK_POSITION = 2;
-
-QSoftKeyManagerPrivateS60::QSoftKeyManagerPrivateS60() : cbaHasImage(4) // 4 since MSK position index is 3
-{
- cachedCbaIconSize[0] = QSize(0,0);
- cachedCbaIconSize[1] = QSize(0,0);
- cachedCbaIconSize[2] = QSize(0,0);
- cachedCbaIconSize[3] = QSize(0,0);
-}
-
-bool QSoftKeyManagerPrivateS60::skipCbaUpdate()
-{
- // Lets not update softkeys if
- // 1. We don't have application panes, i.e. cba
- // 2. Our CBA is not active, i.e. S60 native dialog or menu with custom CBA is shown
- // 2.1. Except if thre is no current CBA at all and WindowSoftkeysRespondHint is set
-
- // Note: Cannot use IsDisplayingMenuOrDialog since CBA update can be triggered before
- // menu/dialog CBA is actually displayed i.e. it is being costructed.
- CEikButtonGroupContainer *appUiCba = S60->buttonGroupContainer();
- if (!appUiCba)
- return true;
- // CEikButtonGroupContainer::Current returns 0 if CBA is not visible at all
- CEikButtonGroupContainer *currentCba = CEikButtonGroupContainer::Current();
- // Check if softkey need to be update even they are not visible
- bool cbaRespondsWhenInvisible = false;
- QWidget *window = QApplication::activeWindow();
- if (window && (window->windowFlags() & Qt::WindowSoftkeysRespondHint))
- cbaRespondsWhenInvisible = true;
-
- if (QApplication::testAttribute(Qt::AA_S60DontConstructApplicationPanes)
- || (appUiCba != currentCba && !cbaRespondsWhenInvisible)) {
- return true;
- }
- return false;
-}
-
-void QSoftKeyManagerPrivateS60::ensureCbaVisibilityAndResponsiviness(CEikButtonGroupContainer &cba)
-{
- RDrawableWindow *cbaWindow = cba.DrawableWindow();
- Q_ASSERT_X(cbaWindow, Q_FUNC_INFO, "Native CBA does not have window!");
- // Make sure CBA is visible, i.e. CBA window is on top
- cbaWindow->SetOrdinalPosition(0);
- // Qt shares same CBA instance between top-level widgets,
- // make sure we are not faded by underlying window.
- cbaWindow->SetFaded(EFalse, RWindowTreeNode::EFadeIncludeChildren);
- // Modal dialogs capture pointer events, but shared cba instance
- // shall stay responsive. Raise pointer capture priority to keep
- // softkeys responsive in modal dialogs
- cbaWindow->SetPointerCapturePriority(1);
-}
-
-void QSoftKeyManagerPrivateS60::clearSoftkeys(CEikButtonGroupContainer &cba)
-{
-#ifdef SYMBIAN_VERSION_SYMBIAN3
- QT_TRAP_THROWING(
- //EAknSoftkeyEmpty is used, because using -1 adds softkeys without actions on Symbian3
- cba.SetCommandL(0, EAknSoftkeyEmpty, KNullDesC);
- cba.SetCommandL(2, EAknSoftkeyEmpty, KNullDesC);
- );
-#else
- QT_TRAP_THROWING(
- //Using -1 instead of EAknSoftkeyEmpty to avoid flickering.
- cba.SetCommandL(0, -1, KNullDesC);
- // TODO: Should we clear also middle SK?
- cba.SetCommandL(2, -1, KNullDesC);
- );
-#endif
- realSoftKeyActions.clear();
-}
-
-QString QSoftKeyManagerPrivateS60::softkeyText(QAction &softkeyAction)
-{
- // In S60 softkeys and menu items do not support key accelerators (i.e.
- // CTRL+X). Therefore, removing the accelerator characters from both softkey
- // and menu item texts.
- const int underlineShortCut = QApplication::style()->styleHint(QStyle::SH_UnderlineShortcut);
- QString iconText = softkeyAction.iconText();
- return underlineShortCut ? softkeyAction.text() : iconText;
-}
-
-QAction *QSoftKeyManagerPrivateS60::highestPrioritySoftkey(QAction::SoftKeyRole role)
-{
- QAction *ret = NULL;
- // Priority look up is two level
- // 1. First widget with softkeys always has highest priority
- for (int level = 0; !ret; level++) {
- // 2. Highest priority action within widget
- QList<QAction*> actions = requestedSoftKeyActions.values(level);
- if (actions.isEmpty())
- break;
- qSort(actions.begin(), actions.end(), QSoftKeyManagerPrivateS60::actionPriorityMoreThan);
- foreach (QAction *action, actions) {
- if (action->softKeyRole() == role) {
- ret = action;
- break;
- }
- }
- }
- return ret;
-}
-
-bool QSoftKeyManagerPrivateS60::actionPriorityMoreThan(const QAction *firstItem, const QAction *secondItem)
-{
- return firstItem->priority() > secondItem->priority();
-}
-
-void QSoftKeyManagerPrivateS60::setNativeSoftkey(CEikButtonGroupContainer &cba,
- TInt position, TInt command, const TDesC &text)
-{
- // Calling SetCommandL causes CBA redraw
- QT_TRAP_THROWING(cba.SetCommandL(position, command, text));
-}
-
-QPoint QSoftKeyManagerPrivateS60::softkeyIconPosition(int position, QSize sourceSize, QSize targetSize)
-{
- QPoint iconPosition(0,0);
- switch( AknLayoutUtils::CbaLocation() )
- {
- case AknLayoutUtils::EAknCbaLocationBottom:
- // RSK must be moved to right, LSK in on correct position by default
- if (position == RSK_POSITION)
- iconPosition.setX(targetSize.width() - sourceSize.width());
- break;
- case AknLayoutUtils::EAknCbaLocationRight:
- case AknLayoutUtils::EAknCbaLocationLeft:
- // Already in correct position
- default:
- break;
- }
-
- // Align horizontally to center
- iconPosition.setY((targetSize.height() - sourceSize.height()) >> 1);
- return iconPosition;
-}
-
-QPixmap QSoftKeyManagerPrivateS60::prepareSoftkeyPixmap(QPixmap src, int position, QSize targetSize)
-{
- QPixmap target(targetSize);
- target.fill(Qt::transparent);
- QPainter p;
- p.begin(&target);
- p.drawPixmap(softkeyIconPosition(position, src.size(), targetSize), src);
- p.end();
- return target;
-}
-
-bool QSoftKeyManagerPrivateS60::isOrientationLandscape()
-{
- // Hard to believe that there is no public API in S60 to
- // get current orientation. This workaround works with currently supported resolutions
- return S60->screenHeightInPixels < S60->screenWidthInPixels;
-}
-
-QSize QSoftKeyManagerPrivateS60::cbaIconSize(CEikButtonGroupContainer *cba, int position)
-{
-
- int index = position;
- index += isOrientationLandscape() ? 0 : 1;
- if(cachedCbaIconSize[index].isNull()) {
- // Only way I figured out to get CBA icon size without RnD SDK, was
- // to set some dummy icon to CBA first and then ask CBA button CCoeControl::Size()
- // The returned value is cached to avoid unnecessary icon setting every time.
- const bool left = (position == LSK_POSITION);
- if(position == LSK_POSITION || position == RSK_POSITION) {
- CEikImage* tmpImage = NULL;
- QT_TRAP_THROWING(tmpImage = new (ELeave) CEikImage);
- EikSoftkeyImage::SetImage(cba, *tmpImage, left); // Takes myimage ownership
- int command = S60_COMMAND_START + position;
- setNativeSoftkey(*cba, position, command, KNullDesC());
- cachedCbaIconSize[index] = qt_TSize2QSize(cba->ControlOrNull(command)->Size());
- EikSoftkeyImage::SetLabel(cba, left);
-
- if(cachedCbaIconSize[index] == QSize(138,72)) {
- // Hack for S60 5.0 (5800) landscape orientation, which return wrong icon size
- cachedCbaIconSize[index] = QSize(60,60);
- }
- }
- }
-
- return cachedCbaIconSize[index];
-}
-
-bool QSoftKeyManagerPrivateS60::setSoftkeyImage(CEikButtonGroupContainer *cba,
- QAction &action, int position)
-{
- bool ret = false;
-
- const bool left = (position == LSK_POSITION);
- if(position == LSK_POSITION || position == RSK_POSITION) {
- QIcon icon = action.icon();
- if (!icon.isNull()) {
- // Get size of CBA icon area based on button position and orientation
- QSize requiredIconSize = cbaIconSize(cba, position);
- // Get pixmap out of icon based on preferred size, the aspect ratio is kept
- QPixmap pmWihtAspectRatio = icon.pixmap(requiredIconSize);
- // Native softkeys require that pixmap size is exactly the same as requiredIconSize
- // prepareSoftkeyPixmap creates a new pixmap with requiredIconSize and blits the 'pmWihtAspectRatio'
- // to correct location of it
- QPixmap softkeyPixmap = prepareSoftkeyPixmap(pmWihtAspectRatio, position, requiredIconSize);
-
- QPixmap softkeyAlpha = softkeyPixmap.alphaChannel();
- // Alpha channel in 5.1 and older devices need to be inverted
- // TODO: Switch to use toSymbianCFbsBitmap with invert when available
- if(QSysInfo::s60Version() <= QSysInfo::SV_S60_5_1) {
- QImage alphaImage = softkeyAlpha.toImage();
- alphaImage.invertPixels();
- softkeyAlpha = QPixmap::fromImage(alphaImage);
- }
-
- CFbsBitmap* nBitmap = softkeyPixmap.toSymbianCFbsBitmap();
- CFbsBitmap* nMask = softkeyAlpha.toSymbianCFbsBitmap();
-
- CEikImage* myimage = new (ELeave) CEikImage;
- myimage->SetPicture( nBitmap, nMask ); // nBitmap and nMask ownership transferred
-
- EikSoftkeyImage::SetImage(cba, *myimage, left); // Takes myimage ownership
- cbaHasImage[position] = true;
- ret = true;
- } else {
- // Restore softkey to text based
- if (cbaHasImage[position]) {
- EikSoftkeyImage::SetLabel(cba, left);
- cbaHasImage[position] = false;
- }
- }
- }
- return ret;
-}
-
-bool QSoftKeyManagerPrivateS60::setSoftkey(CEikButtonGroupContainer &cba,
- QAction::SoftKeyRole role, int position)
-{
- QAction *action = highestPrioritySoftkey(role);
- if (action) {
- setSoftkeyImage(&cba, *action, position);
- QString text = softkeyText(*action);
- TPtrC nativeText = qt_QString2TPtrC(text);
- int command = S60_COMMAND_START + position;
-#ifdef SYMBIAN_VERSION_SYMBIAN3
- if (softKeyCommandActions.contains(action))
- command = softKeyCommandActions.value(action);
-#endif
- setNativeSoftkey(cba, position, command, nativeText);
- const bool dimmed = !action->isEnabled() && !QSoftKeyManager::isForceEnabledInSofkeys(action);
- cba.DimCommand(command, dimmed);
- realSoftKeyActions.insert(command, action);
- return true;
- }
- return false;
-}
-
-bool QSoftKeyManagerPrivateS60::setLeftSoftkey(CEikButtonGroupContainer &cba)
-{
- return setSoftkey(cba, QAction::PositiveSoftKey, LSK_POSITION);
-}
-
-bool QSoftKeyManagerPrivateS60::setMiddleSoftkey(CEikButtonGroupContainer &cba)
-{
- // Note: In order to get MSK working, application has to have EAknEnableMSK flag set
- // Currently it is not possible very easily)
- // For more information see: http://wiki.forum.nokia.com/index.php/Middle_softkey_usage
- return setSoftkey(cba, QAction::SelectSoftKey, MSK_POSITION);
-}
-
-bool QSoftKeyManagerPrivateS60::setRightSoftkey(CEikButtonGroupContainer &cba)
-{
- if (!setSoftkey(cba, QAction::NegativeSoftKey, RSK_POSITION)) {
- const Qt::WindowType windowType = initialSoftKeySource
- ? initialSoftKeySource->window()->windowType() : Qt::Window;
- if (windowType != Qt::Dialog && windowType != Qt::Popup) {
- QString text(QSoftKeyManager::tr("Exit"));
- TPtrC nativeText = qt_QString2TPtrC(text);
- if (cbaHasImage[RSK_POSITION]) {
- EikSoftkeyImage::SetLabel(&cba, false);
- cbaHasImage[RSK_POSITION] = false;
- }
- setNativeSoftkey(cba, RSK_POSITION, EAknSoftkeyExit, nativeText);
- cba.DimCommand(EAknSoftkeyExit, false);
- return true;
- }
- }
- return false;
-}
-
-void QSoftKeyManagerPrivateS60::setSoftkeys(CEikButtonGroupContainer &cba)
-{
- int requestedSoftkeyCount = requestedSoftKeyActions.count();
- const int maxSoftkeyCount = 2; // TODO: differs based on orientation ans S60 versions (some have MSK)
- if (requestedSoftkeyCount > maxSoftkeyCount) {
- // We have more softkeys than available slots
- // Put highest priority negative action to RSK and Options menu with rest of softkey actions to LSK
- // TODO: Build menu
- setLeftSoftkey(cba);
- if(AknLayoutUtils::MSKEnabled())
- setMiddleSoftkey(cba);
- setRightSoftkey(cba);
- } else {
- // We have less softkeys than available slots
- // Put softkeys to request slots based on role
- setLeftSoftkey(cba);
- if(AknLayoutUtils::MSKEnabled())
- setMiddleSoftkey(cba);
- setRightSoftkey(cba);
- }
-}
-
-void QSoftKeyManagerPrivateS60::updateSoftKeys_sys()
-{
- if (skipCbaUpdate())
- return;
-
- CEikButtonGroupContainer *nativeContainer = S60->buttonGroupContainer();
- Q_ASSERT_X(nativeContainer, Q_FUNC_INFO, "Native CBA does not exist!");
- ensureCbaVisibilityAndResponsiviness(*nativeContainer);
- clearSoftkeys(*nativeContainer);
- setSoftkeys(*nativeContainer);
-
- nativeContainer->DrawDeferred(); // 3.1 needs an extra invitation
-}
-
-static void resetMenuBeingConstructed(TAny* /*aAny*/)
-{
- S60->menuBeingConstructed = false;
-}
-
-void QSoftKeyManagerPrivateS60::tryDisplayMenuBarL()
-{
- CleanupStack::PushL(TCleanupItem(resetMenuBeingConstructed, NULL));
- S60->menuBeingConstructed = true;
- S60->menuBar()->TryDisplayMenuBarL();
- CleanupStack::PopAndDestroy(); // Reset menuBeingConstructed to false in all cases
-}
-
-bool QSoftKeyManagerPrivateS60::handleCommand(int command)
-{
- QAction *action = realSoftKeyActions.value(command);
- if (action) {
- bool property = QActionPrivate::get(action)->menuActionSoftkeys;
- if (property) {
- QT_TRAP_THROWING(tryDisplayMenuBarL());
- } else if (action->menu()) {
- // TODO: This is hack, in order to use exising QMenuBar implementation for Symbian
- // menubar needs to have widget to which it is associated. Since we want to associate
- // menubar to action (which is inherited from QObject), we create and associate QWidget
- // to action and pass that for QMenuBar. This associates the menubar to action, and we
- // can have own menubar for each action.
- QWidget *actionContainer = action->property("_q_action_widget").value<QWidget*>();
- if(!actionContainer) {
- actionContainer = new QWidget(action->parentWidget());
- QMenuBar *menuBar = new QMenuBar(actionContainer);
- foreach(QAction *menuAction, action->menu()->actions()) {
- QMenu *menu = menuAction->menu();
- if(menu)
- menuBar->addMenu(menu);
- else
- menuBar->addAction(menuAction);
- }
- QVariant v;
- v.setValue(actionContainer);
- action->setProperty("_q_action_widget", v);
- }
- qt_symbian_next_menu_from_action(actionContainer);
- QT_TRAP_THROWING(tryDisplayMenuBarL());
- }
-
- Q_ASSERT(action->softKeyRole() != QAction::NoSoftKey);
- QWidget *actionParent = action->parentWidget();
- Q_ASSERT_X(actionParent, Q_FUNC_INFO, "No parent set for softkey action!");
- if (actionParent->isEnabled()) {
- action->activate(QAction::Trigger);
- return true;
- }
- }
- return false;
-}
-
-QT_END_NAMESPACE
-#endif //QT_NO_SOFTKEYMANAGER
diff --git a/src/gui/kernel/qsoftkeymanager_s60_p.h b/src/gui/kernel/qsoftkeymanager_s60_p.h
deleted file mode 100644
index 9cb3787cb8..0000000000
--- a/src/gui/kernel/qsoftkeymanager_s60_p.h
+++ /dev/null
@@ -1,113 +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 QSOFTKEYMANAGER_S60_P_H
-#define QSOFTKEYMANAGER_S60_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 "qbitarray.h"
-#include "private/qobject_p.h"
-#include "private/qsoftkeymanager_common_p.h"
-
-QT_BEGIN_HEADER
-
-#ifndef QT_NO_SOFTKEYMANAGER
-
-QT_BEGIN_NAMESPACE
-
-class CEikButtonGroupContainer;
-class QAction;
-
-class QSoftKeyManagerPrivateS60 : public QSoftKeyManagerPrivate
-{
- Q_DECLARE_PUBLIC(QSoftKeyManager)
-
-public:
- QSoftKeyManagerPrivateS60();
-
-public:
- void updateSoftKeys_sys();
- bool handleCommand(int command);
-
-private:
- void tryDisplayMenuBarL();
- bool skipCbaUpdate();
- void ensureCbaVisibilityAndResponsiviness(CEikButtonGroupContainer &cba);
- void clearSoftkeys(CEikButtonGroupContainer &cba);
- QString softkeyText(QAction &softkeyAction);
- QAction *highestPrioritySoftkey(QAction::SoftKeyRole role);
- static bool actionPriorityMoreThan(const QAction* item1, const QAction* item2);
- void setNativeSoftkey(CEikButtonGroupContainer &cba, TInt position, TInt command, const TDesC& text);
- QPoint softkeyIconPosition(int position, QSize sourceSize, QSize targetSize);
- QPixmap prepareSoftkeyPixmap(QPixmap src, int position, QSize targetSize);
- bool isOrientationLandscape();
- QSize cbaIconSize(CEikButtonGroupContainer *cba, int position);
- bool setSoftkeyImage(CEikButtonGroupContainer *cba, QAction &action, int position);
- bool setSoftkey(CEikButtonGroupContainer &cba, QAction::SoftKeyRole role, int position);
- bool setLeftSoftkey(CEikButtonGroupContainer &cba);
- bool setMiddleSoftkey(CEikButtonGroupContainer &cba);
- bool setRightSoftkey(CEikButtonGroupContainer &cba);
- void setSoftkeys(CEikButtonGroupContainer &cba);
-
-private:
- QHash<int, QAction*> realSoftKeyActions;
- QSize cachedCbaIconSize[4];
- QBitArray cbaHasImage;
-};
-
-
-QT_END_NAMESPACE
-
-#endif //QT_NO_SOFTKEYMANAGER
-
-QT_END_HEADER
-
-#endif // QSOFTKEYMANAGER_S60_P_H
diff --git a/src/gui/kernel/qsound_mac.mm b/src/gui/kernel/qsound_mac.mm
deleted file mode 100644
index 5a9af135b0..0000000000
--- a/src/gui/kernel/qsound_mac.mm
+++ /dev/null
@@ -1,190 +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 "qsound.h"
-#include "qsound_p.h"
-#include <private/qt_mac_p.h>
-#include <qhash.h>
-#include <qdebug.h>
-#import <AppKit/AppKit.h>
-
-#include <AppKit/NSSound.h>
-
-QT_BEGIN_NAMESPACE
-
-void qt_mac_beep()
-{
- NSBeep();
-}
-
-QT_END_NAMESPACE
-
-#ifndef QT_NO_SOUND
-
-QT_BEGIN_NAMESPACE
-
-typedef QHash<QSound *, NSSound const *> Sounds;
-static Sounds sounds;
-
-class QAuServerMac : public QAuServer
-{
- Q_OBJECT
-public:
- QAuServerMac(QObject* parent) : QAuServer(parent) { }
- void play(const QString& filename);
- void play(QSound *s);
- void stop(QSound*);
- bool okay() { return true; }
- using QAuServer::decLoop; // promote to public.
-protected:
- NSSound *createNSSound(const QString &filename, QSound *qSound);
-};
-
-QT_END_NAMESPACE
-
-#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5
-@protocol NSSoundDelegate <NSObject>
--(void)sound:(NSSound *)sound didFinishPlaying:(BOOL)aBool;
-@end
-#endif
-
-QT_USE_NAMESPACE
-
-@interface QT_MANGLE_NAMESPACE(QMacSoundDelegate) : NSObject<NSSoundDelegate> {
- QSound *qSound; // may be null.
- QAuServerMac* server;
-}
--(id)initWithQSound:(QSound*)sound:(QAuServerMac*)server;
-@end
-
-@implementation QT_MANGLE_NAMESPACE(QMacSoundDelegate)
--(id)initWithQSound:(QSound*)s:(QAuServerMac*)serv {
- self = [super init];
- if(self) {
- qSound = s;
- server = serv;
- }
- return self;
-}
-
-// Delegate function that gets called each time a sound finishes.
--(void)sound:(NSSound *)sound didFinishPlaying:(BOOL)finishedOk
-{
- // qSound is null if this sound was started by play(QString),
- // in which case there is no corresponding QSound object.
- if (qSound == 0) {
- [sound release];
- [self release];
- return;
- }
-
- // finishedOk is false if the sound cold not be played or
- // if it was interrupted by stop().
- if (finishedOk == false) {
- sounds.remove(qSound);
- [sound release];
- [self release];
- return;
- }
-
- // Check if the sound should loop "forever" (until stop).
- if (qSound->loops() == -1) {
- [sound play];
- return;
- }
-
- const int remainingIterations = server->decLoop(qSound);
- if (remainingIterations > 0) {
- [sound play];
- } else {
- sounds.remove(qSound);
- [sound release];
- [self release];
- }
-}
-@end
-
-QT_BEGIN_NAMESPACE
-
-void QAuServerMac::play(const QString &fileName)
-{
- QMacCocoaAutoReleasePool pool;
- NSSound * const nsSound = createNSSound(fileName, 0);
- [nsSound play];
-}
-
-void QAuServerMac::play(QSound *qSound)
-{
- QMacCocoaAutoReleasePool pool;
- NSSound * const nsSound = createNSSound(qSound->fileName(), qSound);
- [nsSound play];
- // Keep track of the nsSound object so we can find it again in stop().
- sounds[qSound] = nsSound;
-}
-
-void QAuServerMac::stop(QSound *qSound)
-{
- Sounds::const_iterator it = sounds.constFind(qSound);
- if (it != sounds.constEnd())
- [*it stop];
-}
-
-// Creates an NSSound object and installs a "sound finished" callack delegate on it.
-NSSound *QAuServerMac::createNSSound(const QString &fileName, QSound *qSound)
-{
- NSString *nsFileName = const_cast<NSString *>(reinterpret_cast<const NSString *>(QCFString::toCFStringRef(fileName)));
- NSSound * const nsSound = [[NSSound alloc] initWithContentsOfFile: nsFileName byReference:YES];
- QT_MANGLE_NAMESPACE(QMacSoundDelegate) * const delegate = [[QT_MANGLE_NAMESPACE(QMacSoundDelegate) alloc] initWithQSound:qSound:this];
- [nsSound setDelegate:delegate];
- [nsFileName release];
- return nsSound;
-}
-
-QAuServer* qt_new_audio_server()
-{
- return new QAuServerMac(qApp);
-}
-
-QT_END_NAMESPACE
-
-#include "qsound_mac.moc"
-
-#endif // QT_NO_SOUND
diff --git a/src/gui/kernel/qsound_s60.cpp b/src/gui/kernel/qsound_s60.cpp
deleted file mode 100644
index acc5c2a56f..0000000000
--- a/src/gui/kernel/qsound_s60.cpp
+++ /dev/null
@@ -1,224 +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 QT_NO_SOUND
-
-#include "qdir.h"
-#include "qapplication.h"
-#include "qsound.h"
-#include "qsound_p.h"
-#include "qfileinfo.h"
-#include <private/qcore_symbian_p.h>
-
-#include <e32std.h>
-#include <mdaaudiosampleplayer.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAuServerS60;
-
-class QAuBucketS60 : public QAuBucket, public MMdaAudioPlayerCallback
-{
-public:
- QAuBucketS60(QAuServerS60 *server, QSound *sound);
- ~QAuBucketS60();
-
- void play();
- void stop();
-
- inline QSound *sound() const { return m_sound; }
-
-public: // from MMdaAudioPlayerCallback
- void MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& aDuration);
- void MapcPlayComplete(TInt aError);
-
-private:
- QSound *m_sound;
- QAuServerS60 *m_server;
- bool m_prepared;
- bool m_playCalled;
- CMdaAudioPlayerUtility *m_playUtility;
-};
-
-
-class QAuServerS60 : public QAuServer
-{
-public:
- QAuServerS60(QObject *parent);
-
- void init(QSound *s)
- {
- QAuBucketS60 *bucket = new QAuBucketS60(this, s);
- setBucket(s, bucket);
- }
-
- void play(QSound *s)
- {
- bucket(s)->play();
- }
-
- void stop(QSound *s)
- {
- bucket(s)->stop();
- }
-
- bool okay() { return true; }
-
- void play(const QString& filename);
-
-protected:
- void playCompleted(QAuBucketS60 *bucket, int error);
-
-protected:
- QAuBucketS60 *bucket(QSound *s)
- {
- return (QAuBucketS60 *)QAuServer::bucket( s );
- }
-
- friend class QAuBucketS60;
-
- // static QSound::play(filename) cannot be stopped, meaning that playCompleted
- // will get always called and QSound gets removed form this list.
- QList<QSound *> staticPlayingSounds;
-};
-
-QAuServerS60::QAuServerS60(QObject *parent) :
- QAuServer(parent)
-{
- setObjectName(QLatin1String("QAuServerS60"));
-}
-
-void QAuServerS60::play(const QString& filename)
-{
- QSound *s = new QSound(filename);
- staticPlayingSounds.append(s);
- play(s);
-}
-
-void QAuServerS60::playCompleted(QAuBucketS60 *bucket, int error)
-{
- QSound *sound = bucket->sound();
- if (!error) {
- // We need to handle repeats by ourselves, since with Symbian API we don't
- // know how many loops have been played when user asks it
- if (decLoop(sound)) {
- play(sound);
- } else {
- if (staticPlayingSounds.removeAll(sound))
- delete sound;
- }
- } else {
- // We don't have a way to inform about errors -> just decrement loops
- // in order that QSound::isFinished will return true;
- while (decLoop(sound) > 0) {}
- if (staticPlayingSounds.removeAll(sound))
- delete sound;
- }
-}
-
-QAuServer *qt_new_audio_server()
-{
- return new QAuServerS60(qApp);
-}
-
-QAuBucketS60::QAuBucketS60(QAuServerS60 *server, QSound *sound)
- : m_sound(sound), m_server(server), m_prepared(false), m_playCalled(false)
-{
- QString filepath = QFileInfo(m_sound->fileName()).absoluteFilePath();
- filepath = QDir::toNativeSeparators(filepath);
- TPtrC filepathPtr(qt_QString2TPtrC(filepath));
- TRAPD(err, m_playUtility = CMdaAudioPlayerUtility::NewL(*this);
- m_playUtility->OpenFileL(filepathPtr));
- if (err) {
- m_server->playCompleted(this, err);
- }
-}
-
-void QAuBucketS60::play()
-{
- if (m_prepared) {
- // OpenFileL call is completed we can start playing immediately
- m_playUtility->Play();
- } else {
- m_playCalled = true;
- }
-
-}
-
-void QAuBucketS60::stop()
-{
- m_playCalled = false;
- m_playUtility->Stop();
-}
-
-void QAuBucketS60::MapcPlayComplete(TInt aError)
-{
- m_server->playCompleted(this, aError);
-}
-
-void QAuBucketS60::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
-{
- if (aError) {
- m_server->playCompleted(this, aError);
- } else {
- m_prepared = true;
- if (m_playCalled){
- play();
- }
- }
-}
-
-QAuBucketS60::~QAuBucketS60()
-{
- if (m_playUtility){
- m_playUtility->Stop();
- m_playUtility->Close();
- }
-
- delete m_playUtility;
-}
-
-
-#endif // QT_NO_SOUND
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qsound_win.cpp b/src/gui/kernel/qsound_win.cpp
deleted file mode 100644
index c11482d608..0000000000
--- a/src/gui/kernel/qsound_win.cpp
+++ /dev/null
@@ -1,205 +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 "qsound.h"
-
-#ifndef QT_NO_SOUND
-
-#include "qapplication.h"
-#include "qapplication_p.h"
-#include <qfile.h>
-#include "qpointer.h"
-#include "qsound_p.h"
-
-#include <qt_windows.h>
-
-QT_BEGIN_NAMESPACE
-
-class QAuServerWindows : public QAuServer {
- Q_OBJECT
-
-public:
- QAuServerWindows(QObject* parent);
- ~QAuServerWindows();
-
- void playHelper(const QString &filename, int loop, QSound *snd);
- void play(const QString& filename, int loop);
- void play(QSound*);
-
- void stop(QSound*);
- bool okay();
-
- int decLoop(QSound *snd) { return QAuServer::decLoop(snd); }
-
- HANDLE current;
- HANDLE mutex;
- HANDLE event;
-};
-
-QAuServerWindows::QAuServerWindows(QObject* parent) :
- QAuServer(parent), current(0)
-{
- mutex = CreateMutex(0, 0, 0);
- event = CreateEvent(0, FALSE, FALSE, 0);
-}
-
-QAuServerWindows::~QAuServerWindows()
-{
- HANDLE mtx = mutex;
- WaitForSingleObject(mtx, INFINITE);
- mutex = 0;
-
- ReleaseMutex(mtx);
- CloseHandle(mtx);
- CloseHandle(event);
-}
-
-struct SoundInfo
-{
- SoundInfo(const QString &fn, int lp, QSound *snd, QAuServerWindows *srv)
- : sound(snd), server(srv), filename(fn), loops(lp)
- {
- }
-
- QSound *sound;
- QAuServerWindows *server;
- QString filename;
- int loops;
-};
-
-DWORD WINAPI SoundPlayProc(LPVOID param)
-{
- SoundInfo *info = (SoundInfo*)param;
-
- // copy data before waking up GUI thread
- QAuServerWindows *server = info->server;
- QSound *sound = info->sound;
- int loops = info->loops;
- QString filename = info->filename;
- HANDLE mutex = server->mutex;
- HANDLE event = server->event;
- info = 0;
-
- // server must not be destroyed until thread finishes
- // and all other sounds have to wait
- WaitForSingleObject(mutex, INFINITE);
-
- if (loops <= 1) {
- server->current = 0;
- int flags = SND_FILENAME|SND_ASYNC;
- if (loops == -1)
- flags |= SND_LOOP;
-
- PlaySound((wchar_t*)filename.utf16(), 0, flags);
- if (sound && loops == 1)
- server->decLoop(sound);
-
- // GUI thread continues, but we are done as well.
- SetEvent(event);
- } else {
- // signal GUI thread to continue - sound might be reset!
- QPointer<QSound> guarded_sound = sound;
- SetEvent(event);
-
- for (int l = 0; l < loops && server->current; ++l) {
- PlaySound((wchar_t*)filename.utf16(), 0, SND_FILENAME | SND_SYNC);
-
- if (guarded_sound)
- server->decLoop(guarded_sound);
- }
- server->current = 0;
- }
- ReleaseMutex(mutex);
-
- return 0;
-}
-
-void QAuServerWindows::playHelper(const QString &filename, int loop, QSound *snd)
-{
- if (loop == 0)
- return;
- // busy?
- if (WaitForSingleObject(mutex, 0) == WAIT_TIMEOUT)
- return;
- ReleaseMutex(mutex);
-
- DWORD threadid = 0;
- SoundInfo info(filename, loop, snd, this);
- current = CreateThread(0, 0, SoundPlayProc, &info, 0, &threadid);
- CloseHandle(current);
-
- WaitForSingleObject(event, INFINITE);
-}
-
-void QAuServerWindows::play(const QString& filename, int loop)
-{
- playHelper(filename, loop, 0);
-}
-
-void QAuServerWindows::play(QSound* s)
-{
- playHelper(s->fileName(), s->loops(), s);
-}
-
-void QAuServerWindows::stop(QSound*)
-{
- // stop unlooped sound
- if (!current)
- PlaySound(0, 0, 0);
- // stop after loop is done
- current = 0;
-}
-
-bool QAuServerWindows::okay()
-{
- return true;
-}
-
-QAuServer* qt_new_audio_server()
-{
- return new QAuServerWindows(qApp);
-}
-
-QT_END_NAMESPACE
-
-#include "qsound_win.moc"
-
-#endif // QT_NO_SOUND
diff --git a/src/gui/kernel/qsound_x11.cpp b/src/gui/kernel/qsound_x11.cpp
deleted file mode 100644
index 12c06f0aa1..0000000000
--- a/src/gui/kernel/qsound_x11.cpp
+++ /dev/null
@@ -1,296 +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 "qsound.h"
-
-#ifndef QT_NO_SOUND
-
-#include "qhash.h"
-#include "qsocketnotifier.h"
-#include "qapplication.h"
-#include "qsound_p.h"
-
-QT_BEGIN_NAMESPACE
-
-#ifndef QT_NO_NAS
-
-QT_BEGIN_INCLUDE_NAMESPACE
-#include <audio/audiolib.h>
-#include <audio/soundlib.h>
-QT_END_INCLUDE_NAMESPACE
-
-static AuServer *nas=0;
-
-static AuBool eventPred(AuServer *, AuEvent *e, AuPointer p)
-{
- if (e && (e->type == AuEventTypeElementNotify)) {
- if (e->auelementnotify.flow == *((AuFlowID *)p))
- return true;
- }
- return false;
-}
-
-class QAuBucketNAS : public QAuBucket {
-public:
- QAuBucketNAS(AuBucketID b, AuFlowID f = 0) : id(b), flow(f), stopped(true), numplaying(0) { }
- ~QAuBucketNAS()
- {
- if (nas) {
- AuSync(nas, false);
- AuDestroyBucket(nas, id, NULL);
-
- AuEvent ev;
- while (AuScanEvents(nas, AuEventsQueuedAfterFlush, true, eventPred, &flow, &ev))
- ;
- }
- }
-
- AuBucketID id;
- AuFlowID flow;
- bool stopped;
- int numplaying;
-};
-
-class QAuServerNAS : public QAuServer {
- Q_OBJECT
-
- QSocketNotifier* sn;
-
-public:
- QAuServerNAS(QObject* parent);
- ~QAuServerNAS();
-
- void init(QSound*);
- void play(const QString& filename);
- void play(QSound*);
- void stop(QSound*);
- bool okay();
- void setDone(QSound*);
-
-public slots:
- void dataReceived();
- void soundDestroyed(QObject *o);
-
-private:
- QAuBucketNAS* bucket(QSound* s)
- {
- return (QAuBucketNAS*)QAuServer::bucket(s);
- }
-};
-
-QAuServerNAS::QAuServerNAS(QObject* parent) :
- QAuServer(parent)
-{
- setObjectName(QLatin1String("Network Audio System"));
- nas = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL);
- if (nas) {
- AuSetCloseDownMode(nas, AuCloseDownDestroy, NULL);
- // Ask Qt for async messages...
- sn=new QSocketNotifier(AuServerConnectionNumber(nas),
- QSocketNotifier::Read);
- QObject::connect(sn, SIGNAL(activated(int)),
- this, SLOT(dataReceived()));
- } else {
- sn = 0;
- }
-}
-
-QAuServerNAS::~QAuServerNAS()
-{
- if (nas)
- AuCloseServer(nas);
- delete sn;
- nas = 0;
-}
-
-typedef QHash<void*,QAuServerNAS*> AuServerHash;
-static AuServerHash *inprogress=0;
-
-void QAuServerNAS::soundDestroyed(QObject *o)
-{
- if (inprogress) {
- QSound *so = static_cast<QSound *>(o);
- while (inprogress->remove(so))
- ; // Loop while remove returns true
- }
-}
-
-void QAuServerNAS::play(const QString& filename)
-{
- if (nas) {
- int iv=100;
- AuFixedPoint volume=AuFixedPointFromFraction(iv,100);
- AuSoundPlayFromFile(nas, filename.toLocal8Bit().constData(), AuNone, volume,
- NULL, NULL, NULL, NULL, NULL, NULL);
- AuFlush(nas);
- dataReceived();
- AuFlush(nas);
- qApp->flush();
- }
-}
-
-static void callback(AuServer*, AuEventHandlerRec*, AuEvent* e, AuPointer p)
-{
- if (inprogress->contains(p) && e) {
- if (e->type==AuEventTypeElementNotify &&
- e->auelementnotify.kind==AuElementNotifyKindState) {
- if (e->auelementnotify.cur_state == AuStateStop) {
- AuServerHash::Iterator it = inprogress->find(p);
- if (it != inprogress->end())
- (*it)->setDone((QSound*)p);
- }
- }
- }
-}
-
-void QAuServerNAS::setDone(QSound* s)
-{
- if (nas) {
- decLoop(s);
- if (s->loopsRemaining() && !bucket(s)->stopped) {
- bucket(s)->stopped = true;
- play(s);
- } else {
- if (--(bucket(s)->numplaying) == 0)
- bucket(s)->stopped = true;
- inprogress->remove(s);
- }
- }
-}
-
-void QAuServerNAS::play(QSound* s)
-{
- if (nas) {
- ++(bucket(s)->numplaying);
- if (!bucket(s)->stopped) {
- stop(s);
- }
-
- bucket(s)->stopped = false;
- if (!inprogress)
- inprogress = new AuServerHash;
- inprogress->insert(s,this);
- int iv=100;
- AuFixedPoint volume=AuFixedPointFromFraction(iv,100);
- QAuBucketNAS *b = bucket(s);
- AuSoundPlayFromBucket(nas, b->id, AuNone, volume,
- callback, s, 0, &b->flow, NULL, NULL, NULL);
- AuFlush(nas);
- dataReceived();
- AuFlush(nas);
- qApp->flush();
- }
-}
-
-void QAuServerNAS::stop(QSound* s)
-{
- if (nas && !bucket(s)->stopped) {
- bucket(s)->stopped = true;
- AuStopFlow(nas, bucket(s)->flow, NULL);
- AuFlush(nas);
- dataReceived();
- AuFlush(nas);
- qApp->flush();
- }
-}
-
-void QAuServerNAS::init(QSound* s)
-{
- connect(s, SIGNAL(destroyed(QObject*)),
- this, SLOT(soundDestroyed(QObject*)));
-
- if (nas) {
- AuBucketID b_id =
- AuSoundCreateBucketFromFile(nas, s->fileName().toLocal8Bit().constData(),
- 0 /*AuAccessAllMasks*/, NULL, NULL);
- setBucket(s, new QAuBucketNAS(b_id));
- }
-}
-
-bool QAuServerNAS::okay()
-{
- return !!nas;
-}
-
-void QAuServerNAS::dataReceived()
-{
- AuHandleEvents(nas);
-}
-
-QT_BEGIN_INCLUDE_NAMESPACE
-#include "qsound_x11.moc"
-QT_END_INCLUDE_NAMESPACE
-
-#endif
-
-
-class QAuServerNull : public QAuServer
-{
-public:
- QAuServerNull(QObject* parent);
-
- void play(const QString&) { }
- void play(QSound*s) { while(decLoop(s) > 0) /* nothing */ ; }
- void stop(QSound*) { }
- bool okay() { return false; }
-};
-
-QAuServerNull::QAuServerNull(QObject* parent)
- : QAuServer(parent)
-{
-}
-
-
-QAuServer* qt_new_audio_server()
-{
-#ifndef QT_NO_NAS
- QAuServer* s = new QAuServerNAS(qApp);
- if (s->okay())
- return s;
- else
- delete s;
-#endif
- return new QAuServerNull(qApp);
-}
-
-QT_END_NAMESPACE
-
-#endif // QT_NO_SOUND
diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm
deleted file mode 100644
index 32123ee682..0000000000
--- a/src/gui/kernel/qt_cocoa_helpers_mac.mm
+++ /dev/null
@@ -1,1824 +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$
-**
-****************************************************************************/
-
-/****************************************************************************
-**
-** Copyright (c) 2007-2008, Apple, Inc.
-**
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-**
-** * Redistributions of source code must retain the above copyright notice,
-** this list of conditions and the following disclaimer.
-**
-** * Redistributions in binary form must reproduce the above copyright notice,
-** this list of conditions and the following disclaimer in the documentation
-** and/or other materials provided with the distribution.
-**
-** * Neither the name of Apple, Inc. nor the names of its contributors
-** may be used to endorse or promote products derived from this software
-** without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-****************************************************************************/
-
-#include <private/qcore_mac_p.h>
-#include <qaction.h>
-#include <qwidget.h>
-#include <qdesktopwidget.h>
-#include <qevent.h>
-#include <qpixmapcache.h>
-#include <qvarlengtharray.h>
-#include <private/qevent_p.h>
-#include <private/qt_cocoa_helpers_mac_p.h>
-#include <private/qt_mac_p.h>
-#include <private/qapplication_p.h>
-#include <private/qcocoaapplication_mac_p.h>
-#include <private/qcocoawindow_mac_p.h>
-#include <private/qcocoaview_mac_p.h>
-#include <private/qkeymapper_p.h>
-#include <private/qwidget_p.h>
-#include <private/qcocoawindow_mac_p.h>
-
-QT_BEGIN_NAMESPACE
-
-#ifdef QT_MAC_USE_COCOA
-// Cmd + left mousebutton should produce a right button
-// press (mainly for mac users with one-button mice):
-static bool qt_leftButtonIsRightButton = false;
-#endif
-
-Q_GLOBAL_STATIC(QMacWindowFader, macwindowFader);
-
-QMacWindowFader::QMacWindowFader()
- : m_duration(0.250)
-{
-}
-
-QMacWindowFader *QMacWindowFader::currentFader()
-{
- return macwindowFader();
-}
-
-void QMacWindowFader::registerWindowToFade(QWidget *window)
-{
- m_windowsToFade.append(window);
-}
-
-void QMacWindowFader::performFade()
-{
- const QWidgetList myWidgetsToFade = m_windowsToFade;
- const int widgetCount = myWidgetsToFade.count();
-#if QT_MAC_USE_COCOA
- QMacCocoaAutoReleasePool pool;
- [NSAnimationContext beginGrouping];
- [[NSAnimationContext currentContext] setDuration:NSTimeInterval(m_duration)];
-#endif
-
- for (int i = 0; i < widgetCount; ++i) {
- QWidget *widget = m_windowsToFade.at(i);
- OSWindowRef window = qt_mac_window_for(widget);
-#if QT_MAC_USE_COCOA
- [[window animator] setAlphaValue:0.0];
- QTimer::singleShot(qRound(m_duration * 1000), widget, SLOT(hide()));
-#else
- TransitionWindowOptions options = {0, m_duration, 0, 0};
- TransitionWindowWithOptions(window, kWindowFadeTransitionEffect, kWindowHideTransitionAction,
- 0, 1, &options);
-#endif
- }
-#if QT_MAC_USE_COCOA
- [NSAnimationContext endGrouping];
-#endif
- m_duration = 0.250;
- m_windowsToFade.clear();
-}
-
-extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); // qapplication.cpp;
-extern QWidget * mac_mouse_grabber;
-extern QWidget *qt_button_down; //qapplication_mac.cpp
-extern QPointer<QWidget> qt_last_mouse_receiver;
-extern OSViewRef qt_mac_effectiveview_for(const QWidget *w);
-extern void qt_mac_updateCursorWithWidgetUnderMouse(QWidget *widgetUnderMouse); // qcursor_mac.mm
-
-void macWindowFade(void * /*OSWindowRef*/ window, float durationSeconds)
-{
-#ifdef QT_MAC_USE_COCOA
- QMacCocoaAutoReleasePool pool;
-#endif
- OSWindowRef wnd = static_cast<OSWindowRef>(window);
- if (wnd) {
- QWidget *widget;
-#if QT_MAC_USE_COCOA
- widget = [wnd QT_MANGLE_NAMESPACE(qt_qwidget)];
-#else
- const UInt32 kWidgetCreatorQt = kEventClassQt;
- enum {
- kWidgetPropertyQWidget = 'QWId' //QWidget *
- };
- if (GetWindowProperty(static_cast<WindowRef>(window), kWidgetCreatorQt, kWidgetPropertyQWidget, sizeof(widget), 0, &widget) != noErr)
- widget = 0;
-#endif
- if (widget) {
- QMacWindowFader::currentFader()->setFadeDuration(durationSeconds);
- QMacWindowFader::currentFader()->registerWindowToFade(widget);
- QMacWindowFader::currentFader()->performFade();
- }
- }
-}
-struct dndenum_mapper
-{
- NSDragOperation mac_code;
- Qt::DropAction qt_code;
- bool Qt2Mac;
-};
-
-#if defined(QT_MAC_USE_COCOA) && defined(__OBJC__)
-
-static dndenum_mapper dnd_enums[] = {
- { NSDragOperationLink, Qt::LinkAction, true },
- { NSDragOperationMove, Qt::MoveAction, true },
- { NSDragOperationCopy, Qt::CopyAction, true },
- { NSDragOperationGeneric, Qt::CopyAction, false },
- { NSDragOperationEvery, Qt::ActionMask, false },
- { NSDragOperationNone, Qt::IgnoreAction, false }
-};
-
-NSDragOperation qt_mac_mapDropAction(Qt::DropAction action)
-{
- for (int i=0; dnd_enums[i].qt_code; i++) {
- if (dnd_enums[i].Qt2Mac && (action & dnd_enums[i].qt_code)) {
- return dnd_enums[i].mac_code;
- }
- }
- return NSDragOperationNone;
-}
-
-NSDragOperation qt_mac_mapDropActions(Qt::DropActions actions)
-{
- NSDragOperation nsActions = NSDragOperationNone;
- for (int i=0; dnd_enums[i].qt_code; i++) {
- if (dnd_enums[i].Qt2Mac && (actions & dnd_enums[i].qt_code))
- nsActions |= dnd_enums[i].mac_code;
- }
- return nsActions;
-}
-
-Qt::DropAction qt_mac_mapNSDragOperation(NSDragOperation nsActions)
-{
- Qt::DropAction action = Qt::IgnoreAction;
- for (int i=0; dnd_enums[i].mac_code; i++) {
- if (nsActions & dnd_enums[i].mac_code)
- return dnd_enums[i].qt_code;
- }
- return action;
-}
-
-Qt::DropActions qt_mac_mapNSDragOperations(NSDragOperation nsActions)
-{
- Qt::DropActions actions = Qt::IgnoreAction;
- for (int i=0; dnd_enums[i].mac_code; i++) {
- if (nsActions & dnd_enums[i].mac_code)
- actions |= dnd_enums[i].qt_code;
- }
- return actions;
-}
-
-Q_GLOBAL_STATIC(DnDParams, currentDnDParameters);
-DnDParams *macCurrentDnDParameters()
-{
- return currentDnDParameters();
-}
-#endif
-
-bool macWindowIsTextured( void * /*OSWindowRef*/ window )
-{
- OSWindowRef wnd = static_cast<OSWindowRef>(window);
-#if QT_MAC_USE_COCOA
- return ( [wnd styleMask] & NSTexturedBackgroundWindowMask ) ? true : false;
-#else
- WindowAttributes currentAttributes;
- GetWindowAttributes(wnd, &currentAttributes);
- return (currentAttributes & kWindowMetalAttribute) ? true : false;
-#endif
-}
-
-void macWindowToolbarShow(const QWidget *widget, bool show )
-{
- OSWindowRef wnd = qt_mac_window_for(widget);
-#if QT_MAC_USE_COCOA
- if (NSToolbar *toolbar = [wnd toolbar]) {
- QMacCocoaAutoReleasePool pool;
- if (show != [toolbar isVisible]) {
- [toolbar setVisible:show];
- } else {
- // The toolbar may be in sync, but we are not, update our framestrut.
- qt_widget_private(const_cast<QWidget *>(widget))->updateFrameStrut();
- }
- }
-#else
- qt_widget_private(const_cast<QWidget *>(widget))->updateFrameStrut();
- ShowHideWindowToolbar(wnd, show, false);
-#endif
-}
-
-
-void macWindowToolbarSet( void * /*OSWindowRef*/ window, void *toolbarRef )
-{
- OSWindowRef wnd = static_cast<OSWindowRef>(window);
-#if QT_MAC_USE_COCOA
- [wnd setToolbar:static_cast<NSToolbar *>(toolbarRef)];
-#else
- SetWindowToolbar(wnd, static_cast<HIToolbarRef>(toolbarRef));
-#endif
-}
-
-bool macWindowToolbarIsVisible( void * /*OSWindowRef*/ window )
-{
- OSWindowRef wnd = static_cast<OSWindowRef>(window);
-#if QT_MAC_USE_COCOA
- if (NSToolbar *toolbar = [wnd toolbar])
- return [toolbar isVisible];
- return false;
-#else
- return IsWindowToolbarVisible(wnd);
-#endif
-}
-
-void macWindowSetHasShadow( void * /*OSWindowRef*/ window, bool hasShadow )
-{
- OSWindowRef wnd = static_cast<OSWindowRef>(window);
-#if QT_MAC_USE_COCOA
- [wnd setHasShadow:BOOL(hasShadow)];
-#else
- if (hasShadow)
- ChangeWindowAttributes(wnd, 0, kWindowNoShadowAttribute);
- else
- ChangeWindowAttributes(wnd, kWindowNoShadowAttribute, 0);
-#endif
-}
-
-void macWindowFlush(void * /*OSWindowRef*/ window)
-{
- OSWindowRef wnd = static_cast<OSWindowRef>(window);
-#if QT_MAC_USE_COCOA
- [wnd flushWindowIfNeeded];
-#else
- HIWindowFlush(wnd);
-#endif
-}
-
-void * /*NSImage */qt_mac_create_nsimage(const QPixmap &pm)
-{
- QMacCocoaAutoReleasePool pool;
- if(QCFType<CGImageRef> image = pm.toMacCGImageRef()) {
- NSImage *newImage = 0;
- NSRect imageRect = NSMakeRect(0.0, 0.0, CGImageGetWidth(image), CGImageGetHeight(image));
- newImage = [[NSImage alloc] initWithSize:imageRect.size];
- [newImage lockFocus];
- {
- CGContextRef imageContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
- CGContextDrawImage(imageContext, *(CGRect*)&imageRect, image);
- }
- [newImage unlockFocus];
- return newImage;
- }
- return 0;
-}
-
-void qt_mac_update_mouseTracking(QWidget *widget)
-{
-#ifdef QT_MAC_USE_COCOA
- [qt_mac_nativeview_for(widget) updateTrackingAreas];
-#else
- Q_UNUSED(widget);
-#endif
-}
-
-OSStatus qt_mac_drawCGImage(CGContextRef inContext, const CGRect *inBounds, CGImageRef inImage)
-{
- // Verbatim copy if HIViewDrawCGImage (as shown on Carbon-Dev)
- OSStatus err = noErr;
-
- require_action(inContext != NULL, InvalidContext, err = paramErr);
- require_action(inBounds != NULL, InvalidBounds, err = paramErr);
- require_action(inImage != NULL, InvalidImage, err = paramErr);
-
- CGContextSaveGState( inContext );
- CGContextTranslateCTM (inContext, 0, inBounds->origin.y + CGRectGetMaxY(*inBounds));
- CGContextScaleCTM(inContext, 1, -1);
-
- CGContextDrawImage(inContext, *inBounds, inImage);
-
- CGContextRestoreGState(inContext);
-InvalidImage:
-InvalidBounds:
-InvalidContext:
- return err;
-}
-
-bool qt_mac_checkForNativeSizeGrip(const QWidget *widget)
-{
-#ifndef QT_MAC_USE_COCOA
- OSViewRef nativeSizeGrip = 0;
- HIViewFindByID(HIViewGetRoot(HIViewGetWindow(HIViewRef(widget->winId()))), kHIViewWindowGrowBoxID, &nativeSizeGrip);
- return (nativeSizeGrip != 0);
-#else
- return [[reinterpret_cast<NSView *>(widget->effectiveWinId()) window] showsResizeIndicator];
-#endif
-}
-struct qt_mac_enum_mapper
-{
- int mac_code;
- int qt_code;
-#if defined(DEBUG_MOUSE_MAPS)
-# define QT_MAC_MAP_ENUM(x) x, #x
- const char *desc;
-#else
-# define QT_MAC_MAP_ENUM(x) x
-#endif
-};
-
-//mouse buttons
-static qt_mac_enum_mapper qt_mac_mouse_symbols[] = {
-{ kEventMouseButtonPrimary, QT_MAC_MAP_ENUM(Qt::LeftButton) },
-{ kEventMouseButtonSecondary, QT_MAC_MAP_ENUM(Qt::RightButton) },
-{ kEventMouseButtonTertiary, QT_MAC_MAP_ENUM(Qt::MidButton) },
-{ 4, QT_MAC_MAP_ENUM(Qt::XButton1) },
-{ 5, QT_MAC_MAP_ENUM(Qt::XButton2) },
-{ 0, QT_MAC_MAP_ENUM(0) }
-};
-Qt::MouseButtons qt_mac_get_buttons(int buttons)
-{
-#ifdef DEBUG_MOUSE_MAPS
- qDebug("Qt: internal: **Mapping buttons: %d (0x%04x)", buttons, buttons);
-#endif
- Qt::MouseButtons ret = Qt::NoButton;
- for(int i = 0; qt_mac_mouse_symbols[i].qt_code; i++) {
- if (buttons & (0x01<<(qt_mac_mouse_symbols[i].mac_code-1))) {
-#ifdef DEBUG_MOUSE_MAPS
- qDebug("Qt: internal: got button: %s", qt_mac_mouse_symbols[i].desc);
-#endif
- ret |= Qt::MouseButtons(qt_mac_mouse_symbols[i].qt_code);
- }
- }
- return ret;
-}
-Qt::MouseButton qt_mac_get_button(EventMouseButton button)
-{
-#ifdef DEBUG_MOUSE_MAPS
- qDebug("Qt: internal: **Mapping button: %d (0x%04x)", button, button);
-#endif
- Qt::MouseButtons ret = 0;
- for(int i = 0; qt_mac_mouse_symbols[i].qt_code; i++) {
- if (button == qt_mac_mouse_symbols[i].mac_code) {
-#ifdef DEBUG_MOUSE_MAPS
- qDebug("Qt: internal: got button: %s", qt_mac_mouse_symbols[i].desc);
-#endif
- return Qt::MouseButton(qt_mac_mouse_symbols[i].qt_code);
- }
- }
- return Qt::NoButton;
-}
-
-void macSendToolbarChangeEvent(QWidget *widget)
-{
- QToolBarChangeEvent ev(!(GetCurrentKeyModifiers() & cmdKey));
- qt_sendSpontaneousEvent(widget, &ev);
-}
-
-Q_GLOBAL_STATIC(QMacTabletHash, tablet_hash)
-QMacTabletHash *qt_mac_tablet_hash()
-{
- return tablet_hash();
-}
-
-#ifdef QT_MAC_USE_COCOA
-
-// Clears the QWidget pointer that each QCocoaView holds.
-void qt_mac_clearCocoaViewQWidgetPointers(QWidget *widget)
-{
- QT_MANGLE_NAMESPACE(QCocoaView) *cocoaView = reinterpret_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(qt_mac_nativeview_for(widget));
- if (cocoaView && [cocoaView respondsToSelector:@selector(qt_qwidget)]) {
- [cocoaView qt_clearQWidget];
- }
-}
-
-void qt_dispatchTabletProximityEvent(void * /*NSEvent * */ tabletEvent)
-{
- NSEvent *proximityEvent = static_cast<NSEvent *>(tabletEvent);
- // simply construct a Carbon proximity record and handle it all in one spot.
- TabletProximityRec carbonProximityRec = { [proximityEvent vendorID],
- [proximityEvent tabletID],
- [proximityEvent pointingDeviceID],
- [proximityEvent deviceID],
- [proximityEvent systemTabletID],
- [proximityEvent vendorPointingDeviceType],
- [proximityEvent pointingDeviceSerialNumber],
- [proximityEvent uniqueID],
- [proximityEvent capabilityMask],
- [proximityEvent pointingDeviceType],
- [proximityEvent isEnteringProximity] };
- qt_dispatchTabletProximityEvent(carbonProximityRec);
-}
-#endif // QT_MAC_USE_COCOA
-
-void qt_dispatchTabletProximityEvent(const ::TabletProximityRec &proxRec)
-{
- QTabletDeviceData proximityDevice;
- proximityDevice.tabletUniqueID = proxRec.uniqueID;
- proximityDevice.capabilityMask = proxRec.capabilityMask;
-
- switch (proxRec.pointerType) {
- case NSUnknownPointingDevice:
- default:
- proximityDevice.tabletPointerType = QTabletEvent::UnknownPointer;
- break;
- case NSPenPointingDevice:
- proximityDevice.tabletPointerType = QTabletEvent::Pen;
- break;
- case NSCursorPointingDevice:
- proximityDevice.tabletPointerType = QTabletEvent::Cursor;
- break;
- case NSEraserPointingDevice:
- proximityDevice.tabletPointerType = QTabletEvent::Eraser;
- break;
- }
- uint bits = proxRec.vendorPointerType;
- if (bits == 0 && proximityDevice.tabletUniqueID != 0) {
- // Fallback. It seems that the driver doesn't always include all the information.
- // High-End Wacom devices store their "type" in the uper bits of the Unique ID.
- // I'm not sure how to handle it for consumer devices, but I'll test that in a bit.
- bits = proximityDevice.tabletUniqueID >> 32;
- }
- // Defined in the "EN0056-NxtGenImpGuideX"
- // on Wacom's Developer Website (www.wacomeng.com)
- if (((bits & 0x0006) == 0x0002) && ((bits & 0x0F06) != 0x0902)) {
- proximityDevice.tabletDeviceType = QTabletEvent::Stylus;
- } else {
- switch (bits & 0x0F06) {
- case 0x0802:
- proximityDevice.tabletDeviceType = QTabletEvent::Stylus;
- break;
- case 0x0902:
- proximityDevice.tabletDeviceType = QTabletEvent::Airbrush;
- break;
- case 0x0004:
- proximityDevice.tabletDeviceType = QTabletEvent::FourDMouse;
- break;
- case 0x0006:
- proximityDevice.tabletDeviceType = QTabletEvent::Puck;
- break;
- case 0x0804:
- proximityDevice.tabletDeviceType = QTabletEvent::RotationStylus;
- break;
- default:
- proximityDevice.tabletDeviceType = QTabletEvent::NoDevice;
- }
- }
- // The deviceID is "unique" while in the proximity, it's a key that we can use for
- // linking up TabletDeviceData to an event (especially if there are two devices in action).
- bool entering = proxRec.enterProximity;
- if (entering) {
- qt_mac_tablet_hash()->insert(proxRec.deviceID, proximityDevice);
- } else {
- qt_mac_tablet_hash()->remove(proxRec.deviceID);
- }
-
- QTabletEvent qtabletProximity(entering ? QEvent::TabletEnterProximity
- : QEvent::TabletLeaveProximity,
- QPoint(), QPoint(), QPointF(), proximityDevice.tabletDeviceType,
- proximityDevice.tabletPointerType, 0., 0, 0, 0., 0., 0, 0,
- proximityDevice.tabletUniqueID);
-
- qt_sendSpontaneousEvent(qApp, &qtabletProximity);
-}
-
-// Use this method to keep all the information in the TextSegment. As long as it is ordered
-// we are in OK shape, and we can influence that ourselves.
-struct KeyPair
-{
- QChar cocoaKey;
- Qt::Key qtKey;
-};
-
-bool operator==(const KeyPair &entry, QChar qchar)
-{
- return entry.cocoaKey == qchar;
-}
-
-bool operator<(const KeyPair &entry, QChar qchar)
-{
- return entry.cocoaKey < qchar;
-}
-
-bool operator<(QChar qchar, const KeyPair &entry)
-{
- return qchar < entry.cocoaKey;
-}
-
-bool operator<(const Qt::Key &key, const KeyPair &entry)
-{
- return key < entry.qtKey;
-}
-
-bool operator<(const KeyPair &entry, const Qt::Key &key)
-{
- return entry.qtKey < key;
-}
-
-static bool qtKey2CocoaKeySortLessThan(const KeyPair &entry1, const KeyPair &entry2)
-{
- return entry1.qtKey < entry2.qtKey;
-}
-
-static const int NumEntries = 59;
-static const KeyPair entries[NumEntries] = {
- { NSEnterCharacter, Qt::Key_Enter },
- { NSBackspaceCharacter, Qt::Key_Backspace },
- { NSTabCharacter, Qt::Key_Tab },
- { NSNewlineCharacter, Qt::Key_Return },
- { NSCarriageReturnCharacter, Qt::Key_Return },
- { NSBackTabCharacter, Qt::Key_Backtab },
- { kEscapeCharCode, Qt::Key_Escape },
- // Cocoa sends us delete when pressing backspace!
- // (NB when we reverse this list in qtKey2CocoaKey, there
- // will be two indices of Qt::Key_Backspace. But is seems to work
- // ok for menu shortcuts (which uses that function):
- { NSDeleteCharacter, Qt::Key_Backspace },
- { NSUpArrowFunctionKey, Qt::Key_Up },
- { NSDownArrowFunctionKey, Qt::Key_Down },
- { NSLeftArrowFunctionKey, Qt::Key_Left },
- { NSRightArrowFunctionKey, Qt::Key_Right },
- { NSF1FunctionKey, Qt::Key_F1 },
- { NSF2FunctionKey, Qt::Key_F2 },
- { NSF3FunctionKey, Qt::Key_F3 },
- { NSF4FunctionKey, Qt::Key_F4 },
- { NSF5FunctionKey, Qt::Key_F5 },
- { NSF6FunctionKey, Qt::Key_F6 },
- { NSF7FunctionKey, Qt::Key_F7 },
- { NSF8FunctionKey, Qt::Key_F8 },
- { NSF9FunctionKey, Qt::Key_F8 },
- { NSF10FunctionKey, Qt::Key_F10 },
- { NSF11FunctionKey, Qt::Key_F11 },
- { NSF12FunctionKey, Qt::Key_F12 },
- { NSF13FunctionKey, Qt::Key_F13 },
- { NSF14FunctionKey, Qt::Key_F14 },
- { NSF15FunctionKey, Qt::Key_F15 },
- { NSF16FunctionKey, Qt::Key_F16 },
- { NSF17FunctionKey, Qt::Key_F17 },
- { NSF18FunctionKey, Qt::Key_F18 },
- { NSF19FunctionKey, Qt::Key_F19 },
- { NSF20FunctionKey, Qt::Key_F20 },
- { NSF21FunctionKey, Qt::Key_F21 },
- { NSF22FunctionKey, Qt::Key_F22 },
- { NSF23FunctionKey, Qt::Key_F23 },
- { NSF24FunctionKey, Qt::Key_F24 },
- { NSF25FunctionKey, Qt::Key_F25 },
- { NSF26FunctionKey, Qt::Key_F26 },
- { NSF27FunctionKey, Qt::Key_F27 },
- { NSF28FunctionKey, Qt::Key_F28 },
- { NSF29FunctionKey, Qt::Key_F29 },
- { NSF30FunctionKey, Qt::Key_F30 },
- { NSF31FunctionKey, Qt::Key_F31 },
- { NSF32FunctionKey, Qt::Key_F32 },
- { NSF33FunctionKey, Qt::Key_F33 },
- { NSF34FunctionKey, Qt::Key_F34 },
- { NSF35FunctionKey, Qt::Key_F35 },
- { NSInsertFunctionKey, Qt::Key_Insert },
- { NSDeleteFunctionKey, Qt::Key_Delete },
- { NSHomeFunctionKey, Qt::Key_Home },
- { NSEndFunctionKey, Qt::Key_End },
- { NSPageUpFunctionKey, Qt::Key_PageUp },
- { NSPageDownFunctionKey, Qt::Key_PageDown },
- { NSPrintScreenFunctionKey, Qt::Key_Print },
- { NSScrollLockFunctionKey, Qt::Key_ScrollLock },
- { NSPauseFunctionKey, Qt::Key_Pause },
- { NSSysReqFunctionKey, Qt::Key_SysReq },
- { NSMenuFunctionKey, Qt::Key_Menu },
- { NSHelpFunctionKey, Qt::Key_Help },
-};
-static const KeyPair * const end = entries + NumEntries;
-
-QChar qtKey2CocoaKey(Qt::Key key)
-{
- // The first time this function is called, create a reverse
- // looup table sorted on Qt Key rather than Cocoa key:
- static QVector<KeyPair> rev_entries(NumEntries);
- static bool mustInit = true;
- if (mustInit){
- mustInit = false;
- for (int i=0; i<NumEntries; ++i)
- rev_entries[i] = entries[i];
- qSort(rev_entries.begin(), rev_entries.end(), qtKey2CocoaKeySortLessThan);
- }
- const QVector<KeyPair>::iterator i
- = qBinaryFind(rev_entries.begin(), rev_entries.end(), key);
- if (i == rev_entries.end())
- return QChar();
- return i->cocoaKey;
-}
-
-#ifdef QT_MAC_USE_COCOA
-static Qt::Key cocoaKey2QtKey(QChar keyCode)
-{
- const KeyPair *i = qBinaryFind(entries, end, keyCode);
- if (i == end)
- return Qt::Key(keyCode.unicode());
- return i->qtKey;
-}
-
-Qt::KeyboardModifiers qt_cocoaModifiers2QtModifiers(ulong modifierFlags)
-{
- Qt::KeyboardModifiers qtMods =Qt::NoModifier;
- if (modifierFlags & NSShiftKeyMask)
- qtMods |= Qt::ShiftModifier;
- if (modifierFlags & NSControlKeyMask)
- qtMods |= Qt::MetaModifier;
- if (modifierFlags & NSAlternateKeyMask)
- qtMods |= Qt::AltModifier;
- if (modifierFlags & NSCommandKeyMask)
- qtMods |= Qt::ControlModifier;
- if (modifierFlags & NSNumericPadKeyMask)
- qtMods |= Qt::KeypadModifier;
- return qtMods;
-}
-
-NSString *qt_mac_removePrivateUnicode(NSString* string)
-{
- int len = [string length];
- if (len) {
- QVarLengthArray <unichar, 10> characters(len);
- bool changed = false;
- for (int i = 0; i<len; i++) {
- characters[i] = [string characterAtIndex:i];
- // check if they belong to key codes in private unicode range
- // currently we need to handle only the NSDeleteFunctionKey
- if (characters[i] == NSDeleteFunctionKey) {
- characters[i] = NSDeleteCharacter;
- changed = true;
- }
- }
- if (changed)
- return [NSString stringWithCharacters:characters.data() length:len];
- }
- return string;
-}
-
-Qt::KeyboardModifiers qt_cocoaDragOperation2QtModifiers(uint dragOperations)
-{
- Qt::KeyboardModifiers qtMods =Qt::NoModifier;
- if (dragOperations & NSDragOperationLink)
- qtMods |= Qt::MetaModifier;
- if (dragOperations & NSDragOperationGeneric)
- qtMods |= Qt::ControlModifier;
- if (dragOperations & NSDragOperationCopy)
- qtMods |= Qt::AltModifier;
- return qtMods;
-}
-
-static inline QEvent::Type cocoaEvent2QtEvent(NSUInteger eventType)
-{
- // Handle the trivial cases that can be determined from the type.
- switch (eventType) {
- case NSKeyDown:
- return QEvent::KeyPress;
- case NSKeyUp:
- return QEvent::KeyRelease;
- case NSLeftMouseDown:
- case NSRightMouseDown:
- case NSOtherMouseDown:
- return QEvent::MouseButtonPress;
- case NSLeftMouseUp:
- case NSRightMouseUp:
- case NSOtherMouseUp:
- return QEvent::MouseButtonRelease;
- case NSMouseMoved:
- case NSLeftMouseDragged:
- case NSRightMouseDragged:
- case NSOtherMouseDragged:
- return QEvent::MouseMove;
- case NSScrollWheel:
- return QEvent::Wheel;
- }
- return QEvent::None;
-}
-
-static bool mustUseCocoaKeyEvent()
-{
- QCFType<TISInputSourceRef> source = TISCopyCurrentKeyboardInputSource();
- return TISGetInputSourceProperty(source, kTISPropertyUnicodeKeyLayoutData) == 0;
-}
-
-bool qt_dispatchKeyEventWithCocoa(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent)
-{
- NSEvent *event = static_cast<NSEvent *>(keyEvent);
- NSString *keyChars = [event charactersIgnoringModifiers];
- int keyLength = [keyChars length];
- if (keyLength == 0)
- return false; // Dead Key, nothing to do!
- bool ignoreText = false;
- Qt::Key qtKey = Qt::Key_unknown;
- if (keyLength == 1) {
- QChar ch([keyChars characterAtIndex:0]);
- if (ch.isLower())
- ch = ch.toUpper();
- qtKey = cocoaKey2QtKey(ch);
- // Do not set the text for Function-Key Unicodes characters (0xF700–0xF8FF).
- ignoreText = (ch.unicode() >= 0xF700 && ch.unicode() <= 0xF8FF);
- }
- Qt::KeyboardModifiers keyMods = qt_cocoaModifiers2QtModifiers([event modifierFlags]);
- QString text;
-
- // To quote from the Carbon port: This is actually wrong--but it is the best that
- // can be done for now because of the Control/Meta mapping issues
- // (we always get text on the Mac)
- if (!ignoreText && !(keyMods & (Qt::ControlModifier | Qt::MetaModifier)))
- text = QCFString::toQString(reinterpret_cast<CFStringRef>(keyChars));
-
- UInt32 macScanCode = 1;
- QKeyEventEx ke(cocoaEvent2QtEvent([event type]), qtKey, keyMods, text, [event isARepeat], qMax(1, keyLength),
- macScanCode, [event keyCode], [event modifierFlags]);
- return qt_sendSpontaneousEvent(widgetToGetEvent, &ke) && ke.isAccepted();
-}
-#endif
-
-Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum)
-{
- if (buttonNum == 0)
- return Qt::LeftButton;
- if (buttonNum == 1)
- return Qt::RightButton;
- if (buttonNum == 2)
- return Qt::MidButton;
- if (buttonNum == 3)
- return Qt::XButton1;
- if (buttonNum == 4)
- return Qt::XButton2;
- return Qt::NoButton;
-}
-
-bool qt_dispatchKeyEvent(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent)
-{
-#ifndef QT_MAC_USE_COCOA
- Q_UNUSED(keyEvent);
- Q_UNUSED(widgetToGetEvent);
- return false;
-#else
- NSEvent *event = static_cast<NSEvent *>(keyEvent);
- EventRef key_event = static_cast<EventRef>(const_cast<void *>([event eventRef]));
- Q_ASSERT(key_event);
- unsigned int info = 0;
-
- if ([event type] == NSKeyDown) {
- NSString *characters = [event characters];
- if ([characters length]) {
- unichar value = [characters characterAtIndex:0];
- qt_keymapper_private()->updateKeyMap(0, key_event, (void *)&value);
- info = value;
- }
- }
-
- if (qt_mac_sendMacEventToWidget(widgetToGetEvent, key_event))
- return true;
-
- if (mustUseCocoaKeyEvent())
- return qt_dispatchKeyEventWithCocoa(keyEvent, widgetToGetEvent);
-
- bool consumed = qt_keymapper_private()->translateKeyEvent(widgetToGetEvent, 0, key_event, &info, true);
- return consumed && (info != 0);
-#endif
-}
-
-void qt_dispatchModifiersChanged(void * /*NSEvent * */flagsChangedEvent, QWidget *widgetToGetEvent)
-{
-#ifndef QT_MAC_USE_COCOA
- Q_UNUSED(flagsChangedEvent);
- Q_UNUSED(widgetToGetEvent);
-#else
- UInt32 modifiers = 0;
- // Sync modifiers with Qt
- NSEvent *event = static_cast<NSEvent *>(flagsChangedEvent);
- EventRef key_event = static_cast<EventRef>(const_cast<void *>([event eventRef]));
- Q_ASSERT(key_event);
- GetEventParameter(key_event, kEventParamKeyModifiers, typeUInt32, 0,
- sizeof(modifiers), 0, &modifiers);
- extern void qt_mac_send_modifiers_changed(quint32 modifiers, QObject *object);
- qt_mac_send_modifiers_changed(modifiers, widgetToGetEvent);
-#endif
-}
-
-QPointF flipPoint(const NSPoint &p)
-{
- return QPointF(p.x, flipYCoordinate(p.y));
-}
-
-NSPoint flipPoint(const QPoint &p)
-{
- return NSMakePoint(p.x(), flipYCoordinate(p.y()));
-}
-
-NSPoint flipPoint(const QPointF &p)
-{
- return NSMakePoint(p.x(), flipYCoordinate(p.y()));
-}
-
-#if QT_MAC_USE_COCOA && __OBJC__
-
-void qt_mac_handleNonClientAreaMouseEvent(NSWindow *window, NSEvent *event)
-{
- QWidget *widgetToGetEvent = [window QT_MANGLE_NAMESPACE(qt_qwidget)];
- if (widgetToGetEvent == 0)
- return;
-
- NSEventType evtType = [event type];
- QPoint qlocalPoint;
- QPoint qglobalPoint;
- bool processThisEvent = false;
- bool fakeNCEvents = false;
- bool fakeMouseEvents = false;
-
- // Check if this is a mouse event.
- if (evtType == NSLeftMouseDown || evtType == NSLeftMouseUp
- || evtType == NSRightMouseDown || evtType == NSRightMouseUp
- || evtType == NSOtherMouseDown || evtType == NSOtherMouseUp
- || evtType == NSMouseMoved || evtType == NSLeftMouseDragged
- || evtType == NSRightMouseDragged || evtType == NSOtherMouseDragged) {
- // Check if we want to pass this message to another window
- if (mac_mouse_grabber && mac_mouse_grabber != widgetToGetEvent) {
- NSWindow *grabWindow = static_cast<NSWindow *>(qt_mac_window_for(mac_mouse_grabber));
- if (window != grabWindow) {
- window = grabWindow;
- widgetToGetEvent = mac_mouse_grabber;
- fakeNCEvents = true;
- }
- }
- // Dont generate normal NC mouse events for Left Button dragged
- if(evtType != NSLeftMouseDragged || fakeNCEvents) {
- NSPoint windowPoint = [event locationInWindow];
- NSPoint globalPoint = [[event window] convertBaseToScreen:windowPoint];
- NSRect frameRect = [window frame];
- if (fakeNCEvents || NSMouseInRect(globalPoint, frameRect, NO)) {
- NSRect contentRect = [window contentRectForFrameRect:frameRect];
- qglobalPoint = QPoint(flipPoint(globalPoint).toPoint());
- QWidget *w = widgetToGetEvent->childAt(widgetToGetEvent->mapFromGlobal(qglobalPoint));
- // check that the mouse pointer is on the non-client area and
- // there are not widgets in it.
- if (fakeNCEvents || (!NSMouseInRect(globalPoint, contentRect, NO) && !w)) {
- qglobalPoint = QPoint(flipPoint(globalPoint).toPoint());
- qlocalPoint = widgetToGetEvent->mapFromGlobal(qglobalPoint);
- processThisEvent = true;
- }
- }
- }
- }
- // This is not an NC area mouse message.
- if (!processThisEvent)
- return;
-
- // If the window is frame less, generate fake mouse events instead. (floating QToolBar)
- // or if someone already got an explicit or implicit grab
- if (mac_mouse_grabber || qt_button_down ||
- (fakeNCEvents && (widgetToGetEvent->window()->windowFlags() & Qt::FramelessWindowHint)))
- fakeMouseEvents = true;
-
- Qt::MouseButton button;
- QEvent::Type eventType;
- // Convert to Qt::Event type
- switch (evtType) {
- case NSLeftMouseDown:
- button = Qt::LeftButton;
- eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseButtonPress
- : QEvent::MouseButtonPress;
- break;
- case NSLeftMouseUp:
- button = Qt::LeftButton;
- eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseButtonRelease
- : QEvent::MouseButtonRelease;
- break;
- case NSRightMouseDown:
- button = Qt::RightButton;
- eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseButtonPress
- : QEvent::MouseButtonPress;
- break;
- case NSRightMouseUp:
- button = Qt::RightButton;
- eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseButtonRelease
- : QEvent::MouseButtonRelease;
- break;
- case NSOtherMouseDown:
- button = cocoaButton2QtButton([event buttonNumber]);
- eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseButtonPress
- : QEvent::MouseButtonPress;
- break;
- case NSOtherMouseUp:
- button = cocoaButton2QtButton([event buttonNumber]);
- eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseButtonRelease
- : QEvent::MouseButtonRelease;
- break;
- case NSMouseMoved:
- button = Qt::NoButton;
- eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseMove
- : QEvent::MouseMove;
- break;
- case NSLeftMouseDragged:
- button = Qt::LeftButton;
- eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseMove
- : QEvent::MouseMove;
- break;
- case NSRightMouseDragged:
- button = Qt::RightButton;
- eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseMove
- : QEvent::MouseMove;
- break;
- case NSOtherMouseDragged:
- button = cocoaButton2QtButton([event buttonNumber]);
- eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseMove
- : QEvent::MouseMove;
- break;
- default:
- qWarning("not handled! Non client area mouse message");
- return;
- }
-
- Qt::KeyboardModifiers keyMods = qt_cocoaModifiers2QtModifiers([event modifierFlags]);
- if (eventType == QEvent::NonClientAreaMouseButtonPress || eventType == QEvent::MouseButtonPress) {
- NSInteger clickCount = [event clickCount];
- if (clickCount % 2 == 0)
- eventType = (!fakeMouseEvents) ? QEvent::NonClientAreaMouseButtonDblClick
- : QEvent::MouseButtonDblClick;
- if (button == Qt::LeftButton && (keyMods & Qt::MetaModifier)) {
- button = Qt::RightButton;
- qt_leftButtonIsRightButton = true;
- }
- } else if (eventType == QEvent::NonClientAreaMouseButtonRelease || eventType == QEvent::MouseButtonRelease) {
- if (button == Qt::LeftButton && qt_leftButtonIsRightButton) {
- button = Qt::RightButton;
- qt_leftButtonIsRightButton = false;
- }
- }
-
- Qt::MouseButtons buttons = 0;
- {
- UInt32 mac_buttons;
- if (GetEventParameter((EventRef)[event eventRef], kEventParamMouseChord, typeUInt32, 0,
- sizeof(mac_buttons), 0, &mac_buttons) == noErr)
- buttons = qt_mac_get_buttons(mac_buttons);
- }
-
- QMouseEvent qme(eventType, qlocalPoint, qglobalPoint, button, buttons, keyMods);
- qt_sendSpontaneousEvent(widgetToGetEvent, &qme);
-
- // We don't need to set the implicit grab widget here because we won't
- // reach this point if then event type is Press over a Qt widget.
- // However we might need to unset it if the event is Release.
- if (eventType == QEvent::MouseButtonRelease)
- qt_button_down = 0;
-}
-
-QWidget *qt_mac_getTargetForKeyEvent(QWidget *widgetThatReceivedEvent)
-{
- if (QWidget *popup = QApplication::activePopupWidget()) {
- QWidget *focusInPopup = popup->focusWidget();
- return focusInPopup ? focusInPopup : popup;
- }
-
- QWidget *widgetToGetKey = qApp->focusWidget();
- if (!widgetToGetKey)
- widgetToGetKey = widgetThatReceivedEvent;
-
- return widgetToGetKey;
-}
-
-// This function will find the widget that should receive the
-// mouse event. Because of explicit/implicit mouse grabs, popups,
-// etc, this might not end up being the same as the widget under
-// the mouse (which is more interresting when handling enter/leave
-// events
-QWidget *qt_mac_getTargetForMouseEvent(
- // You can call this function without providing an event.
- NSEvent *event,
- QEvent::Type eventType,
- QPoint &returnLocalPoint,
- QPoint &returnGlobalPoint,
- QWidget *nativeWidget,
- QWidget **returnWidgetUnderMouse)
-{
- Q_UNUSED(event);
- NSPoint nsglobalpoint = event ? [[event window] convertBaseToScreen:[event locationInWindow]] : [NSEvent mouseLocation];
- returnGlobalPoint = flipPoint(nsglobalpoint).toPoint();
- QWidget *mouseGrabber = QWidget::mouseGrabber();
- bool buttonDownNotBlockedByModal = qt_button_down && !QApplicationPrivate::isBlockedByModal(qt_button_down);
- QWidget *popup = QApplication::activePopupWidget();
-
- // Resolve the widget under the mouse:
- QWidget *widgetUnderMouse = 0;
- if (popup || qt_button_down || !nativeWidget || !nativeWidget->isVisible()) {
- // Using QApplication::widgetAt for finding the widget under the mouse
- // is most safe, since it ignores cocoas own mouse down redirections (which
- // we need to be prepared for when using nativeWidget as starting point).
- // (the only exception is for QMacNativeWidget, where QApplication::widgetAt fails).
- // But it is also slower (I guess), so we try to avoid it and use nativeWidget if we can:
- widgetUnderMouse = QApplication::widgetAt(returnGlobalPoint);
- }
-
- if (!widgetUnderMouse && nativeWidget) {
- // Entering here should be the common case. We
- // also handle the QMacNativeWidget fallback case.
- QPoint p = nativeWidget->mapFromGlobal(returnGlobalPoint);
- widgetUnderMouse = nativeWidget->childAt(p);
- if (!widgetUnderMouse && nativeWidget->rect().contains(p))
- widgetUnderMouse = nativeWidget;
- }
-
- if (widgetUnderMouse) {
- // Check if widgetUnderMouse is blocked by a modal
- // window, or the mouse if over the frame strut:
- if (widgetUnderMouse == qt_button_down) {
- // Small optimization to avoid an extra call to isBlockedByModal:
- if (buttonDownNotBlockedByModal == false)
- widgetUnderMouse = 0;
- } else if (QApplicationPrivate::isBlockedByModal(widgetUnderMouse)) {
- widgetUnderMouse = 0;
- }
-
- if (widgetUnderMouse && widgetUnderMouse->isWindow()) {
- // Exclude the titlebar (and frame strut) when finding widget under mouse:
- QPoint p = widgetUnderMouse->mapFromGlobal(returnGlobalPoint);
- if (!widgetUnderMouse->rect().contains(p))
- widgetUnderMouse = 0;
- }
- }
- if (returnWidgetUnderMouse)
- *returnWidgetUnderMouse = widgetUnderMouse;
-
- // Resolve the target for the mouse event. Default will be
- // widgetUnderMouse, except if there is a grab (popup/mouse/button-down):
- if (popup && !mouseGrabber) {
- // We special case handling of popups, since they have an implicitt mouse grab.
- QWidget *candidate = buttonDownNotBlockedByModal ? qt_button_down : widgetUnderMouse;
- if (!popup->isAncestorOf(candidate)) {
- // INVARIANT: we have a popup, but the candidate is not
- // in it. But the popup will grab the mouse anyway,
- // except if the user scrolls:
- if (eventType == QEvent::Wheel)
- return 0;
- returnLocalPoint = popup->mapFromGlobal(returnGlobalPoint);
- return popup;
- } else if (popup == candidate) {
- // INVARIANT: The candidate is the popup itself, and not a child:
- returnLocalPoint = popup->mapFromGlobal(returnGlobalPoint);
- return popup;
- } else {
- // INVARIANT: The candidate is a child inside the popup:
- returnLocalPoint = candidate->mapFromGlobal(returnGlobalPoint);
- return candidate;
- }
- }
-
- QWidget *target = mouseGrabber;
- if (!target && buttonDownNotBlockedByModal)
- target = qt_button_down;
- if (!target)
- target = widgetUnderMouse;
- if (!target)
- return 0;
-
- returnLocalPoint = target->mapFromGlobal(returnGlobalPoint);
- return target;
-}
-
-QPointer<QWidget> qt_last_native_mouse_receiver = 0;
-
-static inline void qt_mac_checkEnterLeaveForNativeWidgets(QWidget *maybeEnterWidget)
-{
- // Dispatch enter/leave for the cases where QApplicationPrivate::sendMouseEvent do
- // not. This will in general be the cases when alien widgets are not involved:
- // 1. from a native widget to another native widget or
- // 2. from a native widget to no widget
- // 3. from no widget to a native or alien widget
-
- if (qt_button_down || QWidget::mouseGrabber())
- return;
-
- if ((maybeEnterWidget == qt_last_native_mouse_receiver) && qt_last_native_mouse_receiver)
- return;
- if (maybeEnterWidget) {
- if (!qt_last_native_mouse_receiver) {
- // case 3
- QApplicationPrivate::dispatchEnterLeave(maybeEnterWidget, 0);
- qt_last_native_mouse_receiver = maybeEnterWidget->internalWinId() ? maybeEnterWidget : maybeEnterWidget->nativeParentWidget();
- } else if (maybeEnterWidget->internalWinId()) {
- // case 1
- QApplicationPrivate::dispatchEnterLeave(maybeEnterWidget, qt_last_native_mouse_receiver);
- qt_last_native_mouse_receiver = maybeEnterWidget->internalWinId() ? maybeEnterWidget : maybeEnterWidget->nativeParentWidget();
- } // else at lest one of the widgets are alien, so enter/leave will be handled in QApplicationPrivate
- } else {
- if (qt_last_native_mouse_receiver) {
- // case 2
- QApplicationPrivate::dispatchEnterLeave(0, qt_last_native_mouse_receiver);
- qt_last_mouse_receiver = 0;
- qt_last_native_mouse_receiver = 0;
- }
- }
-}
-
-bool qt_mac_handleMouseEvent(NSEvent *event, QEvent::Type eventType, Qt::MouseButton button, QWidget *nativeWidget)
-{
- // Give the Input Manager a chance to process the mouse events.
- NSInputManager *currentIManager = [NSInputManager currentInputManager];
- if (currentIManager && [currentIManager wantsToHandleMouseEvents]) {
- [currentIManager handleMouseEvent:event];
- }
-
- // Find the widget that should receive the event, and the widget under the mouse. Those
- // can differ if an implicit or explicit mouse grab is active:
- QWidget *widgetUnderMouse = 0;
- QPoint localPoint, globalPoint;
- QWidget *widgetToGetMouse = qt_mac_getTargetForMouseEvent(event, eventType, localPoint, globalPoint, nativeWidget, &widgetUnderMouse);
- if (!widgetToGetMouse)
- return false;
-
- // From here on, we let nativeWidget actually be the native widget under widgetUnderMouse. The reason
- // for this, is that qt_mac_getTargetForMouseEvent will set cocoa's mouse event redirection aside when
- // determining which widget is under the mouse (in other words, it will usually ignore nativeWidget).
- // nativeWidget will be used in QApplicationPrivate::sendMouseEvent to correctly dispatch enter/leave events.
- if (widgetUnderMouse)
- nativeWidget = widgetUnderMouse->internalWinId() ? widgetUnderMouse : widgetUnderMouse->nativeParentWidget();
- if (!nativeWidget)
- return false;
- NSView *view = qt_mac_effectiveview_for(nativeWidget);
-
- // Handle tablet events (if any) first.
- if (qt_mac_handleTabletEvent(view, event)) {
- // Tablet event was handled. In Qt we aren't supposed to send the mouse event.
- return true;
- }
-
- EventRef carbonEvent = static_cast<EventRef>(const_cast<void *>([event eventRef]));
- if (qt_mac_sendMacEventToWidget(widgetToGetMouse, carbonEvent))
- return true;
-
- // Keep previousButton to make sure we don't send double click
- // events when the user double clicks using two different buttons:
- static Qt::MouseButton previousButton = Qt::NoButton;
-
- Qt::KeyboardModifiers keyMods = qt_cocoaModifiers2QtModifiers([event modifierFlags]);
- NSInteger clickCount = [event clickCount];
- Qt::MouseButtons buttons = 0;
- {
- UInt32 mac_buttons;
- if (GetEventParameter(carbonEvent, kEventParamMouseChord, typeUInt32, 0,
- sizeof(mac_buttons), 0, &mac_buttons) == noErr)
- buttons = qt_mac_get_buttons(mac_buttons);
- }
-
- // Send enter/leave events for the cases when QApplicationPrivate::sendMouseEvent do not:
- qt_mac_checkEnterLeaveForNativeWidgets(widgetUnderMouse);
-
- switch (eventType) {
- default:
- qWarning("not handled! %d", eventType);
- break;
- case QEvent::MouseMove:
- if (button == Qt::LeftButton && qt_leftButtonIsRightButton)
- button = Qt::RightButton;
- break;
- case QEvent::MouseButtonPress:
- qt_button_down = widgetUnderMouse;
- if (clickCount % 2 == 0 && (previousButton == Qt::NoButton || previousButton == button))
- eventType = QEvent::MouseButtonDblClick;
- if (button == Qt::LeftButton && (keyMods & Qt::MetaModifier)) {
- button = Qt::RightButton;
- qt_leftButtonIsRightButton = true;
- }
- break;
- case QEvent::MouseButtonRelease:
- if (button == Qt::LeftButton && qt_leftButtonIsRightButton) {
- button = Qt::RightButton;
- qt_leftButtonIsRightButton = false;
- }
- qt_button_down = 0;
- break;
- }
-
- qt_mac_updateCursorWithWidgetUnderMouse(widgetUnderMouse);
-
- DnDParams *dndParams = currentDnDParameters();
- dndParams->view = view;
- dndParams->theEvent = event;
- dndParams->globalPoint = globalPoint;
-
- // Send the mouse event:
- QMouseEvent qme(eventType, localPoint, globalPoint, button, buttons, keyMods);
- QApplicationPrivate::sendMouseEvent(
- widgetToGetMouse, &qme, widgetUnderMouse, nativeWidget,
- &qt_button_down, qt_last_mouse_receiver, true);
-
- if (eventType == QEvent::MouseButtonPress && button == Qt::RightButton) {
- QContextMenuEvent qcme(QContextMenuEvent::Mouse, localPoint, globalPoint, keyMods);
- qt_sendSpontaneousEvent(widgetToGetMouse, &qcme);
- }
-
- if (eventType == QEvent::MouseButtonRelease) {
- // A mouse button was released, which means that the implicit grab was
- // released. We therefore need to re-check if should send (delayed) enter leave events:
- // qt_button_down has now become NULL since the call at the top of the function. Also, since
- // the relase might have closed a window, we dont give the nativeWidget hint
- qt_mac_getTargetForMouseEvent(0, QEvent::None, localPoint, globalPoint, nativeWidget, &widgetUnderMouse);
- qt_mac_checkEnterLeaveForNativeWidgets(widgetUnderMouse);
- }
-
- previousButton = button;
- return true;
-}
-#endif
-
-bool qt_mac_handleTabletEvent(void * /*QCocoaView * */view, void * /*NSEvent * */tabletEvent)
-{
-#ifndef QT_MAC_USE_COCOA
- Q_UNUSED(view);
- Q_UNUSED(tabletEvent);
- return false;
-#else
- QT_MANGLE_NAMESPACE(QCocoaView) *theView = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(view);
- NSView *theNSView = static_cast<NSView *>(view);
- NSEvent *theTabletEvent = static_cast<NSEvent *>(tabletEvent);
-
- NSEventType eventType = [theTabletEvent type];
- if (eventType != NSTabletPoint && [theTabletEvent subtype] != NSTabletPointEventSubtype)
- return false; // Not a tablet event.
-
- NSPoint windowPoint = [theTabletEvent locationInWindow];
- NSPoint globalPoint = [[theTabletEvent window] convertBaseToScreen:windowPoint];
-
- QWidget *qwidget = [theView qt_qwidget];
- QWidget *widgetToGetMouse = qwidget;
- QWidget *popup = qAppInstance()->activePopupWidget();
- if (popup && popup != qwidget->window())
- widgetToGetMouse = popup;
-
- if (qt_mac_sendMacEventToWidget(widgetToGetMouse,
- static_cast<EventRef>(const_cast<void *>([theTabletEvent eventRef]))))
- return true;
- if (widgetToGetMouse != qwidget) {
- theNSView = qt_mac_nativeview_for(widgetToGetMouse);
- windowPoint = [[theNSView window] convertScreenToBase:globalPoint];
- }
- NSPoint localPoint = [theNSView convertPoint:windowPoint fromView:nil];
- // Tablet events do not handle WA_TransparentForMouseEvents ATM
- // In theory, people who set the WA_TransparentForMouseEvents attribute won't handle
- // tablet events either in which case they will fall into the mouse event case and get
- // them passed on. This will NOT handle the raw events, but that might not be a big problem.
-
- const QMacTabletHash *tabletHash = qt_mac_tablet_hash();
- if (!tabletHash->contains([theTabletEvent deviceID])) {
- qWarning("QCocoaView handleTabletEvent: This tablet device is unknown"
- " (received no proximity event for it). Discarding event.");
- return false;
- }
- const QTabletDeviceData &deviceData = tabletHash->value([theTabletEvent deviceID]);
-
-
- QEvent::Type qType;
- switch (eventType) {
- case NSLeftMouseDown:
- case NSRightMouseDown:
- qType = QEvent::TabletPress;
- break;
- case NSLeftMouseUp:
- case NSRightMouseUp:
- qType = QEvent::TabletRelease;
- break;
- case NSMouseMoved:
- case NSTabletPoint:
- case NSLeftMouseDragged:
- case NSRightMouseDragged:
- default:
- qType = QEvent::TabletMove;
- break;
- }
-
- qreal pressure;
- if (eventType != NSMouseMoved) {
- pressure = [theTabletEvent pressure];
- } else {
- pressure = 0.0;
- }
-
- NSPoint tilt = [theTabletEvent tilt];
- int xTilt = qRound(tilt.x * 60.0);
- int yTilt = qRound(tilt.y * -60.0);
- qreal tangentialPressure = 0;
- qreal rotation = 0;
- int z = 0;
- if (deviceData.capabilityMask & 0x0200)
- z = [theTabletEvent absoluteZ];
-
- if (deviceData.capabilityMask & 0x0800)
- tangentialPressure = [theTabletEvent tangentialPressure];
-
- rotation = [theTabletEvent rotation];
- QPointF hiRes = flipPoint(globalPoint);
- QTabletEvent qtabletEvent(qType, QPoint(localPoint.x, localPoint.y),
- hiRes.toPoint(), hiRes,
- deviceData.tabletDeviceType, deviceData.tabletPointerType,
- pressure, xTilt, yTilt, tangentialPressure, rotation, z,
- qt_cocoaModifiers2QtModifiers([theTabletEvent modifierFlags]),
- deviceData.tabletUniqueID);
-
- qt_sendSpontaneousEvent(widgetToGetMouse, &qtabletEvent);
- return qtabletEvent.isAccepted();
-#endif
-}
-
-void qt_mac_updateContentBorderMetricts(void * /*OSWindowRef */window, const ::HIContentBorderMetrics &metrics)
-{
- OSWindowRef theWindow = static_cast<OSWindowRef>(window);
-#if !defined(QT_MAC_USE_COCOA)
-# if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
- ::HIWindowSetContentBorderThickness(theWindow, &metrics);
- }
-# else
- Q_UNUSED(window);
- Q_UNUSED(metrics);
-# endif
-#else
- if ([theWindow styleMask] & NSTexturedBackgroundWindowMask)
- [theWindow setContentBorderThickness:metrics.top forEdge:NSMaxYEdge];
- [theWindow setContentBorderThickness:metrics.bottom forEdge:NSMinYEdge];
-#endif
-}
-
-#if QT_MAC_USE_COCOA
-void qt_mac_replaceDrawRect(void * /*OSWindowRef */window, QWidgetPrivate *widget)
-{
- QMacCocoaAutoReleasePool pool;
- OSWindowRef theWindow = static_cast<OSWindowRef>(window);
- if(!theWindow)
- return;
- id theClass = [[[theWindow contentView] superview] class];
- // What we do here is basically to add a new selector to NSThemeFrame called
- // "drawRectOriginal:" which will contain the original implementation of
- // "drawRect:". After that we get the new implementation from QCocoaWindow
- // and exchange them. The new implementation is called drawRectSpecial.
- // We cannot just add the method because it might have been added before and since
- // we cannot remove a method once it has been added we need to ask QCocoaWindow if
- // we did the swap or not.
- if(!widget->drawRectOriginalAdded) {
- Method m2 = class_getInstanceMethod(theClass, @selector(drawRect:));
- if(!m2) {
- // This case is pretty extreme, no drawRect means no drawing!
- return;
- }
- class_addMethod(theClass, @selector(drawRectOriginal:), method_getImplementation(m2), method_getTypeEncoding(m2));
- widget->drawRectOriginalAdded = true;
- }
- if(widget->originalDrawMethod) {
- Method m0 = class_getInstanceMethod([theWindow class], @selector(drawRectSpecial:));
- if(!m0) {
- // Ok, this means the methods were never swapped. Just ignore
- return;
- }
- Method m1 = class_getInstanceMethod(theClass, @selector(drawRect:));
- if(!m1) {
- // Ok, this means the methods were never swapped. Just ignore
- return;
- }
- // We have the original method here. Proceed and swap the methods.
- method_exchangeImplementations(m1, m0);
- widget->originalDrawMethod = false;
- [theWindow display];
- }
-}
-
-void qt_mac_replaceDrawRectOriginal(void * /*OSWindowRef */window, QWidgetPrivate *widget)
-{
- QMacCocoaAutoReleasePool pool;
- OSWindowRef theWindow = static_cast<OSWindowRef>(window);
- id theClass = [[[theWindow contentView] superview] class];
- // Now we need to revert the methods to their original state.
- // We cannot remove the method, so we just keep track of it in QCocoaWindow.
- Method m0 = class_getInstanceMethod([theWindow class], @selector(drawRectSpecial:));
- if(!m0) {
- // Ok, this means the methods were never swapped. Just ignore
- return;
- }
- Method m1 = class_getInstanceMethod(theClass, @selector(drawRect:));
- if(!m1) {
- // Ok, this means the methods were never swapped. Just ignore
- return;
- }
- method_exchangeImplementations(m1, m0);
- widget->originalDrawMethod = true;
- [theWindow display];
-}
-#endif // QT_MAC_USE_COCOA
-
-#if QT_MAC_USE_COCOA
-void qt_mac_showBaseLineSeparator(void * /*OSWindowRef */window, bool show)
-{
- if(!window)
- return;
- QMacCocoaAutoReleasePool pool;
- OSWindowRef theWindow = static_cast<OSWindowRef>(window);
- NSToolbar *macToolbar = [theWindow toolbar];
- [macToolbar setShowsBaselineSeparator:show];
-}
-#endif // QT_MAC_USE_COCOA
-
-QStringList qt_mac_NSArrayToQStringList(void *nsarray)
-{
- QStringList result;
- NSArray *array = static_cast<NSArray *>(nsarray);
- for (NSUInteger i=0; i<[array count]; ++i)
- result << qt_mac_NSStringToQString([array objectAtIndex:i]);
- return result;
-}
-
-void *qt_mac_QStringListToNSMutableArrayVoid(const QStringList &list)
-{
- NSMutableArray *result = [NSMutableArray arrayWithCapacity:list.size()];
- for (int i=0; i<list.size(); ++i){
- [result addObject:reinterpret_cast<const NSString *>(QCFString::toCFStringRef(list[i]))];
- }
- return result;
-}
-
-#if QT_MAC_USE_COCOA
-void qt_syncCocoaTitleBarButtons(OSWindowRef window, QWidget *widgetForWindow)
-{
- if (!widgetForWindow)
- return;
-
- Qt::WindowFlags flags = widgetForWindow->windowFlags();
- bool customize = flags & Qt::CustomizeWindowHint;
-
- NSButton *btn = [window standardWindowButton:NSWindowZoomButton];
- // BOOL is not an int, so the bitwise AND doesn't work.
- bool go = uint(customize && !(flags & Qt::WindowMaximizeButtonHint)) == 0;
- [btn setEnabled:go];
-
- btn = [window standardWindowButton:NSWindowMiniaturizeButton];
- go = uint(customize && !(flags & Qt::WindowMinimizeButtonHint)) == 0;
- [btn setEnabled:go];
-
- btn = [window standardWindowButton:NSWindowCloseButton];
- go = uint(customize && !(flags & Qt::WindowSystemMenuHint
- || flags & Qt::WindowCloseButtonHint)) == 0;
- [btn setEnabled:go];
-
- [window setShowsToolbarButton:uint(flags & Qt::MacWindowToolBarButtonHint) != 0];
-}
-#endif // QT_MAC_USE_COCOA
-
-// Carbon: Make sure you call QDEndContext on the context when done with it.
-CGContextRef qt_mac_graphicsContextFor(QWidget *widget)
-{
- if (!widget)
- return 0;
-
-#ifndef QT_MAC_USE_COCOA
- CGContextRef context;
- CGrafPtr port = GetWindowPort(qt_mac_window_for(widget));
- QDBeginCGContext(port, &context);
-#else
- CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithWindow:qt_mac_window_for(widget)] graphicsPort];
-#endif
- return context;
-}
-
-void qt_mac_dispatchPendingUpdateRequests(QWidget *widget)
-{
- if (!widget)
- return;
-#ifndef QT_MAC_USE_COCOA
- HIViewRender(qt_mac_nativeview_for(widget));
-#else
- [qt_mac_nativeview_for(widget) displayIfNeeded];
-#endif
-}
-
-CGFloat qt_mac_get_scalefactor()
-{
-#ifndef QT_MAC_USE_COCOA
- return HIGetScaleFactor();
-#else
- return [[NSScreen mainScreen] userSpaceScaleFactor];
-#endif
-}
-
-QString qt_mac_get_pasteboardString(OSPasteboardRef paste)
-{
- QMacCocoaAutoReleasePool pool;
- NSPasteboard *pb = nil;
- CFStringRef pbname;
- if (PasteboardCopyName(paste, &pbname) == noErr) {
- pb = [NSPasteboard pasteboardWithName:const_cast<NSString *>(reinterpret_cast<const NSString *>(pbname))];
- CFRelease(pbname);
- } else {
- pb = [NSPasteboard generalPasteboard];
- }
- if (pb) {
- NSString *text = [pb stringForType:NSStringPboardType];
- if (text)
- return qt_mac_NSStringToQString(text);
- }
- return QString();
-}
-
-QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height)
-{
- QPixmap ret(width, height);
- ret.fill(QColor(0, 0, 0, 0));
-
- CGRect rect = CGRectMake(0, 0, width, height);
-
- CGContextRef ctx = qt_mac_cg_context(&ret);
- CGAffineTransform old_xform = CGContextGetCTM(ctx);
- CGContextConcatCTM(ctx, CGAffineTransformInvert(old_xform));
- CGContextConcatCTM(ctx, CGAffineTransformIdentity);
-
- ::RGBColor b;
- b.blue = b.green = b.red = 255*255;
- PlotIconRefInContext(ctx, &rect, kAlignNone, kTransformNone, &b, kPlotIconRefNormalFlags, icon);
- CGContextRelease(ctx);
- return ret;
-}
-
-void qt_mac_constructQIconFromIconRef(const IconRef icon, const IconRef overlayIcon, QIcon *retIcon, QStyle::StandardPixmap standardIcon)
-{
- int size = 16;
- while (size <= 128) {
-
- const QString cacheKey = QLatin1String("qt_mac_constructQIconFromIconRef") + QString::number(standardIcon) + QString::number(size);
- QPixmap mainIcon;
- if (standardIcon >= QStyle::SP_CustomBase) {
- mainIcon = qt_mac_convert_iconref(icon, size, size);
- } else if (QPixmapCache::find(cacheKey, mainIcon) == false) {
- mainIcon = qt_mac_convert_iconref(icon, size, size);
- QPixmapCache::insert(cacheKey, mainIcon);
- }
-
- if (overlayIcon) {
- int littleSize = size / 2;
- QPixmap overlayPix = qt_mac_convert_iconref(overlayIcon, littleSize, littleSize);
- QPainter painter(&mainIcon);
- painter.drawPixmap(size - littleSize, size - littleSize, overlayPix);
- }
-
- retIcon->addPixmap(mainIcon);
- size += size; // 16 -> 32 -> 64 -> 128
- }
-}
-
-#ifdef QT_MAC_USE_COCOA
-void qt_mac_menu_collapseSeparators(void */*NSMenu **/ theMenu, bool collapse)
-{
- QMacCocoaAutoReleasePool pool;
- OSMenuRef menu = static_cast<OSMenuRef>(theMenu);
- if (collapse) {
- bool previousIsSeparator = true; // setting to true kills all the separators placed at the top.
- NSMenuItem *previousItem = nil;
-
- NSArray *itemArray = [menu itemArray];
- for (unsigned int i = 0; i < [itemArray count]; ++i) {
- NSMenuItem *item = reinterpret_cast<NSMenuItem *>([itemArray objectAtIndex:i]);
- if ([item isSeparatorItem]) {
- [item setHidden:previousIsSeparator];
- }
-
- if (![item isHidden]) {
- previousItem = item;
- previousIsSeparator = ([previousItem isSeparatorItem]);
- }
- }
-
- // We now need to check the final item since we don't want any separators at the end of the list.
- if (previousItem && previousIsSeparator)
- [previousItem setHidden:YES];
- } else {
- NSArray *itemArray = [menu itemArray];
- for (unsigned int i = 0; i < [itemArray count]; ++i) {
- NSMenuItem *item = reinterpret_cast<NSMenuItem *>([itemArray objectAtIndex:i]);
- if (QAction *action = reinterpret_cast<QAction *>([item tag]))
- [item setHidden:!action->isVisible()];
- }
- }
-}
-
-class CocoaPostMessageAfterEventLoopExitHelp : public QObject
-{
- id target;
- SEL selector;
- int argCount;
- id arg1;
- id arg2;
-public:
- CocoaPostMessageAfterEventLoopExitHelp(id target, SEL selector, int argCount, id arg1, id arg2)
- : target(target), selector(selector), argCount(argCount), arg1(arg1), arg2(arg2){
- deleteLater();
- }
-
- ~CocoaPostMessageAfterEventLoopExitHelp()
- {
- qt_cocoaPostMessage(target, selector, argCount, arg1, arg2);
- }
-};
-
-void qt_cocoaPostMessage(id target, SEL selector, int argCount, id arg1, id arg2)
-{
- // WARNING: data1 and data2 is truncated to from 64-bit to 32-bit on OS 10.5!
- // That is why we need to split the address in two parts:
- QCocoaPostMessageArgs *args = new QCocoaPostMessageArgs(target, selector, argCount, arg1, arg2);
- quint32 lower = quintptr(args);
- quint32 upper = quintptr(args) >> 32;
- NSEvent *e = [NSEvent otherEventWithType:NSApplicationDefined
- location:NSZeroPoint modifierFlags:0 timestamp:0 windowNumber:0
- context:nil subtype:QtCocoaEventSubTypePostMessage data1:lower data2:upper];
- [NSApp postEvent:e atStart:NO];
-}
-
-void qt_cocoaPostMessageAfterEventLoopExit(id target, SEL selector, int argCount, id arg1, id arg2)
-{
- if (QApplicationPrivate::instance()->threadData->eventLoops.size() <= 1)
- qt_cocoaPostMessage(target, selector, argCount, arg1, arg2);
- else
- new CocoaPostMessageAfterEventLoopExitHelp(target, selector, argCount, arg1, arg2);
-}
-
-#endif
-
-QMacCocoaAutoReleasePool::QMacCocoaAutoReleasePool()
-{
-#ifndef QT_MAC_USE_COCOA
- NSApplicationLoad();
-#endif
- pool = (void*)[[NSAutoreleasePool alloc] init];
-}
-
-QMacCocoaAutoReleasePool::~QMacCocoaAutoReleasePool()
-{
- [(NSAutoreleasePool*)pool release];
-}
-
-void qt_mac_post_retranslateAppMenu()
-{
-#ifdef QT_MAC_USE_COCOA
- QMacCocoaAutoReleasePool pool;
- qt_cocoaPostMessage([NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)], @selector(qtTranslateApplicationMenu));
-#endif
-}
-
-QWidgetPrivate *QMacScrollOptimization::_target = 0;
-bool QMacScrollOptimization::_inWheelEvent = false;
-int QMacScrollOptimization::_dx = 0;
-int QMacScrollOptimization::_dy = 0;
-QRect QMacScrollOptimization::_scrollRect = QRect(0, 0, -1, -1);
-
-#ifdef QT_MAC_USE_COCOA
-// This method implements the magic for the drawRectSpecial method.
-// We draw a line at the upper edge of the content view in order to
-// override the title baseline.
-void macDrawRectOnTop(void * /*OSWindowRef */window)
-{
- OSWindowRef theWindow = static_cast<OSWindowRef>(window);
- NSView *contentView = [theWindow contentView];
- if(!contentView)
- return;
- // Get coordinates of the content view
- NSRect contentRect = [contentView frame];
- // Draw a line on top of the already drawn line.
- // We need to check if we are active or not to use the proper color.
- if([theWindow isKeyWindow] || [theWindow isMainWindow]) {
- [[NSColor colorWithCalibratedRed:1.0 green:1.0 blue:1.0 alpha:1.0] set];
- } else {
- [[NSColor colorWithCalibratedRed:1.0 green:1.0 blue:1.0 alpha:1.0] set];
- }
- NSPoint origin = NSMakePoint(0, contentRect.size.height);
- NSPoint end = NSMakePoint(contentRect.size.width, contentRect.size.height);
- [NSBezierPath strokeLineFromPoint:origin toPoint:end];
-}
-
-// This method will (or at least should) get called only once.
-// Its mission is to find out if we are active or not. If we are active
-// we assume that we were launched via finder, otherwise we assume
-// we were called from the command line. The distinction is important,
-// since in the first case we don't need to trigger a paintEvent, while
-// in the second case we do.
-void macSyncDrawingOnFirstInvocation(void * /*OSWindowRef */window)
-{
- OSWindowRef theWindow = static_cast<OSWindowRef>(window);
- NSApplication *application = [NSApplication sharedApplication];
- NSToolbar *toolbar = [theWindow toolbar];
- if([application isActive]) {
- // Launched from finder
- [toolbar setShowsBaselineSeparator:NO];
- } else {
- // Launched from commandline
- [toolbar setVisible:false];
- [toolbar setShowsBaselineSeparator:NO];
- [toolbar setVisible:true];
- [theWindow display];
- }
-}
-
-void qt_cocoaStackChildWindowOnTopOfOtherChildren(QWidget *childWidget)
-{
- if (!childWidget)
- return;
-
- QWidget *parent = childWidget->parentWidget();
- if (childWidget->isWindow() && parent) {
- if ([[qt_mac_window_for(parent) childWindows] containsObject:qt_mac_window_for(childWidget)]) {
- QWidgetPrivate *d = qt_widget_private(childWidget);
- d->setSubWindowStacking(false);
- d->setSubWindowStacking(true);
- }
- }
-}
-
-void qt_mac_display(QWidget *widget)
-{
- NSView *theNSView = qt_mac_nativeview_for(widget);
- [theNSView display];
-}
-
-void qt_mac_setNeedsDisplay(QWidget *widget)
-{
- NSView *theNSView = qt_mac_nativeview_for(widget);
- [theNSView setNeedsDisplay:YES];
-}
-
-void qt_mac_setNeedsDisplayInRect(QWidget *widget, QRegion region)
-{
- NSView *theNSView = qt_mac_nativeview_for(widget);
- if (region.isEmpty()) {
- [theNSView setNeedsDisplay:YES];
- return;
- }
-
- QVector<QRect> rects = region.rects();
- for (int i = 0; i < rects.count(); ++i) {
- const QRect &rect = rects.at(i);
- NSRect nsrect = NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height());
- [theNSView setNeedsDisplayInRect:nsrect];
- }
-
-}
-
-#endif // QT_MAC_USE_COCOA
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qt_cocoa_helpers_mac_p.h b/src/gui/kernel/qt_cocoa_helpers_mac_p.h
deleted file mode 100644
index a49753ae2f..0000000000
--- a/src/gui/kernel/qt_cocoa_helpers_mac_p.h
+++ /dev/null
@@ -1,340 +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$
-**
-****************************************************************************/
-
-/****************************************************************************
-**
-** Copyright (c) 2007-2008, Apple, Inc.
-**
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-**
-** * Redistributions of source code must retain the above copyright notice,
-** this list of conditions and the following disclaimer.
-**
-** * Redistributions in binary form must reproduce the above copyright notice,
-** this list of conditions and the following disclaimer in the documentation
-** and/or other materials provided with the distribution.
-**
-** * Neither the name of Apple, Inc. nor the names of its contributors
-** may be used to endorse or promote products derived from this software
-** without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-****************************************************************************/
-
-#ifndef QT_COCOA_HELPERS_MAC_P_H
-#define QT_COCOA_HELPERS_MAC_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of qapplication_*.cpp, qwidget*.cpp, qcolor_x11.cpp, qfiledialog.cpp
-// and many other. This header file may change from version to version
-// without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qt_mac_p.h>
-
-#include <qapplication.h>
-#include <qdesktopwidget.h>
-#include <qwidget.h>
-#include <qevent.h>
-#include <qhash.h>
-#include <qlabel.h>
-#include <qpointer.h>
-#include <qstyle.h>
-#include <qstyleoption.h>
-#include <qstylepainter.h>
-#include <qtimer.h>
-#include <qtooltip.h>
-#include <private/qeffects_p.h>
-#include <private/qwidget_p.h>
-#include <qtextdocument.h>
-#include <qdebug.h>
-#include <qpoint.h>
-#include "private/qt_mac_p.h"
-
-struct HIContentBorderMetrics;
-
-#ifdef Q_WS_MAC32
-typedef struct _NSPoint NSPoint; // Just redefine here so I don't have to pull in all of Cocoa.
-#else
-typedef struct CGPoint NSPoint;
-#endif
-
-QT_BEGIN_NAMESPACE
-
-enum {
- QtCocoaEventSubTypeWakeup = SHRT_MAX,
- QtCocoaEventSubTypePostMessage = SHRT_MAX-1
-};
-
-Qt::MouseButtons qt_mac_get_buttons(int buttons);
-Qt::MouseButton qt_mac_get_button(EventMouseButton button);
-void macWindowFade(void * /*OSWindowRef*/ window, float durationSeconds = 0.15);
-bool macWindowIsTextured(void * /*OSWindowRef*/ window);
-void macWindowToolbarShow(const QWidget *widget, bool show );
-void macWindowToolbarSet( void * /*OSWindowRef*/ window, void* toolbarRef );
-bool macWindowToolbarIsVisible( void * /*OSWindowRef*/ window );
-void macWindowSetHasShadow( void * /*OSWindowRef*/ window, bool hasShadow );
-void macWindowFlush(void * /*OSWindowRef*/ window);
-void macSendToolbarChangeEvent(QWidget *widget);
-void qt_mac_updateContentBorderMetricts(void * /*OSWindowRef */window, const ::HIContentBorderMetrics &metrics);
-void qt_mac_replaceDrawRect(void * /*OSWindowRef */window, QWidgetPrivate *widget);
-void qt_mac_replaceDrawRectOriginal(void * /*OSWindowRef */window, QWidgetPrivate *widget);
-void qt_mac_showBaseLineSeparator(void * /*OSWindowRef */window, bool show);
-void * /*NSImage */qt_mac_create_nsimage(const QPixmap &pm);
-void qt_mac_update_mouseTracking(QWidget *widget);
-OSStatus qt_mac_drawCGImage(CGContextRef cg, const CGRect *inbounds, CGImageRef);
-bool qt_mac_checkForNativeSizeGrip(const QWidget *widget);
-void qt_dispatchTabletProximityEvent(void * /*NSEvent * */ tabletEvent);
-#ifdef QT_MAC_USE_COCOA
-bool qt_dispatchKeyEventWithCocoa(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent);
-// These methods exists only for supporting unified mode.
-void macDrawRectOnTop(void * /*OSWindowRef */ window);
-void macSyncDrawingOnFirstInvocation(void * /*OSWindowRef */window);
-void qt_cocoaStackChildWindowOnTopOfOtherChildren(QWidget *widget);
-void qt_mac_menu_collapseSeparators(void * /*NSMenu */ menu, bool collapse);
-#endif
-bool qt_dispatchKeyEvent(void * /*NSEvent * */ keyEvent, QWidget *widgetToGetEvent);
-void qt_dispatchModifiersChanged(void * /*NSEvent * */flagsChangedEvent, QWidget *widgetToGetEvent);
-bool qt_mac_handleTabletEvent(void * /*QCocoaView * */view, void * /*NSEvent * */event);
-inline QApplication *qAppInstance() { return static_cast<QApplication *>(QCoreApplication::instance()); }
-struct ::TabletProximityRec;
-void qt_dispatchTabletProximityEvent(const ::TabletProximityRec &proxRec);
-Qt::KeyboardModifiers qt_cocoaModifiers2QtModifiers(ulong modifierFlags);
-Qt::KeyboardModifiers qt_cocoaDragOperation2QtModifiers(uint dragOperations);
-QPixmap qt_mac_convert_iconref(const IconRef icon, int width, int height);
-void qt_mac_constructQIconFromIconRef(const IconRef icon, const IconRef overlayIcon, QIcon *retIcon,
- QStyle::StandardPixmap standardIcon = QStyle::SP_CustomBase);
-
-#if QT_MAC_USE_COCOA && __OBJC__
-struct DnDParams
-{
- NSView *view;
- NSEvent *theEvent;
- QPoint globalPoint;
- NSDragOperation performedAction;
-};
-
-DnDParams *macCurrentDnDParameters();
-NSDragOperation qt_mac_mapDropAction(Qt::DropAction action);
-NSDragOperation qt_mac_mapDropActions(Qt::DropActions actions);
-Qt::DropAction qt_mac_mapNSDragOperation(NSDragOperation nsActions);
-Qt::DropActions qt_mac_mapNSDragOperations(NSDragOperation nsActions);
-
-QWidget *qt_mac_getTargetForKeyEvent(QWidget *widgetThatReceivedEvent);
-QWidget *qt_mac_getTargetForMouseEvent(NSEvent *event, QEvent::Type eventType,
- QPoint &returnLocalPoint, QPoint &returnGlobalPoint, QWidget *nativeWidget, QWidget **returnWidgetUnderMouse);
-bool qt_mac_handleMouseEvent(NSEvent *event, QEvent::Type eventType, Qt::MouseButton button, QWidget *nativeWidget);
-void qt_mac_handleNonClientAreaMouseEvent(NSWindow *window, NSEvent *event);
-#endif
-
-inline int flipYCoordinate(int y)
-{
- return QApplication::desktop()->screenGeometry(0).height() - y;
-}
-
-inline qreal flipYCoordinate(qreal y)
-{
- return QApplication::desktop()->screenGeometry(0).height() - y;
-}
-
-QPointF flipPoint(const NSPoint &p);
-NSPoint flipPoint(const QPoint &p);
-NSPoint flipPoint(const QPointF &p);
-
-QStringList qt_mac_NSArrayToQStringList(void *nsarray);
-void *qt_mac_QStringListToNSMutableArrayVoid(const QStringList &list);
-
-void qt_syncCocoaTitleBarButtons(OSWindowRef window, QWidget *widgetForWindow);
-
-CGFloat qt_mac_get_scalefactor();
-QString qt_mac_get_pasteboardString(OSPasteboardRef paste);
-
-#ifdef __OBJC__
-inline NSMutableArray *qt_mac_QStringListToNSMutableArray(const QStringList &qstrlist)
-{ return reinterpret_cast<NSMutableArray *>(qt_mac_QStringListToNSMutableArrayVoid(qstrlist)); }
-
-inline QString qt_mac_NSStringToQString(const NSString *nsstr)
-{ return QCFString::toQString(reinterpret_cast<const CFStringRef>(nsstr)); }
-
-inline NSString *qt_mac_QStringToNSString(const QString &qstr)
-{ return [reinterpret_cast<const NSString *>(QCFString::toCFStringRef(qstr)) autorelease]; }
-
-#ifdef QT_MAC_USE_COCOA
-class QCocoaPostMessageArgs {
-public:
- id target;
- SEL selector;
- int argCount;
- id arg1;
- id arg2;
- QCocoaPostMessageArgs(id target, SEL selector, int argCount=0, id arg1=0, id arg2=0)
- : target(target), selector(selector), argCount(argCount), arg1(arg1), arg2(arg2)
- {
- [target retain];
- [arg1 retain];
- [arg2 retain];
- }
-
- ~QCocoaPostMessageArgs()
- {
- [arg2 release];
- [arg1 release];
- [target release];
- }
-};
-void qt_cocoaPostMessage(id target, SEL selector, int argCount=0, id arg1=0, id arg2=0);
-void qt_cocoaPostMessageAfterEventLoopExit(id target, SEL selector, int argCount=0, id arg1=0, id arg2=0);
-#endif
-
-#endif
-
-class QMacScrollOptimization {
- // This class is made to optimize for the case when the user
- // scrolls both horizontally and vertically at the same
- // time. This will result in two QWheelEvents (one for each
- // direction), which will typically result in two calls to
- // QWidget::_scroll_sys. Rather than copying pixels twize on
- // screen because of this, we add this helper class to try to
- // get away with only one blit.
- static QWidgetPrivate *_target;
- static bool _inWheelEvent;
- static int _dx;
- static int _dy;
- static QRect _scrollRect;
-
-public:
- static void initDelayedScroll()
- {
- _inWheelEvent = true;
- }
-
- static bool delayScroll(QWidgetPrivate *target, int dx, int dy, const QRect &scrollRect)
- {
- if (!_inWheelEvent)
- return false;
- if (_target && _target != target)
- return false;
- if (_scrollRect.width() != -1 && _scrollRect != scrollRect)
- return false;
-
- _target = target;
- _dx += dx;
- _dy += dy;
- _scrollRect = scrollRect;
- return true;
- }
-
- static void performDelayedScroll()
- {
- if (!_inWheelEvent)
- return;
- _inWheelEvent = false;
- if (!_target)
- return;
-
- _target->scroll_sys(_dx, _dy, _scrollRect);
-
- _target = 0;
- _dx = 0;
- _dy = 0;
- _scrollRect = QRect(0, 0, -1, -1);
- }
-};
-
-void qt_mac_post_retranslateAppMenu();
-
-#ifdef QT_MAC_USE_COCOA
-void qt_mac_display(QWidget *widget);
-void qt_mac_setNeedsDisplay(QWidget *widget);
-void qt_mac_setNeedsDisplayInRect(QWidget *widget, QRegion region);
-#endif // QT_MAC_USE_COCOA
-
-
-// Utility functions to ease the use of Core Graphics contexts.
-
-inline void qt_mac_retain_graphics_context(CGContextRef context)
-{
- CGContextRetain(context);
- CGContextSaveGState(context);
-}
-
-inline void qt_mac_release_graphics_context(CGContextRef context)
-{
- CGContextRestoreGState(context);
- CGContextRelease(context);
-}
-
-inline void qt_mac_draw_image(CGContextRef context, CGContextRef imageContext, CGRect area, CGRect drawingArea)
-{
- CGImageRef image = CGBitmapContextCreateImage(imageContext);
- CGImageRef subImage = CGImageCreateWithImageInRect(image, area);
-
- CGContextTranslateCTM (context, 0, drawingArea.origin.y + CGRectGetMaxY(drawingArea));
- CGContextScaleCTM(context, 1, -1);
- CGContextDrawImage(context, drawingArea, subImage);
-
- CGImageRelease(subImage);
- CGImageRelease(image);
-}
-
-QT_END_NAMESPACE
-
-#endif // QT_COCOA_HELPERS_MAC_P_H
diff --git a/src/gui/kernel/qt_mac.cpp b/src/gui/kernel/qt_mac.cpp
deleted file mode 100644
index 046bcf6a54..0000000000
--- a/src/gui/kernel/qt_mac.cpp
+++ /dev/null
@@ -1,174 +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/qt_mac_p.h>
-#include <private/qpixmap_mac_p.h>
-#include <private/qnativeimage_p.h>
-#include <qdebug.h>
-
-QT_BEGIN_NAMESPACE
-#ifdef QT_MAC_USE_COCOA
-static CTFontRef CopyCTThemeFont(ThemeFontID themeID)
-{
- CTFontUIFontType ctID = HIThemeGetUIFontType(themeID);
- return CTFontCreateUIFontForLanguage(ctID, 0, 0);
-}
-#endif
-
-QFont qfontForThemeFont(ThemeFontID themeID)
-{
-#ifndef QT_MAC_USE_COCOA
- static const ScriptCode Script = smRoman;
- Str255 f_name;
- SInt16 f_size;
- Style f_style;
- GetThemeFont(themeID, Script, f_name, &f_size, &f_style);
- extern QString qt_mac_from_pascal_string(const Str255); //qglobal.cpp
- return QFont(qt_mac_from_pascal_string(f_name), f_size,
- (f_style & ::bold) ? QFont::Bold : QFont::Normal,
- (bool)(f_style & ::italic));
-#else
- QCFType<CTFontRef> ctfont = CopyCTThemeFont(themeID);
- QString familyName = QCFString(CTFontCopyFamilyName(ctfont));
- QCFType<CFDictionaryRef> dict = CTFontCopyTraits(ctfont);
- CFNumberRef num = static_cast<CFNumberRef>(CFDictionaryGetValue(dict, kCTFontWeightTrait));
- float fW;
- CFNumberGetValue(num, kCFNumberFloat32Type, &fW);
- QFont::Weight wght = fW > 0. ? QFont::Bold : QFont::Normal;
- num = static_cast<CFNumberRef>(CFDictionaryGetValue(dict, kCTFontSlantTrait));
- CFNumberGetValue(num, kCFNumberFloatType, &fW);
- bool italic = (fW != 0.0);
- return QFont(familyName, CTFontGetSize(ctfont), wght, italic);
-#endif
-}
-
-#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
-static QColor qcolorFromCGColor(CGColorRef cgcolor)
-{
- QColor pc;
- CGColorSpaceModel model = CGColorSpaceGetModel(CGColorGetColorSpace(cgcolor));
- const CGFloat *components = CGColorGetComponents(cgcolor);
- if (model == kCGColorSpaceModelRGB) {
- pc.setRgbF(components[0], components[1], components[2], components[3]);
- } else if (model == kCGColorSpaceModelCMYK) {
- pc.setCmykF(components[0], components[1], components[2], components[3]);
- } else if (model == kCGColorSpaceModelMonochrome) {
- pc.setRgbF(components[0], components[0], components[0], components[1]);
- } else {
- // Colorspace we can't deal with.
- qWarning("Qt: qcolorFromCGColor: cannot convert from colorspace model: %d", model);
- Q_ASSERT(false);
- }
- return pc;
-}
-
-static inline QColor leopardBrush(ThemeBrush brush)
-{
- QCFType<CGColorRef> cgClr = 0;
- HIThemeBrushCreateCGColor(brush, &cgClr);
- return qcolorFromCGColor(cgClr);
-}
-#endif
-
-QColor qcolorForTheme(ThemeBrush brush)
-{
-#ifndef QT_MAC_USE_COCOA
-# if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
- if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
- return leopardBrush(brush);
- } else
-# endif
- {
- RGBColor rgbcolor;
- GetThemeBrushAsColor(brush, 32, true, &rgbcolor);
- return QColor(rgbcolor.red / 256, rgbcolor.green / 256, rgbcolor.blue / 256);
- }
-#else
- return leopardBrush(brush);
-#endif
-}
-
-QColor qcolorForThemeTextColor(ThemeTextColor themeColor)
-{
-#ifdef Q_OS_MAC32
- RGBColor c;
- GetThemeTextColor(themeColor, 32, true, &c);
- QColor color = QColor(c.red / 256, c.green / 256, c.blue / 256);
- return color;
-#else
- // There is no equivalent to GetThemeTextColor in 64-bit and it was rather bad that
- // I didn't file a request to implement this for Snow Leopard. So, in the meantime
- // I've encoded the values from the GetThemeTextColor. This is not exactly ideal
- // as if someone really wants to mess with themeing, these colors will be wrong.
- // It also means that we need to make sure the values for differences between
- // OS releases (and it will be likely that we are a step behind.)
- switch (themeColor) {
- case kThemeTextColorAlertActive:
- case kThemeTextColorTabFrontActive:
- case kThemeTextColorBevelButtonActive:
- case kThemeTextColorListView:
- case kThemeTextColorPlacardActive:
- case kThemeTextColorPopupButtonActive:
- case kThemeTextColorPopupLabelActive:
- case kThemeTextColorPushButtonActive:
- return Qt::black;
- case kThemeTextColorAlertInactive:
- case kThemeTextColorDialogInactive:
- case kThemeTextColorPlacardInactive:
- return QColor(69, 69, 69, 255);
- case kThemeTextColorPopupButtonInactive:
- case kThemeTextColorPopupLabelInactive:
- case kThemeTextColorPushButtonInactive:
- case kThemeTextColorTabFrontInactive:
- case kThemeTextColorBevelButtonInactive:
- return QColor(127, 127, 127, 255);
- default: {
- QNativeImage nativeImage(16,16, QNativeImage::systemFormat());
- CGRect cgrect = CGRectMake(0, 0, 16, 16);
- HIThemeSetTextFill(themeColor, 0, nativeImage.cg, kHIThemeOrientationNormal);
- CGContextFillRect(nativeImage.cg, cgrect);
- QColor color = nativeImage.image.pixel(0,0);
- return QColor(nativeImage.image.pixel(0 , 0));
- }
- }
-#endif
-}
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qt_mac_p.h b/src/gui/kernel/qt_mac_p.h
deleted file mode 100644
index b2bb804ff0..0000000000
--- a/src/gui/kernel/qt_mac_p.h
+++ /dev/null
@@ -1,286 +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 QT_MAC_P_H
-#define QT_MAC_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 "qmacdefines_mac.h"
-
-#ifdef __OBJC__
-#include <Cocoa/Cocoa.h>
-#ifdef QT_MAC_USE_COCOA
-#include <objc/runtime.h>
-#endif // QT_MAC_USE_COCOA
-#endif
-
-#include <CoreServices/CoreServices.h>
-
-#include "QtCore/qglobal.h"
-#include "QtCore/qvariant.h"
-#include "QtCore/qmimedata.h"
-#include "QtCore/qpointer.h"
-#include "private/qcore_mac_p.h"
-
-
-#include "QtGui/qpainter.h"
-
-#include <Carbon/Carbon.h>
-
-QT_BEGIN_NAMESPACE
-class QWidget;
-class QDragMoveEvent;
-
-/* Event masks */
-// internal Qt types
-
- // Event class for our own Carbon events.
-#if defined(QT_NAMESPACE) && defined(QT_NAMESPACE_MAC_CRC)
-// Take the CRC we generated at configure time. This *may* result in a
-// collision with another value If that is the case, please change the value
-// here to something other than 'Cute'.
-const UInt32 kEventClassQt = QT_NAMESPACE_MAC_CRC;
-#else
-const UInt32 kEventClassQt = 'Cute';
-#endif
-
-enum {
- //AE types
- typeAEClipboardChanged = 1,
- //types
- typeQWidget = 1, /* QWidget * */
- //params
- kEventParamQWidget = 'qwid', /* typeQWidget */
- //events
- kEventQtRequestContext = 13,
- kEventQtRequestMenubarUpdate = 14,
- kEventQtRequestShowSheet = 17,
- kEventQtRequestActivate = 18,
- kEventQtRequestWindowChange = 20
-};
-
-// Simple class to manage short-lived regions
-class QMacSmartQuickDrawRegion
-{
- RgnHandle qdRgn;
- Q_DISABLE_COPY(QMacSmartQuickDrawRegion)
-public:
- explicit QMacSmartQuickDrawRegion(RgnHandle rgn) : qdRgn(rgn) {}
- ~QMacSmartQuickDrawRegion() {
- extern void qt_mac_dispose_rgn(RgnHandle); // qregion_mac.cpp
- qt_mac_dispose_rgn(qdRgn);
- }
- operator RgnHandle() {
- return qdRgn;
- }
-};
-
-// Class for chaining to gether a bunch of fades. It pretty much is only used for qmenu fading.
-class QMacWindowFader
-{
- QWidgetList m_windowsToFade;
- float m_duration;
- Q_DISABLE_COPY(QMacWindowFader)
-public:
- QMacWindowFader(); // PLEASE DON'T CALL THIS.
- static QMacWindowFader *currentFader();
- void registerWindowToFade(QWidget *window);
- void setFadeDuration(float durationInSecs) { m_duration = durationInSecs; }
- float fadeDuration() const { return m_duration; }
- void performFade();
-};
-
-class Q_GUI_EXPORT QMacCocoaAutoReleasePool
-{
-private:
- void *pool;
-public:
- QMacCocoaAutoReleasePool();
- ~QMacCocoaAutoReleasePool();
-
- inline void *handle() const { return pool; }
-};
-
-QString qt_mac_removeMnemonics(const QString &original); //implemented in qmacstyle_mac.cpp
-
-class Q_GUI_EXPORT QMacWindowChangeEvent
-{
-private:
- static QList<QMacWindowChangeEvent*> *change_events;
-public:
- QMacWindowChangeEvent() {
- }
- virtual ~QMacWindowChangeEvent() {
- }
- static inline void exec(bool ) {
- }
-protected:
- virtual void windowChanged() = 0;
- virtual void flushWindowChanged() = 0;
-};
-
-class QMacCGContext
-{
- CGContextRef context;
-public:
- QMacCGContext(QPainter *p); //qpaintengine_mac.cpp
- inline QMacCGContext() { context = 0; }
- inline QMacCGContext(const QPaintDevice *pdev) {
- extern CGContextRef qt_mac_cg_context(const QPaintDevice *);
- context = qt_mac_cg_context(pdev);
- }
- inline QMacCGContext(CGContextRef cg, bool takeOwnership=false) {
- context = cg;
- if(!takeOwnership)
- CGContextRetain(context);
- }
- inline QMacCGContext(const QMacCGContext &copy) : context(0) { *this = copy; }
- inline ~QMacCGContext() {
- if(context)
- CGContextRelease(context);
- }
- inline bool isNull() const { return context; }
- inline operator CGContextRef() { return context; }
- inline QMacCGContext &operator=(const QMacCGContext &copy) {
- if(context)
- CGContextRelease(context);
- context = copy.context;
- CGContextRetain(context);
- return *this;
- }
- inline QMacCGContext &operator=(CGContextRef cg) {
- if(context)
- CGContextRelease(context);
- context = cg;
- CGContextRetain(context); //we do not take ownership
- return *this;
- }
-};
-
-class QMacPasteboardMime;
-class QMimeData;
-
-class QMacPasteboard
-{
- struct Promise {
- Promise() : itemId(0), convertor(0) { }
- Promise(int itemId, QMacPasteboardMime *c, QString m, QVariant d, int o=0) : itemId(itemId), offset(o), convertor(c), mime(m), data(d) { }
- int itemId, offset;
- QMacPasteboardMime *convertor;
- QString mime;
- QVariant data;
- };
- QList<Promise> promises;
-
- OSPasteboardRef paste;
- uchar mime_type;
- mutable QPointer<QMimeData> mime;
- mutable bool mac_mime_source;
- static OSStatus promiseKeeper(OSPasteboardRef, PasteboardItemID, CFStringRef, void *);
- void clear_helper();
-public:
- QMacPasteboard(OSPasteboardRef p, uchar mime_type=0);
- QMacPasteboard(uchar mime_type);
- QMacPasteboard(CFStringRef name=0, uchar mime_type=0);
- ~QMacPasteboard();
-
- bool hasFlavor(QString flavor) const;
- bool hasOSType(int c_flavor) const;
-
- OSPasteboardRef pasteBoard() const;
- QMimeData *mimeData() const;
- void setMimeData(QMimeData *mime);
-
- QStringList formats() const;
- bool hasFormat(const QString &format) const;
- QVariant retrieveData(const QString &format, QVariant::Type) const;
-
- void clear();
- bool sync() const;
-};
-
-extern QPaintDevice *qt_mac_safe_pdev; //qapplication_mac.cpp
-
-extern OSWindowRef qt_mac_window_for(const QWidget*); //qwidget_mac.mm
-extern OSViewRef qt_mac_nativeview_for(const QWidget *); //qwidget_mac.mm
-extern QPoint qt_mac_nativeMapFromParent(const QWidget *child, const QPoint &pt); //qwidget_mac.mm
-
-#ifdef check
-# undef check
-#endif
-
-QFont qfontForThemeFont(ThemeFontID themeID);
-
-QColor qcolorForTheme(ThemeBrush brush);
-
-QColor qcolorForThemeTextColor(ThemeTextColor themeColor);
-
-struct QMacDndAnswerRecord {
- QRect rect;
- Qt::KeyboardModifiers modifiers;
- Qt::MouseButtons buttons;
- Qt::DropAction lastAction;
- unsigned int lastOperation;
- void clear() {
- rect = QRect();
- modifiers = Qt::NoModifier;
- buttons = Qt::NoButton;
- lastAction = Qt::IgnoreAction;
- lastOperation = 0;
- }
-};
-extern QMacDndAnswerRecord qt_mac_dnd_answer_rec;
-void qt_mac_copy_answer_rect(const QDragMoveEvent &event);
-bool qt_mac_mouse_inside_answer_rect(QPoint mouse);
-
-QT_END_NAMESPACE
-
-#endif // QT_MAC_P_H
diff --git a/src/gui/kernel/qt_s60_p.h b/src/gui/kernel/qt_s60_p.h
deleted file mode 100644
index 8aba53a168..0000000000
--- a/src/gui/kernel/qt_s60_p.h
+++ /dev/null
@@ -1,625 +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 QT_S60_P_H
-#define QT_S60_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 "QtGui/qwindowdefs.h"
-#include "private/qcore_symbian_p.h"
-#include "qhash.h"
-#include "qpoint.h"
-#include "QtGui/qfont.h"
-#include "QtGui/qimage.h"
-#include "QtGui/qevent.h"
-#include "qpointer.h"
-#include "qapplication.h"
-#include "qelapsedtimer.h"
-#include "QtCore/qthreadstorage.h"
-#include "qwidget_p.h"
-#include <w32std.h>
-#include <coecntrl.h>
-#include <eikenv.h>
-#include <eikappui.h>
-
-#ifdef Q_WS_S60
-#include <AknUtils.h> // AknLayoutUtils
-#include <avkon.hrh> // EEikStatusPaneUidTitle
-#include <akntitle.h> // CAknTitlePane
-#include <akncontext.h> // CAknContextPane
-#include <eikspane.h> // CEikStatusPane
-#include <AknPopupFader.h> // MAknFadedComponent and TAknPopupFader
-#include <gfxtranseffect/gfxtranseffect.h> // BeginFullScreen
-#ifdef QT_SYMBIAN_HAVE_AKNTRANSEFFECT_H
-#include <akntranseffect.h> // BeginFullScreen
-#endif
-#endif
-
-QT_BEGIN_NAMESPACE
-
-// Application internal HandleResourceChangeL events,
-// system events seems to start with 0x10
-const TInt KInternalStatusPaneChange = 0x50000000;
-
-// For BeginFullScreen().
-const TUint KQtAppExitFlag = 0x400;
-
-static const int qt_symbian_max_screens = 4;
-
-//this macro exists because EColor16MAP enum value doesn't exist in Symbian OS 9.2
-#define Q_SYMBIAN_ECOLOR16MAP TDisplayMode(13)
-
-class Q_AUTOTEST_EXPORT QS60ThreadLocalData
-{
-public:
- QS60ThreadLocalData();
- ~QS60ThreadLocalData();
- bool usingCONEinstances;
- RWsSession wsSession;
- CWsScreenDevice *screenDevice;
-};
-
-class QS60Data
-{
-public:
- QS60Data();
- QThreadStorage<QS60ThreadLocalData *> tls;
- TUid uid;
- int screenDepth;
- QPoint lastCursorPos;
- QPoint lastPointerEventPos;
- QPointer<QWidget> lastPointerEventTarget;
- QPointer<QWidget> mousePressTarget;
- int screenWidthInPixels;
- int screenHeightInPixels;
- int screenWidthInTwips;
- int screenHeightInTwips;
- int defaultDpiX;
- int defaultDpiY;
- WId curWin;
- enum PressedKeys {
- Select = 0x1,
- Right = 0x2,
- Down = 0x4,
- Left = 0x8,
- Up = 0x10,
- LeftUp = 0x20,
- RightUp = 0x40,
- RightDown = 0x80,
- LeftDown = 0x100
- };
- int virtualMousePressedKeys; // of the above type, but avoids casting problems
- int virtualMouseAccelDX;
- int virtualMouseAccelDY;
- QElapsedTimer virtualMouseAccelTimeout;
- int virtualMouseMaxAccel;
-#ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
- int brokenPointerCursors : 1;
-#endif
- int hasTouchscreen : 1;
- int mouseInteractionEnabled : 1;
- int virtualMouseRequired : 1;
- int qtOwnsS60Environment : 1;
- int supportsPremultipliedAlpha : 1;
- int avkonComponentsSupportTransparency : 1;
- int menuBeingConstructed : 1;
- int orientationSet : 1;
- int partial_keyboard : 1;
- QApplication::QS60MainApplicationFactory s60ApplicationFactory; // typedef'ed pointer type
- QPointer<QWidget> splitViewLastWidget;
-
- static CEikButtonGroupContainer *cba;
-
- enum ScanCodeState {
- Unpressed,
- KeyDown,
- KeyDownAndKey
- };
- QHash<TInt, ScanCodeState> scanCodeStates;
-
- static inline void updateScreenSize();
- inline RWsSession& wsSession();
- static inline int screenCount();
- static inline RWindowGroup& windowGroup();
- static inline RWindowGroup& windowGroup(const QWidget *widget);
- static inline RWindowGroup& windowGroup(int screenNumber);
- inline CWsScreenDevice* screenDevice();
- inline CWsScreenDevice* screenDevice(const QWidget *widget);
- inline CWsScreenDevice* screenDevice(int screenNumber);
- static inline int screenNumberForWidget(const QWidget *widget);
- static inline CCoeAppUi* appUi();
- static inline CEikMenuBar* menuBar();
-#ifdef Q_WS_S60
- static inline CEikStatusPane* statusPane();
- static inline CCoeControl* statusPaneSubPane(TInt aPaneId);
- static inline CAknTitlePane* titlePane();
- static inline CAknContextPane* contextPane();
- static inline CEikButtonGroupContainer* buttonGroupContainer();
- static inline void setButtonGroupContainer(CEikButtonGroupContainer* newCba);
- static void setStatusPaneAndButtonGroupVisibility(bool statusPaneVisible, bool buttonGroupVisible);
- static bool setRecursiveDecorationsVisibility(QWidget *window, Qt::WindowStates newState);
-#endif
- static void controlVisibilityChanged(CCoeControl *control, bool visible);
-
-#ifdef Q_OS_SYMBIAN
- TTrapHandler *s60InstalledTrapHandler;
-#endif
-
- int screenWidthInPixelsForScreen[qt_symbian_max_screens];
- int screenHeightInPixelsForScreen[qt_symbian_max_screens];
- int screenWidthInTwipsForScreen[qt_symbian_max_screens];
- int screenHeightInTwipsForScreen[qt_symbian_max_screens];
-
- int nativeScreenWidthInPixels;
- int nativeScreenHeightInPixels;
-
- int beginFullScreenCalled : 1;
- int endFullScreenCalled : 1;
-};
-
-Q_AUTOTEST_EXPORT QS60Data* qGlobalS60Data();
-#define S60 qGlobalS60Data()
-
-class QAbstractLongTapObserver
-{
-public:
- virtual void HandleLongTapEventL( const TPoint& aPenEventLocation,
- const TPoint& aPenEventScreenLocation ) = 0;
-};
-class QLongTapTimer;
-
-
-class QSymbianControl : public CCoeControl, public QAbstractLongTapObserver
-#ifdef Q_WS_S60
-, public MAknFadedComponent, public MEikStatusPaneObserver
-#endif
-{
-public:
- DECLARE_TYPE_ID(0x51740000) // Fun fact: the two first values are "Qt" in ASCII.
-
-public:
- QSymbianControl(QWidget *w);
- void ConstructL(bool isWindowOwning = false, bool desktop = false);
- ~QSymbianControl();
- void HandleResourceChange(int resourceType);
- void HandlePointerEventL(const TPointerEvent& aPointerEvent);
- TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
-#if !defined(QT_NO_IM) && defined(Q_WS_S60)
- TCoeInputCapabilities InputCapabilities() const;
-#endif
- TTypeUid::Ptr MopSupplyObject(TTypeUid id);
-
- inline QWidget* widget() const { return qwidget; }
- void setWidget(QWidget *w);
- void sendInputEvent(QWidget *widget, QInputEvent *inputEvent);
- void setIgnoreFocusChanged(bool enabled) { m_ignoreFocusChanged = enabled; }
- void CancelLongTapTimer();
-
- void setFocusSafely(bool focus);
-
- bool isControlActive();
-
- void ensureFixNativeOrientation();
- QPoint translatePointForFixedNativeOrientation(const TPoint &pointerEventPos) const;
- TRect translateRectForFixedNativeOrientation(const TRect &controlRect) const;
-
-#ifdef Q_WS_S60
- void FadeBehindPopup(bool fade){ popupFader.FadeBehindPopup( this, this, fade); }
- void HandleStatusPaneSizeChange();
-
-protected: // from MAknFadedComponent
- TInt CountFadedComponents() {return 1;}
- CCoeControl* FadedComponent(TInt /*aIndex*/) {return this;}
-#else
- // #warning No fallback implementation for QSymbianControl::FadeBehindPopup
- void FadeBehindPopup(bool /*fade*/){ }
-#endif
-
-protected:
- void Draw(const TRect& aRect) const;
- void SizeChanged();
- void PositionChanged();
- void FocusChanged(TDrawNow aDrawNow);
-
-protected:
- void qwidgetResize_helper(const QSize &newSize);
-
-private:
- void HandlePointerEvent(const TPointerEvent& aPointerEvent);
- TKeyResponse OfferKeyEvent(const TKeyEvent& aKeyEvent,TEventCode aType);
- TKeyResponse sendSymbianKeyEvent(const TKeyEvent &keyEvent, QEvent::Type type);
- TKeyResponse sendKeyEvent(QWidget *widget, QKeyEvent *keyEvent);
- TKeyResponse handleVirtualMouse(const TKeyEvent& keyEvent,TEventCode type);
- bool sendMouseEvent(QWidget *widget, QMouseEvent *mEvent);
- void sendMouseEvent(
- QWidget *receiver,
- QEvent::Type type,
- const QPoint &globalPos,
- Qt::MouseButton button,
- Qt::KeyboardModifiers modifiers);
- void processTouchEvent(int pointerNumber, TPointerEvent::TType type, QPointF screenPos, qreal pressure);
- void HandleLongTapEventL( const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation );
-#ifdef QT_SYMBIAN_SUPPORTS_ADVANCED_POINTER
- void translateAdvancedPointerEvent(const TAdvancedPointerEvent *event);
-#endif
- bool isSplitViewWidget(QWidget *widget);
-
-public:
- void handleClientAreaChange();
-
-private:
- static QSymbianControl *lastFocusedControl;
-
-private:
- QWidget *qwidget;
- QLongTapTimer* m_longTapDetector;
- QElapsedTimer m_doubleClickTimer;
- bool m_ignoreFocusChanged : 1;
- bool m_symbianPopupIsOpen : 1;
-
-#ifdef Q_WS_S60
- // Fader object used to fade everything except this menu and the CBA.
- TAknPopupFader popupFader;
-#endif
-
- bool m_inExternalScreenOverride : 1;
- bool m_lastStatusPaneVisibility : 1;
-};
-
-inline QS60Data::QS60Data()
-: uid(TUid::Null()),
- screenDepth(0),
- screenWidthInPixels(0),
- screenHeightInPixels(0),
- screenWidthInTwips(0),
- screenHeightInTwips(0),
- defaultDpiX(0),
- defaultDpiY(0),
- curWin(0),
- virtualMousePressedKeys(0),
- virtualMouseAccelDX(0),
- virtualMouseAccelDY(0),
- virtualMouseMaxAccel(0),
-#ifndef Q_SYMBIAN_FIXED_POINTER_CURSORS
- brokenPointerCursors(0),
-#endif
- hasTouchscreen(0),
- mouseInteractionEnabled(0),
- virtualMouseRequired(0),
- qtOwnsS60Environment(0),
- supportsPremultipliedAlpha(0),
- avkonComponentsSupportTransparency(0),
- menuBeingConstructed(0),
- orientationSet(0),
- partial_keyboard(0),
- s60ApplicationFactory(0)
-#ifdef Q_OS_SYMBIAN
- ,s60InstalledTrapHandler(0)
-#endif
- ,beginFullScreenCalled(0),
- endFullScreenCalled(0)
-{
-}
-
-inline void QS60Data::updateScreenSize()
-{
- CWsScreenDevice *dev = S60->screenDevice();
- int screenModeCount = dev->NumScreenModes();
- int mode = dev->CurrentScreenMode();
- TPixelsTwipsAndRotation params;
- dev->GetScreenModeSizeAndRotation(mode, params);
- S60->screenWidthInPixels = params.iPixelSize.iWidth;
- S60->screenHeightInPixels = params.iPixelSize.iHeight;
- S60->screenWidthInTwips = params.iTwipsSize.iWidth;
- S60->screenHeightInTwips = params.iTwipsSize.iHeight;
-
- S60->virtualMouseMaxAccel = qMax(S60->screenHeightInPixels, S60->screenWidthInPixels) / 10;
-
- TReal inches = S60->screenHeightInTwips / (TReal)KTwipsPerInch;
- S60->defaultDpiY = S60->screenHeightInPixels / inches;
- inches = S60->screenWidthInTwips / (TReal)KTwipsPerInch;
- S60->defaultDpiX = S60->screenWidthInPixels / inches;
-
- int screens = S60->screenCount();
- for (int i = 0; i < screens; ++i) {
- CWsScreenDevice *dev = S60->screenDevice(i);
- mode = dev->CurrentScreenMode();
- dev->GetScreenModeSizeAndRotation(mode, params);
- S60->screenWidthInPixelsForScreen[i] = params.iPixelSize.iWidth;
- S60->screenHeightInPixelsForScreen[i] = params.iPixelSize.iHeight;
- S60->screenWidthInTwipsForScreen[i] = params.iTwipsSize.iWidth;
- S60->screenHeightInTwipsForScreen[i] = params.iTwipsSize.iHeight;
- }
-
- // Look for a screen mode with rotation 0
- // in order to decide what the native orientation is.
- for (mode = 0; mode < screenModeCount; ++mode) {
- TPixelsAndRotation sizeAndRotation;
- dev->GetScreenModeSizeAndRotation(mode, sizeAndRotation);
- if (sizeAndRotation.iRotation == CFbsBitGc::EGraphicsOrientationNormal) {
- S60->nativeScreenWidthInPixels = sizeAndRotation.iPixelSize.iWidth;
- S60->nativeScreenHeightInPixels = sizeAndRotation.iPixelSize.iHeight;
- break;
- }
- }
-}
-
-inline RWsSession& QS60Data::wsSession()
-{
- if(!tls.hasLocalData()) {
- tls.setLocalData(new QS60ThreadLocalData);
- }
- return tls.localData()->wsSession;
-}
-
-inline int QS60Data::screenCount()
-{
-#if defined(Q_SYMBIAN_SUPPORTS_MULTIPLE_SCREENS)
- CCoeEnv *env = CCoeEnv::Static();
- if (env) {
- return qMin(env->WsSession().NumberOfScreens(), qt_symbian_max_screens);
- }
-#endif
- return 1;
-}
-
-inline RWindowGroup& QS60Data::windowGroup()
-{
- return CCoeEnv::Static()->RootWin();
-}
-
-inline RWindowGroup& QS60Data::windowGroup(const QWidget *widget)
-{
- return windowGroup(screenNumberForWidget(widget));
-}
-
-inline RWindowGroup& QS60Data::windowGroup(int screenNumber)
-{
-#if defined(Q_SYMBIAN_SUPPORTS_MULTIPLE_SCREENS)
- RWindowGroup *wg = CCoeEnv::Static()->RootWin(screenNumber);
- return wg ? *wg : windowGroup();
-#else
- Q_UNUSED(screenNumber);
- return windowGroup();
-#endif
-}
-
-inline CWsScreenDevice* QS60Data::screenDevice()
-{
- if(!tls.hasLocalData()) {
- tls.setLocalData(new QS60ThreadLocalData);
- }
- return tls.localData()->screenDevice;
-}
-
-inline CWsScreenDevice* QS60Data::screenDevice(const QWidget *widget)
-{
- return screenDevice(screenNumberForWidget(widget));
-}
-
-inline CWsScreenDevice* QS60Data::screenDevice(int screenNumber)
-{
-#if defined(Q_SYMBIAN_SUPPORTS_MULTIPLE_SCREENS)
- CCoeEnv *env = CCoeEnv::Static();
- if (env) {
- CWsScreenDevice *dev = env->ScreenDevice(screenNumber);
- return dev ? dev : screenDevice();
- } else {
- return screenDevice();
- }
-#else
- return screenDevice();
-#endif
-}
-
-inline int QS60Data::screenNumberForWidget(const QWidget *widget)
-{
- if (!widget)
- return 0;
- const QWidget *w = widget;
- while (w->parentWidget())
- w = w->parentWidget();
- return qt_widget_private(const_cast<QWidget *>(w))->symbianScreenNumber;
-}
-
-inline CCoeAppUi* QS60Data::appUi()
-{
- return CCoeEnv::Static()-> AppUi();
-}
-
-inline CEikMenuBar* QS60Data::menuBar()
-{
- return CEikonEnv::Static()->AppUiFactory()->MenuBar();
-}
-
-#ifdef Q_WS_S60
-inline CEikStatusPane* QS60Data::statusPane()
-{
- return CEikonEnv::Static()->AppUiFactory()->StatusPane();
-}
-
-// Returns the application's status pane control, if not present returns NULL.
-inline CCoeControl* QS60Data::statusPaneSubPane( TInt aPaneId )
-{
- const TUid paneUid = { aPaneId };
- CEikStatusPane* statusPane = S60->statusPane();
- if (statusPane && statusPane->PaneCapabilities(paneUid).IsPresent()) {
- CCoeControl* control = NULL;
- // ControlL shouldn't leave because the pane is present
- TRAPD(err, control = statusPane->ControlL(paneUid));
- return err != KErrNone ? NULL : control;
- }
- return NULL;
-}
-
-// Returns the application's title pane, if not present returns NULL.
-inline CAknTitlePane* QS60Data::titlePane()
-{
- return static_cast<CAknTitlePane*>(S60->statusPaneSubPane(EEikStatusPaneUidTitle));
-}
-
-// Returns the application's title pane, if not present returns NULL.
-inline CAknContextPane* QS60Data::contextPane()
-{
- return static_cast<CAknContextPane*>(S60->statusPaneSubPane(EEikStatusPaneUidContext));
-}
-
-inline CEikButtonGroupContainer* QS60Data::buttonGroupContainer()
-{
- return QS60Data::cba;
-}
-
-inline void QS60Data::setButtonGroupContainer(CEikButtonGroupContainer *newCba)
-{
- QS60Data::cba = newCba;
-}
-#endif // Q_WS_S60
-
-static inline QFont qt_TFontSpec2QFontL(const TFontSpec &fontSpec)
-{
- return QFont(
- qt_TDesC2QString(fontSpec.iTypeface.iName),
- fontSpec.iHeight / KTwipsPerPoint,
- fontSpec.iFontStyle.StrokeWeight() == EStrokeWeightNormal ? QFont::Normal : QFont::Bold,
- fontSpec.iFontStyle.Posture() == EPostureItalic
- );
-}
-
-static inline QImage::Format qt_TDisplayMode2Format(TDisplayMode mode)
-{
- QImage::Format format;
- switch(mode) {
- case EGray2:
- format = QImage::Format_MonoLSB;
- break;
- case EColor256:
- case EGray256:
- format = QImage::Format_Indexed8;
- break;
- case EColor4K:
- format = QImage::Format_RGB444;
- break;
- case EColor64K:
- format = QImage::Format_RGB16;
- break;
- case EColor16M:
- format = QImage::Format_RGB888;
- break;
- case EColor16MU:
- format = QImage::Format_RGB32;
- break;
- case EColor16MA:
- format = QImage::Format_ARGB32;
- break;
- case Q_SYMBIAN_ECOLOR16MAP:
- format = QImage::Format_ARGB32_Premultiplied;
- break;
- default:
- format = QImage::Format_Invalid;
- break;
- }
- return format;
-}
-
-#ifndef QT_NO_CURSOR
-void qt_symbian_setWindowCursor(const QCursor &cursor, const CCoeControl* wid);
-void qt_symbian_setWindowGroupCursor(const QCursor &cursor, RWindowTreeNode &node);
-void qt_symbian_setGlobalCursor(const QCursor &cursor);
-void qt_symbian_set_cursor_visible(bool visible);
-bool qt_symbian_is_cursor_visible();
-#endif
-
-static inline bool qt_beginFullScreenEffect()
-{
-#if defined(Q_WS_S60) && defined(QT_SYMBIAN_HAVE_AKNTRANSEFFECT_H)
- // Only for post-S^3. On earlier versions the system transition effects
- // may not be able to capture the non-Avkon content, leading to confusing
- // looking effects, so just skip the whole thing.
- if (S60->beginFullScreenCalled || QSysInfo::s60Version() <= QSysInfo::SV_S60_5_2)
- return false;
- S60->beginFullScreenCalled = true;
- // For Avkon apps the app-exit effect is triggered from CAknAppUi::PrepareToExit().
- // That is good for Avkon apps, but in case of Qt the RWindows are destroyed earlier.
- // Therefore we call BeginFullScreen() ourselves.
- GfxTransEffect::BeginFullScreen(AknTransEffect::EApplicationExit,
- TRect(0, 0, 0, 0),
- AknTransEffect::EParameterType,
- AknTransEffect::GfxTransParam(S60->uid,
- AknTransEffect::TParameter::EAvkonCheck | KQtAppExitFlag));
- return true;
-#else
- return false;
-#endif
-}
-
-static inline void qt_abortFullScreenEffect()
-{
-#if defined(Q_WS_S60) && defined(QT_SYMBIAN_HAVE_AKNTRANSEFFECT_H)
- if (!S60->beginFullScreenCalled || QSysInfo::s60Version() <= QSysInfo::SV_S60_5_2)
- return;
- GfxTransEffect::AbortFullScreen();
- S60->beginFullScreenCalled = S60->endFullScreenCalled = false;
-#endif
-}
-
-static inline void qt_endFullScreenEffect()
-{
-#if defined(Q_WS_S60) && defined(QT_SYMBIAN_HAVE_AKNTRANSEFFECT_H)
- if (S60->endFullScreenCalled || QSysInfo::s60Version() <= QSysInfo::SV_S60_5_2)
- return;
- S60->endFullScreenCalled = true;
- GfxTransEffect::EndFullScreen();
-#endif
-}
-
-QT_END_NAMESPACE
-
-#endif // QT_S60_P_H
diff --git a/src/gui/kernel/qt_x11_p.h b/src/gui/kernel/qt_x11_p.h
deleted file mode 100644
index 69079cfaad..0000000000
--- a/src/gui/kernel/qt_x11_p.h
+++ /dev/null
@@ -1,757 +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 QT_X11_P_H
-#define QT_X11_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 "QtGui/qwindowdefs.h"
-#include "QtCore/qlist.h"
-#include "QtCore/qvariant.h"
-
-// the following is necessary to work around breakage in many versions
-// of XFree86's Xlib.h still in use
-// ### which versions?
-#if defined(_XLIB_H_) // crude hack, but...
-#error "cannot include <X11/Xlib.h> before this file"
-#endif
-#define XRegisterIMInstantiateCallback qt_XRegisterIMInstantiateCallback
-#define XUnregisterIMInstantiateCallback qt_XUnregisterIMInstantiateCallback
-#define XSetIMValues qt_XSetIMValues
-#include <X11/Xlib.h>
-#undef XRegisterIMInstantiateCallback
-#undef XUnregisterIMInstantiateCallback
-#undef XSetIMValues
-
-#include <X11/Xutil.h>
-#include <X11/Xos.h>
-#ifdef index
-# undef index
-#endif
-#ifdef rindex
-# undef rindex
-#endif
-#ifdef Q_OS_VXWORS
-# ifdef open
-# undef open
-# endif
-# ifdef getpid
-# undef getpid
-# endif
-#endif // Q_OS_VXWORKS
-#include <X11/Xatom.h>
-
-//#define QT_NO_SHAPE
-#ifdef QT_NO_SHAPE
-# define XShapeCombineRegion(a,b,c,d,e,f,g)
-# define XShapeCombineMask(a,b,c,d,e,f,g)
-#else
-# include <X11/extensions/shape.h>
-#endif // QT_NO_SHAPE
-
-
-#if !defined (QT_NO_TABLET)
-# include <X11/extensions/XInput.h>
-#if defined (Q_OS_IRIX)
-# include <X11/extensions/SGIMisc.h>
-# include <wacom.h>
-#endif
-#endif // QT_NO_TABLET
-
-
-// #define QT_NO_XINERAMA
-#ifndef QT_NO_XINERAMA
-# if 0 // ### Xsun, but how to detect it?
-// Xinerama is only supported in Solaris 7 with patches 107648/108376 and
-// Solaris 8 or above which introduce the X11R6.4 Xserver.
-// To switch the Xinerama functionality on, you need to add the "+xinerama"
-// argument to the Xsun start line.
-// At least Solaris 7 and 8 are missing Xinerama system headers and function
-// declarations (bug 4284701).
-// The Xinerama API is not documented. In theory it could change but it
-// probably won't because Sun are using it in at least dtlogin (bug 4221829).
-extern "C" Bool XPanoramiXQueryExtension(
- Display*,
- int*,
- int*
-);
-extern "C" Status XPanoramiXQueryVersion(
- Display*,
- int*,
- int*
-);
-extern "C" Status XPanoramiXGetState(
- Display*,
- Drawable,
- XPanoramiXInfo*
-);
-extern "C" Status XPanoramiXGetScreenCount(
- Display *,
- Drawable,
- XPanoramiXInfo*
-);
-extern "C" Status XPanoramiXGetScreenSize(
- Display*,
- Drawable,
- int,
- XPanoramiXInfo*
-);
-# else // XFree86
-// XFree86 does not C++ify Xinerama (at least up to XFree86 4.0.3).
-extern "C" {
-# include <X11/extensions/Xinerama.h>
-}
-# endif
-#endif // QT_NO_XINERAMA
-
-// #define QT_NO_XRANDR
-#ifndef QT_NO_XRANDR
-# include <X11/extensions/Xrandr.h>
-#endif // QT_NO_XRANDR
-
-// #define QT_NO_XRENDER
-#ifndef QT_NO_XRENDER
-# include <X11/extensions/Xrender.h>
-#endif // QT_NO_XRENDER
-
-#ifndef QT_NO_XSYNC
-extern "C" {
-# include "X11/extensions/sync.h"
-}
-#endif
-
-// #define QT_NO_XKB
-#ifndef QT_NO_XKB
-# include <X11/XKBlib.h>
-#endif // QT_NO_XKB
-
-
-#if !defined(XlibSpecificationRelease)
-# define X11R4
-typedef char *XPointer;
-#else
-# undef X11R4
-#endif
-
-// #define QT_NO_XIM
-#if defined(X11R4)
-// X11R4 does not have XIM
-#define QT_NO_XIM
-#elif defined(Q_OS_OSF) && (XlibSpecificationRelease < 6)
-// broken in Xlib up to OSF/1 3.2
-#define QT_NO_XIM
-#elif defined(Q_OS_AIX)
-// broken in Xlib up to what version of AIX?
-#define QT_NO_XIM
-#elif defined(QT_NO_DEBUG) && defined(Q_OS_IRIX)
-// XmbLookupString broken on IRIX
-// XCreateIC broken when compiling -64 on IRIX 6.5.2
-#define QT_NO_XIM
-#elif defined(Q_OS_HPUX) && defined(__LP64__)
-// XCreateIC broken when compiling 64-bit ELF on HP-UX 11.0
-#define QT_NO_XIM
-#elif defined(Q_OS_SCO)
-// ### suggested by user...
-// ### #define QT_NO_XIM
-#endif // QT_NO_XIM
-
-#ifndef QT_NO_XFIXES
-typedef Bool (*PtrXFixesQueryExtension)(Display *, int *, int *);
-typedef Status (*PtrXFixesQueryVersion)(Display *, int *, int *);
-typedef void (*PtrXFixesSetCursorName)(Display *dpy, Cursor cursor, const char *name);
-typedef void (*PtrXFixesSelectSelectionInput)(Display *dpy, Window win, Atom selection, unsigned long eventMask);
-#endif // QT_NO_XFIXES
-
-#ifndef QT_NO_XCURSOR
-#include <X11/Xcursor/Xcursor.h>
-typedef Cursor (*PtrXcursorLibraryLoadCursor)(Display *, const char *);
-#endif // QT_NO_XCURSOR
-
-#ifndef QT_NO_XINERAMA
-typedef Bool (*PtrXineramaQueryExtension)(Display *dpy, int *event_base, int *error_base);
-typedef Bool (*PtrXineramaIsActive)(Display *dpy);
-typedef XineramaScreenInfo *(*PtrXineramaQueryScreens)(Display *dpy, int *number);
-#endif // QT_NO_XINERAMA
-
-#ifndef QT_NO_XRANDR
-typedef void (*PtrXRRSelectInput)(Display *, Window, int);
-typedef int (*PtrXRRUpdateConfiguration)(XEvent *);
-typedef int (*PtrXRRRootToScreen)(Display *, Window);
-typedef Bool (*PtrXRRQueryExtension)(Display *, int *, int *);
-typedef XRRScreenSize *(*PtrXRRSizes)(Display *, int, int *);
-#endif // QT_NO_XRANDR
-
-#ifndef QT_NO_XINPUT
-typedef int (*PtrXCloseDevice)(Display *, XDevice *);
-typedef XDeviceInfo* (*PtrXListInputDevices)(Display *, int *);
-typedef XDevice* (*PtrXOpenDevice)(Display *, XID);
-typedef void (*PtrXFreeDeviceList)(XDeviceInfo *);
-typedef int (*PtrXSelectExtensionEvent)(Display *, Window, XEventClass *, int);
-#endif // QT_NO_XINPUT
-
-/*
- * Solaris patch 108652-47 and higher fixes crases in
- * XRegisterIMInstantiateCallback, but the function doesn't seem to
- * work.
- *
- * Instead, we disabled R6 input, and open the input method
- * immediately at application start.
- */
-#if !defined(QT_NO_XIM) && (XlibSpecificationRelease >= 6) && \
- !defined(Q_OS_SOLARIS)
-#define USE_X11R6_XIM
-
-//######### XFree86 has wrong declarations for XRegisterIMInstantiateCallback
-//######### and XUnregisterIMInstantiateCallback in at least version 3.3.2.
-//######### Many old X11R6 header files lack XSetIMValues.
-//######### Therefore, we have to declare these functions ourselves.
-
-extern "C" Bool XRegisterIMInstantiateCallback(
- Display*,
- struct _XrmHashBucketRec*,
- char*,
- char*,
- XIMProc, //XFree86 has XIDProc, which has to be wrong
- XPointer
-);
-
-extern "C" Bool XUnregisterIMInstantiateCallback(
- Display*,
- struct _XrmHashBucketRec*,
- char*,
- char*,
- XIMProc, //XFree86 has XIDProc, which has to be wrong
- XPointer
-);
-
-extern "C" char *XSetIMValues(XIM /* im */, ...);
-
-#endif
-
-#ifndef QT_NO_FONTCONFIG
-#include <fontconfig/fontconfig.h>
-#endif
-
-#ifndef QT_NO_XIM
-// some platforms (eg. Solaris 2.51) don't have these defines in Xlib.h
-#ifndef XNResetState
-#define XNResetState "resetState"
-#endif
-#ifndef XIMPreserveState
-#define XIMPreserveState (1L<<1)
-#endif
-#endif
-
-
-#ifndef X11R4
-# include <X11/Xlocale.h>
-#endif // X11R4
-
-
-#ifndef QT_NO_MITSHM
-# include <X11/extensions/XShm.h>
-#endif // QT_NO_MITSHM
-
-QT_BEGIN_NAMESPACE
-
-class QWidget;
-
-struct QX11InfoData {
- uint ref;
- int screen;
- int dpiX;
- int dpiY;
- int depth;
- int cells;
- Colormap colormap;
- Visual *visual;
- bool defaultColormap;
- bool defaultVisual;
- int subpixel;
-};
-
-class QDrag;
-struct QXdndDropTransaction
-{
- Time timestamp;
- Window target;
- Window proxy_target;
- QWidget *targetWidget;
- QWidget *embedding_widget;
- QDrag *object;
-};
-
-class QMimeData;
-
-struct QX11Data;
-extern Q_GUI_EXPORT QX11Data *qt_x11Data;
-
-enum DesktopEnvironment {
- DE_UNKNOWN,
- DE_KDE,
- DE_GNOME,
- DE_CDE,
- DE_MEEGO_COMPOSITOR,
- DE_4DWM
-};
-
-struct QX11Data
-{
- static Qt::KeyboardModifiers translateModifiers(int s);
-
- Window findClientWindow(Window, Atom, bool);
-
- // from qclipboard_x11.cpp
- bool clipboardWaitForEvent(Window win, int type, XEvent *event, int timeout);
- bool clipboardReadProperty(Window win, Atom property, bool deleteProperty,
- QByteArray *buffer, int *size, Atom *type, int *format);
- QByteArray clipboardReadIncrementalProperty(Window win, Atom property, int nbytes, bool nullterm);
-
- // from qdnd_x11.cpp
- bool dndEnable(QWidget* w, bool on);
- static void xdndSetup();
- void xdndHandleEnter(QWidget *, const XEvent *, bool);
- void xdndHandlePosition(QWidget *, const XEvent *, bool);
- void xdndHandleStatus(QWidget *, const XEvent *, bool);
- void xdndHandleLeave(QWidget *, const XEvent *, bool);
- void xdndHandleDrop(QWidget *, const XEvent *, bool);
- void xdndHandleFinished(QWidget *, const XEvent *, bool);
- void xdndHandleSelectionRequest(const XSelectionRequestEvent *);
- static bool xdndHandleBadwindow();
- QByteArray xdndAtomToString(Atom a);
- Atom xdndStringToAtom(const char *);
-
- QString xdndMimeAtomToString(Atom a);
- Atom xdndMimeStringToAtom(const QString &mimeType);
- QStringList xdndMimeFormatsForAtom(Atom a);
- bool xdndMimeDataForAtom(Atom a, QMimeData *mimeData, QByteArray *data, Atom *atomFormat, int *dataFormat);
- QList<Atom> xdndMimeAtomsForFormat(const QString &format);
- QVariant xdndMimeConvertToFormat(Atom a, const QByteArray &data, const QString &format, QVariant::Type requestedType, const QByteArray &encoding);
- Atom xdndMimeAtomForFormat(const QString &format, QVariant::Type requestedType, const QList<Atom> &atoms, QByteArray *requestedEncoding);
-
- QList<QXdndDropTransaction> dndDropTransactions;
-
- // from qmotifdnd_x11.cpp
- void motifdndHandle(QWidget *, const XEvent *, bool);
- void motifdndEnable(QWidget *, bool);
- QVariant motifdndObtainData(const char *format);
- QByteArray motifdndFormat(int n);
- bool motifdnd_active;
-
- Display *display;
- char *displayName;
- bool foreignDisplay;
- // current focus model
- enum {
- FM_Unknown = -1,
- FM_Other = 0,
- FM_PointerRoot = 1
- };
- int focus_model;
-
- // true if Qt is compiled w/ RANDR support and RANDR is supported on the connected Display
- bool use_xrandr;
- int xrandr_major;
- int xrandr_eventbase;
- int xrandr_errorbase;
-
- // true if Qt is compiled w/ RENDER support and RENDER is supported on the connected Display
- bool use_xrender;
- int xrender_major;
- int xrender_version;
-
- // true if Qt is compiled w/ XFIXES support and XFIXES is supported on the connected Display
- bool use_xfixes;
- int xfixes_major;
- int xfixes_eventbase;
- int xfixes_errorbase;
-
-#ifndef QT_NO_XFIXES
- PtrXFixesQueryExtension ptrXFixesQueryExtension;
- PtrXFixesQueryVersion ptrXFixesQueryVersion;
- PtrXFixesSetCursorName ptrXFixesSetCursorName;
- PtrXFixesSelectSelectionInput ptrXFixesSelectSelectionInput;
-#endif
-
-#ifndef QT_NO_XINPUT
- PtrXCloseDevice ptrXCloseDevice;
- PtrXListInputDevices ptrXListInputDevices;
- PtrXOpenDevice ptrXOpenDevice;
- PtrXFreeDeviceList ptrXFreeDeviceList;
- PtrXSelectExtensionEvent ptrXSelectExtensionEvent;
-#endif // QT_NO_XINPUT
-
-
- // true if Qt is compiled w/ MIT-SHM support and MIT-SHM is supported on the connected Display
- bool use_mitshm;
- bool use_mitshm_pixmaps;
- int mitshm_major;
-
- // true if Qt is compiled w/ Tablet support and we have a tablet.
- bool use_xinput;
- int xinput_major;
- int xinput_eventbase;
- int xinput_errorbase;
-
- // for XKEYBOARD support
- bool use_xkb;
- int xkb_major;
- int xkb_eventbase;
- int xkb_errorbase;
-
- QList<QWidget *> deferred_map;
- struct ScrollInProgress {
- long id;
- QWidget* scrolled_widget;
- int dx, dy;
- };
- long sip_serial;
- QList<ScrollInProgress> sip_list;
-
- // window managers list of supported "stuff"
- Atom *net_supported_list;
- // list of virtual root windows
- Window *net_virtual_root_list;
- // client leader window
- Window wm_client_leader;
-
- QX11InfoData *screens;
- Visual **argbVisuals;
- Colormap *argbColormaps;
- int screenCount;
- int defaultScreen;
-
- Time time;
- Time userTime;
-
- QString default_im;
-
- // starts to ignore bad window errors from X
- static inline void ignoreBadwindow() {
- qt_x11Data->ignore_badwindow = true;
- qt_x11Data->seen_badwindow = false;
- }
-
- // ends ignoring bad window errors and returns whether an error had happened.
- static inline bool badwindow() {
- qt_x11Data->ignore_badwindow = false;
- return qt_x11Data->seen_badwindow;
- }
-
- bool ignore_badwindow;
- bool seen_badwindow;
-
- // options
- int visual_class;
- int visual_id;
- int color_count;
- bool custom_cmap;
-
- // outside visual/colormap
- Visual *visual;
- Colormap colormap;
-
-#ifndef QT_NO_XRENDER
- enum { solid_fill_count = 16 };
- struct SolidFills {
- XRenderColor color;
- int screen;
- Picture picture;
- } solid_fills[solid_fill_count];
- enum { pattern_fill_count = 16 };
- struct PatternFills {
- XRenderColor color;
- XRenderColor bg_color;
- int screen;
- int style;
- bool opaque;
- Picture picture;
- } pattern_fills[pattern_fill_count];
- Picture getSolidFill(int screen, const QColor &c);
- XRenderColor preMultiply(const QColor &c);
-#endif
-
- bool has_fontconfig;
- qreal fc_scale;
- bool fc_antialias;
- int fc_hint_style;
-
- char *startupId;
-
- DesktopEnvironment desktopEnvironment : 8;
- uint desktopVersion : 8; /* Used only for KDE */
-
- /* Warning: if you modify this list, modify the names of atoms in qapplication_x11.cpp as well! */
- enum X11Atom {
- // window-manager <-> client protocols
- WM_PROTOCOLS,
- WM_DELETE_WINDOW,
- WM_TAKE_FOCUS,
- _NET_WM_PING,
- _NET_WM_CONTEXT_HELP,
- _NET_WM_SYNC_REQUEST,
- _NET_WM_SYNC_REQUEST_COUNTER,
-
- // ICCCM window state
- WM_STATE,
- WM_CHANGE_STATE,
-
- // Session management
- WM_CLIENT_LEADER,
- WM_WINDOW_ROLE,
- SM_CLIENT_ID,
-
- // Clipboard
- CLIPBOARD,
- INCR,
- TARGETS,
- MULTIPLE,
- TIMESTAMP,
- SAVE_TARGETS,
- CLIP_TEMPORARY,
- _QT_SELECTION,
- _QT_CLIPBOARD_SENTINEL,
- _QT_SELECTION_SENTINEL,
- CLIPBOARD_MANAGER,
-
- RESOURCE_MANAGER,
-
- _XSETROOT_ID,
-
- _QT_SCROLL_DONE,
- _QT_INPUT_ENCODING,
-
- _MOTIF_WM_HINTS,
-
- DTWM_IS_RUNNING,
- ENLIGHTENMENT_DESKTOP,
- _DT_SAVE_MODE,
- _SGI_DESKS_MANAGER,
-
- // EWMH (aka NETWM)
- _NET_SUPPORTED,
- _NET_VIRTUAL_ROOTS,
- _NET_WORKAREA,
-
- _NET_MOVERESIZE_WINDOW,
- _NET_WM_MOVERESIZE,
-
- _NET_WM_NAME,
- _NET_WM_ICON_NAME,
- _NET_WM_ICON,
-
- _NET_WM_PID,
-
- _NET_WM_WINDOW_OPACITY,
-
- _NET_WM_STATE,
- _NET_WM_STATE_ABOVE,
- _NET_WM_STATE_BELOW,
- _NET_WM_STATE_FULLSCREEN,
- _NET_WM_STATE_MAXIMIZED_HORZ,
- _NET_WM_STATE_MAXIMIZED_VERT,
- _NET_WM_STATE_MODAL,
- _NET_WM_STATE_STAYS_ON_TOP,
- _NET_WM_STATE_DEMANDS_ATTENTION,
-
- _NET_WM_USER_TIME,
- _NET_WM_USER_TIME_WINDOW,
- _NET_WM_FULL_PLACEMENT,
-
- _NET_WM_WINDOW_TYPE,
- _NET_WM_WINDOW_TYPE_DESKTOP,
- _NET_WM_WINDOW_TYPE_DOCK,
- _NET_WM_WINDOW_TYPE_TOOLBAR,
- _NET_WM_WINDOW_TYPE_MENU,
- _NET_WM_WINDOW_TYPE_UTILITY,
- _NET_WM_WINDOW_TYPE_SPLASH,
- _NET_WM_WINDOW_TYPE_DIALOG,
- _NET_WM_WINDOW_TYPE_DROPDOWN_MENU,
- _NET_WM_WINDOW_TYPE_POPUP_MENU,
- _NET_WM_WINDOW_TYPE_TOOLTIP,
- _NET_WM_WINDOW_TYPE_NOTIFICATION,
- _NET_WM_WINDOW_TYPE_COMBO,
- _NET_WM_WINDOW_TYPE_DND,
- _NET_WM_WINDOW_TYPE_NORMAL,
- _KDE_NET_WM_WINDOW_TYPE_OVERRIDE,
-
- _KDE_NET_WM_FRAME_STRUT,
-
- _NET_STARTUP_INFO,
- _NET_STARTUP_INFO_BEGIN,
-
- _NET_SUPPORTING_WM_CHECK,
-
- _NET_WM_CM_S0,
-
- _NET_SYSTEM_TRAY_VISUAL,
-
- _NET_ACTIVE_WINDOW,
-
- // Property formats
- COMPOUND_TEXT,
- TEXT,
- UTF8_STRING,
-
- // Xdnd
- XdndEnter,
- XdndPosition,
- XdndStatus,
- XdndLeave,
- XdndDrop,
- XdndFinished,
- XdndTypelist,
- XdndActionList,
-
- XdndSelection,
-
- XdndAware,
- XdndProxy,
-
- XdndActionCopy,
- XdndActionLink,
- XdndActionMove,
- XdndActionPrivate,
-
- // Motif DND
- _MOTIF_DRAG_AND_DROP_MESSAGE,
- _MOTIF_DRAG_INITIATOR_INFO,
- _MOTIF_DRAG_RECEIVER_INFO,
- _MOTIF_DRAG_WINDOW,
- _MOTIF_DRAG_TARGETS,
-
- XmTRANSFER_SUCCESS,
- XmTRANSFER_FAILURE,
-
- // Xkb
- _XKB_RULES_NAMES,
-
- // XEMBED
- _XEMBED,
- _XEMBED_INFO,
-
- XWacomStylus,
- XWacomCursor,
- XWacomEraser,
-
- XTabletStylus,
- XTabletEraser,
-
- NPredefinedAtoms,
-
- _QT_SETTINGS_TIMESTAMP = NPredefinedAtoms,
- NAtoms
- };
- Atom atoms[NAtoms];
-
- bool isSupportedByWM(Atom atom);
-
- bool compositingManagerRunning;
-
-#ifndef QT_NO_XCURSOR
- PtrXcursorLibraryLoadCursor ptrXcursorLibraryLoadCursor;
-#endif // QT_NO_XCURSOR
-
-#ifndef QT_NO_XINERAMA
- PtrXineramaQueryExtension ptrXineramaQueryExtension;
- PtrXineramaIsActive ptrXineramaIsActive;
- PtrXineramaQueryScreens ptrXineramaQueryScreens;
-#endif // QT_NO_XINERAMA
-
-#ifndef QT_NO_XRANDR
- PtrXRRSelectInput ptrXRRSelectInput;
- PtrXRRUpdateConfiguration ptrXRRUpdateConfiguration;
- PtrXRRRootToScreen ptrXRRRootToScreen;
- PtrXRRQueryExtension ptrXRRQueryExtension;
- PtrXRRSizes ptrXRRSizes;
-#endif // QT_NO_XRANDR
-};
-
-extern QX11Data *qt_x11Data;
-#define ATOM(x) qt_x11Data->atoms[QX11Data::x]
-#define X11 qt_x11Data
-
-// rename a couple of X defines to get rid of name clashes
-// resolve the conflict between X11's FocusIn and QEvent::FocusIn
-enum {
- XFocusOut = FocusOut,
- XFocusIn = FocusIn,
- XKeyPress = KeyPress,
- XKeyRelease = KeyRelease,
- XNone = None,
- XRevertToParent = RevertToParent,
- XGrayScale = GrayScale,
- XCursorShape = CursorShape
-};
-#undef FocusOut
-#undef FocusIn
-#undef KeyPress
-#undef KeyRelease
-#undef None
-#undef RevertToParent
-#undef GrayScale
-#undef CursorShape
-
-#ifdef FontChange
-#undef FontChange
-#endif
-
-Q_DECLARE_TYPEINFO(XPoint, Q_PRIMITIVE_TYPE);
-Q_DECLARE_TYPEINFO(XRectangle, Q_PRIMITIVE_TYPE);
-Q_DECLARE_TYPEINFO(XChar2b, Q_PRIMITIVE_TYPE);
-#ifndef QT_NO_XRENDER
-Q_DECLARE_TYPEINFO(XGlyphElt32, Q_PRIMITIVE_TYPE);
-#endif
-
-
-QT_END_NAMESPACE
-
-#endif // QT_X11_P_H
diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm
deleted file mode 100644
index 354f05ba10..0000000000
--- a/src/gui/kernel/qwidget_mac.mm
+++ /dev/null
@@ -1,5420 +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$
-**
-****************************************************************************/
-
-/****************************************************************************
-**
-** Copyright (c) 2007-2008, Apple, Inc.
-**
-** All rights reserved.
-**
-** Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are met:
-**
-** * Redistributions of source code must retain the above copyright notice,
-** this list of conditions and the following disclaimer.
-**
-** * Redistributions in binary form must reproduce the above copyright notice,
-** this list of conditions and the following disclaimer in the documentation
-** and/or other materials provided with the distribution.
-**
-** * Neither the name of Apple, Inc. nor the names of its contributors
-** may be used to endorse or promote products derived from this software
-** without specific prior written permission.
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-**
-****************************************************************************/
-
-#include <private/qt_mac_p.h>
-#include <private/qeventdispatcher_mac_p.h>
-
-#include "qapplication.h"
-#include "qapplication_p.h"
-#include "qbitmap.h"
-#include "qcursor.h"
-#include "qdesktopwidget.h"
-#include "qevent.h"
-#include "qfileinfo.h"
-#include "qimage.h"
-#include "qlayout.h"
-#include "qmenubar.h"
-#include <private/qbackingstore_p.h>
-#include <private/qwindowsurface_mac_p.h>
-#include <private/qpaintengine_mac_p.h>
-#include "qpainter.h"
-#include "qstyle.h"
-#include "qtimer.h"
-#include "qfocusframe.h"
-#include "qdebug.h"
-#include <private/qmainwindowlayout_p.h>
-
-#include <private/qabstractscrollarea_p.h>
-#include <qabstractscrollarea.h>
-#include <ApplicationServices/ApplicationServices.h>
-#include <limits.h>
-#include <private/qt_cocoa_helpers_mac_p.h>
-#include <private/qcocoaview_mac_p.h>
-#include <private/qcocoawindow_mac_p.h>
-#include <private/qcocoawindowdelegate_mac_p.h>
-#include <private/qcocoapanel_mac_p.h>
-
-#include "qwidget_p.h"
-#include "qevent_p.h"
-#include "qdnd_p.h"
-#include <QtGui/qgraphicsproxywidget.h>
-#include "qmainwindow.h"
-
-QT_BEGIN_NAMESPACE
-
-// qmainwindow.cpp
-extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window);
-
-#define XCOORD_MAX 16383
-#define WRECT_MAX 8191
-
-#ifndef QT_MAC_USE_COCOA
-
-extern "C" {
- extern OSStatus _HIViewScrollRectWithOptions(HIViewRef, const HIRect *, CGFloat, CGFloat,
- OptionBits) __attribute__ ((weak));
-}
-#define kHIViewScrollRectAdjustInvalid 1
-#define kHIViewScrollRectDontInvalidateRevealedArea 2
-#endif
-
-
-/*****************************************************************************
- QWidget debug facilities
- *****************************************************************************/
-//#define DEBUG_WINDOW_RGNS
-//#define DEBUG_WINDOW_CREATE
-//#define DEBUG_WINDOW_STATE
-//#define DEBUG_WIDGET_PAINT
-
-/*****************************************************************************
- QWidget globals
- *****************************************************************************/
-#ifndef QT_MAC_USE_COCOA
-typedef QHash<Qt::WindowFlags, WindowGroupRef> WindowGroupHash;
-Q_GLOBAL_STATIC(WindowGroupHash, qt_mac_window_groups)
-const UInt32 kWidgetCreatorQt = kEventClassQt;
-enum {
- kWidgetPropertyQWidget = 'QWId' //QWidget *
-};
-#endif
-
-static bool qt_mac_raise_process = true;
-static OSWindowRef qt_root_win = 0;
-QWidget *mac_mouse_grabber = 0;
-QWidget *mac_keyboard_grabber = 0;
-
-#ifndef QT_MAC_USE_COCOA
-#ifdef QT_NAMESPACE
-
-// produce the string "com.trolltech.qt-namespace.widget", where "namespace" is the contents of QT_NAMESPACE.
-#define SS(x) #x
-#define S0(x) SS(x)
-#define S "com.trolltech.qt-" S0(QT_NAMESPACE) ".widget"
-
-static CFStringRef kObjectQWidget = CFSTR(S);
-
-#undef SS
-#undef S0
-#undef S
-
-#else
-static CFStringRef kObjectQWidget = CFSTR("com.trolltech.qt.widget");
-#endif // QT_NAMESPACE
-#endif // QT_MAC_USE_COCOA
-
-/*****************************************************************************
- Externals
- *****************************************************************************/
-extern QPointer<QWidget> qt_button_down; //qapplication_mac.cpp
-extern QWidget *qt_mac_modal_blocked(QWidget *); //qapplication_mac.mm
-extern void qt_event_request_activate(QWidget *); //qapplication_mac.mm
-extern bool qt_event_remove_activate(); //qapplication_mac.mm
-extern void qt_mac_event_release(QWidget *w); //qapplication_mac.mm
-extern void qt_event_request_showsheet(QWidget *); //qapplication_mac.mm
-extern void qt_event_request_window_change(QWidget *); //qapplication_mac.mm
-extern QPointer<QWidget> qt_last_mouse_receiver; //qapplication_mac.mm
-extern QPointer<QWidget> qt_last_native_mouse_receiver; //qt_cocoa_helpers_mac.mm
-extern IconRef qt_mac_create_iconref(const QPixmap &); //qpixmap_mac.cpp
-extern void qt_mac_set_cursor(const QCursor *, const QPoint &); //qcursor_mac.mm
-extern void qt_mac_update_cursor(); //qcursor_mac.mm
-extern bool qt_nograb();
-extern CGImageRef qt_mac_create_cgimage(const QPixmap &, bool); //qpixmap_mac.cpp
-extern RgnHandle qt_mac_get_rgn(); //qregion_mac.cpp
-extern QRegion qt_mac_convert_mac_region(RgnHandle rgn); //qregion_mac.cpp
-extern void qt_mac_setMouseGrabCursor(bool set, QCursor *cursor = 0); // qcursor_mac.mm
-extern QPointer<QWidget> topLevelAt_cache; // qapplication_mac.mm
-/*****************************************************************************
- QWidget utility functions
- *****************************************************************************/
-void Q_GUI_EXPORT qt_mac_set_raise_process(bool b) { qt_mac_raise_process = b; }
-static QSize qt_mac_desktopSize()
-{
- int w = 0, h = 0;
- CGDisplayCount cg_count;
- CGGetActiveDisplayList(0, 0, &cg_count);
- QVector<CGDirectDisplayID> displays(cg_count);
- CGGetActiveDisplayList(cg_count, displays.data(), &cg_count);
- Q_ASSERT(cg_count == (CGDisplayCount)displays.size());
- for(int i = 0; i < (int)cg_count; ++i) {
- CGRect r = CGDisplayBounds(displays.at(i));
- w = qMax<int>(w, qRound(r.origin.x + r.size.width));
- h = qMax<int>(h, qRound(r.origin.y + r.size.height));
- }
- return QSize(w, h);
-}
-
-#ifdef QT_MAC_USE_COCOA
-static NSDrawer *qt_mac_drawer_for(const QWidget *widget)
-{
- NSView *widgetView = reinterpret_cast<NSView *>(widget->window()->effectiveWinId());
- NSArray *windows = [NSApp windows];
- for (NSWindow *window in windows) {
- NSArray *drawers = [window drawers];
- for (NSDrawer *drawer in drawers) {
- if ([drawer contentView] == widgetView)
- return drawer;
- }
- }
- return 0;
-}
-#endif
-
-static void qt_mac_destructView(OSViewRef view)
-{
-#ifdef QT_MAC_USE_COCOA
- NSWindow *window = [view window];
- if ([window contentView] == view)
- [window setContentView:[[NSView alloc] initWithFrame:[view bounds]]];
- [view removeFromSuperview];
- [view release];
-#else
- HIViewRemoveFromSuperview(view);
- CFRelease(view);
-#endif
-}
-
-static void qt_mac_destructWindow(OSWindowRef window)
-{
-#ifdef QT_MAC_USE_COCOA
- if ([window isVisible] && [window isSheet]){
- [NSApp endSheet:window];
- [window orderOut:window];
- }
-
- [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] resignDelegateForWindow:window];
- [window release];
-#else
- // Remove property to clean up memory:
- RemoveWindowProperty(window, kWidgetCreatorQt, kWidgetPropertyQWidget);
- CFRelease(window);
-#endif
-}
-
-static void qt_mac_destructDrawer(NSDrawer *drawer)
-{
-#ifdef QT_MAC_USE_COCOA
- [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] resignDelegateForDrawer:drawer];
- [drawer release];
-#else
- Q_UNUSED(drawer);
-#endif
-}
-
-bool qt_mac_can_clickThrough(const QWidget *w)
-{
- static int qt_mac_carbon_clickthrough = -1;
- if (qt_mac_carbon_clickthrough < 0)
- qt_mac_carbon_clickthrough = !qgetenv("QT_MAC_NO_COCOA_CLICKTHROUGH").isEmpty();
- bool ret = !qt_mac_carbon_clickthrough;
- for ( ; w; w = w->parentWidget()) {
- if (w->testAttribute(Qt::WA_MacNoClickThrough)) {
- ret = false;
- break;
- }
- }
- return ret;
-}
-
-bool qt_mac_is_macsheet(const QWidget *w)
-{
- if (!w)
- return false;
-
- Qt::WindowModality modality = w->windowModality();
- if (modality == Qt::ApplicationModal)
- return false;
- return w->parentWidget() && (modality == Qt::WindowModal || w->windowType() == Qt::Sheet);
-}
-
-bool qt_mac_is_macdrawer(const QWidget *w)
-{
- return (w && w->parentWidget() && w->windowType() == Qt::Drawer);
-}
-
-bool qt_mac_insideKeyWindow(const QWidget *w)
-{
-#ifdef QT_MAC_USE_COCOA
- return [[reinterpret_cast<NSView *>(w->effectiveWinId()) window] isKeyWindow];
-#else
- Q_UNUSED(w);
-#endif
- return false;
-}
-
-bool qt_mac_set_drawer_preferred_edge(QWidget *w, Qt::DockWidgetArea where) //users of Qt for Mac OS X can use this..
-{
- if(!qt_mac_is_macdrawer(w))
- return false;
-
-#if QT_MAC_USE_COCOA
- NSDrawer *drawer = qt_mac_drawer_for(w);
- if (!drawer)
- return false;
- NSRectEdge edge;
- if (where & Qt::LeftDockWidgetArea)
- edge = NSMinXEdge;
- else if (where & Qt::RightDockWidgetArea)
- edge = NSMaxXEdge;
- else if (where & Qt::TopDockWidgetArea)
- edge = NSMaxYEdge;
- else if (where & Qt::BottomDockWidgetArea)
- edge = NSMinYEdge;
- else
- return false;
-
- if (edge == [drawer preferredEdge]) //no-op
- return false;
-
- if (w->isVisible()) {
- [drawer close];
- [drawer openOnEdge:edge];
- }
- [drawer setPreferredEdge:edge];
-#else
- OSWindowRef window = qt_mac_window_for(w);
- OptionBits edge;
- if(where & Qt::LeftDockWidgetArea)
- edge = kWindowEdgeLeft;
- else if(where & Qt::RightDockWidgetArea)
- edge = kWindowEdgeRight;
- else if(where & Qt::TopDockWidgetArea)
- edge = kWindowEdgeTop;
- else if(where & Qt::BottomDockWidgetArea)
- edge = kWindowEdgeBottom;
- else
- return false;
-
- if(edge == GetDrawerPreferredEdge(window)) //no-op
- return false;
-
- //do it
- SetDrawerPreferredEdge(window, edge);
- if(w->isVisible()) {
- CloseDrawer(window, false);
- OpenDrawer(window, edge, true);
- }
-#endif
- return true;
-}
-
-#ifndef QT_MAC_USE_COCOA
-Q_GUI_EXPORT
-#endif
-QPoint qt_mac_posInWindow(const QWidget *w)
-{
- QPoint ret = w->data->wrect.topLeft();
- while(w && !w->isWindow()) {
- ret += w->pos();
- w = w->parentWidget();
- }
- return ret;
-}
-
-//find a QWidget from a OSWindowRef
-QWidget *qt_mac_find_window(OSWindowRef window)
-{
-#ifdef QT_MAC_USE_COCOA
- return [window QT_MANGLE_NAMESPACE(qt_qwidget)];
-#else
- if(!window)
- return 0;
-
- QWidget *ret;
- if(GetWindowProperty(window, kWidgetCreatorQt, kWidgetPropertyQWidget, sizeof(ret), 0, &ret) == noErr)
- return ret;
- return 0;
-#endif
-}
-
-inline static void qt_mac_set_fullscreen_mode(bool b)
-{
- extern bool qt_mac_app_fullscreen; //qapplication_mac.mm
- if(qt_mac_app_fullscreen == b)
- return;
- qt_mac_app_fullscreen = b;
- if (b) {
- SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
- } else {
- SetSystemUIMode(kUIModeNormal, 0);
- }
-}
-
-Q_GUI_EXPORT OSViewRef qt_mac_nativeview_for(const QWidget *w)
-{
- return reinterpret_cast<OSViewRef>(w->internalWinId());
-}
-
-Q_GUI_EXPORT OSViewRef qt_mac_effectiveview_for(const QWidget *w)
-{
- // Get the first non-alien (parent) widget for
- // w, and return its NSView (if it has one):
- return reinterpret_cast<OSViewRef>(w->effectiveWinId());
-}
-
-Q_GUI_EXPORT OSViewRef qt_mac_get_contentview_for(OSWindowRef w)
-{
-#ifdef QT_MAC_USE_COCOA
- return [w contentView];
-#else
- HIViewRef contentView = 0;
- OSStatus err = GetRootControl(w, &contentView); // Returns the window's content view (Apple QA1214)
- if (err == errUnknownControl) {
- contentView = HIViewGetRoot(w);
- } else if (err != noErr) {
- qWarning("Qt:Could not get content or root view of window! %s:%d [%ld]",
- __FILE__, __LINE__, err);
- }
- return contentView;
-#endif
-}
-
-bool qt_mac_sendMacEventToWidget(QWidget *widget, EventRef ref)
-{
- return widget->macEvent(0, ref);
-}
-
-Q_GUI_EXPORT OSWindowRef qt_mac_window_for(OSViewRef view)
-{
-#ifdef QT_MAC_USE_COCOA
- if (view)
- return [view window];
- return 0;
-#else
- return HIViewGetWindow(view);
-#endif
-}
-
-static bool qt_isGenuineQWidget(OSViewRef ref)
-{
-#ifdef QT_MAC_USE_COCOA
- return [ref isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaView) class]];
-#else
- return HIObjectIsOfClass(HIObjectRef(ref), kObjectQWidget);
-#endif
-}
-
-bool qt_isGenuineQWidget(const QWidget *window)
-{
- if (!window)
- return false;
-
- if (!window->internalWinId())
- return true; //alien
-
- return qt_isGenuineQWidget(OSViewRef(window->internalWinId()));
-}
-
-Q_GUI_EXPORT OSWindowRef qt_mac_window_for(const QWidget *w)
-{
- if (OSViewRef hiview = qt_mac_effectiveview_for(w)) {
- OSWindowRef window = qt_mac_window_for(hiview);
- if (window)
- return window;
-
- if (qt_isGenuineQWidget(hiview)) {
- // This is a workaround for NSToolbar. When a widget is hidden
- // by clicking the toolbar button, Cocoa reparents the widgets
- // to another window (but Qt doesn't know about it).
- // When we start showing them, it reparents back,
- // but at this point it's window is nil, but the window it's being brought
- // into (the Qt one) is for sure created.
- // This stops the hierarchy moving under our feet.
- QWidget *toplevel = w->window();
- if (toplevel != w) {
- hiview = qt_mac_nativeview_for(toplevel);
- if (OSWindowRef w = qt_mac_window_for(hiview))
- return w;
- }
-
- toplevel->d_func()->createWindow_sys();
- // Reget the hiview since "create window" could potentially move the view (I guess).
- hiview = qt_mac_nativeview_for(toplevel);
- return qt_mac_window_for(hiview);
- }
- }
- return 0;
-}
-
-#ifndef QT_MAC_USE_COCOA
-/* Checks if the current group is a 'stay on top' group. If so, the
- group gets removed from the hash table */
-static void qt_mac_release_stays_on_top_group(WindowGroupRef group)
-{
- for (WindowGroupHash::iterator it = qt_mac_window_groups()->begin(); it != qt_mac_window_groups()->end(); ++it) {
- if (it.value() == group) {
- qt_mac_window_groups()->remove(it.key());
- return;
- }
- }
-}
-
-/* Use this function instead of ReleaseWindowGroup, this will be sure to release the
- stays on top window group (created with qt_mac_get_stays_on_top_group below) */
-static void qt_mac_release_window_group(WindowGroupRef group)
-{
- ReleaseWindowGroup(group);
- if (GetWindowGroupRetainCount(group) == 0)
- qt_mac_release_stays_on_top_group(group);
-}
-#define ReleaseWindowGroup(x) Are you sure you wanted to do that? (you wanted qt_mac_release_window_group)
-
-SInt32 qt_mac_get_group_level(WindowClass wclass)
-{
- SInt32 group_level;
- CGWindowLevel tmpLevel;
- GetWindowGroupLevelOfType(GetWindowGroupOfClass(wclass), kWindowGroupLevelActive, &tmpLevel);
- group_level = tmpLevel;
- return group_level;
-}
-#endif
-
-#ifndef QT_MAC_USE_COCOA
-static void qt_mac_set_window_group(OSWindowRef window, Qt::WindowFlags flags, int level)
-{
- WindowGroupRef group = 0;
- if (qt_mac_window_groups()->contains(flags)) {
- group = qt_mac_window_groups()->value(flags);
- RetainWindowGroup(group);
- } else {
- CreateWindowGroup(kWindowActivationScopeNone, &group);
- SetWindowGroupLevel(group, level);
- SetWindowGroupParent(group, GetWindowGroupOfClass(kAllWindowClasses));
- qt_mac_window_groups()->insert(flags, group);
- }
- SetWindowGroup(window, group);
-}
-
-inline static void qt_mac_set_window_group_to_stays_on_top(OSWindowRef window, Qt::WindowType type)
-{
- // We create one static stays on top window group so that
- // all stays on top (aka popups) will fall into the same
- // group and be able to be raise()'d with releation to one another (from
- // within the same window group).
- qt_mac_set_window_group(window, type|Qt::WindowStaysOnTopHint, qt_mac_get_group_level(kOverlayWindowClass));
-}
-
-inline static void qt_mac_set_window_group_to_tooltip(OSWindowRef window)
-{
- // Since new groups are created for 'stays on top' windows, the
- // same must be done for tooltips. Otherwise, tooltips would be drawn
- // below 'stays on top' widgets even tough they are on the same level.
- // Also, add 'two' to the group level to make sure they also get on top of popups.
- qt_mac_set_window_group(window, Qt::ToolTip, qt_mac_get_group_level(kHelpWindowClass)+2);
-}
-
-inline static void qt_mac_set_window_group_to_popup(OSWindowRef window)
-{
- // In Qt, a popup is seen as a 'stay on top' window.
- // Since new groups are created for 'stays on top' windows, the
- // same must be done for popups. Otherwise, popups would be drawn
- // below 'stays on top' windows. Add 1 to get above pure stay-on-top windows.
- qt_mac_set_window_group(window, Qt::Popup, qt_mac_get_group_level(kOverlayWindowClass)+1);
-}
-#endif
-
-inline static bool updateRedirectedToGraphicsProxyWidget(QWidget *widget, const QRect &rect)
-{
- if (!widget)
- return false;
-
-#ifndef QT_NO_GRAPHICSVIEW
- QWidget *tlw = widget->window();
- QWExtra *extra = qt_widget_private(tlw)->extra;
- if (extra && extra->proxyWidget) {
- extra->proxyWidget->update(rect.translated(widget->mapTo(tlw, QPoint())));
- return true;
- }
-#endif
-
- return false;
-}
-
-inline static bool updateRedirectedToGraphicsProxyWidget(QWidget *widget, const QRegion &rgn)
-{
- if (!widget)
- return false;
-
-#ifndef QT_NO_GRAPHICSVIEW
- QWidget *tlw = widget->window();
- QWExtra *extra = qt_widget_private(tlw)->extra;
- if (extra && extra->proxyWidget) {
- const QPoint offset(widget->mapTo(tlw, QPoint()));
- const QVector<QRect> rects = rgn.rects();
- for (int i = 0; i < rects.size(); ++i)
- extra->proxyWidget->update(rects.at(i).translated(offset));
- return true;
- }
-#endif
-
- return false;
-}
-
-void QWidgetPrivate::macSetNeedsDisplay(QRegion region)
-{
- Q_Q(QWidget);
-#ifndef QT_MAC_USE_COCOA
- if (region.isEmpty())
- HIViewSetNeedsDisplay(qt_mac_nativeview_for(q), true);
- else if (RgnHandle rgnHandle = region.toQDRgnForUpdate_sys())
- HIViewSetNeedsDisplayInRegion(qt_mac_nativeview_for(q), QMacSmartQuickDrawRegion(rgnHandle), true);
- else
- HIViewSetNeedsDisplay(qt_mac_nativeview_for(q), true); // do a complete repaint on overflow.
-#else
- if (NSView *nativeView = qt_mac_nativeview_for(q)) {
- // INVARIANT: q is _not_ alien. So we can optimize a little:
- if (region.isEmpty()) {
- [nativeView setNeedsDisplay:YES];
- } else {
- QVector<QRect> rects = region.rects();
- for (int i = 0; i<rects.count(); ++i) {
- const QRect &rect = rects.at(i);
- NSRect nsrect = NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height());
- [nativeView setNeedsDisplayInRect:nsrect];
- }
- }
- } else if (QWidget *effectiveWidget = q->nativeParentWidget()) {
- // INVARIANT: q is alien, and effectiveWidget is native.
- if (NSView *effectiveView = qt_mac_nativeview_for(effectiveWidget)) {
- if (region.isEmpty()) {
- const QRect &rect = q->rect();
- QPoint p = q->mapTo(effectiveWidget, rect.topLeft());
- NSRect nsrect = NSMakeRect(p.x(), p.y(), rect.width(), rect.height());
- [effectiveView setNeedsDisplayInRect:nsrect];
- } else {
- QVector<QRect> rects = region.rects();
- for (int i = 0; i<rects.count(); ++i) {
- const QRect &rect = rects.at(i);
- QPoint p = q->mapTo(effectiveWidget, rect.topLeft());
- NSRect nsrect = NSMakeRect(p.x(), p.y(), rect.width(), rect.height());
- [effectiveView setNeedsDisplayInRect:nsrect];
- }
- }
- }
- }
-#endif
-}
-
-void QWidgetPrivate::macUpdateIsOpaque()
-{
- Q_Q(QWidget);
- if (!q->testAttribute(Qt::WA_WState_Created))
- return;
-#ifndef QT_MAC_USE_COCOA
- HIViewFeatures bits;
- HIViewRef hiview = qt_mac_nativeview_for(q);
- HIViewGetFeatures(hiview, &bits);
- if ((bits & kHIViewIsOpaque) == isOpaque)
- return;
- if (isOpaque) {
- HIViewChangeFeatures(hiview, kHIViewIsOpaque, 0);
- } else {
- HIViewChangeFeatures(hiview, 0, kHIViewIsOpaque);
- }
- if (q->isVisible())
- HIViewReshapeStructure(qt_mac_nativeview_for(q));
-#else
- if (isRealWindow() && !q->testAttribute(Qt::WA_MacBrushedMetal)) {
- bool opaque = isOpaque;
- if (extra && extra->imageMask)
- opaque = false; // we are never opaque when we have a mask.
- [qt_mac_window_for(q) setOpaque:opaque];
- }
-#endif
-}
-#ifdef QT_MAC_USE_COCOA
-static OSWindowRef qt_mac_create_window(QWidget *widget, WindowClass wclass,
- NSUInteger wattr, const QRect &crect)
-{
- // Determine if we need to add in our "custom window" attribute. Cocoa is rather clever
- // in deciding if we need the maximize button or not (i.e., it's resizeable, so you
- // must need a maximize button). So, the only buttons we have control over are the
- // close and minimize buttons. If someone wants to customize and NOT have the maximize
- // button, then we have to do our hack. We only do it for these cases because otherwise
- // the window looks different when activated. This "QtMacCustomizeWindow" attribute is
- // intruding on a public space and WILL BREAK in the future.
- // One can hope that there is a more public API available by that time.
- Qt::WindowFlags flags = widget ? widget->windowFlags() : Qt::WindowFlags(0);
- if ((flags & Qt::CustomizeWindowHint)) {
- if ((flags & (Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint
- | Qt::WindowMinimizeButtonHint | Qt::WindowTitleHint))
- && !(flags & Qt::WindowMaximizeButtonHint))
- wattr |= QtMacCustomizeWindow;
- }
-
- // If we haven't created the desktop widget, you have to pass the rectangle
- // in "cocoa coordinates" (i.e., top points to the lower left coordinate).
- // Otherwise, we do the conversion for you. Since we are the only ones that
- // create the desktop widget, this is OK (but confusing).
- NSRect geo = NSMakeRect(crect.left(),
- (qt_root_win != 0) ? flipYCoordinate(crect.bottom() + 1) : crect.top(),
- crect.width(), crect.height());
- QMacCocoaAutoReleasePool pool;
- OSWindowRef window;
- switch (wclass) {
- case kMovableModalWindowClass:
- case kModalWindowClass:
- case kSheetWindowClass:
- case kFloatingWindowClass:
- case kOverlayWindowClass:
- case kHelpWindowClass: {
- NSPanel *panel;
- BOOL needFloating = NO;
- BOOL worksWhenModal = widget && (widget->windowType() == Qt::Popup);
- // Add in the extra flags if necessary.
- switch (wclass) {
- case kSheetWindowClass:
- wattr |= NSDocModalWindowMask;
- break;
- case kFloatingWindowClass:
- case kHelpWindowClass:
- needFloating = YES;
- wattr |= NSUtilityWindowMask;
- break;
- default:
- break;
- }
- panel = [[QT_MANGLE_NAMESPACE(QCocoaPanel) alloc] QT_MANGLE_NAMESPACE(qt_initWithQWidget):widget contentRect:geo styleMask:wattr];
- [panel setFloatingPanel:needFloating];
- [panel setWorksWhenModal:worksWhenModal];
- window = panel;
- break;
- }
- case kDrawerWindowClass: {
- NSDrawer *drawer = [[NSDrawer alloc] initWithContentSize:geo.size preferredEdge:NSMinXEdge];
- [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] becomeDelegateForDrawer:drawer widget:widget];
- QWidget *parentWidget = widget->parentWidget();
- if (parentWidget)
- [drawer setParentWindow:qt_mac_window_for(parentWidget)];
- [drawer setLeadingOffset:0.0];
- [drawer setTrailingOffset:25.0];
- window = [[drawer contentView] window]; // Just to make sure we actually return a window
- break;
- }
- default:
- window = [[QT_MANGLE_NAMESPACE(QCocoaWindow) alloc] QT_MANGLE_NAMESPACE(qt_initWithQWidget):widget contentRect:geo styleMask:wattr];
- break;
- }
- qt_syncCocoaTitleBarButtons(window, widget);
- return window;
-}
-#else
-static OSWindowRef qt_mac_create_window(QWidget *, WindowClass wclass, WindowAttributes wattr,
- const QRect &crect)
-{
- OSWindowRef window;
- Rect geo;
- SetRect(&geo, crect.left(), crect.top(), crect.right() + 1, crect.bottom() + 1);
- OSStatus err;
- if(geo.right <= geo.left) geo.right = geo.left + 1;
- if(geo.bottom <= geo.top) geo.bottom = geo.top + 1;
- Rect null_rect;
- SetRect(&null_rect, 0, 0, 1, 1);
- err = CreateNewWindow(wclass, wattr, &null_rect, &window);
- if(err == noErr) {
- err = SetWindowBounds(window, kWindowContentRgn, &geo);
- if(err != noErr)
- qWarning("QWidget: Internal error (%s:%d)", __FILE__, __LINE__);
- }
- return window;
-}
-
-#ifndef QT_NO_GESTURES
-#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
-/* We build the release package against the 10.4 SDK.
- So, to enable gestures for applications running on
- 10.6+, we define the missing constants here: */
-enum {
- kEventClassGesture = 'gest',
- kEventGestureStarted = 1,
- kEventGestureEnded = 2,
- kEventGestureMagnify = 4,
- kEventGestureSwipe = 5,
- kEventGestureRotate = 6,
- kEventParamRotationAmount = 'rota',
- kEventParamSwipeDirection = 'swip',
- kEventParamMagnificationAmount = 'magn'
-};
-#endif
-#endif // QT_NO_GESTURES
-
-// window events
-static EventTypeSpec window_events[] = {
- { kEventClassWindow, kEventWindowClose },
- { kEventClassWindow, kEventWindowExpanded },
- { kEventClassWindow, kEventWindowHidden },
- { kEventClassWindow, kEventWindowZoom },
- { kEventClassWindow, kEventWindowZoomed },
- { kEventClassWindow, kEventWindowCollapsed },
- { kEventClassWindow, kEventWindowToolbarSwitchMode },
- { kEventClassWindow, kEventWindowProxyBeginDrag },
- { kEventClassWindow, kEventWindowProxyEndDrag },
- { kEventClassWindow, kEventWindowResizeCompleted },
- { kEventClassWindow, kEventWindowBoundsChanging },
- { kEventClassWindow, kEventWindowGetRegion },
- { kEventClassWindow, kEventWindowGetClickModality },
- { kEventClassWindow, kEventWindowTransitionCompleted },
- { kEventClassGesture, kEventGestureStarted },
- { kEventClassGesture, kEventGestureEnded },
- { kEventClassGesture, kEventGestureMagnify },
- { kEventClassGesture, kEventGestureSwipe },
- { kEventClassGesture, kEventGestureRotate },
- { kEventClassMouse, kEventMouseDown }
-};
-static EventHandlerUPP mac_win_eventUPP = 0;
-static void cleanup_win_eventUPP()
-{
- DisposeEventHandlerUPP(mac_win_eventUPP);
- mac_win_eventUPP = 0;
-}
-static const EventHandlerUPP make_win_eventUPP()
-{
- if(mac_win_eventUPP)
- return mac_win_eventUPP;
- qAddPostRoutine(cleanup_win_eventUPP);
- return mac_win_eventUPP = NewEventHandlerUPP(QWidgetPrivate::qt_window_event);
-}
-OSStatus QWidgetPrivate::qt_window_event(EventHandlerCallRef er, EventRef event, void *)
-{
- QScopedLoopLevelCounter loopLevelCounter(qApp->d_func()->threadData);
- bool handled_event = true;
- UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event);
- switch(eclass) {
- case kEventClassWindow: {
- WindowRef wid = 0;
- GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 0,
- sizeof(WindowRef), 0, &wid);
- QWidget *widget = qt_mac_find_window(wid);
- if(!widget) {
- handled_event = false;
- } else if(ekind == kEventWindowGetClickModality) {
- // Carbon will send us kEventWindowGetClickModality before every
- // mouse press / release event. By returning 'true', we tell Carbon
- // that we would like the event target to receive the mouse event even
- // if the target is modally shaddowed. In Qt, this makes sense when we
- // e.g. have a popup showing, as the popup will grab the event
- // and perhaps use it to close itself.
- // By also setting the current modal window back into the event, we
- // help Carbon determining which window is supposed to be raised.
- handled_event = qApp->activePopupWidget() ? true : false;
- } else if(ekind == kEventWindowClose) {
- widget->d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent);
- QMenuBar::macUpdateMenuBar();
- } else if (ekind == kEventWindowTransitionCompleted) {
- WindowTransitionAction transitionAction;
- GetEventParameter(event, kEventParamWindowTransitionAction, typeWindowTransitionAction,
- 0, sizeof(transitionAction), 0, &transitionAction);
- if (transitionAction == kWindowHideTransitionAction)
- widget->hide();
- } else if(ekind == kEventWindowExpanded) {
- Qt::WindowStates currState = Qt::WindowStates(widget->data->window_state);
- Qt::WindowStates newState = currState;
- if (currState & Qt::WindowMinimized)
- newState &= ~Qt::WindowMinimized;
- if (!(currState & Qt::WindowActive))
- newState |= Qt::WindowActive;
- if (newState != currState) {
- // newState will differ from currState if the window
- // was expanded after clicking on the jewels (as opposed
- // to calling QWidget::setWindowState)
- widget->data->window_state = newState;
- QWindowStateChangeEvent e(currState);
- QApplication::sendSpontaneousEvent(widget, &e);
- }
-
- QShowEvent qse;
- QApplication::sendSpontaneousEvent(widget, &qse);
- } else if(ekind == kEventWindowZoom) {
- widget->d_func()->topData()->normalGeometry = widget->geometry();
- handled_event = false;
- } else if(ekind == kEventWindowZoomed) {
- WindowPartCode windowPart;
- GetEventParameter(event, kEventParamWindowPartCode,
- typeWindowPartCode, 0, sizeof(windowPart), 0, &windowPart);
- if(windowPart == inZoomIn && widget->isMaximized()) {
-
- widget->data->window_state = widget->data->window_state & ~Qt::WindowMaximized;
- QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state | Qt::WindowMaximized));
- QApplication::sendSpontaneousEvent(widget, &e);
- } else if(windowPart == inZoomOut && !widget->isMaximized()) {
- widget->data->window_state = widget->data->window_state | Qt::WindowMaximized;
- QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state
- & ~Qt::WindowMaximized));
- QApplication::sendSpontaneousEvent(widget, &e);
- }
- qt_button_down = 0;
- } else if(ekind == kEventWindowCollapsed) {
- if (!widget->isMinimized()) {
- widget->data->window_state = widget->data->window_state | Qt::WindowMinimized;
- QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state & ~Qt::WindowMinimized));
- QApplication::sendSpontaneousEvent(widget, &e);
- }
-
- // Deactivate this window:
- if (widget->isActiveWindow() && !(widget->windowType() == Qt::Popup)) {
- QWidget *w = 0;
- if (widget->parentWidget())
- w = widget->parentWidget()->window();
- if (!w || (!w->isVisible() && !w->isMinimized())) {
- for (WindowPtr wp = GetFrontWindowOfClass(kDocumentWindowClass, true);
- wp; wp = GetNextWindowOfClass(wp, kDocumentWindowClass, true)) {
- if ((w = qt_mac_find_window(wp)))
- break;
- }
- }
- if(!(w && w->isVisible() && !w->isMinimized()))
- qApp->setActiveWindow(0);
- }
-
- //we send a hide to be like X11/Windows
- QEvent e(QEvent::Hide);
- QApplication::sendSpontaneousEvent(widget, &e);
- qt_button_down = 0;
- } else if(ekind == kEventWindowToolbarSwitchMode) {
- macSendToolbarChangeEvent(widget);
- HIToolbarRef toolbar;
- if (GetWindowToolbar(wid, &toolbar) == noErr) {
- if (toolbar) {
- // Let HIToolbar do its thang, but things like the OpenGL context
- // needs to know about it.
- CallNextEventHandler(er, event);
- qt_event_request_window_change(widget);
- widget->data->fstrut_dirty = true;
- }
- }
- } else if(ekind == kEventWindowGetRegion) {
- WindowRef window;
- GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 0,
- sizeof(window), 0, &window);
- WindowRegionCode wcode;
- GetEventParameter(event, kEventParamWindowRegionCode, typeWindowRegionCode, 0,
- sizeof(wcode), 0, &wcode);
- if (wcode != kWindowOpaqueRgn){
- // If the region is kWindowOpaqueRgn, don't call next
- // event handler cause this will make the shadow of
- // masked windows become offset. Unfortunately, we're not sure why.
- CallNextEventHandler(er, event);
- }
- RgnHandle rgn;
- GetEventParameter(event, kEventParamRgnHandle, typeQDRgnHandle, 0,
- sizeof(rgn), 0, &rgn);
-
- if(QWidgetPrivate::qt_widget_rgn(qt_mac_find_window(window), wcode, rgn, false))
- SetEventParameter(event, kEventParamRgnHandle, typeQDRgnHandle, sizeof(rgn), &rgn);
- } else if(ekind == kEventWindowProxyBeginDrag) {
- QIconDragEvent e;
- QApplication::sendSpontaneousEvent(widget, &e);
- } else if(ekind == kEventWindowResizeCompleted) {
- // Create a mouse up event, since such an event is not send by carbon to the
- // application event handler (while a mouse down <b>is</b> on kEventWindowResizeStarted)
- EventRef mouseUpEvent;
- CreateEvent(0, kEventClassMouse, kEventMouseUp, 0, kEventAttributeUserEvent, &mouseUpEvent);
- UInt16 mbutton = kEventMouseButtonPrimary;
- SetEventParameter(mouseUpEvent, kEventParamMouseButton, typeMouseButton, sizeof(mbutton), &mbutton);
- WindowRef window;
- GetEventParameter(event, kEventParamDirectObject, typeWindowRef, 0, sizeof(window), 0, &window);
- Rect dragRect;
- GetWindowBounds(window, kWindowGrowRgn, &dragRect);
- Point pos = {dragRect.bottom, dragRect.right};
- SetEventParameter(mouseUpEvent, kEventParamMouseLocation, typeQDPoint, sizeof(pos), &pos);
- SendEventToApplication(mouseUpEvent);
- ReleaseEvent(mouseUpEvent);
- } else if(ekind == kEventWindowBoundsChanging) {
- UInt32 flags = 0;
- GetEventParameter(event, kEventParamAttributes, typeUInt32, 0,
- sizeof(flags), 0, &flags);
- Rect nr;
- GetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, 0,
- sizeof(nr), 0, &nr);
-
- QRect newRect(nr.left, nr.top, nr.right - nr.left, nr.bottom - nr.top);
-
- QTLWExtra * const tlwExtra = widget->d_func()->maybeTopData();
- if (tlwExtra && tlwExtra->isSetGeometry == 1) {
- widget->d_func()->setGeometry_sys_helper(newRect.left(), newRect.top(), newRect.width(), newRect.height(), tlwExtra->isMove);
- } else {
- //implicitly removes the maximized bit
- if((widget->data->window_state & Qt::WindowMaximized) &&
- IsWindowInStandardState(wid, 0, 0)) {
- widget->data->window_state &= ~Qt::WindowMaximized;
- QWindowStateChangeEvent e(Qt::WindowStates(widget->data->window_state
- | Qt::WindowMaximized));
- QApplication::sendSpontaneousEvent(widget, &e);
-
- }
-
- handled_event = false;
- const QRect oldRect = widget->data->crect;
- if((flags & kWindowBoundsChangeOriginChanged)) {
- if(nr.left != oldRect.x() || nr.top != oldRect.y()) {
- widget->data->crect.moveTo(nr.left, nr.top);
- QMoveEvent qme(widget->data->crect.topLeft(), oldRect.topLeft());
- QApplication::sendSpontaneousEvent(widget, &qme);
- }
- }
- if((flags & kWindowBoundsChangeSizeChanged)) {
- if (widget->isWindow()) {
- QSize newSize = QLayout::closestAcceptableSize(widget, newRect.size());
- int dh = newSize.height() - newRect.height();
- int dw = newSize.width() - newRect.width();
- if (dw != 0 || dh != 0) {
- handled_event = true; // We want to change the bounds, so we handle the event
-
- // set the rect, so we can also do the resize down below (yes, we need to resize).
- newRect.setBottom(newRect.bottom() + dh);
- newRect.setRight(newRect.right() + dw);
-
- nr.left = newRect.x();
- nr.top = newRect.y();
- nr.right = nr.left + newRect.width();
- nr.bottom = nr.top + newRect.height();
- SetEventParameter(event, kEventParamCurrentBounds, typeQDRectangle, sizeof(Rect), &nr);
- }
- }
-
- if (oldRect.width() != newRect.width() || oldRect.height() != newRect.height()) {
- widget->data->crect.setSize(newRect.size());
- HIRect bounds = CGRectMake(0, 0, newRect.width(), newRect.height());
-
- // If the WA_StaticContents attribute is set we can optimize the resize
- // by only repainting the newly exposed area. We do this by disabling
- // painting when setting the size of the view. The OS will invalidate
- // the newly exposed area for us.
- const bool staticContents = widget->testAttribute(Qt::WA_StaticContents);
- const HIViewRef view = qt_mac_nativeview_for(widget);
- if (staticContents)
- HIViewSetDrawingEnabled(view, false);
- HIViewSetFrame(view, &bounds);
- if (staticContents)
- HIViewSetDrawingEnabled(view, true);
-
- QResizeEvent qre(newRect.size(), oldRect.size());
- QApplication::sendSpontaneousEvent(widget, &qre);
- qt_event_request_window_change(widget);
- }
- }
- }
- } else if (ekind == kEventWindowHidden) {
- // Make sure that we also hide any visible sheets on our window.
- // Cocoa does the right thing for us.
- const QObjectList children = widget->children();
- const int childCount = children.count();
- for (int i = 0; i < childCount; ++i) {
- QObject *obj = children.at(i);
- if (obj->isWidgetType()) {
- QWidget *widget = static_cast<QWidget *>(obj);
- if (qt_mac_is_macsheet(widget) && widget->isVisible())
- widget->hide();
- }
- }
- } else {
- handled_event = false;
- }
- break; }
- case kEventClassMouse: {
-#if 0
- return SendEventToApplication(event);
-#endif
-
- bool send_to_app = false;
- {
- WindowPartCode wpc;
- if (GetEventParameter(event, kEventParamWindowPartCode, typeWindowPartCode, 0,
- sizeof(wpc), 0, &wpc) == noErr && wpc != inContent)
- send_to_app = true;
- }
- if(!send_to_app) {
- WindowRef window;
- if(GetEventParameter(event, kEventParamWindowRef, typeWindowRef, 0,
- sizeof(window), 0, &window) == noErr) {
- HIViewRef hiview;
- if(HIViewGetViewForMouseEvent(HIViewGetRoot(window), event, &hiview) == noErr) {
- if(QWidget *w = QWidget::find((WId)hiview)) {
-#if 0
- send_to_app = !w->isActiveWindow();
-#else
- Q_UNUSED(w);
- send_to_app = true;
-#endif
- }
- }
- }
- }
- if(send_to_app)
- return SendEventToApplication(event);
- handled_event = false;
- break; }
-
-#ifndef QT_NO_GESTURES
- case kEventClassGesture: {
- // First, find the widget that was under
- // the mouse when the gesture happened:
- HIPoint screenLocation;
- if (GetEventParameter(event, kEventParamMouseLocation, typeHIPoint, 0,
- sizeof(screenLocation), 0, &screenLocation) != noErr) {
- handled_event = false;
- break;
- }
- QWidget *widget = QApplication::widgetAt(screenLocation.x, screenLocation.y);
- if (!widget) {
- handled_event = false;
- break;
- }
-
- QNativeGestureEvent qNGEvent;
- qNGEvent.position = QPoint(screenLocation.x, screenLocation.y);
-
- switch (ekind) {
- case kEventGestureStarted:
- qNGEvent.gestureType = QNativeGestureEvent::GestureBegin;
- break;
- case kEventGestureEnded:
- qNGEvent.gestureType = QNativeGestureEvent::GestureEnd;
- break;
- case kEventGestureRotate: {
- CGFloat amount;
- if (GetEventParameter(event, kEventParamRotationAmount, 'cgfl', 0,
- sizeof(amount), 0, &amount) != noErr) {
- handled_event = false;
- break;
- }
- qNGEvent.gestureType = QNativeGestureEvent::Rotate;
- qNGEvent.percentage = float(-amount);
- break; }
- case kEventGestureSwipe: {
- HIPoint swipeDirection;
- if (GetEventParameter(event, kEventParamSwipeDirection, typeHIPoint, 0,
- sizeof(swipeDirection), 0, &swipeDirection) != noErr) {
- handled_event = false;
- break;
- }
- qNGEvent.gestureType = QNativeGestureEvent::Swipe;
- if (swipeDirection.x == 1)
- qNGEvent.angle = 180.0f;
- else if (swipeDirection.x == -1)
- qNGEvent.angle = 0.0f;
- else if (swipeDirection.y == 1)
- qNGEvent.angle = 90.0f;
- else if (swipeDirection.y == -1)
- qNGEvent.angle = 270.0f;
- break; }
- case kEventGestureMagnify: {
- CGFloat amount;
- if (GetEventParameter(event, kEventParamMagnificationAmount, 'cgfl', 0,
- sizeof(amount), 0, &amount) != noErr) {
- handled_event = false;
- break;
- }
- qNGEvent.gestureType = QNativeGestureEvent::Zoom;
- qNGEvent.percentage = float(amount);
- break; }
- }
-
- QApplication::sendSpontaneousEvent(widget, &qNGEvent);
- break; }
-#endif // QT_NO_GESTURES
-
- default:
- handled_event = false;
- }
- if(!handled_event) //let the event go through
- return eventNotHandledErr;
- return noErr; //we eat the event
-}
-
-// widget events
-static HIObjectClassRef widget_class = 0;
-static EventTypeSpec widget_events[] = {
- { kEventClassHIObject, kEventHIObjectConstruct },
- { kEventClassHIObject, kEventHIObjectDestruct },
-
- { kEventClassControl, kEventControlDraw },
- { kEventClassControl, kEventControlInitialize },
- { kEventClassControl, kEventControlGetPartRegion },
- { kEventClassControl, kEventControlGetClickActivation },
- { kEventClassControl, kEventControlSetFocusPart },
- { kEventClassControl, kEventControlDragEnter },
- { kEventClassControl, kEventControlDragWithin },
- { kEventClassControl, kEventControlDragLeave },
- { kEventClassControl, kEventControlDragReceive },
- { kEventClassControl, kEventControlOwningWindowChanged },
- { kEventClassControl, kEventControlBoundsChanged },
- { kEventClassControl, kEventControlGetSizeConstraints },
- { kEventClassControl, kEventControlVisibilityChanged },
-
- { kEventClassMouse, kEventMouseDown },
- { kEventClassMouse, kEventMouseUp },
- { kEventClassMouse, kEventMouseMoved },
- { kEventClassMouse, kEventMouseDragged }
-};
-static EventHandlerUPP mac_widget_eventUPP = 0;
-static void cleanup_widget_eventUPP()
-{
- DisposeEventHandlerUPP(mac_widget_eventUPP);
- mac_widget_eventUPP = 0;
-}
-static const EventHandlerUPP make_widget_eventUPP()
-{
- if(mac_widget_eventUPP)
- return mac_widget_eventUPP;
- qAddPostRoutine(cleanup_widget_eventUPP);
- return mac_widget_eventUPP = NewEventHandlerUPP(QWidgetPrivate::qt_widget_event);
-}
-OSStatus QWidgetPrivate::qt_widget_event(EventHandlerCallRef er, EventRef event, void *)
-{
- QScopedLoopLevelCounter loopLevelCounter(QApplicationPrivate::instance()->threadData);
-
- bool handled_event = true;
- UInt32 ekind = GetEventKind(event), eclass = GetEventClass(event);
- switch(eclass) {
- case kEventClassHIObject: {
- HIViewRef view = 0;
- GetEventParameter(event, kEventParamHIObjectInstance, typeHIObjectRef,
- 0, sizeof(view), 0, &view);
- if(ekind == kEventHIObjectConstruct) {
- if(view) {
- HIViewChangeFeatures(view, kHIViewAllowsSubviews, 0);
- SetEventParameter(event, kEventParamHIObjectInstance,
- typeVoidPtr, sizeof(view), &view);
- }
- } else if(ekind == kEventHIObjectDestruct) {
- //nothing to really do.. or is there?
- } else {
- handled_event = false;
- }
- break; }
- case kEventClassControl: {
- QWidget *widget = 0;
- HIViewRef hiview = 0;
- if(GetEventParameter(event, kEventParamDirectObject, typeControlRef,
- 0, sizeof(hiview), 0, &hiview) == noErr)
- widget = QWidget::find((WId)hiview);
- if (widget && widget->macEvent(er, event))
- return noErr;
- if(ekind == kEventControlDraw) {
- if(widget && qt_isGenuineQWidget(hiview)) {
-
- // if there is a window change event pending for any gl child wigets,
- // send it immediately. (required for flicker-free resizing)
- extern void qt_mac_send_posted_gl_updates(QWidget *widget);
- qt_mac_send_posted_gl_updates(widget);
-
- if (QApplicationPrivate::graphicsSystem() && !widget->d_func()->paintOnScreen()) {
- widget->d_func()->syncBackingStore();
- widget->d_func()->dirtyOnWidget = QRegion();
- return noErr;
- }
-
- //requested rgn
- RgnHandle rgn;
- GetEventParameter(event, kEventParamRgnHandle, typeQDRgnHandle, 0, sizeof(rgn), 0, &rgn);
- QRegion qrgn(qt_mac_convert_mac_region(rgn));
-
- //update handles
- GrafPtr qd = 0;
- CGContextRef cg = 0;
- if(GetEventParameter(event, kEventParamCGContextRef, typeCGContextRef, 0, sizeof(cg), 0, &cg) != noErr) {
- Q_ASSERT(false);
- }
- widget->d_func()->hd = cg;
- widget->d_func()->qd_hd = qd;
- CGContextSaveGState(cg);
-
-#ifdef DEBUG_WIDGET_PAINT
- const bool doDebug = true;
- if(doDebug) {
- qDebug("asked to draw %p[%p] [%s::%s] %p[%p] [%d] [%dx%d]", widget, hiview, widget->metaObject()->className(),
- widget->objectName().local8Bit().data(), widget->parentWidget(),
- (HIViewRef)(widget->parentWidget() ? qt_mac_nativeview_for(widget->parentWidget()) : (HIViewRef)0),
- HIViewIsCompositingEnabled(hiview), qt_mac_posInWindow(widget).x(), qt_mac_posInWindow(widget).y());
-#if 0
- QVector<QRect> region_rects = qrgn.rects();
- qDebug("Region! %d", region_rects.count());
- for(int i = 0; i < region_rects.count(); i++)
- qDebug("%d %d %d %d", region_rects[i].x(), region_rects[i].y(),
- region_rects[i].width(), region_rects[i].height());
- region_rects = widget->d_func()->clp.rects();
- qDebug("Widget Region! %d", region_rects.count());
- for(int i = 0; i < region_rects.count(); i++)
- qDebug("%d %d %d %d", region_rects[i].x(), region_rects[i].y(),
- region_rects[i].width(), region_rects[i].height());
-#endif
- }
-#endif
- if (widget->isVisible() && widget->updatesEnabled()) { //process the actual paint event.
- if(widget->testAttribute(Qt::WA_WState_InPaintEvent))
- qWarning("QWidget::repaint: Recursive repaint detected");
- if (widget->isWindow() && !widget->d_func()->isOpaque
- && !widget->testAttribute(Qt::WA_MacBrushedMetal)) {
- QRect qrgnRect = qrgn.boundingRect();
- CGContextClearRect(cg, CGRectMake(qrgnRect.x(), qrgnRect.y(), qrgnRect.width(), qrgnRect.height()));
- }
-
- QPoint redirectionOffset(0, 0);
- QWidget *tl = widget->window();
- if (tl) {
- Qt::WindowFlags flags = tl->windowFlags();
- if (flags & Qt::FramelessWindowHint
- || (flags & Qt::CustomizeWindowHint && !(flags & Qt::WindowTitleHint))) {
- if(tl->d_func()->extra && !tl->d_func()->extra->mask.isEmpty())
- redirectionOffset += tl->d_func()->extra->mask.boundingRect().topLeft();
- }
- }
-
- //setup the context
- widget->setAttribute(Qt::WA_WState_InPaintEvent);
- QPaintEngine *engine = widget->paintEngine();
- if (engine)
- engine->setSystemClip(qrgn);
-
- //handle the erase
- if (engine && (!widget->testAttribute(Qt::WA_NoSystemBackground)
- && (widget->isWindow() || widget->autoFillBackground())
- || widget->testAttribute(Qt::WA_TintedBackground)
- || widget->testAttribute(Qt::WA_StyledBackground))) {
-#ifdef DEBUG_WIDGET_PAINT
- if(doDebug)
- qDebug(" Handling erase for [%s::%s]", widget->metaObject()->className(),
- widget->objectName().local8Bit().data());
-#endif
- if (!redirectionOffset.isNull())
- widget->d_func()->setRedirected(widget, redirectionOffset);
-
- bool was_unclipped = widget->testAttribute(Qt::WA_PaintUnclipped);
- widget->setAttribute(Qt::WA_PaintUnclipped, false);
- QPainter p(widget);
- p.setClipping(false);
- if(was_unclipped)
- widget->setAttribute(Qt::WA_PaintUnclipped);
- widget->d_func()->paintBackground(&p, qrgn, widget->isWindow() ? DrawAsRoot : 0);
- if (widget->testAttribute(Qt::WA_TintedBackground)) {
- QColor tint = widget->palette().window().color();
- tint.setAlphaF(.6);
- const QVector<QRect> &rects = qrgn.rects();
- for (int i = 0; i < rects.size(); ++i)
- p.fillRect(rects.at(i), tint);
- }
- p.end();
- if (!redirectionOffset.isNull())
- widget->d_func()->restoreRedirected();
- }
-
- if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget))
- CallNextEventHandler(er, event);
-
- //send the paint
- redirectionOffset += widget->data->wrect.topLeft(); // Map from system to qt coordinates
- if (!redirectionOffset.isNull())
- widget->d_func()->setRedirected(widget, redirectionOffset);
- qrgn.translate(redirectionOffset);
- QPaintEvent e(qrgn);
- widget->d_func()->dirtyOnWidget = QRegion();
-#ifdef QT3_SUPPORT
- e.setErased(true);
-#endif
- QApplication::sendSpontaneousEvent(widget, &e);
- if (!redirectionOffset.isNull())
- widget->d_func()->restoreRedirected();
-
- //cleanup
- if (engine)
- engine->setSystemClip(QRegion());
-
- widget->setAttribute(Qt::WA_WState_InPaintEvent, false);
- if(!widget->testAttribute(Qt::WA_PaintOutsidePaintEvent) && widget->paintingActive())
- qWarning("QWidget: It is dangerous to leave painters active on a widget outside of the PaintEvent");
- }
-
- widget->d_func()->hd = 0;
- widget->d_func()->qd_hd = 0;
- CGContextRestoreGState(cg);
- } else if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget)) {
- CallNextEventHandler(er, event);
- }
- } else if(ekind == kEventControlInitialize) {
- if(HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget)) {
- UInt32 features = kControlSupportsDragAndDrop | kControlSupportsClickActivation | kControlSupportsFocus;
- SetEventParameter(event, kEventParamControlFeatures, typeUInt32, sizeof(features), &features);
- } else {
- handled_event = false;
- }
- } else if(ekind == kEventControlSetFocusPart) {
- if(widget) {
- ControlPartCode part;
- GetEventParameter(event, kEventParamControlPart, typeControlPartCode, 0,
- sizeof(part), 0, &part);
- if(part == kControlFocusNoPart){
- if (widget->hasFocus())
- QApplicationPrivate::setFocusWidget(0, Qt::OtherFocusReason);
- } else
- widget->setFocus();
- }
- if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget))
- CallNextEventHandler(er, event);
- } else if(ekind == kEventControlGetClickActivation) {
- ClickActivationResult clickT = kActivateAndIgnoreClick;
- SetEventParameter(event, kEventParamClickActivation, typeClickActivationResult,
- sizeof(clickT), &clickT);
- } else if(ekind == kEventControlGetPartRegion) {
- handled_event = false;
- if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget) && CallNextEventHandler(er, event) == noErr) {
- handled_event = true;
- break;
- }
- if(widget && !widget->isWindow()) {
- ControlPartCode part;
- GetEventParameter(event, kEventParamControlPart, typeControlPartCode, 0,
- sizeof(part), 0, &part);
- if(part == kControlClickableMetaPart && widget->testAttribute(Qt::WA_TransparentForMouseEvents)) {
- RgnHandle rgn;
- GetEventParameter(event, kEventParamControlRegion, typeQDRgnHandle, 0,
- sizeof(rgn), 0, &rgn);
- SetEmptyRgn(rgn);
- handled_event = true;
- } else if(part == kControlStructureMetaPart || part == kControlClickableMetaPart) {
- RgnHandle rgn;
- GetEventParameter(event, kEventParamControlRegion, typeQDRgnHandle, 0,
- sizeof(rgn), 0, &rgn);
- SetRectRgn(rgn, 0, 0, widget->width(), widget->height());
- if(QWidgetPrivate::qt_widget_rgn(widget, kWindowStructureRgn, rgn, false))
- handled_event = true;
- } else if(part == kControlOpaqueMetaPart) {
- if(widget->d_func()->isOpaque) {
- RgnHandle rgn;
- GetEventParameter(event, kEventParamControlRegion, typeQDRgnHandle, 0,
- sizeof(RgnHandle), 0, &rgn);
- SetRectRgn(rgn, 0, 0, widget->width(), widget->height());
- QWidgetPrivate::qt_widget_rgn(widget, kWindowStructureRgn, rgn, false);
- SetEventParameter(event, kEventParamControlRegion, typeQDRgnHandle,
- sizeof(RgnHandle), &rgn);
- handled_event = true;
- }
- }
- }
- } else if(ekind == kEventControlOwningWindowChanged) {
- if(!HIObjectIsOfClass((HIObjectRef)hiview, kObjectQWidget))
- CallNextEventHandler(er, event);
- if(widget && qt_mac_window_for(hiview)) {
- WindowRef foo = 0;
- GetEventParameter(event, kEventParamControlCurrentOwningWindow, typeWindowRef, 0,
- sizeof(foo), 0, &foo);
- widget->d_func()->initWindowPtr();
- }
- if (widget)
- qt_event_request_window_change(widget);
- } else if(ekind == kEventControlDragEnter || ekind == kEventControlDragWithin ||
- ekind == kEventControlDragLeave || ekind == kEventControlDragReceive) {
- // dnd are really handled in qdnd_mac.cpp,
- // just modularize the code a little...
- DragRef drag;
- GetEventParameter(event, kEventParamDragRef, typeDragRef, 0, sizeof(drag), 0, &drag);
- handled_event = false;
- bool drag_allowed = false;
-
- QWidget *dropWidget = widget;
- if (qobject_cast<QFocusFrame *>(widget)){
- // We might shadow widgets underneath the focus
- // frame, so stay interrested, and let the dnd through
- drag_allowed = true;
- handled_event = true;
- Point where;
- GetDragMouse(drag, &where, 0);
- dropWidget = QApplication::widgetAt(QPoint(where.h, where.v));
-
- if (dropWidget != QDragManager::self()->currentTarget()) {
- // We have to 'fake' enter and leave events for the shaddowed widgets:
- if (ekind == kEventControlDragEnter) {
- if (QDragManager::self()->currentTarget())
- QDragManager::self()->currentTarget()->d_func()->qt_mac_dnd_event(kEventControlDragLeave, drag);
- if (dropWidget) {
- dropWidget->d_func()->qt_mac_dnd_event(kEventControlDragEnter, drag);
- }
- // Set dropWidget to zero, so qt_mac_dnd_event
- // doesn't get called a second time below:
- dropWidget = 0;
- } else if (ekind == kEventControlDragLeave) {
- dropWidget = QDragManager::self()->currentTarget();
- if (dropWidget) {
- dropWidget->d_func()->qt_mac_dnd_event(kEventControlDragLeave, drag);
- }
- // Set dropWidget to zero, so qt_mac_dnd_event
- // doesn't get called a second time below:
- dropWidget = 0;
- }
- }
- }
-
- // Send the dnd event to the widget:
- if (dropWidget && dropWidget->d_func()->qt_mac_dnd_event(ekind, drag)) {
- drag_allowed = true;
- handled_event = true;
- }
-
- if (ekind == kEventControlDragEnter) {
- // If we don't accept the enter event, we will
- // receive no more drag events for this widget
- const Boolean wouldAccept = drag_allowed ? true : false;
- SetEventParameter(event, kEventParamControlWouldAcceptDrop, typeBoolean,
- sizeof(wouldAccept), &wouldAccept);
- }
- } else if (ekind == kEventControlBoundsChanged) {
- if (!widget || widget->isWindow() || widget->testAttribute(Qt::WA_Moved) || widget->testAttribute(Qt::WA_Resized)) {
- handled_event = false;
- } else {
- // Sync our view in case some other (non-Qt) view is controlling us.
- handled_event = true;
- Rect newBounds;
- GetEventParameter(event, kEventParamCurrentBounds,
- typeQDRectangle, 0, sizeof(Rect), 0, &newBounds);
- QRect rect(newBounds.left, newBounds.top,
- newBounds.right - newBounds.left, newBounds.bottom - newBounds.top);
-
- bool moved = widget->testAttribute(Qt::WA_Moved);
- bool resized = widget->testAttribute(Qt::WA_Resized);
- widget->setGeometry(rect);
- widget->setAttribute(Qt::WA_Moved, moved);
- widget->setAttribute(Qt::WA_Resized, resized);
- qt_event_request_window_change(widget);
- }
- } else if (ekind == kEventControlGetSizeConstraints) {
- if (!widget || !qt_isGenuineQWidget(widget)) {
- handled_event = false;
- } else {
- handled_event = true;
- QWidgetItem item(widget);
- QSize size = item.minimumSize();
- HISize hisize = { size.width(), size.height() };
- SetEventParameter(event, kEventParamMinimumSize, typeHISize, sizeof(HISize), &hisize);
- size = item.maximumSize();
- hisize.width = size.width() + 2; // ### shouldn't have to add 2 (but it works).
- hisize.height = size.height();
- SetEventParameter(event, kEventParamMaximumSize, typeHISize, sizeof(HISize), &hisize);
- }
- } else if (ekind == kEventControlVisibilityChanged) {
- handled_event = false;
- if (widget) {
- qt_event_request_window_change(widget);
- if (!HIViewIsVisible(HIViewRef(widget->winId()))) {
- if (widget == qt_button_down)
- qt_button_down = 0;
- }
- }
- }
- break; }
- case kEventClassMouse: {
- bool send_to_app = false;
- if(qt_button_down)
- send_to_app = true;
- if(send_to_app) {
- OSStatus err = SendEventToApplication(event);
- if(err != noErr)
- handled_event = false;
- } else {
- CallNextEventHandler(er, event);
- }
- break; }
- default:
- handled_event = false;
- break;
- }
- if(!handled_event) //let the event go through
- return eventNotHandledErr;
- return noErr; //we eat the event
-}
-#endif
-
-OSViewRef qt_mac_create_widget(QWidget *widget, QWidgetPrivate *widgetPrivate, OSViewRef parent)
-{
-#ifdef QT_MAC_USE_COCOA
- QMacCocoaAutoReleasePool pool;
- QT_MANGLE_NAMESPACE(QCocoaView) *view = [[QT_MANGLE_NAMESPACE(QCocoaView) alloc] initWithQWidget:widget widgetPrivate:widgetPrivate];
-
-#ifdef ALIEN_DEBUG
- qDebug() << "Creating NSView for" << widget;
-#endif
-
- if (view && parent)
- [parent addSubview:view];
- return view;
-#else
- Q_UNUSED(widget);
- Q_UNUSED(widgetPrivate);
- if(!widget_class) {
- OSStatus err = HIObjectRegisterSubclass(kObjectQWidget, kHIViewClassID, 0, make_widget_eventUPP(),
- GetEventTypeCount(widget_events), widget_events,
- 0, &widget_class);
- if (err && err != hiObjectClassExistsErr)
- qWarning("QWidget: Internal error (%d)", __LINE__);
- }
- HIViewRef ret = 0;
- if(HIObjectCreate(kObjectQWidget, 0, (HIObjectRef*)&ret) != noErr)
- qWarning("QWidget: Internal error (%d)", __LINE__);
- if(ret && parent)
- HIViewAddSubview(parent, ret);
- return ret;
-#endif
-}
-
-void qt_mac_unregister_widget()
-{
-#ifndef QT_MAC_USE_COCOA
- HIObjectUnregisterClass(widget_class);
- widget_class = 0;
-#endif
-}
-
-void QWidgetPrivate::toggleDrawers(bool visible)
-{
- for (int i = 0; i < children.size(); ++i) {
- register QObject *object = children.at(i);
- if (!object->isWidgetType())
- continue;
- QWidget *widget = static_cast<QWidget*>(object);
- if(qt_mac_is_macdrawer(widget)) {
- bool oldState = widget->testAttribute(Qt::WA_WState_ExplicitShowHide);
- if(visible) {
- if (!widget->testAttribute(Qt::WA_WState_ExplicitShowHide))
- widget->show();
- } else {
- widget->hide();
- if(!oldState)
- widget->setAttribute(Qt::WA_WState_ExplicitShowHide, false);
- }
- }
- }
-}
-
-/*****************************************************************************
- QWidgetPrivate member functions
- *****************************************************************************/
-bool QWidgetPrivate::qt_mac_update_sizer(QWidget *w, int up)
-{
- // I'm not sure what "up" is
- if(!w || !w->isWindow())
- return false;
-
- QTLWExtra *topData = w->d_func()->topData();
- QWExtra *extraData = w->d_func()->extraData();
- // topData->resizer is only 4 bits, so subtracting -1 from zero causes bad stuff
- // to happen, prevent that here (you really want the thing hidden).
- if (up >= 0 || topData->resizer != 0)
- topData->resizer += up;
- OSWindowRef windowRef = qt_mac_window_for(OSViewRef(w->effectiveWinId()));
- {
-#ifndef QT_MAC_USE_COCOA
- WindowClass wclass;
- GetWindowClass(windowRef, &wclass);
- if(!(GetAvailableWindowAttributes(wclass) & kWindowResizableAttribute))
- return true;
-#endif
- }
- bool remove_grip = (topData->resizer || (w->windowFlags() & Qt::FramelessWindowHint)
- || (extraData->maxw && extraData->maxh &&
- extraData->maxw == extraData->minw && extraData->maxh == extraData->minh));
-#ifndef QT_MAC_USE_COCOA
- WindowAttributes attr;
- GetWindowAttributes(windowRef, &attr);
- if(remove_grip) {
- if(attr & kWindowResizableAttribute) {
- ChangeWindowAttributes(qt_mac_window_for(w), kWindowNoAttributes,
- kWindowResizableAttribute);
- ReshapeCustomWindow(qt_mac_window_for(w));
- }
- } else if(!(attr & kWindowResizableAttribute)) {
- ChangeWindowAttributes(windowRef, kWindowResizableAttribute,
- kWindowNoAttributes);
- ReshapeCustomWindow(windowRef);
- }
-#else
- [windowRef setShowsResizeIndicator:!remove_grip];
-#endif
- return true;
-}
-
-void QWidgetPrivate::qt_clean_root_win()
-{
-#ifdef QT_MAC_USE_COCOA
- QMacCocoaAutoReleasePool pool;
- [qt_root_win release];
-#else
- if(!qt_root_win)
- return;
- CFRelease(qt_root_win);
-#endif
- qt_root_win = 0;
-}
-
-bool QWidgetPrivate::qt_create_root_win()
-{
- if(qt_root_win)
- return false;
- const QSize desktopSize = qt_mac_desktopSize();
- QRect desktopRect(QPoint(0, 0), desktopSize);
-#ifdef QT_MAC_USE_COCOA
- qt_root_win = qt_mac_create_window(0, kOverlayWindowClass, NSBorderlessWindowMask, desktopRect);
-#else
- WindowAttributes wattr = (kWindowCompositingAttribute | kWindowStandardHandlerAttribute);
- qt_root_win = qt_mac_create_window(0, kOverlayWindowClass, wattr, desktopRect);
-#endif
- if(!qt_root_win)
- return false;
- qAddPostRoutine(qt_clean_root_win);
- return true;
-}
-
-bool QWidgetPrivate::qt_widget_rgn(QWidget *widget, short wcode, RgnHandle rgn, bool force = false)
-{
- bool ret = false;
-#ifndef QT_MAC_USE_COCOA
- switch(wcode) {
- case kWindowStructureRgn: {
- if(widget) {
- if(widget->d_func()->extra && !widget->d_func()->extra->mask.isEmpty()) {
- QRegion rin = qt_mac_convert_mac_region(rgn);
- if(!rin.isEmpty()) {
- QPoint rin_tl = rin.boundingRect().topLeft(); //in offset
- rin.translate(-rin_tl.x(), -rin_tl.y()); //bring into same space as below
- QRegion mask = widget->d_func()->extra->mask;
- Qt::WindowFlags flags = widget->windowFlags();
- if(widget->isWindow()
- && !(flags & Qt::FramelessWindowHint
- || (flags & Qt::CustomizeWindowHint && !(flags & Qt::WindowTitleHint)))) {
- QRegion title;
- {
- QMacSmartQuickDrawRegion rgn(qt_mac_get_rgn());
- GetWindowRegion(qt_mac_window_for(widget), kWindowTitleBarRgn, rgn);
- title = qt_mac_convert_mac_region(rgn);
- }
- QRect br = title.boundingRect();
- mask.translate(0, br.height()); //put the mask 'under' the title bar..
- title.translate(-br.x(), -br.y());
- mask += title;
- }
-
- QRegion cr = rin & mask;
- cr.translate(rin_tl.x(), rin_tl.y()); //translate back to incoming space
- CopyRgn(QMacSmartQuickDrawRegion(cr.toQDRgn()), rgn);
- }
- ret = true;
- } else if(force) {
- QRegion cr(widget->geometry());
- CopyRgn(QMacSmartQuickDrawRegion(cr.toQDRgn()), rgn);
- ret = true;
- }
- }
- break; }
- default: break;
- }
- //qDebug() << widget << ret << wcode << qt_mac_convert_mac_region(rgn);
-#else
- Q_UNUSED(widget);
- Q_UNUSED(wcode);
- Q_UNUSED(rgn);
- Q_UNUSED(force);
-#endif
- return ret;
-}
-
-/*****************************************************************************
- QWidget member functions
- *****************************************************************************/
-void QWidgetPrivate::determineWindowClass()
-{
- Q_Q(QWidget);
-#if !defined(QT_NO_MAINWINDOW) && !defined(QT_NO_TOOLBAR)
- // Make sure that QMainWindow has the MacWindowToolBarButtonHint when the
- // unifiedTitleAndToolBarOnMac property is ON. This is to avoid reentry of
- // setParent() triggered by the QToolBar::event(QEvent::ParentChange).
- QMainWindow *mainWindow = qobject_cast<QMainWindow *>(q);
- if (mainWindow && mainWindow->unifiedTitleAndToolBarOnMac()) {
- data.window_flags |= Qt::MacWindowToolBarButtonHint;
- }
-#endif
-#ifndef QT_MAC_USE_COCOA
-// ### COCOA:Interleave these better!
-
- const Qt::WindowType type = q->windowType();
- Qt::WindowFlags &flags = data.window_flags;
- const bool popup = (type == Qt::Popup);
- if (type == Qt::ToolTip || type == Qt::SplashScreen || popup)
- flags |= Qt::FramelessWindowHint;
-
- WindowClass wclass = kSheetWindowClass;
- if(qt_mac_is_macdrawer(q))
- wclass = kDrawerWindowClass;
- else if (q->testAttribute(Qt::WA_ShowModal) && flags & Qt::CustomizeWindowHint)
- wclass = kDocumentWindowClass;
- else if(popup || (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 && type == Qt::SplashScreen))
- wclass = kModalWindowClass;
- else if(q->testAttribute(Qt::WA_ShowModal))
- wclass = kMovableModalWindowClass;
- else if(type == Qt::ToolTip)
- wclass = kHelpWindowClass;
- else if(type == Qt::Tool || (QSysInfo::MacintoshVersion < QSysInfo::MV_10_5
- && type == Qt::SplashScreen))
- wclass = kFloatingWindowClass;
- else
- wclass = kDocumentWindowClass;
-
- WindowGroupRef grp = 0;
- WindowAttributes wattr = (kWindowCompositingAttribute | kWindowStandardHandlerAttribute);
- if (q->testAttribute(Qt::WA_MacFrameworkScaled))
- wattr |= kWindowFrameworkScaledAttribute;
- if(qt_mac_is_macsheet(q)) {
- //grp = GetWindowGroupOfClass(kMovableModalWindowClass);
- wclass = kSheetWindowClass;
- } else {
- grp = GetWindowGroupOfClass(wclass);
- // Shift things around a bit to get the correct window class based on the presence
- // (or lack) of the border.
- bool customize = flags & Qt::CustomizeWindowHint;
- bool framelessWindow = (flags & Qt::FramelessWindowHint || (customize && !(flags & Qt::WindowTitleHint)));
- if (framelessWindow) {
- if(wclass == kDocumentWindowClass) {
- wattr |= kWindowNoTitleBarAttribute;
- } else if(wclass == kFloatingWindowClass) {
- wattr |= kWindowNoTitleBarAttribute;
- } else if (wclass == kMovableModalWindowClass) {
- wclass = kModalWindowClass;
- }
- } else {
- if(wclass != kModalWindowClass)
- wattr |= kWindowResizableAttribute;
- }
- // Only add extra decorations (well, buttons) for widgets that can have them
- // and have an actual border we can put them on.
- if(wclass != kModalWindowClass && wclass != kMovableModalWindowClass
- && wclass != kSheetWindowClass && wclass != kPlainWindowClass
- && !framelessWindow && wclass != kDrawerWindowClass
- && wclass != kHelpWindowClass) {
- if (flags & Qt::WindowMaximizeButtonHint)
- wattr |= kWindowFullZoomAttribute;
- if (flags & Qt::WindowMinimizeButtonHint)
- wattr |= kWindowCollapseBoxAttribute;
- if (flags & Qt::WindowSystemMenuHint || flags & Qt::WindowCloseButtonHint)
- wattr |= kWindowCloseBoxAttribute;
- if (flags & Qt::MacWindowToolBarButtonHint)
- wattr |= kWindowToolbarButtonAttribute;
- } else {
- // Clear these hints so that we aren't call them on invalid windows
- flags &= ~(Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint
- | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint);
- }
- }
- if((popup || type == Qt::Tool) && !q->isModal())
- wattr |= kWindowHideOnSuspendAttribute;
- wattr |= kWindowLiveResizeAttribute;
-
-#ifdef DEBUG_WINDOW_CREATE
-#define ADD_DEBUG_WINDOW_NAME(x) { x, #x }
- struct {
- UInt32 tag;
- const char *name;
- } known_attribs[] = {
- ADD_DEBUG_WINDOW_NAME(kWindowCompositingAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowStandardHandlerAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowMetalAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowHideOnSuspendAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowStandardHandlerAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowCollapseBoxAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowHorizontalZoomAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowVerticalZoomAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowResizableAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowNoActivatesAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowNoUpdatesAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowOpaqueForEventsAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowLiveResizeAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowCloseBoxAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowHideOnSuspendAttribute),
- { 0, 0 }
- }, known_classes[] = {
- ADD_DEBUG_WINDOW_NAME(kHelpWindowClass),
- ADD_DEBUG_WINDOW_NAME(kPlainWindowClass),
- ADD_DEBUG_WINDOW_NAME(kDrawerWindowClass),
- ADD_DEBUG_WINDOW_NAME(kUtilityWindowClass),
- ADD_DEBUG_WINDOW_NAME(kToolbarWindowClass),
- ADD_DEBUG_WINDOW_NAME(kSheetWindowClass),
- ADD_DEBUG_WINDOW_NAME(kFloatingWindowClass),
- ADD_DEBUG_WINDOW_NAME(kUtilityWindowClass),
- ADD_DEBUG_WINDOW_NAME(kDocumentWindowClass),
- ADD_DEBUG_WINDOW_NAME(kToolbarWindowClass),
- ADD_DEBUG_WINDOW_NAME(kMovableModalWindowClass),
- ADD_DEBUG_WINDOW_NAME(kModalWindowClass),
- { 0, 0 }
- };
- qDebug("Qt: internal: ************* Creating new window %p (%s::%s)", q, q->metaObject()->className(),
- q->objectName().toLocal8Bit().constData());
- bool found_class = false;
- for(int i = 0; known_classes[i].name; i++) {
- if(wclass == known_classes[i].tag) {
- found_class = true;
- qDebug("Qt: internal: ** Class: %s", known_classes[i].name);
- break;
- }
- }
- if(!found_class)
- qDebug("Qt: internal: !! Class: Unknown! (%d)", (int)wclass);
- if(wattr) {
- WindowAttributes tmp_wattr = wattr;
- qDebug("Qt: internal: ** Attributes:");
- for(int i = 0; tmp_wattr && known_attribs[i].name; i++) {
- if((tmp_wattr & known_attribs[i].tag) == known_attribs[i].tag) {
- tmp_wattr ^= known_attribs[i].tag;
- qDebug("Qt: internal: * %s %s", known_attribs[i].name,
- (GetAvailableWindowAttributes(wclass) & known_attribs[i].tag) ? "" : "(*)");
- }
- }
- if(tmp_wattr)
- qDebug("Qt: internal: !! Attributes: Unknown (%d)", (int)tmp_wattr);
- }
-#endif
-
- /* Just to be extra careful we will change to the kUtilityWindowClass if the
- requested attributes cannot be used */
- if((GetAvailableWindowAttributes(wclass) & wattr) != wattr) {
- WindowClass tmp_class = wclass;
- if(wclass == kToolbarWindowClass || wclass == kUtilityWindowClass)
- wclass = kFloatingWindowClass;
- if(tmp_class != wclass) {
- if(!grp)
- grp = GetWindowGroupOfClass(wclass);
- wclass = tmp_class;
- }
- }
- topData()->wclass = wclass;
- topData()->wattr = wattr;
-#else
- const Qt::WindowType type = q->windowType();
- Qt::WindowFlags &flags = data.window_flags;
- const bool popup = (type == Qt::Popup);
- if (type == Qt::ToolTip || type == Qt::SplashScreen || popup)
- flags |= Qt::FramelessWindowHint;
-
- WindowClass wclass = kSheetWindowClass;
- if(qt_mac_is_macdrawer(q))
- wclass = kDrawerWindowClass;
- else if (q->testAttribute(Qt::WA_ShowModal) && flags & Qt::CustomizeWindowHint)
- wclass = kDocumentWindowClass;
- else if(popup || (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5 && type == Qt::SplashScreen))
- wclass = kModalWindowClass;
- else if(type == Qt::Dialog)
- wclass = kMovableModalWindowClass;
- else if(type == Qt::ToolTip)
- wclass = kHelpWindowClass;
- else if(type == Qt::Tool || (QSysInfo::MacintoshVersion < QSysInfo::MV_10_5
- && type == Qt::SplashScreen))
- wclass = kFloatingWindowClass;
- else if(q->testAttribute(Qt::WA_ShowModal))
- wclass = kMovableModalWindowClass;
- else
- wclass = kDocumentWindowClass;
-
- WindowAttributes wattr = NSBorderlessWindowMask;
- if(qt_mac_is_macsheet(q)) {
- //grp = GetWindowGroupOfClass(kMovableModalWindowClass);
- wclass = kSheetWindowClass;
- wattr = NSTitledWindowMask | NSResizableWindowMask;
- } else {
-#ifndef QT_MAC_USE_COCOA
- grp = GetWindowGroupOfClass(wclass);
-#endif
- // Shift things around a bit to get the correct window class based on the presence
- // (or lack) of the border.
- bool customize = flags & Qt::CustomizeWindowHint;
- bool framelessWindow = (flags & Qt::FramelessWindowHint || (customize && !(flags & Qt::WindowTitleHint)));
- if (framelessWindow) {
- if (wclass == kDocumentWindowClass) {
- wclass = kSimpleWindowClass;
- } else if (wclass == kFloatingWindowClass) {
- wclass = kToolbarWindowClass;
- } else if (wclass == kMovableModalWindowClass) {
- wclass = kModalWindowClass;
- }
- } else {
- wattr |= NSTitledWindowMask;
- if (wclass != kModalWindowClass)
- wattr |= NSResizableWindowMask;
- }
- // Only add extra decorations (well, buttons) for widgets that can have them
- // and have an actual border we can put them on.
- if (wclass != kModalWindowClass
- && wclass != kSheetWindowClass && wclass != kPlainWindowClass
- && !framelessWindow && wclass != kDrawerWindowClass
- && wclass != kHelpWindowClass) {
- if (flags & Qt::WindowMinimizeButtonHint)
- wattr |= NSMiniaturizableWindowMask;
- if (flags & Qt::WindowSystemMenuHint || flags & Qt::WindowCloseButtonHint)
- wattr |= NSClosableWindowMask;
- } else {
- // Clear these hints so that we aren't call them on invalid windows
- flags &= ~(Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint
- | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint);
- }
- }
- if (q->testAttribute(Qt::WA_MacBrushedMetal))
- wattr |= NSTexturedBackgroundWindowMask;
-
-#ifdef DEBUG_WINDOW_CREATE
-#define ADD_DEBUG_WINDOW_NAME(x) { x, #x }
- struct {
- UInt32 tag;
- const char *name;
- } known_attribs[] = {
- ADD_DEBUG_WINDOW_NAME(kWindowCompositingAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowStandardHandlerAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowMetalAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowHideOnSuspendAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowStandardHandlerAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowCollapseBoxAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowHorizontalZoomAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowVerticalZoomAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowResizableAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowNoActivatesAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowNoUpdatesAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowOpaqueForEventsAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowLiveResizeAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowCloseBoxAttribute),
- ADD_DEBUG_WINDOW_NAME(kWindowHideOnSuspendAttribute),
- { 0, 0 }
- }, known_classes[] = {
- ADD_DEBUG_WINDOW_NAME(kHelpWindowClass),
- ADD_DEBUG_WINDOW_NAME(kPlainWindowClass),
- ADD_DEBUG_WINDOW_NAME(kDrawerWindowClass),
- ADD_DEBUG_WINDOW_NAME(kUtilityWindowClass),
- ADD_DEBUG_WINDOW_NAME(kToolbarWindowClass),
- ADD_DEBUG_WINDOW_NAME(kSheetWindowClass),
- ADD_DEBUG_WINDOW_NAME(kFloatingWindowClass),
- ADD_DEBUG_WINDOW_NAME(kUtilityWindowClass),
- ADD_DEBUG_WINDOW_NAME(kDocumentWindowClass),
- ADD_DEBUG_WINDOW_NAME(kToolbarWindowClass),
- ADD_DEBUG_WINDOW_NAME(kMovableModalWindowClass),
- ADD_DEBUG_WINDOW_NAME(kModalWindowClass),
- { 0, 0 }
- };
- qDebug("Qt: internal: ************* Creating new window %p (%s::%s)", q, q->metaObject()->className(),
- q->objectName().toLocal8Bit().constData());
- bool found_class = false;
- for(int i = 0; known_classes[i].name; i++) {
- if(wclass == known_classes[i].tag) {
- found_class = true;
- qDebug("Qt: internal: ** Class: %s", known_classes[i].name);
- break;
- }
- }
- if(!found_class)
- qDebug("Qt: internal: !! Class: Unknown! (%d)", (int)wclass);
- if(wattr) {
- WindowAttributes tmp_wattr = wattr;
- qDebug("Qt: internal: ** Attributes:");
- for(int i = 0; tmp_wattr && known_attribs[i].name; i++) {
- if((tmp_wattr & known_attribs[i].tag) == known_attribs[i].tag) {
- tmp_wattr ^= known_attribs[i].tag;
- }
- }
- if(tmp_wattr)
- qDebug("Qt: internal: !! Attributes: Unknown (%d)", (int)tmp_wattr);
- }
-#endif
-
-#ifndef QT_MAC_USE_COCOA
- /* Just to be extra careful we will change to the kUtilityWindowClass if the
- requested attributes cannot be used */
- if((GetAvailableWindowAttributes(wclass) & wattr) != wattr) {
- WindowClass tmp_class = wclass;
- if(wclass == kToolbarWindowClass || wclass == kUtilityWindowClass)
- wclass = kFloatingWindowClass;
- if(tmp_class != wclass) {
- if(!grp)
- grp = GetWindowGroupOfClass(wclass);
- wclass = tmp_class;
- }
- }
-#endif
-#endif
- topData()->wclass = wclass;
- topData()->wattr = wattr;
-}
-
-#ifndef QT_MAC_USE_COCOA // This is handled in Cocoa via our category.
-void QWidgetPrivate::initWindowPtr()
-{
- Q_Q(QWidget);
- OSWindowRef windowRef = qt_mac_window_for(qt_mac_nativeview_for(q)); //do not create!
- if(!windowRef)
- return;
- QWidget *window = q->window(), *oldWindow = 0;
- if(GetWindowProperty(windowRef, kWidgetCreatorQt, kWidgetPropertyQWidget, sizeof(oldWindow), 0, &oldWindow) == noErr) {
- Q_ASSERT(window == oldWindow);
- return;
- }
-
- if(SetWindowProperty(windowRef, kWidgetCreatorQt, kWidgetPropertyQWidget, sizeof(window), &window) != noErr)
- qWarning("Qt:Internal error (%s:%d)", __FILE__, __LINE__); //no real way to recover
- if(!q->windowType() != Qt::Desktop) { //setup an event callback handler on the window
- InstallWindowEventHandler(windowRef, make_win_eventUPP(), GetEventTypeCount(window_events),
- window_events, static_cast<void *>(qApp), &window_event);
- }
-}
-
-void QWidgetPrivate::finishCreateWindow_sys_Carbon(OSWindowRef windowRef)
-{
- Q_Q(QWidget);
- const Qt::WindowType type = q->windowType();
- Qt::WindowFlags &flags = data.window_flags;
- QWidget *parentWidget = q->parentWidget();
-
- const bool desktop = (type == Qt::Desktop);
- const bool dialog = (type == Qt::Dialog
- || type == Qt::Sheet
- || type == Qt::Drawer
- || (flags & Qt::MSWindowsFixedSizeDialogHint));
- QTLWExtra *topExtra = topData();
- quint32 wattr = topExtra->wattr;
- if (!desktop)
- SetAutomaticControlDragTrackingEnabledForWindow(windowRef, true);
- HIWindowChangeFeatures(windowRef, kWindowCanCollapse, 0);
- if (wattr & kWindowHideOnSuspendAttribute)
- HIWindowChangeAvailability(windowRef, kHIWindowExposeHidden, 0);
- else
- HIWindowChangeAvailability(windowRef, 0, kHIWindowExposeHidden);
- if ((flags & Qt::WindowStaysOnTopHint))
- ChangeWindowAttributes(windowRef, kWindowNoAttributes, kWindowHideOnSuspendAttribute);
- if (qt_mac_is_macdrawer(q) && parentWidget)
- SetDrawerParent(windowRef, qt_mac_window_for (parentWidget));
- if (topExtra->group) {
- qt_mac_release_window_group(topExtra->group);
- topExtra->group = 0;
- }
- if (type == Qt::ToolTip)
- qt_mac_set_window_group_to_tooltip(windowRef);
- else if (type == Qt::Popup && (flags & Qt::WindowStaysOnTopHint))
- qt_mac_set_window_group_to_popup(windowRef);
- else if (flags & Qt::WindowStaysOnTopHint)
- qt_mac_set_window_group_to_stays_on_top(windowRef, type);
- else if (dialog)
- SetWindowGroup(windowRef, GetWindowGroupOfClass(kMovableModalWindowClass));
-
-#ifdef DEBUG_WINDOW_CREATE
- if (WindowGroupRef grpf = GetWindowGroup(windowRef)) {
- QCFString cfname;
- CopyWindowGroupName(grpf, &cfname);
- SInt32 lvl;
- GetWindowGroupLevel(grpf, &lvl);
- const char *from = "Default";
- if (topExtra && grpf == topData()->group)
- from = "Created";
- else if (grpf == grp)
- from = "Copied";
- qDebug("Qt: internal: With window group '%s' [%p] @ %d: %s",
- static_cast<QString>(cfname).toLatin1().constData(), grpf, (int)lvl, from);
- } else {
- qDebug("Qt: internal: No window group!!!");
- }
- HIWindowAvailability hi_avail = 0;
- if (HIWindowGetAvailability(windowRef, &hi_avail) == noErr) {
- struct {
- UInt32 tag;
- const char *name;
- } known_avail[] = {
- ADD_DEBUG_WINDOW_NAME(kHIWindowExposeHidden),
- { 0, 0 }
- };
- qDebug("Qt: internal: ** HIWindowAvailibility:");
- for (int i = 0; hi_avail && known_avail[i].name; i++) {
- if ((hi_avail & known_avail[i].tag) == known_avail[i].tag) {
- hi_avail ^= known_avail[i].tag;
- qDebug("Qt: internal: * %s", known_avail[i].name);
- }
- }
- if (hi_avail)
- qDebug("Qt: internal: !! Attributes: Unknown (%d)", (int)hi_avail);
- }
-#undef ADD_DEBUG_WINDOW_NAME
-#endif
- if (extra && !extra->mask.isEmpty())
- ReshapeCustomWindow(windowRef);
- SetWindowModality(windowRef, kWindowModalityNone, 0);
- if (qt_mac_is_macdrawer(q))
- SetDrawerOffsets(windowRef, 0.0, 25.0);
- data.fstrut_dirty = true; // when we create a toplevel widget, the frame strut should be dirty
- HIViewRef hiview = (HIViewRef)data.winid;
- HIViewRef window_hiview = qt_mac_get_contentview_for(windowRef);
- if(!hiview) {
- hiview = qt_mac_create_widget(q, this, window_hiview);
- setWinId((WId)hiview);
- } else {
- HIViewAddSubview(window_hiview, hiview);
- }
- if (hiview) {
- Rect win_rect;
- GetWindowBounds(qt_mac_window_for (window_hiview), kWindowContentRgn, &win_rect);
- HIRect bounds = CGRectMake(0, 0, win_rect.right-win_rect.left, win_rect.bottom-win_rect.top);
- HIViewSetFrame(hiview, &bounds);
- HIViewSetVisible(hiview, true);
- if (q->testAttribute(Qt::WA_DropSiteRegistered))
- registerDropSite(true);
- transferChildren();
- }
- initWindowPtr();
-
- if (topExtra->posFromMove) {
- updateFrameStrut();
- const QRect &fStrut = frameStrut();
- Rect r;
- SetRect(&r, data.crect.left(), data.crect.top(), data.crect.right() + 1, data.crect.bottom() + 1);
- SetRect(&r, r.left + fStrut.left(), r.top + fStrut.top(),
- (r.left + fStrut.left() + data.crect.width()) - fStrut.right(),
- (r.top + fStrut.top() + data.crect.height()) - fStrut.bottom());
- SetWindowBounds(windowRef, kWindowContentRgn, &r);
- topExtra->posFromMove = false;
- }
-
- if (q->testAttribute(Qt::WA_WState_WindowOpacitySet)){
- q->setWindowOpacity(topExtra->opacity / 255.0f);
- } else if (qt_mac_is_macsheet(q)){
- SetThemeWindowBackground(qt_mac_window_for(q), kThemeBrushSheetBackgroundTransparent, true);
- CGFloat alpha = 0;
- GetWindowAlpha(qt_mac_window_for(q), &alpha);
- if (alpha == 1){
- // For some reason the 'SetThemeWindowBackground' does not seem
- // to work. So we do this little hack until it hopefully starts to
- // work in newer versions of mac OS.
- q->setWindowOpacity(0.95f);
- q->setAttribute(Qt::WA_WState_WindowOpacitySet, false);
- }
- } else{
- // If the window has been recreated after beeing e.g. a sheet,
- // make sure that we don't report a faulty opacity:
- q->setWindowOpacity(1.0f);
- q->setAttribute(Qt::WA_WState_WindowOpacitySet, false);
- }
-
- // Since we only now have a window, sync our state.
- macUpdateHideOnSuspend();
- macUpdateOpaqueSizeGrip();
- macUpdateMetalAttribute();
- macUpdateIgnoreMouseEvents();
- setWindowTitle_helper(extra->topextra->caption);
- setWindowIconText_helper(extra->topextra->iconText);
- setWindowFilePath_helper(extra->topextra->filePath);
- setWindowModified_sys(q->isWindowModified());
- updateFrameStrut();
- qt_mac_update_sizer(q);
- applyMaxAndMinSizeOnWindow();
-}
-#else // QT_MAC_USE_COCOA
-
-void QWidgetPrivate::setWindowLevel()
-{
- Q_Q(QWidget);
- const QWidget * const windowParent = q->window()->parentWidget();
- const QWidget * const primaryWindow = windowParent ? windowParent->window() : 0;
- NSInteger winLevel = -1;
-
- if (q->windowType() == Qt::Popup) {
- winLevel = NSPopUpMenuWindowLevel;
- // Popup should be in at least the same level as its parent.
- if (primaryWindow) {
- OSWindowRef parentRef = qt_mac_window_for(primaryWindow);
- winLevel = qMax([parentRef level], winLevel);
- }
- } else if (q->windowType() == Qt::Tool) {
- winLevel = NSFloatingWindowLevel;
- } else if (q->windowType() == Qt::Dialog) {
- // Correct modality level (NSModalPanelWindowLevel) will be
- // set by cocoa when creating a modal session later.
- winLevel = NSNormalWindowLevel;
- }
-
- // StayOnTop window should appear above Tool windows.
- if (data.window_flags & Qt::WindowStaysOnTopHint)
- winLevel = NSPopUpMenuWindowLevel;
- // Tooltips should appear above StayOnTop windows.
- if (q->windowType() == Qt::ToolTip)
- winLevel = NSScreenSaverWindowLevel;
- // All other types are Normal level.
- if (winLevel == -1)
- winLevel = NSNormalWindowLevel;
- [qt_mac_window_for(q) setLevel:winLevel];
-}
-
-void QWidgetPrivate::finishCreateWindow_sys_Cocoa(void * /*NSWindow * */ voidWindowRef)
-{
- Q_Q(QWidget);
- QMacCocoaAutoReleasePool pool;
- NSWindow *windowRef = static_cast<NSWindow *>(voidWindowRef);
- const Qt::WindowType type = q->windowType();
- Qt::WindowFlags &flags = data.window_flags;
- QWidget *parentWidget = q->parentWidget();
-
- const bool popup = (type == Qt::Popup);
- const bool dialog = (type == Qt::Dialog
- || type == Qt::Sheet
- || type == Qt::Drawer
- || (flags & Qt::MSWindowsFixedSizeDialogHint));
- QTLWExtra *topExtra = topData();
-
- if ((popup || type == Qt::Tool || type == Qt::ToolTip) && !q->isModal()) {
- [windowRef setHidesOnDeactivate:YES];
- } else {
- [windowRef setHidesOnDeactivate:NO];
- }
- if (q->testAttribute(Qt::WA_MacNoShadow))
- [windowRef setHasShadow:NO];
- else
- [windowRef setHasShadow:YES];
- Q_UNUSED(parentWidget);
- Q_UNUSED(dialog);
-
- data.fstrut_dirty = true; // when we create a toplevel widget, the frame strut should be dirty
-
- OSViewRef nsview = (OSViewRef)data.winid;
- if (!nsview) {
- nsview = qt_mac_create_widget(q, this, 0);
- setWinId(WId(nsview));
- }
- [windowRef setContentView:nsview];
- [nsview setHidden:NO];
- transferChildren();
-
- // Tell Cocoa explicit that we wan't the view to receive key events
- // (regardless of focus policy) because this is how it works on other
- // platforms (and in the carbon port):
- [windowRef makeFirstResponder:nsview];
-
- if (topExtra->posFromMove) {
- updateFrameStrut();
-
- const QRect &fStrut = frameStrut();
- const QRect &crect = data.crect;
- const QRect frameRect(QPoint(crect.left(), crect.top()),
- QSize(fStrut.left() + fStrut.right() + crect.width(),
- fStrut.top() + fStrut.bottom() + crect.height()));
- NSRect cocoaFrameRect = NSMakeRect(frameRect.x(), flipYCoordinate(frameRect.bottom() + 1),
- frameRect.width(), frameRect.height());
- [windowRef setFrame:cocoaFrameRect display:NO];
- topExtra->posFromMove = false;
- }
-
- if (q->testAttribute(Qt::WA_WState_WindowOpacitySet)){
- q->setWindowOpacity(topExtra->opacity / 255.0f);
- } else if (qt_mac_is_macsheet(q)){
- CGFloat alpha = [qt_mac_window_for(q) alphaValue];
- if (alpha >= 1.0) {
- q->setWindowOpacity(0.95f);
- q->setAttribute(Qt::WA_WState_WindowOpacitySet, false);
- }
- } else{
- // If the window has been recreated after beeing e.g. a sheet,
- // make sure that we don't report a faulty opacity:
- q->setWindowOpacity(1.0f);
- q->setAttribute(Qt::WA_WState_WindowOpacitySet, false);
- }
-
- // Its more performant to handle the mouse cursor
- // ourselves, expecially when using alien widgets:
- [windowRef disableCursorRects];
-
- setWindowLevel();
- macUpdateHideOnSuspend();
- macUpdateOpaqueSizeGrip();
- macUpdateIgnoreMouseEvents();
- setWindowTitle_helper(extra->topextra->caption);
- setWindowIconText_helper(extra->topextra->iconText);
- setWindowModified_sys(q->isWindowModified());
- updateFrameStrut();
- syncCocoaMask();
- macUpdateIsOpaque();
- qt_mac_update_sizer(q);
- applyMaxAndMinSizeOnWindow();
-}
-
-#endif // QT_MAC_USE_COCOA
-
-/*
- Recreates widget window. Useful if immutable
- properties for it has changed.
- */
-void QWidgetPrivate::recreateMacWindow()
-{
- Q_Q(QWidget);
- OSViewRef myView = qt_mac_nativeview_for(q);
- OSWindowRef oldWindow = qt_mac_window_for(myView);
-#ifndef QT_MAC_USE_COCOA
- HIViewRemoveFromSuperview(myView);
- determineWindowClass();
- createWindow_sys();
-
- if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) {
- mwl->updateHIToolBarStatus();
- }
-
- if (IsWindowVisible(oldWindow))
- show_sys();
-#else
- QMacCocoaAutoReleasePool pool;
- [myView removeFromSuperview];
- determineWindowClass();
- createWindow_sys();
- if (NSToolbar *toolbar = [oldWindow toolbar]) {
- OSWindowRef newWindow = qt_mac_window_for(myView);
- [newWindow setToolbar:toolbar];
- [toolbar setVisible:[toolbar isVisible]];
- }
- if ([oldWindow isVisible]){
- if ([oldWindow isSheet])
- [NSApp endSheet:oldWindow];
- [oldWindow orderOut:oldWindow];
- show_sys();
- }
-#endif // QT_MAC_USE_COCOA
-
- // Release the window after creating the new window, because releasing it early
- // may cause the app to quit ("close on last window closed attribute")
- qt_mac_destructWindow(oldWindow);
-}
-
-void QWidgetPrivate::createWindow_sys()
-{
- Q_Q(QWidget);
- Qt::WindowFlags &flags = data.window_flags;
- QWidget *parentWidget = q->parentWidget();
-
- QTLWExtra *topExtra = topData();
- if (topExtra->embedded)
- return; // Simply return because this view "is" the top window.
- quint32 wattr = topExtra->wattr;
-
- if(parentWidget && (parentWidget->window()->windowFlags() & Qt::WindowStaysOnTopHint)) // If our parent has Qt::WStyle_StaysOnTop, so must we
- flags |= Qt::WindowStaysOnTopHint;
-
- data.fstrut_dirty = true;
-
- OSWindowRef windowRef = qt_mac_create_window(q, topExtra->wclass, wattr, data.crect);
- if (windowRef == 0)
- qWarning("QWidget: Internal error: %s:%d: If you reach this error please contact Qt Support and include the\n"
- " WidgetFlags used in creating the widget.", __FILE__, __LINE__);
-#ifndef QT_MAC_USE_COCOA
- finishCreateWindow_sys_Carbon(windowRef);
-#else
- finishCreateWindow_sys_Cocoa(windowRef);
-#endif
-}
-
-void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow)
-{
- Q_Q(QWidget);
- QMacCocoaAutoReleasePool pool;
-
- OSViewRef destroyid = 0;
-#ifndef QT_MAC_USE_COCOA
- window_event = 0;
-#endif
-
- Qt::WindowType type = q->windowType();
- Qt::WindowFlags flags = data.window_flags;
- QWidget *parentWidget = q->parentWidget();
-
- bool topLevel = (flags & Qt::Window);
- bool popup = (type == Qt::Popup);
- bool dialog = (type == Qt::Dialog
- || type == Qt::Sheet
- || type == Qt::Drawer
- || (flags & Qt::MSWindowsFixedSizeDialogHint));
- bool desktop = (type == Qt::Desktop);
-
- // Determine this early for top-levels so, we can use it later.
- if (topLevel)
- determineWindowClass();
-
- if (desktop) {
- QSize desktopSize = qt_mac_desktopSize();
- q->setAttribute(Qt::WA_WState_Visible);
- data.crect.setRect(0, 0, desktopSize.width(), desktopSize.height());
- dialog = popup = false; // force these flags off
- } else {
- if (topLevel && (type != Qt::Drawer)) {
- if (QDesktopWidget *dsk = QApplication::desktop()) { // calc pos/size from screen
- const bool wasResized = q->testAttribute(Qt::WA_Resized);
- const bool wasMoved = q->testAttribute(Qt::WA_Moved);
- int deskn = dsk->primaryScreen();
- if (parentWidget && parentWidget->windowType() != Qt::Desktop)
- deskn = dsk->screenNumber(parentWidget);
- QRect screenGeo = dsk->screenGeometry(deskn);
- if (!wasResized) {
-#ifndef QT_MAC_USE_COCOA
- data.crect.setSize(QSize(screenGeo.width()/2, 4*screenGeo.height()/10));
-#else
- NSRect newRect = [NSWindow frameRectForContentRect:NSMakeRect(0, 0,
- screenGeo.width() / 2.,
- 4 * screenGeo.height() / 10.)
- styleMask:topData()->wattr];
- data.crect.setSize(QSize(newRect.size.width, newRect.size.height));
-#endif
- // Constrain to minimums and maximums we've set
- if (extra->minw > 0)
- data.crect.setWidth(qMax(extra->minw, data.crect.width()));
- if (extra->minh > 0)
- data.crect.setHeight(qMax(extra->minh, data.crect.height()));
- if (extra->maxw > 0)
- data.crect.setWidth(qMin(extra->maxw, data.crect.width()));
- if (extra->maxh > 0)
- data.crect.setHeight(qMin(extra->maxh, data.crect.height()));
- }
- if (!wasMoved && !q->testAttribute(Qt::WA_DontShowOnScreen))
- data.crect.moveTopLeft(QPoint(screenGeo.width()/4,
- 3 * screenGeo.height() / 10));
- }
- }
- }
-
-
- if(!window) // always initialize
- initializeWindow=true;
-
- hd = 0;
- if(window) { // override the old window (with a new NSView)
- OSViewRef nativeView = OSViewRef(window);
- OSViewRef parent = 0;
-#ifndef QT_MAC_USE_COCOA
- CFRetain(nativeView);
-#else
- [nativeView retain];
-#endif
- if (destroyOldWindow)
- destroyid = qt_mac_nativeview_for(q);
- bool transfer = false;
- setWinId((WId)nativeView);
-#ifndef QT_MAC_USE_COCOA
-#ifndef HIViewInstallEventHandler
- // Macro taken from the CarbonEvents Header on Tiger
-#define HIViewInstallEventHandler( target, handler, numTypes, list, userData, outHandlerRef ) \
- InstallEventHandler( HIObjectGetEventTarget( (HIObjectRef) (target) ), (handler), (numTypes), (list), (userData), (outHandlerRef) )
-#endif
- HIViewInstallEventHandler(nativeView, make_widget_eventUPP(), GetEventTypeCount(widget_events), widget_events, 0, 0);
-#endif
- if(topLevel) {
- for(int i = 0; i < 2; ++i) {
- if(i == 1) {
- if(!initializeWindow)
- break;
- createWindow_sys();
- }
- if(OSWindowRef windowref = qt_mac_window_for(nativeView)) {
-#ifndef QT_MAC_USE_COCOA
- CFRetain(windowref);
-#else
- [windowref retain];
-#endif
- if (initializeWindow) {
- parent = qt_mac_get_contentview_for(windowref);
- } else {
-#ifndef QT_MAC_USE_COCOA
- parent = HIViewGetSuperview(nativeView);
-#else
- parent = [nativeView superview];
-#endif
- }
- break;
- }
- }
- if(!parent)
- transfer = true;
- } else if (parentWidget) {
- // I need to be added to my parent, therefore my parent needs an NSView
- // Alien note: a 'window' was supplied as argument, meaning this widget
- // is not alien. So therefore the parent cannot be alien either.
- parentWidget->createWinId();
- parent = qt_mac_nativeview_for(parentWidget);
- }
- if(parent != nativeView && parent) {
-#ifndef QT_MAC_USE_COCOA
- HIViewAddSubview(parent, nativeView);
-#else
- [parent addSubview:nativeView];
-#endif
- }
- if(transfer)
- transferChildren();
- data.fstrut_dirty = true; // we'll re calculate this later
- q->setAttribute(Qt::WA_WState_Visible,
-#ifndef QT_MAC_USE_COCOA
- HIViewIsVisible(nativeView)
-#else
- ![nativeView isHidden]
-#endif
- );
- if(initializeWindow) {
-#ifndef QT_MAC_USE_COCOA
- HIRect bounds = CGRectMake(data.crect.x(), data.crect.y(), data.crect.width(), data.crect.height());
- HIViewSetFrame(nativeView, &bounds);
- q->setAttribute(Qt::WA_WState_Visible, HIViewIsVisible(nativeView));
-#else
- NSRect bounds = NSMakeRect(data.crect.x(), data.crect.y(), data.crect.width(), data.crect.height());
- [nativeView setFrame:bounds];
- q->setAttribute(Qt::WA_WState_Visible, [nativeView isHidden]);
-#endif
- }
-#ifndef QT_MAC_USE_COCOA
- initWindowPtr();
-#endif
- } else if (desktop) { // desktop widget
- if (!qt_root_win)
- QWidgetPrivate::qt_create_root_win();
- Q_ASSERT(qt_root_win);
- WId rootWinID = 0;
-#ifndef QT_MAC_USE_COCOA
- CFRetain(qt_root_win);
- if(HIViewRef rootContentView = HIViewGetRoot(qt_root_win)) {
- rootWinID = (WId)rootContentView;
- CFRetain(rootContentView);
- }
-#else
- [qt_root_win retain];
- if (OSViewRef rootContentView = [qt_root_win contentView]) {
- rootWinID = (WId)rootContentView;
- [rootContentView retain];
- }
-#endif
- setWinId(rootWinID);
- } else if (topLevel) {
- determineWindowClass();
- if(OSViewRef osview = qt_mac_create_widget(q, this, 0)) {
-#ifndef QT_MAC_USE_COCOA
- HIRect bounds = CGRectMake(data.crect.x(), data.crect.y(),
- data.crect.width(), data.crect.height());
- HIViewSetFrame(osview, &bounds);
-#else
- NSRect bounds = NSMakeRect(data.crect.x(), flipYCoordinate(data.crect.y()),
- data.crect.width(), data.crect.height());
- [osview setFrame:bounds];
-#endif
- setWinId((WId)osview);
- }
- } else {
- data.fstrut_dirty = false; // non-toplevel widgets don't have a frame, so no need to update the strut
-
-#ifdef QT_MAC_USE_COCOA
- if (q->testAttribute(Qt::WA_NativeWindow) == false || q->internalWinId() != 0) {
- // INVARIANT: q is Alien, and we should not create an NSView to back it up.
- } else
-#endif
- if (OSViewRef osview = qt_mac_create_widget(q, this, qt_mac_nativeview_for(parentWidget))) {
-#ifndef QT_MAC_USE_COCOA
- HIRect bounds = CGRectMake(data.crect.x(), data.crect.y(), data.crect.width(), data.crect.height());
- HIViewSetFrame(osview, &bounds);
- setWinId((WId)osview);
-#else
- NSRect bounds = NSMakeRect(data.crect.x(), data.crect.y(), data.crect.width(), data.crect.height());
- [osview setFrame:bounds];
- setWinId((WId)osview);
- if (q->isVisible()) {
- // If q were Alien before, but now became native (e.g. if a call to
- // winId was done from somewhere), we need to show the view immidiatly:
- QMacCocoaAutoReleasePool pool;
- [osview setHidden:NO];
- }
-#endif
- }
- }
-
- updateIsOpaque();
-
- if (q->testAttribute(Qt::WA_DropSiteRegistered))
- registerDropSite(true);
- if (q->hasFocus())
- setFocus_sys();
- if (!topLevel && initializeWindow)
- setWSGeometry();
- if (destroyid)
- qt_mac_destructView(destroyid);
-}
-
-/*!
- Returns the QuickDraw handle of the widget. Use of this function is not
- portable. This function will return 0 if QuickDraw is not supported, or
- if the handle could not be created.
-
- \warning This function is only available on Mac OS X.
-*/
-
-Qt::HANDLE
-QWidget::macQDHandle() const
-{
-#ifndef QT_MAC_USE_COCOA
- return d_func()->qd_hd;
-#else
- return 0;
-#endif
-}
-
-/*!
- Returns the CoreGraphics handle of the widget. Use of this function is
- not portable. This function will return 0 if no painter context can be
- established, or if the handle could not be created.
-
- \warning This function is only available on Mac OS X.
-*/
-Qt::HANDLE
-QWidget::macCGHandle() const
-{
- return handle();
-}
-
-void qt_mac_repaintParentUnderAlienWidget(QWidget *alienWidget)
-{
- QWidget *nativeParent = alienWidget->nativeParentWidget();
- if (!nativeParent)
- return;
-
- QPoint globalPos = alienWidget->mapToGlobal(QPoint(0, 0));
- QRect dirtyRect = QRect(nativeParent->mapFromGlobal(globalPos), alienWidget->size());
- nativeParent->repaint(dirtyRect);
-}
-
-void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
-{
- Q_D(QWidget);
- QMacCocoaAutoReleasePool pool;
- d->aboutToDestroy();
- if (!isWindow() && parentWidget())
- parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry()));
- if (!internalWinId())
- qt_mac_repaintParentUnderAlienWidget(this);
- d->deactivateWidgetCleanup();
- qt_mac_event_release(this);
- if(testAttribute(Qt::WA_WState_Created)) {
- setAttribute(Qt::WA_WState_Created, false);
- QObjectList chldrn = children();
- for(int i = 0; i < chldrn.size(); i++) { // destroy all widget children
- QObject *obj = chldrn.at(i);
- if(obj->isWidgetType())
- static_cast<QWidget*>(obj)->destroy(destroySubWindows, destroySubWindows);
- }
- if(mac_mouse_grabber == this)
- releaseMouse();
- if(mac_keyboard_grabber == this)
- releaseKeyboard();
-
- if(testAttribute(Qt::WA_ShowModal)) // just be sure we leave modal
- QApplicationPrivate::leaveModal(this);
- else if((windowType() == Qt::Popup))
- qApp->d_func()->closePopup(this);
- if (destroyWindow) {
- if(OSViewRef hiview = qt_mac_nativeview_for(this)) {
- OSWindowRef window = 0;
- NSDrawer *drawer = nil;
-#ifdef QT_MAC_USE_COCOA
- if (qt_mac_is_macdrawer(this)) {
- drawer = qt_mac_drawer_for(this);
- } else
-#endif
- if (isWindow())
- window = qt_mac_window_for(hiview);
-
- // Because of how "destruct" works, we have to do just a normal release for the root_win.
- if (window && window == qt_root_win) {
-#ifndef QT_MAC_USE_COCOA
- CFRelease(hiview);
-#else
- [hiview release];
-#endif
- } else {
- qt_mac_destructView(hiview);
- }
- if (drawer)
- qt_mac_destructDrawer(drawer);
- if (window)
- qt_mac_destructWindow(window);
- }
- }
- QT_TRY {
- d->setWinId(0);
- } QT_CATCH (const std::bad_alloc &) {
- // swallow - destructors must not throw
- }
- }
-}
-
-void QWidgetPrivate::transferChildren()
-{
- Q_Q(QWidget);
- if (!q->internalWinId())
- return; // Can't add any views anyway
-
- QObjectList chlist = q->children();
- for (int i = 0; i < chlist.size(); ++i) {
- QObject *obj = chlist.at(i);
- if (obj->isWidgetType()) {
- QWidget *w = (QWidget *)obj;
- if (!w->isWindow()) {
- // This seems weird, no need to call it in a loop right?
- if (!topData()->caption.isEmpty())
- setWindowTitle_helper(extra->topextra->caption);
- if (w->internalWinId()) {
-#ifndef QT_MAC_USE_COCOA
- HIViewAddSubview(qt_mac_nativeview_for(q), qt_mac_nativeview_for(w));
-#else
- // New NSWindows get an extra reference when drops are
- // registered (at least in 10.5) which means that we may
- // access the window later and get a crash (becasue our
- // widget is dead). Work around this be having the drop
- // site disabled until it is part of the new hierarchy.
- bool oldRegistered = w->testAttribute(Qt::WA_DropSiteRegistered);
- w->setAttribute(Qt::WA_DropSiteRegistered, false);
- [qt_mac_nativeview_for(w) retain];
- [qt_mac_nativeview_for(w) removeFromSuperview];
- [qt_mac_nativeview_for(q) addSubview:qt_mac_nativeview_for(w)];
- [qt_mac_nativeview_for(w) release];
- w->setAttribute(Qt::WA_DropSiteRegistered, oldRegistered);
-#endif
- }
- }
- }
- }
-}
-
-#ifdef QT_MAC_USE_COCOA
-void QWidgetPrivate::setSubWindowStacking(bool set)
-{
- // After hitting too many unforeseen bugs trying to put Qt on top of the cocoa child
- // window API, we have decided to revert this behaviour as much as we can. We
- // therefore now only allow child windows to exist for children of modal dialogs.
- static bool use_behaviour_qt473 = !qgetenv("QT_MAC_USE_CHILDWINDOWS").isEmpty();
-
- // This will set/remove a visual relationship between parent and child on screen.
- // The reason for doing this is to ensure that a child always stacks infront of
- // its parent. Unfortunatly is turns out that [NSWindow addChildWindow] has
- // several unwanted side-effects, one of them being the moving of a child when
- // moving the parent, which we choose to accept. A way tougher side-effect is
- // that Cocoa will hide the parent if you hide the child. And in the case of
- // a tool window, since it will normally hide when you deactivate the
- // application, Cocoa will hide the parent upon deactivate as well. The result often
- // being no more visible windows on screen. So, to make a long story short, we only
- // allow parent-child relationships between windows that both are either a plain window
- // or a dialog.
-
- Q_Q(QWidget);
- if (!q->isWindow())
- return;
- NSWindow *qwin = [qt_mac_nativeview_for(q) window];
- if (!qwin)
- return;
- Qt::WindowType qtype = q->windowType();
- if (set && !(qtype == Qt::Window || qtype == Qt::Dialog))
- return;
- if (set && ![qwin isVisible])
- return;
-
- if (QWidget *parent = q->parentWidget()) {
- if (NSWindow *pwin = [qt_mac_nativeview_for(parent) window]) {
- if (set) {
- Qt::WindowType ptype = parent->window()->windowType();
- if ([pwin isVisible]
- && (ptype == Qt::Window || ptype == Qt::Dialog)
- && ![qwin parentWindow]
- && (use_behaviour_qt473 || parent->windowModality() == Qt::ApplicationModal)) {
- NSInteger level = [qwin level];
- [pwin addChildWindow:qwin ordered:NSWindowAbove];
- if ([qwin level] < level)
- [qwin setLevel:level];
- }
- } else {
- [pwin removeChildWindow:qwin];
- }
- }
- }
-
- // Only set-up child windows for q if q is modal:
- if (set && !use_behaviour_qt473 && q->windowModality() != Qt::ApplicationModal)
- return;
-
- QObjectList widgets = q->children();
- for (int i=0; i<widgets.size(); ++i) {
- QWidget *child = qobject_cast<QWidget *>(widgets.at(i));
- if (child && child->isWindow()) {
- if (NSWindow *cwin = [qt_mac_nativeview_for(child) window]) {
- if (set) {
- Qt::WindowType ctype = child->window()->windowType();
- if ([cwin isVisible] && (ctype == Qt::Window || ctype == Qt::Dialog) && ![cwin parentWindow]) {
- NSInteger level = [cwin level];
- [qwin addChildWindow:cwin ordered:NSWindowAbove];
- if ([cwin level] < level)
- [cwin setLevel:level];
- }
- } else {
- [qwin removeChildWindow:qt_mac_window_for(child)];
- }
- }
- }
- }
-}
-#endif
-
-void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
-{
- Q_Q(QWidget);
- QMacCocoaAutoReleasePool pool;
- QTLWExtra *topData = maybeTopData();
- bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
-#ifdef QT_MAC_USE_COCOA
- bool wasWindow = q->isWindow();
-#endif
- OSViewRef old_id = 0;
-
- if (q->isVisible() && q->parentWidget() && parent != q->parentWidget())
- q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
-
- // Maintain the glWidgets list on parent change: remove "our" gl widgets
- // from the list on the old parent and grandparents.
- if (glWidgets.isEmpty() == false) {
- QWidget *current = q->parentWidget();
- while (current) {
- for (QList<QWidgetPrivate::GlWidgetInfo>::const_iterator it = glWidgets.constBegin();
- it != glWidgets.constEnd(); ++it)
- current->d_func()->glWidgets.removeAll(*it);
-
- if (current->isWindow())
- break;
- current = current->parentWidget();
- }
- }
-
-#ifndef QT_MAC_USE_COCOA
- EventHandlerRef old_window_event = 0;
-#else
- bool oldToolbarVisible = false;
- NSDrawer *oldDrawer = nil;
- NSToolbar *oldToolbar = 0;
-#endif
- if (wasCreated && !(q->windowType() == Qt::Desktop)) {
- old_id = qt_mac_nativeview_for(q);
-#ifndef QT_MAC_USE_COCOA
- old_window_event = window_event;
-#else
- if (qt_mac_is_macdrawer(q)) {
- oldDrawer = qt_mac_drawer_for(q);
- }
- if (wasWindow) {
- OSWindowRef oldWindow = qt_mac_window_for(old_id);
- oldToolbar = [oldWindow toolbar];
- if (oldToolbar) {
- [oldToolbar retain];
- oldToolbarVisible = [oldToolbar isVisible];
- [oldWindow setToolbar:nil];
- }
- }
-#endif
- }
- QWidget* oldtlw = q->window();
-
- if (q->testAttribute(Qt::WA_DropSiteRegistered))
- q->setAttribute(Qt::WA_DropSiteRegistered, false);
-
- //recreate and setup flags
- QObjectPrivate::setParent_helper(parent);
- bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
- if (wasCreated && !qt_isGenuineQWidget(q))
- return;
-
- if (!q->testAttribute(Qt::WA_WState_WindowOpacitySet)) {
- q->setWindowOpacity(1.0f);
- q->setAttribute(Qt::WA_WState_WindowOpacitySet, false);
- }
-
- setWinId(0); //do after the above because they may want the id
-
- data.window_flags = f;
- q->setAttribute(Qt::WA_WState_Created, false);
- q->setAttribute(Qt::WA_WState_Visible, false);
- q->setAttribute(Qt::WA_WState_Hidden, false);
- adjustFlags(data.window_flags, q);
- // keep compatibility with previous versions, we need to preserve the created state.
- // (but we recreate the winId for the widget being reparented, again for compatibility,
- // unless this is an alien widget. )
- const bool nonWindowWithCreatedParent = !q->isWindow() && parent->testAttribute(Qt::WA_WState_Created);
- const bool nativeWidget = q->internalWinId() != 0;
- if (wasCreated || (nativeWidget && nonWindowWithCreatedParent)) {
- createWinId();
- if (q->isWindow()) {
-#ifndef QT_MAC_USE_COCOA
- // We do this down below for wasCreated, so avoid doing this twice
- // (only for performance, it gets called a lot anyway).
- if (!wasCreated) {
- if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) {
- mwl->updateHIToolBarStatus();
- }
- }
-#else
- // Simply transfer our toolbar over. Everything should stay put, unlike in Carbon.
- if (oldToolbar && !(f & Qt::FramelessWindowHint)) {
- OSWindowRef newWindow = qt_mac_window_for(q);
- [newWindow setToolbar:oldToolbar];
- [oldToolbar release];
- [oldToolbar setVisible:oldToolbarVisible];
- }
-#endif
- }
- }
- if (q->isWindow() || (!parent || parent->isVisible()) || explicitlyHidden)
- q->setAttribute(Qt::WA_WState_Hidden);
- q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden);
-
- if (wasCreated) {
- transferChildren();
-#ifndef QT_MAC_USE_COCOA
- // If we were a unified window, We just transfered our toolbars out of the unified toolbar.
- // So redo the status one more time. It apparently is not an issue with Cocoa.
- if (q->isWindow()) {
- if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) {
- mwl->updateHIToolBarStatus();
- }
- }
-#endif
-
- if (topData &&
- (!topData->caption.isEmpty() || !topData->filePath.isEmpty()))
- setWindowTitle_helper(q->windowTitle());
- }
-
- if (q->testAttribute(Qt::WA_AcceptDrops)
- || (!q->isWindow() && q->parentWidget()
- && q->parentWidget()->testAttribute(Qt::WA_DropSiteRegistered)))
- q->setAttribute(Qt::WA_DropSiteRegistered, true);
-
- //cleanup
-#ifndef QT_MAC_USE_COCOA
- if (old_window_event)
- RemoveEventHandler(old_window_event);
-#endif
- if (old_id) { //don't need old window anymore
- OSWindowRef window = (oldtlw == q) ? qt_mac_window_for(old_id) : 0;
- qt_mac_destructView(old_id);
-
-#ifdef QT_MAC_USE_COCOA
- if (oldDrawer) {
- qt_mac_destructDrawer(oldDrawer);
- } else
-#endif
- if (window)
- qt_mac_destructWindow(window);
- }
-
- // Maintain the glWidgets list on parent change: add "our" gl widgets
- // to the list on the new parent and grandparents.
- if (glWidgets.isEmpty() == false) {
- QWidget *current = q->parentWidget();
- while (current) {
- current->d_func()->glWidgets += glWidgets;
- if (current->isWindow())
- break;
- current = current->parentWidget();
- }
- }
- invalidateBuffer(q->rect());
- qt_event_request_window_change(q);
-}
-
-QPoint QWidget::mapToGlobal(const QPoint &pos) const
-{
- Q_D(const QWidget);
- if (!internalWinId()) {
- QPoint p = pos + data->crect.topLeft();
- return isWindow() ? p : parentWidget()->mapToGlobal(p);
- }
-#ifndef QT_MAC_USE_COCOA
- QPoint tmp = d->mapToWS(pos);
- HIPoint hi_pos = CGPointMake(tmp.x(), tmp.y());
- HIViewConvertPoint(&hi_pos, qt_mac_nativeview_for(this), 0);
- Rect win_rect;
- GetWindowBounds(qt_mac_window_for(this), kWindowStructureRgn, &win_rect);
- return QPoint((int)hi_pos.x+win_rect.left, (int)hi_pos.y+win_rect.top);
-#else
- QPoint tmp = d->mapToWS(pos);
- NSPoint hi_pos = NSMakePoint(tmp.x(), tmp.y());
- hi_pos = [qt_mac_nativeview_for(this) convertPoint:hi_pos toView:nil];
- NSRect win_rect = [qt_mac_window_for(this) frame];
- hi_pos.x += win_rect.origin.x;
- hi_pos.y += win_rect.origin.y;
- // If we aren't the desktop we need to flip, if you flip the desktop on itself, you get the other problem.
- return ((window()->windowFlags() & Qt::Desktop) == Qt::Desktop) ? QPointF(hi_pos.x, hi_pos.y).toPoint()
- : flipPoint(hi_pos).toPoint();
-#endif
-}
-
-QPoint QWidget::mapFromGlobal(const QPoint &pos) const
-{
- Q_D(const QWidget);
- if (!internalWinId()) {
- QPoint p = isWindow() ? pos : parentWidget()->mapFromGlobal(pos);
- return p - data->crect.topLeft();
- }
-#ifndef QT_MAC_USE_COCOA
- Rect win_rect;
- GetWindowBounds(qt_mac_window_for(this), kWindowStructureRgn, &win_rect);
- HIPoint hi_pos = CGPointMake(pos.x()-win_rect.left, pos.y()-win_rect.top);
- HIViewConvertPoint(&hi_pos, 0, qt_mac_nativeview_for(this));
- return d->mapFromWS(QPoint((int)hi_pos.x, (int)hi_pos.y));
-#else
- NSRect win_rect = [qt_mac_window_for(this) frame];
- // The Window point is in "Cocoa coordinates," but the view is in "Qt coordinates"
- // so make sure to keep them in sync.
- NSPoint hi_pos = NSMakePoint(pos.x()-win_rect.origin.x,
- flipYCoordinate(pos.y())-win_rect.origin.y);
- hi_pos = [qt_mac_nativeview_for(this) convertPoint:hi_pos fromView:0];
- return d->mapFromWS(QPoint(qRound(hi_pos.x), qRound(hi_pos.y)));
-#endif
-}
-
-void QWidgetPrivate::updateSystemBackground()
-{
-}
-
-void QWidgetPrivate::setCursor_sys(const QCursor &)
-{
- qt_mac_update_cursor();
-}
-
-void QWidgetPrivate::unsetCursor_sys()
-{
- qt_mac_update_cursor();
-}
-
-void QWidgetPrivate::setWindowTitle_sys(const QString &caption)
-{
- Q_Q(QWidget);
- if (q->isWindow()) {
-#ifndef QT_MAC_USE_COCOA
- SetWindowTitleWithCFString(qt_mac_window_for(q), QCFString(caption));
-#else
- QMacCocoaAutoReleasePool pool;
- [qt_mac_window_for(q) setTitle:qt_mac_QStringToNSString(caption)];
-#endif
- }
-}
-
-void QWidgetPrivate::setWindowModified_sys(bool mod)
-{
- Q_Q(QWidget);
- if (q->isWindow() && q->testAttribute(Qt::WA_WState_Created)) {
-#ifndef QT_MAC_USE_COCOA
- SetWindowModified(qt_mac_window_for(q), mod);
-#else
- [qt_mac_window_for(q) setDocumentEdited:mod];
-#endif
- }
-}
-
-void QWidgetPrivate::setWindowFilePath_sys(const QString &filePath)
-{
- Q_Q(QWidget);
-#ifdef QT_MAC_USE_COCOA
- QMacCocoaAutoReleasePool pool;
- QFileInfo fi(filePath);
- [qt_mac_window_for(q) setRepresentedFilename:fi.exists() ? qt_mac_QStringToNSString(filePath) : @""];
-#else
- bool validRef = false;
- FSRef ref;
- bzero(&ref, sizeof(ref));
- OSStatus status;
-
- if (!filePath.isEmpty()) {
- status = FSPathMakeRef(reinterpret_cast<const UInt8 *>(filePath.toUtf8().constData()), &ref, 0);
- validRef = (status == noErr);
- }
- // Set the proxy regardless, since this is our way of clearing it as well, but ignore the
- // return value as well.
- if (validRef) {
- status = HIWindowSetProxyFSRef(qt_mac_window_for(q), &ref);
- } else {
- status = RemoveWindowProxy(qt_mac_window_for(q));
- }
- if (status != noErr)
- qWarning("QWidget::setWindowFilePath: Error setting proxyicon for path (%s):%ld",
- qPrintable(filePath), status);
-#endif
-}
-
-void QWidgetPrivate::setWindowIcon_sys(bool forceReset)
-{
- Q_Q(QWidget);
-
- if (!q->testAttribute(Qt::WA_WState_Created))
- return;
-
- QTLWExtra *topData = this->topData();
- if (topData->iconPixmap && !forceReset) // already set
- return;
-
- QIcon icon = q->windowIcon();
- QPixmap *pm = 0;
- if (!icon.isNull()) {
- // now create the extra
- if (!topData->iconPixmap) {
- pm = new QPixmap(icon.pixmap(QSize(22, 22)));
- topData->iconPixmap = pm;
- } else {
- pm = topData->iconPixmap;
- }
- }
- if (q->isWindow()) {
-#ifndef QT_MAC_USE_COCOA
- IconRef previousIcon = 0;
- if (icon.isNull()) {
- RemoveWindowProxy(qt_mac_window_for(q));
- previousIcon = topData->windowIcon;
- topData->windowIcon = 0;
- } else {
- WindowClass wclass;
- GetWindowClass(qt_mac_window_for(q), &wclass);
-
- if (wclass == kDocumentWindowClass) {
- IconRef newIcon = qt_mac_create_iconref(*pm);
- previousIcon = topData->windowIcon;
- topData->windowIcon = newIcon;
- SetWindowProxyIcon(qt_mac_window_for(q), newIcon);
- }
- }
-
- // Release the previous icon if it was set by this function.
- if (previousIcon != 0)
- ReleaseIconRef(previousIcon);
-#else
- QMacCocoaAutoReleasePool pool;
- if (icon.isNull())
- return;
- NSButton *iconButton = [qt_mac_window_for(q) standardWindowButton:NSWindowDocumentIconButton];
- if (iconButton == nil) {
- QCFString string(q->windowTitle());
- const NSString *tmpString = reinterpret_cast<const NSString *>((CFStringRef)string);
- [qt_mac_window_for(q) setRepresentedURL:[NSURL fileURLWithPath:const_cast<NSString *>(tmpString)]];
- iconButton = [qt_mac_window_for(q) standardWindowButton:NSWindowDocumentIconButton];
- }
- if (icon.isNull()) {
- [iconButton setImage:nil];
- } else {
- QPixmap scaled = pm->scaled(QSize(16,16), Qt::KeepAspectRatio, Qt::SmoothTransformation);
- NSImage *image = static_cast<NSImage *>(qt_mac_create_nsimage(scaled));
- [iconButton setImage:image];
- [image release];
- }
-#endif
- }
-}
-
-void QWidgetPrivate::setWindowIconText_sys(const QString &iconText)
-{
- Q_Q(QWidget);
- if(q->isWindow() && !iconText.isEmpty()) {
-#ifndef QT_MAC_USE_COCOA
- SetWindowAlternateTitle(qt_mac_window_for(q), QCFString(iconText));
-#else
- QMacCocoaAutoReleasePool pool;
- [qt_mac_window_for(q) setMiniwindowTitle:qt_mac_QStringToNSString(iconText)];
-#endif
- }
-}
-
-void QWidget::grabMouse()
-{
- if(isVisible() && !qt_nograb()) {
- if(mac_mouse_grabber)
- mac_mouse_grabber->releaseMouse();
- mac_mouse_grabber=this;
- qt_mac_setMouseGrabCursor(true);
- }
-}
-
-#ifndef QT_NO_CURSOR
-void QWidget::grabMouse(const QCursor &cursor)
-{
- if(isVisible() && !qt_nograb()) {
- if(mac_mouse_grabber)
- mac_mouse_grabber->releaseMouse();
- mac_mouse_grabber=this;
- qt_mac_setMouseGrabCursor(true, const_cast<QCursor *>(&cursor));
- }
-}
-#endif
-
-void QWidget::releaseMouse()
-{
- if(!qt_nograb() && mac_mouse_grabber == this) {
- mac_mouse_grabber = 0;
- qt_mac_setMouseGrabCursor(false);
- }
-}
-
-void QWidget::grabKeyboard()
-{
- if(!qt_nograb()) {
- if(mac_keyboard_grabber)
- mac_keyboard_grabber->releaseKeyboard();
- mac_keyboard_grabber = this;
- }
-}
-
-void QWidget::releaseKeyboard()
-{
- if(!qt_nograb() && mac_keyboard_grabber == this)
- mac_keyboard_grabber = 0;
-}
-
-QWidget *QWidget::mouseGrabber()
-{
- return mac_mouse_grabber;
-}
-
-QWidget *QWidget::keyboardGrabber()
-{
- return mac_keyboard_grabber;
-}
-
-void QWidget::activateWindow()
-{
- QWidget *tlw = window();
- if(!tlw->isVisible() || !tlw->isWindow() || (tlw->windowType() == Qt::Desktop))
- return;
- qt_event_remove_activate();
-
- QWidget *fullScreenWidget = tlw;
- QWidget *parentW = tlw;
- // Find the oldest parent or the parent with fullscreen, whichever comes first.
- while (parentW) {
- fullScreenWidget = parentW->window();
- if (fullScreenWidget->windowState() & Qt::WindowFullScreen)
- break;
- parentW = fullScreenWidget->parentWidget();
- }
-
- if (fullScreenWidget->windowType() != Qt::ToolTip) {
- qt_mac_set_fullscreen_mode((fullScreenWidget->windowState() & Qt::WindowFullScreen) &&
- qApp->desktop()->screenNumber(this) == 0);
- }
-
- bool windowActive;
- OSWindowRef win = qt_mac_window_for(tlw);
-#ifndef QT_MAC_USE_COCOA
- windowActive = IsWindowActive(win);
-#else
- QMacCocoaAutoReleasePool pool;
- windowActive = [win isKeyWindow];
-#endif
- if ((tlw->windowType() == Qt::Popup)
- || (tlw->windowType() == Qt::Tool)
- || qt_mac_is_macdrawer(tlw)
- || windowActive) {
-#ifndef QT_MAC_USE_COCOA
- ActivateWindow(win, true);
- qApp->setActiveWindow(tlw);
-#else
- [win makeKeyWindow];
-#endif
- } else if(!isMinimized()) {
-#ifndef QT_MAC_USE_COCOA
- SelectWindow(win);
-#else
- [win makeKeyAndOrderFront:win];
-#endif
- }
-}
-
-QWindowSurface *QWidgetPrivate::createDefaultWindowSurface_sys()
-{
- return new QMacWindowSurface(q_func());
-}
-
-void QWidgetPrivate::update_sys(const QRect &r)
-{
- Q_Q(QWidget);
- if (updateRedirectedToGraphicsProxyWidget(q, r))
- return;
- dirtyOnWidget += r;
- macSetNeedsDisplay(r != q->rect() ? r : QRegion());
-}
-
-void QWidgetPrivate::update_sys(const QRegion &rgn)
-{
- Q_Q(QWidget);
- if (updateRedirectedToGraphicsProxyWidget(q, rgn))
- return;
- dirtyOnWidget += rgn;
- macSetNeedsDisplay(rgn);
-}
-
-bool QWidgetPrivate::isRealWindow() const
-{
- return q_func()->isWindow() && !topData()->embedded;
-}
-
-void QWidgetPrivate::show_sys()
-{
- Q_Q(QWidget);
- if ((q->windowType() == Qt::Desktop)) //desktop is always visible
- return;
-
- invalidateBuffer(q->rect());
- if (q->testAttribute(Qt::WA_OutsideWSRange))
- return;
- QMacCocoaAutoReleasePool pool;
- q->setAttribute(Qt::WA_Mapped);
- if (q->testAttribute(Qt::WA_DontShowOnScreen))
- return;
-
- bool realWindow = isRealWindow();
-#ifndef QT_MAC_USE_COCOA
- if (realWindow && !q->testAttribute(Qt::WA_Moved)) {
- if (qt_mac_is_macsheet(q))
- recreateMacWindow();
- q->createWinId();
- if (QWidget *p = q->parentWidget()) {
- p->createWinId();
- RepositionWindow(qt_mac_window_for(q), qt_mac_window_for(p), kWindowCenterOnParentWindow);
- } else {
- RepositionWindow(qt_mac_window_for(q), 0, kWindowCenterOnMainScreen);
- }
- }
-#endif
-
- data.fstrut_dirty = true;
- if (realWindow) {
- bool isCurrentlyMinimized = (q->windowState() & Qt::WindowMinimized);
- setModal_sys();
- OSWindowRef window = qt_mac_window_for(q);
-#ifndef QT_MAC_USE_COCOA
- SizeWindow(window, q->width(), q->height(), true);
-#endif
-
-#ifdef QT_MAC_USE_COCOA
- // Make sure that we end up sending a repaint event to
- // the widget if the window has been visible one before:
- [qt_mac_get_contentview_for(window) setNeedsDisplay:YES];
-#endif
- if(qt_mac_is_macsheet(q)) {
- qt_event_request_showsheet(q);
- } else if(qt_mac_is_macdrawer(q)) {
-#ifndef QT_MAC_USE_COCOA
- OpenDrawer(window, kWindowEdgeDefault, false);
-#else
- NSDrawer *drawer = qt_mac_drawer_for(q);
- [drawer openOnEdge:[drawer preferredEdge]];
-#endif
- } else {
-#ifndef QT_MAC_USE_COCOA
- ShowHide(window, true);
-#else
- // sync the opacity value back (in case of a fade).
- [window setAlphaValue:q->windowOpacity()];
-
- QWidget *top = 0;
- if (QApplicationPrivate::tryModalHelper(q, &top)) {
- [window makeKeyAndOrderFront:window];
- // If this window is app modal, we need to start spinning
- // a modal session for it. Interrupting
- // the event dispatcher will make this happend:
- if (data.window_modality == Qt::ApplicationModal)
- QEventDispatcherMac::instance()->interrupt();
- } else {
- // The window is modally shaddowed, so we need to make
- // sure that we don't pop in front of the modal window:
- [window orderFront:window];
- if (!top->testAttribute(Qt::WA_DontShowOnScreen)) {
- if (NSWindow *modalWin = qt_mac_window_for(top))
- [modalWin orderFront:window];
- }
- }
- setSubWindowStacking(true);
- qt_mac_update_cursor();
-#endif
- if (q->windowType() == Qt::Popup) {
- qt_button_down = 0;
- if (q->focusWidget())
- q->focusWidget()->d_func()->setFocus_sys();
- else
- setFocus_sys();
- }
- toggleDrawers(true);
- }
- if (isCurrentlyMinimized) { //show in collapsed state
-#ifndef QT_MAC_USE_COCOA
- CollapseWindow(window, true);
-#else
- [window miniaturize:window];
-#endif
- } else if (!q->testAttribute(Qt::WA_ShowWithoutActivating)) {
-#ifndef QT_MAC_USE_COCOA
- qt_event_request_activate(q);
-#endif
- }
- } else if(topData()->embedded || !q->parentWidget() || q->parentWidget()->isVisible()) {
-#ifndef QT_MAC_USE_COCOA
- HIViewSetVisible(qt_mac_nativeview_for(q), true);
-#else
- if (NSView *view = qt_mac_nativeview_for(q)) {
- // INVARIANT: q is native. Just show the view:
- [view setHidden:NO];
- } else {
- // INVARIANT: q is alien. Repaint q instead:
- q->repaint();
- }
-#endif
- }
-
-#ifdef QT_MAC_USE_COCOA
- if ([NSApp isActive] && !qt_button_down && !QWidget::mouseGrabber()){
- // Update enter/leave immidiatly, don't wait for a move event. But only
- // if no grab exists (even if the grab points to this widget, it seems, ref X11)
- QPoint qlocal, qglobal;
- QWidget *widgetUnderMouse = 0;
- qt_mac_getTargetForMouseEvent(0, QEvent::Enter, qlocal, qglobal, 0, &widgetUnderMouse);
- QApplicationPrivate::dispatchEnterLeave(widgetUnderMouse, qt_last_mouse_receiver);
- qt_last_mouse_receiver = widgetUnderMouse;
- qt_last_native_mouse_receiver = widgetUnderMouse ?
- (widgetUnderMouse->internalWinId() ? widgetUnderMouse : widgetUnderMouse->nativeParentWidget()) : 0;
- }
-#endif
-
- topLevelAt_cache = 0;
- qt_event_request_window_change(q);
-}
-
-QPoint qt_mac_nativeMapFromParent(const QWidget *child, const QPoint &pt)
-{
-#ifndef QT_MAC_USE_COCOA
- CGPoint nativePoint = CGPointMake(pt.x(), pt.y());
- HIViewConvertPoint(&nativePoint, qt_mac_nativeview_for(child->parentWidget()),
- qt_mac_nativeview_for(child));
-#else
- NSPoint nativePoint = [qt_mac_nativeview_for(child) convertPoint:NSMakePoint(pt.x(), pt.y()) fromView:qt_mac_nativeview_for(child->parentWidget())];
-#endif
- return QPoint(nativePoint.x, nativePoint.y);
-}
-
-
-void QWidgetPrivate::hide_sys()
-{
- Q_Q(QWidget);
- if((q->windowType() == Qt::Desktop)) //you can't hide the desktop!
- return;
- QMacCocoaAutoReleasePool pool;
- if(q->isWindow()) {
-#ifdef QT_MAC_USE_COCOA
- setSubWindowStacking(false);
-#endif
- OSWindowRef window = qt_mac_window_for(q);
- if(qt_mac_is_macsheet(q)) {
-#ifndef QT_MAC_USE_COCOA
- WindowRef parent = 0;
- if(GetSheetWindowParent(window, &parent) != noErr || !parent)
- ShowHide(window, false);
- else
- HideSheetWindow(window);
-#else
- [NSApp endSheet:window];
- [window orderOut:window];
-#endif
- } else if(qt_mac_is_macdrawer(q)) {
-#ifndef QT_MAC_USE_COCOA
- CloseDrawer(window, false);
-#else
- [qt_mac_drawer_for(q) close];
-#endif
- } else {
-#ifndef QT_MAC_USE_COCOA
- ShowHide(window, false);
-#else
- [window orderOut:window];
- // Unfortunately it is not as easy as just hiding the window, we need
- // to find out if we were in full screen mode. If we were and this is
- // the last window in full screen mode then we need to unset the full screen
- // mode. If this is not the last visible window in full screen mode then we
- // don't change the full screen mode.
- if(q->isFullScreen())
- {
- bool keepFullScreen = false;
- QWidgetList windowList = qApp->topLevelWidgets();
- int windowCount = windowList.count();
- for(int i = 0; i < windowCount; i++)
- {
- QWidget *w = windowList[i];
- // If it is the same window, we don't need to check :-)
- if(q == w)
- continue;
- // If they are not visible or if they are minimized then
- // we just ignore them.
- if(!w->isVisible() || w->isMinimized())
- continue;
- // Is it full screen?
- // Notice that if there is one window in full screen mode then we
- // cannot switch the full screen mode off, therefore we just abort.
- if(w->isFullScreen()) {
- keepFullScreen = true;
- break;
- }
- }
- // No windows in full screen mode, so let just unset that flag.
- if(!keepFullScreen)
- qt_mac_set_fullscreen_mode(false);
- }
-#endif
- toggleDrawers(false);
- qt_mac_update_cursor();
-#ifndef QT_MAC_USE_COCOA
- // Clear modality (because it seems something that we've always done).
- if (data.window_modality != Qt::NonModal) {
- SetWindowModality(window, kWindowModalityNone,
- q->parentWidget() ? qt_mac_window_for(q->parentWidget()->window()) : 0);
- }
-#endif
- }
-#ifndef QT_MAC_USE_COCOA
- // If the window we now hide was the active window, we need
- // to find, and activate another window on screen. NB: Cocoa takes care of this
- // logic for us (and distinquishes between main windows and key windows)
- if (q->isActiveWindow() && !(q->windowType() == Qt::Popup)) {
- QWidget *w = 0;
- if(q->parentWidget())
- w = q->parentWidget()->window();
- if(!w || (!w->isVisible() && !w->isMinimized())) {
- for (WindowPtr wp = GetFrontWindowOfClass(kMovableModalWindowClass, true);
- wp; wp = GetNextWindowOfClass(wp, kMovableModalWindowClass, true)) {
- if((w = qt_mac_find_window(wp)))
- break;
- }
- if (!w){
- for (WindowPtr wp = GetFrontWindowOfClass(kDocumentWindowClass, true);
- wp; wp = GetNextWindowOfClass(wp, kDocumentWindowClass, true)) {
- if((w = qt_mac_find_window(wp)))
- break;
- }
- }
- if (!w){
- for(WindowPtr wp = GetFrontWindowOfClass(kSimpleWindowClass, true);
- wp; wp = GetNextWindowOfClass(wp, kSimpleWindowClass, true)) {
- if((w = qt_mac_find_window(wp)))
- break;
- }
- }
- }
- if(w && w->isVisible() && !w->isMinimized()) {
- qt_event_request_activate(w);
- }
- }
-#endif
- } else {
- invalidateBuffer(q->rect());
-#ifndef QT_MAC_USE_COCOA
- HIViewSetVisible(qt_mac_nativeview_for(q), false);
-#else
- if (NSView *view = qt_mac_nativeview_for(q)) {
- // INVARIANT: q is native. Just hide the view:
- [view setHidden:YES];
- } else {
- // INVARIANT: q is alien. Repaint where q is placed instead:
- qt_mac_repaintParentUnderAlienWidget(q);
- }
-#endif
- }
-
-#ifdef QT_MAC_USE_COCOA
- if ([NSApp isActive] && !qt_button_down && !QWidget::mouseGrabber()){
- // Update enter/leave immidiatly, don't wait for a move event. But only
- // if no grab exists (even if the grab points to this widget, it seems, ref X11)
- QPoint qlocal, qglobal;
- QWidget *widgetUnderMouse = 0;
- qt_mac_getTargetForMouseEvent(0, QEvent::Leave, qlocal, qglobal, 0, &widgetUnderMouse);
- QApplicationPrivate::dispatchEnterLeave(widgetUnderMouse, qt_last_native_mouse_receiver);
- qt_last_mouse_receiver = widgetUnderMouse;
- qt_last_native_mouse_receiver = widgetUnderMouse ?
- (widgetUnderMouse->internalWinId() ? widgetUnderMouse : widgetUnderMouse->nativeParentWidget()) : 0;
- }
-#endif
-
- topLevelAt_cache = 0;
- qt_event_request_window_change(q);
- deactivateWidgetCleanup();
- qt_mac_event_release(q);
-}
-
-void QWidget::setWindowState(Qt::WindowStates newstate)
-{
- Q_D(QWidget);
- bool needShow = false;
- Qt::WindowStates oldstate = windowState();
- if (oldstate == newstate)
- return;
-
-#ifdef QT_MAC_USE_COCOA
- QMacCocoaAutoReleasePool pool;
-#endif
- bool needSendStateChange = true;
- if(isWindow()) {
- if((oldstate & Qt::WindowFullScreen) != (newstate & Qt::WindowFullScreen)) {
- if(newstate & Qt::WindowFullScreen) {
- if(QTLWExtra *tlextra = d->topData()) {
- if(tlextra->normalGeometry.width() < 0) {
- if(!testAttribute(Qt::WA_Resized))
- adjustSize();
- tlextra->normalGeometry = geometry();
- }
- tlextra->savedFlags = windowFlags();
- }
- needShow = isVisible();
- const QRect fullscreen(qApp->desktop()->screenGeometry(qApp->desktop()->screenNumber(this)));
- setParent(parentWidget(), Qt::Window | Qt::FramelessWindowHint | (windowFlags() & 0xffff0000)); //save
- setGeometry(fullscreen);
- if(!qApp->desktop()->screenNumber(this))
- qt_mac_set_fullscreen_mode(true);
- } else {
- needShow = isVisible();
- if(!qApp->desktop()->screenNumber(this))
- qt_mac_set_fullscreen_mode(false);
- setParent(parentWidget(), d->topData()->savedFlags);
- setGeometry(d->topData()->normalGeometry);
- d->topData()->normalGeometry.setRect(0, 0, -1, -1);
- }
- }
-
- d->createWinId();
-
- OSWindowRef window = qt_mac_window_for(this);
- if((oldstate & Qt::WindowMinimized) != (newstate & Qt::WindowMinimized)) {
- if (newstate & Qt::WindowMinimized) {
-#ifndef QT_MAC_USE_COCOA
- CollapseWindow(window, true);
-#else
- [window miniaturize:window];
-#endif
- } else {
-#ifndef QT_MAC_USE_COCOA
- CollapseWindow(window, false);
-#else
- [window deminiaturize:window];
-#endif
- }
- needSendStateChange = oldstate == windowState(); // Collapse didn't change our flags.
- }
-
- if((newstate & Qt::WindowMaximized) && !((newstate & Qt::WindowFullScreen))) {
- if(QTLWExtra *tlextra = d->topData()) {
- if(tlextra->normalGeometry.width() < 0) {
- if(!testAttribute(Qt::WA_Resized))
- adjustSize();
- tlextra->normalGeometry = geometry();
- }
- }
- } else if(!(newstate & Qt::WindowFullScreen)) {
-// d->topData()->normalGeometry = QRect(0, 0, -1, -1);
- }
-
-#ifdef DEBUG_WINDOW_STATE
-#define WSTATE(x) qDebug("%s -- %s --> %s", #x, (oldstate & x) ? "true" : "false", (newstate & x) ? "true" : "false")
- WSTATE(Qt::WindowMinimized);
- WSTATE(Qt::WindowMaximized);
- WSTATE(Qt::WindowFullScreen);
-#undef WSTATE
-#endif
- if(!(newstate & (Qt::WindowMinimized|Qt::WindowFullScreen)) &&
- ((oldstate & Qt::WindowFullScreen) || (oldstate & Qt::WindowMinimized) ||
- (oldstate & Qt::WindowMaximized) != (newstate & Qt::WindowMaximized))) {
- if(newstate & Qt::WindowMaximized) {
- data->fstrut_dirty = true;
-#ifndef QT_MAC_USE_COCOA
- HIToolbarRef toolbarRef;
- if (GetWindowToolbar(window, &toolbarRef) == noErr && toolbarRef
- && !isVisible() && !IsWindowToolbarVisible(window)) {
- // HIToolbar, needs to be shown so that it's in the structure window
- // Typically this is part of a main window and will get shown
- // during the show, but it's will make the maximize all wrong.
- ShowHideWindowToolbar(window, true, false);
- d->updateFrameStrut(); // In theory the dirty would work, but it's optimized out if the window is not visible :(
- }
- Rect bounds;
- QDesktopWidget *dsk = QApplication::desktop();
- QRect avail = dsk->availableGeometry(dsk->screenNumber(this));
- SetRect(&bounds, avail.x(), avail.y(), avail.x() + avail.width(), avail.y() + avail.height());
- if(QWExtra *extra = d->extraData()) {
- if(bounds.right - bounds.left > extra->maxw)
- bounds.right = bounds.left + extra->maxw;
- if(bounds.bottom - bounds.top > extra->maxh)
- bounds.bottom = bounds.top + extra->maxh;
- }
- if(d->topData()) {
- QRect fs = d->frameStrut();
- bounds.left += fs.left();
- if(bounds.right < avail.x()+avail.width())
- bounds.right = qMin<short>((uint)avail.x()+avail.width(), bounds.right+fs.left());
- if(bounds.bottom < avail.y()+avail.height())
- bounds.bottom = qMin<short>((uint)avail.y()+avail.height(), bounds.bottom+fs.top());
- bounds.top += fs.top();
- bounds.right -= fs.right();
- bounds.bottom -= fs.bottom();
- }
- QRect orect(geometry().x(), geometry().y(), width(), height()),
- nrect(bounds.left, bounds.top, bounds.right - bounds.left,
- bounds.bottom - bounds.top);
- if(orect != nrect) { // the new rect differ from the old
- Point idealSize = { nrect.height(), nrect.width() };
- ZoomWindowIdeal(window, inZoomOut, &idealSize);
- }
-#else
- NSToolbar *toolbarRef = [window toolbar];
- if (toolbarRef && !isVisible() && ![toolbarRef isVisible]) {
- // HIToolbar, needs to be shown so that it's in the structure window
- // Typically this is part of a main window and will get shown
- // during the show, but it's will make the maximize all wrong.
- // ### Not sure this is right for NSToolbar...
- [toolbarRef setVisible:true];
-// ShowHideWindowToolbar(window, true, false);
- d->updateFrameStrut(); // In theory the dirty would work, but it's optimized out if the window is not visible :(
- }
- // Everything should be handled by Cocoa.
- [window zoom:window];
-#endif
- needSendStateChange = oldstate == windowState(); // Zoom didn't change flags.
- } else if(oldstate & Qt::WindowMaximized && !(oldstate & Qt::WindowFullScreen)) {
-#ifndef QT_MAC_USE_COCOA
- Point idealSize;
- ZoomWindowIdeal(window, inZoomIn, &idealSize);
-#else
- [window zoom:window];
-#endif
- if(QTLWExtra *tlextra = d->topData()) {
- setGeometry(tlextra->normalGeometry);
- tlextra->normalGeometry.setRect(0, 0, -1, -1);
- }
- }
- }
- }
-
- data->window_state = newstate;
-
- if(needShow)
- show();
-
- if(newstate & Qt::WindowActive)
- activateWindow();
-
- qt_event_request_window_change(this);
- if (needSendStateChange) {
- QWindowStateChangeEvent e(oldstate);
- QApplication::sendEvent(this, &e);
- }
-}
-
-void QWidgetPrivate::setFocus_sys()
-{
- Q_Q(QWidget);
- if (q->testAttribute(Qt::WA_WState_Created)) {
-#ifdef QT_MAC_USE_COCOA
- QMacCocoaAutoReleasePool pool;
- NSView *view = qt_mac_nativeview_for(q);
- [[view window] makeFirstResponder:view];
-#else
- SetKeyboardFocus(qt_mac_window_for(q), qt_mac_nativeview_for(q), 1);
-#endif
- }
-}
-
-NSComparisonResult compareViews2Raise(id view1, id view2, void *context)
-{
- id topView = reinterpret_cast<id>(context);
- if (view1 == topView)
- return NSOrderedDescending;
- if (view2 == topView)
- return NSOrderedAscending;
- return NSOrderedSame;
-}
-
-void QWidgetPrivate::raise_sys()
-{
- Q_Q(QWidget);
- if((q->windowType() == Qt::Desktop))
- return;
-
-#if QT_MAC_USE_COCOA
- QMacCocoaAutoReleasePool pool;
- if (isRealWindow()) {
- // With the introduction of spaces it is not as simple as just raising the window.
- // First we need to check if we are in the right space. If we are, then we just continue
- // as usual. The problem comes when we are not in the active space. There are two main cases:
- // 1. Our parent was moved to a new space. In this case we want the window to be raised
- // in the same space as its parent.
- // 2. We don't have a parent. For this case we will just raise the window and let Cocoa
- // switch to the corresponding space.
- // NOTICE: There are a lot of corner cases here. We are keeping this simple for now, if
- // required we will introduce special handling for some of them.
- if (!q->testAttribute(Qt::WA_DontShowOnScreen) && q->isVisible()) {
- OSWindowRef window = qt_mac_window_for(q);
- // isOnActiveSpace is available only from 10.6 onwards, so we need to check if it is
- // available before calling it.
- if([window respondsToSelector:@selector(isOnActiveSpace)]) {
- if(![window performSelector:@selector(isOnActiveSpace)]) {
- QWidget *parentWidget = q->parentWidget();
- if(parentWidget) {
- OSWindowRef parentWindow = qt_mac_window_for(parentWidget);
- if(parentWindow && [parentWindow respondsToSelector:@selector(isOnActiveSpace)]) {
- if ([parentWindow performSelector:@selector(isOnActiveSpace)]) {
- // The window was created in a different space. Therefore if we want
- // to show it in the current space we need to recreate it in the new
- // space.
- recreateMacWindow();
- window = qt_mac_window_for(q);
- }
- }
- }
- }
- }
- [window orderFront:window];
- }
- if (qt_mac_raise_process) { //we get to be the active process now
- ProcessSerialNumber psn;
- GetCurrentProcess(&psn);
- SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly);
- }
- } else {
- NSView *view = qt_mac_nativeview_for(q);
- NSView *parentView = [view superview];
- [parentView sortSubviewsUsingFunction:compareViews2Raise context:reinterpret_cast<void *>(view)];
- }
- topLevelAt_cache = 0;
-#else
- if(q->isWindow()) {
- //raise this window
- BringToFront(qt_mac_window_for(q));
- if(qt_mac_raise_process) { //we get to be the active process now
- ProcessSerialNumber psn;
- GetCurrentProcess(&psn);
- SetFrontProcessWithOptions(&psn, kSetFrontProcessFrontWindowOnly);
- }
- } else if(q->parentWidget()) {
- HIViewSetZOrder(qt_mac_nativeview_for(q), kHIViewZOrderAbove, 0);
- qt_event_request_window_change(q);
- }
-#endif
-}
-
-NSComparisonResult compareViews2Lower(id view1, id view2, void *context)
-{
- id topView = reinterpret_cast<id>(context);
- if (view1 == topView)
- return NSOrderedAscending;
- if (view2 == topView)
- return NSOrderedDescending;
- return NSOrderedSame;
-}
-
-void QWidgetPrivate::lower_sys()
-{
- Q_Q(QWidget);
- if((q->windowType() == Qt::Desktop))
- return;
-#ifdef QT_MAC_USE_COCOA
- if (isRealWindow()) {
- OSWindowRef window = qt_mac_window_for(q);
- [window orderBack:window];
- } else {
- NSView *view = qt_mac_nativeview_for(q);
- NSView *parentView = [view superview];
- [parentView sortSubviewsUsingFunction:compareViews2Lower context:reinterpret_cast<void *>(view)];
- }
- topLevelAt_cache = 0;
-#else
- if(q->isWindow()) {
- SendBehind(qt_mac_window_for(q), 0);
- } else if(q->parentWidget()) {
- invalidateBuffer(q->rect());
- HIViewSetZOrder(qt_mac_nativeview_for(q), kHIViewZOrderBelow, 0);
- qt_event_request_window_change(q);
- }
-#endif
-}
-
-NSComparisonResult compareViews2StackUnder(id view1, id view2, void *context)
-{
- const QHash<NSView *, int> &viewOrder = *reinterpret_cast<QHash<NSView *, int> *>(context);
- if (viewOrder[view1] < viewOrder[view2])
- return NSOrderedAscending;
- if (viewOrder[view1] > viewOrder[view2])
- return NSOrderedDescending;
- return NSOrderedSame;
-}
-
-void QWidgetPrivate::stackUnder_sys(QWidget *w)
-{
- // stackUnder
- Q_Q(QWidget);
- if(!w || q->isWindow() || (q->windowType() == Qt::Desktop))
- return;
-#ifdef QT_MAC_USE_COCOA
- // Do the same trick as lower_sys() and put this widget before the widget passed in.
- NSView *myView = qt_mac_nativeview_for(q);
- NSView *wView = qt_mac_nativeview_for(w);
-
- QHash<NSView *, int> viewOrder;
- NSView *parentView = [myView superview];
- NSArray *subviews = [parentView subviews];
- NSUInteger index = 1;
- // make a hash of view->zorderindex and make sure z-value is always odd,
- // so that when we modify the order we create a new (even) z-value which
- // will not interfere with others.
- for (NSView *subview in subviews) {
- viewOrder.insert(subview, index * 2);
- ++index;
- }
- viewOrder[myView] = viewOrder[wView] - 1;
-
- [parentView sortSubviewsUsingFunction:compareViews2StackUnder context:reinterpret_cast<void *>(&viewOrder)];
-#else
- QWidget *p = q->parentWidget();
- if(!p || p != w->parentWidget())
- return;
- invalidateBuffer(q->rect());
- HIViewSetZOrder(qt_mac_nativeview_for(q), kHIViewZOrderBelow, qt_mac_nativeview_for(w));
- qt_event_request_window_change(q);
-#endif
-}
-
-#ifndef QT_MAC_USE_COCOA
-/*
- Modifies the bounds for a widgets backing HIView during moves and resizes. Also updates the
- widget, either by scrolling its contents or repainting, depending on the WA_StaticContents
- flag
-*/
-static void qt_mac_update_widget_position(QWidget *q, QRect oldRect, QRect newRect)
-{
- HIRect bounds = CGRectMake(newRect.x(), newRect.y(),
- newRect.width(), newRect.height());
-
- const HIViewRef view = qt_mac_nativeview_for(q);
- const bool isMove = (oldRect.topLeft() != newRect.topLeft());
- const bool isResize = (oldRect.size() != newRect.size());
-
-// qDebug() << oldRect << newRect << isMove << isResize << q->testAttribute(Qt::WA_OpaquePaintEvent) << q->testAttribute(Qt::WA_StaticContents);
- QWidgetPrivate *qd = qt_widget_private(q);
-
- // Perform a normal (complete repaint) update in some cases:
- if (
- // always repaint on move.
- (isMove) ||
-
- // limited update on resize requires WA_StaticContents.
- (isResize && q->testAttribute(Qt::WA_StaticContents) == false) ||
-
- // one of the rects are invalid
- (oldRect.isValid() == false || newRect.isValid() == false) ||
-
- // the position update is a part of a drag-and-drop operation
- QDragManager::self()->object ||
-
- // we are on Panther (no HIViewSetNeedsDisplayInRect)
- QSysInfo::MacintoshVersion < QSysInfo::MV_10_4
- ){
- HIViewSetFrame(view, &bounds);
- return;
- }
-
- const int dx = newRect.x() - oldRect.x();
- const int dy = newRect.y() - oldRect.y();
-
- if (isMove) {
- // HIViewScrollRect silently fails if we try to scroll anything under the grow box.
- // Check if there's one present within the widget rect, and if there is fall back
- // to repainting the entire widget.
- QWidget const * const parentWidget = q->parentWidget();
- const HIViewRef parentView = qt_mac_nativeview_for(parentWidget);
- HIViewRef nativeSizeGrip = 0;
- if (q->testAttribute(Qt::WA_WState_Created))
- HIViewFindByID(HIViewGetRoot(HIViewGetWindow(HIViewRef(q->winId()))), kHIViewWindowGrowBoxID, &nativeSizeGrip);
- if (nativeSizeGrip) {
- QWidget * const window = q->window();
-
- const int sizeGripSize = 20;
- const QRect oldWidgetRect = QRect(q->mapTo(window, QPoint(0, 0)), QSize(oldRect.width(), oldRect.height()));
- const QRect newWidgetRect = QRect(q->mapTo(window, QPoint(0, 0)), QSize(newRect.width(), newRect.height()));
- const QRect sizeGripRect = QRect(window->rect().bottomRight() - QPoint(sizeGripSize, sizeGripSize),
- window->rect().bottomRight());
-
- if (sizeGripRect.intersects(oldWidgetRect) || sizeGripRect.intersects(newWidgetRect)) {
- HIViewSetFrame(view, &bounds);
- return;
- }
- }
-
- // Don't scroll anything outside the parent widget rect.
- const QRect scrollRect = (oldRect | newRect) & parentWidget->rect();
- const HIRect scrollBounds =
- CGRectMake(scrollRect.x(), scrollRect.y(), scrollRect.width(), scrollRect.height());
-
- // We cannot scroll when the widget has a mask as that would
- // scroll the masked out areas too
- if (qd->extra && qd->extra->hasMask) {
- HIViewMoveBy(view, dx, dy);
- return;
- }
-
- OSStatus err = HIViewScrollRect(parentView, &scrollBounds, dx, dy);
- if (err != noErr) {
- HIViewSetNeedsDisplay(view, true);
- qWarning("QWidget: Internal error (%s:%d)", __FILE__, __LINE__);
- }
- }
- // Set the view bounds with drawing disabled to prevent repaints.
- HIViewSetDrawingEnabled(view, false);
- HIViewSetFrame(view, &bounds);
- HIViewSetDrawingEnabled(view, true);
-
- // Update any newly exposed areas due to resizing.
- const int startx = oldRect.width();
- const int stopx = newRect.width();
- const int starty = oldRect.height();
- const int stopy = newRect.height();
-
- const HIRect verticalSlice = CGRectMake(startx, 0, stopx , stopy);
- HIViewSetNeedsDisplayInRect(view, &verticalSlice, true);
- const HIRect horizontalSlice = CGRectMake(0, starty, startx, stopy);
- HIViewSetNeedsDisplayInRect(view, &horizontalSlice, true);
-}
-#endif
-
-/*
- Helper function for non-toplevel widgets. Helps to map Qt's 32bit
- coordinate system to OS X's 16bit coordinate system.
-
- Sets the geometry of the widget to data.crect, but clipped to sizes
- that OS X can handle. Unmaps widgets that are completely outside the
- valid range.
-
- Maintains data.wrect, which is the geometry of the OS X widget,
- measured in this widget's coordinate system.
-
- if the parent is not clipped, parentWRect is empty, otherwise
- parentWRect is the geometry of the parent's OS X rect, measured in
- parent's coord sys
-*/
-void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &oldRect)
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
-
- if (!q->internalWinId() && QApplicationPrivate::graphicsSystem() != 0) {
- // We have no view to move, and no paint engine that
- // we can update dirty regions on. So just return:
- return;
- }
-
- QMacCocoaAutoReleasePool pool;
-
- /*
- There are up to four different coordinate systems here:
- Qt coordinate system for this widget.
- X coordinate system for this widget (relative to wrect).
- Qt coordinate system for parent
- X coordinate system for parent (relative to parent's wrect).
- */
-
- // wrect is the same as crect, except that it is
- // clipped to fit inside parent (and screen):
- QRect wrect;
-
- // wrectInParentCoordSys will be the same as wrect, except that it is
- // originated in q's parent rather than q itself. It starts out in
- // parent's Qt coord system, and ends up in parent's coordinate system:
- QRect wrectInParentCoordSys = data.crect;
-
- // If q's parent has been clipped, parentWRect will
- // be filled with the parents clipped crect:
- QRect parentWRect;
-
- // Embedded have different meaning on each platform, and on
- // Mac, it means that q is a QMacNativeWidget.
- bool isEmbeddedWindow = (q->isWindow() && topData()->embedded);
-#ifdef QT_MAC_USE_COCOA
- NSView *nsview = qt_mac_nativeview_for(q);
-#endif
- if (!isEmbeddedWindow) {
- parentWRect = q->parentWidget()->data->wrect;
- } else {
- // INVARIANT: q's parent view is not owned by Qt. So we need to
- // do some extra calls to get the clipped rect of the parent view:
-#ifndef QT_MAC_USE_COCOA
- HIViewRef parentView = HIViewGetSuperview(qt_mac_nativeview_for(q));
-#else
- NSView *parentView = [qt_mac_nativeview_for(q) superview];
-#endif
- if (parentView) {
-#ifndef QT_MAC_USE_COCOA
- HIRect tmpRect;
- HIViewGetFrame(parentView, &tmpRect);
-#else
- NSRect tmpRect = [parentView frame];
-#endif
- parentWRect = QRect(tmpRect.origin.x, tmpRect.origin.y,
- tmpRect.size.width, tmpRect.size.height);
- } else {
- const QRect wrectRange(-WRECT_MAX,-WRECT_MAX, 2*WRECT_MAX, 2*WRECT_MAX);
- parentWRect = wrectRange;
- }
- }
-
- if (parentWRect.isValid()) {
- // INVARIANT: q's parent has been clipped.
- // So we fit our own wrects inside it:
- if (!parentWRect.contains(wrectInParentCoordSys) && !isEmbeddedWindow) {
- wrectInParentCoordSys &= parentWRect;
- wrect = wrectInParentCoordSys;
- // Make sure wrect is originated in q's coordinate system:
- wrect.translate(-data.crect.topLeft());
- }
- // // Make sure wrectInParentCoordSys originated in q's parent coordinate system:
- wrectInParentCoordSys.translate(-parentWRect.topLeft());
- } else {
- // INVARIANT: we dont know yet the clipping rect of q's parent.
- // So we may or may not have to adjust our wrects:
-
- if (data.wrect.isValid() && QRect(QPoint(),data.crect.size()).contains(data.wrect)) {
- // This is where the main optimization is: we have an old wrect from an earlier
- // setGeometry call, and the new crect is smaller than it. If the final wrect is
- // also inside the old wrect, we can just move q and its children to the new
- // location without any clipping:
-
- // vrect will be the part of q that's will be visible inside
- // q's parent. If it inside the old wrect, then we can just move:
- QRect vrect = wrectInParentCoordSys & q->parentWidget()->rect();
- vrect.translate(-data.crect.topLeft());
-
- if (data.wrect.contains(vrect)) {
- wrectInParentCoordSys = data.wrect;
- wrectInParentCoordSys.translate(data.crect.topLeft());
-#ifndef QT_MAC_USE_COCOA
- HIRect bounds = CGRectMake(wrectInParentCoordSys.x(), wrectInParentCoordSys.y(),
- wrectInParentCoordSys.width(), wrectInParentCoordSys.height());
- HIViewSetFrame(qt_mac_nativeview_for(q), &bounds);
-#else
- if (nsview) {
- // INVARIANT: q is native. Set view frame:
- NSRect bounds = NSMakeRect(wrectInParentCoordSys.x(), wrectInParentCoordSys.y(),
- wrectInParentCoordSys.width(), wrectInParentCoordSys.height());
- [nsview setFrame:bounds];
- } else {
- // INVARIANT: q is alien. Repaint wrect instead (includes old and new wrect):
- QWidget *parent = q->parentWidget();
- QPoint globalPosWRect = parent->mapToGlobal(data.wrect.topLeft());
-
- QWidget *nativeParent = q->nativeParentWidget();
- QRect dirtyWRect = QRect(nativeParent->mapFromGlobal(globalPosWRect), data.wrect.size());
-
- nativeParent->update(dirtyWRect);
- }
-#endif
- if (q->testAttribute(Qt::WA_OutsideWSRange)) {
- q->setAttribute(Qt::WA_OutsideWSRange, false);
- if (!dontShow) {
- q->setAttribute(Qt::WA_Mapped);
-#ifndef QT_MAC_USE_COCOA
- HIViewSetVisible(qt_mac_nativeview_for(q), true);
-#else
- // If q is Alien, the following call does nothing:
- [nsview setHidden:NO];
-#endif
- }
- }
- return;
- }
- }
-
-#ifndef QT_MAC_USE_COCOA
- const QRect validRange(-XCOORD_MAX,-XCOORD_MAX, 2*XCOORD_MAX, 2*XCOORD_MAX);
- if (!validRange.contains(wrectInParentCoordSys)) {
- // We're too big, and must clip:
- QPoint screenOffset(0, 0); // offset of the part being on screen
- const QWidget *parentWidget = q->parentWidget();
- while (parentWidget && !parentWidget->isWindow()) {
- screenOffset -= parentWidget->data->crect.topLeft();
- parentWidget = parentWidget->parentWidget();
- }
- QRect cropRect(screenOffset.x() - WRECT_MAX,
- screenOffset.y() - WRECT_MAX,
- 2*WRECT_MAX,
- 2*WRECT_MAX);
-
- wrectInParentCoordSys &=cropRect;
- wrect = wrectInParentCoordSys;
- wrect.translate(-data.crect.topLeft());
- }
-#endif //QT_MAC_USE_COCOA
- }
-
- // unmap if we are outside the valid window system coord system
- bool outsideRange = !wrectInParentCoordSys.isValid();
- bool mapWindow = false;
- if (q->testAttribute(Qt::WA_OutsideWSRange) != outsideRange) {
- q->setAttribute(Qt::WA_OutsideWSRange, outsideRange);
- if (outsideRange) {
-#ifndef QT_MAC_USE_COCOA
- HIViewSetVisible(qt_mac_nativeview_for(q), false);
-#else
- // If q is Alien, the following call does nothing:
- [nsview setHidden:YES];
-#endif
- q->setAttribute(Qt::WA_Mapped, false);
- } else if (!q->isHidden()) {
- mapWindow = true;
- }
- }
-
- if (outsideRange)
- return;
-
- // Store the new clipped rect:
- bool jump = (data.wrect != wrect);
- data.wrect = wrect;
-
- // and now recursively for all children...
- // ### can be optimized
- for (int i = 0; i < children.size(); ++i) {
- QObject *object = children.at(i);
- if (object->isWidgetType()) {
- QWidget *w = static_cast<QWidget *>(object);
- if (!w->isWindow() && w->testAttribute(Qt::WA_WState_Created))
- w->d_func()->setWSGeometry();
- }
- }
-
-#ifndef QT_MAC_USE_COCOA
- // Move the actual HIView:
- qt_mac_update_widget_position(q, oldRect, wrectInParentCoordSys);
- if (jump)
- q->update();
-#else
- if (nsview) {
- // INVARIANT: q is native. Move the actual NSView:
- NSRect bounds = NSMakeRect(
- wrectInParentCoordSys.x(), wrectInParentCoordSys.y(),
- wrectInParentCoordSys.width(), wrectInParentCoordSys.height());
- [nsview setFrame:bounds];
- if (jump)
- q->update();
- } else if (QApplicationPrivate::graphicsSystem() == 0){
- // INVARIANT: q is alien and we use native paint engine.
- // Schedule updates where q is moved from and to:
- const QWidget *parent = q->parentWidget();
- const QPoint globalPosOldWRect = parent->mapToGlobal(oldRect.topLeft());
- const QPoint globalPosNewWRect = parent->mapToGlobal(wrectInParentCoordSys.topLeft());
-
- QWidget *nativeParent = q->nativeParentWidget();
- const QRegion dirtyOldWRect = QRect(nativeParent->mapFromGlobal(globalPosOldWRect), oldRect.size());
- const QRegion dirtyNewWRect = QRect(nativeParent->mapFromGlobal(globalPosNewWRect), wrectInParentCoordSys.size());
-
- const bool sizeUnchanged = oldRect.size() == wrectInParentCoordSys.size();
- const bool posUnchanged = oldRect.topLeft() == wrectInParentCoordSys.topLeft();
-
- // Resolve/minimize the region that needs to update:
- if (sizeUnchanged && q->testAttribute(Qt::WA_OpaquePaintEvent)) {
- // INVARIANT: q is opaque, and is only moved (not resized). So in theory we only
- // need to blit pixels, and skip a repaint. But we can only make this work if we
- // had access to the backbuffer, so we need to update all:
- nativeParent->update(dirtyOldWRect | dirtyNewWRect);
- } else if (posUnchanged && q->testAttribute(Qt::WA_StaticContents)) {
- // We only need to redraw exposed areas:
- nativeParent->update(dirtyNewWRect - dirtyOldWRect);
- } else {
- nativeParent->update(dirtyOldWRect | dirtyNewWRect);
- }
- }
-#endif
-
- if (mapWindow && !dontShow) {
- q->setAttribute(Qt::WA_Mapped);
-#ifndef QT_MAC_USE_COCOA
- HIViewSetVisible(qt_mac_nativeview_for(q), true);
-#else
- // If q is Alien, the following call does nothing:
- [nsview setHidden:NO];
-#endif
- }
-}
-
-void QWidgetPrivate::adjustWithinMaxAndMinSize(int &w, int &h)
-{
- if (QWExtra *extra = extraData()) {
- w = qMin(w, extra->maxw);
- h = qMin(h, extra->maxh);
- w = qMax(w, extra->minw);
- h = qMax(h, extra->minh);
-
- // Deal with size increment
- if (QTLWExtra *top = topData()) {
- if(top->incw) {
- w = w/top->incw;
- w *= top->incw;
- }
- if(top->inch) {
- h = h/top->inch;
- h *= top->inch;
- }
- }
- }
-
- if (isRealWindow()) {
- w = qMax(0, w);
- h = qMax(0, h);
- }
-}
-
-void QWidgetPrivate::applyMaxAndMinSizeOnWindow()
-{
- Q_Q(QWidget);
- QMacCocoaAutoReleasePool pool;
-
- const float max_f(20000);
-#ifndef QT_MAC_USE_COCOA
-#define SF(x) ((x > max_f) ? max_f : x)
- HISize max = CGSizeMake(SF(extra->maxw), SF(extra->maxh));
- HISize min = CGSizeMake(SF(extra->minw), SF(extra->minh));
-#undef SF
- SetWindowResizeLimits(qt_mac_window_for(q), &min, &max);
-#else
-#define SF(x) ((x > max_f) ? max_f : x)
- NSSize max = NSMakeSize(SF(extra->maxw), SF(extra->maxh));
- NSSize min = NSMakeSize(SF(extra->minw), SF(extra->minh));
-#undef SF
- [qt_mac_window_for(q) setContentMinSize:min];
- [qt_mac_window_for(q) setContentMaxSize:max];
-#endif
-}
-
-void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
-
- if(q->windowType() == Qt::Desktop)
- return;
-
- QMacCocoaAutoReleasePool pool;
- bool realWindow = isRealWindow();
-
- if (realWindow && !q->testAttribute(Qt::WA_DontShowOnScreen)){
- adjustWithinMaxAndMinSize(w, h);
-#ifndef QT_MAC_USE_COCOA
- if (w != 0 && h != 0) {
- topData()->isSetGeometry = 1;
- topData()->isMove = isMove;
- Rect r; SetRect(&r, x, y, x + w, y + h);
- SetWindowBounds(qt_mac_window_for(q), kWindowContentRgn, &r);
- topData()->isSetGeometry = 0;
- } else {
- setGeometry_sys_helper(x, y, w, h, isMove);
- }
-#else
- if (!isMove && !q->testAttribute(Qt::WA_Moved) && !q->isVisible()) {
- // INVARIANT: The location of the window has not yet been set. The default will
- // instead be to center it on the desktop, or over the parent, if any. Since we now
- // resize the window, we need to adjust the top left position to keep the window
- // centeralized. And we need to to this now (and before show) in case the positioning
- // of other windows (e.g. sub-windows) depend on this position:
- if (QWidget *p = q->parentWidget()) {
- x = p->geometry().center().x() - (w / 2);
- y = p->geometry().center().y() - (h / 2);
- } else {
- QRect availGeo = QApplication::desktop()->availableGeometry(q);
- x = availGeo.center().x() - (w / 2);
- y = availGeo.center().y() - (h / 2);
- }
- }
-
- QSize olds = q->size();
- const bool isResize = (olds != QSize(w, h));
- NSWindow *window = qt_mac_window_for(q);
- const QRect &fStrut = frameStrut();
- const QRect frameRect(QPoint(x - fStrut.left(), y - fStrut.top()),
- QSize(fStrut.left() + fStrut.right() + w,
- fStrut.top() + fStrut.bottom() + h));
- NSRect cocoaFrameRect = NSMakeRect(frameRect.x(), flipYCoordinate(frameRect.bottom() + 1),
- frameRect.width(), frameRect.height());
- // The setFrame call will trigger a 'windowDidResize' notification for the corresponding
- // NSWindow. The pending flag is set, so that the resize event can be send as non-spontaneous.
- if (isResize)
- q->setAttribute(Qt::WA_PendingResizeEvent);
- QPoint currTopLeft = data.crect.topLeft();
- if (currTopLeft.x() == x && currTopLeft.y() == y
- && cocoaFrameRect.size.width != 0
- && cocoaFrameRect.size.height != 0) {
- [window setFrame:cocoaFrameRect display:realWindow];
- } else {
- // The window is moved and resized (or resized to zero).
- // Since Cocoa usually only sends us a resize callback after
- // setting a window frame, we issue an explicit move as
- // well. To stop Cocoa from optimize away the move (since the move
- // would have the same origin as the setFrame call) we shift the
- // window back and forth inbetween.
- cocoaFrameRect.origin.y += 1;
- [window setFrame:cocoaFrameRect display:realWindow];
- cocoaFrameRect.origin.y -= 1;
- [window setFrameOrigin:cocoaFrameRect.origin];
- }
-#endif
- } else {
- setGeometry_sys_helper(x, y, w, h, isMove);
- }
-
- topLevelAt_cache = 0;
-}
-
-void QWidgetPrivate::setGeometry_sys_helper(int x, int y, int w, int h, bool isMove)
-{
- Q_Q(QWidget);
- bool realWindow = isRealWindow();
-
- QPoint oldp = q->pos();
- QSize olds = q->size();
- const bool isResize = (olds != QSize(w, h));
-
- if (!realWindow && !isResize && QPoint(x, y) == oldp)
- return;
-
- if (isResize)
- data.window_state = data.window_state & ~Qt::WindowMaximized;
-
- const bool visible = q->isVisible();
- // Apply size restrictions, applicable for Windows & Widgets.
- if (QWExtra *extra = extraData()) {
- w = qMin(w, extra->maxw);
- h = qMin(h, extra->maxh);
- w = qMax(w, extra->minw);
- h = qMax(h, extra->minh);
- }
- data.crect = QRect(x, y, w, h);
-
- if (realWindow) {
- adjustWithinMaxAndMinSize(w, h);
- qt_mac_update_sizer(q);
-
-#ifndef QT_MAC_USE_COCOA
- if (q->windowFlags() & Qt::WindowMaximizeButtonHint) {
- OSWindowRef window = qt_mac_window_for(q);
- if (extra->maxw && extra->maxh && extra->maxw == extra->minw
- && extra->maxh == extra->minh) {
- ChangeWindowAttributes(window, kWindowNoAttributes, kWindowFullZoomAttribute);
- } else {
- ChangeWindowAttributes(window, kWindowFullZoomAttribute, kWindowNoAttributes);
- }
- }
- HIRect bounds = CGRectMake(0, 0, w, h);
- HIViewSetFrame(qt_mac_nativeview_for(q), &bounds);
-#else
- [qt_mac_nativeview_for(q) setFrame:NSMakeRect(0, 0, w, h)];
-#endif
- } else {
- const QRect oldRect(oldp, olds);
- if (!isResize && QApplicationPrivate::graphicsSystem())
- moveRect(oldRect, x - oldp.x(), y - oldp.y());
-
- setWSGeometry(false, oldRect);
-
- if (isResize && QApplicationPrivate::graphicsSystem())
- invalidateBuffer_resizeHelper(oldp, olds);
- }
-
- if(isMove || isResize) {
- if(!visible) {
- if(isMove && q->pos() != oldp)
- q->setAttribute(Qt::WA_PendingMoveEvent, true);
- if(isResize)
- q->setAttribute(Qt::WA_PendingResizeEvent, true);
- } else {
- if(isResize) { //send the resize event..
- QResizeEvent e(q->size(), olds);
- QApplication::sendEvent(q, &e);
- }
- if(isMove && q->pos() != oldp) { //send the move event..
- QMoveEvent e(q->pos(), oldp);
- QApplication::sendEvent(q, &e);
- }
- }
- }
- qt_event_request_window_change(q);
-}
-
-void QWidgetPrivate::setConstraints_sys()
-{
- updateMaximizeButton_sys();
- applyMaxAndMinSizeOnWindow();
-}
-
-void QWidgetPrivate::updateMaximizeButton_sys()
-{
- Q_Q(QWidget);
- if (q->data->window_flags & Qt::CustomizeWindowHint)
- return;
-
- OSWindowRef window = qt_mac_window_for(q);
- QTLWExtra * tlwExtra = topData();
-#ifdef QT_MAC_USE_COCOA
- QMacCocoaAutoReleasePool pool;
- NSButton *maximizeButton = [window standardWindowButton:NSWindowZoomButton];
-#endif
- if (extra->maxw && extra->maxh
- && extra->maxw == extra->minw
- && extra->maxh == extra->minh) {
- // The window has a fixed size, so gray out the maximize button:
- if (!tlwExtra->savedWindowAttributesFromMaximized) {
-#ifndef QT_MAC_USE_COCOA
- GetWindowAttributes(window,
- (WindowAttributes*)&extra->topextra->savedWindowAttributesFromMaximized);
-
-#else
- tlwExtra->savedWindowAttributesFromMaximized = (![maximizeButton isHidden] && [maximizeButton isEnabled]);
-#endif
- }
-#ifndef QT_MAC_USE_COCOA
- ChangeWindowAttributes(window, kWindowNoAttributes, kWindowFullZoomAttribute);
-#else
- [maximizeButton setEnabled:NO];
-#endif
-
-
- } else {
- if (tlwExtra->savedWindowAttributesFromMaximized) {
-#ifndef QT_MAC_USE_COCOA
- ChangeWindowAttributes(window,
- extra->topextra->savedWindowAttributesFromMaximized,
- kWindowNoAttributes);
-#else
- [maximizeButton setEnabled:YES];
-#endif
- tlwExtra->savedWindowAttributesFromMaximized = 0;
- }
- }
-
-
-}
-
-void QWidgetPrivate::scroll_sys(int dx, int dy)
-{
- if (QApplicationPrivate::graphicsSystem() && !paintOnScreen()) {
- // INVARIANT: Alien paint engine
- scrollChildren(dx, dy);
- scrollRect(q_func()->rect(), dx, dy);
- } else {
- scroll_sys(dx, dy, QRect());
- }
-}
-
-void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &qscrollRect)
-{
- if (QMacScrollOptimization::delayScroll(this, dx, dy, qscrollRect))
- return;
-
- Q_Q(QWidget);
- if (QApplicationPrivate::graphicsSystem() && !paintOnScreen()) {
- // INVARIANT: Alien paint engine
- scrollRect(qscrollRect, dx, dy);
- return;
- }
-
- static int accelEnv = -1;
- if (accelEnv == -1) {
- accelEnv = qgetenv("QT_NO_FAST_SCROLL").toInt() == 0;
- }
-
- // Scroll the whole widget if qscrollRect is not valid:
- QRect validScrollRect = qscrollRect.isValid() ? qscrollRect : q->rect();
- validScrollRect &= clipRect();
-
- // If q is overlapped by other widgets, we cannot just blit pixels since
- // this will move overlapping widgets as well. In case we just update:
- const bool overlapped = isOverlapped(validScrollRect.translated(data.crect.topLeft()));
- const bool accelerateScroll = accelEnv && isOpaque && !overlapped;
- const bool isAlien = (q->internalWinId() == 0);
- const QPoint scrollDelta(dx, dy);
-
- // If qscrollRect is valid, we are _not_ supposed to scroll q's children (as documented).
- // But we do scroll children (and the whole of q) if qscrollRect is invalid. This case is
- // documented as undefined, but we exploit it to help factor our code into one function.
- const bool scrollChildren = !qscrollRect.isValid();
-
- if (!q->updatesEnabled()) {
- // We are told not to update anything on q at this point. So unless
- // we are supposed to scroll children, we bail out early:
- if (!scrollChildren || q->children().isEmpty())
- return;
- }
-
- if (!accelerateScroll) {
- if (overlapped) {
- QRegion region(validScrollRect);
- subtractOpaqueSiblings(region);
- update_sys(region);
- }else {
- update_sys(qscrollRect);
- }
- return;
- }
-
-#ifdef QT_MAC_USE_COCOA
- QMacCocoaAutoReleasePool pool;
-#else
- Q_UNUSED(isAlien);
- // We're not sure what the following call is supposed to achive
- // but until we see what it breaks, we don't bring it into the
- // Cocoa port:
- qt_event_request_window_change(q);
-#endif
-
- // First move all native children. Alien children will indirectly be
- // moved when the parent is scrolled. All directly or indirectly moved
- // children will receive a move event before the function call returns.
- QWidgetList movedChildren;
- if (scrollChildren) {
- QObjectList children = q->children();
-
- for (int i=0; i<children.size(); i++) {
- QObject *obj = children.at(i);
- if (QWidget *w = qobject_cast<QWidget*>(obj)) {
- if (!w->isWindow()) {
- w->data->crect = QRect(w->pos() + scrollDelta, w->size());
-#ifndef QT_MAC_USE_COCOA
- if (w->testAttribute(Qt::WA_WState_Created)) {
- HIRect bounds = CGRectMake(w->data->crect.x(), w->data->crect.y(),
- w->data->crect.width(), w->data->crect.height());
- HIViewRef hiview = qt_mac_nativeview_for(w);
- const bool opaque = q->testAttribute(Qt::WA_OpaquePaintEvent);
-
- if (opaque)
- HIViewSetDrawingEnabled(hiview, false);
- HIViewSetFrame(hiview, &bounds);
- if (opaque)
- HIViewSetDrawingEnabled(hiview, true);
- }
-#else
- if (NSView *view = qt_mac_nativeview_for(w)) {
- // INVARIANT: w is not alien
- [view setFrame:NSMakeRect(
- w->data->crect.x(), w->data->crect.y(),
- w->data->crect.width(), w->data->crect.height())];
- }
-#endif
- movedChildren.append(w);
- }
- }
- }
- }
-
- if (q->testAttribute(Qt::WA_WState_Created) && q->isVisible()) {
- // Scroll q itself according to the qscrollRect, and
- // call update on any exposed areas so that they get redrawn:
-
-#ifndef QT_MAC_USE_COCOA
- OSViewRef view = qt_mac_nativeview_for(q);
- HIRect scrollrect = CGRectMake(qscrollRect.x(), qscrollRect.y(), qscrollRect.width(), qscrollRect.height());
- OSStatus err = _HIViewScrollRectWithOptions(view, qscrollRect.isValid() ? &scrollrect : 0, dx, dy, kHIViewScrollRectAdjustInvalid);
- if (err) {
- // The only parameter that can go wrong, is the rect.
- qWarning("QWidget::scroll: Your rectangle was too big for the widget, clipping rect");
- scrollrect = CGRectMake(qMax(qscrollRect.x(), 0), qMax(qscrollRect.y(), 0),
- qMin(qscrollRect.width(), q->width()), qMin(qscrollRect.height(), q->height()));
- _HIViewScrollRectWithOptions(view, qscrollRect.isValid() ? &scrollrect : 0, dx, dy, kHIViewScrollRectAdjustInvalid);
- }
-#else
-
- QWidget *nativeWidget = isAlien ? q->nativeParentWidget() : q;
- if (!nativeWidget)
- return;
- OSViewRef view = qt_mac_nativeview_for(nativeWidget);
- if (!view)
- return;
-
- // Calculate the rectangles that needs to be redrawn
- // after the scroll. This will be source rect minus destination rect:
- QRect deltaXRect;
- if (dx != 0) {
- deltaXRect.setY(validScrollRect.y());
- deltaXRect.setHeight(validScrollRect.height());
- if (dx > 0) {
- deltaXRect.setX(validScrollRect.x());
- deltaXRect.setWidth(dx);
- } else {
- deltaXRect.setX(validScrollRect.x() + validScrollRect.width() + dx);
- deltaXRect.setWidth(-dx);
- }
- }
-
- QRect deltaYRect;
- if (dy != 0) {
- deltaYRect.setX(validScrollRect.x());
- deltaYRect.setWidth(validScrollRect.width());
- if (dy > 0) {
- deltaYRect.setY(validScrollRect.y());
- deltaYRect.setHeight(dy);
- } else {
- deltaYRect.setY(validScrollRect.y() + validScrollRect.height() + dy);
- deltaYRect.setHeight(-dy);
- }
- }
-
- if (isAlien) {
- // Adjust the scroll rect to the location as seen from the native parent:
- QPoint scrollTopLeftInsideNative = nativeWidget->mapFromGlobal(q->mapToGlobal(validScrollRect.topLeft()));
- validScrollRect.moveTo(scrollTopLeftInsideNative);
- }
-
- // Make the pixel copy rect within the validScrollRect bounds:
- NSRect nsscrollRect = NSMakeRect(
- validScrollRect.x() + (dx < 0 ? -dx : 0),
- validScrollRect.y() + (dy < 0 ? -dy : 0),
- validScrollRect.width() + (dx > 0 ? -dx : 0),
- validScrollRect.height() + (dy > 0 ? -dy : 0));
-
- NSSize deltaSize = NSMakeSize(dx, dy);
- [view scrollRect:nsscrollRect by:deltaSize];
-
- // Some areas inside the scroll rect might have been marked as dirty from before, which
- // means that they are scheduled to be redrawn. But as we now scroll, those dirty rects
- // should also move along to ensure that q receives repaints on the correct places.
- // Since some of the dirty rects might lay outside, or only intersect with, the scroll
- // rect, the old calls to setNeedsDisplay still makes sense.
- // NB: Using [view translateRectsNeedingDisplayInRect:nsscrollRect by:deltaSize] have
- // so far not been proven fruitful to solve this problem.
- const QVector<QRect> &dirtyRectsToScroll = dirtyOnWidget.rects();
- for (int i=0; i<dirtyRectsToScroll.size(); ++i) {
- QRect qdirtyRect = dirtyRectsToScroll[i];
- qdirtyRect.translate(dx, dy);
- update_sys(qdirtyRect);
- }
-
- // Update newly exposed areas. This will generate new dirty areas on
- // q, and therefore, we do it after updating the old dirty rects above:
- if (dx != 0)
- update_sys(deltaXRect);
- if (dy != 0)
- update_sys(deltaYRect);
-
-#endif // QT_MAC_USE_COCOA
- }
-
- for (int i=0; i<movedChildren.size(); i++) {
- QWidget *w = movedChildren.at(i);
- QMoveEvent e(w->pos(), w->pos() - scrollDelta);
- QApplication::sendEvent(w, &e);
- }
-}
-
-int QWidget::metric(PaintDeviceMetric m) const
-{
- switch(m) {
- case PdmHeightMM:
- return qRound(metric(PdmHeight) * 25.4 / qreal(metric(PdmDpiY)));
- case PdmWidthMM:
- return qRound(metric(PdmWidth) * 25.4 / qreal(metric(PdmDpiX)));
- case PdmHeight:
- case PdmWidth:
-#ifndef QT_MAC_USE_COCOA
- { HIRect rect;
- HIViewGetFrame(qt_mac_nativeview_for(this), &rect);
- if(m == PdmWidth)
- return (int)rect.size.width;
- return (int)rect.size.height; }
-#else
- if (m == PdmWidth)
- return data->crect.width();
- else
- return data->crect.height();
-#endif
- case PdmDepth:
- return 32;
- case PdmNumColors:
- return INT_MAX;
- case PdmDpiX:
- case PdmPhysicalDpiX: {
- Q_D(const QWidget);
- if (d->extra && d->extra->customDpiX)
- return d->extra->customDpiX;
- else if (d->parent)
- return static_cast<QWidget *>(d->parent)->metric(m);
- extern float qt_mac_defaultDpi_x(); //qpaintdevice_mac.cpp
- return int(qt_mac_defaultDpi_x()); }
- case PdmDpiY:
- case PdmPhysicalDpiY: {
- Q_D(const QWidget);
- if (d->extra && d->extra->customDpiY)
- return d->extra->customDpiY;
- else if (d->parent)
- return static_cast<QWidget *>(d->parent)->metric(m);
- extern float qt_mac_defaultDpi_y(); //qpaintdevice_mac.cpp
- return int(qt_mac_defaultDpi_y()); }
- default: //leave this so the compiler complains when new ones are added
- qWarning("QWidget::metric: Unhandled parameter %d", m);
- return QPaintDevice::metric(m);
- }
- return 0;
-}
-
-void QWidgetPrivate::createSysExtra()
-{
-#ifdef QT_MAC_USE_COCOA
- extra->imageMask = 0;
-#endif
-}
-
-void QWidgetPrivate::deleteSysExtra()
-{
-#ifdef QT_MAC_USE_COCOA
- if (extra->imageMask)
- CFRelease(extra->imageMask);
-#endif
-}
-
-void QWidgetPrivate::createTLSysExtra()
-{
- extra->topextra->resizer = 0;
- extra->topextra->isSetGeometry = 0;
- extra->topextra->isMove = 0;
- extra->topextra->wattr = 0;
- extra->topextra->wclass = 0;
- extra->topextra->group = 0;
- extra->topextra->windowIcon = 0;
- extra->topextra->savedWindowAttributesFromMaximized = 0;
-}
-
-void QWidgetPrivate::deleteTLSysExtra()
-{
-#ifndef QT_MAC_USE_COCOA
- if (extra->topextra->group) {
- qt_mac_release_window_group(extra->topextra->group);
- extra->topextra->group = 0;
- }
- if (extra->topextra->windowIcon) {
- ReleaseIconRef(extra->topextra->windowIcon);
- extra->topextra->windowIcon = 0;
- }
-#endif
-}
-
-void QWidgetPrivate::updateFrameStrut()
-{
- Q_Q(QWidget);
-
- QWidgetPrivate *that = const_cast<QWidgetPrivate*>(this);
-
- that->data.fstrut_dirty = false;
- QTLWExtra *top = that->topData();
-
-#if QT_MAC_USE_COCOA
- // 1 Get the window frame
- OSWindowRef oswnd = qt_mac_window_for(q);
- NSRect frameW = [oswnd frame];
- // 2 Get the content frame - so now
- NSRect frameC = [oswnd contentRectForFrameRect:frameW];
- top->frameStrut.setCoords(frameC.origin.x - frameW.origin.x,
- (frameW.origin.y + frameW.size.height) - (frameC.origin.y + frameC.size.height),
- (frameW.origin.x + frameW.size.width) - (frameC.origin.x + frameC.size.width),
- frameC.origin.y - frameW.origin.y);
-#else
- Rect window_r;
- GetWindowStructureWidths(qt_mac_window_for(q), &window_r);
- top->frameStrut.setCoords(window_r.left, window_r.top, window_r.right, window_r.bottom);
-#endif
-}
-
-void QWidgetPrivate::registerDropSite(bool on)
-{
- Q_Q(QWidget);
- if (!q->testAttribute(Qt::WA_WState_Created))
- return;
-#ifndef QT_MAC_USE_COCOA
- SetControlDragTrackingEnabled(qt_mac_nativeview_for(q), on);
-#else
- NSWindow *win = qt_mac_window_for(q);
- if (on) {
- if ([win isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaWindow) class]])
- [static_cast<QT_MANGLE_NAMESPACE(QCocoaWindow) *>(win) registerDragTypes];
- else if ([win isKindOfClass:[QT_MANGLE_NAMESPACE(QCocoaPanel) class]])
- [static_cast<QT_MANGLE_NAMESPACE(QCocoaPanel) *>(win) registerDragTypes];
- }
-#endif
-}
-
-void QWidgetPrivate::registerTouchWindow(bool enable)
-{
- Q_UNUSED(enable);
-#ifdef QT_MAC_USE_COCOA
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
- if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_6)
- return;
-
- Q_Q(QWidget);
- if (enable == touchEventsEnabled)
- return;
-
- QCocoaView *view = static_cast<QCocoaView *>(qt_mac_effectiveview_for(q));
- if (!view)
- return;
-
- if (enable) {
- ++view->alienTouchCount;
- if (view->alienTouchCount == 1) {
- touchEventsEnabled = true;
- [view setAcceptsTouchEvents:YES];
- }
- } else {
- --view->alienTouchCount;
- if (view->alienTouchCount == 0) {
- touchEventsEnabled = false;
- [view setAcceptsTouchEvents:NO];
- }
- }
-#endif
-#endif
-}
-
-void QWidgetPrivate::setMask_sys(const QRegion &region)
-{
- Q_UNUSED(region);
- Q_Q(QWidget);
-
-#ifndef QT_MAC_USE_COCOA
- if (q->isWindow())
- ReshapeCustomWindow(qt_mac_window_for(q));
- else
- HIViewReshapeStructure(qt_mac_nativeview_for(q));
-#else
- if (!q->internalWinId())
- return;
-
- if (extra->mask.isEmpty()) {
- extra->maskBits = QImage();
- finishCocoaMaskSetup();
- } else {
- syncCocoaMask();
- }
-
- topLevelAt_cache = 0;
-#endif
-}
-
-void QWidgetPrivate::setWindowOpacity_sys(qreal level)
-{
- Q_Q(QWidget);
-
- if (!q->isWindow())
- return;
-
- level = qBound(0.0, level, 1.0);
- topData()->opacity = (uchar)(level * 255);
- if (!q->testAttribute(Qt::WA_WState_Created))
- return;
-
- OSWindowRef oswindow = qt_mac_window_for(q);
-#if QT_MAC_USE_COCOA
- [oswindow setAlphaValue:level];
-#else
- SetWindowAlpha(oswindow, level);
-#endif
-}
-
-#ifdef QT_MAC_USE_COCOA
-void QWidgetPrivate::syncCocoaMask()
-{
- Q_Q(QWidget);
- if (!q->testAttribute(Qt::WA_WState_Created) || !extra)
- return;
-
- if (extra->hasMask) {
- if(extra->maskBits.size() != q->size()) {
- extra->maskBits = QImage(q->size(), QImage::Format_Mono);
- }
- extra->maskBits.fill(QColor(Qt::color1).rgba());
- extra->maskBits.setNumColors(2);
- extra->maskBits.setColor(0, QColor(Qt::color0).rgba());
- extra->maskBits.setColor(1, QColor(Qt::color1).rgba());
- QPainter painter(&extra->maskBits);
- painter.setBrush(Qt::color1);
- painter.setPen(Qt::NoPen);
- painter.drawRects(extra->mask.rects());
- painter.end();
- finishCocoaMaskSetup();
- }
-}
-
-void QWidgetPrivate::finishCocoaMaskSetup()
-{
- Q_Q(QWidget);
-
- if (!q->testAttribute(Qt::WA_WState_Created) || !extra)
- return;
-
- // Technically this is too late to release, because the data behind the image
- // has already been released. But it's more tidy to do it here.
- // If you are seeing a crash, consider doing a CFRelease before changing extra->maskBits.
- if (extra->imageMask) {
- CFRelease(extra->imageMask);
- extra->imageMask = 0;
- }
-
- if (!extra->maskBits.isNull()) {
- QCFType<CGDataProviderRef> dataProvider = CGDataProviderCreateWithData(0,
- extra->maskBits.bits(),
- extra->maskBits.numBytes(),
- 0); // shouldn't need to release.
- CGFloat decode[2] = {1, 0};
- extra->imageMask = CGImageMaskCreate(extra->maskBits.width(), extra->maskBits.height(),
- 1, 1, extra->maskBits.bytesPerLine(), dataProvider,
- decode, false);
- }
- if (q->isWindow()) {
- NSWindow *window = qt_mac_window_for(q);
- [window setOpaque:(extra->imageMask == 0)];
- [window invalidateShadow];
- }
- macSetNeedsDisplay(QRegion());
-}
-#endif
-
-struct QPaintEngineCleanupHandler
-{
- inline QPaintEngineCleanupHandler() : engine(0) {}
- inline ~QPaintEngineCleanupHandler() { delete engine; }
- QPaintEngine *engine;
-};
-
-Q_GLOBAL_STATIC(QPaintEngineCleanupHandler, engineHandler)
-
-QPaintEngine *QWidget::paintEngine() const
-{
- QPaintEngine *&pe = engineHandler()->engine;
- if (!pe)
- pe = new QCoreGraphicsPaintEngine();
- if (pe->isActive()) {
- QPaintEngine *engine = new QCoreGraphicsPaintEngine();
- engine->setAutoDestruct(true);
- return engine;
- }
- return pe;
-}
-
-void QWidgetPrivate::setModal_sys()
-{
- Q_Q(QWidget);
- if (!q->testAttribute(Qt::WA_WState_Created) || !q->isWindow())
- return;
- const QWidget * const windowParent = q->window()->parentWidget();
- const QWidget * const primaryWindow = windowParent ? windowParent->window() : 0;
- OSWindowRef windowRef = qt_mac_window_for(q);
-
-#ifdef QT_MAC_USE_COCOA
- QMacCocoaAutoReleasePool pool;
- bool alreadySheet = [windowRef styleMask] & NSDocModalWindowMask;
-
- if (windowParent && q->windowModality() == Qt::WindowModal){
- // INVARIANT: Window should be window-modal (which implies a sheet).
- if (!alreadySheet) {
- // NB: the following call will call setModal_sys recursivly:
- recreateMacWindow();
- windowRef = qt_mac_window_for(q);
- }
- if ([windowRef isKindOfClass:[NSPanel class]]){
- // If the primary window of the sheet parent is a child of a modal dialog,
- // the sheet parent should not be modally shaddowed.
- // This goes for the sheet as well:
- OSWindowRef ref = primaryWindow ? qt_mac_window_for(primaryWindow) : 0;
- bool isDialog = ref ? [ref isKindOfClass:[NSPanel class]] : false;
- bool worksWhenModal = isDialog ? [static_cast<NSPanel *>(ref) worksWhenModal] : false;
- if (worksWhenModal)
- [static_cast<NSPanel *>(windowRef) setWorksWhenModal:YES];
- }
- } else {
- // INVARIANT: Window shold _not_ be window-modal (and as such, not a sheet).
- if (alreadySheet){
- // NB: the following call will call setModal_sys recursivly:
- recreateMacWindow();
- windowRef = qt_mac_window_for(q);
- }
- if (q->windowModality() == Qt::NonModal
- && primaryWindow && primaryWindow->windowModality() == Qt::ApplicationModal) {
- // INVARIANT: Our window has a parent that is application modal.
- // This means that q is supposed to be on top of this window and
- // not be modally shaddowed:
- if ([windowRef isKindOfClass:[NSPanel class]])
- [static_cast<NSPanel *>(windowRef) setWorksWhenModal:YES];
- }
- }
-
-#else
- const bool primaryWindowModal = primaryWindow ? primaryWindow->testAttribute(Qt::WA_ShowModal) : false;
- const bool modal = q->testAttribute(Qt::WA_ShowModal);
-
- WindowClass old_wclass;
- GetWindowClass(windowRef, &old_wclass);
-
- if (modal || primaryWindowModal) {
- if (q->windowModality() == Qt::WindowModal
- || (primaryWindow && primaryWindow->windowModality() == Qt::WindowModal)){
- // Window should be window-modal (which implies a sheet).
- if (old_wclass != kSheetWindowClass){
- // We cannot convert a created window to a sheet.
- // So we recreate the window:
- recreateMacWindow();
- return;
- }
- } else {
- // Window should be application-modal (which implies NOT using a sheet).
- if (old_wclass == kSheetWindowClass){
- // We cannot convert a sheet to a window.
- // So we recreate the window:
- recreateMacWindow();
- return;
- } else if (!(q->data->window_flags & Qt::CustomizeWindowHint)) {
- if (old_wclass == kDocumentWindowClass || old_wclass == kFloatingWindowClass || old_wclass == kUtilityWindowClass){
- // Only change the class to kMovableModalWindowClass if the no explicit jewels
- // are set (kMovableModalWindowClass can't contain them), and the current window class
- // can be converted to modal (according to carbon doc). Mind the order of
- // HIWindowChangeClass and ChangeWindowAttributes.
- WindowGroupRef group = GetWindowGroup(windowRef);
- HIWindowChangeClass(windowRef, kMovableModalWindowClass);
- quint32 tmpWattr = kWindowCloseBoxAttribute | kWindowHorizontalZoomAttribute;
- ChangeWindowAttributes(windowRef, tmpWattr, kWindowNoAttributes);
- ChangeWindowAttributes(windowRef, kWindowNoAttributes, tmpWattr);
- // If the window belongs to a qt-created group, set that group once more:
- if (data.window_flags & Qt::WindowStaysOnTopHint
- || q->windowType() == Qt::Popup
- || q->windowType() == Qt::ToolTip)
- SetWindowGroup(windowRef, group);
- }
- // Popups are usually handled "special" and are never modal.
- Qt::WindowType winType = q->windowType();
- if (winType != Qt::Popup && winType != Qt::ToolTip)
- SetWindowModality(windowRef, kWindowModalityAppModal, 0);
- }
- }
- } else if (windowRef) {
- if (old_wclass == kSheetWindowClass){
- // Converting a sheet to a window is complex. It's easier to recreate:
- recreateMacWindow();
- return;
- }
-
- SetWindowModality(windowRef, kWindowModalityNone, 0);
- if (!(q->data->window_flags & Qt::CustomizeWindowHint)) {
- if (q->window()->d_func()->topData()->wattr |= kWindowCloseBoxAttribute)
- ChangeWindowAttributes(windowRef, kWindowCloseBoxAttribute, kWindowNoAttributes);
- if (q->window()->d_func()->topData()->wattr |= kWindowHorizontalZoomAttribute)
- ChangeWindowAttributes(windowRef, kWindowHorizontalZoomAttribute, kWindowNoAttributes);
- if (q->window()->d_func()->topData()->wattr |= kWindowCollapseBoxAttribute)
- ChangeWindowAttributes(windowRef, kWindowCollapseBoxAttribute, kWindowNoAttributes);
- }
-
- WindowClass newClass = q->window()->d_func()->topData()->wclass;
- if (old_wclass != newClass && newClass != 0){
- WindowGroupRef group = GetWindowGroup(windowRef);
- HIWindowChangeClass(windowRef, newClass);
- // If the window belongs to a qt-created group, set that group once more:
- if (data.window_flags & Qt::WindowStaysOnTopHint
- || q->windowType() == Qt::Popup
- || q->windowType() == Qt::ToolTip)
- SetWindowGroup(windowRef, group);
- }
- }
-
- // Make sure that HIWindowChangeClass didn't remove drag support
- // or reset the opaque size grip setting:
- SetAutomaticControlDragTrackingEnabledForWindow(windowRef, true);
- macUpdateOpaqueSizeGrip();
-#endif
-}
-
-void QWidgetPrivate::macUpdateHideOnSuspend()
-{
- Q_Q(QWidget);
- if (!q->testAttribute(Qt::WA_WState_Created) || !q->isWindow() || q->windowType() != Qt::Tool)
- return;
-#ifndef QT_MAC_USE_COCOA
- if(q->testAttribute(Qt::WA_MacAlwaysShowToolWindow))
- ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowHideOnSuspendAttribute);
- else
- ChangeWindowAttributes(qt_mac_window_for(q), kWindowHideOnSuspendAttribute, 0);
-#else
- if(q->testAttribute(Qt::WA_MacAlwaysShowToolWindow))
- [qt_mac_window_for(q) setHidesOnDeactivate:NO];
- else
- [qt_mac_window_for(q) setHidesOnDeactivate:YES];
-#endif
-}
-
-void QWidgetPrivate::macUpdateOpaqueSizeGrip()
-{
- Q_Q(QWidget);
-
- if (!q->testAttribute(Qt::WA_WState_Created) || !q->isWindow())
- return;
-
-#ifndef QT_MAC_USE_COCOA // Growbox is always transparent on Cocoa. Can emulate with setting a QSizeGrip
- HIViewRef growBox;
- HIViewFindByID(HIViewGetRoot(qt_mac_window_for(q)), kHIViewWindowGrowBoxID, &growBox);
- if (!growBox)
- return;
- HIGrowBoxViewSetTransparent(growBox, !q->testAttribute(Qt::WA_MacOpaqueSizeGrip));
-#endif
-}
-
-void QWidgetPrivate::macUpdateSizeAttribute()
-{
- Q_Q(QWidget);
- QEvent event(QEvent::MacSizeChange);
- QApplication::sendEvent(q, &event);
- for (int i = 0; i < children.size(); ++i) {
- QWidget *w = qobject_cast<QWidget *>(children.at(i));
- if (w && (!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))
- && !q->testAttribute(Qt::WA_MacMiniSize) // no attribute set? inherit from parent
- && !w->testAttribute(Qt::WA_MacSmallSize)
- && !w->testAttribute(Qt::WA_MacNormalSize))
- w->d_func()->macUpdateSizeAttribute();
- }
- resolveFont();
-}
-
-void QWidgetPrivate::macUpdateIgnoreMouseEvents()
-{
-#ifndef QT_MAC_USE_COCOA // This is handled inside the mouse handler on Cocoa.
- Q_Q(QWidget);
- if (!q->testAttribute(Qt::WA_WState_Created))
- return;
-
- if(q->isWindow())
- {
- if(q->testAttribute(Qt::WA_TransparentForMouseEvents))
- ChangeWindowAttributes(qt_mac_window_for(q), kWindowIgnoreClicksAttribute, 0);
- else
- ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowIgnoreClicksAttribute);
- ReshapeCustomWindow(qt_mac_window_for(q));
- } else {
-#ifndef kHIViewFeatureIgnoresClicks
-#define kHIViewFeatureIgnoresClicks kHIViewIgnoresClicks
-#endif
- if(q->testAttribute(Qt::WA_TransparentForMouseEvents))
- HIViewChangeFeatures(qt_mac_nativeview_for(q), kHIViewFeatureIgnoresClicks, 0);
- else
- HIViewChangeFeatures(qt_mac_nativeview_for(q), 0, kHIViewFeatureIgnoresClicks);
- HIViewReshapeStructure(qt_mac_nativeview_for(q));
- }
-#endif
-}
-
-void QWidgetPrivate::macUpdateMetalAttribute()
-{
- Q_Q(QWidget);
- bool realWindow = isRealWindow();
- if (!q->testAttribute(Qt::WA_WState_Created) || !realWindow)
- return;
-
- if (realWindow) {
-#if QT_MAC_USE_COCOA
- // Cocoa doesn't let us change the style mask once it's been changed
- // So, that means we need to recreate the window.
- OSWindowRef cocoaWindow = qt_mac_window_for(q);
- if ([cocoaWindow styleMask] & NSTexturedBackgroundWindowMask)
- return;
- recreateMacWindow();
-#else
- QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q));
- if (q->testAttribute(Qt::WA_MacBrushedMetal)) {
- if (layout)
- layout->updateHIToolBarStatus();
- ChangeWindowAttributes(qt_mac_window_for(q), kWindowMetalAttribute, 0);
- ChangeWindowAttributes(qt_mac_window_for(q), kWindowMetalNoContentSeparatorAttribute, 0);
- } else {
- ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowMetalNoContentSeparatorAttribute);
- ChangeWindowAttributes(qt_mac_window_for(q), 0, kWindowMetalAttribute);
- if (layout)
- layout->updateHIToolBarStatus();
- }
-#endif
- }
-}
-
-void QWidgetPrivate::setEnabled_helper_sys(bool enable)
-{
-#ifdef QT_MAC_USE_COCOA
- Q_Q(QWidget);
- NSView *view = qt_mac_nativeview_for(q);
- if ([view isKindOfClass:[NSControl class]])
- [static_cast<NSControl *>(view) setEnabled:enable];
-#else
- Q_UNUSED(enable);
-#endif
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qwidget_s60.cpp b/src/gui/kernel/qwidget_s60.cpp
deleted file mode 100644
index e28a75a6ab..0000000000
--- a/src/gui/kernel/qwidget_s60.cpp
+++ /dev/null
@@ -1,1450 +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_p.h"
-#include "qdesktopwidget.h"
-#include "qapplication.h"
-#include "qapplication_p.h"
-#include "private/qbackingstore_p.h"
-#include "qevent.h"
-#include "qt_s60_p.h"
-
-#include "qbitmap.h"
-#include "private/qwindowsurface_s60_p.h"
-
-#include <qinputcontext.h>
-
-#ifdef Q_WS_S60
-#include <aknappui.h>
-#include <eikbtgpc.h>
-#endif
-
-// This is necessary in order to be able to perform delayed invocation on slots
-// which take arguments of type WId. One example is
-// QWidgetPrivate::_q_delayedDestroy, which is used to delay destruction of
-// CCoeControl objects until after the CONE event handler has finished running.
-Q_DECLARE_METATYPE(WId)
-
-// Workaround for the fact that S60 SDKs 3.x do not contain the akntoolbar.h
-// header, even though the documentation says that it should be there, and indeed
-// it is present in the library.
-class CAknToolbar : public CAknControl,
- public MCoeControlObserver,
- public MCoeControlBackground,
- public MEikCommandObserver,
- public MAknFadedComponent
-{
-public:
- IMPORT_C void SetToolbarVisibility(const TBool visible);
-};
-
-QT_BEGIN_NAMESPACE
-
-extern bool qt_nograb();
-
-QWidget *QWidgetPrivate::mouseGrabber = 0;
-QWidget *QWidgetPrivate::keyboardGrabber = 0;
-CEikButtonGroupContainer *QS60Data::cba = 0;
-
-int qt_symbian_create_desktop_on_screen = -1;
-
-static bool isEqual(const QList<QAction*>& a, const QList<QAction*>& b)
-{
- if ( a.count() != b.count())
- return false;
- int index=0;
- while (index<a.count()) {
- if (a.at(index)->softKeyRole() != b.at(index)->softKeyRole())
- return false;
- if (a.at(index)->text().compare(b.at(index)->text())!=0)
- return false;
- index++;
- }
- return true;
-}
-
-void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &)
-{
- // Note: based on x11 implementation
-
- static const int XCOORD_MAX = 16383;
- static const int WRECT_MAX = 16383;
-
- Q_Q(QWidget);
-
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
-
- /*
- There are up to four different coordinate systems here:
- Qt coordinate system for this widget.
- Symbian coordinate system for this widget (relative to wrect).
- Qt coordinate system for parent
- Symbian coordinate system for parent (relative to parent's wrect).
- */
-
- QRect validRange(-XCOORD_MAX,-XCOORD_MAX, 2*XCOORD_MAX, 2*XCOORD_MAX);
- QRect wrectRange(-WRECT_MAX,-WRECT_MAX, 2*WRECT_MAX, 2*WRECT_MAX);
- QRect wrect;
- //xrect is the Symbian geometry of my widget. (starts out in parent's Qt coord sys, and ends up in parent's Symbian coord sys)
- QRect xrect = data.crect;
-
- const QWidget *const parent = q->parentWidget();
- QRect parentWRect = parent->data->wrect;
-
- if (parentWRect.isValid()) {
- // parent is clipped, and we have to clip to the same limit as parent
- if (!parentWRect.contains(xrect)) {
- xrect &= parentWRect;
- wrect = xrect;
- //translate from parent's to my Qt coord sys
- wrect.translate(-data.crect.topLeft());
- }
- //translate from parent's Qt coords to parent's X coords
- xrect.translate(-parentWRect.topLeft());
-
- } else {
- // parent is not clipped, we may or may not have to clip
-
- if (data.wrect.isValid() && QRect(QPoint(),data.crect.size()).contains(data.wrect)) {
- // This is where the main optimization is: we are already
- // clipped, and if our clip is still valid, we can just
- // move our window, and do not need to move or clip
- // children
-
- QRect vrect = xrect & parent->rect();
- vrect.translate(-data.crect.topLeft()); //the part of me that's visible through parent, in my Qt coords
- if (data.wrect.contains(vrect)) {
- xrect = data.wrect;
- xrect.translate(data.crect.topLeft());
- if (data.winid)
- data.winid->SetExtent(TPoint(xrect.x(), xrect.y()), TSize(xrect.width(), xrect.height()));
- return;
- }
- }
-
- if (!validRange.contains(xrect)) {
- // we are too big, and must clip
- xrect &=wrectRange;
- wrect = xrect;
- wrect.translate(-data.crect.topLeft());
- //parent's X coord system is equal to parent's Qt coord
- //sys, so we don't need to map xrect.
- }
- }
-
- // unmap if we are outside the valid window system coord system
- bool outsideRange = !xrect.isValid();
- bool mapWindow = false;
- if (q->testAttribute(Qt::WA_OutsideWSRange) != outsideRange) {
- q->setAttribute(Qt::WA_OutsideWSRange, outsideRange);
- if (outsideRange) {
- if (data.winid)
- data.winid->DrawableWindow()->SetVisible(EFalse);
- q->setAttribute(Qt::WA_Mapped, false);
- } else if (!q->isHidden()) {
- mapWindow = true;
- }
- }
-
- if (outsideRange)
- return;
-
- bool jump = (data.wrect != wrect);
- data.wrect = wrect;
-
- // and now recursively for all children...
- for (int i = 0; i < children.size(); ++i) {
- QObject *object = children.at(i);
- if (object->isWidgetType()) {
- QWidget *w = static_cast<QWidget *>(object);
- if (!w->isWindow() && w->testAttribute(Qt::WA_WState_Created))
- w->d_func()->setWSGeometry(jump);
- }
- }
-
- if (data.winid) {
- // move ourselves to the new position and map (if necessary) after
- // the movement. Rationale: moving unmapped windows is much faster
- // than moving mapped windows
- if (!parent->internalWinId())
- xrect.translate(parent->mapTo(q->nativeParentWidget(), QPoint(0, 0)));
-
- data.winid->SetExtent(TPoint(xrect.x(), xrect.y()), TSize(xrect.width(), xrect.height()));
- }
-
- if (mapWindow and !dontShow) {
- q->setAttribute(Qt::WA_Mapped);
- if (q->internalWinId())
- q->internalWinId()->DrawableWindow()->SetVisible(ETrue);
- }
-
- if (jump && data.winid) {
- RWindow *const window = static_cast<RWindow *>(data.winid->DrawableWindow());
- window->Invalidate(TRect(0, 0, wrect.width(), wrect.height()));
- }
-}
-
-void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
-{
- Q_Q(QWidget);
-
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
-
- if ((q->windowType() == Qt::Desktop))
- return;
-
- QPoint oldPos(q->pos());
- QSize oldSize(q->size());
- QRect oldGeom(data.crect);
-
- // Lose maximized status if deliberate resize
- if (w != oldSize.width() || h != oldSize.height())
- data.window_state &= ~Qt::WindowMaximized;
-
- if (extra) { // any size restrictions?
- w = qMin(w,extra->maxw);
- h = qMin(h,extra->maxh);
- w = qMax(w,extra->minw);
- h = qMax(h,extra->minh);
- }
-
- if (q->isWindow())
- topData()->normalGeometry = QRect(0, 0, -1, -1);
- else {
- uint s = data.window_state;
- s &= ~(Qt::WindowMaximized | Qt::WindowFullScreen);
- data.window_state = s;
- }
-
- bool isResize = w != oldSize.width() || h != oldSize.height();
- if (!isMove && !isResize)
- return;
-
- if (q->isWindow()) {
- if (w == 0 || h == 0) {
- q->setAttribute(Qt::WA_OutsideWSRange, true);
- if (q->isVisible() && q->testAttribute(Qt::WA_Mapped))
- hide_sys();
- data.crect = QRect(x, y, w, h);
- data.window_state &= ~Qt::WindowFullScreen;
- } else if (q->isVisible() && q->testAttribute(Qt::WA_OutsideWSRange)) {
- q->setAttribute(Qt::WA_OutsideWSRange, false);
-
- // put the window in its place and show it
- q->internalWinId()->SetRect(TRect(TPoint(x, y), TSize(w, h)));
- data.crect.setRect(x, y, w, h);
- show_sys();
- } else {
- QRect r = QRect(x, y, w, h);
- data.crect = r;
- q->internalWinId()->SetRect(TRect(TPoint(x, y), TSize(w, h)));
- topData()->normalGeometry = data.crect;
- }
- QSymbianControl *window = static_cast<QSymbianControl *>(q->internalWinId());
- window->ensureFixNativeOrientation();
- } else {
- data.crect.setRect(x, y, w, h);
-
- QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
- const bool inTopLevelResize = tlwExtra ? tlwExtra->inTopLevelResize : false;
-
- if (q->isVisible() && (!inTopLevelResize || q->internalWinId())) {
- // Top-level resize optimization does not work for native child widgets;
- // disable it for this particular widget.
- if (inTopLevelResize)
- tlwExtra->inTopLevelResize = false;
- if (!isResize && maybeBackingStore())
- moveRect(QRect(oldPos, oldSize), x - oldPos.x(), y - oldPos.y());
- else
- invalidateBuffer_resizeHelper(oldPos, oldSize);
-
- if (inTopLevelResize)
- tlwExtra->inTopLevelResize = true;
- }
- if (q->testAttribute(Qt::WA_WState_Created))
- setWSGeometry();
- }
-
- if (q->isVisible()) {
- if (isMove && q->pos() != oldPos) {
- QMoveEvent e(q->pos(), oldPos);
- QApplication::sendEvent(q, &e);
- }
- if (isResize) {
- bool slowResize = qgetenv("QT_SLOW_TOPLEVEL_RESIZE").toInt();
- const bool setTopLevelResize = !slowResize && q->isWindow() && extra && extra->topextra
- && !extra->topextra->inTopLevelResize;
- if (setTopLevelResize)
- extra->topextra->inTopLevelResize = true;
- QResizeEvent e(q->size(), oldSize);
- QApplication::sendEvent(q, &e);
- if (!q->testAttribute(Qt::WA_StaticContents) && q->internalWinId())
- q->internalWinId()->DrawDeferred();
- if (setTopLevelResize)
- extra->topextra->inTopLevelResize = false;
- }
- } else {
- if (isMove && q->pos() != oldPos)
- q->setAttribute(Qt::WA_PendingMoveEvent, true);
- if (isResize)
- q->setAttribute(Qt::WA_PendingResizeEvent, true);
- }
-}
-
-void QWidgetPrivate::create_sys(WId window, bool /* initializeWindow */, bool destroyOldWindow)
-{
- Q_Q(QWidget);
-
- Qt::WindowType type = q->windowType();
- Qt::WindowFlags &flags = data.window_flags;
- QWidget *parentWidget = q->parentWidget();
-
- bool topLevel = (flags & Qt::Window);
- bool popup = (type == Qt::Popup);
- bool dialog = (type == Qt::Dialog
- || type == Qt::Sheet
- || (flags & Qt::MSWindowsFixedSizeDialogHint));
- bool desktop = (type == Qt::Desktop);
- //bool tool = (type == Qt::Tool || type == Qt::Drawer);
-
- if (popup)
- flags |= Qt::WindowStaysOnTopHint; // a popup stays on top
-
- TRect clientRect = static_cast<CEikAppUi*>(S60->appUi())->ClientRect();
- int sw = clientRect.Width();
- int sh = clientRect.Height();
-
- if (desktop) {
- symbianScreenNumber = qMax(qt_symbian_create_desktop_on_screen, 0);
- TSize screenSize = S60->screenDevice(symbianScreenNumber)->SizeInPixels();
- data.crect.setRect(0, 0, screenSize.iWidth, screenSize.iHeight);
- q->setAttribute(Qt::WA_DontShowOnScreen);
- } else if (topLevel && !q->testAttribute(Qt::WA_Resized)){
- int width = sw;
- int height = sh;
- if (symbianScreenNumber > 0) {
- TSize screenSize = S60->screenDevice(symbianScreenNumber)->SizeInPixels();
- width = screenSize.iWidth;
- height = screenSize.iHeight;
- }
- if (extra) {
- width = qMax(qMin(width, extra->maxw), extra->minw);
- height = qMax(qMin(height, extra->maxh), extra->minh);
- }
- data.crect.setSize(QSize(width, height));
- }
-
- CCoeControl *const destroyw = destroyOldWindow ? data.winid : 0;
-
- createExtra();
- if (window) {
- setWinId(window);
- TRect tr = window->Rect();
- data.crect.setRect(tr.iTl.iX, tr.iTl.iY, tr.Width(), tr.Height());
-
- } else if (topLevel) {
- if (!q->testAttribute(Qt::WA_Moved) && !q->testAttribute(Qt::WA_DontShowOnScreen))
- data.crect.moveTopLeft(QPoint(clientRect.iTl.iX, clientRect.iTl.iY));
-
- QScopedPointer<QSymbianControl> control( new QSymbianControl(q) );
- Q_CHECK_PTR(control);
-
- QT_TRAP_THROWING(control->ConstructL(true, desktop));
- control->SetMopParent(static_cast<CEikAppUi*>(S60->appUi()));
-
- // Symbian windows are always created in an inactive state
- // We perform this assignment for the case where the window is being re-created
- // as a result of a call to setParent_sys, on either this widget or one of its
- // ancestors.
- extra->activated = 0;
-
- if (!desktop) {
- TInt stackingFlags;
- if ((q->windowType() & Qt::Popup) == Qt::Popup) {
- stackingFlags = ECoeStackFlagRefusesAllKeys | ECoeStackFlagRefusesFocus;
- } else {
- stackingFlags = ECoeStackFlagStandard;
- }
- control->MakeVisible(false);
- QT_TRAP_THROWING(control->ControlEnv()->AppUi()->AddToStackL(control.data(), ECoeStackPriorityDefault, stackingFlags));
- // Avoid keyboard focus to a hidden window.
- control->setFocusSafely(false);
-
- RDrawableWindow *const drawableWindow = control->DrawableWindow();
- // Request mouse move events.
- drawableWindow->PointerFilter(EPointerFilterEnterExit
- | EPointerFilterMove | EPointerFilterDrag, 0);
- drawableWindow->EnableVisibilityChangeEvents();
-
- }
-
- q->setAttribute(Qt::WA_WState_Created);
-
- int x, y, w, h;
- data.crect.getRect(&x, &y, &w, &h);
- control->SetRect(TRect(TPoint(x, y), TSize(w, h)));
-
- // We wait until the control is fully constructed before calling setWinId, because
- // this generates a WinIdChanged event.
- setWinId(control.take());
-
- if (!desktop)
- s60UpdateIsOpaque(); // must be called after setWinId()
-
- } else if (q->testAttribute(Qt::WA_NativeWindow) || paintOnScreen()) { // create native child widget
-
- QScopedPointer<QSymbianControl> control( new QSymbianControl(q) );
- Q_CHECK_PTR(control);
-
- QT_TRAP_THROWING(control->ConstructL(!parentWidget));
-
- // Symbian windows are always created in an inactive state
- // We perform this assignment for the case where the window is being re-created
- // as a result of a call to setParent_sys, on either this widget or one of its
- // ancestors.
- extra->activated = 0;
-
- TInt stackingFlags;
- if ((q->windowType() & Qt::Popup) == Qt::Popup) {
- stackingFlags = ECoeStackFlagRefusesAllKeys | ECoeStackFlagRefusesFocus;
- } else {
- stackingFlags = ECoeStackFlagStandard;
- }
- control->MakeVisible(false);
- QT_TRAP_THROWING(control->ControlEnv()->AppUi()->AddToStackL(control.data(), ECoeStackPriorityDefault, stackingFlags));
- // Avoid keyboard focus to a hidden window.
- control->setFocusSafely(false);
-
- q->setAttribute(Qt::WA_WState_Created);
- int x, y, w, h;
- data.crect.getRect(&x, &y, &w, &h);
- control->SetRect(TRect(TPoint(x, y), TSize(w, h)));
-
- RDrawableWindow *const drawableWindow = control->DrawableWindow();
- // Request mouse move events.
- drawableWindow->PointerFilter(EPointerFilterEnterExit
- | EPointerFilterMove | EPointerFilterDrag, 0);
- drawableWindow->EnableVisibilityChangeEvents();
-
- if (q->isVisible() && q->testAttribute(Qt::WA_Mapped)) {
- activateSymbianWindow(control.data());
- control->MakeVisible(true);
- }
-
- // We wait until the control is fully constructed before calling setWinId, because
- // this generates a WinIdChanged event.
- setWinId(control.take());
- }
-
- if (destroyw) {
- destroyw->ControlEnv()->AppUi()->RemoveFromStack(destroyw);
-
- // Delay deletion of the control in case this function is called in the
- // context of a CONE event handler such as
- // CCoeControl::ProcessPointerEventL
- QMetaObject::invokeMethod(q, "_q_delayedDestroy",
- Qt::QueuedConnection, Q_ARG(WId, destroyw));
- }
-
- if (q->testAttribute(Qt::WA_AcceptTouchEvents))
- registerTouchWindow();
-}
-
-
-void QWidgetPrivate::show_sys()
-{
- Q_Q(QWidget);
-
- if (q->testAttribute(Qt::WA_OutsideWSRange))
- return;
-
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
-
- q->setAttribute(Qt::WA_Mapped);
-
- if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
- invalidateBuffer(q->rect());
- return;
- }
-
- if (q->internalWinId()) {
- if (!extra->activated)
- activateSymbianWindow();
-
- QSymbianControl *id = static_cast<QSymbianControl *>(q->internalWinId());
- const bool isFullscreen = q->windowState() & Qt::WindowFullScreen;
- const TBool cbaRequested = q->windowFlags() & Qt::WindowSoftkeysVisibleHint;
-
-#ifdef Q_WS_S60
- // Lazily initialize the S60 screen furniture when the first window is shown.
- if (q->isWindow() && !QApplication::testAttribute(Qt::AA_S60DontConstructApplicationPanes)
- && !S60->buttonGroupContainer() && !S60->statusPane()) {
-
- if (!q->testAttribute(Qt::WA_DontShowOnScreen)) {
-
- // Create the status pane and CBA here
- CEikAppUi *ui = static_cast<CEikAppUi *>(S60->appUi());
- MEikAppUiFactory *factory = CEikonEnv::Static()->AppUiFactory();
-
- QT_TRAP_THROWING(
- factory->CreateResourceIndependentFurnitureL(ui);
-
- TRect boundingRect = static_cast<CEikAppUi*>(S60->appUi())->ClientRect();
-
- CEikButtonGroupContainer *cba = CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::ECba,
- CEikButtonGroupContainer::EHorizontal,ui,R_AVKON_SOFTKEYS_EMPTY_WITH_IDS);
- if (isFullscreen && !cbaRequested)
- cba->MakeVisible(false);
-
- CEikButtonGroupContainer *oldCba = factory->SwapButtonGroup(cba);
- Q_ASSERT(!oldCba);
- S60->setButtonGroupContainer(cba);
-
- // If the creation of the first widget is delayed, for example by doing it
- // inside the event loop, S60 somehow "forgets" to set the visibility of the
- // toolbar (the three middle softkeys) when you flip the phone over, so we
- // need to do it ourselves to avoid a "hole" in the application, even though
- // Qt itself does not use the toolbar directly..
- CAknAppUi *appui = dynamic_cast<CAknAppUi *>(CEikonEnv::Static()->AppUi());
- if (appui) {
- CAknToolbar *toolbar = appui->PopupToolbar();
- if (toolbar && !toolbar->IsVisible())
- toolbar->SetToolbarVisibility(ETrue);
- }
-
- CEikMenuBar *menuBar = new(ELeave) CEikMenuBar;
- menuBar->ConstructL(ui, 0, R_AVKON_MENUPANE_EMPTY);
- menuBar->SetMenuType(CEikMenuBar::EMenuOptions);
- S60->appUi()->AddToStackL(menuBar,ECoeStackPriorityMenu,ECoeStackFlagRefusesFocus);
-
- CEikMenuBar *oldMenu = factory->SwapMenuBar(menuBar);
- Q_ASSERT(!oldMenu);
- )
-
- if (S60->statusPane()) {
- // Use QDesktopWidget as the status pane observer to proxy for the AppUi.
- // Can't use AppUi directly because it privately inherits from MEikStatusPaneObserver.
- QSymbianControl *desktopControl = static_cast<QSymbianControl *>(QApplication::desktop()->winId());
- S60->statusPane()->SetObserver(desktopControl);
- if (isFullscreen) {
- const bool cbaVisible = S60->buttonGroupContainer() && S60->buttonGroupContainer()->IsVisible();
- S60->setStatusPaneAndButtonGroupVisibility(false, cbaVisible);
- }
- }
- }
- }
-#endif
-
- // Fill client area if maximized OR
- // Put window below status pane unless the window has an explicit position.
- if (!isFullscreen) {
- if (q->windowState() & Qt::WindowMaximized) {
- TRect r = static_cast<CEikAppUi*>(S60->appUi())->ClientRect();
- id->SetExtent(r.iTl, r.Size());
- } else if (!q->testAttribute(Qt::WA_Moved) && q->windowType() != Qt::Dialog) {
- id->SetPosition(static_cast<CEikAppUi*>(S60->appUi())->ClientRect().iTl);
- }
- }
-
- id->MakeVisible(true);
-
- if(q->isWindow()&&!q->testAttribute(Qt::WA_ShowWithoutActivating))
- id->setFocusSafely(true);
- }
-
- invalidateBuffer(q->rect());
-}
-
-void QWidgetPrivate::activateSymbianWindow(WId wid)
-{
- Q_Q(QWidget);
-
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- Q_ASSERT(q->testAttribute(Qt::WA_Mapped));
- Q_ASSERT(!extra->activated);
-
- if(!wid)
- wid = q->internalWinId();
-
- Q_ASSERT(wid);
-
- QT_TRAP_THROWING(wid->ActivateL());
- extra->activated = 1;
-}
-
-void QWidgetPrivate::hide_sys()
-{
- Q_Q(QWidget);
-
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- deactivateWidgetCleanup();
- QSymbianControl *id = static_cast<QSymbianControl *>(q->internalWinId());
-
- if (id) {
- //Incorrect optimization - for popup windows, Qt's focus is moved before
- //hide_sys is called, resulting in the popup window keeping its elevated
- //position in the CONE control stack.
- //This can result in keyboard focus being in an invisible widget in some
- //conditions - e.g. QTBUG-4733
- //if(id->IsFocused()) // Avoid unnecessary calls to FocusChanged()
- id->setFocusSafely(false);
- id->MakeVisible(false);
- if (QWidgetBackingStore *bs = maybeBackingStore())
- bs->releaseBuffer();
- } else {
- invalidateBuffer(q->rect());
- }
-
- q->setAttribute(Qt::WA_Mapped, false);
-}
-
-void QWidgetPrivate::setFocus_sys()
-{
- Q_Q(QWidget);
- if (q->testAttribute(Qt::WA_WState_Created) && q->window()->windowType() != Qt::Popup)
- if (!q->effectiveWinId()->IsFocused()) // Avoid unnecessry calls to FocusChanged()
- static_cast<QSymbianControl *>(q->effectiveWinId())->setFocusSafely(true);
-}
-
-void QWidgetPrivate::raise_sys()
-{
- Q_Q(QWidget);
-
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- if (q->internalWinId()) {
- q->internalWinId()->DrawableWindow()->SetOrdinalPosition(0);
-
- // If toplevel widget, raise app to foreground
- if (q->isWindow())
- S60->wsSession().SetWindowGroupOrdinalPosition(S60->windowGroup(q).Identifier(), 0);
- }
-}
-
-void QWidgetPrivate::lower_sys()
-{
- Q_Q(QWidget);
-
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- if (q->internalWinId()) {
- // If toplevel widget, lower app to background
- if (q->isWindow())
- S60->wsSession().SetWindowGroupOrdinalPosition(S60->windowGroup(q).Identifier(), -1);
- else
- q->internalWinId()->DrawableWindow()->SetOrdinalPosition(-1);
- }
-
- if (!q->isWindow())
- invalidateBuffer(q->rect());
-}
-
-void QWidgetPrivate::setModal_sys()
-{
-
-}
-
-void QWidgetPrivate::stackUnder_sys(QWidget* w)
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
-
- if (q->internalWinId() && w->internalWinId()) {
- RDrawableWindow *const thisWindow = q->internalWinId()->DrawableWindow();
- RDrawableWindow *const otherWindow = w->internalWinId()->DrawableWindow();
- thisWindow->SetOrdinalPosition(otherWindow->OrdinalPosition() + 1);
- }
-
- if (!q->isWindow() || !w->internalWinId())
- invalidateBuffer(q->rect());
-}
-
-void QWidgetPrivate::reparentChildren()
-{
- Q_Q(QWidget);
-
- QObjectList chlist = q->children();
- for (int i = 0; i < chlist.size(); ++i) { // reparent children
- QObject *obj = chlist.at(i);
- if (obj->isWidgetType()) {
- QWidget *w = (QWidget *)obj;
- if (!w->testAttribute(Qt::WA_WState_Created))
- continue;
- if (!w->isWindow()) {
- w->d_func()->invalidateBuffer(w->rect());
- WId parent = q->effectiveWinId();
- WId child = w->effectiveWinId();
- if (parent != child) {
- // Child widget is native. Because Symbian windows cannot be
- // re-parented, we must re-create the window.
- const WId window = 0;
- const bool initializeWindow = false;
- const bool destroyOldWindow = true;
- w->d_func()->create_sys(window, initializeWindow, destroyOldWindow);
- }
- // ### TODO: We probably also need to update the component array here
- w->d_func()->reparentChildren();
- } else {
- bool showIt = w->isVisible();
- QPoint old_pos = w->pos();
- w->setParent(q, w->windowFlags());
- w->move(old_pos);
- if (showIt)
- w->show();
- }
- }
- }
-}
-
-void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
-{
- Q_Q(QWidget);
-
- if (parent && parent->windowType() == Qt::Desktop) {
- symbianScreenNumber = qt_widget_private(parent)->symbianScreenNumber;
- parent = 0;
- }
-
- bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
-
- if (q->isVisible() && q->parentWidget() && parent != q->parentWidget())
- q->parentWidget()->d_func()->invalidateBuffer(q->geometry());
-
- if (q->testAttribute(Qt::WA_DropSiteRegistered))
- q->setAttribute(Qt::WA_DropSiteRegistered, false);
-
- QSymbianControl *old_winid = static_cast<QSymbianControl *>(wasCreated ? data.winid : 0);
- if ((q->windowType() == Qt::Desktop))
- old_winid = 0;
-
- // old_winid may not have received a 'not visible' visibility
- // changed event before being destroyed; make sure that it is
- // removed from the backing store's list of visible windows.
- if (old_winid)
- S60->controlVisibilityChanged(old_winid, false);
-
- setWinId(0);
-
- // hide and reparent our own window away. Otherwise we might get
- // destroyed when emitting the child remove event below. See QWorkspace.
- if (wasCreated && old_winid) {
- old_winid->MakeVisible(false);
- if (old_winid->IsFocused()) // Avoid unnecessary calls to FocusChanged()
- old_winid->setFocusSafely(false);
- old_winid->SetParent(0);
- }
-
- QObjectPrivate::setParent_helper(parent);
- bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
-
- data.window_flags = f;
- data.fstrut_dirty = true;
- q->setAttribute(Qt::WA_WState_Created, false);
- q->setAttribute(Qt::WA_WState_Visible, false);
- q->setAttribute(Qt::WA_WState_Hidden, false);
- adjustFlags(data.window_flags, q);
- // keep compatibility with previous versions, we need to preserve the created state
- // (but we recreate the winId for the widget being reparented, again for compatibility)
- if (wasCreated || (!q->isWindow() && parent->testAttribute(Qt::WA_WState_Created)))
- createWinId();
- if (q->isWindow() || (!parent || parent->isVisible()) || explicitlyHidden)
- q->setAttribute(Qt::WA_WState_Hidden);
- q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden);
-
- if (wasCreated)
- reparentChildren();
-
- if (old_winid) {
- CBase::Delete(old_winid);
- }
-
- if (q->testAttribute(Qt::WA_AcceptDrops)
- || (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_DropSiteRegistered)))
- q->setAttribute(Qt::WA_DropSiteRegistered, true);
-
- invalidateBuffer(q->rect());
-}
-
-void QWidgetPrivate::setConstraints_sys()
-{
-
-}
-
-
-void QWidgetPrivate::s60UpdateIsOpaque()
-{
- Q_Q(QWidget);
-
- if (!q->testAttribute(Qt::WA_WState_Created))
- return;
-
- const bool writeAlpha = extraData()->nativePaintMode == QWExtra::BlitWriteAlpha;
- if (!q->testAttribute(Qt::WA_TranslucentBackground) && !writeAlpha)
- return;
- const bool requireAlphaChannel = !isOpaque || writeAlpha;
-
- createTLExtra();
-
- RWindow *const window = static_cast<RWindow *>(q->effectiveWinId()->DrawableWindow());
-
-#ifdef Q_SYMBIAN_SEMITRANSPARENT_BG_SURFACE
- if (QApplicationPrivate::instance()->useTranslucentEGLSurfaces) {
- window->SetSurfaceTransparency(!isOpaque);
- extra->topextra->nativeWindowTransparencyEnabled = !isOpaque;
- return;
- }
-#endif
- if (requireAlphaChannel) {
- const TDisplayMode displayMode = static_cast<TDisplayMode>(window->SetRequiredDisplayMode(EColor16MA));
- if (window->SetTransparencyAlphaChannel() == KErrNone) {
- window->SetBackgroundColor(TRgb(255, 255, 255, 0));
- extra->topextra->nativeWindowTransparencyEnabled = 1;
- if (extra->topextra->backingStore.data() && (
- QApplicationPrivate::graphics_system_name == QLatin1String("openvg")
- || QApplicationPrivate::graphics_system_name == QLatin1String("opengl"))) {
- // Semi-transparent EGL surfaces aren't supported. We need to
- // recreate backing store to get translucent surface (raster surface).
- extra->topextra->backingStore.create(q);
- extra->topextra->backingStore.registerWidget(q);
- // FixNativeOrientation() will not work without an EGL surface.
- q->setAttribute(Qt::WA_SymbianNoSystemRotation, false);
- }
- }
- } else if (extra->topextra->nativeWindowTransparencyEnabled) {
- window->SetTransparentRegion(TRegionFix<1>());
- extra->topextra->nativeWindowTransparencyEnabled = 0;
- }
-}
-
-void QWidgetPrivate::setWindowIcon_sys(bool forceReset)
-{
-#ifdef Q_WS_S60
- Q_Q(QWidget);
-
- if (!q->testAttribute(Qt::WA_WState_Created) || !q->isWindow() )
- return;
-
- QTLWExtra* topData = this->topData();
- if (topData->iconPixmap && !forceReset)
- // already been set
- return;
-
- TRect cPaneRect;
- TBool found = AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EContextPane, cPaneRect );
- CAknContextPane* contextPane = S60->contextPane();
- if (found && contextPane) { // We have context pane with valid metrics
- QIcon icon = q->windowIcon();
- if (!icon.isNull()) {
- // Valid icon -> set it as an context pane picture
- QSize size = icon.actualSize(QSize(cPaneRect.Size().iWidth, cPaneRect.Size().iHeight));
- QPixmap pm = icon.pixmap(size);
- QBitmap mask = pm.mask();
- if (mask.isNull()) {
- mask = QBitmap(pm.size());
- mask.fill(Qt::color1);
- }
-
- CFbsBitmap* nBitmap = pm.toSymbianCFbsBitmap();
- CFbsBitmap* nMask = mask.toSymbianCFbsBitmap();
- contextPane->SetPicture(nBitmap,nMask);
- } else {
- // Icon set to null -> set context pane picture to default
- QT_TRAP_THROWING(contextPane->SetPictureToDefaultL());
- }
- } else {
- // Context pane does not exist, try setting small icon to title pane
- TRect titlePaneRect;
- TBool found = AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::ETitlePane, titlePaneRect );
- CAknTitlePane* titlePane = S60->titlePane();
- if (found && titlePane) { // We have title pane with valid metrics
- // The API to get title_pane graphics size is not public -> assume square space based
- // on titlebar font height. CAknBitmap would be optimum, wihtout setting the size, since
- // then title pane would automatically scale the bitmap. Unfortunately it is not public API
- // Also this function is leaving, although it is not named as such.
- const CFont * font;
- QT_TRAP_THROWING(font = AknLayoutUtils::FontFromId(EAknLogicalFontTitleFont));
- TSize iconSize(font->HeightInPixels(), font->HeightInPixels());
-
- QIcon icon = q->windowIcon();
- if (!icon.isNull()) {
- // Valid icon -> set it as an title pane small picture
- QSize size = icon.actualSize(QSize(iconSize.iWidth, iconSize.iHeight));
- QPixmap pm = icon.pixmap(size);
- QBitmap mask = pm.mask();
- if (mask.isNull()) {
- mask = QBitmap(pm.size());
- mask.fill(Qt::color1);
- }
-
- CFbsBitmap* nBitmap = pm.toSymbianCFbsBitmap();
- CFbsBitmap* nMask = mask.toSymbianCFbsBitmap();
- titlePane->SetSmallPicture( nBitmap, nMask, ETrue );
- } else {
- // Icon set to null -> set context pane picture to default
- titlePane->SetSmallPicture( NULL, NULL, EFalse );
- }
- }
- }
-
-#else
- Q_UNUSED(forceReset)
-#endif
-}
-
-void QWidgetPrivate::setWindowTitle_sys(const QString &caption)
-{
-#ifdef Q_WS_S60
- Q_Q(QWidget);
- if (q->isWindow()) {
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- CAknTitlePane* titlePane = S60->titlePane();
- if (titlePane) {
- if (caption.isEmpty()) {
- QT_TRAP_THROWING(titlePane->SetTextToDefaultL());
- } else {
- QT_TRAP_THROWING(titlePane->SetTextL(qt_QString2TPtrC(caption)));
- }
- }
- }
-#else
- Q_UNUSED(caption)
-#endif
-}
-
-void QWidgetPrivate::setWindowIconText_sys(const QString & /*iconText */)
-{
-
-}
-
-void QWidgetPrivate::scroll_sys(int dx, int dy)
-{
- Q_Q(QWidget);
-
- scrollChildren(dx, dy);
- if (!paintOnScreen() || !q->internalWinId() || !q->internalWinId()->OwnsWindow()) {
- scrollRect(q->rect(), dx, dy);
- } else {
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- RDrawableWindow *const window = q->internalWinId()->DrawableWindow();
- window->Scroll(TPoint(dx, dy));
- }
-}
-
-void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r)
-{
- Q_Q(QWidget);
-
- if (!paintOnScreen() || !q->internalWinId() || !q->internalWinId()->OwnsWindow()) {
- scrollRect(r, dx, dy);
- } else {
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- RDrawableWindow *const window = q->internalWinId()->DrawableWindow();
- window->Scroll(TPoint(dx, dy), qt_QRect2TRect(r));
- }
-}
-
-/*!
- For this function to work in the emulator, you must add:
- TRANSPARENCY
- To a line in the wsini.ini file.
-*/
-void QWidgetPrivate::setWindowOpacity_sys(qreal)
-{
- // ### TODO: Implement uniform window transparency
-}
-
-void QWidgetPrivate::updateFrameStrut()
-{
-
-}
-
-void QWidgetPrivate::updateSystemBackground()
-{
-
-}
-
-void QWidgetPrivate::registerDropSite(bool /* on */)
-{
-
-}
-
-void QWidgetPrivate::createTLSysExtra()
-{
- extra->topextra->inExpose = 0;
- extra->topextra->nativeWindowTransparencyEnabled = 0;
-}
-
-void QWidgetPrivate::deleteTLSysExtra()
-{
- extra->topextra->backingStore.destroy();
-}
-
-void QWidgetPrivate::createSysExtra()
-{
- extra->activated = 0;
- extra->nativePaintMode = QWExtra::Default;
- extra->receiveNativePaintEvents = 0;
-}
-
-void QWidgetPrivate::deleteSysExtra()
-{
- // this should only be non-zero if destroy() has not run due to constructor fail
- if (data.winid) {
- data.winid->ControlEnv()->AppUi()->RemoveFromStack(data.winid);
- delete data.winid;
- data.winid = 0;
- }
-}
-
-QWindowSurface *QWidgetPrivate::createDefaultWindowSurface_sys()
-{
- return new QS60WindowSurface(q_func());
-}
-
-void QWidgetPrivate::setMask_sys(const QRegion& /* region */)
-{
-
-}
-
-void QWidgetPrivate::registerTouchWindow()
-{
-#ifdef QT_SYMBIAN_SUPPORTS_ADVANCED_POINTER
- Q_Q(QWidget);
- if (q->testAttribute(Qt::WA_WState_Created) && q->windowType() != Qt::Desktop) {
- RWindow *rwindow = static_cast<RWindow *>(q->effectiveWinId()->DrawableWindow());
- QSymbianControl *window = static_cast<QSymbianControl *>(q->effectiveWinId());
- //Enabling advanced pointer events for controls that already have active windows causes a panic.
- if (!window->isControlActive())
- rwindow->EnableAdvancedPointers();
- }
-#endif
-}
-
-int QWidget::metric(PaintDeviceMetric m) const
-{
- Q_D(const QWidget);
- int val;
- if (m == PdmWidth) {
- val = data->crect.width();
- } else if (m == PdmHeight) {
- val = data->crect.height();
- } else {
- CWsScreenDevice *scr = S60->screenDevice(this);
- switch(m) {
- case PdmDpiX:
- case PdmPhysicalDpiX:
- if (d->extra && d->extra->customDpiX) {
- val = d->extra->customDpiX;
- } else {
- const QWidgetPrivate *p = d;
- while (p->parent) {
- p = static_cast<const QWidget *>(p->parent)->d_func();
- if (p->extra && p->extra->customDpiX) {
- val = p->extra->customDpiX;
- break;
- }
- }
- if (p == d || !(p->extra && p->extra->customDpiX))
- val = S60->defaultDpiX;
- }
- break;
- case PdmDpiY:
- case PdmPhysicalDpiY:
- if (d->extra && d->extra->customDpiY) {
- val = d->extra->customDpiY;
- } else {
- const QWidgetPrivate *p = d;
- while (p->parent) {
- p = static_cast<const QWidget *>(p->parent)->d_func();
- if (p->extra && p->extra->customDpiY) {
- val = p->extra->customDpiY;
- break;
- }
- }
- if (p == d || !(p->extra && p->extra->customDpiY))
- val = S60->defaultDpiY;
- }
- break;
- case PdmWidthMM:
- {
- TInt twips = scr->HorizontalPixelsToTwips(data->crect.width());
- val = (int)(twips * (25.4/KTwipsPerInch));
- break;
- }
- case PdmHeightMM:
- {
- TInt twips = scr->VerticalPixelsToTwips(data->crect.height());
- val = (int)(twips * (25.4/KTwipsPerInch));
- break;
- }
- case PdmNumColors:
- val = TDisplayModeUtils::NumDisplayModeColors(scr->DisplayMode());
- break;
- case PdmDepth:
- val = TDisplayModeUtils::NumDisplayModeBitsPerPixel(scr->DisplayMode());
- break;
- default:
- val = 0;
- qWarning("QWidget::metric: Invalid metric command");
- }
- }
- return val;
-}
-
-QPaintEngine *QWidget::paintEngine() const
-{
- return 0;
-}
-
-QPoint QWidget::mapToGlobal(const QPoint &pos) const
-{
- Q_D(const QWidget);
- if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) {
-
- QPoint p = pos + data->crect.topLeft();
- return (isWindow() || !parentWidget()) ? p : parentWidget()->mapToGlobal(p);
-
- } else if ((d->data.window_flags & Qt::Window) && internalWinId()) { //toplevel
- QPoint tp = geometry().topLeft();
- return pos + tp;
- }
-
- // Native window case
- const TPoint widgetScreenOffset = internalWinId()->PositionRelativeToScreen();
- const QPoint globalPos = QPoint(widgetScreenOffset.iX, widgetScreenOffset.iY) + pos;
- return globalPos;
-}
-
-QPoint QWidget::mapFromGlobal(const QPoint &pos) const
-{
- Q_D(const QWidget);
- if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) {
- QPoint p = (isWindow() || !parentWidget()) ? pos : parentWidget()->mapFromGlobal(pos);
- return p - data->crect.topLeft();
- } else if ((d->data.window_flags & Qt::Window) && internalWinId()) { //toplevel
- QPoint tp = geometry().topLeft();
- return pos - tp;
- }
-
- // Native window case
- const TPoint widgetScreenOffset = internalWinId()->PositionRelativeToScreen();
- const QPoint widgetPos = pos - QPoint(widgetScreenOffset.iX, widgetScreenOffset.iY);
- return widgetPos;
-}
-
-static Qt::WindowStates effectiveState(Qt::WindowStates state)
-{
- if (state & Qt::WindowMinimized)
- return Qt::WindowMinimized;
- else if (state & Qt::WindowFullScreen)
- return Qt::WindowFullScreen;
- else if (state & Qt::WindowMaximized)
- return Qt::WindowMaximized;
- return Qt::WindowNoState;
-}
-
-void QWidget::setWindowState(Qt::WindowStates newstate)
-{
- Q_D(QWidget);
-
- Qt::WindowStates oldstate = windowState();
-
- const TBool isFullscreen = newstate & Qt::WindowFullScreen;
-#ifdef Q_WS_S60
- const TBool cbaRequested = windowFlags() & Qt::WindowSoftkeysVisibleHint;
- const TBool cbaVisible = CEikButtonGroupContainer::Current() ? true : false;
- const TBool softkeyVisibilityChange = isFullscreen && (cbaRequested != cbaVisible);
-
- if (oldstate == newstate && !softkeyVisibilityChange)
- return;
-#endif // Q_WS_S60
-
- if (isWindow()) {
- createWinId();
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
-
- const bool wasResized = testAttribute(Qt::WA_Resized);
- const bool wasMoved = testAttribute(Qt::WA_Moved);
-
- QSymbianControl *window = static_cast<QSymbianControl *>(effectiveWinId());
- if (window && newstate & Qt::WindowMinimized) {
- window->setFocusSafely(false);
- window->MakeVisible(false);
- } else if (window && oldstate & Qt::WindowMinimized) {
- window->setFocusSafely(true);
- window->MakeVisible(true);
- }
-
-#ifdef Q_WS_S60
- // The window decoration visibility has to be changed before doing actual window state
- // change since in that order the availableGeometry will return directly the right size and
- // we will avoid unnecessary redraws
- bool decorationsVisible = S60->setRecursiveDecorationsVisibility(this, newstate);
-#endif // Q_WS_S60
-
- // Ensure the initial size is valid, since we store it as normalGeometry below.
- if (!wasResized && !isVisible())
- adjustSize();
-
- QTLWExtra *top = d->topData();
- QRect normalGeometry = (top->normalGeometry.width() < 0) ? geometry() : top->normalGeometry;
-
- const bool cbaVisibilityHint = windowFlags() & Qt::WindowSoftkeysVisibleHint;
- if (newstate & Qt::WindowFullScreen && !cbaVisibilityHint) {
- setAttribute(Qt::WA_OutsideWSRange, false);
- if (d->symbianScreenNumber > 0) {
- int w = S60->screenWidthInPixelsForScreen[d->symbianScreenNumber];
- int h = S60->screenHeightInPixelsForScreen[d->symbianScreenNumber];
- if (w <= 0 || h <= 0)
- window->SetExtentToWholeScreen();
- else
- window->SetExtent(TPoint(0, 0), TSize(w, h));
- } else {
- window->SetExtentToWholeScreen();
- }
- } else if (newstate & Qt::WindowMaximized || ((newstate & Qt::WindowFullScreen) && cbaVisibilityHint)) {
- setAttribute(Qt::WA_OutsideWSRange, false);
- TRect maxExtent = qt_QRect2TRect(qApp->desktop()->availableGeometry(this));
- window->SetExtent(maxExtent.iTl, maxExtent.Size());
- } else {
-#ifdef Q_WS_S60
- // With delayed creation of S60 app panes, the normalGeometry calculated above is not
- // accurate because it did not consider the status pane. This means that when returning
- // normal mode after showing the status pane, the geometry would overlap so we should
- // move it if it never had an explicit position.
- if (!wasMoved && S60->statusPane() && decorationsVisible) {
- TPoint tl = static_cast<CEikAppUi*>(S60->appUi())->ClientRect().iTl;
- normalGeometry.setTopLeft(QPoint(tl.iX, tl.iY));
- }
-#endif
- setGeometry(normalGeometry);
- }
-
- //restore normal geometry
- top->normalGeometry = normalGeometry;
-
- // FixMe QTBUG-8977
- // In some platforms, WA_Resized and WA_Moved are also not set when application window state is
- // anything else than normal. In Symbian we can restore them only for normal window state since
- // restoring for other modes, will make fluidlauncher to be launched in wrong size (200x100)
- if (effectiveState(newstate) == Qt::WindowNoState) {
- setAttribute(Qt::WA_Resized, wasResized);
- setAttribute(Qt::WA_Moved, wasMoved);
- }
- }
-
- data->window_state = newstate;
-
- if (newstate & Qt::WindowActive)
- activateWindow();
-
- if (isWindow()) {
- // Now that the new state is set, fix the display memory layout, if needed.
- QSymbianControl *window = static_cast<QSymbianControl *>(effectiveWinId());
- window->ensureFixNativeOrientation();
- }
-
- QWindowStateChangeEvent e(oldstate);
- QApplication::sendEvent(this, &e);
-}
-
-
-void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
-{
- Q_D(QWidget);
- d->aboutToDestroy();
- if (!isWindow() && parentWidget())
- parentWidget()->d_func()->invalidateBuffer(geometry());
- d->deactivateWidgetCleanup();
- QSymbianControl *id = static_cast<QSymbianControl *>(internalWinId());
- if (testAttribute(Qt::WA_WState_Created)) {
-
-#ifndef QT_NO_IM
- if (d->ic) {
- delete d->ic;
- } else {
- QInputContext *ic = QApplicationPrivate::inputContext;
- if (ic) {
- ic->widgetDestroyed(this);
- }
- }
-#endif
-
- if (QWidgetPrivate::mouseGrabber == this)
- releaseMouse();
- if (QWidgetPrivate::keyboardGrabber == this)
- releaseKeyboard();
- setAttribute(Qt::WA_WState_Created, false);
- QObjectList childList = children();
- for (int i = 0; i < childList.size(); ++i) { // destroy all widget children
- register QObject *obj = childList.at(i);
- if (obj->isWidgetType())
- static_cast<QWidget*>(obj)->destroy(destroySubWindows,
- destroySubWindows);
- }
- if (destroyWindow && !(windowType() == Qt::Desktop) && id) {
- if (id->IsFocused()) // Avoid unnecessry calls to FocusChanged()
- id->setFocusSafely(false);
- id->ControlEnv()->AppUi()->RemoveFromStack(id);
- }
- }
-
- QT_TRY {
- d->setWinId(0);
- } QT_CATCH (const std::bad_alloc &) {
- // swallow - destructors must not throw
- }
-
- if (destroyWindow) {
- delete id;
- // At this point the backing store should already be destroyed
- // so we flush the command buffer to ensure that the freeing of
- // those resources and deleting the window can happen "atomically"
- if (qApp)
- S60->wsSession().Flush();
- }
-}
-
-QWidget *QWidget::mouseGrabber()
-{
- return QWidgetPrivate::mouseGrabber;
-}
-
-QWidget *QWidget::keyboardGrabber()
-{
- return QWidgetPrivate::keyboardGrabber;
-}
-
-void QWidget::grabKeyboard()
-{
- if (!qt_nograb()) {
- if (QWidgetPrivate::keyboardGrabber && QWidgetPrivate::keyboardGrabber != this)
- QWidgetPrivate::keyboardGrabber->releaseKeyboard();
-
- // ### TODO: Native keyboard grab
-
- QWidgetPrivate::keyboardGrabber = this;
- }
-}
-
-void QWidget::releaseKeyboard()
-{
- if (!qt_nograb() && QWidgetPrivate::keyboardGrabber == this) {
- // ### TODO: Native keyboard release
- QWidgetPrivate::keyboardGrabber = 0;
- }
-}
-
-void QWidget::grabMouse()
-{
- if (isVisible() && !qt_nograb()) {
- if (QWidgetPrivate::mouseGrabber && QWidgetPrivate::mouseGrabber != this)
- QWidgetPrivate::mouseGrabber->releaseMouse();
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
- WId id = effectiveWinId();
- id->SetPointerCapture(true);
- QWidgetPrivate::mouseGrabber = this;
-
-#ifndef QT_NO_CURSOR
- QApplication::setOverrideCursor(cursor());
-#endif
- }
-}
-
-#ifndef QT_NO_CURSOR
-void QWidget::grabMouse(const QCursor &cursor)
-{
- if (isVisible() && !qt_nograb()) {
- if (QWidgetPrivate::mouseGrabber && QWidgetPrivate::mouseGrabber != this)
- QWidgetPrivate::mouseGrabber->releaseMouse();
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
- WId id = effectiveWinId();
- id->SetPointerCapture(true);
- QWidgetPrivate::mouseGrabber = this;
-
- QApplication::setOverrideCursor(cursor);
- }
-}
-#endif
-
-void QWidget::releaseMouse()
-{
- if (!qt_nograb() && QWidgetPrivate::mouseGrabber == this) {
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
- if(!window()->isModal()) {
- WId id = effectiveWinId();
- id->SetPointerCapture(false);
- }
- QWidgetPrivate::mouseGrabber = 0;
-#ifndef QT_NO_CURSOR
- QApplication::restoreOverrideCursor();
-#endif
- }
-}
-
-void QWidget::activateWindow()
-{
- Q_D(QWidget);
-
- QWidget *tlw = window();
- if (tlw->isVisible()) {
- window()->createWinId();
- QSymbianControl *id = static_cast<QSymbianControl *>(tlw->internalWinId());
- if (!id->IsFocused())
- id->setFocusSafely(true);
- }
-}
-
-#ifndef QT_NO_CURSOR
-
-void QWidgetPrivate::setCursor_sys(const QCursor &cursor)
-{
- Q_UNUSED(cursor);
- Q_Q(QWidget);
- qt_symbian_set_cursor(q, false);
-}
-
-void QWidgetPrivate::unsetCursor_sys()
-{
- Q_Q(QWidget);
- qt_symbian_set_cursor(q, false);
-}
-#endif
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qwidget_win.cpp b/src/gui/kernel/qwidget_win.cpp
deleted file mode 100644
index a02c5ba008..0000000000
--- a/src/gui/kernel/qwidget_win.cpp
+++ /dev/null
@@ -1,2139 +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 "qbitmap.h"
-#include "qcursor.h"
-#include "qdesktopwidget.h"
-#include "qevent.h"
-#include "qimage.h"
-#include "qlayout.h"
-#include "qpainter.h"
-#include "qstack.h"
-#include "qt_windows.h"
-#include "qwidget.h"
-#include "qwidget_p.h"
-#include "private/qbackingstore_p.h"
-#include "private/qwindowsurface_raster_p.h"
-
-#include "qscrollbar.h"
-#include "qabstractscrollarea.h"
-#include <private/qabstractscrollarea_p.h>
-
-#include <qdebug.h>
-
-#include <private/qapplication_p.h>
-#include <private/qwininputcontext_p.h>
-#include <private/qpaintengine_raster_p.h>
-#include <private/qsystemlibrary_p.h>
-
-#if defined(Q_WS_WINCE)
-#include "qguifunctions_wince.h"
-QT_USE_NAMESPACE
-extern void qt_wince_maximize(QWidget *widget); //defined in qguifunctions_wince.cpp
-extern void qt_wince_unmaximize(QWidget *widget); //defined in qguifunctions_wince.cpp
-extern void qt_wince_minimize(HWND hwnd); //defined in qguifunctions_wince.cpp
-extern void qt_wince_full_screen(HWND hwnd, bool fullScreen, UINT swpf); //defined in qguifunctions_wince.cpp
-extern bool qt_wince_is_mobile(); //defined in qguifunctions_wince.cpp
-#endif
-
-typedef BOOL (WINAPI *PtrSetLayeredWindowAttributes)(HWND hwnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
-static PtrSetLayeredWindowAttributes ptrSetLayeredWindowAttributes = 0;
-
-#ifndef QT_NO_DIRECTDRAW
-#include <ddraw.h>
-#include <private/qimage_p.h>
-static IDirectDraw *qt_ddraw_object;
-static IDirectDrawSurface *qt_ddraw_primary;
-#endif
-
-
-
-#if defined(QT_NON_COMMERCIAL)
-#include "qnc_win.h"
-#endif
-
-#if !defined(WS_EX_TOOLWINDOW)
-#define WS_EX_TOOLWINDOW 0x00000080
-#endif
-
-#if !defined(GWLP_WNDPROC)
-#define GWLP_WNDPROC GWL_WNDPROC
-#endif
-
-//#define TABLET_DEBUG
-#define PACKETDATA (PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE \
- | PK_ORIENTATION | PK_CURSOR | PK_Z)
-#define PACKETMODE 0
-#include <wintab.h>
-#include <pktdef.h>
-
-QT_BEGIN_NAMESPACE
-
-typedef HCTX (API *PtrWTOpen)(HWND, LPLOGCONTEXT, BOOL);
-typedef BOOL (API *PtrWTClose)(HCTX);
-typedef UINT (API *PtrWTInfo)(UINT, UINT, LPVOID);
-typedef BOOL (API *PtrWTEnable)(HCTX, BOOL);
-typedef BOOL (API *PtrWTOverlap)(HCTX, BOOL);
-typedef int (API *PtrWTPacketsGet)(HCTX, int, LPVOID);
-typedef BOOL (API *PtrWTGet)(HCTX, LPLOGCONTEXT);
-typedef int (API *PtrWTQueueSizeGet)(HCTX);
-typedef BOOL (API *PtrWTQueueSizeSet)(HCTX, int);
-
-static PtrWTOpen ptrWTOpen = 0;
-static PtrWTClose ptrWTClose = 0;
-static PtrWTInfo ptrWTInfo = 0;
-static PtrWTQueueSizeGet ptrWTQueueSizeGet = 0;
-static PtrWTQueueSizeSet ptrWTQueueSizeSet = 0;
-#ifndef QT_NO_TABLETEVENT
-static void init_wintab_functions();
-static void qt_tablet_init();
-static void qt_tablet_cleanup();
-#endif // QT_NO_TABLETEVENT
-extern HCTX qt_tablet_context;
-extern bool qt_tablet_tilt_support;
-
-static QWidget *qt_tablet_widget = 0;
-QWidget* qt_get_tablet_widget()
-{
- return qt_tablet_widget;
-}
-
-extern bool qt_is_gui_used;
-
-#ifndef QT_NO_TABLETEVENT
-static void init_wintab_functions()
-{
-#if defined(Q_OS_WINCE)
- return;
-#else
- if (!qt_is_gui_used)
- return;
- QSystemLibrary library(QLatin1String("wintab32"));
- ptrWTOpen = (PtrWTOpen)library.resolve("WTOpenW");
- ptrWTInfo = (PtrWTInfo)library.resolve("WTInfoW");
- ptrWTClose = (PtrWTClose)library.resolve("WTClose");
- ptrWTQueueSizeGet = (PtrWTQueueSizeGet)library.resolve("WTQueueSizeGet");
- ptrWTQueueSizeSet = (PtrWTQueueSizeSet)library.resolve("WTQueueSizeSet");
-#endif // Q_OS_WINCE
-}
-
-static void qt_tablet_init()
-{
- static bool firstTime = true;
- if (!firstTime)
- return;
- firstTime = false;
- qt_tablet_widget = new QWidget(0);
- qt_tablet_widget->createWinId();
- qt_tablet_widget->setObjectName(QLatin1String("Qt internal tablet widget"));
- // We don't need this internal widget to appear in QApplication::topLevelWidgets()
- if (QWidgetPrivate::allWidgets)
- QWidgetPrivate::allWidgets->remove(qt_tablet_widget);
- LOGCONTEXT lcMine;
- qAddPostRoutine(qt_tablet_cleanup);
- struct tagAXIS tpOri[3];
- init_wintab_functions();
- if (ptrWTInfo && ptrWTOpen && ptrWTQueueSizeGet && ptrWTQueueSizeSet) {
- // make sure we have WinTab
- if (!ptrWTInfo(0, 0, NULL)) {
-#ifdef TABLET_DEBUG
- qWarning("QWidget: Wintab services not available");
-#endif
- return;
- }
-
- // some tablets don't support tilt, check if it is possible,
- qt_tablet_tilt_support = ptrWTInfo(WTI_DEVICES, DVC_ORIENTATION, &tpOri);
- if (qt_tablet_tilt_support) {
- // check for azimuth and altitude
- qt_tablet_tilt_support = tpOri[0].axResolution && tpOri[1].axResolution;
- }
- // build our context from the default context
- ptrWTInfo(WTI_DEFSYSCTX, 0, &lcMine);
- // Go for the raw coordinates, the tablet event will return good stuff
- lcMine.lcOptions |= CXO_MESSAGES | CXO_CSRMESSAGES;
- lcMine.lcPktData = PACKETDATA;
- lcMine.lcPktMode = PACKETMODE;
- lcMine.lcMoveMask = PACKETDATA;
- lcMine.lcOutOrgX = 0;
- lcMine.lcOutExtX = lcMine.lcInExtX;
- lcMine.lcOutOrgY = 0;
- lcMine.lcOutExtY = -lcMine.lcInExtY;
- qt_tablet_context = ptrWTOpen(qt_tablet_widget->winId(), &lcMine, true);
-#ifdef TABLET_DEBUG
- qDebug("Tablet is %p", qt_tablet_context);
-#endif
- if (!qt_tablet_context) {
-#ifdef TABLET_DEBUG
- qWarning("QWidget: Failed to open the tablet");
-#endif
- return;
- }
- // Set the size of the Packet Queue to the correct size...
- int currSize = ptrWTQueueSizeGet(qt_tablet_context);
- if (!ptrWTQueueSizeSet(qt_tablet_context, QT_TABLET_NPACKETQSIZE)) {
- // Ideally one might want to use a smaller
- // multiple, but for now, since we managed to destroy
- // the existing Q with the previous call, set it back
- // to the other size, which should work. If not,
- // there will be trouble.
- if (!ptrWTQueueSizeSet(qt_tablet_context, currSize)) {
- Q_ASSERT_X(0, "Qt::Internal", "There is no packet queue for"
- " the tablet. The tablet will not work");
- }
- }
- }
-}
-
-static void qt_tablet_cleanup()
-{
- if (ptrWTClose)
- ptrWTClose(qt_tablet_context);
- delete qt_tablet_widget;
- qt_tablet_widget = 0;
-}
-#endif // QT_NO_TABLETEVENT
-
-const QString qt_reg_winclass(QWidget *w); // defined in qapplication_win.cpp
-
-#ifndef QT_NO_DRAGANDDROP
-void qt_olednd_unregister(QWidget* widget, QOleDropTarget *dst); // dnd_win
-QOleDropTarget* qt_olednd_register(QWidget* widget);
-#endif
-
-extern bool qt_nograb();
-extern HRGN qt_win_bitmapToRegion(const QBitmap& bitmap);
-
-static QWidget *mouseGrb = 0;
-static QCursor *mouseGrbCur = 0;
-static QWidget *keyboardGrb = 0;
-static HHOOK journalRec = 0;
-
-extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND, UINT, WPARAM, LPARAM);
-
-#define XCOORD_MAX 16383
-#define WRECT_MAX 16383
-
-/*****************************************************************************
- QWidget member functions
- *****************************************************************************/
-
-#ifndef Q_WS_WINCE
-void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow)
-{
- Q_Q(QWidget);
- static int sw = -1, sh = -1;
-
- Qt::WindowType type = q->windowType();
- Qt::WindowFlags flags = data.window_flags;
-
- bool topLevel = (flags & Qt::Window);
- bool popup = (type == Qt::Popup);
- bool dialog = (type == Qt::Dialog
- || type == Qt::Sheet
- || (flags & Qt::MSWindowsFixedSizeDialogHint));
- bool desktop = (type == Qt::Desktop);
- bool tool = (type == Qt::Tool || type == Qt::Drawer);
-
- HINSTANCE appinst = qWinAppInst();
- HWND parentw, destroyw = 0;
- WId id = 0;
-
- QString windowClassName = qt_reg_winclass(q);
-
- if (!window) // always initialize
- initializeWindow = true;
-
- if (popup)
- flags |= Qt::WindowStaysOnTopHint; // a popup stays on top
-
- if (sw < 0) { // get the (primary) screen size
- sw = GetSystemMetrics(SM_CXSCREEN);
- sh = GetSystemMetrics(SM_CYSCREEN);
- }
-
- if (desktop && !q->testAttribute(Qt::WA_DontShowOnScreen)) { // desktop widget
- popup = false; // force this flags off
- data.crect.setRect(GetSystemMetrics(76 /* SM_XVIRTUALSCREEN */), GetSystemMetrics(77 /* SM_YVIRTUALSCREEN */),
- GetSystemMetrics(78 /* SM_CXVIRTUALSCREEN */), GetSystemMetrics(79 /* SM_CYVIRTUALSCREEN */));
- }
-
- parentw = q->parentWidget() ? q->parentWidget()->effectiveWinId() : 0;
-
- QString title;
- int style = WS_CHILD;
- int exsty = 0;
-
- if (window) {
- style = GetWindowLong(window, GWL_STYLE);
- if (!style)
- qErrnoWarning("QWidget::create: GetWindowLong failed");
- topLevel = false; // #### needed for some IE plugins??
- } else if (popup || (type == Qt::ToolTip) || (type == Qt::SplashScreen)) {
- style = WS_POPUP;
- } else if (topLevel && !desktop) {
- if (flags & Qt::FramelessWindowHint)
- style = WS_POPUP; // no border
- else if (flags & Qt::WindowTitleHint)
- style = WS_OVERLAPPED;
- else
- style = 0;
- }
- if (!desktop) {
- // if (!testAttribute(Qt::WA_PaintUnclipped))
- // ### Commented out for now as it causes some problems, but
- // this should be correct anyway, so dig some more into this
-#ifndef Q_FLATTEN_EXPOSE
- style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN ;
-#endif
- if (topLevel) {
- if ((type == Qt::Window || dialog || tool)) {
- if (!(flags & Qt::FramelessWindowHint)) {
- style |= WS_POPUP;
- if (!(flags & Qt::MSWindowsFixedSizeDialogHint))
- style |= WS_THICKFRAME;
- else
- style |= WS_DLGFRAME;
- }
- if (flags & Qt::WindowTitleHint)
- style |= WS_CAPTION;
- if (flags & Qt::WindowSystemMenuHint)
- style |= WS_SYSMENU;
- if (flags & Qt::WindowMinimizeButtonHint)
- style |= WS_MINIMIZEBOX;
- if (shouldShowMaximizeButton())
- style |= WS_MAXIMIZEBOX;
- if (tool)
- exsty |= WS_EX_TOOLWINDOW;
- if (flags & Qt::WindowContextHelpButtonHint)
- exsty |= WS_EX_CONTEXTHELP;
- } else {
- exsty |= WS_EX_TOOLWINDOW;
- }
- }
- }
-
- if (flags & Qt::WindowTitleHint) {
- title = q->isWindow() ? qAppName() : q->objectName();
- }
-
- // The Qt::WA_WState_Created flag is checked by translateConfigEvent() in
- // qapplication_win.cpp. We switch it off temporarily to avoid move
- // and resize events during creationt
- q->setAttribute(Qt::WA_WState_Created, false);
-
- if (window) { // override the old window
- if (destroyOldWindow)
- destroyw = data.winid;
- id = window;
- setWinId(window);
- LONG res = SetWindowLong(window, GWL_STYLE, style);
- if (!res)
- qErrnoWarning("QWidget::create: Failed to set window style");
-#ifdef _WIN64
- res = SetWindowLongPtr( window, GWLP_WNDPROC, (LONG_PTR)QtWndProc );
-#else
- res = SetWindowLong( window, GWL_WNDPROC, (LONG)QtWndProc );
-#endif
- if (!res)
- qErrnoWarning("QWidget::create: Failed to set window procedure");
- } else if (desktop) { // desktop widget
- id = GetDesktopWindow();
-// QWidget *otherDesktop = QWidget::find(id); // is there another desktop?
-// if (otherDesktop && otherDesktop->testWFlags(Qt::WPaintDesktop)) {
-// otherDesktop->d_func()->setWinId(0); // remove id from widget mapper
-// d->setWinId(id); // make sure otherDesktop is
-// otherDesktop->d_func()->setWinId(id); // found first
-// } else {
- setWinId(id);
-// }
- } else if (topLevel) { // create top-level widget
- if (popup)
- parentw = 0;
-
- const bool wasMoved = q->testAttribute(Qt::WA_Moved);
- int x = wasMoved ? data.crect.left() : CW_USEDEFAULT;
- int y = wasMoved ? data.crect.top() : CW_USEDEFAULT;
- int w = CW_USEDEFAULT;
- int h = CW_USEDEFAULT;
-
- // Adjust for framestrut when needed
- RECT rect = {0,0,0,0};
- bool isVisibleOnScreen = !q->testAttribute(Qt::WA_DontShowOnScreen);
- if (isVisibleOnScreen && AdjustWindowRectEx(&rect, style & ~WS_OVERLAPPED, FALSE, exsty)) {
- QTLWExtra *td = maybeTopData();
- if (wasMoved && (td && !td->posFromMove)) {
- x = data.crect.x() + rect.left;
- y = data.crect.y() + rect.top;
- }
-
- if (q->testAttribute(Qt::WA_Resized)) {
- w = data.crect.width() + (rect.right - rect.left);
- h = data.crect.height() + (rect.bottom - rect.top);
- }
- }
- //update position & initial size of POPUP window
- if (isVisibleOnScreen && topLevel && initializeWindow && (style & WS_POPUP)) {
- if (!q->testAttribute(Qt::WA_Resized)) {
- w = sw/2;
- h = 4*sh/10;
- if (extra) {
- int dx = rect.right - rect.left;
- int dy = rect.bottom - rect.top;
- w = qMin(w, extra->maxw + dx);
- h = qMin(h, extra->maxh + dy);
- w = qMax(w, extra->minw + dx);
- h = qMax(h, extra->minh + dy);
- }
- }
- if (!wasMoved) {
- x = sw/2 - w/2;
- y = sh/2 - h/2;
- }
- }
-
- id = CreateWindowEx(exsty, reinterpret_cast<const wchar_t *>(windowClassName.utf16()),
- reinterpret_cast<const wchar_t *>(title.utf16()), style,
- x, y, w, h,
- parentw, NULL, appinst, NULL);
- if (!id)
- qErrnoWarning("QWidget::create: Failed to create window");
- setWinId(id);
- if ((flags & Qt::WindowStaysOnTopHint) || (type == Qt::ToolTip)) {
- SetWindowPos(id, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
- if (flags & Qt::WindowStaysOnBottomHint)
- qWarning() << "QWidget: Incompatible window flags: the window can't be on top and on bottom at the same time";
- } else if (flags & Qt::WindowStaysOnBottomHint)
- SetWindowPos(id, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
- winUpdateIsOpaque();
- } else if (q->testAttribute(Qt::WA_NativeWindow) || paintOnScreen()) { // create child widget
- id = CreateWindowEx(exsty, reinterpret_cast<const wchar_t *>(windowClassName.utf16()),
- reinterpret_cast<const wchar_t *>(title.utf16()), style,
- data.crect.left(), data.crect.top(), data.crect.width(), data.crect.height(),
- parentw, NULL, appinst, NULL);
- if (!id)
- qErrnoWarning("QWidget::create: Failed to create window");
- SetWindowPos(id, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- setWinId(id);
- }
-
- if (desktop) {
- q->setAttribute(Qt::WA_WState_Visible);
- } else if (topLevel && !q->testAttribute(Qt::WA_DontShowOnScreen)) {
- RECT cr;
- GetClientRect(id, &cr);
- // one cannot trust cr.left and cr.top, use a correction POINT instead
- POINT pt;
- pt.x = 0;
- pt.y = 0;
- ClientToScreen(id, &pt);
-
- if (data.crect.width() == 0 || data.crect.height() == 0) {
- data.crect = QRect(pt.x, pt.y, data.crect.width(), data.crect.height());
- } else {
- data.crect = QRect(QPoint(pt.x, pt.y),
- QPoint(pt.x + cr.right - 1, pt.y + cr.bottom - 1));
- }
-
- if (data.fstrut_dirty) {
- // be nice to activeqt
- updateFrameStrut();
- }
- }
-
- if (topLevel) {
- if (data.window_flags & Qt::CustomizeWindowHint
- && data.window_flags & Qt::WindowTitleHint) {
- HMENU systemMenu = GetSystemMenu((HWND)q->internalWinId(), FALSE);
- if (data.window_flags & Qt::WindowCloseButtonHint)
- EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_ENABLED);
- else
- EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_GRAYED);
- }
- }
-
- q->setAttribute(Qt::WA_WState_Created); // accept move/resize events
- hd = 0; // no display context
-
- if (q->testAttribute(Qt::WA_AcceptTouchEvents))
- registerTouchWindow();
-
- if (window) { // got window from outside
- if (IsWindowVisible(window))
- q->setAttribute(Qt::WA_WState_Visible);
- else
- q->setAttribute(Qt::WA_WState_Visible, false);
- }
-
- if (extra && !extra->mask.isEmpty())
- setMask_sys(extra->mask);
-
-#if defined(QT_NON_COMMERCIAL)
- QT_NC_WIDGET_CREATE
-#endif
-
- if (q->hasFocus() && q->testAttribute(Qt::WA_InputMethodEnabled))
- q->inputContext()->setFocusWidget(q);
-
- if (destroyw) {
- DestroyWindow(destroyw);
- }
-
-#ifndef QT_NO_TABLETEVENT
- if (q != qt_tablet_widget && QWidgetPrivate::mapper)
- qt_tablet_init();
-#endif // QT_NO_TABLETEVENT
-
- if (q->testAttribute(Qt::WA_DropSiteRegistered))
- registerDropSite(true);
-
- if (maybeTopData() && maybeTopData()->opacity != 255)
- q->setWindowOpacity(maybeTopData()->opacity/255.);
-
- if (topLevel && (data.crect.width() == 0 || data.crect.height() == 0)) {
- q->setAttribute(Qt::WA_OutsideWSRange, true);
- }
-
- if (!topLevel && q->testAttribute(Qt::WA_NativeWindow) && q->testAttribute(Qt::WA_Mapped)) {
- Q_ASSERT(q->internalWinId());
- ShowWindow(q->internalWinId(), SW_SHOW);
- }
-}
-
-#endif //Q_WS_WINCE
-
-
-void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
-{
- Q_D(QWidget);
- d->aboutToDestroy();
- if (!isWindow() && parentWidget())
- parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry()));
- d->deactivateWidgetCleanup();
- if (testAttribute(Qt::WA_WState_Created)) {
- setAttribute(Qt::WA_WState_Created, false);
- for(int i = 0; i < d->children.size(); ++i) { // destroy all widget children
- register QObject *obj = d->children.at(i);
- if (obj->isWidgetType())
- ((QWidget*)obj)->destroy(destroySubWindows,
- destroySubWindows);
- }
- if (mouseGrb == this)
- releaseMouse();
- if (keyboardGrb == this)
- releaseKeyboard();
- if (testAttribute(Qt::WA_ShowModal)) // just be sure we leave modal
- QApplicationPrivate::leaveModal(this);
- else if ((windowType() == Qt::Popup))
- qApp->d_func()->closePopup(this);
- if (destroyWindow && !(windowType() == Qt::Desktop) && internalWinId()) {
- DestroyWindow(internalWinId());
- }
-#ifdef Q_WS_WINCE
- if (destroyWindow && (windowType() == Qt::Desktop) && !GetDesktopWindow()) {
- DestroyWindow(internalWinId());
- }
-
-#endif
- QT_TRY {
- d->setWinId(0);
- } QT_CATCH (const std::bad_alloc &) {
- // swallow - destructors must not throw
- }
- }
-}
-
-void QWidgetPrivate::reparentChildren()
-{
- Q_Q(QWidget);
- QObjectList chlist = q->children();
- for(int i = 0; i < chlist.size(); ++i) { // reparent children
- QObject *obj = chlist.at(i);
- if (obj->isWidgetType()) {
- QWidget *w = (QWidget *)obj;
- if ((w->windowType() == Qt::Popup)) {
- ;
- } else if (w->isWindow()) {
- bool showIt = w->isVisible();
- QPoint old_pos = w->pos();
- w->setParent(q, w->windowFlags());
- w->move(old_pos);
- if (showIt)
- w->show();
- } else {
- w->d_func()->invalidateBuffer(w->rect());
- SetParent(w->effectiveWinId(), q->effectiveWinId());
- w->d_func()->reparentChildren();
- }
- }
- }
-}
-
-void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
-{
- Q_Q(QWidget);
- bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
- if (q->isVisible() && q->parentWidget() && parent != q->parentWidget())
- q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
-
- WId old_winid = data.winid;
- // hide and reparent our own window away. Otherwise we might get
- // destroyed when emitting the child remove event below. See QWorkspace.
- if (q->isVisible() && data.winid) {
- ShowWindow(data.winid, SW_HIDE);
- SetParent(data.winid, 0);
- }
- bool dropSiteWasRegistered = false;
- if (q->testAttribute(Qt::WA_DropSiteRegistered)) {
- dropSiteWasRegistered = true;
- q->setAttribute(Qt::WA_DropSiteRegistered, false); // ole dnd unregister (we will register again below)
- }
-
- if ((q->windowType() == Qt::Desktop))
- old_winid = 0;
- setWinId(0);
-
- QObjectPrivate::setParent_helper(parent);
- bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
-
- data.window_flags = f;
- data.fstrut_dirty = true;
- q->setAttribute(Qt::WA_WState_Created, false);
- q->setAttribute(Qt::WA_WState_Visible, false);
- q->setAttribute(Qt::WA_WState_Hidden, false);
- adjustFlags(data.window_flags, q);
- // keep compatibility with previous versions, we need to preserve the created state
- // (but we recreate the winId for the widget being reparented, again for compatibility)
- if (wasCreated || (!q->isWindow() && parent->testAttribute(Qt::WA_WState_Created)))
- createWinId();
- if (q->isWindow() || (!parent || parent->isVisible()) || explicitlyHidden)
- q->setAttribute(Qt::WA_WState_Hidden);
- q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden);
-
- if (wasCreated) {
- reparentChildren();
- }
-
- if (extra && !extra->mask.isEmpty()) {
- QRegion r = extra->mask;
- extra->mask = QRegion();
- q->setMask(r);
- }
- if (extra && extra->topextra && !extra->topextra->caption.isEmpty()) {
- setWindowIcon_sys(true);
- setWindowTitle_helper(extra->topextra->caption);
- }
- if (old_winid)
- DestroyWindow(old_winid);
-
- if (q->testAttribute(Qt::WA_AcceptDrops) || dropSiteWasRegistered
- || (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_DropSiteRegistered)))
- q->setAttribute(Qt::WA_DropSiteRegistered, true);
-
-#ifdef Q_WS_WINCE
- // Show borderless toplevel windows in tasklist & NavBar
- if (!parent) {
- QString txt = q->windowTitle().isEmpty()?qAppName():q->windowTitle();
- SetWindowText(q->internalWinId(), (wchar_t*)txt.utf16());
- }
-#endif
- invalidateBuffer(q->rect());
-}
-
-
-QPoint QWidget::mapToGlobal(const QPoint &pos) const
-{
- Q_D(const QWidget);
- QWidget *parentWindow = window();
- QWExtra *extra = parentWindow->d_func()->extra;
- if (!isVisible() || parentWindow->isMinimized() || !testAttribute(Qt::WA_WState_Created) || !internalWinId()
- || (extra
-#ifndef QT_NO_GRAPHICSVIEW
- && extra->proxyWidget
-#endif //QT_NO_GRAPHICSVIEW
- )) {
- if (extra && extra->topextra && extra->topextra->embedded) {
- QPoint pt = mapTo(parentWindow, pos);
- POINT p = {pt.x(), pt.y()};
- ClientToScreen(parentWindow->effectiveWinId(), &p);
- return QPoint(p.x, p.y);
- } else {
- QPoint toGlobal = mapTo(parentWindow, pos) + parentWindow->pos();
- // Adjust for window decorations
- toGlobal += parentWindow->geometry().topLeft() - parentWindow->frameGeometry().topLeft();
- return toGlobal;
- }
- }
- POINT p;
- QPoint tmp = d->mapToWS(pos);
- p.x = tmp.x();
- p.y = tmp.y();
- ClientToScreen(internalWinId(), &p);
- return QPoint(p.x, p.y);
-}
-
-QPoint QWidget::mapFromGlobal(const QPoint &pos) const
-{
- Q_D(const QWidget);
- QWidget *parentWindow = window();
- QWExtra *extra = parentWindow->d_func()->extra;
- if (!isVisible() || parentWindow->isMinimized() || !testAttribute(Qt::WA_WState_Created) || !internalWinId()
- || (extra
-#ifndef QT_NO_GRAPHICSVIEW
- && extra->proxyWidget
-#endif //QT_NO_GRAPHICSVIEW
- )) {
- if (extra && extra->topextra && extra->topextra->embedded) {
- POINT p = {pos.x(), pos.y()};
- ScreenToClient(parentWindow->effectiveWinId(), &p);
- return mapFrom(parentWindow, QPoint(p.x, p.y));
- } else {
- QPoint fromGlobal = mapFrom(parentWindow, pos - parentWindow->pos());
- // Adjust for window decorations
- fromGlobal -= parentWindow->geometry().topLeft() - parentWindow->frameGeometry().topLeft();
- return fromGlobal;
- }
- }
- POINT p;
- p.x = pos.x();
- p.y = pos.y();
- ScreenToClient(internalWinId(), &p);
- return d->mapFromWS(QPoint(p.x, p.y));
-}
-
-void QWidgetPrivate::updateSystemBackground() {}
-
-#ifndef QT_NO_CURSOR
-void QWidgetPrivate::setCursor_sys(const QCursor &cursor)
-{
- Q_UNUSED(cursor);
- Q_Q(QWidget);
- qt_win_set_cursor(q, false);
-}
-
-void QWidgetPrivate::unsetCursor_sys()
-{
- Q_Q(QWidget);
- qt_win_set_cursor(q, false);
-}
-#endif
-
-void QWidgetPrivate::setWindowTitle_sys(const QString &caption)
-{
- Q_Q(QWidget);
- if (!q->isWindow())
- return;
-
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- SetWindowText(q->internalWinId(), (wchar_t*)caption.utf16());
-}
-
-HICON qt_createIcon(QIcon icon, int xSize, int ySize, QPixmap **cache)
-{
- HICON result = 0;
- if (!icon.isNull()) { // valid icon
- QSize size = icon.actualSize(QSize(xSize, ySize));
- QPixmap pm = icon.pixmap(size);
- if (pm.isNull())
- return 0;
-
- result = pm.toWinHICON();
-
- if (cache) {
- delete *cache;
- *cache = new QPixmap(pm);;
- }
- }
- return result;
-}
-
-void QWidgetPrivate::setWindowIcon_sys(bool forceReset)
-{
- Q_Q(QWidget);
- if (!q->testAttribute(Qt::WA_WState_Created) || !q->isWindow())
- return;
- QTLWExtra* x = topData();
- if (x->iconPixmap && !forceReset)
- // already been set
- return;
-
- if (x->winIconBig) {
- DestroyIcon(x->winIconBig);
- x->winIconBig = 0;
- }
- if (x->winIconSmall) {
- DestroyIcon(x->winIconSmall);
- x->winIconSmall = 0;
- }
-
- x->winIconSmall = qt_createIcon(q->windowIcon(),
- GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
- &(x->iconPixmap));
- x->winIconBig = qt_createIcon(q->windowIcon(),
- GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
- &(x->iconPixmap));
- if (x->winIconBig) {
- SendMessage(q->internalWinId(), WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)x->winIconSmall);
- SendMessage(q->internalWinId(), WM_SETICON, 1 /* ICON_BIG */, (LPARAM)x->winIconBig);
- } else {
- SendMessage(q->internalWinId(), WM_SETICON, 0 /* ICON_SMALL */, (LPARAM)x->winIconSmall);
- SendMessage(q->internalWinId(), WM_SETICON, 1 /* ICON_BIG */, (LPARAM)x->winIconSmall);
- }
-}
-
-
-void QWidgetPrivate::setWindowIconText_sys(const QString &iconText)
-{
- Q_UNUSED(iconText);
-}
-
-
-QCursor *qt_grab_cursor()
-{
- return mouseGrbCur;
-}
-
-// The procedure does nothing, but is required for mousegrabbing to work
-#ifndef Q_WS_WINCE
-LRESULT QT_WIN_CALLBACK qJournalRecordProc(int nCode, WPARAM wParam, LPARAM lParam)
-{
- return CallNextHookEx(journalRec, nCode, wParam, lParam);
-}
-#endif //Q_WS_WINCE
-
-/* Works only as long as pointer is inside the application's window,
- which is good enough for QDockWidget.
-
- Doesn't call SetWindowsHookEx() - this function causes a system-wide
- freeze if any other app on the system installs a hook and fails to
- process events. */
-void QWidgetPrivate::grabMouseWhileInWindow()
-{
- Q_Q(QWidget);
- if (!qt_nograb()) {
- if (mouseGrb)
- mouseGrb->releaseMouse();
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- SetCapture(q->effectiveWinId());
- mouseGrb = q;
-#ifndef QT_NO_CURSOR
- mouseGrbCur = new QCursor(mouseGrb->cursor());
-#endif
- }
-}
-
-#ifndef Q_WS_WINCE
-void QWidget::grabMouse()
-{
- if (!qt_nograb()) {
- if (mouseGrb)
- mouseGrb->releaseMouse();
- journalRec = SetWindowsHookEx(WH_JOURNALRECORD, (HOOKPROC)qJournalRecordProc, GetModuleHandle(0), 0);
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
- SetCapture(effectiveWinId());
- mouseGrb = this;
-#ifndef QT_NO_CURSOR
- mouseGrbCur = new QCursor(mouseGrb->cursor());
-#endif
- }
-}
-
-#ifndef QT_NO_CURSOR
-void QWidget::grabMouse(const QCursor &cursor)
-{
- if (!qt_nograb()) {
- if (mouseGrb)
- mouseGrb->releaseMouse();
- journalRec = SetWindowsHookEx(WH_JOURNALRECORD, (HOOKPROC)qJournalRecordProc, GetModuleHandle(0), 0);
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
- SetCapture(effectiveWinId());
- mouseGrbCur = new QCursor(cursor);
- SetCursor(mouseGrbCur->handle());
- mouseGrb = this;
- }
-}
-#endif
-
-void QWidget::releaseMouse()
-{
- if (!qt_nograb() && mouseGrb == this) {
- ReleaseCapture();
- if (journalRec) {
- UnhookWindowsHookEx(journalRec);
- journalRec = 0;
- }
- if (mouseGrbCur) {
- delete mouseGrbCur;
- mouseGrbCur = 0;
- }
- mouseGrb = 0;
- }
-}
-#endif
-
-void QWidget::grabKeyboard()
-{
- if (!qt_nograb()) {
- if (keyboardGrb)
- keyboardGrb->releaseKeyboard();
- keyboardGrb = this;
- }
-}
-
-void QWidget::releaseKeyboard()
-{
- if (!qt_nograb() && keyboardGrb == this)
- keyboardGrb = 0;
-}
-
-
-QWidget *QWidget::mouseGrabber()
-{
- return mouseGrb;
-}
-
-QWidget *QWidget::keyboardGrabber()
-{
- return keyboardGrb;
-}
-
-void QWidget::activateWindow()
-{
- window()->createWinId();
- SetForegroundWindow(window()->internalWinId());
-}
-
-#ifndef Q_WS_WINCE
-void QWidget::setWindowState(Qt::WindowStates newstate)
-{
- Q_D(QWidget);
- Qt::WindowStates oldstate = windowState();
- if (oldstate == newstate)
- return;
-
- int max = SW_MAXIMIZE;
- int min = SW_MINIMIZE;
-
- int normal = SW_SHOWNOACTIVATE;
- if (newstate & Qt::WindowActive) {
- max = SW_SHOWMAXIMIZED;
- min = SW_SHOWMINIMIZED;
- normal = SW_SHOWNORMAL;
- }
-
- if (isWindow()) {
- createWinId();
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
-
- // Ensure the initial size is valid, since we store it as normalGeometry below.
- if (!testAttribute(Qt::WA_Resized) && !isVisible())
- adjustSize();
-
- if ((oldstate & Qt::WindowMaximized) != (newstate & Qt::WindowMaximized)) {
- if (newstate & Qt::WindowMaximized && !(oldstate & Qt::WindowFullScreen))
- d->topData()->normalGeometry = geometry();
- if (isVisible() && !(newstate & Qt::WindowMinimized)) {
- ShowWindow(internalWinId(), (newstate & Qt::WindowMaximized) ? max : normal);
- if (!(newstate & Qt::WindowFullScreen)) {
- QRect r = d->topData()->normalGeometry;
- if (!(newstate & Qt::WindowMaximized) && r.width() >= 0) {
- if (pos() != r.topLeft() || size() !=r.size()) {
- d->topData()->normalGeometry = QRect(0,0,-1,-1);
- setGeometry(r);
- }
- }
- } else {
- d->updateFrameStrut();
- }
- }
- }
-
- if ((oldstate & Qt::WindowFullScreen) != (newstate & Qt::WindowFullScreen)) {
- if (newstate & Qt::WindowFullScreen) {
- if (d->topData()->normalGeometry.width() < 0 && !(oldstate & Qt::WindowMaximized))
- d->topData()->normalGeometry = geometry();
- d->topData()->savedFlags = Qt::WindowFlags(GetWindowLong(internalWinId(), GWL_STYLE));
-#ifndef Q_FLATTEN_EXPOSE
- UINT style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP;
-#else
- UINT style = WS_POPUP;
-#endif
- if (ulong(d->topData()->savedFlags) & WS_SYSMENU)
- style |= WS_SYSMENU;
- if (isVisible())
- style |= WS_VISIBLE;
- SetWindowLong(internalWinId(), GWL_STYLE, style);
- QRect r = QApplication::desktop()->screenGeometry(this);
- UINT swpf = SWP_FRAMECHANGED;
- if (newstate & Qt::WindowActive)
- swpf |= SWP_NOACTIVATE;
-
- SetWindowPos(internalWinId(), HWND_TOP, r.left(), r.top(), r.width(), r.height(), swpf);
- d->updateFrameStrut();
- } else {
- UINT style = d->topData()->savedFlags;
- if (isVisible())
- style |= WS_VISIBLE;
- SetWindowLong(internalWinId(), GWL_STYLE, style);
-
- UINT swpf = SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE;
- if (newstate & Qt::WindowActive)
- swpf |= SWP_NOACTIVATE;
- SetWindowPos(internalWinId(), 0, 0, 0, 0, 0, swpf);
- d->updateFrameStrut();
-
- // preserve maximized state
- if (isVisible())
- ShowWindow(internalWinId(), (newstate & Qt::WindowMaximized) ? max : normal);
-
- if (!(newstate & Qt::WindowMaximized)) {
- QRect r = d->topData()->normalGeometry;
- d->topData()->normalGeometry = QRect(0,0,-1,-1);
- if (r.isValid())
- setGeometry(r);
- }
- }
- }
-
- if ((oldstate & Qt::WindowMinimized) != (newstate & Qt::WindowMinimized)) {
- if (isVisible())
- ShowWindow(internalWinId(), (newstate & Qt::WindowMinimized) ? min :
- (newstate & Qt::WindowMaximized) ? max : normal);
- }
- }
- data->window_state = newstate;
- QWindowStateChangeEvent e(oldstate);
- QApplication::sendEvent(this, &e);
-}
-#endif //Q_WS_WINCE
-
-
-/*
- \internal
- Platform-specific part of QWidget::hide().
-*/
-
-void QWidgetPrivate::hide_sys()
-{
- Q_Q(QWidget);
- deactivateWidgetCleanup();
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
-#ifdef Q_WS_WINCE
- if (!qt_wince_is_mobile() && q->isFullScreen()) {
- HWND handle = FindWindow(L"HHTaskBar", L"");
- if (handle) {
- ShowWindow(handle, 1);
- EnableWindow(handle, true);
- }
- }
-#endif
- if (q->windowFlags() != Qt::Desktop) {
- if ((q->windowFlags() & Qt::Popup) && q->internalWinId())
- ShowWindow(q->internalWinId(), SW_HIDE);
- else if (q->internalWinId())
- SetWindowPos(q->internalWinId(),0, 0,0,0,0, SWP_HIDEWINDOW|SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER);
- }
- if (q->isWindow()) {
- if (QWidgetBackingStore *bs = maybeBackingStore())
- bs->releaseBuffer();
- } else {
- invalidateBuffer(q->rect());
- }
- q->setAttribute(Qt::WA_Mapped, false);
-}
-
-
-/*
- \internal
- Platform-specific part of QWidget::show().
-*/
-#ifndef Q_WS_WINCE
-void QWidgetPrivate::show_sys()
-{
- Q_Q(QWidget);
-#if defined(QT_NON_COMMERCIAL)
- QT_NC_SHOW_WINDOW
-#endif
- if (q->testAttribute(Qt::WA_OutsideWSRange))
- return;
- q->setAttribute(Qt::WA_Mapped);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
-
- if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
- invalidateBuffer(q->rect());
- return;
- }
-
- if (data.window_flags & Qt::Window) {
- QTLWExtra *extra = topData();
- if (!extra->hotkeyRegistered) {
- // Try to set the hotkey using information from STARTUPINFO
- STARTUPINFO startupInfo;
- GetStartupInfo(&startupInfo);
- // If STARTF_USEHOTKEY is set, hStdInput is the virtual keycode
- if (startupInfo.dwFlags & 0x00000200) {
- WPARAM hotKey = (WPARAM)startupInfo.hStdInput;
- SendMessage(data.winid, WM_SETHOTKEY, hotKey, 0);
- }
- extra->hotkeyRegistered = 1;
- }
- }
-
- int sm = SW_SHOWNORMAL;
- bool fakedMaximize = false;
- if (q->isWindow()) {
- if (q->isMinimized()) {
- sm = SW_SHOWMINIMIZED;
- if (!IsWindowVisible(q->internalWinId()))
- sm = SW_SHOWMINNOACTIVE;
- } else if (q->isMaximized()) {
- sm = SW_SHOWMAXIMIZED;
- // Windows will not behave correctly when we try to maximize a window which does not
- // have minimize nor maximize buttons in the window frame. Windows would then ignore
- // non-available geometry, and rather maximize the widget to the full screen, minus the
- // window frame (caption). So, we do a trick here, by adding a maximize button before
- // maximizing the widget, and then remove the maximize button afterwards.
- Qt::WindowFlags &flags = data.window_flags;
- if (flags & Qt::WindowTitleHint &&
- !(flags & (Qt::WindowMinMaxButtonsHint | Qt::FramelessWindowHint))) {
- fakedMaximize = TRUE;
- int style = GetWindowLong(q->internalWinId(), GWL_STYLE);
- SetWindowLong(q->internalWinId(), GWL_STYLE, style | WS_MAXIMIZEBOX);
- }
- }
- }
- if (q->testAttribute(Qt::WA_ShowWithoutActivating)
- || (q->windowType() == Qt::Popup)
- || (q->windowType() == Qt::ToolTip)
- || (q->windowType() == Qt::Tool)) {
- sm = SW_SHOWNOACTIVATE;
- }
-
-
- if (q->internalWinId())
- ShowWindow(q->internalWinId(), sm);
-
- if (fakedMaximize) {
- int style = GetWindowLong(q->internalWinId(), GWL_STYLE);
- SetWindowLong(q->internalWinId(), GWL_STYLE, style & ~WS_MAXIMIZEBOX);
- SetWindowPos(q->internalWinId(), 0, 0, 0, 0, 0,
- SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER
- | SWP_FRAMECHANGED);
- }
-
- if (q->internalWinId()) {
- if (IsIconic(q->internalWinId()))
- data.window_state |= Qt::WindowMinimized;
- if (IsZoomed(q->internalWinId()))
- data.window_state |= Qt::WindowMaximized;
- // This is to resolve the problem where popups are opened from the
- // system tray and not being implicitly activated
- if (q->windowType() == Qt::Popup &&
- !q->parentWidget() && !qApp->activeWindow())
- q->activateWindow();
- }
-
- winSetupGestures();
-
- invalidateBuffer(q->rect());
-}
-#endif //Q_WS_WINCE
-
-void QWidgetPrivate::setFocus_sys()
-{
- Q_Q(QWidget);
- if (q->testAttribute(Qt::WA_WState_Created) && q->window()->windowType() != Qt::Popup)
- SetFocus(q->effectiveWinId());
-}
-
-void QWidgetPrivate::raise_sys()
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- if (q->internalWinId())
- SetWindowPos(q->internalWinId(), HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
-}
-
-void QWidgetPrivate::lower_sys()
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- if (q->internalWinId())
- SetWindowPos(q->internalWinId(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
- invalidateBuffer(q->rect());
-}
-
-void QWidgetPrivate::stackUnder_sys(QWidget* w)
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- if (q->internalWinId() && w->internalWinId())
- SetWindowPos(q->internalWinId(), w->internalWinId() , 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- invalidateBuffer(q->rect());
-}
-
-
-/*
- Helper function for non-toplevel widgets. Helps to map Qt's 32bit
- coordinate system to Windpws's 16bit coordinate system.
-
- This code is duplicated from the X11 code, so any changes there
- should also (most likely) be reflected here.
-
- (In all comments below: s/X/Windows/g)
- */
-
-void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &)
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
-
- /*
- There are up to four different coordinate systems here:
- Qt coordinate system for this widget.
- X coordinate system for this widget (relative to wrect).
- Qt coordinate system for parent
- X coordinate system for parent (relative to parent's wrect).
- */
- QRect validRange(-XCOORD_MAX,-XCOORD_MAX, 2*XCOORD_MAX, 2*XCOORD_MAX);
- QRect wrectRange(-WRECT_MAX,-WRECT_MAX, 2*WRECT_MAX, 2*WRECT_MAX);
- QRect wrect;
- //xrect is the X geometry of my X widget. (starts out in parent's Qt coord sys, and ends up in parent's X coord sys)
- QRect xrect = data.crect;
-
- const QWidget *const parent = q->parentWidget();
- QRect parentWRect = parent->data->wrect;
-
- if (parentWRect.isValid()) {
- // parent is clipped, and we have to clip to the same limit as parent
- if (!parentWRect.contains(xrect)) {
- xrect &= parentWRect;
- wrect = xrect;
- //translate from parent's to my Qt coord sys
- wrect.translate(-data.crect.topLeft());
- }
- //translate from parent's Qt coords to parent's X coords
- xrect.translate(-parentWRect.topLeft());
-
- } else {
- // parent is not clipped, we may or may not have to clip
-
- if (data.wrect.isValid() && QRect(QPoint(),data.crect.size()).contains(data.wrect)) {
- // This is where the main optimization is: we are already
- // clipped, and if our clip is still valid, we can just
- // move our window, and do not need to move or clip
- // children
-
- QRect vrect = xrect & parent->rect();
- vrect.translate(-data.crect.topLeft()); //the part of me that's visible through parent, in my Qt coords
- if (data.wrect.contains(vrect)) {
- xrect = data.wrect;
- xrect.translate(data.crect.topLeft());
- if (q->internalWinId())
- MoveWindow(q->internalWinId(), xrect.x(), xrect.y(), xrect.width(), xrect.height(), true);
- return;
- }
- }
-
- if (!validRange.contains(xrect)) {
- // we are too big, and must clip
- xrect &=wrectRange;
- wrect = xrect;
- wrect.translate(-data.crect.topLeft());
- //parent's X coord system is equal to parent's Qt coord
- //sys, so we don't need to map xrect.
- }
-
- }
-
-
- // unmap if we are outside the valid window system coord system
- bool outsideRange = !xrect.isValid();
- bool mapWindow = false;
- if (q->testAttribute(Qt::WA_OutsideWSRange) != outsideRange) {
- q->setAttribute(Qt::WA_OutsideWSRange, outsideRange);
- if (outsideRange) {
- if (q->internalWinId())
- ShowWindow(q->internalWinId(), SW_HIDE);
- q->setAttribute(Qt::WA_Mapped, false);
- } else if (!q->isHidden()) {
- mapWindow = true;
- }
- }
-
- if (outsideRange)
- return;
-
- bool jump = (data.wrect != wrect);
- data.wrect = wrect;
-
- // and now recursively for all children...
- for (int i = 0; i < children.size(); ++i) {
- QObject *object = children.at(i);
- if (object->isWidgetType()) {
- QWidget *w = static_cast<QWidget *>(object);
- if (!w->isWindow() && w->testAttribute(Qt::WA_WState_Created))
- w->d_func()->setWSGeometry();
- }
- }
-
- // move ourselves to the new position and map (if necessary) after
- // the movement. Rationale: moving unmapped windows is much faster
- // than moving mapped windows
- if (q->internalWinId()) {
- if (!parent->internalWinId())
- xrect.translate(parent->mapTo(q->nativeParentWidget(), QPoint(0, 0)));
- MoveWindow(q->internalWinId(), xrect.x(), xrect.y(), xrect.width(), xrect.height(), !jump);
- }
- if (mapWindow && !dontShow) {
- q->setAttribute(Qt::WA_Mapped);
- if (q->internalWinId())
- ShowWindow(q->internalWinId(), SW_SHOWNOACTIVATE);
- }
-
- if (jump && q->internalWinId())
- InvalidateRect(q->internalWinId(), 0, false);
-
-}
-
-//
-// The internal qWinRequestConfig, defined in qapplication_win.cpp, stores move,
-// resize and setGeometry requests for a widget that is already
-// processing a config event. The purpose is to avoid recursion.
-//
-void qWinRequestConfig(WId, int, int, int, int, int);
-
-void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- if (extra) { // any size restrictions?
- w = qMin(w,extra->maxw);
- h = qMin(h,extra->maxh);
- w = qMax(w,extra->minw);
- h = qMax(h,extra->minh);
- }
- if (q->isWindow())
- topData()->normalGeometry = QRect(0, 0, -1, -1);
-
- QSize oldSize(q->size());
- QPoint oldPos(q->pos());
-
- if (!q->isWindow())
- isMove = (data.crect.topLeft() != QPoint(x, y));
- bool isResize = w != oldSize.width() || h != oldSize.height();
-
- if (!isMove && !isResize)
- return;
-
- if (isResize && !q->testAttribute(Qt::WA_StaticContents) && q->internalWinId())
- ValidateRgn(q->internalWinId(), 0);
-
-#ifdef Q_WS_WINCE
- // On Windows CE we can't just fiddle around with the window state.
- // Too much magic in setWindowState.
- if (isResize && q->isMaximized())
- q->setWindowState(q->windowState() & ~Qt::WindowMaximized);
-#else
- if (isResize)
- data.window_state &= ~Qt::WindowMaximized;
-#endif
-
- if (data.window_state & Qt::WindowFullScreen) {
- QTLWExtra *top = topData();
-
- if (q->isWindow()) {
- // We need to update these flags when we remove the full screen state
- // or the frame will not be updated
- UINT style = top->savedFlags;
- if (q->isVisible())
- style |= WS_VISIBLE;
- SetWindowLong(q->internalWinId(), GWL_STYLE, style);
-
- UINT swpf = SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE;
- if (data.window_state & Qt::WindowActive)
- swpf |= SWP_NOACTIVATE;
- SetWindowPos(q->internalWinId(), 0, 0, 0, 0, 0, swpf);
- updateFrameStrut();
- }
- data.window_state &= ~Qt::WindowFullScreen;
- topData()->savedFlags = 0;
- }
-
- QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
- const bool inTopLevelResize = tlwExtra ? tlwExtra->inTopLevelResize : false;
- const bool isTranslucentWindow = !isOpaque && ptrUpdateLayeredWindowIndirect && (data.window_flags & Qt::FramelessWindowHint)
- && GetWindowLong(q->internalWinId(), GWL_EXSTYLE) & Q_WS_EX_LAYERED;
-
- if (q->testAttribute(Qt::WA_WState_ConfigPending)) { // processing config event
- if (q->internalWinId())
- qWinRequestConfig(q->internalWinId(), isMove ? 2 : 1, x, y, w, h);
- } else {
- if (!q->testAttribute(Qt::WA_DontShowOnScreen))
- q->setAttribute(Qt::WA_WState_ConfigPending);
- if (q->windowType() == Qt::Desktop) {
- data.crect.setRect(x, y, w, h);
- } else if (q->isWindow()) {
- QRect fs(frameStrut());
- if (extra) {
- fs.setLeft(x - fs.left());
- fs.setTop(y - fs.top());
- fs.setRight((x + w - 1) + fs.right());
- fs.setBottom((y + h - 1) + fs.bottom());
- }
- if (w == 0 || h == 0) {
- q->setAttribute(Qt::WA_OutsideWSRange, true);
- if (q->isVisible() && q->testAttribute(Qt::WA_Mapped))
- hide_sys();
- data.crect = QRect(x, y, w, h);
- } else if (q->isVisible() && q->testAttribute(Qt::WA_OutsideWSRange)) {
- q->setAttribute(Qt::WA_OutsideWSRange, false);
-
- // put the window in its place and show it
- MoveWindow(q->internalWinId(), fs.x(), fs.y(), fs.width(), fs.height(), true);
- RECT rect;
- if (!q->testAttribute(Qt::WA_DontShowOnScreen)) {
- GetClientRect(q->internalWinId(), &rect);
- data.crect.setRect(x, y, rect.right - rect.left, rect.bottom - rect.top);
- } else {
- data.crect.setRect(x, y, w, h);
- }
-
- show_sys();
- } else if (!q->testAttribute(Qt::WA_DontShowOnScreen)) {
- q->setAttribute(Qt::WA_OutsideWSRange, false);
-#ifndef Q_WS_WINCE
- // If the window is hidden and in maximized state or minimized, instead of moving the
- // window, set the normal position of the window.
- WINDOWPLACEMENT wndpl;
- GetWindowPlacement(q->internalWinId(), &wndpl);
- if ((wndpl.showCmd == SW_MAXIMIZE && !IsWindowVisible(q->internalWinId())) || wndpl.showCmd == SW_SHOWMINIMIZED) {
- RECT normal = {fs.x(), fs.y(), fs.x()+fs.width(), fs.y()+fs.height()};
- wndpl.rcNormalPosition = normal;
- wndpl.showCmd = wndpl.showCmd == SW_SHOWMINIMIZED ? SW_SHOWMINIMIZED : SW_HIDE;
- SetWindowPlacement(q->internalWinId(), &wndpl);
- } else {
-#else
- if (data.window_state & Qt::WindowMaximized) {
- qt_wince_maximize(q);
- } else {
-#endif
- MoveWindow(q->internalWinId(), fs.x(), fs.y(), fs.width(), fs.height(), true);
- }
- if (!q->isVisible())
- InvalidateRect(q->internalWinId(), 0, FALSE);
- RECT rect;
- // If the layout has heightForWidth, the MoveWindow() above can
- // change the size/position, so refresh them.
-
- if (isTranslucentWindow) {
- data.crect.setRect(x, y, w, h);
- } else {
- GetClientRect(q->internalWinId(), &rect);
- RECT rcNormalPosition ={0};
- // Use (0,0) as window position for embedded ActiveQt controls.
- if (!tlwExtra || !tlwExtra->embedded)
- GetWindowRect(q->internalWinId(), &rcNormalPosition);
- QRect fStrut(frameStrut());
- data.crect.setRect(rcNormalPosition.left + fStrut.left(),
- rcNormalPosition.top + fStrut.top(),
- rect.right - rect.left,
- rect.bottom - rect.top);
- isResize = data.crect.size() != oldSize;
- }
- } else {
- q->setAttribute(Qt::WA_OutsideWSRange, false);
- data.crect.setRect(x, y, w, h);
- }
- } else {
- QRect oldGeom(data.crect);
- data.crect.setRect(x, y, w, h);
- if (q->isVisible() && (!inTopLevelResize || q->internalWinId())) {
- // Top-level resize optimization does not work for native child widgets;
- // disable it for this particular widget.
- if (inTopLevelResize)
- tlwExtra->inTopLevelResize = false;
-
- if (!isResize)
- moveRect(QRect(oldPos, oldSize), x - oldPos.x(), y - oldPos.y());
- else
- invalidateBuffer_resizeHelper(oldPos, oldSize);
-
- if (inTopLevelResize)
- tlwExtra->inTopLevelResize = true;
- }
- if (q->testAttribute(Qt::WA_WState_Created))
- setWSGeometry();
- }
- q->setAttribute(Qt::WA_WState_ConfigPending, false);
- }
-
- if (q->isWindow() && q->isVisible() && isResize && !inTopLevelResize) {
- invalidateBuffer(q->rect()); //after the resize
- }
-
- // Process events immediately rather than in translateConfigEvent to
- // avoid windows message process delay.
- if (q->isVisible()) {
- if (isMove && q->pos() != oldPos) {
- QMoveEvent e(q->pos(), oldPos);
- QApplication::sendEvent(q, &e);
- }
- if (isResize) {
- static bool slowResize = qgetenv("QT_SLOW_TOPLEVEL_RESIZE").toInt();
- // If we have a backing store with static contents, we have to disable the top-level
- // resize optimization in order to get invalidated regions for resized widgets.
- // The optimization discards all invalidateBuffer() calls since we're going to
- // repaint everything anyways, but that's not the case with static contents.
- const bool setTopLevelResize = !slowResize && q->isWindow() && extra && extra->topextra
- && !extra->topextra->inTopLevelResize
- && (!extra->topextra->backingStore
- || !extra->topextra->backingStore->hasStaticContents());
- if (setTopLevelResize)
- extra->topextra->inTopLevelResize = true;
- QResizeEvent e(q->size(), oldSize);
- QApplication::sendEvent(q, &e);
- if (setTopLevelResize)
- extra->topextra->inTopLevelResize = false;
- }
- } else {
- if (isMove && q->pos() != oldPos)
- q->setAttribute(Qt::WA_PendingMoveEvent, true);
- if (isResize)
- q->setAttribute(Qt::WA_PendingResizeEvent, true);
- }
-}
-
-bool QWidgetPrivate::shouldShowMaximizeButton()
-{
- if (data.window_flags & Qt::MSWindowsFixedSizeDialogHint)
- return false;
- // if the user explicitly asked for the maximize button, we try to add
- // it even if the window has fixed size.
- if (data.window_flags & Qt::CustomizeWindowHint &&
- data.window_flags & Qt::WindowMaximizeButtonHint)
- return true;
- if (extra) {
- if ((extra->maxw && extra->maxw != QWIDGETSIZE_MAX && extra->maxw != QLAYOUTSIZE_MAX)
- || (extra->maxh && extra->maxh != QWIDGETSIZE_MAX && extra->maxh != QLAYOUTSIZE_MAX))
- return false;
- }
- return data.window_flags & Qt::WindowMaximizeButtonHint;
-}
-
-void QWidgetPrivate::winUpdateIsOpaque()
-{
-#ifndef Q_WS_WINCE
- Q_Q(QWidget);
-
- if (!q->isWindow() || !q->testAttribute(Qt::WA_TranslucentBackground))
- return;
-
- if ((data.window_flags & Qt::FramelessWindowHint) == 0)
- return;
-
- if (!isOpaque && ptrUpdateLayeredWindowIndirect) {
- SetWindowLong(q->internalWinId(), GWL_EXSTYLE,
- GetWindowLong(q->internalWinId(), GWL_EXSTYLE) | Q_WS_EX_LAYERED);
- } else {
- SetWindowLong(q->internalWinId(), GWL_EXSTYLE,
- GetWindowLong(q->internalWinId(), GWL_EXSTYLE) & ~Q_WS_EX_LAYERED);
- }
-#endif
-}
-
-void QWidgetPrivate::setConstraints_sys()
-{
-#ifndef Q_WS_WINCE_WM
- Q_Q(QWidget);
- if (q->isWindow() && q->testAttribute(Qt::WA_WState_Created)) {
- int style = GetWindowLong(q->internalWinId(), GWL_STYLE);
- if (shouldShowMaximizeButton())
- style |= WS_MAXIMIZEBOX;
- else
- style &= ~WS_MAXIMIZEBOX;
- SetWindowLong(q->internalWinId(), GWL_STYLE, style);
- }
-#endif
-}
-
-void QWidgetPrivate::scroll_sys(int dx, int dy)
-{
- Q_Q(QWidget);
- scrollChildren(dx, dy);
-
- if (!paintOnScreen()) {
- scrollRect(q->rect(), dx, dy);
- } else {
- UINT flags = SW_INVALIDATE;
- if (!q->testAttribute(Qt::WA_OpaquePaintEvent))
- flags |= SW_ERASE;
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- ScrollWindowEx(q->internalWinId(), dx, dy, 0, 0, 0, 0, flags);
- UpdateWindow(q->internalWinId());
- }
-}
-
-void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r)
-{
- Q_Q(QWidget);
-
- if (!paintOnScreen()) {
- scrollRect(r, dx, dy);
- } else {
- RECT wr;
- wr.top = r.top();
- wr.left = r.left();
- wr.bottom = r.bottom()+1;
- wr.right = r.right()+1;
-
- UINT flags = SW_INVALIDATE;
- if (!q->testAttribute(Qt::WA_OpaquePaintEvent))
- flags |= SW_ERASE;
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- ScrollWindowEx(q->internalWinId(), dx, dy, &wr, &wr, 0, 0, flags);
- UpdateWindow(q->internalWinId());
- }
-}
-
-int QWidget::metric(PaintDeviceMetric m) const
-{
- Q_D(const QWidget);
- int val;
- if (m == PdmWidth) {
- val = data->crect.width();
- } else if (m == PdmHeight) {
- val = data->crect.height();
- } else {
- HDC gdc = GetDC(0);
- switch (m) {
- case PdmDpiX:
- case PdmPhysicalDpiX:
- if (d->extra && d->extra->customDpiX)
- val = d->extra->customDpiX;
- else if (d->parent)
- val = static_cast<QWidget *>(d->parent)->metric(m);
- else
- val = GetDeviceCaps(gdc, LOGPIXELSX);
- break;
- case PdmDpiY:
- case PdmPhysicalDpiY:
- if (d->extra && d->extra->customDpiY)
- val = d->extra->customDpiY;
- else if (d->parent)
- val = static_cast<QWidget *>(d->parent)->metric(m);
- else
- val = GetDeviceCaps(gdc, LOGPIXELSY);
- break;
- case PdmWidthMM:
- val = data->crect.width()
- * GetDeviceCaps(gdc, HORZSIZE)
- / GetDeviceCaps(gdc, HORZRES);
- break;
- case PdmHeightMM:
- val = data->crect.height()
- * GetDeviceCaps(gdc, VERTSIZE)
- / GetDeviceCaps(gdc, VERTRES);
- break;
- case PdmNumColors:
- if (GetDeviceCaps(gdc, RASTERCAPS) & RC_PALETTE)
- val = GetDeviceCaps(gdc, SIZEPALETTE);
- else {
- HDC hd = d->hd ? HDC(d->hd) : gdc;
- int bpp = GetDeviceCaps(hd, BITSPIXEL);
- if (bpp == 32)
- val = INT_MAX; // ### this is bogus, it should be 2^24 colors for 32 bit as well
- else if(bpp<=8)
- val = GetDeviceCaps(hd, NUMCOLORS);
- else
- val = 1 << (bpp * GetDeviceCaps(hd, PLANES));
- }
- break;
- case PdmDepth:
- val = GetDeviceCaps(gdc, BITSPIXEL);
- break;
- default:
- val = 0;
- qWarning("QWidget::metric: Invalid metric command");
- }
- ReleaseDC(0, gdc);
- }
- return val;
-}
-
-void QWidgetPrivate::createSysExtra()
-{
-#ifndef QT_NO_DRAGANDDROP
- extra->dropTarget = 0;
-#endif
-}
-
-#ifndef Q_WS_WINCE
-void QWidgetPrivate::deleteSysExtra()
-{
-}
-#endif //Q_WS_WINCE
-
-void QWidgetPrivate::createTLSysExtra()
-{
- extra->topextra->hotkeyRegistered = 0;
- extra->topextra->savedFlags = 0;
- extra->topextra->winIconBig = 0;
- extra->topextra->winIconSmall = 0;
-}
-
-void QWidgetPrivate::deleteTLSysExtra()
-{
- if (extra->topextra->winIconSmall)
- DestroyIcon(extra->topextra->winIconSmall);
- if (extra->topextra->winIconBig)
- DestroyIcon(extra->topextra->winIconBig);
-}
-
-void QWidgetPrivate::registerDropSite(bool on)
-{
- Q_Q(QWidget);
- if (!q->testAttribute(Qt::WA_WState_Created))
- return;
- // Enablement is defined by d->extra->dropTarget != 0.
- if (on) {
- // Turn on.
- createExtra();
-#ifndef QT_NO_DRAGANDDROP
- if (!q->internalWinId())
- q->nativeParentWidget()->d_func()->createExtra();
- QWExtra *extra = extraData();
- if (!extra->dropTarget)
- extra->dropTarget = registerOleDnd(q);
-#endif
- } else {
- // Turn off.
- QWExtra *extra = extraData();
-#ifndef QT_NO_DRAGANDDROP
- if (extra && extra->dropTarget) {
- unregisterOleDnd(q, extra->dropTarget);
- extra->dropTarget = 0;
- }
-#endif
- }
-}
-
-#ifndef QT_NO_DRAGANDDROP
-QOleDropTarget* QWidgetPrivate::registerOleDnd(QWidget *widget)
-{
- QOleDropTarget *dropTarget = new QOleDropTarget(widget);
- Q_ASSERT(widget->testAttribute(Qt::WA_WState_Created));
- if (!widget->internalWinId()) {
- QWidget *nativeParent = widget->nativeParentWidget();
- Q_ASSERT(nativeParent);
- QWExtra *nativeExtra = nativeParent->d_func()->extra;
- Q_ASSERT(nativeExtra);
- if (!nativeParent->acceptDrops())
- nativeParent->setAcceptDrops(true);
- if (!nativeExtra->oleDropWidgets.contains(widget))
- nativeExtra->oleDropWidgets.append(widget);
- if (!nativeExtra->dropTarget) {
- nativeExtra->dropTarget = registerOleDnd(nativeParent);
- Q_ASSERT(nativeExtra->dropTarget);
-#ifndef Q_OS_WINCE
- CoLockObjectExternal(nativeExtra->dropTarget, false, true);
-#endif
- RegisterDragDrop(nativeParent->internalWinId(), nativeExtra->dropTarget);
- }
- } else {
- RegisterDragDrop(widget->internalWinId(), dropTarget);
-#ifndef Q_OS_WINCE
- CoLockObjectExternal(dropTarget, true, true);
-#endif
- }
- return dropTarget;
-}
-
-void QWidgetPrivate::unregisterOleDnd(QWidget *widget, QOleDropTarget *dropTarget)
-{
- dropTarget->releaseQt();
- dropTarget->Release();
- Q_ASSERT(widget->testAttribute(Qt::WA_WState_Created));
- if (!widget->internalWinId()) {
- QWidget *nativeParent = widget->nativeParentWidget();
- Q_ASSERT(nativeParent);
- QWExtra *nativeExtra = nativeParent->d_func()->extra;
- Q_ASSERT(nativeExtra);
- nativeExtra->oleDropWidgets.removeAll(widget);
- nativeExtra->oleDropWidgets.removeAll(static_cast<QWidget *>(0));
- if (nativeExtra->oleDropWidgets.isEmpty() && nativeExtra->dropTarget
- && !nativeParent->testAttribute(Qt::WA_DropSiteRegistered)) {
-#ifndef Q_OS_WINCE
- CoLockObjectExternal(nativeExtra->dropTarget, false, true);
-#endif
- RevokeDragDrop(nativeParent->internalWinId());
- nativeExtra->dropTarget = 0;
- }
- } else {
-#ifndef Q_OS_WINCE
- CoLockObjectExternal(dropTarget, false, true);
-#endif
- RevokeDragDrop(widget->internalWinId());
- }
-}
-
-#endif //QT_NO_DRAGANDDROP
-
-// from qregion_win.cpp
-extern HRGN qt_tryCreateRegion(QRegion::RegionType type, int left, int top, int right, int bottom);
-void QWidgetPrivate::setMask_sys(const QRegion &region)
-{
- Q_Q(QWidget);
- if (!q->internalWinId())
- return;
-
- if (region.isEmpty()) {
- SetWindowRgn(q->internalWinId(), 0, true);
- return;
- }
-
- // Since SetWindowRegion takes ownership, and we need to translate,
- // we take a copy.
- HRGN wr = qt_tryCreateRegion(QRegion::Rectangle, 0,0,0,0);
- CombineRgn(wr, region.handle(), 0, RGN_COPY);
-
- QPoint offset = (q->isWindow()
- ? frameStrut().topLeft()
- : QPoint(0, 0));
- OffsetRgn(wr, offset.x(), offset.y());
-
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- if (!SetWindowRgn(data.winid, wr, true))
- DeleteObject(wr);
-}
-
-void QWidgetPrivate::updateFrameStrut()
-{
- Q_Q(QWidget);
-
- if (!q->testAttribute(Qt::WA_WState_Created))
- return;
-
- if (!q->internalWinId()) {
- data.fstrut_dirty = false;
- return;
- }
-
- RECT rect = {0,0,0,0};
-
- QTLWExtra *top = topData();
- uint exstyle = GetWindowLong(q->internalWinId(), GWL_EXSTYLE);
- uint style = GetWindowLong(q->internalWinId(), GWL_STYLE);
-#ifndef Q_WS_WINCE
- if (AdjustWindowRectEx(&rect, style & ~(WS_OVERLAPPED), FALSE, exstyle)) {
-#else
- if (AdjustWindowRectEx(&rect, style, FALSE, exstyle)) {
-#endif
- top->frameStrut.setCoords(-rect.left, -rect.top, rect.right, rect.bottom);
- data.fstrut_dirty = false;
- }
-}
-
-#ifndef Q_WS_WINCE
-void QWidgetPrivate::setWindowOpacity_sys(qreal level)
-{
- Q_Q(QWidget);
-
- if (!isOpaque && ptrUpdateLayeredWindow && (data.window_flags & Qt::FramelessWindowHint)) {
- if (GetWindowLong(q->internalWinId(), GWL_EXSTYLE) & Q_WS_EX_LAYERED) {
- BLENDFUNCTION blend = {AC_SRC_OVER, 0, (int)(255.0 * level), AC_SRC_ALPHA};
- ptrUpdateLayeredWindow(q->internalWinId(), NULL, NULL, NULL, NULL, NULL, 0, &blend, Q_ULW_ALPHA);
- }
- return;
- }
-
- static bool function_resolved = false;
- if (!function_resolved) {
- ptrSetLayeredWindowAttributes =
- (PtrSetLayeredWindowAttributes) QSystemLibrary::resolve(QLatin1String("user32"),
- "SetLayeredWindowAttributes");
- function_resolved = true;
- }
-
- if (!ptrSetLayeredWindowAttributes)
- return;
-
- int wl = GetWindowLong(q->internalWinId(), GWL_EXSTYLE);
-
- if (level != 1.0) {
- if ((wl&Q_WS_EX_LAYERED) == 0)
- SetWindowLong(q->internalWinId(), GWL_EXSTYLE, wl | Q_WS_EX_LAYERED);
- } else if (wl&Q_WS_EX_LAYERED) {
- SetWindowLong(q->internalWinId(), GWL_EXSTYLE, wl & ~Q_WS_EX_LAYERED);
- }
- ptrSetLayeredWindowAttributes(q->internalWinId(), 0, (int)(level * 255), Q_LWA_ALPHA);
-}
-#endif //Q_WS_WINCE
-
-// class QGlobalRasterPaintEngine: public QRasterPaintEngine
-// {
-// public:
-// inline QGlobalRasterPaintEngine() : QRasterPaintEngine() { setFlushOnEnd(false); }
-// };
-// Q_GLOBAL_STATIC(QGlobalRasterPaintEngine, globalRasterPaintEngine)
-
-
-#ifndef QT_NO_DIRECTDRAW
-static uchar *qt_primary_surface_bits;
-static int qt_primary_surface_stride;
-static QImage::Format qt_primary_surface_format;
-
-void qt_win_initialize_directdraw()
-{
- HRESULT res;
-
- // Some initialization...
- if (!qt_ddraw_object) {
- res = DirectDrawCreate(0, &qt_ddraw_object, 0);
-
- if (res != DD_OK)
- qWarning("DirectDrawCreate failed: %d", res);
-
- qt_ddraw_object->SetCooperativeLevel(0, DDSCL_NORMAL);
-
- DDSURFACEDESC surfaceDesc;
- memset(&surfaceDesc, 0, sizeof(DDSURFACEDESC));
-
- surfaceDesc.dwSize = sizeof(DDSURFACEDESC);
- surfaceDesc.dwFlags = DDSD_CAPS;
- surfaceDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
-
- res = qt_ddraw_object->CreateSurface(&surfaceDesc, &qt_ddraw_primary, 0);
- if (res != DD_OK)
- qWarning("CreateSurface failed: %d", res);
-
- memset(&surfaceDesc, 0, sizeof(DDSURFACEDESC));
- surfaceDesc.dwSize = sizeof(DDSURFACEDESC);
- res = qt_ddraw_primary->Lock(0, &surfaceDesc, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, 0);
- if (res != DD_OK)
- qWarning("Locking surface failed: %d", res);
-
- if (surfaceDesc.ddpfPixelFormat.dwFlags == DDPF_RGB) {
- qt_primary_surface_bits = (uchar *) surfaceDesc.lpSurface;
- qt_primary_surface_stride = surfaceDesc.lPitch;
- qt_primary_surface_format = QImage::Format_RGB32;
- } else {
- qWarning("QWidget painting: unsupported device depth for onscreen painting...\n");
- }
-
- qt_ddraw_primary->Unlock(0);
- }
-}
-
-class QOnScreenRasterPaintEngine : public QRasterPaintEngine
-{
-public:
- // The image allocated here leaks... Fix if this code is ifdef'ed
- // in
- QOnScreenRasterPaintEngine()
- : QRasterPaintEngine(new QImage(qt_primary_surface_bits,
- QApplication::desktop()->width(),
- QApplication::desktop()->height(),
- qt_primary_surface_stride,
- qt_primary_surface_format))
- {
- device = static_cast<QImage *>(d_func()->device);
- }
-
- bool begin(QPaintDevice *)
- {
- QRegion clip = systemClip();
- originalSystemClip = clip;
- clip.translate(widget->mapToGlobal(QPoint(0, 0)));
- setSystemClip(clip);
-
- QRect bounds = clip.boundingRect();
- DDSURFACEDESC surface;
- surface.dwSize = sizeof(DDSURFACEDESC);
- HRESULT res = qt_ddraw_primary->Lock((RECT *) &bounds, &surface, DDLOCK_WAIT, 0);
- if (res != DD_OK) {
- qWarning("QWidget painting: locking onscreen bits failed: %d\n", res);
- return false;
- }
-
- if (surface.lpSurface == qt_primary_surface_bits) {
- qt_primary_surface_bits = (uchar *) surface.lpSurface;
- device->data_ptr()->data = qt_primary_surface_bits;
- }
-
- return QRasterPaintEngine::begin(device);
- }
-
- bool end()
- {
- HRESULT res = qt_ddraw_primary->Unlock(0);
- if (res != DD_OK)
- qWarning("QWidget::paint, failed to unlock DirectDraw surface: %d", res);
- bool ok = QRasterPaintEngine::end();
- setSystemClip(originalSystemClip);
- return ok;
- }
-
- QPoint coordinateOffset() const {
- return -widget->mapToGlobal(QPoint(0, 0));
- }
-
- const QWidget *widget;
- QImage *device;
- QRegion originalSystemClip;
-};
-Q_GLOBAL_STATIC(QOnScreenRasterPaintEngine, onScreenPaintEngine)
-#else
-void qt_win_initialize_directdraw() { }
-#endif
-
-QPaintEngine *QWidget::paintEngine() const
-{
-#ifndef QT_NO_DIRECTDRAW
- QOnScreenRasterPaintEngine *pe = onScreenPaintEngine();
- pe->widget = this;
- return pe;
-#endif
-
- // We set this bit which is checked in setAttribute for
- // Qt::WA_PaintOnScreen. We do this to allow these two scenarios:
- //
- // 1. Users accidentally set Qt::WA_PaintOnScreen on X and port to
- // windows which would mean suddenly their widgets stop working.
- //
- // 2. Users set paint on screen and subclass paintEngine() to
- // return 0, in which case we have a "hole" in the backingstore
- // allowing use of GDI or DirectX directly.
- //
- // 1 is WRONG, but to minimize silent failures, we have set this
- // bit to ignore the setAttribute call. 2. needs to be
- // supported because its our only means of embeddeding native
- // graphics stuff.
- const_cast<QWidgetPrivate *>(d_func())->noPaintOnScreen = 1;
-
- return 0;
-}
-
-QWindowSurface *QWidgetPrivate::createDefaultWindowSurface_sys()
-{
- Q_Q(QWidget);
- return new QRasterWindowSurface(q);
-}
-
-void QWidgetPrivate::setModal_sys()
-{
-}
-
-void QWidgetPrivate::registerTouchWindow()
-{
- Q_Q(QWidget);
-
- // enable WM_TOUCH* messages on our window
- if (q->testAttribute(Qt::WA_WState_Created)
- && QApplicationPrivate::RegisterTouchWindow
- && q->windowType() != Qt::Desktop)
- QApplicationPrivate::RegisterTouchWindow(q->effectiveWinId(), 0);
-}
-
-void QWidgetPrivate::winSetupGestures()
-{
-#if !defined(QT_NO_GESTURES) && !defined(QT_NO_NATIVE_GESTURES)
- Q_Q(QWidget);
- if (!q || !q->isVisible() || !nativeGesturePanEnabled)
- return;
-
- if (!QApplicationPrivate::HasTouchSupport)
- return;
- QApplicationPrivate *qAppPriv = QApplicationPrivate::instance();
- if (!qAppPriv->SetGestureConfig)
- return;
- WId winid = q->internalWinId();
-
- bool needh = false;
- bool needv = false;
- bool singleFingerPanEnabled = false;
-
-#ifndef QT_NO_SCROLLAREA
- if (QAbstractScrollArea *asa = qobject_cast<QAbstractScrollArea*>(q->parent())) {
- QScrollBar *hbar = asa->horizontalScrollBar();
- QScrollBar *vbar = asa->verticalScrollBar();
- Qt::ScrollBarPolicy hbarpolicy = asa->horizontalScrollBarPolicy();
- Qt::ScrollBarPolicy vbarpolicy = asa->verticalScrollBarPolicy();
- needh = (hbarpolicy == Qt::ScrollBarAlwaysOn ||
- (hbarpolicy == Qt::ScrollBarAsNeeded && hbar->minimum() < hbar->maximum()));
- needv = (vbarpolicy == Qt::ScrollBarAlwaysOn ||
- (vbarpolicy == Qt::ScrollBarAsNeeded && vbar->minimum() < vbar->maximum()));
- singleFingerPanEnabled = asa->d_func()->singleFingerPanEnabled;
- if (!winid) {
- winid = q->winId(); // enforces the native winid on the viewport
- }
- }
-#endif //QT_NO_SCROLLAREA
- if (winid) {
- GESTURECONFIG gc[1];
- memset(gc, 0, sizeof(gc));
- gc[0].dwID = GID_PAN;
- if (nativeGesturePanEnabled) {
- gc[0].dwWant = GC_PAN;
- if (needv && singleFingerPanEnabled)
- gc[0].dwWant |= GC_PAN_WITH_SINGLE_FINGER_VERTICALLY;
- else
- gc[0].dwBlock |= GC_PAN_WITH_SINGLE_FINGER_VERTICALLY;
- if (needh && singleFingerPanEnabled)
- gc[0].dwWant |= GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY;
- else
- gc[0].dwBlock |= GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY;
- } else {
- gc[0].dwBlock = GC_PAN;
- }
-
- qAppPriv->SetGestureConfig(winid, 0, sizeof(gc)/sizeof(gc[0]), gc, sizeof(gc[0]));
- }
-#endif
-}
-
-QT_END_NAMESPACE
-
-#ifdef Q_WS_WINCE
-# include "qwidget_wince.cpp"
-#endif
diff --git a/src/gui/kernel/qwidget_wince.cpp b/src/gui/kernel/qwidget_wince.cpp
deleted file mode 100644
index 7676182ef0..0000000000
--- a/src/gui/kernel/qwidget_wince.cpp
+++ /dev/null
@@ -1,675 +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$
-**
-****************************************************************************/
-
-#ifdef Q_WS_WINCE
-
-#include "qguifunctions_wince.h"
-
-QT_BEGIN_NAMESPACE
-
-const QString qt_reg_winclass(QWidget *w); // defined in qapplication_win.cpp
-extern "C" LRESULT QT_WIN_CALLBACK QtWndProc(HWND, UINT, WPARAM, LPARAM);
-
-//#define TABLET_DEBUG
-#define PACKETDATA (PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE \
- | PK_ORIENTATION | PK_CURSOR | PK_Z)
-#define PACKETMODE 0
-
-typedef HCTX (API *PtrWTOpen)(HWND, LPLOGCONTEXT, BOOL);
-typedef BOOL (API *PtrWTClose)(HCTX);
-typedef UINT (API *PtrWTInfo)(UINT, UINT, LPVOID);
-typedef BOOL (API *PtrWTEnable)(HCTX, BOOL);
-typedef BOOL (API *PtrWTOverlap)(HCTX, BOOL);
-typedef int (API *PtrWTPacketsGet)(HCTX, int, LPVOID);
-typedef BOOL (API *PtrWTGet)(HCTX, LPLOGCONTEXT);
-typedef int (API *PtrWTQueueSizeGet)(HCTX);
-typedef BOOL (API *PtrWTQueueSizeSet)(HCTX, int);
-
-#ifndef QT_NO_TABLETEVENT
-static void qt_tablet_init_wce();
-static void qt_tablet_cleanup_wce();
-
-static void qt_tablet_init_wce() {
- static bool firstTime = true;
- if (!firstTime)
- return;
- firstTime = false;
- qt_tablet_widget = new QWidget(0);
- qt_tablet_widget->createWinId();
- qt_tablet_widget->setObjectName(QLatin1String("Qt internal tablet widget"));
- LOGCONTEXT lcMine;
- qAddPostRoutine(qt_tablet_cleanup_wce);
- struct tagAXIS tpOri[3];
- if (ptrWTInfo && ptrWTOpen && ptrWTQueueSizeGet && ptrWTQueueSizeSet) {
- // make sure we have WinTab
- if (!ptrWTInfo(0, 0, NULL)) {
-#ifdef TABLET_DEBUG
- qWarning("QWidget: Wintab services not available");
-#endif
- return;
- }
-
- // some tablets don't support tilt, check if it is possible,
- qt_tablet_tilt_support = ptrWTInfo(WTI_DEVICES, DVC_ORIENTATION, &tpOri);
- if (qt_tablet_tilt_support) {
- // check for azimuth and altitude
- qt_tablet_tilt_support = tpOri[0].axResolution && tpOri[1].axResolution;
- }
- // build our context from the default context
- ptrWTInfo(WTI_DEFSYSCTX, 0, &lcMine);
- // Go for the raw coordinates, the tablet event will return good stuff
- lcMine.lcOptions |= CXO_MESSAGES | CXO_CSRMESSAGES;
- lcMine.lcPktData = PACKETDATA;
- lcMine.lcPktMode = PACKETMODE;
- lcMine.lcMoveMask = PACKETDATA;
- lcMine.lcOutOrgX = 0;
- lcMine.lcOutExtX = lcMine.lcInExtX;
- lcMine.lcOutOrgY = 0;
- lcMine.lcOutExtY = -lcMine.lcInExtY;
- qt_tablet_context = ptrWTOpen(qt_tablet_widget->winId(), &lcMine, true);
-#ifdef TABLET_DEBUG
- qDebug("Tablet is %p", qt_tablet_context);
-#endif
- if (!qt_tablet_context) {
-#ifdef TABLET_DEBUG
- qWarning("QWidget: Failed to open the tablet");
-#endif
- return;
- }
- // Set the size of the Packet Queue to the correct size...
- int currSize = ptrWTQueueSizeGet(qt_tablet_context);
- if (!ptrWTQueueSizeSet(qt_tablet_context, QT_TABLET_NPACKETQSIZE)) {
- // Ideally one might want to use a smaller
- // multiple, but for now, since we managed to destroy
- // the existing Q with the previous call, set it back
- // to the other size, which should work. If not,
- // there will be trouble.
- if (!ptrWTQueueSizeSet(qt_tablet_context, currSize)) {
- Q_ASSERT_X(0, "Qt::Internal", "There is no packet queue for"
- " the tablet. The tablet will not work");
- }
- }
- }
-}
-
-static void qt_tablet_cleanup_wce() {
- if (ptrWTClose)
- ptrWTClose(qt_tablet_context);
- delete qt_tablet_widget;
- qt_tablet_widget = 0;
-}
-#endif // QT_NO_TABLETEVENT
-
-
-// The internal qWinRequestConfig, defined in qapplication_win.cpp, stores move,
-// resize and setGeometry requests for a widget that is already
-// processing a config event. The purpose is to avoid recursion.
-//
-void qWinRequestConfig(WId, int, int, int, int, int);
-
-void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow) {
- Q_Q(QWidget);
- static int sw = -1, sh = -1;
-
- Qt::WindowType type = q->windowType();
- Qt::WindowFlags flags = data.window_flags;
-
- bool topLevel = (flags & Qt::Window);
- bool popup = (type == Qt::Popup);
- bool dialog = (type == Qt::Dialog
- || type == Qt::Sheet
- || (flags & Qt::MSWindowsFixedSizeDialogHint));
- bool desktop = (type == Qt::Desktop);
- bool tool = (type == Qt::Tool || type == Qt::Drawer);
-
- HINSTANCE appinst = qWinAppInst();
- HWND parentw, destroyw = 0;
- WId id;
-
- QString windowClassName = qt_reg_winclass(q);
-
- if (!window) // always initialize
- initializeWindow = true;
-
- if (popup)
- flags |= Qt::WindowStaysOnTopHint; // a popup stays on top
-
- if (flags & (Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowContextHelpButtonHint)) {
- flags |= Qt::WindowSystemMenuHint;
- flags |= Qt::WindowTitleHint;
- flags &= ~Qt::FramelessWindowHint;
- }
-
- if (sw < 0) { // get the (primary) screen size
- sw = GetSystemMetrics(SM_CXSCREEN);
- sh = GetSystemMetrics(SM_CYSCREEN);
- }
-
- if (desktop) { // desktop widget
- popup = false; // force this flags off
- data.crect.setRect(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
- }
-
- parentw = q->parentWidget() ? q->parentWidget()->effectiveWinId() : 0;
-
- QString title;
- int style = WS_CHILD;
- int exsty = WS_EX_NOPARENTNOTIFY;
-
- if (topLevel) {
- if (!(flags & Qt::FramelessWindowHint) && !tool && !q->testAttribute(Qt::WA_DontShowOnScreen))
- style = (WS_OVERLAPPED) | WS_SYSMENU;
- else
- style = WS_POPUP;
- if ((type == Qt::ToolTip) || (type == Qt::SplashScreen)) {
- style = WS_POPUP;
- exsty |= WS_EX_NOANIMATION;
- } else {
- if (flags & Qt::WindowTitleHint)
- style |= WS_CAPTION;
- if (flags & Qt::WindowSystemMenuHint)
- style |= WS_SYSMENU;
- if (flags & Qt::WindowContextHelpButtonHint)
- exsty |= WS_EX_CONTEXTHELP;
-#ifndef Q_WS_WINCE_WM
- if (flags & Qt::WindowMinimizeButtonHint)
- style |= WS_MINIMIZEBOX;
- if (shouldShowMaximizeButton())
- style |= WS_MAXIMIZEBOX;
-#endif
- if (tool)
- exsty |= WS_EX_TOOLWINDOW;
- }
- }
- if (dialog) {
- style = WS_BORDER | WS_CAPTION;
- if (flags & Qt::WindowOkButtonHint)
- exsty |= WS_EX_CAPTIONOKBTN;
- if (flags & Qt::WindowCancelButtonHint || flags & Qt::WA_DeleteOnClose)
- style |= WS_SYSMENU;
- if (flags & Qt::WindowContextHelpButtonHint)
- exsty |= WS_EX_CONTEXTHELP;
- }
- if (popup) {
- style = WS_POPUP;
- exsty |= WS_EX_NOANIMATION;
- }
-
- if (flags & Qt::WindowTitleHint) {
- title = q->isWindow() ? qAppName() : q->objectName();
- }
-
- // The Qt::WA_WState_Created flag is checked by translateConfigEvent() in
- // qapplication_win.cpp. We switch it off temporarily to avoid move
- // and resize events during creationt
- q->setAttribute(Qt::WA_WState_Created, false);
-
- if (window) { // override the old window
- if (destroyOldWindow)
- destroyw = data.winid;
- id = window;
- setWinId(window);
- LONG res = SetWindowLong(window, GWL_STYLE, style);
- if (!res)
- qErrnoWarning("QWidget::create: Failed to set window style");
-
- res = SetWindowLong( window, GWL_WNDPROC, (LONG)QtWndProc );
-
- if (!res)
- qErrnoWarning("QWidget::create: Failed to set window procedure");
- } else if (desktop) { // desktop widget
- id = GetDesktopWindow();
- if (!id) { //Create a dummy desktop
- RECT r;
- SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
- id = CreateWindow(reinterpret_cast<const wchar_t *>(windowClassName.utf16()),
- reinterpret_cast<const wchar_t *>(title.utf16()), style,
- r.left, r.top, r.right - r.left, r.bottom - r.top,
- 0, 0, appinst, 0);
- }
- setWinId(id);
- } else if (topLevel) { // create top-level widget
- const bool wasMoved = q->testAttribute(Qt::WA_Moved);
-
- int x, y;
- if (qt_wince_is_mobile()) {
- x = wasMoved ? data.crect.left() : CW_USEDEFAULT;
- y = wasMoved ? data.crect.top() : CW_USEDEFAULT;
- } else {
- x = wasMoved ? data.crect.left() : 100;
- y = wasMoved ? data.crect.top() : 100;
- }
-
- int w = CW_USEDEFAULT;
- int h = CW_USEDEFAULT;
-
- // Adjust for framestrut when needed
- RECT rect = {0,0,0,0};
- if (AdjustWindowRectEx(&rect, style, FALSE, exsty)) {
- QTLWExtra *td = maybeTopData();
- if (wasMoved && (td && !td->posFromMove)) {
- x = data.crect.x() + rect.left;
- y = data.crect.y() + rect.top;
- }
-
- if (q->testAttribute(Qt::WA_Resized)) {
- w = data.crect.width() + (rect.right - rect.left);
- h = data.crect.height() + (rect.bottom - rect.top);
- }
- }
-
- id = CreateWindowEx(exsty, reinterpret_cast<const wchar_t *>(windowClassName.utf16()),
- reinterpret_cast<const wchar_t *>(title.utf16()), style,
- x, y, w, h,
- 0, 0, appinst, 0);
-
- if (!id)
- qErrnoWarning("QWidget::create: Failed to create window");
- setWinId(id);
- if ((flags & Qt::WindowStaysOnTopHint) || (type == Qt::ToolTip))
- SetWindowPos(id, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
- } else if (q->testAttribute(Qt::WA_NativeWindow) || paintOnScreen()) { // create child widget
- id = CreateWindowEx(exsty, (wchar_t*)windowClassName.utf16(), (wchar_t*)title.utf16(), style,
- data.crect.left(), data.crect.top(), data.crect.width(), data.crect.height(),
- parentw, NULL, appinst, NULL);
- if (!id)
- qErrnoWarning("QWidget::create: Failed to create window");
- SetWindowPos(id, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- setWinId(id);
- }
-
- if (desktop) {
- q->setAttribute(Qt::WA_WState_Visible);
- } else if (topLevel && !q->testAttribute(Qt::WA_DontShowOnScreen)) {
- RECT cr;
- GetClientRect(id, &cr);
- // one cannot trust cr.left and cr.top, use a correction POINT instead
- POINT pt;
- pt.x = 0;
- pt.y = 0;
- if (!q->testAttribute(Qt::WA_DontShowOnScreen) || q->testAttribute(Qt::WA_Moved))
- ClientToScreen(id, &pt);
- data.crect = QRect(QPoint(pt.x, pt.y),
- QPoint(pt.x + cr.right - 1, pt.y + cr.bottom - 1));
-
- if (data.fstrut_dirty) {
- // be nice to activeqt
- updateFrameStrut();
- }
- }
-
- q->setAttribute(Qt::WA_WState_Created); // accept move/resize events
- hd = 0; // no display context
-
- if (window) { // got window from outside
- if (IsWindowVisible(window))
- q->setAttribute(Qt::WA_WState_Visible);
- else
- q->setAttribute(Qt::WA_WState_Visible, false);
- }
-
- if (extra && !extra->mask.isEmpty())
- setMask_sys(extra->mask);
-
-#if defined(QT_NON_COMMERCIAL)
- QT_NC_WIDGET_CREATE
-#endif
-
- if (q->hasFocus() && q->testAttribute(Qt::WA_InputMethodEnabled))
- q->inputContext()->setFocusWidget(q);
-
- if (destroyw) {
- DestroyWindow(destroyw);
- }
-
-#ifndef QT_NO_TABLETEVENT
- if (q != qt_tablet_widget && QWidgetPrivate::mapper)
- qt_tablet_init_wce();
-#endif // QT_NO_TABLETEVENT
-
- if (q->testAttribute(Qt::WA_DropSiteRegistered))
- registerDropSite(true);
-
- if (maybeTopData() && maybeTopData()->opacity != 255)
- q->setWindowOpacity(maybeTopData()->opacity/255.);
-
- if (!topLevel && q->testAttribute(Qt::WA_NativeWindow) && q->testAttribute(Qt::WA_Mapped)) {
- Q_ASSERT(q->internalWinId());
- ShowWindow(q->internalWinId(), SW_SHOW);
- }
-}
-
-/*
- \internal
- Platform-specific part of QWidget::show().
-*/
-void QWidgetPrivate::show_sys() {
- Q_Q(QWidget);
-#if defined(QT_NON_COMMERCIAL)
- QT_NC_SHOW_WINDOW
-#endif
- if (q->testAttribute(Qt::WA_OutsideWSRange))
- return;
-
- q->setAttribute(Qt::WA_Mapped);
-
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
-
- if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
- invalidateBuffer(q->rect());
- return;
- }
-
-
- int sm = SW_SHOW;
- bool fakedMaximize = false;
- if (q->isWindow()) {
-#ifndef Q_WS_WINCE_WM
- if (q->isMinimized()) {
- sm = SW_SHOWMINIMIZED;
- } else if (q->isMaximized()) {
- sm = SW_SHOWMAXIMIZED;
- // Windows will not behave correctly when we try to maximize a window which does not
- // have minimize nor maximize buttons in the window frame. Windows would then ignore
- // non-available geometry, and rather maximize the widget to the full screen, minus the
- // window frame (caption). So, we do a trick here, by adding a maximize button before
- // maximizing the widget, and then remove the maximize button afterwards.
- Qt::WindowFlags &flags = data.window_flags;
- if (flags & Qt::WindowTitleHint &&
- !(flags & (Qt::WindowMinMaxButtonsHint | Qt::FramelessWindowHint))) {
- fakedMaximize = TRUE;
- int style = GetWindowLong(q->internalWinId(), GWL_STYLE);
- SetWindowLong(q->internalWinId(), GWL_STYLE, style | WS_MAXIMIZEBOX);
- }
- } else
-#else
- // Imitate minimizing on Windows mobile by hiding the widget.
- if (q->isMinimized())
- sm = SW_HIDE;
-#endif
- if (q->isHidden()) {
- sm = SW_HIDE;
- }
- }
- if (q->testAttribute(Qt::WA_ShowWithoutActivating)
- || (q->windowType() == Qt::Popup)
- || (q->windowType() == Qt::ToolTip)
- || (q->windowType() == Qt::Tool)) {
- sm = SW_SHOWNOACTIVATE;
- }
-
- ShowWindow(q->internalWinId(), sm);
-
- if (q->isMaximized() && q->isWindow())
- qt_wince_maximize(q);
-
-#ifndef Q_WS_WINCE_WM
- if (!qt_wince_is_mobile() && q->isFullScreen()) {
- HWND handle = FindWindow(L"HHTaskBar", L"");
- if (handle) {
- ShowWindow(handle, SW_HIDE);
- EnableWindow(handle, false);
- }
- }
-
- if (fakedMaximize) {
- int style = GetWindowLong(q->internalWinId(), GWL_STYLE);
- SetWindowLong(q->internalWinId(), GWL_STYLE, style & ~WS_MAXIMIZEBOX);
- SetWindowPos(q->internalWinId(), 0, 0, 0, 0, 0,
- SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER
- | SWP_FRAMECHANGED);
- }
-#else
- Q_UNUSED(fakedMaximize);
-#endif
-
- if (q->isWindow() && sm == SW_SHOW)
- SetForegroundWindow(q->internalWinId());
-
- invalidateBuffer(q->rect());
-}
-
-void QWidget::setWindowState(Qt::WindowStates newstate)
-{
- Q_D(QWidget);
- Qt::WindowStates oldstate = windowState();
- if (oldstate == newstate)
- return;
-
- int max = SW_SHOWNORMAL;
- int normal = SW_SHOWNOACTIVATE;
-
- if ((oldstate & Qt::WindowMinimized) && !(newstate & Qt::WindowMinimized))
- newstate |= Qt::WindowActive;
- if (newstate & Qt::WindowActive)
- normal = SW_SHOWNORMAL;
- if (isWindow()) {
- createWinId();
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
- // Ensure the initial size is valid, since we store it as normalGeometry below.
- if ((!testAttribute(Qt::WA_Resized) && !isVisible()))
- adjustSize();
- if (!d->topData()->normalGeometry.isValid()) {
- if (newstate & Qt::WindowMaximized && !(oldstate & Qt::WindowFullScreen))
- d->topData()->normalGeometry = geometry();
- if (newstate & Qt::WindowMinimized && !(oldstate & Qt::WindowFullScreen))
- d->topData()->normalGeometry = geometry();
- }
- if ((oldstate & Qt::WindowMaximized) != (newstate & Qt::WindowMaximized)) {
- if (!(newstate & Qt::WindowMaximized)) {
- int style = GetWindowLong(internalWinId(), GWL_STYLE) | WS_BORDER | WS_POPUP | WS_CAPTION;
- SetWindowLong(internalWinId(), GWL_STYLE, style);
- SetWindowLong(internalWinId(), GWL_EXSTYLE, GetWindowLong (internalWinId(), GWL_EXSTYLE) & ~ WS_EX_NODRAG);
- qt_wince_unmaximize(this);
- }
- if (isVisible() && newstate & Qt::WindowMaximized)
- qt_wince_maximize(this);
- if (isVisible() && !(newstate & Qt::WindowMinimized)) {
- ShowWindow(internalWinId(), (newstate & Qt::WindowMaximized) ? max : normal);
- if (!(newstate & Qt::WindowFullScreen)) {
- QRect r = d->topData()->normalGeometry;
- if (!(newstate & Qt::WindowMaximized) && r.width() >= 0) {
- if (pos() != r.topLeft() || size() !=r.size()) {
- d->topData()->normalGeometry = QRect(0,0,-1,-1);
- setGeometry(r);
- }
- }
- } else {
- d->updateFrameStrut();
- }
- }
- }
- if ((oldstate & Qt::WindowFullScreen) != (newstate & Qt::WindowFullScreen)) {
- if (newstate & Qt::WindowFullScreen) {
- if (d->topData()->normalGeometry.width() < 0 && !(oldstate & Qt::WindowMaximized))
- d->topData()->normalGeometry = geometry();
- d->topData()->savedFlags = (Qt::WindowFlags)GetWindowLong(internalWinId(), GWL_STYLE);
- UINT style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP;
- if (isVisible())
- style |= WS_VISIBLE;
- SetWindowLong(internalWinId(), GWL_STYLE, style);
- QRect r = qApp->desktop()->screenGeometry(this);
- UINT swpf = SWP_FRAMECHANGED;
- if (newstate & Qt::WindowActive)
- swpf |= SWP_NOACTIVATE;
- qt_wince_full_screen(internalWinId(), true, swpf);
- d->updateFrameStrut();
- } else {
- UINT style = d->topData()->savedFlags;
- if (isVisible())
- style |= WS_VISIBLE;
- SetWindowLong(internalWinId(), GWL_STYLE, style);
- UINT swpf = SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE;
- if (newstate & Qt::WindowActive)
- swpf |= SWP_NOACTIVATE;
- qt_wince_full_screen(internalWinId(), false, swpf);
- d->updateFrameStrut();
-
- // preserve maximized state
- if (isVisible()) {
- ShowWindow(internalWinId(), (newstate & Qt::WindowMaximized) ? max : normal);
- if (newstate & Qt::WindowMaximized)
- qt_wince_maximize(this);
- }
- if (!(newstate & Qt::WindowMaximized)) {
- QRect r = d->topData()->normalGeometry;
- d->topData()->normalGeometry = QRect(0,0,-1,-1);
- if (r.isValid())
- setGeometry(r);
- }
- }
- }
- if ((oldstate & Qt::WindowMinimized) != (newstate & Qt::WindowMinimized)) {
- if (newstate & Qt::WindowMinimized)
- qt_wince_minimize(internalWinId());
- else if (newstate & Qt::WindowMaximized) {
- ShowWindow(internalWinId(), max);
- qt_wince_maximize(this);
- } else {
- ShowWindow(internalWinId(), normal);
- }
- }
- }
- data->window_state = newstate;
- QWindowStateChangeEvent e(oldstate);
- QApplication::sendEvent(this, &e);
-}
-
-void QWidgetPrivate::deleteSysExtra()
-{
- Q_Q(QWidget);
- if (!qt_wince_is_mobile() && q->isFullScreen()) {
- HWND handle = FindWindow(L"HHTaskBar", L"");
- if (handle) {
- ShowWindow(handle, SW_SHOWNORMAL);
- EnableWindow(handle, true);
- }
- }
-}
-
-void QWidgetPrivate::setWindowOpacity_sys(qreal level) {
- Q_UNUSED(level);
- return;
-}
-
-// The procedure does nothing, but is required for mousegrabbing to work
-LRESULT QT_WIN_CALLBACK qJournalRecordProc(int nCode, WPARAM wParam, LPARAM lParam) {
- Q_UNUSED(nCode);
- Q_UNUSED(wParam);
- Q_UNUSED(lParam);
- return 0;
-}
-
-void QWidget::grabMouse() {
- if (!qt_nograb()) {
- if (mouseGrb)
- mouseGrb->releaseMouse();
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
- SetCapture(internalWinId());
- mouseGrb = this;
- }
-}
-
-#ifndef QT_NO_CURSOR
-void QWidget::grabMouse(const QCursor &cursor) {
- if (!qt_nograb()) {
- if (mouseGrb)
- mouseGrb->releaseMouse();
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
- SetCapture(internalWinId());
- mouseGrbCur = new QCursor(cursor);
- SetCursor(mouseGrbCur->handle());
- mouseGrb = this;
- }
-}
-#endif
-
-void QWidget::releaseMouse() {
- if (!qt_nograb() && mouseGrb == this) {
- ReleaseCapture();
- if (journalRec) {
- journalRec = 0;
- }
- if (mouseGrbCur) {
- delete mouseGrbCur;
- mouseGrbCur = 0;
- }
- mouseGrb = 0;
- }
-}
-
-void QWidget::show()
-{
- Qt::WindowFlags flags = windowFlags() & 0xff;
- int threshold = qApp->autoMaximizeThreshold();
- if ((threshold < 0) || (windowState() & Qt::WindowFullScreen) || (windowState() & Qt::WindowMaximized)) {
- setVisible(true);
- return;
- }
- int height = sizeHint().height();
- int screenHeight = (qreal(threshold) / 100.0f * qApp->desktop()->screenGeometry(this).height());
- bool maximize = height > screenHeight;
- if (!maximize) {
- // If we do not maximize yet we check the widget and its child widgets whether they are
- //vertically expanding. If one of the widgets is expanding we maximize.
- QList<QWidget *> list = findChildren<QWidget *>();
- bool expandingChild = sizePolicy().verticalPolicy () == QSizePolicy::Expanding;
- for (int i = 0; (i < list.size()) && !expandingChild; ++i) {
- expandingChild = list.at(i)->sizePolicy().verticalPolicy () == QSizePolicy::Expanding;
- }
- maximize = expandingChild;
- }
- if ((minimumSizeHint().height() > qApp->desktop()->screenGeometry(this).height()) || (minimumSizeHint().width() > qApp->desktop()->screenGeometry(this).width()))
- maximize = false;
-
- if ((flags == Qt::Window || flags == Qt::Dialog) && maximize) {
- setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowFullScreen))
- | Qt::WindowMaximized);
- setVisible(true);
- }
- else {
- setVisible(true);
- }
-}
-
-QT_END_NAMESPACE
-
-#endif // Q_WS_WINCE
diff --git a/src/gui/kernel/qwidget_x11.cpp b/src/gui/kernel/qwidget_x11.cpp
deleted file mode 100644
index 5ece7d65c6..0000000000
--- a/src/gui/kernel/qwidget_x11.cpp
+++ /dev/null
@@ -1,3146 +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 "qwidget.h"
-#include "qdesktopwidget.h"
-#include "qapplication.h"
-#include "qapplication_p.h"
-#include "qnamespace.h"
-#include "qpainter.h"
-#include "qbitmap.h"
-#include "qlayout.h"
-#include "qtextcodec.h"
-#include "qelapsedtimer.h"
-#include "qcursor.h"
-#include "qstack.h"
-#include "qcolormap.h"
-#include "qdebug.h"
-#include "qmenu.h"
-#include "private/qmenu_p.h"
-#include "private/qbackingstore_p.h"
-#include "private/qwindowsurface_x11_p.h"
-
-//extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); //qapplication_x11.cpp
-
-#include <private/qpixmap_x11_p.h>
-#include <private/qpaintengine_x11_p.h>
-#include "qt_x11_p.h"
-#include "qx11info_x11.h"
-
-#include <stdlib.h>
-
-//#define ALIEN_DEBUG
-
-// defined in qapplication_x11.cpp
-//bool qt_wstate_iconified(WId);
-//void qt_updated_rootinfo();
-
-
-#if !defined(QT_NO_IM)
-#include "qinputcontext.h"
-#include "qinputcontextfactory.h"
-#endif
-
-#include "qwidget_p.h"
-
-#define XCOORD_MAX 16383
-#define WRECT_MAX 8191
-
-QT_BEGIN_NAMESPACE
-
-extern bool qt_nograb();
-
-QWidget *QWidgetPrivate::mouseGrabber = 0;
-QWidget *QWidgetPrivate::keyboardGrabber = 0;
-
-void qt_net_remove_user_time(QWidget *tlw);
-void qt_net_update_user_time(QWidget *tlw, unsigned long timestamp);
-
-int qt_x11_create_desktop_on_screen = -1;
-
-extern void qt_net_update_user_time(QWidget *tlw, unsigned long timestamp);
-
-// MWM support
-struct QtMWMHints {
- ulong flags, functions, decorations;
- long input_mode;
- ulong status;
-};
-
-enum {
- MWM_HINTS_FUNCTIONS = (1L << 0),
-
- MWM_FUNC_ALL = (1L << 0),
- MWM_FUNC_RESIZE = (1L << 1),
- MWM_FUNC_MOVE = (1L << 2),
- MWM_FUNC_MINIMIZE = (1L << 3),
- MWM_FUNC_MAXIMIZE = (1L << 4),
- MWM_FUNC_CLOSE = (1L << 5),
-
- MWM_HINTS_DECORATIONS = (1L << 1),
-
- MWM_DECOR_ALL = (1L << 0),
- MWM_DECOR_BORDER = (1L << 1),
- MWM_DECOR_RESIZEH = (1L << 2),
- MWM_DECOR_TITLE = (1L << 3),
- MWM_DECOR_MENU = (1L << 4),
- MWM_DECOR_MINIMIZE = (1L << 5),
- MWM_DECOR_MAXIMIZE = (1L << 6),
-
- MWM_HINTS_INPUT_MODE = (1L << 2),
-
- MWM_INPUT_MODELESS = 0L,
- MWM_INPUT_PRIMARY_APPLICATION_MODAL = 1L,
- MWM_INPUT_FULL_APPLICATION_MODAL = 3L
-};
-
-
-static QtMWMHints GetMWMHints(Display *display, Window window)
-{
- QtMWMHints mwmhints;
-
- Atom type;
- int format;
- ulong nitems, bytesLeft;
- uchar *data = 0;
- if ((XGetWindowProperty(display, window, ATOM(_MOTIF_WM_HINTS), 0, 5, false,
- ATOM(_MOTIF_WM_HINTS), &type, &format, &nitems, &bytesLeft,
- &data) == Success)
- && (type == ATOM(_MOTIF_WM_HINTS)
- && format == 32
- && nitems >= 5)) {
- mwmhints = *(reinterpret_cast<QtMWMHints *>(data));
- } else {
- mwmhints.flags = 0L;
- mwmhints.functions = MWM_FUNC_ALL;
- mwmhints.decorations = MWM_DECOR_ALL;
- mwmhints.input_mode = 0L;
- mwmhints.status = 0L;
- }
-
- if (data)
- XFree(data);
-
- return mwmhints;
-}
-
-static void SetMWMHints(Display *display, Window window, const QtMWMHints &mwmhints)
-{
- if (mwmhints.flags != 0l) {
- XChangeProperty(display, window, ATOM(_MOTIF_WM_HINTS), ATOM(_MOTIF_WM_HINTS), 32,
- PropModeReplace, (unsigned char *) &mwmhints, 5);
- } else {
- XDeleteProperty(display, window, ATOM(_MOTIF_WM_HINTS));
- }
-}
-
-// Returns true if we should set WM_TRANSIENT_FOR on \a w
-static inline bool isTransient(const QWidget *w)
-{
- return ((w->windowType() == Qt::Dialog
- || w->windowType() == Qt::Sheet
- || w->windowType() == Qt::Tool
- || w->windowType() == Qt::SplashScreen
- || w->windowType() == Qt::ToolTip
- || w->windowType() == Qt::Drawer
- || w->windowType() == Qt::Popup)
- && !w->testAttribute(Qt::WA_X11BypassTransientForHint));
-}
-
-static void do_size_hints(QWidget* widget, QWExtra *x);
-
-/*****************************************************************************
- QWidget member functions
- *****************************************************************************/
-
-const uint stdWidgetEventMask = // X event mask
- (uint)(
- KeyPressMask | KeyReleaseMask |
- ButtonPressMask | ButtonReleaseMask |
- KeymapStateMask |
- ButtonMotionMask | PointerMotionMask |
- EnterWindowMask | LeaveWindowMask |
- FocusChangeMask |
- ExposureMask |
- PropertyChangeMask |
- StructureNotifyMask
- );
-
-const uint stdDesktopEventMask = // X event mask
- (uint)(
- KeymapStateMask |
- EnterWindowMask | LeaveWindowMask |
- PropertyChangeMask
- );
-
-
-/*
- The qt_ functions below are implemented in qwidgetcreate_x11.cpp.
-*/
-
-Window qt_XCreateWindow(const QWidget *creator,
- Display *display, Window parent,
- int x, int y, uint w, uint h,
- int borderwidth, int depth,
- uint windowclass, Visual *visual,
- ulong valuemask, XSetWindowAttributes *attributes);
-Window qt_XCreateSimpleWindow(const QWidget *creator,
- Display *display, Window parent,
- int x, int y, uint w, uint h, int borderwidth,
- ulong border, ulong background);
-void qt_XDestroyWindow(const QWidget *destroyer,
- Display *display, Window window);
-
-
-static void qt_insert_sip(QWidget* scrolled_widget, int dx, int dy)
-{
- if (!scrolled_widget->isWindow() && !scrolled_widget->internalWinId())
- return;
- QX11Data::ScrollInProgress sip = { X11->sip_serial++, scrolled_widget, dx, dy };
- X11->sip_list.append(sip);
-
- XClientMessageEvent client_message;
- client_message.type = ClientMessage;
- client_message.window = scrolled_widget->internalWinId();
- client_message.format = 32;
- client_message.message_type = ATOM(_QT_SCROLL_DONE);
- client_message.data.l[0] = sip.id;
-
- XSendEvent(X11->display, scrolled_widget->internalWinId(), False, NoEventMask,
- (XEvent*)&client_message);
-}
-
-static int qt_sip_count(QWidget* scrolled_widget)
-{
- int sips=0;
-
- for (int i = 0; i < X11->sip_list.size(); ++i) {
- const QX11Data::ScrollInProgress &sip = X11->sip_list.at(i);
- if (sip.scrolled_widget == scrolled_widget)
- sips++;
- }
-
- return sips;
-}
-
-static void create_wm_client_leader()
-{
- if (X11->wm_client_leader) return;
-
- X11->wm_client_leader =
- XCreateSimpleWindow(X11->display,
- QX11Info::appRootWindow(),
- 0, 0, 1, 1, 0, 0, 0);
-
- // set client leader property to itself
- XChangeProperty(X11->display,
- X11->wm_client_leader, ATOM(WM_CLIENT_LEADER),
- XA_WINDOW, 32, PropModeReplace,
- (unsigned char *)&X11->wm_client_leader, 1);
-
-#ifndef QT_NO_SESSIONMANAGER
- // If we are session managed, inform the window manager about it
- QByteArray session = qApp->sessionId().toLatin1();
- if (!session.isEmpty()) {
- XChangeProperty(X11->display,
- X11->wm_client_leader, ATOM(SM_CLIENT_ID),
- XA_STRING, 8, PropModeReplace,
- (unsigned char *)session.data(), session.size());
- }
-#endif
-}
-
-/*!
- \internal
- Update the X11 cursor of the widget w.
- \a force is true if this function is called from dispatchEnterLeave, it means that the
- mouse is actually directly under this widget.
- */
-void qt_x11_enforce_cursor(QWidget * w, bool force)
-{
- if (!w->testAttribute(Qt::WA_WState_Created))
- return;
-
- static QPointer<QWidget> lastUnderMouse = 0;
- if (force) {
- lastUnderMouse = w;
- } else if (lastUnderMouse && lastUnderMouse->effectiveWinId() == w->effectiveWinId()) {
- w = lastUnderMouse;
- } else if (!w->internalWinId()) {
- return; //the mouse is not under this widget, and it's not native, so don't change it
- }
-
- while (!w->internalWinId() && w->parentWidget() && !w->isWindow() && !w->testAttribute(Qt::WA_SetCursor))
- w = w->parentWidget();
-
- QWidget *nativeParent = w;
- if (!w->internalWinId())
- nativeParent = w->nativeParentWidget();
- // This does the same as effectiveWinId(), but since it is possible
- // to not have a native parent widget due to a special hack in
- // qwidget for reparenting widgets to a different X11 screen,
- // added additional check to make sure native parent widget exists.
- if (!nativeParent || !nativeParent->internalWinId())
- return;
- WId winid = nativeParent->internalWinId();
-
- if (w->isWindow() || w->testAttribute(Qt::WA_SetCursor)) {
-#ifndef QT_NO_CURSOR
- QCursor *oc = QApplication::overrideCursor();
- if (oc) {
- XDefineCursor(X11->display, winid, oc->handle());
- } else if (w->isEnabled()) {
- XDefineCursor(X11->display, winid, w->cursor().handle());
- } else {
- // enforce the windows behavior of clearing the cursor on
- // disabled widgets
- XDefineCursor(X11->display, winid, XNone);
- }
-#endif
- } else {
- XDefineCursor(X11->display, winid, XNone);
- }
-}
-
-Q_GUI_EXPORT void qt_x11_enforce_cursor(QWidget * w)
-{
- qt_x11_enforce_cursor(w, false);
-}
-
-void qt_x11_wait_for_window_manager(QWidget *w, bool sendPostedEvents)
-{
- if (!w || (!w->isWindow() && !w->internalWinId()))
- return;
- QApplication::flush();
- XEvent ev;
- QElapsedTimer t;
- t.start();
- static const int maximumWaitTime = 2000;
- if (!w->testAttribute(Qt::WA_WState_Created))
- return;
-
- WId winid = w->internalWinId();
-
- // first deliver events that are already in the local queue
- if (sendPostedEvents)
- QApplication::sendPostedEvents();
-
- // the normal sequence is:
- // ... ConfigureNotify ... ReparentNotify ... MapNotify ... Expose
- // with X11BypassWindowManagerHint:
- // ConfigureNotify ... MapNotify ... Expose
-
- enum State {
- Initial, Mapped
- } state = Initial;
-
- do {
- if (XEventsQueued(X11->display, QueuedAlready)) {
- XNextEvent(X11->display, &ev);
- qApp->x11ProcessEvent(&ev);
-
- switch (state) {
- case Initial:
- if (ev.type == MapNotify && ev.xany.window == winid)
- state = Mapped;
- break;
- case Mapped:
- if (ev.type == Expose && ev.xany.window == winid)
- return;
- break;
- }
- } else {
- if (!XEventsQueued(X11->display, QueuedAfterFlush))
- qApp->syncX(); // non-busy wait
- }
- if (t.elapsed() > maximumWaitTime)
- return;
- } while(1);
-}
-
-Q_GUI_EXPORT void qt_x11_wait_for_window_manager(QWidget *w)
-{
- qt_x11_wait_for_window_manager(w, true);
-}
-
-void qt_change_net_wm_state(const QWidget* w, bool set, Atom one, Atom two = 0)
-{
- if (!w->isVisible()) // not managed by the window manager
- return;
-
- XEvent e;
- e.xclient.type = ClientMessage;
- e.xclient.message_type = ATOM(_NET_WM_STATE);
- e.xclient.display = X11->display;
- e.xclient.window = w->internalWinId();
- e.xclient.format = 32;
- e.xclient.data.l[0] = set ? 1 : 0;
- e.xclient.data.l[1] = one;
- e.xclient.data.l[2] = two;
- e.xclient.data.l[3] = 0;
- e.xclient.data.l[4] = 0;
- XSendEvent(X11->display, RootWindow(X11->display, w->x11Info().screen()),
- false, (SubstructureNotifyMask | SubstructureRedirectMask), &e);
-}
-
-struct QX11WindowAttributes {
- const XWindowAttributes *att;
-};
-
-void qt_x11_getX11InfoForWindow(QX11Info * xinfo, const XWindowAttributes &a)
-{
- QX11WindowAttributes att;
- att.att = &a;
- qt_x11_getX11InfoForWindow(xinfo,att);
-}
-
-
-static QVector<Atom> getNetWmState(QWidget *w)
-{
- QVector<Atom> returnValue;
-
- // Don't read anything, just get the size of the property data
- Atom actualType;
- int actualFormat;
- ulong propertyLength;
- ulong bytesLeft;
- uchar *propertyData = 0;
- if (XGetWindowProperty(X11->display, w->internalWinId(), ATOM(_NET_WM_STATE), 0, 0,
- False, XA_ATOM, &actualType, &actualFormat,
- &propertyLength, &bytesLeft, &propertyData) == Success
- && actualType == XA_ATOM && actualFormat == 32) {
- returnValue.resize(bytesLeft / 4);
- XFree((char*) propertyData);
- propertyData = 0;
-
- // fetch all data
- if (XGetWindowProperty(X11->display, w->internalWinId(), ATOM(_NET_WM_STATE), 0,
- returnValue.size(), False, XA_ATOM, &actualType, &actualFormat,
- &propertyLength, &bytesLeft, &propertyData) != Success) {
- returnValue.clear();
- } else if (propertyLength != (ulong)returnValue.size()) {
- returnValue.resize(propertyLength);
- }
-
- // put it into netWmState
- if (!returnValue.isEmpty()) {
- memcpy(returnValue.data(), propertyData, returnValue.size() * sizeof(Atom));
- }
- if (propertyData)
- XFree((char*) propertyData);
- }
-
- return returnValue;
-}
-
-void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyOldWindow)
-{
- Q_Q(QWidget);
- Qt::WindowType type = q->windowType();
- Qt::WindowFlags &flags = data.window_flags;
- QWidget *parentWidget = q->parentWidget();
-
- if (type == Qt::ToolTip)
- flags |= Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint;
- if (type == Qt::Popup)
- flags |= Qt::X11BypassWindowManagerHint;
-
- bool topLevel = (flags & Qt::Window);
- bool popup = (type == Qt::Popup);
- bool dialog = (type == Qt::Dialog
- || type == Qt::Sheet);
- bool desktop = (type == Qt::Desktop);
- bool tool = (type == Qt::Tool || type == Qt::SplashScreen
- || type == Qt::ToolTip || type == Qt::Drawer);
-
-#ifdef ALIEN_DEBUG
- qDebug() << "QWidgetPrivate::create_sys START:" << q << "topLevel?" << topLevel << "WId:"
- << window << "initializeWindow:" << initializeWindow << "destroyOldWindow" << destroyOldWindow;
-#endif
- if (topLevel) {
- if (parentWidget) { // if our parent stays on top, so must we
- QWidget *ptl = parentWidget->window();
- if(ptl && (ptl->windowFlags() & Qt::WindowStaysOnTopHint))
- flags |= Qt::WindowStaysOnTopHint;
- }
-
- if (type == Qt::SplashScreen) {
- if (X11->isSupportedByWM(ATOM(_NET_WM_WINDOW_TYPE_SPLASH))) {
- flags &= ~Qt::X11BypassWindowManagerHint;
- } else {
- flags |= Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint;
- }
- }
- // All these buttons depend on the system menu, so we enable it
- if (flags & (Qt::WindowMinimizeButtonHint
- | Qt::WindowMaximizeButtonHint
- | Qt::WindowContextHelpButtonHint))
- flags |= Qt::WindowSystemMenuHint;
- }
-
-
- Window parentw, destroyw = 0;
- WId id = 0;
-
- // always initialize
- if (!window)
- initializeWindow = true;
-
- QX11Info *parentXinfo = parentWidget ? &parentWidget->d_func()->xinfo : 0;
-
- if (desktop &&
- qt_x11_create_desktop_on_screen >= 0 &&
- qt_x11_create_desktop_on_screen != xinfo.screen()) {
- // desktop on a certain screen other than the default requested
- QX11InfoData *xd = &X11->screens[qt_x11_create_desktop_on_screen];
- xinfo.setX11Data(xd);
- } else if (parentXinfo && (parentXinfo->screen() != xinfo.screen()
- || (parentXinfo->visual() != xinfo.visual()
- && !q->inherits("QGLWidget"))))
- {
- // QGLWidgets have to be excluded here as they have a
- // specially crafted QX11Info structure which can't be swapped
- // out with the parent widgets QX11Info. The parent visual,
- // for instance, might not even be GL capable.
- xinfo = *parentXinfo;
- }
-
- //get display, screen number, root window and desktop geometry for
- //the current screen
- Display *dpy = X11->display;
- int scr = xinfo.screen();
- Window root_win = RootWindow(dpy, scr);
- int sw = DisplayWidth(dpy,scr);
- int sh = DisplayHeight(dpy,scr);
-
- if (desktop) { // desktop widget
- dialog = popup = false; // force these flags off
- data.crect.setRect(0, 0, sw, sh);
- } else if (topLevel && !q->testAttribute(Qt::WA_Resized)) {
- QDesktopWidget *desktopWidget = qApp->desktop();
- if (desktopWidget->isVirtualDesktop()) {
- QRect r = desktopWidget->screenGeometry();
- sw = r.width();
- sh = r.height();
- }
-
- int width = sw / 2;
- int height = 4 * sh / 10;
- if (extra) {
- width = qMax(qMin(width, extra->maxw), extra->minw);
- height = qMax(qMin(height, extra->maxh), extra->minh);
- }
- data.crect.setSize(QSize(width, height));
- }
-
- parentw = topLevel ? root_win : parentWidget->effectiveWinId();
-
- XSetWindowAttributes wsa;
-
- if (window) { // override the old window
- if (destroyOldWindow) {
- if (topLevel)
- X11->dndEnable(q, false);
- destroyw = data.winid;
- }
- id = window;
- setWinId(window);
- XWindowAttributes a;
- XGetWindowAttributes(dpy, window, &a);
- data.crect.setRect(a.x, a.y, a.width, a.height);
-
- if (a.map_state == IsUnmapped)
- q->setAttribute(Qt::WA_WState_Visible, false);
- else
- q->setAttribute(Qt::WA_WState_Visible);
-
- qt_x11_getX11InfoForWindow(&xinfo,a);
-
- } else if (desktop) { // desktop widget
-#ifdef QWIDGET_EXTRA_DEBUG
- qDebug() << "create desktop";
-#endif
- id = (WId)parentw; // id = root window
-// QWidget *otherDesktop = find(id); // is there another desktop?
-// if (otherDesktop && otherDesktop->testWFlags(Qt::WPaintDesktop)) {
-// otherDesktop->d->setWinId(0); // remove id from widget mapper
-// d->setWinId(id); // make sure otherDesktop is
-// otherDesktop->d->setWinId(id); // found first
-// } else {
- setWinId(id);
-// }
- } else if (topLevel || q->testAttribute(Qt::WA_NativeWindow) || paintOnScreen()) {
-#ifdef QWIDGET_EXTRA_DEBUG
- static int topLevels = 0;
- static int children = 0;
- if (parentw == root_win)
- qDebug() << "create toplevel" << ++topLevels;
- else
- qDebug() << "create child" << ++children;
-#endif
- QRect safeRect = data.crect; //##### must handle huge sizes as well.... i.e. wrect
- if (safeRect.width() < 1|| safeRect.height() < 1) {
- if (topLevel) {
- // top-levels must be at least 1x1
- safeRect.setSize(safeRect.size().expandedTo(QSize(1, 1)));
- } else {
- // create it way off screen, and rely on
- // setWSGeometry() to do the right thing with it later
- safeRect = QRect(-1000,-1000,1,1);
- }
- }
-#ifndef QT_NO_XRENDER
- int screen = xinfo.screen();
- if (topLevel && X11->use_xrender
- && xinfo.depth() != 32 && X11->argbVisuals[screen]
- && q->testAttribute(Qt::WA_TranslucentBackground))
- {
- QX11InfoData *xd = xinfo.getX11Data(true);
-
- xd->screen = screen;
- xd->visual = X11->argbVisuals[screen];
- xd->colormap = X11->argbColormaps[screen];
- xd->depth = 32;
- xd->defaultVisual = false;
- xd->defaultColormap = false;
- xd->cells = xd->visual->map_entries;
- xinfo.setX11Data(xd);
- }
-#endif
- if (xinfo.defaultVisual() && xinfo.defaultColormap()) {
- id = (WId)qt_XCreateSimpleWindow(q, dpy, parentw,
- safeRect.left(), safeRect.top(),
- safeRect.width(), safeRect.height(),
- 0,
- BlackPixel(dpy, xinfo.screen()),
- WhitePixel(dpy, xinfo.screen()));
- } else {
- wsa.background_pixel = WhitePixel(dpy, xinfo.screen());
- wsa.border_pixel = BlackPixel(dpy, xinfo.screen());
- wsa.colormap = xinfo.colormap();
- id = (WId)qt_XCreateWindow(q, dpy, parentw,
- safeRect.left(), safeRect.top(),
- safeRect.width(), safeRect.height(),
- 0, xinfo.depth(), InputOutput,
- (Visual *) xinfo.visual(),
- CWBackPixel|CWBorderPixel|CWColormap,
- &wsa);
- }
-
- setWinId(id); // set widget id/handle + hd
- }
-
-#ifndef QT_NO_XRENDER
- if (picture) {
- XRenderFreePicture(X11->display, picture);
- picture = 0;
- }
-
- if (X11->use_xrender && !desktop && q->internalWinId()) {
- XRenderPictFormat *format = XRenderFindVisualFormat(dpy, (Visual *) xinfo.visual());
- if (format)
- picture = XRenderCreatePicture(dpy, id, format, 0, 0);
- }
-#endif // QT_NO_XRENDER
-
- QtMWMHints mwmhints;
- mwmhints.flags = 0L;
- mwmhints.functions = 0L;
- mwmhints.decorations = 0;
- mwmhints.input_mode = 0L;
- mwmhints.status = 0L;
-
- if (topLevel) {
- ulong wsa_mask = 0;
- if (type != Qt::SplashScreen) { // && customize) {
- mwmhints.flags |= MWM_HINTS_DECORATIONS;
-
- bool customize = flags & Qt::CustomizeWindowHint;
- if (!(flags & Qt::FramelessWindowHint) && !(customize && !(flags & Qt::WindowTitleHint))) {
- mwmhints.decorations |= MWM_DECOR_BORDER;
- mwmhints.decorations |= MWM_DECOR_RESIZEH;
-
- if (flags & Qt::WindowTitleHint)
- mwmhints.decorations |= MWM_DECOR_TITLE;
-
- if (flags & Qt::WindowSystemMenuHint)
- mwmhints.decorations |= MWM_DECOR_MENU;
-
- if (flags & Qt::WindowMinimizeButtonHint) {
- mwmhints.decorations |= MWM_DECOR_MINIMIZE;
- mwmhints.functions |= MWM_FUNC_MINIMIZE;
- }
-
- if (flags & Qt::WindowMaximizeButtonHint) {
- mwmhints.decorations |= MWM_DECOR_MAXIMIZE;
- mwmhints.functions |= MWM_FUNC_MAXIMIZE;
- }
-
- if (flags & Qt::WindowCloseButtonHint)
- mwmhints.functions |= MWM_FUNC_CLOSE;
- }
- } else {
- // if type == Qt::SplashScreen
- mwmhints.decorations = MWM_DECOR_ALL;
- }
-
- if (tool) {
- wsa.save_under = True;
- wsa_mask |= CWSaveUnder;
- }
-
- if (flags & Qt::X11BypassWindowManagerHint) {
- wsa.override_redirect = True;
- wsa_mask |= CWOverrideRedirect;
- }
-
- if (wsa_mask && initializeWindow) {
- Q_ASSERT(id);
- XChangeWindowAttributes(dpy, id, wsa_mask, &wsa);
- }
-
- if (mwmhints.functions != 0) {
- mwmhints.flags |= MWM_HINTS_FUNCTIONS;
- mwmhints.functions |= MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
- } else {
- mwmhints.functions = MWM_FUNC_ALL;
- }
-
- if (!(flags & Qt::FramelessWindowHint)
- && flags & Qt::CustomizeWindowHint
- && flags & Qt::WindowTitleHint
- && !(flags &
- (Qt::WindowMinimizeButtonHint
- | Qt::WindowMaximizeButtonHint
- | Qt::WindowCloseButtonHint))) {
- // a special case - only the titlebar without any button
- mwmhints.flags = MWM_HINTS_FUNCTIONS;
- mwmhints.functions = MWM_FUNC_MOVE | MWM_FUNC_RESIZE;
- mwmhints.decorations = 0;
- }
- }
-
- if (!initializeWindow) {
- // do no initialization
- } else if (popup) { // popup widget
- // set EWMH window types
- setNetWmWindowTypes();
-
- wsa.override_redirect = True;
- wsa.save_under = True;
- Q_ASSERT(id);
- XChangeWindowAttributes(dpy, id, CWOverrideRedirect | CWSaveUnder,
- &wsa);
- } else if (topLevel && !desktop) { // top-level widget
- if (!X11->wm_client_leader)
- create_wm_client_leader();
-
- // note: WM_TRANSIENT_FOR is set in QWidgetPrivate::show_sys()
-
- XSizeHints size_hints;
- size_hints.flags = USSize | PSize | PWinGravity;
- size_hints.x = data.crect.left();
- size_hints.y = data.crect.top();
- size_hints.width = data.crect.width();
- size_hints.height = data.crect.height();
- size_hints.win_gravity =
- QApplication::isRightToLeft() ? NorthEastGravity : NorthWestGravity;
-
- XWMHints wm_hints; // window manager hints
- memset(&wm_hints, 0, sizeof(wm_hints)); // make valgrind happy
- wm_hints.flags = InputHint | StateHint | WindowGroupHint;
- wm_hints.input = q->testAttribute(Qt::WA_X11DoNotAcceptFocus) ? False : True;
- wm_hints.initial_state = NormalState;
- wm_hints.window_group = X11->wm_client_leader;
-
- XClassHint class_hint;
- QByteArray appName = qAppName().toLatin1();
- class_hint.res_name = appName.data(); // application name
- class_hint.res_class = const_cast<char *>(QX11Info::appClass()); // application class
-
- XSetWMProperties(dpy, id, 0, 0,
- qApp->d_func()->argv, qApp->d_func()->argc,
- &size_hints, &wm_hints, &class_hint);
-
- XResizeWindow(dpy, id,
- qBound(1, data.crect.width(), XCOORD_MAX),
- qBound(1, data.crect.height(), XCOORD_MAX));
- XStoreName(dpy, id, appName.data());
- Atom protocols[5];
- int n = 0;
- protocols[n++] = ATOM(WM_DELETE_WINDOW); // support del window protocol
- protocols[n++] = ATOM(WM_TAKE_FOCUS); // support take focus window protocol
- protocols[n++] = ATOM(_NET_WM_PING); // support _NET_WM_PING protocol
-#ifndef QT_NO_XSYNC
- protocols[n++] = ATOM(_NET_WM_SYNC_REQUEST); // support _NET_WM_SYNC_REQUEST protocol
-#endif // QT_NO_XSYNC
- if (flags & Qt::WindowContextHelpButtonHint)
- protocols[n++] = ATOM(_NET_WM_CONTEXT_HELP);
- XSetWMProtocols(dpy, id, protocols, n);
-
- // set mwm hints
- SetMWMHints(dpy, id, mwmhints);
-
- // set EWMH window types
- setNetWmWindowTypes();
-
- // set _NET_WM_PID
- long curr_pid = getpid();
- XChangeProperty(dpy, id, ATOM(_NET_WM_PID), XA_CARDINAL, 32, PropModeReplace,
- (unsigned char *) &curr_pid, 1);
-
- // when we create a toplevel widget, the frame strut should be dirty
- data.fstrut_dirty = 1;
-
- // declare the widget's window role
- if (QTLWExtra *topData = maybeTopData()) {
- if (!topData->role.isEmpty()) {
- QByteArray windowRole = topData->role.toUtf8();
- XChangeProperty(dpy, id,
- ATOM(WM_WINDOW_ROLE), XA_STRING, 8, PropModeReplace,
- (unsigned char *)windowRole.constData(), windowRole.length());
- }
- }
-
- // set client leader property
- XChangeProperty(dpy, id, ATOM(WM_CLIENT_LEADER),
- XA_WINDOW, 32, PropModeReplace,
- (unsigned char *)&X11->wm_client_leader, 1);
- } else {
- // non-toplevel widgets don't have a frame, so no need to
- // update the strut
- data.fstrut_dirty = 0;
- }
-
- if (initializeWindow && q->internalWinId()) {
- // don't erase when resizing
- wsa.bit_gravity = QApplication::isRightToLeft() ? NorthEastGravity : NorthWestGravity;
- Q_ASSERT(id);
- XChangeWindowAttributes(dpy, id, CWBitGravity, &wsa);
- }
-
- // set X11 event mask
- if (desktop) {
-// QWidget* main_desktop = find(id);
-// if (main_desktop->testWFlags(Qt::WPaintDesktop))
-// XSelectInput(dpy, id, stdDesktopEventMask | ExposureMask);
-// else
- XSelectInput(dpy, id, stdDesktopEventMask);
- } else if (q->internalWinId()) {
- XSelectInput(dpy, id, stdWidgetEventMask);
-#if !defined (QT_NO_TABLET)
- QTabletDeviceDataList *tablet_list = qt_tablet_devices();
- if (X11->ptrXSelectExtensionEvent) {
- for (int i = 0; i < tablet_list->size(); ++i) {
- QTabletDeviceData tablet = tablet_list->at(i);
- X11->ptrXSelectExtensionEvent(dpy, id, reinterpret_cast<XEventClass*>(tablet.eventList),
- tablet.eventCount);
- }
- }
-#endif
- }
-
- if (desktop) {
- q->setAttribute(Qt::WA_WState_Visible);
- } else if (topLevel) { // set X cursor
- if (initializeWindow) {
- qt_x11_enforce_cursor(q);
-
- if (QTLWExtra *topData = maybeTopData())
- if (!topData->caption.isEmpty())
- setWindowTitle_helper(topData->caption);
-
- //always enable dnd: it's not worth the effort to maintain the state
- // NOTE: this always creates topData()
- X11->dndEnable(q, true);
-
- if (maybeTopData() && maybeTopData()->opacity != 255)
- q->setWindowOpacity(maybeTopData()->opacity/255.);
-
- }
- } else if (q->internalWinId()) {
- qt_x11_enforce_cursor(q);
- if (QWidget *p = q->parentWidget()) // reset the cursor on the native parent
- qt_x11_enforce_cursor(p);
- }
-
- if (extra && !extra->mask.isEmpty() && q->internalWinId())
- XShapeCombineRegion(X11->display, q->internalWinId(), ShapeBounding, 0, 0,
- extra->mask.handle(), ShapeSet);
-
- if (q->hasFocus() && q->testAttribute(Qt::WA_InputMethodEnabled)) {
- QInputContext *inputContext = q->inputContext();
- if (inputContext)
- inputContext->setFocusWidget(q);
- }
-
- if (destroyw) {
- qt_XDestroyWindow(q, dpy, destroyw);
- if (QTLWExtra *topData = maybeTopData()) {
-#ifndef QT_NO_XSYNC
- if (topData->syncUpdateCounter)
- XSyncDestroyCounter(dpy, topData->syncUpdateCounter);
-#endif
- // we destroyed our old window - reset the top-level state
- createTLSysExtra();
- }
- }
-
- // newly created windows are positioned at the window system's
- // (0,0) position. If the parent uses wrect mapping to expand the
- // coordinate system, we must also adjust this widget's window
- // system position
- if (!topLevel && !parentWidget->data->wrect.topLeft().isNull())
- setWSGeometry();
- else if (topLevel && (data.crect.width() == 0 || data.crect.height() == 0))
- q->setAttribute(Qt::WA_OutsideWSRange, true);
-
- if (!topLevel && q->testAttribute(Qt::WA_NativeWindow) && q->testAttribute(Qt::WA_Mapped)) {
- Q_ASSERT(q->internalWinId());
- XMapWindow(X11->display, q->internalWinId());
- // Ensure that mapped alien widgets are flushed immediately when re-created as native widgets.
- if (QWindowSurface *surface = q->windowSurface())
- surface->flush(q, q->rect(), q->mapTo(surface->window(), QPoint()));
- }
-
-#ifdef ALIEN_DEBUG
- qDebug() << "QWidgetPrivate::create_sys END:" << q;
-#endif
-}
-
-static void qt_x11_recreateWidget(QWidget *widget)
-{
- if (widget->inherits("QGLWidget")) {
- // We send QGLWidgets a ParentChange event which causes them to
- // recreate their GL context, which in turn causes them to choose
- // their visual again. Now that WA_TranslucentBackground is set,
- // QGLContext::chooseVisual will select an ARGB visual.
- QEvent e(QEvent::ParentChange);
- QApplication::sendEvent(widget, &e);
- } else {
- // For regular widgets, reparent them with their parent which
- // also triggers a recreation of the native window
- QPoint pos = widget->pos();
- bool visible = widget->isVisible();
- if (visible)
- widget->hide();
-
- widget->setParent(widget->parentWidget(), widget->windowFlags());
- widget->move(pos);
- if (visible)
- widget->show();
- }
-}
-
-static void qt_x11_recreateNativeWidgetsRecursive(QWidget *widget)
-{
- if (widget->internalWinId())
- qt_x11_recreateWidget(widget);
-
- const QObjectList &children = widget->children();
- for (int i = 0; i < children.size(); ++i) {
- QWidget *child = qobject_cast<QWidget*>(children.at(i));
- if (child)
- qt_x11_recreateNativeWidgetsRecursive(child);
- }
-}
-
-void QWidgetPrivate::x11UpdateIsOpaque()
-{
-#ifndef QT_NO_XRENDER
- Q_Q(QWidget);
- if (!q->testAttribute(Qt::WA_WState_Created) || !q->testAttribute(Qt::WA_TranslucentBackground))
- return;
-
- bool topLevel = (data.window_flags & Qt::Window);
- int screen = xinfo.screen();
- if (topLevel && X11->use_xrender
- && X11->argbVisuals[screen] && xinfo.depth() != 32)
- {
- qt_x11_recreateNativeWidgetsRecursive(q);
- }
-#endif
-}
-
-/*
- Returns true if the background is inherited; otherwise returns
- false.
-
- Mainly used in the paintOnScreen case.
-*/
-bool QWidgetPrivate::isBackgroundInherited() const
-{
- Q_Q(const QWidget);
-
- // windows do not inherit their background
- if (q->isWindow() || q->windowType() == Qt::SubWindow)
- return false;
-
- if (q->testAttribute(Qt::WA_NoSystemBackground) || q->testAttribute(Qt::WA_OpaquePaintEvent))
- return false;
-
- const QPalette &pal = q->palette();
- QPalette::ColorRole bg = q->backgroundRole();
- QBrush brush = pal.brush(bg);
-
- // non opaque brushes leaves us no choice, we must inherit
- if (!q->autoFillBackground() || !brush.isOpaque())
- return true;
-
- if (brush.style() == Qt::SolidPattern) {
- // the background is just a solid color. If there is no
- // propagated contents, then we claim as performance
- // optimization that it was not inheritet. This is the normal
- // case in standard Windows or Motif style.
- const QWidget *w = q->parentWidget();
- if (!w->d_func()->isBackgroundInherited())
- return false;
- }
-
- return true;
-}
-
-void QWidget::destroy(bool destroyWindow, bool destroySubWindows)
-{
- Q_D(QWidget);
- d->aboutToDestroy();
- if (!isWindow() && parentWidget())
- parentWidget()->d_func()->invalidateBuffer(d->effectiveRectFor(geometry()));
- d->deactivateWidgetCleanup();
- if (testAttribute(Qt::WA_WState_Created)) {
- setAttribute(Qt::WA_WState_Created, false);
- QObjectList childList = children();
- for (int i = 0; i < childList.size(); ++i) { // destroy all widget children
- register QObject *obj = childList.at(i);
- if (obj->isWidgetType())
- static_cast<QWidget*>(obj)->destroy(destroySubWindows,
- destroySubWindows);
- }
- if (QWidgetPrivate::mouseGrabber == this)
- releaseMouse();
- if (QWidgetPrivate::keyboardGrabber == this)
- releaseKeyboard();
- if (isWindow())
- X11->deferred_map.removeAll(this);
- if (isModal()) {
- // just be sure we leave modal
- QApplicationPrivate::leaveModal(this);
- }
- else if ((windowType() == Qt::Popup))
- qApp->d_func()->closePopup(this);
-
-#ifndef QT_NO_XRENDER
- if (d->picture) {
- if (destroyWindow)
- XRenderFreePicture(X11->display, d->picture);
- d->picture = 0;
- }
-#endif // QT_NO_XRENDER
-
- // delete the _NET_WM_USER_TIME_WINDOW
- qt_net_remove_user_time(this);
-
- if ((windowType() == Qt::Desktop)) {
- if (acceptDrops())
- X11->dndEnable(this, false);
- } else {
- if (isWindow())
- X11->dndEnable(this, false);
- if (destroyWindow)
- qt_XDestroyWindow(this, X11->display, data->winid);
- }
- QT_TRY {
- d->setWinId(0);
- } QT_CATCH (const std::bad_alloc &) {
- // swallow - destructors must not throw
- }
-
- extern void qPRCleanup(QWidget *widget); // from qapplication_x11.cpp
- if (testAttribute(Qt::WA_WState_Reparented))
- qPRCleanup(this);
-
- if(d->ic) {
- delete d->ic;
- } else {
- // release previous focus information participating with
- // preedit preservation of qic
- QInputContext *qic = QApplicationPrivate::inputContext;
- if (qic)
- qic->widgetDestroyed(this);
- }
- }
-}
-
-void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
-{
- Q_Q(QWidget);
-#ifdef ALIEN_DEBUG
- qDebug() << "QWidgetPrivate::setParent_sys START" << q << "parent:" << parent;
-#endif
- QX11Info old_xinfo = xinfo;
- if (parent && parent->windowType() == Qt::Desktop) {
- // make sure the widget is created on the same screen as the
- // programmer specified desktop widget
- xinfo = parent->d_func()->xinfo;
- parent = 0;
- }
-
- QTLWExtra *topData = maybeTopData();
- bool wasCreated = q->testAttribute(Qt::WA_WState_Created);
- if (q->isVisible() && q->parentWidget() && parent != q->parentWidget())
- q->parentWidget()->d_func()->invalidateBuffer(effectiveRectFor(q->geometry()));
- extern void qPRCreate(const QWidget *, Window);
-#ifndef QT_NO_CURSOR
- QCursor oldcurs;
-#endif
-
- // dnd unregister (we will register again below)
- if (q->testAttribute(Qt::WA_DropSiteRegistered))
- q->setAttribute(Qt::WA_DropSiteRegistered, false);
-
- // if we are a top then remove our dnd prop for now
- // it will get rest later
- if (q->isWindow() && wasCreated)
- X11->dndEnable(q, false);
-
- if (topData)
- qt_net_remove_user_time(q);
-
-// QWidget *oldparent = q->parentWidget();
- WId old_winid = wasCreated ? data.winid : 0;
- if ((q->windowType() == Qt::Desktop))
- old_winid = 0;
- setWinId(0);
-
-#ifndef QT_NO_XRENDER
- if (picture) {
- XRenderFreePicture(X11->display, picture);
- picture = 0;
- }
-#endif
-
- // hide and reparent our own window away. Otherwise we might get
- // destroyed when emitting the child remove event below. See QWorkspace.
- if (wasCreated && old_winid) {
- XUnmapWindow(X11->display, old_winid);
- if (!old_xinfo.screen() != xinfo.screen())
- XReparentWindow(X11->display, old_winid, RootWindow(X11->display, xinfo.screen()), 0, 0);
- }
- if (topData) {
- topData->parentWinId = 0;
- // zero the frame strut and mark it dirty
- topData->frameStrut.setCoords(0, 0, 0, 0);
-
- // reparenting from top-level, make sure show() works again
- topData->waitingForMapNotify = 0;
- topData->validWMState = 0;
- }
- data.fstrut_dirty = (!parent || (f & Qt::Window)); // toplevels get a dirty framestrut
-
- QObjectPrivate::setParent_helper(parent);
- bool explicitlyHidden = q->testAttribute(Qt::WA_WState_Hidden) && q->testAttribute(Qt::WA_WState_ExplicitShowHide);
-
- data.window_flags = f;
- q->setAttribute(Qt::WA_WState_Created, false);
- q->setAttribute(Qt::WA_WState_Visible, false);
- q->setAttribute(Qt::WA_WState_Hidden, false);
- adjustFlags(data.window_flags, q);
- // keep compatibility with previous versions, we need to preserve the created state
- // (but we recreate the winId for the widget being reparented, again for compatibility)
- if (wasCreated)
- createWinId();
- if (q->isWindow() || (!parent || parent->isVisible()) || explicitlyHidden)
- q->setAttribute(Qt::WA_WState_Hidden);
- q->setAttribute(Qt::WA_WState_ExplicitShowHide, explicitlyHidden);
-
- if (wasCreated) {
- QObjectList chlist = q->children();
- for (int i = 0; i < chlist.size(); ++i) { // reparent children
- QObject *obj = chlist.at(i);
- if (obj->isWidgetType()) {
- QWidget *w = (QWidget *)obj;
- if (!w->testAttribute(Qt::WA_WState_Created))
- continue;
- if (xinfo.screen() != w->d_func()->xinfo.screen()) {
- // ### force setParent() to not shortcut out (because
- // ### we're setting the parent to the current parent)
- // ### setParent will add child back to the list
- // ### of children so we need to make sure the
- // ### widget won't be added twice.
- w->d_func()->parent = 0;
- this->children.removeOne(w);
- w->setParent(q);
- } else if (!w->isWindow()) {
- w->d_func()->invalidateBuffer(w->rect());
- if (w->internalWinId()) {
- if (w->testAttribute(Qt::WA_NativeWindow)) {
- QWidget *nativeParentWidget = w->nativeParentWidget();
- // Qt::WA_NativeWindow ensures that we always have a nativeParentWidget
- Q_ASSERT(nativeParentWidget != 0);
- QPoint p = w->mapTo(nativeParentWidget, QPoint());
- XReparentWindow(X11->display,
- w->internalWinId(),
- nativeParentWidget->internalWinId(),
- p.x(), p.y());
- } else {
- w->d_func()->setParent_sys(q, w->data->window_flags);
- }
- }
- } else if (isTransient(w)) {
- /*
- when reparenting toplevel windows with toplevel-transient children,
- we need to make sure that the window manager gets the updated
- WM_TRANSIENT_FOR information... unfortunately, some window managers
- don't handle changing WM_TRANSIENT_FOR before the toplevel window is
- visible, so we unmap and remap all toplevel-transient children *after*
- the toplevel parent has been mapped. thankfully, this is easy in Qt :)
-
- note that the WM_TRANSIENT_FOR hint is actually updated in
- QWidgetPrivate::show_sys()
- */
- if (w->internalWinId())
- XUnmapWindow(X11->display, w->internalWinId());
- QApplication::postEvent(w, new QEvent(QEvent::ShowWindowRequest));
- }
- }
- }
- qPRCreate(q, old_winid);
- updateSystemBackground();
-
- if (old_winid) {
- Window *cmwret;
- int count;
- if (XGetWMColormapWindows(X11->display, old_winid, &cmwret, &count)) {
- Window *cmw;
- int cmw_size = sizeof(Window)*count;
- cmw = new Window[count];
- memcpy((char *)cmw, (char *)cmwret, cmw_size);
- XFree((char *)cmwret);
- int i;
- for (i=0; i<count; i++) {
- if (cmw[i] == old_winid) {
- cmw[i] = q->internalWinId();
- break;
- }
- }
- int top_count;
- if (XGetWMColormapWindows(X11->display, q->window()->internalWinId(),
- &cmwret, &top_count))
- {
- Window *merged_cmw = new Window[count + top_count];
- memcpy((char *)merged_cmw, (char *)cmw, cmw_size);
- memcpy((char *)merged_cmw + cmw_size, (char *)cmwret, sizeof(Window)*top_count);
- delete [] cmw;
- XFree((char *)cmwret);
- cmw = merged_cmw;
- count += top_count;
- }
-
- XSetWMColormapWindows(X11->display, q->window()->internalWinId(), cmw, count);
- delete [] cmw;
- }
-
- qt_XDestroyWindow(q, X11->display, old_winid);
- }
- }
-
- // check if we need to register our dropsite
- if (q->testAttribute(Qt::WA_AcceptDrops)
- || (!q->isWindow() && q->parentWidget() && q->parentWidget()->testAttribute(Qt::WA_DropSiteRegistered))) {
- q->setAttribute(Qt::WA_DropSiteRegistered, true);
- }
-#if !defined(QT_NO_IM)
- ic = 0;
-#endif
- invalidateBuffer(q->rect());
-#ifdef ALIEN_DEBUG
- qDebug() << "QWidgetPrivate::setParent_sys END" << q;
-#endif
-}
-
-QPoint QWidgetPrivate::mapToGlobal(const QPoint &pos) const
-{
- Q_Q(const QWidget);
- if (!q->testAttribute(Qt::WA_WState_Created) || !q->internalWinId()) {
- QPoint p = pos + q->data->crect.topLeft();
- //cannot trust that !isWindow() implies parentWidget() before create
- return (q->isWindow() || !q->parentWidget()) ? p : q->parentWidget()->d_func()->mapToGlobal(p);
- }
- int x, y;
- Window child;
- QPoint p = mapToWS(pos);
- XTranslateCoordinates(X11->display, q->internalWinId(),
- QApplication::desktop()->screen(xinfo.screen())->internalWinId(),
- p.x(), p.y(), &x, &y, &child);
- return QPoint(x, y);
-}
-
-QPoint QWidgetPrivate::mapFromGlobal(const QPoint &pos) const
-{
- Q_Q(const QWidget);
- if (!q->testAttribute(Qt::WA_WState_Created) || !q->internalWinId()) {
- //cannot trust that !isWindow() implies parentWidget() before create
- QPoint p = (q->isWindow() || !q->parentWidget()) ? pos : q->parentWidget()->d_func()->mapFromGlobal(pos);
- return p - q->data->crect.topLeft();
- }
- int x, y;
- Window child;
- XTranslateCoordinates(X11->display,
- QApplication::desktop()->screen(xinfo.screen())->internalWinId(),
- q->internalWinId(), pos.x(), pos.y(), &x, &y, &child);
- return mapFromWS(QPoint(x, y));
-}
-
-QPoint QWidget::mapToGlobal(const QPoint &pos) const
-{
- Q_D(const QWidget);
- QPoint offset = data->crect.topLeft();
- const QWidget *w = this;
- const QWidget *p = w->parentWidget();
- while (!w->isWindow() && p) {
- w = p;
- p = p->parentWidget();
- offset += w->data->crect.topLeft();
- }
-
- const QWidgetPrivate *wd = w->d_func();
- QTLWExtra *tlw = wd->topData();
- if (!tlw->embedded)
- return pos + offset;
-
- return d->mapToGlobal(pos);
-}
-
-QPoint QWidget::mapFromGlobal(const QPoint &pos) const
-{
- Q_D(const QWidget);
- QPoint offset = data->crect.topLeft();
- const QWidget *w = this;
- const QWidget *p = w->parentWidget();
- while (!w->isWindow() && p) {
- w = p;
- p = p->parentWidget();
- offset += w->data->crect.topLeft();
- }
-
- const QWidgetPrivate *wd = w->d_func();
- QTLWExtra *tlw = wd->topData();
- if (!tlw->embedded)
- return pos - offset;
-
- return d->mapFromGlobal(pos);
-}
-
-void QWidgetPrivate::updateSystemBackground()
-{
- Q_Q(QWidget);
- if (!q->testAttribute(Qt::WA_WState_Created) || !q->internalWinId())
- return;
- QBrush brush = q->palette().brush(QPalette::Active, q->backgroundRole());
- Qt::WindowType type = q->windowType();
- if (brush.style() == Qt::NoBrush
- || q->testAttribute(Qt::WA_NoSystemBackground)
- || q->testAttribute(Qt::WA_UpdatesDisabled)
- || type == Qt::Popup || type == Qt::ToolTip) {
- if (QX11Info::isCompositingManagerRunning()
- && q->testAttribute(Qt::WA_TranslucentBackground)
- && !(q->parent()))
- XSetWindowBackground(X11->display, q->internalWinId(),
- QColormap::instance(xinfo.screen()).pixel(Qt::transparent));
- else
- XSetWindowBackgroundPixmap(X11->display, q->internalWinId(), XNone);
- }
- else if (brush.style() == Qt::SolidPattern && brush.isOpaque())
- XSetWindowBackground(X11->display, q->internalWinId(),
- QColormap::instance(xinfo.screen()).pixel(brush.color()));
- else if (isBackgroundInherited())
- XSetWindowBackgroundPixmap(X11->display, q->internalWinId(), ParentRelative);
- else if (brush.style() == Qt::TexturePattern) {
- extern QPixmap qt_toX11Pixmap(const QPixmap &pixmap); // qpixmap_x11.cpp
- XSetWindowBackgroundPixmap(X11->display, q->internalWinId(),
- static_cast<QX11PixmapData*>(qt_toX11Pixmap(brush.texture()).data.data())->x11ConvertToDefaultDepth());
- } else
- XSetWindowBackground(X11->display, q->internalWinId(),
- QColormap::instance(xinfo.screen()).pixel(brush.color()));
-}
-
-#ifndef QT_NO_CURSOR
-void QWidgetPrivate::setCursor_sys(const QCursor &)
-{
- Q_Q(QWidget);
- qt_x11_enforce_cursor(q);
- XFlush(X11->display);
-}
-
-void QWidgetPrivate::unsetCursor_sys()
-{
- Q_Q(QWidget);
- qt_x11_enforce_cursor(q);
- XFlush(X11->display);
-}
-#endif
-
-static XTextProperty*
-qstring_to_xtp(const QString& s)
-{
- static XTextProperty tp = { 0, 0, 0, 0 };
- static bool free_prop = true; // we can't free tp.value in case it references
- // the data of the static QCString below.
- if (tp.value) {
- if (free_prop)
- XFree(tp.value);
- tp.value = 0;
- free_prop = true;
- }
-
- static const QTextCodec* mapper = QTextCodec::codecForLocale();
- int errCode = 0;
- if (mapper) {
- QByteArray mapped = mapper->fromUnicode(s);
- char* tl[2];
- tl[0] = mapped.data();
- tl[1] = 0;
- errCode = XmbTextListToTextProperty(X11->display, tl, 1, XStdICCTextStyle, &tp);
-#if defined(QT_DEBUG)
- if (errCode < 0)
- qDebug("qstring_to_xtp result code %d", errCode);
-#endif
- }
- if (!mapper || errCode < 0) {
- static QByteArray qcs;
- qcs = s.toAscii();
- tp.value = (uchar*)qcs.data();
- tp.encoding = XA_STRING;
- tp.format = 8;
- tp.nitems = qcs.length();
- free_prop = false;
- }
-
- // ### If we knew WM could understand unicode, we could use
- // ### a much simpler, cheaper encoding...
- /*
- tp.value = (XChar2b*)s.unicode();
- tp.encoding = XA_UNICODE; // wish
- tp.format = 16;
- tp.nitems = s.length();
- */
-
- return &tp;
-}
-
-void QWidgetPrivate::setWindowTitle_sys(const QString &caption)
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- if (!q->internalWinId())
- return;
- XSetWMName(X11->display, q->internalWinId(), qstring_to_xtp(caption));
-
- QByteArray net_wm_name = caption.toUtf8();
- XChangeProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_NAME), ATOM(UTF8_STRING), 8,
- PropModeReplace, (unsigned char *)net_wm_name.data(), net_wm_name.size());
-}
-
-void QWidgetPrivate::setWindowIcon_sys(bool forceReset)
-{
- Q_Q(QWidget);
- if (!q->testAttribute(Qt::WA_WState_Created))
- return;
- QTLWExtra *topData = this->topData();
- if (topData->iconPixmap && !forceReset)
- // already been set
- return;
-
- // preparing images to set the _NET_WM_ICON property
- QIcon icon = q->windowIcon();
- QVector<long> icon_data;
- Qt::HANDLE pixmap_handle = 0;
- if (!icon.isNull()) {
- QList<QSize> availableSizes = icon.availableSizes();
- if(availableSizes.isEmpty()) {
- // try to use default sizes since the icon can be a scalable image like svg.
- availableSizes.push_back(QSize(16,16));
- availableSizes.push_back(QSize(32,32));
- availableSizes.push_back(QSize(64,64));
- availableSizes.push_back(QSize(128,128));
- }
- for(int i = 0; i < availableSizes.size(); ++i) {
- QSize size = availableSizes.at(i);
- QPixmap pixmap = icon.pixmap(size);
- if (!pixmap.isNull()) {
- QImage image = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
- int pos = icon_data.size();
- icon_data.resize(pos + 2 + image.width()*image.height());
- icon_data[pos++] = image.width();
- icon_data[pos++] = image.height();
- if (sizeof(long) == sizeof(quint32)) {
- memcpy(icon_data.data() + pos, image.scanLine(0), image.byteCount());
- } else {
- for (int y = 0; y < image.height(); ++y) {
- uint *scanLine = reinterpret_cast<uint *>(image.scanLine(y));
- for (int x = 0; x < image.width(); ++x)
- icon_data[pos + y*image.width() + x] = scanLine[x];
- }
- }
- }
- }
- if (!icon_data.isEmpty()) {
- extern QPixmap qt_toX11Pixmap(const QPixmap &pixmap);
- /*
- if the app is running on an unknown desktop, or it is not
- using the default visual, convert the icon to 1bpp as stated
- in the ICCCM section 4.1.2.4; otherwise, create the icon pixmap
- in the default depth (even though this violates the ICCCM)
- */
- if (X11->desktopEnvironment == DE_UNKNOWN
- || !QX11Info::appDefaultVisual(xinfo.screen())
- || !QX11Info::appDefaultColormap(xinfo.screen())) {
- // unknown DE or non-default visual/colormap, use 1bpp bitmap
- if (!forceReset || !topData->iconPixmap)
- topData->iconPixmap = new QPixmap(qt_toX11Pixmap(QBitmap(icon.pixmap(QSize(64,64)))));
- pixmap_handle = topData->iconPixmap->handle();
- } else {
- // default depth, use a normal pixmap (even though this
- // violates the ICCCM), since this works on all DEs known to Qt
- if (!forceReset || !topData->iconPixmap)
- topData->iconPixmap = new QPixmap(qt_toX11Pixmap(icon.pixmap(QSize(64,64))));
- pixmap_handle = static_cast<QX11PixmapData*>(topData->iconPixmap->data.data())->x11ConvertToDefaultDepth();
- }
- }
- }
-
- if (!q->internalWinId())
- return;
-
- if (!icon_data.isEmpty()) {
- XChangeProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_ICON), XA_CARDINAL, 32,
- PropModeReplace, (unsigned char *) icon_data.data(),
- icon_data.size());
- } else {
- XDeleteProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_ICON));
- }
-
- XWMHints *h = XGetWMHints(X11->display, q->internalWinId());
- XWMHints wm_hints;
- if (!h) {
- memset(&wm_hints, 0, sizeof(wm_hints)); // make valgrind happy
- h = &wm_hints;
- }
-
- if (pixmap_handle) {
- h->icon_pixmap = pixmap_handle;
- h->flags |= IconPixmapHint;
- } else {
- h->icon_pixmap = 0;
- h->flags &= ~(IconPixmapHint | IconMaskHint);
- }
-
- XSetWMHints(X11->display, q->internalWinId(), h);
- if (h != &wm_hints)
- XFree((char *)h);
-}
-
-void QWidgetPrivate::setWindowIconText_sys(const QString &iconText)
-{
- Q_Q(QWidget);
- if (!q->internalWinId())
- return;
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- XSetWMIconName(X11->display, q->internalWinId(), qstring_to_xtp(iconText));
-
- QByteArray icon_name = iconText.toUtf8();
- XChangeProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_ICON_NAME), ATOM(UTF8_STRING), 8,
- PropModeReplace, (unsigned char *) icon_name.constData(), icon_name.size());
-}
-
-
-void QWidget::grabMouse()
-{
- if (isVisible() && !qt_nograb()) {
- if (QWidgetPrivate::mouseGrabber && QWidgetPrivate::mouseGrabber != this)
- QWidgetPrivate::mouseGrabber->releaseMouse();
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
-#ifndef QT_NO_DEBUG
- int status =
-#endif
- XGrabPointer(X11->display, effectiveWinId(), False,
- (uint)(ButtonPressMask | ButtonReleaseMask |
- PointerMotionMask | EnterWindowMask |
- LeaveWindowMask),
- GrabModeAsync, GrabModeAsync,
- XNone, XNone, X11->time);
-#ifndef QT_NO_DEBUG
- if (status) {
- const char *s =
- status == GrabNotViewable ? "\"GrabNotViewable\"" :
- status == AlreadyGrabbed ? "\"AlreadyGrabbed\"" :
- status == GrabFrozen ? "\"GrabFrozen\"" :
- status == GrabInvalidTime ? "\"GrabInvalidTime\"" :
- "<?>";
- qWarning("QWidget::grabMouse: Failed with %s", s);
- }
-#endif
- QWidgetPrivate::mouseGrabber = this;
- }
-}
-
-
-#ifndef QT_NO_CURSOR
-void QWidget::grabMouse(const QCursor &cursor)
-{
- if (!qt_nograb()) {
- if (QWidgetPrivate::mouseGrabber && QWidgetPrivate::mouseGrabber != this)
- QWidgetPrivate::mouseGrabber->releaseMouse();
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
-#ifndef QT_NO_DEBUG
- int status =
-#endif
- XGrabPointer(X11->display, effectiveWinId(), False,
- (uint)(ButtonPressMask | ButtonReleaseMask |
- PointerMotionMask | EnterWindowMask | LeaveWindowMask),
- GrabModeAsync, GrabModeAsync,
- XNone, cursor.handle(), X11->time);
-#ifndef QT_NO_DEBUG
- if (status) {
- const char *s =
- status == GrabNotViewable ? "\"GrabNotViewable\"" :
- status == AlreadyGrabbed ? "\"AlreadyGrabbed\"" :
- status == GrabFrozen ? "\"GrabFrozen\"" :
- status == GrabInvalidTime ? "\"GrabInvalidTime\"" :
- "<?>";
- qWarning("QWidget::grabMouse: Failed with %s", s);
- }
-#endif
- QWidgetPrivate::mouseGrabber = this;
- }
-}
-#endif
-
-
-void QWidget::releaseMouse()
-{
- if (!qt_nograb() && QWidgetPrivate::mouseGrabber == this) {
- XUngrabPointer(X11->display, X11->time);
- XFlush(X11->display);
- QWidgetPrivate::mouseGrabber = 0;
- }
-}
-
-
-void QWidget::grabKeyboard()
-{
- if (!qt_nograb()) {
- if (QWidgetPrivate::keyboardGrabber && QWidgetPrivate::keyboardGrabber != this)
- QWidgetPrivate::keyboardGrabber->releaseKeyboard();
- XGrabKeyboard(X11->display, effectiveWinId(), False, GrabModeAsync, GrabModeAsync,
- X11->time);
- QWidgetPrivate::keyboardGrabber = this;
- }
-}
-
-
-void QWidget::releaseKeyboard()
-{
- if (!qt_nograb() && QWidgetPrivate::keyboardGrabber == this) {
- XUngrabKeyboard(X11->display, X11->time);
- QWidgetPrivate::keyboardGrabber = 0;
- }
-}
-
-
-QWidget *QWidget::mouseGrabber()
-{
- return QWidgetPrivate::mouseGrabber;
-}
-
-
-QWidget *QWidget::keyboardGrabber()
-{
- return QWidgetPrivate::keyboardGrabber;
-}
-
-void QWidget::activateWindow()
-{
- QWidget *tlw = window();
- if (tlw->isVisible() && !tlw->d_func()->topData()->embedded && !X11->deferred_map.contains(tlw)) {
- if (X11->userTime == 0)
- X11->userTime = X11->time;
- qt_net_update_user_time(tlw, X11->userTime);
-
- if (X11->isSupportedByWM(ATOM(_NET_ACTIVE_WINDOW))
- && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint)) {
- XEvent e;
- e.xclient.type = ClientMessage;
- e.xclient.message_type = ATOM(_NET_ACTIVE_WINDOW);
- e.xclient.display = X11->display;
- e.xclient.window = tlw->internalWinId();
- e.xclient.format = 32;
- e.xclient.data.l[0] = 1; // 1 == application
- e.xclient.data.l[1] = X11->userTime;
- if (QWidget *aw = QApplication::activeWindow())
- e.xclient.data.l[2] = aw->internalWinId();
- else
- e.xclient.data.l[2] = XNone;
- e.xclient.data.l[3] = 0;
- e.xclient.data.l[4] = 0;
- XSendEvent(X11->display, RootWindow(X11->display, tlw->x11Info().screen()),
- false, SubstructureNotifyMask | SubstructureRedirectMask, &e);
- } else {
- if (!qt_widget_private(tlw)->topData()->waitingForMapNotify)
- XSetInputFocus(X11->display, tlw->internalWinId(), XRevertToParent, X11->time);
- }
- }
-}
-
-void QWidget::setWindowState(Qt::WindowStates newstate)
-{
- Q_D(QWidget);
- bool needShow = false;
- Qt::WindowStates oldstate = windowState();
- if (oldstate == newstate)
- return;
- if (isWindow()) {
- // Ensure the initial size is valid, since we store it as normalGeometry below.
- if (!testAttribute(Qt::WA_Resized) && !isVisible())
- adjustSize();
-
- QTLWExtra *top = d->topData();
-
- if ((oldstate & Qt::WindowMaximized) != (newstate & Qt::WindowMaximized)) {
- if (X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ))
- && X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_VERT))) {
- if ((newstate & Qt::WindowMaximized) && !(oldstate & Qt::WindowFullScreen))
- top->normalGeometry = geometry();
- qt_change_net_wm_state(this, (newstate & Qt::WindowMaximized),
- ATOM(_NET_WM_STATE_MAXIMIZED_HORZ),
- ATOM(_NET_WM_STATE_MAXIMIZED_VERT));
- } else if (! (newstate & Qt::WindowFullScreen)) {
- if (newstate & Qt::WindowMaximized) {
- // save original geometry
- const QRect normalGeometry = geometry();
-
- if (isVisible()) {
- data->fstrut_dirty = true;
- const QRect maxRect = QApplication::desktop()->availableGeometry(this);
- const QRect r = top->normalGeometry;
- const QRect fs = d->frameStrut();
- setGeometry(maxRect.x() + fs.left(),
- maxRect.y() + fs.top(),
- maxRect.width() - fs.left() - fs.right(),
- maxRect.height() - fs.top() - fs.bottom());
- top->normalGeometry = r;
- }
-
- if (top->normalGeometry.width() < 0)
- top->normalGeometry = normalGeometry;
- } else {
- // restore original geometry
- setGeometry(top->normalGeometry);
- }
- }
- }
-
- if ((oldstate & Qt::WindowFullScreen) != (newstate & Qt::WindowFullScreen)) {
- if (X11->isSupportedByWM(ATOM(_NET_WM_STATE_FULLSCREEN))) {
- if (newstate & Qt::WindowFullScreen) {
- top->normalGeometry = geometry();
- top->fullScreenOffset = d->frameStrut().topLeft();
- }
- qt_change_net_wm_state(this, (newstate & Qt::WindowFullScreen),
- ATOM(_NET_WM_STATE_FULLSCREEN));
- } else {
- needShow = isVisible();
-
- if (newstate & Qt::WindowFullScreen) {
- data->fstrut_dirty = true;
- const QRect normalGeometry = geometry();
- const QPoint fullScreenOffset = d->frameStrut().topLeft();
-
- top->savedFlags = windowFlags();
- setParent(0, Qt::Window | Qt::FramelessWindowHint);
- const QRect r = top->normalGeometry;
- setGeometry(qApp->desktop()->screenGeometry(this));
- top->normalGeometry = r;
-
- if (top->normalGeometry.width() < 0) {
- top->normalGeometry = normalGeometry;
- top->fullScreenOffset = fullScreenOffset;
- }
- } else {
- setParent(0, top->savedFlags);
-
- if (newstate & Qt::WindowMaximized) {
- // from fullscreen to maximized
- data->fstrut_dirty = true;
- const QRect maxRect = QApplication::desktop()->availableGeometry(this);
- const QRect r = top->normalGeometry;
- const QRect fs = d->frameStrut();
- setGeometry(maxRect.x() + fs.left(),
- maxRect.y() + fs.top(),
- maxRect.width() - fs.left() - fs.right(),
- maxRect.height() - fs.top() - fs.bottom());
- top->normalGeometry = r;
- } else {
- // restore original geometry
- setGeometry(top->normalGeometry.adjusted(-top->fullScreenOffset.x(),
- -top->fullScreenOffset.y(),
- -top->fullScreenOffset.x(),
- -top->fullScreenOffset.y()));
- }
- }
- }
- }
-
- createWinId();
- Q_ASSERT(testAttribute(Qt::WA_WState_Created));
- if ((oldstate & Qt::WindowMinimized) != (newstate & Qt::WindowMinimized)) {
- if (isVisible()) {
- if (newstate & Qt::WindowMinimized) {
- XEvent e;
- e.xclient.type = ClientMessage;
- e.xclient.message_type = ATOM(WM_CHANGE_STATE);
- e.xclient.display = X11->display;
- e.xclient.window = data->winid;
- e.xclient.format = 32;
- e.xclient.data.l[0] = IconicState;
- e.xclient.data.l[1] = 0;
- e.xclient.data.l[2] = 0;
- e.xclient.data.l[3] = 0;
- e.xclient.data.l[4] = 0;
- XSendEvent(X11->display,
- RootWindow(X11->display,d->xinfo.screen()),
- False, (SubstructureNotifyMask|SubstructureRedirectMask), &e);
- } else {
- setAttribute(Qt::WA_Mapped);
- XMapWindow(X11->display, effectiveWinId());
- }
- }
-
- needShow = false;
- }
- }
-
- data->window_state = newstate;
-
- if (needShow)
- show();
-
- if (newstate & Qt::WindowActive)
- activateWindow();
-
- QWindowStateChangeEvent e(oldstate);
- QApplication::sendEvent(this, &e);
-}
-
-/*!
- \internal
- Platform-specific part of QWidget::show().
-*/
-
-void QWidgetPrivate::show_sys()
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
-
- if (q->testAttribute(Qt::WA_DontShowOnScreen)) {
- invalidateBuffer(q->rect());
- q->setAttribute(Qt::WA_Mapped);
- if (QTLWExtra *tlwExtra = maybeTopData())
- tlwExtra->waitingForMapNotify = 0;
- return;
- }
-
- if (q->isWindow()) {
- XWMHints *h = XGetWMHints(X11->display, q->internalWinId());
- XWMHints wm_hints;
- bool got_hints = h != 0;
- if (!got_hints) {
- memset(&wm_hints, 0, sizeof(wm_hints)); // make valgrind happy
- h = &wm_hints;
- }
- h->initial_state = q->isMinimized() ? IconicState : NormalState;
- h->flags |= StateHint;
- XSetWMHints(X11->display, q->internalWinId(), h);
- if (got_hints)
- XFree((char *)h);
-
- // update WM_NORMAL_HINTS
- do_size_hints(q, extra);
-
- // udpate WM_TRANSIENT_FOR
- if (isTransient(q)) {
- QWidget *p = q->parentWidget();
-
-#ifndef QT_NO_MENU
- // hackish ... try to find the main window related to this QMenu
- if (qobject_cast<QMenu *>(q)) {
- p = static_cast<QMenuPrivate*>(this)->causedPopup.widget;
- if (!p)
- p = q->parentWidget();
- if (!p)
- p = QApplication::widgetAt(q->pos());
- if (!p)
- p = qApp->activeWindow();
- }
-#endif
- if (p)
- p = p->window();
- if (p) {
- // transient for window
- XSetTransientForHint(X11->display, q->internalWinId(), p->internalWinId());
- } else {
- // transient for group
- XSetTransientForHint(X11->display, q->internalWinId(), X11->wm_client_leader);
- }
- }
-
- // update _MOTIF_WM_HINTS
- QtMWMHints mwmhints = GetMWMHints(X11->display, q->internalWinId());
-
- if (data.window_modality != Qt::NonModal) {
- switch (data.window_modality) {
- case Qt::WindowModal:
- mwmhints.input_mode = MWM_INPUT_PRIMARY_APPLICATION_MODAL;
- break;
- case Qt::ApplicationModal:
- default:
- mwmhints.input_mode = MWM_INPUT_FULL_APPLICATION_MODAL;
- break;
- }
- mwmhints.flags |= MWM_HINTS_INPUT_MODE;
- } else {
- mwmhints.input_mode = MWM_INPUT_MODELESS;
- mwmhints.flags &= ~MWM_HINTS_INPUT_MODE;
- }
-
- if (q->minimumSize() == q->maximumSize()) {
- // fixed size, remove the resize handle (since mwm/dtwm
- // isn't smart enough to do it itself)
- mwmhints.flags |= MWM_HINTS_FUNCTIONS;
- if (mwmhints.functions == MWM_FUNC_ALL) {
- mwmhints.functions = MWM_FUNC_MOVE;
- } else {
- mwmhints.functions &= ~MWM_FUNC_RESIZE;
- }
-
- if (mwmhints.decorations == MWM_DECOR_ALL) {
- mwmhints.flags |= MWM_HINTS_DECORATIONS;
- mwmhints.decorations = (MWM_DECOR_BORDER
- | MWM_DECOR_TITLE
- | MWM_DECOR_MENU);
- } else {
- mwmhints.decorations &= ~MWM_DECOR_RESIZEH;
- }
-
- if (q->windowFlags() & Qt::WindowMinimizeButtonHint) {
- mwmhints.flags |= MWM_HINTS_DECORATIONS;
- mwmhints.decorations |= MWM_DECOR_MINIMIZE;
- mwmhints.functions |= MWM_FUNC_MINIMIZE;
- }
- if (q->windowFlags() & Qt::WindowMaximizeButtonHint) {
- mwmhints.flags |= MWM_HINTS_DECORATIONS;
- mwmhints.decorations |= MWM_DECOR_MAXIMIZE;
- mwmhints.functions |= MWM_FUNC_MAXIMIZE;
- }
- if (q->windowFlags() & Qt::WindowCloseButtonHint)
- mwmhints.functions |= MWM_FUNC_CLOSE;
- }
-
- SetMWMHints(X11->display, q->internalWinId(), mwmhints);
-
- // update _NET_WM_STATE
- QVector<Atom> netWmState = getNetWmState(q);
-
- Qt::WindowFlags flags = q->windowFlags();
- if (flags & Qt::WindowStaysOnTopHint) {
- if (flags & Qt::WindowStaysOnBottomHint)
- qWarning() << "QWidget: Incompatible window flags: the window can't be on top and on bottom at the same time";
- if (!netWmState.contains(ATOM(_NET_WM_STATE_ABOVE)))
- netWmState.append(ATOM(_NET_WM_STATE_ABOVE));
- if (!netWmState.contains(ATOM(_NET_WM_STATE_STAYS_ON_TOP)))
- netWmState.append(ATOM(_NET_WM_STATE_STAYS_ON_TOP));
- } else if (flags & Qt::WindowStaysOnBottomHint) {
- if (!netWmState.contains(ATOM(_NET_WM_STATE_BELOW)))
- netWmState.append(ATOM(_NET_WM_STATE_BELOW));
- }
- if (q->isFullScreen()) {
- if (!netWmState.contains(ATOM(_NET_WM_STATE_FULLSCREEN)))
- netWmState.append(ATOM(_NET_WM_STATE_FULLSCREEN));
- }
- if (q->isMaximized()) {
- if (!netWmState.contains(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ)))
- netWmState.append(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ));
- if (!netWmState.contains(ATOM(_NET_WM_STATE_MAXIMIZED_VERT)))
- netWmState.append(ATOM(_NET_WM_STATE_MAXIMIZED_VERT));
- }
- if (data.window_modality != Qt::NonModal) {
- if (!netWmState.contains(ATOM(_NET_WM_STATE_MODAL)))
- netWmState.append(ATOM(_NET_WM_STATE_MODAL));
- }
-
- if (!netWmState.isEmpty()) {
- XChangeProperty(X11->display, q->internalWinId(),
- ATOM(_NET_WM_STATE), XA_ATOM, 32, PropModeReplace,
- (unsigned char *) netWmState.data(), netWmState.size());
- } else {
- XDeleteProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_STATE));
- }
-
- // set _NET_WM_USER_TIME
- Time userTime = X11->userTime;
- bool setUserTime = false;
- if (q->testAttribute(Qt::WA_ShowWithoutActivating)) {
- userTime = 0;
- setUserTime = true;
- } else if (userTime != CurrentTime) {
- setUserTime = true;
- }
- if (setUserTime)
- qt_net_update_user_time(q, userTime);
-
-#ifndef QT_NO_XSYNC
- if (!topData()->syncUpdateCounter) {
- XSyncValue value;
- XSyncIntToValue(&value, 0);
- topData()->syncUpdateCounter = XSyncCreateCounter(X11->display, value);
-
- XChangeProperty(X11->display, q->internalWinId(),
- ATOM(_NET_WM_SYNC_REQUEST_COUNTER),
- XA_CARDINAL,
- 32, PropModeReplace,
- (uchar *) &topData()->syncUpdateCounter, 1);
-
- topData()->newCounterValueHi = 0;
- topData()->newCounterValueLo = 0;
- }
-#endif
-
- if (!topData()->embedded
- && (topData()->validWMState || topData()->waitingForMapNotify)
- && !q->isMinimized()) {
- X11->deferred_map.append(q);
- return;
- }
-
- if (q->isMaximized() && !q->isFullScreen()
- && !(X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ))
- && X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_VERT)))) {
- XMapWindow(X11->display, q->internalWinId());
- data.fstrut_dirty = true;
- qt_x11_wait_for_window_manager(q);
-
- // if the wm was not smart enough to adjust our size, do that manually
- QRect maxRect = QApplication::desktop()->availableGeometry(q);
-
- QTLWExtra *top = topData();
- QRect normalRect = top->normalGeometry;
- const QRect fs = frameStrut();
-
- q->setGeometry(maxRect.x() + fs.left(),
- maxRect.y() + fs.top(),
- maxRect.width() - fs.left() - fs.right(),
- maxRect.height() - fs.top() - fs.bottom());
-
- // restore the original normalGeometry
- top->normalGeometry = normalRect;
- // internalSetGeometry() clears the maximized flag... make sure we set it back
- data.window_state = data.window_state | Qt::WindowMaximized;
- q->setAttribute(Qt::WA_Mapped);
- return;
- }
-
- if (q->isFullScreen() && !X11->isSupportedByWM(ATOM(_NET_WM_STATE_FULLSCREEN))) {
- XMapWindow(X11->display, q->internalWinId());
- qt_x11_wait_for_window_manager(q);
- q->setAttribute(Qt::WA_Mapped);
- return;
- }
- }
-
- invalidateBuffer(q->rect());
-
- if (q->testAttribute(Qt::WA_OutsideWSRange))
- return;
- q->setAttribute(Qt::WA_Mapped);
- if (q->isWindow())
- topData()->waitingForMapNotify = 1;
-
- if (!q->isWindow()
- && (!q->autoFillBackground()
- || q->palette().brush(q->backgroundRole()).style() == Qt::LinearGradientPattern)) {
- if (q->internalWinId()) {
- XSetWindowBackgroundPixmap(X11->display, q->internalWinId(), XNone);
- XMapWindow(X11->display, q->internalWinId());
- updateSystemBackground();
- }
- return;
- }
-
- if (q->internalWinId())
- XMapWindow(X11->display, q->internalWinId());
-
- // Freedesktop.org Startup Notification
- if (X11->startupId && q->isWindow()) {
- QByteArray message("remove: ID=");
- message.append(X11->startupId);
- sendStartupMessage(message.constData());
- X11->startupId = 0;
- }
-}
-
-/*!
- \internal
- Platform-specific part of QWidget::show().
-*/
-
-void QWidgetPrivate::sendStartupMessage(const char *message) const
-{
- Q_Q(const QWidget);
-
- if (!message)
- return;
-
- XEvent xevent;
- xevent.xclient.type = ClientMessage;
- xevent.xclient.message_type = ATOM(_NET_STARTUP_INFO_BEGIN);
- xevent.xclient.display = X11->display;
- xevent.xclient.window = q->internalWinId();
- xevent.xclient.format = 8;
-
- Window rootWindow = RootWindow(X11->display, DefaultScreen(X11->display));
- uint sent = 0;
- uint length = strlen(message) + 1;
- do {
- if (sent == 20)
- xevent.xclient.message_type = ATOM(_NET_STARTUP_INFO);
-
- for (uint i = 0; i < 20 && i + sent <= length; i++)
- xevent.xclient.data.b[i] = message[i + sent++];
-
- XSendEvent(X11->display, rootWindow, false, PropertyChangeMask, &xevent);
- } while (sent <= length);
-}
-
-void QWidgetPrivate::setNetWmWindowTypes()
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
-
- if (!q->isWindow()) {
- if (q->internalWinId())
- XDeleteProperty(X11->display, q->internalWinId(), ATOM(_NET_WM_WINDOW_TYPE));
- return;
- }
-
- QVector<long> windowTypes;
-
- // manual selection 1 (these are never set by Qt and take precedence)
- if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDesktop))
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_DESKTOP));
- if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDock))
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_DOCK));
- if (q->testAttribute(Qt::WA_X11NetWmWindowTypeNotification))
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_NOTIFICATION));
-
- // manual selection 2 (Qt uses these during auto selection);
- if (q->testAttribute(Qt::WA_X11NetWmWindowTypeUtility))
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_UTILITY));
- if (q->testAttribute(Qt::WA_X11NetWmWindowTypeSplash))
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_SPLASH));
- if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDialog))
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_DIALOG));
- if (q->testAttribute(Qt::WA_X11NetWmWindowTypeToolTip))
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_TOOLTIP));
-
- // manual selection 3 (these can be set by Qt, but don't have a
- // corresponding Qt::WindowType). note that order of the *MENU
- // atoms is important
- if (q->testAttribute(Qt::WA_X11NetWmWindowTypeMenu))
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_MENU));
- if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu))
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_DROPDOWN_MENU));
- if (q->testAttribute(Qt::WA_X11NetWmWindowTypePopupMenu))
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_POPUP_MENU));
- if (q->testAttribute(Qt::WA_X11NetWmWindowTypeToolBar))
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_TOOLBAR));
- if (q->testAttribute(Qt::WA_X11NetWmWindowTypeCombo))
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_COMBO));
- if (q->testAttribute(Qt::WA_X11NetWmWindowTypeDND))
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_DND));
-
- // automatic selection
- switch (q->windowType()) {
- case Qt::Dialog:
- case Qt::Sheet:
- // dialog netwm type
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_DIALOG));
- break;
-
- case Qt::Tool:
- case Qt::Drawer:
- // utility netwm type
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_UTILITY));
- break;
-
- case Qt::ToolTip:
- // tooltip netwm type
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_TOOLTIP));
- break;
-
- case Qt::SplashScreen:
- // splash netwm type
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_SPLASH));
- break;
-
- default:
- break;
- }
-
- if (q->windowFlags() & Qt::FramelessWindowHint) {
- // override netwm type - quick and easy for KDE noborder
- windowTypes.append(ATOM(_KDE_NET_WM_WINDOW_TYPE_OVERRIDE));
- }
-
- // normal netwm type - default
- windowTypes.append(ATOM(_NET_WM_WINDOW_TYPE_NORMAL));
-
- if (!windowTypes.isEmpty()) {
- XChangeProperty(X11->display, q->winId(), ATOM(_NET_WM_WINDOW_TYPE), XA_ATOM, 32,
- PropModeReplace, (unsigned char *) windowTypes.constData(),
- windowTypes.count());
- } else {
- XDeleteProperty(X11->display, q->winId(), ATOM(_NET_WM_WINDOW_TYPE));
- }
-}
-
-/*!
- \internal
- Platform-specific part of QWidget::hide().
-*/
-
-void QWidgetPrivate::hide_sys()
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- deactivateWidgetCleanup();
- if (q->isWindow()) {
- X11->deferred_map.removeAll(q);
- if (q->internalWinId()) // in nsplugin, may be 0
- XWithdrawWindow(X11->display, q->internalWinId(), xinfo.screen());
- XFlush(X11->display);
- } else {
- invalidateBuffer(q->rect());
- if (q->internalWinId()) // in nsplugin, may be 0
- XUnmapWindow(X11->display, q->internalWinId());
- }
- q->setAttribute(Qt::WA_Mapped, false);
-}
-
-void QWidgetPrivate::setFocus_sys()
-{
-
-}
-
-
-void QWidgetPrivate::raise_sys()
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- if (q->internalWinId())
- XRaiseWindow(X11->display, q->internalWinId());
-}
-
-void QWidgetPrivate::lower_sys()
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- if (q->internalWinId())
- XLowerWindow(X11->display, q->internalWinId());
- if(!q->isWindow())
- invalidateBuffer(q->rect());
-}
-
-void QWidgetPrivate::stackUnder_sys(QWidget* w)
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- if (q->internalWinId() && w->internalWinId()) {
- Window stack[2];
- stack[0] = w->internalWinId();;
- stack[1] = q->internalWinId();
- XRestackWindows(X11->display, stack, 2);
- }
- if(!q->isWindow() || !w->internalWinId())
- invalidateBuffer(q->rect());
-}
-
-
-static void do_size_hints(QWidget* widget, QWExtra *x)
-{
- Q_ASSERT(widget->testAttribute(Qt::WA_WState_Created));
- XSizeHints s;
- s.flags = 0;
- if (x) {
- QRect g = widget->geometry();
- s.x = g.x();
- s.y = g.y();
- s.width = g.width();
- s.height = g.height();
- if (x->minw > 0 || x->minh > 0) {
- // add minimum size hints
- s.flags |= PMinSize;
- s.min_width = qMin(XCOORD_MAX, x->minw);
- s.min_height = qMin(XCOORD_MAX, x->minh);
- }
- if (x->maxw < QWIDGETSIZE_MAX || x->maxh < QWIDGETSIZE_MAX) {
- // add maximum size hints
- s.flags |= PMaxSize;
- s.max_width = qMin(XCOORD_MAX, x->maxw);
- s.max_height = qMin(XCOORD_MAX, x->maxh);
- }
- if (x->topextra &&
- (x->topextra->incw > 0 || x->topextra->inch > 0)) {
- // add resize increment hints
- s.flags |= PResizeInc | PBaseSize;
- s.width_inc = x->topextra->incw;
- s.height_inc = x->topextra->inch;
- s.base_width = x->topextra->basew;
- s.base_height = x->topextra->baseh;
- }
- }
- if (widget->testAttribute(Qt::WA_Moved)) {
- // user (i.e. command-line) specified position
- s.flags |= USPosition;
- s.flags |= PPosition;
- }
- if (widget->testAttribute(Qt::WA_Resized)) {
- // user (i.e. command-line) specified size
- s.flags |= USSize;
- s.flags |= PSize;
- }
- s.flags |= PWinGravity;
- if (widget->testAttribute(Qt::WA_Moved) && x && x->topextra && !x->topextra->posFromMove) {
- // position came from setGeometry(), tell the WM that we don't
- // want our window gravity-shifted
- s.win_gravity = StaticGravity;
- } else {
- // position came from move()
- s.x = widget->x();
- s.y = widget->y();
- s.win_gravity = QApplication::isRightToLeft() ? NorthEastGravity : NorthWestGravity;
- }
- if (widget->internalWinId())
- XSetWMNormalHints(X11->display, widget->internalWinId(), &s);
-}
-
-
-/*
- Helper function for non-toplevel widgets. Helps to map Qt's 32bit
- coordinate system to X11's 16bit coordinate system.
-
- Sets the geometry of the widget to data.crect, but clipped to sizes
- that X can handle. Unmaps widgets that are completely outside the
- valid range.
-
- Maintains data.wrect, which is the geometry of the X widget,
- measured in this widget's coordinate system.
-
- if the parent is not clipped, parentWRect is empty, otherwise
- parentWRect is the geometry of the parent's X rect, measured in
- parent's coord sys
- */
-void QWidgetPrivate::setWSGeometry(bool dontShow, const QRect &)
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
-
- /*
- There are up to four different coordinate systems here:
- Qt coordinate system for this widget.
- X coordinate system for this widget (relative to wrect).
- Qt coordinate system for parent
- X coordinate system for parent (relative to parent's wrect).
- */
- Display *dpy = xinfo.display();
- QRect validRange(-XCOORD_MAX,-XCOORD_MAX, 2*XCOORD_MAX, 2*XCOORD_MAX);
- QRect wrectRange(-WRECT_MAX,-WRECT_MAX, 2*WRECT_MAX, 2*WRECT_MAX);
- QRect wrect;
- //xrect is the X geometry of my X widget. (starts out in parent's Qt coord sys, and ends up in parent's X coord sys)
- QRect xrect = data.crect;
-
- const QWidget *const parent = q->parentWidget();
- QRect parentWRect = parent->data->wrect;
-
- if (parentWRect.isValid()) {
- // parent is clipped, and we have to clip to the same limit as parent
- if (!parentWRect.contains(xrect)) {
- xrect &= parentWRect;
- wrect = xrect;
- //translate from parent's to my Qt coord sys
- wrect.translate(-data.crect.topLeft());
- }
- //translate from parent's Qt coords to parent's X coords
- xrect.translate(-parentWRect.topLeft());
-
- } else {
- // parent is not clipped, we may or may not have to clip
-
- if (data.wrect.isValid() && QRect(QPoint(),data.crect.size()).contains(data.wrect)) {
- // This is where the main optimization is: we are already
- // clipped, and if our clip is still valid, we can just
- // move our window, and do not need to move or clip
- // children
-
- QRect vrect = xrect & parent->rect();
- vrect.translate(-data.crect.topLeft()); //the part of me that's visible through parent, in my Qt coords
- if (data.wrect.contains(vrect)) {
- xrect = data.wrect;
- xrect.translate(data.crect.topLeft());
- if (data.winid)
- XMoveWindow(dpy, data.winid, xrect.x(), xrect.y());
- return;
- }
- }
-
- if (!validRange.contains(xrect)) {
- // we are too big, and must clip
- xrect &=wrectRange;
- wrect = xrect;
- wrect.translate(-data.crect.topLeft());
- //parent's X coord system is equal to parent's Qt coord
- //sys, so we don't need to map xrect.
- }
-
- }
-
- // unmap if we are outside the valid window system coord system
- bool outsideRange = !xrect.isValid();
- bool mapWindow = false;
- if (q->testAttribute(Qt::WA_OutsideWSRange) != outsideRange) {
- q->setAttribute(Qt::WA_OutsideWSRange, outsideRange);
- if (outsideRange) {
- if (data.winid)
- XUnmapWindow(dpy, data.winid);
- q->setAttribute(Qt::WA_Mapped, false);
- } else if (!q->isHidden()) {
- mapWindow = true;
- }
- }
-
- if (outsideRange)
- return;
-
- bool jump = (data.wrect != wrect);
- data.wrect = wrect;
-
-
- // and now recursively for all children...
- // ### can be optimized
- for (int i = 0; i < children.size(); ++i) {
- QObject *object = children.at(i);
- if (object->isWidgetType()) {
- QWidget *w = static_cast<QWidget *>(object);
- if (!w->isWindow() && w->testAttribute(Qt::WA_WState_Created))
- w->d_func()->setWSGeometry(jump);
- }
- }
-
- if (data.winid) {
- // move ourselves to the new position and map (if necessary) after
- // the movement. Rationale: moving unmapped windows is much faster
- // than moving mapped windows
- if (jump) //avoid flicker when jumping
- XSetWindowBackgroundPixmap(dpy, data.winid, XNone);
- if (!parent->internalWinId())
- xrect.translate(parent->mapTo(q->nativeParentWidget(), QPoint(0, 0)));
- XMoveResizeWindow(dpy, data.winid, xrect.x(), xrect.y(), xrect.width(), xrect.height());
- }
-
- //to avoid flicker, we have to show children after the helper widget has moved
- if (jump) {
- for (int i = 0; i < children.size(); ++i) {
- QObject *object = children.at(i);
- if (object->isWidgetType()) {
- QWidget *w = static_cast<QWidget *>(object);
- if (!w->testAttribute(Qt::WA_OutsideWSRange) && !w->testAttribute(Qt::WA_Mapped) && !w->isHidden()) {
- w->setAttribute(Qt::WA_Mapped);
- if (w->internalWinId())
- XMapWindow(dpy, w->data->winid);
- }
- }
- }
- }
-
-
- if (jump && data.winid)
- XClearArea(dpy, data.winid, 0, 0, wrect.width(), wrect.height(), True);
-
- if (mapWindow && !dontShow) {
- q->setAttribute(Qt::WA_Mapped);
- if (data.winid)
- XMapWindow(dpy, data.winid);
- }
-}
-
-void QWidgetPrivate::setGeometry_sys(int x, int y, int w, int h, bool isMove)
-{
- Q_Q(QWidget);
- Q_ASSERT(q->testAttribute(Qt::WA_WState_Created));
- Display *dpy = X11->display;
-
- if ((q->windowType() == Qt::Desktop))
- return;
- if (q->isWindow()) {
- if (!X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_VERT))
- && !X11->isSupportedByWM(ATOM(_NET_WM_STATE_MAXIMIZED_HORZ)))
- data.window_state &= ~Qt::WindowMaximized;
- if (!X11->isSupportedByWM(ATOM(_NET_WM_STATE_FULLSCREEN)))
- data.window_state &= ~Qt::WindowFullScreen;
- if (QTLWExtra *topData = maybeTopData())
- topData->normalGeometry = QRect(0,0,-1,-1);
- } else {
- uint s = data.window_state;
- s &= ~(Qt::WindowMaximized | Qt::WindowFullScreen);
- data.window_state = s;
- }
- if (extra) { // any size restrictions?
- w = qMin(w,extra->maxw);
- h = qMin(h,extra->maxh);
- w = qMax(w,extra->minw);
- h = qMax(h,extra->minh);
- }
- QPoint oldPos(q->pos());
- QSize oldSize(q->size());
- QRect oldGeom(data.crect);
- QRect r(x, y, w, h);
-
- // We only care about stuff that changes the geometry, or may
- // cause the window manager to change its state
- if (!q->isWindow() && oldGeom == r)
- return;
-
- data.crect = r;
- bool isResize = q->size() != oldSize;
-
- if (q->isWindow()) {
- if (w == 0 || h == 0) {
- q->setAttribute(Qt::WA_OutsideWSRange, true);
- if (q->isVisible() && q->testAttribute(Qt::WA_Mapped))
- hide_sys();
- } else if (q->isVisible() && q->testAttribute(Qt::WA_OutsideWSRange)) {
- q->setAttribute(Qt::WA_OutsideWSRange, false);
-
- // put the window in its place and show it
- if (data.winid)
- XMoveResizeWindow(dpy, data.winid, x, y, w, h);
- topData()->posFromMove = false; // force StaticGravity
- do_size_hints(q, extra);
- show_sys();
- } else {
- q->setAttribute(Qt::WA_OutsideWSRange, false);
- if (!q->isVisible())
- do_size_hints(q, extra);
- if (isMove) {
- if ((data.window_flags & Qt::X11BypassWindowManagerHint) == Qt::X11BypassWindowManagerHint
- // work around 4Dwm's incompliance with ICCCM 4.1.5
- || X11->desktopEnvironment == DE_4DWM) {
- if (data.winid)
- XMoveResizeWindow(dpy, data.winid, x, y, w, h);
- } else if (q->isVisible()
- && topData()->validWMState
- && X11->isSupportedByWM(ATOM(_NET_MOVERESIZE_WINDOW))) {
- XEvent e;
- e.xclient.type = ClientMessage;
- e.xclient.message_type = ATOM(_NET_MOVERESIZE_WINDOW);
- e.xclient.display = X11->display;
- e.xclient.window = q->internalWinId();
- e.xclient.format = 32;
- e.xclient.data.l[0] = StaticGravity | 1<<8 | 1<<9 | 1<<10 | 1<<11 | 1<<12;
- e.xclient.data.l[1] = x;
- e.xclient.data.l[2] = y;
- e.xclient.data.l[3] = w;
- e.xclient.data.l[4] = h;
- XSendEvent(X11->display, RootWindow(X11->display, q->x11Info().screen()),
- false, (SubstructureNotifyMask | SubstructureRedirectMask), &e);
- } else if (data.winid) {
- // pos() is right according to ICCCM 4.1.5
- XMoveResizeWindow(dpy, data.winid, q->pos().x(), q->pos().y(), w, h);
- }
- } else if (isResize && data.winid) {
- if (!q->isVisible()
- && topData()->validWMState
- && !q->testAttribute(Qt::WA_PendingMoveEvent)) {
- /*
- even though we've not visible, we could be in a
- race w/ the window manager, and it may ignore
- our ConfigureRequest. setting posFromMove to
- false makes sure that doDeferredMap() in
- qapplication_x11.cpp keeps the window in the
- right place
- */
- topData()->posFromMove = false;
- }
- XResizeWindow(dpy, data.winid, w, h);
- }
- }
- if (isResize && !q->testAttribute(Qt::WA_DontShowOnScreen)) // set config pending only on resize, see qapplication_x11.cpp, translateConfigEvent()
- q->setAttribute(Qt::WA_WState_ConfigPending);
-
- } else {
- QTLWExtra *tlwExtra = q->window()->d_func()->maybeTopData();
- const bool inTopLevelResize = tlwExtra ? tlwExtra->inTopLevelResize : false;
- const bool disableInTopLevelResize = inTopLevelResize && q->internalWinId();
- if (disableInTopLevelResize) {
- // Top-level resize optimization does not work for native child widgets;
- // disable it for this particular widget.
- tlwExtra->inTopLevelResize = false;
- }
-
- if (!isResize && (!inTopLevelResize || disableInTopLevelResize) && q->isVisible()) {
- moveRect(QRect(oldPos, oldSize), x - oldPos.x(), y - oldPos.y());
- }
- if (q->testAttribute(Qt::WA_WState_Created))
- setWSGeometry();
-
- if (isResize && (!inTopLevelResize || disableInTopLevelResize) && q->isVisible())
- invalidateBuffer_resizeHelper(oldPos, oldSize);
-
- if (disableInTopLevelResize)
- tlwExtra->inTopLevelResize = true;
- }
-
- if (q->isVisible()) {
- if (isMove && q->pos() != oldPos) {
- if (X11->desktopEnvironment != DE_4DWM) {
- // pos() is right according to ICCCM 4.1.5
- QMoveEvent e(q->pos(), oldPos);
- QApplication::sendEvent(q, &e);
- } else {
- // work around 4Dwm's incompliance with ICCCM 4.1.5
- QMoveEvent e(data.crect.topLeft(), oldGeom.topLeft());
- QApplication::sendEvent(q, &e);
- }
- }
- if (isResize) {
- static bool slowResize = qgetenv("QT_SLOW_TOPLEVEL_RESIZE").toInt();
- // If we have a backing store with static contents, we have to disable the top-level
- // resize optimization in order to get invalidated regions for resized widgets.
- // The optimization discards all invalidateBuffer() calls since we're going to
- // repaint everything anyways, but that's not the case with static contents.
- const bool setTopLevelResize = !slowResize && q->isWindow() && extra && extra->topextra
- && !extra->topextra->inTopLevelResize
- && (!extra->topextra->backingStore
- || !extra->topextra->backingStore->hasStaticContents());
- if (setTopLevelResize)
- extra->topextra->inTopLevelResize = true;
- QResizeEvent e(q->size(), oldSize);
- QApplication::sendEvent(q, &e);
- if (setTopLevelResize)
- extra->topextra->inTopLevelResize = false;
- }
- } else {
- if (isMove && q->pos() != oldPos)
- q->setAttribute(Qt::WA_PendingMoveEvent, true);
- if (isResize)
- q->setAttribute(Qt::WA_PendingResizeEvent, true);
- }
-}
-
-void QWidgetPrivate::setConstraints_sys()
-{
- Q_Q(QWidget);
-#ifdef ALIEN_DEBUG
- qDebug() << "QWidgetPrivate::setConstraints_sys START" << q;
-#endif
- if (q->testAttribute(Qt::WA_WState_Created))
- do_size_hints(q, extra);
-#ifdef ALIEN_DEBUG
- qDebug() << "QWidgetPrivate::setConstraints_sys END" << q;
-#endif
-}
-
-void QWidgetPrivate::scroll_sys(int dx, int dy)
-{
- Q_Q(QWidget);
-
- scrollChildren(dx, dy);
- if (!paintOnScreen()) {
- scrollRect(q->rect(), dx, dy);
- } else {
- scroll_sys(dx, dy, QRect());
- }
-}
-
-void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &r)
-{
- Q_Q(QWidget);
-
- if (!paintOnScreen()) {
- scrollRect(r, dx, dy);
- return;
- }
- bool valid_rect = r.isValid();
- bool just_update = qAbs(dx) > q->width() || qAbs(dy) > q->height();
- QRect sr = valid_rect ? r : clipRect();
- if (just_update)
- q->update();
- else if (!valid_rect)
- dirty.translate(dx, dy);
-
- int x1, y1, x2, y2, w = sr.width(), h = sr.height();
- if (dx > 0) {
- x1 = sr.x();
- x2 = x1+dx;
- w -= dx;
- } else {
- x2 = sr.x();
- x1 = x2-dx;
- w += dx;
- }
- if (dy > 0) {
- y1 = sr.y();
- y2 = y1+dy;
- h -= dy;
- } else {
- y2 = sr.y();
- y1 = y2-dy;
- h += dy;
- }
-
- if (dx == 0 && dy == 0)
- return;
-
- Display *dpy = X11->display;
- // Want expose events
- if (w > 0 && h > 0 && !just_update && q->internalWinId()) {
- GC gc = XCreateGC(dpy, q->internalWinId(), 0, 0);
- XSetGraphicsExposures(dpy, gc, True);
- XCopyArea(dpy, q->internalWinId(), q->internalWinId(), gc, x1, y1, w, h, x2, y2);
- XFreeGC(dpy, gc);
- }
-
- if (!valid_rect && !children.isEmpty()) { // scroll children
- QPoint pd(dx, dy);
- for (int i = 0; i < children.size(); ++i) { // move all children
- register QObject *object = children.at(i);
- if (object->isWidgetType()) {
- QWidget *w = static_cast<QWidget *>(object);
- if (!w->isWindow())
- w->move(w->pos() + pd);
- }
- }
- }
-
- if (just_update)
- return;
-
- // Don't let the server be bogged-down with repaint events
- bool repaint_immediately = (qt_sip_count(q) < 3 && !q->testAttribute(Qt::WA_WState_InPaintEvent));
-
- if (dx) {
- int x = x2 == sr.x() ? sr.x()+w : sr.x();
- if (repaint_immediately)
- q->repaint(x, sr.y(), qAbs(dx), sr.height());
- else if (q->internalWinId())
- XClearArea(dpy, data.winid, x, sr.y(), qAbs(dx), sr.height(), True);
- }
- if (dy) {
- int y = y2 == sr.y() ? sr.y()+h : sr.y();
- if (repaint_immediately)
- q->repaint(sr.x(), y, sr.width(), qAbs(dy));
- else if (q->internalWinId())
- XClearArea(dpy, data.winid, sr.x(), y, sr.width(), qAbs(dy), True);
- }
-
- qt_insert_sip(q, dx, dy); // #### ignores r
-}
-
-int QWidget::metric(PaintDeviceMetric m) const
-{
- Q_D(const QWidget);
- int val;
- if (m == PdmWidth) {
- val = data->crect.width();
- } else if (m == PdmHeight) {
- val = data->crect.height();
- } else {
- Display *dpy = X11->display;
- int scr = d->xinfo.screen();
- switch (m) {
- case PdmDpiX:
- case PdmPhysicalDpiX:
- if (d->extra && d->extra->customDpiX)
- val = d->extra->customDpiX;
- else if (d->parent)
- val = static_cast<QWidget *>(d->parent)->metric(m);
- else
- val = QX11Info::appDpiX(scr);
- break;
- case PdmDpiY:
- case PdmPhysicalDpiY:
- if (d->extra && d->extra->customDpiY)
- val = d->extra->customDpiY;
- else if (d->parent)
- val = static_cast<QWidget *>(d->parent)->metric(m);
- else
- val = QX11Info::appDpiY(scr);
- break;
- case PdmWidthMM:
- val = (DisplayWidthMM(dpy,scr)*data->crect.width())/
- DisplayWidth(dpy,scr);
- break;
- case PdmHeightMM:
- val = (DisplayHeightMM(dpy,scr)*data->crect.height())/
- DisplayHeight(dpy,scr);
- break;
- case PdmNumColors:
- val = d->xinfo.cells();
- break;
- case PdmDepth:
- val = d->xinfo.depth();
- break;
- default:
- val = 0;
- qWarning("QWidget::metric: Invalid metric command");
- }
- }
- return val;
-}
-
-void QWidgetPrivate::createSysExtra()
-{
- extra->compress_events = true;
- extra->xDndProxy = 0;
-}
-
-void QWidgetPrivate::deleteSysExtra()
-{
-}
-
-void QWidgetPrivate::createTLSysExtra()
-{
- extra->topextra->spont_unmapped = 0;
- extra->topextra->dnd = 0;
- extra->topextra->validWMState = 0;
- extra->topextra->waitingForMapNotify = 0;
- extra->topextra->parentWinId = 0;
- extra->topextra->userTimeWindow = 0;
-#ifndef QT_NO_XSYNC
- extra->topextra->syncUpdateCounter = 0;
- extra->topextra->syncRequestTimestamp = 0;
- extra->topextra->newCounterValueHi = 0;
- extra->topextra->newCounterValueLo = 0;
-#endif
-}
-
-void QWidgetPrivate::deleteTLSysExtra()
-{
- // don't destroy input context here. it will be destroyed in
- // QWidget::destroy() destroyInputContext();
-}
-
-void QWidgetPrivate::registerDropSite(bool on)
-{
- Q_UNUSED(on);
-}
-
-void QWidgetPrivate::setMask_sys(const QRegion &region)
-{
- Q_Q(QWidget);
- if (!q->internalWinId())
- return;
-
- if (region.isEmpty()) {
- XShapeCombineMask(X11->display, q->internalWinId(), ShapeBounding, 0, 0,
- XNone, ShapeSet);
- } else {
- XShapeCombineRegion(X11->display, q->internalWinId(), ShapeBounding, 0, 0,
- region.handle(), ShapeSet);
- }
-}
-
-/*!
- \internal
-
- Computes the frame rectangle when needed. This is an internal function, you
- should never call this.
-*/
-
-void QWidgetPrivate::updateFrameStrut()
-{
- Q_Q(QWidget);
-
- QTLWExtra *top = topData();
- if (!top->validWMState) {
- return;
- }
- if (!q->isWindow() && !q->internalWinId()) {
- data.fstrut_dirty = false;
- return;
- }
-
- Atom type_ret;
- Window l = q->effectiveWinId(), w = l, p, r; // target window, its parent, root
- Window *c;
- int i_unused;
- unsigned int nc;
- unsigned char *data_ret;
- unsigned long l_unused;
-
- while (XQueryTree(X11->display, w, &r, &p, &c, &nc)) {
- if (c && nc > 0)
- XFree(c);
-
- if (! p) {
- qWarning("QWidget::updateFrameStrut: No parent");
- return;
- }
-
- // if the parent window is the root window, an Enlightenment virtual root or
- // a NET WM virtual root window, stop here
- data_ret = 0;
- if (p == r ||
- (XGetWindowProperty(X11->display, p,
- ATOM(ENLIGHTENMENT_DESKTOP), 0, 1, False, XA_CARDINAL,
- &type_ret, &i_unused, &l_unused, &l_unused,
- &data_ret) == Success &&
- type_ret == XA_CARDINAL)) {
- if (data_ret)
- XFree(data_ret);
-
- break;
- } else if (X11->isSupportedByWM(ATOM(_NET_VIRTUAL_ROOTS)) && X11->net_virtual_root_list) {
- int i = 0;
- while (X11->net_virtual_root_list[i] != 0) {
- if (X11->net_virtual_root_list[i++] == p)
- break;
- }
- }
-
- l = w;
- w = p;
- }
-
- // we have our window
- int transx, transy;
- XWindowAttributes wattr;
- if (XTranslateCoordinates(X11->display, l, w,
- 0, 0, &transx, &transy, &p) &&
- XGetWindowAttributes(X11->display, w, &wattr)) {
- top->frameStrut.setCoords(transx,
- transy,
- wattr.width - data.crect.width() - transx,
- wattr.height - data.crect.height() - transy);
-
- // add the border_width for the window managers frame... some window managers
- // do not use a border_width of zero for their frames, and if we the left and
- // top strut, we ensure that pos() is absolutely correct. frameGeometry()
- // will still be incorrect though... perhaps i should have foffset as well, to
- // indicate the frame offset (equal to the border_width on X).
- // - Brad
- top->frameStrut.adjust(wattr.border_width,
- wattr.border_width,
- wattr.border_width,
- wattr.border_width);
- }
-
- data.fstrut_dirty = false;
-}
-
-void QWidgetPrivate::setWindowOpacity_sys(qreal opacity)
-{
- Q_Q(QWidget);
- ulong value = ulong(opacity * 0xffffffff);
- XChangeProperty(QX11Info::display(), q->internalWinId(), ATOM(_NET_WM_WINDOW_OPACITY), XA_CARDINAL,
- 32, PropModeReplace, (uchar*)&value, 1);
-}
-
-const QX11Info &QWidget::x11Info() const
-{
- Q_D(const QWidget);
- return d->xinfo;
-}
-
-void QWidgetPrivate::setWindowRole()
-{
- Q_Q(QWidget);
- if (!q->internalWinId())
- return;
- QByteArray windowRole = topData()->role.toUtf8();
- XChangeProperty(X11->display, q->internalWinId(),
- ATOM(WM_WINDOW_ROLE), XA_STRING, 8, PropModeReplace,
- (unsigned char *)windowRole.constData(), windowRole.length());
-}
-
-Q_GLOBAL_STATIC(QX11PaintEngine, qt_widget_paintengine)
-QPaintEngine *QWidget::paintEngine() const
-{
- Q_D(const QWidget);
- if (qt_widget_paintengine()->isActive()) {
- if (d->extraPaintEngine)
- return d->extraPaintEngine;
- QWidget *self = const_cast<QWidget *>(this);
- self->d_func()->extraPaintEngine = new QX11PaintEngine();
- return d->extraPaintEngine;
- }
- return qt_widget_paintengine();
-}
-
-QWindowSurface *QWidgetPrivate::createDefaultWindowSurface_sys()
-{
- return new QX11WindowSurface(q_func());
-}
-
-Qt::HANDLE QWidget::x11PictureHandle() const
-{
-#ifndef QT_NO_XRENDER
- Q_D(const QWidget);
- if (!internalWinId() && testAttribute(Qt::WA_WState_Created))
- (void)winId(); // enforce native window
- return d->picture;
-#else
- return 0;
-#endif // QT_NO_XRENDER
-}
-
-#ifndef QT_NO_XRENDER
-XRenderColor QX11Data::preMultiply(const QColor &c)
-{
- XRenderColor color;
- const uint A = c.alpha(),
- R = c.red(),
- G = c.green(),
- B = c.blue();
- color.alpha = (A | A << 8);
- color.red = (R | R << 8) * color.alpha / 0x10000;
- color.green = (G | G << 8) * color.alpha / 0x10000;
- color.blue = (B | B << 8) * color.alpha / 0x10000;
- return color;
-}
-Picture QX11Data::getSolidFill(int screen, const QColor &c)
-{
- if (!X11->use_xrender)
- return XNone;
-
- XRenderColor color = preMultiply(c);
- for (int i = 0; i < X11->solid_fill_count; ++i) {
- if (X11->solid_fills[i].screen == screen
- && X11->solid_fills[i].color.alpha == color.alpha
- && X11->solid_fills[i].color.red == color.red
- && X11->solid_fills[i].color.green == color.green
- && X11->solid_fills[i].color.blue == color.blue)
- return X11->solid_fills[i].picture;
- }
- // none found, replace one
- int i = qrand() % 16;
-
- if (X11->solid_fills[i].screen != screen && X11->solid_fills[i].picture) {
- XRenderFreePicture (X11->display, X11->solid_fills[i].picture);
- X11->solid_fills[i].picture = 0;
- }
-
- if (!X11->solid_fills[i].picture) {
- Pixmap pixmap = XCreatePixmap (X11->display, RootWindow (X11->display, screen), 1, 1, 32);
- XRenderPictureAttributes attrs;
- attrs.repeat = True;
- X11->solid_fills[i].picture = XRenderCreatePicture (X11->display, pixmap,
- XRenderFindStandardFormat(X11->display, PictStandardARGB32),
- CPRepeat, &attrs);
- XFreePixmap (X11->display, pixmap);
- }
-
- X11->solid_fills[i].color = color;
- X11->solid_fills[i].screen = screen;
- XRenderFillRectangle (X11->display, PictOpSrc, X11->solid_fills[i].picture, &color, 0, 0, 1, 1);
- return X11->solid_fills[i].picture;
-}
-#endif
-
-void QWidgetPrivate::setModal_sys()
-{
-}
-
-void qt_x11_getX11InfoForWindow(QX11Info * xinfo, const QX11WindowAttributes &att)
-{
- QX11InfoData* xd = xinfo->getX11Data(true);
- const XWindowAttributes &a = *(att.att);
- // find which screen the window is on...
- xd->screen = QX11Info::appScreen(); // by default, use the default :)
- int i;
- for (i = 0; i < ScreenCount(X11->display); i++) {
- if (RootWindow(X11->display, i) == a.root) {
- xd->screen = i;
- break;
- }
- }
-
- xd->depth = a.depth;
- xd->cells = DisplayCells(X11->display, xd->screen);
- xd->visual = a.visual;
- xd->defaultVisual = (XVisualIDFromVisual((Visual *) a.visual) ==
- XVisualIDFromVisual((Visual *) QX11Info::appVisual(xinfo->screen())));
- xd->colormap = a.colormap;
- xd->defaultColormap = (a.colormap == QX11Info::appColormap(xinfo->screen()));
- xinfo->setX11Data(xd);
-}
-
-void QWidgetPrivate::updateX11AcceptFocus()
-{
- Q_Q(QWidget);
- if (!q->isWindow() || !q->internalWinId())
- return;
-
- XWMHints *h = XGetWMHints(X11->display, q->internalWinId());
- XWMHints wm_hints;
- if (!h) {
- memset(&wm_hints, 0, sizeof(wm_hints)); // make valgrind happy
- h = &wm_hints;
- }
- h->flags |= InputHint;
- h->input = q->testAttribute(Qt::WA_X11DoNotAcceptFocus) ? False : True;
-
- XSetWMHints(X11->display, q->internalWinId(), h);
- if (h != &wm_hints)
- XFree((char *)h);
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qwidgetcreate_x11.cpp b/src/gui/kernel/qwidgetcreate_x11.cpp
deleted file mode 100644
index 16bd6abf9a..0000000000
--- a/src/gui/kernel/qwidgetcreate_x11.cpp
+++ /dev/null
@@ -1,79 +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 "qt_x11_p.h"
-
-/*
- Internal Qt functions to create X windows. We have put them in
- separate functions to allow the programmer to reimplement them by
- custom versions.
-*/
-
-QT_BEGIN_NAMESPACE
-
-Window qt_XCreateWindow(const QWidget *, Display *display, Window parent,
- int x, int y, uint w, uint h,
- int borderwidth, int depth,
- uint windowclass, Visual *visual,
- ulong valuemask, XSetWindowAttributes *attributes)
-{
- return XCreateWindow(display, parent, x, y, w, h, borderwidth, depth,
- windowclass, visual, valuemask, attributes);
-}
-
-
-Window qt_XCreateSimpleWindow(const QWidget *, Display *display, Window parent,
- int x, int y, uint w, uint h, int borderwidth,
- ulong border, ulong background)
-{
- return XCreateSimpleWindow(display, parent, x, y, w, h, borderwidth,
- border, background);
-}
-
-
-void qt_XDestroyWindow(const QWidget *, Display *display, Window window)
-{
- if (window)
- XDestroyWindow(display, window);
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp b/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp
deleted file mode 100644
index 0d13bafc0c..0000000000
--- a/src/gui/kernel/qwinnativepangesturerecognizer_win.cpp
+++ /dev/null
@@ -1,133 +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/qwinnativepangesturerecognizer_win_p.h"
-
-#include "qevent.h"
-#include "qgraphicsitem.h"
-#include "qgesture.h"
-
-#include "private/qgesture_p.h"
-#include "private/qevent_p.h"
-#include "private/qapplication_p.h"
-#include "private/qwidget_p.h"
-
-#ifndef QT_NO_GESTURES
-
-QT_BEGIN_NAMESPACE
-
-#if !defined(QT_NO_NATIVE_GESTURES)
-
-QWinNativePanGestureRecognizer::QWinNativePanGestureRecognizer()
-{
-}
-
-QGesture *QWinNativePanGestureRecognizer::create(QObject *target)
-{
- if (!target)
- return new QPanGesture; // a special case
- if (!target->isWidgetType())
- return 0;
- if (qobject_cast<QGraphicsObject *>(target))
- return 0;
-
- QWidget *q = static_cast<QWidget *>(target);
- QWidgetPrivate *d = q->d_func();
- d->nativeGesturePanEnabled = true;
- d->winSetupGestures();
-
- return new QPanGesture;
-}
-
-QGestureRecognizer::Result QWinNativePanGestureRecognizer::recognize(QGesture *state,
- QObject *,
- QEvent *event)
-{
- QPanGesture *q = static_cast<QPanGesture*>(state);
- QPanGesturePrivate *d = q->d_func();
-
- QGestureRecognizer::Result result = QGestureRecognizer::Ignore;
- if (event->type() == QEvent::NativeGesture) {
- QNativeGestureEvent *ev = static_cast<QNativeGestureEvent*>(event);
- switch(ev->gestureType) {
- case QNativeGestureEvent::GestureBegin:
- break;
- case QNativeGestureEvent::Pan:
- result = QGestureRecognizer::TriggerGesture;
- event->accept();
- break;
- case QNativeGestureEvent::GestureEnd:
- if (q->state() == Qt::NoGesture)
- return QGestureRecognizer::Ignore; // some other gesture has ended
- result = QGestureRecognizer::FinishGesture;
- break;
- default:
- return QGestureRecognizer::Ignore;
- }
- if (q->state() == Qt::NoGesture) {
- d->lastOffset = d->offset = QPointF();
- d->startPosition = ev->position;
- } else {
- d->lastOffset = d->offset;
- d->offset = QPointF(ev->position.x() - d->startPosition.x(),
- ev->position.y() - d->startPosition.y());
- }
- }
- return result;
-}
-
-void QWinNativePanGestureRecognizer::reset(QGesture *state)
-{
- QPanGesture *pan = static_cast<QPanGesture*>(state);
- QPanGesturePrivate *d = pan->d_func();
-
- d->lastOffset = d->offset = QPointF();
- d->startPosition = QPoint();
- d->acceleration = 0;
-
- QGestureRecognizer::reset(state);
-}
-
-#endif // QT_NO_NATIVE_GESTURES
-
-QT_END_NAMESPACE
-
-#endif // QT_NO_GESTURES
diff --git a/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h b/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h
deleted file mode 100644
index 6d23e41ce3..0000000000
--- a/src/gui/kernel/qwinnativepangesturerecognizer_win_p.h
+++ /dev/null
@@ -1,80 +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 QWINNATIVEPANGESTURERECOGNIZER_WIN_P_H
-#define QWINNATIVEPANGESTURERECOGNIZER_WIN_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 <QGestureRecognizer>
-
-#ifndef QT_NO_GESTURES
-
-QT_BEGIN_NAMESPACE
-
-#if !defined(QT_NO_NATIVE_GESTURES)
-
-class QWinNativePanGestureRecognizer : public QGestureRecognizer
-{
-public:
- QWinNativePanGestureRecognizer();
-
- QGesture *create(QObject *target);
- QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event);
- void reset(QGesture *state);
-};
-
-#endif // QT_NO_NATIVE_GESTURES
-
-QT_END_NAMESPACE
-
-#endif // QT_NO_GESTURES
-
-#endif // QWINNATIVEPANGESTURERECOGNIZER_WIN_P_H
diff --git a/src/gui/kernel/qx11embed_x11.cpp b/src/gui/kernel/qx11embed_x11.cpp
deleted file mode 100644
index 49a819469e..0000000000
--- a/src/gui/kernel/qx11embed_x11.cpp
+++ /dev/null
@@ -1,1808 +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 "qx11embed_x11.h"
-#include <qapplication.h>
-#include <qevent.h>
-#include <qpainter.h>
-#include <qlayout.h>
-#include <qstyle.h>
-#include <qstyleoption.h>
-#include <qelapsedtimer.h>
-#include <qpointer.h>
-#include <qdebug.h>
-#include <qx11info_x11.h>
-#include <private/qt_x11_p.h>
-#include <private/qwidget_p.h>
-
-#define XK_MISCELLANY
-#define XK_LATIN1
-#define None 0
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-#include <X11/Xutil.h>
-#include <X11/keysymdef.h>
-#include <X11/X.h>
-
-#ifndef XK_ISO_Left_Tab
-#define XK_ISO_Left_Tab 0xFE20
-#endif
-
-//#define QX11EMBED_DEBUG
-#ifdef QX11EMBED_DEBUG
-#include <qdebug.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QX11EmbedWidget
- \ingroup advanced
-
- \brief The QX11EmbedWidget class provides an XEmbed client widget.
-
- XEmbed is an X11 protocol that supports the embedding of a widget
- from one application into another application.
-
- An XEmbed \e{client widget} is a window that is embedded into a
- \e container. A container is the graphical location that embeds
- (or \e swallows) an external application.
-
- QX11EmbedWidget is a widget used for writing XEmbed applets or
- plugins. When it has been embedded and the container receives tab
- focus, focus is passed on to the widget. When the widget reaches
- the end of its focus chain, focus is passed back to the
- container. Window activation, accelerator support, modality and
- drag and drop (XDND) are also handled.
-
- The widget and container can both initiate the embedding. If the
- widget is the initiator, the X11 window ID of the container that
- it wants to embed itself into must be passed to embedInto().
-
- If the container initiates the embedding, the window ID of the
- embedded widget must be known. The container calls embed(),
- passing the window ID.
-
- This example shows an application that embeds a QX11EmbedWidget
- subclass into the window whose ID is passed as a command-line
- argument:
-
- \snippet doc/src/snippets/qx11embedwidget/main.cpp 0
-
- The problem of obtaining the window IDs is often solved by the
- container invoking the application that provides the widget as a
- separate process (as a panel invokes a docked applet), passing
- its window ID to the new process as a command-line argument. The
- new process can then call embedInto() with the container's window
- ID, as shown in the example code above. Similarly, the new
- process can report its window ID to the container through IPC, in
- which case the container can embed the widget.
-
- When the widget has been embedded, it emits the signal
- embedded(). If it is closed by the container, the widget emits
- containerClosed(). If an error occurs when embedding, error() is
- emitted.
-
- There are XEmbed widgets available for KDE and GTK+. The GTK+
- equivalent of QX11EmbedWidget is GtkPlug. The corresponding KDE 3
- widget is called QXEmbed.
-
- \sa QX11EmbedContainer, {XEmbed Specification}
-*/
-
-/*!
- \class QX11EmbedContainer
- \ingroup advanced
-
- \brief The QX11EmbedContainer class provides an XEmbed container
- widget.
-
- XEmbed is an X11 protocol that supports the embedding of a widget
- from one application into another application.
-
- An XEmbed \e container is the graphical location that embeds an
- external \e {client widget}. A client widget is a window that is
- embedded into a container.
-
- When a widget has been embedded and the container receives tab
- focus, focus is passed on to the widget. When the widget reaches
- the end of its focus chain, focus is passed back to the
- container. Window activation, accelerator support, modality and
- drag and drop (XDND) are also handled.
-
- QX11EmbedContainer is commonly used for writing panels or
- toolbars that hold applets, or for \e swallowing X11
- applications. When writing a panel application, one container
- widget is created on the toolbar, and it can then either swallow
- another widget using embed(), or allow an XEmbed widget to be
- embedded into itself. The container's X11 window ID, which is
- retrieved with winId(), must then be known to the client widget.
- After embedding, the client's window ID can be retrieved with
- clientWinId().
-
- In the following example, a container widget is created as the
- main widget. It then invokes an application called "playmovie",
- passing its window ID as a command line argument. The "playmovie"
- program is an XEmbed client widget. The widget embeds itself into
- the container using the container's window ID.
-
- \snippet doc/src/snippets/qx11embedcontainer/main.cpp 0
-
- When the client widget is embedded, the container emits the
- signal clientIsEmbedded(). The signal clientClosed() is emitted
- when a widget is closed.
-
- It is possible for QX11EmbedContainer to embed XEmbed widgets
- from toolkits other than Qt, such as GTK+. Arbitrary (non-XEmbed)
- X11 widgets can also be embedded, but the XEmbed-specific
- features such as window activation and focus handling are then
- lost.
-
- The GTK+ equivalent of QX11EmbedContainer is GtkSocket. The
- corresponding KDE 3 widget is called QXEmbed.
-
- \sa QX11EmbedWidget, {XEmbed Specification}
-*/
-
-/*! \fn void QX11EmbedWidget::embedded()
-
- This signal is emitted by the widget that has been embedded by an
- XEmbed container.
-*/
-
-/*! \fn void QX11EmbedWidget::containerClosed()
-
- This signal is emitted by the client widget when the container
- closes the widget. This can happen if the container itself
- closes, or if the widget is rejected.
-
- The container can reject a widget for any reason, but the most
- common cause of a rejection is when an attempt is made to embed a
- widget into a container that already has an embedded widget.
-*/
-
-/*! \fn void QX11EmbedContainer::clientIsEmbedded()
-
- This signal is emitted by the container when a client widget has
- been embedded.
-*/
-
-/*! \fn void QX11EmbedContainer::clientClosed()
-
- This signal is emitted by the container when the client widget
- closes.
-*/
-
-/*!
- \fn void QX11EmbedWidget::error(QX11EmbedWidget::Error error)
-
- This signal is emitted if an error occurred as a result of
- embedding into or communicating with a container. The specified
- \a error describes the problem that occurred.
-
- \sa QX11EmbedWidget::Error
-*/
-
-/*!
- \fn QX11EmbedContainer::Error QX11EmbedContainer::error() const
-
- Returns the last error that occurred.
-*/
-
-/*! \fn void QX11EmbedContainer::error(QX11EmbedContainer::Error error)
-
- This signal is emitted if an error occurred when embedding or
- communicating with a client. The specified \a error describes the
- problem that occurred.
-
- \sa QX11EmbedContainer::Error
-*/
-
-/*!
- \enum QX11EmbedWidget::Error
-
- \value Unknown An unrecognized error occurred.
-
- \value InvalidWindowID The X11 window ID of the container was
- invalid. This error is usually triggered by passing an invalid
- window ID to embedInto().
-
- \omitvalue Internal
-*/
-
-/*!
- \enum QX11EmbedContainer::Error
-
- \value Unknown An unrecognized error occurred.
-
- \value InvalidWindowID The X11 window ID of the container was
- invalid. This error is usually triggered by passing an invalid
- window ID to embed().
-
- \omitvalue Internal
-*/
-
-const int XButtonPress = ButtonPress;
-const int XButtonRelease = ButtonRelease;
-#undef ButtonPress
-#undef ButtonRelease
-
-// This is a hack to move topData() out from QWidgetPrivate to public. We
-// need to to inspect window()'s embedded state.
-class QHackWidget : public QWidget
-{
- Q_DECLARE_PRIVATE(QWidget)
-public:
- QTLWExtra* topData() { return d_func()->topData(); }
-};
-
-static unsigned int XEMBED_VERSION = 0;
-
-enum QX11EmbedMessageType {
- XEMBED_EMBEDDED_NOTIFY = 0,
- XEMBED_WINDOW_ACTIVATE = 1,
- XEMBED_WINDOW_DEACTIVATE = 2,
- XEMBED_REQUEST_FOCUS = 3,
- XEMBED_FOCUS_IN = 4,
- XEMBED_FOCUS_OUT = 5,
- XEMBED_FOCUS_NEXT = 6,
- XEMBED_FOCUS_PREV = 7,
- XEMBED_MODALITY_ON = 10,
- XEMBED_MODALITY_OFF = 11,
- XEMBED_REGISTER_ACCELERATOR = 12,
- XEMBED_UNREGISTER_ACCELERATOR = 13,
- XEMBED_ACTIVATE_ACCELERATOR = 14
-};
-
-enum QX11EmbedFocusInDetail {
- XEMBED_FOCUS_CURRENT = 0,
- XEMBED_FOCUS_FIRST = 1,
- XEMBED_FOCUS_LAST = 2
-};
-
-enum QX11EmbedFocusInFlags {
- XEMBED_FOCUS_OTHER = (0 << 0),
- XEMBED_FOCUS_WRAPAROUND = (1 << 0)
-};
-
-enum QX11EmbedInfoFlags {
- XEMBED_MAPPED = (1 << 0)
-};
-
-enum QX11EmbedAccelModifiers {
- XEMBED_MODIFIER_SHIFT = (1 << 0),
- XEMBED_MODIFIER_CONTROL = (1 << 1),
- XEMBED_MODIFIER_ALT = (1 << 2),
- XEMBED_MODIFIER_SUPER = (1 << 3),
- XEMBED_MODIFIER_HYPER = (1 << 4)
-};
-
-enum QX11EmbedAccelFlags {
- XEMBED_ACCELERATOR_OVERLOADED = (1 << 0)
-};
-
-// Silence the default X11 error handler.
-static int x11ErrorHandler(Display *, XErrorEvent *)
-{
- return 0;
-}
-
-// Returns the X11 timestamp. Maintained mainly by qapplication
-// internals, but also updated by the XEmbed widgets.
-static Time x11Time()
-{
- return qt_x11Data->time;
-}
-
-// Gives the version and flags of the supported XEmbed protocol.
-static unsigned int XEmbedVersion()
-{
- return 0;
-}
-
-// Sends an XEmbed message.
-static void sendXEmbedMessage(WId window, Display *display, long message,
- long detail = 0, long data1 = 0, long data2 = 0)
-{
- XClientMessageEvent c;
- memset(&c, 0, sizeof(c));
- c.type = ClientMessage;
- c.message_type = ATOM(_XEMBED);
- c.format = 32;
- c.display = display;
- c.window = window;
-
- c.data.l[0] = x11Time();
- c.data.l[1] = message;
- c.data.l[2] = detail;
- c.data.l[3] = data1;
- c.data.l[4] = data2;
-
- XSendEvent(display, window, false, NoEventMask, (XEvent *) &c);
-}
-
-// From qapplication_x11.cpp
-static XKeyEvent lastKeyEvent;
-
-static QCoreApplication::EventFilter oldX11EventFilter;
-
-// The purpose of this global x11 filter is for one to capture the key
-// events in their original state, but most importantly this is the
-// only way to get the WM_TAKE_FOCUS message from WM_PROTOCOLS.
-static bool x11EventFilter(void *message, long *result)
-{
- XEvent *event = reinterpret_cast<XEvent *>(message);
- if (event->type == XKeyPress || event->type == XKeyRelease)
- lastKeyEvent = event->xkey;
-
- if (oldX11EventFilter && oldX11EventFilter != &x11EventFilter)
- return oldX11EventFilter(message, result);
- else
- return false;
-}
-
-//
-struct functorData
-{
- Window id, rootWindow;
- bool clearedWmState;
- bool reparentedToRoot;
-};
-
-static Bool functor(Display *display, XEvent *event, XPointer arg)
-{
- functorData *data = (functorData *) arg;
-
- if (!data->reparentedToRoot && event->type == ReparentNotify
- && event->xreparent.window == data->id
- && event->xreparent.parent == data->rootWindow) {
- data->reparentedToRoot = true;
- return true;
- }
-
- if (!data->clearedWmState
- && event->type == PropertyNotify
- && event->xproperty.window == data->id
- && event->xproperty.atom == ATOM(WM_STATE)) {
- if (event->xproperty.state == PropertyDelete) {
- data->clearedWmState = true;
- return true;
- }
-
- Atom ret;
- int format, status;
- unsigned char *retval;
- unsigned long nitems, after;
- status = XGetWindowProperty(display, data->id, ATOM(WM_STATE), 0, 2, False, ATOM(WM_STATE),
- &ret, &format, &nitems, &after, &retval );
- if (status == Success && ret == ATOM(WM_STATE) && format == 32 && nitems > 0) {
- long state = *(long *)retval;
- XFree(retval);
- if (state == WithdrawnState) {
- data->clearedWmState = true;
- return true;
- }
- }
- }
-
- return false;
-}
-
-class QX11EmbedWidgetPrivate : public QWidgetPrivate
-{
- Q_DECLARE_PUBLIC(QX11EmbedWidget)
-public:
- inline QX11EmbedWidgetPrivate()
- {
- lastError = QX11EmbedWidget::Unknown;
- container = 0;
- }
-
- void setEmbedded();
-
- void emitError(QX11EmbedWidget::Error error) {
- Q_Q(QX11EmbedWidget);
-
- lastError = error;
- emit q->error(error);
- }
-
- enum FocusWidgets {
- FirstFocusWidget,
- LastFocusWidget
- };
-
- int focusOriginator;
- QWidget *getFocusWidget(FocusWidgets fw);
- void checkActivateWindow(QObject *o);
- QX11EmbedWidget *xEmbedWidget(QObject *o) const;
- void clearFocus();
-
- WId container;
- QPointer<QWidget> currentFocus;
-
- QX11EmbedWidget::Error lastError;
-
-};
-
-/*!
- Constructs a QX11EmbedWidget object with the given \a parent.
-*/
-QX11EmbedWidget::QX11EmbedWidget(QWidget *parent)
- : QWidget(*new QX11EmbedWidgetPrivate, parent, 0)
-{
- XSetErrorHandler(x11ErrorHandler);
-
- setAttribute(Qt::WA_NativeWindow);
- setAttribute(Qt::WA_DontCreateNativeAncestors);
- createWinId();
- XSelectInput(x11Info().display(), internalWinId(),
- KeyPressMask | KeyReleaseMask | ButtonPressMask
- | ButtonReleaseMask
- | KeymapStateMask | ButtonMotionMask | PointerMotionMask
- | FocusChangeMask
- | ExposureMask | StructureNotifyMask
- | SubstructureNotifyMask | PropertyChangeMask);
-
- long data[] = {XEMBED_VERSION, XEMBED_MAPPED};
- XChangeProperty(x11Info().display(), internalWinId(), ATOM(_XEMBED_INFO),
- ATOM(_XEMBED_INFO), 32, PropModeReplace,
- (unsigned char*) data, 2);
-
- setFocusPolicy(Qt::StrongFocus);
- setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- QApplication::instance()->installEventFilter(this);
-
-#ifdef QX11EMBED_DEBUG
- qDebug() << "QX11EmbedWidget::QX11EmbedWidget: constructed client"
- << (void *)this << "with winId" << winId();
-#endif
-}
-
-/*!
- Destructs the QX11EmbedWidget object. If the widget is embedded
- when deleted, it is hidden and then detached from its container,
- so that the container is free to embed a new widget.
-*/
-QX11EmbedWidget::~QX11EmbedWidget()
-{
- Q_D(QX11EmbedWidget);
- if (d->container) {
-#ifdef QX11EMBED_DEBUG
- qDebug() << "QX11EmbedWidget::~QX11EmbedWidget: unmapping"
- << (void *)this << "with winId" << winId()
- << "from container with winId" << d->container;
-#endif
- XUnmapWindow(x11Info().display(), internalWinId());
- XReparentWindow(x11Info().display(), internalWinId(), x11Info().appRootWindow(x11Info().screen()), 0, 0);
- }
-
-#ifdef QX11EMBED_DEBUG
- qDebug() << "QX11EmbedWidget::~QX11EmbedWidget: destructed client"
- << (void *)this << "with winId" << winId();
-#endif
-}
-
-/*!
- Returns the type of error that occurred last. This is the same error code
- that is emitted by the error() signal.
-
- \sa Error
-*/
-QX11EmbedWidget::Error QX11EmbedWidget::error() const
-{
- return d_func()->lastError;
-}
-
-/*!
- When this function is called, the widget embeds itself into the
- container whose window ID is \a id.
-
- If \a id is \e not the window ID of a container this function will
- behave unpredictably.
-*/
-void QX11EmbedWidget::embedInto(WId id)
-{
- Q_D(QX11EmbedWidget);
-#ifdef QX11EMBED_DEBUG
- qDebug() << "QX11EmbedWidget::embedInto: embedding client"
- << (void *)this << "with winId" << winId() << "into container"
- << id;
-#endif
-
- d->container = id;
- switch (XReparentWindow(x11Info().display(), internalWinId(), d->container, 0, 0)) {
- case BadWindow:
- d->emitError(InvalidWindowID);
- break;
- case BadMatch:
- d->emitError(Internal);
- break;
- case Success:
- default:
- break;
- }
- QTLWExtra* x = d->extra ? d->extra->topextra : 0;
- if (x)
- x->frameStrut.setCoords(0, 0, 0, 0);
- d->data.fstrut_dirty = false;
-}
-
-/*! \internal
-
- Gets the first or last child widget that can get focus.
-*/
-QWidget *QX11EmbedWidgetPrivate::getFocusWidget(FocusWidgets fw)
-{
- Q_Q(QX11EmbedWidget);
- QWidget *tlw = q;
- QWidget *w = tlw->nextInFocusChain();
-
- QWidget *last = tlw;
-
- extern bool qt_tab_all_widgets;
- uint focus_flag = qt_tab_all_widgets ? Qt::TabFocus : Qt::StrongFocus;
-
- while (w != tlw)
- {
- if (((w->focusPolicy() & focus_flag) == focus_flag)
- && w->isVisibleTo(q) && w->isEnabled())
- {
- last = w;
- if (fw == FirstFocusWidget)
- break;
- }
- w = w->nextInFocusChain();
- }
-
- return last;
-}
-
-/*! \internal
-
- Returns the xembed widget that the widget is a child of
-*/
-QX11EmbedWidget *QX11EmbedWidgetPrivate::xEmbedWidget(QObject *o) const
-{
- QX11EmbedWidget *xec = 0;
-
- // Check the widget itself, then its parents, and find the first
- // QX11EmbedWidget.
- do {
- if ((xec = qobject_cast<QX11EmbedWidget *>(o)))
- return xec;
- } while ((o = o->parent()));
- return 0;
-}
-
-/*! \internal
-
- Checks the active window.
-*/
-void QX11EmbedWidgetPrivate::checkActivateWindow(QObject *o)
-{
- Q_Q(QX11EmbedWidget);
- QX11EmbedWidget *xec = xEmbedWidget(o);
-
- // check if we are in the right xembed client
- if (q != xec)
- return;
-
- QWidget *w = qobject_cast<QWidget *>(o);
-
- // if it is no active window, then don't do the change
- if (!(w && qApp->activeWindow()))
- return;
-
- // if it already is the active window, don't do anything
- if (w->window() != qApp->activeWindow())
- {
- qApp->setActiveWindow(w->window());
- currentFocus = w;
-
- sendXEmbedMessage(xec->containerWinId(), q->x11Info().display(), XEMBED_REQUEST_FOCUS);
- }
-}
-
-/*! \internal
-
- Clears the focus
-*/
-void QX11EmbedWidgetPrivate::clearFocus()
-{
- Q_Q(QX11EmbedWidget);
- // Setting focus on the client itself removes Qt's
- // logical focus rectangle. We can't just do a
- // clearFocus here, because when we send the synthetic
- // FocusIn to ourselves on activation, Qt will set
- // focus on focusWidget() again. This way, we "hide"
- // focus rather than clearing it.
-
- if (!q->window()->hasFocus())
- q->window()->setFocus(Qt::OtherFocusReason);
-
- currentFocus = 0;
-}
-
-/*! \internal
-
- Sets the embedded flag on the client.
-*/
-void QX11EmbedWidgetPrivate::setEmbedded()
-{
- Q_Q(QX11EmbedWidget);
- ((QHackWidget *)q->window())->topData()->embedded = 1;
-}
-
-/*! \internal
-
- Handles WindowActivate and FocusIn events for the client.
-*/
-bool QX11EmbedWidget::eventFilter(QObject *o, QEvent *event)
-{
- Q_D(QX11EmbedWidget);
- switch (event->type()) {
- case QEvent::FocusIn:
- switch (((QFocusEvent *)event)->reason()) {
- case Qt::MouseFocusReason:
- // If the user clicks into one of the client widget's
- // children and we didn't have focus already, we request
- // focus from our container.
- if (d->xEmbedWidget(o) == this) {
- if (d->currentFocus.isNull())
- sendXEmbedMessage(d->container, x11Info().display(), XEMBED_REQUEST_FOCUS);
-
- d->currentFocus = qobject_cast<QWidget *>(o);
- }
- break;
- case Qt::TabFocusReason:
- // If the xembed client receives a focus event because of
- // a Tab, then we are at the end of our focus chain and we
- // ask the container to move to its next focus widget.
- if (o == this) {
- d->clearFocus();
- sendXEmbedMessage(d->container, x11Info().display(), XEMBED_FOCUS_NEXT);
- return true;
- } else {
- // We're listening on events from qApp, so in order
- // for us to know who to set focus on if we receive an
- // activation event, we note the widget that got the
- // focusin last.
- if (d->xEmbedWidget(o) == this)
- d->currentFocus = qobject_cast<QWidget *>(o);
- }
- break;
- case Qt::BacktabFocusReason:
- // If the window receives a focus event because of
- // a Backtab, then we are at the start of our focus chain
- // and we ask the container to move to its previous focus
- // widget.
- if (o == this) {
- // See comment for Tab.
- // If we receive a XEMBED_FOCUS_IN
- // XEMBED_FOCUS_CURRENT, we will set focus in
- // currentFocus. To avoid that in this case, we reset
- // currentFocus.
- d->clearFocus();
- sendXEmbedMessage(d->container, x11Info().display(), XEMBED_FOCUS_PREV);
- return true;
- } else {
- if (d->xEmbedWidget(o) == this)
- d->currentFocus = qobject_cast<QWidget *>(o);
- }
- break;
- case Qt::ActiveWindowFocusReason:
- if (isActiveWindow()) {
- if (!d->currentFocus.isNull()) {
- if (!d->currentFocus->hasFocus())
- d->currentFocus->setFocus(Qt::OtherFocusReason);
- } else {
- d->clearFocus();
- return true;
- }
- }
-
- break;
- case Qt::PopupFocusReason:
- case Qt::ShortcutFocusReason:
- case Qt::OtherFocusReason:
- // If focus is received to any child widget because of any
- // other reason, remember the widget so that we can give
- // it focus again if we're activated.
- if (d->xEmbedWidget(o) == this) {
- d->currentFocus = qobject_cast<QWidget *>(o);
- }
- break;
- default:
- break;
- }
- break;
- case QEvent::MouseButtonPress:
- // If we get a mouse button press event inside a embedded widget
- // make sure this is the active window in qapp.
- d->checkActivateWindow(o);
- break;
- default:
- break;
- }
-
- return QWidget::eventFilter(o, event);
-}
-
-/*! \internal
-
- Handles some notification events and client messages. Client side
- XEmbed message receiving is also handled here.
-*/
-bool QX11EmbedWidget::x11Event(XEvent *event)
-{
- Q_D(QX11EmbedWidget);
- switch (event->type) {
- case DestroyNotify:
-#ifdef QX11EMBED_DEBUG
- qDebug() << "QX11EmbedWidget::x11Event: client"
- << (void *)this << "with winId" << winId()
- << "received a DestroyNotify";
-#endif
- // If the container window is destroyed, we signal this to the user.
- d->container = 0;
- emit containerClosed();
- break;
- case ReparentNotify:
-#ifdef QX11EMBED_DEBUG
- qDebug() << "QX11EmbedWidget::x11Event: client"
- << (void *)this << "with winId" << winId()
- << "received a ReparentNotify to"
- << ((event->xreparent.parent == x11Info().appRootWindow(x11Info().screen()))
- ? QString::fromLatin1("root") : QString::number(event->xreparent.parent));
-#endif
- // If the container shuts down, we will be reparented to the
- // root window. We must also consider the case that we may be
- // reparented from one container to another.
- if (event->xreparent.parent == x11Info().appRootWindow(x11Info().screen())) {
- if (((QHackWidget *)this)->topData()->embedded) {
- d->container = 0;
- emit containerClosed();
- }
- return true;
- } else {
- d->container = event->xreparent.parent;
- }
- break;
- case UnmapNotify:
- // Mapping and unmapping are handled by changes to the
- // _XEMBED_INFO property. Any default map/unmap requests are
- // ignored.
- return true;
- case PropertyNotify:
- // The container sends us map/unmap messages through the
- // _XEMBED_INFO property. We adhere to the XEMBED_MAPPED bit in
- // data2.
- if (event->xproperty.atom == ATOM(_XEMBED_INFO)) {
- Atom actual_type_return;
- int actual_format_return;
- unsigned long nitems_return;
- unsigned long bytes_after_return;
- unsigned char *prop_return = 0;
- if (XGetWindowProperty(x11Info().display(), internalWinId(), ATOM(_XEMBED_INFO), 0, 2,
- false, ATOM(_XEMBED_INFO), &actual_type_return,
- &actual_format_return, &nitems_return,
- &bytes_after_return, &prop_return) == Success) {
- if (nitems_return > 1) {
- if (((long * )prop_return)[1] & XEMBED_MAPPED) {
- XMapWindow(x11Info().display(), internalWinId());
- } else {
- XUnmapWindow(x11Info().display(), internalWinId());
- }
- }
- if (prop_return)
- XFree(prop_return);
- }
- }
-
- break;
- case ClientMessage:
- // XEMBED messages have message_type _XEMBED
- if (event->xclient.message_type == ATOM(_XEMBED)) {
- // Discard XEMBED messages not to ourselves. (### dead code?)
- if (event->xclient.window != internalWinId())
- break;
-
- // Update qt_x_time if necessary
- Time msgtime = (Time) event->xclient.data.l[0];
- if (msgtime > X11->time)
- X11->time = msgtime;
-
- switch (event->xclient.data.l[1]) {
- case XEMBED_WINDOW_ACTIVATE: {
- // When we receive an XEMBED_WINDOW_ACTIVATE, we simply send
- // ourselves a WindowActivate event. Real activation happens
- // when receive XEMBED_FOCUS_IN.
- if (!isActiveWindow()) {
- QEvent ev(QEvent::WindowActivate);
- QApplication::sendEvent(this, &ev);
- }
- }
- break;
- case XEMBED_WINDOW_DEACTIVATE: {
- // When we receive an XEMBED_WINDOW_DEACTIVATE, we simply send
- // ourselves a WindowDeactivate event. Real activation happens
- // when receive XEMBED_FOCUS_IN.
- if (isActiveWindow()) {
- if (!qApp->activePopupWidget())
- QApplication::setActiveWindow(0);
- } else {
- QEvent ev(QEvent::WindowDeactivate);
- QApplication::sendEvent(this, &ev);
- }
- }
- break;
- case XEMBED_EMBEDDED_NOTIFY: {
-#ifdef QX11EMBED_DEBUG
- qDebug() << "QX11EmbedWidget::x11Event: client"
- << (void *)this << "with winId" << winId()
- << "received an XEMBED EMBEDDED NOTIFY message";
-#endif
- // In this message's l[2] we have the max version
- // supported by both the client and the
- // container. QX11EmbedWidget does not use this field.
-
- // We have been embedded, so we set our
- // client's embedded flag.
- d->setEmbedded();
- emit embedded();
- }
- break;
- case XEMBED_FOCUS_IN:
- // don't set the focus if a modal dialog is open
- if (qApp->activeModalWidget())
- break;
-
- // in case we embed more than one topLevel window inside the same
- // host window.
- if (window() != qApp->activeWindow())
- qApp->setActiveWindow(this);
-
- switch (event->xclient.data.l[2]) {
- case XEMBED_FOCUS_CURRENT:
- // The container sends us this message if it wants
- // us to focus on the widget that last had focus.
- // This is the reply when XEMBED_REQUEST_FOCUS is
- // sent to the container.
- if (!d->currentFocus.isNull()) {
- if (!d->currentFocus->hasFocus())
- d->currentFocus->setFocus(Qt::OtherFocusReason);
- } else {
- // No widget currently has focus. We set focus
- // on the first widget next to the
- // client widget. Since the setFocus will not work
- // if the window is disabled, set the currentFocus
- // directly so that it's set on window activate.
- d->currentFocus = d->getFocusWidget(QX11EmbedWidgetPrivate::FirstFocusWidget);
- d->currentFocus->setFocus(Qt::OtherFocusReason);
- }
- break;
- case XEMBED_FOCUS_FIRST:
- // The container sends this message when it wants
- // us to focus on the first widget in our focus
- // chain (typically because of a tab).
- d->currentFocus = d->getFocusWidget(QX11EmbedWidgetPrivate::FirstFocusWidget);
- d->currentFocus->setFocus(Qt::TabFocusReason);
- break;
- case XEMBED_FOCUS_LAST:
- // The container sends this message when it wants
- // us to focus on the last widget in our focus
- // chain (typically because of a backtab).
- d->currentFocus = d->getFocusWidget(QX11EmbedWidgetPrivate::LastFocusWidget);
- d->currentFocus->setFocus(Qt::BacktabFocusReason);
- break;
- default:
- // Ignore any other XEMBED_FOCUS_IN details.
- break;
- }
- break;
- case XEMBED_FOCUS_OUT:
- // The container sends us this message when it wants us
- // to lose focus and forget about the widget that last
- // had focus. Typically sent by the container when it
- // loses focus because of mouse or tab activity. We do
- // then not want to set focus on anything if we're
- // activated.
- if (isActiveWindow())
- d->clearFocus();
-
- break;
- default:
- // Ignore any other XEMBED messages.
- break;
- };
- } else {
- // Non-XEMBED client messages are not interesting.
- }
-
- break;
- default:
- // Ignore all other x11 events.
- break;
- }
-
- // Allow default handling.
- return QWidget::x11Event(event);
-}
-
-/*!
- \reimp
-*/
-bool QX11EmbedWidget::event(QEvent *event)
-{
- if (event->type() == QEvent::ParentChange) {
- XSelectInput(x11Info().display(), internalWinId(),
- KeyPressMask | KeyReleaseMask | ButtonPressMask
- | ButtonReleaseMask
- | KeymapStateMask | ButtonMotionMask | PointerMotionMask
- | FocusChangeMask
- | ExposureMask | StructureNotifyMask
- | SubstructureNotifyMask | PropertyChangeMask);
- }
- return QWidget::event(event);
-}
-
-/*!
- \reimp
-*/
-void QX11EmbedWidget::resizeEvent(QResizeEvent *event)
-{
- if (layout())
- layout()->update();
- QWidget::resizeEvent(event);
-}
-
-/*!
- If the widget is embedded, returns the window ID of the
- container; otherwize returns 0.
-*/
-WId QX11EmbedWidget::containerWinId() const
-{
- Q_D(const QX11EmbedWidget);
- return d->container;
-}
-
-class QX11EmbedContainerPrivate : public QWidgetPrivate
-{
- Q_DECLARE_PUBLIC(QX11EmbedContainer)
-public:
- inline QX11EmbedContainerPrivate()
- {
- lastError = QX11EmbedContainer::Unknown;
- client = 0;
- focusProxy = 0;
- clientIsXEmbed = false;
- xgrab = false;
- }
-
- bool isEmbedded() const;
- void moveInputToProxy();
-
- void acceptClient(WId window);
- void rejectClient(WId window);
-
- void checkGrab();
-
- WId topLevelParentWinId() const;
-
- void emitError(QX11EmbedContainer::Error error) {
- Q_Q(QX11EmbedContainer);
- lastError = error;
- emit q->error(error);
- }
-
- WId client;
- QWidget *focusProxy;
- bool clientIsXEmbed;
- bool xgrab;
- QRect clientOriginalRect;
- QSize wmMinimumSizeHint;
-
- QX11EmbedContainer::Error lastError;
-
- static QX11EmbedContainer *activeContainer;
-};
-
-QX11EmbedContainer *QX11EmbedContainerPrivate::activeContainer = 0;
-
-/*!
- Creates a QX11EmbedContainer object with the given \a parent.
-*/
-QX11EmbedContainer::QX11EmbedContainer(QWidget *parent)
- : QWidget(*new QX11EmbedContainerPrivate, parent, 0)
-{
- Q_D(QX11EmbedContainer);
- XSetErrorHandler(x11ErrorHandler);
-
- setAttribute(Qt::WA_NativeWindow);
- setAttribute(Qt::WA_DontCreateNativeAncestors);
- createWinId();
-
- setFocusPolicy(Qt::StrongFocus);
- setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- // ### PORT setKeyCompression(false);
- setAcceptDrops(true);
- setEnabled(false);
-
- // Everybody gets a focus proxy, but only one toplevel container's
- // focus proxy is actually in use.
- d->focusProxy = new QWidget(this);
- d->focusProxy->setAttribute(Qt::WA_NativeWindow);
- d->focusProxy->setAttribute(Qt::WA_DontCreateNativeAncestors);
- d->focusProxy->createWinId();
- d->focusProxy->setGeometry(-1, -1, 1, 1);
-
- // We need events from the window (activation status) and
- // from qApp (keypress/release).
- qApp->installEventFilter(this);
-
- // Install X11 event filter.
- if (!oldX11EventFilter)
- oldX11EventFilter = QCoreApplication::instance()->setEventFilter(x11EventFilter);
-
- XSelectInput(x11Info().display(), internalWinId(),
- KeyPressMask | KeyReleaseMask
- | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
- | KeymapStateMask
- | PointerMotionMask
- | EnterWindowMask | LeaveWindowMask
- | FocusChangeMask
- | ExposureMask
- | StructureNotifyMask
- | SubstructureNotifyMask);
-
- // Make sure our new event mask takes effect as soon as possible.
- XFlush(x11Info().display());
-
- // Move input to our focusProxy if this widget is active, and not
- // shaded by a modal dialog (in which case isActiveWindow() would
- // still return true, but where we must not move input focus).
- if (qApp->activeWindow() == window() && !d->isEmbedded())
- d->moveInputToProxy();
-
-#ifdef QX11EMBED_DEBUG
- qDebug() << "QX11EmbedContainer::QX11EmbedContainer: constructed container"
- << (void *)this << "with winId" << winId();
-#endif
-}
-
-/*!
- Destructs a QX11EmbedContainer.
-*/
-QX11EmbedContainer::~QX11EmbedContainer()
-{
- Q_D(QX11EmbedContainer);
- if (d->client) {
- XUnmapWindow(x11Info().display(), d->client);
- XReparentWindow(x11Info().display(), d->client, x11Info().appRootWindow(x11Info().screen()), 0, 0);
- }
-
- if (d->xgrab)
- XUngrabButton(x11Info().display(), AnyButton, AnyModifier, internalWinId());
-}
-
-
-QX11EmbedContainer::Error QX11EmbedContainer::error() const {
- return d_func()->lastError;
-}
-
-
-/*! \reimp
-*/
-void QX11EmbedContainer::paintEvent(QPaintEvent *)
-{
-}
-
-/*! \internal
-
- Returns whether or not the windows' embedded flag is set.
-*/
-bool QX11EmbedContainerPrivate::isEmbedded() const
-{
- Q_Q(const QX11EmbedContainer);
- return ((QHackWidget *)q->window())->topData()->embedded == 1;
-}
-
-/*! \internal
-
- Returns the parentWinId of the window.
-*/
-WId QX11EmbedContainerPrivate::topLevelParentWinId() const
-{
- Q_Q(const QX11EmbedContainer);
- return ((QHackWidget *)q->window())->topData()->parentWinId;
-}
-
-/*!
- If the container has an embedded widget, this function returns
- the X11 window ID of the client; otherwise it returns 0.
-*/
-WId QX11EmbedContainer::clientWinId() const
-{
- Q_D(const QX11EmbedContainer);
- return d->client;
-}
-
-/*!
- Instructs the container to embed the X11 window with window ID \a
- id. The client widget will then move on top of the container
- window and be resized to fit into the container.
-
- The \a id should be the ID of a window controlled by an XEmbed
- enabled application, but this is not mandatory. If \a id does not
- belong to an XEmbed client widget, then focus handling,
- activation, accelerators and other features will not work
- properly.
-*/
-void QX11EmbedContainer::embedClient(WId id)
-{
- Q_D(QX11EmbedContainer);
-
- if (id == 0) {
- d->emitError(InvalidWindowID);
- return;
- }
-
- // Walk up the tree of parent windows to prevent embedding of ancestors.
- WId thisId = internalWinId();
- Window rootReturn;
- Window parentReturn;
- Window *childrenReturn = 0;
- unsigned int nchildrenReturn;
- do {
- if (XQueryTree(x11Info().display(), thisId, &rootReturn,
- &parentReturn, &childrenReturn, &nchildrenReturn) == 0) {
- d->emitError(InvalidWindowID);
- return;
- }
- if (childrenReturn) {
- XFree(childrenReturn);
- childrenReturn = 0;
- }
-
- thisId = parentReturn;
- if (id == thisId) {
- d->emitError(InvalidWindowID);
- return;
- }
- } while (thisId != rootReturn);
-
- // watch for property notify events (see below)
- XGrabServer(x11Info().display());
- XWindowAttributes attrib;
- if (!XGetWindowAttributes(x11Info().display(), id, &attrib)) {
- XUngrabServer(x11Info().display());
- d->emitError(InvalidWindowID);
- return;
- }
- XSelectInput(x11Info().display(), id, attrib.your_event_mask | PropertyChangeMask | StructureNotifyMask);
- XUngrabServer(x11Info().display());
-
- // Put the window into WithdrawnState
- XUnmapWindow(x11Info().display(), id);
- XSync(x11Info().display(), False); // make sure the window is hidden
-
- /*
- Wait for notification from the window manager that the window is
- in withdrawn state. According to the ICCCM section 4.1.3.1,
- we should wait for the WM_STATE property to either be deleted or
- set to WithdrawnState.
-
- For safety, we will not wait more than 500 ms, so that we can
- preemptively workaround buggy window managers.
- */
- QElapsedTimer t;
- t.start();
-
- functorData data;
- data.id = id;
- data.rootWindow = attrib.root;
- data.clearedWmState = false;
- data.reparentedToRoot = false;
-
- do {
- if (t.elapsed() > 500) // time-out after 500 ms
- break;
-
- XEvent event;
- if (!XCheckIfEvent(x11Info().display(), &event, functor, (XPointer) &data)) {
- XSync(x11Info().display(), False);
- usleep(50000);
- continue;
- }
-
- qApp->x11ProcessEvent(&event);
- } while (!data.clearedWmState || !data.reparentedToRoot);
-
- // restore the event mask
- XSelectInput(x11Info().display(), id, attrib.your_event_mask);
-
- switch (XReparentWindow(x11Info().display(), id, internalWinId(), 0, 0)) {
- case BadWindow:
- case BadMatch:
- d->emitError(InvalidWindowID);
- break;
- default:
- break;
- }
-}
-
-/*! \internal
-
- Handles key, activation and focus events for the container.
-*/
-bool QX11EmbedContainer::eventFilter(QObject *o, QEvent *event)
-{
- Q_D(QX11EmbedContainer);
- switch (event->type()) {
- case QEvent::KeyPress:
- // Forward any keypresses to our client.
- if (o == this && d->client) {
- lastKeyEvent.window = d->client;
- XSendEvent(x11Info().display(), d->client, false, KeyPressMask, (XEvent *) &lastKeyEvent);
- return true;
- }
- break;
- case QEvent::KeyRelease:
- // Forward any keyreleases to our client.
- if (o == this && d->client) {
- lastKeyEvent.window = d->client;
- XSendEvent(x11Info().display(), d->client, false, KeyReleaseMask, (XEvent *) &lastKeyEvent);
- return true;
- }
- break;
-
- case QEvent::WindowActivate:
- // When our container window is activated, we pass the
- // activation message on to our client. Note that X input
- // focus is set to our focus proxy. We want to intercept all
- // keypresses.
- if (o == window() && d->client) {
- if (d->clientIsXEmbed) {
- sendXEmbedMessage(d->client, x11Info().display(), XEMBED_WINDOW_ACTIVATE);
- } else {
- d->checkGrab();
- if (hasFocus())
- XSetInputFocus(x11Info().display(), d->client, XRevertToParent, x11Time());
- }
- if (!d->isEmbedded())
- d->moveInputToProxy();
- }
- break;
- case QEvent::WindowDeactivate:
- // When our container window is deactivated, we pass the
- // deactivation message to our client.
- if (o == window() && d->client) {
- if (d->clientIsXEmbed)
- sendXEmbedMessage(d->client, x11Info().display(), XEMBED_WINDOW_DEACTIVATE);
- else
- d->checkGrab();
- }
- break;
- case QEvent::FocusIn:
- // When receiving FocusIn events generated by Tab or Backtab,
- // we pass focus on to our client. Any mouse activity is sent
- // directly to the client, and it will ask us for focus with
- // XEMBED_REQUEST_FOCUS.
- if (o == this && d->client) {
- if (!d->isEmbedded())
- d->activeContainer = this;
-
- if (d->clientIsXEmbed) {
- if (!d->isEmbedded())
- d->moveInputToProxy();
-
- QFocusEvent *fe = (QFocusEvent *)event;
- switch (fe->reason()) {
- case Qt::TabFocusReason:
- sendXEmbedMessage(d->client, x11Info().display(), XEMBED_FOCUS_IN, XEMBED_FOCUS_FIRST);
- break;
- case Qt::BacktabFocusReason:
- sendXEmbedMessage(d->client, x11Info().display(), XEMBED_FOCUS_IN, XEMBED_FOCUS_LAST);
- break;
- default:
- sendXEmbedMessage(d->client, x11Info().display(), XEMBED_FOCUS_IN, XEMBED_FOCUS_CURRENT);
- break;
- }
- } else {
- d->checkGrab();
- XSetInputFocus(x11Info().display(), d->client, XRevertToParent, x11Time());
- }
- }
-
- break;
- case QEvent::FocusOut: {
- // When receiving a FocusOut, we ask our client to remove its
- // focus.
- if (o == this && d->client) {
- if (!d->isEmbedded()) {
- d->activeContainer = 0;
- if (isActiveWindow())
- d->moveInputToProxy();
- }
-
- if (d->clientIsXEmbed) {
- QFocusEvent *fe = (QFocusEvent *)event;
- if (o == this && d->client && fe->reason() != Qt::ActiveWindowFocusReason)
- sendXEmbedMessage(d->client, x11Info().display(), XEMBED_FOCUS_OUT);
- } else {
- d->checkGrab();
- }
- }
- }
- break;
-
- case QEvent::Close: {
- if (o == this && d->client) {
- // Unmap the client and reparent it to the root window.
- // Wait until the messages have been processed. Then ask
- // the window manager to delete the window.
- XUnmapWindow(x11Info().display(), d->client);
- XReparentWindow(x11Info().display(), d->client, x11Info().appRootWindow(x11Info().screen()), 0, 0);
- XSync(x11Info().display(), false);
-
- XEvent ev;
- memset(&ev, 0, sizeof(ev));
- ev.xclient.type = ClientMessage;
- ev.xclient.window = d->client;
- ev.xclient.message_type = ATOM(WM_PROTOCOLS);
- ev.xclient.format = 32;
- ev.xclient.data.s[0] = ATOM(WM_DELETE_WINDOW);
- XSendEvent(x11Info().display(), d->client, false, NoEventMask, &ev);
-
- XFlush(x11Info().display());
- d->client = 0;
- d->clientIsXEmbed = false;
- d->wmMinimumSizeHint = QSize();
- updateGeometry();
- setEnabled(false);
- update();
-
- emit clientClosed();
- }
- }
- default:
- break;
- }
-
- return QWidget::eventFilter(o, event);
-}
-
-/*! \internal
-
- Handles X11 events for the container.
-*/
-bool QX11EmbedContainer::x11Event(XEvent *event)
-{
- Q_D(QX11EmbedContainer);
-
- switch (event->type) {
- case CreateNotify:
- // The client created an embedded window.
- if (d->client)
- d->rejectClient(event->xcreatewindow.window);
- else
- d->acceptClient(event->xcreatewindow.window);
- break;
- case DestroyNotify:
- if (event->xdestroywindow.window == d->client) {
- // The client died.
- d->client = 0;
- d->clientIsXEmbed = false;
- d->wmMinimumSizeHint = QSize();
- updateGeometry();
- update();
- setEnabled(false);
- emit clientClosed();
- }
- break;
- case ReparentNotify:
- // The client sends us this if it reparents itself out of our
- // widget.
- if (event->xreparent.window == d->client && event->xreparent.parent != internalWinId()) {
- d->client = 0;
- d->clientIsXEmbed = false;
- d->wmMinimumSizeHint = QSize();
- updateGeometry();
- update();
- setEnabled(false);
- emit clientClosed();
- } else if (event->xreparent.parent == internalWinId()) {
- // The client reparented itself into this window.
- if (d->client)
- d->rejectClient(event->xreparent.window);
- else
- d->acceptClient(event->xreparent.window);
- }
- break;
- case ClientMessage: {
- if (event->xclient.message_type == ATOM(_XEMBED)) {
- // Ignore XEMBED messages not to ourselves
- if (event->xclient.window != internalWinId())
- break;
-
- // Receiving an XEmbed message means the client
- // is an XEmbed client.
- d->clientIsXEmbed = true;
-
- Time msgtime = (Time) event->xclient.data.l[0];
- if (msgtime > X11->time)
- X11->time = msgtime;
-
- switch (event->xclient.data.l[1]) {
- case XEMBED_REQUEST_FOCUS: {
- // This typically happens when the client gets focus
- // because of a mouse click.
- if (!hasFocus())
- setFocus(Qt::OtherFocusReason);
-
- // The message is passed along to the topmost container
- // that eventually responds with a XEMBED_FOCUS_IN
- // message. The focus in message is passed all the way
- // back until it reaches the original focus
- // requestor. In the end, not only the original client
- // has focus, but also all its ancestor containers.
- if (d->isEmbedded()) {
- // If our window's embedded flag is set, then
- // that suggests that we are part of a client. The
- // parentWinId will then point to an container to whom
- // we must pass this message.
- sendXEmbedMessage(d->topLevelParentWinId(), x11Info().display(), XEMBED_REQUEST_FOCUS);
- } else {
- // Our window's embedded flag is not set,
- // so we are the topmost container. We respond to
- // the focus request message with a focus in
- // message. This message will pass on from client
- // to container to client until it reaches the
- // originator of the XEMBED_REQUEST_FOCUS message.
- sendXEmbedMessage(d->client, x11Info().display(), XEMBED_FOCUS_IN, XEMBED_FOCUS_CURRENT);
- }
-
- break;
- }
- case XEMBED_FOCUS_NEXT:
- // Client sends this event when it received a tab
- // forward and was at the end of its focus chain. If
- // we are the only widget in the focus chain, we send
- // ourselves a FocusIn event.
- if (d->focus_next != this) {
- focusNextPrevChild(true);
- } else {
- QFocusEvent event(QEvent::FocusIn, Qt::TabFocusReason);
- qApp->sendEvent(this, &event);
- }
-
- break;
- case XEMBED_FOCUS_PREV:
- // Client sends this event when it received a backtab
- // and was at the start of its focus chain. If we are
- // the only widget in the focus chain, we send
- // ourselves a FocusIn event.
- if (d->focus_next != this) {
- focusNextPrevChild(false);
- } else {
- QFocusEvent event(QEvent::FocusIn, Qt::BacktabFocusReason);
- qApp->sendEvent(this, &event);
- }
-
- break;
- default:
- break;
- }
- }
- }
- break;
- case XButtonPress:
- if (!d->clientIsXEmbed) {
- setFocus(Qt::MouseFocusReason);
- XAllowEvents(x11Info().display(), ReplayPointer, CurrentTime);
- return true;
- }
- break;
- case XButtonRelease:
- if (!d->clientIsXEmbed)
- XAllowEvents(x11Info().display(), SyncPointer, CurrentTime);
- break;
- default:
- break;
- }
-
- return QWidget::x11Event(event);
-}
-
-/*! \internal
-
- Whenever the container is resized, we need to resize our client.
-*/
-void QX11EmbedContainer::resizeEvent(QResizeEvent *)
-{
- Q_D(QX11EmbedContainer);
- if (d->client)
- XResizeWindow(x11Info().display(), d->client, width(), height());
-}
-
-/*! \internal
-
- We use the QShowEvent to signal to our client that we want it to
- map itself. We do this by changing its window property
- XEMBED_INFO. The client will get an X11 PropertyNotify.
-*/
-void QX11EmbedContainer::showEvent(QShowEvent *)
-{
- Q_D(QX11EmbedContainer);
- if (d->client) {
- long data[] = {XEMBED_VERSION, XEMBED_MAPPED};
- XChangeProperty(x11Info().display(), d->client, ATOM(_XEMBED_INFO), ATOM(_XEMBED_INFO), 32,
- PropModeReplace, (unsigned char *) data, 2);
- }
-}
-
-/*! \internal
-
- We use the QHideEvent to signal to our client that we want it to
- unmap itself. We do this by changing its window property
- XEMBED_INFO. The client will get an X11 PropertyNotify.
-*/
-void QX11EmbedContainer::hideEvent(QHideEvent *)
-{
- Q_D(QX11EmbedContainer);
- if (d->client) {
- long data[] = {XEMBED_VERSION, XEMBED_MAPPED};
- XChangeProperty(x11Info().display(), d->client, ATOM(_XEMBED_INFO), ATOM(_XEMBED_INFO), 32,
- PropModeReplace, (unsigned char *) data, 2);
- }
-}
-
-/*!
- \reimp
-*/
-bool QX11EmbedContainer::event(QEvent *event)
-{
- if (event->type() == QEvent::ParentChange) {
- XSelectInput(x11Info().display(), internalWinId(),
- KeyPressMask | KeyReleaseMask
- | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
- | KeymapStateMask
- | PointerMotionMask
- | EnterWindowMask | LeaveWindowMask
- | FocusChangeMask
- | ExposureMask
- | StructureNotifyMask
- | SubstructureNotifyMask);
- }
- return QWidget::event(event);
-}
-
-/*! \internal
-
- Rejects a client window by reparenting it to the root window. The
- client will receive a reparentnotify, and will most likely assume
- that the container has shut down. The XEmbed protocol does not
- define any way to reject a client window, but this is a clean way
- to do it.
-*/
-void QX11EmbedContainerPrivate::rejectClient(WId window)
-{
- Q_Q(QX11EmbedContainer);
- q->setEnabled(false);
- XRemoveFromSaveSet(q->x11Info().display(), client);
- XReparentWindow(q->x11Info().display(), window, q->x11Info().appRootWindow(q->x11Info().screen()), 0, 0);
-}
-
-/*! \internal
-
- Accepts a client by mapping it, resizing it and optionally
- activating and giving it logical focusing through XEMBED messages.
-*/
-void QX11EmbedContainerPrivate::acceptClient(WId window)
-{
- Q_Q(QX11EmbedContainer);
- client = window;
- q->setEnabled(true);
-
- // This tells Qt that we wish to forward DnD messages to
- // our client.
- if (!extra)
- createExtra();
- extraData()->xDndProxy = client;
-
- unsigned int version = XEmbedVersion();
-
- Atom actual_type_return;
- int actual_format_return;
- unsigned long nitems_return = 0;
- unsigned long bytes_after_return;
- unsigned char *prop_return = 0;
- unsigned int clientversion = 0;
-
- // Add this client to our saveset, so if we crash, the client window
- // doesn't get destroyed. This is useful for containers that restart
- // automatically after a crash, because it can simply reembed its clients
- // without having to restart them (KDE panel).
- XAddToSaveSet(q->x11Info().display(), client);
-
- // XEmbed clients have an _XEMBED_INFO property in which we can
- // fetch the version
- if (XGetWindowProperty(q->x11Info().display(), client, ATOM(_XEMBED_INFO), 0, 2, false,
- ATOM(_XEMBED_INFO), &actual_type_return, &actual_format_return,
- &nitems_return, &bytes_after_return, &prop_return) == Success) {
-
- if (actual_type_return != None && actual_format_return != 0) {
- // Clients with the _XEMBED_INFO property are XEMBED clients.
- clientIsXEmbed = true;
-
- long *p = (long *)prop_return;
- if (nitems_return >= 2)
- clientversion = (unsigned int)p[0];
- }
-
- XFree(prop_return);
- }
-
- // Store client window's original size and placement.
- Window root;
- int x_return, y_return;
- unsigned int width_return, height_return, border_width_return, depth_return;
- XGetGeometry(q->x11Info().display(), client, &root, &x_return, &y_return,
- &width_return, &height_return, &border_width_return, &depth_return);
- clientOriginalRect.setCoords(x_return, y_return,
- x_return + width_return - 1,
- y_return + height_return - 1);
-
- // Ask the client for its minimum size.
- XSizeHints size;
- long msize;
- if (XGetWMNormalHints(q->x11Info().display(), client, &size, &msize) && (size.flags & PMinSize)) {
- wmMinimumSizeHint = QSize(size.min_width, size.min_height);
- q->updateGeometry();
- }
-
- // The container should set the data2 field to the lowest of its
- // supported version number and that of the client (from
- // _XEMBED_INFO property).
- unsigned int minversion = version > clientversion ? clientversion : version;
- sendXEmbedMessage(client, q->x11Info().display(), XEMBED_EMBEDDED_NOTIFY, q->internalWinId(), minversion);
- XMapWindow(q->x11Info().display(), client);
-
- // Resize it, but no smaller than its minimum size hint.
- XResizeWindow(q->x11Info().display(),
- client,
- qMax(q->width(), wmMinimumSizeHint.width()),
- qMax(q->height(), wmMinimumSizeHint.height()));
- q->update();
-
- // Not mentioned in the protocol is that if the container
- // is already active, the client must be activated to work
- // properly.
- if (q->window()->isActiveWindow())
- sendXEmbedMessage(client, q->x11Info().display(), XEMBED_WINDOW_ACTIVATE);
-
- // Also, if the container already has focus, then it must
- // send a focus in message to its new client; otherwise we ask
- // it to remove focus.
- if (q->focusWidget() == q && q->hasFocus())
- sendXEmbedMessage(client, q->x11Info().display(), XEMBED_FOCUS_IN, XEMBED_FOCUS_FIRST);
- else
- sendXEmbedMessage(client, q->x11Info().display(), XEMBED_FOCUS_OUT);
-
- if (!clientIsXEmbed) {
- checkGrab();
- if (q->hasFocus()) {
- XSetInputFocus(q->x11Info().display(), client, XRevertToParent, x11Time());
- }
- } else {
- if (!isEmbedded())
- moveInputToProxy();
- }
-
- emit q->clientIsEmbedded();
-}
-
-/*! \internal
-
- Moves X11 keyboard input focus to the focusProxy, unless the focus
- is there already. When X11 keyboard input focus is on the
- focusProxy, which is a child of the container and a sibling of the
- client, X11 keypresses and keyreleases will always go to the proxy
- and not to the client.
-*/
-void QX11EmbedContainerPrivate::moveInputToProxy()
-{
- Q_Q(QX11EmbedContainer);
- // Following Owen Taylor's advice from the XEmbed specification to
- // always use CurrentTime when no explicit user action is involved.
- XSetInputFocus(q->x11Info().display(), focusProxy->internalWinId(), XRevertToParent, CurrentTime);
-}
-
-/*! \internal
-
- Ask the window manager to give us a default minimum size.
-*/
-QSize QX11EmbedContainer::minimumSizeHint() const
-{
- Q_D(const QX11EmbedContainer);
- if (!d->client || !d->wmMinimumSizeHint.isValid())
- return QWidget::minimumSizeHint();
- return d->wmMinimumSizeHint;
-}
-
-/*! \internal
-
-*/
-void QX11EmbedContainerPrivate::checkGrab()
-{
- Q_Q(QX11EmbedContainer);
- if (!clientIsXEmbed && q->isActiveWindow() && !q->hasFocus()) {
- if (!xgrab) {
- XGrabButton(q->x11Info().display(), AnyButton, AnyModifier, q->internalWinId(),
- true, ButtonPressMask, GrabModeSync, GrabModeAsync,
- None, None);
- }
- xgrab = true;
- } else {
- if (xgrab)
- XUngrabButton(q->x11Info().display(), AnyButton, AnyModifier, q->internalWinId());
- xgrab = false;
- }
-}
-
-/*!
- Detaches the client from the embedder. The client will appear as a
- standalone window on the desktop.
-*/
-void QX11EmbedContainer::discardClient()
-{
- Q_D(QX11EmbedContainer);
- if (d->client) {
- XResizeWindow(x11Info().display(), d->client, d->clientOriginalRect.width(),
- d->clientOriginalRect.height());
-
- d->rejectClient(d->client);
- }
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qx11embed_x11.h b/src/gui/kernel/qx11embed_x11.h
deleted file mode 100644
index 30929f7ba9..0000000000
--- a/src/gui/kernel/qx11embed_x11.h
+++ /dev/null
@@ -1,132 +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 QX11EMBED_X11_H
-#define QX11EMBED_X11_H
-
-#include <QtGui/qwidget.h>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Gui)
-
-class QX11EmbedWidgetPrivate;
-class Q_GUI_EXPORT QX11EmbedWidget : public QWidget
-{
- Q_OBJECT
-public:
- QX11EmbedWidget(QWidget *parent = 0);
- ~QX11EmbedWidget();
-
- void embedInto(WId id);
- WId containerWinId() const;
-
- enum Error {
- Unknown,
- Internal,
- InvalidWindowID
- };
- Error error() const;
-
-Q_SIGNALS:
- void embedded();
- void containerClosed();
- void error(QX11EmbedWidget::Error error);
-
-protected:
- bool x11Event(XEvent *);
- bool eventFilter(QObject *, QEvent *);
- bool event(QEvent *);
- void resizeEvent(QResizeEvent *);
-
-private:
- Q_DECLARE_PRIVATE(QX11EmbedWidget)
- Q_DISABLE_COPY(QX11EmbedWidget)
-};
-
-class QX11EmbedContainerPrivate;
-class Q_GUI_EXPORT QX11EmbedContainer : public QWidget
-{
- Q_OBJECT
-public:
- QX11EmbedContainer(QWidget *parent = 0);
- ~QX11EmbedContainer();
-
- void embedClient(WId id);
- void discardClient();
-
- WId clientWinId() const;
-
- QSize minimumSizeHint() const;
-
- enum Error {
- Unknown,
- Internal,
- InvalidWindowID
- };
- Error error() const;
-
-Q_SIGNALS:
- void clientIsEmbedded();
- void clientClosed();
- void error(QX11EmbedContainer::Error);
-
-protected:
- bool x11Event(XEvent *);
- bool eventFilter(QObject *, QEvent *);
- void paintEvent(QPaintEvent *e);
- void resizeEvent(QResizeEvent *);
- void showEvent(QShowEvent *);
- void hideEvent(QHideEvent *);
- bool event(QEvent *);
-
-private:
- Q_DECLARE_PRIVATE(QX11EmbedContainer)
- Q_DISABLE_COPY(QX11EmbedContainer)
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // QX11EMBED_X11_H
diff --git a/src/gui/kernel/qx11info_x11.cpp b/src/gui/kernel/qx11info_x11.cpp
deleted file mode 100644
index f52443befc..0000000000
--- a/src/gui/kernel/qx11info_x11.cpp
+++ /dev/null
@@ -1,543 +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 "qpixmap.h"
-#include "qx11info_x11.h"
-#include "qt_x11_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QX11Info
- \brief The QX11Info class provides information about the X display
- configuration.
-
- \ingroup shared
-
- The class provides two APIs: a set of non-static functions that
- provide information about a specific widget or pixmap, and a set
- of static functions that provide the default information for the
- application.
-
- \warning This class is only available on X11. For querying
- per-screen information in a portable way, use QDesktopWidget.
-
- \sa QWidget::x11Info(), QPixmap::x11Info(), QDesktopWidget
-*/
-
-/*!
- Constructs an empty QX11Info object.
-*/
-QX11Info::QX11Info()
- : x11data(0)
-{
-}
-
-/*!
- Constructs a copy of \a other.
-*/
-QX11Info::QX11Info(const QX11Info &other)
-{
- x11data = other.x11data;
- if (x11data)
- ++x11data->ref;
-}
-
-/*!
- Assigns \a other to this object and returns a reference to this
- object.
-*/
-QX11Info &QX11Info::operator=(const QX11Info &other)
-{
- if (other.x11data)
- ++other.x11data->ref;
- if (x11data && !--x11data->ref)
- delete x11data;
- x11data = other.x11data;
- return *this;
-}
-
-/*!
- Destroys the QX11Info object.
-*/
-QX11Info::~QX11Info()
-{
- if (x11data && !--x11data->ref)
- delete x11data;
-}
-
-/*!
- \internal
- Makes a shallow copy of the X11-specific data of \a fromDevice, if it is not
- null. Otherwise this function sets it to null.
-*/
-
-void QX11Info::copyX11Data(const QPaintDevice *fromDevice)
-{
- QX11InfoData *xd = 0;
- if (fromDevice) {
- if (fromDevice->devType() == QInternal::Widget)
- xd = static_cast<const QWidget *>(fromDevice)->x11Info().x11data;
- else if (fromDevice->devType() == QInternal::Pixmap)
- xd = static_cast<const QPixmap *>(fromDevice)->x11Info().x11data;
- }
- setX11Data(xd);
-}
-
-/*!
- \internal
- Makes a deep copy of the X11-specific data of \a fromDevice, if it is not
- null. Otherwise this function sets it to null.
-*/
-
-void QX11Info::cloneX11Data(const QPaintDevice *fromDevice)
-{
- QX11InfoData *d = 0;
- if (fromDevice) {
- QX11InfoData *xd;
- if (fromDevice->devType() == QInternal::Widget) {
- xd = static_cast<const QWidget *>(fromDevice)->x11Info().x11data;
- } else {
- Q_ASSERT(fromDevice->devType() == QInternal::Pixmap);
- xd = static_cast<const QPixmap *>(fromDevice)->x11Info().x11data;
- }
- d = new QX11InfoData(*xd);
- d->ref = 0;
- }
- setX11Data(d);
-}
-
-/*!
- \internal
- Makes a shallow copy of the X11-specific data \a d and assigns it to this
- class. This function increments the reference code of \a d.
-*/
-
-void QX11Info::setX11Data(const QX11InfoData* d)
-{
- if (x11data && !--x11data->ref)
- delete x11data;
- x11data = (QX11InfoData *)d;
- if (x11data)
- ++x11data->ref;
-}
-
-
-/*!
- \internal
- If \a def is false, returns a deep copy of the x11Data, or 0 if x11Data is 0.
- If \a def is true, makes a QX11Data struct filled with the default
- values.
-
- In either case the caller is responsible for deleting the returned
- struct. But notice that the struct is a shared class, so other
- classes might also have a reference to it. The reference count of
- the returned QX11Data* is 0.
-*/
-
-QX11InfoData* QX11Info::getX11Data(bool def) const
-{
- QX11InfoData* res = 0;
- if (def) {
- res = new QX11InfoData;
- res->ref = 0;
- res->screen = appScreen();
- res->depth = appDepth();
- res->cells = appCells();
- res->colormap = colormap();
- res->defaultColormap = appDefaultColormap();
- res->visual = (Visual*) appVisual();
- res->defaultVisual = appDefaultVisual();
- } else if (x11data) {
- res = new QX11InfoData;
- *res = *x11data;
- res->ref = 0;
- }
- return res;
-}
-
-/*!
- Returns the horizontal resolution of the given \a screen in terms of the
- number of dots per inch.
-
- The \a screen argument is an X screen number. Be aware that if
- the user's system uses Xinerama (as opposed to traditional X11
- multiscreen), there is only one X screen. Use QDesktopWidget to
- query for information about Xinerama screens.
-
- \sa setAppDpiX(), appDpiY()
-*/
-int QX11Info::appDpiX(int screen)
-{
- if (!X11)
- return 75;
- if (screen < 0)
- screen = X11->defaultScreen;
- if (screen > X11->screenCount)
- return 0;
- return X11->screens[screen].dpiX;
-}
-
-/*!
- Sets the horizontal resolution of the given \a screen to the number of
- dots per inch specified by \a xdpi.
-
- The \a screen argument is an X screen number. Be aware that if
- the user's system uses Xinerama (as opposed to traditional X11
- multiscreen), there is only one X screen. Use QDesktopWidget to
- query for information about Xinerama screens.
-
- \sa appDpiX(), setAppDpiY()
-*/
-
-void QX11Info::setAppDpiX(int screen, int xdpi)
-{
- if (!X11)
- return;
- if (screen < 0)
- screen = X11->defaultScreen;
- if (screen > X11->screenCount)
- return;
- X11->screens[screen].dpiX = xdpi;
-}
-
-/*!
- Returns the vertical resolution of the given \a screen in terms of the
- number of dots per inch.
-
- The \a screen argument is an X screen number. Be aware that if
- the user's system uses Xinerama (as opposed to traditional X11
- multiscreen), there is only one X screen. Use QDesktopWidget to
- query for information about Xinerama screens.
-
- \sa setAppDpiY(), appDpiX()
-*/
-
-int QX11Info::appDpiY(int screen)
-{
- if (!X11)
- return 75;
- if (screen < 0)
- screen = X11->defaultScreen;
- if (screen > X11->screenCount)
- return 0;
- return X11->screens[screen].dpiY;
-}
-
-/*!
- Sets the vertical resolution of the given \a screen to the number of
- dots per inch specified by \a ydpi.
-
- The \a screen argument is an X screen number. Be aware that if
- the user's system uses Xinerama (as opposed to traditional X11
- multiscreen), there is only one X screen. Use QDesktopWidget to
- query for information about Xinerama screens.
-
- \sa appDpiY(), setAppDpiX()
-*/
-void QX11Info::setAppDpiY(int screen, int ydpi)
-{
- if (!X11)
- return;
- if (screen < 0)
- screen = X11->defaultScreen;
- if (screen > X11->screenCount)
- return;
- X11->screens[screen].dpiY = ydpi;
-}
-
-/*!
- Returns the X11 time.
-
- \sa setAppTime(), appUserTime()
-*/
-unsigned long QX11Info::appTime()
-{
- return X11 ? X11->time : 0;
-}
-
-/*!
- Sets the X11 time to the value specified by \a time.
-
- \sa appTime(), setAppUserTime()
-*/
-void QX11Info::setAppTime(unsigned long time)
-{
- if (X11) {
- X11->time = time;
- }
-}
-
-/*!
- Returns the X11 user time.
-
- \sa setAppUserTime(), appTime()
-*/
-unsigned long QX11Info::appUserTime()
-{
- return X11 ? X11->userTime : 0;
-}
-
-/*!
- Sets the X11 user time as specified by \a time.
-
- \sa appUserTime(), setAppTime()
-*/
-void QX11Info::setAppUserTime(unsigned long time)
-{
- if (X11) {
- X11->userTime = time;
- }
-}
-
-
-/*!
- \fn const char *QX11Info::appClass()
-
- Returns the X11 application class.
-
- \sa display()
-*/
-
-/*!
- Returns the default display for the application.
-
- \sa appScreen()
-*/
-
-Display *QX11Info::display()
-{
- return X11 ? X11->display : 0;
-}
-
-/*!
- Returns the number of the screen where the application is being
- displayed.
-
- \sa display(), screen()
-*/
-int QX11Info::appScreen()
-{
- return X11 ? X11->defaultScreen : 0;
-}
-
-/*!
- Returns a handle for the application's color map on the given \a screen.
-
- The \a screen argument is an X screen number. Be aware that if
- the user's system uses Xinerama (as opposed to traditional X11
- multiscreen), there is only one X screen. Use QDesktopWidget to
- query for information about Xinerama screens.
-
- \sa colormap(), defaultColormap()
-*/
-Qt::HANDLE QX11Info::appColormap(int screen)
-{
- return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].colormap : 0;
-}
-
-/*!
- Returns the current visual used by the application on the given
- \a screen.
-
- The \a screen argument is an X screen number. Be aware that if
- the user's system uses Xinerama (as opposed to traditional X11
- multiscreen), there is only one X screen. Use QDesktopWidget to
- query for information about Xinerama screens.
-
- \sa visual(), defaultVisual()
-*/
-
-void *QX11Info::appVisual(int screen)
-{
- return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].visual : 0;
-}
-
-/*!
- Returns a handle for the applications root window on the given \a screen.
-
- The \a screen argument is an X screen number. Be aware that if
- the user's system uses Xinerama (as opposed to traditional X11
- multiscreen), there is only one X screen. Use QDesktopWidget to
- query for information about Xinerama screens.
-
- \sa QApplication::desktop()
-*/
-Qt::HANDLE QX11Info::appRootWindow(int screen)
-{
- return X11 ? RootWindow(X11->display, screen == -1 ? X11->defaultScreen : screen) : 0;
-}
-
-/*!
- Returns the color depth (bits per pixel) used by the application on the
- given \a screen.
-
- The \a screen argument is an X screen number. Be aware that if
- the user's system uses Xinerama (as opposed to traditional X11
- multiscreen), there is only one X screen. Use QDesktopWidget to
- query for information about Xinerama screens.
-
- \sa depth()
-*/
-
-int QX11Info::appDepth(int screen)
-{
- return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].depth : 32;
-}
-
-/*!
- Returns the number of cells used by the application on the given \a screen.
-
- The \a screen argument is an X screen number. Be aware that if
- the user's system uses Xinerama (as opposed to traditional X11
- multiscreen), there is only one X screen. Use QDesktopWidget to
- query for information about Xinerama screens.
-
- \sa cells()
-*/
-
-int QX11Info::appCells(int screen)
-{ return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].cells : 0; }
-
-/*!
- Returns true if the application has a default color map on the given
- \a screen; otherwise returns false.
-
- The \a screen argument is an X screen number. Be aware that if
- the user's system uses Xinerama (as opposed to traditional X11
- multiscreen), there is only one X screen. Use QDesktopWidget to
- query for information about Xinerama screens.
-*/
-bool QX11Info::appDefaultColormap(int screen)
-{ return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].defaultColormap : true; }
-
-/*!
- Returns true if the application has a default visual on the given \a screen;
- otherwise returns false.
-
- The \a screen argument is an X screen number. Be aware that if
- the user's system uses Xinerama (as opposed to traditional X11
- multiscreen), there is only one X screen. Use QDesktopWidget to
- query for information about Xinerama screens.
-*/
-bool QX11Info::appDefaultVisual(int screen)
-{ return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].defaultVisual : true; }
-
-/*!
- Returns the number of the screen currently in use.
-
- The return value is an X screen number. Be aware that if the
- user's system uses Xinerama (as opposed to traditional X11
- multiscreen), there is only one X screen. Use QDesktopWidget to
- query for information about Xinerama screens.
-
- \sa appScreen()
-*/
-int QX11Info::screen() const
-{ return x11data ? x11data->screen : QX11Info::appScreen(); }
-
-/*!
- Returns the color depth (bits per pixel) of the X display.
-
- \sa appDepth()
-*/
-
-int QX11Info::depth() const
-{ return x11data ? x11data->depth : QX11Info::appDepth(); }
-
-/*!
- Returns the number of cells.
-
- \sa appCells()
-*/
-
-int QX11Info::cells() const
-{ return x11data ? x11data->cells : QX11Info::appCells(); }
-
-/*!
- Returns a handle for the color map.
-
- \sa defaultColormap()
-*/
-
-Qt::HANDLE QX11Info::colormap() const
-{ return x11data ? x11data->colormap : QX11Info::appColormap(); }
-
-/*!
- Returns true if there is a default color map; otherwise returns false.
-
- \sa colormap()
-*/
-
-bool QX11Info::defaultColormap() const
-{ return x11data ? x11data->defaultColormap : QX11Info::appDefaultColormap(); }
-
-/*!
- Returns the current visual.
-
- \sa appVisual(), defaultVisual()
-*/
-
-void *QX11Info::visual() const
-{ return x11data ? x11data->visual : QX11Info::appVisual(); }
-
-/*!
- Returns true if there is a default visual; otherwise returns false.
-
- \sa visual(), appVisual()
-*/
-
-bool QX11Info::defaultVisual() const
-{ return x11data ? x11data->defaultVisual : QX11Info::appDefaultVisual(); }
-
-
-/*!
- \since 4.4
-
- Returns true if there is a compositing manager running.
-*/
-bool QX11Info::isCompositingManagerRunning()
-{
- return X11 ? X11->compositingManagerRunning : false;
-}
-
-QT_END_NAMESPACE
diff --git a/src/gui/kernel/qx11info_x11.h b/src/gui/kernel/qx11info_x11.h
deleted file mode 100644
index ece85740d2..0000000000
--- a/src/gui/kernel/qx11info_x11.h
+++ /dev/null
@@ -1,123 +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 QX11INFO_X11_H
-#define QX11INFO_X11_H
-
-#include <QtCore/qnamespace.h>
-
-typedef struct _XDisplay Display;
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Gui)
-
-struct QX11InfoData;
-class QX11Info;
-class QPaintDevice;
-class QApplicationPrivate;
-class QX11InfoPrivate;
-struct QX11WindowAttributes;
-
-void qt_x11_getX11InfoForWindow(QX11Info * xinfo, const QX11WindowAttributes &a);
-class Q_GUI_EXPORT QX11Info
-{
-public:
- QX11Info();
- ~QX11Info();
- QX11Info(const QX11Info &other);
- QX11Info &operator=(const QX11Info &other);
-
- static Display *display();
- static const char *appClass();
- int screen() const;
- int depth() const;
- int cells() const;
- Qt::HANDLE colormap() const;
- bool defaultColormap() const;
- void *visual() const;
- bool defaultVisual() const;
-
- static int appScreen();
- static int appDepth(int screen = -1);
- static int appCells(int screen = -1);
- static Qt::HANDLE appColormap(int screen = -1);
- static void *appVisual(int screen = -1);
- static Qt::HANDLE appRootWindow(int screen = -1);
- static bool appDefaultColormap(int screen = -1);
- static bool appDefaultVisual(int screen = -1);
- static int appDpiX(int screen = -1);
- static int appDpiY(int screen = -1);
- static void setAppDpiX(int screen, int dpi);
- static void setAppDpiY(int screen, int dpi);
- static unsigned long appTime();
- static unsigned long appUserTime();
- static void setAppTime(unsigned long time);
- static void setAppUserTime(unsigned long time);
- static bool isCompositingManagerRunning();
-
-protected:
- void copyX11Data(const QPaintDevice *);
- void cloneX11Data(const QPaintDevice *);
- void setX11Data(const QX11InfoData *);
- QX11InfoData* getX11Data(bool def = false) const;
-
- QX11InfoData *x11data;
-
- friend class QX11PaintEngine;
- friend class QPixmap;
- friend class QX11PixmapData;
- friend class QWidget;
- friend class QWidgetPrivate;
- friend class QGLWidget;
- friend void qt_init(QApplicationPrivate *priv, int, Display *display, Qt::HANDLE visual,
- Qt::HANDLE colormap);
- friend void qt_cleanup();
- friend void qt_x11_getX11InfoForWindow(QX11Info * xinfo, const QX11WindowAttributes &a);
-};
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // QX11INFO_X11_H