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