Cocoa: fix #40853, Merge branch 'cocoa/scroll'

This commit is contained in:
rich2014 2024-03-17 22:23:54 +08:00
commit adc486abd0
5 changed files with 292 additions and 205 deletions

View File

@ -250,10 +250,6 @@ var
function CocoaScrollBarSetScrollInfo(bar: TCocoaScrollBar; const ScrollInfo: TScrollInfo): Integer;
function CocoaScrollBarGetScrollInfo(bar: TCocoaScrollBar; var ScrollInfo: TScrollInfo): Boolean;
procedure NSScrollerGetScrollInfo(docSz, pageSz: CGFloat; rl: NSSCroller; Var ScrollInfo: TScrollInfo);
procedure NSScrollViewGetScrollInfo(sc: NSScrollView; BarFlag: Integer; Var ScrollInfo: TScrollInfo);
procedure NSScrollerSetScrollInfo(docSz, pageSz: CGFloat; rl: NSSCroller; const ScrollInfo: TScrollInfo);
procedure NSScrollViewSetScrollPos(sc: NSScrollView; BarFlag: Integer; const ScrollInfo: TScrollInfo);
function CocoaPromptUser(const DialogCaption, DialogMessage: String;
DialogType: longint; Buttons: PLongint; ButtonCount, DefaultIndex,
@ -414,76 +410,6 @@ begin
Result:=true;
end;
procedure NSScrollerGetScrollInfo(docSz, pageSz: CGFloat; rl: NSSCroller; Var ScrollInfo: TScrollInfo);
begin
ScrollInfo.cbSize:=sizeof(ScrollInfo);
ScrollInfo.fMask:=SIF_ALL;
ScrollInfo.nPos:=round(rl.floatValue*(docSz-pageSz));
ScrollInfo.nTrackPos:=ScrollInfo.nPos;
ScrollInfo.nMin:=0;
ScrollInfo.nMax:=round(docSz);
ScrollInfo.nPage:=round(rl.knobProportion*docSz);
end;
procedure NSScrollViewGetScrollInfo(sc: NSScrollView; BarFlag: Integer; Var ScrollInfo: TScrollInfo);
var
ns : NSView;
vr : NSRect;
begin
ns:=sc.documentView;
if not Assigned(ns) then begin
FillChar(ScrollInfo, sizeof(ScrollInfo),0);
ScrollInfo.cbSize:=sizeof(ScrollInfo);
Exit;
end;
vr:=sc.documentVisibleRect;
if BarFlag = SB_Vert then
NSScrollerGetScrollInfo(ns.frame.size.height, vr.size.height, sc.verticalScroller, ScrollInfo)
else
NSScrollerGetScrollInfo(ns.frame.size.width, vr.size.width, sc.horizontalScroller, ScrollInfo);
end;
procedure NSScrollerSetScrollInfo(docSz, pageSz: CGFloat; rl: NSSCroller; const ScrollInfo: TScrollInfo);
var
sz : CGFloat;
begin
if ScrollInfo.fMask and SIF_POS>0 then begin
sz:=docSz-pageSz;
if sz=0 then rl.setFloatValue(0)
else rl.setFloatValue(ScrollInfo.nPos/sz);
end;
if ScrollInfo.fMask and SIF_PAGE>0 then begin
sz:=docSz-pageSz;
if sz=0 then rl.setKnobProportion(1)
else rl.setKnobProportion(1/sz);
end;
end;
procedure NSScrollViewSetScrollPos(sc: NSScrollView; BarFlag: Integer; const ScrollInfo: TScrollInfo);
var
ns : NSView;
vr : NSRect;
begin
ns:=sc.documentView;
if not Assigned(ns) then Exit;
vr:=sc.documentVisibleRect;
if BarFlag = SB_Vert then
begin
//NSScrollerSetScrollInfo(ns.frame.size.height, sc.verticalScroller, ScrollInfo)
if not sc.documentView.isFlipped then
vr.origin.y := sc.documentView.frame.size.height - ScrollInfo.nPos - vr.size.Height
else
vr.origin.y := ScrollInfo.nPos;
end
else
begin
//NSScrollerSetScrollInfo(ns.frame.size.width, sc.horizontalScroller, ScrollInfo);
vr.origin.x:=ScrollInfo.nPos;
end;
ns.scrollRectToVisible(vr);
end;
{ TModalSession }
constructor TModalSession.Create(awin: NSWindow; asess: NSModalSession;

View File

@ -24,7 +24,7 @@ interface
uses
// rtl+ftl
Math, Classes, SysUtils,
Math, Classes, SysUtils, LclType,
// Libs
MacOSAll, CocoaAll, CocoaUtils, CocoaPrivate;
@ -36,8 +36,14 @@ type
callback: ICommonCallback;
isCustomRange: Boolean;
// the corresponding LCL ScrollInfo,
// which are needed when documentView.frame changes.
lclHoriScrollInfo: TScrollInfo;
lclVertScrollInfo: TScrollInfo;
docrect : NSRect; // have to remember old
holdscroll : Integer; // do not send scroll messages
function initWithFrame(ns: NSRect): id; override;
procedure dealloc; override;
procedure setFrame(aframe: NSRect); override;
@ -47,12 +53,19 @@ type
function lclClientFrame: TRect; override;
function lclContentView: NSView; override;
procedure setDocumentView(aView: NSView); override;
procedure scrollWheel(theEvent: NSEvent); override;
procedure ensureDocumentViewSizeChanged(newSize: NSSize;
ensureWidth: Boolean; ensureHeight: Boolean);
message 'ensureDocumentViewSizeChanged:newSize:ensureWidth:';
procedure scrollContentViewBoundsChanged(notify: NSNotification); message 'scrollContentViewBoundsChanged:';
procedure resetScrollRect; message 'resetScrollRect';
procedure resetScrollData; message 'resetScrollData';
procedure lclUpdate; override;
procedure lclInvalidateRect(const r: TRect); override;
procedure lclInvalidate; override;
procedure fillScrollInfo(barFlag: Integer; var scrollInfo: TScrollInfo); message 'fillScrollInfo:barFlag:';
procedure applyScrollInfo(barFlag: Integer; const scrollInfo: TScrollInfo); message 'applyScrollInfo:barFlag:';
end;
{ TCocoaManualScrollView }
@ -133,6 +146,7 @@ type
function lclContentView: NSView; override;
function lclClientFrame: TRect; override;
procedure scrollWheel(theEvent: NSEvent); override;
procedure setFrame(newValue: NSRect); override;
end;
function isMouseEventInScrollBar(host: TCocoaManualScrollView; event: NSEvent): Boolean;
@ -294,6 +308,86 @@ begin
end;
end;
procedure allocScroller(parent: TCocoaManualScrollView; var sc: NSScroller; dst: NSRect; aVisible: Boolean);
begin
sc:=TCocoaScrollBar(TCocoaScrollBar.alloc).initWithFrame(dst);
parent.addSubview(sc);
{$ifdef BOOLFIX}
sc.setEnabled_(Ord(true));
sc.setHidden_(Ord(not AVisible));
{$else}
sc.setEnabled(true);
sc.setHidden(not AVisible);
{$endif}
TCocoaScrollBar(sc).preventBlock := true;
//Suppress scrollers notifications.
TCocoaScrollBar(sc).callback := parent.callback;
TCocoaScrollBar(sc).suppressLCLMouse := true;
sc.setTarget(sc);
sc.setAction(objcselector('actionScrolling:'));
end;
procedure updateDocSize(parent: NSView; doc: NSView; hScroller, vScroller: NSScroller);
var
docFrame : NSRect;
hScrollerFrame : NSRect;
vScrollerFrame : NSRect;
hScrollerHeight : CGFLoat;
vScrollerWidth : CGFLoat;
begin
if not Assigned(parent) or not Assigned(doc) then
Exit;
docFrame := parent.frame;
docFrame.origin := NSZeroPoint;
hScrollerFrame := docFrame;
vScrollerFrame := docFrame;
if Assigned(hScroller) and (not hScroller.isHidden) then
begin
hScrollerHeight := NSScroller.scrollerWidthForControlSize_scrollerStyle(
hScroller.controlSize, hScroller.preferredScrollerStyle);
hScrollerFrame.size.height := hScrollerHeight;
docFrame.size.height := docFrame.size.height - hScrollerHeight;
if docFrame.size.height < 0 then
docFrame.size.height := 0;
docFrame.origin.y := hScrollerHeight;
end;
if Assigned(vScroller) and (not vScroller.isHidden) then
begin
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 Assigned(hScroller) then
hScroller.setFrame(hScrollerFrame);
if Assigned(vScroller) then
vScroller.setFrame(vScrollerFrame);
if not NSEqualRects(doc.frame, docFrame) then
begin
doc.setFrame(docFrame);
{$ifdef BOOLFIX}
doc.setNeedsDisplay__(Ord(true));
{$else}
doc.setNeedsDisplay_(true);
{$endif}
end;
end;
{ TCocoaManualScrollHost }
function TCocoaManualScrollHost.lclContentView: NSView;
@ -323,6 +417,16 @@ begin
else inherited scrollWheel(theEvent);
end;
procedure TCocoaManualScrollHost.setFrame(newValue: NSRect);
var
sc: TCocoaManualScrollView;
begin
inherited setFrame(newValue);
sc:= TCocoaManualScrollView(self.documentView);
sc.setFrame(newValue);
updateDocSize(sc, sc.documentView, sc.horizontalScroller, sc.verticalScroller);
end;
{ TCocoaManualScrollView }
procedure TCocoaManualScrollView.dealloc;
@ -401,87 +505,6 @@ begin
Result:=fdocumentView;
end;
procedure allocScroller(parent: TCocoaManualScrollView; var sc: NSScroller; dst: NSRect; aVisible: Boolean);
begin
sc:=TCocoaScrollBar(TCocoaScrollBar.alloc).initWithFrame(dst);
parent.addSubview(sc);
{$ifdef BOOLFIX}
sc.setEnabled_(Ord(true));
sc.setHidden_(Ord(not AVisible));
{$else}
sc.setEnabled(true);
sc.setHidden(not AVisible);
{$endif}
TCocoaScrollBar(sc).preventBlock := true;
//Suppress scrollers notifications.
TCocoaScrollBar(sc).callback := parent.callback;
TCocoaScrollBar(sc).suppressLCLMouse := true;
sc.setTarget(sc);
sc.setAction(objcselector('actionScrolling:'));
end;
procedure updateDocSize(parent: NSView; doc: NSView; hScroller, vScroller: NSScroller);
var
docFrame : NSRect;
hScrollerFrame : NSRect;
vScrollerFrame : NSRect;
hScrollerHeight : CGFLoat;
vScrollerWidth : CGFLoat;
begin
if not Assigned(parent) or not Assigned(doc) then
Exit;
docFrame := parent.frame;
docFrame.origin := NSZeroPoint;
hScrollerFrame := docFrame;
vScrollerFrame := docFrame;
if Assigned(hScroller) and (not hScroller.isHidden) then
begin
hScrollerHeight := NSScroller.scrollerWidthForControlSize_scrollerStyle(
hScroller.controlSize, hScroller.preferredScrollerStyle);
hScrollerFrame.size.height := hScrollerHeight;
docFrame.size.height := docFrame.size.height - hScrollerHeight;
if docFrame.size.height < 0 then
docFrame.size.height := 0;
docFrame.origin.y := hScrollerHeight;
end;
if Assigned(vScroller) and (not vScroller.isHidden) then
begin
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 Assigned(hScroller) then
hScroller.setFrame(hScrollerFrame);
if Assigned(vScroller) then
vScroller.setFrame(vScrollerFrame);
if not NSEqualRects(doc.frame, docFrame) then
begin
doc.setFrame(docFrame);
{$ifdef BOOLFIX}
doc.setNeedsDisplay__(Ord(true));
{$else}
doc.setNeedsDisplay_(true);
{$endif}
end;
end;
procedure TCocoaManualScrollView.setHasVerticalScroller(doshow: Boolean);
begin
if doshow then
@ -644,7 +667,26 @@ end;
procedure TCocoaScrollView.setDocumentView(aView: NSView);
begin
inherited setDocumentView(aView);
resetScrollRect;
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
@ -679,9 +721,21 @@ begin
end;
end;
procedure TCocoaScrollView.resetScrollRect;
procedure TCocoaScrollView.resetScrollData;
begin
docrect:=documentVisibleRect;
lclHoriScrollInfo.fMask:= 0;
lclVertScrollInfo.fMask:= 0;
end;
procedure TCocoaScrollView.scrollWheel(theEvent: NSEvent);
begin
if self.hasHorizontalScroller or self.hasVerticalScroller then
inherited scrollWheel( theEvent )
else if Assigned(self.enclosingScrollView) then
self.enclosingScrollView.scrollWheel( theEvent )
else
inherited scrollWheel( theEvent );
end;
procedure TCocoaScrollView.lclUpdate;
@ -699,6 +753,61 @@ begin
documentView.lclInvalidate;
end;
procedure TCocoaScrollView.fillScrollInfo(barFlag: Integer;
var scrollInfo: TScrollInfo);
var
docSize: NSSize;
procedure fillScrollerScrollInfo(maxValue: CGFloat; pageValue: CGFloat;
scroller: NSScroller);
begin
scrollInfo.cbSize:=sizeof(scrollInfo);
scrollInfo.fMask:=SIF_ALL;
scrollInfo.nPos:=round(scroller.doubleValue*(maxValue-pageValue));
scrollInfo.nTrackPos:=ScrollInfo.nPos;
scrollInfo.nMin:=0;
scrollInfo.nMax:=round(maxValue);
scrollInfo.nPage:=round(scroller.knobProportion*maxValue);
end;
begin
if not Assigned(self.documentView) then begin
FillChar(scrollInfo, sizeof(scrollInfo),0);
scrollInfo.cbSize:=sizeof(scrollInfo);
Exit;
end;
docSize:= self.documentView.frame.size;
if barFlag = SB_Vert then
fillScrollerScrollInfo(docSize.height, self.contentSize.height, self.verticalScroller)
else
fillScrollerScrollInfo(docSize.width, self.contentSize.width, self.horizontalScroller);
end;
procedure TCocoaScrollView.applyScrollInfo(barFlag: Integer;
const scrollInfo: TScrollInfo);
var
newOrigin : NSPoint;
begin
if not Assigned(self.documentView) then Exit;
newOrigin:= self.contentView.bounds.origin;
if BarFlag = SB_Vert then
begin
self.lclVertScrollInfo:= scrollInfo;
if not self.documentView.isFlipped then
newOrigin.y := self.documentView.frame.size.height - scrollInfo.nPos - self.contentSize.height
else
newOrigin.y := scrollInfo.nPos;
end
else
begin
self.lclHoriScrollInfo:= scrollInfo;
newOrigin.x:= scrollInfo.nPos;
end;
self.contentView.setBoundsOrigin( newOrigin );
end;
function TCocoaScrollView.initWithFrame(ns: NSRect): id;
var
sc : TCocoaScrollView;
@ -829,7 +938,7 @@ end;
function TCocoaScrollBar.lclPos: Integer;
begin
Result:=round( floatValue * (maxint-minInt-pageInt)) + minInt;
Result:=round( doubleValue * (maxint-minInt-pageInt)) + minInt;
end;
procedure TCocoaScrollBar.lclSetPos(aPos: integer);

View File

@ -1571,20 +1571,22 @@ begin
begin
sc := NSScrollView(obj);
case SBStyle of
SB_Vert: Result := sc.hasVerticalScroller;
SB_Horz: Result := sc.hasHorizontalScroller;
SB_Vert: Result := sc.hasVerticalScroller and not sc.verticalScroller.isHidden;
SB_Horz: Result := sc.hasHorizontalScroller and not sc.horizontalScroller.isHidden;
else
Result := sc.hasHorizontalScroller and sc.hasVerticalScroller;
Result := sc.hasHorizontalScroller and not sc.horizontalScroller.isHidden
and sc.hasVerticalScroller and not sc.verticalScroller.isHidden;
end;
end
else if obj.isKindOfClass(TCocoaManualScrollView) then
begin
mn := TCocoaManualScrollView(obj);
case SBStyle of
SB_Vert: Result := mn.hasVerticalScroller;
SB_Horz: Result := mn.hasHorizontalScroller;
SB_Vert: Result := mn.hasVerticalScroller and not mn.verticalScroller.isHidden;
SB_Horz: Result := mn.hasHorizontalScroller and not mn.horizontalScroller.isHidden;
else
Result := mn.hasHorizontalScroller and mn.hasVerticalScroller;
Result := mn.hasHorizontalScroller and not mn.horizontalScroller.isHidden
and mn.hasVerticalScroller and not mn.verticalScroller.isHidden;
end;
end
else
@ -1605,16 +1607,16 @@ begin
obj := TCocoaManualScrollHost(obj).documentView;
if obj.isKindOfClass(TCocoaScrollBar) then
Result := CocoaScrollBarGetScrollInfo(TCocoaScrollBar(obj), ScrollInfo)
Result := CocoaScrollBarGetScrollInfo(TCocoaScrollBar(obj), scrollInfo)
else
if obj.isKindOfClass(TCocoaManualScrollView) then
begin
if BarFlag = SB_Vert then
Result := CocoaScrollBarGetScrollInfo( TCocoaScrollBar(TCocoaManualScrollView(obj).verticalScroller), ScrollInfo)
Result := CocoaScrollBarGetScrollInfo( TCocoaScrollBar(TCocoaManualScrollView(obj).verticalScroller), scrollInfo)
else
Result := CocoaScrollBarGetScrollInfo( TCocoaScrollBar(TCocoaManualScrollView(obj).horizontalScroller), ScrollInfo);
end else if obj.isKindOfClass(NSScrollView) then
NSScrollViewGetScrollInfo(NSScrollView(obj), BarFlag, ScrollInfo)
Result := CocoaScrollBarGetScrollInfo( TCocoaScrollBar(TCocoaManualScrollView(obj).horizontalScroller), scrollInfo);
end else if obj.isKindOfClass(TCocoaScrollView) then
TCocoaScrollView(obj).fillScrollInfo(BarFlag, scrollInfo)
else
Result := False;
end;
@ -1694,14 +1696,25 @@ end;
function TCocoaWidgetSet.SetScrollInfo(Handle : HWND; SBStyle : Integer; ScrollInfo: TScrollInfo; bRedraw : Boolean): Integer;
var
si : TScrollInfo;
obj : NSObject;
sc : TCocoaScrollView;
lclControl: TScrollingWinControl;
bar : TCocoaScrollBar;
f : NSSize;
sz : NSSize;
flg : NSUInteger;
contentSize : NSSize;
documentSize : NSSize;
sizingMask : NSUInteger;
hosted: Boolean;
ensureWidth: Boolean = false;
ensureHeight: Boolean = false;
function getNewScrollPos: Integer;
var
si: TScrollInfo;
begin
sc.fillScrollInfo(SBStyle, si);
Result:=si.nPos;
end;
begin
obj := NSObject(Handle);
Result := 0;
@ -1717,38 +1730,55 @@ begin
if obj.isKindOfClass(TCocoaScrollView) then
begin
sc:=TCocoaScrollView(obj);
if sc.lclGetTarget is TScrollingWinControl then
lclControl:=TScrollingWinControl(sc.lclGetTarget);
if sc.isCustomRange and (ScrollInfo.fMask and SIF_RANGE>0) then begin
f:=sc.frame.size;
sz:=NSView(sc.documentView).frame.size; // type casting is here for the compiler. for i386 it messes up types
flg:=sc.documentView.autoresizingMask;
contentSize:=sc.contentSize;
documentSize:=NSView(sc.documentView).frame.size; // type casting is here for the compiler. for i386 it messes up types
sizingMask:=sc.documentView.autoresizingMask;
if SBStyle=SB_Horz then begin
if ScrollInfo.nMax>f.width then begin
sz.width := ScrollInfo.nMax;
flg:=flg and not NSViewWidthSizable;
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 begin
sc.setHasHorizontalScroller(true);
ensureHeight:= true;
end;
end else begin
sz.width := f.width;
flg:=flg or NSViewWidthSizable;
documentSize.width := contentSize.width;
sizingMask:=sizingMask or NSViewWidthSizable;
end;
end else if SBStyle=SB_Vert then begin
if ScrollInfo.nMax>f.height then begin
sz.height := ScrollInfo.nMax;
flg:=flg and not NSViewHeightSizable;
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 begin
sc.setHasVerticalScroller(true);
ensureHeight:= true;
end;
end else begin
sz.height := f.height;
flg:=flg or NSViewHeightSizable;
documentSize.height := contentSize.height;
sizingMask:=sizingMask or NSViewHeightSizable;
end;
end;
sc.documentView.setAutoresizingMask(flg);
sc.documentView.setFrameSize( sz );
sc.documentView.setAutoresizingMask(sizingMask);
sc.ensureDocumentViewSizeChanged(documentSize, ensureWidth, ensureHeight);
// frame changed, Need to update another ScrollBar too
if SbStyle=SB_Horz then begin
if sc.lclVertScrollInfo.fMask<>0 then
sc.applyScrollInfo(SB_Vert, sc.lclVertScrollInfo)
end else begin
if sc.lclHoriScrollInfo.fMask<>0 then
sc.applyScrollInfo(SB_Horz, sc.lclHoriScrollInfo);
end;
end;
// if frame changed, another ScrollBar has been updated
if ScrollInfo.fMask and SIF_ALL > 0 then
NSScrollViewSetScrollPos(NSScrollView(obj), SBStyle, ScrollInfo);
FillChar(si, sizeof(si), 0);
si.cbSize:=sizeof(si);
NSScrollViewGetScrollInfo(NSScrollView(obj), SBStyle, si);
Result:=si.nPos;
sc.applyScrollInfo(SBStyle, ScrollInfo);
Result:= getNewScrollPos();
end else if obj.isKindOfClass(TCocoaManualScrollView) then
begin
bar:=nil;

View File

@ -287,6 +287,7 @@ begin
p := AView.superview;
p.setAutoresizingMask( NSViewWidthSizable or NSViewHeightSizable);
Result := TCocoaManualScrollView.alloc.initWithFrame(NSNullRect);
Result.setAutoresizesSubviews(false);
if Assigned(p) then p.addSubView(Result);
Result.lclSetFrame(r);
{$ifdef BOOLFIX}
@ -326,7 +327,7 @@ begin
{$endif}
Result.setDocumentView(AView);
Result.setDrawsBackground(false); // everything is covered anyway
Result.contentView.setAutoresizesSubviews(true);
Result.contentView.setAutoresizesSubviews(false);
AView.setAutoresizingMask(NSViewWidthSizable or NSViewHeightSizable);
AView.release;

View File

@ -199,6 +199,9 @@ implementation
uses
GraphMath;
type
TControlScrollBarAccess = class(TControlScrollBar);
const
// The documentation is using constants like "NSNormalWindowLevel=4" for normal forms,
// however, these are macros of a function call to CGWindowLevelKey()
@ -535,21 +538,23 @@ var
docview: TCocoaCustomControl;
lcl : TLCLCommonCallback;
begin
docview := TCocoaCustomControl.alloc.lclInitWithCreateParams(AParams);
scrollcon:=EmbedInScrollView(docView);
scrollcon:= TCocoaScrollView.alloc.lclInitWithCreateParams(AParams);
ScrollViewSetBorderStyle(scrollcon, TScrollingWinControl(AWincontrol).BorderStyle);
scrollcon.setDrawsBackground(false); // everything is covered anyway
scrollcon.setBackgroundColor(NSColor.windowBackgroundColor);
scrollcon.setAutohidesScrollers(True);
scrollcon.setHasHorizontalScroller(True);
scrollcon.setHasVerticalScroller(True);
scrollcon.isCustomRange := true;
docview:= TCocoaCustomControl.alloc.init;
docview.setFrameSize( scrollcon.contentSize );
scrollcon.setDocumentView(docview);
lcl := TLCLCommonCallback.Create(docview, AWinControl, scrollcon);
lcl.BlockCocoaUpDown := true;
scrollcon.callback := lcl;
docview.callback := lcl;
docview.setAutoresizingMask(NSViewWidthSizable or NSViewHeightSizable);
scrollcon.callback := lcl;
scrollcon.setDocumentView(docview);
ScrollViewSetBorderStyle(scrollcon, TScrollingWinControl(AWincontrol).BorderStyle);
Result := TLCLHandle(scrollcon);
end;
@ -697,6 +702,22 @@ begin
Result := TCocoaWindow(TCocoaWindow.alloc);
end;
function hasScrollBar(AScrollBar: TControlScrollBar): Boolean; inline;
begin
Result:= TControlScrollBarAccess(AScrollBar).ScrollBarShouldBeVisible;
end;
function hasHorzScrollBar(AWinControl: TWinControl): Boolean; inline;
begin
Result:= hasScrollBar( TScrollingWinControl(AWinControl).HorzScrollBar );
end;
function hasVertScrollBar(AWinControl: TWinControl): Boolean; inline;
begin
Result:= hasScrollBar( TScrollingWinControl(AWinControl).VertScrollBar );
end;
class function TCocoaWSCustomForm.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
@ -732,8 +753,8 @@ begin
cnt.wincallback := cb;
cnt.isCustomRange := true;
cnt.setHasHorizontalScroller(True);
cnt.setHasVerticalScroller(True);
cnt.setHasHorizontalScroller( hasHorzScrollBar(AWinControl) );
cnt.setHasVerticalScroller( hasVertScrollBar(AWinControl) );
cnt.setVerticalScrollElasticity(NSScrollElasticityNone);
cnt.setHorizontalScrollElasticity(NSScrollElasticityNone);
cnt.setDocumentView(doc);