mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-24 13:59:20 +02:00
Cocoa/ToolBar: refactor the Adapter that convert user friendly config data to Class
This commit is contained in:
parent
570bb27f8b
commit
e428d6a340
@ -1,7 +1,7 @@
|
|||||||
unit CocoaConfig;
|
unit CocoaConfig;
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
{$modeswitch objectivec1}
|
{$modeswitch objectivec2}
|
||||||
{$interfaces corba}
|
{$interfaces corba}
|
||||||
{$include cocoadefines.inc}
|
{$include cocoadefines.inc}
|
||||||
|
|
||||||
@ -13,44 +13,53 @@ uses
|
|||||||
CocoaAll, Cocoa_Extra, CocoaConst;
|
CocoaAll, Cocoa_Extra, CocoaConst;
|
||||||
|
|
||||||
type
|
type
|
||||||
TCocoaConfigToolBarItemAdapter = interface
|
TCocoaConfigToolBarItemClassAbstract = class
|
||||||
function createItem: NSToolBarItem;
|
public
|
||||||
function identifier: String;
|
function identifier: String; virtual; abstract;
|
||||||
function iconName: String;
|
function createItem: NSToolBarItem; virtual; abstract;
|
||||||
function title: String;
|
|
||||||
function tips: String;
|
|
||||||
function onClick: Pointer;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TCocoaConfigToolBarItems = Array of TCocoaConfigToolBarItemAdapter;
|
TCocoaConfigToolBarItems = Array of TCocoaConfigToolBarItemClassAbstract;
|
||||||
|
|
||||||
{ TCocoaConfigToolBarItem }
|
{ TCocoaConfigToolBarItemBase }
|
||||||
|
|
||||||
TCocoaConfigToolBarItem = object
|
TCocoaConfigToolBarItemBase = object
|
||||||
identifier: String;
|
identifier: String;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaConfigToolBarItemWithUI }
|
||||||
|
|
||||||
|
TCocoaConfigToolBarItemWithUI = object( TCocoaConfigToolBarItemBase )
|
||||||
iconName: String;
|
iconName: String;
|
||||||
title: String;
|
title: String;
|
||||||
tips: String;
|
tips: String;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaConfigToolBarItemWithAction }
|
||||||
|
|
||||||
|
TCocoaConfigToolBarItemWithAction = object( TCocoaConfigToolBarItemWithUI )
|
||||||
onClick: Pointer;
|
onClick: Pointer;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TCocoaConfigToolBarItemSharing = object( TCocoaConfigToolBarItem )
|
TCocoaConfigToolBarItem = TCocoaConfigToolBarItemWithAction;
|
||||||
|
|
||||||
|
TCocoaConfigToolBarItemSharing = object( TCocoaConfigToolBarItemWithUI )
|
||||||
onGetItems: Pointer;
|
onGetItems: Pointer;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TCocoaConfigToolBarItemSearch = object( TCocoaConfigToolBarItem )
|
TCocoaConfigToolBarItemSearch = object( TCocoaConfigToolBarItemWithAction )
|
||||||
sendWhole: Boolean;
|
sendWhole: Boolean;
|
||||||
sendImmediately: Boolean;
|
sendImmediately: Boolean;
|
||||||
resignsWithCancel: Boolean;
|
resignsWithCancel: Boolean;
|
||||||
preferredWidth: Double;
|
preferredWidth: Double;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TCocoaConfigToolBarItemMenu = object( TCocoaConfigToolBarItem )
|
TCocoaConfigToolBarItemMenu = object( TCocoaConfigToolBarItemWithAction )
|
||||||
showsIndicator: Boolean;
|
showsIndicator: Boolean;
|
||||||
menu: TMenuItem;
|
menu: TMenuItem;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TCocoaConfigToolBarItemGroup = object( TCocoaConfigToolBarItem )
|
TCocoaConfigToolBarItemGroup = object( TCocoaConfigToolBarItemWithAction )
|
||||||
representation: NSToolbarItemGroupControlRepresentation;
|
representation: NSToolbarItemGroupControlRepresentation;
|
||||||
selectionMode: NSToolbarItemGroupSelectionMode;
|
selectionMode: NSToolbarItemGroupSelectionMode;
|
||||||
selectedIndex: NSInteger;
|
selectedIndex: NSInteger;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
unit CocoaToolBar;
|
unit CocoaToolBar;
|
||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
{$interfaces corba}
|
|
||||||
{$modeswitch objectivec2}
|
{$modeswitch objectivec2}
|
||||||
|
{$interfaces corba}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
@ -14,32 +14,62 @@ uses
|
|||||||
type
|
type
|
||||||
TCocoaToolBarItemHandler = procedure ( Sender: id );
|
TCocoaToolBarItemHandler = procedure ( Sender: id );
|
||||||
TCocoaToolBarItemSharingOnGetItems = function ( item: NSToolBarItem ): TStringArray;
|
TCocoaToolBarItemSharingOnGetItems = function ( item: NSToolBarItem ): TStringArray;
|
||||||
|
|
||||||
|
PCocoaConfigToolBarItemBase = ^TCocoaConfigToolBarItemBase;
|
||||||
|
PCocoaConfigToolBarItemWithUI = ^TCocoaConfigToolBarItemWithUI;
|
||||||
|
PCocoaConfigToolBarItemWithAction = ^TCocoaConfigToolBarItemWithAction;
|
||||||
PCocoaConfigToolBarItem = ^TCocoaConfigToolBarItem;
|
PCocoaConfigToolBarItem = ^TCocoaConfigToolBarItem;
|
||||||
|
|
||||||
{ TCocoaConfigToolBarItemAdapterBase }
|
{ TCocoaConfigToolBarItemClassBase }
|
||||||
|
|
||||||
TCocoaConfigToolBarItemAdapterBase = class( TCocoaConfigToolBarItemAdapter )
|
TCocoaConfigToolBarItemClassBase = class( TCocoaConfigToolBarItemClassAbstract )
|
||||||
protected
|
protected
|
||||||
_identifier: String;
|
_identifier: String;
|
||||||
|
protected
|
||||||
|
procedure toClassConfig( pItemConfig: PCocoaConfigToolBarItemBase );
|
||||||
|
public
|
||||||
|
procedure setItemAttribs( item: NSToolBarItem ); virtual;
|
||||||
|
function identifier: String; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaConfigToolBarItemClassWithUI }
|
||||||
|
|
||||||
|
TCocoaConfigToolBarItemClassWithUI = class( TCocoaConfigToolBarItemClassBase )
|
||||||
|
protected
|
||||||
_iconName: String;
|
_iconName: String;
|
||||||
_title: String;
|
_title: String;
|
||||||
_tips: String;
|
_tips: String;
|
||||||
_onClick: Pointer;
|
|
||||||
protected
|
protected
|
||||||
procedure initItemConfig( pItemConfig: PCocoaConfigToolBarItem );
|
procedure toClassConfig( pItemConfig: PCocoaConfigToolBarItemWithUI );
|
||||||
public
|
public
|
||||||
constructor Create( itemConfig: TCocoaConfigToolBarItem );
|
procedure setItemAttribs( item: NSToolBarItem ); override;
|
||||||
function createItem: NSToolBarItem; virtual;
|
|
||||||
function identifier: String; virtual;
|
|
||||||
function iconName: String; virtual;
|
function iconName: String; virtual;
|
||||||
function title: String; virtual;
|
function title: String; virtual;
|
||||||
function tips: String; virtual;
|
function tips: String; virtual;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaConfigToolBarItemClassWithAction }
|
||||||
|
|
||||||
|
TCocoaConfigToolBarItemClassWithAction = class( TCocoaConfigToolBarItemClassWithUI )
|
||||||
|
protected
|
||||||
|
_onClick: Pointer;
|
||||||
|
protected
|
||||||
|
procedure toClassConfig( pItemConfig: PCocoaConfigToolBarItemWithAction );
|
||||||
|
public
|
||||||
|
procedure setItemAttribs( item: NSToolBarItem ); override;
|
||||||
function onClick: Pointer; virtual;
|
function onClick: Pointer; virtual;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaConfigToolBarItemAdapterSharing }
|
{ TCocoaConfigToolBarItemClass }
|
||||||
|
|
||||||
TCocoaConfigToolBarItemAdapterSharing = class( TCocoaConfigToolBarItemAdapterBase )
|
TCocoaConfigToolBarItemClass = class( TCocoaConfigToolBarItemClassWithAction )
|
||||||
|
constructor Create( itemConfig: TCocoaConfigToolBarItem );
|
||||||
|
function createItem: NSToolBarItem; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaConfigToolBarItemClassSharing }
|
||||||
|
|
||||||
|
TCocoaConfigToolBarItemClassSharing = class( TCocoaConfigToolBarItemClassWithUI )
|
||||||
protected
|
protected
|
||||||
_onGetItems: TCocoaToolBarItemSharingOnGetItems;
|
_onGetItems: TCocoaToolBarItemSharingOnGetItems;
|
||||||
public
|
public
|
||||||
@ -48,9 +78,9 @@ type
|
|||||||
function onGetItems: TCocoaToolBarItemSharingOnGetItems;
|
function onGetItems: TCocoaToolBarItemSharingOnGetItems;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaConfigToolBarItemAdapterSearch }
|
{ TCocoaConfigToolBarItemClassSearch }
|
||||||
|
|
||||||
TCocoaConfigToolBarItemAdapterSearch = class( TCocoaConfigToolBarItemAdapterBase )
|
TCocoaConfigToolBarItemClassSearch = class( TCocoaConfigToolBarItemClassWithAction )
|
||||||
protected
|
protected
|
||||||
_sendWhole: Boolean;
|
_sendWhole: Boolean;
|
||||||
_sendImmediately: Boolean;
|
_sendImmediately: Boolean;
|
||||||
@ -65,9 +95,9 @@ type
|
|||||||
function preferredWidth: Double;
|
function preferredWidth: Double;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaConfigToolBarItemAdapterMenu }
|
{ TCocoaConfigToolBarItemClassMenu }
|
||||||
|
|
||||||
TCocoaConfigToolBarItemAdapterMenu = class( TCocoaConfigToolBarItemAdapterBase )
|
TCocoaConfigToolBarItemClassMenu = class( TCocoaConfigToolBarItemClassWithAction )
|
||||||
protected
|
protected
|
||||||
_showsIndicator: Boolean;
|
_showsIndicator: Boolean;
|
||||||
_menu: TMenuItem;
|
_menu: TMenuItem;
|
||||||
@ -78,9 +108,9 @@ type
|
|||||||
function menu: TMenuItem;
|
function menu: TMenuItem;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaConfigToolBarItemAdapterGroup }
|
{ TCocoaConfigToolBarItemClassGroup }
|
||||||
|
|
||||||
TCocoaConfigToolBarItemAdapterGroup = class( TCocoaConfigToolBarItemAdapterBase )
|
TCocoaConfigToolBarItemClassGroup = class( TCocoaConfigToolBarItemClassWithAction )
|
||||||
protected
|
protected
|
||||||
_representation: NSToolbarItemGroupControlRepresentation;
|
_representation: NSToolbarItemGroupControlRepresentation;
|
||||||
_selectionMode: NSToolbarItemGroupSelectionMode;
|
_selectionMode: NSToolbarItemGroupSelectionMode;
|
||||||
@ -197,19 +227,18 @@ type
|
|||||||
{ TCocoaToolBarUtils }
|
{ TCocoaToolBarUtils }
|
||||||
|
|
||||||
TCocoaToolBarUtils = class
|
TCocoaToolBarUtils = class
|
||||||
private
|
|
||||||
class procedure initItemCommonData( item: NSToolBarItem; itemConfig: TCocoaConfigToolBarItemAdapter );
|
|
||||||
public
|
public
|
||||||
class function forItem( itemConfig: TCocoaConfigToolBarItem ):
|
class function toClass( itemConfig: TCocoaConfigToolBarItem ):
|
||||||
TCocoaConfigToolBarItemAdapter;
|
TCocoaConfigToolBarItemClassAbstract;
|
||||||
class function forItem( itemConfig: TCocoaConfigToolBarItemSharing ):
|
class function toClass( itemConfig: TCocoaConfigToolBarItemSharing ):
|
||||||
TCocoaConfigToolBarItemAdapter;
|
TCocoaConfigToolBarItemClassAbstract;
|
||||||
class function forItem( itemConfig: TCocoaConfigToolBarItemSearch ):
|
class function toClass( itemConfig: TCocoaConfigToolBarItemSearch ):
|
||||||
TCocoaConfigToolBarItemAdapter;
|
TCocoaConfigToolBarItemClassAbstract;
|
||||||
class function forItem( itemConfig: TCocoaConfigToolBarItemMenu ):
|
class function toClass( itemConfig: TCocoaConfigToolBarItemMenu ):
|
||||||
TCocoaConfigToolBarItemAdapter;
|
TCocoaConfigToolBarItemClassAbstract;
|
||||||
class function forItem( itemConfig: TCocoaConfigToolBarItemGroup ):
|
class function toClass( itemConfig: TCocoaConfigToolBarItemGroup ):
|
||||||
TCocoaConfigToolBarItemAdapter;
|
TCocoaConfigToolBarItemClassAbstract;
|
||||||
|
public
|
||||||
class function createItem( identifier: String; itemsConfig: TCocoaConfigToolBarItems ): NSToolbarItem;
|
class function createItem( identifier: String; itemsConfig: TCocoaConfigToolBarItems ): NSToolbarItem;
|
||||||
class procedure createToolBar( win: NSWindow );
|
class procedure createToolBar( win: NSWindow );
|
||||||
end;
|
end;
|
||||||
@ -218,58 +247,34 @@ type
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
class procedure TCocoaToolBarUtils.initItemCommonData( item: NSToolBarItem;
|
class function TCocoaToolBarUtils.toClass(itemConfig: TCocoaConfigToolBarItem
|
||||||
itemConfig: TCocoaConfigToolBarItemAdapter );
|
): TCocoaConfigToolBarItemClassAbstract;
|
||||||
var
|
|
||||||
cocoaImageName: NSString;
|
|
||||||
cocoaLabel: NSString;
|
|
||||||
cocoaTips: NSString;
|
|
||||||
begin
|
begin
|
||||||
cocoaImageName:= StrToNSString( itemConfig.iconName );
|
Result:= TCocoaConfigToolBarItemClass.Create( itemConfig );
|
||||||
cocoaLabel:= StrToNSString( itemConfig.title );
|
|
||||||
cocoaTips:= StrToNSString( itemConfig.tips );
|
|
||||||
|
|
||||||
if cocoaImageName.length > 0 then begin
|
|
||||||
item.setImage( NSImage.imageWithSystemSymbolName_accessibilityDescription(
|
|
||||||
cocoaImageName, nil ) );
|
|
||||||
end;
|
|
||||||
item.setLabel( cocoaLabel );
|
|
||||||
item.setPaletteLabel( cocoaLabel );
|
|
||||||
item.setToolTip( cocoaTips );
|
|
||||||
item.setBordered( True );
|
|
||||||
item.setVisibilityPriority( NSToolbarItemVisibilityPriorityHigh );
|
|
||||||
item.setTarget( item );
|
|
||||||
item.setAction( ObjCSelector('lclItemAction:') );
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCocoaToolBarUtils.forItem(itemConfig: TCocoaConfigToolBarItem
|
class function TCocoaToolBarUtils.toClass( itemConfig: TCocoaConfigToolBarItemSharing
|
||||||
): TCocoaConfigToolBarItemAdapter;
|
): TCocoaConfigToolBarItemClassAbstract;
|
||||||
begin
|
begin
|
||||||
Result:= TCocoaConfigToolBarItemAdapterBase.Create( itemConfig );
|
Result:= TCocoaConfigToolBarItemClassSharing.Create( itemConfig );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCocoaToolBarUtils.forItem( itemConfig: TCocoaConfigToolBarItemSharing
|
class function TCocoaToolBarUtils.toClass( itemConfig: TCocoaConfigToolBarItemSearch
|
||||||
): TCocoaConfigToolBarItemAdapter;
|
): TCocoaConfigToolBarItemClassAbstract;
|
||||||
begin
|
begin
|
||||||
Result:= TCocoaConfigToolBarItemAdapterSharing.Create( itemConfig );
|
Result:= TCocoaConfigToolBarItemClassSearch.Create( itemConfig );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCocoaToolBarUtils.forItem( itemConfig: TCocoaConfigToolBarItemSearch
|
class function TCocoaToolBarUtils.toClass( itemConfig: TCocoaConfigToolBarItemMenu
|
||||||
): TCocoaConfigToolBarItemAdapter;
|
): TCocoaConfigToolBarItemClassAbstract;
|
||||||
begin
|
begin
|
||||||
Result:= TCocoaConfigToolBarItemAdapterSearch.Create( itemConfig );
|
Result:= TCocoaConfigToolBarItemClassMenu.Create( itemConfig );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCocoaToolBarUtils.forItem( itemConfig: TCocoaConfigToolBarItemMenu
|
class function TCocoaToolBarUtils.toClass( itemConfig: TCocoaConfigToolBarItemGroup
|
||||||
): TCocoaConfigToolBarItemAdapter;
|
): TCocoaConfigToolBarItemClassAbstract;
|
||||||
begin
|
begin
|
||||||
Result:= TCocoaConfigToolBarItemAdapterMenu.Create( itemConfig );
|
Result:= TCocoaConfigToolBarItemClassGroup.Create( itemConfig );
|
||||||
end;
|
|
||||||
|
|
||||||
class function TCocoaToolBarUtils.forItem( itemConfig: TCocoaConfigToolBarItemGroup
|
|
||||||
): TCocoaConfigToolBarItemAdapter;
|
|
||||||
begin
|
|
||||||
Result:= TCocoaConfigToolBarItemAdapterGroup.Create( itemConfig );
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCocoaToolBarUtils.createItem( identifier: String;
|
class function TCocoaToolBarUtils.createItem( identifier: String;
|
||||||
@ -489,72 +494,127 @@ begin
|
|||||||
_allowedItemIdentifiers.retain;
|
_allowedItemIdentifiers.retain;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaConfigToolBarItemAdapterBase }
|
{ TCocoaConfigToolBarItemClassBase }
|
||||||
|
|
||||||
procedure TCocoaConfigToolBarItemAdapterBase.initItemConfig(
|
procedure TCocoaConfigToolBarItemClassBase.toClassConfig(
|
||||||
pItemConfig: PCocoaConfigToolBarItem);
|
pItemConfig: PCocoaConfigToolBarItemBase);
|
||||||
begin
|
begin
|
||||||
_identifier:= pItemConfig^.identifier;
|
_identifier:= pItemConfig^.identifier;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaConfigToolBarItemClassBase.setItemAttribs(item: NSToolBarItem);
|
||||||
|
begin
|
||||||
|
item.setBordered( True );
|
||||||
|
item.setVisibilityPriority( NSToolbarItemVisibilityPriorityHigh );
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCocoaConfigToolBarItemClassBase.identifier: String;
|
||||||
|
begin
|
||||||
|
Result:= _identifier;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaConfigToolBarItemClassWithUI }
|
||||||
|
|
||||||
|
procedure TCocoaConfigToolBarItemClassWithUI.toClassConfig(
|
||||||
|
pItemConfig: PCocoaConfigToolBarItemWithUI );
|
||||||
|
begin
|
||||||
|
Inherited toClassConfig( pItemConfig );
|
||||||
_iconName:= pItemConfig^.iconName;
|
_iconName:= pItemConfig^.iconName;
|
||||||
_title:= pItemConfig^.title;
|
_title:= pItemConfig^.title;
|
||||||
_tips:= pItemConfig^.tips;
|
_tips:= pItemConfig^.tips;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaConfigToolBarItemClassWithUI.setItemAttribs(item: NSToolBarItem
|
||||||
|
);
|
||||||
|
var
|
||||||
|
cocoaImageName: NSString;
|
||||||
|
cocoaLabel: NSString;
|
||||||
|
cocoaTips: NSString;
|
||||||
|
begin
|
||||||
|
Inherited;
|
||||||
|
|
||||||
|
cocoaImageName:= StrToNSString( self.iconName );
|
||||||
|
cocoaLabel:= StrToNSString( self.title );
|
||||||
|
cocoaTips:= StrToNSString( self.tips );
|
||||||
|
|
||||||
|
if cocoaImageName.length > 0 then begin
|
||||||
|
item.setImage( NSImage.imageWithSystemSymbolName_accessibilityDescription(
|
||||||
|
cocoaImageName, nil ) );
|
||||||
|
end;
|
||||||
|
item.setLabel( cocoaLabel );
|
||||||
|
item.setPaletteLabel( cocoaLabel );
|
||||||
|
item.setToolTip( cocoaTips );
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCocoaConfigToolBarItemClassWithUI.iconName: String;
|
||||||
|
begin
|
||||||
|
Result:= _iconName;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCocoaConfigToolBarItemClassWithUI.title: String;
|
||||||
|
begin
|
||||||
|
Result:= _title;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCocoaConfigToolBarItemClassWithUI.tips: String;
|
||||||
|
begin
|
||||||
|
Result:= _tips;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaConfigToolBarItemClassWithAction }
|
||||||
|
|
||||||
|
procedure TCocoaConfigToolBarItemClassWithAction.toClassConfig(
|
||||||
|
pItemConfig: PCocoaConfigToolBarItemWithAction );
|
||||||
|
begin
|
||||||
|
Inherited toClassConfig( pItemConfig );
|
||||||
_onClick:= pItemConfig^.onClick;
|
_onClick:= pItemConfig^.onClick;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TCocoaConfigToolBarItemAdapterBase.Create(
|
procedure TCocoaConfigToolBarItemClassWithAction.setItemAttribs(
|
||||||
itemConfig: TCocoaConfigToolBarItem );
|
item: NSToolBarItem);
|
||||||
begin
|
begin
|
||||||
self.initItemConfig( @itemConfig );
|
inherited setItemAttribs(item);
|
||||||
|
item.setTarget( item );
|
||||||
|
item.setAction( ObjCSelector('lclItemAction:') );
|
||||||
|
if item.respondsToSelector( ObjCSelector('lclSetHandler:') ) then
|
||||||
|
item.performSelector_withObject( ObjCSelector('lclSetHandler:'), self.onClick );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterBase.createItem: NSToolBarItem;
|
function TCocoaConfigToolBarItemClassWithAction.onClick: Pointer;
|
||||||
|
begin
|
||||||
|
Result:= _onClick;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TCocoaConfigToolBarItemClass }
|
||||||
|
|
||||||
|
constructor TCocoaConfigToolBarItemClass.Create(
|
||||||
|
itemConfig: TCocoaConfigToolBarItem );
|
||||||
|
begin
|
||||||
|
Inherited toClassConfig( @ItemConfig );
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TCocoaConfigToolBarItemClass.createItem: NSToolBarItem;
|
||||||
var
|
var
|
||||||
cocoaIdentifier: NSString;
|
cocoaIdentifier: NSString;
|
||||||
cocoaItem: TCocoaToolBarItem;
|
cocoaItem: TCocoaToolBarItem;
|
||||||
begin
|
begin
|
||||||
cocoaIdentifier:= StrToNSString( self.identifier );
|
cocoaIdentifier:= StrToNSString( self.identifier );
|
||||||
cocoaItem:= TCocoaToolBarItem.alloc.initWithItemIdentifier( cocoaIdentifier );
|
cocoaItem:= TCocoaToolBarItem.alloc.initWithItemIdentifier( cocoaIdentifier );
|
||||||
TCocoaToolBarUtils.initItemCommonData( cocoaItem, self );
|
self.setItemAttribs( cocoaItem );
|
||||||
cocoaItem.lclSetHandler( TCocoaToolBarItemHandler(self.onClick) );
|
|
||||||
cocoaItem.autorelease;
|
cocoaItem.autorelease;
|
||||||
Result:= cocoaItem;
|
Result:= cocoaItem;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterBase.identifier: String;
|
{ TCocoaConfigToolBarItemClassSharing }
|
||||||
begin
|
|
||||||
Result:= _identifier;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterBase.iconName: String;
|
constructor TCocoaConfigToolBarItemClassSharing.Create(
|
||||||
begin
|
|
||||||
Result:= _iconName;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterBase.title: String;
|
|
||||||
begin
|
|
||||||
Result:= _title;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterBase.tips: String;
|
|
||||||
begin
|
|
||||||
Result:= _tips;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterBase.onClick: Pointer;
|
|
||||||
begin
|
|
||||||
Result:= _onClick;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TCocoaConfigToolBarItemAdapterSharing }
|
|
||||||
|
|
||||||
constructor TCocoaConfigToolBarItemAdapterSharing.Create(
|
|
||||||
itemConfig: TCocoaConfigToolBarItemSharing);
|
itemConfig: TCocoaConfigToolBarItemSharing);
|
||||||
begin
|
begin
|
||||||
self.initItemConfig( @itemConfig );
|
self.toClassConfig( @itemConfig );
|
||||||
_onGetItems:= TCocoaToolBarItemSharingOnGetItems( itemConfig.onGetItems );
|
_onGetItems:= TCocoaToolBarItemSharingOnGetItems( itemConfig.onGetItems );
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterSharing.createItem: NSToolBarItem;
|
function TCocoaConfigToolBarItemClassSharing.createItem: NSToolBarItem;
|
||||||
var
|
var
|
||||||
cocoaIdentifier: NSString;
|
cocoaIdentifier: NSString;
|
||||||
cocoaItem: TCocoaToolBarItemSharing;
|
cocoaItem: TCocoaToolBarItemSharing;
|
||||||
@ -562,7 +622,7 @@ var
|
|||||||
begin
|
begin
|
||||||
cocoaIdentifier:= StrToNSString( self.identifier );
|
cocoaIdentifier:= StrToNSString( self.identifier );
|
||||||
cocoaItem:= TCocoaToolBarItemSharing.alloc.initWithItemIdentifier( cocoaIdentifier );
|
cocoaItem:= TCocoaToolBarItemSharing.alloc.initWithItemIdentifier( cocoaIdentifier );
|
||||||
TCocoaToolBarUtils.initItemCommonData( cocoaItem, self );
|
self.setItemAttribs( cocoaItem );
|
||||||
cocoaItem.setAutovalidates( False );
|
cocoaItem.setAutovalidates( False );
|
||||||
|
|
||||||
// release in TCocoaToolBarItemSharing
|
// release in TCocoaToolBarItemSharing
|
||||||
@ -574,24 +634,24 @@ begin
|
|||||||
Result:= cocoaItem;
|
Result:= cocoaItem;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterSharing.onGetItems: TCocoaToolBarItemSharingOnGetItems;
|
function TCocoaConfigToolBarItemClassSharing.onGetItems: TCocoaToolBarItemSharingOnGetItems;
|
||||||
begin
|
begin
|
||||||
Result:= _onGetItems;
|
Result:= _onGetItems;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaConfigToolBarItemAdapterSearch }
|
{ TCocoaConfigToolBarItemClassSearch }
|
||||||
|
|
||||||
constructor TCocoaConfigToolBarItemAdapterSearch.Create(
|
constructor TCocoaConfigToolBarItemClassSearch.Create(
|
||||||
itemConfig: TCocoaConfigToolBarItemSearch);
|
itemConfig: TCocoaConfigToolBarItemSearch);
|
||||||
begin
|
begin
|
||||||
self.initItemConfig( @itemConfig );
|
self.toClassConfig( @itemConfig );
|
||||||
_sendWhole:= itemConfig.sendWhole;
|
_sendWhole:= itemConfig.sendWhole;
|
||||||
_sendImmediately:= itemConfig.sendImmediately;
|
_sendImmediately:= itemConfig.sendImmediately;
|
||||||
_resignsWithCancel:= itemConfig.resignsWithCancel;
|
_resignsWithCancel:= itemConfig.resignsWithCancel;
|
||||||
_preferredWidth:= itemConfig.preferredWidth;
|
_preferredWidth:= itemConfig.preferredWidth;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterSearch.createItem: NSToolBarItem;
|
function TCocoaConfigToolBarItemClassSearch.createItem: NSToolBarItem;
|
||||||
var
|
var
|
||||||
cocoaIdentifier: NSString;
|
cocoaIdentifier: NSString;
|
||||||
cocoaItem: TCocoaToolBarItemSearch;
|
cocoaItem: TCocoaToolBarItemSearch;
|
||||||
@ -604,43 +664,42 @@ begin
|
|||||||
cocoaItem.setResignsFirstResponderWithCancel( self.resignsWithCancel );
|
cocoaItem.setResignsFirstResponderWithCancel( self.resignsWithCancel );
|
||||||
if self.preferredWidth > 0 then
|
if self.preferredWidth > 0 then
|
||||||
cocoaItem.setPreferredWidthForSearchField( self.preferredWidth );
|
cocoaItem.setPreferredWidthForSearchField( self.preferredWidth );
|
||||||
TCocoaToolBarUtils.initItemCommonData( cocoaItem, self );
|
self.setItemAttribs( cocoaItem );
|
||||||
cocoaItem.lclSetHandler( TCocoaToolBarItemHandler(self.onClick) );
|
|
||||||
cocoaItem.autorelease;
|
cocoaItem.autorelease;
|
||||||
Result:= cocoaItem;
|
Result:= cocoaItem;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterSearch.sendWhole: Boolean;
|
function TCocoaConfigToolBarItemClassSearch.sendWhole: Boolean;
|
||||||
begin
|
begin
|
||||||
Result:= _sendWhole;
|
Result:= _sendWhole;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterSearch.sendImmediately: Boolean;
|
function TCocoaConfigToolBarItemClassSearch.sendImmediately: Boolean;
|
||||||
begin
|
begin
|
||||||
Result:= _sendImmediately;
|
Result:= _sendImmediately;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterSearch.resignsWithCancel: Boolean;
|
function TCocoaConfigToolBarItemClassSearch.resignsWithCancel: Boolean;
|
||||||
begin
|
begin
|
||||||
Result:= _resignsWithCancel;
|
Result:= _resignsWithCancel;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterSearch.preferredWidth: Double;
|
function TCocoaConfigToolBarItemClassSearch.preferredWidth: Double;
|
||||||
begin
|
begin
|
||||||
Result:= _preferredWidth;
|
Result:= _preferredWidth;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaConfigToolBarItemAdapterMenu }
|
{ TCocoaConfigToolBarItemClassMenu }
|
||||||
|
|
||||||
constructor TCocoaConfigToolBarItemAdapterMenu.Create(
|
constructor TCocoaConfigToolBarItemClassMenu.Create(
|
||||||
itemConfig: TCocoaConfigToolBarItemMenu);
|
itemConfig: TCocoaConfigToolBarItemMenu);
|
||||||
begin
|
begin
|
||||||
self.initItemConfig( @itemConfig );
|
self.toClassConfig( @itemConfig );
|
||||||
_showsIndicator:= itemConfig.showsIndicator;
|
_showsIndicator:= itemConfig.showsIndicator;
|
||||||
_menu:= itemConfig.menu;
|
_menu:= itemConfig.menu;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterMenu.createItem: NSToolBarItem;
|
function TCocoaConfigToolBarItemClassMenu.createItem: NSToolBarItem;
|
||||||
var
|
var
|
||||||
cocoaIdentifier: NSString;
|
cocoaIdentifier: NSString;
|
||||||
cocoaItem: TCocoaToolBarItemMenu;
|
cocoaItem: TCocoaToolBarItemMenu;
|
||||||
@ -649,10 +708,8 @@ begin
|
|||||||
cocoaIdentifier:= StrToNSString( self.identifier );
|
cocoaIdentifier:= StrToNSString( self.identifier );
|
||||||
cocoaItem:= TCocoaToolBarItemMenu.alloc.initWithItemIdentifier( cocoaIdentifier );
|
cocoaItem:= TCocoaToolBarItemMenu.alloc.initWithItemIdentifier( cocoaIdentifier );
|
||||||
cocoaItem.setShowsIndicator( self.showsIndicator );
|
cocoaItem.setShowsIndicator( self.showsIndicator );
|
||||||
TCocoaToolBarUtils.initItemCommonData( cocoaItem, self );
|
self.setItemAttribs( cocoaItem );
|
||||||
if Assigned(self.onClick) then
|
if NOT Assigned(self.onClick) then
|
||||||
cocoaItem.lclSetHandler( TCocoaToolBarItemHandler(self.onClick) )
|
|
||||||
else
|
|
||||||
cocoaItem.setAction( nil );
|
cocoaItem.setAction( nil );
|
||||||
|
|
||||||
cocoaMenu:= NSMenu.new;
|
cocoaMenu:= NSMenu.new;
|
||||||
@ -664,29 +721,29 @@ begin
|
|||||||
Result:= cocoaItem;
|
Result:= cocoaItem;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterMenu.showsIndicator: Boolean;
|
function TCocoaConfigToolBarItemClassMenu.showsIndicator: Boolean;
|
||||||
begin
|
begin
|
||||||
Result:= _showsIndicator;
|
Result:= _showsIndicator;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterMenu.menu: TMenuItem;
|
function TCocoaConfigToolBarItemClassMenu.menu: TMenuItem;
|
||||||
begin
|
begin
|
||||||
Result:= _menu;
|
Result:= _menu;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaConfigToolBarItemAdapterGroup }
|
{ TCocoaConfigToolBarItemClassGroup }
|
||||||
|
|
||||||
constructor TCocoaConfigToolBarItemAdapterGroup.Create(
|
constructor TCocoaConfigToolBarItemClassGroup.Create(
|
||||||
itemConfig: TCocoaConfigToolBarItemGroup);
|
itemConfig: TCocoaConfigToolBarItemGroup);
|
||||||
begin
|
begin
|
||||||
self.initItemConfig( @itemConfig );
|
self.toClassConfig( @itemConfig );
|
||||||
_representation:= itemConfig.representation;
|
_representation:= itemConfig.representation;
|
||||||
_selectionMode:= itemConfig.selectionMode;
|
_selectionMode:= itemConfig.selectionMode;
|
||||||
_selectedIndex:= itemConfig.selectedIndex;
|
_selectedIndex:= itemConfig.selectedIndex;
|
||||||
_subitems:= itemConfig.subitems;
|
_subitems:= itemConfig.subitems;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterGroup.createItem: NSToolBarItem;
|
function TCocoaConfigToolBarItemClassGroup.createItem: NSToolBarItem;
|
||||||
var
|
var
|
||||||
groupWrapper: TCocoaToolBarItemGroupWrapper;
|
groupWrapper: TCocoaToolBarItemGroupWrapper;
|
||||||
toolbarItem: NSToolbarItemGroup;
|
toolbarItem: NSToolbarItemGroup;
|
||||||
@ -703,8 +760,12 @@ var
|
|||||||
labels:= NSMutableArray.arrayWithCapacity( count );
|
labels:= NSMutableArray.arrayWithCapacity( count );
|
||||||
for i:=0 to count-1 do begin
|
for i:=0 to count-1 do begin
|
||||||
images.addObject( NSImage.imageWithSystemSymbolName_accessibilityDescription(
|
images.addObject( NSImage.imageWithSystemSymbolName_accessibilityDescription(
|
||||||
StrToNSString(self.subitems[i].iconName), nil) );
|
StrToNSString(
|
||||||
labels.addObject( StrToNSString(self.subitems[i].title) );
|
TCocoaConfigToolBarItemClass(
|
||||||
|
self.subitems[i]).iconName), nil) );
|
||||||
|
labels.addObject( StrToNSString(
|
||||||
|
TCocoaConfigToolBarItemClass(
|
||||||
|
self.subitems[i]).title) );
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -722,28 +783,27 @@ begin
|
|||||||
groupWrapper.lclSetItemGroup( toolbarItem );
|
groupWrapper.lclSetItemGroup( toolbarItem );
|
||||||
groupWrapper.lclSetSelectedIndex( self.selectedIndex );
|
groupWrapper.lclSetSelectedIndex( self.selectedIndex );
|
||||||
groupWrapper.lclSetHandler( TCocoaToolBarItemHandler(self.onClick) );
|
groupWrapper.lclSetHandler( TCocoaToolBarItemHandler(self.onClick) );
|
||||||
TCocoaToolBarUtils.initItemCommonData( toolbarItem, self );
|
self.setItemAttribs( toolbarItem );
|
||||||
toolbarItem.setTarget( groupWrapper );
|
toolbarItem.setTarget( groupWrapper );
|
||||||
toolbarItem.setAction( ObjCSelector('lclItemAction:') );
|
|
||||||
Result:= toolbarItem;
|
Result:= toolbarItem;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterGroup.representation: NSToolbarItemGroupControlRepresentation;
|
function TCocoaConfigToolBarItemClassGroup.representation: NSToolbarItemGroupControlRepresentation;
|
||||||
begin
|
begin
|
||||||
Result:= _representation;
|
Result:= _representation;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterGroup.selectionMode: NSToolbarItemGroupSelectionMode;
|
function TCocoaConfigToolBarItemClassGroup.selectionMode: NSToolbarItemGroupSelectionMode;
|
||||||
begin
|
begin
|
||||||
Result:= _selectionMode;
|
Result:= _selectionMode;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterGroup.selectedIndex: NSInteger;
|
function TCocoaConfigToolBarItemClassGroup.selectedIndex: NSInteger;
|
||||||
begin
|
begin
|
||||||
Result:= _selectedIndex;
|
Result:= _selectedIndex;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaConfigToolBarItemAdapterGroup.subitems: TCocoaConfigToolBarItems;
|
function TCocoaConfigToolBarItemClassGroup.subitems: TCocoaConfigToolBarItems;
|
||||||
begin
|
begin
|
||||||
Result:= _subitems;
|
Result:= _subitems;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user