Delphi OS X子类NSWindow无边框与鼠标事件 [英] Delphi OS X subclass NSWindow borderless with mouse events

查看:355
本文介绍了Delphi OS X子类NSWindow无边框与鼠标事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在delphi firemonkey中创建一个派生类的NSWindow?
我成功地创建了一个只包含一个webview的Cocoa窗口。 (使用NSWindow.Wrap,setContentView,orderFront等)
我使它无边界,但问题是它不接受鼠标移动事件,如下所示:
为什么NSWindow没有styleMask:NSTitledWindowMask不能是keyWindow?



是否可以在delphi中子类化NSWindow并覆盖canBecomeKeyWindow?



它不工作(编译,但方法不调用) p>

  type 
TMYNSWindow = class(TNSWindow)
function canBecomeKeyWindow:Boolean; cdecl;
end;
function TMYNSWindow.canBecomeKeyWindow:Boolean;
begin
结果:= true;
end;

`



/ p>

TMYNSWindow = class(TOCGenericImport< NSWindowClass,NSWindow>)
function canBecomeKeyWindow:Boolean; cdecl;
end;



那么,我如何继承NSWindow并覆盖它的一个方法?



编辑



使用Sebastian的解决方案后,
实际上可以创建窗口,

 构造函数TMYNSWindow.Create(contentRect:NSRect; styleMask:NSUInteger; backing:NSBackingStoreType; defer:Boolean); 
var
V:Pointer;
begin
inherited创建;
V:= NSWindow(Super).initWithContentRect(contentRect,styleMask,backing,defer);
if GetObjectID<> V然后UpdateObjectID(V);
end;


var
MyNSW:TMyNSWindow;
NSW:NSWindow;

...

MyNSW:= TMyNSWindow.Create(
MakeNSRect(0,0,600,400),
NSBorderlessWindowMask
// NSClosableWindowMask或NSMiniaturizableWindowMask或NSResizableWindowMask
,NSBackingStoreBuffered,false);

MyNSW.Super.QueryInterface(StringToGUID(GUID_NSWINDOW),NSW); // GUID_NSWINDOW ='{8CDBAC20-6E46-4618-A33F-229394B70A6D}';
NSW.setFrame(R,true,true); // R is NSRect,fill it before ...
NSW.orderFront((TNSApplication.Wrap(TNSApplication.OCClass.sharedApplication)as ILocalObject).GetObjectID);


解决方案

以下是从Cocoa类派生的一个简单示例。

 单位Unit2; 

接口

使用
MacApi.AppKit,Macapi.ObjectiveC,System.TypInfo;

type
MyNSWindow = interface(NSWindow)
//按Ctrl + Shift + G在这里插入一个唯一的引用
function canBecomeKeyWindow:Boolean; cdecl;
end;

TMyNSWindow = class(TOCLocal)
protected
function GetObjectiveCClass:PTypeInfo;覆盖;
public
function canBecomeKeyWindow:Boolean; cdecl;
constructor创建;
end;

实现

{TMyNSWindow}

函数TMyNSWindow.canBecomeKeyWindow:Boolean;
begin
结果:= True;
end;

构造函数TMyNSWindow.Create;
var
V:Pointer;
begin
inherited创建;
V:= NSWindow(Super).init;
if GetObjectID<> V then
UpdateObjectID(V);
end;

function TMyNSWindow.GetObjectiveCClass:PTypeInfo;
begin
结果:= TypeInfo(MyNSWindow);
end;


end。


How to create a derived class of NSWindow in delphi firemonkey? I've succeeded in creating a Cocoa window that contains only a webview. (using NSWindow.Wrap, setContentView, orderFront etc) I made it borderless, but the problem is that it does not accept mouse moved events, as described here: Why NSWindow without styleMask:NSTitledWindowMask can not be keyWindow?

Is it possible to subclass NSWindow in delphi and override canBecomeKeyWindow?

It's not working (compiles, but method not called):

type
 TMYNSWindow = class(TNSWindow)
   function canBecomeKeyWindow: Boolean; cdecl;
 end;
 function TMYNSWindow.canBecomeKeyWindow: Boolean;
 begin
   Result := true;
end;

`

This also ineffective:

TMYNSWindow = class(TOCGenericImport<NSWindowClass, NSWindow>) function canBecomeKeyWindow: Boolean; cdecl; end;

So, how can I subclass NSWindow and override one of its method?

EDIT

After using Sebastian's solution, to create the window actually, you can use something like this:

  constructor TMYNSWindow.Create( contentRect: NSRect; styleMask: NSUInteger; backing: NSBackingStoreType; defer: Boolean );
  var
    V : Pointer;
  begin
    inherited Create;
    V := NSWindow(Super).initWithContentRect( contentRect, styleMask, backing, defer );
    if GetObjectID <> V then UpdateObjectID(V);
  end;


var
  MyNSW : TMyNSWindow;
  NSW : NSWindow;

...

  MyNSW := TMyNSWindow.Create(
    MakeNSRect(0, 0, 600, 400),
    NSBorderlessWindowMask
    //NSClosableWindowMask or NSMiniaturizableWindowMask or NSResizableWindowMask
    ,NSBackingStoreBuffered, false );

  MyNSW.Super.QueryInterface( StringToGUID(GUID_NSWINDOW), NSW );   //GUID_NSWINDOW = '{8CDBAC20-6E46-4618-A33F-229394B70A6D}';
  NSW.setFrame( R, true, true );  // R is NSRect, fill it before...
  NSW.orderFront((TNSApplication.Wrap(TNSApplication.OCClass.sharedApplication) as ILocalObject).GetObjectID );

解决方案

Here's a quick example for deriving from a Cocoa class.

unit Unit2;

interface

uses
  MacApi.AppKit, Macapi.ObjectiveC, System.TypInfo;

type
  MyNSWindow = interface(NSWindow)
    // Press Ctrl+Shift+G to insert a unique guid here
    function canBecomeKeyWindow: Boolean; cdecl;
  end;

  TMyNSWindow = class(TOCLocal)
  protected
    function GetObjectiveCClass: PTypeInfo; override;
  public
    function canBecomeKeyWindow: Boolean; cdecl;
    constructor Create;
  end;

implementation

{ TMyNSWindow }

function TMyNSWindow.canBecomeKeyWindow: Boolean;
begin
  Result := True;
end;

constructor TMyNSWindow.Create;
var
  V: Pointer;
begin
  inherited Create;
  V := NSWindow(Super).init;
  if GetObjectID <> V then
    UpdateObjectID(V);
end;

function TMyNSWindow.GetObjectiveCClass: PTypeInfo;
begin
  Result := TypeInfo(MyNSWindow);
end;


end.

这篇关于Delphi OS X子类NSWindow无边框与鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆