Qt 4.8
qnspanelproxy_mac.mm
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <qdialogbuttonbox.h>
43 #if defined(Q_WS_MAC)
44 #include <private/qt_mac_p.h>
45 #include <private/qcocoaintrospection_p.h>
46 #import <AppKit/AppKit.h>
47 #import <Foundation/Foundation.h>
48 #import <objc/objc-class.h>
49 
51 static QWidget *currentWindow = 0;
53 
55 
57 
58 @interface QT_MANGLE_NAMESPACE(QNSPanelProxy) : NSWindow {
59 }
60 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
61  backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation;
62 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
63  backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen;
64 - (id)qt_fakeInitWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
65  backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation;
66 - (id)qt_fakeInitWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
67  backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen;
68 @end
69 
70 @implementation QT_MANGLE_NAMESPACE(QNSPanelProxy)
71 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
72  backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
73 {
74  // remove evil flag
75  windowStyle &= ~NSUtilityWindowMask;
76  self = [self qt_fakeInitWithContentRect:contentRect styleMask:windowStyle
77  backing:bufferingType defer:deferCreation];
78  return self;
79 }
80 
81 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
82  backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen
83 {
84  // remove evil flag
85  windowStyle &= ~NSUtilityWindowMask;
86  return [self qt_fakeInitWithContentRect:contentRect styleMask:windowStyle
87  backing:bufferingType defer:deferCreation screen:screen];
88 }
89 
90 - (id)qt_fakeInitWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
91  backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
92 {
93  Q_UNUSED(contentRect);
94  Q_UNUSED(windowStyle);
95  Q_UNUSED(bufferingType);
96  Q_UNUSED(deferCreation);
97  return nil;
98 }
99 
100 - (id)qt_fakeInitWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
101  backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen
102 {
103  Q_UNUSED(contentRect);
104  Q_UNUSED(windowStyle);
105  Q_UNUSED(bufferingType);
106  Q_UNUSED(deferCreation);
107  Q_UNUSED(screen);
108  return nil;
109 }
110 @end
111 
113 
114 @interface QT_MANGLE_NAMESPACE(QNSWindowProxy) : NSWindow {
115 }
116 - (void)setTitle:(NSString *)title;
117 - (void)qt_fakeSetTitle:(NSString *)title;
118 @end
119 
120 @implementation QT_MANGLE_NAMESPACE(QNSWindowProxy)
121 - (void)setTitle:(NSString *)title
122 {
123  QCFString cftitle(currentWindow->windowTitle());
124 
125  // evil reverse engineering
126  if ([title isEqualToString:@"Print"]
127  || [title isEqualToString:@"Page Setup"]
128  || [[self className] isEqualToString:@"PMPrintingWindow"])
129  title = (NSString *)(static_cast<CFStringRef>(cftitle));
130  return [self qt_fakeSetTitle:title];
131 }
132 
133 - (void)qt_fakeSetTitle:(NSString *)title
134 {
135  Q_UNUSED(title);
136 }
137 @end
138 
140 
141 /*
142  Intercept the NSColorPanel constructor if the shared
143  color panel doesn't exist yet. What's going on here is
144  quite wacky, because we want to override the NSPanel
145  constructor and at the same time call the old NSPanel
146  constructor. So what we do is we effectively rename the
147  old NSPanel constructor qt_fakeInitWithContentRect:...
148  and have the new one call the old one.
149 */
151 {
153  [NSPanel class],
154  @selector(initWithContentRect:styleMask:backing:defer:),
156  @selector(initWithContentRect:styleMask:backing:defer:),
157  @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:));
159  [NSPanel class],
160  @selector(initWithContentRect:styleMask:backing:defer:screen:),
162  @selector(initWithContentRect:styleMask:backing:defer:screen:),
163  @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:screen:));
164 }
165 
166 /*
167  Restore things as they were.
168 */
170 {
172  [NSPanel class],
173  @selector(initWithContentRect:styleMask:backing:defer:screen:),
174  @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:screen:));
176  [NSPanel class],
177  @selector(initWithContentRect:styleMask:backing:defer:),
178  @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:));
179 }
180 
181 /*
182  Intercept the NSPrintPanel and NSPageLayout setTitle: calls. The
183  hack is similar as for NSColorPanel above.
184 */
186 {
187  currentWindow = window;
189  [NSWindow class],
190  @selector(setTitle:),
192  @selector(setTitle:),
193  @selector(qt_fakeSetTitle:));
194 }
195 
196 /*
197  Restore things as they were.
198 */
200 {
201  currentWindow = 0;
203  [NSWindow class],
204  @selector(setTitle:),
205  @selector(qt_fakeSetTitle:));
206 }
207 
208 /*
209  Doesn't really belong in here.
210 */
211 NSButton *macCreateButton(const char *text, NSView *superview)
212 {
213  static const NSRect buttonFrameRect = { { 0.0, 0.0 }, { 0.0, 0.0 } };
214 
215  NSButton *button = [[NSButton alloc] initWithFrame:buttonFrameRect];
216  [button setButtonType:NSMomentaryLightButton];
217  [button setBezelStyle:NSRoundedBezelStyle];
218  [button setTitle:(NSString*)(CFStringRef)QCFString(QDialogButtonBox::tr(text)
219  .remove(QLatin1Char('&')))];
220  [[button cell] setFont:[NSFont systemFontOfSize:
221  [NSFont systemFontSizeForControlSize:NSRegularControlSize]]];
222  [superview addSubview:button];
223  return button;
224 }
225 
227 
228 #endif
static QWidget * currentWindow
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
NSButton * macCreateButton(const char *text, NSView *superview)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
id qt_fakeInitWithContentRect:styleMask:backing:defer:(NSRect contentRect, [styleMask] NSUInteger windowStyle, [backing] NSBackingStoreType bufferingType, [defer] BOOL deferCreation)
const char * className
Definition: qwizard.cpp:137
NSWindow * window
void qt_fakeSetTitle:(NSString *title)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
id qt_fakeInitWithContentRect:styleMask:backing:defer:screen:(NSRect contentRect, [styleMask] NSUInteger windowStyle, [backing] NSBackingStoreType bufferingType, [defer] BOOL deferCreation, [screen] NSScreen *screen)
QString windowTitle
the window title (caption)
Definition: qwidget.h:198
void qt_cocoa_change_implementation(Class baseClass, SEL originalSel, Class proxyClass, SEL replacementSel, SEL backupSel)
void qt_cocoa_change_back_implementation(Class baseClass, SEL originalSel, SEL backupSel)
void macStartInterceptNSPanelCtor()
void macStopInterceptWindowTitle()
void macStartInterceptWindowTitle(QWidget *window)
#define QT_MANGLE_NAMESPACE(name)
Definition: qglobal.h:106
void macStopInterceptNSPanelCtor()
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
Definition: qglobal.h:88
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
#define text
Definition: qobjectdefs.h:80