Cocoa/ListBox: ScrollWidth / Horizontal Scrolling supported, Merge branch 'cocoa/listbox'

This commit is contained in:
rich2014 2023-09-16 18:38:56 +08:00
commit fb4cb204e7
3 changed files with 45 additions and 6 deletions

View File

@ -81,6 +81,7 @@ type
isOwnerDraw : Boolean;
isDynamicRowHeight: Boolean;
CustomRowHeight: Integer;
ScrollWidth: Integer;
smallimages : NSMutableDictionary;

View File

@ -97,11 +97,6 @@ const
function CFStringToStr(AString: CFStringRef; Encoding: CFStringEncoding = DEFAULT_CFSTRING_ENCODING): String;
function CFStringToString(AString: CFStringRef): String;
// Missing things from NSTableColumns.inc
const
NSTableColumnAutoresizingMask = 1 shl 0;
NSTableColumnUserResizingMask = 1 shl 1;
function VirtualKeyCodeToMacString(AKey: Word): NSString;
procedure FillStandardDescription(out Desc: TRawImageDescription);

View File

@ -134,6 +134,7 @@ type
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
class function GetItemIndex(const ACustomListBox: TCustomListBox): integer; override;
class function GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
class function GetScrollWidth(const ACustomListBox: TCustomListBox): Integer; override;
class function GetSelCount(const ACustomListBox: TCustomListBox): integer; override;
class function GetSelected(const ACustomListBox: TCustomListBox; const AIndex: integer): boolean; override;
class function GetStrings(const ACustomListBox: TCustomListBox): TStrings; override;
@ -143,6 +144,7 @@ type
class procedure SetBorderStyle(const AWinControl: TWinControl; const ABorderStyle: TBorderStyle); override;
//class procedure SetBorder(const ACustomListBox: TCustomListBox); override;
class procedure SetItemIndex(const ACustomListBox: TCustomListBox; const AIndex: integer); override;
class procedure SetScrollWidth(const ACustomListBox: TCustomListBox; const AScrollWidth: Integer); override;
class procedure SetSelectionMode(const ACustomListBox: TCustomListBox; const AExtendedSelect, AMultiSelect: boolean); override;
class procedure SetStyle(const ACustomListBox: TCustomListBox); override;
{class procedure SetSorted(const ACustomListBox: TCustomListBox; AList: TStrings; ASorted: boolean); override;}
@ -2365,6 +2367,7 @@ class function TCocoaWSCustomListBox.CreateHandle(const AWinControl:TWinControl;
const AParams:TCreateParams):TLCLHandle;
var
list : TCocoaTableListView;
column : NSTableColumn;
scroll : TCocoaScrollView;
lclListBox: TCustomListBox absolute AWinControl;
cb : TLCLListBoxCallback;
@ -2375,9 +2378,18 @@ begin
Result := 0;
Exit;
end;
cb := TLCLListBoxCallback.CreateWithView(list, AWinControl);
list.callback := cb;
list.addTableColumn(NSTableColumn.alloc.init.autorelease);
column := NSTableColumn.alloc.init.autorelease;
if lclListBox.ScrollWidth > 0 then
begin
column.setResizingMask(NSTableColumnNoResizing);
column.setWidth(lclListBox.ScrollWidth);
end;
list.addTableColumn(column);
list.setHeaderView(nil);
list.setDataSource(list);
list.setDelegate(list);
@ -2403,6 +2415,7 @@ begin
cb.HandleFrame := scroll;
scroll.callback := list.callback;
scroll.setHasVerticalScroller(true);
scroll.setHasHorizontalScroller(true);
scroll.setAutohidesScrollers(true);
ScrollViewSetBorderStyle(scroll, lclListBox.BorderStyle);
UpdateFocusRing(list, lclListBox.BorderStyle);
@ -2437,6 +2450,15 @@ begin
Result := LCLGetItemRect(view, Index, 0, ARect);
end;
class function TCocoaWSCustomListBox.GetScrollWidth(const ACustomListBox: TCustomListBox): Integer;
var
view: TCocoaTableListView;
begin
view := GetListBox(ACustomListBox);
if not Assigned(view) then Exit(0);
Result := view.ScrollWidth;
end;
class function TCocoaWSCustomListBox.GetItemIndex(const ACustomListBox: TCustomListBox): integer;
var
view: TCocoaTableListView;
@ -2537,6 +2559,27 @@ begin
end;
end;
class procedure TCocoaWSCustomListBox.SetScrollWidth(const ACustomListBox: TCustomListBox; const AScrollWidth: Integer);
var
view: TCocoaTableListView;
column: NSTableColumn;
begin
view := GetListBox(ACustomListBox);
if not Assigned(view) then Exit;
view.ScrollWidth := AScrollWidth;
column := NSTableColumn(view.tableColumns.objectAtIndex(0));
if AScrollWidth = 0 then
begin
column.setResizingMask(NSTableColumnAutoresizingMask);
view.sizeLastColumnToFit;
end
else
begin
column.setResizingMask(NSTableColumnNoResizing);
column.setWidth(AScrollWidth);
end;
end;
class procedure TCocoaWSCustomListBox.SetSelectionMode(const ACustomListBox: TCustomListBox; const AExtendedSelect, AMultiSelect: boolean);
var
list: TCocoaTableListView;