mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-06 14:54:42 +01:00
cocoa: remove the direct reference between TCocoaWindow and LCLForm
git-svn-id: trunk@59020 -
This commit is contained in:
parent
c002ba7df4
commit
46bb1236fc
@ -115,7 +115,7 @@ type
|
|||||||
procedure OnWakeMainThread(Sender: TObject);
|
procedure OnWakeMainThread(Sender: TObject);
|
||||||
public
|
public
|
||||||
// modal session
|
// modal session
|
||||||
CurModalForm: TCustomForm;
|
CurModalForm: NSWindow;
|
||||||
|
|
||||||
constructor Create; override;
|
constructor Create; override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|||||||
@ -532,7 +532,7 @@ begin
|
|||||||
lNSObj := NSWindow(AControl.window());
|
lNSObj := NSWindow(AControl.window());
|
||||||
if lNSObj = nil then Exit;
|
if lNSObj = nil then Exit;
|
||||||
if not lNSObj.isKindOfClass_(TCocoaWindow) then Exit;
|
if not lNSObj.isKindOfClass_(TCocoaWindow) then Exit;
|
||||||
if lNSWin.LCLForm = CurModalForm then Exit;
|
if lNSWin = CurModalForm then Exit;
|
||||||
Result := True;
|
Result := True;
|
||||||
{$endif}
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|||||||
@ -2332,21 +2332,26 @@ end;
|
|||||||
function TCocoaWidgetSet.SetMenu(AWindowHandle: HWND; AMenuHandle: HMENU): Boolean;
|
function TCocoaWidgetSet.SetMenu(AWindowHandle: HWND; AMenuHandle: HMENU): Boolean;
|
||||||
var
|
var
|
||||||
lWin: NSWindow;
|
lWin: NSWindow;
|
||||||
|
frm : TCustomForm;
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
|
|
||||||
lWin := NSWindow(GetNSObjectWindow(NSObject(AWindowHandle)));
|
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;
|
Result := true;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
if not Assigned(frm) then Exit;
|
||||||
|
|
||||||
if (lWin <> nil) and lWin.isKindOfClass(TCocoaWindow) and
|
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
|
begin
|
||||||
if lWin.isKeyWindow or lWin.isMainWindow then
|
if lWin.isKeyWindow or lWin.isMainWindow then
|
||||||
SetMainMenu(AMenuHandle, TCocoaWindow(lWin).LCLForm.Menu);
|
SetMainMenu(AMenuHandle, frm.Menu);
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|||||||
@ -29,7 +29,8 @@ uses
|
|||||||
MacOSAll, CocoaAll, CocoaUtils, CocoaGDIObjects,
|
MacOSAll, CocoaAll, CocoaUtils, CocoaGDIObjects,
|
||||||
cocoa_extra, CocoaPrivate, CocoaTextEdits,
|
cocoa_extra, CocoaPrivate, CocoaTextEdits,
|
||||||
// LCL
|
// LCL
|
||||||
Forms, LCLType, LCLProc;
|
//Forms,
|
||||||
|
LCLType, LCLProc;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -69,6 +70,9 @@ type
|
|||||||
function GetEnabled: Boolean;
|
function GetEnabled: Boolean;
|
||||||
procedure SetEnabled(AValue: Boolean);
|
procedure SetEnabled(AValue: Boolean);
|
||||||
|
|
||||||
|
function AcceptFilesDrag: Boolean;
|
||||||
|
procedure DropFiles(const FileNames: array of string);
|
||||||
|
|
||||||
property Enabled: Boolean read GetEnabled write SetEnabled;
|
property Enabled: Boolean read GetEnabled write SetEnabled;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -130,7 +134,7 @@ type
|
|||||||
procedure windowDidExitFullScreen(notification: NSNotification); message 'windowDidExitFullScreen:';
|
procedure windowDidExitFullScreen(notification: NSNotification); message 'windowDidExitFullScreen:';
|
||||||
public
|
public
|
||||||
callback: IWindowCallback;
|
callback: IWindowCallback;
|
||||||
LCLForm: TCustomForm;
|
//LCLForm: TCustomForm;
|
||||||
procedure dealloc; override;
|
procedure dealloc; override;
|
||||||
function acceptsFirstResponder: Boolean; override;
|
function acceptsFirstResponder: Boolean; override;
|
||||||
function canBecomeKeyWindow: Boolean; override;
|
function canBecomeKeyWindow: Boolean; override;
|
||||||
@ -881,16 +885,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaWindow.draggingEntered(sender: NSDraggingInfoProtocol): NSDragOperation;
|
function TCocoaWindow.draggingEntered(sender: NSDraggingInfoProtocol): NSDragOperation;
|
||||||
var
|
|
||||||
lTarget: TCustomForm = nil;
|
|
||||||
begin
|
begin
|
||||||
Result := NSDragOperationNone;
|
Result := NSDragOperationNone;
|
||||||
if (callback <> nil) and (callback.GetTarget() <> nil) and (callback.GetTarget() is TCustomForm) then
|
if (callback <> nil) and (callback.AcceptFilesDrag) then
|
||||||
lTarget := TCustomForm(callback.GetTarget());
|
|
||||||
if (lTarget <> nil) and (lTarget.OnDropFiles <> nil) then
|
|
||||||
begin
|
|
||||||
Result := sender.draggingSourceOperationMask();
|
Result := sender.draggingSourceOperationMask();
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCocoaWindow.performDragOperation(sender: NSDraggingInfoProtocol): Boolean;
|
function TCocoaWindow.performDragOperation(sender: NSDraggingInfoProtocol): Boolean;
|
||||||
@ -928,8 +926,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;}
|
end;}
|
||||||
|
|
||||||
if (Length(lFiles) > 0) and (callback <> nil) and (callback.GetTarget() <> nil) then
|
if (Length(lFiles) > 0) and (callback <> nil) then
|
||||||
TCustomForm(callback.GetTarget()).IntfDropFiles(lFiles);
|
callback.DropFiles(lFiles);
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
@ -55,6 +55,9 @@ type
|
|||||||
function GetEnabled: Boolean; virtual;
|
function GetEnabled: Boolean; virtual;
|
||||||
procedure SetEnabled(AValue: Boolean); virtual;
|
procedure SetEnabled(AValue: Boolean); virtual;
|
||||||
|
|
||||||
|
function AcceptFilesDrag: Boolean;
|
||||||
|
procedure DropFiles(const FileNames: array of string);
|
||||||
|
|
||||||
property Enabled: Boolean read GetEnabled write SetEnabled;
|
property Enabled: Boolean read GetEnabled write SetEnabled;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -166,7 +169,6 @@ type
|
|||||||
|
|
||||||
procedure ArrangeTabOrder(const AWinControl: TWinControl);
|
procedure ArrangeTabOrder(const AWinControl: TWinControl);
|
||||||
function HWNDToForm(AFormHandle: HWND): TCustomForm;
|
function HWNDToForm(AFormHandle: HWND): TCustomForm;
|
||||||
function isFormDesigned(AFormHandle:HWND): Boolean;
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -337,7 +339,7 @@ begin
|
|||||||
CanClose := LCLSendCloseQueryMsg(Target) > 0;
|
CanClose := LCLSendCloseQueryMsg(Target) > 0;
|
||||||
|
|
||||||
// Special code for modal forms, which otherwise would get 0 here and not call Close
|
// 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
|
(TCustomForm(Target).ModalResult <> mrNone) then
|
||||||
begin
|
begin
|
||||||
{$IFDEF COCOA_USE_NATIVE_MODAL}
|
{$IFDEF COCOA_USE_NATIVE_MODAL}
|
||||||
@ -389,6 +391,17 @@ begin
|
|||||||
Owner.lclSetEnabled(AValue);
|
Owner.lclSetEnabled(AValue);
|
||||||
end;
|
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}
|
{ TCocoaWSScrollingWinControl}
|
||||||
|
|
||||||
class function TCocoaWSScrollingWinControl.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
|
class function TCocoaWSScrollingWinControl.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
|
||||||
@ -584,7 +597,6 @@ begin
|
|||||||
|
|
||||||
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);
|
||||||
|
|
||||||
// Don't call addChildWindow_ordered here because this function can cause
|
// Don't call addChildWindow_ordered here because this function can cause
|
||||||
@ -739,7 +751,7 @@ begin
|
|||||||
if (lWinContent <> nil) and (not fullscreen) then
|
if (lWinContent <> nil) and (not fullscreen) then
|
||||||
lWinContent.resolvePopupParent();
|
lWinContent.resolvePopupParent();
|
||||||
|
|
||||||
CocoaWidgetSet.CurModalForm := ACustomForm;
|
CocoaWidgetSet.CurModalForm := lWinContent.lclOwnWindow;
|
||||||
// LCL initialization code would cause the custom form to be disabled
|
// 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
|
// (due to the fact, ShowModal() has not been called yet, and a previous form
|
||||||
// might be disabled at the time.
|
// might be disabled at the time.
|
||||||
@ -774,7 +786,7 @@ end;
|
|||||||
class procedure TCocoaWSCustomForm.SetModalResult(const ACustomForm: TCustomForm;
|
class procedure TCocoaWSCustomForm.SetModalResult(const ACustomForm: TCustomForm;
|
||||||
ANewValue: TModalResult);
|
ANewValue: TModalResult);
|
||||||
begin
|
begin
|
||||||
if (CocoaWidgetSet.CurModalForm = ACustomForm) and (ANewValue <> 0) then
|
if (CocoaWidgetSet.CurModalForm = NSView(ACustomForm.Handle).window) and (ANewValue <> 0) then
|
||||||
CloseModal(ACustomForm);
|
CloseModal(ACustomForm);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -928,12 +940,4 @@ begin
|
|||||||
else Result := nil;
|
else Result := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function isFormDesigned(AFormHandle:HWND): Boolean;
|
|
||||||
var
|
|
||||||
frm : TCustomForm;
|
|
||||||
begin
|
|
||||||
frm := HWNDToForm(AFormHandle);
|
|
||||||
Result := Assigned(frm) and (csDesigning in frm.ComponentState);
|
|
||||||
end;
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user