GEOS SDK TechDocs
|
|
1.2 How Controllers Work
|
2 Standard Controllers
As stated above, for an application to use a controller (or several controllers), the application programmer needs to know very little about the controller itself. A Sample Controller Application (psctext.goc) shows the entire code for the PSCText sample application; note that the programmer has to add no code (just object declarations) to create two editable text objects which can have selectable and settable point sizes.
The application programmer must do two essential things to use a controller object: First, you must include and set up the controller properly. In the example application, the PSCTSizeControl object is a menu; it could easily have been set up as GIV_DIALOG (typically, though, this particular controller is implemented as a menu). Because
GenControlClass
is a subclass of
GenInteractionClass
, you can set up the controller exactly like any other GenInteraction.
Second, you must set up your data objects to interact with the controller. The data objects should be written for this automatically; for example, the GenText objects automatically send the proper notification to the GCN mechanism to ensure that all appropriate controllers are notified of all changes. Note, however, that the GenText objects have to be set targetable before the controller can operate on them. Some data objects will be set up to work with their controllers automatically; others may need to have certain attributes set. The GenText objects, for example, are not by default targetable; the controller, however, sends its messages to the application's target object. If the GenTexts are not targetable, they will never gain the application's target and therefore will never react to the controller's requests.
To use a particular controller, you should learn about how that controller's data object needs to be set up. To help you with this, Standard Controllers lists the various controllers included in the system and where they are documented.
Code Display 12-1 A S ample Controller Application (psctext.goc)
@include <stdapp.goh> @include <ui.goh> @include <Objects/Text/tCtrlC.goh>
/* The PSCText application's process class runs the application's primary * thread. For a description of GenProcessClass, see Hello World. */
@class PSCTextProcessClass, GenProcessClass; @endc @classdecl PSCTextProcessClass;
@start AppResource;
/* The PSCTextApp object defines the application object for the
* application. For full information, see Hello World.
* The controller is also placed on the application's self-load-options
* GCN list to ensure that it loads its options properly when returning
* from saved state. This is shown below in the second of the two
* GCN list declarations. */
@object GenApplicationClass PSCTextApp = {
GI_visMoniker = "Point Size Control Sample Application";
GI_comp = @PSCTPrimary;
gcnList(MANUFACTURER_ID_GEOWORKS,GAGCNLT_WINDOWS) = @2PSCTPrimary;
gcnList(MANUFACTURER_ID_GEOWORKS,GAGCNLT_SELF_LOAD_OPTIONS) = @PSCTSizeControl;
}
@end AppResource
@start Interface;
/* The PSCTPrimary object serves as the primary window of this sample application.
* Its children are the Point Size Control object and the two GenText objects. */
@object GenPrimaryClass PSCTPrimary = {
GI_comp = @PSCTSizeControl, @PSCTopTextObj, @PSCBotTextObj;
HINT_SIZE_WINDOW_AS_DESIRED;
HINT_ORIENT_CHILDREN_VERTICALLY;
}
/* The PSCTSizeControl object is the controller that provides all the point size
* functionality. It will automatically create a menu called "Sizes" (due to the
* GI_visMoniker) and all the entries of that menu.
* This controller will work on whichever of the two GenText objects
* (PSCGTopTextObj and PSCBotTextObj) is set the target; the controller's UI
* objects (the Sizes menu) send their messages directly to the target via the
* TravelOption TO_TARGET. If a point size is selected as the user's first action,
* it will work on PSCTopTextObj because that is set up as the default target. */
@object PointSizeControlClass PSCTSizeControl = {
GI_visMoniker = 'z', "Sizes"; /* Give the controller a name */
GII_visibility = GIV_POPUP; /* Make the controller a menu */
}
/* These two GenText objects are simple; they use only the defaults plus the
* items shown here. Both must be set targetable (GA_TARGETABLE) to be included
* in the target hierarchy; this is necessary when using controllers because of
* the note in the above comment. The PSCTopTextObj is made the default focus
* (to get keyboard input) and the default target (for controller operation). */
@object GenTextClass PSCTopTextObj = {
GI_attrs = @default | GA_TARGETABLE;
/* Initially, this text object uses the VisTextDefaultSize VTDS_12
* (12 pts) and the VisTextDefaultFont VTDF_URW_ROMAN. You can use
* the PointSizeControl object to change this point size. */
ATTR_GEN_TEXT_DEFAULT_CHAR_ATTR = ((VTDS_12 << VTDCA_SIZE_OFFSET) |
VTDF_URW_ROMAN);
/* Set the font mapping to none to turn off the defaults. */
HINT_DEFAULT_FOCUS;
HINT_DEFAULT_TARGET;
}
@object GenTextClass PSCBotTextObj = {
GI_attrs = @default | GA_TARGETABLE;
ATTR_GEN_TEXT_DEFAULT_CHAR_ATTR = ((VTDS_12 << VTDCA_SIZE_OFFSET) |
VTDF_URW_ROMAN);
}
@end Interface
GEOS SDK TechDocs
|
|
1.2 How Controllers Work
|
2 Standard Controllers