Using ViewKit and X and OSF/Motif Functions

As stated earlier, ViewKit ObjectPak does not replace OSF/Motif. It uses OSF/Motif widgets to implement all of its user interface components, and you are free to make X and OSF/Motif calls directly in a ViewKit ObjectPak application. ViewKit ObjectPak doesn't do anything that you can't do yourself using OSF/Motif directly, but the advantage of using ViewKit ObjectPak is that many commonly-needed services are already implemented for you.

Naturally, not all ViewKit services are appropriate for all applications at all times. If a situation arises in which a ViewKit ObjectPak facility doesn't meet your needs, you can use the lower-level OSF/Motif, Xt, or Xlib facilities to perform the desired operation yourself.

Most ViewKit classes are optional; however, you should be aware that certain ViewKit classes depend on other classes. In particular, most classes depend on the existence of an instance of the VkApp class for application management. If you plan to use any ViewKit ObjectPak facilities, you should not attempt to bypass VkApp and open your own connection to the X server, or directly call XtAppInitialize() or an equivalent function. For best results, you should always allow VkApp to handle the Xt initialization and event dispatching. VkApp is described in detail in Chapter 3--Application Class.

Also, use VkSimpleWindow or VkWindow for all top-level windows. These classes are described in detail in Chapter 4--ViewKit Windows.

As an example of some optional classes, consider the ViewKit dialog management facilities. These are intended to let you use dialogs easily and effectively. ViewKit ObjectPak automatically recycles dialogs (reusing the same dialog over and over for multiple purposes), which uses less memory and can lead to faster response times. It is also easy to add additional buttons to any dialog, to provide context-sensitive help on individual dialogs, and much more. The ViewKit ObjectPak dialog management facility is designed to be as flexible as possible, while minimizing the amount of work required of you. You can even write your own custom dialogs that take advantage of the dialog manager.

However, because the design of the ViewKit ObjectPak dialog management classes makes assumptions about the way typical applications use dialogs, the ViewKit ObjectPak dialog manager can't offer the same control that you could obtain by directly constructing and manipulating an OSF/Motif dialog. Should you encounter a situation where the behavior of the dialog manager doesn't match your application's needs, you can always take the same approach you would have to take if the dialog manager didn't exist: create and manipulate your own OSF/Motif dialog directly using OSF/Motif and Xt functions. This doesn't interfere with ViewKit ObjectPak in any way.

Before implementing your own mechanisms, you should be sure you understand the support offered by ViewKit ObjectPak. Situations in which it's necessary to duplicate functionality supported by ViewKit ObjectPak should be rare. On the other hand, extending the class library by deriving new classes, or writing completely new classes to meet application-specific needs, is a natural part of developing any application based on ViewKit ObjectPak or any C++ class library.