Unexpected NSTextView behavior (due to NSWindow without a header?)

I have an NSWindow (my main window) and a child window (the NSWindowBelow located main window) that has an NSTextView . There is no title bar, shadow, or transparency in the child window.
Here is the code that I use to configure my child window to make it transparent:

 - (id) initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag{ if (![super initWithContentRect: contentRect styleMask:NSBorderlessWindowMask backing: bufferingType defer:NO]) return nil; [self setBackgroundColor: [NSColor clearColor]]; [self setOpaque:NO]; return self; } 

But when I try to select the text in it, this is what happens (the black window above the child window is the main window):
enter image description here
It seems that NSTextView not focused, because the selection is not blue. I tried calling: [[_childWindow textView] becomeFirstResponder]; but the result is the same. Another thing is that when I scroll it, sometimes it is very laggy and β€œbroken”.

Do you guys have any ideas on what causes this and how to fix it? I suspect because there is no title bar in the window, but I'm not sure. Thanks!

+4
source share
1 answer

From NSWindow docs:

 canBecomeKeyWindow Indicates whether the window can become the key window. - (BOOL)canBecomeKeyWindow Return Value YES if the window can become the key window, otherwise, NO. Discussion Attempts to make the window the key window are abandoned if this method returns NO. The NSWindow implementation returns YES if the window has a title bar or a resize bar, or NO otherwise. 

Try overriding -canBecomeKeyWindow and return YES.

+2
source

Source: https://habr.com/ru/post/1481023/


All Articles