ViewKit Window Support

This section describes how ViewKit ObjectPak supports multiple top-level windows in an application and the ViewKit ObjectPak classes that implement these windows.

ViewKit ObjectPak's Multi-Window Model

There are several possible models for multi-window applications in Xt. One approach is to create a single top-level window used as the main window of the application. All other windows are then popup shells whose parent is the main window. Another approach is to create a single shell that never appears on the screen. All other windows are then popup children of the main shell. In this model, all top-level windows are treated equally, as siblings. One window may logically be the top-level window of the application, but as far as Xt is concerned, all windows are equal.

ViewKit ObjectPak follows the second model. The VkApp class, described in Chapter 3--Application Class creates a single widget that serves as the parent of all top-level windows created by the program. The VkApp base widget does not appear on the screen.

ViewKit ObjectPak Window Classes

All top-level windows in a ViewKit ObjectPak application must be instances of VkSimpleWindow, VkWindow, or a subclass of one of these classes. The VkSimpleWindow class supports a top-level window that does not include a menu bar. The VkWindow class, derived from VkSimpleWindow, adds support for a menu bar along the top of the window. You must create a separate instance of VkSimpleWindow, VkWindow, or a subclass of one of these classes for each top-level window in your application.

Instantiating a VkSimpleWindow or VkWindow object creates a popup shell as a child of the invisible shell created by your application's instance of VkApp. VkSimpleWindow and VkWindow also create a XmMainWindow widget as a child of the popup shell. You define the contents of a window by creating a widget or ObjectPak component to use as the work area (or view) for the XmMainWindow widget.

Typically, you create several widgets and/or ObjectPak components as children of a container widget and then assign that container widget as the view of the XmMainWindow widget. "Creating the Window Interface" describes how to assign a view to a window. Figure 11. illustrates widget hierarchy for the top-level windows of a simple ObjectPak application with two top-level windows.

Figure 11. Widget Hierarchy of Top-level Widgets in ObjectPak Applications

Creating a separate subclass for each window

In most cases, directly instantiating a VkSimpleWindow or VkWindow object is inappropriate.1 In addition to the widgets and components composing the window's interface, most windows require other data and support functions. In accordance with good object-oriented programming style, the functions and data associated with a window should be contained within that window's class. Therefore, the best practice to follow when creating a ViewKit ObjectPak application is to create a separate subclass for each window in your application. You can derive these subclasses from VkWindow for those windows that require menu bars, and from VkSimpleWindow for those windows that do not. "Deriving Window Subclasses" describes the process of deriving window subclasses.

In addition to creating shell and XmMainWindow widgets, the VkSimpleWindow and VkWindow classes set up various properties on the shell window and provide simple hooks for window manager interactions. "Window Manager Interface" discusses the built-in window manager support.

The VkSimpleWindow and VkWindow classes provide simple functions to raise, lower, iconify, and open windows, as described in "Manipulating Windows" . The classes also provide several convenience function for determining a window's state (for example, whether it is visible, iconified, and so on) and for retrieving other window information. These access functions are described in "Window Data Access Functions" .

The VkSimpleWindow and VkWindow classes also register their windows with the application's VkApp instance to support application-wide services such as setting the cursor for all of an application's windows, entering busy states, and manipulating all windows in an application. Chapter 3--Application Class describes how to use these application-wide services.

Documentation Type: