author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 23 Jun 2010 19:07:03 +0300 | |
changeset 29 | b72c6db6890b |
parent 18 | 2f34d5167611 |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtGui module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qfontdialog_p.h" |
|
43 |
#if !defined(QT_NO_FONTDIALOG) && defined(Q_WS_MAC) |
|
44 |
#include <qapplication.h> |
|
45 |
#include <qdialogbuttonbox.h> |
|
46 |
#include <qlineedit.h> |
|
47 |
#include <private/qapplication_p.h> |
|
48 |
#include <private/qfont_p.h> |
|
49 |
#include <private/qfontengine_p.h> |
|
50 |
#include <private/qt_cocoa_helpers_mac_p.h> |
|
51 |
#include <private/qt_mac_p.h> |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
52 |
#include <qabstracteventdispatcher.h> |
0 | 53 |
#include <qdebug.h> |
54 |
#import <AppKit/AppKit.h> |
|
55 |
#import <Foundation/Foundation.h> |
|
56 |
||
57 |
#if !CGFLOAT_DEFINED |
|
58 |
typedef float CGFloat; // Should only not be defined on 32-bit platforms |
|
59 |
#endif |
|
60 |
||
61 |
QT_USE_NAMESPACE |
|
62 |
||
63 |
// should a priori be kept in sync with qcolordialog_mac.mm |
|
64 |
const CGFloat ButtonMinWidth = 78.0; |
|
65 |
const CGFloat ButtonMinHeight = 32.0; |
|
66 |
const CGFloat ButtonSpacing = 0.0; |
|
67 |
const CGFloat ButtonTopMargin = 0.0; |
|
68 |
const CGFloat ButtonBottomMargin = 7.0; |
|
69 |
const CGFloat ButtonSideMargin = 9.0; |
|
70 |
||
71 |
// looks better with some margins |
|
72 |
const CGFloat DialogTopMargin = 7.0; |
|
73 |
const CGFloat DialogSideMargin = 9.0; |
|
74 |
||
75 |
const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask; |
|
76 |
||
77 |
@class QCocoaFontPanelDelegate; |
|
78 |
||
79 |
||
80 |
#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 |
|
81 |
||
82 |
@protocol NSWindowDelegate <NSObject> |
|
83 |
- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize; |
|
84 |
@end |
|
85 |
||
86 |
#endif |
|
87 |
||
88 |
@interface QCocoaFontPanelDelegate : NSObject <NSWindowDelegate> { |
|
89 |
NSFontPanel *mFontPanel; |
|
90 |
NSView *mStolenContentView; |
|
91 |
NSButton *mOkButton; |
|
92 |
NSButton *mCancelButton; |
|
93 |
QFontDialogPrivate *mPriv; |
|
94 |
QFont *mQtFont; |
|
95 |
BOOL mPanelHackedWithButtons; |
|
96 |
CGFloat mDialogExtraWidth; |
|
97 |
CGFloat mDialogExtraHeight; |
|
98 |
NSModalSession mModalSession; |
|
99 |
} |
|
100 |
- (id)initWithFontPanel:(NSFontPanel *)panel |
|
101 |
stolenContentView:(NSView *)stolenContentView |
|
102 |
okButton:(NSButton *)okButton |
|
103 |
cancelButton:(NSButton *)cancelButton |
|
104 |
priv:(QFontDialogPrivate *)priv |
|
105 |
extraWidth:(CGFloat)extraWidth |
|
106 |
extraHeight:(CGFloat)extraHeight; |
|
107 |
- (void)changeFont:(id)sender; |
|
108 |
- (void)changeAttributes:(id)sender; |
|
109 |
- (void)setModalSession:(NSModalSession)session; |
|
110 |
- (BOOL)windowShouldClose:(id)window; |
|
111 |
- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize; |
|
112 |
- (void)relayout; |
|
113 |
- (void)relayoutToContentSize:(NSSize)frameSize; |
|
114 |
- (void)onOkClicked; |
|
115 |
- (void)onCancelClicked; |
|
116 |
- (NSFontPanel *)fontPanel; |
|
117 |
- (NSWindow *)actualPanel; |
|
118 |
- (NSSize)dialogExtraSize; |
|
119 |
- (void)setQtFont:(const QFont &)newFont; |
|
120 |
- (QFont)qtFont; |
|
121 |
- (void)finishOffWithCode:(NSInteger)result; |
|
122 |
- (void)cleanUpAfterMyself; |
|
123 |
@end |
|
124 |
||
125 |
static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) |
|
126 |
{ |
|
127 |
QFont newFont; |
|
128 |
if (cocoaFont) { |
|
129 |
int pSize = qRound([cocoaFont pointSize]); |
|
130 |
QString family(qt_mac_NSStringToQString([cocoaFont familyName])); |
|
131 |
QString typeface(qt_mac_NSStringToQString([cocoaFont fontName])); |
|
132 |
||
133 |
int hyphenPos = typeface.indexOf(QLatin1Char('-')); |
|
134 |
if (hyphenPos != -1) { |
|
135 |
typeface.remove(0, hyphenPos + 1); |
|
136 |
} else { |
|
137 |
typeface = QLatin1String("Normal"); |
|
138 |
} |
|
139 |
||
140 |
newFont = QFontDatabase().font(family, typeface, pSize); |
|
141 |
newFont.setUnderline(resolveFont.underline()); |
|
142 |
newFont.setStrikeOut(resolveFont.strikeOut()); |
|
143 |
||
144 |
} |
|
145 |
return newFont; |
|
146 |
} |
|
147 |
||
148 |
@implementation QCocoaFontPanelDelegate |
|
149 |
- (id)initWithFontPanel:(NSFontPanel *)panel |
|
150 |
stolenContentView:(NSView *)stolenContentView |
|
151 |
okButton:(NSButton *)okButton |
|
152 |
cancelButton:(NSButton *)cancelButton |
|
153 |
priv:(QFontDialogPrivate *)priv |
|
154 |
extraWidth:(CGFloat)extraWidth |
|
155 |
extraHeight:(CGFloat)extraHeight |
|
156 |
{ |
|
157 |
self = [super init]; |
|
158 |
mFontPanel = panel; |
|
159 |
mStolenContentView = stolenContentView; |
|
160 |
mOkButton = okButton; |
|
161 |
mCancelButton = cancelButton; |
|
162 |
mPriv = priv; |
|
163 |
mPanelHackedWithButtons = (okButton != 0); |
|
164 |
mDialogExtraWidth = extraWidth; |
|
165 |
mDialogExtraHeight = extraHeight; |
|
166 |
mModalSession = 0; |
|
167 |
||
168 |
if (mPanelHackedWithButtons) { |
|
169 |
[self relayout]; |
|
170 |
||
171 |
[okButton setAction:@selector(onOkClicked)]; |
|
172 |
[okButton setTarget:self]; |
|
173 |
||
174 |
[cancelButton setAction:@selector(onCancelClicked)]; |
|
175 |
[cancelButton setTarget:self]; |
|
176 |
} |
|
177 |
mQtFont = new QFont(); |
|
178 |
return self; |
|
179 |
} |
|
180 |
||
181 |
- (void)dealloc |
|
182 |
{ |
|
183 |
delete mQtFont; |
|
184 |
[super dealloc]; |
|
185 |
} |
|
186 |
||
187 |
- (void)changeFont:(id)sender |
|
188 |
{ |
|
189 |
NSFont *dummyFont = [NSFont userFontOfSize:12.0]; |
|
190 |
[self setQtFont:qfontForCocoaFont([sender convertFont:dummyFont], *mQtFont)]; |
|
191 |
if (mPriv) |
|
192 |
mPriv->updateSampleFont(*mQtFont); |
|
193 |
} |
|
194 |
||
195 |
- (void)changeAttributes:(id)sender |
|
196 |
{ |
|
197 |
NSDictionary *dummyAttribs = [NSDictionary dictionary]; |
|
198 |
NSDictionary *attribs = [sender convertAttributes:dummyAttribs]; |
|
199 |
||
200 |
#ifdef QT_MAC_USE_COCOA |
|
201 |
for (id key in attribs) { |
|
202 |
#else |
|
203 |
NSEnumerator *enumerator = [attribs keyEnumerator]; |
|
204 |
id key; |
|
205 |
while((key = [enumerator nextObject])) { |
|
206 |
#endif |
|
207 |
NSNumber *number = static_cast<NSNumber *>([attribs objectForKey:key]); |
|
208 |
if ([key isEqual:NSUnderlineStyleAttributeName]) { |
|
209 |
mQtFont->setUnderline([number intValue] != NSUnderlineStyleNone); |
|
210 |
} else if ([key isEqual:NSStrikethroughStyleAttributeName]) { |
|
211 |
mQtFont->setStrikeOut([number intValue] != NSUnderlineStyleNone); |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
if (mPriv) |
|
216 |
mPriv->updateSampleFont(*mQtFont); |
|
217 |
} |
|
218 |
||
219 |
- (void)setModalSession:(NSModalSession)session |
|
220 |
{ |
|
221 |
Q_ASSERT(!mModalSession); |
|
222 |
mModalSession = session; |
|
223 |
} |
|
224 |
||
225 |
- (BOOL)windowShouldClose:(id)window |
|
226 |
{ |
|
227 |
Q_UNUSED(window); |
|
228 |
if (mPanelHackedWithButtons) { |
|
229 |
[self onCancelClicked]; |
|
230 |
} else { |
|
231 |
[self finishOffWithCode:NSCancelButton]; |
|
232 |
} |
|
233 |
return true; |
|
234 |
} |
|
235 |
||
236 |
- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize |
|
237 |
{ |
|
238 |
if (mFontPanel == window) { |
|
239 |
proposedFrameSize = [static_cast<id <NSWindowDelegate> >(mFontPanel) windowWillResize:mFontPanel toSize:proposedFrameSize]; |
|
240 |
} else { |
|
241 |
/* |
|
242 |
Ugly hack: NSFontPanel rearranges the layout of its main |
|
243 |
component in windowWillResize:toSize:. So we temporarily |
|
244 |
restore the stolen content view to its rightful owner, |
|
245 |
call windowWillResize:toSize:, and steal the content view |
|
246 |
again. |
|
247 |
*/ |
|
248 |
[mStolenContentView removeFromSuperview]; |
|
249 |
[mFontPanel setContentView:mStolenContentView]; |
|
250 |
NSSize extraSize = [self dialogExtraSize]; |
|
251 |
proposedFrameSize.width -= extraSize.width; |
|
252 |
proposedFrameSize.height -= extraSize.height; |
|
253 |
proposedFrameSize = [static_cast<id <NSWindowDelegate> >(mFontPanel) windowWillResize:mFontPanel toSize:proposedFrameSize]; |
|
254 |
NSRect frameRect = { { 0.0, 0.0 }, proposedFrameSize }; |
|
255 |
[mFontPanel setFrame:frameRect display:NO]; |
|
256 |
[mFontPanel setContentView:0]; |
|
257 |
[[window contentView] addSubview:mStolenContentView]; |
|
258 |
proposedFrameSize.width += extraSize.width; |
|
259 |
proposedFrameSize.height += extraSize.height; |
|
260 |
} |
|
261 |
if (mPanelHackedWithButtons) { |
|
262 |
NSRect frameRect = { { 0.0, 0.0 }, proposedFrameSize }; |
|
263 |
NSRect contentRect = [NSWindow contentRectForFrameRect:frameRect styleMask:[window styleMask]]; |
|
264 |
[self relayoutToContentSize:contentRect.size]; |
|
265 |
} |
|
266 |
return proposedFrameSize; |
|
267 |
} |
|
268 |
||
269 |
- (void)relayout |
|
270 |
{ |
|
271 |
[self relayoutToContentSize:[[mStolenContentView superview] frame].size]; |
|
272 |
} |
|
273 |
||
274 |
- (void)relayoutToContentSize:(NSSize)frameSize; |
|
275 |
{ |
|
276 |
Q_ASSERT(mPanelHackedWithButtons); |
|
277 |
||
278 |
[mOkButton sizeToFit]; |
|
279 |
NSSize okSizeHint = [mOkButton frame].size; |
|
280 |
||
281 |
[mCancelButton sizeToFit]; |
|
282 |
NSSize cancelSizeHint = [mCancelButton frame].size; |
|
283 |
||
284 |
const CGFloat ButtonWidth = qMin(qMax(ButtonMinWidth, |
|
285 |
qMax(okSizeHint.width, cancelSizeHint.width)), |
|
286 |
CGFloat((frameSize.width - 2.0 * ButtonSideMargin |
|
287 |
- ButtonSpacing) * 0.5)); |
|
288 |
const CGFloat ButtonHeight = qMax(ButtonMinHeight, |
|
289 |
qMax(okSizeHint.height, cancelSizeHint.height)); |
|
290 |
||
291 |
const CGFloat X = DialogSideMargin; |
|
292 |
const CGFloat Y = ButtonBottomMargin + ButtonHeight + ButtonTopMargin; |
|
293 |
||
294 |
NSRect okRect = { { frameSize.width - ButtonSideMargin - ButtonWidth, |
|
295 |
ButtonBottomMargin }, |
|
296 |
{ ButtonWidth, ButtonHeight } }; |
|
297 |
[mOkButton setFrame:okRect]; |
|
298 |
[mOkButton setNeedsDisplay:YES]; |
|
299 |
||
300 |
NSRect cancelRect = { { okRect.origin.x - ButtonSpacing - ButtonWidth, |
|
301 |
ButtonBottomMargin }, |
|
302 |
{ ButtonWidth, ButtonHeight } }; |
|
303 |
[mCancelButton setFrame:cancelRect]; |
|
304 |
[mCancelButton setNeedsDisplay:YES]; |
|
305 |
||
306 |
NSRect stolenCVRect = { { X, Y }, |
|
307 |
{ frameSize.width - X - X, frameSize.height - Y - DialogTopMargin } }; |
|
308 |
[mStolenContentView setFrame:stolenCVRect]; |
|
309 |
[mStolenContentView setNeedsDisplay:YES]; |
|
310 |
||
311 |
[[mStolenContentView superview] setNeedsDisplay:YES]; |
|
312 |
} |
|
313 |
||
314 |
- (void)onOkClicked |
|
315 |
{ |
|
316 |
Q_ASSERT(mPanelHackedWithButtons); |
|
317 |
NSFontManager *fontManager = [NSFontManager sharedFontManager]; |
|
318 |
[self setQtFont:qfontForCocoaFont([fontManager convertFont:[fontManager selectedFont]], |
|
319 |
*mQtFont)]; |
|
320 |
[[mStolenContentView window] close]; |
|
321 |
[self finishOffWithCode:NSOKButton]; |
|
322 |
} |
|
323 |
||
324 |
- (void)onCancelClicked |
|
325 |
{ |
|
326 |
Q_ASSERT(mPanelHackedWithButtons); |
|
327 |
[[mStolenContentView window] close]; |
|
328 |
[self finishOffWithCode:NSCancelButton]; |
|
329 |
} |
|
330 |
||
331 |
- (NSFontPanel *)fontPanel |
|
332 |
{ |
|
333 |
return mFontPanel; |
|
334 |
} |
|
335 |
||
336 |
- (NSWindow *)actualPanel |
|
337 |
{ |
|
338 |
return [mStolenContentView window]; |
|
339 |
} |
|
340 |
||
341 |
- (NSSize)dialogExtraSize |
|
342 |
{ |
|
343 |
// this must be recomputed each time, because sometimes the |
|
344 |
// NSFontPanel has the NSDocModalWindowMask flag set, and sometimes |
|
345 |
// not -- which affects the frame rect vs. content rect measurements |
|
346 |
||
347 |
// take the different frame rectangles into account for dialogExtra{Width,Height} |
|
348 |
NSRect someRect = { { 0.0, 0.0 }, { 100000.0, 100000.0 } }; |
|
349 |
NSRect sharedFontPanelContentRect = [mFontPanel contentRectForFrameRect:someRect]; |
|
350 |
NSRect ourPanelContentRect = [NSWindow contentRectForFrameRect:someRect styleMask:StyleMask]; |
|
351 |
||
352 |
NSSize result = { mDialogExtraWidth, mDialogExtraHeight }; |
|
353 |
result.width -= ourPanelContentRect.size.width - sharedFontPanelContentRect.size.width; |
|
354 |
result.height -= ourPanelContentRect.size.height - sharedFontPanelContentRect.size.height; |
|
355 |
return result; |
|
356 |
} |
|
357 |
||
358 |
- (void)setQtFont:(const QFont &)newFont |
|
359 |
{ |
|
360 |
delete mQtFont; |
|
361 |
mQtFont = new QFont(newFont); |
|
362 |
} |
|
363 |
||
364 |
- (QFont)qtFont |
|
365 |
{ |
|
366 |
return *mQtFont; |
|
367 |
} |
|
368 |
||
369 |
- (void)finishOffWithCode:(NSInteger)code |
|
370 |
{ |
|
371 |
if (mPriv) { |
|
372 |
if (mModalSession) { |
|
373 |
[NSApp endModalSession:mModalSession]; |
|
374 |
mModalSession = 0; |
|
375 |
} |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
376 |
// Hack alert! |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
377 |
// Since this code path was never intended to be followed when starting from exec |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
378 |
// we need to force the dialog to communicate the new font, otherwise the signal |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
379 |
// won't get emitted. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
380 |
if(code == NSOKButton) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
381 |
mPriv->sampleEdit->setFont([self qtFont]); |
0 | 382 |
mPriv->done((code == NSOKButton) ? QDialog::Accepted : QDialog::Rejected); |
383 |
} else { |
|
384 |
[NSApp stopModalWithCode:code]; |
|
385 |
} |
|
386 |
} |
|
387 |
||
388 |
- (void)cleanUpAfterMyself |
|
389 |
{ |
|
390 |
if (mPanelHackedWithButtons) { |
|
391 |
NSView *ourContentView = [mFontPanel contentView]; |
|
392 |
||
393 |
// return stolen stuff to its rightful owner |
|
394 |
[mStolenContentView removeFromSuperview]; |
|
395 |
[mFontPanel setContentView:mStolenContentView]; |
|
396 |
||
397 |
[mOkButton release]; |
|
398 |
[mCancelButton release]; |
|
399 |
[ourContentView release]; |
|
400 |
} |
|
401 |
[mFontPanel setDelegate:nil]; |
|
402 |
[[NSFontManager sharedFontManager] setDelegate:nil]; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
#ifdef QT_MAC_USE_COCOA |
0 | 404 |
[[NSFontManager sharedFontManager] setTarget:nil]; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
#endif |
0 | 406 |
} |
407 |
@end |
|
408 |
||
409 |
QT_BEGIN_NAMESPACE |
|
410 |
||
411 |
extern void macStartInterceptNSPanelCtor(); |
|
412 |
extern void macStopInterceptNSPanelCtor(); |
|
413 |
extern NSButton *macCreateButton(const char *text, NSView *superview); |
|
414 |
||
415 |
void *QFontDialogPrivate::openCocoaFontPanel(const QFont &initial, |
|
416 |
QWidget *parent, const QString &title, QFontDialog::FontDialogOptions options, |
|
417 |
QFontDialogPrivate *priv) |
|
418 |
{ |
|
419 |
Q_UNUSED(parent); // we would use the parent if only NSFontPanel could be a sheet |
|
420 |
QMacCocoaAutoReleasePool pool; |
|
421 |
||
422 |
/* |
|
423 |
The standard Cocoa font panel has no OK or Cancel button and |
|
424 |
is created as a utility window. For strange reasons (which seem |
|
425 |
to stem from the fact that the font panel is based on a NIB |
|
426 |
file), the approach we use for the color panel doesn't work for |
|
427 |
the font panel (and, inversely, the approach we use here doesn't |
|
428 |
quite work for color panel, and crashed last time I tried). So |
|
429 |
instead, we take the following steps: |
|
430 |
||
431 |
1. Constructs a plain NSPanel that looks the way we want it |
|
432 |
to look. Specifically, if the NoButtons option is off, we |
|
433 |
construct a panel without the NSUtilityWindowMask flag |
|
434 |
and with buttons (OK and Cancel). |
|
435 |
||
436 |
2. Steal the content view from the shared NSFontPanel and |
|
437 |
put it inside our new NSPanel's content view, together |
|
438 |
with the OK and Cancel buttons. |
|
439 |
||
440 |
3. Lay out the original content view and the buttons when |
|
441 |
the font panel is shown and whenever it is resized. |
|
442 |
||
443 |
4. Clean up after ourselves. |
|
444 |
||
445 |
PS. Some customization is also done in QCocoaApplication |
|
446 |
validModesForFontPanel:. |
|
447 |
*/ |
|
448 |
||
449 |
Qt::WindowModality modality = Qt::ApplicationModal; |
|
450 |
if (priv) |
|
451 |
modality = priv->fontDialog()->windowModality(); |
|
452 |
||
453 |
bool needButtons = !(options & QFontDialog::NoButtons); |
|
454 |
// don't need our own panel if the title bar isn't visible anyway (in a sheet) |
|
455 |
bool needOwnPanel = (needButtons && modality != Qt::WindowModal); |
|
456 |
||
457 |
bool sharedFontPanelExisted = [NSFontPanel sharedFontPanelExists]; |
|
458 |
NSFontPanel *sharedFontPanel = [NSFontPanel sharedFontPanel]; |
|
459 |
[sharedFontPanel setHidesOnDeactivate:false]; |
|
460 |
||
461 |
// hack to ensure that QCocoaApplication's validModesForFontPanel: |
|
462 |
// implementation is honored |
|
463 |
if (!sharedFontPanelExisted && needOwnPanel) { |
|
464 |
[sharedFontPanel makeKeyAndOrderFront:sharedFontPanel]; |
|
465 |
[sharedFontPanel close]; |
|
466 |
} |
|
467 |
||
468 |
NSPanel *ourPanel = 0; |
|
469 |
NSView *stolenContentView = 0; |
|
470 |
NSButton *okButton = 0; |
|
471 |
NSButton *cancelButton = 0; |
|
472 |
||
473 |
CGFloat dialogExtraWidth = 0.0; |
|
474 |
CGFloat dialogExtraHeight = 0.0; |
|
475 |
||
476 |
if (!needOwnPanel) { |
|
477 |
// we can reuse the NSFontPanel unchanged |
|
478 |
ourPanel = sharedFontPanel; |
|
479 |
} else { |
|
480 |
// compute dialogExtra{Width,Height} |
|
481 |
dialogExtraWidth = 2.0 * DialogSideMargin; |
|
482 |
dialogExtraHeight = DialogTopMargin + ButtonTopMargin + ButtonMinHeight |
|
483 |
+ ButtonBottomMargin; |
|
484 |
||
485 |
// compute initial contents rectangle |
|
486 |
NSRect contentRect = [sharedFontPanel contentRectForFrameRect:[sharedFontPanel frame]]; |
|
487 |
contentRect.size.width += dialogExtraWidth; |
|
488 |
contentRect.size.height += dialogExtraHeight; |
|
489 |
||
490 |
// create the new panel |
|
491 |
ourPanel = [[NSPanel alloc] initWithContentRect:contentRect |
|
492 |
styleMask:StyleMask |
|
493 |
backing:NSBackingStoreBuffered |
|
494 |
defer:YES]; |
|
495 |
[ourPanel setReleasedWhenClosed:YES]; |
|
496 |
} |
|
497 |
||
498 |
stolenContentView = [sharedFontPanel contentView]; |
|
499 |
||
500 |
if (needButtons) { |
|
501 |
// steal the font panel's contents view |
|
502 |
[stolenContentView retain]; |
|
503 |
[sharedFontPanel setContentView:0]; |
|
504 |
||
505 |
// create a new content view and add the stolen one as a subview |
|
506 |
NSRect frameRect = { { 0.0, 0.0 }, { 0.0, 0.0 } }; |
|
507 |
NSView *ourContentView = [[NSView alloc] initWithFrame:frameRect]; |
|
508 |
[ourContentView addSubview:stolenContentView]; |
|
509 |
||
510 |
// create OK and Cancel buttons and add these as subviews |
|
511 |
okButton = macCreateButton("&OK", ourContentView); |
|
512 |
cancelButton = macCreateButton("Cancel", ourContentView); |
|
513 |
||
514 |
[ourPanel setContentView:ourContentView]; |
|
515 |
[ourPanel setDefaultButtonCell:[okButton cell]]; |
|
516 |
} |
|
517 |
||
518 |
// create a delegate and set it |
|
519 |
QCocoaFontPanelDelegate *delegate = |
|
520 |
[[QCocoaFontPanelDelegate alloc] initWithFontPanel:sharedFontPanel |
|
521 |
stolenContentView:stolenContentView |
|
522 |
okButton:okButton |
|
523 |
cancelButton:cancelButton |
|
524 |
priv:priv |
|
525 |
extraWidth:dialogExtraWidth |
|
526 |
extraHeight:dialogExtraHeight]; |
|
527 |
[ourPanel setDelegate:delegate]; |
|
528 |
[[NSFontManager sharedFontManager] setDelegate:delegate]; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
529 |
#ifdef QT_MAC_USE_COCOA |
0 | 530 |
[[NSFontManager sharedFontManager] setTarget:delegate]; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
531 |
#endif |
0 | 532 |
setFont(delegate, initial); |
533 |
||
534 |
// hack to get correct initial layout |
|
535 |
NSRect frameRect = [ourPanel frame]; |
|
536 |
frameRect.size.width += 1.0; |
|
537 |
[ourPanel setFrame:frameRect display:NO]; |
|
538 |
frameRect.size.width -= 1.0; |
|
539 |
frameRect.size = [delegate windowWillResize:ourPanel toSize:frameRect.size]; |
|
540 |
[ourPanel setFrame:frameRect display:NO]; |
|
541 |
[ourPanel center]; |
|
542 |
||
543 |
[ourPanel setTitle:(NSString*)(CFStringRef)QCFString(title)]; |
|
544 |
||
545 |
if (priv) { |
|
546 |
switch (modality) { |
|
547 |
case Qt::WindowModal: |
|
548 |
if (parent) { |
|
549 |
#ifndef QT_MAC_USE_COCOA |
|
550 |
WindowRef hiwindowRef = qt_mac_window_for(parent); |
|
551 |
NSWindow *window = |
|
552 |
[[NSWindow alloc] initWithWindowRef:hiwindowRef]; |
|
553 |
// Cocoa docs say I should retain the Carbon ref. |
|
554 |
CFRetain(hiwindowRef); |
|
555 |
#else |
|
556 |
NSWindow *window = qt_mac_window_for(parent); |
|
557 |
#endif |
|
558 |
[NSApp beginSheet:ourPanel |
|
559 |
modalForWindow:window |
|
560 |
modalDelegate:0 |
|
561 |
didEndSelector:0 |
|
562 |
contextInfo:0]; |
|
563 |
#ifndef QT_MAC_USE_COCOA |
|
564 |
[window release]; |
|
565 |
#endif |
|
566 |
break; |
|
567 |
} |
|
568 |
// fallthrough |
|
569 |
case Qt::ApplicationModal: |
|
570 |
[delegate setModalSession:[NSApp beginModalSessionForWindow:ourPanel]]; |
|
571 |
break; |
|
572 |
default: |
|
573 |
[ourPanel makeKeyAndOrderFront:ourPanel]; |
|
574 |
} |
|
575 |
} |
|
576 |
return delegate; |
|
577 |
} |
|
578 |
||
579 |
void QFontDialogPrivate::closeCocoaFontPanel(void *delegate) |
|
580 |
{ |
|
581 |
QMacCocoaAutoReleasePool pool; |
|
582 |
QCocoaFontPanelDelegate *theDelegate = static_cast<QCocoaFontPanelDelegate *>(delegate); |
|
583 |
NSWindow *ourPanel = [theDelegate actualPanel]; |
|
584 |
[ourPanel close]; |
|
585 |
[theDelegate cleanUpAfterMyself]; |
|
586 |
[theDelegate autorelease]; |
|
587 |
} |
|
588 |
||
589 |
QFont QFontDialogPrivate::execCocoaFontPanel(bool *ok, const QFont &initial, |
|
590 |
QWidget *parent, const QString &title, QFontDialog::FontDialogOptions options) |
|
591 |
{ |
|
592 |
QMacCocoaAutoReleasePool pool; |
|
593 |
QCocoaFontPanelDelegate *delegate = |
|
594 |
static_cast<QCocoaFontPanelDelegate *>( |
|
595 |
openCocoaFontPanel(initial, parent, title, options)); |
|
596 |
NSWindow *ourPanel = [delegate actualPanel]; |
|
597 |
[ourPanel retain]; |
|
598 |
int rval = [NSApp runModalForWindow:ourPanel]; |
|
599 |
QFont font([delegate qtFont]); |
|
600 |
[ourPanel release]; |
|
601 |
[delegate cleanUpAfterMyself]; |
|
602 |
[delegate release]; |
|
603 |
bool isOk = ((options & QFontDialog::NoButtons) || rval == NSOKButton); |
|
604 |
if (ok) |
|
605 |
*ok = isOk; |
|
606 |
if (isOk) { |
|
607 |
return font; |
|
608 |
} else { |
|
609 |
return initial; |
|
610 |
} |
|
611 |
} |
|
612 |
||
613 |
void QFontDialogPrivate::setFont(void *delegate, const QFont &font) |
|
614 |
{ |
|
615 |
QMacCocoaAutoReleasePool pool; |
|
616 |
QFontEngine *fe = font.d->engineForScript(QUnicodeTables::Common); |
|
617 |
NSFontManager *mgr = [NSFontManager sharedFontManager]; |
|
618 |
NSFont *nsFont = 0; |
|
619 |
||
620 |
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 |
|
621 |
if (qstrcmp(fe->name(), "CoreText") == 0) { |
|
622 |
nsFont = reinterpret_cast<const NSFont *>(static_cast<QCoreTextFontEngineMulti *>(fe)->ctfont); |
|
623 |
} else |
|
624 |
#endif |
|
625 |
{ |
|
626 |
int weight = 5; |
|
627 |
NSFontTraitMask mask = 0; |
|
628 |
if (font.style() == QFont::StyleItalic) { |
|
629 |
mask |= NSItalicFontMask; |
|
630 |
} |
|
631 |
if (font.weight() == QFont::Bold) { |
|
632 |
weight = 9; |
|
633 |
mask |= NSBoldFontMask; |
|
634 |
} |
|
635 |
||
636 |
NSFontManager *mgr = [NSFontManager sharedFontManager]; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
637 |
QFontInfo fontInfo(font); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
638 |
nsFont = [mgr fontWithFamily:qt_mac_QStringToNSString(fontInfo.family()) |
0 | 639 |
traits:mask |
640 |
weight:weight |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
641 |
size:fontInfo.pointSize()]; |
0 | 642 |
} |
643 |
||
644 |
[mgr setSelectedFont:nsFont isMultiple:NO]; |
|
645 |
[static_cast<QCocoaFontPanelDelegate *>(delegate) setQtFont:font]; |
|
646 |
} |
|
647 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
648 |
void *QFontDialogPrivate::_q_constructNativePanel() |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
649 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
650 |
QMacCocoaAutoReleasePool pool; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
651 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
652 |
bool sharedFontPanelExisted = [NSFontPanel sharedFontPanelExists]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
653 |
NSFontPanel *sharedFontPanel = [NSFontPanel sharedFontPanel]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
654 |
[sharedFontPanel setHidesOnDeactivate:false]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
655 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
656 |
// hack to ensure that QCocoaApplication's validModesForFontPanel: |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
657 |
// implementation is honored |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
658 |
if (!sharedFontPanelExisted) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
659 |
[sharedFontPanel makeKeyAndOrderFront:sharedFontPanel]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
660 |
[sharedFontPanel close]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
661 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
662 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
663 |
NSPanel *ourPanel = 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
664 |
NSView *stolenContentView = 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
665 |
NSButton *okButton = 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
666 |
NSButton *cancelButton = 0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
667 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
668 |
CGFloat dialogExtraWidth = 0.0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
669 |
CGFloat dialogExtraHeight = 0.0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
670 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
671 |
// compute dialogExtra{Width,Height} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
672 |
dialogExtraWidth = 2.0 * DialogSideMargin; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
673 |
dialogExtraHeight = DialogTopMargin + ButtonTopMargin + ButtonMinHeight |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
674 |
+ ButtonBottomMargin; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
675 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
676 |
// compute initial contents rectangle |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
677 |
NSRect contentRect = [sharedFontPanel contentRectForFrameRect:[sharedFontPanel frame]]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
678 |
contentRect.size.width += dialogExtraWidth; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
679 |
contentRect.size.height += dialogExtraHeight; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
680 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
681 |
// create the new panel |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
682 |
ourPanel = [[NSPanel alloc] initWithContentRect:contentRect |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
683 |
styleMask:StyleMask |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
684 |
backing:NSBackingStoreBuffered |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
685 |
defer:YES]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
686 |
[ourPanel setReleasedWhenClosed:YES]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
687 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
688 |
stolenContentView = [sharedFontPanel contentView]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
689 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
690 |
// steal the font panel's contents view |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
691 |
[stolenContentView retain]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
692 |
[sharedFontPanel setContentView:0]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
693 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
694 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
695 |
// create a new content view and add the stolen one as a subview |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
696 |
NSRect frameRect = { { 0.0, 0.0 }, { 0.0, 0.0 } }; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
697 |
NSView *ourContentView = [[NSView alloc] initWithFrame:frameRect]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
698 |
[ourContentView addSubview:stolenContentView]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
699 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
700 |
// create OK and Cancel buttons and add these as subviews |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
701 |
okButton = macCreateButton("&OK", ourContentView); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
702 |
cancelButton = macCreateButton("Cancel", ourContentView); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
703 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
704 |
[ourPanel setContentView:ourContentView]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
705 |
[ourPanel setDefaultButtonCell:[okButton cell]]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
706 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
707 |
// create a delegate and set it |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
708 |
QCocoaFontPanelDelegate *delegate = |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
709 |
[[QCocoaFontPanelDelegate alloc] initWithFontPanel:sharedFontPanel |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
710 |
stolenContentView:stolenContentView |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
711 |
okButton:okButton |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
712 |
cancelButton:cancelButton |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
713 |
priv:this |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
714 |
extraWidth:dialogExtraWidth |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
715 |
extraHeight:dialogExtraHeight]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
716 |
[ourPanel setDelegate:delegate]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
717 |
[[NSFontManager sharedFontManager] setDelegate:delegate]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
718 |
#ifdef QT_MAC_USE_COCOA |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
719 |
[[NSFontManager sharedFontManager] setTarget:delegate]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
720 |
#endif |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
721 |
setFont(delegate, QApplication::font()); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
722 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
723 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
724 |
// hack to get correct initial layout |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
725 |
NSRect frameRect = [ourPanel frame]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
726 |
frameRect.size.width += 1.0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
727 |
[ourPanel setFrame:frameRect display:NO]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
728 |
frameRect.size.width -= 1.0; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
729 |
frameRect.size = [delegate windowWillResize:ourPanel toSize:frameRect.size]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
730 |
[ourPanel setFrame:frameRect display:NO]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
731 |
[ourPanel center]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
732 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
733 |
NSString *title = @"Select font"; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
734 |
[ourPanel setTitle:title]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
735 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
736 |
[delegate setModalSession:[NSApp beginModalSessionForWindow:ourPanel]]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
737 |
return delegate; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
738 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
739 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
740 |
void QFontDialogPrivate::mac_nativeDialogModalHelp() |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
741 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
742 |
// Copied from QFileDialogPrivate |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
743 |
// Do a queued meta-call to open the native modal dialog so it opens after the new |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
744 |
// event loop has started to execute (in QDialog::exec). Using a timer rather than |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
745 |
// a queued meta call is intentional to ensure that the call is only delivered when |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
746 |
// [NSApp run] runs (timers are handeled special in cocoa). If NSApp is not |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
747 |
// running (which is the case if e.g a top-most QEventLoop has been |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
748 |
// interrupted, and the second-most event loop has not yet been reactivated (regardless |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
749 |
// if [NSApp run] is still on the stack)), showing a native modal dialog will fail. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
750 |
if (nativeDialogInUse) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
751 |
Q_Q(QFontDialog); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
752 |
QTimer::singleShot(1, q, SLOT(_q_macRunNativeAppModalPanel())); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
753 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
754 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
755 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
756 |
// The problem with the native font dialog is that OS X does not |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
757 |
// offer a proper dialog, but a panel (i.e. without Ok and Cancel buttons). |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
758 |
// This means we need to "construct" a native dialog by taking the panel |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
759 |
// and "adding" the buttons. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
760 |
void QFontDialogPrivate::_q_macRunNativeAppModalPanel() |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
761 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
762 |
QBoolBlocker nativeDialogOnTop(QApplicationPrivate::native_modal_dialog_active); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
763 |
Q_Q(QFontDialog); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
764 |
QCocoaFontPanelDelegate *delegate = (QCocoaFontPanelDelegate *)_q_constructNativePanel(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
765 |
NSWindow *ourPanel = [delegate actualPanel]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
766 |
[ourPanel retain]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
767 |
int rval = [NSApp runModalForWindow:ourPanel]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
768 |
QAbstractEventDispatcher::instance()->interrupt(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
769 |
[ourPanel release]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
770 |
[delegate cleanUpAfterMyself]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
771 |
[delegate release]; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
772 |
bool isOk = (rval == NSOKButton); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
773 |
if(isOk) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
774 |
rescode = QDialog::Accepted; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
775 |
else |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
776 |
rescode = QDialog::Rejected; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
777 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
778 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
779 |
bool QFontDialogPrivate::setVisible_sys(bool visible) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
780 |
{ |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
781 |
Q_Q(QFontDialog); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
782 |
if (!visible == q->isHidden()) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
783 |
return false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
784 |
return visible; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
785 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
786 |
|
0 | 787 |
QT_END_NAMESPACE |
788 |
||
789 |
#endif |