mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-02 11:01:20 +02:00
cocoa: update in Get-SetScrollInfo for CocoaScrollView - making it documentViewRect based. Processing LMScroll messages whenever user scrolls. Removed implementation of ScrollBy in basic CocoaWSWinControl
git-svn-id: trunk@57074 -
This commit is contained in:
parent
58eefa59cd
commit
b5a54b56f0
@ -325,23 +325,26 @@ end;
|
||||
procedure NSScrollViewSetScrollInfo(sc: NSScrollView; BarFlag: Integer; const ScrollInfo: TScrollInfo);
|
||||
var
|
||||
ns : NSView;
|
||||
vr : NSRect;
|
||||
p : NSPoint;
|
||||
begin
|
||||
ns:=sc.documentView;
|
||||
if not Assigned(ns) then Exit;
|
||||
|
||||
p:=sc.documentVisibleRect.origin;
|
||||
vr:=sc.documentVisibleRect;
|
||||
if BarFlag = SB_Vert then
|
||||
begin
|
||||
//NSScrollerSetScrollInfo(ns.frame.size.height, sc.verticalScroller, ScrollInfo)
|
||||
p:=NSMakePoint(p.x, ScrollInfo.nPos);
|
||||
vr.origin.y := sc.documentView.frame.size.height - ScrollInfo.nPos - vr.size.Height;
|
||||
if vr.origin.y < 0 then vr.origin.y := 0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
//NSScrollerSetScrollInfo(ns.frame.size.width, sc.horizontalScroller, ScrollInfo);
|
||||
p:=NSMakePoint(ScrollInfo.nPos, p.y);
|
||||
vr.origin.x:=ScrollInfo.nPos;
|
||||
end;
|
||||
ns.scrollPoint(p);
|
||||
ns.scrollRectToVisible(vr);
|
||||
p:=sc.documentVisibleRect.origin;
|
||||
end;
|
||||
|
||||
function HandleToNSObject(AHWnd: HWND): id;
|
||||
|
@ -481,6 +481,11 @@ type
|
||||
public
|
||||
callback: ICommonCallback;
|
||||
isCustomRange: Boolean;
|
||||
|
||||
docrect : NSRect; // have to remember old
|
||||
holdscroll : Integer; // do not send scroll messages
|
||||
function initWithFrame(ns: NSRect): id; override;
|
||||
procedure dealloc; override;
|
||||
function acceptsFirstResponder: Boolean; override;
|
||||
function becomeFirstResponder: Boolean; override;
|
||||
function resignFirstResponder: Boolean; override;
|
||||
@ -490,6 +495,9 @@ type
|
||||
function lclIsHandle: Boolean; override;
|
||||
function lclClientFrame: TRect; override;
|
||||
function lclContentView: NSView; override;
|
||||
procedure setDocumentView(aView: NSView); override;
|
||||
procedure scrollContentViewBoundsChanged(notify: NSNotification); message 'scrollContentViewBoundsChanged:';
|
||||
procedure resetScrollRect; message 'resetScrollRect';
|
||||
end;
|
||||
|
||||
{ TCocoaManualScrollView }
|
||||
@ -1918,6 +1926,66 @@ begin
|
||||
Result:=documentView;
|
||||
end;
|
||||
|
||||
procedure TCocoaScrollView.setDocumentView(aView: NSView);
|
||||
begin
|
||||
inherited setDocumentView(aView);
|
||||
resetScrollRect;
|
||||
end;
|
||||
|
||||
procedure TCocoaScrollView.scrollContentViewBoundsChanged(notify: NSNotification
|
||||
);
|
||||
var
|
||||
nw : NSRect;
|
||||
dx,dy : CGFloat;
|
||||
begin
|
||||
if not assigned(documentView) then Exit;
|
||||
nw:=documentVisibleRect;
|
||||
|
||||
dx:=nw.origin.x-docrect.origin.x;
|
||||
dy:=docrect.origin.y-nw.origin.y; // cocoa flipped coordinates
|
||||
|
||||
docrect:=nw;
|
||||
if (dx=0) and (dy=0) then Exit;
|
||||
|
||||
if holdscroll>0 then Exit;
|
||||
inc(holdscroll);
|
||||
try
|
||||
if (dx<>0) and assigned(callback) then
|
||||
callback.scroll(false, round(nw.origin.x));
|
||||
|
||||
if (dy<>0) and assigned(callback) then
|
||||
callback.scroll(true, round(self.documentView.frame.size.height - self.documentVisibleRect.origin.y - self.documentVisibleRect.size.height));
|
||||
finally
|
||||
dec(holdscroll);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCocoaScrollView.resetScrollRect;
|
||||
begin
|
||||
docrect:=documentVisibleRect;
|
||||
end;
|
||||
|
||||
function TCocoaScrollView.initWithFrame(ns: NSRect): id;
|
||||
var
|
||||
sc : TCocoaScrollView;
|
||||
begin
|
||||
Result:=inherited initWithFrame(ns);
|
||||
sc:=TCocoaScrollView(Result);
|
||||
|
||||
//sc.contentView.setPostsBoundsChangedNotifications(true);
|
||||
NSNotificationCenter.defaultCenter
|
||||
.addObserver_selector_name_object(sc, ObjCSelector('scrollContentViewBoundsChanged:')
|
||||
,NSViewBoundsDidChangeNotification
|
||||
,sc.contentView);
|
||||
end;
|
||||
|
||||
procedure TCocoaScrollView.dealloc;
|
||||
begin
|
||||
NSNotificationCenter.defaultCenter
|
||||
.removeObserver(self);
|
||||
inherited dealloc;
|
||||
end;
|
||||
|
||||
function TCocoaScrollView.acceptsFirstResponder: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
|
@ -101,7 +101,6 @@ type
|
||||
class procedure SetChildZPosition(const AWinControl, AChild: TWinControl; const AOldPos, ANewPos: Integer; const AChildren: TFPList); override;
|
||||
class procedure ShowHide(const AWinControl: TWinControl); override;
|
||||
class procedure Invalidate(const AWinControl: TWinControl); override;
|
||||
class procedure ScrollBy(const AWinControl: TWinControl; DeltaX, DeltaY: integer); override;
|
||||
end;
|
||||
|
||||
|
||||
@ -1573,24 +1572,6 @@ begin
|
||||
NSObject(AWinControl.Handle).lclInvalidate;
|
||||
end;
|
||||
|
||||
class procedure TCocoaWSWinControl.ScrollBy(const AWinControl: TWinControl; DeltaX, DeltaY: integer);
|
||||
var
|
||||
obj: NSObject;
|
||||
p: NSPoint;
|
||||
dv, cv: NSRect;
|
||||
begin
|
||||
obj := NSObject(AWinControl.Handle);
|
||||
if obj.isKindOfClass_(NSScrollView) and
|
||||
assigned(NSScrollView(obj).documentView) then
|
||||
begin
|
||||
dv := NSRect(NSScrollView(obj).documentView.bounds);
|
||||
cv := NSRect(NSScrollView(obj).contentView.bounds);
|
||||
p.x := cv.origin.x + DeltaX;
|
||||
p.y := cv.origin.y + (dv.size.height + DeltaY) - cv.size.height;
|
||||
NSScrollview(obj).documentView.scrollPoint(p);
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TCocoaWSCustomControl }
|
||||
|
||||
class function TCocoaWSCustomControl.CreateHandle(const AWinControl: TWinControl;
|
||||
|
Loading…
Reference in New Issue
Block a user