home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
x
/
volume5
/
xview.demos
/
part02
< prev
next >
Wrap
Text File
|
1989-12-07
|
57KB
|
1,758 lines
Path: uunet!island!sun.com
From: argv@sun.com (Dan Heller)
Newsgroups: comp.sources.x
Subject: v05i040: XView example programs, Part02/06
Message-ID: <1240@island.uu.net>
Date: 8 Dec 89 07:37:51 GMT
Sender: argv@island.uu.net
Lines: 1747
Approved: island!argv@sun.com
Submitted-by: Dan Heller <argv@sun.com>
Posting-number: Volume 5, Issue 40
Archive-name: xview.demos/part02
#! /bin/sh
# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# If this archive is complete, you will see the following message at the end:
# "End of archive 2 (of 6)."
# Contents: xview.demos/canvas/canvas_input.c
# xview.demos/canvas/scroll_view.c xview.demos/canvas/split_views.c
# xview.demos/color/x_draw.c xview.demos/menus/menu_dir2.c
# xview.demos/menus/pin_menu.c xview.demos/seln_svc/long_seln.c
# xview.demos/seln_svc/seln.c
# Wrapped by argv@island on Thu Dec 7 23:18:16 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'xview.demos/canvas/canvas_input.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/canvas/canvas_input.c'\"
else
echo shar: Extracting \"'xview.demos/canvas/canvas_input.c'\" \(7680 characters\)
sed "s/^X//" >'xview.demos/canvas/canvas_input.c' <<'END_OF_FILE'
X/*
X * canvas_input.c --
X * Display a canvas whose views may be split repeatedly. The event
X * handler is installed for each view, so events are displayed in
X * each paint window.
X */
X#include <xview/xview.h>
X#include <xview/canvas.h>
X#include <xview/scrollbar.h>
X#include <xview/xv_xrect.h>
X
XCanvas canvas;
XFrame frame;
Xchar msg[128];
Xvoid init_split(), my_event_proc(), my_repaint_proc();
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X /*
X * Initialize, create base frame (with footers) and create canvas.
X */
X xv_init(XV_INIT_ARGS, argc, argv, NULL);
X frame = (Frame)xv_create(NULL,FRAME,
X FRAME_LABEL, "Split View Windows.",
X FRAME_SHOW_FOOTER, TRUE,
X NULL);
X canvas = (Canvas)xv_create(frame,CANVAS,
X CANVAS_X_PAINT_WINDOW, TRUE,
X OPENWIN_SPLIT,
X OPENWIN_SPLIT_INIT_PROC, init_split,
X NULL,
X CANVAS_REPAINT_PROC, my_repaint_proc,
X NULL);
X
X (void) xv_create(canvas, SCROLLBAR,
X SCROLLBAR_SPLITTABLE, TRUE,
X SCROLLBAR_DIRECTION, SCROLLBAR_VERTICAL,
X NULL);
X (void) xv_create(canvas, SCROLLBAR,
X SCROLLBAR_SPLITTABLE, TRUE,
X SCROLLBAR_DIRECTION, SCROLLBAR_HORIZONTAL,
X NULL);
X
X /*
X * Set input mask
X */
X xv_set(canvas_paint_window(canvas),
X WIN_CONSUME_EVENTS,
X WIN_NO_EVENTS, WIN_ASCII_EVENTS, KBD_USE, KBD_DONE,
X LOC_DRAG, LOC_WINENTER, LOC_WINEXIT, WIN_MOUSE_BUTTONS,
X NULL,
X WIN_EVENT_PROC, my_event_proc,
X NULL);
X
X xv_main_loop(frame);
X}
X
X/*
X * when a viewport is split, this routine is called.
X */
Xvoid
Xinit_split(splitview, newview, pos)
XXv_Window splitview, newview;
Xint pos;
X{
X Xv_Window view;
X int i = 0;
X
X /*
X * Determine view # from the new view and set its scrollbar to 0,0
X */
X OPENWIN_EACH_VIEW(canvas, view)
X if (view == splitview) {
X /* identify the view # of the view the user just split. */
X sprintf(msg, "Split view #%d", i+1);
X xv_set(frame, FRAME_LEFT_FOOTER, msg, NULL);
X } else if (view == newview) {
X xv_set(xv_get(canvas, OPENWIN_VERTICAL_SCROLLBAR, view),
X SCROLLBAR_VIEW_START, 0,
X NULL);
X xv_set(xv_get(canvas, OPENWIN_HORIZONTAL_SCROLLBAR, view),
X SCROLLBAR_VIEW_START, 0,
X NULL);
X }
X i++;
X OPENWIN_END_EACH
X sprintf(msg, "Total views: %d", i);
X xv_set(frame, FRAME_RIGHT_FOOTER, msg, NULL);
X}
X
X/*
X * Called when an event is received in an arbitrary paint window.
X */
Xvoid
Xmy_event_proc(window, event, arg)
XXv_Window window;
XEvent *event;
XNotify_arg arg;
X{
X register char *p = msg;
X
X *p = 0;
X
X /* test to see if a function key has been hit */
X if (event_is_key_left(event))
X sprintf(p, "(L%d) ", event_id(event) - KEY_LEFTFIRST + 1);
X else if (event_is_key_top(event))
X sprintf(p, "(T%d) ", event_id(event) - KEY_TOPFIRST + 1);
X else if (event_is_key_right(event))
X sprintf(p, "(R%d) ", event_id(event) - KEY_RIGHTFIRST + 1);
X else if (event_id(event) == KEY_BOTTOMLEFT)
X strcpy(p, "bottom left ");
X else if (event_id(event) == KEY_BOTTOMRIGHT)
X strcpy(p, "bottom right ");
X p += strlen(p);
X
X
X if (event_is_ascii(event)) {
X /*
X * note that shift modifier is reflected in the event code by
X * virtue of the char printed is upper/lower case.
X */
X sprintf(p, "Keyboard: key '%c' (%d) %s at %d,%d",
X event_action(event), event_action(event),
X event_is_down(event)? "pressed" : "released",
X event_x(event), event_y(event));
X } else switch (event_action(event)) {
X case ACTION_CLOSE :
X xv_set(frame, FRAME_CLOSED, TRUE, NULL);
X break;
X case ACTION_OPEN :
X strcpy(p, "frame opened up");
X break;
X case ACTION_HELP :
X strcpy(p, "Help (action ignored)");
X break;
X case ACTION_SELECT :
X sprintf(p, "Button: Select (Left) %s at %d,%d",
X event_is_down(event)? "pressed" : "released",
X event_x(event), event_y(event));
X break;
X case ACTION_ADJUST :
X sprintf(p, "Button: Adjust (Middle) %s at %d,%d",
X event_is_down(event)? "pressed" : "released",
X event_x(event), event_y(event));
X break;
X case ACTION_MENU :
X sprintf(p, "Button: Menu (Right) %s at %d,%d",
X event_is_down(event)? "pressed" : "released",
X event_x(event), event_y(event));
X break;
X case SHIFT_RIGHT :
X sprintf(p, "Keyboard: right shift %s",
X event_is_down(event)? "pressed" : "released");
X break;
X case SHIFT_LEFT :
X sprintf(p, "Keyboard: left shift %s",
X event_is_down(event)? "pressed" : "released");
X break;
X case SHIFT_LEFTCTRL : case SHIFT_RIGHTCTRL :
X sprintf(p, "Keyboard: control key %s",
X event_is_down(event)? "pressed" : "released");
X break;
X case SHIFT_META :
X sprintf(p, "Keyboard: meta key %s",
X event_is_down(event)? "pressed" : "released");
X break;
X case SHIFT_ALT :
X sprintf(p, "Keyboard: alt key %s",
X event_is_down(event)? "pressed" : "released");
X break;
X case KBD_USE:
X sprintf(p, "Keyboard: got keyboard focus");
X break;
X case KBD_DONE:
X sprintf(p, "Keyboard: lost keyboard focus");
X break;
X case LOC_MOVE:
X sprintf(p, "Pointer: moved to %d,%d",
X event_x(event),event_y(event));
X break;
X case LOC_DRAG:
X sprintf(p, "Pointer: dragged to %d,%d",
X event_x(event), event_y(event));
X break;
X case LOC_WINENTER:
X win_set_kbd_focus(window, xv_get(window, XV_XID));
X sprintf(p, "Pointer: entered window at %d,%d",
X event_x(event), event_y(event));
X break;
X case LOC_WINEXIT:
X sprintf(p, "Pointer: exited window at %d,%d",
X event_x(event), event_y(event));
X break;
X case WIN_RESIZE :
X case WIN_REPAINT :
X return;
X default : ;
X /* There are too many ACTION events to trap -- ignore the
X * ones we're not interested in.
X */
X }
X
X my_repaint_proc(canvas, window,
X xv_get(canvas, XV_DISPLAY), xv_get(window, XV_XID), NULL);
X}
X
X/*
X * my_repaint_proc()
X * Called to repaint the canvas in response to damage events
X * and the initial painting of the canvas window.
X * Displays the keyboard, pointer and button message strings
X * after erasing the previous messages.
X */
Xvoid
Xmy_repaint_proc(canvas, pw, dpy, xwin, xrects)
XCanvas canvas;
XXv_Window pw;
XDisplay *dpy;
XWindow xwin;
XXv_xrectlist *xrects;
X{
X char win_num[16];
X Xv_Window w;
X int i = 0;
X GC gc = DefaultGC(dpy, DefaultScreen(dpy));
X
X /*
X * Determine which paint window we're writing in.
X */
X CANVAS_EACH_PAINT_WINDOW(canvas, w)
X if (w == pw)
X break;
X i++;
X CANVAS_END_EACH
X sprintf(win_num, "(Window #%d) ", i+1);
X
X XClearWindow(dpy, xwin);
X XDrawString(dpy, xwin, gc, 25, 25, win_num, strlen(win_num));
X XDrawString(dpy, xwin, gc, 25, 45, msg, strlen(msg));
X}
END_OF_FILE
if test 7680 -ne `wc -c <'xview.demos/canvas/canvas_input.c'`; then
echo shar: \"'xview.demos/canvas/canvas_input.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/canvas/canvas_input.c'
fi
if test -f 'xview.demos/canvas/scroll_view.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/canvas/scroll_view.c'\"
else
echo shar: Extracting \"'xview.demos/canvas/scroll_view.c'\" \(6567 characters\)
sed "s/^X//" >'xview.demos/canvas/scroll_view.c' <<'END_OF_FILE'
X/*
X * scroll_view.c
X * Dan Heller <argv@sun.com> 1989
X *
X * Display a canvas in a frame. The canvas displays a window that has
X * lines drawn from the opposite corners and draws a black box in the
X * top left corner. This canvas may be split in many ways (vertically
X * and/or horizontally), but the repaint routine makes sure that each
X * paint window displays the same thing.
X
X * This program also demonstrates how to handle splitting views
X * programmatically. Using the left mouse button splits a view
X * horizontally at the Y location of the mouse. Using the middle
X * mouse button splits the view vertically at the X location of
X * the mouse.
X */
X#include <stdio.h>
X#include <X11/X.h>
X#include <X11/Xlib.h> /* Using Xlib graphicsas well */
X#include <xview/xview.h>
X#include <xview/canvas.h>
X#include <xview/scrollbar.h>
X#include <xview/rectlist.h>
X
XCanvas canvas;
Xvoid events(), repaint_proc(), init_split(), join_split();
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Frame frame;
X Xv_Window view;
X Rect *rect;
X
X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
X
X /*
X * Create a frame that's 300 wide by 150 high -- give it a titlebar
X */
X frame = (Frame)xv_create(XV_NULL, FRAME,
X XV_WIDTH, 300,
X XV_HEIGHT, 150,
X FRAME_LABEL, argv[0],
X NULL);
X
X /*
X * Create a canvas that's 500 by 500. This canvas should not adjust
X * its size if resized. Install the repaint callback: repaint_proc()
X */
X canvas = (Canvas)xv_create(frame, CANVAS,
X CANVAS_WIDTH, 500,
X CANVAS_HEIGHT, 500,
X CANVAS_AUTO_SHRINK, FALSE,
X CANVAS_AUTO_EXPAND, FALSE,
X CANVAS_REPAINT_PROC, repaint_proc,
X NULL);
X
X /* Install the callback for events on the first (and only, so far)
X * paint window. We'll use the default events provided by the canvas.
X */
X xv_set(canvas_paint_window(canvas),
X WIN_EVENT_PROC, events,
X WIN_CONSUME_EVENTS, ACTION_SELECT, ACTION_ADJUST, NULL,
X NULL);
X
X /*
X * There's only one viewport since multi-views cannot be created
X * when creating a canvas. Install "init" and "destroy" callbacks
X * in the canvas object. See the corresponding routines for specifics.
X */
X xv_set(canvas,
X OPENWIN_SPLIT,
X OPENWIN_SPLIT_INIT_PROC, init_split,
X OPENWIN_SPLIT_DESTROY_PROC, join_split,
X NULL,
X NULL);
X
X /*
X * Attach scrollbars to the canvas.
X */
X xv_create(canvas, SCROLLBAR,
X SCROLLBAR_SPLITTABLE, TRUE,
X SCROLLBAR_DIRECTION, SCROLLBAR_VERTICAL,
X NULL);
X xv_create(canvas, SCROLLBAR,
X SCROLLBAR_SPLITTABLE, TRUE,
X SCROLLBAR_DIRECTION, SCROLLBAR_HORIZONTAL,
X NULL);
X
X xv_main_loop(frame);
X exit(0);
X}
X
X/*
X * The repaint procedure is called whenever repainting is needed in a
X * paint window. If the canvas has been split into several views and
X * repainting is necessary, then this repaint procedure is called for
X * each paint window in the canvas.
X */
Xvoid
Xrepaint_proc(canvas, paint_window, repaint_area)
XCanvas canvas;
XXv_Window paint_window;
XRectlist repaint_area;
X{
X Display *dpy;
X Window win;
X Xv_Window pw;
X Rect *rect;
X
X /* Get the size of the entire paint window */
X rect = (Rect *)xv_get(paint_window, XV_RECT);
X
X /* Use Xview graphics to draw lines from opposite corners. */
X xv_vector(paint_window, 0, 0, rect->r_width, rect->r_height, PIX_SET, 1);
X xv_vector(paint_window, rect->r_width, 0, 0, rect->r_height, PIX_SET, 1);
X
X /* Use Xlib calls to draw a black square in the top corner of the pw */
X dpy = (Display *)XV_DISPLAY_FROM_WINDOW(paint_window);
X win = (Window)xv_get(paint_window, XV_XID);
X XFillRectangle(dpy, win, DefaultGC(dpy, DefaultScreen(dpy)), 10,10, 50,50);
X}
X
X/*
X * This routine is installed as the callback for events for the paint
X * window. If more paint windows are created as a result of a view
X * split, then this routine must be reinstalled in a new view.
X */
Xvoid
Xevents(pw, event)
XXv_Window pw;
XEvent *event;
X{
X int code = event_action(event);
X Xv_Window view;
X int i = (int)xv_get(canvas, OPENWIN_NVIEWS);
X
X /* Not interested in button up events */
X if (win_inputnegevent(event))
X return;
X
X /* Determine which paint window this event happened in. */
X while (pw != xv_get(canvas, CANVAS_NTH_PAINT_WINDOW, --i) && i > 0)
X ;
X /* The paint window number is "i" -- get the "i"th view window */
X view = xv_get(canvas, OPENWIN_NTH_VIEW, i);
X
X /* determine which event was passed and deal with it. */
X switch (code) {
X case ACTION_SELECT : case ACTION_ADJUST :
X /*
X * split the view at the appropriate position -- this call
X * will generate a call to init_split below since a new view
X * will have been created.
X */
X printf("split at %d,%d\n", event_x(event), event_y(event));
X xv_set(canvas,
X OPENWIN_SPLIT, /* takes a null-terminated attr-value list */
X OPENWIN_SPLIT_VIEW, view,
X OPENWIN_SPLIT_DIRECTION, code == ACTION_ADJUST?
X OPENWIN_SPLIT_VERTICAL :
X OPENWIN_SPLIT_HORIZONTAL,
X OPENWIN_SPLIT_POSITION, code == ACTION_ADJUST?
X event_x(event) :
X event_y(event),
X NULL,
X NULL);
X break;
X default:
X return;
X }
X /* indicate which paint window and view window ID's */
X printf("win %x, view: %x\n", pw, view);
X}
X
X/*
X * notify this routine whenever two views are joined.
X */
Xvoid
Xjoin_split(view)
XXv_Window view;
X{
X puts("joined view");
X}
X
X/*
X * Notify this routine whenever a view is split. The new view is
X * created and its position is indicated. This is the first time
X * the new view can be accessed by the program. Immediately install
X * the callback for events for the new paint window.
X */
Xvoid
Xinit_split(oldview, newview, pos)
XXv_Window oldview, newview;
Xint pos;
X{
X xv_set(xv_get(newview, CANVAS_VIEW_PAINT_WINDOW),
X WIN_EVENT_PROC, events,
X WIN_CONSUME_EVENT, ACTION_SELECT, ACTION_ADJUST, NULL,
X NULL);
X}
END_OF_FILE
if test 6567 -ne `wc -c <'xview.demos/canvas/scroll_view.c'`; then
echo shar: \"'xview.demos/canvas/scroll_view.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/canvas/scroll_view.c'
fi
if test -f 'xview.demos/canvas/split_views.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/canvas/split_views.c'\"
else
echo shar: Extracting \"'xview.demos/canvas/split_views.c'\" \(7095 characters\)
sed "s/^X//" >'xview.demos/canvas/split_views.c' <<'END_OF_FILE'
X/*
X * split_views.c -- run this program and then split the views using the
X * scrollbars. The new view should be scrolled to 0, 0 (click on the
X * left and top elevator anchors to reset both scrollbars on the new view).
X */
X#include <stdio.h>
X#include <xview/xview.h>
X#include <xview/canvas.h>
X#include <xview/scrollbar.h>
X
XCanvas canvas;
XFrame frame;
Xchar msg[128];
Xvoid init_split(), my_event_proc(), my_repaint_proc();
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X /*
X * Initialize, create base frame (with footers) and * create canvas.
X */
X xv_init(XV_INIT_ARGS, argc,argv, 0);
X frame = xv_create(NULL,FRAME,
X FRAME_LABEL, "Try Splitting views.",
X FRAME_SHOW_FOOTER, TRUE,
X NULL);
X canvas = xv_create(frame,CANVAS,
X OPENWIN_SPLIT,
X OPENWIN_SPLIT_INIT_PROC, init_split,
X NULL,
X CANVAS_REPAINT_PROC, my_repaint_proc,
X NULL);
X
X xv_create(canvas, SCROLLBAR,
X SCROLLBAR_SPLITTABLE, TRUE,
X SCROLLBAR_DIRECTION, SCROLLBAR_VERTICAL,
X NULL);
X xv_create(canvas, SCROLLBAR,
X SCROLLBAR_SPLITTABLE, TRUE,
X SCROLLBAR_DIRECTION, SCROLLBAR_HORIZONTAL,
X NULL);
X
X /*
X * Set input mask
X */
X xv_set(canvas_paint_window(canvas),
X WIN_CONSUME_EVENTS,
X WIN_NO_EVENTS, WIN_ASCII_EVENTS, KBD_USE, KBD_DONE,
X LOC_DRAG, LOC_WINENTER, LOC_WINEXIT, WIN_MOUSE_BUTTONS,
X NULL,
X WIN_EVENT_PROC, my_event_proc,
X NULL);
X
X xv_main_loop(frame);
X return 0;
X}
X
X/*
X * when a viewport is split, this routine is called.
X */
Xvoid
Xinit_split(splitview, newview, pos)
XXv_Window splitview, newview;
Xint pos;
X{
X Xv_Window view, win;
X int i = 0;
X
X /*
X * Determine which view # is the new view and which is the original view
X */
X OPENWIN_EACH_VIEW(canvas, view)
X if (view == splitview) {
X /* identify the view # of the view the user just split. */
X sprintf(msg, "Split view #%d", i+1);
X xv_set(frame, FRAME_LEFT_FOOTER, msg, NULL);
X } else if (view == newview) {
X /*
X * install the same event handling mask and event callback
X * for the newview's paint window.
X */
X xv_set(win = xv_get(canvas, CANVAS_NTH_PAINT_WINDOW, i),
X WIN_CONSUME_EVENTS,
X WIN_NO_EVENTS, WIN_ASCII_EVENTS, KBD_USE, KBD_DONE,
X LOC_DRAG, LOC_WINENTER, LOC_WINEXIT, WIN_MOUSE_BUTTONS,
X NULL,
X WIN_EVENT_PROC, my_event_proc,
X NULL);
X }
X i++;
X OPENWIN_END_EACH
X printf("win = %x, CANVAS_VIEW_PAINT_WINDOW = %x\n",
X win, xv_get(newview, CANVAS_VIEW_PAINT_WINDOW));
X sprintf(msg, "Total views: %d", i);
X xv_set(frame, FRAME_RIGHT_FOOTER, msg, NULL);
X}
X
X/*
X * Called when an event is received in an arbitrary paint window.
X */
Xvoid
Xmy_event_proc(window, event, arg)
XXv_Window window;
XEvent *event;
XNotify_arg arg;
X{
X register char *p = msg;
X
X *p = 0;
X
X /* test to see if a function key has been hit */
X if (event_is_key_left(event))
X sprintf(p, "(L%d) ", event_id(event) - KEY_LEFTFIRST + 1);
X else if (event_is_key_top(event))
X sprintf(p, "(T%d) ", event_id(event) - KEY_TOPFIRST + 1);
X else if (event_is_key_right(event))
X sprintf(p, "(R%d) ", event_id(event) - KEY_RIGHTFIRST + 1);
X else if (event_id(event) == KEY_BOTTOMLEFT)
X strcpy(p, "bottom left ");
X else if (event_id(event) == KEY_BOTTOMRIGHT)
X strcpy(p, "bottom left ");
X p += strlen(p);
X
X /* Test to see if event is a special "mnemonic" action */
X if (event_action(event) != event_id(event)) {
X switch (event_action(event)) {
X case ACTION_CLOSE :
X strcpy(p, "close (action ignored)");
X break;
X case ACTION_OPEN :
X strcpy(p, "open (action ignored)");
X break;
X case ACTION_HELP :
X strcpy(p, "Help (action ignored)");
X break;
X case ACTION_SELECT : /* the action */
X case MS_LEFT : /* the actual (literal) event */
X sprintf(p, "Button: Select (Left) %s at %d,%d",
X event_is_down(event)? "pressed" : "released",
X event_x(event), event_y(event));
X break;
X case ACTION_ADJUST :
X case MS_MIDDLE :
X sprintf(p, "Button: Adjust (Middle) %s at %d,%d",
X event_is_down(event)? "pressed" : "released",
X event_x(event), event_y(event));
X break;
X case ACTION_MENU :
X case MS_RIGHT :
X sprintf(p, "Button: Menu (Right) %s at %d,%d",
X event_is_down(event)? "pressed" : "released",
X event_x(event), event_y(event));
X break;
X default : ;
X /* There are too many ACTION events to trap -- ignore the
X * ones we're not interested in.
X */
X }
X } else if (event_is_ascii(event))
X /*
X * note that shift modifier is reflected in the event code by
X * virtue of the char printed is upper/lower case.
X */
X sprintf(p, "Keyboard: key '%c' (%d) %s at %d,%d",
X event_action(event), event_action(event),
X event_is_down(event)? "pressed" : "released",
X event_x(event), event_y(event));
X else switch (event_id(event)) {
X case SHIFT_RIGHT :
X sprintf(p, "Keyboard: right shift %s",
X event_is_down(event)? "pressed" : "released");
X break;
X case SHIFT_LEFT :
X sprintf(p, "Keyboard: left shift %s",
X event_is_down(event)? "pressed" : "released");
X break;
X case SHIFT_LEFTCTRL : case SHIFT_RIGHTCTRL :
X sprintf(p, "Keyboard: control key %s",
X event_is_down(event)? "pressed" : "released");
X break;
X case SHIFT_META :
X sprintf(p, "Keyboard: meta key %s",
X event_is_down(event)? "pressed" : "released");
X break;
X case SHIFT_ALT :
X sprintf(p, "Keyboard: alt key %s",
X event_is_down(event)? "pressed" : "released");
X break;
X case KBD_USE:
X sprintf(p, "Keyboard: got keyboard focus");
X break;
X case KBD_DONE:
X sprintf(p, "Keyboard: lost keyboard focus");
X break;
X case LOC_MOVE:
X sprintf(p, "Pointer: moved to %d,%d",
X event_x(event),event_y(event));
X break;
X case LOC_DRAG:
X sprintf(p, "Pointer: dragged to %d,%d",
X event_x(event), event_y(event));
X break;
X case LOC_WINENTER:
X win_set_kbd_focus(window, xv_get(window, XV_XID));
X sprintf(p, "Pointer: entered window at %d,%d",
X event_x(event), event_y(event));
X break;
X case LOC_WINEXIT:
X sprintf(p, "Pointer: exited window at %d,%d",
X event_x(event), event_y(event));
X break;
X case WIN_RESIZE :
X strcpy(msg, "resize");
X break;
X case WIN_REPAINT :
X strcpy(msg, "repaint");
X break;
X default:
X if (msg[0])
X printf("unknown event: %d\n", event_id(event));
X }
X my_repaint_proc(canvas, window, NULL);
X}
X
X/*
X * my_repaint_proc()
X * Called to repaint the canvas in response to damage events
X * and the initial painting of the canvas window.
X * Displays the keyboard, pointer and button message strings
X * after erasing the previous messages.
X */
Xvoid
Xmy_repaint_proc(canvas, pw, repaint_area)
XCanvas canvas;
XXv_Window pw;
XRectlist *repaint_area;
X{
X static char buf[] =
X " ";
X char win_num[16];
X Xv_Window w;
X int i = 0;
X
X /*
X * Determine which # paint window we're writing in.
X */
X CANVAS_EACH_PAINT_WINDOW(canvas, w)
X if (w == pw)
X break;
X i++;
X CANVAS_END_EACH
X sprintf(win_num, "(Window #%d) ", i+1);
X xv_text(pw, 25, 25, PIX_SRC, NULL, win_num);
X
X xv_text(pw, 25, 45, PIX_SRC, NULL, buf);
X xv_text(pw, 25, 45, PIX_SRC, NULL, msg);
X}
END_OF_FILE
if test 7095 -ne `wc -c <'xview.demos/canvas/split_views.c'`; then
echo shar: \"'xview.demos/canvas/split_views.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/canvas/split_views.c'
fi
if test -f 'xview.demos/color/x_draw.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/color/x_draw.c'\"
else
echo shar: Extracting \"'xview.demos/color/x_draw.c'\" \(5651 characters\)
sed "s/^X//" >'xview.demos/color/x_draw.c' <<'END_OF_FILE'
X/*
X * x_draw.c --
X * Demonstrates the use of Xlib drawing functions inside an
X * XView canvas. Color is also used, but not required.
X */
X#include <xview/xview.h>
X#include <xview/canvas.h>
X#include <xview/cms.h>
X#include <xview/xv_xrect.h>
X
X/* indices into color table renders specified colors. */
X#define WHITE 0
X#define RED 1
X#define GREEN 2
X#define BLUE 3
X#define ORANGE 4
X#define AQUA 5
X#define PINK 6
X#define BLACK 7
X
XGC gc; /* GC used for Xlib drawing */
Xunsigned long *colors; /* the color table */
X
X/*
X * initialize cms data to support colors specified above. Assign
X * data to new cms -- use either static or dynamic cms depending
X * on -dynamic command line switch.
X */
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X unsigned char red[8], green[8], blue[8];
X static char stipple_bits[] = {0xAA, 0xAA, 0x55, 0x55};
X Frame frame;
X Canvas canvas;
X XFontStruct *font;
X Display *display;
X XGCValues gc_val;
X XID xid;
X void canvas_repaint();
X Xv_cmsdata cms_data;
X int use_dynamic = FALSE;
X
X /* Create windows */
X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
X if (*++argv && !strcmp(*argv, "-dynamic"))
X use_dynamic = TRUE;
X
X frame = xv_create(NULL,FRAME,
X FRAME_LABEL, "xv_canvas_x_draw",
X XV_WIDTH, 400,
X XV_HEIGHT, 300,
X NULL);
X
X /* initialize RGB values for specified colors */
X red[WHITE] = 255; green[WHITE] = 255; blue[WHITE] = 255;
X red[RED] = 255; green[RED] = 0; blue[RED] = 0;
X red[GREEN] = 0; green[GREEN] = 255; blue[GREEN] = 0;
X red[BLUE] = 0; green[BLUE] = 0; blue[BLUE] = 255;
X red[ORANGE] = 250; green[ORANGE] = 130; blue[ORANGE] = 80;
X red[AQUA] = 30; green[AQUA] = 230; blue[AQUA] = 250;
X red[PINK] = 230; green[PINK] = 30; blue[PINK] = 250;
X
X cms_data.type = use_dynamic? XV_DYNAMIC_CMS : XV_STATIC_CMS;
X cms_data.size = 8;
X cms_data.rgb_count = 8;
X cms_data.index = 0;
X cms_data.red = red;
X cms_data.green = green;
X cms_data.blue = blue;
X
X canvas = xv_create(frame, CANVAS,
X CANVAS_REPAINT_PROC, canvas_repaint,
X CANVAS_X_PAINT_WINDOW, TRUE,
X WIN_DYNAMIC_VISUAL, use_dynamic,
X WIN_CMS_NAME, "palette",
X WIN_CMS_DATA, &cms_data,
X NULL);
X
X /* Get display and xid */
X display = (Display *)xv_get(frame, XV_DISPLAY);
X xid = (XID)xv_get(canvas_paint_window(canvas), XV_XID);
X
X if (!(font = XLoadQueryFont(display, "fixed"))) {
X puts("cannot load fixed font");
X exit(1);
X }
X
X /* Create and initialize GC */
X gc_val.font = font->fid;
X gc_val.stipple =
X XCreateBitmapFromData(display, xid, stipple_bits, 16, 2);
X gc = XCreateGC(display, xid, GCFont | GCStipple, &gc_val);
X
X /* get the colormap from the canvas now that
X * the cms has been installed
X */
X colors = (unsigned long *)xv_get(canvas, WIN_X_COLOR_INDICES);
X
X /* Start event loop */
X xv_main_loop(frame);
X}
X
X/*
X * Draws onto the canvas using Xlib drawing functions.
X */
Xvoid
Xcanvas_repaint(canvas, pw, display, xid, xrects)
XCanvas canvas;
XXv_Window pw;
XDisplay *display;
XWindow xid;
XXv_xrectlist *xrects;
X{
X static XPoint box[] = {
X {0,0}, {100,100}, {0,-100}, {-100,100}, {0,-100}
X };
X static XPoint points[] = {
X {0,0}, /* this point to be overwritten below */
X {25,0}, {25,0}, {25,0}, {25,0}, {-100,25},
X {25,0}, {25,0}, {25,0}, {25,0}, {-100,25},
X {25,0}, {25,0}, {25,0}, {25,0}, {-100,25},
X {25,0}, {25,0}, {25,0}, {25,0}, {-100,25},
X {25,0}, {25,0}, {25,0}, {25,0}, {-100,25},
X };
X
X XSetForeground(display, gc, colors[RED]);
X XDrawString(display, xid, gc, 30, 20, "XFillRectangle", 14);
X XFillRectangle(display, xid, gc, 25, 25, 100, 100);
X XSetFunction(display, gc, GXinvert);
X XFillRectangle(display, xid, gc, 50, 50, 50, 50);
X XSetFunction(display, gc, GXcopy);
X
X XSetForeground(display, gc, colors[BLACK]);
X XDrawString(display, xid, gc, 155, 20, "XFillRect - stipple", 19);
X XSetFillStyle(display, gc, FillStippled);
X XFillRectangle(display, xid, gc, 150, 25, 100, 100);
X XSetFillStyle(display, gc, FillSolid);
X
X XSetForeground(display, gc, colors[BLUE]);
X XDrawString(display, xid, gc, 280, 20, "XDrawPoints", 11);
X points[0].x = 275; points[0].y = 25;
X XDrawPoints(display, xid, gc, points,
X sizeof(points)/sizeof(XPoint), CoordModePrevious);
X
X XSetForeground(display, gc, colors[ORANGE]);
X XDrawString(display, xid, gc, 30, 145, "XDrawLine - solid", 17);
X XDrawLine(display, xid, gc, 25, 150, 125, 250);
X XDrawLine(display, xid, gc, 25, 250, 125, 150);
X
X XSetForeground(display, gc, colors[AQUA]);
X XDrawString(display, xid, gc, 155, 145, "XDrawLine - dashed", 18);
X XSetLineAttributes(display, gc, 5,
X LineDoubleDash, CapButt, JoinMiter);
X XDrawLine(display, xid, gc, 150, 150, 250, 250);
X XDrawLine(display, xid, gc, 150, 250, 250, 150);
X XSetLineAttributes(display, gc, 0, LineSolid, CapButt, JoinMiter);
X
X XSetForeground(display, gc, colors[PINK]);
X XDrawString(display, xid, gc, 280, 145, "XDrawLines", 10);
X box[0].x = 275; box[0].y = 150;
X XDrawLines(display, xid, gc, box, 5, CoordModePrevious);
X
X XSetForeground(display, gc, colors[GREEN]);
X XDrawRectangle(display, xid, gc,
X 5, 5, xv_get(pw, XV_WIDTH)-10, xv_get(pw, XV_HEIGHT)-10);
X XDrawRectangle(display, xid, gc,
X 7, 7, xv_get(pw, XV_WIDTH)-14, xv_get(pw, XV_HEIGHT)-14);
X}
END_OF_FILE
if test 5651 -ne `wc -c <'xview.demos/color/x_draw.c'`; then
echo shar: \"'xview.demos/color/x_draw.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/color/x_draw.c'
fi
if test -f 'xview.demos/menus/menu_dir2.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/menus/menu_dir2.c'\"
else
echo shar: Extracting \"'xview.demos/menus/menu_dir2.c'\" \(6585 characters\)
sed "s/^X//" >'xview.demos/menus/menu_dir2.c' <<'END_OF_FILE'
X/*
X * menu_dir2.c -
X * Demonstrate the use of an XView menu in a canvas subwindow.
X * A menu is brought up with the MENU mouse button and displays
X * menu choices representing the files in the directory. If a
X * directory entry is found, a new pullright item is created with
X * that subdir as the pullright menu's contents. This implementation
X * creates directories on an as-needed basis. Thus, we provide a
X * MENU_GEN_PULLRIGHT procedure.
X *
X * argv[1] indicates which directory to start from.
X */
X#include <xview/xview.h>
X#include <xview/canvas.h>
X#include <sys/stat.h>
X#include <sys/dir.h>
X#include <X11/Xos.h>
X#ifndef MAXPATHLEN
X#include <sys/param.h>
X#endif /* MAXPATHLEN */
X
XFrame frame;
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X Canvas canvas;
X extern void exit();
X void my_event_proc();
X Menu menu;
X Menu_item mi, add_path_to_menu();
X
X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
X
X frame = (Frame)xv_create(NULL, FRAME,
X FRAME_LABEL, argv[1]? argv[1] : "cwd",
X FRAME_SHOW_FOOTER, TRUE,
X NULL);
X canvas = (Canvas)xv_create(frame, CANVAS,
X FRAME_LABEL, argv[0],
X XV_WIDTH, 400,
X XV_HEIGHT, 100,
X NULL);
X
X mi = add_path_to_menu(argc > 1? argv[1] : ".");
X menu = (Menu)xv_get(mi, MENU_PULLRIGHT);
X /* We no longer need the item since we have the menu from it */
X xv_destroy(mi);
X
X /* associate the menu to the canvas win for easy etreival */
X xv_set(canvas_paint_window(canvas),
X WIN_CONSUME_EVENTS, WIN_MOUSE_BUTTONS, NULL,
X WIN_EVENT_PROC, my_event_proc,
X WIN_CLIENT_DATA, menu,
X NULL);
X
X window_fit(frame);
X window_main_loop(frame);
X}
X
X/*
X * my_action_proc - display the selected item in the frame footer.
X */
Xvoid
Xmy_action_proc(menu, menu_item)
XMenu menu;
XMenu_item menu_item;
X{
X xv_set(frame,
X FRAME_LEFT_FOOTER, xv_get(menu_item, MENU_STRING),
X NULL);
X}
X
X/*
X * Call menu_show() to display menu on right mouse button push.
X */
Xvoid
Xmy_event_proc(canvas, event)
XCanvas canvas;
XEvent *event;
X{
X if ((event_id(event) == MS_RIGHT) && event_is_down(event)) {
X Menu menu = (Menu)xv_get(canvas, WIN_CLIENT_DATA);
X menu_show(menu, canvas, event, NULL);
X }
X}
X
X/*
X * return an allocated char * that points to the last item in a path.
X */
Xchar *
Xgetfilename(path)
Xchar *path;
X{
X char *p;
X
X if (p = rindex(path, '/'))
X p++;
X else
X p = path;
X return strcpy(malloc(strlen(p)+1), p);
X}
X
XMenu
Xgen_pullright(mi, op)
XMenu_item mi;
XMenu_generate op;
X{
X Menu menu;
X Menu_item new, old = mi;
X char buf[MAXPATHLEN];
X
X if (op == MENU_DISPLAY) {
X menu = (Menu)xv_get(mi, MENU_PARENT);
X sprintf(buf, "%s/%s",
X xv_get(menu, MENU_CLIENT_DATA), xv_get(mi, MENU_STRING));
X new = add_path_to_menu(buf);
X /* if item has a pullright menu, free it (its data first) */
X if (menu = (Menu)xv_get(mi, MENU_PULLRIGHT)) {
X free(xv_get(menu, MENU_CLIENT_DATA));
X xv_destroy(menu);
X }
X if (new) {
X menu = (Menu)xv_get(new, MENU_PULLRIGHT);
X xv_destroy(new);
X return menu;
X }
X }
X if (!(menu = (Menu)xv_get(mi, MENU_PULLRIGHT)))
X menu = (Menu)xv_create(NULL, MENU,
X MENU_STRINGS, "Couldn't build a menu.", NULL,
X NULL);
X return menu;
X}
X
X/*
X * The path passed in is scanned via readdir(). For each file in the
X * path, a menu item is created and inserted into a new menu. That
X * new menu is made the PULLRIGHT_MENU of a newly created panel item
X * for the path item originally passed it. Since this routine is
X * recursive, a new menu is created for each subdirectory under the
X * original path.
X */
XMenu_item
Xadd_path_to_menu(path)
Xchar *path;
X{
X DIR *dirp;
X struct direct *dp;
X struct stat s_buf;
X Menu_item mi;
X Menu next_menu;
X char buf[MAXPATHLEN];
X static int recursion;
X
X /* don't add a folder to the list if user can't read it */
X if (stat(path, &s_buf) == -1 || !(s_buf.st_mode & S_IREAD))
X return NULL;
X if (s_buf.st_mode & S_IFDIR) {
X int cnt = 0;
X if (!(dirp = opendir(path)))
X /* don't bother adding to list if we can't scan it */
X return NULL;
X if (recursion)
X return (Menu_item)-1;
X recursion++;
X next_menu = (Menu)xv_create(XV_NULL, MENU, NULL);
X while (dp = readdir(dirp))
X if (strcmp(dp->d_name, ".") && strcmp(dp->d_name, "..")) {
X (void) sprintf(buf, "%s/%s", path, dp->d_name);
X mi = add_path_to_menu(buf);
X if (!mi || mi == (Menu_item)-1) {
X int do_gen_pullright = (mi == (Menu_item)-1);
X /* unreadable file or dir - deactivate item */
X mi = (Menu_item)xv_create(XV_NULL, MENUITEM,
X MENU_STRING, getfilename(dp->d_name),
X MENU_RELEASE,
X MENU_RELEASE_IMAGE,
X NULL);
X if (do_gen_pullright)
X xv_set(mi,
X MENU_GEN_PULLRIGHT, gen_pullright,
X NULL);
X else
X xv_set(mi, MENU_INACTIVE, TRUE, NULL);
X }
X xv_set(next_menu, MENU_APPEND_ITEM, mi, NULL);
X cnt++;
X }
X closedir(dirp);
X mi = (Menu_item)xv_create(XV_NULL, MENUITEM,
X MENU_STRING, getfilename(path),
X MENU_RELEASE,
X MENU_RELEASE_IMAGE,
X MENU_NOTIFY_PROC, my_action_proc,
X NULL);
X if (!cnt) {
X xv_destroy(next_menu);
X /* An empty or unsearchable directory - deactivate item */
X xv_set(mi, MENU_INACTIVE, TRUE, NULL);
X } else {
X xv_set(next_menu,
X MENU_TITLE_ITEM, strcpy(malloc(strlen(path)+1), path),
X MENU_CLIENT_DATA, strcpy(malloc(strlen(path)+1), path),
X NULL);
X xv_set(mi, MENU_PULLRIGHT, next_menu, NULL);
X }
X recursion--;
X return mi;
X }
X return (Menu_item)xv_create(NULL, MENUITEM,
X MENU_STRING, getfilename(path),
X MENU_RELEASE,
X MENU_RELEASE_IMAGE,
X MENU_NOTIFY_PROC, my_action_proc,
X NULL);
X}
END_OF_FILE
if test 6585 -ne `wc -c <'xview.demos/menus/menu_dir2.c'`; then
echo shar: \"'xview.demos/menus/menu_dir2.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/menus/menu_dir2.c'
fi
if test -f 'xview.demos/menus/pin_menu.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/menus/pin_menu.c'\"
else
echo shar: Extracting \"'xview.demos/menus/pin_menu.c'\" \(4815 characters\)
sed "s/^X//" >'xview.demos/menus/pin_menu.c' <<'END_OF_FILE'
X/*
X * pin_menu.c -
X * Demonstrate how to generate your own pinup menu.
X * Use of MENU_GEN_PIN_WINDOW is for static menus only.
X * This demo uses menus whose items may change, so we
X * need to reflect those changes in our own command frame.
X */
X#include <xview/xview.h>
X#include <xview/canvas.h>
X#include <xview/panel.h>
X
XFrame frame;
X
X/*
X * main -
X * Create a frame, canvas and menu.
X * A canvas receives input in its canvas_paint_window().
X * Specify creation of an Open Look Menu and transformation of
X * the menu to a pinned command window.
X * Each menu item specifies an action proc to be called when the
X * item is chosen, regardless of whether or not menu is pinned.
X */
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X Canvas canvas;
X Menu menu;
X void my_notify_proc(), my_event_proc(), menu_done();
X extern void exit();
X
X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
X
X frame = (Frame)xv_create(NULL, FRAME,
X FRAME_LABEL, argv[0],
X NULL);
X canvas = (Canvas)xv_create(frame, CANVAS,
X XV_WIDTH, 300,
X XV_HEIGHT, 200,
X NULL);
X menu = (Menu)xv_create(NULL, MENU,
X MENU_GEN_PIN_WINDOW, frame, "Junk",
X MENU_DONE_PROC, menu_done,
X /*
X MENU_STRINGS, "Yes", "No", "Maybe", NULL,
X MENU_NOTIFY_PROC, my_notify_proc,
X */
X MENU_ITEM, MENU_STRING, "No", MENU_NOTIFY_PROC, my_notify_proc, NULL,
X MENU_ITEM, MENU_STRING, "Yes", MENU_NOTIFY_PROC, my_notify_proc, NULL,
X MENU_ITEM, MENU_STRING, "Maybe", MENU_NOTIFY_PROC, my_notify_proc, NULL,
X MENU_ITEM,
X MENU_STRING, "Save",
X MENU_NOTIFY_PROC, my_notify_proc,
X MENU_PULLRIGHT,
X xv_create(canvas, MENU,
X MENU_ITEM,
X MENU_STRING, "Update Changes",
X MENU_NOTIFY_PROC, my_notify_proc,
X NULL,
X NULL),
X NULL,
X MENU_ITEM,
X MENU_STRING, "Quit",
X MENU_NOTIFY_PROC, exit,
X NULL,
X NULL);
X
X xv_set(canvas_paint_window(canvas),
X WIN_CONSUME_EVENTS, WIN_MOUSE_BUTTONS, NULL,
X WIN_EVENT_PROC, my_event_proc,
X /* associate the menu to the canvas win so we can retreive it easily */
X WIN_CLIENT_DATA, menu,
X NULL);
X
X window_fit(frame);
X window_main_loop(frame);
X}
X
X/*
X * menu_done - menu has been popped-down. Make sure the command frame panel
X * matches the menu.
X */
Xvoid
Xmenu_done(menu, result)
XMenu menu;
XXv_opaque result;
X{
X int default_item, i;
X Frame pin_frame;
X Panel panel;
X Panel_item pi;
X
X printf("result = %x\n", result);
X if (!(pin_frame = (Frame)xv_get(menu, MENU_PIN_WINDOW))) {
X puts("menu has no pin frame");
X return;
X }
X panel = (Panel)xv_get(pin_frame, FRAME_CMD_PANEL);
X /* get the ordinal number of the default menu item */
X default_item = (int)xv_get(menu, MENU_DEFAULT);
X
X /* search for the <default>-th item in the panel and... */
X pi = (Panel_item)xv_get(panel, PANEL_FIRST_ITEM);
X for (i = 1 /*menu items offset at 1*/; i < default_item && pi; i++)
X pi = (Panel_item)xv_get(pi, PANEL_NEXT_ITEM);
X
X /* set that paenl item to be the default item */
X xv_set(panel, PANEL_DEFAULT_ITEM, pi, NULL);
X}
X
X/*
X * my_notify_proc - Display menu selection in frame header.
X */
Xvoid
Xmy_notify_proc(menu, menu_item)
XMenu menu;
XMenu_item menu_item;
X{
X xv_set(frame,
X FRAME_LABEL, xv_get(menu_item, MENU_STRING),
X NULL);
X}
X
X/*
X * my_event_proc - Call menu_show() to display menu on right mouse button push.
X */
Xvoid
Xmy_event_proc(window, event)
XXv_Window window;
XEvent *event;
X{
X if (event_action(event) == ACTION_MENU && event_is_down(event)) {
X Menu menu = (Menu)xv_get(window, WIN_CLIENT_DATA);
X if (!xv_get(menu, MENU_PIN_WINDOW))
X create_pin_win(menu);
X menu_show(menu, window, event, NULL);
X }
X}
X
X#define MENU_KEY 100
X#define MENU_ITEM_KEY 101
X#define ACTION_KEY 102
X
Xcreate_pin_win(menu)
XMenu menu;
X{
X int i;
X void pin_btn_notify();
X Frame cmd_frame = (Frame)xv_create(frame, FRAME_CMD, XV_SHOW, FALSE, NULL);
X Panel panel = (Panel)xv_get(cmd_frame, FRAME_CMD_PANEL);
X Menu_item mi;
X
X printf("frame = %x, panel = %x\n", cmd_frame, panel);
X for (i = (int)xv_get(menu, MENU_NITEMS); i > 0; i--) {
X mi = (Menu_item)xv_get(menu, MENU_NTH_ITEM, i);
X printf("adding panel item: %s\n", xv_get(mi, MENU_STRING));
X xv_create(panel, PANEL_BUTTON,
X /* PANEL_MENU_ITEM, TRUE, */
X PANEL_LABEL_STRING, xv_get(mi, MENU_STRING),
X PANEL_NOTIFY_PROC, pin_btn_notify,
X XV_KEY_DATA, MENU_KEY, menu,
X XV_KEY_DATA, MENU_ITEM_KEY, mi,
X XV_KEY_DATA, ACTION_KEY, xv_get(mi, MENU_NOTIFY_PROC),
X NULL);
X }
X window_fit(panel);
X window_fit(cmd_frame);
X xv_set(menu, MENU_PIN_WINDOW, cmd_frame, NULL);
X}
X
Xvoid
Xpin_btn_notify(item, event)
XPanel_item item;
XEvent *event;
X{
X Menu menu = (Menu)xv_get(item, XV_KEY_DATA, MENU_KEY);
X Menu_item mi = (Menu)xv_get(item, XV_KEY_DATA, MENU_ITEM_KEY);
X void (*action)() = (void (*)())xv_get(item, XV_KEY_DATA, ACTION_KEY);
X
X (*action)(menu, mi);
X}
END_OF_FILE
if test 4815 -ne `wc -c <'xview.demos/menus/pin_menu.c'`; then
echo shar: \"'xview.demos/menus/pin_menu.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/menus/pin_menu.c'
fi
if test -f 'xview.demos/seln_svc/long_seln.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/seln_svc/long_seln.c'\"
else
echo shar: Extracting \"'xview.demos/seln_svc/long_seln.c'\" \(5727 characters\)
sed "s/^X//" >'xview.demos/seln_svc/long_seln.c' <<'END_OF_FILE'
X/*
X * long_seln.c shows how to get an arbitrarily large selection by
X * providing a reading procedure to selection_query(). The panel
X * items allow the user to choose between 3 selection ranks.
X */
X#include <xview/xview.h>
X#include <xview/textsw.h>
X#include <xview/panel.h>
X#include <xview/seln.h>
X
Xextern char *malloc();
X
XSeln_rank seln_type = SELN_PRIMARY;
X
X#define FIRST_BUFFER 0
X#define NOT_FIRST_BUFFER !FIRST_BUFFER
X
Xchar *seln_bufs[3]; /* contents of each of the three selections */
X
XSeln_result read_proc(); /* supplied to selection_query() as reader */
X
XTextsw textsw; /* select from this textsw */
XXv_Server server;
Xchar *get_selection();
X
Xvoid
Xchange_selection(item, value)
XPanel_item item;
Xint value;
X{
X if (value == 0)
X seln_type = SELN_PRIMARY;
X else if (value == 1)
X seln_type = SELN_SECONDARY;
X else
X seln_type = SELN_SHELF;
X}
X
Xmain(argc, argv)
Xchar *argv[];
X{
X Frame frame;
X Panel panel;
X void print_seln(), exit();
X
X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
X frame = (Frame) xv_create(NULL, FRAME,
X FRAME_LABEL, argv[0],
X NULL);
X
X panel = (Panel)xv_create(frame, PANEL,
X WIN_WIDTH, WIN_EXTEND_TO_EDGE,
X NULL);
X
X (void) xv_create(panel, PANEL_BUTTON,
X PANEL_LABEL_STRING, "Quit",
X PANEL_NOTIFY_PROC, exit,
X NULL);
X (void) xv_create(panel, PANEL_BUTTON,
X PANEL_LABEL_STRING, "Get Selection",
X PANEL_NOTIFY_PROC, print_seln,
X NULL);
X (void) xv_create(panel, PANEL_CHOICE,
X PANEL_LABEL_STRING, "Selection Type",
X PANEL_CHOICE_STRINGS, "Primary", "Secondary", "Shelf", NULL,
X PANEL_NOTIFY_PROC, change_selection,
X NULL);
X window_fit(panel);
X
X textsw = (Textsw)xv_create(frame, TEXTSW,
X WIN_X, 0,
X WIN_BELOW, panel,
X WIN_ROWS, 10,
X WIN_COLUMNS, 80,
X TEXTSW_FILE_CONTENTS, "/etc/termcap",
X NULL);
X window_fit(frame);
X server = (Xv_Server)xv_get(xv_get(frame, XV_SCREEN), SCREEN_SERVER);
X xv_main_loop(frame);
X}
X
Xvoid
Xprint_seln()
X{
X char *text = get_selection();
X
X if (text)
X printf("---seln---\n%.*s [...]\n---end seln---\n", 20, text);
X}
X
X/*
X * return the text selected in the current selection rank. Use
X * selection_query() to guarantee that the entire selection is
X * retrieved. selection_query() calls our installed routine,
X * read_proc() (see below).
X */
Xchar *
Xget_selection()
X{
X Seln_holder holder;
X Seln_result result;
X Seln_request *response;
X char context = FIRST_BUFFER;
X
X holder = selection_inquire(server, seln_type);
X printf("selection type = %s\n",
X seln_type == SELN_PRIMARY? "primary" :
X seln_type == SELN_SECONDARY? "secondary" : "shelf");
X
X /* result is based on the return value of read_proc() */
X result = selection_query(server, &holder, read_proc, &context,
X SELN_REQ_BYTESIZE, NULL,
X SELN_REQ_CONTENTS_ASCII, NULL,
X NULL);
X if (result == SELN_FAILED) {
X puts("couldn't get selection");
X return NULL;
X }
X
X return seln_bufs[seln_type];
X}
X
X/*
X * Called by selection_query for every buffer of information received.
X * Short messages (under about 2000 bytes) will fit into one buffer.
X * For larger messages, read_proc is called for each buffer in the
X * selection. The context pointer passed to selection_query is
X * modified by read_proc so that we know if this is the first buffer
X * or not.
X */
XSeln_result
Xread_proc(response)
XSeln_request *response;
X{
X char *reply; /* pointer to the data in the response received */
X long seln_len; /* total number of bytes in the selection */
X static long seln_have_bytes;
X /* number of bytes of the selection
X * which have been read; cumulative over all calls for
X * the same selection (it is reset when the first
X * response of a selection is read)
X */
X
X printf("read_proc status: %s (%d)\n",
X response->status == SELN_FAILED? "failed" :
X response->status == SELN_SUCCESS? "succeeded" :
X response->status == SELN_CONTINUED? "continued" : "???",
X response->status);
X if (*response->requester.context == FIRST_BUFFER) {
X reply = response->data;
X
X /* read in the length of the selection -- first attribute.
X * advance "reply" passed attribute to point to actual data.
X */
X reply += sizeof(SELN_REQ_BYTESIZE);
X /* set seln_len to actual data now. (bytes selected) */
X seln_len = *(int *)reply;
X printf("selection size is %ld bytes\n", seln_len);
X /* advance "reply" to next attribute in list */
X reply += sizeof(long);
X
X /* create a buffer large enough to store entire selection */
X if (seln_bufs[seln_type] != NULL)
X free(seln_bufs[seln_type]);
X if (!(seln_bufs[seln_type] = malloc(seln_len + 1))) {
X puts("out of memory");
X return(SELN_FAILED);
X }
X seln_have_bytes = 0;
X
X /* move "reply" passed attribute so it points to contents */
X reply += sizeof(SELN_REQ_CONTENTS_ASCII);
X *response->requester.context = NOT_FIRST_BUFFER;
X } else {
X /* this is not the first buffer, so the contents of the
X * response is just more of the selection
X */
X reply = response->data;
X }
X
X /* copy data from received to the seln buffer allocated above */
X (void) strcpy(&seln_bufs[seln_type][seln_have_bytes], reply);
X seln_have_bytes += strlen(reply);
X
X return SELN_SUCCESS;
X}
END_OF_FILE
if test 5727 -ne `wc -c <'xview.demos/seln_svc/long_seln.c'`; then
echo shar: \"'xview.demos/seln_svc/long_seln.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/seln_svc/long_seln.c'
fi
if test -f 'xview.demos/seln_svc/seln.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/seln_svc/seln.c'\"
else
echo shar: Extracting \"'xview.demos/seln_svc/seln.c'\" \(5659 characters\)
sed "s/^X//" >'xview.demos/seln_svc/seln.c' <<'END_OF_FILE'
X/*
X * seln.c -- print the primary selection from the server. If the
X * selection is in a text subwindow, then print information about
X * the line number(s) the selection spans and the indexes of the
X * bytes within the textsw's text stream. This simple program
X * may not be sufficient for general usage -- see comments in
X * get_selection() comments below.
X */
X#include <stdio.h>
X#include <xview/xview.h>
X#include <xview/textsw.h>
X#include <xview/panel.h>
X#include <xview/server.h>
X#include <xview/seln.h>
X
XXv_Server server;
XTextsw textsw;
X
Xchar *get_selection();
X
Xmain(argc, argv)
Xchar *argv[];
X{
X Frame frame;
X Panel panel;
X void print_seln(), exit();
X
X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
X
X frame = (Frame) xv_create(NULL, FRAME,
X FRAME_LABEL, argv[0],
X NULL);
X panel = (Panel) xv_create(frame, PANEL,
X WIN_WIDTH, WIN_EXTEND_TO_EDGE,
X NULL);
X (void) xv_create(panel, PANEL_BUTTON,
X PANEL_LABEL_STRING, "Quit",
X PANEL_NOTIFY_PROC, exit,
X NULL);
X (void) xv_create(panel, PANEL_BUTTON,
X PANEL_LABEL_STRING, "Get Selection",
X PANEL_NOTIFY_PROC, print_seln,
X NULL);
X window_fit(panel);
X
X textsw = (Textsw)xv_create(frame, TEXTSW,
X WIN_X, 0,
X WIN_BELOW, panel,
X WIN_ROWS, 10,
X WIN_COLUMNS, 80,
X TEXTSW_FILE_CONTENTS, "/etc/passwd",
X NULL);
X window_fit(frame);
X
X server = (Xv_Server)xv_get(xv_get(frame, XV_SCREEN), SCREEN_SERVER);
X
X xv_main_loop(frame);
X}
X
Xvoid
Xprint_seln()
X{
X char *text = get_selection();
X
X if (text)
X printf("---selection---\n%s\n---end seln---\n", text);
X}
X
X/*
X * Get the selection using selection_ask(). Note that if the
X * selection is bigger than about 2K, the whole selection will
X * not be gotten with one call, thus this method of getting the
X * selection may not be sufficient.
X */
Xchar *
Xget_selection()
X{
X long sel_lin_num, lines_selected;
X Textsw_index first, last;
X Seln_holder holder;
X Seln_result result;
X int len;
X Seln_request *request;
X static char selection_buf[BUFSIZ];
X register char *ptr;
X
X /* get the holder of the primary selection */
X holder = selection_inquire(server, SELN_PRIMARY);
X
X /* If the selection occurs in the text subwindow, print lots
X * of info about the selection.
X */
X if (seln_holder_same_client(&holder, textsw)) {
X /* ask for information from the selection service */
X request = selection_ask(server, &holder,
X /* get the index of the first and last chars in seln */
X SELN_REQ_FIRST, NULL,
X SELN_REQ_LAST, NULL,
X /* get the actual selection bytes */
X SELN_REQ_CONTENTS_ASCII, NULL,
X /* fool the textsw to think entire lines are selected */
X SELN_REQ_FAKE_LEVEL, SELN_LEVEL_LINE,
X /* line numbers of beginning and ending of the seln */
X SELN_REQ_FIRST_UNIT, NULL,
X SELN_REQ_LAST_UNIT, NULL,
X NULL);
X /* set the ptr to beginning of data -- SELN_REQ_FIRST */
X ptr = request->data;
X /* "first" is data succeeding SELN_REQ_FIRST -- skip attr */
X first = *(Textsw_index *)(ptr += sizeof(SELN_REQ_FIRST));
X ptr += sizeof(Textsw_index); /* skip over value of "first" */
X /* "last" is data succeeding SELN_REQ_LAST -- skip attr */
X last = *(Textsw_index *)(ptr += sizeof(SELN_REQ_LAST));
X ptr += sizeof(Textsw_index); /* skip over value of "last" */
X
X /* advance pointer past SELN_REQ_CONTENTS_ASCII */
X ptr += sizeof(SELN_REQ_CONTENTS_ASCII);
X len = strlen(ptr); /* length of string in request */
X (void) strcpy(selection_buf, ptr);
X /*
X * advance pointer past length of string. If the string
X * length isn't aligned to a 4-byte boundary, add the
X * difference in bytes -- then advance pointer passed "value".
X */
X if (len % 4)
X len = len + (4 - (len % 4));
X ptr += len + sizeof(Seln_attribute); /* skip over "value" */
X
X /* advance past SELN_REQ_FAKE_LEVEL, SELN_LEVEL_LINE */
X ptr += sizeof(SELN_REQ_FAKE_LEVEL) + sizeof(SELN_LEVEL_LINE);
X
X sel_lin_num = *(long *)(ptr += sizeof(SELN_REQ_FIRST_UNIT));
X ptr += sizeof(long);
X lines_selected = *(long *)(ptr += sizeof(SELN_REQ_LAST_UNIT));
X ptr += sizeof(long);
X
X /* hack to workaround bug with SELN_REQ_LAST_UNIT always
X * returning -1. We have to count the line numbers ourselves.
X */
X if (lines_selected < 0) {
X register char *p;
X lines_selected++;
X for (p = selection_buf; *p; p++)
X if (*p == '\n')
X lines_selected++;
X }
X printf("index in textsw: %d-%d, line number(s) = %d-%d\n",
X first+1, last+1, sel_lin_num+1,
X sel_lin_num+lines_selected+1);
X } else {
X /* the selection is not in the text subwindow */
X request = selection_ask(server, &holder,
X SELN_REQ_CONTENTS_ASCII, NULL,
X NULL);
X if (request->status != SELN_SUCCESS) {
X printf("selection_ask() returns %d\n", request->status);
X return "";
X }
X (void) strcpy(selection_buf,
X request->data + sizeof(SELN_REQ_CONTENTS_ASCII));
X }
X return selection_buf;
X}
END_OF_FILE
if test 5659 -ne `wc -c <'xview.demos/seln_svc/seln.c'`; then
echo shar: \"'xview.demos/seln_svc/seln.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/seln_svc/seln.c'
fi
echo shar: End of archive 2 \(of 6\).
cp /dev/null ark2isdone
MISSING=""
for I in 1 2 3 4 5 6 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 6 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0