Cocoa: support keyboard in TCustomComboBox (TCocoaReadOnlyComboBox)

This commit is contained in:
rich2014 2024-10-30 00:22:39 +08:00
parent a914ea80b1
commit db6685cd02
2 changed files with 8 additions and 4 deletions

View File

@ -319,7 +319,9 @@ type
TCocoaReadOnlyComboBoxMenuDelegate = objcclass( NSObject, NSMenuDelegateProtocol )
private
_lastHightlightItem: NSMenuItem;
_comboBox: NSPopUpButton;
procedure menu_willHighlightItem (menu: NSMenu; item: NSMenuItem);
procedure menuDidClose (menu: NSMenu);
end;
{ TCocoaReadOnlyComboBox }
@ -712,8 +714,6 @@ begin
if Assigned(combobox) then
begin
combobox.selectItemAtIndex(itemIndex);
combobox.callback.ComboBoxSelectionDidChange;
combobox.menu.performActionForItemAtIndex(itemIndex);
combobox.menu.cancelTracking;
end;
end;
@ -1608,6 +1608,7 @@ begin
Result:=inherited initWithFrame(frameRect);
_defaultItemHeight:= CocoaConfigComboBox.readOnly.item.defaultHeight;
_menuDelegate:= TCocoaReadOnlyComboBoxMenuDelegate.new;
_menuDelegate._comboBox:= self;
self.menu.setDelegate( _menuDelegate );
end;
@ -1867,6 +1868,11 @@ begin
_lastHightlightItem:= item;
end;
procedure TCocoaReadOnlyComboBoxMenuDelegate.menuDidClose(menu: NSMenu);
begin
TCocoaReadOnlyComboBox(_comboBox).comboboxAction( nil );
end;
{ TCocoaSpinEdit }
{$IFDEF COCOA_SPINEDIT_INSIDE_CONTAINER}

View File

@ -1977,8 +1977,6 @@ begin
if not Assigned(rocmb) then Exit;
rocmb.isComboBoxEx:= AWinControl is TCustomComboBoxEx;
rocmb.list:=TCocoaReadOnlyComboBoxList.Create(rocmb);
rocmb.setTarget(rocmb);
rocmb.setAction(objcselector('comboboxAction:'));
rocmb.lastSelectedItemIndex:= -1;
TComboBoxAsyncHelper.SetLastIndex(rocmb);
rocmb.callback:=TLCLComboboxCallback.Create(rocmb, AWinControl);