cocoa: remove the direct reference between TCocoaWindow and LCLForm

git-svn-id: trunk@59020 -
This commit is contained in:
dmitry 2018-09-15 22:54:14 +00:00
parent c002ba7df4
commit 46bb1236fc
5 changed files with 36 additions and 29 deletions

View File

@ -115,7 +115,7 @@ type
procedure OnWakeMainThread(Sender: TObject);
public
// modal session
CurModalForm: TCustomForm;
CurModalForm: NSWindow;
constructor Create; override;
destructor Destroy; override;

View File

@ -532,7 +532,7 @@ begin
lNSObj := NSWindow(AControl.window());
if lNSObj = nil then Exit;
if not lNSObj.isKindOfClass_(TCocoaWindow) then Exit;
if lNSWin.LCLForm = CurModalForm then Exit;
if lNSWin = CurModalForm then Exit;
Result := True;
{$endif}
end;

View File

@ -2332,21 +2332,26 @@ end;
function TCocoaWidgetSet.SetMenu(AWindowHandle: HWND; AMenuHandle: HMENU): Boolean;
var
lWin: NSWindow;
frm : TCustomForm;
begin
Result := False;
lWin := NSWindow(GetNSObjectWindow(NSObject(AWindowHandle)));
if isFormDesigned(AWindowHandle) then begin
frm := HWNDToForm(AWindowHandle);
if Assigned(frm) and (csDesigning in frm.ComponentState) then begin
Result := true;
Exit;
end;
if not Assigned(frm) then Exit;
if (lWin <> nil) and lWin.isKindOfClass(TCocoaWindow) and
(TCocoaWindow(lWin).LCLForm.Menu.Handle = AMenuHandle) then
//todo: why is Menu handle checked here?
(frm.Menu.Handle = AMenuHandle)
then
begin
if lWin.isKeyWindow or lWin.isMainWindow then
SetMainMenu(AMenuHandle, TCocoaWindow(lWin).LCLForm.Menu);
SetMainMenu(AMenuHandle, frm.Menu);
Result := True;
end;
end;

View File

@ -29,7 +29,8 @@ uses
MacOSAll, CocoaAll, CocoaUtils, CocoaGDIObjects,
cocoa_extra, CocoaPrivate, CocoaTextEdits,
// LCL
Forms, LCLType, LCLProc;
//Forms,
LCLType, LCLProc;
type
@ -69,6 +70,9 @@ type
function GetEnabled: Boolean;
procedure SetEnabled(AValue: Boolean);
function AcceptFilesDrag: Boolean;
procedure DropFiles(const FileNames: array of string);
property Enabled: Boolean read GetEnabled write SetEnabled;
end;
@ -130,7 +134,7 @@ type
procedure windowDidExitFullScreen(notification: NSNotification); message 'windowDidExitFullScreen:';
public
callback: IWindowCallback;
LCLForm: TCustomForm;
//LCLForm: TCustomForm;
procedure dealloc; override;
function acceptsFirstResponder: Boolean; override;
function canBecomeKeyWindow: Boolean; override;
@ -881,16 +885,10 @@ begin
end;
function TCocoaWindow.draggingEntered(sender: NSDraggingInfoProtocol): NSDragOperation;
var
lTarget: TCustomForm = nil;
begin
Result := NSDragOperationNone;
if (callback <> nil) and (callback.GetTarget() <> nil) and (callback.GetTarget() is TCustomForm) then
lTarget := TCustomForm(callback.GetTarget());
if (lTarget <> nil) and (lTarget.OnDropFiles <> nil) then
begin
if (callback <> nil) and (callback.AcceptFilesDrag) then
Result := sender.draggingSourceOperationMask();
end;
end;
function TCocoaWindow.performDragOperation(sender: NSDraggingInfoProtocol): Boolean;
@ -928,8 +926,8 @@ begin
end;
end;}
if (Length(lFiles) > 0) and (callback <> nil) and (callback.GetTarget() <> nil) then
TCustomForm(callback.GetTarget()).IntfDropFiles(lFiles);
if (Length(lFiles) > 0) and (callback <> nil) then
callback.DropFiles(lFiles);
Result := True;
end;

View File

@ -55,6 +55,9 @@ type
function GetEnabled: Boolean; virtual;
procedure SetEnabled(AValue: Boolean); virtual;
function AcceptFilesDrag: Boolean;
procedure DropFiles(const FileNames: array of string);
property Enabled: Boolean read GetEnabled write SetEnabled;
end;
@ -166,7 +169,6 @@ type
procedure ArrangeTabOrder(const AWinControl: TWinControl);
function HWNDToForm(AFormHandle: HWND): TCustomForm;
function isFormDesigned(AFormHandle:HWND): Boolean;
implementation
@ -337,7 +339,7 @@ begin
CanClose := LCLSendCloseQueryMsg(Target) > 0;
// Special code for modal forms, which otherwise would get 0 here and not call Close
if (CocoaWidgetSet.CurModalForm = FTarget) and
if (CocoaWidgetSet.CurModalForm = window) and
(TCustomForm(Target).ModalResult <> mrNone) then
begin
{$IFDEF COCOA_USE_NATIVE_MODAL}
@ -389,6 +391,17 @@ begin
Owner.lclSetEnabled(AValue);
end;
function TLCLWindowCallback.AcceptFilesDrag: Boolean;
begin
Result := Assigned(Target) and Assigned(TCustomForm(Target).OnDropFiles);
end;
procedure TLCLWindowCallback.DropFiles(const FileNames: array of string);
begin
if Assigned(Target) then
TCustomForm(Target).IntfDropFiles(FileNames);
end;
{ TCocoaWSScrollingWinControl}
class function TCocoaWSScrollingWinControl.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
@ -584,7 +597,6 @@ begin
cnt.callback := TCocoaWindow(win).callback;
cnt.callback.IsOpaque:=true;
win.LCLForm := Form;
win.setContentView(cnt);
// Don't call addChildWindow_ordered here because this function can cause
@ -739,7 +751,7 @@ begin
if (lWinContent <> nil) and (not fullscreen) then
lWinContent.resolvePopupParent();
CocoaWidgetSet.CurModalForm := ACustomForm;
CocoaWidgetSet.CurModalForm := lWinContent.lclOwnWindow;
// LCL initialization code would cause the custom form to be disabled
// (due to the fact, ShowModal() has not been called yet, and a previous form
// might be disabled at the time.
@ -774,7 +786,7 @@ end;
class procedure TCocoaWSCustomForm.SetModalResult(const ACustomForm: TCustomForm;
ANewValue: TModalResult);
begin
if (CocoaWidgetSet.CurModalForm = ACustomForm) and (ANewValue <> 0) then
if (CocoaWidgetSet.CurModalForm = NSView(ACustomForm.Handle).window) and (ANewValue <> 0) then
CloseModal(ACustomForm);
end;
@ -928,12 +940,4 @@ begin
else Result := nil;
end;
function isFormDesigned(AFormHandle:HWND): Boolean;
var
frm : TCustomForm;
begin
frm := HWNDToForm(AFormHandle);
Result := Assigned(frm) and (csDesigning in frm.ComponentState);
end;
end.