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 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
41 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
42 | **
|
---|
43 | ****************************************************************************/
|
---|
44 |
|
---|
45 | #include "qmacdefines_mac.h"
|
---|
46 | #ifdef QT_MAC_USE_COCOA
|
---|
47 | #import <private/qcocoawindow_mac_p.h>
|
---|
48 | #import <private/qcocoawindowdelegate_mac_p.h>
|
---|
49 | #import <private/qcocoaview_mac_p.h>
|
---|
50 | #import <private/qt_cocoa_helpers_mac_p.h>
|
---|
51 | #import <private/qcocoawindowcustomthemeframe_mac_p.h>
|
---|
52 |
|
---|
53 | #include <QtGui/QWidget>
|
---|
54 |
|
---|
55 | QT_FORWARD_DECLARE_CLASS(QWidget);
|
---|
56 | QT_BEGIN_NAMESPACE
|
---|
57 | extern Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum); // qcocoaview.mm
|
---|
58 | QT_END_NAMESPACE
|
---|
59 | QT_USE_NAMESPACE
|
---|
60 |
|
---|
61 | @implementation NSWindow (QT_MANGLE_NAMESPACE(QWidgetIntegration))
|
---|
62 |
|
---|
63 | - (id)QT_MANGLE_NAMESPACE(qt_initWithQWidget):(QWidget*)widget contentRect:(NSRect)rect styleMask:(NSUInteger)mask;
|
---|
64 | {
|
---|
65 | self = [self initWithContentRect:rect styleMask:mask backing:NSBackingStoreBuffered defer:YES];
|
---|
66 | if (self) {
|
---|
67 | [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] becomeDelegteForWindow:self widget:widget];
|
---|
68 | [self setReleasedWhenClosed:NO];
|
---|
69 | }
|
---|
70 | return self;
|
---|
71 | }
|
---|
72 |
|
---|
73 | - (QWidget *)QT_MANGLE_NAMESPACE(qt_qwidget)
|
---|
74 | {
|
---|
75 | QWidget *widget = 0;
|
---|
76 | if ([self delegate] == [QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate])
|
---|
77 | widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self];
|
---|
78 | return widget;
|
---|
79 | }
|
---|
80 |
|
---|
81 | @end
|
---|
82 |
|
---|
83 | @implementation QT_MANGLE_NAMESPACE(QCocoaWindow)
|
---|
84 |
|
---|
85 | - (BOOL)canBecomeKeyWindow
|
---|
86 | {
|
---|
87 | return YES;
|
---|
88 | }
|
---|
89 |
|
---|
90 | /***********************************************************************
|
---|
91 | BEGIN Copy and Paste between QCocoaWindow and QCocoaPanel
|
---|
92 | This is a bit unfortunate, but thanks to the dynamic dispatch we
|
---|
93 | have to duplicate this code or resort to really silly forwarding methods
|
---|
94 | **************************************************************************/
|
---|
95 |
|
---|
96 | /*
|
---|
97 | The methods keyDown, keyUp, and flagsChanged... These really shouldn't ever
|
---|
98 | get hit. We automatically say we can be first responder if we are a window.
|
---|
99 | So, the handling should get handled by the view. This is here more as a
|
---|
100 | last resort (i.e., this is code that can potentially be removed).
|
---|
101 | */
|
---|
102 |
|
---|
103 | - (void)keyDown:(NSEvent *)theEvent
|
---|
104 | {
|
---|
105 | bool keyOK = qt_dispatchKeyEvent(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]);
|
---|
106 | if (!keyOK)
|
---|
107 | [super keyDown:theEvent];
|
---|
108 | }
|
---|
109 |
|
---|
110 | - (void)keyUp:(NSEvent *)theEvent
|
---|
111 | {
|
---|
112 | bool keyOK = qt_dispatchKeyEvent(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]);
|
---|
113 | if (!keyOK)
|
---|
114 | [super keyUp:theEvent];
|
---|
115 | }
|
---|
116 |
|
---|
117 | - (void)flagsChanged:(NSEvent *)theEvent
|
---|
118 | {
|
---|
119 | qt_dispatchModifiersChanged(theEvent, [self QT_MANGLE_NAMESPACE(qt_qwidget)]);
|
---|
120 | [super flagsChanged:theEvent];
|
---|
121 | }
|
---|
122 |
|
---|
123 |
|
---|
124 | - (void)tabletProximity:(NSEvent *)tabletEvent
|
---|
125 | {
|
---|
126 | qt_dispatchTabletProximityEvent(tabletEvent);
|
---|
127 | }
|
---|
128 |
|
---|
129 | - (void)sendEvent:(NSEvent *)event
|
---|
130 | {
|
---|
131 | [self retain];
|
---|
132 |
|
---|
133 | QWidget *widget = [[QT_MANGLE_NAMESPACE(QCocoaWindowDelegate) sharedDelegate] qt_qwidgetForWindow:self];
|
---|
134 | QT_MANGLE_NAMESPACE(QCocoaView) *view = static_cast<QT_MANGLE_NAMESPACE(QCocoaView) *>(qt_mac_nativeview_for(widget));
|
---|
135 | Qt::MouseButton mouseButton = cocoaButton2QtButton([event buttonNumber]);
|
---|
136 |
|
---|
137 | // sometimes need to redirect mouse events to the popup.
|
---|
138 | QWidget *popup = qAppInstance()->activePopupWidget();
|
---|
139 | if (popup && popup != widget) {
|
---|
140 | switch([event type])
|
---|
141 | {
|
---|
142 | case NSLeftMouseDown:
|
---|
143 | qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton);
|
---|
144 | // Don't call super here. This prevents us from getting the mouseUp event,
|
---|
145 | // which we need to send even if the mouseDown event was not accepted.
|
---|
146 | // (this is standard Qt behavior.)
|
---|
147 | break;
|
---|
148 | case NSRightMouseDown:
|
---|
149 | case NSOtherMouseDown:
|
---|
150 | if (!qt_mac_handleMouseEvent(view, event, QEvent::MouseButtonPress, mouseButton))
|
---|
151 | [super sendEvent:event];
|
---|
152 | break;
|
---|
|
---|