Cocoa/Scroller: fix issues, Merge branch 'cocoa/scroller'

This commit is contained in:
rich2014 2023-12-17 18:13:13 +08:00
parent 1666b45e46
commit a3b1df19bb
2 changed files with 52 additions and 62 deletions

View File

@ -421,52 +421,59 @@ begin
end;
procedure updateDocSize(parent: NSView; doc: NSView; hrz, vrt: NSScroller);
procedure updateDocSize(parent: NSView; doc: NSView; hScroller, vScroller: NSScroller);
var
f : NSRect;
hr : NSRect;
vr : NSRect;
hw : CGFLoat;
vw : CGFLoat;
docFrame : NSRect;
hScrollerFrame : NSRect;
vScrollerFrame : NSRect;
hScrollerHeight : CGFLoat;
vScrollerWidth : CGFLoat;
begin
if not Assigned(parent) or not Assigned(doc) then Exit;
if not Assigned(parent) or not Assigned(doc) then
Exit;
f := parent.frame;
f.origin.x := 0;
f.origin.y := 0;
hr := f;
vr := f;
hw := NSScroller.scrollerWidthForControlSize_scrollerStyle(
hrz.controlSize, hrz.preferredScrollerStyle);
vw := NSScroller.scrollerWidthForControlSize_scrollerStyle(
vrt.controlSize, vrt.preferredScrollerStyle);
vr.size.width:=vw;
vr.origin.x:=f.size.width-vr.size.width;
hr.size.height:=hw;
docFrame := parent.frame;
docFrame.origin := NSZeroPoint;
hScrollerFrame := docFrame;
vScrollerFrame := docFrame;
if Assigned(hrz) and (not hrz.isHidden) then
if Assigned(hScroller) and (not hScroller.isHidden) then
begin
f.size.height := f.size.height - hw;
f.origin.y := hw;
hScrollerHeight := NSScroller.scrollerWidthForControlSize_scrollerStyle(
hScroller.controlSize, hScroller.preferredScrollerStyle);
hScrollerFrame.size.height := hScrollerHeight;
vr.origin.y := hw;
vr.size.height := vr.size.height - hw;
if Assigned(vrt) and (not vrt.isHidden) then
hr.size.width:=hr.size.width-vw;
hrz.setFrame(hr);
docFrame.size.height := docFrame.size.height - hScrollerHeight;
if docFrame.size.height < 0 then
docFrame.size.height := 0;
docFrame.origin.y := hScrollerHeight;
end;
if Assigned(vrt) and (not vrt.isHidden) then
if Assigned(vScroller) and (not vScroller.isHidden) then
begin
f.size.width := f.size.width-vw;
vrt.setFrame(vr);
vScrollerWidth := NSScroller.scrollerWidthForControlSize_scrollerStyle(
vScroller.controlSize, vScroller.preferredScrollerStyle);
vScrollerFrame.size.width := vScrollerWidth;
docFrame.size.width := docFrame.size.width - vScrollerWidth;
if docFrame.size.width < 0 then
docFrame.size.width:= 0;
end;
hScrollerFrame.size.width := docFrame.size.width;
vScrollerFrame.size.height := docFrame.size.height;
vScrollerFrame.origin.x := docFrame.size.width;
vScrollerFrame.origin.y := docFrame.origin.y;
if not NSEqualRects(doc.frame, f) then
if Assigned(hScroller) then
hScroller.setFrame(hScrollerFrame);
if Assigned(vScroller) then
vScroller.setFrame(vScrollerFrame);
if not NSEqualRects(doc.frame, docFrame) then
begin
doc.setFrame(f);
doc.setFrame(docFrame);
{$ifdef BOOLFIX}
doc.setNeedsDisplay__(Ord(true));
{$else}
@ -476,17 +483,11 @@ begin
end;
procedure TCocoaManualScrollView.setHasVerticalScroller(doshow: Boolean);
var
ch : Boolean;
begin
ch := false;
if doshow then
begin
if not Assigned(fvscroll) then
begin
fvscroll := allocVerticalScroller(true);
ch := true;
end;
if fvscroll.isHidden then
begin
@ -495,7 +496,6 @@ begin
{$else}
fvscroll.setHidden(false);
{$endif}
ch := true;
end;
end
else if Assigned(fvscroll) and not fvscroll.isHidden then
@ -505,27 +505,18 @@ begin
{$else}
fvscroll.setHidden(true);
{$endif}
ch := true;
end;
if ch then
updateDocSize(self, fdocumentView, fhscroll, fvscroll);
updateDocSize(self, fdocumentView, fhscroll, fvscroll);
end;
procedure TCocoaManualScrollView.setHasHorizontalScroller(doshow: Boolean);
var
r : NSRect;
f : NSRect;
ch : Boolean;
begin
f:=frame;
ch:=false;
if doshow then
begin
if not Assigned(fhscroll) then
begin
fhscroll := allocHorizontalScroller(true);
ch := true;
end;
if fhscroll.isHidden then
begin
{$ifdef BOOLFIX}
@ -533,7 +524,6 @@ begin
{$else}
fhscroll.setHidden(false);
{$endif}
ch := true;
end;
end
else if Assigned(fhscroll) and (not fhscroll.isHidden) then
@ -543,11 +533,9 @@ begin
{$else}
fhscroll.setHidden(true);
{$endif}
ch := true;
end;
if ch then
updateDocSize(self, fdocumentView, fhscroll, fvscroll);
updateDocSize(self, fdocumentView, fhscroll, fvscroll);
end;
function TCocoaManualScrollView.hasVerticalScroller: Boolean;
@ -581,7 +569,8 @@ begin
else
begin
f := frame;
w := NSScroller.scrollerWidth;
w := NSScroller.scrollerWidthForControlSize_scrollerStyle(
fhscroll.controlSize, fhscroll.preferredScrollerStyle);
r := NSMakeRect(0, 0, Max(f.size.width,w+1), w); // width<height to create a horizontal scroller
allocScroller( self, fhscroll, r, avisible);
fhscroll.setAutoresizingMask(NSViewWidthSizable);
@ -600,7 +589,8 @@ begin
else
begin
f := frame;
w := NSScroller.scrollerWidth;
w := NSScroller.scrollerWidthForControlSize_scrollerStyle(
fvscroll.controlSize, fvscroll.preferredScrollerStyle);
r := NSMakeRect(0, 0, w, Max(f.size.height,w+1)); // height<width to create a vertical scroller
allocScroller( self, fvscroll, r, avisible);
fvscroll.setAutoresizingMask(NSViewHeightSizable or NSViewMinXMargin);

View File

@ -1548,10 +1548,10 @@ begin
else if (BarKind = SB_Horz) and Assigned(NSScrollView(obj).horizontalScroller) then
Result:=round(NSScrollView(obj).verticalScroller.frame.size.height)
else
Result := Round(NSScroller.scrollerWidth);
Result := GetSystemMetrics(SM_CXVSCROLL);
end
else
Result := Round(NSScroller.scrollerWidth);
Result := GetSystemMetrics(SM_CXVSCROLL);
end;
function TCocoaWidgetSet.GetScrollbarVisible(Handle: HWND; SBStyle: Integer): boolean;
@ -2601,7 +2601,7 @@ begin
SM_CYHSCROLL,
SM_CXVSCROLL,
SM_CYVSCROLL:
Result := Round(NSScroller.scrollerWidthForControlSize(NSRegularControlSize));
Result := Round(NSScroller.scrollerWidthForControlSize_scrollerStyle(NSRegularControlSize, NSScrollerStyleLegacy));
SM_CXSCREEN,
SM_CXFULLSCREEN:
Result := Round(NSPrimaryScreenFrame.size.width);
@ -2631,7 +2631,7 @@ begin
end;
SM_CXDRAG,SM_CYDRAG: Result := 5;
SM_CXHTHUMB, SM_CYVTHUMB:
Result := Round(NSScroller.scrollerWidthForControlSize(NSRegularControlSize));
Result := Round(NSScroller.scrollerWidthForControlSize_scrollerStyle(NSRegularControlSize, NSScrollerStyleLegacy));
SM_SWSCROLLBARSPACING:
Result := 0;
SM_LCLHasFormAlphaBlend: