From 126638922389ca967c1a82b6254de8ac00042158 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 4 Nov 2009 13:41:15 +0100 Subject: Cocoa: QColorDialog crashing when selection colors from system palette The reason was that we did not handle the color space of the selected color correctly. When selection from the system palette, the color points to an index rather than e.g. RGB directly. This patch closes the gap. Another, a bit more evil, crash comes when trying to click on 'SelectedMenuItemColor' from the 'Developer' palette. The exact same behaviour occurs when testing a native cocoa app in xcode directly. So, to handle this as gracefully as possible, we sourround the 'run modal' call with try-catch, and makes sure that we don't quit the dialog until the user actually tells it to. Bugreport to Apple created (bugreport.apple.com): 7364080 Task-number: QTBUG-4578 Reviewed-by: Prasanth --- src/gui/dialogs/qcolordialog_mac.mm | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'src/gui/dialogs/qcolordialog_mac.mm') diff --git a/src/gui/dialogs/qcolordialog_mac.mm b/src/gui/dialogs/qcolordialog_mac.mm index 9e4fdd1d0b..5f074c0d94 100644 --- a/src/gui/dialogs/qcolordialog_mac.mm +++ b/src/gui/dialogs/qcolordialog_mac.mm @@ -252,15 +252,20 @@ QT_USE_NAMESPACE delete mQtColor; mQtColor = new QColor(); NSColor *color = [mColorPanel color]; - NSString *colorSpace = [color colorSpaceName]; - if (colorSpace == NSDeviceCMYKColorSpace) { - CGFloat cyan, magenta, yellow, black, alpha; + NSString *colorSpaceName = [color colorSpaceName]; + if (colorSpaceName == NSDeviceCMYKColorSpace) { + CGFloat cyan = 0, magenta = 0, yellow = 0, black = 0, alpha = 0; [color getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha]; mQtColor->setCmykF(cyan, magenta, yellow, black, alpha); - } else if (colorSpace == NSCalibratedRGBColorSpace || colorSpace == NSDeviceRGBColorSpace) { - CGFloat red, green, blue, alpha; + } else if (colorSpaceName == NSCalibratedRGBColorSpace || colorSpaceName == NSDeviceRGBColorSpace) { + CGFloat red = 0, green = 0, blue = 0, alpha = 0; [color getRed:&red green:&green blue:&blue alpha:&alpha]; mQtColor->setRgbF(red, green, blue, alpha); + } else if (colorSpaceName == NSNamedColorSpace) { + NSColor *tmpColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; + CGFloat red = 0, green = 0, blue = 0, alpha = 0; + [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha]; + mQtColor->setRgbF(red, green, blue, alpha); } else { NSColorSpace *colorSpace = [color colorSpace]; if ([colorSpace colorSpaceModel] == NSCMYKColorSpaceModel && [color numberOfComponents] == 5){ @@ -269,7 +274,7 @@ QT_USE_NAMESPACE mQtColor->setCmykF(components[0], components[1], components[2], components[3], components[4]); } else { NSColor *tmpColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; - CGFloat red, green, blue, alpha; + CGFloat red = 0, green = 0, blue = 0, alpha = 0; [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha]; mQtColor->setRgbF(red, green, blue, alpha); } @@ -319,7 +324,18 @@ QT_USE_NAMESPACE QBoolBlocker nativeDialogOnTop(QApplicationPrivate::native_modal_dialog_active); QMacCocoaAutoReleasePool pool; mDialogIsExecuting = true; - [NSApp runModalForWindow:mColorPanel]; + bool modalEnded = false; + while (!modalEnded) { + @try { + [NSApp runModalForWindow:mColorPanel]; + modalEnded = true; + } @catch (NSException *) { + // For some reason, NSColorPanel throws an exception when + // clicking on 'SelectedMenuItemColor' from the 'Developer' + // palette (tab three). + } + } + QAbstractEventDispatcher::instance()->interrupt(); if (mResultCode == NSCancelButton) mPriv->colorDialog()->reject(); -- cgit v1.2.3