mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-25 21:59:14 +02:00
Cocoa: Enhance TCocoaWSCustomListBox functionality
git-svn-id: trunk@43754 -
This commit is contained in:
parent
4dd58709a9
commit
4cd110d9c9
@ -143,6 +143,12 @@ type
|
||||
procedure ButtonClick;
|
||||
end;
|
||||
|
||||
{ IListBoxCallBack }
|
||||
|
||||
IListBoxCallBack = interface(ICommonCallback)
|
||||
procedure SelectionChanged;
|
||||
end;
|
||||
|
||||
{ IWindowCallback }
|
||||
|
||||
IWindowCallback = interface(ICommonCallBack)
|
||||
@ -439,9 +445,9 @@ type
|
||||
|
||||
{ TCocoaListView }
|
||||
|
||||
TCocoaListView = objcclass(NSTableView, NSTableViewDataSourceProtocol)
|
||||
TCocoaListView = objcclass(NSTableView, NSTableViewDelegateProtocol, NSTableViewDataSourceProtocol )
|
||||
public
|
||||
callback: ICommonCallback;
|
||||
callback: IListBoxCallback;
|
||||
list: TCocoaStringList;
|
||||
resultNS: NSString; //use to return values to combo
|
||||
function acceptsFirstResponder: Boolean; override;
|
||||
@ -450,11 +456,35 @@ type
|
||||
function lclGetCallback: ICommonCallback; override;
|
||||
procedure lclClearCallback; override;
|
||||
function numberOfRowsInTableView(aTableView: NSTableView): NSInteger; message 'numberOfRowsInTableView:';
|
||||
|
||||
function tableView_shouldEditTableColumn_row(tableView: NSTableView;
|
||||
tableColumn: NSTableColumn; row: NSInteger): Boolean;
|
||||
message 'tableView:shouldEditTableColumn:row:';
|
||||
|
||||
function tableView_objectValueForTableColumn_row(tableView: NSTableView;
|
||||
objectValueForTableColumn: NSTableColumn; row: NSInteger):id;
|
||||
message 'tableView:objectValueForTableColumn:row:';
|
||||
|
||||
procedure tableViewSelectionDidChange(notification: NSNotification); message 'tableViewSelectionDidChange:';
|
||||
|
||||
procedure dealloc; override;
|
||||
procedure resetCursorRects; override;
|
||||
|
||||
// mouse
|
||||
procedure mouseDown(event: NSEvent); override;
|
||||
// procedure mouseUp(event: NSEvent); override; This is eaten by NSTableView - worked around with NSTableViewDelegateProtocol
|
||||
procedure rightMouseDown(event: NSEvent); override;
|
||||
procedure rightMouseUp(event: NSEvent); override;
|
||||
procedure otherMouseDown(event: NSEvent); override;
|
||||
procedure otherMouseUp(event: NSEvent); override;
|
||||
procedure mouseDragged(event: NSEvent); override;
|
||||
procedure mouseEntered(event: NSEvent); override;
|
||||
procedure mouseExited(event: NSEvent); override;
|
||||
procedure mouseMoved(event: NSEvent); override;
|
||||
// key
|
||||
procedure keyDown(event: NSEvent); override;
|
||||
procedure keyUp(event: NSEvent); override;
|
||||
|
||||
end;
|
||||
|
||||
{ TCocoaGroupBox }
|
||||
@ -1802,6 +1832,12 @@ begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
|
||||
function TCocoaListView.tableView_shouldEditTableColumn_row(tableView: NSTableView; tableColumn: NSTableColumn; row: NSInteger): Boolean;
|
||||
begin
|
||||
result:=false; // disable cell editing by default
|
||||
end;
|
||||
|
||||
function TCocoaListView.tableView_objectValueForTableColumn_row(tableView: NSTableView;
|
||||
objectValueForTableColumn: NSTableColumn; row: NSInteger):id;
|
||||
begin
|
||||
@ -1831,6 +1867,75 @@ begin
|
||||
inherited resetCursorRects;
|
||||
end;
|
||||
|
||||
procedure TCocoaListView.tableViewSelectionDidChange(notification: NSNotification);
|
||||
begin
|
||||
if Assigned(callback) then
|
||||
callback.SelectionChanged;
|
||||
end;
|
||||
|
||||
procedure TCocoaListView.mouseDown(event: NSEvent);
|
||||
begin
|
||||
if not Assigned(callback) or not callback.MouseUpDownEvent(event) then
|
||||
inherited mouseDown(event);
|
||||
end;
|
||||
|
||||
procedure TCocoaListView.rightMouseDown(event: NSEvent);
|
||||
begin
|
||||
if not Assigned(callback) or not callback.MouseUpDownEvent(event) then
|
||||
inherited rightMouseDown(event);
|
||||
end;
|
||||
|
||||
procedure TCocoaListView.rightMouseUp(event: NSEvent);
|
||||
begin
|
||||
if not Assigned(callback) or not callback.MouseUpDownEvent(event) then
|
||||
inherited rightMouseUp(event);
|
||||
end;
|
||||
|
||||
procedure TCocoaListView.otherMouseDown(event: NSEvent);
|
||||
begin
|
||||
if not Assigned(callback) or not callback.MouseUpDownEvent(event) then
|
||||
inherited otherMouseDown(event);
|
||||
end;
|
||||
|
||||
procedure TCocoaListView.otherMouseUp(event: NSEvent);
|
||||
begin
|
||||
if not Assigned(callback) or not callback.MouseUpDownEvent(event) then
|
||||
inherited otherMouseUp(event);
|
||||
end;
|
||||
|
||||
procedure TCocoaListView.mouseDragged(event: NSEvent);
|
||||
begin
|
||||
if not Assigned(callback) or not callback.MouseMove(event) then
|
||||
inherited mouseDragged(event);
|
||||
end;
|
||||
|
||||
procedure TCocoaListView.mouseEntered(event: NSEvent);
|
||||
begin
|
||||
inherited mouseEntered(event);
|
||||
end;
|
||||
|
||||
procedure TCocoaListView.mouseExited(event: NSEvent);
|
||||
begin
|
||||
inherited mouseExited(event);
|
||||
end;
|
||||
|
||||
procedure TCocoaListView.mouseMoved(event: NSEvent);
|
||||
begin
|
||||
inherited mouseMoved(event);
|
||||
end;
|
||||
|
||||
procedure TCocoaListView.keyDown(event: NSEvent);
|
||||
begin
|
||||
if not Assigned(callback) or not callback.KeyEvent(event) then
|
||||
inherited keyDown(event);
|
||||
end;
|
||||
|
||||
procedure TCocoaListView.keyUp(event: NSEvent);
|
||||
begin
|
||||
if not Assigned(callback) or not callback.KeyEvent(event) then
|
||||
inherited keyUp(event);
|
||||
end;
|
||||
|
||||
{ TCocoaStringList }
|
||||
|
||||
procedure TCocoaStringList.Changed;
|
||||
|
@ -88,10 +88,10 @@ type
|
||||
TCocoaWSCustomListBox = class(TWSCustomListBox)
|
||||
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 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 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;
|
||||
{class function GetTopIndex(const ACustomListBox: TCustomListBox): integer; override;
|
||||
@ -148,6 +148,17 @@ type
|
||||
end;
|
||||
TLCLButtonCallBackClass = class of TLCLButtonCallBack;
|
||||
|
||||
{ TLCLListBoxCallback }
|
||||
|
||||
TLCLListBoxCallback = class(TLCLCommonCallback, IListBoxCallback)
|
||||
public
|
||||
procedure SelectionChanged; virtual;
|
||||
end;
|
||||
TLCLListBoxCallBackClass = class of TLCLListBoxCallBack;
|
||||
|
||||
|
||||
|
||||
|
||||
{ TCocoaWSButton }
|
||||
|
||||
TCocoaWSButton = class(TWSButton)
|
||||
@ -314,6 +325,15 @@ begin
|
||||
SendSimpleMessage(Target, LM_CLICKED);
|
||||
end;
|
||||
|
||||
{ TLCLListBoxCallback }
|
||||
|
||||
procedure TLCLListBoxCallback.SelectionChanged;
|
||||
begin
|
||||
SendSimpleMessage(Target, LM_SELCHANGE);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
{ TLCLCheckBoxCallback }
|
||||
|
||||
procedure TLCLCheckBoxCallback.ButtonClick;
|
||||
@ -909,11 +929,13 @@ begin
|
||||
Result := 0;
|
||||
Exit;
|
||||
end;
|
||||
list.callback := TLCLCommonCallback.Create(list, AWinControl);
|
||||
list.callback := TLCLListBoxCallback.Create(list, AWinControl);
|
||||
list.list := TCocoaStringList.Create(list);
|
||||
list.addTableColumn(NSTableColumn.alloc.init);
|
||||
list.setHeaderView(nil);
|
||||
list.setDataSource(list);
|
||||
list.setDelegate(list);
|
||||
|
||||
|
||||
scroll := EmbedInScrollView(list);
|
||||
if not Assigned(scroll) then
|
||||
@ -939,5 +961,42 @@ begin
|
||||
Result:=view.list;
|
||||
end;
|
||||
|
||||
class function TCocoaWSCustomListBox.GetItemRect(const ACustomListBox: TCustomListBox; Index: integer; var ARect: TRect): boolean;
|
||||
var view : TCocoaListView;
|
||||
r:NSRect;
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
view:=GetListView(ACustomListBox);
|
||||
if not Assigned(view) then
|
||||
begin
|
||||
Result:=false;
|
||||
exit;
|
||||
end;
|
||||
|
||||
r:=view.frameOfCellAtColumn_row(0,index);
|
||||
Arect:=NSRectToRect(r);
|
||||
Result := True;
|
||||
|
||||
end;
|
||||
|
||||
class function TCocoaWSCustomListBox.GetItemIndex(const ACustomListBox: TCustomListBox): integer;
|
||||
var
|
||||
view : TCocoaListView;
|
||||
indexset: NSIndexSet;
|
||||
begin
|
||||
|
||||
view:=GetListView(ACustomListBox);
|
||||
if not Assigned(view) then
|
||||
begin
|
||||
Result:=-1;
|
||||
exit;
|
||||
end;
|
||||
|
||||
indexset:=view.selectedRowIndexes();
|
||||
result:=indexset.firstIndex;
|
||||
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user