Colen
Colen

Reputation: 13918

When reopening an application, how do I restore the zoomed state without causing problems?

If the user zooms our app's main window, closes the app, then reopens it, we want to restore the last state of the main window, so we zoom it before showing the window. The app opens zoomed, so everything is great.

However, if the user clicks the zoom button again, nothing happens. I believe this is because the documentation for zoom: says for step 5:

Determines a new frame. If the window is currently in the standard state, the new frame represents the user state, saved during a previous zoom. If the window is currently in the user state, the new frame represents the standard state, computed in step 1 above. If there is no saved user state because there has been no previous zoom, the size and location of the window do not change.

I think it doesn't unzoom because there's no user state, but I'm not sure why - shouldn't the user state be "the size the windows was at before it was zoomed"? If not, how can I make sure the user state is set properly so that the window un-zooms when the user clicks the zoom button again?

Edit: MrGomez responds below that this is basically how it's meant to work. This doesn't seem to be how other apps behave, though. Try Safari - Zoom it, then quit, then reopen the window, and it restores at the zoomed size. Click the zoom button and it goes back to a smaller size. iCal is the same. How are those apps doing it?

Upvotes: 2

Views: 336

Answers (1)

MrGomez
MrGomez

Reputation: 23896

The trouble is, this is the expected behavior. As you mentioned here:

we want to restore the last state of the main window, so we zoom it before showing the window

You've gone ahead and set the user's view as your standard view. The original default view has not been preserved.

This thread goes into detail about the expected functionality of zoom:. Quoting the accepted answer:

According to the documentation for the zoom: method (note the :), the inverse of zoom: is zoom::

This action method toggles the size and location of the window between its standard state (provided by the application as the “best” size to display the window’s data) and its user state (a new size and location the user may have set by moving or resizing the window).

If it's in the user state (not zoomed), it'll change to the standard state (zoom), and if it's in the standard state (zoomed), it'll change to the user state (unzoom).

The documentation also notes:

If there is no saved user state because there has been no previous zoom, the size and location of the window do not change.

This is what will happen if you started the window out in its standard state; since it was never in any other state, there is nothing for it to unzoom back to.

The trouble is you've overrided the standard state; zoom:'s purpose is to toggle between the user's view and your interface's standard view. To save a user's window state for later restore, follow this guide.

And, for reference, here's the remainder of OSX's style guidelines and a very good tutorial for how you should work with this restriction.


Edit: As discussed, this is also a question of UI modality and the fact OSX windows may be bimodal (user state, maximized state) or trimodal (user state, standard state, maximized state) with a loss of the user state when an application is closed in maximized state. This appears to reproduce itself with stock-standard applications for OSX, including, for example, iCal.app.

As a result, the best that can be done here is to define a functioning UI paradigm that's consistent with applications for OSX, but carries many of the same idiosyncrasies of the little green glob.

Upvotes: 2

Related Questions