mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-09 01:28:19 +02:00
Cocoa: fix #40853 again, Merge branch 'cocoa/scroll'
This commit is contained in:
commit
af9ab99be9
@ -34,7 +34,8 @@ uses
|
||||
MacOSAll,
|
||||
// private
|
||||
CocoaAll, CocoaConst, CocoaConfig, CocoaPrivate, CocoaUtils, Cocoa_Extra,
|
||||
CocoaGDIObjects, CocoaCursor, CocoaMenus, CocoaWindows, CocoaScrollers,
|
||||
CocoaGDIObjects, CocoaCursor, CocoaMenus, CocoaWindows,
|
||||
CocoaScrollers, CocoaWSScrollers,
|
||||
CocoaWSClipboard, CocoaTextEdits,
|
||||
// LCL
|
||||
LMessages, LCLProc, LCLIntf, LCLType,
|
||||
@ -122,6 +123,7 @@ type
|
||||
FNSApp_Delegate: TAppDelegate;
|
||||
FCaptureControl: HWND;
|
||||
FWaitingDropFiles: NSMutableArray;
|
||||
FSendingScrollWheelCount: Integer;
|
||||
|
||||
protected
|
||||
FStockNullBrush: HBRUSH;
|
||||
@ -154,6 +156,8 @@ type
|
||||
function nextEvent(const eventExpDate: NSDate): NSEvent;
|
||||
function nextEventBeforeRunLoop(const eventExpDate: NSDate): NSEvent;
|
||||
|
||||
function isSendingScrollWheelFromInterface(): Boolean;
|
||||
|
||||
procedure SyncClipboard();
|
||||
procedure DropWaitingFiles;
|
||||
procedure DropFiles(filenames: NSArray);
|
||||
|
@ -29,7 +29,7 @@ interface
|
||||
|
||||
uses
|
||||
// rtl+ftl
|
||||
Types, Classes, SysUtils,
|
||||
Types, Classes, SysUtils, LazLoggerBase, Forms,
|
||||
// Libs
|
||||
MacOSAll, CocoaAll, CocoaUtils, CocoaGDIObjects, CocoaCursor,
|
||||
cocoa_extra,
|
||||
@ -897,8 +897,14 @@ end;
|
||||
|
||||
procedure TCocoaCustomControl.scrollWheel(event: NSEvent);
|
||||
begin
|
||||
if not Assigned(callback) or not callback.scrollWheel(event) then
|
||||
if Assigned(self.lclGetTarget) and (self.lclGetTarget is TScrollingWinControl) then begin
|
||||
inherited scrollWheel(event);
|
||||
if Assigned(callback) then
|
||||
callback.scrollWheel(event);
|
||||
end else begin
|
||||
if NOT Assigned(callback) or NOT callback.scrollWheel(event) then
|
||||
inherited scrollWheel(event);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCocoaCustomControl.setFrame(aframe: NSRect);
|
||||
|
@ -26,6 +26,7 @@ uses
|
||||
// rtl+ftl
|
||||
Math, Classes, SysUtils, LclType,
|
||||
// Libs
|
||||
Controls, Forms,
|
||||
MacOSAll, CocoaAll, CocoaUtils, CocoaPrivate;
|
||||
|
||||
type
|
||||
@ -44,7 +45,6 @@ type
|
||||
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;
|
||||
function acceptsFirstResponder: LCLObjCBoolean; override;
|
||||
@ -57,7 +57,6 @@ type
|
||||
procedure ensureDocumentViewSizeChanged(newSize: NSSize;
|
||||
ensureWidth: Boolean; ensureHeight: Boolean);
|
||||
message 'ensureDocumentViewSizeChanged:newSize:ensureWidth:';
|
||||
procedure scrollContentViewBoundsChanged(notify: NSNotification); message 'scrollContentViewBoundsChanged:';
|
||||
procedure resetScrollData; message 'resetScrollData';
|
||||
|
||||
procedure lclUpdate; override;
|
||||
@ -695,44 +694,6 @@ begin
|
||||
self.documentView.setFrameSize( newSize );
|
||||
end;
|
||||
|
||||
procedure TCocoaScrollView.scrollContentViewBoundsChanged(notify: NSNotification
|
||||
);
|
||||
var
|
||||
nw : NSRect;
|
||||
dx,dy : CGFloat;
|
||||
scrollY: 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 self.documentView.isFlipped then
|
||||
scrollY:= nw.origin.y
|
||||
else
|
||||
scrollY:= self.documentView.frame.size.height - nw.origin.y - nw.size.height;
|
||||
|
||||
// update scrollers (this is required, if scrollWheel was called)
|
||||
// so processing LM_xSCROLL will not cause any actually scrolling,
|
||||
// as the current position will match!
|
||||
self.reflectScrolledClipView(contentView);
|
||||
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(scrollY));
|
||||
finally
|
||||
dec(holdscroll);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCocoaScrollView.resetScrollData;
|
||||
begin
|
||||
docrect:=documentVisibleRect;
|
||||
@ -742,9 +703,10 @@ end;
|
||||
|
||||
procedure TCocoaScrollView.scrollWheel(theEvent: NSEvent);
|
||||
begin
|
||||
if self.hasHorizontalScroller or self.hasVerticalScroller then
|
||||
inherited scrollWheel( theEvent )
|
||||
else if Assigned(self.enclosingScrollView) then
|
||||
if self.hasHorizontalScroller or self.hasVerticalScroller then begin
|
||||
inherited scrollWheel( theEvent );
|
||||
callback.scrollWheel( theEvent );
|
||||
end else if Assigned(self.enclosingScrollView) then
|
||||
self.enclosingScrollView.scrollWheel( theEvent )
|
||||
else
|
||||
inherited scrollWheel( theEvent );
|
||||
@ -820,23 +782,6 @@ begin
|
||||
self.contentView.setBoundsOrigin( newOrigin );
|
||||
end;
|
||||
|
||||
function TCocoaScrollView.initWithFrame(ns: NSRect): id;
|
||||
var
|
||||
sc : TCocoaScrollView;
|
||||
begin
|
||||
Result:=inherited initWithFrame(ns);
|
||||
sc:=TCocoaScrollView(Result);
|
||||
|
||||
if NOT sc.isCustomRange then
|
||||
Exit;
|
||||
|
||||
//sc.contentView.setPostsBoundsChangedNotifications(true);
|
||||
NSNotificationCenter.defaultCenter
|
||||
.addObserver_selector_name_object(sc, ObjCSelector('scrollContentViewBoundsChanged:')
|
||||
,NSViewBoundsDidChangeNotification
|
||||
,sc.contentView);
|
||||
end;
|
||||
|
||||
procedure TCocoaScrollView.dealloc;
|
||||
begin
|
||||
NSNotificationCenter.defaultCenter
|
||||
@ -846,62 +791,35 @@ end;
|
||||
|
||||
procedure TCocoaScrollView.setFrame(aframe: NSRect);
|
||||
var
|
||||
flg : NSUInteger;
|
||||
iflg : NSUInteger;
|
||||
docsz : NSSize;
|
||||
scrlsz : NSSize;
|
||||
|
||||
viewRect : NSRect;
|
||||
dRect : NSRect;
|
||||
hh : Single;
|
||||
r : NSRect;
|
||||
const
|
||||
NSBothSizable = NSViewWidthSizable or NSViewHeightSizable;
|
||||
newDocSize: NSSize;
|
||||
lclControl : TScrollingWinControl;
|
||||
lclBar: TControlScrollBar;
|
||||
begin
|
||||
if not isCustomRange then begin
|
||||
inherited setFrame(aframe);
|
||||
Exit;
|
||||
end;
|
||||
|
||||
viewRect := documentVisibleRect;
|
||||
dRect := NSView(documentView).frame;
|
||||
|
||||
inherited setFrame(aframe);
|
||||
|
||||
flg := documentView.autoresizingMask;
|
||||
if (flg and NSBothSizable) = NSBothSizable then Exit; // no need to checl
|
||||
lclControl:= TScrollingWinControl(lclGetTarget);
|
||||
newDocSize:= contentSize;
|
||||
|
||||
iflg := flg;
|
||||
docsz := NSView(documentView).frame.size;
|
||||
scrlsz := frame.size;
|
||||
lclBar:= lclControl.HorzScrollBar;
|
||||
if lclBar.Visible and (lclBar.Range<>0) and (lclBar.Range>lclBar.Page) then
|
||||
newDocSize.Width:= lclBar.Range;
|
||||
|
||||
if (docsz.width<scrlsz.width) and (flg and NSViewWidthSizable = 0) then
|
||||
flg := flg or NSViewWidthSizable;
|
||||
lclBar:= lclControl.VertScrollBar;
|
||||
if lclBar.Visible and (lclBar.Range<>0) and (lclBar.Range>lclBar.Page) then
|
||||
newDocSize.Height:= lclBar.Range;
|
||||
|
||||
if (docsz.height<scrlsz.height) and (flg and NSViewHeightSizable = 0) then
|
||||
begin
|
||||
// force automatic resize for isCustomRange
|
||||
flg := flg or NSViewHeightSizable;
|
||||
documentView.setFrameOrigin( NSMakePoint(0, aframe.size.height));
|
||||
documentView.setFrameSize(aframe.size);
|
||||
//documentView.setAutoresizingMask(flg);
|
||||
end;
|
||||
documentView.setFrameSize(newDocSize);
|
||||
|
||||
if iflg <> flg then
|
||||
documentView.setAutoresizingMask(flg);
|
||||
if lclHoriScrollInfo.fMask<>0 then
|
||||
applyScrollInfo(SB_Horz, lclHoriScrollInfo);
|
||||
|
||||
// the reason for this code here, is the need to re-allign the position
|
||||
// if the control Size adjusted after ScrollInfo got changed.
|
||||
if (documentVisibleRect.size.height < viewRect.size.height)
|
||||
and (flg and NSViewHeightSizable = 0) then
|
||||
begin
|
||||
hh := dRect.size.height - viewRect.origin.y - viewRect.size.height;
|
||||
|
||||
r := documentVisibleRect;
|
||||
r.origin.y := NSView(documentView).frame.size.height - r.size.height - hh;
|
||||
|
||||
NSView(documentView).scrollRectToVisible(r);
|
||||
end;
|
||||
if lclVertScrollInfo.fMask<>0 then
|
||||
applyScrollInfo(SB_Vert, lclVertScrollInfo);
|
||||
end;
|
||||
|
||||
function TCocoaScrollView.acceptsFirstResponder: LCLObjCBoolean;
|
||||
|
@ -117,6 +117,11 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.isSendingScrollWheelFromInterface(): Boolean;
|
||||
begin
|
||||
Result:= self.FSendingScrollWheelCount > 0;
|
||||
end;
|
||||
|
||||
procedure TCocoaWidgetSet.CallDefaultWndHandler(Sender: TObject; var Message);
|
||||
var
|
||||
hnd : NSObject;
|
||||
@ -130,7 +135,7 @@ const
|
||||
WantArrow : array [boolean] of integer = (0, DLGC_WANTARROWS);
|
||||
WantKeys : array [boolean] of integer = (0, DLGC_WANTALLKEYS);
|
||||
|
||||
procedure CallMouseWheelHandler(barFlag: Integer);
|
||||
function CallMouseWheelHandler(barFlag: Integer): LRESULT;
|
||||
var
|
||||
scrollMsg: TLMScroll;
|
||||
pMsg: PLMessage;
|
||||
@ -143,6 +148,7 @@ const
|
||||
offset: Integer;
|
||||
inc: Integer;
|
||||
begin
|
||||
Result:= 0;
|
||||
if NOT (Sender is TWinControl) then
|
||||
Exit;
|
||||
if NOT winControl.HandleAllocated then
|
||||
@ -191,6 +197,18 @@ const
|
||||
scrollMsg.ScrollCode:= SB_THUMBPOSITION;
|
||||
pMsg:= @scrollMsg;
|
||||
winControl.WindowProc(pMsg^);
|
||||
Result:= scrollMsg.Result;
|
||||
end;
|
||||
|
||||
function SendMouseWheel(barFlag: Integer): LRESULT;
|
||||
begin
|
||||
Result:= 0;
|
||||
inc( self.FSendingScrollWheelCount );
|
||||
try
|
||||
Result:= CallMouseWheelHandler( barFlag );
|
||||
finally
|
||||
dec( self.FSendingScrollWheelCount );
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
@ -212,9 +230,9 @@ begin
|
||||
end;
|
||||
end;
|
||||
LM_MOUSEWHEEL:
|
||||
CallMouseWheelHandler(SB_Vert);
|
||||
TLMMouseEvent(Message).Result:= SendMouseWheel(SB_Vert);
|
||||
LM_MOUSEHWHEEL:
|
||||
CallMouseWheelHandler(SB_Horz);
|
||||
TLMMouseEvent(Message).Result:= SendMouseWheel(SB_Horz);
|
||||
else
|
||||
TLMessage(Message).Result := 0;
|
||||
end;
|
||||
@ -1601,24 +1619,35 @@ end;
|
||||
|
||||
function TCocoaWidgetSet.GetScrollBarSize(Handle: HWND; BarKind: Integer): integer;
|
||||
var
|
||||
sc : NSScrollView;
|
||||
obj : NSObject;
|
||||
scroller: NSScroller;
|
||||
begin
|
||||
obj := NSObject(Handle);
|
||||
Result := 0;
|
||||
if not Assigned(obj) then Exit;
|
||||
|
||||
if obj.isKindOfClass(NSScrollView) then
|
||||
begin
|
||||
if (BarKind = SB_Vert) and Assigned(NSScrollView(obj).verticalScroller) then
|
||||
Result:=round(NSScrollView(obj).verticalScroller.frame.size.width)
|
||||
else if (BarKind = SB_Horz) and Assigned(NSScrollView(obj).horizontalScroller) then
|
||||
Result:=round(NSScrollView(obj).verticalScroller.frame.size.height)
|
||||
else
|
||||
Result := GetSystemMetrics(SM_CXVSCROLL);
|
||||
end
|
||||
obj:= NSObject(Handle);
|
||||
if NOT Assigned(obj) then
|
||||
Exit;
|
||||
|
||||
if NOT obj.isKindOfClass(NSScrollView) then begin
|
||||
Result:= GetSystemMetrics(SM_CXVSCROLL);
|
||||
Exit;
|
||||
end;
|
||||
|
||||
if BarKind = SB_VERT then
|
||||
scroller:= NSScrollView(obj).verticalScroller
|
||||
else
|
||||
Result := GetSystemMetrics(SM_CXVSCROLL);
|
||||
scroller:= NSScrollView(obj).horizontalScroller;
|
||||
|
||||
if NOT Assigned(scroller) then
|
||||
Exit;
|
||||
|
||||
if scroller.scrollerStyle = NSScrollerStyleOverlay then
|
||||
Exit;
|
||||
|
||||
if BarKind = SB_Vert then
|
||||
Result:= Round(scroller.frame.size.width)
|
||||
else
|
||||
Result:= Round(scroller.frame.size.height);
|
||||
end;
|
||||
|
||||
function TCocoaWidgetSet.GetScrollbarVisible(Handle: HWND; SBStyle: Integer): boolean;
|
||||
@ -1769,7 +1798,6 @@ var
|
||||
bar : TCocoaScrollBar;
|
||||
contentSize : NSSize;
|
||||
documentSize : NSSize;
|
||||
sizingMask : NSUInteger;
|
||||
hosted: Boolean;
|
||||
ensureWidth: Boolean = false;
|
||||
ensureHeight: Boolean = false;
|
||||
@ -1802,35 +1830,30 @@ begin
|
||||
if sc.isCustomRange and (ScrollInfo.fMask and SIF_RANGE>0) then begin
|
||||
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>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
|
||||
documentSize.width := contentSize.width;
|
||||
sizingMask:=sizingMask or NSViewWidthSizable;
|
||||
end;
|
||||
end else if SBStyle=SB_Vert then 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 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.ensureDocumentViewSizeChanged(documentSize, ensureWidth, ensureHeight);
|
||||
LCLScrollViewAdjustSize(lclControl);
|
||||
|
||||
// frame changed, Need to update another ScrollBar too
|
||||
if SbStyle=SB_Horz then begin
|
||||
@ -1843,8 +1866,10 @@ begin
|
||||
end;
|
||||
|
||||
// if frame changed, another ScrollBar has been updated
|
||||
if ScrollInfo.fMask and SIF_ALL > 0 then
|
||||
sc.applyScrollInfo(SBStyle, ScrollInfo);
|
||||
if NOT self.isSendingScrollWheelFromInterface then begin
|
||||
if ScrollInfo.fMask and SIF_ALL > 0 then
|
||||
sc.applyScrollInfo(SBStyle, ScrollInfo);
|
||||
end;
|
||||
Result:= getNewScrollPos();
|
||||
end else if obj.isKindOfClass(TCocoaManualScrollView) then
|
||||
begin
|
||||
|
@ -30,7 +30,7 @@ uses
|
||||
WSCheckLst, WSLCLClasses,
|
||||
// LCL Cocoa
|
||||
CocoaWSCommon, CocoaPrivate, CocoaUtils, CocoaWSStdCtrls, CocoaTables,
|
||||
CocoaScrollers;
|
||||
CocoaScrollers, CocoaWSScrollers;
|
||||
|
||||
type
|
||||
|
||||
|
@ -18,7 +18,7 @@ uses
|
||||
// WS
|
||||
WSComCtrls,
|
||||
// Cocoa WS
|
||||
CocoaPrivate, CocoaScrollers, CocoaTabControls, CocoaUtils,
|
||||
CocoaPrivate, CocoaScrollers, CocoaWSScrollers, CocoaTabControls, CocoaUtils,
|
||||
CocoaWSCommon, CocoaTables, cocoa_extra, CocoaWSStdCtrls, CocoaGDIObjects, CocoaButtons;
|
||||
|
||||
type
|
||||
|
@ -11,7 +11,8 @@ uses
|
||||
Types, Classes, Controls, SysUtils,
|
||||
WSControls, LCLType, LCLMessageGlue, LMessages, LCLProc, LCLIntf, Graphics, Forms,
|
||||
CocoaAll, CocoaInt, CocoaConfig, CocoaPrivate, CocoaUtils,
|
||||
CocoaGDIObjects, CocoaCursor, CocoaCaret, CocoaScrollers, cocoa_extra;
|
||||
CocoaScrollers, CocoaWSScrollers,
|
||||
CocoaGDIObjects, CocoaCursor, CocoaCaret, cocoa_extra;
|
||||
|
||||
type
|
||||
{ TLCLCommonCallback }
|
||||
@ -170,13 +171,6 @@ type
|
||||
const ABorderStyle: TBorderStyle); override;
|
||||
end;
|
||||
|
||||
// Utility WS functions. todo: it makes sense to put them into CocoaScollers
|
||||
|
||||
function EmbedInScrollView(AView: NSView; AReleaseView: Boolean = true): TCocoaScrollView;
|
||||
function EmbedInManualScrollView(AView: NSView): TCocoaManualScrollView;
|
||||
function EmbedInManualScrollHost(AView: TCocoaManualScrollView): TCocoaManualScrollHost;
|
||||
|
||||
procedure ScrollViewSetBorderStyle(sv: NSScrollView; astyle: TBorderStyle);
|
||||
procedure UpdateFocusRing(v: NSView; astyle: TBorderStyle);
|
||||
|
||||
function ButtonStateToShiftState(BtnState: PtrUInt): TShiftState;
|
||||
@ -225,17 +219,6 @@ begin
|
||||
if AMouseButtons and (1 shl 4) <> 0 then Include(Result, ssExtra2);
|
||||
end;
|
||||
|
||||
procedure ScrollViewSetBorderStyle(sv: NSScrollView; astyle: TBorderStyle);
|
||||
const
|
||||
NSBorderStyle : array [TBorderStyle] of NSBorderType = (
|
||||
NSNoBorder, // bsNone
|
||||
NSBezelBorder // bsSingle (NSLineBorder is too thick)
|
||||
);
|
||||
begin
|
||||
if not Assigned(sv) then Exit;
|
||||
sv.setBorderType( NSBorderStyle[astyle] );
|
||||
end;
|
||||
|
||||
procedure UpdateFocusRing(v: NSView; astyle: TBorderStyle);
|
||||
const
|
||||
NSFocusRing : array [TBorderStyle] of NSBorderType = (
|
||||
@ -247,100 +230,6 @@ begin
|
||||
v.setFocusRingType( NSFocusRing[astyle] );
|
||||
end;
|
||||
|
||||
function EmbedInScrollView(AView: NSView; AReleaseView: Boolean): TCocoaScrollView;
|
||||
var
|
||||
r: TRect;
|
||||
p: NSView;
|
||||
begin
|
||||
if not Assigned(AView) then
|
||||
Exit(nil);
|
||||
r := AView.lclFrame;
|
||||
p := AView.superview;
|
||||
Result := TCocoaScrollView.alloc.initWithFrame(NSNullRect);
|
||||
if Assigned(p) then p.addSubView(Result);
|
||||
Result.lclSetFrame(r);
|
||||
{$ifdef BOOLFIX}
|
||||
Result.setHidden_(Ord(AView.isHidden));
|
||||
{$else}
|
||||
Result.setHidden(AView.isHidden);
|
||||
{$endif}
|
||||
Result.setDocumentView(AView);
|
||||
Result.setDrawsBackground(false); // everything is covered anyway
|
||||
{$ifdef BOOLFIX}
|
||||
AView.setHidden_(Ord(false));
|
||||
{$else}
|
||||
AView.setHidden(false);
|
||||
{$endif}
|
||||
if AReleaseView then AView.release;
|
||||
SetViewDefaults(Result);
|
||||
end;
|
||||
|
||||
function EmbedInManualScrollView(AView: NSView): TCocoaManualScrollView;
|
||||
var
|
||||
r: TRect;
|
||||
p: NSView;
|
||||
begin
|
||||
if not Assigned(AView) then
|
||||
begin
|
||||
Result:=nil;
|
||||
Exit;
|
||||
end;
|
||||
r := AView.lclFrame;
|
||||
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}
|
||||
Result.setHidden_(Ord(AView.isHidden));
|
||||
{$else}
|
||||
Result.setHidden(AView.isHidden);
|
||||
{$endif}
|
||||
Result.setDocumentView(AView);
|
||||
{$ifdef BOOLFIX}
|
||||
AView.setHidden_(Ord(false));
|
||||
{$else}
|
||||
AView.setHidden(false);
|
||||
{$endif}
|
||||
AView.release;
|
||||
SetViewDefaults(Result);
|
||||
if AView.isKindOfClass(TCocoaCustomControl) then
|
||||
TCocoaCustomControl(AView).auxMouseByParent := true;
|
||||
end;
|
||||
|
||||
function EmbedInManualScrollHost(AView: TCocoaManualScrollView
|
||||
): TCocoaManualScrollHost;
|
||||
var
|
||||
r: TRect;
|
||||
p: NSView;
|
||||
begin
|
||||
if not Assigned(AView) then
|
||||
Exit(nil);
|
||||
r := AView.lclFrame;
|
||||
p := AView.superview;
|
||||
Result := TCocoaManualScrollHost.alloc.initWithFrame(NSNullRect);
|
||||
if Assigned(p) then p.addSubView(Result);
|
||||
Result.lclSetFrame(r);
|
||||
{$ifdef BOOLFIX}
|
||||
Result.setHidden_(Ord(AView.isHidden));
|
||||
{$else}
|
||||
Result.setHidden(AView.isHidden);
|
||||
{$endif}
|
||||
Result.setDocumentView(AView);
|
||||
Result.setDrawsBackground(false); // everything is covered anyway
|
||||
Result.contentView.setAutoresizesSubviews(false);
|
||||
AView.setAutoresizingMask(NSViewWidthSizable or NSViewHeightSizable);
|
||||
|
||||
AView.release;
|
||||
{$ifdef BOOLFIX}
|
||||
AView.setHidden_(Ord(false));
|
||||
{$else}
|
||||
AView.setHidden(false);
|
||||
{$endif}
|
||||
SetViewDefaults(Result);
|
||||
end;
|
||||
|
||||
{ TLCLCommonCallback }
|
||||
|
||||
function TLCLCommonCallback.GetHasCaret: Boolean;
|
||||
@ -1524,17 +1413,16 @@ end;
|
||||
procedure TLCLCommonCallback.DrawBackground(ctx: NSGraphicsContext; const bounds, dirtyRect: NSRect);
|
||||
var
|
||||
lTarget: TWinControl;
|
||||
nsr:NSRect;
|
||||
begin
|
||||
// Implement Color property
|
||||
lTarget := TWinControl(GetTarget());
|
||||
if (lTarget.Color <> clDefault) and (lTarget.Color <> clBtnFace) then
|
||||
begin
|
||||
ColorToNSColor(ColorToRGB(lTarget.Color)).set_();
|
||||
nsr:=dirtyRect;
|
||||
if NOT Owner.isKindOfClass(NSView) or NOT NSView(Owner).isFlipped then
|
||||
nsr.origin.y:=bounds.size.height-dirtyRect.origin.y-dirtyRect.size.height;
|
||||
NSRectFill(nsr);
|
||||
// NSRectFill() always requires the coordinate system of the lower left corner
|
||||
// of the origin, contrary to the Rect provided to LCL in
|
||||
// TLCLCommonCallback.Draw() and TLCLCommonCallback.DrawOverlay()
|
||||
NSRectFill(dirtyRect);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -2094,5 +1982,8 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
initialization
|
||||
ASyncLCLControlAdjustSizer:= TASyncLCLControlAdjustSizer.Create;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -32,7 +32,7 @@ uses
|
||||
// LCL Cocoa
|
||||
CocoaInt, CocoaConfig, CocoaPrivate, CocoaUtils, CocoaWSCommon, CocoaMenus,
|
||||
CocoaGDIObjects,
|
||||
CocoaWindows, CocoaScrollers, cocoa_extra;
|
||||
CocoaWindows, CocoaScrollers, CocoaWSScrollers, cocoa_extra;
|
||||
|
||||
type
|
||||
{ TLCLWindowCallback }
|
||||
@ -553,7 +553,6 @@ begin
|
||||
lcl.BlockCocoaUpDown := true;
|
||||
scrollcon.callback := lcl;
|
||||
docview.callback := lcl;
|
||||
docview.setAutoresizingMask(NSViewWidthSizable or NSViewHeightSizable);
|
||||
|
||||
Result := TLCLHandle(scrollcon);
|
||||
end;
|
||||
|
169
lcl/interfaces/cocoa/cocoawsscrollers.pas
Normal file
169
lcl/interfaces/cocoa/cocoawsscrollers.pas
Normal file
@ -0,0 +1,169 @@
|
||||
unit CocoaWSScrollers;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
{$modeswitch objectivec1}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, LCLType, Controls, Forms,
|
||||
CocoaAll, MacOSAll, CocoaPrivate, CocoaScrollers, CocoaUtils, cocoa_extra;
|
||||
|
||||
type
|
||||
{ ASyncLCLControlAdjustSizer }
|
||||
|
||||
TASyncLCLControlAdjustSizer = class
|
||||
private
|
||||
_control: TWinControl;
|
||||
_doing: Boolean;
|
||||
procedure doAdjustSize(data: PtrInt);
|
||||
public
|
||||
procedure adjustSize(control: TWinControl);
|
||||
end;
|
||||
|
||||
function EmbedInScrollView(AView: NSView; AReleaseView: Boolean = true): TCocoaScrollView;
|
||||
function EmbedInManualScrollView(AView: NSView): TCocoaManualScrollView;
|
||||
function EmbedInManualScrollHost(AView: TCocoaManualScrollView): TCocoaManualScrollHost;
|
||||
|
||||
procedure ScrollViewSetBorderStyle(sv: NSScrollView; astyle: TBorderStyle);
|
||||
procedure LCLScrollViewAdjustSize(control: TWinControl);
|
||||
|
||||
var
|
||||
ASyncLCLControlAdjustSizer: TASyncLCLControlAdjustSizer;
|
||||
|
||||
implementation
|
||||
|
||||
function EmbedInScrollView(AView: NSView; AReleaseView: Boolean): TCocoaScrollView;
|
||||
var
|
||||
r: TRect;
|
||||
p: NSView;
|
||||
begin
|
||||
if not Assigned(AView) then
|
||||
Exit(nil);
|
||||
r := AView.lclFrame;
|
||||
p := AView.superview;
|
||||
Result := TCocoaScrollView.alloc.initWithFrame(NSNullRect);
|
||||
if Assigned(p) then p.addSubView(Result);
|
||||
Result.lclSetFrame(r);
|
||||
{$ifdef BOOLFIX}
|
||||
Result.setHidden_(Ord(AView.isHidden));
|
||||
{$else}
|
||||
Result.setHidden(AView.isHidden);
|
||||
{$endif}
|
||||
Result.setDocumentView(AView);
|
||||
Result.setDrawsBackground(false); // everything is covered anyway
|
||||
{$ifdef BOOLFIX}
|
||||
AView.setHidden_(Ord(false));
|
||||
{$else}
|
||||
AView.setHidden(false);
|
||||
{$endif}
|
||||
if AReleaseView then AView.release;
|
||||
SetViewDefaults(Result);
|
||||
end;
|
||||
|
||||
function EmbedInManualScrollView(AView: NSView): TCocoaManualScrollView;
|
||||
var
|
||||
r: TRect;
|
||||
p: NSView;
|
||||
begin
|
||||
if not Assigned(AView) then
|
||||
begin
|
||||
Result:=nil;
|
||||
Exit;
|
||||
end;
|
||||
r := AView.lclFrame;
|
||||
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}
|
||||
Result.setHidden_(Ord(AView.isHidden));
|
||||
{$else}
|
||||
Result.setHidden(AView.isHidden);
|
||||
{$endif}
|
||||
Result.setDocumentView(AView);
|
||||
{$ifdef BOOLFIX}
|
||||
AView.setHidden_(Ord(false));
|
||||
{$else}
|
||||
AView.setHidden(false);
|
||||
{$endif}
|
||||
AView.release;
|
||||
SetViewDefaults(Result);
|
||||
if AView.isKindOfClass(TCocoaCustomControl) then
|
||||
TCocoaCustomControl(AView).auxMouseByParent := true;
|
||||
end;
|
||||
|
||||
function EmbedInManualScrollHost(AView: TCocoaManualScrollView
|
||||
): TCocoaManualScrollHost;
|
||||
var
|
||||
r: TRect;
|
||||
p: NSView;
|
||||
begin
|
||||
if not Assigned(AView) then
|
||||
Exit(nil);
|
||||
r := AView.lclFrame;
|
||||
p := AView.superview;
|
||||
Result := TCocoaManualScrollHost.alloc.initWithFrame(NSNullRect);
|
||||
if Assigned(p) then p.addSubView(Result);
|
||||
Result.lclSetFrame(r);
|
||||
{$ifdef BOOLFIX}
|
||||
Result.setHidden_(Ord(AView.isHidden));
|
||||
{$else}
|
||||
Result.setHidden(AView.isHidden);
|
||||
{$endif}
|
||||
Result.setDocumentView(AView);
|
||||
Result.setDrawsBackground(false); // everything is covered anyway
|
||||
Result.contentView.setAutoresizesSubviews(false);
|
||||
AView.setAutoresizingMask(NSViewWidthSizable or NSViewHeightSizable);
|
||||
|
||||
AView.release;
|
||||
{$ifdef BOOLFIX}
|
||||
AView.setHidden_(Ord(false));
|
||||
{$else}
|
||||
AView.setHidden(false);
|
||||
{$endif}
|
||||
SetViewDefaults(Result);
|
||||
end;
|
||||
|
||||
procedure ScrollViewSetBorderStyle(sv: NSScrollView; astyle: TBorderStyle);
|
||||
const
|
||||
NSBorderStyle : array [TBorderStyle] of NSBorderType = (
|
||||
NSNoBorder, // bsNone
|
||||
NSBezelBorder // bsSingle (NSLineBorder is too thick)
|
||||
);
|
||||
begin
|
||||
if not Assigned(sv) then Exit;
|
||||
sv.setBorderType( NSBorderStyle[astyle] );
|
||||
end;
|
||||
|
||||
procedure LCLScrollViewAdjustSize(control: TWinControl);
|
||||
begin
|
||||
if NSScroller.preferredScrollerStyle = NSScrollerStyleOverlay then
|
||||
Exit;
|
||||
ASyncLCLControlAdjustSizer.adjustSize(control);
|
||||
end;
|
||||
|
||||
{ TASyncLCLControlAdjustSizer }
|
||||
|
||||
procedure TASyncLCLControlAdjustSizer.doAdjustSize(data: PtrInt);
|
||||
begin
|
||||
_control.AdjustSize;
|
||||
_doing:= False;
|
||||
end;
|
||||
|
||||
procedure TASyncLCLControlAdjustSizer.adjustSize(control: TWinControl);
|
||||
begin
|
||||
_control:= control;
|
||||
_control.InvalidateClientRectCache(true);
|
||||
if NOT _doing then
|
||||
Application.QueueAsyncCall(@doAdjustSize, 0);
|
||||
_doing:= True;
|
||||
end;
|
||||
|
||||
initialization
|
||||
ASyncLCLControlAdjustSizer:= TASyncLCLControlAdjustSizer.Create;
|
||||
|
||||
end.
|
||||
|
@ -35,7 +35,7 @@ uses
|
||||
// LCL Cocoa
|
||||
CocoaConst, CocoaConfig,
|
||||
CocoaWSCommon, CocoaPrivate, CocoaUtils, CocoaGDIObjects, CocoaButtons,
|
||||
CocoaTables, CocoaTextEdits, CocoaScrollers, Cocoa_Extra;
|
||||
CocoaTables, CocoaTextEdits, CocoaScrollers, CocoaWSScrollers, Cocoa_Extra;
|
||||
|
||||
type
|
||||
|
||||
|
@ -131,7 +131,7 @@ end;"/>
|
||||
<License Value="modified LGPL-2
|
||||
"/>
|
||||
<Version Major="3" Minor="99"/>
|
||||
<Files Count="535">
|
||||
<Files Count="536">
|
||||
<Item1>
|
||||
<Filename Value="carbon/agl.pp"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
@ -2643,6 +2643,11 @@ end;"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="Cocoa_Extra"/>
|
||||
</Item535>
|
||||
<Item536>
|
||||
<Filename Value="cocoa/cocoawsscrollers.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="CocoaWSScrollers"/>
|
||||
</Item536>
|
||||
</Files>
|
||||
<CompatibilityMode Value="True"/>
|
||||
<LazDoc Paths="../../docs/xml/lcl"/>
|
||||
|
Loading…
Reference in New Issue
Block a user