From 019aa71ce3640b01a7457e2f89d06101ffd3aecf Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Tue, 8 Sep 2015 07:41:15 +0000 Subject: [PATCH] cocoa: Implements the new blocking mechanism for disabling controls due to modal git-svn-id: trunk@49782 - --- lcl/interfaces/cocoa/cocoaint.pas | 3 ++- lcl/interfaces/cocoa/cocoaobject.inc | 28 +++++++++++++++++++++++++++- lcl/interfaces/cocoa/cocoaprivate.pp | 12 +++++++++++- lcl/interfaces/cocoa/cocoawsforms.pp | 1 + 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/lcl/interfaces/cocoa/cocoaint.pas b/lcl/interfaces/cocoa/cocoaint.pas index 685e803c91..02681d0d6c 100644 --- a/lcl/interfaces/cocoa/cocoaint.pas +++ b/lcl/interfaces/cocoa/cocoaint.pas @@ -34,7 +34,7 @@ uses InterfaceBase, GraphType, // private CocoaAll, CocoaPrivate, CocoaUtils, CocoaGDIObjects, - CocoaProc, cocoa_extra, CocoaWSMenus, + CocoaProc, cocoa_extra, CocoaWSMenus, CocoaWSForms, // LCL LCLStrConsts, LMessages, LCLMessageGlue, LCLProc, LCLIntf, LCLType, Controls, Forms, Themes, Menus, @@ -139,6 +139,7 @@ type procedure FreeSysColorBrushes; procedure SetMainMenu(const AMenu: HMENU; const ALCLMenu: TMenu); + function IsControlDisabledDueToModal(AControl: NSView): Boolean; {todo:} function DCGetPixel(CanvasHandle: HDC; X, Y: integer): TGraphicsColor; override; diff --git a/lcl/interfaces/cocoa/cocoaobject.inc b/lcl/interfaces/cocoa/cocoaobject.inc index 103ec8642a..5e8106dfd0 100644 --- a/lcl/interfaces/cocoa/cocoaobject.inc +++ b/lcl/interfaces/cocoa/cocoaobject.inc @@ -430,10 +430,11 @@ var i: Integer; lCurItem: TMenuItem; lMenuObj: NSObject; + lNSMenu: NSMenu absolute AMenu; begin if AMenu<>0 then begin - NSApp.setMainMenu(NSMenu(AMenu)); + NSApp.setMainMenu(lNSMenu); if (ALCLMenu = nil) or not ALCLMenu.HandleAllocated then Exit; // Some older docs say we should use setAppleMenu to obtain the Services/Hide/Quit items, @@ -457,9 +458,34 @@ begin Exit; end;} end; + + // for modal windows work around bug, but doesn't work :( + {$ifdef COCOA_USE_NATIVE_MODAL} + {if CurModalForm <> nil then + for i := 0 to lNSMenu.numberOfItems()-1 do + begin + lNSMenu.itemAtIndex(i).setTarget(TCocoaWSCustomForm.GetWindowFromHandle(CurModalForm)); + end;} + {$endif} end; end; +function TCocoaWidgetSet.IsControlDisabledDueToModal(AControl: NSView): Boolean; +var + lNSObj: NSWindow; + lNSWin: TCocoaWindow absolute lNSObj; +begin + Result := False; + {$ifndef COCOA_USE_NATIVE_MODAL} + if CurModalForm = nil then Exit; + lNSObj := AControl.window(); + if lNSObj = nil then Exit; + if not lNSObj.isKindOfClass_(TCocoaWindow) then Exit; + if lNSWin.LCLForm = CurModalForm then Exit; + Result := True; + {$endif} +end; + {------------------------------------------------------------------------------ Method: TCocoaWidgetSet.GetAppHandle Returns: Returns NSApp object, created via NSApplication.sharedApplication diff --git a/lcl/interfaces/cocoa/cocoaprivate.pp b/lcl/interfaces/cocoa/cocoaprivate.pp index 72abb71f58..b7db1d39c9 100644 --- a/lcl/interfaces/cocoa/cocoaprivate.pp +++ b/lcl/interfaces/cocoa/cocoaprivate.pp @@ -340,6 +340,7 @@ type procedure windowDidMove(notification: NSNotification); message 'windowDidMove:'; public callback: IWindowCallback; + LCLForm: TCustomForm; procedure dealloc; override; function acceptsFirstResponder: Boolean; override; function canBecomeKeyWindow: Boolean; override; @@ -366,6 +367,8 @@ type // NSDraggingDestinationCategory function draggingEntered(sender: NSDraggingInfoProtocol): NSDragOperation; override; function performDragOperation(sender: NSDraggingInfoProtocol): Boolean; override; + // menu support + procedure lclItemSelected(sender: id); message 'lclItemSelected:'; end; { TCocoaCustomControl } @@ -852,7 +855,7 @@ function GetNSViewSuperViewHeight(view: NSView): CGFloat; implementation -uses CocoaWSComCtrls; +uses CocoaWSComCtrls, CocoaInt; {$I mackeycodes.inc} @@ -1450,6 +1453,11 @@ begin Result := True; end; +procedure TCocoaWindow.lclItemSelected(sender: id); +begin + +end; + { TCocoaScrollView } function TCocoaScrollView.lclIsHandle: Boolean; @@ -1632,6 +1640,8 @@ end; procedure TCocoaButton.actionButtonClick(sender: NSObject); begin + if CocoaWidgetSet.IsControlDisabledDueToModal(Self) then Exit; + // this is the action handler of button if Assigned(callback) then callback.ButtonClick; diff --git a/lcl/interfaces/cocoa/cocoawsforms.pp b/lcl/interfaces/cocoa/cocoawsforms.pp index 77e7a82e44..685b303850 100644 --- a/lcl/interfaces/cocoa/cocoawsforms.pp +++ b/lcl/interfaces/cocoa/cocoawsforms.pp @@ -481,6 +481,7 @@ var cnt.callback := TCocoaWindow(win).callback; cnt.callback.IsOpaque:=true; + win.LCLForm := Form; win.setContentView(cnt); if (AParams.WndParent <> 0) then