|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T m
Length: 14271 (0x37bf)
Types: TextFile
Names: »messages.c«
└─⟦a05ed705a⟧ Bits:30007078 DKUUG GNU 2/12/89
└─⟦e10a7c8ba⟧ »./UNRELEASED/xgdb.tar.Z«
└─⟦ae30648b5⟧
└─⟦this⟧ »./messages.c«
\f
#ifndef lint
static char rcsid[] = "$Header: messages.c,v 1.1 89/07/05 15:36:13 hubbard Exp $";
#endif
/*
*
* Copyright 1988, 1989
* PCS Computer Systeme, GmbH
* Munich, West Germany
*
* All rights reserved.
*
* This is unsupported software and is subject to change without notice.
* PCS makes no representations about the suitability of this software
* for any purpose. It is supplied "as is" without express or implied
* warranty.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of PCS Computer Systeme not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission.
*
*/
/*
* Author: Jordan K. Hubbard
* For: PCS Computer Systems, GmbH.
* When: February 10th, 1989.
*
* $Log: messages.c,v $
* Revision 1.1 89/07/05 15:36:13 hubbard
* Initial revision
*
*
*/
#include "xgdb.h"
/*
* Generic message utilities for popping up confirmation boxes, error
* messages, etc.
*/
static void popdown(w, client_data, data)
Widget w;
caddr_t client_data, data;
{
Entry("popdown");
XtPopdown((Widget)client_data);
Leave_void;
}
/*
* Pop up an error message with a close box.
*/
void popupErrorMessage(T_PROC_ARGS)
T_PROC_DECL;
{
static Widget popup, form, label;
static XtCallbackRec callbck[2];
Window root, junk;
int ijunk, xloc, yloc;
char message[BUFSIZ];
Entry("popupErrorMessage");
CPYN(message, s, len);
if (!popup) {
i = 0;
XtSetArg(args[i], XtNallowShellResize, TRUE); i++;
popup = XtCreatePopupShell("error", overrideShellWidgetClass,
Toplevel, args, i);
i = 0;
form = XtCreateManagedWidget("errorForm", formWidgetClass, popup,
args, i);
i = 0;
XtSetArg(args[i], XtNtop, XtChainTop); i++;
XtSetArg(args[i], XtNbottom, XtChainTop); i++;
XtSetArg(args[i], XtNresizable, TRUE); i++;
XtSetArg(args[i], XtNlabel, message); i++;
label = XtCreateManagedWidget("errorLabel", labelWidgetClass, form,
args, i);
i = 0;
callbck[0].callback = popdown;
callbck[0].closure = (caddr_t)popup;
XtSetArg(args[i], XtNcallback, callbck); i++;
XtSetArg(args[i], XtNfromVert, label); i++;
XtSetArg(args[i], XtNtop, XtChainTop); i++;
XtSetArg(args[i], XtNbottom, XtChainTop); i++;
XtCreateManagedWidget("Confirm", commandWidgetClass,
form, args, i);
XtRealizeWidget(popup);
XDefineCursor(XtDisplay(popup), XtWindow(popup),
app_resources.cursors.popup);
}
else {
i = 0;
XtSetArg(args[i], XtNlabel, message); i++;
XtSetValues(label, args, i);
}
root = DefaultRootWindow(XtDisplay(Toplevel));
if (XQueryPointer(XtDisplay(Toplevel), root, &junk, &junk, &xloc, &yloc,
&ijunk, &ijunk, &ijunk))
XtMoveWidget(popup, xloc, yloc);
XtPopup(popup, XtGrabExclusive);
XRaiseWindow(XtDisplay(popup), XtWindow(popup));
Leave_void;
}
/*
* Pop up a message with a yes box and a no box. If yes, send invoke yesproc,
* if no, invoke noproc.
*/
void yesOrNo(p, str, len, yesproc, noproc)
Process *p;
String str;
Cardinal len;
VoidFuncP yesproc, noproc;
{
static Widget form, label, y, n;
Window root, junk;
int ijunk, xloc, yloc;
static Widget me;
char message[BUFSIZ];
static XtCallbackRec option[2];
Entry("yesOrNo");
CPYN(message, str, len);
if (!me) {
i = 0;
XtSetArg(args[i], XtNallowShellResize, TRUE); i++;
me = XtCreatePopupShell("yesorno",
overrideShellWidgetClass,
Toplevel, args, i);
i = 0;
form = XtCreateManagedWidget("yesnoForm", formWidgetClass, me,
args, i);
i = 0;
XtSetArg(args[i], XtNtop, XtChainTop); i++;
XtSetArg(args[i], XtNbottom, XtChainTop); i++;
XtSetArg(args[i], XtNresizable, TRUE); i++;
label = XtCreateManagedWidget("yesnoLabel", labelWidgetClass,
form, args, i);
i = 0;
XtSetArg(args[i], XtNfromVert, label); i++;
XtSetArg(args[i], XtNtop, XtChainTop); i++;
XtSetArg(args[i], XtNbottom, XtChainTop); i++;
XtSetArg(args[i], XtNleft, XtChainLeft); i++;
y = XtCreateManagedWidget("Yes", commandWidgetClass,
form, args, i);
i = 0;
XtSetArg(args[i], XtNfromHoriz, y); i++;
XtSetArg(args[i], XtNfromVert, label); i++;
XtSetArg(args[i], XtNtop, XtChainTop); i++;
XtSetArg(args[i], XtNbottom, XtChainTop); i++;
XtSetArg(args[i], XtNright, XtChainRight); i++;
n = XtCreateManagedWidget("No", commandWidgetClass,
form, args, i);
XtRealizeWidget(me);
XDefineCursor(XtDisplay(me), XtWindow(me),
app_resources.cursors.popup);
}
i = 0;
XtSetArg(args[i], XtNlabel, message); i++;
XtSetValues(label, args, i);
i = 0;
option[0].callback = yesproc;
option[0].closure = (caddr_t)me;
XtSetArg(args[i], XtNcallback, option); i++;
XtSetValues(y, args, i);
i = 0;
option[0].callback = noproc;
option[0].closure = (caddr_t)me;
XtSetArg(args[i], XtNcallback, option); i++;
XtSetValues(n, args, i);
root = DefaultRootWindow(XtDisplay(Toplevel));
if (XQueryPointer(XtDisplay(Toplevel), root, &junk, &junk, &xloc, &yloc,
&ijunk, &ijunk, &ijunk))
XtMoveWidget(me, xloc, yloc);
XtPopup(me, XtGrabExclusive);
XRaiseWindow(XtDisplay(me), XtWindow(me));
Leave_void;
}
/*
* The following routines may look general, but they're not. They all
* operate on "the" menu declared below. They're not for generalized menu
* handling.
*/
static char trans[] = "<LeaveWindow>: PopdownMenu()";
static Widget Menu;
/*
* Create the options menu.
*/
void createMenu(parent, menu)
Widget parent;
SimpleField *menu;
{
Widget box;
static XtCallbackRec callb[2];
Entry("createMenu");
Menu = XtCreatePopupShell("menu", overrideShellWidgetClass,
parent, NULL, ZERO);
XtOverrideTranslations(Menu, XtParseTranslationTable(trans));
box = XtCreateManagedWidget("options", boxWidgetClass, Menu, NULL, ZERO);
convertSimpleToField(menu, &MenuButtons);
createFields(box, MenuButtons, MenuButtons);
XtRealizeWidget(Menu);
XDefineCursor(XtDisplay(Menu), XtWindow(Menu),
app_resources.cursors.popup);
Leave_void;
}
void popupMenu()
{
Window root, junk;
int xloc, yloc, ijunk;
Entry("popupMenu");
ASSERT(NULLP(Menu));
root = DefaultRootWindow(XtDisplay(Toplevel));
if (XQueryPointer(XtDisplay(Toplevel), root, &junk, &junk, &xloc, &yloc,
&ijunk, &ijunk, &ijunk)) {
XWindowAttributes xwa;
XGetWindowAttributes(XtDisplay(Toplevel), XtWindow(Menu), &xwa);
xloc -= (xwa.width / 2);
yloc -= (xwa.height / 2);
if (xloc < 0)
xloc = 0;
if (yloc < 0)
yloc = 0;
XtMoveWidget(Menu, xloc, yloc);
}
XtPopup(Menu, XtGrabNone);
XRaiseWindow(XtDisplay(Menu), XtWindow(Menu));
Leave_void;
}
void popdownMenu()
{
Entry("popdownMenu");
ASSERT(NULLP(Menu));
XtPopdown(Menu);
Leave_void;
}
/* Ring the bell */
void feep()
{
Entry("feep");
XBell(XtDisplay(Toplevel), 100);
Leave_void;
}
/*
* The following is the "field" cruft. Yeah, it's hairy and evil and
* nasty but I didn't have time to write a widget that does the kind of
* layout I wanted, so I made due with the form Widget and lots of
* intermediate steps. Don't look.
*/
/*
* Converts a simple field group to an array of initialized Field
* structures. A maximum of 60 fields can be converted at one time.
* If a list pointer is passed, memory is allocated and the new list
* is copied into it.
*/
Field *convertSimpleToField(grp, list)
SimpleField *grp;
Field **list; /* return */
{
static Field ret[60];
Field *tmp = ret;
Entry("convertSimpleToField");
for (i = 0; grp[i].name && i < 50; i++) {
tmp[i].name = grp[i].name;
tmp[i].function = grp[i].function;
tmp[i].me = NULL;
tmp[i].attr_mask = 0L;
}
tmp[i].name = (String)NULL;
if (list) {
*list = (Field *)XtMalloc(sizeof(Field) * (i + 1));
bcopy(tmp, *list, (i + 1) * sizeof(Field));
tmp = *list;
}
Leave(tmp);
}
/*
* Converts a form field group to an array of initialized Field
* structures. A maximum of 60 fields can be converted at one time.
* If a list pointer is passed, memory is allocated and the new list
* is copied into it.
*/
Field *convertFormToField(grp, list)
FormField *grp;
Field **list; /* return */
{
static Field ret[60];
Field *tmp = ret;
Entry("convertFormToField");
for (i = 0; grp[i].fld.name && i < 50; i++) {
tmp[i].attr_mask = (FldBorderWidth | FldResizable);
tmp[i].name = grp[i].fld.name;
tmp[i].function = grp[i].fld.function;
tmp[i].attrs.border_width = grp[i].border_width;
tmp[i].attrs.resizable = grp[i].resizable;
if (tmp[i].attrs.fromVert = grp[i].from_vert)
tmp[i].attr_mask |= FldFromVert;
if (tmp[i].attrs.fromHoriz = grp[i].from_horiz)
tmp[i].attr_mask |= FldFromHoriz;
if (tmp[i].attrs.vertOffset = grp[i].vert_offset)
tmp[i].attr_mask |= FldVertOffset;
if (tmp[i].attrs.horizOffset = grp[i].horiz_offset)
tmp[i].attr_mask |= FldHorizOffset;
tmp[i].me = NULL;
}
tmp[i].name = (String)NULL;
if (list) {
i++;
*list = (Field *)XtMalloc(i * sizeof(Field));
bcopy(tmp, *list, i * sizeof(Field));
tmp = *list;
}
Leave(tmp);
}
/*
* Convert an attribute mask and corresponding FieldAttributes
* structure to an argument list.
*/
static void convert_mask_to_arglist(mask, attrs, alist, n)
unsigned long mask;
FieldAttributes *attrs;
Arg *alist; /* return */
Cardinal *n; /* return **/
{
int n2 = *n;
Entry("convert_mask_to_arglist");
if (mask & FldBorderWidth) {
XtSetArg(alist[n2], XtNborderWidth, attrs->border_width);
n2++;
}
if (mask & FldSensitive) {
XtSetArg(alist[n2], XtNsensitive, attrs->sensitive);
n2++;
}
if (mask & FldJustify) {
XtSetArg(alist[n2], XtNjustify, attrs->justify);
n2++;
}
if (mask & FldX) {
XtSetArg(alist[n2], XtNx, attrs->x);
n2++;
}
if (mask & FldY) {
XtSetArg(alist[n2], XtNy, attrs->y);
n2++;
}
if (mask & FldLabel) {
XtSetArg(alist[n2], XtNlabel, attrs->label);
n2++;
}
if (mask & FldWidth) {
XtSetArg(alist[n2], XtNwidth, attrs->width);
n2++;
}
if (mask & FldResizable) {
XtSetArg(alist[n2], XtNresizable, attrs->resizable);
n2++;
}
if (mask & FldVertOffset) {
XtSetArg(alist[n2], XtNvertDistance, attrs->vertOffset);
n2++;
}
if (mask & FldHorizOffset) {
XtSetArg(alist[n2], XtNhorizDistance, attrs->horizOffset);
n2++;
}
*n = n2;
Leave_void;
}
/*
* Create a bunch of fields from an array of initialized Field
* structures.
*/
void createFields(parent, flist, arg)
Widget parent;
Field *flist;
caddr_t arg;
{
static XtCallbackRec callback[2];
Cursor curs;
int j;
WidgetClass type;
Field *f;
Entry("createFields");
for (j = 0; flist[j].name; j++) {
f = &(flist[j]);
i = 0;
if (f->function) {
callback[0].callback = f->function;
callback[0].closure = arg;
XtSetArg(args[i], XtNcallback, callback); i++;
type = commandWidgetClass;
curs = app_resources.cursors.button;
}
else {
type = labelWidgetClass;
curs = app_resources.cursors.label;
}
convert_mask_to_arglist(f->attr_mask,
&(f->attrs),
args, &i);
XtSetArg(args[i], XtNleft, XtChainLeft); i++;
XtSetArg(args[i], XtNright, XtChainLeft); i++;
XtSetArg(args[i], XtNtop, XtChainTop); i++;
XtSetArg(args[i], XtNbottom,XtChainTop); i++;
XtSetArg(args[i], XtNcursor,curs); i++;
/*
* These two require special handling as they reference
* widgets in the list already created (at least they'd better).
*/
if (f->attr_mask & FldFromVert) {
XtSetArg(args[i], XtNfromVert, flist[f->attrs.fromVert-1].me);
i++;
}
if (f->attr_mask & FldFromHoriz) {
XtSetArg(args[i], XtNfromHoriz, flist[f->attrs.fromHoriz-1].me);
i++;
}
f->me = XtCreateManagedWidget(f->name, type, parent, args, i);
}
Leave_void;
}
/*
* Find and return field named "name" from fldlist.
*/
Field *nameToField(name, fldlist)
register String name;
register Field *fldlist;
{
Entry("nameToField");
ASSERT(NULLP(name) || NULLP(fldlist));
for (i = 0; fldlist[i].name; i++)
if (!strcmp(name, fldlist[i].name))
Leave(fldlist + i);
puke("%p: Warning: couldn't find field named '%s'", name);
Leave((Field *)NULL);
}
/*
* Change an already created field.
*/
void changeField(fld, attr_mask, attrs)
Field *fld;
unsigned long attr_mask;
FieldAttributes *attrs;
{
Entry("changeField");
i = 0;
convert_mask_to_arglist(attr_mask, attrs, args, &i);
XtSetValues(fld->me, args, i);
Leave_void;
}
/*
* Change an entire group of fields. Could just call changeField
* iteratively, but then we'd end up setting the value mask each
* time unnecessarily.
*/
void changeFields(flds, attr_mask, attrs)
register Field *flds;
unsigned long attr_mask;
FieldAttributes *attrs;
{
register int j;
Entry("changeFields");
i = 0;
convert_mask_to_arglist(attr_mask, attrs, args, &i);
for (j = 0; flds[j].name; j++)
XtSetValues(flds[j].me, args, i);
Leave_void;
}
/*
* See if a field has changed and update it if it has.
*/
void compareAndUpdateField(oldval, newval, name, f)
caddr_t oldval, newval;
String name;
Field *f;
{
FieldAttributes fla;
Entry("compareAndUpdateField");
if (strcmp(*(String *)oldval, (String)newval)) {
STASH(*(String *)oldval, (String)newval);
fla.label = newval;
changeField(nameToField(name, f), FldLabel, &fla);
}
Leave_void;
}