⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch35.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 5 页
字号:


<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




 



<UL>



	<LI><A HREF="#Heading1">- 35 -</A>



	<UL>



		<LI><A HREF="#Heading2">XView Programming</A>



		<UL>



			<LI><A HREF="#Heading3">A Note About CDE</A>



			<LI><A HREF="#Heading4">Overview</A>



			<LI><A HREF="#Heading5">Requirements</A>



			<LI><A HREF="#Heading6">Listing</A>



			<LI><A HREF="#Heading7">35.1. Sample makefile for creating XView applications.</A>



			<UL>



				<LI><A HREF="#Heading8">Header Files</A>



			</UL>



			<LI><A HREF="#Heading9">NOTE</A>



			<UL>



				<LI><A HREF="#Heading10">Sample Application</A>



			</UL>



			<LI><A HREF="#Heading11">Listing</A>



			<LI><A HREF="#Heading12">35.2. A simple application.</A>



			<LI><A HREF="#Heading13">NOTE</A>



			<UL>



				<LI><A HREF="#Heading14">Initialization</A>



				<LI><A HREF="#Heading15">Creating Objects</A>



				<LI><A HREF="#Heading16">Exiting an Application</A>



			</UL>



			<LI><A HREF="#Heading17">Frames</A>



			<LI><A HREF="#Heading18">Listing</A>



			<LI><A HREF="#Heading19">35.3. Header and footer frames.</A>



			<LI><A HREF="#Heading20">Command Frames</A>



			<LI><A HREF="#Heading21">Listing</A>



			<LI><A HREF="#Heading22">35.4. Using command frames.</A>



			<LI><A HREF="#Heading23">NOTE</A>



			<LI><A HREF="#Heading24">TIP</A>



			<LI><A HREF="#Heading25">Setting Colors on Frames</A>



			<LI><A HREF="#Heading26">Listing</A>



			<LI><A HREF="#Heading27">35.5. Using CMS.</A>



			<LI><A HREF="#Heading28">TIP</A>



			<LI><A HREF="#Heading29">CAUTION</A>



			<LI><A HREF="#Heading30">Canvases</A>



			<LI><A HREF="#Heading31">Listing</A>



			<LI><A HREF="#Heading32">35.6. Using canvases and scrollbars.</A>



			<LI><A HREF="#Heading33">TIP</A>



			<LI><A HREF="#Heading34">Buttons</A>



			<LI><A HREF="#Heading35">Listing</A>



			<LI><A HREF="#Heading36">35.7. Using menus, buttons, and choices.</A>



			<LI><A HREF="#Heading37">NOTE</A>



			<LI><A HREF="#Heading38">List Items</A>



			<LI><A HREF="#Heading39">Listing</A>



			<LI><A HREF="#Heading40">35.8. Using lists to display data.</A>



			<LI><A HREF="#Heading41">Scale Bars</A>



			<LI><A HREF="#Heading42">Listing</A>



			<LI><A HREF="#Heading43">35.9. Using slider control.</A>



			<LI><A HREF="#Heading44">TIP</A>



			<LI><A HREF="#Heading45">Text Windows</A>



			<LI><A HREF="#Heading46">Listing</A>



			<LI><A HREF="#Heading47">35.10. Using text items.</A>



			<LI><A HREF="#Heading48">Where to Go from Here</A>



			<LI><A HREF="#Heading49">Summary</A>



		</UL>



	</UL>



</UL>







<P>



<HR SIZE="4">







<H2 ALIGN="CENTER"><A NAME="Heading1<FONT COLOR="#000077">- 35 -</FONT></H2>



<H2 ALIGN="CENTER"><A NAME="Heading2<FONT COLOR="#000077">XView Programming</FONT></H2>



<P><I>by Kamran Husain</I></P>



<P>IN THIS CHAPTER</P>







<UL>



	<LI>A Note About CDE



	<P>



	<LI>Overview



	<P>



	<LI>Requirements



	<P>



	<LI>Frames



	<P>



	<LI>Command Frames



	<P>



	<LI>Setting Color on Frames



	<P>



	<LI>Canvases



	<P>



	<LI>Buttons



	<P>



	<LI>List Items



	<P>



	<LI>Scale Bars



	<P>



	<LI>Text Windows



	<P>



	<LI>Where to Go from Here



</UL>







<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.



<H3 ALIGN="CENTER"><A NAME="Heading3<FONT COLOR="#000077">A Note About CDE</FONT></H3>



<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.



<H3 ALIGN="CENTER"><A NAME="Heading4<FONT COLOR="#000077">Overview</FONT></H3>



<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.</P>



<P>The XView toolkit consists of the objects shown in Figure 35.1. The subclasses



are derived from the classes to their left. For example, <TT>Icon</TT> is a subclass



of <TT>Window</TT>. Each class is also referred to as a package.</P>



<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,



provide frameworks that aid in the display or layout of visible objects.</P>



<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.</P>



<P>The following functions enable you to manipulate all XView objects:







<UL>



	<LI><TT>xv_init()</TT> Establishes the connection to the server, initializes the



	notifier (message handler), and loads the resource databases



	<P>



	<LI><TT>xv_create()</TT> Creates an object



	<P>



	<LI><TT>xv_destroy()</TT> Destroys an object



	<P>



	<LI><TT>xv_find()</TT> Finds an object with given criteria; if not found, creates



	the object



	<P>



	<LI><TT>xv_get()</TT> Gets an attribute value



	<P>



	<LI><TT>xv_set()</TT> Sets an attribute value



</UL>







<P><BR>



<A HREF="../art/35/35lnx01.jpg"><B>Figure 35.1.</B></A> <I>XView class hierarchy.



</I><BR>



<BR>



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, <TT>FRAME_*</TT>, <TT>ICON_*</TT>,



<TT>MENU_*</TT>, and so on. Common and generic attributes are prefixed by <TT>XV_</TT>.



For example, <TT>XV_HEIGHT</TT> applies to all objects, but <TT>FRAME_HEIGHT</TT>



applies only to frame objects.</P>



<P>Each attribute may have different types of values. For example, the following



code sets a <TT>panel_item</TT>.</P>



<PRE><FONT COLOR="#0066FF">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, &quot;Help&quot;,



    PANEL_CHOICE_STRINGS, &quot;About ... &quot;,



                  &quot;How to use Help&quot;,



                 &quot;Search Index&quot;,



                NULL,</FONT></PRE>



<PRE><FONT COLOR="#0066FF">



    NULL);



</FONT></PRE>



<P>Note how the types of values are mixed in this function call. All the attributes



except <TT>PANEL_CHOICE_STRINGS</TT> take a single argument. The <TT>PANEL_CHOICE_STRINGS</TT>



attribute takes a list of arguments. The list is terminated with a <TT>NULL</TT>



value.</P>



<P>We will go over the details of each object in this chapter.



<H3 ALIGN="CENTER"><A NAME="Heading5<FONT COLOR="#000077">Requirements</FONT></H3>



<P>To create an XView program you must link in the XView and <TT>OPENLOOK</TT> graphics



library, which include 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</P>



<PRE><FONT COLOR="#0066FF">$ gcc sample.c -lxview -lolgx -lX11 -o sample



</FONT></PRE>



<P>This compile command relies on the fact that your libraries are located in <TT>/usr/lib</TT>



or you have links to this location. The libraries are located in the <TT>/usr/openwin</TT>



directories.</P>



<P>See the sample makefile in Listing 35.1 that you can use with the applications



in this chapter. Note that this is not a fully functional makefile; you will have



to modify it for your applications. The excerpt shown in Listing 35.1 is for the



<TT>LIST35_1.c</TT> sample file in this chapter.



<H3 ALIGN="CENTER"><A NAME="Heading6<FONT COLOR="#000077">Listing <A NAME="Heading735.1.



Sample makefile for creating XView applications.</FONT></H3>



<PRE><FONT COLOR="#0066FF">CC= gcc



LIBPATH=/usr/openwin/lib



INCPATH=/usr/openwin/include



LIBS= -lxview -lolgx -lX11











LIST33_1: LIST33_1.c



    $(CC) $&lt; -I$(INCPATH) -L$(LIBPATH) $(LIBS) -o $@







LIST33_2: LIST33_2.c



    $(CC) $&lt; -I$(INCPATH) -L$(LIBPATH) $(LIBS) -o $@







LIST33_3: LIST33_3.c



    $(CC) $&lt; -I$(INCPATH) -L$(LIBPATH) $(LIBS) -o $@







LIST33_4: LIST33_4.c



    $(CC) $&lt; -I$(INCPATH) -L$(LIBPATH) $(LIBS) -o $@



</FONT></PRE>



<P>The <TT>-lxview</TT> in <TT>LIBS</TT> refers to the <TT>libxview.a</TT> library.



The <TT>libxview.a</TT> library contains the code for all the windows manipulation,



and <TT>libolgx.a</TT> contains the <TT>OPENLOOK</TT> graphics library. The <TT>libX11.a</TT>



is required by the <TT>libxview.a</TT> library, and <TT>libolgx.a</TT> is required



by the <TT>libxview.a</TT> library.



<H4 ALIGN="CENTER"><A NAME="Heading8<FONT COLOR="#000077">Header Files</FONT></H4>



<P>The basic definitions you must use for XView are located in two files: <TT>xview/generic.h</TT>



and <TT>xview/xview.h</TT> in the <TT>/usr/openwin/include</TT> directory tree. The



header files required by other packages, such as <TT>FONT</TT> or <TT>FRAME</TT>,



are declared in files of the same name as the package. For example, for the <TT>FONT</TT>



package you must use the <TT>xview/font.h</TT> header file. You can include these



files more than once.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading9<FONT COLOR="#000077"><B>NOTE: </B></FONT>In some source distributions,



	the file <TT>generic.h</TT> is not explicitly called out in the source files. In



	order to compile source files under Linux, you will need the <TT>generic.h</TT> file.



	



<HR>







</DL>







<H4 ALIGN="CENTER"><A NAME="Heading10<FONT COLOR="#000077">Sample Application</FONT></H4>



<P>Take a look at the simple application shown in Listing 35.2, which places a window



with a Quit button on it.



<H3 ALIGN="CENTER"><A NAME="Heading11<FONT COLOR="#000077">Listing <A NAME="Heading1235.2.



A simple application.</FONT></H3>



<PRE><FONT COLOR="#0066FF">/*



** A sample program to show you how to present items for



** selection to the user.



**



*/



#include &lt;xview/generic.h&gt;



#include &lt;xview/xview.h&gt;



#include &lt;xview/frame.h&gt;



#include &lt;xview/panel.h&gt;



#include &lt;xview/cms.h&gt;







Frame frame;







#define FORE 0



#define BACK 2







int main(int argc, char *argv[])



{



Cms   cms;



Panel panel;



void quit();







xv_init(XV_INIT_ARGC_PTR_ARGV, &amp;argc, argv, NULL);











cms = (Cms ) xv_create((int)NULL,CMS, /* NULL -&gt; use the default Frame*/



    CMS_SIZE, CMS_CONTROL_COLORS + 4,



    CMS_CONTROL_CMS, True,



    CMS_NAMED_COLORS, &quot;LightBlue&quot;, &quot;Blue&quot;, &quot;Red&quot;, &quot;Green&quot;, NULL,



    NULL);



        



frame = (Frame)xv_create((int)NULL, FRAME,



    FRAME_LABEL, argv[1],



    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, &quot;Quit&quot;,



    PANEL_NOTIFY_PROC, quit,



    NULL);







xv_main_loop(frame);



exit(0);



}







void quit()



{



xv_destroy_safe(frame);



}



</FONT></PRE>







<DL>



	<DT><FONT COLOR="#0066FF"></FONT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading13<FONT COLOR="#000077"><B>NOTE: </B></FONT>At the risk 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. Additionally, you should



	run these programs from the <TT>OPENLOOK</TT> window manager (<TT>olvwm</TT>) to



	ensure proper operation and look-and-feel of these XView implementations 



<HR>







</DL>







<P>The output from this application is shown in Figure 35.2. There are several things



that you should note about this sample application.







⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -