cocoa: extend support of CGContextRef (for macOS 10.10 and later). Adding init of context for custom drawn dropdownlist

git-svn-id: trunk@59027 -
This commit is contained in:
dmitry 2018-09-16 03:27:52 +00:00
parent a1c48e5e97
commit 01c8eef539
3 changed files with 23 additions and 1 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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;