mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 17:19:23 +02:00
cocoa: Implements the new blocking mechanism for disabling controls due to modal
git-svn-id: trunk@49782 -
This commit is contained in:
parent
d92ea0400e
commit
019aa71ce3
@ -34,7 +34,7 @@ uses
|
|||||||
InterfaceBase, GraphType,
|
InterfaceBase, GraphType,
|
||||||
// private
|
// private
|
||||||
CocoaAll, CocoaPrivate, CocoaUtils, CocoaGDIObjects,
|
CocoaAll, CocoaPrivate, CocoaUtils, CocoaGDIObjects,
|
||||||
CocoaProc, cocoa_extra, CocoaWSMenus,
|
CocoaProc, cocoa_extra, CocoaWSMenus, CocoaWSForms,
|
||||||
// LCL
|
// LCL
|
||||||
LCLStrConsts, LMessages, LCLMessageGlue, LCLProc, LCLIntf, LCLType,
|
LCLStrConsts, LMessages, LCLMessageGlue, LCLProc, LCLIntf, LCLType,
|
||||||
Controls, Forms, Themes, Menus,
|
Controls, Forms, Themes, Menus,
|
||||||
@ -139,6 +139,7 @@ type
|
|||||||
procedure FreeSysColorBrushes;
|
procedure FreeSysColorBrushes;
|
||||||
|
|
||||||
procedure SetMainMenu(const AMenu: HMENU; const ALCLMenu: TMenu);
|
procedure SetMainMenu(const AMenu: HMENU; const ALCLMenu: TMenu);
|
||||||
|
function IsControlDisabledDueToModal(AControl: NSView): Boolean;
|
||||||
|
|
||||||
{todo:}
|
{todo:}
|
||||||
function DCGetPixel(CanvasHandle: HDC; X, Y: integer): TGraphicsColor; override;
|
function DCGetPixel(CanvasHandle: HDC; X, Y: integer): TGraphicsColor; override;
|
||||||
|
@ -430,10 +430,11 @@ var
|
|||||||
i: Integer;
|
i: Integer;
|
||||||
lCurItem: TMenuItem;
|
lCurItem: TMenuItem;
|
||||||
lMenuObj: NSObject;
|
lMenuObj: NSObject;
|
||||||
|
lNSMenu: NSMenu absolute AMenu;
|
||||||
begin
|
begin
|
||||||
if AMenu<>0 then
|
if AMenu<>0 then
|
||||||
begin
|
begin
|
||||||
NSApp.setMainMenu(NSMenu(AMenu));
|
NSApp.setMainMenu(lNSMenu);
|
||||||
if (ALCLMenu = nil) or not ALCLMenu.HandleAllocated then Exit;
|
if (ALCLMenu = nil) or not ALCLMenu.HandleAllocated then Exit;
|
||||||
|
|
||||||
// Some older docs say we should use setAppleMenu to obtain the Services/Hide/Quit items,
|
// Some older docs say we should use setAppleMenu to obtain the Services/Hide/Quit items,
|
||||||
@ -457,9 +458,34 @@ begin
|
|||||||
Exit;
|
Exit;
|
||||||
end;}
|
end;}
|
||||||
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;
|
||||||
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
|
Method: TCocoaWidgetSet.GetAppHandle
|
||||||
Returns: Returns NSApp object, created via NSApplication.sharedApplication
|
Returns: Returns NSApp object, created via NSApplication.sharedApplication
|
||||||
|
@ -340,6 +340,7 @@ type
|
|||||||
procedure windowDidMove(notification: NSNotification); message 'windowDidMove:';
|
procedure windowDidMove(notification: NSNotification); message 'windowDidMove:';
|
||||||
public
|
public
|
||||||
callback: IWindowCallback;
|
callback: IWindowCallback;
|
||||||
|
LCLForm: TCustomForm;
|
||||||
procedure dealloc; override;
|
procedure dealloc; override;
|
||||||
function acceptsFirstResponder: Boolean; override;
|
function acceptsFirstResponder: Boolean; override;
|
||||||
function canBecomeKeyWindow: Boolean; override;
|
function canBecomeKeyWindow: Boolean; override;
|
||||||
@ -366,6 +367,8 @@ type
|
|||||||
// NSDraggingDestinationCategory
|
// NSDraggingDestinationCategory
|
||||||
function draggingEntered(sender: NSDraggingInfoProtocol): NSDragOperation; override;
|
function draggingEntered(sender: NSDraggingInfoProtocol): NSDragOperation; override;
|
||||||
function performDragOperation(sender: NSDraggingInfoProtocol): Boolean; override;
|
function performDragOperation(sender: NSDraggingInfoProtocol): Boolean; override;
|
||||||
|
// menu support
|
||||||
|
procedure lclItemSelected(sender: id); message 'lclItemSelected:';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaCustomControl }
|
{ TCocoaCustomControl }
|
||||||
@ -852,7 +855,7 @@ function GetNSViewSuperViewHeight(view: NSView): CGFloat;
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses CocoaWSComCtrls;
|
uses CocoaWSComCtrls, CocoaInt;
|
||||||
|
|
||||||
{$I mackeycodes.inc}
|
{$I mackeycodes.inc}
|
||||||
|
|
||||||
@ -1450,6 +1453,11 @@ begin
|
|||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCocoaWindow.lclItemSelected(sender: id);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
{ TCocoaScrollView }
|
{ TCocoaScrollView }
|
||||||
|
|
||||||
function TCocoaScrollView.lclIsHandle: Boolean;
|
function TCocoaScrollView.lclIsHandle: Boolean;
|
||||||
@ -1632,6 +1640,8 @@ end;
|
|||||||
|
|
||||||
procedure TCocoaButton.actionButtonClick(sender: NSObject);
|
procedure TCocoaButton.actionButtonClick(sender: NSObject);
|
||||||
begin
|
begin
|
||||||
|
if CocoaWidgetSet.IsControlDisabledDueToModal(Self) then Exit;
|
||||||
|
|
||||||
// this is the action handler of button
|
// this is the action handler of button
|
||||||
if Assigned(callback) then
|
if Assigned(callback) then
|
||||||
callback.ButtonClick;
|
callback.ButtonClick;
|
||||||
|
@ -481,6 +481,7 @@ var
|
|||||||
|
|
||||||
cnt.callback := TCocoaWindow(win).callback;
|
cnt.callback := TCocoaWindow(win).callback;
|
||||||
cnt.callback.IsOpaque:=true;
|
cnt.callback.IsOpaque:=true;
|
||||||
|
win.LCLForm := Form;
|
||||||
win.setContentView(cnt);
|
win.setContentView(cnt);
|
||||||
|
|
||||||
if (AParams.WndParent <> 0) then
|
if (AParams.WndParent <> 0) then
|
||||||
|
Loading…
Reference in New Issue
Block a user