cocoa - Why NSWindow without styleMask:NSTitledWindowMask can not be keyWindow? -
problem: have 1 window mainwindow , childwindow
added mainwindow
. childwindow kind of windowext
class. class define catch method call [nswindow becomekeywindow]
must called after [childwindow makekeywindow]
. if create childwindow , try make keywindow on next way:
windowext *childwindow = [[windowext alloc] initwithcontentrect:addedwindowrect stylemask:nsborderlesswindowmask | nstitledwindowmask backing:nsbackingstorebuffered defer:no]; [mainwindow addchildwindow:childwindow ordered:nswindowabove]; [childwindow makekeywindow];
method [windowext becomekeywindow]
childwindow
called - fine, childwindow
become keywindow.
but if create childwindow as
windowext *childwindow = [[windowext alloc] initwithcontentrect:addedwindowrect stylemask:nsborderlesswindowmask backing:nsbackingstorebuffered defer:no]; [mainwindow addchildwindow:childwindow ordered:nswindowabove]; [childwindow makekeywindow];
without nstitledwindowmask
, [windowext becomekeywindow]
childwindow
never called - childwindow
doesn't become keywindow.
that’s cocoa design decision: windows without title or resize bar cannot become key window default.
if want titleless window able become key window, need create subclass of nswindow
, override -canbecomekeywindow
follows:
- (bool)canbecomekeywindow { return yes; }
Comments
Post a Comment