Archives
 
 
 
  Special
 
 
 
  About Us
 
 
 

Newsletter
Free E-mail Newsletter from BYTE.com

 
    
           
Visit the home page Browse the four-year online archive Download platform-neutral CPU/FPU benchmarks Find information for advertisers, authors, vendors, subscribers Request free information on products written about or advertised in BYTE Submit a press release, or scan recent announcements Talk with BYTE's staff and readers about products and technologies

ArticlesExtending OS/2's User Interface


February 1996 / Core Technologies / Extending OS/2's User Interface

The Workplace Shell API is a wondrous object-oriented UI. You can extend it without adding a single executable.

Kurt Westerfeld

IBM's OS/2 Warp gives you hooks to customize its Workplace Shell user interface in ways that Windows 95 has still not caught up with. That capability has been exploited in a number of commercial shell-enhancement products, including Lotus' cc:Mail, Wordperfect's Integration Tools for WP 6.1, and IBM's own Warp Bonus Pak, VisualAge developer tools, Search Manager/2, and multimedia tools. But despite the fact that Workplace Shell has had a stable and robust object technology since 1992, many developers have not become familiar enough with Workplace Shell's underlying S ystem Object Model (SOM) to take full advantage of this power. You can take several routes to a new UI for OS/2, ranging from simply registering new DLLs, through adding object types, to replacing whole classes in the object hierarchy.

For starters, you don't necessarily need to master SOM to change Workplace Shell. Last year, the company I work for, Stardock Systems, introduced a software product based on OS/2 Workplace Shell objects called Object Desktop for OS/2 Warp and OS/2 2.11. Object Desktop blends the use of system objects, object class replacement, system hooks, and other means to create an evolutionary upgrade to the OS/2 Workplace Shell.

Most of Object Desktop is written to the Workplace Shell API. It exploits a number of unique specializations of this API, as well as a few obscure system hooks rarely seen in OS/2 programs. One interesting result of the Object Desktop implementation is that there are no executables! Object Desktop is made up entirely of dynamic link libraries, which are registered either directly or indirectly via the Workplace Shell object-class registration mechanism (WinRegisterObjectClass). Registering a Workplace Shell object class results in an entry being placed in the OS/2 system INI database. The OS/2 Workplace Shell interrogates this database on system start-up and demand loads the corresponding object classes via dynamic linking. Hence, the only executable that runs is the installation program, and thereafter the operating system directly invokes the object code when necessary.

Changing the OS/2 Shell

The most common way to enhance the OS/2 Workplace Shell is by adding new object types to the system class hierarchy. Programming in this environment necessitates using IBM's SOM and Workplace Shell APIs. SOM programming fully supports object-oriented capabilities such as inheritance, polymorphism, and encapsulation, as well as binary replacement of base classes.

To create a new class, you genera te a SOM interface definition language (IDL) file and run it through the SOM precompiler. The precompiler emits C or C++ bindings with empty functions for each object method, private and public header files, and other optional project components. The parent class for the newly generated object class is specified in the SOM IDL file, which, in the case of Workplace Shell objects, is one of the preexisting classes defined by the default OS/2 Workplace Shell. Each overridden method is also specified in the IDL file, along with public and private methods and data.

After the components of the SOM/Workplace Shell project have been generated, OS/2 API or Workplace Shell method code is inserted in each of the overridden methods. The structure of the Workplace Shell methods provides the necessary entry points for creating new windows as necessary, and for creating new threads and initializing resources. For example, a wpInitData method is provided; it's analogous to a C++ object constructor. The Workplace Shell process calls this method whenever a new object is awakened or created. In other cases where new object views may be desired, a programmer can override the base method wpOpen, which is called by the shell whenever a new view is generated for the user to interact with.

Although there are several object types in the Workplace Shell ( see the figure ), there are several reasons for using the WPFolder class as a parent class. Contained objects are saved and restored in a safe and portable manner. File system back-notification of object changes is provided via wpAddToContent and wpDeleteFromContent methods. WPFolder supports background bit maps to customize appearance, custom colors and fonts are saved with no extra effort, and drag-and-drop operations such as copy and delete are supported. And the context menus of contained objects are invoked and dispatched.

WPTransient objects are used within Object Desktop to display temporary objects that do not correspond to any object normally on the OS/2 Desktop. This includes displaying the contents of an Object Archive (i.e., a ZIP file), which is really just a view of a database. In fact, the use of WPTransient objects as temporary placeholders to database query entries is fairly common.

Class Replacement

Probably the most powerful capability exposed by the Workplace Shell API is replacing classes in the SOM/Workplace Shell class hierarchy. Class replacement enables programmers to add behavior to all classes derived from a particular class. The Workplace Shell group originally developed this capability by creating a customized SOM class manager object. (SOM version 2.x has this capability in the somSubstituteClass class manager method).

Class replacement is difficult to describe since there is no analog in other object models to pull examples from, and since "replacement" isn't really what happens. The mechanism is actually more like an "insertion" into the object class hierarch y.

A new class is derived from a parent class in the Workplace Shell class hierarchy. The new class is given specialized behavior -- new private and public data and methods may be added to the new class. A one-time call to the OS/2 WinReplaceObjectClass API is made, replacing the original parent class with the new class. After restarting the system, all classes derived from the original parent class, including instance objects of that parent class, gain the behaviors of the new class.

This mechanism may be hard to visualize, but the results are astounding. As the figure above implies, MyNewClass does not actually replace the parent class WPFolder as much as it sneaks into the class pecking order right after WPFolder. The result is that any behavior added to MyNewClass is propagated down to the classes derived from WPFolder, such as WPDrives and WPNetwork. This is how a number of Workplace Shell enhancements are implemented, including the IBM Multimedia Viewer, Lotus cc:Mail, and some object-lev el security add-ons.

To see class replacement in action, install the Multimedia Viewer from the Warp BonusPak. Then, all objects derived from WPDataFile (which includes any file on your system) will gain the menu choice Create LTReference, which can be used to create a reference for the data object (an image or other multimedia data type) in a new type of folder called a "light table."

Advice for Enhancing the UI

Developing an object that enhances the UI implies that the code is always active, which is a challenge to minimizing system impact. Products intended to be add-ons must work with the same performance features and stability as the system they are installed on. System requirements should not be greatly affected.

The best way to ensure system stability is to use OS exception handlers in all object methods. The OS/2 and Win32 APIs allow for structured exception handlers to be added to programs or objects, giving programs the ability to self-diagnose memory violat ions, to recover gracefully from stray pointers, and so on. If your objects or objects you interact with use semaphores -- a universal trait in a multithreaded environment -- exception handlers are a necessity to ensure that resources acquired are freed even when a memory violation occurs.

When implementing a system add-on, use the least common denominator of API features for maximum compatibility. While it is tempting to use features that may appear only on one particular flavor of an operating system, don't succumb. Use the set of APIs that maximize your potential market.

In terms of forward and backward compatibility, an interesting option surfaces when using a flexible object model like IBM's SOM or another CORBA-compliant object model. With these types of systems, it is easier to write objects that adapt to the environment they encounter. For example, in OS/2 2.11 there is no provision for folder objects to have animated icons. Users of Stardock's Object Desktop, however, would like to have support for this new feature in the OS/2 Warp user interface. By taking advantage of SOM, Object Desktop objects are able to discover that a particular interface is implemented by base functionality when running under OS/2 Warp, and then dynamically overriding the corresponding methods on the fly.

After investigating the various ways you can enhance the OS/2 Warp user interface, and the care you must take to write applications that seamlessly blend with the operating environment, you have to answer a fundamental question: Is it worth it?

There are obvious advantages to developing applications in this manner. Complete forward and backward compatibility is guaranteed by the IBM System Object Model, which allows for changes to base class code without recompiling. Because of this capability, Workplace Shell developers enjoy receiving new features for free as versions of the OS are released with changes to base classes. Another advantage to SOM/Workplace Shell programming is a more elaborate and fle xible architecture for developing adaptable code.

Workplace Shell objects also present a more powerful set of capabilities to end users. Most OS/2 applications are written to the Presentation Manager API alone. These programs miss out on exposing links to shell objects altogether. To gain similar features to shell objects, developers have to laboriously code drag and drop, settings notebook, and other UI nuances instead of inheriting them. What's more, as IBM adds the intended OpenDoc and Taligent code bases to the Workplace Shell, Presentation Manager applications will have to be revised to keep up. Workplace Shell objects will inherit these features for free.


Workplace Shell Classes Revealed

illustration_link (7 Kbytes)

The Workplace Shell object types are organized by their persistence characteristics.

WPTransient objects have no persistence; they exist only during the lifetime of the machine state (Workplace Shell process state).

WPAbstract objects store object settings in the OS/2 INI files, and WPFolder and WPDataFile objects store object settings in extended attributes inside the OS/2 file system.


Class Replacement

illustration_link (19 Kbytes)

Class replacement in the OS/2 Workplace Shell enables programmers to insert their new classes anywhere in the class hierarchy, allowing all derived classes to inherit the new behavior.


Kurt Westerfeld develops software products for Stardock Systems, Inc. You can reach him on the Internet at kwester@mail.os2bbs.com .

Up to the Core Technologies section contentsGo to next article: An Alpha in PC ClothingSearchSend a comment on this articleSubscribe to BYTE or BYTE on CD-ROM  
Flexible C++
Matthew Wilson
My approach to software engineering is far more pragmatic than it is theoretical--and no language better exemplifies this than C++.

more...

BYTE Digest

BYTE Digest editors every month analyze and evaluate the best articles from Information Week, EE Times, Dr. Dobb's Journal, Network Computing, Sys Admin, and dozens of other CMP publications—bringing you critical news and information about wireless communication, computer security, software development, embedded systems, and more!

Find out more

BYTE.com Store

BYTE CD-ROM
NOW, on one CD-ROM, you can instantly access more than 8 years of BYTE.
 
The Best of BYTE Volume 1: Programming Languages
The Best of BYTE
Volume 1: Programming Languages
In this issue of Best of BYTE, we bring together some of the leading programming language designers and implementors...

Copyright © 2005 CMP Media LLC, Privacy Policy, Your California Privacy rights, Terms of Service
Site comments: webmaster@byte.com
SDMG Web Sites: BYTE.com, C/C++ Users Journal, Dr. Dobb's Journal, MSDN Magazine, New Architect, SD Expo, SD Magazine, Sys Admin, The Perl Journal, UnixReview.com, Windows Developer Network