From b06a651094c86fc2f32d194e01c43e88f8285703 Mon Sep 17 00:00:00 2001 From: dmitry Date: Mon, 24 Jun 2019 20:05:43 +0000 Subject: [PATCH] cocoa: allowing a designed form to activate (and focus). #34718 git-svn-id: trunk@61471 - --- lcl/interfaces/cocoa/cocoawsforms.pas | 30 +++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoawsforms.pas b/lcl/interfaces/cocoa/cocoawsforms.pas index b1de3d3bca..e8277a6912 100644 --- a/lcl/interfaces/cocoa/cocoawsforms.pas +++ b/lcl/interfaces/cocoa/cocoawsforms.pas @@ -351,28 +351,36 @@ end; procedure TLCLWindowCallback.Activate; var ACustForm: TCustomForm; + isDesign: Boolean; begin if not IsActivating then begin IsActivating:=True; ACustForm := Target as TCustomForm; - if (csDesigning in ACustForm.ComponentState) - or (Assigned(ACustForm.Menu) and (csDesigning in ACustForm.Menu.ComponentState)) - then Exit; + isDesign := + (csDesigning in ACustForm.ComponentState) + or ( + Assigned(ACustForm.Menu) + and (csDesigning in ACustForm.Menu.ComponentState) + ); - if (ACustForm.Menu <> nil) and - (ACustForm.Menu.HandleAllocated) then + // only adjust main menu, if the form is not being designed + if not isDesign then begin - if NSObject(ACustForm.Menu.Handle).isKindOfClass_(TCocoaMenu) then + if (ACustForm.Menu <> nil) and + (ACustForm.Menu.HandleAllocated) then begin - CocoaWidgetSet.SetMainMenu(ACustForm.Menu.Handle, ACustForm.Menu); + if NSObject(ACustForm.Menu.Handle).isKindOfClass_(TCocoaMenu) then + begin + CocoaWidgetSet.SetMainMenu(ACustForm.Menu.Handle, ACustForm.Menu); + end + else + debugln('Warning: Menu does not have a valid handle.'); end else - debugln('Warning: Menu does not have a valid handle.'); - end - else - CocoaWidgetSet.SetMainMenu(0, nil); + CocoaWidgetSet.SetMainMenu(0, nil); + end; LCLSendActivateMsg(Target, WA_ACTIVE, false); LCLSendSetFocusMsg(Target);