Ticket #62964: patch-mavericks-compatibility.diff
File patch-mavericks-compatibility.diff, 17.1 KB (added by Wowfunhappy (Jonathan), 3 years ago) |
---|
-
src/corelib/global/qoperatingsystemversion_darwin.mm
From 2f0271392a5cd6f7064c2db96f74ccfc6cc13d2e Mon Sep 17 00:00:00 2001 From: Wowfunhappy <Wowfunhappy@gmail.com> Date: Mon, 24 May 2021 16:45:00 -0400 Subject: [PATCH] Initial Mavericks Compat Fixes --- .../global/qoperatingsystemversion_darwin.mm | 53 +++++++- src/corelib/io/qfilesystemengine_unix.cpp | 4 +- src/corelib/kernel/qcore_foundation.mm | 8 +- src/gui/painting/qcoregraphics.mm | 133 +++++++++++---------- .../platforms/cocoa/images/copyarrowcursor.png | Bin 0 -> 1976 bytes .../platforms/cocoa/images/forbiddencursor.png | Bin 0 -> 1745 bytes .../cocoa/images/leopard-unified-toolbar-on.png | Bin 0 -> 356 bytes src/plugins/platforms/cocoa/qcocoaresources.qrc | 17 ++- src/plugins/platforms/cocoa/qcocoawindow.mm | 8 +- 9 files changed, 138 insertions(+), 85 deletions(-) create mode 100644 src/plugins/platforms/cocoa/images/copyarrowcursor.png create mode 100644 src/plugins/platforms/cocoa/images/forbiddencursor.png create mode 100644 src/plugins/platforms/cocoa/images/leopard-unified-toolbar-on.png diff --git src/corelib/global/qoperatingsystemversion_darwin.mm src/corelib/global/qoperatingsystemversion_darwin.mm index d8b927ff5d..3dd007cbb3 100644
40 40 #include "qoperatingsystemversion_p.h" 41 41 #import <Foundation/Foundation.h> 42 42 43 #ifdef Q_OS_IOS 44 #import <UIKit/UIKit.h> 45 #endif 46 43 47 QT_BEGIN_NAMESPACE 44 48 49 typedef qint16 (*GestaltFunction)(quint32 selector, qint32 *response); 50 45 51 QOperatingSystemVersion QOperatingSystemVersion::current() 46 52 { 47 NSOperatingSystemVersion osv = NSProcessInfo.processInfo.operatingSystemVersion;48 53 QOperatingSystemVersion v; 49 54 v.m_os = currentType(); 50 v.m_major = osv.majorVersion; 51 v.m_minor = osv.minorVersion; 52 v.m_micro = osv.patchVersion; 55 v.m_major = -1; 56 v.m_minor = -1; 57 v.m_micro = -1; 58 #if QT_MACOS_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_10, __IPHONE_8_0) || defined(Q_OS_TVOS) || defined(Q_OS_WATCHOS) 59 if ([NSProcessInfo instancesRespondToSelector:@selector(operatingSystemVersion)]) { 60 NSOperatingSystemVersion osv = NSProcessInfo.processInfo.operatingSystemVersion; 61 v.m_major = osv.majorVersion; 62 v.m_minor = osv.minorVersion; 63 v.m_micro = osv.patchVersion; 64 return v; 65 } 66 #endif 67 // Use temporary variables so we can return 0.0.0 (unknown version) 68 // in case of an error partway through determining the OS version 69 qint32 major = 0, minor = 0, patch = 0; 70 #if QT_MACOS_IOS_DEPLOYMENT_TARGET_BELOW(__MAC_10_10, __IPHONE_8_0) 71 #if defined(Q_OS_IOS) 72 @autoreleasepool { 73 NSArray *parts = [UIDevice.currentDevice.systemVersion componentsSeparatedByString:@"."]; 74 major = parts.count > 0 ? [[parts objectAtIndex:0] intValue] : 0; 75 minor = parts.count > 1 ? [[parts objectAtIndex:1] intValue] : 0; 76 patch = parts.count > 2 ? [[parts objectAtIndex:2] intValue] : 0; 77 } 78 #elif defined(Q_OS_MACOS) 79 static GestaltFunction pGestalt = 0; 80 if (!pGestalt) { 81 CFBundleRef b = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.CoreServices")); 82 pGestalt = reinterpret_cast<GestaltFunction>(CFBundleGetFunctionPointerForName(b, 83 CFSTR("Gestalt"))); 84 } 85 if (!pGestalt) 86 return v; 87 if (pGestalt('sys1', &major) != 0) 88 return v; 89 if (pGestalt('sys2', &minor) != 0) 90 return v; 91 if (pGestalt('sys3', &patch) != 0) 92 return v; 93 #endif 94 #endif 95 v.m_major = major; 96 v.m_minor = minor; 97 v.m_micro = patch; 53 98 return v; 54 99 } 55 100 -
src/corelib/io/qfilesystemengine_unix.cpp
diff --git src/corelib/io/qfilesystemengine_unix.cpp src/corelib/io/qfilesystemengine_unix.cpp index 7fed54f733..9e43da8b0d 100644
static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &e 126 126 127 127 #ifdef Q_OS_MACOS 128 128 // Find if an application other than Finder claims to know how to handle the package 129 QCFType<CFURLRef> application = LSCopyDefaultApplicationURLForURL(url,129 /*QCFType<CFURLRef> application = LSCopyDefaultApplicationURLForURL(url, 130 130 kLSRolesEditor | kLSRolesViewer, nullptr); 131 131 132 132 if (application) { … … static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &e 135 135 QString applicationId = QString::fromCFString(identifier); 136 136 if (applicationId != QLatin1String("com.apple.finder")) 137 137 return true; 138 } 138 }*/ 139 139 #endif 140 140 } 141 141 -
src/corelib/kernel/qcore_foundation.mm
diff --git src/corelib/kernel/qcore_foundation.mm src/corelib/kernel/qcore_foundation.mm index 56eabc4b8c..fc448be38f 100644
QTimeZone QTimeZone::fromNSTimeZone(const NSTimeZone *timeZone) 486 486 487 487 \sa fromNSTimeZone() 488 488 */ 489 NSTimeZone *QTimeZone::toNSTimeZone() const490 {491 return [static_cast<NSTimeZone *>(toCFTimeZone()) autorelease];492 }489 //NSTimeZone *QTimeZone::toNSTimeZone() const 490 //{ 491 // return [static_cast<NSTimeZone *>(toCFTimeZone()) autorelease]; 492 //} 493 493 #endif 494 494 495 495 // ---------------------------------------------------------------------------- -
src/gui/painting/qcoregraphics.mm
diff --git src/gui/painting/qcoregraphics.mm src/gui/painting/qcoregraphics.mm index c4fb8afc64..bf2d028b99 100644
CGImageRef qt_mac_toCGImageMask(const QImage &image) 65 65 { 66 66 static const auto deleter = [](void *image, const void *, size_t) { delete static_cast<QImage *>(image); }; 67 67 QCFType<CGDataProviderRef> dataProvider = 68 69 70 68 CGDataProviderCreateWithData(new QImage(image), image.bits(), 69 image.byteCount(), deleter); 70 71 71 return CGImageMaskCreate(image.width(), image.height(), 8, image.depth(), 72 72 image.bytesPerLine(), dataProvider, NULL, false); 73 73 } 74 74 75 75 void qt_mac_drawCGImage(CGContextRef inContext, const CGRect *inBounds, CGImageRef inImage) … … void qt_mac_drawCGImage(CGContextRef inContext, const CGRect *inBounds, CGImageR 77 77 CGContextSaveGState( inContext ); 78 78 CGContextTranslateCTM (inContext, 0, inBounds->origin.y + CGRectGetMaxY(*inBounds)); 79 79 CGContextScaleCTM(inContext, 1, -1); 80 80 81 81 CGContextDrawImage(inContext, *inBounds, inImage); 82 82 83 83 CGContextRestoreGState(inContext); 84 84 } 85 85 86 86 QImage qt_mac_toQImage(CGImageRef image) 87 87 { 88 88 const size_t w = CGImageGetWidth(image), 89 89 h = CGImageGetHeight(image); 90 90 QImage ret(w, h, QImage::Format_ARGB32_Premultiplied); 91 91 ret.fill(Qt::transparent); 92 92 CGRect rect = CGRectMake(0, 0, w, h); … … QPixmap qt_mac_toQPixmap(const NSImage *image, const QSizeF &size) 147 147 QMacCGContext ctx(&pixmap); 148 148 if (!ctx) 149 149 return QPixmap(); 150 NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:ctx flipped:YES]; 150 151 //NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:ctx flipped:YES]; 152 NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithGraphicsPort:ctx flipped:YES]; 153 151 154 if (!gc) 152 155 return QPixmap(); 153 156 [NSGraphicsContext saveGraphicsState]; … … static CGColorSpaceRef qt_mac_displayColorSpace(const QWindow *window) 324 327 } else { 325 328 displayID = CGMainDisplayID(); 326 329 /* 327 ### get correct display328 const QRect &qrect = window->geometry();329 CGRect rect = CGRectMake(qrect.x(), qrect.y(), qrect.width(), qrect.height());330 CGDisplayCount throwAway;331 CGDisplayErr dErr = CGGetDisplaysWithRect(rect, 1, &displayID, &throwAway);332 if (dErr != kCGErrorSuccess)333 334 */330 ### get correct display 331 const QRect &qrect = window->geometry(); 332 CGRect rect = CGRectMake(qrect.x(), qrect.y(), qrect.width(), qrect.height()); 333 CGDisplayCount throwAway; 334 CGDisplayErr dErr = CGGetDisplaysWithRect(rect, 1, &displayID, &throwAway); 335 if (dErr != kCGErrorSuccess) 336 return macDisplayColorSpace(0); // fall back on main display 337 */ 335 338 } 336 339 if ((colorSpace = m_displayColorSpaceHash.value(displayID))) 337 340 return colorSpace; … … QMacCGContext::QMacCGContext(QPaintDevice *paintDevice) : context(0) 442 445 if (paintDevice->devType() == QInternal::Image) { 443 446 image = static_cast<QImage *>(paintDevice); 444 447 } else if (paintDevice->devType() == QInternal::Pixmap) { 445 448 446 449 const QPixmap *pm = static_cast<const QPixmap*>(paintDevice); 447 450 QPlatformPixmap *data = const_cast<QPixmap *>(pm)->data_ptr().data(); 448 451 if (data && data->classId() == QPlatformPixmap::RasterClass) { … … QMacCGContext::QMacCGContext(QPaintDevice *paintDevice) : context(0) 463 466 flags |= kCGBitmapByteOrder32Host; 464 467 465 468 context = CGBitmapContextCreate(image->bits(), image->width(), image->height(), 466 8, image->bytesPerLine(), colorspace, flags);469 8, image->bytesPerLine(), colorspace, flags); 467 470 CGContextTranslateCTM(context, 0, image->height()); 468 471 const qreal devicePixelRatio = paintDevice->devicePixelRatioF(); 469 472 CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio); … … QMacCGContext::QMacCGContext(QPainter *painter) : context(0) 477 480 // Handle the case of QMacPrintEngine, which has an internal QCoreGraphicsPaintEngine 478 481 while (QPaintEngine *aggregateEngine = QPaintEnginePrivate::get(paintEngine)->aggregateEngine()) 479 482 paintEngine = aggregateEngine; 480 483 481 484 paintEngine->syncState(); 482 485 483 486 if (Qt::HANDLE handle = QPaintEnginePrivate::get(paintEngine)->nativeHandle()) { 484 487 context = static_cast<CGContextRef>(handle); 485 488 return; 486 489 } 487 490 488 491 int devType = painter->device()->devType(); 489 492 if (paintEngine->type() == QPaintEngine::Raster 490 491 492 493 494 CGColorSpaceRef colorspace = qt_mac_colorSpaceForDeviceType(paintEngine->paintDevice());495 uint flags = kCGImageAlphaPremultipliedFirst;493 && (devType == QInternal::Widget || 494 devType == QInternal::Pixmap || 495 devType == QInternal::Image)) { 496 497 CGColorSpaceRef colorspace = qt_mac_colorSpaceForDeviceType(paintEngine->paintDevice()); 498 uint flags = kCGImageAlphaPremultipliedFirst; 496 499 #ifdef kCGBitmapByteOrder32Host //only needed because CGImage.h added symbols in the minor version 497 flags |= kCGBitmapByteOrder32Host;500 flags |= kCGBitmapByteOrder32Host; 498 501 #endif 499 const QImage *image = static_cast<const QImage *>(paintEngine->paintDevice()); 500 501 context = CGBitmapContextCreate((void *)image->bits(), image->width(), image->height(), 502 8, image->bytesPerLine(), colorspace, flags); 503 504 // Invert y axis 505 CGContextTranslateCTM(context, 0, image->height()); 506 CGContextScaleCTM(context, 1, -1); 507 508 const qreal devicePixelRatio = image->devicePixelRatio(); 509 510 if (devType == QInternal::Widget) { 511 // Set the clip rect which is an intersection of the system clip 512 // and the painter clip. To make matters more interesting these 513 // are in device pixels and device-independent pixels, respectively. 514 QRegion clip = painter->paintEngine()->systemClip(); // get system clip in device pixels 515 QTransform native = painter->deviceTransform(); // get device transform. dx/dy is in device pixels 516 517 if (painter->hasClipping()) { 518 QRegion r = painter->clipRegion(); // get painter clip, which is in device-independent pixels 519 qt_mac_scale_region(&r, devicePixelRatio); // scale painter clip to device pixels 520 r.translate(native.dx(), native.dy()); 521 if (clip.isEmpty()) 522 clip = r; 523 else 524 clip &= r; 502 const QImage *image = static_cast<const QImage *>(paintEngine->paintDevice()); 503 504 context = CGBitmapContextCreate((void *)image->bits(), image->width(), image->height(), 505 8, image->bytesPerLine(), colorspace, flags); 506 507 // Invert y axis 508 CGContextTranslateCTM(context, 0, image->height()); 509 CGContextScaleCTM(context, 1, -1); 510 511 const qreal devicePixelRatio = image->devicePixelRatio(); 512 513 if (devType == QInternal::Widget) { 514 // Set the clip rect which is an intersection of the system clip 515 // and the painter clip. To make matters more interesting these 516 // are in device pixels and device-independent pixels, respectively. 517 QRegion clip = painter->paintEngine()->systemClip(); // get system clip in device pixels 518 QTransform native = painter->deviceTransform(); // get device transform. dx/dy is in device pixels 519 520 if (painter->hasClipping()) { 521 QRegion r = painter->clipRegion(); // get painter clip, which is in device-independent pixels 522 qt_mac_scale_region(&r, devicePixelRatio); // scale painter clip to device pixels 523 r.translate(native.dx(), native.dy()); 524 if (clip.isEmpty()) 525 clip = r; 526 else 527 clip &= r; 528 } 529 qt_mac_clip_cg(context, clip, 0); // clip in device pixels 530 531 // Scale the context so that painting happens in device-independent pixels 532 CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio); 533 CGContextTranslateCTM(context, native.dx() / devicePixelRatio, native.dy() / devicePixelRatio); 534 } else { 535 // Scale to paint in device-independent pixels 536 CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio); 525 537 } 526 qt_mac_clip_cg(context, clip, 0); // clip in device pixels527 528 // Scale the context so that painting happens in device-independent pixels529 CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio);530 CGContextTranslateCTM(context, native.dx() / devicePixelRatio, native.dy() / devicePixelRatio);531 538 } else { 532 // Scale to paint in device-independent pixels 533 CGContextScaleCTM(context, devicePixelRatio, devicePixelRatio); 539 qDebug() << "QMacCGContext:: Unsupported painter devtype type" << devType; 534 540 } 535 } else {536 qDebug() << "QMacCGContext:: Unsupported painter devtype type" << devType;537 }538 541 } 539 542 540 QT_END_NAMESPACE 543 QT_END_NAMESPACE 544 No newline at end of file -
src/plugins/platforms/cocoa/qcocoawindow.mm
diff --git src/plugins/platforms/cocoa/qcocoawindow.mm src/plugins/platforms/cocoa/qcocoawindow.mm index 86fd7b8a9f..2f45347127 100644
static void qt_closePopups() 324 324 325 325 + (void)applicationActivationChanged:(NSNotification*)notification 326 326 { 327 const id sender = self;327 /*const id sender = self; 328 328 NSEnumerator<NSWindow*> *windowEnumerator = nullptr; 329 329 NSApplication *application = [NSApplication sharedApplication]; 330 330 … … static void qt_closePopups() 384 384 // end up triggering a bug in AppKit where the tool windows would disappear behind 385 385 // the application window. 386 386 [window orderFront:sender]; 387 } 387 }*/ 388 388 } 389 389 390 390 - (id)initWithContentRect:(NSRect)contentRect … … void QCocoaWindow::applyContentBorderThickness(NSWindow *window) 2181 2181 if (!m_drawContentBorderGradient) { 2182 2182 [window setStyleMask:[window styleMask] & ~NSTexturedBackgroundWindowMask]; 2183 2183 [[[window contentView] superview] setNeedsDisplay:YES]; 2184 window.titlebarAppearsTransparent = NO;2184 //window.titlebarAppearsTransparent = NO; 2185 2185 return; 2186 2186 } 2187 2187 … … void QCocoaWindow::applyContentBorderThickness(NSWindow *window) 2206 2206 int effectiveBottomContentBorderThickness = m_bottomContentBorderThickness; 2207 2207 2208 2208 [window setStyleMask:[window styleMask] | NSTexturedBackgroundWindowMask]; 2209 window.titlebarAppearsTransparent = YES;2209 //window.titlebarAppearsTransparent = YES; 2210 2210 2211 2211 [window setContentBorderThickness:effectiveTopContentBorderThickness forEdge:NSMaxYEdge]; 2212 2212 [window setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge];