diff --git a/lcl/interfaces/cocoa/cocoascrollers.pas b/lcl/interfaces/cocoa/cocoascrollers.pas index d0220862a8..4c5cf37b21 100644 --- a/lcl/interfaces/cocoa/cocoascrollers.pas +++ b/lcl/interfaces/cocoa/cocoascrollers.pas @@ -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 diff --git a/lcl/interfaces/cocoa/cocoawinapi.inc b/lcl/interfaces/cocoa/cocoawinapi.inc index 8013af2e2f..18cfe177f2 100644 --- a/lcl/interfaces/cocoa/cocoawinapi.inc +++ b/lcl/interfaces/cocoa/cocoawinapi.inc @@ -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