1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtGui module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <qdialogbuttonbox.h>
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>
51 static QWidget *currentWindow = 0;
56 @class QT_MANGLE_NAMESPACE(QNSPanelProxy);
58 @interface QT_MANGLE_NAMESPACE(QNSPanelProxy) : NSWindow {
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;
70 @implementation QT_MANGLE_NAMESPACE(QNSPanelProxy)
71 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
72 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
75 windowStyle &= ~NSUtilityWindowMask;
76 self = [self qt_fakeInitWithContentRect:contentRect styleMask:windowStyle
77 backing:bufferingType defer:deferCreation];
81 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
82 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen
85 windowStyle &= ~NSUtilityWindowMask;
86 return [self qt_fakeInitWithContentRect:contentRect styleMask:windowStyle
87 backing:bufferingType defer:deferCreation screen:screen];
90 - (id)qt_fakeInitWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
91 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
93 Q_UNUSED(contentRect);
94 Q_UNUSED(windowStyle);
95 Q_UNUSED(bufferingType);
96 Q_UNUSED(deferCreation);
100 - (id)qt_fakeInitWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
101 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen
103 Q_UNUSED(contentRect);
104 Q_UNUSED(windowStyle);
105 Q_UNUSED(bufferingType);
106 Q_UNUSED(deferCreation);
112 @class QT_MANGLE_NAMESPACE(QNSWindowProxy);
114 @interface QT_MANGLE_NAMESPACE(QNSWindowProxy) : NSWindow {
116 - (void)setTitle:(NSString *)title;
117 - (void)qt_fakeSetTitle:(NSString *)title;
120 @implementation QT_MANGLE_NAMESPACE(QNSWindowProxy)
121 - (void)setTitle:(NSString *)title
123 QCFString cftitle(currentWindow->windowTitle());
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];
133 - (void)qt_fakeSetTitle:(NSString *)title
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.
150 void macStartInterceptNSPanelCtor()
152 qt_cocoa_change_implementation(
154 @selector(initWithContentRect:styleMask:backing:defer:),
155 [QT_MANGLE_NAMESPACE(QNSPanelProxy) class],
156 @selector(initWithContentRect:styleMask:backing:defer:),
157 @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:));
158 qt_cocoa_change_implementation(
160 @selector(initWithContentRect:styleMask:backing:defer:screen:),
161 [QT_MANGLE_NAMESPACE(QNSPanelProxy) class],
162 @selector(initWithContentRect:styleMask:backing:defer:screen:),
163 @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:screen:));
167 Restore things as they were.
169 void macStopInterceptNSPanelCtor()
171 qt_cocoa_change_back_implementation(
173 @selector(initWithContentRect:styleMask:backing:defer:screen:),
174 @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:screen:));
175 qt_cocoa_change_back_implementation(
177 @selector(initWithContentRect:styleMask:backing:defer:),
178 @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:));
182 Intercept the NSPrintPanel and NSPageLayout setTitle: calls. The
183 hack is similar as for NSColorPanel above.
185 void macStartInterceptWindowTitle(QWidget *window)
187 currentWindow = window;
188 qt_cocoa_change_implementation(
190 @selector(setTitle:),
191 [QT_MANGLE_NAMESPACE(QNSWindowProxy) class],
192 @selector(setTitle:),
193 @selector(qt_fakeSetTitle:));
197 Restore things as they were.
199 void macStopInterceptWindowTitle()
202 qt_cocoa_change_back_implementation(
204 @selector(setTitle:),
205 @selector(qt_fakeSetTitle:));
209 Doesn't really belong in here.
211 NSButton *macCreateButton(const char *text, NSView *superview)
213 static const NSRect buttonFrameRect = { { 0.0, 0.0 }, { 0.0, 0.0 } };
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];