From f3ecbb007acf39b43c73be26f4cbbf195c352e57 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 2 Mar 2010 15:08:55 +0100 Subject: Mac: QFontDialog will not sometimes leave modality It turns out the the code implemented two different ways of entering modality, and mixed the two when it came to exit modality. This patch just uses the nsapp runmodalforwindow approach. Reviewed-by: cduclos --- src/gui/dialogs/qfontdialog_mac.mm | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/gui/dialogs/qfontdialog_mac.mm b/src/gui/dialogs/qfontdialog_mac.mm index 93410e7..3a4c688 100644 --- a/src/gui/dialogs/qfontdialog_mac.mm +++ b/src/gui/dialogs/qfontdialog_mac.mm @@ -95,7 +95,6 @@ const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWin BOOL mPanelHackedWithButtons; CGFloat mDialogExtraWidth; CGFloat mDialogExtraHeight; - NSModalSession mModalSession; } - (id)initWithFontPanel:(NSFontPanel *)panel stolenContentView:(NSView *)stolenContentView @@ -106,7 +105,6 @@ const int StyleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWin extraHeight:(CGFloat)extraHeight; - (void)changeFont:(id)sender; - (void)changeAttributes:(id)sender; -- (void)setModalSession:(NSModalSession)session; - (BOOL)windowShouldClose:(id)window; - (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize; - (void)relayout; @@ -163,7 +161,6 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) mPanelHackedWithButtons = (okButton != 0); mDialogExtraWidth = extraWidth; mDialogExtraHeight = extraHeight; - mModalSession = 0; if (mPanelHackedWithButtons) { [self relayout]; @@ -216,12 +213,6 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) mPriv->updateSampleFont(*mQtFont); } -- (void)setModalSession:(NSModalSession)session -{ - Q_ASSERT(!mModalSession); - mModalSession = session; -} - - (BOOL)windowShouldClose:(id)window { Q_UNUSED(window); @@ -368,21 +359,14 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) - (void)finishOffWithCode:(NSInteger)code { - if (mPriv) { - if (mModalSession) { - [NSApp endModalSession:mModalSession]; - mModalSession = 0; - } - // Hack alert! - // Since this code path was never intended to be followed when starting from exec - // we need to force the dialog to communicate the new font, otherwise the signal - // won't get emitted. - if(code == NSOKButton) - mPriv->sampleEdit->setFont([self qtFont]); - mPriv->done((code == NSOKButton) ? QDialog::Accepted : QDialog::Rejected); - } else { - [NSApp stopModalWithCode:code]; - } + [NSApp stopModalWithCode:code]; + // Hack alert! + // Since this code path was never intended to be followed when starting from exec + // we need to force the dialog to communicate the new font, otherwise the signal + // won't get emitted. + if(code == NSOKButton) + mPriv->sampleEdit->setFont([self qtFont]); + mPriv->done((code == NSOKButton) ? QDialog::Accepted : QDialog::Rejected); } - (void)cleanUpAfterMyself @@ -544,8 +528,6 @@ void *QFontDialogPrivate::_q_constructNativePanel() } NSString *title = @"Select font"; [ourPanel setTitle:title]; - - [delegate setModalSession:[NSApp beginModalSessionForWindow:ourPanel]]; return delegate; } @@ -575,6 +557,7 @@ void QFontDialogPrivate::_q_macRunNativeAppModalPanel() QCocoaFontPanelDelegate *delegate = (QCocoaFontPanelDelegate *)_q_constructNativePanel(); NSWindow *ourPanel = [delegate actualPanel]; [ourPanel retain]; + int rval = [NSApp runModalForWindow:ourPanel]; QAbstractEventDispatcher::instance()->interrupt(); [ourPanel release]; -- cgit v0.12