mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-28 10:00:46 +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;
|
procedure ButtonClick;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ IListBoxCallBack }
|
||||||
|
|
||||||
|
IListBoxCallBack = interface(ICommonCallback)
|
||||||
|
procedure SelectionChanged;
|
||||||
|
end;
|
||||||
|
|
||||||
{ IWindowCallback }
|
{ IWindowCallback }
|
||||||
|
|
||||||
IWindowCallback = interface(ICommonCallBack)
|
IWindowCallback = interface(ICommonCallBack)
|
||||||
@ -439,9 +445,9 @@ type
|
|||||||
|
|
||||||
{ TCocoaListView }
|
{ TCocoaListView }
|
||||||
|
|
||||||
TCocoaListView = objcclass(NSTableView, NSTableViewDataSourceProtocol)
|
TCocoaListView = objcclass(NSTableView, NSTableViewDelegateProtocol, NSTableViewDataSourceProtocol )
|
||||||
public
|
public
|
||||||
callback: ICommonCallback;
|
callback: IListBoxCallback;
|
||||||
list: TCocoaStringList;
|
list: TCocoaStringList;
|
||||||
resultNS: NSString; //use to return values to combo
|
resultNS: NSString; //use to return values to combo
|
||||||
function acceptsFirstResponder: Boolean; override;
|
function acceptsFirstResponder: Boolean; override;
|
||||||
@ -450,11 +456,35 @@ type
|
|||||||
function lclGetCallback: ICommonCallback; override;
|
function lclGetCallback: ICommonCallback; override;
|
||||||
procedure lclClearCallback; override;
|
procedure lclClearCallback; override;
|
||||||
function numberOfRowsInTableView(aTableView: NSTableView): NSInteger; message 'numberOfRowsInTableView:';
|
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;
|
function tableView_objectValueForTableColumn_row(tableView: NSTableView;
|
||||||
objectValueForTableColumn: NSTableColumn; row: NSInteger):id;
|
objectValueForTableColumn: NSTableColumn; row: NSInteger):id;
|
||||||
message 'tableView:objectValueForTableColumn:row:';
|
message 'tableView:objectValueForTableColumn:row:';
|
||||||
|
|
||||||
|
procedure tableViewSelectionDidChange(notification: NSNotification); message 'tableViewSelectionDidChange:';
|
||||||
|
|
||||||
procedure dealloc; override;
|
procedure dealloc; override;
|
||||||
procedure resetCursorRects; 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;
|
end;
|
||||||
|
|
||||||
{ TCocoaGroupBox }
|
{ TCocoaGroupBox }
|
||||||
@ -1802,6 +1832,12 @@ begin
|
|||||||
Result := 0;
|
Result := 0;
|
||||||
end;
|
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;
|
function TCocoaListView.tableView_objectValueForTableColumn_row(tableView: NSTableView;
|
||||||
objectValueForTableColumn: NSTableColumn; row: NSInteger):id;
|
objectValueForTableColumn: NSTableColumn; row: NSInteger):id;
|
||||||
begin
|
begin
|
||||||
@ -1831,6 +1867,75 @@ begin
|
|||||||
inherited resetCursorRects;
|
inherited resetCursorRects;
|
||||||
end;
|
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 }
|
{ TCocoaStringList }
|
||||||
|
|
||||||
procedure TCocoaStringList.Changed;
|
procedure TCocoaStringList.Changed;
|
||||||
|
@ -88,10 +88,10 @@ type
|
|||||||
TCocoaWSCustomListBox = class(TWSCustomListBox)
|
TCocoaWSCustomListBox = class(TWSCustomListBox)
|
||||||
published
|
published
|
||||||
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; 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 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;
|
||||||
@ -148,6 +148,17 @@ type
|
|||||||
end;
|
end;
|
||||||
TLCLButtonCallBackClass = class of TLCLButtonCallBack;
|
TLCLButtonCallBackClass = class of TLCLButtonCallBack;
|
||||||
|
|
||||||
|
{ TLCLListBoxCallback }
|
||||||
|
|
||||||
|
TLCLListBoxCallback = class(TLCLCommonCallback, IListBoxCallback)
|
||||||
|
public
|
||||||
|
procedure SelectionChanged; virtual;
|
||||||
|
end;
|
||||||
|
TLCLListBoxCallBackClass = class of TLCLListBoxCallBack;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{ TCocoaWSButton }
|
{ TCocoaWSButton }
|
||||||
|
|
||||||
TCocoaWSButton = class(TWSButton)
|
TCocoaWSButton = class(TWSButton)
|
||||||
@ -314,6 +325,15 @@ begin
|
|||||||
SendSimpleMessage(Target, LM_CLICKED);
|
SendSimpleMessage(Target, LM_CLICKED);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TLCLListBoxCallback }
|
||||||
|
|
||||||
|
procedure TLCLListBoxCallback.SelectionChanged;
|
||||||
|
begin
|
||||||
|
SendSimpleMessage(Target, LM_SELCHANGE);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{ TLCLCheckBoxCallback }
|
{ TLCLCheckBoxCallback }
|
||||||
|
|
||||||
procedure TLCLCheckBoxCallback.ButtonClick;
|
procedure TLCLCheckBoxCallback.ButtonClick;
|
||||||
@ -909,11 +929,13 @@ begin
|
|||||||
Result := 0;
|
Result := 0;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
list.callback := TLCLCommonCallback.Create(list, AWinControl);
|
list.callback := TLCLListBoxCallback.Create(list, AWinControl);
|
||||||
list.list := TCocoaStringList.Create(list);
|
list.list := TCocoaStringList.Create(list);
|
||||||
list.addTableColumn(NSTableColumn.alloc.init);
|
list.addTableColumn(NSTableColumn.alloc.init);
|
||||||
list.setHeaderView(nil);
|
list.setHeaderView(nil);
|
||||||
list.setDataSource(list);
|
list.setDataSource(list);
|
||||||
|
list.setDelegate(list);
|
||||||
|
|
||||||
|
|
||||||
scroll := EmbedInScrollView(list);
|
scroll := EmbedInScrollView(list);
|
||||||
if not Assigned(scroll) then
|
if not Assigned(scroll) then
|
||||||
@ -939,5 +961,42 @@ begin
|
|||||||
Result:=view.list;
|
Result:=view.list;
|
||||||
end;
|
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.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user