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

📄 rhl33.htm

📁 linux的初学电子书
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE>The figures shown in this chapter depict the program being run from the dwm window manager.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<BR>

<A NAME="E69E398"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Initialization</B></FONT></CENTER></H4>

<BR>

<P>You should initialize the XView system as soon as possible in any application. The xv_init() call does this for you. By default, xv_init() uses the DISPLAY environment variable for you. By pass-ing the argc and argv values you can override the default 
values for the application from the command line. You can use xv_init() only once in an application; the libraries ignore all other calls. Normally you'd override the DISPLAY variable if you wanted to display the window on a different machine.

<BR>

<P>You can use two types of parameters for the first argument to xv_init(): XV_INIT_ARGS, which leaves the argc and argv unchanged, or XV_INIT_ARGC_PTR_ARGV, which modifies argc and argv to remove all XView-specific arguments. With XV_INIT_ARGS, you pass 
argc into xv_init and with XV_INIT_ARGC_PTR_ARGV you pass the address of argc to xv_init().

<BR>

<BR>

<A NAME="E69E399"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Creating Objects</B></FONT></CENTER></H4>

<BR>

<P>The xv_create function is used to create all the objects in an application. The syntax for the xv_create function is

<BR>

<BR>

<PRE>

<FONT COLOR="#000080">xv_object xv_create(xv_object owner, xv_package pkg, void *attr)</FONT></PRE>

<P>where the owner is the parent of the object being created, and of type pkg given the attributes listed in variable length arguments starting with attr. Sometimes you can use a NULL value in place of the owner parameter to indicate that the owner value 
can be substituted for screen or server as appropriate. However, in some calls the owner parameter must point to a valid object, so the NULL value will generate an error.

<BR>

<P>The attributes for the newly created object inherit their behavior from their parents. The attributes can be overridden by values included in the variable list specified in attr.

<BR>

<P>The values of attributes are set in the following decreasing order of precedence:

<BR>

<UL>

<LI>A call to xv_set will override any other type of setting

<BR>

<BR>

<LI>Any command-line arguments

<BR>

<BR>

<LI>Values in the .Xdefaults file

<BR>

<BR>

<LI>Values in the attributes of an xv_create call

<BR>

<BR>

<LI>Window Manager defaults

<BR>

<BR>

</UL>

<BR>

<A NAME="E69E400"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Exiting an Application</B></FONT></CENTER></H4>

<BR>

<P>The best way to get out of an XView application is to destroy the topmost object. Use the xv_destroy_safe() function call, which waits for the destruction of all derived objects and cleans up after itself. You can also use xv_destroy() to get out 
immediately with the risk of not giving up system resources but be able to exit very quickly. If you don't give up resources, they will not be freed for use by any other applications in the system and will use up valuable memory space.

<BR>

<BR>

<A NAME="E68E283"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Frames</B></FONT></CENTER></H3>

<BR>

<P>A frame is a container for other windows. A frame manages the geometry of subwindows that do not overlap. Some examples include canvases, text windows, panels, and scrollbars. You saw a base frame in the output of LIST33_1.c (refer to Figure 33.2 and 
Listing 33.2).

<BR>

<P>Frames enable you to specify three types of outputs on three areas. The topmost area is the name on the top of the frame called the header. The bottom of the frame is divided into two sections; one is left-justified and the other is right-justified. 
Figure 33.3 shows the output from Listing 33.3, which shows you how to write to these areas.

<BR>

<P><B> <A HREF="33rhl03.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/33rhl03.gif">Figure 33.3. Header and footer frames.</A></B>

<BR>

<P>

<FONT COLOR="#000080"><B>Listing 33.3. Header and footer frames.</B></FONT>

<BR>

<PRE>

<FONT COLOR="#000080">/*

**

** Listing to show headers and footers.

**

*/

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

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

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

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

/*

**

*/

Frame frame;

/*

**

*/

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

{

Panel panel;

void quit();

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

frame = (Frame)xv_create(NULL, FRAME,

FRAME_LABEL, &quot;Title Here&quot;,

FRAME_SHOW_FOOTER, TRUE,

FRAME_LEFT_FOOTER, &quot;left side&quot;,

FRAME_RIGHT_FOOTER, &quot;right side&quot;,

XV_WIDTH, 200,

XV_HEIGHT, 100,

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>

<P>The parameters used to create these headers are shown in the following lines:

<BR>

<PRE>

<FONT COLOR="#000080">Frame frame;

frame = (Frame) xv_create(NULL, FRAME,

FRAME_LABEL, argv[0],

FRAME_SHOW_FOOTER, TRUE,

FRAME_LEFT_FOOTER, &quot;left side&quot;,

FRAME_RIGHT_FOOTER, &quot;right side&quot;,

FRAME_LABEL, &quot;Title Here&quot;,

NULL);</FONT></PRE>

<P>You have to turn the footer display on with the FRAME_SHOW_FOOTER attribute set to TRUE. The other values in this call actually set the values of the header and footer.

<BR>

<BR>

<A NAME="E68E284"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Command Frames</B></FONT></CENTER></H3>

<BR>

<P>Command frames are usually used to perform a quick function and then disappear. These frames are usually pop-up frames like the pushpin dialog boxes you saw in <A HREF="rhl24.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl24.htm">Chapter 24</A>, &quot;OPEN LOOK and OpenWindows.&quot; If the pushpin is 
pressed in, the dialog box remains &quot;pinned&quot; to the screen; otherwise, the dialog box will go away after the user performs the section.

<BR>

<P>Listing 33.4 shows you a program to create command frames.

<BR>

<P>

<FONT COLOR="#000080"><B>Listing 33.4. Using command frames.</B></FONT>

<BR>

<PRE>

<FONT COLOR="#000080">/*

** Sample Application to show command frames.

**

*/

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

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

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

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

/*

** Global Frames

*/

Frame frame;

Frame popup;

/*

**

** Declare the used functions here

**

*/

void show_greeting(Frame *fp);

int show_popup();

int push_it();

void quit();

/*

** The main function

*/

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

{

Panel panel;

Panel fpanel;

/*

** Initialize the toolkit

*/

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

/*

** Create top level frame.

*/

frame = (Frame)xv_create(NULL, FRAME,

FRAME_LABEL, &quot;Title Here&quot;,

FRAME_SHOW_FOOTER, TRUE,

FRAME_LEFT_FOOTER, &quot;Popup&quot;,

FRAME_RIGHT_FOOTER, argv[0],

XV_WIDTH, 200,

XV_HEIGHT, 100,

NULL);

/*

** Create the popup Frame.

*/

popup = (Frame) xv_create(frame, FRAME_CMD,

FRAME_LABEL, &quot;Popup&quot;,

XV_WIDTH, 100,

XV_HEIGHT, 100,

NULL);

/*

** Create panel for popup

*/

fpanel = (Panel)xv_get(popup, FRAME_CMD_PANEL,NULL);

/*

** Add buttons to popup

*/

(void) xv_create(fpanel, PANEL_BUTTON,

PANEL_LABEL_STRING, &quot;Greet&quot;,

PANEL_NOTIFY_PROC, show_greeting,

NULL);

(void) xv_create(fpanel, PANEL_BUTTON,

PANEL_LABEL_STRING, &quot;Push Me&quot;,

PANEL_NOTIFY_PROC, push_it,

NULL);

/*

** Create panel

*/

panel = (Panel)xv_create(frame, PANEL,NULL);

/*

** Add buttons to main application frame

*/

(void) xv_create(panel, PANEL_BUTTON,

PANEL_LABEL_STRING, &quot;Hello&quot;,

PANEL_NOTIFY_PROC, show_popup,

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);

}

void show_greeting(Frame *fp)

{

printf (&quot;\n Greet you? How?&quot;);

}

show_popup(Frame item, Event *ev)

{

xv_set(popup, XV_SHOW, TRUE, NULL);

}

push_it(Panel_item item, Event *ev)

{

int ret;

ret = (int)xv_get(popup, FRAME_CMD_PIN_STATE) ;

if (ret == FRAME_CMD_PIN_IN)

{

printf(&quot;Pin already in.. bye\n&quot;);

xv_set(popup, XV_SHOW, TRUE, NULL); /* refresh anyway */

}

else

{

printf(&quot;Pin out.. pushing it in\n&quot;);

xv_set(popup, FRAME_CMD_PIN_STATE, FRAME_CMD_PIN_IN, NULL);

xv_set(popup, XV_SHOW, TRUE, NULL); /* refresh anyway */

}

}</FONT></PRE>

<P>The output from Listing 33.4 is shown in Figure 33.4.

<BR>

<P><B> <A HREF="tppmsgs/msgs1.htm#154" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/33rhl04.gif">Figure 33.4. Using command frames.</A></B>

<BR>

<P>Look at the important lines of the program in Listing 33.4 in detail. By examining these lines you will learn the following:

<BR>

<UL>

<LI>How to create pop-up menus

<BR>

<BR>

<LI>How to add buttons to a panel

<BR>

<BR>

<LI>How to handle callback functions for xview objects

<BR>

<BR>

</UL>

<P>There are two frames in this application: frame and popup. These frames are declared at the top of the application with the statements

<BR>

<PRE>

<FONT COLOR="#000080">Frame frame;

Frame popup;</FONT></PRE>

<P>We also declared the following functions in this application:

<BR>

<UL>

<LI>void show_greeting(Frame *fp); This function is called when the Greeting button is pressed.

<BR>

<BR>

<LI>int show_popup(); This function is called when the Hello button is pressed.

<BR>

<BR>

<LI>int push_it(); This function is called when the Push Me button is pressed.

<BR>

<BR>

<LI>void quit(); This function is called when the Quit button is pressed.

<BR>

<BR>

</UL>

<P>The main xv_init() and frame creation for the program is as in Listing 33.3. Let's concentrate on the pop-up menu examples.

<BR>

<P>First, the pop-up frame is created with the following lines:

<BR>

<PRE>

<FONT COLOR="#000080">popup = (Frame) xv_create(frame, FRAME_CMD,

⌨️ 快捷键说明

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