📄 rhl33.htm
字号:
FRAME_LABEL, "Popup",
XV_WIDTH, 100,
XV_HEIGHT, 100,
NULL);</FONT></PRE>
<P>This call will create the pop-up frame with frame as the owner. The pop-up frame is not displayed immediately. You can create several pop-up frames this way and display them only when they are needed.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Note that if you do not set the XV_WIDTH and XV_HEIGHT parameters for this xv_create() call, the pop-up screen will occupy the entire screen.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>Next we create a panel for this pop-up with the call
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">fpanel = (Panel)xv_get(popup, FRAME_CMD_PANEL,NULL);</FONT></PRE>
<P>Then we add the Greet and Push Me buttons to this new fpanel. This is done by the xv_create calls, which are shown next:
<BR>
<PRE>
<FONT COLOR="#000080"> (void) xv_create(fpanel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Greet",
PANEL_NOTIFY_PROC, show_greeting,
NULL);
(void) xv_create(fpanel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Push Me",
PANEL_NOTIFY_PROC, push_it,
NULL);</FONT></PRE>
<P>At this point you are ready to create the main application frame, show it, and go into the main loop. The important call that does this is shown next. The function show_popup() is assigned to be called when the Hello button is pressed.
<BR>
<PRE>
<FONT COLOR="#000080">(void) xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Hello",
PANEL_NOTIFY_PROC, show_popup,
NULL);</FONT></PRE>
<P>Now look at the functions that are called when each button is pressed. The show_greeting function simply prints out a string. (You can use your imagination here for the contents of the string for your own application.) The show_popup() function will use
the call to the xv_set() function to actually make the pop-up frame visible.
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">xv_set(popup, XV_SHOW, TRUE, NULL);</FONT></PRE>
<P>Now for the function that will emulate the behavior of pushing in the pin. This is the push_it() function. The FRAME_CMD_PIN_STATE parameter requests the state of the pushpin on the dialog box. The state for the pin is defined as FRAME_CMD_PIN_IN if the
pushpin is already pushed in. This is the state for which you check. If the pushpin is not in this state, it is pushed in with the xv_set(popup, FRAME_CMD_PIN_STATE, FRAME_CMD_PIN_IN, NULL); function call.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>A command frame has no resize corners by default. To turn these corners on, set FRAME_SHOW_RESIZE_CORNERS to TRUE.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E68E285"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Setting Colors on Frames</B></FONT></CENTER></H3>
<BR>
<P>The colors on an XView frame object are defaulted to the OpenWindows.WindowColor resource. This resource is inherited by all subframes as well. You can override these colors with the CMS package. The CMS package is created by a call to xv_create():
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">cms = (Cms *) xv_create(parent, CMS, attrs, NULL);</FONT></PRE>
<P>A CMS can contain as many colors as are allowed in the largest color map you can create. You can have several color maps referencing the same color; in fact, the system can share the location of colors between two independent applications. For this
reason, you should allocate all your colors once, at cms creation, to allocate all the colors in your color map to prevent another application from changing the colors you absolutely need.
<BR>
<P>For example, to create a cms with four named colors, you would use the following function call:
<BR>
<PRE>
<FONT COLOR="#000080">cms = (Cms *)xv_create(parent, CMS,
CMS_SIZE, 4,
CMS_NAMED_COLORS, "Violet", "Yellow", "Blue", "Orange",
NULL);</FONT></PRE>
<P>The CMS_SIZE value asks for a four-entry color table that is indexed from 0 to 3, with the values of the named colors "Violet", "Yellow", "Blue", and "Orange". The foreground color for a frame is the first indexed
color in a Cms and the background color for a frame is the last indexed (n-1) color in a Cms. Setting a CMS_SIZE will give you either an error or a monochromatic display. Of course, to avoid runtime errors you must know that the colors you just specified
by name do exist in the /usr/lib/rgb.txt file.
<BR>
<P>Listing 33.5 is an example of an application that sets the colors. This will let you set the foreground and background colors of a frame and all its children.
<BR>
<P>
<FONT COLOR="#000080"><B>Listing 33.5. Using CMS.</B></FONT>
<BR>
<PRE>
<FONT COLOR="#000080">#include <xview/generic.h>
#include <xview/xview.h>
#include <xview/frame.h>
#include <xview/panel.h>
#include <xview/cms.h>
Frame frame;
#define FORE 3
#define BACK 0
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>You cannot use xv_get with the CMS_NAMED_COLORS attribute.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Use xv_set() to override the colors on a frame. Any color requests on a frame at the time of creation are overridden by values of the .Xdefaults resources values.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E68E286"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Canvases</B></FONT></CENTER></H3>
<BR>
<P>A canvas is an XView object that is used to display items that are too large to fit on a window. The viewable portion of the image is seen through a viewport or view window of the object. You can have multiple views of the same data that is stored on a
canvas by splitting each scrollable portion into two or more views. The split views must all reside on the same canvas because you cannot have multiple views of canvas data that are not on the same frame.
<BR>
<P>There are three components of a canvas object:
<BR>
<UL>
<LI>The Paint window, which contains the actual painted data
<BR>
<BR>
<LI>The View window, which has the scrollbars but no painted data
<BR>
<BR>
<LI>The canvas subwindow, which contains the union of the View window and Paint window
<BR>
<BR>
</UL>
<P>Look at a simple example in Listing 33.6 of how to use scrollbars and how to paint on a paint window. (I have added line numbers for readability.)
<BR>
<P>
<FONT COLOR="#000080"><B>Listing 33.6. Using canvases and scrollbars.</B></FONT>
<BR>
<PRE>
<FONT COLOR="#000080">1 /*
2 ** An example of a scrolled window
3 */
4 #include <X11/Xlib.h>
5 #include <xview/generic.h>
6 #include <xview/xview.h>
7 #include <xview/frame.h>
8 #include <xview/panel.h>
9 #include <xview/canvas.h>
10 #include <xview/scrollbar.h>
11 #include <xview/xv_xrect.h>
12 /*
13 ** Declare our callback functions for this application.
14 */
15 Frame frame;
16 void redraw(Canvas c, Xv_Window pw, Display *dp, Window xwin,
17 Xv_xrectlist *rp) ;
18 int main(int argc, char *argv[])
19 {
20 Canvas canvas;
21 Panel panel;
22 Scrollbar h_s, h_v;
23 void quit();
24 xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
25 frame = (Frame)xv_create(NULL, FRAME,
26 FRAME_LABEL, argv[0],
27 XV_WIDTH, 400,
28 XV_HEIGHT, 200,
29 (int)NULL);
30 /*
31 ** Create the canvas.
32 */
33 canvas = (Canvas) xv_create(frame, CANVAS,
34 CANVAS_REPAINT_PROC, redraw,
35 CANVAS_X_PAINT_WINDOW, TRUE,
36 CANVAS_AUTO_SHRINK, FALSE,
37 CANVAS_AUTO_EXPAND, TRUE,
38 CANVAS_WIDTH, 500,
39 CANVAS_HEIGHT, 500,
40 XV_WIDTH, 400,
41 XV_HEIGHT, 200,
42 NULL);
43 /*
44 ** Create the splittable scrollbars
45 */
46 h_s = (Scrollbar)xv_create(canvas, SCROLLBAR,
47 SCROLLBAR_DIRECTION, SCROLLBAR_HORIZONTAL,
48 SCROLLBAR_SPLITTABLE, TRUE,
49 NULL);
50 h_v = (Scrollbar)xv_create(canvas, SCROLLBAR,
51 SCROLLBAR_DIRECTION, SCROLLBAR_VERTICAL,
52 SCROLLBAR_SPLITTABLE, TRUE,
53 NULL);
54 xv_main_loop(frame);
55 exit(0);
56 }
57 void redraw(Canvas c, Xv_Window pw, Display *dp, Window xwin,
58 Xv_xrectlist *rp)
59 {
60 GC gc;
61 int wd, ht;
62 int i;
63 int j;
64 int dx;
65 int dy;
66 gc = DefaultGC(dp, DefaultScreen(dp));
67 wd = (int)xv_get(pw, XV_WIDTH);
68 ht = (int)xv_get(pw, XV_HEIGHT);
69 dx = ht / 10;
70 for (i = 0; i < ht; i += dx)
71 XDrawLine(dp,xwin,gc, i,0,i,ht);
72
73 dx = wd / 10;
74 for (i = 0; i < wd; i += dx)
75 XDrawLine(dp,xwin,gc, 0,i,wd,i);
76 /* XDrawLine(dp,xwin,gc, 0,0,wd,ht); */
77 }
78 void quit()
79 {
80 xv_destroy_safe(frame);
81 }</FONT></PRE>
<P>Lines 33 through 42 create the canvas. The CANVAS_AUTO_EXPAND and CANVAS_AUTO_SHRINK parameters maintain the relation of the canvas subwindow and the paint subwindow. These values default to TRUE. When both values are TRUE, the canvas and paint
subwindows will expand or shrink based on the size of the window on which they are being displayed.
<BR>
<P>Setting the CANVAS_AUTO_EXPAND value to TRUE enables the paint subwindow to expand larger than the canvas subwindow. If the canvas subwindow expands to a bigger size than the paint subwindow, the paint subwindow is expanded to at least that size as
well. If the canvas subwindow size shrinks, the paint subwindow does not shrink because it is already at the same size or bigger than canvas subwindows at that time.
<BR>
<P>Setting the CANVAS_AUTO_SHRINK value to TRUE forces the canvas object to always confirm that the paint subwindow's height and width are never greater than the canvas subwindow. In other words, the size of the paint subwindow is always changed to be at
least the same or less than the size of the canvas subwindow.
<BR>
<P>You can explicitly set the size of the canvas window with the CANVAS_WIDTH and CANVAS_HEIGHT parameters. (See lines 38 and 39.) These canvas dimensions can be greater than the viewing window dimensions set with XV_WIDTH and XV_HEIGHT (lines 40 and 41).
<BR>
<P>We have to add the include file <xview/scrollbar.h> to get the definitions for the scrollbar package. These are created in lines 46 through 53. Note how we have to create two separate scrollbars, one vertical and one horizontal.
<BR>
<P>The scrollbars in this example show how they can split to provide multiple, tiled views of the data in the canvas window. To split a view, press the right mouse button on a scrollbar and you will be presented with a pop-up menu. Choose the Split View
option to split the view or the Join View option to join two views together. You will not see a Join View option if a scrollbar does not dissect a view.
<BR>
<P>You can programmatically split a canvas view even if scrollbars are not present. Use the OPENWIN_SPLIT attribute in an xv_set() function call. For example:
<BR>
<PRE>
<FONT COLOR="#000080">xv_window xv;
xv = (xv_window)xv_get(canvas,OPENWIN_NTH_VIEW,0);
xv_set(canvas,
OPENWIN_SPLIT,
OPENWIN_SPLIT_VIEW, xv,
OPENWIN_SPLIT_DIRECTION,
OPENWIN_SPLIT_HORIZONTAL,
NULL);</FONT></PRE>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>You may want to group your xv_set() function calls into distinct logical calls to set each type of parameter instead of one long convoluted list of parameters to one xv_set() function. Splitting the code into these groups makes the code easier to
read and debug.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>Note that only OPENWIN_* type of attributes are allowed in the xv_set() call with the OPENWIN_SPLIT parameter. Do not mix other types of attributes. To get the first view you can use a value of 0 to the OPENWIN_NTH_VIEW parameter. For the next view, use
1, and so on. To get an idea of how many views there are for this canvas use the call
<BR>
<PRE>
<FONT COLOR="#000080">int number;
number = (int)xv_get(canvas, OPENWIN_NVIEWS);</FONT></PRE>
<P>To get the paint window to do your own drawing, perhaps in response to other user input, you can use the xv_get() function to get the paint window. For example,
<BR>
<PRE>
<FONT COLOR="#000080">xv_window xv_paint;
xv_paint = (xv_window)xv_get(canvas, CANVAS_VIEW_PAINT, null);</FONT></PRE>
<P>Listing 33.6 shows how to use the standard Xlib function calls to draw on the canvas. (See Figure 33.5.) You must use the include file <X/Xlib.h> for all the definitions and declarations. The XDrawLine function used in this example is somewhat
simple. However, this example shows you how to set up your Graphics Context and use the standard XDrawLine function to draw a grid. You can use other X drawing functions just as easily.
<BR>
<P><B> <A HREF="33rhl05.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/33rhl05.gif">Figure 33.5. The scrolled window example.</A></B>
<BR>
<BR>
<A NAME="E68E287"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Buttons</B></FONT></CENTER></H3>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -