cocoa: initial implementation of CocoaListView and CocoaGroupBox

git-svn-id: trunk@27276 -
This commit is contained in:
dmitry 2010-09-06 13:37:27 +00:00
parent 959ce2b93d
commit bcb791dcb6
3 changed files with 132 additions and 14 deletions

View File

@ -188,6 +188,35 @@ type
callback : TCommonCallback;
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
{ TCocoaButton }
@ -573,5 +602,39 @@ begin
Result.Bottom:=Round(Result.Top+b.size.height);
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.

View File

@ -242,12 +242,13 @@ end;
function RegisterCustomScrollBar: Boolean; alias : 'WSRegisterCustomScrollBar';
begin
RegisterWSComponent(TCustomScrollBar, TCocoaWSScrollBar);
Result:=True;
Result := True;
end;
function RegisterCustomGroupBox: Boolean; alias : 'WSRegisterCustomGroupBox';
begin
Result := False;
RegisterWSComponent(TCustomGroupBox, TCocoaWSCustomGroupBox);
Result := True;
end;
function RegisterCustomComboBox: Boolean; alias : 'WSRegisterCustomComboBox';
@ -258,7 +259,8 @@ end;
function RegisterCustomListBox: Boolean; alias : 'WSRegisterCustomListBox';
begin
Result := False;
RegisterWSComponent(TCustomListBox, TCocoaWSCustomListBox);
Result := True;
end;
function RegisterCustomEdit: Boolean; alias : 'WSRegisterCustomEdit';

View File

@ -50,10 +50,8 @@ type
{ TCocoaWSCustomGroupBox }
TCocoaWSCustomGroupBox = class(TWSCustomGroupBox)
private
protected
public
// class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
end;
{ TCocoaWSGroupBox }
@ -96,17 +94,15 @@ type
{ TCocoaWSCustomListBox }
TCocoaWSCustomListBox = class(TWSCustomListBox)
private
protected
public
{ class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class function GetIndexAtXY(const ACustomListBox: TCustomListBox; X, Y: integer): integer; override;
published
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 GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean; 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 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 SetBorderStyle(const AWinControl: TWinControl; const ABorderStyle: TBorderStyle); override;
@ -713,5 +709,62 @@ begin
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.