Building a Simple Editor Part 1

Written by Gordon Zeglinski

Introduction
The Open Class Library (IOCL) that ships with VisualAge C++ allows the programmer to quickly develop applications. "Fancy" features such as Linkbars, fly-over help, etc. can easily be added to applications. In this issue, we revisit the simple editor created several issues ago, and add some bells and whistles to it.

Linkbars, Linkbars, Everywhere Linkbars
Just about every application has a Linkbar. Creating one without some pre-existing Linkbar control can be a daunting task. Fortunately adding a Linkbar to an IOCL based application is a snap. The ILinkbar class is an easy way to add Linkbars to your applications.

Often, this class will be inherited by the application specific Linkbar as follows: Additionally, the IOCL provides a specialized button class for use in Linkbars. This button class allows Linkbars to display text only, bitmap only or text and bitmap buttons. Linkbars can contain controls other than buttons. But for this example, we will only add in two buttons. The constructor for the EditLinkbarSet is shown below. That's all there is to creating a Linkbar! There's a few things to note though. By default, all ILinkbarButtons use the standard style. This means that they all have the same appearance. Displaying long text in a standard button is impossible. To remove the standard style by changing the button style to ILinkbarButton::defaultStyle&~ILinkbarButton::standardFormat.

To add the Linkbar to the editor window, we have to make the following changes. First, we must add a data member to the Editor class to store the instance pointer to the Linkbar. Then we must add code to constructor and destructor to create and destroy the Linkbar. The changes are shown below.

Help Me: Fly-over Help and Other Fun Stuff
Now that we have a working Linkbar, users usually expect fly-over help and/or a status area to tell them what the buttons do. Adding these features is a simple task. Because these features are related to the Linkbar, I'll add support for them to the EditLinkbarSet class. The new class definition follows Note the order in which the data members are declared.

I've noticed that the order in which the data members are declared matched the order in which they are initialized in the constructor. The initialization order specified in the constructor is NOT followed. This will affect the TAB order of controls in canvas controls in addition to data members that use other data members in their initialization code.

The new constructor for EditLinkbarSet follows. The fly-over help handler loads string from the string resource table. The string it loads for a particular control is based on the control's ID number and the particular table offset (see the included .rc file for an example). It is possible to have a short text phrase for the fly-over window and a longer, more descriptive phrase for the status area.

Once the appropriate entries are added to the string table in the .rc file, and the new code is compiled, we have working fly-over help. All the source for both NT and OS/2 VAC++ is included in oops_src.zip.

Wrapping Things Up
We've seen that adding a Linkbar, fly-over help and an info-area to an application is easy using the IOCL. Although there's a few tricks that have to be looked out for, they are not a hinderance to quickly adding these nifty features to an application.