mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-13 21:19:18 +02:00
cocoa: initial implementation of CocoaListView and CocoaGroupBox
git-svn-id: trunk@27276 -
This commit is contained in:
parent
959ce2b93d
commit
bcb791dcb6
@ -188,6 +188,35 @@ type
|
|||||||
callback : TCommonCallback;
|
callback : TCommonCallback;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TCocoaListView = objcclass;
|
||||||
|
|
||||||
|
{ TCocoaStringList }
|
||||||
|
|
||||||
|
TCocoaStringList = class(TStringList)
|
||||||
|
protected
|
||||||
|
procedure Changed; override;
|
||||||
|
public
|
||||||
|
Owner : TCocoaListView;
|
||||||
|
constructor Create(AOwner: TCocoaListView);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaListView }
|
||||||
|
|
||||||
|
TCocoaListView = objcclass(NSTableView)
|
||||||
|
callback : TCommonCallback;
|
||||||
|
list : TCocoaStringList;
|
||||||
|
function numberOfRowsInTableView(aTableView: NSTableView): NSInteger; message 'numberOfRowsInTableView:';
|
||||||
|
function tableView_objectValueForTableColumn_row(tableView: NSTableView;
|
||||||
|
objectValueForTableColumn: NSTableColumn; row: NSInteger):id;
|
||||||
|
message 'tableView:objectValueForTableColumn:row:';
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaGroupBox }
|
||||||
|
|
||||||
|
TCocoaGroupBox = objcclass(NSBox)
|
||||||
|
callback : TCommonCallback;
|
||||||
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{ TCocoaButton }
|
{ TCocoaButton }
|
||||||
@ -573,5 +602,39 @@ begin
|
|||||||
Result.Bottom:=Round(Result.Top+b.size.height);
|
Result.Bottom:=Round(Result.Top+b.size.height);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TCocoaListView }
|
||||||
|
|
||||||
|
function TCocoaListView.numberOfRowsInTableView(aTableView:NSTableView): NSInteger;
|
||||||
|
begin
|
||||||
|
if Assigned(list)
|
||||||
|
then Result:=list.Count
|
||||||
|
else Result:=0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCocoaListView.tableView_objectValueForTableColumn_row(tableView: NSTableView;
|
||||||
|
objectValueForTableColumn: NSTableColumn; row: NSInteger):id;
|
||||||
|
begin
|
||||||
|
if not Assigned(list) then
|
||||||
|
Result:=nil
|
||||||
|
else begin
|
||||||
|
if row>=list.count then Result:=nil
|
||||||
|
else Result:=NSStringUtf8(list[row]);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaStringList }
|
||||||
|
|
||||||
|
procedure TCocoaStringList.Changed;
|
||||||
|
begin
|
||||||
|
inherited Changed;
|
||||||
|
Owner.reloadData;
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TCocoaStringList.Create(AOwner:TCocoaListView);
|
||||||
|
begin
|
||||||
|
Owner:=AOwner;
|
||||||
|
inherited Create;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -242,12 +242,13 @@ end;
|
|||||||
function RegisterCustomScrollBar: Boolean; alias : 'WSRegisterCustomScrollBar';
|
function RegisterCustomScrollBar: Boolean; alias : 'WSRegisterCustomScrollBar';
|
||||||
begin
|
begin
|
||||||
RegisterWSComponent(TCustomScrollBar, TCocoaWSScrollBar);
|
RegisterWSComponent(TCustomScrollBar, TCocoaWSScrollBar);
|
||||||
Result:=True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function RegisterCustomGroupBox: Boolean; alias : 'WSRegisterCustomGroupBox';
|
function RegisterCustomGroupBox: Boolean; alias : 'WSRegisterCustomGroupBox';
|
||||||
begin
|
begin
|
||||||
Result := False;
|
RegisterWSComponent(TCustomGroupBox, TCocoaWSCustomGroupBox);
|
||||||
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function RegisterCustomComboBox: Boolean; alias : 'WSRegisterCustomComboBox';
|
function RegisterCustomComboBox: Boolean; alias : 'WSRegisterCustomComboBox';
|
||||||
@ -258,7 +259,8 @@ end;
|
|||||||
|
|
||||||
function RegisterCustomListBox: Boolean; alias : 'WSRegisterCustomListBox';
|
function RegisterCustomListBox: Boolean; alias : 'WSRegisterCustomListBox';
|
||||||
begin
|
begin
|
||||||
Result := False;
|
RegisterWSComponent(TCustomListBox, TCocoaWSCustomListBox);
|
||||||
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function RegisterCustomEdit: Boolean; alias : 'WSRegisterCustomEdit';
|
function RegisterCustomEdit: Boolean; alias : 'WSRegisterCustomEdit';
|
||||||
|
@ -50,10 +50,8 @@ type
|
|||||||
{ TCocoaWSCustomGroupBox }
|
{ TCocoaWSCustomGroupBox }
|
||||||
|
|
||||||
TCocoaWSCustomGroupBox = class(TWSCustomGroupBox)
|
TCocoaWSCustomGroupBox = class(TWSCustomGroupBox)
|
||||||
private
|
published
|
||||||
protected
|
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
||||||
public
|
|
||||||
// class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaWSGroupBox }
|
{ TCocoaWSGroupBox }
|
||||||
@ -96,17 +94,15 @@ type
|
|||||||
{ TCocoaWSCustomListBox }
|
{ TCocoaWSCustomListBox }
|
||||||
|
|
||||||
TCocoaWSCustomListBox = class(TWSCustomListBox)
|
TCocoaWSCustomListBox = class(TWSCustomListBox)
|
||||||
private
|
published
|
||||||
protected
|
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
||||||
public
|
{class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
|
||||||
{ class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
|
|
||||||
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
|
|
||||||
class function GetItemIndex(const ACustomListBox: TCustomListBox): 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 GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; override;
|
||||||
class function GetSelCount(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 GetSelected(const ACustomListBox: TCustomListBox; const AIndex: integer): boolean; override;}
|
||||||
class function GetStrings(const ACustomListBox: TCustomListBox): TStrings; override;
|
class function GetStrings(const ACustomListBox: TCustomListBox): TStrings; override;
|
||||||
class function GetTopIndex(const ACustomListBox: TCustomListBox): integer; override;
|
{class function GetTopIndex(const ACustomListBox: TCustomListBox): integer; override;
|
||||||
|
|
||||||
class procedure SelectItem(const ACustomListBox: TCustomListBox; AIndex: integer; ASelected: boolean); override;
|
class procedure SelectItem(const ACustomListBox: TCustomListBox; AIndex: integer; ASelected: boolean); override;
|
||||||
class procedure SetBorderStyle(const AWinControl: TWinControl; const ABorderStyle: TBorderStyle); override;
|
class procedure SetBorderStyle(const AWinControl: TWinControl; const ABorderStyle: TBorderStyle); override;
|
||||||
@ -713,5 +709,62 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TCocoaWSCustomGroupBox }
|
||||||
|
|
||||||
|
class function TCocoaWSCustomGroupBox.CreateHandle(const AWinControl:TWinControl;
|
||||||
|
const AParams:TCreateParams):TLCLIntfHandle;
|
||||||
|
var
|
||||||
|
box : TCocoaGroupBox;
|
||||||
|
begin
|
||||||
|
box := NSView(TCocoaGroupBox.alloc).lclInitWithCreateParams(AParams);
|
||||||
|
box.callback:=TLCLCommonCallback.Create(box, AWinControl);
|
||||||
|
Result:=TLCLIntfHandle(box);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaWSCustomListBox }
|
||||||
|
|
||||||
|
function GetListView(AWinControl: TWinControl): TCocoaListView;
|
||||||
|
begin
|
||||||
|
if not Assigned(AWinControl) or (AWinControl.Handle=0) then
|
||||||
|
Result:=nil
|
||||||
|
else
|
||||||
|
Result:=TCocoaListView(TCocoaScrollView(AWinControl.Handle).documentView);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCocoaWSCustomListBox.CreateHandle(const AWinControl:TWinControl;
|
||||||
|
const AParams:TCreateParams):TLCLIntfHandle;
|
||||||
|
var
|
||||||
|
list : TCocoaListView;
|
||||||
|
scroll : TCocoaScrollView;
|
||||||
|
begin
|
||||||
|
list:=NSView(TCocoaListView.alloc).lclInitWithCreateParams(AParams);
|
||||||
|
list.callback:=TLCLCommonCallback.Create(list, AWinControl);
|
||||||
|
list.list:=TCocoaStringList.Create(list);
|
||||||
|
list.addTableColumn(NSTableColumn.alloc.init);
|
||||||
|
list.setHeaderView(nil);
|
||||||
|
list.setDataSource(list);
|
||||||
|
|
||||||
|
if not Assigned(list) then begin
|
||||||
|
Result:=0;
|
||||||
|
Exit;
|
||||||
|
end;
|
||||||
|
scroll:=EmbedInScrollView(list);
|
||||||
|
scroll.callback:=list.callback;
|
||||||
|
scroll.setHasVerticalScroller(true);
|
||||||
|
scroll.setAutohidesScrollers(true);
|
||||||
|
Result:=TLCLIntfHandle(scroll);
|
||||||
|
end;
|
||||||
|
|
||||||
|
class function TCocoaWSCustomListBox.GetStrings(const ACustomListBox: TCustomListBox):TStrings;
|
||||||
|
var
|
||||||
|
view : TCocoaListView;
|
||||||
|
begin
|
||||||
|
view:=GetListView(ACustomListBox);
|
||||||
|
if not Assigned(view) then
|
||||||
|
Result:=nil
|
||||||
|
else
|
||||||
|
Result:=view.list;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user