mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-12 12:20:46 +01:00
cocoa: complete implementation of GetDC, ReleaseDC
git-svn-id: trunk@38955 -
This commit is contained in:
parent
8929340e01
commit
c48efd29bf
@ -435,6 +435,7 @@ var
|
|||||||
DefaultPen: TCocoaPen;
|
DefaultPen: TCocoaPen;
|
||||||
DefaultFont: TCocoaFont;
|
DefaultFont: TCocoaFont;
|
||||||
DefaultBitmap: TCocoaBitmap;
|
DefaultBitmap: TCocoaBitmap;
|
||||||
|
DefaultContext: TCocoaBitmapContext;
|
||||||
ScreenContext: TCocoaContext;
|
ScreenContext: TCocoaContext;
|
||||||
|
|
||||||
function CheckDC(dc: HDC): TCocoaContext;
|
function CheckDC(dc: HDC): TCocoaContext;
|
||||||
@ -1121,16 +1122,16 @@ end;
|
|||||||
|
|
||||||
procedure TCocoaBitmapContext.SetBitmap(const AValue: TCocoaBitmap);
|
procedure TCocoaBitmapContext.SetBitmap(const AValue: TCocoaBitmap);
|
||||||
begin
|
begin
|
||||||
if FBitmap <> AValue then
|
if Assigned(ctx) then
|
||||||
|
begin
|
||||||
|
ctx.release;
|
||||||
|
ctx := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if FBitmap <> nil then
|
||||||
begin
|
begin
|
||||||
FBitmap := AValue;
|
FBitmap := AValue;
|
||||||
if Assigned(ctx) then
|
ctx := NSGraphicsContext.graphicsContextWithBitmapImageRep(Bitmap.ImageRep);
|
||||||
begin
|
|
||||||
ctx.release;
|
|
||||||
ctx := nil;
|
|
||||||
end;
|
|
||||||
|
|
||||||
ctx := NSGraphicsContext.graphicsContextWithBitmapImageRep(AValue.ImageRep);
|
|
||||||
InitDraw(Bitmap.Width, Bitmap.Height);
|
InitDraw(Bitmap.Width, Bitmap.Height);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -2602,10 +2603,15 @@ initialization
|
|||||||
DefaultPen := TCocoaPen.CreateDefault;
|
DefaultPen := TCocoaPen.CreateDefault;
|
||||||
DefaultFont := TCocoaFont.CreateDefault;
|
DefaultFont := TCocoaFont.CreateDefault;
|
||||||
DefaultBitmap := TCocoaBitmap.CreateDefault;
|
DefaultBitmap := TCocoaBitmap.CreateDefault;
|
||||||
ScreenContext := TCocoaContext.Create(nil);
|
DefaultContext := TCocoaBitmapContext.Create;
|
||||||
|
DefaultContext.Bitmap := DefaultBitmap;
|
||||||
|
|
||||||
|
ScreenContext := TCocoaContext.Create(DefaultContext.ctx);
|
||||||
|
|
||||||
finalization
|
finalization
|
||||||
ScreenContext.Free;
|
ScreenContext.Free;
|
||||||
|
DefaultContext.Free;
|
||||||
|
|
||||||
DefaultBrush.Free;
|
DefaultBrush.Free;
|
||||||
DefaultPen.Free;
|
DefaultPen.Free;
|
||||||
DefaultFont.Free;
|
DefaultFont.Free;
|
||||||
|
|||||||
@ -1307,13 +1307,15 @@ begin
|
|||||||
Result := HDC(ScreenContext)
|
Result := HDC(ScreenContext)
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
// ToDo: Not finished yet
|
|
||||||
Result := 0;
|
|
||||||
|
|
||||||
ctx := NSObject(hWnd).lclGetCallback.GetContext;
|
ctx := NSObject(hWnd).lclGetCallback.GetContext;
|
||||||
|
|
||||||
// todo: use dummy context if we are outside paint event
|
if ctx = nil then
|
||||||
Result := HDC(ctx);
|
begin
|
||||||
|
ctx := TCocoaContext.Create(DefaultContext.ctx);
|
||||||
|
with DefaultContext.size do
|
||||||
|
ctx.InitDraw(cx, cy);
|
||||||
|
end;
|
||||||
|
Result := HDC(ctx)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{$IFDEF VerboseWinAPI}
|
{$IFDEF VerboseWinAPI}
|
||||||
@ -1588,6 +1590,19 @@ begin
|
|||||||
Result := IntersectRect(R, ARect, CGRectToRect(ClipBox));
|
Result := IntersectRect(R, ARect, CGRectToRect(ClipBox));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCocoaWidgetSet.ReleaseDC(hWnd: HWND; DC: HDC): Integer;
|
||||||
|
var
|
||||||
|
ctx: TCocoaContext;
|
||||||
|
begin
|
||||||
|
Result := 0;
|
||||||
|
ctx := CheckDC(DC);
|
||||||
|
if not Assigned(ctx) then
|
||||||
|
Exit;
|
||||||
|
if (ctx <> DefaultContext) and (ctx.ctx <> DefaultContext.ctx) then
|
||||||
|
ctx.Free;
|
||||||
|
Result := 1;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCocoaWidgetSet.GetWindowOrgEx(dc: hdc; P: PPoint): Integer;
|
function TCocoaWidgetSet.GetWindowOrgEx(dc: hdc; P: PPoint): Integer;
|
||||||
var
|
var
|
||||||
ctx: TCocoaContext;
|
ctx: TCocoaContext;
|
||||||
|
|||||||
@ -152,8 +152,8 @@ function PostMessage(Handle: HWND; Msg: Cardinal; wParam: WParam; lParam: LParam
|
|||||||
|
|
||||||
function Rectangle(DC: HDC; X1, Y1, X2, Y2: Integer): Boolean; override;
|
function Rectangle(DC: HDC; X1, Y1, X2, Y2: Integer): Boolean; override;
|
||||||
function RectVisible(dc : hdc; const ARect: TRect) : Boolean; override;
|
function RectVisible(dc : hdc; const ARect: TRect) : Boolean; override;
|
||||||
{function ReleaseCapture : Boolean; override;
|
{function ReleaseCapture : Boolean; override;}
|
||||||
function ReleaseDC(hWnd: HWND; DC: HDC): Integer; override;}
|
function ReleaseDC(hWnd: HWND; DC: HDC): Integer; override;
|
||||||
function RestoreDC(DC: HDC; SavedDC: Integer): Boolean; override;
|
function RestoreDC(DC: HDC; SavedDC: Integer): Boolean; override;
|
||||||
function RoundRect(DC: HDC; X1, Y1, X2, Y2: Integer; RX, RY : Integer): Boolean; override;
|
function RoundRect(DC: HDC; X1, Y1, X2, Y2: Integer; RX, RY : Integer): Boolean; override;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user