cocoa: change processing of AllowDropFiles for forms. Partially based on the patch by Zoë Peterson. Allow files acception even for embeded forms (NSView-based). #35215

git-svn-id: trunk@61031 -
This commit is contained in:
dmitry 2019-04-21 20:44:46 +00:00
parent 0487347061
commit 9980e47dc0
2 changed files with 31 additions and 14 deletions

View File

@ -171,9 +171,6 @@ type
procedure keyDown(event: NSEvent); override;
procedure keyUp(event: NSEvent); override;
procedure flagsChanged(event: NSEvent); override;
// NSDraggingDestinationCategory
function draggingEntered(sender: NSDraggingInfoProtocol): NSDragOperation; override;
function performDragOperation(sender: NSDraggingInfoProtocol): LCLObjCBoolean; override;
// windows
function makeFirstResponder(r: NSResponder): LCLObjCBoolean; override;
// menu support
@ -201,6 +198,7 @@ type
procedure didBecomeKeyNotification(sender: NSNotification); message 'didBecomeKeyNotification:';
procedure didResignKeyNotification(sender: NSNotification); message 'didResignKeyNotification:';
public
wincallback: IWindowCallback;
isembedded: Boolean; // true - if the content is inside of another control, false - if the content is in its own window;
preventKeyOnShow: Boolean;
ownwin: NSWindow;
@ -218,6 +216,9 @@ type
procedure dealloc; override;
procedure setHidden(aisHidden: LCLObjCBoolean); override;
procedure didAddSubview(aview: NSView); override;
// NSDraggingDestinationCategory
function draggingEntered(sender: NSDraggingInfoProtocol): NSDragOperation; override;
function performDragOperation(sender: NSDraggingInfoProtocol): LCLObjCBoolean; override;
end;
procedure WindowPerformKeyDown(win: NSWindow; event: NSEvent; out processed: Boolean);
@ -1082,14 +1083,14 @@ begin
inherited flagsChanged(event);
end;
function TCocoaWindow.draggingEntered(sender: NSDraggingInfoProtocol): NSDragOperation;
function TCocoaWindowContent.draggingEntered(sender: NSDraggingInfoProtocol): NSDragOperation;
begin
Result := NSDragOperationNone;
if (callback <> nil) and (callback.AcceptFilesDrag) then
if (wincallback <> nil) and (wincallback.AcceptFilesDrag) then
Result := sender.draggingSourceOperationMask();
end;
function TCocoaWindow.performDragOperation(sender: NSDraggingInfoProtocol): LCLObjCBoolean;
function TCocoaWindowContent.performDragOperation(sender: NSDraggingInfoProtocol): LCLObjCBoolean;
var
draggedURLs{, lClasses}: NSArray;
lFiles: array of string;
@ -1124,8 +1125,8 @@ begin
end;
end;}
if (Length(lFiles) > 0) and (callback <> nil) then
callback.DropFiles(lFiles);
if (Length(lFiles) > 0) and (wincallback <> nil) then
wincallback.DropFiles(lFiles);
Result := True;
end;

View File

@ -119,6 +119,7 @@ type
class procedure ShowModal(const ACustomForm: TCustomForm); override;
class procedure SetModalResult(const ACustomForm: TCustomForm; ANewValue: TModalResult); override;
class procedure SetAllowDropFiles(const AForm: TCustomForm; AValue: Boolean); override;
class procedure SetAlphaBlend(const ACustomForm: TCustomForm; const AlphaBlend: Boolean; const Alpha: Byte); override;
class procedure SetBorderIcons(const AForm: TCustomForm; const ABorderIcons: TBorderIcons); override;
class procedure SetFormBorderStyle(const AForm: TCustomForm; const AFormBorderStyle: TFormBorderStyle); override;
@ -293,6 +294,7 @@ begin
cb := TLCLWindowCallback.Create(cnt, AWinControl, cnt);
cb.window := win;
cnt.callback := cb;
cnt.wincallback := cb;
cnt.preventKeyOnShow := true;
TCocoaPanel(win).callback := cb;
@ -446,7 +448,9 @@ end;
function TLCLWindowCallback.AcceptFilesDrag: Boolean;
begin
Result := Assigned(Target) and Assigned(TCustomForm(Target).OnDropFiles);
Result := Assigned(Target)
and TCustomForm(Target).AllowDropFiles
and Assigned(TCustomForm(Target).OnDropFiles);
end;
procedure TLCLWindowCallback.DropFiles(const FileNames: array of string);
@ -617,6 +621,7 @@ begin
cnt := TCocoaWindowContent.alloc.initWithFrame(R);
cb := TLCLWindowCallback.Create(cnt, AWinControl, cnt);
cnt.callback := cb;
cnt.wincallback := cb;
if (AParams.Style and WS_CHILD) = 0 then
begin
@ -670,8 +675,8 @@ begin
{$endif}
end;
cnt.callback := TCocoaWindow(win).callback;
cnt.callback.IsOpaque:=true;
cnt.wincallback := TCocoaWindow(win).callback;
win.setContentView(cnt);
// Don't call addChildWindow_ordered here because this function can cause
@ -679,9 +684,6 @@ begin
// while the first didn't finish yet, instead delay the call
cnt.popup_parent := AParams.WndParent;
// support for drag & drop
win.registerForDraggedTypes(NSArray.arrayWithObjects_count(@NSFilenamesPboardType, 1));
if IsFormDesign(AWinControl) then begin
ds:=(TCocoaDesignOverlay.alloc).initWithFrame(cnt.frame);
ds.callback := cnt.callback;
@ -693,7 +695,6 @@ begin
end
else
begin
cnt.callback := TLCLCommonCallback.Create(cnt, AWinControl);
if AParams.WndParent <> 0 then
begin
lDestView := GetNSObjectView(NSObject(AParams.WndParent));
@ -846,6 +847,21 @@ begin
CloseModal(ACustomForm);
end;
class procedure TCocoaWSCustomForm.SetAllowDropFiles(const AForm: TCustomForm;
AValue: Boolean);
var
view : NSView;
begin
if AForm.HandleAllocated then
begin
view := NSView(AForm.Handle);
if AValue then
view.registerForDraggedTypes(NSArray.arrayWithObjects_count(@NSFilenamesPboardType, 1))
else
view.unregisterDraggedTypes
end;
end;
class procedure TCocoaWSCustomForm.SetAlphaBlend(const ACustomForm: TCustomForm; const AlphaBlend: Boolean; const Alpha: Byte);
var
win : NSWindow;