From 01c8eef539f9a2b793e191f80e5735f73576023a Mon Sep 17 00:00:00 2001 From: dmitry Date: Sun, 16 Sep 2018 03:27:52 +0000 Subject: [PATCH] cocoa: extend support of CGContextRef (for macOS 10.10 and later). Adding init of context for custom drawn dropdownlist git-svn-id: trunk@59027 - --- lcl/interfaces/cocoa/cocoa_extra.pas | 2 ++ lcl/interfaces/cocoa/cocoagdiobjects.pas | 21 ++++++++++++++++++++- lcl/interfaces/cocoa/cocoatextedits.pas | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lcl/interfaces/cocoa/cocoa_extra.pas b/lcl/interfaces/cocoa/cocoa_extra.pas index 3c7c1d3f7d..84adbb91ff 100644 --- a/lcl/interfaces/cocoa/cocoa_extra.pas +++ b/lcl/interfaces/cocoa/cocoa_extra.pas @@ -77,6 +77,8 @@ type NSGraphicsContextFix = objccategory external(NSGraphicsContext) procedure setImageInterpolation(interpolation: NSImageInterpolation); message 'setImageInterpolation:'; procedure setShouldAntialias(antialias: Boolean); message 'setShouldAntialias:'; + // 10.10 + function CGContext: CGContextRef; message 'CGContext'; end; NSEventFix = objccategory external (NSEvent) diff --git a/lcl/interfaces/cocoa/cocoagdiobjects.pas b/lcl/interfaces/cocoa/cocoagdiobjects.pas index f677cb3898..a8953af772 100644 --- a/lcl/interfaces/cocoa/cocoagdiobjects.pas +++ b/lcl/interfaces/cocoa/cocoagdiobjects.pas @@ -492,11 +492,30 @@ function CheckDC(dc: HDC; Str: string): Boolean; function CheckGDIOBJ(obj: HGDIOBJ): TCocoaGDIObject; function CheckBitmap(ABitmap: HBITMAP; AStr: string): Boolean; +type + + { LCLNSGraphicsContext } + + LCLNSGraphicsContext = objccategory (NSGraphicsContext) + function lclCGContext: CGContextRef; message 'lclCGContext'; + end; + implementation uses CocoaInt; + +{ LCLNSGraphicsContext } + +function LCLNSGraphicsContext.lclCGcontext: CGContextRef; +begin + if NSAppKitVersionNumber >= NSAppKitVersionNumber10_10 then + Result := CGContext + else + Result := CGContextRef(graphicsPort); +end; + //todo: a better check! function CheckDC(dc: HDC): TCocoaContext; @@ -1378,7 +1397,7 @@ end; function TCocoaContext.CGContext: CGContextRef; begin - Result := CGContextRef(ctx.graphicsPort); + Result := CGContextRef(ctx.lclCGContext); end; procedure TCocoaContext.SetAntialiasing(AValue: Boolean); diff --git a/lcl/interfaces/cocoa/cocoatextedits.pas b/lcl/interfaces/cocoa/cocoatextedits.pas index ed1ad66ac9..b67797e492 100644 --- a/lcl/interfaces/cocoa/cocoatextedits.pas +++ b/lcl/interfaces/cocoa/cocoatextedits.pas @@ -408,6 +408,7 @@ begin ctx := TCocoaContext.Create(NSGraphicsContext.currentContext); try + ctx.InitDraw(Round(dirtyRect.size.width), Round(dirtyRect.size.height)); combobox.callback.ComboBoxDrawItem(itemIndex, ctx, NSRectToRect(frame), false); finally ctx.Free;