Cocoa: Fix Vertical Scroll Bar visibility issue in TCocoaWidgetSet.GetScrollbarVisible()

details:
1. in macOS system settings, set the scroll bar to always be shown.
2. the height of DocumentView does not exceed the visual vertical size of NSScrollView, but the difference is smaller than the scroll bar size.
3. the width of DocumentView exceeds the visible horizontal size of NSScrollView.
at this time, the horizontal scroll bar is shown correctly, but the vertical scroll bar is not shown. the correct result should be that because the horizontal scroll bar occupies vertical space, a vertical scroll bar should appear.
This commit is contained in:
rich2014 2024-02-17 23:47:03 +08:00
parent 142678cee6
commit 5cb028ee29
2 changed files with 31 additions and 3 deletions

View File

@ -53,6 +53,9 @@ type
function lclClientFrame: TRect; override;
function lclContentView: NSView; override;
procedure setDocumentView(aView: NSView); override;
procedure ensureDocumentViewSizeChanged(newSize: NSSize;
ensureWidth: Boolean; ensureHeight: Boolean);
message 'ensureDocumentViewSizeChanged:newSize:ensureWidth:';
procedure scrollContentViewBoundsChanged(notify: NSNotification); message 'scrollContentViewBoundsChanged:';
procedure resetScrollData; message 'resetScrollData';
@ -666,6 +669,25 @@ begin
resetScrollData;
end;
// ensure documentView Size be changed
// setHasXxxScroller() only takes effect after documentView Size is changed
procedure TCocoaScrollView.ensureDocumentViewSizeChanged(newSize: NSSize;
ensureWidth: Boolean; ensureHeight: Boolean);
var
oldSize: NSSize;
tempSize: NSSize;
begin
oldSize:= self.documentView.frame.size;
tempSize:= newSize;
if ensureWidth and (oldSize.width=tempSize.width) then
tempSize.width:= tempSize.width + 1;
if ensureHeight and (oldSize.height=tempSize.height) then
tempSize.height:= tempSize.height + 1;
if ensureWidth or ensureHeight then
self.documentView.setFrameSize( tempSize );
self.documentView.setFrameSize( newSize );
end;
procedure TCocoaScrollView.scrollContentViewBoundsChanged(notify: NSNotification
);
var

View File

@ -1704,6 +1704,8 @@ var
documentSize : NSSize;
sizingMask : NSUInteger;
hosted: Boolean;
ensureWidth: Boolean = false;
ensureHeight: Boolean = false;
function getNewScrollPos: Integer;
var
@ -1739,8 +1741,10 @@ begin
if ScrollInfo.nMax>contentSize.width then begin
documentSize.width := ScrollInfo.nMax;
sizingMask:=sizingMask and not NSViewWidthSizable;
if (documentSize.width>contentSize.width) and Assigned(lclControl) and lclControl.HorzScrollBar.Visible then
if (documentSize.width>contentSize.width) and Assigned(lclControl) and lclControl.HorzScrollBar.Visible then begin
sc.setHasHorizontalScroller(true);
ensureHeight:= true;
end;
end else begin
documentSize.width := contentSize.width;
sizingMask:=sizingMask or NSViewWidthSizable;
@ -1749,15 +1753,17 @@ begin
if ScrollInfo.nMax>contentSize.height then begin
documentSize.height := ScrollInfo.nMax;
sizingMask:=sizingMask and not NSViewHeightSizable;
if (documentSize.height>contentSize.height) and Assigned(lclControl) and lclControl.VertScrollBar.Visible then
if (documentSize.height>contentSize.height) and Assigned(lclControl) and lclControl.VertScrollBar.Visible then begin
sc.setHasVerticalScroller(true);
ensureHeight:= true;
end;
end else begin
documentSize.height := contentSize.height;
sizingMask:=sizingMask or NSViewHeightSizable;
end;
end;
sc.documentView.setAutoresizingMask(sizingMask);
sc.documentView.setFrameSize( documentSize );
sc.ensureDocumentViewSizeChanged(documentSize, ensureWidth, ensureHeight);
// frame changed, Need to update another ScrollBar too
if SbStyle=SB_Horz then begin