mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-24 13:59:20 +02:00
Cocoa/ListView: in vsReport, change cellBase to viewBase, Merge branch 'cocoa/listview'
1. cellBase to viewBase 2. support checkboxes and icons at the same time 3. better support for selection
This commit is contained in:
commit
097eba8da1
@ -8,7 +8,7 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils,
|
Classes, SysUtils,
|
||||||
LclType, Controls,
|
LclType, Controls, ComCtrls,
|
||||||
MacOSAll, CocoaAll, CocoaGDIObjects;
|
MacOSAll, CocoaAll, CocoaGDIObjects;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -92,6 +92,7 @@ type
|
|||||||
|
|
||||||
IListViewCallBack = interface(ICommonCallback)
|
IListViewCallBack = interface(ICommonCallback)
|
||||||
function ItemsCount: Integer;
|
function ItemsCount: Integer;
|
||||||
|
function GetImageListType( out lvil: TListViewImageList ): Boolean;
|
||||||
function GetItemTextAt(ARow, ACol: Integer; var Text: String): Boolean;
|
function GetItemTextAt(ARow, ACol: Integer; var Text: String): Boolean;
|
||||||
function GetItemCheckedAt(ARow, ACol: Integer; var CheckState: Integer): Boolean;
|
function GetItemCheckedAt(ARow, ACol: Integer; var CheckState: Integer): Boolean;
|
||||||
function GetItemImageAt(ARow, ACol: Integer; var imgIdx: Integer): Boolean;
|
function GetItemImageAt(ARow, ACol: Integer; var imgIdx: Integer): Boolean;
|
||||||
@ -100,7 +101,7 @@ type
|
|||||||
procedure SetItemCheckedAt(ARow, ACol: Integer; CheckState: Integer);
|
procedure SetItemCheckedAt(ARow, ACol: Integer; CheckState: Integer);
|
||||||
function shouldSelectionChange(NewSel: Integer): Boolean;
|
function shouldSelectionChange(NewSel: Integer): Boolean;
|
||||||
procedure ColumnClicked(ACol: Integer);
|
procedure ColumnClicked(ACol: Integer);
|
||||||
procedure DrawRow(rowidx: Integer; ctx: TCocoaContext; const r: TRect; state: TOwnerDrawState);
|
function DrawRow(rowidx: Integer; ctx: TCocoaContext; const r: TRect; state: TOwnerDrawState): Boolean;
|
||||||
procedure GetRowHeight(rowidx: Integer; var height: Integer);
|
procedure GetRowHeight(rowidx: Integer; var height: Integer);
|
||||||
function GetBorderStyle: TBorderStyle;
|
function GetBorderStyle: TBorderStyle;
|
||||||
end;
|
end;
|
||||||
|
@ -31,6 +31,7 @@ type
|
|||||||
constructor Create(AOwner: NSObject; ATarget: TWinControl; AHandleView: NSView); override;
|
constructor Create(AOwner: NSObject; ATarget: TWinControl; AHandleView: NSView); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function ItemsCount: Integer;
|
function ItemsCount: Integer;
|
||||||
|
function GetImageListType( out lvil: TListViewImageList ): Boolean;
|
||||||
function GetItemTextAt(ARow, ACol: Integer; var Text: String): Boolean;
|
function GetItemTextAt(ARow, ACol: Integer; var Text: String): Boolean;
|
||||||
function GetItemCheckedAt(ARow, ACol: Integer; var IsChecked: Integer): Boolean;
|
function GetItemCheckedAt(ARow, ACol: Integer; var IsChecked: Integer): Boolean;
|
||||||
function GetItemImageAt(ARow, ACol: Integer; var imgIdx: Integer): Boolean;
|
function GetItemImageAt(ARow, ACol: Integer; var imgIdx: Integer): Boolean;
|
||||||
@ -41,11 +42,10 @@ type
|
|||||||
procedure selectOne(ARow: Integer; isSelected:Boolean );
|
procedure selectOne(ARow: Integer; isSelected:Boolean );
|
||||||
function shouldSelectionChange(NewSel: Integer): Boolean;
|
function shouldSelectionChange(NewSel: Integer): Boolean;
|
||||||
procedure ColumnClicked(ACol: Integer);
|
procedure ColumnClicked(ACol: Integer);
|
||||||
procedure DrawRow(rowidx: Integer; ctx: TCocoaContext; const r: TRect;
|
function DrawRow(rowidx: Integer; ctx: TCocoaContext; const r: TRect;
|
||||||
state: TOwnerDrawState);
|
state: TOwnerDrawState): Boolean;
|
||||||
procedure GetRowHeight(rowidx: Integer; var h: Integer);
|
procedure GetRowHeight(rowidx: Integer; var h: Integer);
|
||||||
function GetBorderStyle: TBorderStyle;
|
function GetBorderStyle: TBorderStyle;
|
||||||
function GetImageListType( out lvil: TListViewImageList ): Boolean;
|
|
||||||
procedure callTargetInitializeWnd;
|
procedure callTargetInitializeWnd;
|
||||||
end;
|
end;
|
||||||
TLCLListViewCallBackClass = class of TLCLListViewCallback;
|
TLCLListViewCallBackClass = class of TLCLListViewCallback;
|
||||||
@ -180,7 +180,6 @@ var
|
|||||||
controlFrame: NSRect;
|
controlFrame: NSRect;
|
||||||
backendControlAccess: TCocoaListViewBackendControlProtocol;
|
backendControlAccess: TCocoaListViewBackendControlProtocol;
|
||||||
begin
|
begin
|
||||||
Writeln( HexStr(@_allocFunc) );
|
|
||||||
_allocFunc( self, _viewStyle, _backendControl, _WSHandler );
|
_allocFunc( self, _viewStyle, _backendControl, _WSHandler );
|
||||||
|
|
||||||
controlFrame:= self.bounds;
|
controlFrame:= self.bounds;
|
||||||
@ -337,6 +336,7 @@ end;
|
|||||||
function TLCLListViewCallback.GetItemImageAt(ARow, ACol: Integer;
|
function TLCLListViewCallback.GetItemImageAt(ARow, ACol: Integer;
|
||||||
var imgIdx: Integer): Boolean;
|
var imgIdx: Integer): Boolean;
|
||||||
begin
|
begin
|
||||||
|
imgIdx:= -1;
|
||||||
Result := (ACol >= 0) and ( (ACol<listView.ColumnCount) or ( ACol=0) )
|
Result := (ACol >= 0) and ( (ACol<listView.ColumnCount) or ( ACol=0) )
|
||||||
and (ARow >= 0) and (ARow < listView.Items.Count);
|
and (ARow >= 0) and (ARow < listView.Items.Count);
|
||||||
|
|
||||||
@ -524,14 +524,16 @@ begin
|
|||||||
LCLMessageGlue.DeliverMessage(ListView, Msg);
|
LCLMessageGlue.DeliverMessage(ListView, Msg);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLCLListViewCallback.DrawRow(rowidx: Integer; ctx: TCocoaContext;
|
function TLCLListViewCallback.DrawRow(rowidx: Integer; ctx: TCocoaContext;
|
||||||
const r: TRect; state: TOwnerDrawState);
|
const r: TRect; state: TOwnerDrawState): Boolean;
|
||||||
var
|
var
|
||||||
ALV: TCustomListViewAccess;
|
ALV: TCustomListViewAccess;
|
||||||
|
drawResult: TCustomDrawResult;
|
||||||
begin
|
begin
|
||||||
ALV:= TCustomListViewAccess(self.listView);
|
ALV:= TCustomListViewAccess(self.listView);
|
||||||
ALV.Canvas.Handle:= HDC(ctx);
|
ALV.Canvas.Handle:= HDC(ctx);
|
||||||
ALV.IntfCustomDraw( dtItem, cdPrePaint, rowidx, 0, [], nil );
|
drawResult:= ALV.IntfCustomDraw( dtItem, cdPrePaint, rowidx, 0, [], nil );
|
||||||
|
Result:= cdrSkipDefault in drawResult;
|
||||||
ALV.Canvas.Handle:= 0;
|
ALV.Canvas.Handle:= 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -212,6 +212,7 @@ class function TCocoaWSCustomCheckListBox.CreateHandle(
|
|||||||
var
|
var
|
||||||
list: TCocoaTableListView;
|
list: TCocoaTableListView;
|
||||||
scroll: TCocoaScrollView;
|
scroll: TCocoaScrollView;
|
||||||
|
processor: TCocoaTableViewProcessor;
|
||||||
begin
|
begin
|
||||||
list := AllocCocoaTableListView.lclInitWithCreateParams(AParams);
|
list := AllocCocoaTableListView.lclInitWithCreateParams(AParams);
|
||||||
if not Assigned(list) then
|
if not Assigned(list) then
|
||||||
@ -219,9 +220,10 @@ begin
|
|||||||
Result := 0;
|
Result := 0;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
list.onSelectionChanged:= @TListBox_selectionChanged;
|
processor:= TCocoaTableListBoxProcessor.Create;
|
||||||
|
list.lclSetProcessor( processor );
|
||||||
list.callback := TLCLCheckboxListCallback.CreateWithView(list, AWinControl);
|
list.callback := TLCLCheckboxListCallback.CreateWithView(list, AWinControl);
|
||||||
list.lclSetFirstColumCheckboxes(true);
|
list.lclSetCheckboxes(true);
|
||||||
//list.list := TCocoaStringList.Create(list);
|
//list.list := TCocoaStringList.Create(list);
|
||||||
list.addTableColumn(NSTableColumn.alloc.init.autorelease);
|
list.addTableColumn(NSTableColumn.alloc.init.autorelease);
|
||||||
list.setHeaderView(nil);
|
list.setHeaderView(nil);
|
||||||
|
@ -96,10 +96,12 @@ type
|
|||||||
procedure CocoaListViewAllocFuncImpl(const listView: NSView; const viewStyle: TViewStyle; out backendControl: NSView; out WSHandler: TCocoaWSListViewHandler );
|
procedure CocoaListViewAllocFuncImpl(const listView: NSView; const viewStyle: TViewStyle; out backendControl: NSView; out WSHandler: TCocoaWSListViewHandler );
|
||||||
var
|
var
|
||||||
cocoaListView: TCocoaListView Absolute listView;
|
cocoaListView: TCocoaListView Absolute listView;
|
||||||
|
processor: TCocoaTableViewProcessor;
|
||||||
begin
|
begin
|
||||||
if viewStyle = vsReport then begin
|
if viewStyle = vsReport then begin
|
||||||
backendControl:= AllocCocoaTableListView;
|
backendControl:= AllocCocoaTableListView;
|
||||||
TCocoaTableListView(backendControl).onSelectionChanged:= CocoaTables.TListView_onSelectionChanged;
|
processor:= TCocoaTableListViewProcessor.Create;
|
||||||
|
TCocoaTableListView(backendControl).lclSetProcessor( processor );
|
||||||
WSHandler:= TCocoaWSListView_TableViewHandler.Create( cocoaListView );
|
WSHandler:= TCocoaWSListView_TableViewHandler.Create( cocoaListView );
|
||||||
end else begin
|
end else begin
|
||||||
backendControl:= AllocCocoaCollectionView( viewStyle );
|
backendControl:= AllocCocoaCollectionView( viewStyle );
|
||||||
|
@ -129,6 +129,15 @@ type
|
|||||||
class procedure SetTextHint(const ACustomComboBox: TCustomComboBox; const ATextHint: string); override;
|
class procedure SetTextHint(const ACustomComboBox: TCustomComboBox; const ATextHint: string); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TCocoaTableListBoxProcessor }
|
||||||
|
|
||||||
|
TCocoaTableListBoxProcessor = class( TCocoaTableViewProcessor )
|
||||||
|
function isInitializing( tv: NSTableView ): Boolean; override;
|
||||||
|
procedure onReloadData(tv: NSTableView); override;
|
||||||
|
procedure onSelectOneItem( tv: NSTableView; selection: NSIndexSet ); override;
|
||||||
|
procedure onSelectionChanged(tv: NSTableView); override;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TCocoaWSCustomListBox }
|
{ TCocoaWSCustomListBox }
|
||||||
|
|
||||||
TCocoaWSCustomListBox = class(TWSCustomListBox)
|
TCocoaWSCustomListBox = class(TWSCustomListBox)
|
||||||
@ -269,6 +278,7 @@ type
|
|||||||
constructor CreateWithView(AOwner: TCocoaTableListView; ATarget: TWinControl);
|
constructor CreateWithView(AOwner: TCocoaTableListView; ATarget: TWinControl);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
function ItemsCount: Integer; virtual;
|
function ItemsCount: Integer; virtual;
|
||||||
|
function GetImageListType(out lvil: TListViewImageList): Boolean; virtual;
|
||||||
function GetItemTextAt(ARow, ACol: Integer; var Text: String): Boolean; virtual;
|
function GetItemTextAt(ARow, ACol: Integer; var Text: String): Boolean; virtual;
|
||||||
function GetItemCheckedAt(ARow, ACol: Integer; var isChecked: Integer): Boolean; virtual;
|
function GetItemCheckedAt(ARow, ACol: Integer; var isChecked: Integer): Boolean; virtual;
|
||||||
function GetItemImageAt(ARow, ACol: Integer; var imgIdx: Integer): Boolean; virtual;
|
function GetItemImageAt(ARow, ACol: Integer; var imgIdx: Integer): Boolean; virtual;
|
||||||
@ -277,7 +287,7 @@ type
|
|||||||
procedure SetItemCheckedAt(ARow, ACol: Integer; isChecked: Integer); virtual;
|
procedure SetItemCheckedAt(ARow, ACol: Integer; isChecked: Integer); virtual;
|
||||||
function shouldSelectionChange(NewSel: Integer): Boolean; virtual;
|
function shouldSelectionChange(NewSel: Integer): Boolean; virtual;
|
||||||
procedure ColumnClicked(ACol: Integer); virtual;
|
procedure ColumnClicked(ACol: Integer); virtual;
|
||||||
procedure DrawRow(rowidx: Integer; ctx: TCocoaContext; const r: TRect; state: TOwnerDrawState); virtual;
|
function DrawRow(rowidx: Integer; ctx: TCocoaContext; const r: TRect; state: TOwnerDrawState): Boolean; virtual;
|
||||||
procedure GetRowHeight(rowidx: integer; var h: Integer); virtual;
|
procedure GetRowHeight(rowidx: integer; var h: Integer); virtual;
|
||||||
function GetBorderStyle: TBorderStyle;
|
function GetBorderStyle: TBorderStyle;
|
||||||
end;
|
end;
|
||||||
@ -380,8 +390,6 @@ procedure ComboBoxSetBorderStyle(box: NSComboBox; astyle: TBorderStyle);
|
|||||||
// LCL expects a change notification in either way. (by software or by user)
|
// LCL expects a change notification in either way. (by software or by user)
|
||||||
procedure ControlSetTextWithChangeEvent(ctrl: NSControl; const text: string);
|
procedure ControlSetTextWithChangeEvent(ctrl: NSControl; const text: string);
|
||||||
|
|
||||||
procedure TListBox_selectionChanged( tv: NSTableView );
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
function AllocButton(const ATarget: TWinControl; const ACallBackClass: TLCLButtonCallBackClass; const AParams: TCreateParams; btnBezel: NSBezelStyle; btnType: NSButtonType): TCocoaButton;
|
function AllocButton(const ATarget: TWinControl; const ACallBackClass: TLCLButtonCallBackClass; const AParams: TCreateParams; btnBezel: NSBezelStyle; btnType: NSButtonType): TCocoaButton;
|
||||||
@ -604,6 +612,12 @@ begin
|
|||||||
Result := strings.Count;
|
Result := strings.Count;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TLCLListBoxCallback.GetImageListType(out lvil: TListViewImageList
|
||||||
|
): Boolean;
|
||||||
|
begin
|
||||||
|
Result:= False;
|
||||||
|
end;
|
||||||
|
|
||||||
function TLCLListBoxCallback.GetItemTextAt(ARow, ACol: Integer; var Text: String): Boolean;
|
function TLCLListBoxCallback.GetItemTextAt(ARow, ACol: Integer; var Text: String): Boolean;
|
||||||
begin
|
begin
|
||||||
Result := (ARow>=0) and (ARow < strings.Count);
|
Result := (ARow>=0) and (ARow < strings.Count);
|
||||||
@ -650,17 +664,21 @@ begin
|
|||||||
// not needed
|
// not needed
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLCLListBoxCallback.DrawRow(rowidx: Integer; ctx: TCocoaContext;
|
function TLCLListBoxCallback.DrawRow(rowidx: Integer; ctx: TCocoaContext;
|
||||||
const r: TRect; state: TOwnerDrawState);
|
const r: TRect; state: TOwnerDrawState): Boolean;
|
||||||
var
|
var
|
||||||
DrawStruct: TDrawListItemStruct;
|
DrawStruct: TDrawListItemStruct;
|
||||||
begin
|
begin
|
||||||
if not listview.isOwnerDraw then Exit;
|
Result:= False;
|
||||||
|
if NOT listview.isOwnerDraw then
|
||||||
|
Exit;
|
||||||
|
|
||||||
DrawStruct.ItemState := state;
|
DrawStruct.ItemState := state;
|
||||||
DrawStruct.Area := r;
|
DrawStruct.Area := r;
|
||||||
DrawStruct.DC := HDC(ctx);
|
DrawStruct.DC := HDC(ctx);
|
||||||
DrawStruct.ItemID := rowIdx;
|
DrawStruct.ItemID := rowIdx;
|
||||||
LCLSendDrawListItemMsg(Target, @DrawStruct);
|
LCLSendDrawListItemMsg(Target, @DrawStruct);
|
||||||
|
Result:= True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLCLListBoxCallback.GetRowHeight(rowidx: integer; var h: Integer);
|
procedure TLCLListBoxCallback.GetRowHeight(rowidx: integer; var h: Integer);
|
||||||
@ -674,23 +692,6 @@ begin
|
|||||||
Result:= TCustomListBox(Target).BorderStyle;
|
Result:= TCustomListBox(Target).BorderStyle;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TListBox_selectionChanged( tv: NSTableView );
|
|
||||||
var
|
|
||||||
lclListView: TCustomListView;
|
|
||||||
cocoaTLV: TCocoaTableListView Absolute tv;
|
|
||||||
lclcb: TLCLListBoxCallback;
|
|
||||||
begin
|
|
||||||
if NOT Assigned(cocoaTLV.callback) then
|
|
||||||
Exit;
|
|
||||||
|
|
||||||
lclcb:= TLCLListBoxCallback( cocoaTLV.callback.GetCallbackObject );
|
|
||||||
lclListView:= TCustomListView( lclcb.Target );
|
|
||||||
|
|
||||||
// do not notify about selection changes while clearing
|
|
||||||
if Assigned(lclcb.strings) and (lclcb.strings.isClearing) then Exit;
|
|
||||||
SendSimpleMessage(lclListView, LM_SELCHANGE);
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TLCLCheckBoxCallback }
|
{ TLCLCheckBoxCallback }
|
||||||
|
|
||||||
procedure TLCLCheckBoxCallback.ButtonClick;
|
procedure TLCLCheckBoxCallback.ButtonClick;
|
||||||
@ -2402,10 +2403,42 @@ begin
|
|||||||
cb.BlockCocoaMouseMove:=true;
|
cb.BlockCocoaMouseMove:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCocoaTableListBoxProcessor.isInitializing(tv: NSTableView): Boolean;
|
||||||
|
begin
|
||||||
|
Result:= False;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaTableListBoxProcessor.onReloadData(tv: NSTableView);
|
||||||
|
begin
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaTableListBoxProcessor.onSelectOneItem(tv: NSTableView;
|
||||||
|
selection: NSIndexSet);
|
||||||
|
begin
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaTableListBoxProcessor.onSelectionChanged(tv: NSTableView);
|
||||||
|
var
|
||||||
|
lclListView: TCustomListView;
|
||||||
|
cocoaTLV: TCocoaTableListView Absolute tv;
|
||||||
|
lclcb: TLCLListBoxCallback;
|
||||||
|
begin
|
||||||
|
if NOT Assigned(cocoaTLV.callback) then
|
||||||
|
Exit;
|
||||||
|
|
||||||
|
lclcb:= TLCLListBoxCallback( cocoaTLV.callback.GetCallbackObject );
|
||||||
|
lclListView:= TCustomListView( lclcb.Target );
|
||||||
|
|
||||||
|
// do not notify about selection changes while clearing
|
||||||
|
if Assigned(lclcb.strings) and (lclcb.strings.isClearing) then Exit;
|
||||||
|
SendSimpleMessage(lclListView, LM_SELCHANGE);
|
||||||
|
end;
|
||||||
|
|
||||||
class function TCocoaWSCustomListBox.CreateHandle(const AWinControl:TWinControl;
|
class function TCocoaWSCustomListBox.CreateHandle(const AWinControl:TWinControl;
|
||||||
const AParams:TCreateParams):TLCLHandle;
|
const AParams:TCreateParams):TLCLHandle;
|
||||||
var
|
var
|
||||||
list : TCocoaTableListView;
|
list : TCocoaTableListView;
|
||||||
|
processor: TCocoaTableViewProcessor;
|
||||||
column : NSTableColumn;
|
column : NSTableColumn;
|
||||||
scroll : TCocoaScrollView;
|
scroll : TCocoaScrollView;
|
||||||
lclListBox: TCustomListBox absolute AWinControl;
|
lclListBox: TCustomListBox absolute AWinControl;
|
||||||
@ -2417,8 +2450,8 @@ begin
|
|||||||
Result := 0;
|
Result := 0;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
list.onSelectionChanged:= @TListBox_selectionChanged;
|
processor:= TCocoaTableListBoxProcessor.Create;
|
||||||
|
list.lclSetProcessor( processor );
|
||||||
cb := TLCLListBoxCallback.CreateWithView(list, AWinControl);
|
cb := TLCLListBoxCallback.CreateWithView(list, AWinControl);
|
||||||
list.callback := cb;
|
list.callback := cb;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user