mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-21 11:39:55 +02:00
Cocoa: fix the issue with Flipped Coordinates, Merge branch 'cocoa/flip'
note that on Cocoa: 1. Not Flipped: opposite to win32 2. Flipped: like win32
This commit is contained in:
parent
33c6b73d32
commit
9c43c3f1d9
@ -505,9 +505,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure SetViewDefaults(AView: NSView);
|
procedure SetViewDefaults(AView: NSView);
|
||||||
|
var
|
||||||
|
mask: NSUInteger;
|
||||||
begin
|
begin
|
||||||
if not Assigned(AView) then Exit;
|
if not Assigned(AView) then Exit;
|
||||||
AView.setAutoresizingMask(NSViewMinYMargin or NSViewMaxXMargin);
|
if Assigned(AView.superview) and AView.superview.isFlipped then
|
||||||
|
mask:= NSViewMaxYMargin or NSViewMaxXMargin
|
||||||
|
else
|
||||||
|
mask:= NSViewMinYMargin or NSViewMaxXMargin;
|
||||||
|
AView.setAutoresizingMask(mask);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function CheckMainThread: Boolean;
|
function CheckMainThread: Boolean;
|
||||||
@ -627,6 +633,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCocoaCustomControl.addSubView(aview: NSView);
|
procedure TCocoaCustomControl.addSubView(aview: NSView);
|
||||||
|
var
|
||||||
|
mask: NSUInteger;
|
||||||
begin
|
begin
|
||||||
inherited addSubView(aview);
|
inherited addSubView(aview);
|
||||||
|
|
||||||
@ -639,7 +647,11 @@ begin
|
|||||||
{$else}
|
{$else}
|
||||||
setAutoresizesSubviews(true);
|
setAutoresizesSubviews(true);
|
||||||
{$endif}
|
{$endif}
|
||||||
aview.setAutoresizingMask(NSViewMaxXMargin or NSViewMinYMargin);
|
if self.isFlipped then
|
||||||
|
mask:= NSViewMaxYMargin or NSViewMaxXMargin
|
||||||
|
else
|
||||||
|
mask:= NSViewMinYMargin or NSViewMaxXMargin;
|
||||||
|
aview.setAutoresizingMask(mask);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1360,7 +1372,7 @@ begin
|
|||||||
if (AParams.WndParent <> 0) then
|
if (AParams.WndParent <> 0) then
|
||||||
p := NSView(AParams.WndParent).lclContentView;
|
p := NSView(AParams.WndParent).lclContentView;
|
||||||
|
|
||||||
if Assigned(p) then
|
if Assigned(p) and p.isFlipped then
|
||||||
LCLToNSRect(Types.Bounds(AParams.X, AParams.Y, AParams.Width, AParams.Height),
|
LCLToNSRect(Types.Bounds(AParams.X, AParams.Y, AParams.Width, AParams.Height),
|
||||||
p.frame.size.height, ns)
|
p.frame.size.height, ns)
|
||||||
else
|
else
|
||||||
|
@ -619,7 +619,10 @@ begin
|
|||||||
fvscroll.controlSize, fvscroll.preferredScrollerStyle);
|
fvscroll.controlSize, fvscroll.preferredScrollerStyle);
|
||||||
r := NSMakeRect(0, 0, w, Max(f.size.height,w+1)); // height<width to create a vertical scroller
|
r := NSMakeRect(0, 0, w, Max(f.size.height,w+1)); // height<width to create a vertical scroller
|
||||||
allocScroller( self, fvscroll, r, avisible);
|
allocScroller( self, fvscroll, r, avisible);
|
||||||
fvscroll.setAutoresizingMask(NSViewHeightSizable or NSViewMinXMargin);
|
if self.isFlipped then
|
||||||
|
fvscroll.setAutoresizingMask(NSViewHeightSizable or NSViewMaxXMargin)
|
||||||
|
else
|
||||||
|
fvscroll.setAutoresizingMask(NSViewHeightSizable or NSViewMinXMargin);
|
||||||
Result := fvscroll;
|
Result := fvscroll;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -697,6 +700,7 @@ procedure TCocoaScrollView.scrollContentViewBoundsChanged(notify: NSNotification
|
|||||||
var
|
var
|
||||||
nw : NSRect;
|
nw : NSRect;
|
||||||
dx,dy : CGFloat;
|
dx,dy : CGFloat;
|
||||||
|
scrollY: CGFloat;
|
||||||
begin
|
begin
|
||||||
if not assigned(documentView) then Exit;
|
if not assigned(documentView) then Exit;
|
||||||
nw:=documentVisibleRect;
|
nw:=documentVisibleRect;
|
||||||
@ -710,6 +714,11 @@ begin
|
|||||||
if holdscroll>0 then Exit;
|
if holdscroll>0 then Exit;
|
||||||
inc(holdscroll);
|
inc(holdscroll);
|
||||||
try
|
try
|
||||||
|
if self.documentView.isFlipped then
|
||||||
|
scrollY:= nw.origin.y
|
||||||
|
else
|
||||||
|
scrollY:= self.documentView.frame.size.height - nw.origin.y - nw.size.height;
|
||||||
|
|
||||||
// update scrollers (this is required, if scrollWheel was called)
|
// update scrollers (this is required, if scrollWheel was called)
|
||||||
// so processing LM_xSCROLL will not cause any actually scrolling,
|
// so processing LM_xSCROLL will not cause any actually scrolling,
|
||||||
// as the current position will match!
|
// as the current position will match!
|
||||||
@ -718,7 +727,7 @@ begin
|
|||||||
callback.scroll(false, round(nw.origin.x));
|
callback.scroll(false, round(nw.origin.x));
|
||||||
|
|
||||||
if (dy<>0) and assigned(callback) then
|
if (dy<>0) and assigned(callback) then
|
||||||
callback.scroll(true, round(self.documentView.frame.size.height - self.documentVisibleRect.origin.y - self.documentVisibleRect.size.height));
|
callback.scroll(true, round(scrollY));
|
||||||
finally
|
finally
|
||||||
dec(holdscroll);
|
dec(holdscroll);
|
||||||
end;
|
end;
|
||||||
|
@ -2117,7 +2117,7 @@ begin
|
|||||||
lRect.Right := lRect.Right - SPINEDIT_DEFAULT_STEPPER_WIDTH;
|
lRect.Right := lRect.Right - SPINEDIT_DEFAULT_STEPPER_WIDTH;
|
||||||
lStepperRect.Left := lRect.Right;
|
lStepperRect.Left := lRect.Right;
|
||||||
svHeight := GetNSViewSuperViewHeight(Self);
|
svHeight := GetNSViewSuperViewHeight(Self);
|
||||||
if Assigned(superview) then
|
if Assigned(superview) and NOT superview.isFlipped then
|
||||||
begin
|
begin
|
||||||
LCLToNSRect(lRect, svHeight, ns);
|
LCLToNSRect(lRect, svHeight, ns);
|
||||||
LCLToNSRect(lStepperRect, svHeight, lStepperNS);
|
LCLToNSRect(lStepperRect, svHeight, lStepperNS);
|
||||||
|
@ -1482,7 +1482,8 @@ begin
|
|||||||
if FContext.InitDraw(Round(bounds.size.width), Round(bounds.size.height)) then
|
if FContext.InitDraw(Round(bounds.size.width), Round(bounds.size.height)) then
|
||||||
begin
|
begin
|
||||||
nsr:=dirty;
|
nsr:=dirty;
|
||||||
nsr.origin.y:=bounds.size.height-dirty.origin.y-dirty.size.height;
|
if NOT Owner.isKindOfClass(NSView) or NOT NSView(Owner).isFlipped then
|
||||||
|
nsr.origin.y:=bounds.size.height-dirty.origin.y-dirty.size.height;
|
||||||
|
|
||||||
if FIsOpaque and (Target.Color<>clDefault) then
|
if FIsOpaque and (Target.Color<>clDefault) then
|
||||||
begin
|
begin
|
||||||
@ -1507,13 +1508,17 @@ end;
|
|||||||
procedure TLCLCommonCallback.DrawBackground(ctx: NSGraphicsContext; const bounds, dirtyRect: NSRect);
|
procedure TLCLCommonCallback.DrawBackground(ctx: NSGraphicsContext; const bounds, dirtyRect: NSRect);
|
||||||
var
|
var
|
||||||
lTarget: TWinControl;
|
lTarget: TWinControl;
|
||||||
|
nsr:NSRect;
|
||||||
begin
|
begin
|
||||||
// Implement Color property
|
// Implement Color property
|
||||||
lTarget := TWinControl(GetTarget());
|
lTarget := TWinControl(GetTarget());
|
||||||
if (lTarget.Color <> clDefault) and (lTarget.Color <> clBtnFace) then
|
if (lTarget.Color <> clDefault) and (lTarget.Color <> clBtnFace) then
|
||||||
begin
|
begin
|
||||||
ColorToNSColor(ColorToRGB(lTarget.Color)).set_();
|
ColorToNSColor(ColorToRGB(lTarget.Color)).set_();
|
||||||
NSRectFill(dirtyRect);
|
nsr:=dirtyRect;
|
||||||
|
if NOT Owner.isKindOfClass(NSView) or NOT NSView(Owner).isFlipped then
|
||||||
|
nsr.origin.y:=bounds.size.height-dirtyRect.origin.y-dirtyRect.size.height;
|
||||||
|
NSRectFill(nsr);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1534,7 +1539,8 @@ begin
|
|||||||
if FContext.InitDraw(Round(bounds.size.width), Round(bounds.size.height)) then
|
if FContext.InitDraw(Round(bounds.size.width), Round(bounds.size.height)) then
|
||||||
begin
|
begin
|
||||||
nsr:=dirty;
|
nsr:=dirty;
|
||||||
nsr.origin.y:=bounds.size.height-dirty.origin.y-dirty.size.height;
|
if NOT Owner.isKindOfClass(NSView) or NOT NSView(Owner).isFlipped then
|
||||||
|
nsr.origin.y:=bounds.size.height-dirty.origin.y-dirty.size.height;
|
||||||
|
|
||||||
FillChar(PS, SizeOf(TPaintStruct), 0);
|
FillChar(PS, SizeOf(TPaintStruct), 0);
|
||||||
PS.hdc := HDC(FContext);
|
PS.hdc := HDC(FContext);
|
||||||
|
Loading…
Reference in New Issue
Block a user