cocoa: Implements the new blocking mechanism for disabling controls due to modal

git-svn-id: trunk@49782 -
This commit is contained in:
sekelsenmat 2015-09-08 07:41:15 +00:00
parent d92ea0400e
commit 019aa71ce3
4 changed files with 41 additions and 3 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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