UpPreviousNext

Creating a Class with Builder Xcessory

When creating a class, you work with all three main Builder Xcessory windows. With the Browser, you switch between Instance and Classes views of your interface, viewing and manipulating the objects within your classes. With the Resource Editor, you customize the look and feel of your classes, setting resources, callbacks and event methods. With the Palette, you create the objects comprising your classes, and use, store, and share the classes themselves.

Creating a class

To create a class, use one of the following methods:

· In Instances view, select the top-level object of the hierarchy that you wish to make a class. Then select Make Class from the Browser:Edit menu (or MB3 Quick Access menu). You are prompted for the name of the new class.

· In Classes view, drag an object from the Palette and place it on the display. You are automatically prompted for the name of the new class. If you drag a widget, your class consists of only that widget. If you drag another class object, the new class is a subclass of the specified object.

Once you supply a class name in the dialog displayed for that purpose, the class is automatically included in the Project Classes group of the Palette.

For example, you might want to create a class that combines a label and text field within a form.

Example:
Creating an object

First, create the objects by following these steps:

1. Create a form.

2. Place a label and a text field within the form as shown in the following figure:

 

Widget Hierarchy

3. You can use the Form Editor and Ctrl+MB1 on the attachment handles to set any appropriate constraint resources. The collection should now look something like the following figure:

 

LabelField Widget Collection

Example:
Making a collection of objects into a class

To make this collection of objects into a class, follow these steps:

1. Select the container widget (the form) by clicking on its instance name in the Browser widget hierarchy.

2. Select Make Class from the Browser Edit menu, or from the MB3 Quick Access menu.

3. In the Name field, enter LabelField. The new class is automatically
added to the Palette in the Project Classes group as shown in the following figure:

 

LabelField Class on Palette

The collection is now collapsed into a class instance on the Browser as shown in the following figure:

 

Class Instance labelField

Switch the Browser to Classes view. The class is now expanded on the Browser and you can view its entire membership as shown in the following figure:

 

LabelField Widget Hierarchy

Editing resources and adding callbacks and event methods

When Builder Xcessory is in Classes view, any component of the class can be modified and any component's widget resource can be exposed. Select the component or components in question and edit the resource values, using the Resource Editor, extended editors, or styles. Callbacks and event methods are treated just as any other resource. Changes made to the class propagate to all instances of the class and its subclasses throughout the interface.


Note: One of the most powerful properties of classes is that changes to the class definition propagate to pre-existing class instances.

Callbacks for class members (Motif) are generated in source code as two separate methods, described in detail in Object-Oriented Programming with C++ and OSF/Motif (Prentice Hall, 1995, 2nd Ed. ISBN 0-13-209255-7) by Doug Young. Exposing a callback results in a third, public method.

See Using Callbacks in C++ Classes for detailed information on these methods.

Creating class instances

You create class instances in the same manner in which you would instantiate any other Palette object, that is, select it on the Palette and drag it to the interface window. Refer to Using the Palette .

Reusing classes

Once saved in the Palette Private Classes or Public Classes group, a class is available each time you start Builder Xcessory. You can also read a previously saved class file into an interface.

Additionally, as with widgets, you can add VkComponent and UIComponent subclasses to the Palette, allowing you to completely code a class and its methods and interact with the fully-working object in Play Mode. For more information on Play Mode see Using Play Mode . For information on adding classes to the Palette, see Permanently Placing Classes on the Palette .

Subclassing

Classes can also be subclassed, furthering the re-usability and usefulness of classes. Subclasses can be modified by adding additional widgets, adding methods and data members, and changing resources.

Adding Methods and Data Members

Methods

In addition to their component objects, classes include methods and the data on which they operate. You can add additional class members from the Resource Editor in Classes view (see Resource Editor in Classes View ). Both methods and data are displayed in a list sorted by item type and scope. Parameter argument types are displayed for methods only.

 

Resource Editor in Classes View

Buttons

You can operate on the items using the following three buttons:

· New

Creates a new class member.

· Edit

Available only for methods. Invokes the code generator and configured editor for this method.

· Delete

Deletes the class member.

Adding members

To add a member to a class, follow these steps:

1. Switch the Browser to Classes view.

2. Select the desired class.

3. Update the Resource Editor.

4. Select the New button.

Builder Xcessory provides an extended editor, the Class Member Editor, to help specify methods and data. (For more details, see Class Member Editor .)

A method or data member specified in the class definition is available to each class instance.


Note: The methods and data you specify on the class itself are in addition to any methods created by Builder Xcessory for callbacks, widget IDs, or event methods that you specify elsewhere.

Class Member Editor

Class Member Editor illustrates the Class Member Editor for a class method:

 

Class Member Editor

Data/Method

Use the toggles at the top of the window to select Data or Method.

Other fields and toggles allow you to assign the type, name, and other attributes such as the member's scope. The attribute selections represented by the tabbed panels vary depending on the code generation language. Also, some cross checking of selections occurs so that inappropriate selections are disabled. For example, if you are using C++ code generation, an initial static value is unavailable for methods and is disabled.

For methods, the parameter fields allow you to enter argument types, parameter names, and (for C++ code generation) default values.

For data, the parameter entry areas and list are hidden. Static data members can provide initial values.

For more information on the Class Member Editor, see Class Member Editor


Note: The Class Member Editor is a valuable tool for specifying language-specific attributes to each added class member. However, even though some cross-checking is performed to confirm the compatibility of your selections, it is not complete and is not meant to be a robust language checker.

User Code Blocks

Member methods and data can also be inserted directly into the User Code Blocks of the class file. These edits are not visible or editable in the Resource Editor. Because they are inside User Code Blocks, they are retained when the files are regenerated.

UpPreviousNext