Cocoa: remove circular unit references, add CocoaWSScrollers unit

This commit is contained in:
rich2014 2024-06-19 00:10:21 +08:00
parent 595fd26f3f
commit 2bb8922ae8
9 changed files with 183 additions and 163 deletions

View File

@ -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,

View File

@ -150,8 +150,6 @@ type
procedure setFrame(newValue: NSRect); override;
end;
procedure LCLScrollViewAdjustSize(control: TWinControl);
function isMouseEventInScrollBar(host: TCocoaManualScrollView; event: NSEvent): Boolean;
// These settings are set by a user in "System Preferences"
@ -169,9 +167,6 @@ function AdjustScrollerPage(sc: TCocoaScrollBar; prt: NSScrollerPart): Boolean;
implementation
uses
CocoaWSCommon;
function SysPrefScrollShow: string;
begin
Result := NSStringToString(NSUserDefaults.standardUserDefaults.stringForKey(NSSTR('AppleShowScrollBars')));
@ -638,13 +633,6 @@ begin
Result:=true;
end;
procedure LCLScrollViewAdjustSize(control: TWinControl);
begin
if NSScroller.preferredScrollerStyle = NSScrollerStyleOverlay then
Exit;
ASyncLCLControlAdjustSizer.adjustSize(control);
end;
function isMouseEventInScrollBar(host: TCocoaManualScrollView; event: NSEvent): Boolean;
var
pt : NSPoint;

View File

@ -30,7 +30,7 @@ uses
WSCheckLst, WSLCLClasses,
// LCL Cocoa
CocoaWSCommon, CocoaPrivate, CocoaUtils, CocoaWSStdCtrls, CocoaTables,
CocoaScrollers;
CocoaScrollers, CocoaWSScrollers;
type

View File

@ -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

View File

@ -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,25 +171,6 @@ type
const ABorderStyle: TBorderStyle); override;
end;
{ ASyncLCLControlAdjustSizer }
TASyncLCLControlAdjustSizer = class
private
_control: TWinControl;
_doing: Boolean;
procedure doAdjustSize(data: PtrInt);
public
procedure adjustSize(control: TWinControl);
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;
@ -200,9 +182,6 @@ function NSObjectDebugStr(obj: NSObject): string;
function CallbackDebugStr(cb: ICommonCallback): string;
procedure DebugDumpParents(fromView: NSView);
var
ASyncLCLControlAdjustSizer: TASyncLCLControlAdjustSizer;
implementation
uses
@ -240,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 = (
@ -262,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;
@ -2076,23 +1950,6 @@ begin
ScrollViewSetBorderStyle( TCocoaManualScrollHost(AWinControl.Handle), ABorderStyle );
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;
function NSObjectDebugStr(obj: NSObject): string;
begin
Result := IntToStr(PtrUInt(obj));

View File

@ -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 }

View 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.

View File

@ -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

View File

@ -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"/>