cocoa: Fixes menuitem groupindex

git-svn-id: trunk@49758 -
This commit is contained in:
sekelsenmat 2015-09-05 07:46:33 +00:00
parent dabd4106ff
commit eedacb424f
2 changed files with 57 additions and 6 deletions

View File

@ -98,7 +98,7 @@ begin
Result := Handle <> 0; Result := Handle <> 0;
if Result then if Result then
NSObject(Handle).lclLocalToScreen(P.X, P.Y); NSObject(Handle).lclLocalToScreen(P.X, P.Y);
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------

View File

@ -45,9 +45,9 @@ type
TLCLMenuItemCallback = class(TLCLCommonCallback, IMenuItemCallback) TLCLMenuItemCallback = class(TLCLCommonCallback, IMenuItemCallback)
private private
FMenuItemTarget: TComponent; FMenuItemTarget: TMenuItem;
public public
constructor Create(AOwner: NSObject; AMenuItemTarget: TComponent); reintroduce; constructor Create(AOwner: NSObject; AMenuItemTarget: TMenuItem); reintroduce;
procedure ItemSelected; procedure ItemSelected;
end; end;
@ -65,8 +65,12 @@ type
public public
menuItemCallback: IMenuItemCallback; menuItemCallback: IMenuItemCallback;
attachedAppleMenuItems: Boolean; attachedAppleMenuItems: Boolean;
FMenuItemTarget: TMenuItem;
procedure UncheckSiblings; message 'UncheckSiblings';
function GetMenuItemHandle(): TMenuItem; message 'GetMenuItemHandle';
procedure lclItemSelected(sender: id); message 'lclItemSelected:'; procedure lclItemSelected(sender: id); message 'lclItemSelected:';
function lclGetCallback: IMenuItemCallback; override; function lclGetCallback: IMenuItemCallback; override;
procedure lclClearCallback; override;
function lclIsHandle: Boolean; override; function lclIsHandle: Boolean; override;
procedure attachAppleMenuItems(); message 'attachAppleMenuItems'; procedure attachAppleMenuItems(); message 'attachAppleMenuItems';
end; end;
@ -135,7 +139,7 @@ implementation
{ TLCLMenuItemCallback } { TLCLMenuItemCallback }
constructor TLCLMenuItemCallback.Create(AOwner: NSObject; AMenuItemTarget: TComponent); constructor TLCLMenuItemCallback.Create(AOwner: NSObject; AMenuItemTarget: TMenuItem);
begin begin
Owner := AOwner; Owner := AOwner;
FMenuItemTarget := AMenuItemTarget; FMenuItemTarget := AMenuItemTarget;
@ -170,9 +174,43 @@ begin
Result:=true; Result:=true;
end; end;
procedure TCocoaMenuItem.UncheckSiblings;
var
i: Integer;
lMenuItem, lSibling, lParentMenu: TMenuItem;
lSiblingHandle: NSMenuItem;
begin
//lMenuItem := GetMenuItemHandle();
lMenuItem := FMenuItemTarget;
if lMenuItem = nil then Exit;
if not lMenuItem.RadioItem then Exit;
if not lMenuItem.Checked then Exit;
lParentMenu := lMenuItem.Parent;
if lParentMenu = nil then Exit;
for i := 0 to lParentMenu.Count - 1 do
begin
lSibling := lParentMenu.Items[i];
if lSibling = nil then Continue;
if lSibling = lMenuItem then Continue;
if lSibling.RadioItem and (lSibling.GroupIndex = lMenuItem.GroupIndex) then
begin
TCocoaWSMenuItem.SetCheck(lSibling, False);
end;
end;
end;
function TCocoaMenuItem.GetMenuItemHandle(): TMenuItem;
begin
Result := nil;
if menuItemCallback = nil then Exit;
Result := TLCLMenuItemCallback(menuItemCallback).FMenuItemTarget;
end;
procedure TCocoaMenuItem.lclItemSelected(sender:id); procedure TCocoaMenuItem.lclItemSelected(sender:id);
begin begin
menuItemCallback.ItemSelected; menuItemCallback.ItemSelected;
UncheckSiblings();
end; end;
function TCocoaMenuItem.lclGetCallback: IMenuItemCallback; function TCocoaMenuItem.lclGetCallback: IMenuItemCallback;
@ -180,6 +218,11 @@ begin
result:=menuItemCallback; result:=menuItemCallback;
end; end;
procedure TCocoaMenuItem.lclClearCallback;
begin
menuItemCallback := nil;
end;
procedure TCocoaMenuItem.attachAppleMenuItems(); procedure TCocoaMenuItem.attachAppleMenuItems();
var var
item : NSMenuItem; item : NSMenuItem;
@ -345,7 +388,9 @@ begin
if not Assigned(AMenuItem) then Exit; if not Assigned(AMenuItem) then Exit;
if AMenuItem.Caption = '-' then if AMenuItem.Caption = '-' then
item := NSMenuItem.separatorItem begin
item := NSMenuItem.separatorItem;
end
else else
begin begin
s := AMenuItem.Caption; s := AMenuItem.Caption;
@ -357,6 +402,7 @@ begin
item := TCocoaMenuItem.alloc.initWithTitle_action_keyEquivalent(ns, item := TCocoaMenuItem.alloc.initWithTitle_action_keyEquivalent(ns,
objcselector('lclItemSelected:'), nsKey); objcselector('lclItemSelected:'), nsKey);
item.setKeyEquivalentModifierMask(ShiftSt); item.setKeyEquivalentModifierMask(ShiftSt);
TCocoaMenuItem(item).FMenuItemTarget := AMenuItem;
if AMenuItem.IsInMenuBar then if AMenuItem.IsInMenuBar then
begin begin
@ -479,8 +525,13 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
class function TCocoaWSMenuItem.SetCheck(const AMenuItem: TMenuItem; class function TCocoaWSMenuItem.SetCheck(const AMenuItem: TMenuItem;
const Checked: boolean): boolean; const Checked: boolean): boolean;
var
lHandle: NSMenuItem;
begin begin
Result:=Assigned(AMenuItem) and (AMenuItem.Handle<>0); Result := Assigned(AMenuItem) and AMenuItem.HandleAllocated() and (AMenuItem.Handle<>0);
if not Result then Exit;
lHandle := NSMenuItem(AMenuItem.Handle);
Result := Result and lHandle.isKindOfClass_(TCocoaMenuItem);
if not Result then Exit; if not Result then Exit;
TCocoaWSMenuItem.Do_SetCheck(NSMenuItem(AMenuItem.Handle), Checked); TCocoaWSMenuItem.Do_SetCheck(NSMenuItem(AMenuItem.Handle), Checked);
end; end;