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

📄 rhl33.htm

📁 linux的初学电子书
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<LI>PANEL_LIST_OP_DESELECT when the row is deselected

<BR>

<BR>

<LI>PANEL_LIST_OP_VALIDATE when a new row is added

<BR>

<BR>

<LI>PANEL_LIST_OP_DELETE when the row has been deleted

<BR>

<BR>

</UL>

<P>You can take action based on the value of the op parameter in one handy function or have this function call other functions. For example, the following pseudocode illustrates how you could handle the op parameter:

<BR>

<PRE>

<FONT COLOR="#000080">switch (op)

{

case PANEL_LIST_OP_SELECT: selectHandler();

break;

case PANEL_LIST_OP_DESELECT: unSelectHandler();

break;

case PANEL_LIST_OP_VALIDATE: addRowHandler();

break;

case PANEL_LIST_OP_DELETE: deleteRowHandler();

break;

}</FONT></PRE>

<BR>

<A NAME="E68E289"></A>

<H3 ALIGN=CENTER>

<CENTER>

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

<BR>

<P>Now look at how you create slider bars so the user can set the value of a variable. An example of this application is shown in Figure 33.8 and a corresponding listing is given in Listing 33.9.

<BR>

<P><B> <A HREF="33rhl08.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/33rhl08.gif">Figure 33.8. Using sliders.</A></B>

<BR>

<P>

<FONT COLOR="#000080"><B>Listing 33.9. Using slider control.</B></FONT>

<BR>

<PRE>

<FONT COLOR="#000080">#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;

Panel_item stationName;

void display_setting(Panel_item, int value, Event *ev);

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

{

Panel panel;

Panel_item slider;

void quit();

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

frame = (Frame)xv_create(NULL, FRAME,

FRAME_LABEL, argv[0],

XV_WIDTH, 400,

XV_HEIGHT, 100,

NULL);

panel = (Panel)xv_create(frame, PANEL,

PANEL_LAYOUT, PANEL_VERTICAL,

NULL);

 (void) xv_create(panel, PANEL_BUTTON,

PANEL_LABEL_STRING, &quot;Quit&quot;,

PANEL_NOTIFY_PROC, quit,

NULL);

slider = xv_create (panel, PANEL_SLIDER,

PANEL_LABEL_STRING, &quot;Radio Station&quot;,

PANEL_MIN_VALUE, 88,

PANEL_MAX_VALUE, 108,

PANEL_NOTIFY_PROC, display_setting,

PANEL_VALUE,99,

PANEL_NOTIFY_LEVEL, PANEL_ALL, /* not just at the end */

PANEL_SHOW_RANGE, TRUE,

PANEL_TICKS,10,

PANEL_SLIDER_WIDTH, 100,

NULL);

stationName = xv_create(panel, PANEL_MESSAGE,

PANEL_LABEL_STRING, &quot;sample&quot;,

NULL);

xv_main_loop(frame);

exit(0);

}

void quit()

{

xv_destroy_safe(frame);

}

/*

** This function is called when the slider value is changed.

*/

void display_setting(Panel_item item, int value, Event *ev)

{

switch (value)

{

case 89: xv_set(stationName,

PANEL_LABEL_STRING,&quot;Classical&quot;, NULL); break;

case 91: xv_set(stationName,

PANEL_LABEL_STRING,&quot;Industrial&quot;, NULL); break;

case 93: xv_set(stationName,

PANEL_LABEL_STRING,&quot;Country&quot;, NULL); break;

case 95: xv_set(stationName,

PANEL_LABEL_STRING,&quot;Soft Rock&quot;, NULL); break;

case 101: xv_set(stationName,

PANEL_LABEL_STRING,&quot;Roll N Roll&quot;, NULL); break;

case 104: xv_set(stationName,

PANEL_LABEL_STRING,&quot;Pop&quot;, NULL); break;

case 107: xv_set(stationName,

PANEL_LABEL_STRING,&quot;Alternative&quot;, NULL); break;

default: xv_set(stationName,

PANEL_LABEL_STRING,&quot;bzzz&quot;, NULL); break;

}

}</FONT></PRE>

<P>To create a slider, assign the PANEL_SLIDER value to the xv_create() function call. How the slider is used and displayed is governed by the following attributes:

<BR>

<UL>

<LI>PANEL_MIN_VALUE and PANEL_MAX_VALUE: The range of values that this slider can take. These values have to be integers. For the example in this book we used 88 and 108.

<BR>

<BR>

<LI>PANEL_SHOW_RANGE: Sets the slider to show the value of the ranges allowed for the selection.

<BR>

<BR>

<LI>PANEL_NOTIFY_LEVEL: Can be set to one of two values: PANEL_ALL if the callback procedure is called while the slider is moving, or PANEL_DONE only when the pointer button is released.

<BR>

<BR>

<LI>PANEL_DIRECTION: Can be used to set the orientation of the slider to either horizontal or vertical.

<BR>

<BR>

<LI>PANEL_TICKS: The number of ticks that show on the display. Set it to 0 if you do not want ticks to be shown. The number of ticks are adjusted as you size the slider. You fix the width of the slider by setting the PANEL_SLIDER_WIDTH to 100 (refer to 
Listing 33.8).

<BR>

<BR>

</UL>

<P>You can edit the selection value by clicking it and using the keyboard. This value will change the location of the slider as soon as you press the Enter key. Error values will be ignored.

<BR>

<P>Note how a message label displays the station name as the slider is being moved. To set the value of this label, make a call to xv_set() and give the attribute PANEL_LABEL_STRING a string value. For example, if the value of the slider is 89, you can set 
the message to &quot;Classical&quot;, as shown in the following lines:

<BR>

<PRE>

<FONT COLOR="#000080">case 89: xv_set(stationName,

PANEL_LABEL_STRING,&quot;Classical&quot;, NULL); break;</FONT></PRE>

<BLOCKQUOTE>

<BLOCKQUOTE>

<HR ALIGN=CENTER>

<BR>

<NOTE>You can create a gauge by using the PANEL_GAUGE package instead of PANEL_SLIDER. The dimensions of the gauge are set by the PANEL_GAUGE_WIDTH and PANEL_GAUGE_HEIGHT attributes. A user cannot change the value of the slider on a gauge because a gauge 
can be used only as a feedback item.</NOTE>

<BR>

<HR ALIGN=CENTER>

</BLOCKQUOTE></BLOCKQUOTE>

<BR>

<A NAME="E68E290"></A>

<H3 ALIGN=CENTER>

<CENTER>

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

<BR>

<P>XView has a lot of options for displaying data. This section will only cover a few portions of this feature. Please refer to the man pages for Text in /usr/openwin/man. Let's get started with some of the basics, though. A sample application is shown in 
Listing 33.10 and its corresponding output is shown in Figure 33.9.

<BR>

<P><B> <A HREF="33rhl09.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/33rhl09.gif">Figure 33.9. Using text items.</A></B>

<BR>

<P>

<FONT COLOR="#000080"><B>Listing 33.10. Using text items.</B></FONT>

<BR>

<PRE>

<FONT COLOR="#000080">#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, argv[0],

XV_WIDTH, 300,

XV_HEIGHT, 300,

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_create(panel, PANEL_TEXT,

PANEL_LABEL_STRING, &quot;Single&quot;,

PANEL_VALUE, &quot;Single Line of Text&quot;,

NULL);

xv_create(panel, PANEL_MULTILINE_TEXT,

PANEL_LABEL_STRING, &quot;Multi&quot;,

PANEL_DISPLAY_ROWS, 3,

PANEL_VALUE_DISPLAY_LENGTH, 30,

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

NULL);

xv_main_loop(frame);

exit(0);

}

void quit()

{

xv_destroy_safe(frame);

}</FONT></PRE>

<P>We created a single panel text entry item with the following lines using the PANEL_TEXT package:

<BR>

<PRE>

<FONT COLOR="#000080">xv_create(panel, PANEL_TEXT,

PANEL_LABEL_STRING, &quot;Single&quot;,

PANEL_VALUE, &quot;Single Line of Text&quot;,

NULL);</FONT></PRE>

<P>If the PANEL_LAYOUT value is set to PANEL_VERTICAL, the value will be placed below the label. The default is PANEL_HORIZONTAL. The number of characters is set with the PANEL_VALUE_DISPLAY_LENGTH attribute. This value should not be less than 4. (This is 
not in the listing and is only for your information.)

<BR>

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

<BR>

<P>You can have notification procedures for four types of input for a text item with the PANEL_NOTIFY_LEVEL. (See Table 33.1.)

<BR>

<BR>

<P ALIGN=CENTER>

<CENTER>

<FONT COLOR="#000080"><B>Table 33.1. Notification procedures.</B></FONT></CENTER>

<BR>



<TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

<I>Notification</I>

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

<I>Action to take on input</I></FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

PANEL_NONE

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

Never inform this package.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

PANEL_NON_PRINTABLE

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

On each non-printable character.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

PANEL_SPECIFIED

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

If the input character is found in a string specified by the attribute PANEL_NOTIFY_STRING.</FONT>

<TR>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

PANEL_ALL 

</FONT>

<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>

On all characters input.</FONT>

</TABLE><P>You can also have multiple lines of text on a display. A sample of this is shown in Listing 33.10. Look at the following excerpted lines:

<BR>

<PRE>

<FONT COLOR="#000080">xv_create(panel, PANEL_MULTILINE_TEXT,

PANEL_LABEL_STRING, &quot;Multi&quot;,

PANEL_DISPLAY_ROWS, 3,

PANEL_VALUE_DISPLAY_LENGTH, 30,

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

NULL);</FONT></PRE>

<P>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, and PANEL_VALUE_DISPLAY_LENGTH is the number of characters wide you want the display to be.

<BR>

<BR>

<A NAME="E68E291"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Where To Go from Here</B></FONT></CENTER></H3>

<BR>

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

<BR>

<P>Some cool binaries to look for in the /usr/openwin/bin directory are props for setting window parameters and textedit, a pretty good editor.

<BR>

<BR>

<A NAME="E68E292"></A>

<H3 ALIGN=CENTER>

<CENTER>

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

<BR>

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

<BR>

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

<BR>

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

<BR>

<P>The XView packages enable you to create and place objects on panels. You can place these objects using absolute positioning from the top left corner of a panel, relative to other objects, or in row/column order.

<BR>

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

<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="#I0" TARGET="_self"><IMG SRC="purtop.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtop.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Page Top"></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>


</BODY></HTML>



⌨️ 快捷键说明

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