home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
x
/
volume14
/
ora.vol6
/
part08
< prev
next >
Wrap
Text File
|
1991-09-18
|
59KB
|
1,791 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: v14i038: Examples from the Motif Programmer's Manual (ORA-Vol. 6), Part08/11
Message-ID: <20152@exodus.Eng.Sun.COM>
Date: 18 Sep 91 22:31:20 GMT
References: <csx-14i031-ora.vol6@uunet.UU.NET>
Sender: news@exodus.Eng.Sun.COM
Lines: 1779
Approved: argv@sun.com
Submitted-by: Dan Heller <argv@z-code.com>
Posting-number: Volume 14, Issue 38
Archive-name: ora.vol6/part08
# 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 8 (of 11)."
# Contents: vol6/ch05/modal.c vol6/ch05/reason.c vol6/ch07/map_dlg.c
# vol6/ch08/traversal.c vol6/ch08/unit_types.c
# vol6/ch09/monitor_sb.c vol6/ch11/arrow.c vol6/ch11/multi_click.c
# vol6/ch12/toggle_box.c vol6/ch14/simple_scale.c vol6/ch15/passwd.c
# vol6/ch15/prompt_phone.c vol6/ch15/text_box.c
# vol6/ch16/simple_option.c vol6/ch16/simple_popup.c
# vol6/ch17/wm_del_proto.c vol6/ch17/wm_delete.c
# vol6/ch20/simple_help.c
# Wrapped by argv@tribbles on Wed Sep 18 15:10:25 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'vol6/ch05/modal.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch05/modal.c'\"
else
echo shar: Extracting \"'vol6/ch05/modal.c'\" \(2604 characters\)
sed "s/^X//" >'vol6/ch05/modal.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/* modal.c -- demonstrate modal dialogs. Display two pushbuttons
X * each activating a modal dialog.
X */
X#include <Xm/RowColumn.h>
X#include <Xm/MessageB.h>
X#include <Xm/PushB.h>
X
X/* main() --create a pushbutton whose callback pops up a dialog box */
Xmain(argc, argv)
Xchar *argv[];
X{
X XtAppContext app;
X Widget toplevel, button, rowcolumn;
X void pushed();
X
X toplevel = XtVaAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL);
X
X rowcolumn = XtCreateManagedWidget("rowcolumn",
X xmRowColumnWidgetClass, toplevel, NULL, 0);
X
X button = XtCreateManagedWidget("application-modal",
X xmPushButtonWidgetClass, rowcolumn, NULL, 0);
X XtAddCallback(button, XmNactivateCallback,
X pushed, XmDIALOG_FULL_APPLICATION_MODAL);
X button = XtCreateManagedWidget("system-modal",
X xmPushButtonWidgetClass, rowcolumn, NULL, 0);
X XtAddCallback(button, XmNactivateCallback, pushed,
X XmDIALOG_SYSTEM_MODAL);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* pushed() --the callback routine for the main app's pushbutton.
X * Create either a full-application or system modal dialog box.
X */
Xvoid
Xpushed(w, modality)
XWidget w;
Xunsigned char modality;
X{
X static Widget dialog;
X XmString t;
X extern void dlg_callback();
X
X /* See if we've already created this dialog -- if so,
X * we don't need to create it again. Just re-pop it up.
X */
X if (!dialog) {
X Arg args[2];
X XmString ok = XmStringCreateSimple("OK");
X XtSetArg(args[0], XmNautoUnmanage, False);
X XtSetArg(args[1], XmNcancelLabelString, ok);
X dialog = XmCreateInformationDialog(w, "notice", args, 2);
X XtAddCallback(dialog, XmNcancelCallback, dlg_callback, NULL);
X XtUnmanageChild(
X XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON));
X XtUnmanageChild(
X XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
X }
X t = XmStringCreateSimple("You must reply to this message now!");
X XtVaSetValues(dialog,
X XmNmessageString, t,
X XmNdialogStyle, modality,
X NULL);
X XmStringFree(t);
X XtManageChild(dialog);
X XtPopup(XtParent(dialog), XtGrabNone);
X}
X
Xvoid
Xdlg_callback(dialog, client_data, cbs)
XWidget dialog;
XXtPointer client_data;
XXmAnyCallbackStruct *cbs;
X{
X XtPopdown(XtParent(dialog));
X}
END_OF_FILE
if test 2604 -ne `wc -c <'vol6/ch05/modal.c'`; then
echo shar: \"'vol6/ch05/modal.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch05/modal.c'
fi
if test -f 'vol6/ch05/reason.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch05/reason.c'\"
else
echo shar: Extracting \"'vol6/ch05/reason.c'\" \(2907 characters\)
sed "s/^X//" >'vol6/ch05/reason.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/* reason.c -- examine the reason field of the callback structure
X * passed as the call_data of the callback function. This field
X * indicates which action area button in the dialog was pressed.
X */
X#include <Xm/RowColumn.h>
X#include <Xm/MessageB.h>
X#include <Xm/PushB.h>
X
X/* main() --create a pushbutton whose callback pops up a dialog box */
Xmain(argc, argv)
Xchar *argv[];
X{
X XtAppContext app;
X Widget toplevel, rc, pb;
X extern void pushed();
X
X toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
X &argc, argv, NULL, NULL);
X
X rc = XtVaCreateWidget("rowcol", xmRowColumnWidgetClass, toplevel, NULL);
X
X pb = XtVaCreateManagedWidget("Hello", xmPushButtonWidgetClass, rc, NULL);
X XtAddCallback(pb, XmNactivateCallback, pushed, "Hello World");
X
X pb = XtVaCreateManagedWidget("Goodbye", xmPushButtonWidgetClass, rc, NULL);
X XtAddCallback(pb, XmNactivateCallback, pushed, "Goodbye World");
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 and popup a dialog box that has callback functions for
X * the Ok, Cancel and Help buttons.
X */
Xvoid
Xpushed(w, message)
XWidget w;
Xchar *message; /* really: client_data, but we know what it is */
X{
X static Widget dialog;
X XmString t = XmStringCreateSimple(message);
X
X /* See if we've already created this dialog -- if so,
X * we don't need to create it again. Just set the message
X * and manage it (repop it up).
X */
X if (!dialog) {
X extern void callback();
X Arg args[1];
X
X XtSetArg(args[0], XmNautoUnmanage, False);
X dialog = XmCreateMessageDialog(w, "notice", args, 1);
X XtAddCallback(dialog, XmNokCallback, callback, "Hi");
X XtAddCallback(dialog, XmNcancelCallback, callback, "Foo");
X XtAddCallback(dialog, XmNhelpCallback, callback, "Bar");
X }
X XtVaSetValues(dialog, XmNmessageString, t, NULL);
X XmStringFree(t);
X XtManageChild(dialog);
X
X XtPopup(XtParent(dialog), XtGrabNone);
X}
X
X/* callback() --One of the dialog buttons was selected.
X * Determine which one by examining the "reason" parameter.
X */
Xvoid
Xcallback(w, client_data, cbs)
XWidget w;
XXtPointer client_data;
XXmAnyCallbackStruct *cbs;
X{
X char *button;
X
X switch (cbs->reason) {
X case XmCR_OK : button = "OK"; break;
X case XmCR_CANCEL : button = "Cancel"; break;
X case XmCR_HELP : button = "Help";
X }
X printf("%s was selected: %s\n", button, client_data);
X if (cbs->reason != XmCR_HELP) {
X /* the ok and cancel buttons "close" the widget */
X XtPopdown(XtParent(w));
X }
X}
END_OF_FILE
if test 2907 -ne `wc -c <'vol6/ch05/reason.c'`; then
echo shar: \"'vol6/ch05/reason.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch05/reason.c'
fi
if test -f 'vol6/ch07/map_dlg.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch07/map_dlg.c'\"
else
echo shar: Extracting \"'vol6/ch07/map_dlg.c'\" \(2310 characters\)
sed "s/^X//" >'vol6/ch07/map_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/* map_dlg.c -- Use the XmNmapCallback to automatically position
X * a dialog on the screen. Each time the dialog is displayed, it
X * is mapped down and to the right by 200 pixels in each direction.
X */
X#include <Xm/MessageB.h>
X#include <Xm/PushB.h>
X
X/* main() --create a pushbutton whose callback pops up a dialog box */
Xmain(argc, argv)
Xchar *argv[];
X{
X Widget toplevel, button;
X XtAppContext app;
X void pushed();
X
X toplevel = XtVaAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL);
X
X button = XtCreateManagedWidget("button", xmPushButtonWidgetClass,
X toplevel, NULL, 0);
X XtAddCallback(button, XmNactivateCallback, pushed, "Hello World");
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* callback function for XmNmapCallback. Position dialog in 200 pixel
X * "steps". When the edge of the screen is hit, start over.
X */
Xstatic void
Xmap_dialog(dialog, client_data, cbs)
XWidget dialog;
XXtPointer client_data;
XXmAnyCallbackStruct *cbs;
X{
X static Position x, y;
X Dimension w, h;
X
X XtVaGetValues(dialog, XmNwidth, &w, XmNheight, &h, NULL);
X if (x + w >= WidthOfScreen(XtScreen(dialog)))
X x = 0;
X if (y + h >= HeightOfScreen(XtScreen(dialog)))
X y = 0;
X XtVaSetValues(dialog, XmNx, x, XmNy, y, NULL);
X x += 200, y += 200;
X}
X
X/* pushed() --the callback routine for the main app's pushbutton.
X * Create and popup a dialog box that has callback functions for
X * the Ok, Cancel and Help buttons.
X */
Xvoid
Xpushed(w, message)
XWidget w;
Xchar *message; /* The client_data parameter passed by XtAddCallback */
X{
X Widget dialog;
X Arg arg[3];
X XmString t = XmStringCreateSimple(message);
X extern void response();
X
X XtSetArg(arg[0], XmNautoUnmanage, False);
X XtSetArg(arg[1], XmNmessageString, t);
X XtSetArg(arg[2], XmNdefaultPosition, False);
X dialog = XmCreateMessageDialog(w, "notice", arg, 3);
X XmStringFree(t);
X
X XtAddCallback(dialog, XmNmapCallback, map_dialog, NULL);
X
X XtManageChild(dialog);
X XtPopup(XtParent(dialog), XtGrabNone);
X}
END_OF_FILE
if test 2310 -ne `wc -c <'vol6/ch07/map_dlg.c'`; then
echo shar: \"'vol6/ch07/map_dlg.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch07/map_dlg.c'
fi
if test -f 'vol6/ch08/traversal.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch08/traversal.c'\"
else
echo shar: Extracting \"'vol6/ch08/traversal.c'\" \(2604 characters\)
sed "s/^X//" >'vol6/ch08/traversal.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/* traverse.c -- demonstrate how keyboard traversal can be
X * manipulated among primitive widgets. Create a tic-tac-toe
X * board of PushButtons. As each item is selected, mark it
X * with an X (unless the Shift key is down) and change the
X * PushButton's XmNtraversalOn to False so user can't traverse
X * to it anymore.
X */
X#include <Xm/PushBG.h>
X#include <Xm/Form.h>
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X XtAppContext app;
X Widget toplevel, parent, w;
X int x, y;
X extern void pushed(); /* callback for the PushButton */
X
X toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
X &argc, argv, NULL, NULL);
X
X parent = XtVaCreateManagedWidget("form", xmFormWidgetClass, toplevel,
X XmNfractionBase, 3,
X NULL);
X /* create nine pushbutton widgets in tic-tac-toe format */
X for (x = 0; x < 3; x++)
X for (y = 0; y < 3; y++) {
X w = XtVaCreateManagedWidget(" ",
X xmPushButtonGadgetClass, parent,
X XmNtopAttachment, XmATTACH_POSITION,
X XmNtopPosition, y,
X XmNleftAttachment, XmATTACH_POSITION,
X XmNleftPosition, x,
X XmNrightAttachment, XmATTACH_POSITION,
X XmNrightPosition, x+1,
X XmNbottomAttachment, XmATTACH_POSITION,
X XmNbottomPosition, y+1,
X NULL);
X XtAddCallback(w, XmNactivateCallback, pushed, NULL);
X }
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
Xvoid
Xpushed(w, client_data, cbs)
XWidget w; /* The PushButton that got activated */
XXtPointer client_data; /* unused -- NULL was passed to XtAddCallback() */
XXmPushButtonCallbackStruct *cbs;
X{
X char buf[2];
X XmString str;
X int letter;
X
X XtVaGetValues(w, XmNuserData, &letter, NULL);
X if (letter) {
X XBell(XtDisplayOfObject(w), 50);
X return;
X }
X /* Shift key gets an O. (xbutton and xkey happen to be similar) */
X if (cbs->event->xbutton.state & ShiftMask)
X letter = buf[0] = '0';
X else
X letter = buf[0] = 'X';
X buf[1] = 0;
X str = XmStringCreateSimple(buf);
X XtVaSetValues(w,
X XmNlabelString, str,
X XmNuserData, letter,
X XmNshadowThickness, 0,
X XmNtraversalOn, False,
X NULL);
X XmStringFree(str);
X}
END_OF_FILE
if test 2604 -ne `wc -c <'vol6/ch08/traversal.c'`; then
echo shar: \"'vol6/ch08/traversal.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch08/traversal.c'
fi
if test -f 'vol6/ch08/unit_types.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch08/unit_types.c'\"
else
echo shar: Extracting \"'vol6/ch08/unit_types.c'\" \(1618 characters\)
sed "s/^X//" >'vol6/ch08/unit_types.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/* unit_types.c --the same as paned_win1.c except that the
X * Labels' minimum and maximum sizes are set to 1/4 inch and
X * 1/2 inch respectively. These measurements are retained
X * regardless of the pixels-per-inch resolution of the user's
X * display.
X */
X#include <Xm/Label.h>
X#include <Xm/PanedW.h>
X#include <Xm/Text.h>
X
Xmain(argc, argv)
Xchar *argv[];
X{
X Widget toplevel, pane;
X XtAppContext app;
X
X toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
X &argc, argv, NULL, NULL);
X
X pane = XtVaCreateWidget("pane",
X xmPanedWindowWidgetClass, toplevel,
X XmNunitType, Xm1000TH_INCHES,
X NULL);
X
X XtVaCreateManagedWidget("Hello", xmLabelWidgetClass, pane,
X XmNpaneMinimum, 250, /* quarter inch */
X XmNpaneMaximum, 500, /* half inch */
X NULL);
X
X XtVaCreateManagedWidget("text", xmTextWidgetClass, pane,
X XmNrows, 5,
X XmNcolumns, 80,
X XmNpaneMinimum, 250,
X XmNeditMode, XmMULTI_LINE_EDIT,
X XmNvalue, "This is a test of the paned window widget.",
X NULL);
X
X XtVaCreateManagedWidget("Goodbye", xmLabelWidgetClass, pane,
X XmNpaneMinimum, 250, /* quarter inch */
X XmNpaneMaximum, 500, /* half inch */
X NULL);
X
X XtManageChild(pane);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
END_OF_FILE
if test 1618 -ne `wc -c <'vol6/ch08/unit_types.c'`; then
echo shar: \"'vol6/ch08/unit_types.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch08/unit_types.c'
fi
if test -f 'vol6/ch09/monitor_sb.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch09/monitor_sb.c'\"
else
echo shar: Extracting \"'vol6/ch09/monitor_sb.c'\" \(3201 characters\)
sed "s/^X//" >'vol6/ch09/monitor_sb.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/* monitor_sb.c -- demonstrate the Scrollbar callback routines by
X * monitoring the Scrollbar for a ScrolledList. Functionally, this
X * program does nothing. However, by tinkering with the Scrolled
X * List and watching the output from the Scrollbar's callback routine,
X * you'll see some interesting behavioral patterns. By interacting
X * with the *List* widget to cause scrolling, the Scrollbar's callback
X * routine is never called. Thus, monitoring the scrolling actions
X * of a Scrollbar should not be used to keep tabs on exactly when
X * the scrollbar's value changes!
X */
X#include <Xm/List.h>
X
X/* print the "interesting" resource values of a scrollbar */
Xvoid
Xscroll_action(scrollbar, client_data, cbs)
XWidget scrollbar;
XXtPointer client_data;
XXmScrollBarCallbackStruct *cbs;
X{
X printf("cbs->reason: %s, cbs->value = %d, cbs->pixel = %d\n",
X cbs->reason == XmCR_DRAG? "drag" :
X cbs->reason == XmCR_VALUE_CHANGED? "value changed" :
X cbs->reason == XmCR_INCREMENT? "increment" :
X cbs->reason == XmCR_DECREMENT? "decrement" :
X cbs->reason == XmCR_PAGE_INCREMENT? "page increment" :
X cbs->reason == XmCR_PAGE_DECREMENT? "page decrement" :
X cbs->reason == XmCR_TO_TOP? "top" :
X cbs->reason == XmCR_TO_BOTTOM? "bottom" : "unknown",
X cbs->value, cbs->pixel);
X}
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Widget toplevel, list_w, sb;
X XtAppContext app;
X char *items = "choice0, choice1, choice2, choice3, choice4, \
X choice5, choice6, choice7, choice8, choice9, \
X choice10, choice11, choice12, choice13, choice14";
X
X toplevel = XtAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL, 0);
X
X list_w = XmCreateScrolledList(toplevel, "list_w", NULL, 0);
X XtVaSetValues(list_w,
X /* Rather than convert the entire list of items into an array
X * of compound strings, let's just let Motif's type converter
X * do it for us and save lots of effort (altho not much time).
X */
X XtVaTypedArg, XmNitems, XmRString, items, strlen(items)+1,
X XmNitemCount, 15,
X XmNvisibleItemCount, 5,
X NULL);
X XtManageChild(list_w);
X
X /* get the scrollbar from ScrolledWindow associated with Text widget */
X XtVaGetValues(XtParent(list_w), XmNverticalScrollBar, &sb, NULL);
X XtAddCallback(sb, XmNvalueChangedCallback, scroll_action, NULL);
X XtAddCallback(sb, XmNdragCallback, scroll_action, NULL);
X XtAddCallback(sb, XmNincrementCallback, scroll_action, NULL);
X XtAddCallback(sb, XmNdecrementCallback, scroll_action, NULL);
X XtAddCallback(sb, XmNpageIncrementCallback, scroll_action, NULL);
X XtAddCallback(sb, XmNpageDecrementCallback, scroll_action, NULL);
X XtAddCallback(sb, XmNtoTopCallback, scroll_action, NULL);
X XtAddCallback(sb, XmNtoBottomCallback, scroll_action, NULL);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
END_OF_FILE
if test 3201 -ne `wc -c <'vol6/ch09/monitor_sb.c'`; then
echo shar: \"'vol6/ch09/monitor_sb.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch09/monitor_sb.c'
fi
if test -f 'vol6/ch11/arrow.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch11/arrow.c'\"
else
echo shar: Extracting \"'vol6/ch11/arrow.c'\" \(2348 characters\)
sed "s/^X//" >'vol6/ch11/arrow.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/* arrow.c -- demonstrate the ArrowButton widget.
X * Have a Form widget display 4 ArrowButtons in a
X * familiar arrangement.
X */
X#include <Xm/ArrowBG.h>
X#include <Xm/Form.h>
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X XtAppContext app;
X Widget toplevel, form;
X XmString btn_text;
X Display *dpy;
X
X toplevel = XtVaAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL);
X
X dpy = XtDisplay(toplevel);
X /* Rather than listing all these resources in an app-defaults file,
X * add them directly to the database for this application only. This
X * would be virtually equivalent to hard-coding values, since these
X * resources will override any other specified external to this file.
X */
X XrmPutStringResource(&dpy->db, "*form*topAttachment", "attach_position");
X XrmPutStringResource(&dpy->db, "*form*leftAttachment", "attach_position");
X XrmPutStringResource(&dpy->db, "*form*rightAttachment", "attach_position");
X XrmPutStringResource(&dpy->db, "*form*bottomAttachment", "attach_position");
X
X form = XtVaCreateWidget("form", xmFormWidgetClass, toplevel,
X XmNfractionBase, 3,
X NULL);
X
X XtVaCreateManagedWidget("arrow1",
X xmArrowButtonGadgetClass, form,
X XmNtopPosition, 0,
X XmNbottomPosition, 1,
X XmNleftPosition, 1,
X XmNrightPosition, 2,
X XmNarrowDirection, XmARROW_UP,
X NULL);
X
X XtVaCreateManagedWidget("arrow2",
X xmArrowButtonGadgetClass, form,
X XmNtopPosition, 1,
X XmNbottomPosition, 2,
X XmNleftPosition, 0,
X XmNrightPosition, 1,
X XmNarrowDirection, XmARROW_LEFT,
X NULL);
X
X XtVaCreateManagedWidget("arrow3",
X xmArrowButtonGadgetClass, form,
X XmNtopPosition, 1,
X XmNbottomPosition, 2,
X XmNleftPosition, 2,
X XmNrightPosition, 3,
X XmNarrowDirection, XmARROW_RIGHT,
X NULL);
X
X XtVaCreateManagedWidget("arrow4",
X xmArrowButtonGadgetClass, form,
X XmNtopPosition, 2,
X XmNbottomPosition, 3,
X XmNleftPosition, 1,
X XmNrightPosition, 2,
X XmNarrowDirection, XmARROW_DOWN,
X NULL);
X
X XtManageChild(form);
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
END_OF_FILE
if test 2348 -ne `wc -c <'vol6/ch11/arrow.c'`; then
echo shar: \"'vol6/ch11/arrow.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch11/arrow.c'
fi
if test -f 'vol6/ch11/multi_click.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch11/multi_click.c'\"
else
echo shar: Extracting \"'vol6/ch11/multi_click.c'\" \(2286 characters\)
sed "s/^X//" >'vol6/ch11/multi_click.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/* multi_click.c -- demonstrate handling multiple PushButton clicks.
X * First, obtain the time interval of what constitutes a multiple
X * button click from the display and pass this as the client_data
X * for the button_click() callback function. In the callback, single
X * button clicks set a timer to expire on that interval and call the
X * function process_clicks(). Double clicks remove the timer and
X * just call process_clicks() directly.
X */
X#include <Xm/PushB.h>
X
XXtAppContext app;
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Widget toplevel, button, WidgetCreate();
X void button_click();
X XmString btn_text;
X int interval;
X
X toplevel = XtVaAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL);
X
X /* get how long for a double click */
X interval = XtGetMultiClickTime(XtDisplay(toplevel));
X printf("interval = %d\n", interval);
X
X btn_text = XmStringCreateSimple("Push Here");
X button = XtVaCreateManagedWidget("button",
X xmPushButtonWidgetClass, toplevel,
X XmNlabelString, btn_text,
X XmNwidth, 50,
X XmNheight, 25,
X NULL);
X XmStringFree(btn_text);
X XtAddCallback(button, XmNactivateCallback, button_click, interval);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* Process button clicks. Single clicks set a timer, double clicks
X * remove the timer, and extended clicks are ignored.
X */
Xvoid
Xbutton_click(w, interval, cbs)
XWidget w;
Xint interval;
XXmPushButtonCallbackStruct *cbs;
X{
X static XtIntervalId id;
X void process_clicks();
X
X if (cbs->click_count == 1)
X id = XtAppAddTimeOut(app, interval, process_clicks, False);
X else if (cbs->click_count == 2) {
X XtRemoveTimeOut(id);
X process_clicks(True);
X }
X}
X
X/* This function won't be called until we've established whether
X * or not a single or a double click has occured.
X */
Xvoid
Xprocess_clicks(double_click)
Xint double_click;
X{
X if (double_click)
X puts("Double click");
X else
X puts("Single click");
X}
END_OF_FILE
if test 2286 -ne `wc -c <'vol6/ch11/multi_click.c'`; then
echo shar: \"'vol6/ch11/multi_click.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch11/multi_click.c'
fi
if test -f 'vol6/ch12/toggle_box.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch12/toggle_box.c'\"
else
echo shar: Extracting \"'vol6/ch12/toggle_box.c'\" \(2896 characters\)
sed "s/^X//" >'vol6/ch12/toggle_box.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/* toggle_box.c -- demonstrate a homebrew ToggleBox. A static
X * list of strings is used as the basis for a list of toggles.
X * The callback routine toggled() is set for each toggle item.
X * The client data for this routine is set to the enumerated
X * value of the item with respect to the entire list. This value
X * is treated as a bit which is toggled in "toggles_set" -- a
X * mask that contains a complete list of all the selected items.
X * This list is printed when the PushButton is selected.
X */
X#include <Xm/ToggleBG.h>
X#include <Xm/PushBG.h>
X#include <Xm/SeparatoG.h>
X#include <Xm/RowColumn.h>
X
Xunsigned long toggles_set; /* has the bits of which toggles are set */
X
Xchar *strings[] = {
X "One", "Two", "Three", "Four", "Five",
X "Six", "Seven", "Eight", "Nine", "Ten",
X};
X
X/* A RowColumn is used to manage a ToggleBox (also a RowColumn) and
X * a PushButton with a separator gadget in between.
X */
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Widget toplevel, rowcol, toggle_box, w;
X XtAppContext app;
X void toggled(), check_bits();
X int i;
X
X toplevel = XtVaAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL);
X
X rowcol = XtVaCreateManagedWidget("rowcolumn",
X xmRowColumnWidgetClass, toplevel,
X NULL);
X
X toggle_box = XtVaCreateWidget("togglebox",
X xmRowColumnWidgetClass, rowcol,
X XmNpacking, XmPACK_COLUMN,
X XmNnumColumns, 2,
X NULL);
X
X /* simply loop thru the strings creating a widget for each one */
X for (i = 0; i < XtNumber(strings); i++) {
X w = XtVaCreateManagedWidget(strings[i],
X xmToggleButtonGadgetClass, toggle_box, NULL);
X XtAddCallback(w, XmNvalueChangedCallback, toggled, i);
X }
X
X XtVaCreateManagedWidget("_sep",
X xmSeparatorGadgetClass, rowcol, NULL);
X w = XtVaCreateManagedWidget("Check Toggles",
X xmPushButtonGadgetClass, rowcol, NULL);
X XtAddCallback(w, XmNactivateCallback, check_bits, NULL);
X
X XtManageChild(rowcol);
X XtManageChild(toggle_box);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* callback for all ToggleButtons. */
Xvoid
Xtoggled(widget, bit, toggle_data)
XWidget widget;
Xint bit;
XXmToggleButtonCallbackStruct *toggle_data;
X{
X if (toggle_data->set) /* if the toggle button is set, flip its bit */
X toggles_set |= (1 << bit);
X else /* if the toggle is "off", turn off the bit. */
X toggles_set &= ~(1 << bit);
X}
X
Xvoid
Xcheck_bits()
X{
X int i;
X
X printf("Toggles set:");
X for (i = 0; i < XtNumber(strings); i++)
X if (toggles_set & (1<<i))
X printf(" %s", strings[i]);
X putchar('\n');
X}
END_OF_FILE
if test 2896 -ne `wc -c <'vol6/ch12/toggle_box.c'`; then
echo shar: \"'vol6/ch12/toggle_box.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch12/toggle_box.c'
fi
if test -f 'vol6/ch14/simple_scale.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch14/simple_scale.c'\"
else
echo shar: Extracting \"'vol6/ch14/simple_scale.c'\" \(2309 characters\)
sed "s/^X//" >'vol6/ch14/simple_scale.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/* scale.c -- demonstrate a few scale widgets. */
X
X#include <Xm/Scale.h>
X#include <Xm/RowColumn.h>
X
Xmain(argc, argv)
Xchar *argv[];
X{
X Widget toplevel, rowcol, scale;
X XtAppContext app;
X void new_value(); /* callback for Scale widgets */
X
X toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
X &argc, argv, NULL, NULL);
X
X rowcol = XtVaCreateWidget("rowcol", xmRowColumnWidgetClass, toplevel,
X XmNorientation, XmHORIZONTAL,
X NULL);
X
X scale = XtVaCreateManagedWidget("Days",
X xmScaleWidgetClass, rowcol,
X XtVaTypedArg, XmNtitleString, XmRString, "Days", 4,
X XmNmaximum, 7,
X XmNminimum, 1,
X XmNvalue, 1,
X XmNshowValue, True,
X NULL);
X XtAddCallback(scale, XmNvalueChangedCallback, new_value, NULL);
X
X scale = XtVaCreateManagedWidget("Weeks",
X xmScaleWidgetClass, rowcol,
X XtVaTypedArg, XmNtitleString, XmRString, "Weeks", 5,
X XmNmaximum, 52,
X XmNminimum, 1,
X XmNvalue, 1,
X XmNshowValue, True,
X NULL);
X XtAddCallback(scale, XmNvalueChangedCallback, new_value, NULL);
X
X scale = XtVaCreateManagedWidget("Months",
X xmScaleWidgetClass, rowcol,
X XtVaTypedArg, XmNtitleString, XmRString, "Months", 6,
X XmNmaximum, 12,
X XmNminimum, 1,
X XmNvalue, 1,
X XmNshowValue, True,
X NULL);
X XtAddCallback(scale, XmNvalueChangedCallback, new_value, NULL);
X
X scale = XtVaCreateManagedWidget("Years",
X xmScaleWidgetClass, rowcol,
X XtVaTypedArg, XmNtitleString, XmRString, "Years", 5,
X XmNmaximum, 20,
X XmNminimum, 1,
X XmNvalue, 1,
X XmNshowValue, True,
X NULL);
X XtAddCallback(scale, XmNvalueChangedCallback, new_value, NULL);
X
X XtManageChild(rowcol);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
Xvoid
Xnew_value(scale_w, client_data, cbs)
XWidget scale_w;
XXtPointer client_data;
XXmScaleCallbackStruct *cbs;
X{
X printf("%s: %d\n", XtName(scale_w), cbs->value);
X}
END_OF_FILE
if test 2309 -ne `wc -c <'vol6/ch14/simple_scale.c'`; then
echo shar: \"'vol6/ch14/simple_scale.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch14/simple_scale.c'
fi
if test -f 'vol6/ch15/passwd.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch15/passwd.c'\"
else
echo shar: Extracting \"'vol6/ch15/passwd.c'\" \(2436 characters\)
sed "s/^X//" >'vol6/ch15/passwd.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/* passwd.c -- prompt for a passwd. Meaning, all input looks like
X * a series of *'s. Store the actual data typed by the user in
X * an internal variable. Don't allow paste operations. Handle
X * backspacing by deleting all text from insertion point to the
X * end of text.
X */
X#include <Xm/Text.h>
X#include <Xm/LabelG.h>
X#include <Xm/RowColumn.h>
X#include <ctype.h>
X
Xvoid check_passwd();
Xchar *passwd; /* store user-typed passwd here. */
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("Password:",
X xmLabelGadgetClass, rowcol, NULL);
X text_w = XtVaCreateManagedWidget("text_w",
X xmTextWidgetClass, rowcol, NULL);
X
X XtAddCallback(text_w, XmNmodifyVerifyCallback, check_passwd, NULL);
X XtAddCallback(text_w, XmNactivateCallback, check_passwd, NULL);
X
X XtManageChild(rowcol);
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
Xvoid
Xcheck_passwd(text_w, unused, cbs)
XWidget text_w;
XXtPointer unused;
XXmTextVerifyCallbackStruct *cbs;
X{
X char *new;
X int len;
X
X if (cbs->reason == XmCR_ACTIVATE) {
X printf("Password: %s\n", passwd);
X return;
X }
X
X if (cbs->text->ptr == NULL) { /* backspace */
X cbs->endPos = strlen(passwd); /* delete from here to end */
X passwd[cbs->startPos] = 0; /* backspace--terminate */
X return;
X }
X
X if (cbs->text->length > 1) {
X cbs->doit = False; /* don't allow "paste" operations */
X return; /* make the user *type* the password! */
X }
X
X new = XtMalloc(cbs->endPos + 2); /* new char + NULL terminator */
X if (passwd) {
X strcpy(new, passwd);
X XtFree(passwd);
X } else
X new[0] = NULL;
X passwd = new;
X strncat(passwd, cbs->text->ptr, cbs->text->length);
X passwd[cbs->endPos + cbs->text->length] = 0;
X
X for (len = 0; len < cbs->text->length; len++)
X cbs->text->ptr[len] = '*';
X}
END_OF_FILE
if test 2436 -ne `wc -c <'vol6/ch15/passwd.c'`; then
echo shar: \"'vol6/ch15/passwd.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch15/passwd.c'
fi
if test -f 'vol6/ch15/prompt_phone.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch15/prompt_phone.c'\"
else
echo shar: Extracting \"'vol6/ch15/prompt_phone.c'\" \(2376 characters\)
sed "s/^X//" >'vol6/ch15/prompt_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
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, 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_VALUE_CHANGED) {
X XmTextSetInsertionPosition(text_w, len);
X return;
X }
X
X /* no backspacing or typing in the 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 2376 -ne `wc -c <'vol6/ch15/prompt_phone.c'`; then
echo shar: \"'vol6/ch15/prompt_phone.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch15/prompt_phone.c'
fi
if test -f 'vol6/ch15/text_box.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch15/text_box.c'\"
else
echo shar: Extracting \"'vol6/ch15/text_box.c'\" \(2787 characters\)
sed "s/^X//" >'vol6/ch15/text_box.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/* text_box.c -- demonstrate simple use of XmNactivateCallback
X * for Text widgets. Create a rowcolumn that has rows of Form
X * widgets, each containing a Label and a Text widget. When
X * the user presses Return, print the value of the text widget
X * and move the focus to the next text widget.
X */
X#include <Xm/TextF.h>
X#include <Xm/LabelG.h>
X#include <Xm/Form.h>
X#include <Xm/RowColumn.h>
X
Xchar *labels[] = { "Name:", "Address:", "City:", "State:", "Zip:" };
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X Widget toplevel, text_w, form, rowcol;
X XtAppContext app;
X int i;
X void print_result();
X
X toplevel = XtVaAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL);
X
X rowcol = XtVaCreateWidget("rowcol",
X xmRowColumnWidgetClass, toplevel, NULL);
X
X for (i = 0; i < XtNumber(labels); i++) {
X form = XtVaCreateWidget("form", xmFormWidgetClass, rowcol,
X XmNfractionBase, 10,
X NULL);
X XtVaCreateManagedWidget(labels[i],
X xmLabelGadgetClass, form,
X XmNtopAttachment, XmATTACH_FORM,
X XmNbottomAttachment, XmATTACH_FORM,
X XmNleftAttachment, XmATTACH_FORM,
X XmNrightAttachment, XmATTACH_POSITION,
X XmNrightPosition, 3,
X XmNalignment, XmALIGNMENT_END,
X NULL);
X text_w = XtVaCreateManagedWidget("text_w",
X xmTextFieldWidgetClass, form,
X XmNtraversalOn, True,
X XmNrightAttachment, XmATTACH_FORM,
X XmNleftAttachment, XmATTACH_POSITION,
X XmNleftPosition, 4,
X NULL);
X
X /* When user hits return, print the label+value of text_w */
X XtAddCallback(text_w, XmNactivateCallback,
X print_result, labels[i]);
X
X /* Also advance focus to next Text widget, which is in the
X * next Tab Group because each Text widget is in a Form by
X * itself. If there were all in the same manager, we'd just
X * use XmTRAVERSE_NEXT instead.
X */
X XtAddCallback(text_w, XmNactivateCallback,
X XmProcessTraversal, XmTRAVERSE_NEXT_TAB_GROUP);
X XtManageChild(form);
X }
X XtManageChild(rowcol);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* callback for when the user his return in the Text widget */
Xvoid
Xprint_result(text_w, label)
XWidget text_w;
Xchar *label;
X{
X char *value = XmTextFieldGetString(text_w);
X
X printf("%s %s\n", label, value);
X XtFree(value);
X}
END_OF_FILE
if test 2787 -ne `wc -c <'vol6/ch15/text_box.c'`; then
echo shar: \"'vol6/ch15/text_box.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch15/text_box.c'
fi
if test -f 'vol6/ch16/simple_option.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch16/simple_option.c'\"
else
echo shar: Extracting \"'vol6/ch16/simple_option.c'\" \(2743 characters\)
sed "s/^X//" >'vol6/ch16/simple_option.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/* simple_option.c -- demonstrate how to use a simple option menu.
X * Display a drawing area (used hypothetically). The user can select
X * the drawing style from the option menu. Notice the difference in
X * appearance between the PushButton and the option menu.
X */
X#include <Xm/RowColumn.h>
X#include <Xm/MainW.h>
X#include <Xm/DrawingA.h>
X#include <Xm/PushB.h>
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X XmString draw_shape, line, square, circle, quit;
X Widget toplevel, main_w, rc, sw, drawing_a, option_menu, pb;
X void option_cb(), exit();
X XtAppContext app;
X
X toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
X &argc, argv, NULL, NULL);
X
X /* Create a MainWindow widget that contains a RowColumn
X * widget as its work window.
X */
X main_w = XtVaCreateManagedWidget("main_w",
X xmMainWindowWidgetClass, toplevel, NULL);
X rc = XtVaCreateWidget("rowcol", xmRowColumnWidgetClass, main_w, NULL);
X
X /* Inside RowColumn is the Quit pushbutton, the option menu and the
X * scrolled window that contains the drawing area.
X */
X pb = XtVaCreateManagedWidget("Quit", xmPushButtonWidgetClass, rc, NULL);
X XtAddCallback(pb, XmNactivateCallback, exit, NULL);
X
X draw_shape = XmStringCreateSimple("Draw Mode:");
X line = XmStringCreateSimple("Line");
X square = XmStringCreateSimple("Square");
X circle = XmStringCreateSimple("Circle");
X option_menu = XmVaCreateSimpleOptionMenu(rc, "option_menu",
X draw_shape, 'D', 0 /*initial menu selection*/, option_cb,
X XmVaPUSHBUTTON, line, 'L', NULL, NULL,
X XmVaPUSHBUTTON, square, 'S', NULL, NULL,
X XmVaPUSHBUTTON, circle, 'C', NULL, NULL,
X NULL);
X XmStringFree(line);
X XmStringFree(square);
X XmStringFree(circle);
X XmStringFree(draw_shape);
X
X XtManageChild(option_menu);
X
X /* Create a DrawingArea inside a ScrolledWindow */
X sw = XtVaCreateManagedWidget("sw", xmScrolledWindowWidgetClass, rc,
X XmNscrollingPolicy, XmAUTOMATIC,
X NULL);
X drawing_a = XtVaCreateManagedWidget("drawing_area",
X xmDrawingAreaWidgetClass, sw,
X XmNwidth, 500,
X XmNheight, 500,
X NULL);
X
X XtManageChild(rc);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* invoked when the user selects an item in the option menu */
Xvoid
Xoption_cb(menu_item, item_no, cbs)
XWidget menu_item;
Xint item_no;
XXmAnyCallbackStruct *cbs;
X{
X puts(XtName(menu_item)); /* Otherwise, just print the selection */
X}
END_OF_FILE
if test 2743 -ne `wc -c <'vol6/ch16/simple_option.c'`; then
echo shar: \"'vol6/ch16/simple_option.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch16/simple_option.c'
fi
if test -f 'vol6/ch16/simple_popup.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch16/simple_popup.c'\"
else
echo shar: Extracting \"'vol6/ch16/simple_popup.c'\" \(2929 characters\)
sed "s/^X//" >'vol6/ch16/simple_popup.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/* simple_popup.c -- demonstrate how to use a simple popup menu.
X * Create a main window that contains a DrawingArea widget, which
X * displays a popup menu when the user presses the menu button
X * (typically button 3).
X */
X#include <Xm/RowColumn.h>
X#include <Xm/MainW.h>
X#include <Xm/DrawingA.h>
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X XmString line, square, circle, quit, quit_acc;
X Widget toplevel, main_w, drawing_a, popup_menu;
X void popup_cb(), input();
X XtAppContext app;
X
X toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
X &argc, argv, NULL, NULL);
X
X /* Create a MainWindow widget that contains a DrawingArea in
X * its work window. (This happens by default.)
X */
X main_w = XtVaCreateManagedWidget("main_w",
X xmMainWindowWidgetClass, toplevel,
X XmNscrollingPolicy, XmAUTOMATIC,
X NULL);
X /* Create a DrawingArea -- no actual drawing will be done. */
X drawing_a = XtVaCreateManagedWidget("drawing_a",
X xmDrawingAreaWidgetClass, main_w,
X XmNwidth, 500,
X XmNheight, 500,
X NULL);
X
X line = XmStringCreateSimple("Line");
X square = XmStringCreateSimple("Square");
X circle = XmStringCreateSimple("Circle");
X quit = XmStringCreateSimple("Quit");
X quit_acc = XmStringCreateSimple("Ctrl-C");
X popup_menu = XmVaCreateSimplePopupMenu(drawing_a, "popup", popup_cb,
X XmVaPUSHBUTTON, line, NULL, NULL, NULL,
X XmVaPUSHBUTTON, square, NULL, NULL, NULL,
X XmVaPUSHBUTTON, circle, NULL, NULL, NULL,
X XmVaSEPARATOR,
X XmVaPUSHBUTTON, quit, NULL, "Ctrl<Key>c", quit_acc,
X NULL);
X XmStringFree(line);
X XmStringFree(square);
X XmStringFree(circle);
X XmStringFree(quit);
X
X /* after popup menu is created, add callback for all input events */
X XtAddCallback(drawing_a, XmNinputCallback, input, popup_menu);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* called in responses to events in the DrawingArea; button-3 pops up menu. */
Xvoid
Xinput(widget, popup, cbs)
XWidget widget;
XWidget popup; /* popup menu associated with drawing area */
XXmDrawingAreaCallbackStruct *cbs;
X{
X if (cbs->event->xany.type != ButtonPress ||
X cbs->event->xbutton.button != 3)
X return;
X
X /* Position the menu where the event occurred */
X XmMenuPosition(popup, cbs->event);
X XtManageChild(popup);
X}
X
X/* invoked when the user selects an item in the popup menu */
Xvoid
Xpopup_cb(menu_item, item_no, cbs)
XWidget menu_item;
Xint item_no;
XXmAnyCallbackStruct *cbs;
X{
X if (item_no == 3) /* Quit was selected -- exit */
X exit(0);
X puts(XtName(menu_item)); /* Otherwise, just print the selection */
X}
END_OF_FILE
if test 2929 -ne `wc -c <'vol6/ch16/simple_popup.c'`; then
echo shar: \"'vol6/ch16/simple_popup.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch16/simple_popup.c'
fi
if test -f 'vol6/ch17/wm_del_proto.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch17/wm_del_proto.c'\"
else
echo shar: Extracting \"'vol6/ch17/wm_del_proto.c'\" \(2792 characters\)
sed "s/^X//" >'vol6/ch17/wm_del_proto.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/* wm_delete.c -- demonstrate how client messages are caught and
X * processed by adding an event handler for them. Main window
X * just pops up a simple dialog, which has a client event handler.
X * Use the Close button in the window manager's system menu to
X * exercise it. Watch the print statements during execution.
X */
X#include <Xm/MessageB.h>
X#include <Xm/PushB.h>
X#include <Xm/Protocols.h>
X
X/* main() --create a pushbutton whose callback pops up a dialog box */
Xmain(argc, argv)
Xchar *argv[];
X{
X Widget toplevel, button;
X XtAppContext app;
X void pushed();
X
X toplevel = XtVaAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL);
X
X button = XtCreateManagedWidget("button", xmPushButtonWidgetClass,
X toplevel, NULL, 0);
X XtAddCallback(button, XmNactivateCallback, pushed, "Hello World");
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* pushed() --the callback routine for the main app's pushbutton.
X * Create any old dialog box that has a callback function for
X * client messages.
X */
Xvoid
Xpushed(w, message)
XWidget w;
Xchar *message; /* really: client_data, but we know what it is */
X{
X Widget dialog, shell;
X void do_client_msg();
X Atom protocol;
X XmString t = XmStringCreateSimple(message);
X Arg args[1];
X
X XtSetArg(args[0], XmNmessageString, t);
X dialog = XmCreateMessageDialog(w, "notice", args, 1);
X XmStringFree(t);
X
X XtManageChild(dialog);
X
X shell = XtParent(dialog);
X protocol = XmInternAtom(XtDisplay(w), "WM_DELETE_WINDOW", False);
X XmAddWMProtocols(shell, &protocol, 1);
X XtAddEventHandler(shell, NoEventMask, True, do_client_msg, NULL);
X}
X
X/* function to handle client messages only. Just catch WM_DELETE_WINDOW
X * messages and report them; ignore other messages.
X */
Xvoid
Xdo_client_msg(widget, client_data, msg)
XWidget widget;
XXtPointer client_data;
XXClientMessageEvent *msg;
X{
X char *str;
X int message = msg->data.l[0];
X Atom WM_DELETE_WINDOW;
X
X if (msg->type != ClientMessage)
X return;
X
X WM_DELETE_WINDOW = XmInternAtom(msg->display, "WM_DELETE_WINDOW", False);
X
X /* Get the atom name associated with the client message */
X str = XGetAtomName(msg->display, msg->message_type);
X printf("msg type = %s (%d)\n", str, msg->message_type);
X XFree(str);
X
X /* Get the atom name of the message itself... */
X str = XGetAtomName(msg->display, message);
X printf("message = %s (%d)\n", str, message);
X XFree(str);
X
X if (message == WM_DELETE_WINDOW)
X puts("closing window");
X}
END_OF_FILE
if test 2792 -ne `wc -c <'vol6/ch17/wm_del_proto.c'`; then
echo shar: \"'vol6/ch17/wm_del_proto.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch17/wm_del_proto.c'
fi
if test -f 'vol6/ch17/wm_delete.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch17/wm_delete.c'\"
else
echo shar: Extracting \"'vol6/ch17/wm_delete.c'\" \(3128 characters\)
sed "s/^X//" >'vol6/ch17/wm_delete.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/* wm_delete.c -- demonstrate how to bind the Close button in the
X * window manager's system menu to the "cancel" button in a dialog.
X */
X#include <Xm/MessageB.h>
X#include <Xm/PushB.h>
X#include <Xm/Protocols.h>
X
X#define YES 1
X#define NO 0
Xint answer;
X
X/* main() --create a pushbutton whose callback pops up a dialog box */
Xmain(argc, argv)
Xchar *argv[];
X{
X Widget toplevel, button;
X XtAppContext app;
X void activate();
X
X toplevel = XtVaAppInitialize(&app, "Demos",
X NULL, 0, &argc, argv, NULL, NULL);
X
X button = XtCreateManagedWidget("button", xmPushButtonWidgetClass,
X toplevel, NULL, 0);
X XtAddCallback(button, XmNactivateCallback, activate, NULL);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X/* Create and popup an ErrorDialog indicating that the user may have
X * done something wrong. The dialog contains an Ok and Cancel button,
X * but he can still choose the Close button in the titlebar.
X */
Xvoid
Xactivate(w)
XWidget w;
X{
X Widget dialog, shell;
X void handle_close(), response();
X XmString t = XmStringCreateSimple("Warning: Delete All Files?");
X Atom WM_DELETE_WINDOW;
X Arg args[2];
X
X /* Make sure the VendorShell associated with the dialog does not
X * react to the user's selection of the Close system menu item.
X */
X XtSetArg(args[0], XmNmessageString, t);
X XtSetArg(args[1], XmNdeleteResponse, XmDO_NOTHING);
X dialog = XmCreateWarningDialog(w, "notice", args, 2);
X XmStringFree(t);
X
X /* add callback routines for ok and cancel -- desensitize help */
X XtAddCallback(dialog, XmNokCallback, response, NULL);
X XtAddCallback(dialog, XmNcancelCallback, response, NULL);
X XtSetSensitive(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON), False);
X
X XtManageChild(dialog);
X
X /* Add a callback for the WM_DELETE_WINDOW protocol */
X shell = XtParent(dialog);
X WM_DELETE_WINDOW = XmInternAtom(XtDisplay(w), "WM_DELETE_WINDOW", False);
X XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW, response, dialog);
X}
X
X/* callback for the Ok and Cancel buttons in the dialog -- may also be
X * called from the WM_DELETE_WINDOW protocol message sent by the wm.
X */
Xvoid
Xresponse(widget, client_data, cbs)
XWidget widget;
XXtPointer client_data;
XXmAnyCallbackStruct *cbs;
X{
X Widget dialog;
X
X if (cbs->reason == XmCR_OK) {
X answer = YES;
X puts("Yes.");
X } else {
X answer = NO;
X puts("No.");
X }
X /* test that "reason" is not the cancel button and not the ok button.
X * It's value is XmCR_PROTOCOLS (6666), but we can't check for that
X * because OSF didn't make that value public.
X */
X if (cbs->reason != XmCR_CANCEL && cbs->reason != XmCR_OK)
X /* we passed the dialog as client data for the protocol callback */
X dialog = (Widget)client_data;
X else
X dialog = widget;
X
X XtDestroyWidget(dialog);
X}
END_OF_FILE
if test 3128 -ne `wc -c <'vol6/ch17/wm_delete.c'`; then
echo shar: \"'vol6/ch17/wm_delete.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch17/wm_delete.c'
fi
if test -f 'vol6/ch20/simple_help.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'vol6/ch20/simple_help.c'\"
else
echo shar: Extracting \"'vol6/ch20/simple_help.c'\" \(3195 characters\)
sed "s/^X//" >'vol6/ch20/simple_help.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/* simple_help.c -- create a pushbutton that posts a dialog box
X * that entices the user to press the help button. The callback
X * for this button displays a new dialog that gives help.
X */
X#include <Xm/MessageB.h>
X#include <Xm/PushB.h>
X
X/* main() --create a pushbutton whose callback pops up a dialog box */
Xmain(argc, argv)
Xchar *argv[];
X{
X Widget toplevel, button;
X XtAppContext app;
X XmString label;
X void pushed();
X
X toplevel = XtVaAppInitialize(&app, "Demos", NULL, 0,
X &argc, argv, NULL, NULL);
X
X label = XmStringCreateSimple("???");
X button = XtVaCreateManagedWidget("button",
X xmPushButtonWidgetClass, toplevel,
X XmNlabelString, label,
X NULL);
X XtAddCallback(button, XmNactivateCallback,
X pushed, "You probably need help for this item.");
X XmStringFree(label);
X
X XtRealizeWidget(toplevel);
X XtAppMainLoop(app);
X}
X
X#define HELP_TEXT "You just got help.\n Now press 'Ok'"
X
X/* pushed() --the callback routine for the main app's pushbutton. */
Xvoid
Xpushed(w, text)
XWidget w;
Xchar *text;
X{
X Widget dialog;
X XmString t = XmStringCreateSimple(text);
X Arg args[2];
X extern void help_callback();
X
X XtSetArg(args[0], XmNautoUnmanage, False);
X XtSetArg(args[1], XmNmessageString, t);
X dialog = XmCreateMessageDialog(XtParent(w), "notice", args, 2);
X XmStringFree(t);
X
X XtUnmanageChild(
X XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
X
X XtAddCallback(dialog, XmNokCallback, XtDestroyWidget, NULL);
X XtAddCallback(dialog, XmNhelpCallback, help_callback, HELP_TEXT);
X
X XtManageChild(dialog);
X XtPopup(XtParent(dialog), XtGrabNone);
X}
X
X/*
X * The callback routine for the Help button in the original dialog
X * box. This routine displays a HelpDialog based on the help_text
X * parameter.
X */
Xvoid
Xhelp_callback(parent, help_text, cbs)
XWidget parent;
Xchar *help_text;
XXmAnyCallbackStruct *cbs;
X{
X Widget dialog;
X XmString text;
X void help_done();
X Arg args[2];
X
X text = XmStringCreateLtoR(help_text, XmSTRING_DEFAULT_CHARSET);
X XtSetArg(args[0], XmNmessageString, text);
X XtSetArg(args[1], XmNautoUnmanage, False);
X dialog = XmCreateInformationDialog(parent, "help", args, 2);
X XmStringFree(text);
X
X XtUnmanageChild( /* no need for the cancel button */
X XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON), False);
X XtSetSensitive( /* no more help is available. */
X XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON), False);
X /* the Ok button will call help_done() below */
X XtAddCallback(dialog, XmNokCallback, help_done, NULL);
X
X /* display the help text */
X XtManageChild(dialog);
X XtPopup(XtParent(dialog), XtGrabNone);
X}
X
X/* help_done() --called when user presses "Ok" in HelpDialog.
X * Destroy the dialog shell and reset it so that help_callback()
X * will create a new one.
X */
Xvoid
Xhelp_done(dialog)
XWidget dialog;
X{
X XtDestroyWidget(dialog);
X}
END_OF_FILE
if test 3195 -ne `wc -c <'vol6/ch20/simple_help.c'`; then
echo shar: \"'vol6/ch20/simple_help.c'\" unpacked with wrong size!
fi
# end of 'vol6/ch20/simple_help.c'
fi
echo shar: End of archive 8 \(of 11\).
cp /dev/null ark8isdone
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