mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-21 22:59:27 +02:00
Cocoa/Toolbar: implement NSSearchToolbarItem
This commit is contained in:
parent
333c34d7a4
commit
1c9ef29497
@ -475,9 +475,30 @@ type
|
||||
procedure setNavigational( newValue: Boolean ); message 'setNavigational:'; { available in 11.0 }
|
||||
end;
|
||||
|
||||
|
||||
NSSearchFieldDelegateProtocol = objcprotocol external (NSTextFieldDelegateProtocol)
|
||||
procedure searchFieldDidStartSearching( sender: NSSearchField );
|
||||
message 'searchFieldDidStartSearching:';
|
||||
procedure searchFieldDidEndSearching( sender: NSSearchField );
|
||||
message 'searchFieldDidEndSearching:';
|
||||
end;
|
||||
|
||||
NSSearchToolbarItem = objcclass external (NSToolBarItem)
|
||||
procedure setSearchField( newValue: NSSearchField );
|
||||
message 'setSearchField:'; { available in 11.0 }
|
||||
function searchField: NSSearchField;
|
||||
message 'searchField'; { available in 11.0 }
|
||||
|
||||
procedure setPreferredWidthForSearchField( newValue: CGFloat );
|
||||
message 'setPreferredWidthForSearchField:'; { available in 11.0 }
|
||||
|
||||
procedure setResignsFirstResponderWithCancel( newValue: Boolean );
|
||||
message 'setResignsFirstResponderWithCancel:'; { available in 11.0 }
|
||||
end;
|
||||
|
||||
NSSharingServicePickerToolbarItem = objcclass;
|
||||
|
||||
NSSharingServicePickerToolbarItemDelegateProtocol = objcprotocol
|
||||
NSSharingServicePickerToolbarItemDelegateProtocol = objcprotocol external name 'NSSharingServicePickerToolbarItemDelegate'
|
||||
function itemsForSharingServicePickerToolbarItem(
|
||||
pickerToolbarItem: NSSharingServicePickerToolbarItem ): NSArray;
|
||||
message 'itemsForSharingServicePickerToolbarItem:'; { available in 10.15 }
|
||||
|
@ -38,6 +38,13 @@ type
|
||||
onGetItems: Pointer;
|
||||
end;
|
||||
|
||||
TCocoaConfigToolBarItemSearch = object( TCocoaConfigToolBarItem )
|
||||
sendWhole: Boolean;
|
||||
sendImmediately: Boolean;
|
||||
resignsWithCancel: Boolean;
|
||||
preferredWidth: Double;
|
||||
end;
|
||||
|
||||
TCocoaConfigToolBarItemGroup = object( TCocoaConfigToolBarItem )
|
||||
representation: NSToolbarItemGroupControlRepresentation;
|
||||
selectionMode: NSToolbarItemGroupSelectionMode;
|
||||
|
@ -44,6 +44,21 @@ type
|
||||
function onClick: Pointer;
|
||||
end;
|
||||
|
||||
{ TCocoaConfigToolBarItemSearchClass }
|
||||
|
||||
TCocoaConfigToolBarItemSearchClass = class( TCocoaConfigToolBarItemInterface )
|
||||
private
|
||||
_itemConfig: TCocoaConfigToolBarItemSearch;
|
||||
public
|
||||
constructor Create( itemConfig: TCocoaConfigToolBarItemSearch );
|
||||
function createItem: NSToolBarItem;
|
||||
function identifier: String;
|
||||
function iconName: String;
|
||||
function title: String;
|
||||
function tips: String;
|
||||
function onClick: Pointer;
|
||||
end;
|
||||
|
||||
{ TCocoaConfigToolBarItemGroupClass }
|
||||
|
||||
TCocoaConfigToolBarItemGroupClass = class( TCocoaConfigToolBarItemInterface )
|
||||
@ -95,6 +110,21 @@ type
|
||||
procedure dealloc; override;
|
||||
end;
|
||||
|
||||
{ TCocoaToolBarItemSearch }
|
||||
|
||||
TCocoaToolBarItemSearch = objcclass( NSSearchToolBarItem, NSSearchFieldDelegateProtocol )
|
||||
private
|
||||
_isSearching: Boolean;
|
||||
_handler: TCocoaToolBarItemHandler;
|
||||
procedure lclItemAction( sender: id ); message 'lclItemAction:';
|
||||
public
|
||||
procedure searchFieldDidStartSearching( sender: NSSearchField );
|
||||
procedure searchFieldDidEndSearching( sender: NSSearchField );
|
||||
public
|
||||
procedure lclSetHandler( handler: TCocoaToolBarItemHandler );
|
||||
message 'lclSetHandler:';
|
||||
end;
|
||||
|
||||
{ TCocoaToolBarItemGroupWrapper }
|
||||
|
||||
TCocoaToolBarItemGroupWrapper = objcclass( NSObject )
|
||||
@ -147,6 +177,7 @@ type
|
||||
public
|
||||
class function forItem( itemsConfig: TCocoaConfigToolBarItem ): TCocoaConfigToolBarItemInterface;
|
||||
class function forItem( itemsConfig: TCocoaConfigToolBarItemSharing ): TCocoaConfigToolBarItemInterface;
|
||||
class function forItem( itemsConfig: TCocoaConfigToolBarItemSearch ): TCocoaConfigToolBarItemInterface;
|
||||
class function forItem( itemsConfig: TCocoaConfigToolBarItemGroup ): TCocoaConfigToolBarItemInterface;
|
||||
class function createItem( identifier: String; itemsConfig: TCocoaConfigToolBarItems ): NSToolbarItem;
|
||||
class procedure createToolBar( win: NSWindow );
|
||||
@ -192,6 +223,12 @@ begin
|
||||
Result:= TCocoaConfigToolBarItemSharingClass.Create( itemsConfig );
|
||||
end;
|
||||
|
||||
class function TCocoaToolBarUtils.forItem(
|
||||
itemsConfig: TCocoaConfigToolBarItemSearch): TCocoaConfigToolBarItemInterface;
|
||||
begin
|
||||
Result:= TCocoaConfigToolBarItemSearchClass.Create( itemsConfig );
|
||||
end;
|
||||
|
||||
class function TCocoaToolBarUtils.forItem(
|
||||
itemsConfig: TCocoaConfigToolBarItemGroup): TCocoaConfigToolBarItemInterface;
|
||||
begin
|
||||
@ -276,6 +313,32 @@ begin
|
||||
Inherited;
|
||||
end;
|
||||
|
||||
{ TCocoaToolBarItemSearch }
|
||||
|
||||
procedure TCocoaToolBarItemSearch.lclItemAction(sender: id);
|
||||
begin
|
||||
if _isSearching then
|
||||
_handler( sender );
|
||||
end;
|
||||
|
||||
procedure TCocoaToolBarItemSearch.searchFieldDidStartSearching(
|
||||
sender: NSSearchField);
|
||||
begin
|
||||
_isSearching:= True;
|
||||
end;
|
||||
|
||||
procedure TCocoaToolBarItemSearch.searchFieldDidEndSearching(
|
||||
sender: NSSearchField);
|
||||
begin
|
||||
_isSearching:= False;
|
||||
end;
|
||||
|
||||
procedure TCocoaToolBarItemSearch.lclSetHandler(
|
||||
handler: TCocoaToolBarItemHandler);
|
||||
begin
|
||||
_handler:= handler;
|
||||
end;
|
||||
|
||||
{ TCocoaToolBarItemGroupWrapper }
|
||||
|
||||
procedure TCocoaToolBarItemGroupWrapper.lclItemAction(sender: id);
|
||||
@ -476,6 +539,58 @@ begin
|
||||
Result:= nil;
|
||||
end;
|
||||
|
||||
{ TCocoaConfigToolBarItemSearchClass }
|
||||
|
||||
constructor TCocoaConfigToolBarItemSearchClass.Create(
|
||||
itemConfig: TCocoaConfigToolBarItemSearch );
|
||||
begin
|
||||
_itemConfig:= itemConfig;
|
||||
end;
|
||||
|
||||
function TCocoaConfigToolBarItemSearchClass.createItem: NSToolBarItem;
|
||||
var
|
||||
cocoaIdentifier: NSString;
|
||||
cocoaItem: TCocoaToolBarItemSearch;
|
||||
begin
|
||||
cocoaIdentifier:= StrToNSString( _itemConfig.identifier );
|
||||
cocoaItem:= TCocoaToolBarItemSearch.alloc.initWithItemIdentifier( cocoaIdentifier );
|
||||
cocoaItem.searchField.setSendsWholeSearchString( _itemConfig.sendWhole );
|
||||
cocoaItem.searchField.setSendsSearchStringImmediately( _itemConfig.sendImmediately );
|
||||
cocoaItem.searchField.setDelegate( NSTextFieldDelegateProtocol(cocoaItem) );
|
||||
cocoaItem.setResignsFirstResponderWithCancel( _itemConfig.resignsWithCancel );
|
||||
if _itemConfig.preferredWidth > 0 then
|
||||
cocoaItem.setPreferredWidthForSearchField( _itemConfig.preferredWidth );
|
||||
TCocoaToolBarUtils.initItemCommonData( cocoaItem, self );
|
||||
cocoaItem.lclSetHandler( TCocoaToolBarItemHandler(self.onClick) );
|
||||
cocoaItem.autorelease;
|
||||
Result:= cocoaItem;
|
||||
end;
|
||||
|
||||
function TCocoaConfigToolBarItemSearchClass.identifier: String;
|
||||
begin
|
||||
Result:= _itemConfig.identifier;
|
||||
end;
|
||||
|
||||
function TCocoaConfigToolBarItemSearchClass.iconName: String;
|
||||
begin
|
||||
Result:= _itemConfig.iconName;
|
||||
end;
|
||||
|
||||
function TCocoaConfigToolBarItemSearchClass.title: String;
|
||||
begin
|
||||
Result:= _itemConfig.title;
|
||||
end;
|
||||
|
||||
function TCocoaConfigToolBarItemSearchClass.tips: String;
|
||||
begin
|
||||
Result:= _itemConfig.tips;
|
||||
end;
|
||||
|
||||
function TCocoaConfigToolBarItemSearchClass.onClick: Pointer;
|
||||
begin
|
||||
Result:= _itemConfig.onClick;
|
||||
end;
|
||||
|
||||
{ TCocoaConfigToolBarItemGroupClass }
|
||||
|
||||
constructor TCocoaConfigToolBarItemGroupClass.Create(
|
||||
|
Loading…
Reference in New Issue
Block a user