home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
x
/
xtici.zip
/
xtici
/
message.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-28
|
13KB
|
447 lines
/*
* Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
* All Rights Reserved
*
* This file is a component of an X Window System client which uses the Xcms
* Color Management System. TekColor is a trademark of Tektronix, Inc. The
* TekColor Editor is the subject of U.S. and foreign patents pending. The
* term "TekHVC" designates a particular color space that is the subject of
* U.S. Patent No. 4,985,853 (equivalent foreign patents pending).
* Permission is hereby granted to use, copy, modify, sell, and otherwise
* distribute this software and its documentation for the X Window System
* environment, for any purpose and without fee, provided that:
*
* 1. The code and documentation are only used to implement a
* TekColor Editor in an X Window System environment; and
* 2. This copyright and permission notice is reproduced in all copies
* of the code and in supporting documentation.
*
* Permission is granted to modify this code as required to allow it to
* be compiled on any host computer, provided that the functionality of
* the TekColor Editor is not modified in any way. A description of any
* modifications must be sent to Tektronix, Inc. Contact
* Tektronix Inc., P.O. Box 1000, Mail Station 60-850,
* Network Displays Division Engineering, Wilsonville, OR 97070.
*
* Tektronix makes no representation about the suitability of this software
* for any purpose. It is provided "as is" and with all faults.
*
* TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
* INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
*
* NAME
* message - print messages to the user
*
* DESCRIPTION
* Display diagnostics to the user, sometimes wait for response.
* There are a number of message types.
* An error message is printed to stderr (on the host). These
* messages detect a problem in the commandline or in the environment.
* These errors are placed on stderr because the windowed environment
* is (usually) not yet established.
* Info messages are popped when something happens the user may want
* to know about. They are not modal - the user can leave them up and
* continue to run.
* Warn is used when the user is about to perform a potentially dangerous
* task, asking for confirmation before proceeding. This includes actions
* where the system is in a contradictory position, proceeding to resolve
* the contradiction may have unusually side effects. The dialog is
* modal.
* Ask is used when two choices are possible but there is no "default"
* action. The question is phrased so the user makes a binary choice.
* This dialog is also modal.
*/
#ifndef LINT
static char *copy_notice = "Copyright 1991 Tektronix, Inc.";
#ifdef RCS_ID
static char *rcsid= "$Header: message.c,v 1.2 91/08/22 11:34:07 adamsc Exp $";
#endif /* RCS_ID */
#endif /* LINT */
/*
* EXTERNAL INCLUDES
*/
/*
* INTERNAL INCLUDES
*/
#include <stdio.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/Xaw/Box.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Dialog.h>
#include <X11/Xaw/Form.h>
#include "xtici.h"
/*
* EXTERNS
*/
extern char *exeName;
/*
* GLOBALS
*/
#ifdef DEC
# define GLOBAL global
#else
# define GLOBAL
#endif
/*
* LOCAL DEFINES
*/
/*
* LOCAL TYPEDEFS
*
*/
/*
* LOCALS VARIABLES
*/
#ifdef DEBUG
# define STATIC
#else
# define STATIC static
#endif
STATIC int answer = -1;
STATIC Widget helpButton = NULL;
STATIC Widget pshell = NULL;
STATIC Widget ishell = NULL;
/************************************************************************
* *
* PRIVATE ROUTINES *
* *
************************************************************************/
/*
* Warning widget callback
*/
/* ARGSUSED */
STATIC void Answer(w, data, call)
Widget w;
XtPointer data;
XtPointer call;
{
answer = (int)data;
}
/*
* Spin our wheels here until the user responds.
*/
STATIC void BlockOnResponse(w1, w2, w3)
Window w1, w2, w3;
{
XtAppContext app = XtDisplayToApplicationContext(dpy);
XEvent ev;
XButtonEvent *ep = (XButtonEvent *)&ev;
Window h = 0;
XEvent cache;
int cached = 0;
answer = -1;
while (answer < 0) {
XtAppNextEvent(app, &ev);
/*
* HACK!! stop button events from all but dialog window
* This is necessary because there is no application modal dialog
* option, just modal with respect to tree.
* Just modifying the buttons is sufficient because this is the only
* input we respond to in the auxiliary window.
*/
switch (ep->type) {
case ButtonPress:
case ButtonRelease:
if (!h && helpButton)
h = XtWindow(helpButton);
if ( (ep->window != w1) && (ep->window != w2) &&
(ep->window != w3) && (ep->window != h) ) {
/*
* But it is often necessary to not lose the first release.
*/
if (!cached && (ep->type == ButtonRelease)) {
cached = 1;
cache = ev;
}
continue;
}
break;
default:
break;
}
XtDispatchEvent(&ev);
}
if (cached)
XPutBackEvent(dpy, &cache);
}
/*
* Clean up the widget.
*/
/* ARGSUSED */
STATIC void DestroyParent(w, pshellw, call)
Widget w;
XtPointer pshellw;
XtPointer call;
{
/* This assumes that a button (w) lays on a form */
/* and all that lays on the popup shell */
XtDestroyWidget (XtParent(w));
XtPopdown ((Widget)pshellw);
}
/*
* Dynamically create a help dialog from the passed string,
* then map it.
*/
/* ARGSUSED */
STATIC void HelpPop(w, pmsg, call)
Widget w;
XtPointer pmsg;
XtPointer call;
{
char *msg = (char *)pmsg;
Arg args[2];
Widget info, infom;
int n = 0;
if (!ishell) {
XtSetArg(args[n], XtNx, 0); n++;
XtSetArg(args[n], XtNy, 0); n++;
ishell = XtCreatePopupShell("info", transientShellWidgetClass,
primary, args, n);
}
n = 0;
info = XtCreateManagedWidget("helpbox", boxWidgetClass, ishell, args, n);
n = 0;
XtSetArg(args[n], XtNlabel, msg); n++;
infom = XtCreateManagedWidget("infom", labelWidgetClass, info, args, n);
n = 0;
XtSetArg(args[n], XtNlabel, "OK"); n++;
helpButton = XtCreateManagedWidget("quit", commandWidgetClass, info,
args, n);
XtAddCallback (helpButton, XtNcallback, DestroyParent, (XtPointer)ishell);
XtPopup (ishell, XtGrabNonexclusive);
}
/************************************************************************
* *
* PUBLIC ROUTINES *
* *
************************************************************************/
/*
* Put up an application modal question dialog.
* This means that we will spin here until the dialog is acknowledged.
* The difference between this routine and Warning is that here we are
* asking for guidance to do one thing or another; with Warning, we are
* allowing the user to back out of an operation.
*/
int Ask(msg, help)
char *msg, *help;
{
Widget ask, askmsg, button1, button2, button3;
Position x, y;
Arg args[5];
int n = 0;
if (!pshell) {
XtTranslateCoords (primary, (Position)0, (Position)0, &x, &y);
XtSetArg(args[n], XtNx, x); n++;
XtSetArg(args[n], XtNy, y); n++;
pshell = XtCreatePopupShell("popup", transientShellWidgetClass,
primary, args, n);
}
n = 0;
ask = XtCreateWidget("ask", formWidgetClass, pshell, args, n);
n = 0;
XtSetArg(args[n], XtNlabel, msg); n++;
askmsg = XtCreateManagedWidget("askmsg", commandWidgetClass, ask, args, n);
n = 0;
XtSetArg(args[n], XtNlabel, "Ok"); n++;
XtSetArg(args[n], XtNfromVert, askmsg); n++;
button1 = XtCreateManagedWidget("ok", commandWidgetClass, ask, args, n);
XtAddCallback(button1, XtNcallback, Answer, (XtPointer)MessageOK);
n = 0;
XtSetArg(args[n], XtNfromVert, askmsg); n++;
XtSetArg(args[n], XtNfromHoriz, button1); n++;
XtSetArg(args[n], XtNlabel, "Cancel"); n++;
button2 = XtCreateManagedWidget("cancel", commandWidgetClass, ask, args,n);
XtAddCallback(button2, XtNcallback, Answer, (XtPointer)MessageCancel);
if (help) {
n = 0;
XtSetArg(args[n], XtNfromVert, askmsg); n++;
XtSetArg(args[n], XtNfromHoriz, button2); n++;
XtSetArg(args[n], XtNlabel, "Help");
button3 = XtCreateManagedWidget("help", commandWidgetClass, ask,
args, n);
XtAddCallback(button3, XtNcallback, HelpPop, (XtPointer)help);
}
XtManageChild(ask);
XtPopup (pshell, XtGrabNonexclusive);
if (!help)
BlockOnResponse(XtWindow(button1), XtWindow(button2), None);
else
BlockOnResponse(XtWindow(button1), XtWindow(button2),
XtWindow(button3));
/* killing the dialog automatically kills the dialog shell */
XtDestroyWidget(ask);
XtPopdown (pshell);
return(answer);
}
/*
* Report a system error; there is no recovery, so just return.
* Typically called during setup, so dialogs are not used.
*/
void Error(diag)
char *diag;
{
fprintf(stderr, "%s: %s\n", exeName, diag);
exit(1);
}
/*
* Put up an information dialog.
* TODO: is there any way these things can be cached / reused ?
*/
void InformMsg(msg, help)
char *msg, *help;
{
Widget info, infomsg, button1, button2;
Position x, y;
Arg args[2];
int n = 0;
if (!pshell) {
XtTranslateCoords (primary, (Position)0, (Position)0, &x, &y);
XtSetArg(args[n], XtNx, x); n++;
XtSetArg(args[n], XtNy, y); n++;
pshell = XtCreatePopupShell("popup", transientShellWidgetClass,
primary, args, n);
}
n = 0;
info = XtCreateWidget("info", formWidgetClass, pshell, args, n);
n = 0;
XtSetArg(args[n], XtNlabel, msg); n++;
infomsg = XtCreateManagedWidget("infomsg", labelWidgetClass, info, args,n);
n = 0;
XtSetArg(args[n], XtNfromVert, infomsg); n++;
XtSetArg(args[n], XtNlabel, "Ok"); n++;
button1 = XtCreateManagedWidget("ok", commandWidgetClass, info, args, n);
XtAddCallback(button1, XtNcallback, DestroyParent, (XtPointer)pshell);
if (help) {
n = 0;
XtSetArg(args[n], XtNfromVert, infomsg); n++;
XtSetArg(args[n], XtNfromHoriz, button1); n++;
button2 = XtCreateManagedWidget("help", commandWidgetClass, info,
args, n);
XtAddCallback(button2, XtNcallback, HelpPop, (XtPointer)help);
}
XtManageChild(info);
XtPopup (pshell, XtGrabNonexclusive);
}
/*
* Put up an application modal warning dialog.
* This means that we will spin here until the dialog is acknowledged.
*/
int Warning(msg, help)
char *msg, *help;
{
Widget warn, warnmsg, button1, button2, button3;
Position x, y;
Arg args[10];
int n = 0;
if (!pshell) {
XtTranslateCoords (primary, (Position)0, (Position)0, &x, &y);
XtSetArg(args[n], XtNx, x); n++;
XtSetArg(args[n], XtNy, y); n++;
pshell = XtCreatePopupShell("popup", transientShellWidgetClass,
primary, args, n);
}
n = 0;
warn = XtCreateWidget("warn", formWidgetClass, pshell, args, n);
n = 0;
XtSetArg(args[n], XtNlabel, msg); n++;
warnmsg = XtCreateManagedWidget("warnmsg", labelWidgetClass, warn,
args, n);
n = 0;
XtSetArg(args[n], XtNfromVert, warnmsg); n++;
XtSetArg(args[n], XtNlabel, "Ok"); n++;
button1 = XtCreateManagedWidget("ok", commandWidgetClass, warn,
args, n);
XtAddCallback(button1, XtNcallback, Answer, (XtPointer)MessageContinue);
n = 0;
XtSetArg(args[n], XtNfromVert, warnmsg); n++;
XtSetArg(args[n], XtNfromHoriz, button1); n++;
XtSetArg(args[n], XtNlabel, "Cancel"); n++;
button2 = XtCreateManagedWidget("cancel", commandWidgetClass, warn,
args, n);
XtAddCallback(button2, XtNcallback, Answer, (XtPointer)MessageCancel);
if (help) {
n = 0;
XtSetArg(args[n], XtNfromVert, warnmsg); n++;
XtSetArg(args[n], XtNfromHoriz, button2); n++;
XtSetArg(args[n], XtNlabel, "Help"); n++;
button3 = XtCreateManagedWidget("help", commandWidgetClass, warn,
args, n);
XtAddCallback(button3, XtNcallback, HelpPop, (XtPointer)help);
}
XtManageChild(warn);
XtPopup (pshell, XtGrabNonexclusive);
if (!help)
BlockOnResponse(XtWindow(button1), XtWindow(button2), None);
else
BlockOnResponse(XtWindow(button1), XtWindow(button2),
XtWindow(button3));
/* killing the form automatically kills the children but not the shell */
XtDestroyWidget(warn);
XtPopdown (pshell);
return(answer);
}