DekGenius.com
[ Team LiB ] Previous Section Next Section

3.7 Drawers

Drawers provide additional window space for an application's interface, and can easily be tucked away from view when not in use. Drawers are ideal for controls that are frequently used, but don't need to be visible at all times. Figure 3-9 shows an example of a drawer in Mail.

Figure 3-9. The mailboxes drawer from Mail.app
figs/cocn_0309.gif

The class NSDrawer defines the behavior of drawers. Interface Builder provides the ability to create drawers and attach them to windows. The window that a drawer is associated with is called the parent window. Like windows, drawers contain a view hierarchy. The top-level view of this hierarchy is the drawer's content view. NSDrawer objects in Interface Builder have outlets connected to the drawer's parent window and content view. Alternatively, you can set a drawer's parent window of a drawer with the method setParentWindow: and set the content view with setContentView:.

When a drawer opens or closes, it slides from an edge of the parent window. Drawers have a preferred edge of the parent window on which they try to open. Without sufficient room between the preferred edge and the adjacent edge of the screen display, the drawer opens on the opposite side of the window. The preferred edge may be any side of the window: top, bottom, left, or right. You can access this property with setPreferredEdge: and preferredEdge. In these methods, the edge is represented by the data type NSRectEdge, which has the possible constant values NSMinXEdge, NSMaxXEdge, NSMinYEdge, and NSMaxYEdge.

A drawer's state is determined by the state method. The state of a drawer can be specified with NSDrawerClosedState, NSDrawerOpenState, NSDrawerClosingState, or NSDrawerOpeningState. To open a drawer, send an open message. If the drawer is open, nothing happens. To close a drawer, invoke close, which will do nothing if the drawer is already closed. Each method has an counterpart that is appropriate for use as the action of an interface object: open: and close:. Additionally, the toggle: action method closes an open drawer and opens a closed drawer.

    [ Team LiB ] Previous Section Next Section