| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | /****************************************************************************
|
|---|
| 43 | **
|
|---|
| 44 | ** Copyright (c) 2007-2008, Apple, Inc.
|
|---|
| 45 | **
|
|---|
| 46 | ** All rights reserved.
|
|---|
| 47 | **
|
|---|
| 48 | ** Redistribution and use in source and binary forms, with or without
|
|---|
| 49 | ** modification, are permitted provided that the following conditions are met:
|
|---|
| 50 | **
|
|---|
| 51 | ** * Redistributions of source code must retain the above copyright notice,
|
|---|
| 52 | ** this list of conditions and the following disclaimer.
|
|---|
| 53 | **
|
|---|
| 54 | ** * Redistributions in binary form must reproduce the above copyright notice,
|
|---|
| 55 | ** this list of conditions and the following disclaimer in the documentation
|
|---|
| 56 | ** and/or other materials provided with the distribution.
|
|---|
| 57 | **
|
|---|
| 58 | ** * Neither the name of Apple, Inc. nor the names of its contributors
|
|---|
| 59 | ** may be used to endorse or promote products derived from this software
|
|---|
| 60 | ** without specific prior written permission.
|
|---|
| 61 | **
|
|---|
| 62 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|---|
| 63 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|---|
| 64 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|---|
| 65 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|---|
| 66 | ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|---|
| 67 | ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|---|
| 68 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|---|
| 69 | ** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|---|
| 70 | ** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|---|
| 71 | ** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|---|
| 72 | ** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 73 | **
|
|---|
| 74 | ****************************************************************************/
|
|---|
| 75 | //#define QT_RASTER_PAINTENGINE
|
|---|
| 76 |
|
|---|
| 77 | #include <private/qt_mac_p.h>
|
|---|
| 78 | #include <private/qeventdispatcher_mac_p.h>
|
|---|
| 79 |
|
|---|
| 80 | #include "qapplication.h"
|
|---|
| 81 | #include "qapplication_p.h"
|
|---|
| 82 | #include "qbitmap.h"
|
|---|
| 83 | #include "qcursor.h"
|
|---|
| 84 | #include "qdesktopwidget.h"
|
|---|
| 85 | #include "qevent.h"
|
|---|
| 86 | #include "qimage.h"
|
|---|
| 87 | #include "qlayout.h"
|
|---|
| 88 | #include "qmenubar.h"
|
|---|
| 89 | #include <private/qbackingstore_p.h>
|
|---|
| 90 | #ifdef QT_RASTER_PAINTENGINE
|
|---|
| 91 | # include <private/qpaintengine_raster_p.h>
|
|---|
| 92 | #endif
|
|---|
| 93 | #include <private/qwindowsurface_mac_p.h>
|
|---|
| 94 | #include <private/qpaintengine_mac_p.h>
|
|---|
| 95 | #include "qpainter.h"
|
|---|
| 96 | #include "qstyle.h"
|
|---|
| 97 | #include "qtimer.h"
|
|---|
| 98 | #include "qfocusframe.h"
|
|---|
| 99 | #include "qdebug.h"
|
|---|
| 100 | #include <private/qmainwindowlayout_p.h>
|
|---|
| 101 |
|
|---|
| 102 | #include <private/qabstractscrollarea_p.h>
|
|---|
| 103 | #include <qabstractscrollarea.h>
|
|---|
| 104 | #include <ApplicationServices/ApplicationServices.h>
|
|---|
| 105 | #include <limits.h>
|
|---|
| 106 | #include <private/qt_cocoa_helpers_mac_p.h>
|
|---|
| 107 | #include <private/qcocoaview_mac_p.h>
|
|---|
| 108 | #include <private/qcocoawindow_mac_p.h>
|
|---|
| 109 | #include <private/qcocoawindowdelegate_mac_p.h>
|
|---|
| 110 | #include <private/qcocoapanel_mac_p.h>
|
|---|
| 111 |
|
|---|
| 112 | #include "qwidget_p.h"
|
|---|
| 113 | #include "qdnd_p.h"
|
|---|
| 114 | #include <QtGui/qgraphicsproxywidget.h>
|
|---|
| 115 |
|
|---|
| 116 | QT_BEGIN_NAMESPACE
|
|---|
| 117 |
|
|---|
| 118 | #define XCOORD_MAX 16383
|
|---|
| 119 | #define WRECT_MAX 8191
|
|---|
| 120 |
|
|---|
| 121 | #ifndef QT_MAC_USE_COCOA
|
|---|
| 122 |
|
|---|
| 123 | extern "C" {
|
|---|
| 124 | extern OSStatus _HIViewScrollRectWithOptions(HIViewRef, const HIRect *, CGFloat, CGFloat,
|
|---|
| 125 | OptionBits);
|
|---|
| 126 | }
|
|---|
| 127 | #define kHIViewScrollRectAdjustInvalid 1
|
|---|
| 128 | #define kHIViewScrollRectDontInvalidateRevealedArea 2
|
|---|
| 129 | #endif
|
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 | /*****************************************************************************
|
|---|
| 133 | QWidget debug facilities
|
|---|
| 134 | *****************************************************************************/
|
|---|
| 135 | //#define DEBUG_WINDOW_RGNS
|
|---|
| 136 | //#define DEBUG_WINDOW_CREATE
|
|---|
| 137 | //#define DEBUG_WINDOW_STATE
|
|---|
| 138 | //#define DEBUG_WIDGET_PAINT
|
|---|
| 139 |
|
|---|
| 140 | /*****************************************************************************
|
|---|
| 141 | QWidget globals
|
|---|
| 142 | *****************************************************************************/
|
|---|
| 143 | #ifndef QT_MAC_USE_COCOA
|
|---|
| 144 | typedef QHash<Qt::WindowFlags, WindowGroupRef> WindowGroupHash;
|
|---|
| 145 | Q_GLOBAL_STATIC(WindowGroupHash, qt_mac_window_groups)
|
|---|
| 146 | const UInt32 kWidgetCreatorQt = kEventClassQt;
|
|---|
| 147 | enum {
|
|---|
| 148 | kWidgetPropertyQWidget = 'QWId' //QWidget *
|
|---|
| 149 | };
|
|---|
| 150 | #endif
|
|---|
| 151 |
|
|---|
| 152 | static bool qt_mac_raise_process = true;
|
|---|
| 153 | static OSWindowRef qt_root_win = 0;
|
|---|
| 154 | QWidget *mac_mouse_grabber = 0;
|
|---|
| 155 | QWidget *mac_keyboard_grabber = 0;
|
|---|
| 156 |
|
|---|
| 157 | #ifndef QT_MAC_USE_COCOA
|
|---|
| 158 | #ifdef QT_NAMESPACE
|
|---|
| 159 |
|
|---|
| 160 | // produce the string "com.trolltech.qt-namespace.widget", where "namespace" is the contents of QT_NAMESPACE.
|
|---|
| 161 | #define SS(x) #x
|
|---|
| 162 | #define S0(x) SS(x)
|
|---|
| 163 | #define S "com.trolltech.qt-" S0(QT_NAMESPACE) ".widget"
|
|---|
| 164 |
|
|---|
| 165 | static CFStringRef kObjectQWidget = CFSTR(S);
|
|---|
| 166 |
|
|---|
| 167 | #undef SS
|
|---|
| 168 | #undef S0
|
|---|
| 169 | #undef S
|
|---|
| 170 |
|
|---|
| 171 | #else
|
|---|
| 172 | static CFStringRef kObjectQWidget = CFSTR("com.trolltech.qt.widget");
|
|---|
| 173 | #endif // QT_NAMESPACE
|
|---|
| 174 | #endif // QT_MAC_USE_COCOA
|
|---|
| 175 |
|
|---|
| 176 | /*****************************************************************************
|
|---|
| 177 | Externals
|
|---|
| 178 | *****************************************************************************/
|
|---|
| 179 | extern QWidget *qt_mac_modal_blocked(QWidget *); //qapplication_mac.mm
|
|---|
| 180 | extern void qt_event_request_activate(QWidget *); //qapplication_mac.mm
|
|---|
| 181 | extern bool qt_event_remove_activate(); //qapplication_mac.mm
|
|---|
| 182 | extern void qt_mac_event_release(QWidget *w); //qapplication_mac.mm
|
|---|
| 183 | extern void qt_event_request_showsheet(QWidget *); //qapplication_mac.mm
|
|---|
| 184 | extern void qt_event_request_window_change(QWidget *); //qapplication_mac.mm
|
|---|
| 185 | extern QPointer<QWidget> qt_mouseover; //qapplication_mac.mm
|
|---|
| 186 | extern IconRef qt_mac_create_iconref(const QPixmap &); //qpixmap_mac.cpp
|
|---|
| 187 | extern void qt_mac_set_cursor(const QCursor *, const QPoint &); //qcursor_mac.mm
|
|---|
| 188 | extern void qt_mac_update_cursor(); //qcursor_mac.mm
|
|---|
| 189 | extern bool qt_nograb();
|
|---|
| 190 | extern CGImageRef qt_mac_create_cgimage(const QPixmap &, bool); //qpixmap_mac.cpp
|
|---|
| 191 | extern RgnHandle qt_mac_get_rgn(); //qregion_mac.cpp
|
|---|
| 192 | extern QRegion qt_mac_convert_mac_region(RgnHandle rgn); //qregion_mac.cpp
|
|---|
| 193 |
|
|---|
| 194 | /*****************************************************************************
|
|---|
| 195 | QWidget utility functions
|
|---|
| 196 | *****************************************************************************/
|
|---|
| 197 | void Q_GUI_EXPORT qt_mac_set_raise_process(bool b) { qt_mac_raise_process = b; }
|
|---|
| 198 | static QSize qt_mac_desktopSize()
|
|---|
| 199 | {
|
|---|
| 200 | int w = 0, h = 0;
|
|---|
| 201 | CGDisplayCount cg_count;
|
|---|
| 202 | CGGetActiveDisplayList(0, 0, &cg_count);
|
|---|
| 203 | QVector<CGDirectDisplayID> displays(cg_count);
|
|---|
| 204 | CGGetActiveDisplayList(cg_count, displays.data(), &cg_count);
|
|---|
| 205 | Q_ASSERT(cg_count == (CGDisplayCount)displays.size());
|
|---|
| 206 | for(int i = 0; i < (int)cg_count; ++i) {
|
|---|
| 207 | CGRect r = CGDisplayBounds(displays.at(i));
|
|---|
| 208 | w = qMax<int>(w, qRound(r.origin.x + r.size.width));
|
|---|
|
|---|