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 );