diff --git a/lcl/interfaces/cocoa/cocoagdiobjects.pas b/lcl/interfaces/cocoa/cocoagdiobjects.pas index 44fcb98008..e2b2b8b8ab 100644 --- a/lcl/interfaces/cocoa/cocoagdiobjects.pas +++ b/lcl/interfaces/cocoa/cocoagdiobjects.pas @@ -275,6 +275,11 @@ type ROP2: Integer; PenPos: TPoint; + WindowOfs: TPoint; + ViewportOfs: TPoint; + +// isClipped: Boolean; +// ClipShape: HIShapeRef; end; TGlyphArray = array of NSGlyph; @@ -327,6 +332,8 @@ type FSavedDCList: TFPObjectList; FPenPos: TPoint; FSize: TSize; + FViewPortOfs: TPoint; + FWindowOfs: TPoint; function GetFont: TCocoaFont; function GetTextColor: TColor; procedure SetBitmap(const AValue: TCocoaBitmap); @@ -338,6 +345,10 @@ type procedure SetRegion(const AValue: TCocoaRegion); procedure SetROP2(AValue: Integer); procedure SetTextColor(AValue: TColor); + + procedure UpdateContextOfs(const AWindowOfs, AViewOfs: TPoint); + procedure SetViewPortOfs(AValue: TPoint); + procedure SetWindowOfs(AValue: TPoint); protected function SaveDCData: TCocoaDCData; virtual; procedure RestoreDCData(const AData: TCocoaDCData); virtual; @@ -374,8 +385,6 @@ type function GetTextExtentPoint(AStr: PChar; ACount: Integer; var Size: TSize): Boolean; function GetTextMetrics(var TM: TTextMetric): Boolean; - procedure SetOrigin(X, Y: Integer); - procedure GetOrigin(var X,Y: Integer); function CGContext: CGContextRef; virtual; procedure SetAntialiasing(AValue: Boolean); @@ -388,6 +397,8 @@ type property PenPos: TPoint read FPenPos write FPenPos; property ROP2: Integer read FROP2 write SetROP2; property Size: TSize read FSize; + property WindowOfs: TPoint read FWindowOfs write SetWindowOfs; + property ViewPortOfs: TPoint read FViewPortOfs write SetViewPortOfs; property BkColor: TColor read FBkColor write SetBkColor; property BkMode: Integer read FBkMode write SetBkMode; @@ -1142,6 +1153,41 @@ begin FText.ForegroundColor := TColor(ColorToRGB(AValue)); end; +procedure GetWindowViewTranslate(const AWindowOfs, AViewOfs: TPoint; out dx, dy: Integer); inline; +begin + dx := AViewOfs.x - AWindowOfs.x; + dy := AViewOfs.y - AWindowOfs.y; +end; + +function isSamePoint(const p1, p2: TPoint): Boolean; inline; +begin + Result:=(p1.x=p2.x) and (p1.y=p2.y); +end; + +procedure TCocoaContext.UpdateContextOfs(const AWindowOfs, AViewOfs: TPoint); +var + dx, dy: Integer; +begin + if isSamePoint(AWindowOfs, FWindowOfs) and isSamePoint(AViewOfs, FViewPortOfs) then Exit; + GetWindowViewTranslate(FWindowOfs, FViewPortOfs, dx{%H-}, dy{%H-}); + CGContextTranslateCTM(CGContext, -dx, -dy); + + FWindowOfs := AWindowOfs; + FViewPortOfs := AViewOfs; + GetWindowViewTranslate(FWindowOfs, FViewPortOfs, dx, dy); + CGContextTranslateCTM(CGContext, dx, dy); +end; + +procedure TCocoaContext.SetViewPortOfs(AValue: TPoint); +begin + UpdateContextOfs(WindowOfs, AValue); +end; + +procedure TCocoaContext.SetWindowOfs(AValue: TPoint); +begin + UpdateContextOfs(AValue, ViewPortOfs); +end; + function TCocoaContext.SaveDCData: TCocoaDCData; begin Result := TCocoaDCData.Create; @@ -1159,6 +1205,12 @@ begin Result.ROP2 := FROP2; Result.PenPos := FPenPos; + + Result.WindowOfs := FWindowOfs; + Result.ViewportOfs := FViewportOfs; + +// Result.isClipped := isClipped; +// Result.ClipShape := FClipRegion.GetShapeCopy; end; procedure TCocoaContext.RestoreDCData(const AData: TCocoaDCData); @@ -1207,6 +1259,12 @@ begin FROP2 := AData.ROP2; FPenPos := AData.PenPos; + + FWindowOfs := AData.WindowOfs; + FViewportOfs := AData.ViewportOfs; + +// isClipped := AData.isClipped; +// FClipRegion.Shape := AData.ClipShape; end; constructor TCocoaContext.Create; @@ -1812,30 +1870,6 @@ begin HIThemeDrawFocusRect(RectToCGRect(ARect), True, CGContext, kHIThemeOrientationNormal); end; -procedure TCocoaContext.SetOrigin(X, Y:Integer); -var - cg: CGContextRef; -begin - cg := CGContext; - if Assigned(cg) then - CGContextTranslateCTM(cg, X, Y); -end; - -procedure TCocoaContext.GetOrigin(var X, Y: Integer); -var - cg: CGContextRef; - t: CGAffineTransform; -begin - cg := CGContext; - if Assigned(cg) then - begin - t := CGContextGetCTM(cg); - X := Round(t.tx); - Y := Size.cy - Round(t.ty); - end; -end; - - { TCocoaRegion } {------------------------------------------------------------------------------ diff --git a/lcl/interfaces/cocoa/cocoawinapi.inc b/lcl/interfaces/cocoa/cocoawinapi.inc index dca1fbc304..f9dce83ca7 100644 --- a/lcl/interfaces/cocoa/cocoawinapi.inc +++ b/lcl/interfaces/cocoa/cocoawinapi.inc @@ -1549,32 +1549,16 @@ begin Result := IntersectRect(R, ARect, CGRectToRect(ClipBox)); end; -function TCocoaWidgetSet.MoveWindowOrgEx(DC: HDC; dX, dY: Integer): Boolean; +function TCocoaWidgetSet.GetWindowOrgEx(dc: hdc; P: PPoint): Integer; var - ctx : TCocoaContext; + ctx: TCocoaContext; begin - Result := False; - ctx:=CheckDC(DC); - if not Assigned(ctx) then Exit; - - {$IFDEF VerboseWinAPI} - DebugLn('TCarbonWidgetSet.MoveWindowOrgEx DC: ' + DbgS(DC) + ' ' + DbgS(DX) + ', ' + DbgS(DY)); - {$ENDIF} - ctx.SetOrigin(dX, dY); - Result := True; -end; - -function TCocoaWidgetSet.GetWindowOrgEx(dc : hdc; P : PPoint): Integer; -var - ctx : TCocoaContext; -begin - ctx:=CheckDC(dc); - if not Assigned(ctx) or not Assigned(P) then - Result:=0 - else begin - ctx.GetOrigin(p^.X, p^.Y); - Result:=1; - end; + ctx := CheckDC(dc); + if not Assigned(ctx) then + Exit(0); + if Assigned(P) then + P^ := ctx.WindowOfs; + Result:=1; end; function TCocoaWidgetSet.SetCursor(ACursor: HCURSOR): HCURSOR; @@ -1652,6 +1636,36 @@ begin Result := CLR_INVALID; end; +function TCocoaWidgetSet.SetViewPortOrgEx(DC: HDC; NewX, NewY: Integer; + OldPoint: PPoint): Boolean; +var + ctx: TCocoaContext; +begin + Result := False; + ctx := CheckDC(DC); + if not Assigned(ctx) then Exit; + + if Assigned(OldPoint) then + OldPoint^ := ctx.ViewportOfs; + ctx.ViewportOfs := Types.Point(NewX, NewY); + Result := True; +end; + +function TCocoaWidgetSet.SetWindowOrgEx(DC: HDC; NewX, NewY: Integer; + OldPoint: PPoint): Boolean; +var + ctx: TCocoaContext; +begin + Result := False; + ctx := CheckDC(DC); + if not Assigned(ctx) then Exit; + + if Assigned(OldPoint) then + OldPoint^ := ctx.WindowOfs; + ctx.WindowOfs := Types.Point(NewX, NewY); + Result := True; +end; + function TCocoaWidgetSet.ShowCaret(Handle: HWND): Boolean; var Obj: NSObject; @@ -1779,6 +1793,18 @@ begin Result := Assigned(ctx) and ctx.GetTextMetrics(TM); end; +function TCocoaWidgetSet.GetViewPortOrgEx(DC: HDC; P: PPoint): Integer; +var + ctx: TCocoaContext; +begin + ctx := CheckDC(dc); + if not Assigned(ctx) then + Exit(0); + if Assigned(P) then + P^ := ctx.ViewportOfs; + Result:=1; +end; + function TCocoaWidgetSet.TextOut(DC: HDC; X,Y: Integer; Str: Pchar; Count: Integer) : Boolean; begin Result := ExtTextOut(DC, X, Y, 0, nil, Str, Count, nil); diff --git a/lcl/interfaces/cocoa/cocoawinapih.inc b/lcl/interfaces/cocoa/cocoawinapih.inc index 91a8d90a27..e6524d738d 100644 --- a/lcl/interfaces/cocoa/cocoawinapih.inc +++ b/lcl/interfaces/cocoa/cocoawinapih.inc @@ -123,13 +123,12 @@ function GetSystemMetrics(nIndex: Integer): Integer; override; function GetTextColor(DC: HDC) : TColorRef; Override; function GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean; override; function GetTextMetrics(DC: HDC; var TM: TTextMetric): Boolean; override; +function GetViewPortOrgEx(DC: HDC; P: PPoint): Integer; override; {function GetWindowLong(Handle : hwnd; int: Integer): PtrInt; override;} function GetWindowOrgEx(dc : hdc; P : PPoint): Integer; override; function GetWindowRect(Handle: hwnd; var ARect: TRect): Integer; override; function GetWindowRelativePosition(Handle: hwnd; var Left, Top: Integer): boolean; override; function GetWindowSize(Handle: hwnd; var Width, Height: Integer): boolean; override; -{function GradientFill(DC: HDC; Vertices: PTriVertex; NumVertices : Longint; - Meshes: Pointer; NumMeshes : Longint; Mode : Longint): Boolean; override;} function HideCaret(Handle: HWND): Boolean; override; @@ -143,7 +142,6 @@ function LineTo(DC: HDC; X, Y: Integer): Boolean; override; {function MessageBox(hWnd: HWND; lpText, lpCaption: PChar; uType: Cardinal): integer; override;} function MoveToEx(DC: HDC; X, Y: Integer; OldPoint: PPoint): Boolean; override; -function MoveWindowOrgEx(DC: HDC; dX, dY: Integer): Boolean; override; {function PeekMessage(var lpMsg : TMsg; Handle : HWND; wMsgFilterMin, wMsgFilterMax,wRemoveMsg : UINT): Boolean; override; function PolyBezier(DC: HDC; Points: PPoint; NumPts: Integer; Filled, Continuous: boolean): boolean; override;} @@ -179,7 +177,8 @@ function SetROP2(DC: HDC; Mode: Integer): Integer; override; function SetScrollInfo(Handle : HWND; SBStyle : Integer; ScrollInfo: TScrollInfo; bRedraw : Boolean): Integer; override; function SetSysColors(cElements: Integer; const lpaElements; const lpaRgbValues): Boolean; override; function SetTextColor(DC: HDC; Color: TColorRef): TColorRef; override; -{function SetWindowOrgEx(DC : HDC; NewX, NewY : Integer; OldPoint: PPoint) : Boolean; override;} +function SetViewPortOrgEx(DC: HDC; NewX, NewY: Integer; OldPoint: PPoint): Boolean; override; +function SetWindowOrgEx(DC: HDC; NewX, NewY: Integer; OldPoint: PPoint) : Boolean; override; function ShowCaret(Handle: HWND): Boolean; override; function ShowScrollBar(Handle: HWND; wBar: Integer; bShow: Boolean): Boolean; override; function ShowWindow(hWnd: HWND; nCmdShow: Integer): Boolean; override;