source: trunk/src/gui/dialogs/qnspanelproxy_mac.mm@ 122

Last change on this file since 122 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 9.0 KB
Line 
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#include <qdialogbuttonbox.h>
43#if defined(Q_WS_MAC)
44#include <private/qt_mac_p.h>
45#import <AppKit/AppKit.h>
46#import <Foundation/Foundation.h>
47#import <objc/objc-class.h>
48
49QT_BEGIN_NAMESPACE
50static QWidget *currentWindow = 0;
51QT_END_NAMESPACE
52
53QT_USE_NAMESPACE
54
55@class QNSPanelProxy;
56
57@interface QNSPanelProxy : NSWindow {
58}
59- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
60 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation;
61- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
62 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen;
63- (id)qt_fakeInitWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
64 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation;
65- (id)qt_fakeInitWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
66 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen;
67@end
68
69@implementation QNSPanelProxy
70- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
71 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
72{
73 // remove evil flag
74 windowStyle &= ~NSUtilityWindowMask;
75 self = [self qt_fakeInitWithContentRect:contentRect styleMask:windowStyle
76 backing:bufferingType defer:deferCreation];
77 return self;
78}
79
80- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
81 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen
82{
83 // remove evil flag
84 windowStyle &= ~NSUtilityWindowMask;
85 return [self qt_fakeInitWithContentRect:contentRect styleMask:windowStyle
86 backing:bufferingType defer:deferCreation screen:screen];
87}
88
89- (id)qt_fakeInitWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
90 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
91{
92 Q_UNUSED(contentRect);
93 Q_UNUSED(windowStyle);
94 Q_UNUSED(bufferingType);
95 Q_UNUSED(deferCreation);
96 return nil;
97}
98
99- (id)qt_fakeInitWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle
100 backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen
101{
102 Q_UNUSED(contentRect);
103 Q_UNUSED(windowStyle);
104 Q_UNUSED(bufferingType);
105 Q_UNUSED(deferCreation);
106 Q_UNUSED(screen);
107 return nil;
108}
109@end
110
111@class QNSWindowProxy;
112
113@interface QNSWindowProxy : NSWindow {
114}
115- (void)setTitle:(NSString *)title;
116- (void)qt_fakeSetTitle:(NSString *)title;
117@end
118
119@implementation QNSWindowProxy
120- (void)setTitle:(NSString *)title
121{
122 QCFString cftitle(currentWindow->windowTitle());
123
124 // evil reverse engineering
125 if ([title isEqualToString:@"Print"]
126 || [title isEqualToString:@"Page Setup"]
127 || [[self className] isEqualToString:@"PMPrintingWindow"])
128 title = (NSString *)(static_cast<CFStringRef>(cftitle));
129 return [self qt_fakeSetTitle:title];
130}
131
132- (void)qt_fakeSetTitle:(NSString *)title
133{
134 Q_UNUSED(title);
135}
136@end
137
138QT_BEGIN_NAMESPACE
139
140void macStartIntercept(SEL originalSel, SEL fakeSel, Class baseClass, Class proxyClass)
141{
142#ifndef QT_MAC_USE_COCOA
143 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5)
144#endif
145 {
146#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
147 Method originalMethod = class_getInstanceMethod(baseClass, originalSel);
148 Method newMethod = class_getInstanceMethod(proxyClass, originalSel);
149 Method fakeMethod = class_getInstanceMethod(proxyClass, fakeSel);
150
151 IMP originalCtorImp = method_setImplementation(originalMethod,
152 method_getImplementation(newMethod));
153 class_addMethod(baseClass, fakeSel, originalCtorImp,
154 method_getTypeEncoding(fakeMethod));
155#endif
156 }
157}
158
159void macStopIntercept(SEL originalSel, SEL fakeSel, Class baseClass, Class /* proxyClass */)
160{
161#ifndef QT_MAC_USE_COCOA
162 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5)
163#endif
164 {
165#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
166 Method originalMethod = class_getInstanceMethod(baseClass, originalSel);
167 Method fakeMethodInBaseClass = class_getInstanceMethod(baseClass, fakeSel);
168 method_setImplementation(originalMethod, method_getImplementation(fakeMethodInBaseClass));
169#endif
170 }
171}
172
173/*
174 Intercept the NSColorPanel constructor if the shared
175 color panel doesn't exist yet. What's going on here is
176 quite wacky, because we want to override the NSPanel
177 constructor and at the same time call the old NSPanel
178 constructor. So what we do is we effectively rename the
179 old NSPanel constructor qt_fakeInitWithContentRect:...
180 and have the new one call the old one.
181*/
182void macStartInterceptNSPanelCtor()
183{
184 macStartIntercept(@selector(initWithContentRect:styleMask:backing:defer:),
185 @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:),
186 [NSPanel class], [QNSPanelProxy class]);
187 macStartIntercept(@selector(initWithContentRect:styleMask:backing:defer:screen:),
188 @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:screen:),
189 [NSPanel class], [QNSPanelProxy class]);
190}
191
192/*
193 Restore things as they were.
194*/
195void macStopInterceptNSPanelCtor()
196{
197 macStopIntercept(@selector(initWithContentRect:styleMask:backing:defer:screen:),
198 @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:screen:),
199 [NSPanel class], [QNSPanelProxy class]);
200 macStopIntercept(@selector(initWithContentRect:styleMask:backing:defer:),
201 @selector(qt_fakeInitWithContentRect:styleMask:backing:defer:),
202 [NSPanel class], [QNSPanelProxy class]);
203}
204
205/*
206 Intercept the NSPrintPanel and NSPageLayout setTitle: calls. The
207 hack is similar as for NSColorPanel above.
208*/
209void macStartInterceptWindowTitle(QWidget *window)
210{
211 currentWindow = window;
212 macStartIntercept(@selector(setTitle:), @selector(qt_fakeSetTitle:),
213 [NSWindow class], [QNSWindowProxy class]);
214}
215
216/*
217 Restore things as they were.
218*/
219void macStopInterceptWindowTitle()
220{
221 currentWindow = 0;
222 macStopIntercept(@selector(setTitle:), @selector(qt_fakeSetTitle:),
223 [NSWindow class], [QNSWindowProxy class]);
224}
225
226/*
227 Doesn't really belong in here.
228*/
229NSButton *macCreateButton(const char *text, NSView *superview)
230{
231 static const NSRect buttonFrameRect = { { 0.0, 0.0 }, { 0.0, 0.0 } };
232
233 NSButton *button = [[NSButton alloc] initWithFrame:buttonFrameRect];
234 [button setButtonType:NSMomentaryLightButton];
235 [button setBezelStyle:NSRoundedBezelStyle];
236 [button setTitle:(NSString*)(CFStringRef)QCFString(QDialogButtonBox::tr(text)
237 .remove(QLatin1Char('&')))];
238 [[button cell] setFont:[NSFont systemFontOfSize:
239 [NSFont systemFontSizeForControlSize:NSRegularControlSize]]];
240 [superview addSubview:button];
241 return button;
242}
243
244QT_END_NAMESPACE
245
246#endif
Note: See TracBrowser for help on using the repository browser.