#include <xview/generic.h>
#include <xview/xview.h>
#include <xview/frame.h>
#include <xview/panel.h>
Frame frame;
int main(int argc, char *argv[])
{
Panel panel;
void quit();
xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
frame = (Frame)xv_create((int)NULL, FRAME,
FRAME_LABEL, argv[1],
XV_WIDTH, 300,
XV_HEIGHT, 300,
NULL);
panel = (Panel)xv_create(frame, PANEL,NULL);
(void) xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Quit",
PANEL_NOTIFY_PROC, quit,
NULL);
xv_create(panel, PANEL_TEXT,
PANEL_LABEL_STRING, "Single",
PANEL_VALUE, "Single Line of Text",
NULL);
xv_create(panel, PANEL_MULTILINE_TEXT,
PANEL_LABEL_STRING, "Multi",
PANEL_DISPLAY_ROWS, 3,
PANEL_VALUE_DISPLAY_LENGTH, 30,
PANEL_VALUE, "Multiple Lines of Text \
in this example \
This is a line 1\
This is a line 2\
This is a line 3\
of some long string",
NULL);
xv_main_loop(frame);
exit(0);
}
void quit()
{
xv_destroy_safe(frame);
}
We created a single panel text entry item with the following lines by using the
PANEL_TEXT package:
xv_create(panel, PANEL_TEXT,
PANEL_LABEL_STRING, "Single",
PANEL_VALUE, "Single Line of Text",
NULL);
Figure 35.9. Using text items.
If the PANEL_LAYOUT value is set to PANEL_VERTICAL, the value is
placed below the label. The default is PANEL_HORIZONTAL. The number of characters
is set with PANEL_VALUE_DISPLAY_LENGTH. This value should not be less than
4. (This is not in the listing and is only for your information.)
If you want the user to enter private data such as password information, you can
set the PANEL_MASK_CHAR value to something like an asterisk. This setting
displays an asterisk for each character that the user types in. The value of the
text remains what the user typed in.
You can have notification procedures for four types of input for a text item with
the PANEL_NOTIFY_LEVEL. (See Table 35.1.)
Table 35.1. Notification procedures.
Notification |
Action to take on input |
PANEL_NONE |
Never inform this package. |
PANEL_NON_PRINTABLE |
On each non-printable character. |
PANEL_SPECIFIED |
If the input character is found in a string specified by the attribute PANEL_NOTIFY_STRING. |
PANEL_ALL |
On all characters input. |
You can also have multiple lines of text on a display. A sample of this is shown
in Listing 35.10. Look at the following excerpted lines:
xv_create(panel, PANEL_MULTILINE_TEXT,
PANEL_LABEL_STRING, "Multi",
PANEL_DISPLAY_ROWS, 3,
PANEL_VALUE_DISPLAY_LENGTH, 30,
PANEL_VALUE, "Multiple Lines of Text \
in this example\
This is a line 1\
This is a line 2\
This is a line 3\
of some long string",
NULL);
The PANEL_MULTILINE_TEXT package can have the following attributes set
for it:\ PANEL_DISPLAY_ROWS sets the number of lines that the viewing window
will display
PANEL_VALUE_DISPLAY_LENGTH is the number of characters wide you want the
display to be
This chapter is a very brief introduction to the XView packages available under
Linux. In this section you have learned a little about putting user interface items
together on a panel. You should now have enough knowledge to start creating your
own interfaces in XView. There are several other locations for getting more information
about XView under Linux.
The following are XView packages for Linux:
- xv32exmp. Perhaps the most important example for the newbie. This package
contains the examples for XView that demonstrate the Slingshot and UIT extensions,
which are libraries that make it much easier to program a user interface under X.
- xv32_a. This package contains static libraries for developing XView
applications (version 3.2). This is required if compiling XView apps with the -g
or -static flags for debugging.
- xv32_sa and xv32_so. These are shared libraries for your compiled
programs.
- xvinc. The include files you use when you are compiling XView programs.
- xvol32. Configuration files, programs, and other documentation for the
OPEN LOOK Window Manager, olwm.
- xvmenus. Menus and help files for olwm.
Some cool binaries to look for in the /usr/openwin/bin directory are
workman, which enables you to play music CDs on your CD player; props,
for setting window parameters; and perfmeter for performance metering.
Look in the /usr/openwin/man directory for all the man pages for the
XView package. The /usr/openwin/include file contains valuable information
about some of the structures used by XView.
You use objects to build XView applications. Each object is a class and is referred
to as a package. Each package has attributes that can have values. Attributes can
be shared among other objects, be common to a few objects only, or be specific to
one object.
You can retrieve an attribute's values by calling xv_get() and set a
value by calling xv_set. An attribute may be assigned more than one value.
Each attribute can have a different type of value attached to it.
You can use standard Xlib function calls to perform drawing operations.
This gives you tremendous flexibility in rendering your custom graphics on screens
and XView packages.
The XView packages enable you to create and place objects on panels. You can place
these objects using absolute positioning from the upper-left corner of a panel, relative
to other objects, or in row/column order.
The xv_create() call passes the type of object as a parameter to create
XView objects. You can set other attributes by passing a NULL-terminated
list to xv_create(). Default attribute values that are not explicitly set
by xv_create() are inherited from the object's parent.
Contact
reference@developer.com with questions or comments.
Copyright 1998
EarthWeb Inc., All rights reserved.
PLEASE READ THE ACCEPTABLE USAGE STATEMENT.
Copyright 1998 Macmillan Computer Publishing. All rights reserved.