mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-07 22:58:14 +02:00
Cocoa/Toolbar: add callback for Menu TooItem, convenient to build the menu later
This commit is contained in:
parent
fd73e63c77
commit
8ca52c8948
@ -13,8 +13,6 @@ uses
|
||||
CocoaAll, Cocoa_Extra, CocoaConst;
|
||||
|
||||
type
|
||||
TCocoaToolBarItemActionHandler = procedure ( const Sender: id );
|
||||
|
||||
TCocoaConfigToolBarItemClassAbstract = class
|
||||
public
|
||||
function identifier: NSString; virtual; abstract;
|
||||
@ -23,6 +21,14 @@ type
|
||||
|
||||
TCocoaConfigToolBarItems = Array of TCocoaConfigToolBarItemClassAbstract;
|
||||
|
||||
type
|
||||
TCocoaToolBarItemCreator = function ( const identifier: String;
|
||||
const items: TCocoaConfigToolBarItems ): NSToolbarItem;
|
||||
TCocoaToolBarItemActionHandler = procedure ( const Sender: id );
|
||||
TCocoaToolBarItemMenuOnGetMenu = function: TMenuItem;
|
||||
TCocoaToolBarItemSharingOnGetItems = function ( item: NSToolBarItem ): TStringArray;
|
||||
|
||||
type
|
||||
{ TCocoaConfigToolBarItemBase }
|
||||
|
||||
TCocoaConfigToolBarItemBase = object
|
||||
@ -49,7 +55,7 @@ type
|
||||
TCocoaConfigToolBarItem = TCocoaConfigToolBarItemWithAction;
|
||||
|
||||
TCocoaConfigToolBarItemSharing = object( TCocoaConfigToolBarItemWithUI )
|
||||
onGetItems: Pointer;
|
||||
onGetItems: TCocoaToolBarItemSharingOnGetItems;
|
||||
end;
|
||||
|
||||
TCocoaConfigToolBarItemSearch = object( TCocoaConfigToolBarItemWithAction )
|
||||
@ -62,6 +68,7 @@ type
|
||||
TCocoaConfigToolBarItemMenu = object( TCocoaConfigToolBarItemWithAction )
|
||||
showsIndicator: Boolean;
|
||||
menu: TMenuItem;
|
||||
onGetMenu: TCocoaToolBarItemMenuOnGetMenu;
|
||||
end;
|
||||
|
||||
TCocoaConfigToolBarItemGroup = object( TCocoaConfigToolBarItemWithAction )
|
||||
|
@ -13,8 +13,6 @@ uses
|
||||
Cocoa_Extra, CocoaUtils;
|
||||
|
||||
type
|
||||
TCocoaToolBarItemSharingOnGetItems = function ( item: NSToolBarItem ): TStringArray;
|
||||
|
||||
PCocoaConfigToolBar = ^TCocoaConfigToolBar;
|
||||
|
||||
PCocoaConfigToolBarItemBase = ^TCocoaConfigToolBarItemBase;
|
||||
@ -109,6 +107,7 @@ type
|
||||
protected
|
||||
_showsIndicator: Boolean;
|
||||
_menu: TMenuItem;
|
||||
_onGetMenu: TCocoaToolBarItemMenuOnGetMenu;
|
||||
public
|
||||
constructor Create( const itemConfig: TCocoaConfigToolBarItemMenu );
|
||||
function createItem: NSToolBarItem; override;
|
||||
@ -199,9 +198,6 @@ type
|
||||
message 'lclSetSelectedIndex:';
|
||||
end;
|
||||
|
||||
TCocoaToolBarItemCreator = function ( const identifier: String;
|
||||
const items: TCocoaConfigToolBarItems ): NSToolbarItem;
|
||||
|
||||
{ TCocoaToolBar }
|
||||
|
||||
TCocoaToolBar = objcclass( NSToolBar, NSToolbarDelegateProtocol )
|
||||
@ -719,6 +715,7 @@ begin
|
||||
self.toClassConfig( @itemConfig );
|
||||
_showsIndicator:= itemConfig.showsIndicator;
|
||||
_menu:= itemConfig.menu;
|
||||
_onGetMenu:= itemConfig.onGetMenu;
|
||||
end;
|
||||
|
||||
function TCocoaConfigToolBarItemClassMenu.createItem: NSToolBarItem;
|
||||
@ -732,6 +729,11 @@ begin
|
||||
if NOT Assigned(_onAction) then
|
||||
cocoaItem.setAction( nil );
|
||||
|
||||
if NOT Assigned(_menu) then begin
|
||||
if Assigned(_onGetMenu) then
|
||||
_menu:= _onGetMenu();
|
||||
end;
|
||||
|
||||
if Assigned(_menu) then begin
|
||||
cocoaMenu:= NSMenuItem(_menu.Handle).submenu;
|
||||
cocoaItem.setMenu( cocoaMenu );
|
||||
|
Loading…
Reference in New Issue
Block a user