![]() |
![]() HP OpenVMS Systems Documentation |
![]() |
DECwindows Motif Guide to Application Programming
9.1.9 Invalidating the SVN widgetThe SVN widget is unlike other widgets in that, when your application needs to change one or more components in an entry, the application calls the DXmSvnInvalidateEntry routine to make the SVN widget reflect the change. For example, assume that your application uses a CSText widget as a subwidget component to store text. To change the text in this component, your application would:
The components of an entry are internal to the SVN widget and cannot be set by calls to XtSetArg and XtSetValues. However, SVN resources not related to the components of an entry---for example, DXmSvnNtreePerpendicularLines---can be set by calls to XtSetArg and XtSetValues.
Your application can also call the DXmSvnValidateAll routine to make
the SVN widget reflect changes to all the entries.
The DXmSvnNuseScrollButtons resource creates outer arrows on a scroll bar. Outer arrows perform operations that are a magnitude greater than the inner, or stepper, arrows. Clicking on the up stepper arrow moves the display up one unit, which is the number of rows in the display. Clicking on the upper outer arrow moves the display to the top level of the hierarchy the user is currently viewing. The DXmSvnNuseScrollButtons resource is TRUE by default. For example, if a screen displays messages 20 through 40 in a folder that contains 200 mail messages, clicking on the upper outer arrow causes messages 1 to 20 to be displayed; clicking on the lower outer arrow causes messages 180 to 200 to be displayed. If the hierarchy is a single-rooted hierarchy, that is, it has one level-zero entry, then clicking Shift/MB1 on the outer arrows scrolls to the top or bottom. If the hierarchy has multiple level-zero entries, clicking Shift/MB1 on the outer arrows scrolls the display to the top or bottom of each level 0 hierarchy. In an application like DECwindows mail, which has multiple drawers (all at level 0) and multiple folders (at level 1), clicking Shift/MB1 on the outer arrows scrolls from drawer to drawer (level 0). Clicking MB1 scrolls from folder to folder.
The Ctrl/Up Arrow and Ctrl/Down Arrow keyboard sequences perform the
same functions as the outer arrows without modifiers.
The SVN widget supports smooth scrolling for outline and column display mode when the DXmSvnNliveScrolling resource is set to TRUE. This is the default action.
However, if you set the DXmSvnNliveScrolling resource to FALSE, the SVN
widget implements an index window. The index window is
a special window, attached to the scroll bar, that offers a guide to
the material to be displayed in the window when a user releases the
mouse button.
Your application can call the DXmSvnSetEntryIndexWindow routine to make
sure an entry is displayed in the index window.
This section discusses SVN widget programming considerations, including
topics related to the data hierarchy, enabling and disabling the SVN
widget, manipulating components, and callbacks.
The SVN widget displays the hierarchical structure supplied by the application. The actual information in the hierarchy is transparent to the SVN widget; the application is responsible for creating the hierarchy and supplying the individual lines of text to the SVN widget. Your application must therefore implement a mechanism for tracking data in the hierarchy. The data is usually arranged as initial entries, children, and siblings. For example, the SVN demo application uses the following node data structure to define its hierarchy:
Table 9-1 describes the fields in the _Node data structure.
The _Node data structure lets you visualize the relationship of the data in the hierarchy. The code fragment shown in Example 9-1 implements part of the data hierarchy for the SVN demo application. B, P1, P2, and so forth are _Node data structures.
The node->children field is a pointer to the first child of an entry. In the case of P1, there are seven children, C11 through C17. (The first child has six siblings.) Note that the node->sibling field of C17 points at P2, not C21; C17 and C21 do not have the same parent. This organization reflects how the SVN demo equates the entry_number supplied in the callback with an entry in the data hierarchy. (See Section 9.2.1.2 for more information.)
The data is arranged so that the application does not have to go back
up the hierarchy to the P level to find the next entry in the
hierarchy. If the C21 entry is not opened, the SVN demo code travels
down the C21 path to find the first sibling of C2. (If the C2 entry is
opened, the last child of C21, C212, has C22 as its sibling.)
After you create an instance of the SVN widget, you must attach it to the data for the hierarchy. The attachment is done in the DXmSvnNattachToSourceCallback callback routine, which is invoked when the SVN widget is realized. Your application's DXmSvnNattachToSourceCallback callback establishes the data in a parent/child/sibling hierarchy and then calls the DXmSvnAddEntries routine to specify the initial entries (and number of entries) in the hierarchy. One of the required arguments to the DXmSvnAddEntries routine is the entry number after which to add the new entries, which for the initial entry is zero. In this way, the SVN widget refers to the first entry as number 1. An application can also specify an application-specific entry_tag argument to be associated with the entry. For example, the SVN demo application call to DXmAddEntries is as follows:
This call adds one entry (starting after zero) with a level of zero. The address of the first entry in the data hierarchy, _Node, is passed as a tag, and the entry appears in the scroll index window (if activated) when the user drags the slider.
The DXmSvnNattachToSourceCallback callback does not provide information
about what the entries contain; that information is obtained by the
GetEntry callbacks.
Your application must be able to equate the entry_number field supplied in the callback with an entry in your data hierarchy. The SVN widget numbering sequence is sequential, starting with 1. The number associated with subsequent entries depends on whether these entries are opened and have children or siblings. If an entry is opened and has children, the children are included in the entry numbers. Otherwise, only the siblings are included. Consider the following example from the demo program. Assume the entry_number field in the callback has a value of 5.
In this example, entry number 1 is opened and has children. However, the child of entry 1, "User Interface Design Principles", and that child's siblings are not opened. In this case, the entry_number value of 5 means that the user double clicked on "Application Design Principles". If the user then double clicked on the child of entry 1, "User Interface Design Principles", and it had children, the possible entry numbers would be as follows:
In this case, an entry_number value of 5 means that the user double clicked on "Use Real-World Metaphors". The SVN demo application uses the following code to map the entry_number field, called node_number in the code, to a _Node data structure. (Do not confuse node_number with references in the code to the node->number field, which tells if there are children.)
This code loops through, trying to find the fifth entry. Assume the
entry_number field in the callback has a value of 5.
The code would go through four parent/sibling tests (2 through 5). The
current_node field then contains the address of either
a child or sibling, depending on which entries were opened.
Once the data is attached to the SVN widget, the SVN widget triggers DXmSvnNgetEntryCallback to get information associated with the first entry, such as the number of components and the text from the data hierarchy to associate with the entry. Note that DXmSvnNgetEntryCallback is triggered to get information about any entry in the hierarchy not just the first entry. In the case of SVN demo application, the DXmSvnNgetEntryCallback callback routine performs the following functions:
9.2.1.4 Associating Hierarchy Data with SVNYour application is responsible for linking the data in the hierarchy to entries in the SVN widget. To do this, your application callback routines call the DXmSvnAddEntries routine based on knowledge of the hierarchy data. As described in Section 9.2.1.1, the top-level entry in the hierarchy is known by the SVN widget as entry number 1. When a user double clicks on this entry, the DXmSvnNselectAndConfirm callback is generated. The callback includes the entry_number of the entry, in this case 1. (The DXmSvnCallbackStruct callback data structure is described in Section 9.4.) The callback indicates that the user wants to expand (or contract) this entry. The demo SVN application's _Node data structure includes fields that track siblings (sibling), children (children), and whether or not the children of the element are expanded (opened). The DXmSvnNselectAndConfirm callback routine opens the entry if it is not already opened and calls the DXmSvnAddEntry routine to add any children that the element might have. For example, when a user double clicks on entry number 1, the call to DXmSvnAddEntries is translated as follows:
This call adds four children (node->number) to entry number 1 (node_number). The actual text of these entries is unspecified.
The SVN widget then calls your application's DXmSvnNgetEntry callback
routine for each displayed entry, as described in Section 9.2.1.3.
Disabling an instance of the SVN widget prohibits the user from altering the selected entries and allows your application to modify the underlying data hierarchy. For the changes to appear as expected, your application must disable the SVN widget before calling the DXmSvnInvalidateEntry routine. The following example disables the SVN widget, changes the label string associated with the menu entry, and enables the SVN widget.
9.2.3 Setting the Location CursorYour application can set the DXmSvnNstartLocationCursor resource to specify which entry the location cursor should be first drawn on. By default, the location cursor begins on entry 1.
This resource can be set only when the SVN widget is created. An
application is not able to change the position of this location cursor
at any other time. If an XtSetValues is done on this resource, the
value is ignored.
Your application can invalidate an entry to force the SVN widget to update the entry. As described in Section 9.1.9, your application can call the SVN DXmSvnInvalidateEntry routine to update an entry. The DXmSvnInvalidateEntry routine in turn invokes your DXmSvnNgetEntryCallback callback routine to obtain the new information. The DXmSvnInvalidateEntry routine therefore allows your application to generate DXmSvnNgetEntryCallbacks as needed. For example:
For each entry, test to see if there is an associated CSText widget. If
there is, unmanage the widget and call DXmSvnInvalidateEntry to invoke
the DXmSvnNgetEntryCallback callback.
If your application is in tree mode, it can specify one of the following constants to set the DXmSvnNtreeStyle resource:
The following example sets the tree style to DXmSvnKtopTree:
9.2.6 Setting the Display ModeYour application can specify one of the following constants to set the DXmSvnNdisplayMode resource:
The following example sets the display mode to DXmSvnKdisplayTree:
|