Window Types and Behavior

On-screen windows fall into four principal categories, which vary in appearance and function:

  • Document windows

  • Utility windows

  • Dialogs (includes sheets)

  • Alerts

We’ll describe each of these window types in the following sections. After that we’ll discuss how and when these four types of windows become the main or key window in an application. For many of our examples we’ll use the TextEdit application, the basic word-processor application bundled with Mac OS X and located in the /Applications folder.

Document Windows

A document window is file-based and is the main working area of an application. A window containing a text document being edited in a word processor is a document window, as is a window containing a spreadsheet in a spreadsheet application or an image being manipulated in a graphics editor application. Most document windows, like some of the windows in Figure 1-1 and the window in Figure 1-3, have resize controls and close, minimize, and zoom buttons. The resize control is at the lower-right corner of a document window, while the three window-control buttons are on the left side of the window’s title bar.

A document window in TextEdit editing a file called “Document Window”

Figure 1-3. A document window in TextEdit editing a file called “Document Window”

The small proxy (file) icon to the left of the title in a document window can be manipulated with drag-and-drop, as can a file icon in the Finder. Command-pressing the proxy icon causes the complete folder path of the document file to appear, and when a user drags to one of those folders and releases the mouse button, the corresponding folder opens in the Finder (even if the proxy icon is in a document window from another application, such as TextEdit.)

A document window’s close button displays an X inside it when the document is saved to disk and a dot when the document has not been saved. Document windows usually contain vertical and/or horizontal scrollers when the window contents are too large to fit in the window. An application can have many document windows open at the same time.

Utility Windows

Utility windows provide tools or controls that support document windows. The Font and Colors windows that are available in many applications are utility windows (see Figure 1-4). Utility windows float over document windows and are distinguished by their shorter (in height) title bars and lack of a (working) minimize button. Utility windows sometimes have no title and have only the close button visible (unlike those in Figure 1-4). Cocoa programmers and former NeXTSTEP users refer to utility windows as panels. The Mac OS X terminology guidelines reject use of the term “panel,” but we will use it in this book anyway because the Cocoa API uses it extensively.

The Colors and Font utility windows in TextEdit

Figure 1-4. The Colors and Font utility windows in TextEdit

Dialogs

A dialog is a window that seeks input from a user in response to a specific request. Examples include the familiar Open, Save, and Print dialogs. The Show Info dialog in the Finder is another example. Dialogs come in three types — modeless, document modal, and application modal:

Modeless dialog

Does not prevent the user from working in any other window of the application. Users can change settings in a dialog while still interacting with document windows. The Find/Replace tool in a word processor (see Figure 1-5) is an example of a modeless dialog; Preferences is another. In a modeless dialog, the close button is usually the only window-control button that is enabled.

The Find modeless dialog in TextEdit; compare with document and utility windows

Figure 1-5. The Find modeless dialog in TextEdit; compare with document and utility windows

Document modal dialog

Prevents the user from working with a particular document, but not with other documents in the same or in other applications. Document modal dialogs are always rectangular sheets that animate downward from a document window’s title bar; see Figure 1-6 for an example. Each sheet is attached to a document window, so there is no way that a user can be confused about which document will be saved, printed, etc.

The “Save as” document modal sheet (window) — the document temporarily can’t be edited

Figure 1-6. The “Save as” document modal sheet (window) — the document temporarily can’t be edited

Application modal dialog

Prevents the user from working anywhere else within the application. The user can still switch to and work in other applications. An Open dialog is a common example of an application modal dialog. In TextEdit, for example, no document window can be edited while the Open dialog is displayed (see Figure 1-7). However, you can switch to the Finder or any other application and use it as you would normally. Application modal dialogs typically display their functions in the title bar (e.g., Open) and do not have any window-control buttons (e.g., no close button) because they are dismissed with an OK, Cancel, or other push button at the bottom of the dialog. Application modal dialogs float above document and utility windows, which makes sense because of the user’s need to dismiss them before working elsewhere in the application.

The Open application modal dialog in TextEdit

Figure 1-7. The Open application modal dialog in TextEdit

Alerts

Alerts are displayed in windows or sheets. Alert windows pop up in the center of the screen and display important messages to notify users that a potentially negative event is about to occur. If a user tries to quit the TextEdit application when two or more documents are unsaved, for example, an application modal alert will be displayed, as shown in Figure 1-8. Another common example is the Finder alert that pops up when you try to empty your Trash.

Alert displayed after a user tried to quit TextEdit without saving documents

Figure 1-8. Alert displayed after a user tried to quit TextEdit without saving documents

An alert can also be document modal (i.e., the alert applies to only a single document), in which case it is displayed as a sheet. For an example, see Figure 1-9. Note also that the “Save as” sheet in Figure 1-6 is not an alert; it’s a dialog.

Alert for a single document displayed as a sheet in TextEdit

Figure 1-9. Alert for a single document displayed as a sheet in TextEdit

Application modal alerts have no title in the title bar and are displayed front and center so the user takes notice. Document modal alerts are sheets attached to document windows. Both types of alerts display the application icon, a large, bold-font message, and some smaller-font informational text. A Cancel button (if possible) and default action button also appear near the bottom of the alert.

Info Dialogs

Info dialogs are common in Mac OS X. They provide details about selected files, objects, and so on in the active application. For example, the Finder and Interface Builder rely heavily on modeless Info dialogs. Two examples of the Finder Info dialog for two different selections are shown in Figure 1-10.

Info dialogs from the Finder

Figure 1-10. Info dialogs from the Finder

Some people refer to an Info dialog as an inspector , because the Info dialog allows you to inspect attributes of the selected item.

Under normal circumstances, an Info dialog is on the screen only while its associated application is active. By pressing the Info dialog’s close button, you can close the dialog without adversely affecting any of the application’s documents.

Multi-View Windows

Some applications support multiple views within the same window. For example, every Finder main window supports three different views: the icon view, the list view, and the column view. The System Preferences application also displays many different views in the same window. These views can be selected by clicking an icon-button in the toolbar. In some multi-view windows, different views can be selected by clicking a tab. The System Preferences Displays and Sound windows are examples of multi-view windows with tabs. Each view in a multi-view window is called a pane.

Windows with Drawers

A few Mac OS X windows have “child” windows called drawers. A drawer slides out from its parent window and typically contains controls that are used regularly but don’t need to be visible all of the time (contrast drawers with utility windows, which typically contain controls that often need to be visible all of the time). The drawer of mailboxes in the Mail application is shown at the left in Figure 1-11. The drawer can be made visible or invisible by clicking the Mailbox (toggle) button in the Mail window’s toolbar.

If there is no room for the drawer on the left side of the window, it will open on the right side.

Drawer (left) of mailboxes in Mail application

Figure 1-11. Drawer (left) of mailboxes in Mail application

Main and Key Windows

The key window is the window or dialog that will respond to the Mac keyboard. The main window is the document window that corresponds to the active document (e.g., a document window in a word processor or image window in a graphics editor). The main window is usually also the key window, because users work in the main window most of the time. A main window relinquishes its key-window status temporarily while a user gives instructions to an application, usually in a dialog or utility window that has become the key window. The key window’s title bar is always highlighted, and its title is displayed in black. The main window remains highlighted even when it’s not the key window.

We’ll give you two examples of main and key windows in TextEdit. The first example, which has two document windows, is shown in Figure 1-12. The document window being edited (Doc 2) is the main window, while the Find dialog is the key window. The other document window is neither main nor key.

Main window (Doc 2) and key window (Find dialog) in TextEdit

Figure 1-12. Main window (Doc 2) and key window (Find dialog) in TextEdit

For a second example, suppose that you are using TextEdit to edit a file in the main document window, and you type Command-T to display the Font utility window. The main document window will remain the key window. If you then click the mouse in the Sizes text field that is used to control point sizes in the Font window, the Font window will become the key window, but the document window will remain the main window. When you close the Font window, the main window will go back to being the key window.

Window Order

When you are using Mac OS X on a large display, you may often see 20 or more windows and other objects on the screen. Without a clear ordering scheme, a user’s screen would often be in chaos, and the GUI would lose much of its ease of use. For example, suppose that a new user had spent hours editing a document within an application without saving her work. Suppose also that an alert window for that application popped up and demanded her action before she could save the document. If the alert window were completely hidden by other windows, the user might think she had a hung application, resign herself to losing hours of work, and kill the application (or worse, restart). If the alert window were front and center, this probably wouldn’t happen. As another example, suppose that user couldn’t find a window for an application you wrote because it was hidden under several other windows. She wouldn’t be very productive if she regularly had trouble finding the window when she needed it, and she probably wouldn’t have a great desire to use your application again!

To prevent problems like these, Mac OS X organizes the on-screen windows into several layers. If two windows belong to the same layer, either one may be in front. However, if two windows belong to different layers and occupy the same screen space, the one in the higher level is always in front. Menus take display precedence over all other on-screen objects.

The display order that Mac OS X screen objects follow, from front to back, is as follows:

  1. Regular menus attached to the menu bar, pop-up menus, pop-down menus

  2. The Dock

  3. Alerts

  4. Application modal dialogs

  5. Utility windows

  6. Modeless dialogs

  7. All other windows, including document windows and document modal dialogs attached to document windows

The frontmost window is called the active window. It is distinguished by a title with black text and colored view-control buttons at its upper-left corner.

Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.