2
votes

I'm trying to replicate the modal behavior of a sheet in Cocoa without actually using a sheet. That is, attaching a borderless child window to the main window and have the child window be the only responder. The parent window should remain key, support resizing, but cannot be navigated/responded to via keyboard or mouse.

So far I've added a borderless NSPanel subclass to the main window, which returns YES from -acceptsFirstResponder, and run the child window modally of the parent. The parent window remains the key window (as the NSPanel subclass returns NO from -canBecomeKeyWindow) but the parent window still has focus. I can use the keyboard to selected a button, which does nothing because of the modal child window. I need the child window to become first responder and calling -makeFirstResponder and setting the -initialFirstResponder view for the window has not effect.

1
So... why not just use a sheet?zpasternack
Sheets have animation (I know I can get rid of this though), a background filter, do not draw layers on top correctly when using transparency, and aren't what I need :)happycodelucky

1 Answers

1
votes

NSWindow has had an - (void)addChildWindow:(NSWindow *)childWindow ordered:(NSWindowOrderingMode)orderingMode method since Mac OS X 10.2. Using the NSWindowAbove ordering mode should be pretty close to what you're looking for. If you create the child window to cover the parent (make the child window borderless), but leave the parent's titlebar exposed – that should do what you're looking for. You may still need to disable interaction with the controls on the parent window while the child is shown if that's the behaviour you want.