home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
x
/
volume14
/
ora.vol6
/
part07
< prev
next >
Wrap
Text File
|
1991-09-18
|
58KB
|
1,777 lines
Path: uunet!cs.utexas.edu!sun-barr!cronkite.Central.Sun.COM!exodus!z-code.com
From: argv@z-code.com (Dan Heller)
Newsgroups: comp.sources.x
Subject: v14i037: Examples from the Motif Programmer's Manual (ORA-Vol. 6), Part07/11
Message-ID: <20151@exodus.Eng.Sun.COM>
Date: 18 Sep 91 22:31:14 GMT
References: <csx-14i031-ora.vol6@uunet.UU.NET>
Sender: news@exodus.Eng.Sun.COM
Lines: 1765
Approved: argv@sun.com
Submitted-by: Dan Heller <argv@z-code.com>
Posting-number: Volume 14, Issue 37
Archive-name: ora.vol6/part07
# 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 7 (of 11)."
# Contents: vol6/ch04/cmd_area.c vol6/ch05/ask_user.c
# vol6/ch06/prompt_dlg.c vol6/ch08/corners.c
# vol6/ch08/dev_ind_draw.c vol6/ch10/drawing.c
# vol6/ch14/color_slide.c vol6/ch15/cut_paste.c vol6/ch15/error.c
# vol6/ch15/phone.c vol6/ch15/select_text.c
# vol6/ch18/copy_retrieve.c vol6/ch18/undo.c vol6/ch20/working.c
# Wrapped by argv@tribbles on Wed Sep 18 15:10:24 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'vol6/ch04/cmd_area.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch04/cmd_area.c'\"
else
echo shar: Extracting \"'vol6/ch04/cmd_area.c'\" \(3792 characters\)
sed "s/^X//" >'vol6/ch04/cmd_area.c' <<'END_OF_FILE'
X/* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
X * This program is freely distributable without licensing fees and
X * is provided without guarantee or warrantee expressed or implied.
X * This program is -not- in the public domain.
X */
X
X/* cmd_area.c -- use a ScrolledText object to view the
X * putput of commands input by the user in a Command window.
X */
X#include <Xm/Text.h>
X#include <Xm/MainW.h>
X#include <Xm/Command.h>
X#include <stdio.h> /* For popen() */
X
X/* main() -- initialize toolkit, create a main window, menubar,
X * a Command Area and a ScrolledText to view the output of commands.
X */
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Widget top, main_w, menubar, menu, command_w, text_w;
X XtAppContext app;
X XmString file, quit;
X extern void exec_cmd(), exit();
X Arg args[4];
X
X /* initialize toolkit and create toplevel shell */
X top = XtVaAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL);
X
X (void) close(0); /* don't let commands read from stdin */
X
X /* MainWindow for the application -- contains menubar, ScrolledText
X * and CommandArea (which prompts for filename).
X */
X main_w = XtVaCreateManagedWidget("main_w",
X xmMainWindowWidgetClass, top,
X NULL);
X
X /* Create a simple MenuBar that contains one menu */
X file = XmStringCreateSimple("File");
X menubar = XmVaCreateSimpleMenuBar(main_w, "menubar",
X XmVaCASCADEBUTTON, file, 'F',
X NULL);
X XmStringFree(file);
X
X /* "File" menu has only one item (Quit), so make callback exit() */
X quit = XmStringCreateSimple("Quit");
X menu = XmVaCreateSimplePulldownMenu(menubar, "file_menu", 0, exit,
X XmVaPUSHBUTTON, quit, 'Q', NULL, NULL,
X NULL);
X XmStringFree(quit);
X
X /* Menubar is done -- manage it */
X XtManageChild(menubar);
X
X /* Create ScrolledText -- this is work area for the MainWindow */
X XtSetArg(args[0], XmNrows, 24);
X XtSetArg(args[1], XmNcolumns, 80);
X XtSetArg(args[2], XmNeditable, False);
X XtSetArg(args[3], XmNeditMode, XmMULTI_LINE_EDIT);
X text_w = XmCreateScrolledText(main_w, "text_w", args, 4);
X XtManageChild(text_w);
X
X /* store text_w as user data in "File" menu for file_cb() callback */
X XtVaSetValues(menu, XmNuserData, text_w, NULL);
X
X /* Create the command area -- this must be a Command class widget */
X file = XmStringCreateSimple("Command:");
X command_w = XtVaCreateWidget("command_w", xmCommandWidgetClass, main_w,
X XmNpromptString, file,
X NULL);
X XmStringFree(file);
X XtAddCallback(command_w, XmNcommandEnteredCallback, exec_cmd, text_w);
X XtManageChild(command_w);
X
X XmMainWindowSetAreas(main_w, menubar, command_w,
X NULL, NULL, XtParent(text_w));
X XtRealizeWidget(top);
X XtAppMainLoop(app);
X}
X
X/* execute the command and redirect output to the ScrolledText window */
Xvoid
Xexec_cmd(cmd_widget, text_w, cbs)
XWidget cmd_widget; /* the command widget itself, not its Text widget */
XWidget text_w; /* passed the text_w as client_data */
XXmCommandCallbackStruct *cbs;
X{
X char *cmd, buf[BUFSIZ];
X XmTextPosition pos;
X FILE *pp;
X
X XmStringGetLtoR(cbs->value, XmSTRING_DEFAULT_CHARSET, &cmd);
X
X if (!cmd || !*cmd) { /* nothing typed? */
X if (cmd)
X XtFree(cmd);
X return;
X }
X
X /* make sure the file is a regular text file and open it */
X if (!(pp = popen(cmd, "r")))
X perror(cmd);
X XtFree(cmd);
X if (!pp)
X return;
X
X /* put the output of the command in the Text widget by reading
X * until EOF (meaning that the command has terminated).
X */
X for (pos = 0; fgets(buf, sizeof buf, pp); pos += strlen(buf))
X XmTextReplace(text_w, pos, pos, buf);
X
X pclose(pp);
X}
END_OF_FILE
if test 3792 -ne `wc -c <'vol6/ch04/cmd_area.c'`; then
echo shar: \"'vol6/ch04/cmd_area.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch04/cmd_area.c'
fi
if test -f 'vol6/ch05/ask_user.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch05/ask_user.c'\"
else
echo shar: Extracting \"'vol6/ch05/ask_user.c'\" \(3577 characters\)
sed "s/^X//" >'vol6/ch05/ask_user.c' <<'END_OF_FILE'
X/* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
X * This program is freely distributable without licensing fees and
X * is provided without guarantee or warrantee expressed or implied.
X * This program is -not- in the public domain.
X */
X
X/*
X * ask_user.c -- create a pushbutton that posts a dialog box
X * that asks the user a question that requires an immediate
X * response. The function that asks the question actually
X * posts the dialog that displays the question, waits for and
X * returns the result.
X */
X#include <X11/Intrinsic.h>
X#include <Xm/DialogS.h>
X#include <Xm/SelectioB.h>
X#include <Xm/RowColumn.h>
X#include <Xm/MessageB.h>
X#include <Xm/PushBG.h>
X#include <Xm/PushB.h>
X
X#define YES 1
X#define NO 2
X
X/* main() --create a pushbutton whose callback pops up a dialog box */
Xmain(argc, argv)
Xchar *argv[];
X{
X Widget parent, button;
X XtAppContext app;
X XmString label;
X void pushed();
X
X toplevel = XtAppInitialize(&app, argv[0], argv[0],
X NULL, 0, &argc, argv, NULL, NULL, 0);
X
X label = XmStringCreateSimple("/bin/rm *");
X button = XtVaCreateManagedWidget("button",
X xmPushButtonWidgetClass, toplevel,
X XmNlabelString, label,
X NULL);
X XtAddCallback(button, XmNactivateCallback,
X pushed, "Remove Everything?");
X XmStringFree(label);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* pushed() --the callback routine for the main app's pushbutton. */
Xvoid
Xpushed(w, question)
XWidget w;
Xchar *question;
X{
X if (AskUser(w, question) == YES)
X puts("Yes");
X else
X puts("No");
X}
X
X/*
X * AskUser() -- a generalized routine that asks the user a question
X * and returns the response.
X */
XAskUser(parent, question)
Xchar *question;
X{
X static Widget dialog;
X XmString text, yes, no;
X int answer = 0;
X extern void response();
X
X if (!dialog) {
X dialog = XmCreateQuestionDialog(parent, "dialog", NULL, 0);
X yes = XmStringCreateSimple("Yes");
X no = XmStringCreateSimple("No");
X XtVaSetValues(dialog,
X XmNdialogStyle, XmDIALOG_SYSTEM_MODAL,
X XmNokLabelString, yes,
X XmNcancelLabelString, no,
X NULL);
X XtSetSensitive(
X XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON), False);
X XtAddCallback(dialog, XmNokCallback, response, &answer);
X XtAddCallback(dialog, XmNcancelCallback, response, &answer);
X }
X text = XmStringCreateSimple(question);
X XtVaSetValues(dialog,
X XmNmessageString, text,
X NULL);
X XmStringFree(text);
X XtManageChild(dialog);
X XtPopup(XtParent(dialog), XtGrabNone);
X
X /* while the user hasn't provided an answer, simulate XtMainLoop.
X * The answer changes as soon as the user selects one of the
X * buttons and the callback routine changes its value. Don't
X * break loop until XtPending() also returns False to assure
X * widget destruction.
X */
X while (answer == 0 || XtPending()) {
X XEvent event;
X XtNextEvent(&event);
X XtDispatchEvent(&event);
X }
X return answer;
X}
X
X/* response() --The user made some sort of response to the
X * question posed in AskUser(). Set the answer (client_data)
X * accordingly and destroy the dialog.
X */
Xvoid
Xresponse(w, answer, reason)
XWidget w;
Xint *answer;
XXmAnyCallbackStruct *reason;
X{
X switch (reason->reason) {
X case XmCR_OK:
X *answer = YES;
X break;
X case XmCR_CANCEL:
X *answer = NO;
X break;
X default:
X return;
X }
X}
END_OF_FILE
if test 3577 -ne `wc -c <'vol6/ch05/ask_user.c'`; then
echo shar: \"'vol6/ch05/ask_user.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch05/ask_user.c'
fi
if test -f 'vol6/ch06/prompt_dlg.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch06/prompt_dlg.c'\"
else
echo shar: Extracting \"'vol6/ch06/prompt_dlg.c'\" \(2855 characters\)
sed "s/^X//" >'vol6/ch06/prompt_dlg.c' <<'END_OF_FILE'
X/* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
X * This program is freely distributable without licensing fees and
X * is provided without guarantee or warrantee expressed or implied.
X * This program is -not- in the public domain.
X */
X
X/* prompt_dlg.c -- prompt the user for a string. Two PushButtons
X * are displayed. When one is selected, a PromptDialog is displayed
X * allowing the user to type a string. When done, the PushButton's
X * label changes to the string.
X */
X#include <Xm/SelectioB.h>
X#include <Xm/RowColumn.h>
X#include <Xm/PushB.h>
X
Xmain(argc, argv)
Xchar *argv[];
X{
X XtAppContext app;
X Widget toplevel, rc, button;
X void pushed();
X
X /* Initialize toolkit and create toplevel shell */
X toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
X &argc, argv, NULL, NULL);
X
X /* RowColumn managed both PushButtons */
X rc = XtVaCreateWidget("rowcol", xmRowColumnWidgetClass, toplevel,
X NULL);
X /* Create two pushbuttons -- both have the same callback */
X button = XtVaCreateManagedWidget("PushMe-1",
X xmPushButtonWidgetClass, rc, NULL);
X XtAddCallback(button, XmNactivateCallback, pushed, NULL);
X button = XtVaCreateManagedWidget("PushMe-2",
X xmPushButtonWidgetClass, rc, NULL);
X XtAddCallback(button, XmNactivateCallback, pushed, NULL);
X
X XtManageChild(rc);
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* pushed() --the callback routine for the main app's pushbuttons.
X * Create a dialog that prompts for a new button name.
X */
Xvoid
Xpushed(pb)
XWidget pb;
X{
X static Widget dialog;
X XmString t = XmStringCreateSimple("Enter New Button Name:");
X extern void read_name();
X Arg args[2];
X
X /* Create the dialog -- the PushButton acts as the DialogShell's
X * parent (not the parent of the PromptDialog).
X */
X XtSetArg(args[0], XmNselectionLabelString, t);
X XtSetArg(args[1], XmNautoUnmanage, False);
X dialog = XmCreatePromptDialog(pb, "prompt", args, 2);
X XmStringFree(t); /* always destroy compound strings when done */
X
X /* When the user types the name, call read_name() ... */
X XtAddCallback(dialog, XmNokCallback, read_name, pb);
X
X /* If the user selects cancel, just destroy the dialog */
X XtAddCallback(dialog, XmNcancelCallback, XtDestroyWidget, NULL);
X
X /* No help is available... */
X XtSetSensitive(
X XmSelectionBoxGetChild(dialog, XmDIALOG_HELP_BUTTON), False);
X XtManageChild(dialog);
X
X XtPopup(XtParent(dialog), XtGrabNone);
X}
X
X/* read_name() --the text field has been filled in. */
Xvoid
Xread_name(w, push_button, cbs)
XWidget w;
XWidget push_button; /* the "client_data" parameter to XtAddCallback */
XXmSelectionBoxCallbackStruct *cbs;
X{
X XtVaSetValues(push_button, XmNlabelString, cbs->value, NULL);
X /* Name's fine -- go ahead and enter it */
X XtDestroyWidget(w);
X}
END_OF_FILE
if test 2855 -ne `wc -c <'vol6/ch06/prompt_dlg.c'`; then
echo shar: \"'vol6/ch06/prompt_dlg.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch06/prompt_dlg.c'
fi
if test -f 'vol6/ch08/corners.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch08/corners.c'\"
else
echo shar: Extracting \"'vol6/ch08/corners.c'\" \(3405 characters\)
sed "s/^X//" >'vol6/ch08/corners.c' <<'END_OF_FILE'
X/* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
X * This program is freely distributable without licensing fees and
X * is provided without guarantee or warrantee expressed or implied.
X * This program is -not- in the public domain.
X */
X
X/* corners.c -- demonstrate widget layout management for a
X * BulletinBoard widget. There are four widgets each labeled
X * top-left, top-right, bottom-left and bottom-right. Their
X * positions in the bulletin board correspond to their names.
X * Only when the widget is resized does the geometry management
X * kick in and position the children in their correct locations.
X */
X#include <Xm/BulletinB.h>
X#include <Xm/PushBG.h>
X
Xchar *corners[] = {
X "Top-Left", "Top-Right", "Bottom-Left", "Bottom-Right",
X};
X
Xstatic void resize();
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Widget toplevel, bboard;
X XtAppContext app;
X XtActionsRec rec;
X int i;
X
X /* Initialize toolkit and create toplevel shell */
X toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
X &argc, argv, NULL, NULL);
X
X /* Create your standard BulletinBoard widget */
X bboard = XtVaCreateManagedWidget("bboard",
X xmBulletinBoardWidgetClass, toplevel, NULL);
X
X /* Set up a translation table that captures "Resize" events
X * (also called ConfigureNotify or Configure events). If the
X * event is generated, call the function resize().
X */
X rec.string = "resize";
X rec.proc = resize;
X XtAppAddActions(app, &rec, 1);
X XtOverrideTranslations(bboard,
X XtParseTranslationTable("<Configure>: resize()"));
X
X /* Create children of the dialog -- a PushButton in each corner. */
X for (i = 0; i < XtNumber(corners); i++)
X XtVaCreateManagedWidget(corners[i],
X xmPushButtonGadgetClass, bboard, NULL);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* resize(), the routine that is automatically called by Xt upon the
X * delivery of a Configure event. This happens whenever the widget
X * gets resized.
X */
Xstatic void
Xresize(w, event, args, num_args)
XCompositeWidget w; /* The widget (BulletinBoard) that got resized */
XXConfigureEvent *event; /* The event struct associated with the event */
XString args[]; /* unused */
Xint *num_args; /* unused */
X{
X WidgetList children;
X int width = event->width;
X int height = event->height;
X Dimension w_width, w_height;
X short margin_w, margin_h;
X
X /* get handle to BulletinBoard's children and marginal spacing */
X XtVaGetValues(w,
X XmNchildren, &children,
X XmNmarginWidth, &margin_w,
X XmNmarginHeight, &margin_h,
X NULL);
X
X /* place the top left widget */
X XtVaSetValues(children[0],
X XmNx, margin_w,
X XmNy, margin_h,
X NULL);
X /* top right */
X XtVaGetValues(children[1], XmNwidth, &w_width, NULL);
X XtVaSetValues(children[1],
X XmNx, width - margin_w - w_width,
X XmNy, margin_h,
X NULL);
X /* bottom left */
X XtVaGetValues(children[2], XmNheight, &w_height, NULL);
X XtVaSetValues(children[2],
X XmNx, margin_w,
X XmNy, height - margin_h - w_height,
X NULL);
X /* bottom right */
X XtVaGetValues(children[3],
X XmNheight, &w_height,
X XmNwidth, &w_width,
X NULL);
X XtVaSetValues(children[3],
X XmNx, width - margin_w - w_width,
X XmNy, height - margin_h - w_height,
X NULL);
X}
END_OF_FILE
if test 3405 -ne `wc -c <'vol6/ch08/corners.c'`; then
echo shar: \"'vol6/ch08/corners.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch08/corners.c'
fi
if test -f 'vol6/ch08/dev_ind_draw.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch08/dev_ind_draw.c'\"
else
echo shar: Extracting \"'vol6/ch08/dev_ind_draw.c'\" \(3297 characters\)
sed "s/^X//" >'vol6/ch08/dev_ind_draw.c' <<'END_OF_FILE'
X/* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
X * This program is freely distributable without licensing fees and
X * is provided without guarantee or warrantee expressed or implied.
X * This program is -not- in the public domain.
X */
X
X/* drawing.c -- extremely simple drawing program that introduces
X * the DrawingArea widget. This widget provides a window for
X * drawing and some callbacks for getting input and other misc
X * events (resize and expose). It's also a manager, so it can
X * have children. There is no geometry management, tho.
X */
X#include <Xm/DrawingA.h>
X#include <Xm/RowColumn.h>
X
XDisplay *dpy;
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Widget toplevel, drawing_a;
X XtAppContext app;
X XGCValues gcv;
X GC gc;
X void drawing_area_callback();
X
X /* Initialize toolkit and create 500x500 top level shell */
X toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
X &argc, argv, NULL, NULL);
X
X /* avoiding having to use a macro everywhere else... */
X dpy = XtDisplay(toplevel);
X
X /* Create a DrawingArea widget. */
X drawing_a = XtVaCreateWidget("drawing_a",
X xmDrawingAreaWidgetClass, toplevel,
X XmNunitType, Xm1000TH_INCHES,
X XmNheight, 2000, /* 2 inches? */
X XmNwidth, 5000, /* 5 inches? */
X NULL);
X
X /* add callback to trap input events */
X XtAddCallback(drawing_a, XmNinputCallback,
X drawing_area_callback, NULL);
X /* add callback to trap resizing */
X XtAddCallback(drawing_a, XmNresizeCallback,
X drawing_area_callback, NULL);
X
X /* Create a GC for drawing (in callback). Attach to
X * DrawingArea's XmNuserData to avoid having to make global.
X */
X gcv.foreground = BlackPixelOfScreen(XtScreen(drawing_a));
X gcv.background = WhitePixelOfScreen(XtScreen(drawing_a));
X gc = XCreateGC(dpy, RootWindowOfScreen(XtScreen(drawing_a)),
X GCForeground|GCBackground, &gcv);
X XtVaSetValues(drawing_a, XmNuserData, gc, NULL);
X
X XtManageChild(drawing_a);
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* Callback routine for DrawingArea's input and resize callbacks.
X * This is also used as the PushButton's callback. Determine which
X * activated us by testing the cbs->reason field.
X */
Xvoid
Xdrawing_area_callback(widget, data, cbs)
XWidget widget;
XXtPointer data;
XXmDrawingAreaCallbackStruct *cbs;
X{
X static Position x, y;
X XEvent *event = cbs->event;
X
X if (cbs->reason == XmCR_INPUT) {
X /* activated by DrawingArea input event */
X if (event->xany.type == ButtonPress) {
X /* anchor initial point */
X x = event->xbutton.x;
X y = event->xbutton.y;
X } else if (event->xany.type == ButtonRelease) {
X /* draw full line; get GC and use in XDrawLine() */
X GC gc;
X XtVaGetValues(widget, XmNuserData, &gc, NULL);
X XDrawLine(dpy, cbs->window, gc, x, y,
X event->xbutton.x, event->xbutton.y);
X x = event->xbutton.x;
X y = event->xbutton.y;
X }
X }
X
X if (cbs->reason == XmCR_RESIZE && cbs->window)
X XClearWindow(dpy, cbs->window);
X
X if (cbs->reason == XmCR_ACTIVATE)
X /* activated by pushbutton -- clear parent's window */
X XClearWindow(dpy, XtWindow(XtParent(widget)));
X}
END_OF_FILE
if test 3297 -ne `wc -c <'vol6/ch08/dev_ind_draw.c'`; then
echo shar: \"'vol6/ch08/dev_ind_draw.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch08/dev_ind_draw.c'
fi
if test -f 'vol6/ch10/drawing.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch10/drawing.c'\"
else
echo shar: Extracting \"'vol6/ch10/drawing.c'\" \(3464 characters\)
sed "s/^X//" >'vol6/ch10/drawing.c' <<'END_OF_FILE'
X/* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
X * This program is freely distributable without licensing fees and
X * is provided without guarantee or warrantee expressed or implied.
X * This program is -not- in the public domain.
X */
X
X/* drawing.c -- extremely simple drawing program that introduces
X * the DrawingArea widget. This widget provides a window for
X * drawing and some callbacks for getting input and other misc
X * events. It's also a manager, so it can have children.
X * There is no geometry management, tho.
X */
X#include <Xm/DrawingA.h>
X#include <Xm/PushBG.h>
X#include <Xm/RowColumn.h>
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Widget toplevel, drawing_a, pb;
X XtAppContext app;
X XGCValues gcv;
X GC gc;
X void drawing_area_callback();
X
X toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
X &argc, argv, NULL,
X XmNwidth, 400,
X XmNheight, 300,
X NULL);
X
X /* Create a DrawingArea widget. */
X drawing_a = XtVaCreateWidget("drawing_a",
X xmDrawingAreaWidgetClass, toplevel,
X NULL);
X /* add callback for all mouse and keyboard input events */
X XtAddCallback(drawing_a, XmNinputCallback, drawing_area_callback, NULL);
X
X /* Since we're going to be drawing, we will be using Xlib routines
X * and therefore need a graphics context. Create a GC and attach
X * to the DrawingArea's XmNuserData to avoid having to make global
X * variable. (Avoiding globals is a good design principle to follow.)
X */
X gcv.foreground = BlackPixelOfScreen(XtScreen(drawing_a));
X gc = XCreateGC(XtDisplay(drawing_a),
X RootWindowOfScreen(XtScreen(drawing_a)), GCForeground, &gcv);
X XtVaSetValues(drawing_a, XmNuserData, gc, NULL);
X
X /* add a pushbutton the user can use to clear the canvas */
X pb = XtVaCreateManagedWidget("Clear",
X xmPushButtonGadgetClass, drawing_a,
X NULL);
X /* if activated, call same callback as XmNinputCallback. */
X XtAddCallback(pb, XmNactivateCallback, drawing_area_callback, NULL);
X
X XtManageChild(drawing_a);
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* Callback routine for DrawingArea's input callbacks and the
X * PushButton's activate callback. Determine which it is by
X * testing the cbs->reason field.
X */
Xvoid
Xdrawing_area_callback(widget, data, cbs)
XWidget widget;
XXtPointer data;
XXmDrawingAreaCallbackStruct *cbs;
X{
X static Position x, y;
X XEvent *event = cbs->event;
X
X if (cbs->reason == XmCR_INPUT) {
X /* activated by DrawingArea input event -- draw lines.
X * Button Down events anchor the initial point and Button
X * Up draws from the anchor point to the button-up point.
X */
X if (event->xany.type == ButtonPress) {
X /* anchor initial point (i.e., save its value) */
X x = event->xbutton.x;
X y = event->xbutton.y;
X } else if (event->xany.type == ButtonRelease) {
X /* draw full line; get GC and use in XDrawLine() */
X GC gc;
X XtVaGetValues(widget, XmNuserData, &gc, NULL);
X XDrawLine(event->xany.display, cbs->window, gc, x, y,
X event->xbutton.x, event->xbutton.y);
X x = event->xbutton.x;
X y = event->xbutton.y;
X }
X }
X
X if (cbs->reason == XmCR_ACTIVATE)
X /* activated by pushbutton -- clear parent's window */
X XClearWindow(event->xany.display, XtWindow(XtParent(widget)));
X}
END_OF_FILE
if test 3464 -ne `wc -c <'vol6/ch10/drawing.c'`; then
echo shar: \"'vol6/ch10/drawing.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch10/drawing.c'
fi
if test -f 'vol6/ch14/color_slide.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch14/color_slide.c'\"
else
echo shar: Extracting \"'vol6/ch14/color_slide.c'\" \(3689 characters\)
sed "s/^X//" >'vol6/ch14/color_slide.c' <<'END_OF_FILE'
X/* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
X * This program is freely distributable without licensing fees and
X * is provided without guarantee or warrantee expressed or implied.
X * This program is -not- in the public domain.
X */
X
X/* color_slide.c -- Use scale widgets to display the different
X * colors of a colormap.
X */
X#include <Xm/LabelG.h>
X#include <Xm/Scale.h>
X#include <Xm/RowColumn.h>
X#include <Xm/DrawingA.h>
X
XWidget colorwindow; /* the window the siplays a solid color */
XXColor color; /* the color in the colorwindow */
X
Xmain(argc, argv)
Xchar *argv[];
X{
X Widget toplevel, rowcol, scale;
X XtAppContext app;
X Pixel background;
X void new_value();
X XtVarArgsList arglist;
X
X toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
X &argc, argv, NULL, NULL);
X
X if (DefaultDepthOfScreen(XtScreen(toplevel)) < 2) {
X puts("You must be using a color screen.");
X exit(1);
X }
X
X color.flags = DoRed|DoGreen|DoBlue;
X /* initialize first color */
X XAllocColor(XtDisplay(toplevel),
X DefaultColormapOfScreen(XtScreen(toplevel)), &color);
X
X rowcol = XtVaCreateManagedWidget("rowcol",
X xmRowColumnWidgetClass, toplevel, NULL);
X
X colorwindow = XtVaCreateManagedWidget("colorwindow",
X widgetClass, rowcol,
X XmNheight, 100,
X XmNbackground, color.pixel,
X NULL);
X
X /* use rowcol again to create another RowColumn under the 1st */
X rowcol = XtVaCreateWidget("rowcol", xmRowColumnWidgetClass, rowcol,
X XmNorientation, XmHORIZONTAL,
X NULL);
X
X arglist = XtVaCreateArgsList(NULL,
X XmNshowValue, True,
X XmNmaximum, 255,
X XmNscaleMultiple, 5,
X NULL);
X
X scale = XtVaCreateManagedWidget("Red",
X xmScaleWidgetClass, rowcol,
X XtVaNestedList, arglist,
X XtVaTypedArg, XmNtitleString, XmRString, "Red", 4,
X XtVaTypedArg, XmNforeground, XmRString, "Red", 4,
X NULL);
X XtAddCallback(scale, XmNdragCallback, new_value, DoRed);
X XtAddCallback(scale, XmNvalueChangedCallback, new_value, DoRed);
X
X scale = XtVaCreateManagedWidget("Green",
X xmScaleWidgetClass, rowcol,
X XtVaNestedList, arglist,
X XtVaTypedArg, XmNtitleString, XmRString, "Green", 6,
X XtVaTypedArg, XmNforeground, XmRString, "Green", 6,
X NULL);
X XtAddCallback(scale, XmNdragCallback, new_value, DoGreen);
X XtAddCallback(scale, XmNvalueChangedCallback, new_value, DoGreen);
X
X scale = XtVaCreateManagedWidget("Blue",
X xmScaleWidgetClass, rowcol,
X XtVaNestedList, arglist,
X XtVaTypedArg, XmNtitleString, XmRString, "Blue", 5,
X XtVaTypedArg, XmNforeground, XmRString, "Blue", 5,
X NULL);
X XtAddCallback(scale, XmNdragCallback, new_value, DoBlue);
X XtAddCallback(scale, XmNvalueChangedCallback, new_value, DoBlue);
X
X XtFree(arglist);
X
X XtManageChild(rowcol);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
Xvoid
Xnew_value(scale_w, rgb, cbs)
XWidget scale_w;
Xint rgb;
XXmScaleCallbackStruct *cbs;
X{
X Colormap cmap = DefaultColormapOfScreen(XtScreen(scale_w));
X
X switch (rgb) {
X case DoRed :
X color.red = (cbs->value << 8);
X break;
X case DoGreen :
X color.green = (cbs->value << 8);
X break;
X case DoBlue :
X color.blue = (cbs->value << 8);
X }
X
X /* reuse the same color again and again */
X XFreeColors(XtDisplay(scale_w), cmap, &color.pixel, 1, 0);
X if (!XAllocColor(XtDisplay(scale_w), cmap, &color))
X puts("Couldn't XallocColor!"), exit(1);
X XtVaSetValues(colorwindow, XmNbackground, color.pixel, NULL);
X}
END_OF_FILE
if test 3689 -ne `wc -c <'vol6/ch14/color_slide.c'`; then
echo shar: \"'vol6/ch14/color_slide.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch14/color_slide.c'
fi
if test -f 'vol6/ch15/cut_paste.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch15/cut_paste.c'\"
else
echo shar: Extracting \"'vol6/ch15/cut_paste.c'\" \(3658 characters\)
sed "s/^X//" >'vol6/ch15/cut_paste.c' <<'END_OF_FILE'
X/* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
X * This program is freely distributable without licensing fees and
X * is provided without guarantee or warrantee expressed or implied.
X * This program is -not- in the public domain.
X */
X
X/* cut_paste.c -- demonstrate the XmText* functions that handle
X * clipboard operations. These functions are convenience routines
X * that relieve the programmer of the need to use clipboard functions.
X * The functionality of these routines already exists in the Text
X * widget, yet it is common to place such features in the interface
X * via the MenuBar's "Edit" pulldown menu.
X */
X#include <Xm/Text.h>
X#include <Xm/LabelG.h>
X#include <Xm/PushBG.h>
X#include <Xm/RowColumn.h>
X#include <Xm/MainW.h>
X
XWidget text_w, text_output;
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Widget toplevel, main_w, menubar, rowcol_v, rowcol_h, pb;
X XtAppContext app;
X int i;
X void cut_paste();
X XmString label, cut, clear, copy, paste;
X Arg args[5];
X
X toplevel = XtVaAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL);
X
X main_w = XtVaCreateWidget("main_w",
X xmMainWindowWidgetClass, toplevel, NULL);
X
X /* Create a simple MenuBar that contains a single menu */
X label = XmStringCreateSimple("Edit");
X menubar = XmVaCreateSimpleMenuBar(main_w, "main_w",
X XmVaCASCADEBUTTON, label, 'E',
X NULL);
X XmStringFree(label);
X
X cut = XmStringCreateSimple("Cut"); /* create a simple */
X copy = XmStringCreateSimple("Copy"); /* pulldown menu that */
X clear = XmStringCreateSimple("Clear"); /* has these menu */
X paste = XmStringCreateSimple("Paste"); /* items in it. */
X XmVaCreateSimplePulldownMenu(menubar, "edit_menu", 0, cut_paste,
X XmVaPUSHBUTTON, cut, 'C', NULL, NULL,
X XmVaPUSHBUTTON, copy, 'o', NULL, NULL,
X XmVaPUSHBUTTON, paste, 'P', NULL, NULL,
X XmVaSEPARATOR,
X XmVaPUSHBUTTON, clear, 'l', NULL, NULL,
X NULL);
X XmStringFree(cut);
X XmStringFree(clear);
X XmStringFree(copy);
X XmStringFree(paste);
X
X XtManageChild(menubar);
X
X /* create a standard vertical RowColumn... */
X rowcol_v = XtVaCreateWidget("rowcol_v",
X xmRowColumnWidgetClass, main_w, NULL);
X
X text_output = XtVaCreateManagedWidget("text_out",
X xmTextWidgetClass, rowcol_v,
X XmNeditable, False,
X XmNcursorPositionVisible, False,
X XmNshadowThickness, 0,
X XmNsensitive, False,
X NULL);
X
X XtSetArg(args[0], XmNrows, 10);
X XtSetArg(args[1], XmNcolumns, 80);
X XtSetArg(args[2], XmNeditMode, XmMULTI_LINE_EDIT);
X XtSetArg(args[3], XmNscrollHorizontal, False);
X XtSetArg(args[4], XmNwordWrap, True);
X text_w = XmCreateScrolledText(rowcol_v, "text_w", args, 5);
X XtManageChild(text_w);
X
X XtManageChild(rowcol_v);
X XtManageChild(main_w);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* the callback routine for the items in the edit menu */
Xvoid
Xcut_paste(widget, num)
XWidget widget; /* the menu item (pushbutton) that was selected */
Xint num; /* the menu item number */
X{
X Boolean result = True;
X
X switch (num) {
X case 0 : result = XmTextCut(text_w, CurrentTime); break;
X case 1 : result = XmTextCopy(text_w, CurrentTime); break;
X case 2 : result = XmTextPaste(text_w);
X case 3 : XmTextClearSelection(text_w, CurrentTime); break;
X }
X if (result == False)
X XmTextSetString(text_output, "There is no selection.");
X else
X XmTextSetString(text_output, NULL);
X}
END_OF_FILE
if test 3658 -ne `wc -c <'vol6/ch15/cut_paste.c'`; then
echo shar: \"'vol6/ch15/cut_paste.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch15/cut_paste.c'
fi
if test -f 'vol6/ch15/error.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch15/error.c'\"
else
echo shar: Extracting \"'vol6/ch15/error.c'\" \(3488 characters\)
sed "s/^X//" >'vol6/ch15/error.c' <<'END_OF_FILE'
X/* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
X * This program is freely distributable without licensing fees and
X * is provided without guarantee or warrantee expressed or implied.
X * This program is -not- in the public domain.
X */
X
X#include <stdio.h>
X#include <Xm/Text.h>
X#include <Xm/PushBG.h>
X#include <Xm/RowColumn.h>
X#include <varargs.h>
X
Xvoid wprint();
XWidget text_w;
X
Xstatic void
Xx_error(dpy, err_event)
XDisplay *dpy;
XXErrorEvent *err_event;
X{
X char buf[BUFSIZ];
X
X XGetErrorText(dpy, err_event->error_code, buf, sizeof buf);
X
X wprint("X Error: <%s>\n", buf);
X}
X
Xstatic void
Xxt_error(message)
Xchar *message;
X{
X wprint("Xt Error: %s\n", message);
X}
X
Xstatic void
Xmake_x_error(w, which)
XWidget w;
Xint which;
X{
X switch (which) {
X case 0 : XLookupColor(XtDisplay(text_w), NULL, "", NULL); break;
X case 2 : XtError("This is an XtError call!"); break;
X case 3 : XtWarning("This is an XtWarning call."); break;
X }
X}
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X XtAppContext app;
X Widget toplevel, rowcol1, rowcol2, pb;
X Arg args[7];
X
X toplevel = XtVaAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL);
X
X rowcol1 = XtVaCreateWidget("rowcol1", xmRowColumnWidgetClass, toplevel,
X NULL);
X rowcol2 = XtVaCreateWidget("rowcol2", xmRowColumnWidgetClass, rowcol1,
X XmNorientation, XmHORIZONTAL,
X NULL);
X pb = XtVaCreateManagedWidget("XLib Error",
X xmPushButtonGadgetClass, rowcol2,
X NULL);
X XtAddCallback(pb, XmNactivateCallback, make_x_error, 0);
X pb = XtVaCreateManagedWidget("Xt Error",
X xmPushButtonGadgetClass, rowcol2,
X NULL);
X XtAddCallback(pb, XmNactivateCallback, make_x_error, 2);
X pb = XtVaCreateManagedWidget("Xt Warning",
X xmPushButtonGadgetClass, rowcol2,
X NULL);
X XtAddCallback(pb, XmNactivateCallback, make_x_error, 3);
X
X /* Create text_w as a ScrolledText window */
X XtSetArg(args[0], XmNrows, 6);
X XtSetArg(args[1], XmNcolumns, 80);
X XtSetArg(args[2], XmNeditable, False);
X XtSetArg(args[3], XmNeditMode, XmMULTI_LINE_EDIT);
X XtSetArg(args[4], XmNwordWrap, True);
X XtSetArg(args[5], XmNscrollHorizontal, False);
X XtSetArg(args[6], XmNcursorPositionVisible, False);
X text_w = XmCreateScrolledText(rowcol1, "text_w", args, 7);
X XtManageChild(text_w);
X
X /* catch Xt errors */
X XtAppSetErrorHandler(app, xt_error);
X XtAppSetWarningHandler(app, xt_error);
X /* and Xlib errors */
X XSetErrorHandler(x_error);
X
X XtManageChild(rowcol1);
X XtManageChild(rowcol2);
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/*VARARGS*/
Xvoid
Xwprint(va_alist)
Xva_dcl
X{
X char msgbuf[BUFSIZ]; /* we're not getting huge strings */
X char *fmt;
X static XmTextPosition wpr_position; /* maintain text position */
X va_list args;
X
X va_start(args);
X fmt = va_arg(args, char *);
X#ifndef NO_VPRINTF
X (void) vsprintf(msgbuf, fmt, args);
X#else /* !NO_VPRINTF */
X {
X FILE foo;
X foo._cnt = BUFSIZ;
X foo._base = foo._ptr = msgbuf; /* (unsigned char *) ?? */
X foo._flag = _IOWRT+_IOSTRG;
X (void) _doprnt(fmt, args, &foo);
X *foo._ptr = '\0'; /* plant terminating null character */
X }
X#endif /* NO_VPRINTF */
X va_end(args);
X
X XmTextInsert(text_w, wpr_position, msgbuf);
X wpr_position += strlen(msgbuf);
X XtVaSetValues(text_w, XmNcursorPosition, wpr_position, NULL);
X XmTextShowPosition(text_w, wpr_position);
X}
END_OF_FILE
if test 3488 -ne `wc -c <'vol6/ch15/error.c'`; then
echo shar: \"'vol6/ch15/error.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch15/error.c'
fi
if test -f 'vol6/ch15/phone.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch15/phone.c'\"
else
echo shar: Extracting \"'vol6/ch15/phone.c'\" \(3274 characters\)
sed "s/^X//" >'vol6/ch15/phone.c' <<'END_OF_FILE'
X/* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
X * This program is freely distributable without licensing fees and
X * is provided without guarantee or warrantee expressed or implied.
X * This program is -not- in the public domain.
X */
X
X/* prompt_phone.c -- a complex problem for XmNmodifyVerifyCallback.
X * prompt for a phone number by filtering digits only from input.
X * Don't allow paste operations and handle backspacing.
X */
X#include <Xm/Text.h>
X#include <Xm/LabelG.h>
X#include <Xm/RowColumn.h>
X#include <ctype.h>
X#include <stdio.h>
X
Xvoid check_phone();
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Widget toplevel, text_w, rowcol;
X XtAppContext app;
X
X toplevel = XtVaAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL);
X
X rowcol = XtVaCreateWidget("rowcol",
X xmRowColumnWidgetClass, toplevel,
X XmNorientation, XmHORIZONTAL,
X NULL);
X
X XtVaCreateManagedWidget("Phone Number:",
X xmLabelGadgetClass, rowcol, NULL);
X text_w = XtVaCreateManagedWidget("text_w",
X xmTextWidgetClass, rowcol, NULL);
X
X XtAddCallback(text_w, XmNmodifyVerifyCallback, check_phone, NULL);
X XtAddCallback(text_w, XmNmotionVerifyCallback, check_phone, NULL);
X XtAddCallback(text_w, XmNvalueChangedCallback, check_phone, NULL);
X
X XtManageChild(rowcol);
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
Xvoid
Xcheck_phone(text_w, unused, cbs)
XWidget text_w;
XXtPointer unused;
XXmTextVerifyCallbackStruct *cbs;
X{
X char c;
X int len = XmTextGetLastPosition(text_w);
X
X if (cbs->reason == XmCR_MOVING_INSERT_CURSOR) {
X /* we'll get a motion-notify if the user clicks somewhere with the
X * intent of changing the insertion point, or we'll get one if the
X * program actually sets the cursor position like we do below.
X * If we reset the cursor manually (like below) "event" is NULL,
X * and we allow it -- however, if the user "clicks" to move the
X * insertion cursor, we cannot allow it. We would -normally-
X * test for that by testing cbs->event != NULL (like we do here),
X * but it currently won't work because of a bug with Motif where
X * it sets the event field to NULL anyway!!
X */
X if (cbs->newInsert != len && cbs->event)
X cbs->doit = False;
X return;
X }
X
X if (cbs->reason == XmCR_VALUE_CHANGED) {
X XmTextSetInsertionPosition(text_w, len);
X return;
X }
X
X /* no backspacing, typing or stuffing in middle of string */
X if (cbs->currInsert < len) {
X cbs->doit = False;
X return;
X }
X
X if (cbs->text->ptr == NULL) { /* backspace */
X if (cbs->startPos == 3 || cbs->startPos == 7)
X cbs->startPos--; /* delete the hyphen too */
X return;
X }
X
X if (cbs->text->length > 1) { /* don't allow clipboard copies */
X cbs->doit = False;
X return;
X }
X
X /* don't allow non-digits or let the input exceed 12 chars */
X if (!isdigit(c = cbs->text->ptr[0]) || len >= 12)
X cbs->doit = False;
X else if (len == 2 || len == 6) {
X cbs->text->ptr = XtRealloc(cbs->text->ptr, 2);
X cbs->text->length = 2;
X cbs->text->ptr[0] = c;
X cbs->text->ptr[1] = '-';
X }
X}
END_OF_FILE
if test 3274 -ne `wc -c <'vol6/ch15/phone.c'`; then
echo shar: \"'vol6/ch15/phone.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch15/phone.c'
fi
if test -f 'vol6/ch15/select_text.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch15/select_text.c'\"
else
echo shar: Extracting \"'vol6/ch15/select_text.c'\" \(3518 characters\)
sed "s/^X//" >'vol6/ch15/select_text.c' <<'END_OF_FILE'
X/* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
X * This program is freely distributable without licensing fees and
X * is provided without guarantee or warrantee expressed or implied.
X * This program is -not- in the public domain.
X */
X
X/* select_text.c -- demonstrate how to position a cursor at a
X * particular location. The position is determined by a search_pat-
X * match search.
X */
X#include <Xm/Text.h>
X#include <Xm/LabelG.h>
X#include <Xm/RowColumn.h>
X#include <X11/Xos.h> /* for the index() function */
X
XWidget text_w, search_w, text_output;
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Widget toplevel, rowcol_v, rowcol_h;
X XtAppContext app;
X int i;
X void search_text();
X Arg args[5];
X
X toplevel = XtVaAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL);
X
X rowcol_v = XtVaCreateWidget("rowcol_v",
X xmRowColumnWidgetClass, toplevel, NULL);
X
X rowcol_h = XtVaCreateWidget("rowcol_h",
X xmRowColumnWidgetClass, rowcol_v,
X XmNorientation, XmHORIZONTAL,
X NULL);
X XtVaCreateManagedWidget("Search Pattern:",
X xmLabelGadgetClass, rowcol_h, NULL);
X search_w = XtVaCreateManagedWidget("search_text",
X xmTextWidgetClass, rowcol_h, NULL);
X XtManageChild(rowcol_h);
X
X text_output = XtVaCreateManagedWidget("text_out",
X xmTextWidgetClass, rowcol_v,
X XmNeditable, False,
X XmNcursorPositionVisible, False,
X XmNshadowThickness, 0,
X XmNsensitive, False,
X NULL);
X
X XtSetArg(args[0], XmNrows, 10);
X XtSetArg(args[1], XmNcolumns, 80);
X XtSetArg(args[2], XmNeditMode, XmMULTI_LINE_EDIT);
X XtSetArg(args[3], XmNscrollHorizontal, False);
X XtSetArg(args[4], XmNwordWrap, True);
X text_w = XmCreateScrolledText(rowcol_v, "text_w", args, 5);
X XtManageChild(text_w);
X
X XtAddCallback(search_w, XmNactivateCallback, search_text, NULL);
X
X XtManageChild(rowcol_v);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
Xvoid
Xsearch_text()
X{
X char *search_pat, *p, *string, buf[32];
X XmTextPosition pos;
X int len;
X Boolean found = False;
X
X string = XmTextGetString(text_w);
X if (!*string) {
X XmTextSetString(text_output, "No text to search.");
X XtFree(string);
X return;
X }
X
X search_pat = XmTextGetString(search_w);
X if (!*search_pat) {
X XmTextSetString(text_output, "Specify a search pattern.");
X XtFree(string);
X XtFree(search_pat);
X return;
X }
X len = strlen(search_pat);
X /* start searching at current cursor position + 1 */
X pos = XmTextGetCursorPosition(text_w);
X for (p = &string[pos+1]; p = index(p, *search_pat); p++)
X if (!strncmp(p, search_pat, len)) {
X found = True;
X break;
X }
X if (!found) { /* didn't find pattern? */
X /* search from beginning till we've passed "pos" */
X for (p = string; p = index(p, *search_pat); p++)
X if (p - string > pos || !strncmp(p, search_pat, len)) {
X found = True;
X break;
X }
X }
X if (!found)
X XmTextSetString(text_output, "Pattern not found.");
X else {
X pos = (XmTextPosition)(p - string);
X sprintf(buf, "Pattern found at position %ld.", pos);
X XmTextSetString(text_output, buf);
X XmTextSetInsertionPosition(text_w, pos);
X XmTextSetHighlight(text_w, pos, pos + len, XmHIGHLIGHT_SELECTED);
X }
X}
END_OF_FILE
if test 3518 -ne `wc -c <'vol6/ch15/select_text.c'`; then
echo shar: \"'vol6/ch15/select_text.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch15/select_text.c'
fi
if test -f 'vol6/ch18/copy_retrieve.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch18/copy_retrieve.c'\"
else
echo shar: Extracting \"'vol6/ch18/copy_retrieve.c'\" \(3416 characters\)
sed "s/^X//" >'vol6/ch18/copy_retrieve.c' <<'END_OF_FILE'
X/* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
X * This program is freely distributable without licensing fees and
X * is provided without guarantee or warrantee expressed or implied.
X * This program is -not- in the public domain.
X */
X
X/* copy_retrieve.c -- simple copy and retrieve program. Two
X * pushbuttons: the first places text in the clipboard, the other
X * receives text from the clipboard. This just demonstrates the
X * API involved.
X */
X#include <Xm/CutPaste.h>
X#include <Xm/RowColumn.h>
X#include <Xm/PushBG.h>
X
Xstatic void to_clipbd(), from_clipbd();
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Widget toplevel, rowcol, button;
X XtAppContext app;
X
X /* Initialize toolkit, application context and toplevel shell */
X toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
X &argc, argv, NULL, NULL);
X
X /* manage two buttons in a RowColumn widget */
X rowcol = XtVaCreateWidget("rowcol", xmRowColumnWidgetClass, toplevel, NULL);
X
X /* button1 copies to the clipboard */
X button = XtVaCreateManagedWidget("button1",
X xmPushButtonGadgetClass, rowcol,
X XtVaTypedArg, XmNlabelString, XmRString,
X "Copy To Clipboard", 18, /* strlen() + 1 */
X NULL);
X XtAddCallback(button, XmNactivateCallback, to_clipbd, "text");
X
X /* button2 retrieves text stored in the clipboard */
X button = XtVaCreateManagedWidget("button2",
X xmPushButtonGadgetClass, rowcol,
X XtVaTypedArg, XmNlabelString, XmRString,
X "Retrieve From Clipboard", 24, /* strlen() + 1 */
X NULL);
X XtAddCallback(button, XmNactivateCallback, from_clipbd, NULL);
X
X /* manage RowColumn, realize toplevel shell and start main loop */
X XtManageChild(rowcol);
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* copy data to clipboard. */
Xstatic void
Xto_clipbd(widget, data)
XWidget widget;
Xchar *data;
X{
X unsigned long item_id = 0; /* clipboard item id */
X int status;
X XmString clip_label;
X char buf[32];
X static int cnt;
X Display *dpy = XtDisplayOfObject(widget);
X Window window = XtWindowOfObject(widget);
X
X sprintf(buf, "%s-%d", data, ++cnt); /* make each copy unique */
X
X clip_label = XmStringCreateSimple("to_clipbd");
X
X /* start a copy. retry till unlocked */
X do
X status = XmClipboardStartCopy(dpy, window,
X clip_label, CurrentTime, NULL, NULL, &item_id);
X while (status == ClipboardLocked);
X
X XmStringFree(clip_label);
X
X /* copy the data (buf) -- pass "cnt" as private id for kicks */
X do
X status = XmClipboardCopy(dpy, window, item_id, "STRING",
X buf, (long)strlen(buf)+1, cnt, NULL);
X while (status == ClipboardLocked);
X
X /* end the copy */
X do
X status = XmClipboardEndCopy(dpy, window, item_id);
X while (status == ClipboardLocked);
X
X printf("copied \"%s\" to clipboard.\n", buf);
X}
X
Xstatic void
Xfrom_clipbd(widget)
XWidget widget;
X{
X int status, private_id;
X char buf[32];
X Display *dpy = XtDisplayOfObject(widget);
X Window window = XtWindowOfObject(widget);
X
X do
X status = XmClipboardRetrieve(dpy, window,
X "STRING", buf, sizeof buf, NULL, &private_id);
X while (status == ClipboardLocked);
X
X if (status == ClipboardSuccess)
X printf("retrieved \"%s\" (private id = %d).\n",
X buf, private_id);
X}
END_OF_FILE
if test 3416 -ne `wc -c <'vol6/ch18/copy_retrieve.c'`; then
echo shar: \"'vol6/ch18/copy_retrieve.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch18/copy_retrieve.c'
fi
if test -f 'vol6/ch18/undo.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch18/undo.c'\"
else
echo shar: Extracting \"'vol6/ch18/undo.c'\" \(3596 characters\)
sed "s/^X//" >'vol6/ch18/undo.c' <<'END_OF_FILE'
X/* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
X * This program is freely distributable without licensing fees and
X * is provided without guarantee or warrantee expressed or implied.
X * This program is -not- in the public domain.
X */
X
X/* undo.c -- demonstrate undoing a clipboard copy */
X
X#include <Xm/Xm.h>
X#include <Xm/CutPaste.h>
X#include <Xm/RowColumn.h>
X#include <Xm/PushBG.h>
X
Xvoid
Xcut_to_clipboard(widget, data)
XWidget widget;
Xchar *data;
X{
X unsigned long item_id = 0; /* clipboard item id */
X int data_id = 0; /* clipboard data id */
X int status = 0; /* clipboard status */
X XmString clip_label;
X char buf[32];
X static int cnt;
X Display *dpy = XtDisplayOfObject(widget);
X Window window = XtWindowOfObject(widget);
X
X sprintf(buf, "%s %d", data, ++cnt);
X printf("Putting \"%s\" on clipboard\n", buf);
X
X clip_label = XmStringCreateSimple("cut_to_clipboard");
X /*
X * start copy to clipboard, and continue till a sucessful start copy
X * is made
X */
X status = 0;
X while (status != ClipboardSuccess)
X status = XmClipboardStartCopy(dpy, window,
X clip_label, CurrentTime, NULL, NULL, &item_id);
X
X /*
X * move the data to the clipboard, and continue till a sucessful copy
X * is made
X */
X status = 0;
X while (status != ClipboardSuccess)
X status = XmClipboardCopy(dpy, window,
X item_id, "STRING", buf, (long) strlen(buf) + 1, 0, &data_id);
X
X /*
X * end the copy to the clipboard and continue till a sucessful end
X * copy is made
X */
X status = 0;
X while (status != ClipboardSuccess)
X status = XmClipboardEndCopy(dpy, window,
X item_id);
X}
X
Xvoid
Xundo(widget)
XWidget widget;
X{
X XmClipboardUndoCopy(XtDisplayOfObject(widget), XtWindowOfObject(widget));
X}
X
Xvoid
Xretrieve_from_clipboard(widget)
XWidget widget;
X{
X int status = ClipboardLocked;
X char buf[32];
X Display *dpy = XtDisplayOfObject(widget);
X Window window = XtWindowOfObject(widget);
X
X XmClipboardStartRetrieve(dpy, window, CurrentTime);
X while (status == ClipboardLocked) {
X status = XmClipboardRetrieve(dpy, window,
X "STRING", buf, sizeof buf, NULL, NULL);
X printf("status = %s\n",
X (status == ClipboardSuccess)? "success" :
X (status == ClipboardLocked)? "locked" :
X (status == ClipboardNoData)? "no data" :
X (status == ClipboardTruncate)? "data truncated" :
X (status == ClipboardFail)? "Failed" : "Bad Format");
X if (status == ClipboardSuccess)
X puts(buf);
X }
X XmClipboardEndRetrieve(dpy, window);
X}
X
Xmain(argc, argv)
Xchar *argv[];
X{
X Widget toplevel, rowcol, button;
X XtAppContext app;
X
X toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
X &argc, argv, NULL, NULL);
X
X rowcol = XtVaCreateManagedWidget("rowcol",
X xmRowColumnWidgetClass, toplevel,
X NULL);
X button = XtVaCreateManagedWidget("button1",
X xmPushButtonGadgetClass, rowcol,
X XtVaTypedArg, XmNlabelString, XmRString,
X "Cut To Clipboard", sizeof (char *),
X NULL);
X XtAddCallback(button, XmNactivateCallback, cut_to_clipboard, "data");
X
X button = XtVaCreateManagedWidget("button2",
X xmPushButtonGadgetClass, rowcol,
X XtVaTypedArg, XmNlabelString, XmRString,
X "Undo Cut", sizeof (char *),
X NULL);
X XtAddCallback(button, XmNactivateCallback, undo, NULL);
X
X button = XtVaCreateManagedWidget("retrieve",
X xmPushButtonGadgetClass, rowcol,
X XtVaTypedArg, XmNlabelString, XmRString,
X "Retrieve From Clipboard", sizeof (char *),
X NULL);
X XtAddCallback(button, XmNactivateCallback, retrieve_from_clipboard, NULL);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
END_OF_FILE
if test 3596 -ne `wc -c <'vol6/ch18/undo.c'`; then
echo shar: \"'vol6/ch18/undo.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch18/undo.c'
fi
if test -f 'vol6/ch20/working.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch20/working.c'\"
else
echo shar: Extracting \"'vol6/ch20/working.c'\" \(3574 characters\)
sed "s/^X//" >'vol6/ch20/working.c' <<'END_OF_FILE'
X/* Written by Dan Heller. Copyright 1991, O'Reilly && Associates.
X * This program is freely distributable without licensing fees and
X * is provided without guarantee or warrantee expressed or implied.
X * This program is -not- in the public domain.
X */
X
X/* working.c -- represent a complicated, time-consuming task by
X * counting from 0 to 20000 and provide feedback to the user about
X * how far we are in the process. The user may terminate the process
X * at any time by selecting the Stop button in the WorkingDialog.
X * This demonstrates how WorkingDialogs can be used to allow the
X * user to interrupt lengthy procedures.
X */
X#include <Xm/MessageB.h>
X#include <Xm/PushB.h>
X
X#define MAXNUM 20000
X
X/* main() --create a pushbutton whose callback pops up a dialog box */
Xmain(argc, argv)
Xchar *argv[];
X{
X XtAppContext app;
X XtWorkProcId work_id;
X Widget toplevel, dialog;
X XmString stop_txt;
X extern void done();
X Arg args[1];
X int count();
X
X toplevel = XtVaAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL);
X
X /* Create the dialog -- the "cancel" button says "Stop" */
X stop_txt = XmStringCreateSimple("Stop");
X XtSetArg(args[0], XmNcancelLabelString, stop_txt);
X dialog = XmCreateWorkingDialog(toplevel, "working", args, 1);
X XmStringFree(stop_txt);
X
X work_id = XtAppAddWorkProc(app, count, dialog);
X XtVaSetValues(dialog, XmNuserData, work_id, NULL);
X
X XtUnmanageChild( /* no need for the ok button */
X XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON), False);
X XtUnmanageChild( /* no need for the help button */
X XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON), False);
X
X /* Use cancel button to stop counting. True = remove work proc */
X XtAddCallback(dialog, XmNcancelCallback, done, True);
X
X XtManageChild(dialog);
X XtPopup(XtParent(dialog), XtGrabNone);
X
X /* XtRealizeWidget(toplevel); */
X XtAppMainLoop(app);
X}
X
X/* work procedure -- counts to MAXNUM. When we hit it, change the
X * "Stop" button to say "Done".
X */
Xint
Xcount(dialog)
XWidget dialog; /* client data for XtAppAddWorkProc() */
X{
X static int n;
X char buf[64];
X XmString str, button;
X Arg args[2];
X
X /* if we printed every number, the flicker is too fast to read.
X * Therefore, just print every 1000 ticks for smoother feedback.
X */
X if (++n % 1000 != 0)
X return False;
X
X /* display where we are in the counter. */
X sprintf(buf, "Counter: %d", n);
X str = XmStringCreateSimple(buf);
X XtSetArg(args[0], XmNmessageString, str);
X
X if (n == MAXNUM) {
X button = XmStringCreateSimple("Done");
X XtSetArg(args[1], XmNcancelLabelString, button);
X XtRemoveCallback(dialog, XmNcancelCallback, done, True);
X XtAddCallback(dialog, XmNcancelCallback, done, False);
X
X XtManageChild(dialog);
X /* or, use:
X if (!XtIsManaged(dialog))
X done(dialog, False);
X */
X }
X
X XtSetValues(dialog, args, 1 + (n == MAXNUM));
X
X /* return either True (we're done, remove the work proc)
X * or False (continue working by calling this function).
X */
X return n == MAXNUM;
X}
X
X/* User pressed "Stop" or "Done" in WorkingDialog. */
Xvoid
Xdone(dialog, remove_work_proc)
XWidget dialog;
Xint remove_work_proc;
X{
X if (remove_work_proc) {
X XtWorkProcId work_id;
X XtVaGetValues(dialog, XmNuserData, &work_id, NULL);
X XtRemoveWorkProc(work_id);
X }
X XtDestroyWidget(dialog);
X exit(0); /* for purposes of this demo; remove for general use */
X}
END_OF_FILE
if test 3574 -ne `wc -c <'vol6/ch20/working.c'`; then
echo shar: \"'vol6/ch20/working.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch20/working.c'
fi
echo shar: End of archive 7 \(of 11\).
cp /dev/null ark7isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 11 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
--
Dan Heller
O'Reilly && Associates Z-Code Software Comp-sources-x:
Senior Writer President comp-sources-x@uunet.uu.net
argv@ora.com argv@zipcode.com