How to implement my own pop-up control in Cocoa?

656 views Asked by At

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

There are 1 answers

1
Dmitry On

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