1

I want to make a custom autocomplete control for my NSWindow, sort of like Xcode's fancy one, but I can't quite figure out how.

I made an NSPanel with its own NSWindowController, and I display it with some code like:

_popupController = [[MYPopupWindowController alloc] initWithWindowNibName: @"MYPopupPanel"];
NSPanel *popup = [_popupController window];
[popup setFrameTopLeftPoint: ...];  // location of the cursor
[popup setLevel: NSPopUpMenuWindowLevel];
[_window addChildWindow: popup ordered: NSWindowAbove];
[_popupController showWindow: sender];

The NSPanel itself has its own subclass which implements -canBecomeKeyWindow (returning YES), so that the NSTableView in the popup can receive key events.

This works pretty well. The only problem I have with this is that when my NSPanel is the key window, the main app NSWindow is not (obviously), which causes the red/yellow/green window controls to go dim. Clearly, in programs like Xcode, the window controls don't dim every time you start to type a method name.

Am I barking up the wrong tree? Is NSPanel the wrong way to make a custom pop-up control? Or is there some way to make an NSPanel become the key window without its parent window (or other windows) dimming their window controls?

EDIT: Is there any way to find out what Xcode is actually using, like whether it's an NSPanel?

1 Answers1

1

Try to add NSNonactivatingPanelMask flag to your NSPanel style (if you use xib just set "Non Activating" checkbox in Attributes inspector).

Dmitry
  • 7,300
  • 6
  • 32
  • 55
  • This is a useful thing to look at (thanks!), but it wasn't what was causing the problem here. For some reason, even if the NSPanel wasn't `-canBecomeKeyWindow`, it will still accept keyboard events (and not mess up the parent window's controls, of course). I'm not sure I understand the Cocoa responder chain, but it works now. – user241221 Jan 13 '14 at 20:43