7.15.5 Text Value
You can set or get the value of a keyboard focus item at any time via PANEL_VALUE. The fol-
lowing call retrieves the value of name_item into name:
Panel_item name_item;
char name[NAME_ITEM_MAX_LENGTH];
...
strcpy(name, (char *)xv_get(name_item, PANEL_VALUE));
Note that name_item should have been created with a PANEL_VALUE_STORED_LENGTH not
greater than NAME_ITEM_MAX_LENGTH so the buffer name will not overflow.
7.16 Numeric Text Items
Panel numeric text items are virtually the same as panel text items except that the value
displayed is of type int. Also, convenience features (such as increment and decrement but-
tons) ease the manipulation of the text string’s numeric value. There is little programmatic
difference between the text item and the numeric text item. You create a numeric text item
using the
PANEL_NUMERIC_TEXT package. You can also set the minimum and maximum
range for the numeric text field by using PANEL_MIN_VALUE and PANEL_MAX_VALUE, respec-
tively.
7.17 Multiline Text Items
Multiline text items are a special type of panel text item that allow a text field to display mul-
tiple lines. You create a multiline text item using the
PANEL_MULTILINE_TEXT package.
Multiline text items use the attribute PANEL_DISPLAY_ROWS to specify the number of rows of
text to display. PANEL_VALUE_DISPLAY_LENGTH specifies the length in characters of a row
in a multiline text field. PANEL_VALUE_DISPLAY_WIDTH specifies the length in pixels of
each row. A multiline text item will have scrollbars if the stored length is greater than the
displayed length (rows × columns). The maximum stored length for a multiline text item is
specified using
PANEL_VALUE_STORED_LENGTH.* If PANEL_LINE_BREAK_ACTION is
PANEL_WRAP_AT_CHAR, the lines wrap as soon as the number of characters on a line exceeds
the length of the line. If this attribute is PANEL_WRAP_AT_WORD, the lines in the multiline
text item wrap only at word breaks.
*XView Version 3 only supports multiline text items with scrollbars.
Panels
Panels 193
NOTE
Multiline text items display multiple rows, or “lines,” but do not contain embed-
ded returns or line feeds.
Example 7-5 shows how to create a multiline text item with scrollbars.
Example 7-5. The multiline.c program
/*
* multiline.c -- simple panel multiline text item example.
*/
#include <xview/xview.h>
#include <xview/panel.h>
Frame frame;
Panel panel;
main(argc, argv)
int argc;
char **argv;
{
xv_init(XV_INIT_ARGS, argc, argv, NULL);
frame = xv_create(NULL, FRAME, NULL);
panel = xv_create(frame, PANEL, NULL);
xv_create(panel, PANEL_MULTILINE_TEXT,
PANEL_LABEL_STRING, "Product Description:",
PANEL_DISPLAY_ROWS, 6,
PANEL_VALUE_DISPLAY_LENGTH, 32,
PANEL_VALUE, "This wonderful product is \
designed to allow the user to combine and manipulate both \
text and graphic objects easily. The goal of the design team \
is to provide an intuitive, logical interface.",
NULL);
window_fit(panel);
window_fit(frame);
xv_main_loop(frame);
}
The output of this code fragment is shown in Figure 7-19.
7.18 Drop Target Items
A panel drop target item is a bordered image in a panel area that is used to transfer data be-
tween applications. Before you use a panel drop target item you need to be familiar with the
SELECTION and DRAGDROP packages; these are described in Chapter, 18, Selections, and
Chapter 19, Drag and Drop.
A panel drop target item is an object in the class Panel_drop_target_item which is
equivalent to a Panel_item. A drop target item’s owner is a Panel. Examples of several
drop target items are shown in Figure 7-20.
194 XView Programming Manual
Figure 7-19. Panel multiline text item
To use the PANEL_DROP_TARGET package in an application, you need to include both the
<xview/dragdrop.h> and <xview/svrimage.h> header files. The program panel_dnd.c, show-
ing a panel drag and drop example, is presented in Appendix F, Example Programs.
File View Edit Find
Load... Save... Print
Snap View
Text Editor V3 - (NONE), dir; /tmp_mnt/home/user1
/tmp_mnt/home/user1
Snap Type:
Snap Delay:
Window Region Screen
0 2 4 8 16
seconds
Beep During Countdown
Hide Window During Capture
SELECT - Select Window. ADJUST or MENU - Can
Drop Items
Figure 7-20. Sample panel with drop target items
Panels
Panels 195
7.18.1 Programming a Panel Drop Target Item
To use a panel drop target item follow these programming steps:
Create the drop target item.
Specify the glyphs.
Create drag and drop object.
Define the drop target item’s requestor.
Control the glyphs.
Drop on the target item.
Drag from the drop target item.
7.18.1.1 Create the drop target item
You create a panel drop target using xv_create() with the PANEL_DROP_TARGET pack-
age. The following code fragment shows a how to create a drop target item called
drop_target:
Panel_drop_target_item drop_target;
drop_target = xv_create(panel, PANEL_DROP_TARGET, NULL);
7.18.1.2 Specify the glyphs
The attribute
PANEL_DROP_GLYPH
specifies the glyph for a “normal” drop target. The normal
glyph is shown when the drop target item is inactive (no data transfer is occurring).
PANEL_DROP_BUSY_GLYPH specifies the glyph for the “busy” drop target. The busy drop tar-
get glyph is displayed when the drop target item is receiving a drop, or when data is being
sent to another application. You can define the bits for the glyphs as follows (assuming the
files normal.icon and busy.icon contain appropriate data):
static unsigned short normal_bitmap[ ] = {
#include "normal.icon"
};
static unsigned short busy_bitmap[ ] = {
#include "busy.icon"
};
Once the bits are defined, you create server images to represent them as follows:
normal_glyph = xv_create(NULL, SERVER_IMAGE,
XV_HEIGHT, 64,
XV_WIDTH, 64,
SERVER_IMAGE_DEPTH, 1,
SERVER_IMAGE_BITS, normal_bitmap,
NULL);
196 XView Programming Manual
busy_glyph = xv_create(NULL, SERVER_IMAGE,
XV_HEIGHT, 64,
XV_WIDTH, 64,
SERVER_IMAGE_DEPTH, 1,
SERVER_IMAGE_BITS, busy_bitmap,
NULL),
Set the panel drop target attributes to use the server images defined above:
xv_set(drop_target,
PANEL_DROP_GLYPH, normal_glyph,
PANEL_DROP_BUSY_GLYPH, busy_glyph,
NULL);
7.18.1.3 Create the drag and drop object
If the drop target item will support drags, create a Drag_drop object and set the attribute
PANEL_DROP_DND. This attribute is the DRAGDROP object associated with the panel drop tar-
get item. The Drag_drop object is used to initiate a drag and drop operation. If
PANEL_DROP_DND does not exist, then the panel drop target item will not support drags and is
called an empty drop target. In this case, PANEL_DROP_FULL will be FALSE (the default).
Drag_drop dnd;
dnd = xv_create(panel, DRAGDROP, NULL);
If the drop target item will support drags, then set the appropriate attributes on the Dnd ob-
ject (rank, cursor, etc.).
Create a selection item associated with the Dnd object. This defines the data and the conver-
sion(s) supported for the source of the drag. For example:
xv_create(dnd, SELECTION_ITEM,
SEL_DATA, "dnd selection data",
NULL);
After data is defined, you need to set PANEL_DROP_FULL to TRUE. When set to TRUE,
PANEL_DROP_FULL indicates that valid, “draggable” data is set on the PANEL_DROP_DND ob-
ject’s selection items. For example:
xv_set(drop_target,
PANEL_DROP_DND, dnd,
PANEL_DROP_FULL, TRUE,
NULL);
7.18.1.4 Define the drop target item’s requestor
The panel package creates a selection requestor, from the SELECTION_REQUESTOR package
that is associated with each drop target item. This selection requestor’s attributes need to be
set. PANEL_DROP_SEL_REQ returns the SELECTION_REQUESTOR associated with the panel
drop target item. The following code fragment gets the selection requestor associated with
an item:
Selection_requestor sel_req;
Panels
Panels 197

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.