home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
x
/
volume5
/
xview.demos
/
part03
< prev
next >
Wrap
Text File
|
1989-12-07
|
57KB
|
1,748 lines
Path: uunet!island!sun.com
From: argv@sun.com (Dan Heller)
Newsgroups: comp.sources.x
Subject: v05i041: XView example programs, Part03/06
Message-ID: <1241@island.uu.net>
Date: 8 Dec 89 07:38:06 GMT
Sender: argv@island.uu.net
Lines: 1737
Approved: island!argv@sun.com
Submitted-by: Dan Heller <argv@sun.com>
Posting-number: Volume 5, Issue 41
Archive-name: xview.demos/part03
#! /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 3 (of 6)."
# Contents: xview.demos/canvas/canvas_event.c
# xview.demos/color/color_animate.c xview.demos/color/color_logo.c
# xview.demos/menus/menu_dir.c xview.demos/misc/drag_n_drop.c
# xview.demos/notice/notice.c xview.demos/notifier/ntfy_pipe.c
# xview.demos/panels/choices.c xview.demos/seln_svc/text_seln.c
# xview.demos/textsw/textsw.font.c
# Wrapped by argv@island on Thu Dec 7 23:18:19 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'xview.demos/canvas/canvas_event.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/canvas/canvas_event.c'\"
else
echo shar: Extracting \"'xview.demos/canvas/canvas_event.c'\" \(4710 characters\)
sed "s/^X//" >'xview.demos/canvas/canvas_event.c' <<'END_OF_FILE'
X/*
X * canvas_event.c
X * Demonstrates how to get keyboard and mouse events in an canvas
X * window. Looks for keyboards, pointer movement and button
X * events and displays the info in the canvas.
X */
X#include <X11/Xlib.h>
X#include <xview/xview.h>
X#include <xview/canvas.h>
X#include <xview/xv_xrect.h>
X
Xvoid event_proc(), repaint_proc();
Xchar kbd_msg[128], ptr_msg[128], but_msg[128];
X
X/*
X * main()
X * Create a canvas specifying a repaint procedure.
X * Get the paint window for the canvas and set the input
X * mask and the event procedure.
X */
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Frame frame;
X Canvas canvas;
X
X /* Initialize XView */
X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
X
X /* Create windows -- base frame and canvas. */
X frame = (Frame)xv_create(NULL, FRAME, NULL);
X
X canvas = (Canvas)xv_create(frame, CANVAS,
X XV_WIDTH, 300,
X XV_HEIGHT, 110,
X CANVAS_X_PAINT_WINDOW, TRUE,
X CANVAS_REPAINT_PROC, repaint_proc,
X NULL);
X window_fit(frame);
X
X /* Set input mask */
X xv_set(canvas_paint_window(canvas),
X WIN_EVENT_PROC, event_proc,
X WIN_CONSUME_EVENTS,
X KBD_DONE, KBD_USE, LOC_DRAG, LOC_MOVE, LOC_WINENTER,
X LOC_WINEXIT, WIN_ASCII_EVENTS, WIN_MOUSE_BUTTONS,
X NULL,
X NULL);
X
X /* Initial messages */
X strcpy(kbd_msg, "Keyboard: key press events");
X strcpy(ptr_msg, "Pointer: pointer movement events");
X strcpy(but_msg, "Button: button press events");
X
X /* Start event loop */
X xv_main_loop(frame);
X}
X
X/*
X * event_proc()
X * Called when an event is received in the canvas window.
X * Updates the keyboard, pointer and button message strings
X * and then calls repaint_proc() to paint them to the window.
X */
Xvoid
Xevent_proc(window, event)
XXv_Window window;
XEvent *event;
X{
X if (event_is_ascii(event))
X sprintf(kbd_msg, "Keyboard: key '%c' %d pressed at %d,%d",
X event_action(event), event_action(event),
X event_x(event), event_y(event));
X else
X switch (event_action(event)) {
X case KBD_USE:
X sprintf(kbd_msg, "Keyboard: got keyboard focus");
X break;
X case KBD_DONE:
X sprintf(kbd_msg, "Keyboard: lost keyboard focus");
X break;
X case LOC_MOVE:
X sprintf(ptr_msg, "Pointer: moved to %d,%d",
X event_x(event), event_y(event));
X break;
X case LOC_DRAG:
X sprintf(ptr_msg, "Pointer: dragged to %d,%d",
X event_x(event), event_y(event));
X break;
X case LOC_WINENTER:
X sprintf(ptr_msg, "Pointer: entered window at %d,%d",
X event_x(event), event_y(event));
X break;
X case LOC_WINEXIT:
X sprintf(ptr_msg, "Pointer: exited window at %d,%d",
X event_x(event), event_y(event));
X break;
X case ACTION_SELECT:
X case MS_LEFT:
X sprintf(but_msg, "Button: Select (Left) at %d,%d",
X event_x(event), event_y(event));
X break;
X case ACTION_ADJUST:
X case MS_MIDDLE:
X sprintf(but_msg, "Button: Adjust (Middle) at %d,%d",
X event_x(event), event_y(event));
X break;
X case ACTION_MENU:
X case MS_RIGHT:
X sprintf(but_msg, "Button: Menu (Right) at %d,%d",
X event_x(event), event_y(event));
X break;
X default:
X return;
X }
X
X /* call repaint proc directly to update messages */
X repaint_proc((Canvas)NULL, window,
X (Display *)xv_get(window, XV_DISPLAY),
X xv_get(window, XV_XID), (Xv_xrectlist *) NULL);
X}
X
X/*
X * 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
Xrepaint_proc(canvas, paint_window, dpy, xwin, xrects)
XCanvas canvas; /* Ignored */
XXv_Window paint_window; /* Ignored */
XDisplay *dpy;
XWindow xwin;
XXv_xrectlist *xrects; /* Ignored */
X{
X GC gc = DefaultGC(dpy, DefaultScreen(dpy));
X
X XClearWindow(dpy, xwin);
X XDrawString(dpy, xwin, gc, 25, 25, kbd_msg, strlen(kbd_msg));
X XDrawString(dpy, xwin, gc, 25, 50, ptr_msg, strlen(ptr_msg));
X XDrawString(dpy, xwin, gc, 25, 75, but_msg, strlen(but_msg));
X}
END_OF_FILE
if test 4710 -ne `wc -c <'xview.demos/canvas/canvas_event.c'`; then
echo shar: \"'xview.demos/canvas/canvas_event.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/canvas/canvas_event.c'
fi
if test -f 'xview.demos/color/color_animate.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/color/color_animate.c'\"
else
echo shar: Extracting \"'xview.demos/color/color_animate.c'\" \(5359 characters\)
sed "s/^X//" >'xview.demos/color/color_animate.c' <<'END_OF_FILE'
X/*
X * color_animate.c -- use glyphs from the "icon" font distributed
X * with XView to do frame-by-frame animation.
X */
X#include <stdio.h>
X#include <ctype.h>
X#include <X11/X.h>
X#include <X11/Xlib.h>
X#include <X11/Xos.h> /* for <sys/time.h> */
X#include <xview/xview.h>
X#include <xview/panel.h>
X#include <xview/font.h>
X#include <xview/notify.h>
X#include <xview/cms.h>
X
XFrame frame;
XCanvas canvas;
XDisplay *dpy;
XGC gc;
XWindow canvas_win;
XNotify_value animate();
Xstruct itimerval timer;
X
X#define ArraySize(x) (sizeof(x)/sizeof(x[0]))
Xchar *horses[] = { "N", "O", "P", "Q", "R" };
Xchar *eyes[] = { "2", "5", "4", "3", "4", "5", "2", "1", "0", "/", "0", "1" };
Xchar *boys[] = { "\007", "\005", "\007", "\010" };
Xchar *men[] = { "\\", "]", "Y", "Z", "[" };
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#define RANDOM_COLOR 8
X
Xint max_images = ArraySize(horses);
Xchar **images = horses;
Xint cnt;
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X unsigned char red[8], green[8], blue[8];
X Panel panel;
X XGCValues gcvalues;
X Xv_Font _font;
X XFontStruct *font;
X void start_stop(), adjust_speed(), change_glyph();
X Xv_cmsdata cms_data;
X long *colors;
X extern void exit();
X
X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, 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] = 50;
X red[BLUE] = 10; green[BLUE] = 50; 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 = 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 frame = (Frame)xv_create(XV_NULL, FRAME,
X FRAME_LABEL, argv[0],
X FRAME_SHOW_FOOTER, TRUE,
X NULL);
X
X panel = (Panel)xv_create(frame, PANEL,
X PANEL_LAYOUT, PANEL_VERTICAL,
X WIN_CMS_NAME, "panel",
X WIN_CMS_DATA, &cms_data,
X NULL);
X xv_create(panel, PANEL_BUTTON,
X PANEL_LABEL_STRING, "Quit",
X PANEL_NOTIFY_PROC, exit,
X PANEL_ITEM_COLOR, RED,
X NULL);
X xv_create(panel, PANEL_SLIDER,
X PANEL_LABEL_STRING, "Millisecs Between Frames",
X PANEL_VALUE, 0,
X PANEL_MAX_VALUE, 120,
X PANEL_ITEM_COLOR, BLUE,
X PANEL_NOTIFY_PROC, adjust_speed,
X NULL);
X xv_create(panel, PANEL_CHOICE,
X PANEL_LABEL_STRING, "Glyphs",
X PANEL_LAYOUT, PANEL_HORIZONTAL,
X PANEL_DISPLAY_LEVEL, PANEL_ALL,
X PANEL_CHOICE_STRINGS, "Horse", "Man", "Boy", "Eye", NULL,
X PANEL_ITEM_COLOR, GREEN,
X PANEL_NOTIFY_PROC, change_glyph,
X NULL);
X window_fit(panel);
X
X cms_data.type = XV_STATIC_CMS;
X cms_data.rgb_count = cms_data.size = 2;
X canvas = (Canvas)xv_create(frame, CANVAS,
X XV_WIDTH, 64,
X XV_HEIGHT, 64,
X WIN_CMS_NAME, "rainbow",
X WIN_CMS_DATA, &cms_data,
X CANVAS_X_PAINT_WINDOW, TRUE,
X /* WIN_DYNAMIC_VISUAL, TRUE, */
X CANVAS_RETAINED, FALSE,
X NULL);
X canvas_win = (Window)xv_get(canvas_paint_window(canvas), XV_XID);
X
X window_fit(frame);
X
X dpy = (Display *)xv_get(frame, XV_DISPLAY);
X _font = (Xv_Font)xv_find(frame, FONT,
X FONT_NAME, "icon",
X NULL);
X font = (XFontStruct *)xv_get(_font, FONT_INFO);
X
X colors = (long *)xv_get(canvas, WIN_X_COLOR_INDICES);
X gcvalues.font = font->fid;
X gcvalues.graphics_exposures = False;
X gcvalues.foreground = colors[1];
X gcvalues.background = WhitePixel(dpy, DefaultScreen(dpy));
X gc = XCreateGC(dpy, RootWindow(dpy, DefaultScreen(dpy)),
X GCForeground | GCBackground | GCFont | GCGraphicsExposures,
X &gcvalues);
X
X xv_main_loop(frame);
X}
X
XNotify_value
Xanimate()
X{
X static unsigned char red, green, blue;
X Xv_cmsdata cms_data;
X long *colors;
X
X red = (red+1) % 255;
X green = (green+2) % 255;
X blue = (blue+3) % 255;
X
X cms_data.type = XV_STATIC_CMS;
X cms_data.size = 2;
X cms_data.rgb_count = 2;
X cms_data.index = 1;
X cms_data.red = &red;
X cms_data.green = &green;
X cms_data.blue = &blue;
X xv_set(canvas, WIN_CMS_DATA, &cms_data, NULL);
X colors = (long *)xv_get(canvas, WIN_X_COLOR_INDICES);
X XSetForeground(dpy, gc, colors[1]);
X
X XDrawImageString(dpy, canvas_win, gc, 5, 40, images[cnt], 1);
X cnt = (cnt + 1) % max_images;
X
X return NOTIFY_DONE;
X}
X
Xvoid
Xchange_glyph(item, value)
XPanel_item item;
Xint value;
X{
X cnt = 0;
X if (value == 0) {
X max_images = ArraySize(horses);
X images = horses;
X } else if (value == 1) {
X max_images = ArraySize(men);
X images = men;
X } else if (value == 2) {
X max_images = ArraySize(boys);
X images = boys;
X } else if (value == 3) {
X max_images = ArraySize(eyes);
X images = eyes;
X }
X XClearWindow(dpy, canvas_win);
X}
X
Xvoid
Xadjust_speed(item, value)
XPanel_item item;
Xint value;
X{
X if (value > 0) {
X timer.it_value.tv_usec = (value + 20) * 1000;
X timer.it_interval.tv_usec = (value + 20) * 1000;
X notify_set_itimer_func(frame, animate, ITIMER_REAL, &timer, NULL);
X } else
X /* turn it off */
X notify_set_itimer_func(frame, NULL, ITIMER_REAL, NULL, NULL);
X}
END_OF_FILE
if test 5359 -ne `wc -c <'xview.demos/color/color_animate.c'`; then
echo shar: \"'xview.demos/color/color_animate.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/color/color_animate.c'
fi
if test -f 'xview.demos/color/color_logo.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/color/color_logo.c'\"
else
echo shar: Extracting \"'xview.demos/color/color_logo.c'\" \(4703 characters\)
sed "s/^X//" >'xview.demos/color/color_logo.c' <<'END_OF_FILE'
X/*
X * color_logo.c --
X * This program demonstrates the combined use of the XView color
X * model/API and Xlib graphics calls. The program uses XView to
X * create and manage its colormap segment while doing its actual
X * drawing using Xlib routines.
X * The program draws the X logo in red, green and blue in a canvas.
X */
X#include <X11/Xlib.h>
X#include <X11/bitmaps/xlogo64>
X#include <xview/xview.h>
X#include <xview/canvas.h>
X#include <xview/cms.h>
X#include <xview/xv_xrect.h>
X
X/* Color indices */
X#define WHITE 0
X#define RED 1
X#define GREEN 2
X#define BLUE 3
X#define NUM_COLORS 4
X
X/* graphics context used for rendering logos */
XGC gc;
X
X/* table of pixel values for colors */
Xunsigned long *pixel_table;
X
X/*
X * Create a frame and a canvas.
X * Allocate read-only colors (called a static colormap segment in
X * XView parlance) and associate colors with the canvas. The indices
X * into an XView colormap segment always range from 0 to size-1, where
X * size is the number of colors allocated in the colormap segment.
X * These logical index values translate into actual indices into the
X * colormap map as allocated by the X server. The WIN_X_COLOR_INDICES
X * attribute returns the actual colormap indices. The indices are
X * returned as an array of unsigned longs.
X */
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X Frame frame;
X Canvas canvas;
X Xv_cmsdata cms_data;
X unsigned char red[NUM_COLORS], green[NUM_COLORS], blue[NUM_COLORS];
X Display *display;
X XGCValues gc_val;
X XID xid;
X Pixmap xlogo;
X XGCValues gcvalues;
X int gcvaluemask;
X void canvas_repaint_proc();
X
X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
X
X /* initalize the cms data and set the required RGB values */
X initialize_cms_data(&cms_data, red, green, blue);
X
X frame = (Frame)xv_create(XV_NULL, FRAME,
X FRAME_LABEL, argv[0],
X XV_WIDTH, 448,
X XV_HEIGHT, 192,
X NULL);
X
X canvas = (Canvas)xv_create(frame, CANVAS,
X CANVAS_X_PAINT_WINDOW, TRUE,
X CANVAS_REPAINT_PROC, canvas_repaint_proc,
X WIN_CMS_NAME, "palette",
X WIN_CMS_DATA, &cms_data,
X NULL);
X
X /* Get the actual indices into the colormap */
X pixel_table = (int *)xv_get(canvas, WIN_X_COLOR_INDICES);
X
X /* Get display and the XID of the canvas */
X display = (Display *)xv_get(canvas, XV_DISPLAY);
X xid = (XID)xv_get(canvas, XV_XID);
X
X /* create the stipple xlogo */
X xlogo = XCreateBitmapFromData(display, xid, xlogo64_bits,
X xlogo64_width, xlogo64_height);
X
X /* setup gc for rendering logos to screen */
X gcvalues.function = GXcopy;
X gcvalues.stipple = xlogo;
X gcvalues.fill_style = FillStippled;
X gcvalues.graphics_exposures = False;
X gcvaluemask = GCFunction|GCStipple|GCFillStyle|GCGraphicsExposures;
X
X /* create normal render gc for logo rendering */
X gc = XCreateGC(display, xid, gcvaluemask, &gcvalues);
X
X /* Start event loop */
X xv_main_loop(frame);
X}
X
X/*
X * Draws onto the canvas using Xlib drawing functions.
X * Draw the X logo into the window in three colors. In each case,
X * change the GC's foreground color to the pixel value specified.
X */
Xvoid
Xcanvas_repaint_proc(canvas, pw, display, xid, xrects)
XCanvas canvas;
XXv_Window pw;
XDisplay *display;
XWindow xid;
XXv_xrectlist *xrects;
X{
X XGCValues gc_val;
X unsigned long pixel_value;
X
X /* draw the logos in red, green and blue */
X XSetForeground(display, gc, pixel_table[RED]);
X XFillRectangle(display, xid, gc, 64, 64,
X xlogo64_width, xlogo64_height);
X
X XSetForeground(display, gc, pixel_table[GREEN]);
X XFillRectangle(display, xid, gc, 192, 64,
X xlogo64_width, xlogo64_height);
X
X XSetForeground(display, gc, pixel_table[BLUE]);
X XFillRectangle(display, xid, gc, 320, 64,
X xlogo64_width, xlogo64_height);
X}
X
X/*
X * initialize_cms_data()
X * Initialize the colormap segment data and setup the RGB values.
X */
Xinitialize_cms_data(cms_data, red, green, blue)
XXv_cmsdata *cms_data;
Xunsigned char *red, *green, *blue;
X{
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
X cms_data->type = XV_STATIC_CMS;
X cms_data->size = 4;
X cms_data->rgb_count = 4;
X cms_data->index = 0;
X cms_data->red = red;
X cms_data->green = green;
X cms_data->blue = blue;
X}
END_OF_FILE
if test 4703 -ne `wc -c <'xview.demos/color/color_logo.c'`; then
echo shar: \"'xview.demos/color/color_logo.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/color/color_logo.c'
fi
if test -f 'xview.demos/menus/menu_dir.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/menus/menu_dir.c'\"
else
echo shar: Extracting \"'xview.demos/menus/menu_dir.c'\" \(5218 characters\)
sed "s/^X//" >'xview.demos/menus/menu_dir.c' <<'END_OF_FILE'
X/*
X * menu_dir.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 the entire directory tree initially. Do not attempt to
X * build a tree from /. You will most likely run out of resources.
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> /* probably sun/BSD specific */
X#endif /* MAXPATHLEN */
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 * Its callback procedure calls menu_show().
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
X /* associate the menu to the canvas win for easy retrieval */
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
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
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 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 if (!(mi = add_path_to_menu(buf)))
X /* unreadable file or dir - deactivate item */
X mi = xv_create(XV_NULL, MENUITEM,
X MENU_STRING, getfilename(dp->d_name),
X MENU_RELEASE,
X MENU_RELEASE_IMAGE,
X MENU_INACTIVE, TRUE,
X NULL);
X xv_set(next_menu, MENU_APPEND_ITEM, mi, NULL);
X cnt++;
X }
X closedir(dirp);
X mi = 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, MENU_TITLE_ITEM, getfilename(path), NULL);
X xv_set(mi, MENU_PULLRIGHT, next_menu, NULL);
X }
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 5218 -ne `wc -c <'xview.demos/menus/menu_dir.c'`; then
echo shar: \"'xview.demos/menus/menu_dir.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/menus/menu_dir.c'
fi
if test -f 'xview.demos/misc/drag_n_drop.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/misc/drag_n_drop.c'\"
else
echo shar: Extracting \"'xview.demos/misc/drag_n_drop.c'\" \(4535 characters\)
sed "s/^X//" >'xview.demos/misc/drag_n_drop.c' <<'END_OF_FILE'
X/*
X * drag_n_drop.c -- demonstrate how to handle drag and drop usage in
X * OPEN LOOK. Create a base frame, canvas and text subwindow. Install
X * an event handler for the canvas to interpret drag-and-drop actions.
X * The text subwindow is there for convenience, but you can drag and
X * drop from anywhere on the screen. The "file manager" application
X * can be used to generate the ACTION_DRAG_LOAD event/action. The user
X * can select text and then "drag" the selection on top of the canvas
X * window. When this happens, the canvas' callback routine is called
X * and the event_action(event) will be set accordingly.
X */
X#include <X11/Xlib.h>
X#include <xview/xview.h>
X#include <xview/canvas.h>
X#include <xview/textsw.h>
X#include <xview/seln.h>
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Frame frame;
X Canvas canvas;
X void event_handler();
X
X xv_init(XV_INIT_ARGS, argc, argv, NULL);
X
X frame = (Frame)xv_create(NULL, FRAME, NULL);
X canvas = (Canvas)xv_create(frame, CANVAS,
X XV_WIDTH, 300,
X XV_HEIGHT, 300,
X NULL);
X xv_set(canvas_paint_window(canvas),
X WIN_EVENT_PROC, event_handler,
X NULL);
X (void) xv_create(frame, TEXTSW,
X TEXTSW_CONTENTS,
X "This is a test of the emergency broadcasting system.",
X XV_HEIGHT, 300,
X XV_WIDTH, 300,
X NULL);
X window_fit(frame);
X
X xv_main_loop(frame);
X}
X
X/*
X * handle the drag and drop actions. Also handle the ACTION_PASTE
X * event since it is very similar. The action specifies how the
X * event was generated. In all drag-and-drop cases, the contents
X * of the selection is held in the primary selection. Use the
X * selection service routines to extract the information.
X */
Xvoid
Xevent_handler(window, event, arg)
XXv_Window window;
XEvent *event;
XNotify_arg arg;
X{
X Display *dpy = (Display *)xv_get(window, XV_DISPLAY);
X char msg[128];
X
X /* not interested in action-up events */
X if (event_is_up(event))
X return;
X switch (event_action(event)) {
X case ACTION_PASTE:
X case ACTION_DRAG_LOAD:
X case ACTION_DRAG_COPY:
X case ACTION_DRAG_MOVE: {
X Seln_holder holder;
X Seln_request *result;
X Seln_rank selection;
X char *data;
X int read_only;
X
X /*
X * ACTION_PASTE is generated by hitting L8, or the "paste"
X * key on the left side of the keyboard. This assumes you
X * have cut (L10) or copied (L6) a selection first.
X */
X
X if (event_action(event) == ACTION_PASTE) {
X strcpy(msg, "paste from shelf: ");
X selection = SELN_SHELF;
X } else {
X sprintf(msg, "drag and drop (%s): ",
X event_action(event) == ACTION_DRAG_MOVE ? "move" :
X event_action(event) == ACTION_DRAG_LOAD ? "load" : "copy");
X selection = SELN_PRIMARY;
X }
X holder = seln_inquire(selection);
X result = seln_ask(&holder,
X SELN_REQ_IS_READONLY, NULL,
X SELN_REQ_CONTENTS_ASCII, NULL,
X NULL);
X data = result->data;
X data += sizeof(Seln_attribute);
X
X /* testing read-only is only important if the selection
X * came from a textsw. If so, then we need to know if
X * it is read-only to head off a drag-move since we won't
X * be able to delete the selection from that window.
X * Note, there is no way to determine the type of the xview
X * object that is holding the selection! :-(
X */
X
X if ((read_only = *(int *) data) == TRUE &&
X event_action(event) == ACTION_DRAG_MOVE)
X /* can't "move" text from a read-only window. use copy */
X return;
X data += sizeof(int) + sizeof(SELN_REQ_CONTENTS_ASCII);
X strcat(msg, data);
X if (event_action(event) == ACTION_DRAG_MOVE)
X /* ask holder to delete its selection for drag moves */
X seln_ask(&holder, SELN_REQ_DELETE, NULL, NULL);
X break;
X }
X default :
X /* we could go on and on with the above cases ... */
X return;
X }
X XClearWindow(dpy, xv_get(window, XV_XID));
X XDrawString(dpy, xv_get(window, XV_XID),
X DefaultGC(dpy, DefaultScreen(dpy)), 20, 20, msg, strlen(msg));
X}
END_OF_FILE
if test 4535 -ne `wc -c <'xview.demos/misc/drag_n_drop.c'`; then
echo shar: \"'xview.demos/misc/drag_n_drop.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/misc/drag_n_drop.c'
fi
if test -f 'xview.demos/notice/notice.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/notice/notice.c'\"
else
echo shar: Extracting \"'xview.demos/notice/notice.c'\" \(4345 characters\)
sed "s/^X//" >'xview.demos/notice/notice.c' <<'END_OF_FILE'
X/*
X * notice.c --
X * This application creates a frame, a panel, and 3 panel buttons.
X * A message button, a Quit button (to exit the program) and a
X * dummy "commit" button. Extra data is attached to the panel
X * items by the use of XV_KEY_DATA. The callback routine for the
X * quit and Commit buttons is generalized enough that it can apply
X * to either button (or any arbitrary button) because it extracts
X * the expected "data" (via XV_KEY_DATA) from whatever panel
X * button might have called it.
X */
X#include <xview/xview.h>
X#include <xview/panel.h>
X#include <xview/notice.h>
X
X/*
X * assign "data" to panel items using XV_KEY_DATA ... attach the
X * message panel item, a prompt string specific for the panel
X * item's notice_prompt, and a callback function if the user
X * chooses "yes".
X */
X#define MSG_ITEM 10 /* any arbitrary integer */
X#define NOTICE_PROMPT 11
X#define CALLBACK_FUNC 12
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X Frame frame;
X Panel panel;
X Panel_item msg_item;
X Xv_opaque my_notify_proc();
X extern int exit();
X
X /*
X * Initialize XView, and create frame, panel and buttons.
X */
X xv_init(XV_INIT_ARGS, argc, argv, NULL);
X frame = (Frame)xv_create(XV_NULL, FRAME,
X FRAME_LABEL, argv[0],
X NULL);
X panel = (Panel)xv_create(frame, PANEL,
X PANEL_LAYOUT, PANEL_VERTICAL,
X NULL);
X msg_item = (Panel_item)xv_create(panel, PANEL_MESSAGE, NULL);
X (void) xv_create(panel, PANEL_BUTTON,
X PANEL_LABEL_STRING, "Quit",
X PANEL_NOTIFY_PROC, my_notify_proc,
X XV_KEY_DATA, MSG_ITEM, msg_item,
X /*
X * attach a prompt specific for this button used by
X * notice_prompt()
X */
X XV_KEY_DATA, NOTICE_PROMPT, "Really Quit?",
X /*
X * a callback function to call if the user answers "yes"
X * to prompt
X */
X XV_KEY_DATA, CALLBACK_FUNC, exit,
X NULL);
X /*
X * now that the Quit button is under the message item,
X * layout horizontally
X */
X xv_set(panel, PANEL_LAYOUT, PANEL_HORIZONTAL, NULL);
X (void) xv_create(panel, PANEL_BUTTON,
X PANEL_LABEL_STRING, "Commit...",
X PANEL_NOTIFY_PROC, my_notify_proc,
X XV_KEY_DATA, MSG_ITEM, msg_item,
X /*
X * attach a prompt specific for this button used by
X * notice_prompt()
X */
X XV_KEY_DATA, NOTICE_PROMPT, "Update all changes?",
X /*
X * Note there is no callback func here, but one could be
X * written
X */
X NULL);
X
X window_fit(panel);
X window_fit(frame);
X xv_main_loop(frame);
X}
X
X/*
X * my_notify_proc()
X * The notice appears as a result of notice_prompt().
X * The "key data" associated with the panel item is extracted via
X * xv_get(). The resulting choice is displayed in the panel
X * message item.
X */
XXv_opaque
Xmy_notify_proc(item, event)
XPanel_item item;
XEvent *event;
X{
X int result;
X int (*func)();
X char *prompt;
X Panel_item msg_item;
X Panel panel;
X
X func = (int(*)())xv_get(item, XV_KEY_DATA, CALLBACK_FUNC);
X prompt = (char *)xv_get(item, XV_KEY_DATA, NOTICE_PROMPT);
X msg_item = (Panel_item)xv_get(item, XV_KEY_DATA, MSG_ITEM);
X panel = (Panel)xv_get(item, PANEL_PARENT_PANEL);
X /*
X * Create the notice and get a response.
X */
X result = notice_prompt(panel, NULL,
X NOTICE_MESSAGE_STRINGS,
X prompt,
X "Press YES to confirm",
X "Press NO to cancel",
X NULL,
X NOTICE_BUTTON_YES, "YES",
X NOTICE_BUTTON_NO, "NO",
X NULL);
X
X switch(result) {
X case NOTICE_YES:
X xv_set(msg_item, PANEL_LABEL_STRING, "Confirmed", NULL);
X if (func)
X (*func)();
X break;
X case NOTICE_NO:
X xv_set(msg_item, PANEL_LABEL_STRING, "Cancelled", NULL);
X break;
X case NOTICE_FAILED:
X xv_set(msg_item, PANEL_LABEL_STRING, "unable to pop-up",
X NULL);
X break;
X default:
X xv_set(msg_item, PANEL_LABEL_STRING, "unknown choice",
X NULL);
X }
X}
END_OF_FILE
if test 4345 -ne `wc -c <'xview.demos/notice/notice.c'`; then
echo shar: \"'xview.demos/notice/notice.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/notice/notice.c'
fi
if test -f 'xview.demos/notifier/ntfy_pipe.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/notifier/ntfy_pipe.c'\"
else
echo shar: Extracting \"'xview.demos/notifier/ntfy_pipe.c'\" \(5313 characters\)
sed "s/^X//" >'xview.demos/notifier/ntfy_pipe.c' <<'END_OF_FILE'
X/*
X * notify_pipe.c -- fork and set up a pipe to read the IO from the
X * forked process. The program to run is specified on the command
X * line. The functions notify_set_input_func() and
X * notify_set_output_func() are used to install functions which read
X * and write to the process' stdin and stdout.
X * The program does not use any xview code -- just the notifier.
X */
X#include <stdio.h>
X#include <errno.h>
X#include <signal.h>
X#include <sys/time.h>
X#include <sys/types.h>
X#include <sys/wait.h>
X#include <sys/resource.h>
X#include <sys/ioctl.h>
X#include <xview/notify.h>
X
XNotify_client client1 = (Notify_client)10;
XNotify_client client2 = (Notify_client)11;
X
Xint pipe_io[2][2]; /* see diagram */
X/*
X * [0] [1]
X * child reads: |========= pipe_io[0] ========| <- parent writes
X * pipe_io[0][0] pipe_io[0][1]
X *
X * parent reads: |========= pipe_io[1] ========| <- child writes
X * pipe_io[1][0] pipe_io[1][1]
X *
X * The parent process reads the output of the child process by reading
X * pipe_io[1][0] because the child is writing to pipe_io[1][1].
X * The child process gets its input from pipe_io[0][0] because the
X * parent writes to pipe_io[0][1]. Thus, one process is reading from
X * one end of the pipe while the other is writing at the other end.
X */
Xmain(argc, argv)
Xchar *argv[];
X{
X Notify_value read_it(), write_it(), sigchldcatcher();
X int pid, i;
X FILE *fp;
X
X if (!*++argv)
X puts("specify a program [w/args]"), exit(1);
X
X pipe(pipe_io[0]); /* set up input pipe */
X pipe(pipe_io[1]); /* set up output pipe */
X switch (pid = fork()) {
X case -1:
X close(pipe_io[0][0]);
X close(pipe_io[0][1]);
X close(pipe_io[1][0]);
X close(pipe_io[1][1]);
X perror("fork failed");
X exit(1);
X case 0: /* child */
X /* redirect child's stdin (0), stdout (1) and stderr(2) */
X dup2(pipe_io[0][0], 0);
X dup2(pipe_io[1][1], 1);
X dup2(pipe_io[1][1], 2);
X for (i = getdtablesize(); i > 2; i--)
X (void) close(i);
X for (i = 0; i < NSIG; i++)
X (void) signal(i, SIG_DFL);
X execvp(*argv, argv);
X if (errno == ENOENT)
X printf("%s: command not found.\n", *argv);
X else
X perror(*argv);
X perror("execvp");
X _exit(-1);
X default: /* parent */
X close(pipe_io[0][0]); /* close unused portions of pipes */
X close(pipe_io[1][1]);
X }
X
X /* when the process outputs data, read it */
X notify_set_input_func(client1, read_it, pipe_io[1][0]);
X notify_set_wait3_func(client1, sigchldcatcher, pid);
X
X /* wait for user input -- then write data to pipe */
X notify_set_input_func(client2, write_it, 0);
X notify_set_wait3_func(client2, sigchldcatcher, pid);
X
X notify_start();
X}
X
X/*
X * callback routine for when there is data on the parent's stdin to
X * read. Read it and then write the data to the child process via
X * the pipe.
X */
XNotify_value
Xwrite_it(client, fd)
XNotify_client client;
Xint fd;
X{
X char buf[BUFSIZ];
X int bytes, i;
X
X /* only write to pipe (child's stdin) if user typed anything */
X if (ioctl(fd, FIONREAD, &bytes) == -1 || bytes == 0) {
X notify_set_input_func(client, NOTIFY_FUNC_NULL, pipe_io[0][1]);
X close(pipe_io[0][1]);
X } else
X while (bytes > 0) {
X if ((i = read(fd, buf, sizeof buf)) > 0) {
X printf("[Sending %d bytes to pipe (fd=%d)]\n",
X i, pipe_io[0][1]);
X write(pipe_io[0][1], buf, i);
X } else if (i == -1)
X break;
X bytes -= i;
X }
X return NOTIFY_DONE;
X}
X
X/*
X * callback routine for when there is data on the child's stdout to
X * read. Read, then write the data to stdout (owned by the parent).
X */
XNotify_value
Xread_it(client, fd)
XNotify_client client;
Xregister int fd;
X{
X char buf[BUFSIZ];
X int bytes, i;
X
X if (ioctl(fd, FIONREAD, &bytes) == 0)
X while (bytes > 0) {
X if ((i = read(fd, buf, sizeof buf)) > 0) {
X printf("[Reading %d bytes from pipe (fd=%d)]\n",
X i, fd);
X (void) write(1, buf, i);
X bytes -= i;
X }
X }
X return NOTIFY_DONE;
X}
X
X/*
X * handle the death of the child. If the process dies, the child
X * dies and generates a SIGCHLD signal. Capture it and disable the
X * functions that talk to the pipes.
X */
XNotify_value
Xsigchldcatcher(client, pid, status, rusage)
XNotify_client client; /* the client noted in main() */
Xint pid; /* the pid that died */
Xunion wait *status; /* the status of the process (unused here) */
Xstruct rusage *rusage; /* resources used by this process (unused) */
X{
X if (WIFEXITED(*status)) {
X printf("Process termined with status %d\n", status->w_retcode);
X /* unregister input func with appropriate file descriptor */
X notify_set_input_func(client, NOTIFY_FUNC_NULL,
X (client == client1)? pipe_io[1][0] : 0);
X return NOTIFY_DONE;
X }
X puts("SIGCHLD not handled");
X return NOTIFY_IGNORED;
X}
END_OF_FILE
if test 5313 -ne `wc -c <'xview.demos/notifier/ntfy_pipe.c'`; then
echo shar: \"'xview.demos/notifier/ntfy_pipe.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/notifier/ntfy_pipe.c'
fi
if test -f 'xview.demos/panels/choices.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/panels/choices.c'\"
else
echo shar: Extracting \"'xview.demos/panels/choices.c'\" \(3960 characters\)
sed "s/^X//" >'xview.demos/panels/choices.c' <<'END_OF_FILE'
X#include <xview/xview.h>
X#include <xview/panel.h>
X#include <xview/openmenu.h>
X
XPanel panel;
X
X#define gray_width 2
X#define gray_height 2
Xstatic char gray_bits[] = {
X 0x01, 0x02
X};
X#define gray1_width 16
X#define gray1_height 16
Xstatic char gray1_bits[] = {
X 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa,
X 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa,
X 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa
X};
X#define gray3_width 16
X#define gray3_height 16
Xstatic char gray3_bits[] = {
X 0x11, 0x11, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00,
X 0x44, 0x44, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00,
X 0x11, 0x11, 0x00, 0x00, 0x44, 0x44, 0x00, 0x00
X};
X
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Frame frame;
X Menu menu;
X void quit();
X int selected(), numeric_text(), toggle_selected();
X
X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
X
X frame = xv_create(XV_NULL, FRAME,
X XV_WIDTH, 450,
X XV_HEIGHT, 250,
X FRAME_SHOW_FOOTER, TRUE,
X NULL);
X panel = xv_create(frame, PANEL, NULL);
X xv_set(canvas_paint_window(panel), NULL);
X xv_create(panel, PANEL_BUTTON,
X PANEL_LABEL_STRING, "Quit",
X PANEL_NOTIFY_PROC, quit,
X PANEL_CLIENT_DATA, frame,
X NULL);
X
X xv_create(panel, PANEL_CHOICE,
X PANEL_CHOICE_STRINGS, "One", "Two", "Three", "Four", NULL,
X PANEL_NOTIFY_PROC, selected,
X PANEL_CLIENT_DATA, frame,
X NULL);
X xv_create(panel, PANEL_CHOICE,
X PANEL_DISPLAY_LEVEL, PANEL_CURRENT,
X PANEL_LABEL_STRING, "Choices",
X PANEL_CHOICE_STRINGS, "One", "Two", "Three", "Four", NULL,
X PANEL_NOTIFY_PROC, selected,
X PANEL_CLIENT_DATA, frame,
X NULL);
X xv_create(panel, PANEL_CHOICE,
X PANEL_LABEL_STRING, "Choices",
X PANEL_CHOICE_STRINGS, "One", "Two", "Three", "Four", NULL,
X PANEL_NOTIFY_PROC, selected,
X PANEL_CLIENT_DATA, frame,
X NULL);
X xv_create(panel, PANEL_CHOICE,
X PANEL_CHOOSE_ONE, FALSE,
X PANEL_LABEL_STRING, "Choices",
X PANEL_VALUE, 5, /* choices 1 and 3 */
X PANEL_CHOICE_STRINGS, "One", "Two", "Three", "Four", NULL,
X PANEL_NOTIFY_PROC, toggle_selected,
X PANEL_CLIENT_DATA, frame,
X NULL);
X xv_create(panel, PANEL_TOGGLE,
X PANEL_FEEDBACK, PANEL_MARKED,
X PANEL_LABEL_STRING, "Choices",
X PANEL_VALUE, 5, /* choices 1 and 3 */
X PANEL_CHOICE_STRINGS, "One", "Two", "Three", "Four", NULL,
X PANEL_NOTIFY_PROC, toggle_selected,
X PANEL_CLIENT_DATA, frame,
X NULL);
X xv_create(panel, PANEL_NUMERIC_TEXT,
X PANEL_LABEL_STRING, "Numbers:",
X PANEL_VALUE, 5,
X PANEL_NOTIFY_PROC, numeric_text,
X PANEL_CLIENT_DATA, frame,
X NULL);
X xv_main_loop(frame);
X}
X
Xint
Xtoggle_selected(item, value, event)
XPanel_item item;
Xunsigned value;
XEvent *event;
X{
X char buf[32];
X Frame frame = xv_get(item, PANEL_CLIENT_DATA);
X int i;
X buf[0] = 0;
X if (event_id(event) == MS_LEFT) {
X for (i = 0; value; i++, value >>= 1)
X if (value & 1)
X sprintf(buf+strlen(buf), "%s%c ",
X xv_get(item, PANEL_CHOICE_STRING, i),
X (value >> 1)? ',' : ' ');
X xv_set(frame, FRAME_RIGHT_FOOTER, buf, NULL);
X return XV_OK;
X }
X return XV_ERROR;
X}
X
Xint
Xselected(item, value, event)
XPanel_item item;
Xint value;
XEvent *event;
X{
X char buf[32];
X Frame frame = xv_get(item, PANEL_CLIENT_DATA);
X if (event_id(event) == MS_LEFT) {
X sprintf(buf, "\"%s\" selected",
X xv_get(item, PANEL_CHOICE_STRING, panel_get_value(item)));
X xv_set(frame, FRAME_RIGHT_FOOTER, buf, NULL);
X return XV_OK;
X }
X return XV_ERROR;
X}
X
X
Xnumeric_text(item, value, event)
XPanel_item item;
Xint value;
XEvent *event;
X{
X char buf[32];
X Frame frame = xv_get(item, PANEL_CLIENT_DATA);
X
X sprintf(buf, "\"%s\" set to %d",
X xv_get(item, PANEL_LABEL_STRING), value);
X xv_set(frame, FRAME_RIGHT_FOOTER, buf, NULL);
X return PANEL_NEXT;
X}
X
Xvoid
Xquit(item, event)
XPanel_item item;
XEvent *event;
X{
X Frame frame = xv_get(item, PANEL_CLIENT_DATA);
X if (event_id(event) == MS_LEFT)
X xv_destroy_safe(frame);
X}
END_OF_FILE
if test 3960 -ne `wc -c <'xview.demos/panels/choices.c'`; then
echo shar: \"'xview.demos/panels/choices.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/panels/choices.c'
fi
if test -f 'xview.demos/seln_svc/text_seln.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/seln_svc/text_seln.c'\"
else
echo shar: Extracting \"'xview.demos/seln_svc/text_seln.c'\" \(5545 characters\)
sed "s/^X//" >'xview.demos/seln_svc/text_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, also print information about
X * the line number(s) the selection spans and the indexes of
X * the bytes within the textsw's buffer.
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 exit();
X int print_seln();
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 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
Xint
Xprint_seln()
X{
X char *text = get_selection();
X
X if (text)
X printf("---selection---\n%s\n---end seln---\n", text);
X
X return XV_OK;
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 *response;
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 of
X * info about the selection.
X */
X if (seln_holder_same_client(&holder, textsw)) {
X /* ask for information from the selection service */
X response = selection_ask(server, &holder,
X /* get index of the first and last chars in the textsw */
X SELN_REQ_FIRST, NULL,
X SELN_REQ_LAST, NULL,
X /* get the actual selection bytes */
X SELN_REQ_CONTENTS_ASCII, NULL,
X /* Now fool the textsw to think entire lines are selected */
X SELN_REQ_FAKE_LEVEL, SELN_LEVEL_LINE,
X /* Get the line numbers of beginning and ending of the
X * selection */
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 = response->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 response */
X (void) strcpy(selection_buf, ptr);
X /*
X * advance pointer past length of string. If the string length
X * isn't aligned to a 4-byte boundary, add the difference in
X * 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 pointer 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. Count the lines explicitly in the selection.
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 does not lie in our text subwindow */
X response = selection_ask(server, &holder,
X SELN_REQ_CONTENTS_ASCII, NULL,
X NULL);
X if (response->status != SELN_SUCCESS) {
X printf("selection_ask() returns %d\n", response->status);
X return NULL;
X }
X (void) strcpy(selection_buf,
X response->data + sizeof(SELN_REQ_CONTENTS_ASCII));
X }
X return selection_buf;
X}
END_OF_FILE
if test 5545 -ne `wc -c <'xview.demos/seln_svc/text_seln.c'`; then
echo shar: \"'xview.demos/seln_svc/text_seln.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/seln_svc/text_seln.c'
fi
if test -f 'xview.demos/textsw/textsw.font.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xview.demos/textsw/textsw.font.c'\"
else
echo shar: Extracting \"'xview.demos/textsw/textsw.font.c'\" \(5472 characters\)
sed "s/^X//" >'xview.demos/textsw/textsw.font.c' <<'END_OF_FILE'
X/*
X * textsw.font.c --display a text subwindow and allow the user to edit
X * it. Panel items allow the user to change the font (family, style and
X * size) of the textsw.
X */
X#include <xview/xview.h>
X#include <xview/panel.h>
X#include <xview/textsw.h>
X#include <xview/font.h>
X
XPanel_item family_item, style_item, scale_item, name_item;
XTextsw textsw;
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Frame frame;
X Panel panel;
X Xv_Font font;
X void change_font();
X int change_font_by_name();
X extern void exit();
X
X xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
X
X frame = (Frame)xv_create(XV_NULL, FRAME,
X FRAME_LABEL, argv[0],
X FRAME_SHOW_FOOTER, TRUE,
X NULL);
X
X panel = (Panel)xv_create(frame, PANEL,
X PANEL_LAYOUT, PANEL_VERTICAL,
X NULL);
X (void) xv_create(panel, PANEL_BUTTON,
X PANEL_LABEL_STRING, "Quit",
X PANEL_NOTIFY_PROC, exit,
X NULL);
X family_item = (Panel_item)xv_create(panel, PANEL_CHOICE,
X PANEL_LABEL_STRING, "Family",
X PANEL_LAYOUT, PANEL_HORIZONTAL,
X PANEL_DISPLAY_LEVEL, PANEL_CURRENT,
X PANEL_CHOICE_STRINGS,
X FONT_FAMILY_DEFAULT, FONT_FAMILY_DEFAULT_FIXEDWIDTH,
X FONT_FAMILY_LUCIDA, FONT_FAMILY_LUCIDA_FIXEDWIDTH,
X FONT_FAMILY_ROMAN, FONT_FAMILY_SERIF, FONT_FAMILY_COUR,
X FONT_FAMILY_CMR, FONT_FAMILY_GALLENT,
X NULL,
X PANEL_NOTIFY_PROC, change_font,
X NULL);
X style_item = (Panel_item)xv_create(panel, PANEL_CHOICE,
X PANEL_LABEL_STRING, "Style",
X PANEL_LAYOUT, PANEL_HORIZONTAL,
X PANEL_DISPLAY_LEVEL, PANEL_CURRENT,
X PANEL_CHOICE_STRINGS,
X FONT_STYLE_DEFAULT, FONT_STYLE_NORMAL, FONT_STYLE_BOLD,
X FONT_STYLE_ITALIC, FONT_STYLE_BOLD_ITALIC, NULL,
X PANEL_NOTIFY_PROC, change_font,
X NULL);
X scale_item = (Panel_item)xv_create(panel, PANEL_CHOICE,
X PANEL_LABEL_STRING, "Scale",
X PANEL_LAYOUT, PANEL_HORIZONTAL,
X PANEL_DISPLAY_LEVEL, PANEL_CURRENT,
X PANEL_CHOICE_STRINGS,
X "Small", "Medium", "Large", "X-Large", NULL,
X PANEL_NOTIFY_PROC, change_font,
X NULL);
X name_item = (Panel_item)xv_create(panel, PANEL_TEXT,
X PANEL_LABEL_STRING, "Font Name:",
X PANEL_LAYOUT, PANEL_HORIZONTAL,
X PANEL_VALUE_DISPLAY_LENGTH, 20,
X PANEL_NOTIFY_PROC, change_font_by_name,
X NULL);
X window_fit(panel);
X
X textsw = (Textsw)xv_create(frame, TEXTSW,
X WIN_ROWS, 20,
X WIN_COLUMNS, 80,
X NULL);
X
X window_fit(frame);
X
X font = (Xv_Font)xv_get(frame, XV_FONT);
X xv_set(textsw, WIN_FONT, font, NULL);
X xv_set(frame, FRAME_LEFT_FOOTER, xv_get(font, FONT_NAME), NULL);
X
X xv_main_loop(frame);
X}
X
Xvoid
Xchange_font(item, value, event)
XPanel_item item;
XEvent *event;
X{
X static int family, style, scale;
X char buf[128];
X Frame frame;
X char *family_name;
X char *style_name;
X int scale_value;
X Xv_Font font;
X
X frame = (Frame)xv_get(xv_get(item, PANEL_PARENT_PANEL), XV_OWNER);
X family_name = (char *) xv_get(family_item, PANEL_CHOICE_STRING,
X xv_get(family_item, PANEL_VALUE));
X style_name = (char *) xv_get(style_item, PANEL_CHOICE_STRING,
X xv_get(style_item, PANEL_VALUE));
X scale_value = (int) xv_get(scale_item, PANEL_VALUE);
X
X xv_set(frame, FRAME_BUSY, TRUE, NULL);
X font = (Xv_Font)xv_find(frame, FONT,
X FONT_FAMILY, family_name,
X FONT_STYLE, style_name,
X /* scale_value happens to coincide with Window_rescale_state values */
X FONT_SCALE, scale_value,
X NULL);
X xv_set(frame, FRAME_BUSY, FALSE, NULL);
X
X if (!font) {
X if (item == family_item) {
X sprintf(buf, "cannot load '%s'", family_name);
X xv_set(family_item, PANEL_VALUE, family, NULL);
X } else if (item == style_item) {
X sprintf(buf, "cannot load '%s'", style_name);
X xv_set(style_item, PANEL_VALUE, style, NULL);
X } else {
X sprintf(buf, "Not available in %s scale.",
X xv_get(scale_item, PANEL_CHOICE_STRING, scale));
X xv_set(scale_item, PANEL_VALUE, scale, NULL);
X }
X xv_set(frame, FRAME_RIGHT_FOOTER, buf, NULL);
X return;
X }
X if (item == family_item)
X family = value;
X else if (item == style_item)
X style = value;
X else
X scale = value;
X xv_set(textsw, WIN_FONT, font, NULL);
X sprintf(buf, "Current font: %s", xv_get(font, FONT_NAME));
X xv_set(frame, FRAME_LEFT_FOOTER, buf, NULL);
X}
X
Xchange_font_by_name(item, event)
XPanel_item item;
XEvent *event;
X{
X char buf[128];
X char *name = (char *)xv_get(item, PANEL_VALUE);
X Frame frame = (Frame)xv_get(xv_get(item, PANEL_PARENT_PANEL), XV_OWNER);
X Xv_Font font = (Xv_Font)font = (Xv_Font)xv_find(frame, FONT,
X FONT_NAME, name,
X NULL);
X
X if (!font) {
X sprintf(buf, "cannot load '%s'", name);
X xv_set(frame, FRAME_RIGHT_FOOTER, buf, NULL);
X return PANEL_NONE;
X }
X xv_set(textsw, WIN_FONT, font, NULL);
X sprintf(buf, "Current font: %s", xv_get(font, FONT_NAME));
X xv_set(frame, FRAME_LEFT_FOOTER, buf, NULL);
X return PANEL_NONE;
X}
END_OF_FILE
if test 5472 -ne `wc -c <'xview.demos/textsw/textsw.font.c'`; then
echo shar: \"'xview.demos/textsw/textsw.font.c'\" unpacked with wrong size!
fi
# end of 'xview.demos/textsw/textsw.font.c'
fi
echo shar: End of archive 3 \(of 6\).
cp /dev/null ark3isdone
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