GEOS SDK TechDocs
|
|
3.1 Using a Basic GenControl Object
|
4 Creating Your Own Controllers
HINT_GEN_CONTROL_TOOLBOX_ONLY, ATTR_GEN_CONTROL_REQUIRE_TOOLBOX_UI, ATTR_GEN_CONTROL_PROHIBIT_TOOLBOX_UI, ATTR_GEN_CONTROL_APP_TOOLBOX_UI
A s stated earlier, any GenControl object can be manifested either as menus and menu items or as a set of tools. In fact, the controller can potentially have both its menu and its tools usable at once. Creating and using a toolbox or tool bar is a bit more complex than simply including the controller, however.
You can add the use of tool bars and tool boxes to your application in two ways: First, you can simply add a GenToolControl object and associated GenToolGroups and let them do all the work for you. Second, you can interact directly with the controller object(s) to put up, take down, and otherwise manage the tools. In nearly all cases, the first is preferable.
This section focuses on the use of a GenToolControl and GenToolGroup objects to manage and place your tools and toolboxes. If you want to manage tools without using a GenToolControl, you will have to know more about
GenControlClass
; see Creating Your Own Controllers
for complete details.
Tools are most often represented by specific buttons or popup lists presented in various toolbars for easy use. They are functionally redundant to the menu features represented by the normal features of the controller, but the tools and menus can both be visible and usable at the same time.
To provide and manage tools, you need to understand the following components:
The most basic tool configuration includes a floating tool box in which the controllers' tools appear. To use a tool box, you only need to define a toolbox GenInteraction, add a GenToolControl object, and put them both in a menu. Typically, this will be an "Options" menu.
Providing a Basic Tool Box
shows the configuration required for providing a basic tool box as well as the controller's default menu. (You could prohibit the appearance of the menu by setting
ATTR_GEN_CONTROL_TOOLBOX_ONLY
in the controller's instance data.) This example provides all the tools by setting the application's UI level in the GenApplication object. All the tools will then appear in the toolbox and its associated popups as shown in the figure above.
The tool box must be a GenInteraction object; for a floating tool box (as opposed to a tool bar), set it to be a dialog box (GIV_DIALOG). It should also have a moniker and
HINT_TOOLBOX
. The tool box must also be given a name. This name is used by the GenToolControl to identify the tool box. The name is set in a separate chunk and is a simple character string.
At startup, the GenToolGroup for the point size controller is set as a child of the floating tool box. The GenToolControl will move the GenToolGroup to other toolbars if possible; the tools must be set somewhere at startup, though, and the tool box is the logical starting point.
The GenToolControl object will be of
GenToolControlClass
, as shown. It must at least have the
GTCI_toolboxList
field set to the chunk handle of a table of tool locations. In this example, the only location available to tools is in the floating tool box; other locations may be specified as detailed in Tool Placement
below.
The table must appear in its own chunk in the same resource block as the GenToolControl object. It is an array of
ToolboxInfo
structures, each of which contains two optrs. The first is the optr of a tool location (typically a GenInteraction that may contain tools), and the second is the optr of the associated name. The structure of
ToolboxInfo
is shown below:
typedef struct {
optr TI_object; /* A GenInteraction that
* can contain tools */
optr TI_name; /* The name chunk of the
* TI_object object */
} ToolboxInfo;
The table is defined as shown in Providing a Basic Tool Box . If you had other controllers to be managed by the tool control, you would add other entries separated by commas.
The GenToolControl also has a tool group list indicating the name of each GenToolGroup. It is set up in a similar form to the tool box table.
Code Display 12-4 Providing a Basic Tool Box
/* This code display shows the entire psctext.goc file, with changes noted. All * unchanged code has had its comments stripped. For descriptions, see earlier * displays in this chapter. */
@include <stdapp.goh> @include <ui.goh> @include <Objects/Text/tCtrlC.goh>
@class PSCTextProcessClass, GenProcessClass; @endc
@classdecl PSCTextProcessClass, neverSaved;
@start AppResource;
@object GenApplicationClass PSCTextApp = {
GI_visMoniker = "Point Size Control Sample Application";
GI_comp = @PSCTPrimary;
gcnList(MANUFACTURER_ID_GEOWORKS, GAGCNLT_WINDOWS) = @PSCTPrimary;
gcnList(MANUFACTURER_ID_GEOWORKS, GAGCNLT_SELF_LOAD_OPTIONS) =
@PSCTSizeControl, @PSCTToolControl;
}
@end AppResource
@start Interface;
/* GenPrimary Object * Typically, an Options menu will be set up as a child of the Primary and * the tool box and tool control will be children of that menu. */
@object GenPrimaryClass PSCTPrimary = {
GI_comp = @PSCTSizeControl, @PSCTopTextObj, @PSCBotTextObj, @PSCTOptionsMenu;
HINT_SIZE_WINDOW_AS_DESIRED;
HINT_ORIENT_CHILDREN_VERTICALLY;
}
/* Options Menu
* This menu is the parent for both the Tool Box and the tool controller. */
@object GenInteractionClass PSCTOptMenu = {
GI_comp = @PSCTToolBox, @PSCTToolControl;
GII_visibility = GIV_POPUP;
ATTR_GEN_INTERACTION_GROUP_TYPE = (GIGT_OPTIONS_MENU);
}
/* Tool Box Location Table * The Tool Box Location Table is used by the GenToolControl object * to associate tool locations with their names. The table is an array * of ToolboxInfo structures. Multiple entries would be separated with * commas. */
@chunk ToolboxInfo PSCTToolboxList[] = {
{@PSCTToolBox, @PSCTToolBoxName} /* The single tool location is the
* floating tool box PSCTToolBox. */
};
/* Tool Group Information Table * The Tool Group Information Table is used by the GenToolControl to associate * tool groups with their names. The table is an array of ToolGroupInfo structures. * Multiple entries would be separated with commas. */
@chunk ToolGroupInfo PSCTToolGroupTable[] = {
{@PSCTPointSizeToolGroup}
};
/* Floating Tool Box * The Tool Box object is a GenInteraction dialog box. All toolboxes must * have HINT_TOOLBOX and may have any additional geometry hints you * deem necessary. Because every controller's GenToolGroup object must * be a child of some tool bar, the PSCTPointSizeToolGroup is set at * startup as a child of this floating toolbox. */
@object GenInteractionClass PSCTToolBox = {
GI_visMoniker = `T', "Tools";
GI_comp = @PSCTPointSizeToolGroup;
GII_visibility = GIV_DIALOG;
HINT_TOOLBOX;
HINT_ALLOW_CHILDREN_TO_WRAP;
HINT_ORIENT_CHILDREN_HORIZONTALLY;
HINT_FULL_JUSTIFY_CHILDREN_HORIZONTALLY;
}
/* The Tool Box Name must be specified for the tool control object. It * must be a character string, and there must be one for each entry in * the Tool Location table. */ @chunk char PSCTToolBoxName[] = "Floating Tool Box";
/* GenToolControl Object * The Tool Control object must have just the GTCI_toolboxList and * GTCI_toolGroupList fields set; these contain lists of tool bars and * tool groups along with their names. */
@object GenToolControlClass PSCTToolControl = {
GTCI_toolboxList = @PSCTToolboxList;
GTCI_toolGroupList = @PSCTToolGroupTable;
HINT_SAME_CATEGORY_AS_PARENT;
}
/* PointSizeControl */
@object PointSizeControlClass PSCTSizeControl = {
GI_visMoniker = `z', "Sizes";
GII_visibility = GIV_POPUP;
}
/* GenToolGroup Object * Each controller object has exactly one GenToolGroup object for managing * its tools and for management by the GenToolControl. The Tool Group has * a single instance field specifying the controller for which it works. */
@object GenToolGroupClass PSCTPointSizeToolGroup = {
GTGI_controller = @PSCTSizeControl;
}
/* GenText Objects */
@object GenTextClass PSCTopTextObj = {
GI_attrs = @default | GA_TARGETABLE;
HINT_DEFAULT_FOCUS;
HINT_DEFAULT_TARGET;
ATTR_GEN_TEXT_DEFAULT_CHAR_ATTR = ((VTDS_12 << VTDCA_SIZE_OFFSET) |
VTDF_URW_ROMAN);
}
@object GenTextClass PSCBotTextObj = {
GI_attrs = @default | GA_TARGETABLE;
ATTR_GEN_TEXT_DEFAULT_CHAR_ATTR =
((VTDS_12 << VTDCA_SIZE_OFFSET) | VTDF_URW_ROMAN);
}
@end Interface
Tools are movable; this means that controller tools can appear in any GenInteraction you may specify in the Tool Location Table. For example, you may want the user to be able to specify where she or he wants the tools to appear: in the floating tool box, at the top of the primary window, at the left of the display, or between the text objects. To support these locations for the tools, all you need to do is set up empty GenInteraction objects in the appropriate locations and add entries to the Tool Location Table.
The setup described above requires quite a few GenInteraction objects to be added to the application's generic tree. A line drawing of the geometry with all the empty GenInteractions is given in the figure above and the new generic tree of the application is shown in the figure below. The code representing this configuration is shown in Movable Tools
--pay particular attention to the Tool Location Table and to the fact that each GenInteraction must have the hint
HINT_TOOLBOX
set in order to receive the tools.
Code Display 12-5 Movable Tools
/* This code display builds on Providing a Basic Tool Box to show how tools * may be moved around your application's window by the user. Although this is * not difficult to do from scratch, it is quite involved; if you want this * functionality, it is best to include a GenToolControl object. * This code display only shows those objects that are additional to or altered * from the previous display. */
/* GenPrimary Object * Two GenInteractions are made children of the Primary for geometry purposes. * The first, LeftToolBar, is actually a tool bar; the second, * TextAndToolInteraction, is a grouper interaction for geometry purposes. */
@object GenPrimaryClass PSCTPrimary = {
GI_comp = @LeftToolBar, @PSCTSizeControl, @PSCTOptMenu,
@TextAndToolInteraction;
gcnList(MANUFACTURER_ID_GEOWORKS, GAGCNLT_SELF_LOAD_OPTIONS) =
@PSCTSizeControl, @PSCTToolControl;
HINT_SIZE_WINDOW_AS_DESIRED;
HINT_ORIENT_CHILDREN_HORIZONTALLY;
}
/* Tool Location Table * The Tool Location Table is updated with the new tool box information. Each of * the new tool boxes is given a name, and each must appear in this table. * Note that the ToolGroup Information Table does not change. */
@chunk ToolboxInfo PSCTToolboxList[] = {
{@PSCTToolBox, @PSCTToolBoxName},
{@LeftToolBar, @LeftToolBarName},
{@TopToolBar, @TopToolBarName},
{@MiddleToolBar, @MiddleToolBarName}
};
/* TextAndToolInteraction Interaction
* This GenInteraction is used solely as a place holder grouping object to allow
* the LeftToolBar object to extend the full height of the Primary window. */
@object GenInteractionClass TextAndToolInteraction = {
GI_comp = @TopToolBar, @PSCTopTextObj, @MiddleToolBar, @PSCBotTextObj;
HINT_ORIENT_CHILDREN_VERTICALLY;
HINT_EXPAND_WIDTH_TO_FIT_PARENT;
}
/* New Tool Box Interactions * These GenInteraction objects are all tool boxes that appear in the Tool Location * Table. None actually has tools in it on startup; the tool controller allows the * user to place the tools of each active controller in any of these tool boxes. */
@object GenInteractionClass LeftToolBar = {
HINT_TOOLBOX;
HINT_EXPAND_HEIGHT_TO_FIT_PARENT;
HINT_ALLOW_CHILDREN_TO_WRAP;
HINT_ORIENT_CHILDREN_VERTICALLY;
}
@chunk char LeftToolBarName[] = "Left of Text";
@object GenInteractionClass TopToolBar = {
HINT_TOOLBOX;
HINT_EXPAND_WIDTH_TO_FIT_PARENT;
HINT_ORIENT_CHILDREN_HORIZONTALLY;
HINT_ALLOW_CHILDREN_TO_WRAP;
}
@chunk char TopToolBarName[] = "Above Text";
@object GenInteractionClass MiddleToolBar = {
HINT_TOOLBOX;
HINT_EXPAND_WIDTH_TO_FIT_PARENT;
HINT_ORIENT_CHILDREN_HORIZONTALLY;
HINT_ALLOW_CHILDREN_TO_WRAP;
}
@chunk char MiddleToolBarName[] = "In Between Text";
ATTR_GEN_CONTROL_APP_TOOLBOX_UI
Occasionally an application may want to add some additional UI gadgetry to
a set of controller tools.
ATTR_GEN_CONTROL_APP_TOOLBOX_UI
is analogous to
ATTR_GEN_CONTROL_APP_UI
, described in Adding Application-Specific UI Gadgetry
. This attribute specifies a generic object tree that can be attached to the controller's tools as if it were part of the controller normally. For an example of
ATTR_GEN_CONTROL_APP_UI
's use, see
Adding Application-Specific UI Gadgetry
.
GEOS SDK TechDocs
|
|
3.1 Using a Basic GenControl Object
|
4 Creating Your Own Controllers