diff options
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoahelpers.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoahelpers.mm | 119 |
1 files changed, 4 insertions, 115 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 7480d99d19..9b4055d92d 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -202,34 +202,13 @@ NSImage *qt_mac_create_nsimage(const QIcon &icon) HIMutableShapeRef qt_mac_QRegionToHIMutableShape(const QRegion ®ion) { HIMutableShapeRef shape = HIShapeCreateMutable(); - QVector<QRect> rects = region.rects(); - if (!rects.isEmpty()) { - int n = rects.count(); - const QRect *qt_r = rects.constData(); - while (n--) { - CGRect cgRect = CGRectMake(qt_r->x(), qt_r->y(), qt_r->width(), qt_r->height()); - HIShapeUnionWithRect(shape, &cgRect); - ++qt_r; - } + for (const QRect &rect : region) { + CGRect cgRect = CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()); + HIShapeUnionWithRect(shape, &cgRect); } return shape; } -NSSize qt_mac_toNSSize(const QSize &qtSize) -{ - return NSMakeSize(qtSize.width(), qtSize.height()); -} - -NSRect qt_mac_toNSRect(const QRect &rect) -{ - return NSMakeRect(rect.x(), rect.y(), rect.width(), rect.height()); -} - -QRect qt_mac_toQRect(const NSRect &rect) -{ - return QRect(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); -} - QColor qt_mac_toQColor(const NSColor *color) { QColor qtColor; @@ -340,38 +319,8 @@ QBrush qt_mac_toQBrush(const NSColor *color, QPalette::ColorGroup colorGroup) // (and providing no public API to get the underlying color without this insanity) if (qt_mac_isSystemColorOrInstance(color, @"controlColor", @"NSGradientPatternColor") || qt_mac_isSystemColorOrInstance(color, @"windowBackgroundColor", @"NSGradientPatternColor")) { - static QColor newColor; - if (!newColor.isValid()) { -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_8, __IPHONE_NA) - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_8) { - newColor = qt_mac_toQColor(color.CGColor); - } else -#endif - { - NSBitmapImageRep *offscreenRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil - pixelsWide:1 - pixelsHigh:1 - bitsPerSample:8 - samplesPerPixel:4 - hasAlpha:YES - isPlanar:NO - colorSpaceName:NSDeviceRGBColorSpace - bytesPerRow:4 - bitsPerPixel:32]; - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:offscreenRep]]; - NSEraseRect(NSMakeRect(0, 0, 1, 1)); - [color drawSwatchInRect:NSMakeRect(0, 0, 1, 1)]; - [NSGraphicsContext restoreGraphicsState]; - NSUInteger pixel[4]; - [offscreenRep getPixel:pixel atX:0 y:0]; - [offscreenRep release]; - newColor = QColor(pixel[0], pixel[1], pixel[2], pixel[3]); - } - } - qtBrush.setStyle(Qt::SolidPattern); - qtBrush.setColor(newColor); + qtBrush.setColor(qt_mac_toQColor(color.CGColor)); return qtBrush; } @@ -687,66 +636,6 @@ Qt::MouseButton cocoaButton2QtButton(NSInteger buttonNum) return Qt::NoButton; } -bool qt_mac_execute_apple_script(const char *script, long script_len, AEDesc *ret) { - OSStatus err; - AEDesc scriptTextDesc; - ComponentInstance theComponent = 0; - OSAID scriptID = kOSANullScript, resultID = kOSANullScript; - - // set up locals to a known state - AECreateDesc(typeNull, 0, 0, &scriptTextDesc); - scriptID = kOSANullScript; - resultID = kOSANullScript; - - // open the scripting component - theComponent = OpenDefaultComponent(kOSAComponentType, typeAppleScript); - if (!theComponent) { - err = paramErr; - goto bail; - } - - // put the script text into an aedesc - err = AECreateDesc(typeUTF8Text, script, script_len, &scriptTextDesc); - if (err != noErr) - goto bail; - - // compile the script - err = OSACompile(theComponent, &scriptTextDesc, kOSAModeNull, &scriptID); - if (err != noErr) - goto bail; - - // run the script - err = OSAExecute(theComponent, scriptID, kOSANullScript, kOSAModeNull, &resultID); - - // collect the results - if any - if (ret) { - AECreateDesc(typeNull, 0, 0, ret); - if (err == errOSAScriptError) - OSAScriptError(theComponent, kOSAErrorMessage, typeChar, ret); - else if (err == noErr && resultID != kOSANullScript) - OSADisplay(theComponent, resultID, typeChar, kOSAModeNull, ret); - } -bail: - AEDisposeDesc(&scriptTextDesc); - if (scriptID != kOSANullScript) - OSADispose(theComponent, scriptID); - if (resultID != kOSANullScript) - OSADispose(theComponent, resultID); - if (theComponent) - CloseComponent(theComponent); - return err == noErr; -} - -bool qt_mac_execute_apple_script(const char *script, AEDesc *ret) -{ - return qt_mac_execute_apple_script(script, qstrlen(script), ret); -} - -bool qt_mac_execute_apple_script(const QString &script, AEDesc *ret) -{ - const QByteArray l = script.toUtf8(); return qt_mac_execute_apple_script(l.constData(), l.size(), ret); -} - QString qt_mac_removeAmpersandEscapes(QString s) { return QPlatformTheme::removeMnemonics(s).trimmed(); |