📄 rhl33.htm
字号:
<HTML>
<HEAD>
<TITLE>Red Hat Linux Unleashed rhl33.htm </TITLE>
<LINK REL="ToC" HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm">
<LINK REL="Index" HREF="htindex.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/htindex.htm">
<LINK REL="Next" HREF="rhl34.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl34.htm">
<LINK REL="Previous" HREF="tppmsgs/msgs0.htm#33" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl32.htm"></HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<A NAME="I0"></A>
<H2>Red Hat Linux Unleashed rhl33.htm</H2>
<P ALIGN=LEFT>
<A HREF="tppmsgs/msgs0.htm#33" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl32.htm" TARGET="_self"><IMG SRC="purprev.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm" TARGET="_self"><IMG SRC="purtoc.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="rhl34.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl34.htm" TARGET="_self"><IMG SRC="purnext.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>
<HR ALIGN=CENTER>
<P>
<UL>
<UL>
<UL>
<LI>
<A HREF="#E68E280" >A Note About CDE</A>
<LI>
<A HREF="#E68E281" >Overview</A>
<LI>
<A HREF="#E68E282" >Requirements</A>
<UL>
<LI>
<A HREF="#E69E396" >Header Files</A>
<LI>
<A HREF="#E69E397" >Sample Application</A>
<LI>
<A HREF="#E69E398" >Initialization</A>
<LI>
<A HREF="#E69E399" >Creating Objects</A>
<LI>
<A HREF="#E69E400" >Exiting an Application</A></UL>
<LI>
<A HREF="#E68E283" >Frames</A>
<LI>
<A HREF="#E68E284" >Command Frames</A>
<LI>
<A HREF="#E68E285" >Setting Colors on Frames</A>
<LI>
<A HREF="#E68E286" >Canvases</A>
<LI>
<A HREF="#E68E287" >Buttons</A>
<LI>
<A HREF="#E68E288" >List Items</A>
<LI>
<A HREF="#E68E289" >Scale Bars</A>
<LI>
<A HREF="#E68E290" >Text Windows</A>
<LI>
<A HREF="#E68E291" >Where To Go from Here</A>
<LI>
<A HREF="#E68E292" >Summary</A></UL></UL></UL>
<HR ALIGN=CENTER>
<A NAME="E66E33"></A>
<H1 ALIGN=CENTER>
<CENTER>
<FONT SIZE=6 COLOR="#FF0000"><B>33</B></FONT></CENTER></H1>
<BR>
<A NAME="E67E33"></A>
<H2 ALIGN=CENTER>
<CENTER>
<FONT SIZE=6 COLOR="#FF0000"><B>Programming XView Applications</B></FONT></CENTER></H2>
<BR>
<P>In this chapter you will learn how to program in an older, but still widely found, OPEN LOOK—based user interface manager called XView. You will find this distribution helpful when you work with older code or when you port code from the OPEN LOOK
style to Motif.
<BR>
<BR>
<A NAME="E68E280"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>A Note About CDE</B></FONT></CENTER></H3>
<BR>
<P>In March 1993, the Common Open Software Environment (COSE) committees adopted the Common Desktop Environment (CDE). CDE is based on the Motif interface. Sun Microsystems Inc., the primary developer of OPEN LOOK applications, agreed to conform to CDE as
well. In short, this means that OPEN LOOK interface—based applications will soon be out of style. However, applications with an OPEN LOOK interface still exist and have to be ported to Motif eventually. A good knowledge of how OPEN LOOK applications
work will be very beneficial to you if you ever have to port old existing code to conform to CDE.
<BR>
<BR>
<A NAME="E68E281"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Overview</B></FONT></CENTER></H3>
<BR>
<P>To a programmer, the XView toolkit is an object-oriented toolkit. Think of XView objects as building blocks from which the user can create complicated applications, and think of each block as part of a package. Each package provides properties that you
can modify to configure the object.
<BR>
<P>The XView toolkit consists of the objects shown in Figure 33.1. The subclasses are derived from the classes to their left. For example, Icon is a subclass of Window. Each class is also referred to as a package.
<BR>
<P><B> <A HREF="33rhl01.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/33rhl01.gif">Figure 33.1. XView class hierarchy.</A></B>
<BR>
<P>Some objects are visible and some are not. The visible objects provide the windows, scrollbars, and so on. The invisible objects, such as the font, display, or server, <A NAME="I2"></A>provide frameworks that aid in the display or layout of visible
objects.
<BR>
<P>When you create an object, you get a handle to the object back from the XView libraries. Handles are opaque pointers to structures. This means that you can pass information via functions to these objects via their handles but you cannot see their
structures directly.
<BR>
<P>The following functions enable you to manipulate all XView objects:
<BR>
<TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
xv_init()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Establishes the connection to the server, initializes the notifier (message handler), and loads the resource databases</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
xv_create()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Creates an object</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
xv_destroy()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Destroys an object</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
xv_find()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Finds an object with given criteria; if not found, creates the object</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
xv_get()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Gets an attribute value</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
xv_set()
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Sets an attribute value</FONT>
</TABLE><P>There are three categories of attributes: generic attributes apply to all objects; common attributes are shared by some, but not all, objects; and specific attributes belong to one class of objects only. Attributes that are specific to a type of
object are prefixed with the name of the object; for example, FRAME_*, ICON_*, MENU_*, and so on. Common and generic attributes are prefixed by XV_. For example, XV_HEIGHT applies to all objects, but FRAME_HEIGHT applies only to frame objects.
<BR>
<P>Each attribute may have different types of values. For example, the following code sets a panel_item.
<BR>
<PRE>
<FONT COLOR="#000080">panel_item = (Panel_item) xv_create( masterpanel, PANEL_CYCLE,
XV_HEIGHT, 100,
XV_WIDTH, 50,
PANEL_LABEL_X, 100,
PANEL_LABEL_Y, 100,
PANEL_LABEL_STRING, "Help",
PANEL_CHOICE_STRINGS, "About ... ",
"How to use Help",
"Search Index",
NULL,
NULL);</FONT></PRE>
<P>Note how the types of values are mixed in this function call. All attributes except PANEL_CHOICE_STRINGS take a single argument. The PANEL_CHOICE_STRINGS attribute takes a list of arguments. The list is terminated with a NULL value.
<BR>
<P>We will go over the details of each object in this chapter.
<BR>
<BR>
<A NAME="E68E282"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Requirements</B></FONT></CENTER></H3>
<BR>
<P>To create an XView program you must link in the XView and OPEN LOOK graphics library, which includes all the toolkit functions for you. You will also need the X11 library. The command line to use the gcc compiler for a simple XView application is
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">$ gcc sample.c -lxview -lolgx -lX11 -o sample</FONT></PRE>
<P>However, this compile command relies on the fact that your libraries are located in /usr/lib or you have links to this location. The XView libraries are located in the /usr/openwin/lib directories.
<BR>
<P>See the sample makefile in Listing 33.1 that you can use with the applications in this chapter. To compile a listing from this book, type make filename. For example, type make list33_2.
<BR>
<P>
<FONT COLOR="#000080"><B>Listing 33.1. Sample </B><B>makefile</B><B> for creating XView applications.</B></FONT>
<BR>
<PRE>
<FONT COLOR="#000080">CC=gcc
LIBPATH=-L/usr/openwin/lib -L/usr/X11/lib
INCPATH=/usr/openwin/include
LIBS= -lxview -lolgx -lX11
list33_2: list 33_2.c
$(CC) $< -I$(INCPATH) $(LIBPATH) $(LIBS) -o $@
list33_3: list 33_3.c
$(CC) $< -I$(INCPATH) $(LIBPATH) $(LIBS) -o $@
list33_4: list 33_4.c
$(CC) $< -I$(INCPATH) $(LIBPATH) $(LIBS) -o $@
list33_5: list 33_5.c
$(CC) $< -I$(INCPATH) $(LIBPATH) $(LIBS) -o $@
list33_6: list 33_6.c
$(CC) $< -I$(INCPATH) $(LIBPATH) $(LIBS) -o $@
list33_7: list 33_7.c
$(CC) $< -I$(INCPATH) $(LIBPATH) $(LIBS) -o $@
list33_8: list 33_8.c
$(CC) $< -I$(INCPATH) $(LIBPATH) $(LIBS) -o $@
list33_9: list 33_9.c
$(CC) $< -I$(INCPATH) $(LIBPATH) $(LIBS) -o $@
list33_10: list 33_10.c
$(CC) $< -I$(INCPATH) $(LIBPATH) $(LIBS) -o $@</FONT></PRE>
<P>The -lxview in LIBS refers to the libxview.a library. The libxview.a library contains the code for all the windows manipulation and libolgx.a contains the OPENLOOK graphics library. The libX11.a is required by the libxview.a library, and libolgx.a is
required by the libxview.a library.
<BR>
<BR>
<A NAME="E69E396"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Header Files</B></FONT></CENTER></H4>
<BR>
<P>The basic definitions you must use for XView are located in two files: xview/generic.h and xview/xview.h in the /usr/openwin/include directory tree. The header files required by other packages, such as FONT or FRAME, are declared in files of the same
name as the package. For example, for the FONT package you must use the xview/font.h header file. You can include these files more than once.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>In some source distributions, the file generic.h is not explicitly called out in the source files. In order to compile source files under Linux, you will need the generic.h file.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E69E397"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>Sample Application</B></FONT></CENTER></H4>
<BR>
<P>Take a look at the simple application shown in Listing 33.2, which places a window with a Quit button on it.
<BR>
<P>
<FONT COLOR="#000080"><B>Listing 33.2. A simple application.</B></FONT>
<BR>
<PRE>
<FONT COLOR="#000080">/*
** A sample program to show you how to present items for
** selection to the user.
**
*/
#include <xview/generic.h>
#include <xview/xview.h>
#include <xview/frame.h>
#include <xview/panel.h>
#include <xview/cms.h>
Frame frame;
#define FORE 0
#define BACK 2
int main(int argc, char *argv[])
{
Cms cms;
Panel panel;
void quit();
printf("\n 0\n");
xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
cms = (Cms ) xv_create((int)NULL,CMS, /* NULL -> use the default Frame*/
CMS_SIZE, CMS_CONTROL_COLORS + 4,
CMS_CONTROL_CMS, True,
CMS_NAMED_COLORS, "LightBlue", "Blue", "Red", "Green", NULL,
NULL);
frame = (Frame)xv_create((int)NULL, FRAME,
FRAME_LABEL, argv[0],
XV_WIDTH, 200,
XV_HEIGHT, 100,
NULL);
xv_set(frame,
WIN_CMS, cms,
WIN_FOREGROUND_COLOR, CMS_CONTROL_COLORS + FORE,
WIN_BACKGROUND_COLOR, CMS_CONTROL_COLORS + BACK,
NULL);
panel = (Panel)xv_create(frame, PANEL,NULL);
(void) xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Quit",
PANEL_NOTIFY_PROC, quit,
NULL);
xv_main_loop(frame);
exit(0);
}
void quit()
{
xv_destroy_safe(frame);
}</FONT></PRE>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>At the chance of being too literal, don't forget to run the applications in this chapter from an X terminal. The programs will not run without the X server.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>The output from this application is shown in Figure 33.2. There are several things that you should note about this sample application.
<BR>
<P><B> <A HREF="33rhl02.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/33rhl02.gif">Figure 33.2. A sample XView application.</A></B>
<BR>
<UL>
<LI>The XV toolkit is initialized as soon as possible in the application with the xv_init call.
<BR>
<BR>
<LI>All attribute values to the xv_create() function call are terminated with a NULL parameter.
<BR>
<BR>
<LI>The (Frame) cast is used to override the default returned value from xv_create().
<BR>
<BR>
<LI>The <xview/generic.h> header file is used to get all the required definitions for the file.
<BR>
<BR>
</UL>
<BLOCKQUOTE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -