views:

28

answers:

1

Hi,

I'm working on an NSWindow subclass and I'm running into some strange behavior that makes me question some of my assumptions about how windows work on Mac OS X.

What precisely happens to NSWindow instances when [[NSApplication sharedApplication] hide: self] is called?

All windows that do not return NO to -(BOOL)canHide disappear from the screen. Then all windows re-appear when the application becomes active or [NSApplication sharedApplication] unhide: self] is called.

I had assumed that this would be achieved by taking a snapshot of the current window state, then calling orderOut: on all NSWindow instances and then performing the whole thing backwards when unhide: is called.

That does not seem to be the case, however. The orderOut: method of my NSWindow subclass isn't called.. in fact it's not hidden either. It does set setCanHide: to YES though.. what's happening?

Any insights would be very much appreciated.

Best regards,

Frank

+1  A: 

Fire up Instruments and find out for yourself! On my machine (10.6.4) and a 32-Bit application, [NSApplication hide:] calls ShowHideProcess. It's documented there:

http://developer.apple.com/library/mac/#documentation/Carbon/Reference/Process_Manager/process_mgr_ref.pdf

The ShowHideProcess then calls CPSPostHideReq (something in CoreGraphics).

But there is no orderOut:, actually no objc_msgSend() at all.

What do you need it for? Or were you just curious? Because for most cases, you should do just fine listening for the NSApplicationWill/DidHideNotification.

w.m
Thanks for having a look. I did pretty much the same thing in the end, single stepping through the debugger, but it's not the kind of thing that I'm very comfortable with. I thought somebody might have some idea on how this works from previous work.. as so often in OS X the Cocoa layer only does the surface work and then everything goes down into the Carbon layer. I was trying to do a lot of the window management myself because I needed a bit more control of window behavior than Cocoa usually gives you (windows changing layers); that would be fine if NSWindow actually did the whole job.
Frank R.
In the end, realizing that I couldn't get to all the required functionality by subclassing NSWindow or via notifications, I got a hybrid solution (overriding some window management tasks and doing some behind the scenes reconfiguring of NSWindow in response to application and window notifications) and it seems to work fine. It's just not very elegant. Thanks for your help.
Frank R.