[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    Interactor(3X) manual page Table of Contents

Name

Interactor - base class for interactive objects

Synopsis

#include <ivplus/interactor.h>

Description

Interactor is the base class for all interactive objects. Every interactor has a Shape member variable that defines the desired characteristics of screen space in terms of size, shrinkability, and stretchability. This information is used to allocate display space for the interactor. The interactor’s canvas member variable is set to the actual space obtained.

The lower left corner of the canvas is addressed by <0, 0>. The upper right by the member variables <xmax, ymax>.

The input member variable points to the default Sensor for reading events, if any. The output member variable points to the standard painter for performing graphics operations. Interactors generally should not set output. It will either be inherited (and shared) from the interactor’s parent or set by user customization attributes.

An interactor may optionally define the perspective member variable to represent the portion of total area that the interactor is displaying. Perspectives allow interactors to coordinate with other interactors, such as scrollbars, that want to control the display area by scrolling or possibly zooming.

An interactor also may specify certain characteristics of the interactor’s canvas, such as whether it is read-only or read/write, or whether its contents should be saved when not visible.

To be mapped to some portion of the display, an interactor must have been inserted into a scene, called its parent. The interactor will be mapped when its parent is mapped. An interactor that has been inserted directly into the world is called a top-level interactor.

The interactor can specify whether or not it is traversable using the Motif keyboard traversal model.

The interactor has an event translation table which contains a set of event-action pairs. If an incoming event is matched to an entry in the translation table, the corresponding action(s) are sent to Interpret(). See Translations(3X) for a full description of the event translator syntax.

Interactor is an abstract base class.

Class Hierarchy

Interactor->Glyph->Resource

Note:

Interactor is derived from Glyph which in turn is derived from Resource (since Glyphs are shared objects). InterViews Plus is based on the Interactor hierarchy, so for the purposes of this Reference Manual, Interactor is considered the root class of the hierarchy.

Constructors

Interactor()

Interactor(const char* instanceName)

Create an interactor. The interactor can not perform input or output until it has been configured, that is, it or one of its ancestors, has been inserted into the world.

The optional instanceName creates an interactor associated with the string instanceName. The string is used to customize the behavior of the interactor according to user preferences.

Since Interactor is an abstract base class, these constructors are protected.

Public Data

enum NavType { Tab_Item, Tab_Group, Menus }

This is used by the keyboard traversal mechanism to construct tab groups.

enum DirectiveType { Override, Replace, Augment }

This is used by the event translation mechanism to determine how to combine translation strings.

enum CanvasType { CanvasShapeOnly, CanvasInputOnly, CavasInputOutput, CanvasSaveUnder, CanvasSaveContents, CanvasSaveBoth }

See SetCanvasType().

Public Operations

virtual void Adjust(Perspective&)

Suggests to an interactor that its perspective should change to the given perspective. The interactor may choose to accept any part of the new perspective and must ensure that the parameter matches its (new) perspective before returning. Adjust() can be used by another interactor to scroll, pan, or zoom an interactor.

void Align(Alignment, int w, int h, IntCoord& l, IntCoord& b) const

Returns the coordinates which an object with the given width and height will have using the given alignment within the interactor’s canvas. See Alignment(3X) for valid values.

boolean AttributeIsSet(const char*) const

Returns true if On, on, True, or true for the given attribute has been set by the user. Otherwise, it returns false.

boolean Check()

A return of true ensures that a subsequent call to Read() will not block. In other words, there is an event of interest to this interactor on the event queue.

int CheckQueue()

Returns the number of input packets that have been queued within the application. The event queue manager always reads as much information as possible from input. Thus, a single read might store many events in a local buffer. Subsequent reads can simply access the buffer. This buffer can include out-of-band packets, such as those requiring a Redraw(). The number returned by CheckQueue() does not correspond, therefore, to the actual number of input events.

void Config(Scene* nil)

Configures this interactor and its descendants according to user preferences. The scene is assumed to be the interactor’s parent and is used to inherit attribute values. This operation need not be called explicitly. It is called automatically when the ancestors of an interactor become known (e.g., when the interactor or an ancestor is inserted into a world).

Configuration involves a traversal of the interactor hierarchy. For each interactor in the hierarchy, the output painter is either inherited or copied from its parent. If there are user preferences specific to the interactor for painter attributes such as colors, font, and brush, the painter will be copied. For example, suppose the user preference is A*B*font:9x15 and the interactor hierarchy is A.B.C.D (each represents a nesting level in the hierarchy). Interactors A and B will share the same output painter, C will copy B’s output and change the font to 9x15, and D will share C’s output.

After assigning the output painter, configuration is performed recursively on any children interactors. The final step at each node in the traversal is to call the virtual Reconfig() operation.

void Config(World*)

Performs the same actions as void Config(Scene*) except that attributes are inherited from World rather than a parent scene.

void CreateTabGroup()

Builds the tab group structure for the traversable child interactors of the calling interactor. The tab groups created are added to the list of tab groups maintained by the TabGroupLeader object associated with the top level interactor.

void CreateTabGroups()

This operation is only called by a top level interactor from one of the World::Insert* operations. The first time it is called, it creates a TabGroupLeader object to manage the keyboard traversal for the interactors within this window. It then calls CreateTabGroup() on the top level interactor to actually create the tab group structure.

virtual void CurrentFocus(Interactor*)

Changes the keyboard focus to the given interactor.

virtual Interactor* CurrentFocus()

Returns a pointer to the interactor that currently has the keyboard traversal focus. Returns nil if no interactor has the focus or if keyboardFocusPolicy is pointer.

virtual void Disable()

Makes the interactor disabled. If it is currently accepting input, it may not now.

virtual void Draw()

Displays the contents of an interactor, including the contents of any interior interactors. The default Draw() operation calls Redraw(0, 0, xmax, ymax). Interactors usually don’t need to redefine Draw() unless they contain interior interactors (e.g. Scene). Most simple interactors only redefine Redraw().

virtual void Enable()

Makes the interactor enabled. If it had previously not been accepting input, accept it now.

virtual boolean Enabled()

Returns whether or not this interactor is enabled. Disabled interactors ignore input events and may have a different visual appearance.

void Flush()

Makes sure the local buffer of pending operations (if any) is sent to the interactor’s display.

virtual void Focused(boolean)

Focused(true) tells the interactor that it has the current keyboard focus. The interactor will typically set some internal state, and draw a highlight border called the location cursor, using the static painter highlightPainter. Focused() is called during keyboard traversal.

boolean FocusIsExplicit()

Returns true if the X resource keyboardFocusPolicy is set to explicit for this application. In general, an explicit focus means that the user must click in an interactor to give it the keyboard focus. TabGroups and keyboard traversal are available in explicit mode. If keyboardFocusPolicy is set to pointer or any other value, this routine will return false.

const char* GetAttribute(const char*) const

Retrieves the value of a user preference with the given name. GetAttribute() searches for the most specific match to the current context. Returns nil if no match is made. This may be called anytime during or after the Config() traversal which takes place after a composition is inserted into the World.

Canvas* GetCanvas() const

Returns the interactor’s canvas. If the interactor has not been mapped to a display, GetCanvas() will return nil.

CanvasType GetCanvasType() const

Returns the CanvasType used for the interactor. See SetCanvasType() for more information.

const char* GetClassName() const

Gets the class name associated with an interactor.

virtual void GetComponents(Interactor**, int, Interactor**&, int&)

Constructs an array of pointers to the interactors contained within this interactor. The first and second parameters specify an array of interactors that is already allocated. This array is used if it is large enough, otherwise a new array is allocated from free store. The third and fourth parameters return the actual array that was used and the actual number of components. This operation is defined only by Scene. The default operation sets the number of elements to zero.

Cursor* GetCursor() const

Returns a pointer to the Cursor that will be displayed when the pointing device is inside the interactor’s canvas. If the interactor does not explicitly set its cursor, returns nil.

const char* GetInstance() const

Returns the instance name associated with an interactor. Returns nil if no instance name was specified for the interactor.

Perspective* GetPerspective() const

Returns the perspective associated with an interactor or nil if the interactor has not assigned one.

void GetPosition(IntCoord& left, IntCoord& bottom) const

Returns the world coordinates of the lower-left corner of the interactor.

void GetRelative(IntCoord& x, IntCoord& y, Interactor* = nil) const

Maps local coordinates into another interactor’s coordinate system.

If the other interactor is nil, then the coordinates are made relative to the world. This is often used to find the coordinates of an interactor relative to its parent.

void GetRelative(IntCoord& x, IntCoord& y, World*) const

Maps coordinates that are relative to this interactor’s canvas to be relative to the interactor’s world.

Shape* GetShape() const

Returns a pointer to the Shape object of the interactor.

TabGroup* GetTabGroup()

Returns the tab group pointer associated with the interactor. The TabGroup class is used internally by the library during keyboard traversal.

ManagedWindow* GetTopLevelWindow() const

Called by a top level interactor (one which has been inserted directly into the world), returns the associated ManagedWindow. An interactor that is not top level or is not mapped will return nil.

World* GetWorld() const

Returns a pointer to the world the interactor has been inserted into or nil if the interactor’s root ancestor is not mapped. Use World::current() to retrieve a world pointer in situations where GetWorld() fails.

virtual void GrabTopLevel(Cursor* = nil)

Blocks input events for all other windows on the display except for the calling interactor’s top level window. An optional cursor can be passed which will change the cursor used for the pointing device during the grab.

virtual void Handle(Event&)

Processes the given event. This is usually done by checking one or more attributes of the event, such as the event type, and then performing some action. The mouse-based behavior of the interactor is largely determined by the actions defined in this function.

Handle() is typically called by the current event loop after having failed to find an event translation.

virtual void Highlight(boolean)

Turns highlight on or off. The default operation does nothing. Derived classes can define an appearance and behavior when highlighted.

virtual boolean Intercept(Event&)

Takes an action based on the given event prior to passing the event to the target interactor’s Handle() function. This is generally used to check for a match against the interactor’s translation table. If the event is successfully intercepted, returns true, otherwise returns false. In general, if true is returned, the target interactor’s Handle() will not be called.

virtual boolean Interpret(const char* action)

When an incoming event is matched to an event translation in this interactor’s translation table, Interpret() is called for each action specified in the translation.

The action string is an arbitrary string and does not necessarily correspond to an actual member function of the interactor.

The action string is compared against the set of valid actions for this interactor and if a match is found, the corresponding functionality is invoked and Interpret() returns true. In the default event loop Run(), this will result in the target interactor’s Handle() function not being called.

If no match is found, call this interactor’s base class Interpret() with the action string and return the result.

void Listen(Sensor*)

When an interactor is mapped onto a display, its input interest is determined by its input sensor. A different sensor can be specified with the Listen () operation. To switch back to input, call Listen(input).

If the interactor is a top level interactor (i.e., it was inserted directly into the world), Listen() will augment the current sensor or create a new sensor, if one was not defined, with the following event interest:


UpEvent
DownEvent
KeyEvent
FocusInEvent
FocusOutEvent

This guarantees that events of interest to the event translation and keyboard traversal mechanisms are not lost.

virtual NavType NavigationType()

Returns the navigation type of the interactor: Tab_Item, Tab_Group, or Menus.

virtual void NavigationType(NavType)

Sets the navigation type for the interactor.

Scene* Parent() const

Returns the interactor’s parent. If the interactor has not been inserted into a scene or was inserted directly into the world, returns nil.

void Poll(Event&)

Sets an event to reflect the current input state. This is often used to get the current <x, y> coordinates of the mouse pointer. It is important to note that the event’s target field is not set and will cause problems if passed to a function expecting a valid value for this field.

void QuitRunning(Event&)

Sets the event’s target to nil. A Handle() operation can call it to make Run() exit its event dispatching loop. If an event is not available, consider using World::quit().

void Read(Event&)

Each application has a single input queue of events. Any interactor can use Read() to take the next event from the queue. Redraw() and Resize() operations may be called as a side effect of a Read() (or any input operation). The target field of the event specifies the interactor for which the event is intended. This is not necessarily the same as the interactor that performed the Read(). The target is normally the first interactor whose canvas is under the pointing device, and whose sensor has expressed event interest in the event’s eventType.

boolean Read(long sec, long usec, Event&)

Performs the same function as Read(Event&) with one exception. If there are no events to read within the given number of sec seconds and usec microseconds, the call will time out and return a value of false. If an event was successfully read, return true.

virtual void Reconfig()

Performs any configuration specific to a particular interactor. This operation should minimally compute the interactor’s shape based on the shape of its children and/or the characteristics of its output painter (e.g., font). It can also retrieve user preferences specific to this interactor’s class or instance name using GetAttribute().

virtual void RemoveAccelerator(Interactor* target)

Removes any event translations associated with target from this interactor’s translation table.

virtual void Reshape(Shape&)

Sets the shape of the interactor to the passed Shape. The default operation sets the interactor’s shape to the new shape and calls Scene::Change() on the interactor’s parent. Suggested shape information may be lost when an interactor is configured. Thus, it is best to avoid the use of Reshape().

void Run()

Implements a simple event dispatching loop. It calls Read() to get the next event and passes the event to Intercept() to see if there is a valid event translation defined in the translation table. If Intercept() returns false, the target interactor’s Handle() function is called. The loop terminates if World::Done() returns true, or the Handle() operation sets the event’s target to nil with QuitRunning().

virtual void SetAccelerator(const char* accelerator, Interactor* destination)

Adds an accelerator (an event translation) to this interactor’s translation table along with the given destination interactor. When the event specified in the accelerator occurs in this interactor, the action(s) also defined in the accelerator will be passed to the destination’s Interpret() function.

void SetCanvasType(CanvasType)

Sets the type of canvas desired for an interactor. This operation must be performed before an interactor is mapped. The possible canvas types are:
CanvasShapeOnly
The interactor performs no input or output.
CanvasInputOnly
The interactor performs no output.
CanvasInputOutput
This is the default. The interactor performs both input and output operations.
CanvasSaveUnder
Suggests that the interactor will be mapped for a short time and that the information under the canvas should be saved.
CanvasSaveContents
Suggests that Redraw() calls are expensive and should be avoided by caching the display.
CanvasSaveBoth
Requests both CanvasSaveUnder and CanvasSaveContents.

void SetCursor(Cursor*)

Sets the cursor that will be displayed when the pointing device is inside the interactor’s canvas. If the interactor does not explicitly set its cursor, it will use its parent’s cursor.

virtual void SetTabGroup(TabGroup*)

Sets the tab group pointer to the given TabGroup. The TabGroup class is not currently documented.

virtual void SetTabLeader(TabGroupLeader*)

Sets the TabGroupLeader object for the top level interactor. This class manages the keyboard traversal for this window.

void Sync()

Waits until any pending operations have completed. An input operation will do a Sync() automatically if it would block. Thus, applications generally need not call Sync() explicitly.

virtual TabGroupLeader* TabLeader()

Returns the TabGroupLeader object for the top level interactor. This class manages the keyboard traversal for this window.

virtual Scene* TopLevelParent()

Returns a pointer to the interactor’s top level parent in the instance hierarchy. A top level object is one which has been inserted directly into the world.

virtual boolean Traversable()

Returns true if the interactor is traversable using the keyboard traversal model, false otherwise.

virtual void Traversable(boolean)

Sets whether or not this interactor can be a member of a tab group. If set to true, the operation Focused() must also be defined, and the interactor must take responsibility for drawing the location cursor.

virtual void UnGrabTopLevel()

Stops blocking input events to other windows and returns the cursor to the default cursor.

void UnRead(Event&)

Puts an event back on the input queue as if it had never been read.

virtual void Update()

Changes the display to reflect some state change on which the interactor depends. This operation is used in a number of contexts. One example is in managing perspectives. If an interactor changes its perspective (e.g., the total of size of what it is displaying changes), it must notify its perspective, which in turn calls Update() on the interactors that access the perspective (such as a scroller).

Protected Data

int bevelWidth

The width of the Motif-style bevel for this interactor (if any). This can be set by the user using the X resource shadowThickness. If not specified it will default to Beveller::DefaultBevelWidth=2.

This variable is commonly used to calculate canvas offsets and as an argument to the Beveller::Update() function.

static Beveller* beveller

Created during the Config() traversal, this instance pointer is used by derived classes to draw Motif-style bevels.

const char* bottomShadowColor

The user can set this variable by using the X resource bottomShadowColor. It is used exclusively as an argument to the Beveller::Update() function.

Canvas* canvas

Pointer to this interactor’s canvas object.

boolean highlightOnEnter

Indicates whether the X resource highlightOnEnter is set to true or false for this program. A value of true will cause traversable interactors to display their location cursor when the keyboard focus policy is explicit, and the mouse pointer is within canvas of this interactor.

static Painter* highlightPainter

Used by derived classes to draw the keyboard traversal highlight border called the location cursor. The color of this painter defaults to black (#000000) and can be set by the user using the X resource highlightColor.

static int highlightWidth

The width of the keyboard traversal highlight border called the location cursor. This can be set by the user using the X resource highlightThickness . If not specified it will default to DefaultHighlightWidth=2.

This variable is commonly used to calculate canvas offsets and as an argument to the Beveller::Update() function.

Sensor* input

Pointer to this interactor’s default input sensor, if defined.

boolean ktFocus

Indicates whether or not this interactor has the current keyboard traversal focus.

Painter* output

Pointer to this interactor’s default output painter.

Perspective* perspective

Pointer to this interactor’s perspective object.

const char* selectColor

The user can set this variable by using the X resource selectColor. It is used exclusively as an argument to the Beveller::Update() function.

Shape* shape

Pointer to this interactor’s shape object.

TabGroup* tabGroup

The tab group associated with this interactor, if any. The Scene class allocates a TabGroup object in its constructor.

TabGroupLeader* tabGroupLeader

The tab group leader associated with this interactor, if any. Only top level interactors, and some menu classes have a TabGroupLeader object associated with them. This class manages the keyboard traversal structure.

const char* topShadowColor

The user can set this variable by using the X resource topShadowColor. It is used exclusively as an argument to the Beveller::Update() function.

IntCoord xmax, ymax

Coordinates for the upper right corner of this interactor’s canvas object. xmax is equal to the canvas’ width minus one, and ymax is equal to the canvas’ height minus one. These variables are used in most calculations of offsets and drawing coordinates relative to the canvas.

Protected Operations

virtual void Activate()

Notifies the interactor that its canvas has just been mapped.

virtual void Deactivate()

Notifies the interactor that its canvas is about to be unmapped.

virtual DirectiveType Directive(char* &)

Strips the directive (if any) from a translation string and returns the corresponding DirectiveType.

virtual boolean PerformActions(Event&, Interactor*)

Called by Intercept() to check for a match between the event and the event translations in the interactor’s translation table. If found, the action string(s) specified in the translation are passed to Interpret().

virtual void ProcessTranslations(const char* translation, DirectiveType directive = Override)

Take the given translation and merge it with the current set of translations depending on the directive (Augment, Replace, Override). The resulting string will eventually be converted into the interactor’s translation table during the configuration traversal.

virtual void Redraw(IntCoord left, IntCoord bottom, IntCoord right, IntCoord top)

Called when some portion of the interactor needs to be redrawn, presumably because it was previously obscured. The Redraw() operation should not redraw interior interactors. The Interviews library or the Draw() operation will call their Redraw() operations automatically. The default Redraw() operation does nothing.

virtual void RedrawList(int n, IntCoord l[], IntCoord b[], IntCoord r[], IntCoord t[])

Notifies an interactor that several areas of its canvas need to be redrawn, presumably because it was raised to the top of other canvases. The default RedrawList() operation redraws each area separately with calls to Redraw().

virtual void Resize()

Notifies an interactor that its canvas has been created or modified. Only Scenes are typically concerned with calling Resize(), as they must place their component interactors within the new or resized canvas. The default Resize() operation does nothing. Interactors should update their perspective and any other information dependent on the dimensions of the canvas.

void SetClassName(const char*)

Sets the class name associated with the interactor. The name is used to determine user style preferences.

void SetInstance(const char*)

Sets the instance name associated with the interactor. The name can be used to determine user style preferences.

X Resources

background:color

Sets the default output painter’s background color.

bottomShadowColor:color

Darker shadow color used in drawing Motif-style bevels.

font:font

Font for text drawing operations.

foreground:color

Sets the default output painter’s foreground color.

highlightColor:color

Color used to draw the keyboard traversal border. The default is black (#000000).

highlightOnEnter:[On|Off|True|False]

Controls whether or not traversable interactors will draw their highlight border. Only valid when the application resource keyboardFocusPolicy is set to pointer.

highlightThickness:int

Width of the keyboard traversal border (location cursor).

navigationType:[None|TabGroup]

If set to None and the interactor is traversable, it will be included in a tab group. If set to TabGroup and the interactor is traversable, the interactor becomes a tab group by itself. If set to TabGroup and the interactor is a scene, it will create a tab group with any traversable children.

selectColor:color

Typically darker than the background. Used to enhance the appearance of the 3D bevelled appearance of a selected interactor.

sensitive:[On|Off|True|False]

Determines input sensitivity. An interactor with a sensitivity of False or Off will be disabled, meaning it generally not accept any input from the user and may appear grayed out. An interactor with a sensitivity of True or On will be enabled.

shadowThickness:int

The width of the Motif-style bevelled border around most visual interactors. Defaults to Beveller::DefaultBevelWidth=2.

topShadowColor:color

Lighter shadow color used in drawing Motif-style bevels.

translations:string

Modifies the default translation table (if any). A directive can be used to either augment, replace, or override the existing translations. Multiple translations can be given by separating them with a For a full description of the event translation syntax, see Translations(3X) .

traversalOn:[On|Off|True|False]

Only valid for interactors that are already traversable and wehn the keyboard focus policy is explicit. A value of Off or False excludes the interactor from being included in the tab group structure. This prevents the interactor from ever receiving the keyboard focus. A value of On or True allows the interactor to be traversed normally.

Default Keyboard Translations

None.

Examples

No example for this abstract base class.

Files


interactor.h

See Also

Canvas(3X) , Perspective(3X) , Resource(3X) , Scene(3X) , Sensor(3X) , Shape(3X) , Translations(3X) , World(3X) .


Table of Contents