| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #import "private/qcocoawindowdelegate_mac_p.h"
|
|---|
| 43 | #ifdef QT_MAC_USE_COCOA
|
|---|
| 44 | #include <private/qwidget_p.h>
|
|---|
| 45 | #include <private/qapplication_p.h>
|
|---|
| 46 | #include <private/qt_cocoa_helpers_mac_p.h>
|
|---|
| 47 | #include <qevent.h>
|
|---|
| 48 | #include <qlayout.h>
|
|---|
| 49 | #include <qcoreapplication.h>
|
|---|
| 50 | #include <qmenubar.h>
|
|---|
| 51 |
|
|---|
| 52 | QT_BEGIN_NAMESPACE
|
|---|
| 53 | extern QWidgetData *qt_qwidget_data(QWidget *); // qwidget.cpp
|
|---|
| 54 | extern void onApplicationWindowChangedActivation(QWidget *, bool); //qapplication_mac.mm
|
|---|
| 55 | extern bool qt_sendSpontaneousEvent(QObject *, QEvent *); // qapplication.cpp
|
|---|
| 56 | QT_END_NAMESPACE
|
|---|
| 57 |
|
|---|
| 58 | QT_USE_NAMESPACE
|
|---|
| 59 |
|
|---|
| 60 | static QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) *sharedCocoaWindowDelegate = nil;
|
|---|
| 61 |
|
|---|
| 62 | // This is a singleton, but unlike most Cocoa singletons, it lives in a library and could be
|
|---|
| 63 | // pontentially loaded and unloaded. This means we should at least attempt to do the
|
|---|
| 64 | // memory management correctly.
|
|---|
| 65 |
|
|---|
| 66 | static void cleanupCocoaWindowDelegate()
|
|---|
| 67 | {
|
|---|
| 68 | [sharedCocoaWindowDelegate release];
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | @implementation QT_MANGLE_NAMESPACE(QCocoaWindowDelegate)
|
|---|
| 72 |
|
|---|
| 73 | - (id)init
|
|---|
| 74 | {
|
|---|
| 75 | self = [super init];
|
|---|
| 76 | if (self != nil) {
|
|---|
| 77 | m_windowHash = new QHash<NSWindow *, QWidget *>();
|
|---|
| 78 | m_drawerHash = new QHash<NSDrawer *, QWidget *>();
|
|---|
| 79 | }
|
|---|
| 80 | return self;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | - (void)dealloc
|
|---|
| 84 | {
|
|---|
| 85 | sharedCocoaWindowDelegate = nil;
|
|---|
| 86 | QHash<NSWindow *, QWidget *>::const_iterator windowIt = m_windowHash->constBegin();
|
|---|
| 87 | while (windowIt != m_windowHash->constEnd()) {
|
|---|
| 88 | [windowIt.key() setDelegate:nil];
|
|---|
| 89 | ++windowIt;
|
|---|
| 90 | }
|
|---|
| 91 | delete m_windowHash;
|
|---|
| 92 | QHash<NSDrawer *, QWidget *>::const_iterator drawerIt = m_drawerHash->constBegin();
|
|---|
| 93 | while (drawerIt != m_drawerHash->constEnd()) {
|
|---|
| 94 | [drawerIt.key() setDelegate:nil];
|
|---|
| 95 | ++drawerIt;
|
|---|
| 96 | }
|
|---|
| 97 | delete m_drawerHash;
|
|---|
| 98 | [super dealloc];
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | + (id)allocWithZone:(NSZone *)zone
|
|---|
| 102 | {
|
|---|
| 103 | @synchronized(self) {
|
|---|
| 104 | if (sharedCocoaWindowDelegate == nil) {
|
|---|
| 105 | sharedCocoaWindowDelegate = [super allocWithZone:zone];
|
|---|
| 106 | return sharedCocoaWindowDelegate;
|
|---|
| 107 | qAddPostRoutine(cleanupCocoaWindowDelegate);
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 | return nil;
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | + (QT_MANGLE_NAMESPACE(QCocoaWindowDelegate)*)sharedDelegate
|
|---|
| 114 | {
|
|---|
| 115 | @synchronized(self) {
|
|---|
| 116 | if (sharedCocoaWindowDelegate == nil)
|
|---|
| 117 | [[self alloc] init];
|
|---|
| 118 | }
|
|---|
| 119 | return [[sharedCocoaWindowDelegate retain] autorelease];
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | -(void)syncSizeForWidget:(QWidget *)qwidget toSize:(const QSize &)newSize fromSize:(const QSize &)oldSize
|
|---|
| 123 | {
|
|---|
| 124 | qt_qwidget_data(qwidget)->crect.setSize(newSize);
|
|---|
| 125 | // ### static contents optimization needs to go here
|
|---|
| 126 | const OSViewRef view = qt_mac_nativeview_for(qwidget);
|
|---|
| 127 | [view setFrameSize:NSMakeSize(newSize.width(), newSize.height())];
|
|---|
| 128 | if (!qwidget->isVisible()) {
|
|---|
| 129 | qwidget->setAttribute(Qt::WA_PendingResizeEvent, true);
|
|---|
| 130 | } else {
|
|---|
| 131 | QResizeEvent qre(newSize, oldSize);
|
|---|
| 132 | if (qwidget->testAttribute(Qt::WA_PendingResizeEvent)) {
|
|---|
| 133 | qwidget->setAttribute(Qt::WA_PendingResizeEvent, false);
|
|---|
| 134 | QApplication::sendEvent(qwidget, &qre);
|
|---|
| 135 | } else {
|
|---|
| 136 | qt_sendSpontaneousEvent(qwidget, &qre);
|
|---|
| 137 | }
|
|---|
| 138 | }
|
|---|
| 139 | }
|
|---|
|
|---|