From 00f0bda2b1aced2e1f346c50bfcdc32b16405017 Mon Sep 17 00:00:00 2001 From: rich2014 Date: Sat, 17 Aug 2024 18:51:05 +0800 Subject: [PATCH] Cocoa: move CocoaTables.TCocoaStringList to CocoaListControl.TCocoaListControlStringList --- lcl/interfaces/cocoa/cocoalistcontrol.pas | 37 ++++++++++++++++++++++ lcl/interfaces/cocoa/cocoatables.pas | 38 ----------------------- lcl/interfaces/cocoa/cocoawschecklst.pas | 10 +++--- lcl/interfaces/cocoa/cocoawsstdctrls.pas | 8 ++--- 4 files changed, 45 insertions(+), 48 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoalistcontrol.pas b/lcl/interfaces/cocoa/cocoalistcontrol.pas index 4f5085451c..f048e84620 100644 --- a/lcl/interfaces/cocoa/cocoalistcontrol.pas +++ b/lcl/interfaces/cocoa/cocoalistcontrol.pas @@ -82,6 +82,19 @@ type function isCustomDrawSupported: Boolean; virtual; abstract; end; + { TCocoaListControlStringList } + + TCocoaListControlStringList = class(TStringList) + protected + procedure Changed; override; + public + Owner: NSTableView; + // some notificaitons (i.e. selection change) + // should not be passed to LCL while clearing + isClearing: Boolean; + constructor Create(AOwner: NSTableView); + procedure Clear; override; + end; implementation @@ -112,5 +125,29 @@ begin Result:= _checkedIndexSet; end; +{ TCocoaListControlStringList } + +procedure TCocoaListControlStringList.Changed; +begin + inherited Changed; + Owner.reloadData; +end; + +constructor TCocoaListControlStringList.Create(AOwner: NSTableView); +begin + Owner:=AOwner; + inherited Create; +end; + +procedure TCocoaListControlStringList.Clear; +begin + isClearing := true; + try + inherited Clear; + finally + isClearing := false; + end; +end; + end. diff --git a/lcl/interfaces/cocoa/cocoatables.pas b/lcl/interfaces/cocoa/cocoatables.pas index aa1c0c7062..44b5a7a799 100644 --- a/lcl/interfaces/cocoa/cocoatables.pas +++ b/lcl/interfaces/cocoa/cocoatables.pas @@ -33,20 +33,6 @@ uses type - { TCocoaStringList } - - TCocoaStringList = class(TStringList) - protected - procedure Changed; override; - public - Owner: NSTableView; - // some notificaitons (i.e. selection change) - // should not be passed to LCL while clearing - isClearing: Boolean; - constructor Create(AOwner: NSTableView); - procedure Clear; override; - end; - { TCocoaTableListItem } TCocoaTableListItem = objcclass(NSTableCellView) @@ -1051,30 +1037,6 @@ begin self.reloadData; end; -{ TCocoaStringList } - -procedure TCocoaStringList.Changed; -begin - inherited Changed; - Owner.reloadData; -end; - -constructor TCocoaStringList.Create(AOwner: NSTableView); -begin - Owner:=AOwner; - inherited Create; -end; - -procedure TCocoaStringList.Clear; -begin - isClearing := true; - try - inherited Clear; - finally - isClearing := false; - end; -end; - { TCocoaTableListItem } function TCocoaTableListItem.checkBox: NSButton; diff --git a/lcl/interfaces/cocoa/cocoawschecklst.pas b/lcl/interfaces/cocoa/cocoawschecklst.pas index 5fa1151acf..2e2fa8196e 100644 --- a/lcl/interfaces/cocoa/cocoawschecklst.pas +++ b/lcl/interfaces/cocoa/cocoawschecklst.pas @@ -30,13 +30,13 @@ uses WSCheckLst, WSLCLClasses, // LCL Cocoa CocoaWSCommon, CocoaPrivate, CocoaCallback, CocoaWSStdCtrls, - CocoaTables, CocoaScrollers, CocoaWSScrollers; + CocoaListControl, CocoaTables, CocoaScrollers, CocoaWSScrollers; type { TCocoaCheckStringList } - TCocoaCheckStringList = class(TCocoaStringList) + TCocoaCheckStringList = class(TCocoaListControlStringList) protected procedure ExchangeItems(Index1, Index2: Integer); override; public @@ -50,7 +50,7 @@ type TLCLCheckboxListCallback = class(TLCLListBoxCallback) protected - function AllocStrings(ATable: NSTableView): TCocoaStringList; override; + function AllocStrings(ATable: NSTableView): TCocoaListControlStringList; override; public checklist: TCustomCheckListBox; constructor Create(AOwner: NSObject; ATarget: TWinControl; AHandleView: NSView); override; @@ -71,8 +71,6 @@ type class procedure SetState(const ACheckListBox: TCustomCheckListBox; const AIndex: integer; const AState: TCheckBoxState); override; end; -function CtrlToCheckList(ctrl: TWinControl; out tbl: TCocoaTableListView; out cb: TLCLCheckboxListCallback): Boolean; - implementation function CtrlToCheckList(ctrl: TWinControl; out tbl: TCocoaTableListView; out cb: TLCLCheckboxListCallback): Boolean; @@ -139,7 +137,7 @@ end; { TLCLCheckboxListCallback } -function TLCLCheckboxListCallback.AllocStrings(ATable: NSTableView): TCocoaStringList; +function TLCLCheckboxListCallback.AllocStrings(ATable: NSTableView): TCocoaListControlStringList; begin Result:=TCocoaCheckStringList.Create(ATable); end; diff --git a/lcl/interfaces/cocoa/cocoawsstdctrls.pas b/lcl/interfaces/cocoa/cocoawsstdctrls.pas index 0fbd8299dc..1a09330102 100644 --- a/lcl/interfaces/cocoa/cocoawsstdctrls.pas +++ b/lcl/interfaces/cocoa/cocoawsstdctrls.pas @@ -272,10 +272,10 @@ type TLCLListBoxCallback = class(TLCLListControlCallback) protected - function AllocStrings(ATable: NSTableView): TCocoaStringList; virtual; + function AllocStrings(ATable: NSTableView): TCocoaListControlStringList; virtual; public listview : TCocoaTableListView; - strings : TCocoaStringList; + strings : TCocoaListControlStringList; constructor CreateWithView(AOwner: TCocoaTableListView; ATarget: TWinControl); destructor Destroy; override; function ItemsCount: Integer; override; @@ -601,9 +601,9 @@ end; { TLCLListBoxCallback } function TLCLListBoxCallback.AllocStrings(ATable: NSTableView - ): TCocoaStringList; + ): TCocoaListControlStringList; begin - Result := TCocoaStringList.Create(ATable); + Result := TCocoaListControlStringList.Create(ATable); end; constructor TLCLListBoxCallback.CreateWithView(AOwner: TCocoaTableListView;