This call to xv_get() returns TRUE if row i is selected. To return the first selected row, use
PANEL_LIST_FIRST_SELECTED as follows:
int first_selected;
first_selected = (int)xv_get(list_item, PANEL_LIST_FIRST_SELECTED);
PANEL_LIST_NEXT_SELECTED
returns the next selected row after a specified row. This attri-
bute takes a single integer argument representing the row to start from. If no row is selected
following the specified row, PANEL_LIST_NEXT_SELECTED returns -1.
7.11.4 List Notification
The procedure specified via the attribute PANEL_NOTIFY_PROC is called when a row is se-
lected, de-selected, added, or deleted. List notify procedures are passed the following: the
list item, the string indicating the label of the item being acted upon, any client data associat-
ed with the list entry, a parameter indicating the action being taken, the event which caused
notification, and the row number of the row being operated on. The form of the procedure is:
int
list_notify_proc(item, string, client_data, op, event, row)
Panel_item item; /* panel list item */
char *string;
Xv_opaque client_data;
Panel_list_op op;
Event *event;
int row; /* row number */
item is the panel list item that contains the row that was acted upon. The string parame-
ter is the label of the row. If there is no string associated with the row, the parameter is NULL.
If the row contains both a string and an image, then the string is passed as the parameter.
op is one of the following:
PANEL_LIST_OP_SELECT
PANEL_LIST_OP_DESELECT
PANEL_LIST_OP_VALIDATE
PANEL_LIST_OP_DELETE
If the user selects a row that is not currently selected, the notify procedure is called twice.
The first time it is called with the previously selected row, the op is
PANEL_LIST_OP_DESELECT. The next time the function is called, the op is
PANEL_LIST_OP_SELECT. If the user selects an item that is already selected, the function is
called once, passing the row selected (op is PANEL_LIST_OP_SELECT). Validate is called
when the user inserts a new row (op is set to
PANEL_LIST_OP_VALIDATE). The notify
procedure should return XV_OK to accept the row, or XV_ERROR to reject the row. Delete is
called when the user deletes a row (op is set to PANEL_LIST_OP_DELETE).
Panels
Panels 183
7.11.4.1 List item client data
The client_data parameter is set to whatever client data is associated with the row.
list_glyphs.c uses the attribute PANEL_LIST_CLIENT_DATAS to assign a set of values to the
list items. Each value could have been assigned to the rows one by one using the attribute
PANEL_LIST_CLIENT_DATA. This attribute takes two values: the first is the number of the
row to assign the data to, and the second is the data itself.
xv_create(panel, PANEL_LIST,
...
PANEL_LIST_CLIENT_DATA, 0, "one",
PANEL_LIST_CLIENT_DATA, 1, "two",
PANEL_LIST_CLIENT_DATA, 2, "three",
...
NULL);
You can still assign client data to the panel list item itself using XV_KEY_DATA as with any
other XView object. However, this data can only be retrieved using xv_get() from the
panel list item itself, the first parameter in the callback function.
7.11.5 The Scrolling List Menu
PANEL_ITEM_MENU sets or gets the scrolling list’s read menu if the Scrolling List is in read
mode or the edit menu if the Scrolling List is in edit mode. The mode of the scrolling list is
set with the attribute PANEL_LIST_MODE. PANEL_LIST_MODE takes one of two values:
PANEL_LIST_READ and PANEL_LIST_EDIT. The attribute PANEL_VALUE_
STORED_LENGTH
controls the amount of text that may be edited when in edit mode.
7.12 Message Items
Message items display a text or image message within a panel. The only visible component
of a message item is the label itself. Message items are useful for annotations of all kinds, in-
cluding titles, comments, descriptions, pictures and dynamic status messages. The message is
often used to identify elements on the panel. A message has no value.
You may set or change the label for a message item via PANEL_LABEL_STRING or
PANEL_LABEL_IMAGE. Message items can have notify procedures which are called when
SELECT_UP occurs over the message item. Panel message items are the only panel items
whose font can be set to boldface. The boldness of message items is controlled using the at-
tribute
PANEL_LABEL_BOLD.
Since messages cannot be selected, their primary use is for display purposes only. In
Example 7-4, two message items display normal pipeline pressure, and a warning for high
pipeline pressure.
184 XView Programming Manual
Example 7-4. The message_item.c program
#include <xview/xview.h>
#include <xview/panel.h>
Frame frame;
Panel_item message;
Panel panel;
Panel_item slider;
void
slider_notify_proc(item, value, event)
Panel_item item;
int value;
Event *event;
{
xv_set(message,
PANEL_LABEL_STRING,
value > 500 ? "** HIGH PIPELINE PRESSURE **" : "Okay",
0);
}
main(argc, argv)
int argc;
char **argv;
{
xv_init(XV_INIT_ARGS, argc, argv, 0);
frame = xv_create(NULL, FRAME,
FRAME_LABEL, "Message Item",
0);
panel = xv_create(frame, PANEL,
PANEL_LAYOUT, PANEL_VERTICAL,
0);
slider = xv_create(panel, PANEL_SLIDER,
PANEL_LABEL_STRING, "Pipeline pressure (psi):",
PANEL_MIN_VALUE, 0,
PANEL_MAX_VALUE, 1000,
PANEL_NOTIFY_PROC, slider_notify_proc,
PANEL_SHOW_RANGE, TRUE,
PANEL_VALUE, 100,
0);
message = xv_create(panel, PANEL_MESSAGE,
PANEL_LABEL_STRING, "Okay",
0);
window_fit(panel);
window_fit(frame);
xv_main_loop(frame);
exit(0);
}
Messages produced by this program are shown in Figure 7-15 and Figure 7-16.
Panels
Panels 185
Figure 7-15. Sample panel with message item
Figure 7-16. Sample panel with message item
High Pressure
7.13 Slider Items
Slider items allow the graphical representation and selection of a value within a range. Slid-
ers are appropriate for situations where it is desired to make fine adjustments over a continu-
ous range of values. The user selects the slider bar and drags it to the value that he wishes. A
slider has the following displayable components: the label, the current value, the slider bar
and the minimum and maximum allowable integral values (the range), end boxes, tick marks,
tick mark minimum and maximum tick strings, as well as minimum and maximum value text
strings.
Sliders may be horizontal or vertical depending on the value of PANEL_DIRECTION. This at-
tribute defaults to PANEL_HORIZONTAL, but may be set to a vertical orientation by using the
value PANEL_VERTICAL. The attribute PANEL_SLIDER_END_BOXES sets whether the boxes
at the endpoints of the slider are visible. This attribute defaults to FALSE. The PANEL_TICKS
attribute takes a numeric value that indicates how many evenly spaced “tick-marks” are
drawn next to the item. When PANEL_SHOW_VALUE is TRUE, the current value is shown after
the label in an editable text field. The minimum and maximum allowable values are set with
PANEL_MIN_VALUE and PANEL_MAX_VALUE. The width of the slider bar can be adjusted us-
ing the
PANEL_SLIDER_WIDTH
attribute. When PANEL_SHOW_RANGE is TRUE, the minimum
value of the slider PANEL_MIN_VALUE is shown to the left of the slider bar and the maximum
value PANEL_MAX_VALUE is shown to the right of the slider bar.* The attributes
PANEL_MIN_TICK_STRING and PANEL_MAX_TICK_STRING specify text labels for the mini-
mum and maximum tick values. On horizontal sliders, these strings appear
underneath the maximum and minimum tick marks. If the attribute PANEL_SHOW_RANGE
does not adequately describe the slider values, PANEL_MIN_VALUE_STRING and
*The top and bottom of the slider is used when the orientation is vertical.
186 XView Programming Manual
PANEL_MAX_VALUE_STRING can specify string value labels for the minimum and maximum
slider values. On horizontal sliders, these strings appear to the left/right of the mini-
mum/maximum end boxes.
7.13.1 Slider Selection
Only the slider bar of a slider may be selected. When the SELECT button is pressed within
the slider drag box, the black area of the bar will advance or retreat with the position of the
cursor. The slider value can also be changed via the numeric text field by clicking in the sli-
der bar to the left (horizontal sliders) or below (vertical sliders) the drag box to decrement the
value, or by clicking in the slider bar to the right (horizontal sliders) or above (vertical sli-
ders) to increment the value.
7.13.2 Slider Notification
Slider notify procedures are passed the item, the item’s value at time of notification, and the
event which caused notification:
void
slider_notify_proc(item, value, event)
Panel_item item;
int value;
Event *event;
The notification behavior of a slider is controlled by the value of
PANEL_NOTIFY_LEVEL. It
can be set to one of two values:
PANEL_DONE The default. The notify procedure is called only when the SELECT button
is released within the panel or when the user types in a new value for the
slider’s numeric text field.
PANEL_ALL The notify procedure is called whenever the value of the slider is changed;
this includes when the user selects, drags or releases the SELECT button in
a slider. For each movement of the mouse while dragging the slider drag
box, the slider’s notify procedure is called.
7.13.3 Slider Value
The value of a slider is an integer in the range
PANEL_MIN_VALUE to PANEL_MAX_VALUE.
You can retrieve or set a slider’s value with the attribute PANEL_VALUE and the functions
xv_set() or xv_get().
Panels
Panels 187

Get Volume 7A: XView Programming Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.