home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
s
/
seyon197.tz
/
seyon197
/
seyon
/
SeWin.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-20
|
20KB
|
987 lines
/*
* This file is part of the Seyon, Copyright (c) 1992-1993 by Muhammad M.
* Saggaf. All rights reserved.
*
* See the file COPYING (1-COPYING) or the manual page seyon(1) for a full
* statement of rights and permissions for this program.
*/
#include <setjmp.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xmu/CharSet.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/List.h>
#include "MultiList.h"
#include <X11/Xaw/Toggle.h>
#include <X11/Xaw/AsciiText.h>
#include <X11/Xaw/Box.h>
#include <X11/Xaw/Dialog.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Paned.h>
#include "seyon.h"
#include "SeDecl.h"
extern Widget topLevel;
extern Widget statusMessage;
extern Pixmap progIcon;
void SePopupMsg(),
SeEditSaveFile(),
StopMainLoop();
Boolean DoMainLoop;
/*
* does nothing
*/
void
DoNothing()
{
return;
}
/*
* distroys a popup
*/
void
DestroyShell(widget)
Widget widget;
{
Widget shell = GetShell(widget);
XtPopdown(shell);
XtDestroyWidget(shell);
}
void
DestroyShellCallBack(widget, child)
Widget widget;
XtPointer child;
{
DestroyShell((Widget)child);
}
void
DestroyParentPopup(widget, child)
Widget widget;
XtPointer child;
{
DestroyShellCallBack(widget, child);
}
void
DismissPopup(widget, up_flag)
Widget widget;
XtPointer up_flag;
{
*(Boolean *) up_flag = False;
DestroyParentPopup(NULL, XtParent(widget));
}
void
DismissPopup2(widget, up_flag)
Widget widget;
XtPointer up_flag;
{
DismissPopup(XtParent(widget), up_flag);
}
/*
* same as the above
*/
void
DestroyPopupPrompt(w, client_data, call_data)
Widget w;
XtPointer client_data,
call_data;
{
Widget popup = XtParent((Widget) client_data);
XtDestroyWidget(popup);
}
/*
* creates a button
*/
Widget
SeAddButton(name, parent, call_back)
String name;
Widget parent;
void (*call_back) ();
{
Widget widget;
widget = XtCreateManagedWidget(name, commandWidgetClass, parent, NULL, 0);
XtAddCallback(widget, XtNcallback, call_back, (XtPointer) parent);
return widget;
}
/*
* similar to the above, but also passes client data to the call back
* WCD = with client data
*/
Widget
SeAddButtonWCD(name, parent, call_back, client_data)
String name;
Widget parent;
void (*call_back) ();
XtPointer client_data;
{
Widget widget;
widget = XtCreateManagedWidget(name, commandWidgetClass, parent, NULL, 0);
XtAddCallback(widget, XtNcallback, call_back, client_data);
return widget;
}
Widget
SeAddButtonWithClientData(name, parent, call_back, client_data)
String name;
Widget parent;
void (*call_back) ();
XtPointer client_data;
{
return SeAddButtonWCD(name, parent, call_back, client_data);
}
/*
* creates a label
*/
Widget
SeAddLabel(name, parent)
String name;
Widget parent;
{
return XtCreateManagedWidget(name, labelWidgetClass, parent, NULL, 0);
}
/*
* sets a widget's label
*/
void
SeSetLabel(widget, label)
Widget widget;
String label;
{
XtVaSetValues(widget, XtNlabel, label, NULL);
}
/*
* creates a toggle
*/
Widget
SeAddToggleWCD(name, parent, call_back, clientData)
String name;
Widget parent;
void (*call_back) ();
XtPointer clientData;
{
Widget widget;
widget = XtCreateManagedWidget(name, toggleWidgetClass, parent, NULL, 0);
if (call_back) {
if (clientData == NULL)
clientData = (XtPointer) parent;
XtAddCallback(widget, XtNcallback, call_back, clientData);
}
return widget;
}
Widget
SeAddToggle(name, parent, call_back)
String name;
Widget parent;
void (*call_back) ();
{
return SeAddToggleWCD(name, parent, call_back, NULL);
}
/*
* sets or unsets a toggle
*/
void
SeSetUnsetToggle(widget, state)
Widget widget;
Boolean state;
{
XtVaSetValues(widget, XtNstate, state, NULL);
}
/*
* gets a toggle's state
*/
Boolean
SeGetToggleState(widget)
Widget widget;
{
Boolean state;
XtVaGetValues(widget, XtNstate, &state, NULL);
return state;
}
Widget
SePopupRadio(popup_name, parent, name, active, call_back, clientData)
String popup_name;
Widget parent;
String name[];
int active;
void (*call_back) ();
XtPointer clientData;
{
Widget popup,
mBox,
uBox,
lBox,
toggle,
widget;
long i = 0;
popup = AddSimplePopup(popup_name, parent);
mBox = SeAddPaned("mBox", popup);
uBox = SeAddBox("Radio", mBox);
lBox = SeAddBox("lBox", mBox);
toggle =
XtVaCreateManagedWidget(name[i], toggleWidgetClass, uBox, XtNradioData,
(XtPointer) (i + 1), NULL);
SeSetUnsetToggle(toggle, (active == i + 1));
XtAddCallback(toggle, XtNcallback, call_back, clientData);
for (i++; name[i]; i++) {
widget =
XtVaCreateManagedWidget(name[i], toggleWidgetClass, uBox, XtNradioGroup,
toggle, XtNradioData, (XtPointer) (i + 1), NULL);
SeSetUnsetToggle(widget, (active == i + 1));
XtAddCallback(widget, XtNcallback, call_back, clientData);
}
SeAddButtonWCD("dismiss", lBox, DestroyParentPopup, (XtPointer) mBox);
PopupCentered(popup, parent);
return toggle;
}
/*
* creates a box
*/
Widget
SeAddBox(name, parent)
String name;
Widget parent;
{
return XtCreateManagedWidget(name, boxWidgetClass, parent, NULL, 0);
}
/*
* creates a dialog
*/
Widget
SeAddDialog(name, parent)
String name;
Widget parent;
{
return XtCreateManagedWidget(name, dialogWidgetClass, parent, NULL, 0);
}
/*
* sets a dialog's label
*/
void
SeSetDialogValue(dialog, value)
Widget dialog;
String value;
{
Arg args;
XtSetArg(args, XtNvalue, value);
XtSetValues(dialog, &args, 1);
}
Widget
SePopupDialogGetStringE(popup_name, parent, ok_callback,
ok_client_data, def_val, UL)
String popup_name;
Widget parent;
void (*ok_callback) ();
XtPointer ok_client_data;
String def_val;
Boolean UL;
{
Widget popup,
dialog;
popup = AddSimplePopup(popup_name, parent);
dialog = SeAddDialog("dialog", popup);
if (def_val)
SeSetDialogValue(dialog, def_val);
if (ok_client_data == NULL)
ok_client_data = (XtPointer) dialog;
XawDialogAddButton(dialog, "ok", ok_callback, ok_client_data);
XawDialogAddButton(dialog, "cancel", DestroyShellCallBack,
(XtPointer) dialog);
PopupCentered(popup, parent);
return dialog;
}
Widget
SePopupDialogGetString(popup_name, parent, ok_callback,
ok_client_data)
String popup_name;
Widget parent;
void (*ok_callback) ();
XtPointer ok_client_data;
{
return SePopupDialogGetStringE(popup_name, parent, ok_callback,
ok_client_data, NULL, False);
}
/*
* creates a from
*/
Widget
SeAddForm(name, parent)
String name;
Widget parent;
{
return XtCreateManagedWidget(name, formWidgetClass, parent, NULL, 0);
}
Widget
SeAddPaned(name, parent)
String name;
Widget parent;
{
return XtCreateManagedWidget(name, panedWidgetClass, parent, NULL, 0);
}
/*
* sets a viewport's dimensions
*/
void
SeSetViewportDimensions(viewport, child, max_height)
Widget viewport,
child;
Dimension max_height;
{
SeSetWidgetWidth(viewport, SeWidgetWidth(child) + 14);
if (SeWidgetHeight(child) > max_height)
SeSetWidgetHeight(viewport, max_height);
}
/*
* sets a viwport's dimensions according to a child list
*/
void
SeSetViewportDimFromList(viewport, list, rows)
Widget viewport,
list;
Cardinal rows;
{
XFontStruct *font;
Dimension height,
internalHeight,
rowSpacing,
borderWidth;
Cardinal n;
Arg args[5];
n = 0;
XtSetArg(args[n], XtNfont, &font);
n++;
XtSetArg(args[n], XtNinternalHeight, &internalHeight);
n++;
XtSetArg(args[n], XtNrowSpacing, &rowSpacing);
n++;
XtSetArg(args[n], XtNborderWidth, &borderWidth);
n++;
XtGetValues(list, args, n);
height = font->ascent + font->descent;
height = height * rows + rowSpacing * (rows - 1) +
2 * (internalHeight + borderWidth);
SeSetViewportDimensions(viewport, list, height);
}
/*
* sets a viwport's dimensions according to a child multi-list
*/
void
SeSetViewportDimFromMultiList(viewport, list, rows)
Widget viewport,
list;
Cardinal rows;
{
Dimension rowHeight,
borderWidth;
Cardinal n;
Arg args[2];
n = 0;
XtSetArg(args[n], XtNrowHeight, &rowHeight);
n++;
XtSetArg(args[n], XtNborderWidth, &borderWidth);
n++;
XtGetValues(list, args, n);
SeSetViewportDimensions(viewport, list,
rowHeight * rows + 2 * borderWidth);
}
/*
* creates a transient popup
*/
Widget
SeCreatePopup(name, parent)
String name;
Widget parent;
{
return SeAddPopup(name, parent);
}
Widget
GetShell(w)
Widget w;
{
while ((w != NULL) && !XtIsShell(w))
w = XtParent(w);
return (w);
}
/*
* Creates a popup with a bit more control on geometry.
* WG = With Geometry
*/
void
CenterShell(widget, geomParent)
Widget widget,
geomParent;
{
Dimension width, height, borderWidth;
Position x, y, max;
XtVaGetValues(geomParent, XtNwidth, &width, XtNheight, &height, NULL);
XtTranslateCoords(geomParent, (Position)width/2, (Position)height/2,
&x, &y);
widget = GetShell(widget);
if (!XtIsRealized(widget)) XtRealizeWidget(widget);
XtVaGetValues(widget, XtNwidth, &width, XtNheight, &height, XtNborderWidth,
&borderWidth, NULL);
width += 2 * borderWidth;
height += 2 * borderWidth;
x -= (Position)width/2;
if (x < 0) x = 0;
if (x > (max = (Position)(XtScreen(widget)->width - width))) x = max;
y -= (Position)height/2;
if (y < 0) y = 0;
if (y > (max = (Position)(XtScreen(widget)->height - height))) y = max;
XtVaSetValues(widget, XtNx, x, XtNy, y, NULL);
}
Widget
SeAddPopupWG(name, parent, x_widget, y_widget, x_offset, y_offset, topLev,
setGeom)
String name;
Widget parent,
x_widget,
y_widget;
Position x_offset,
y_offset;
Boolean topLev;
Boolean setGeom;
{
Widget popup;
Position x,
y,
dummy;
if (x_widget == NULL)
x_widget = parent;
if (y_widget == NULL)
y_widget = x_widget;
if (topLev)
popup = XtVaCreatePopupShell(name, topLevelShellWidgetClass, parent,
XtNiconPixmap, progIcon, NULL);
else
popup = XtVaCreatePopupShell(name, transientShellWidgetClass, parent,
XtNtransientFor, GetShell(parent),
XtNiconPixmap, progIcon, NULL);
if (setGeom) {
XtTranslateCoords(x_widget, x_offset, (Position)0, &x, &dummy);
XtTranslateCoords(y_widget, (Position)0, y_offset, &dummy, &y);
XtVaSetValues(popup, XtNx, x, XtNy, y, NULL);
}
return popup;
}
Widget
AddSimplePopup(name, parent)
String name;
Widget parent;
{
return XtVaCreatePopupShell(name, transientShellWidgetClass, parent,
XtNtransientFor, GetShell(parent),
XtNiconPixmap, progIcon, NULL);
}
Widget
SeAddPopup(name, parent)
String name;
Widget parent;
{
return SeAddPopupWG(name, parent, NULL, NULL, SeWidgetWidth(parent) / 2,
SeWidgetHeight(parent), False, True);
}
Widget
SeAddPopupOffset(name, parent, geomParent)
String name;
Widget parent;
Widget geomParent;
{
return SeAddPopupWG(name, parent, geomParent, geomParent, 10, 10, False,
True);
}
Widget
SeAddPopupUL(name, parent)
String name;
Widget parent;
{
return SeAddPopupOffset(name, parent, XtParent(parent));
}
Widget
SeAddPopupSh(name, parent)
String name;
Widget parent;
{
return SeAddPopupOffset(name, parent, GetShell(parent));
}
/*
* creates a top-level popup
*/
Widget
SeCreateTopLevelPopup(name, parent, x_widget, y_widget)
String name;
Widget parent,
x_widget,
y_widget;
{
Arg args[5];
Position x,
y,
dummy;
Dimension width,
height;
Cardinal n;
if (x_widget == NULL)
x_widget = parent;
if (y_widget == NULL)
y_widget = x_widget;
n = 0;
XtSetArg(args[n], XtNwidth, &width);
n++;
XtGetValues(x_widget, args, n);
XtTranslateCoords(x_widget, (Position) (width / 2),
(Position) 0, &x, &dummy);
n = 0;
XtSetArg(args[n], XtNheight, &height);
n++;
XtGetValues(y_widget, args, n);
XtTranslateCoords(y_widget, (Position) 0, (Position) height,
&dummy, &y);
/*
XtSetArg(args[n], XtNinternalHeight, &internalHeight); n++;
XtTranslateCoords(y_widget, (Position) 0,
(Position) (height + 2 * internalHeight),
&dummy, &y);
*/
n = 0;
XtSetArg(args[n], XtNx, x);
n++;
XtSetArg(args[n], XtNy, y);
n++;
return XtCreatePopupShell(name, topLevelShellWidgetClass,
parent, args, n);
}
/*
* pops up a message
*/
void
SePopupMsg(parent, msg)
Widget parent;
String msg;
{
Widget popup,
dialog;
Arg args;
popup = SeCreatePopup("message", parent);
XtSetArg(args, XtNlabel, msg);
dialog = XtCreateManagedWidget("dialog", dialogWidgetClass, popup,
&args, 1);
XawDialogAddButton(dialog, "dismiss", DestroyPopupPrompt,
(XtPointer) dialog);
XtPopup(popup, XtGrabExclusive);
}
void
SePopupMsgf(parent, fmt, a, b, c)
Widget parent;
String fmt,
a,
b,
c;
{
char buf[REG_BUF];
sprintf(buf, fmt, a, b, c);
SePopupMsg(parent, buf);
}
Widget
SePopupNotice(parent, title, call_back, msg)
Widget parent;
String title;
void (*call_back) ();
String msg;
{
Widget popup,
dialog;
popup = SeAddPopupUL("notice", parent);
XtVaSetValues(popup, XtNtitle, title, NULL);
dialog = XtVaCreateManagedWidget("dialog", dialogWidgetClass, popup,
XtNlabel, msg, NULL);
XawDialogAddButton(dialog, "dismiss", call_back, (XtPointer) dialog);
XtPopup(popup, XtGrabExclusive);
return popup;
}
void
SePopupNoticeF(parent, title, call_back, fmt, a, b, c, d)
Widget parent;
String title;
void (*call_back) ();
String fmt,
a,
b,
c,
d;
{
char buf[REG_BUF];
sprintf(buf, fmt, a, b, c);
SePopupNotice(parent, title, call_back, buf);
}
/*
* almost similar to the above
*/
void
SeTransMsg(name, parent)
String name;
Widget parent;
{
Widget popup,
dialog;
popup = SeCreatePopup(name, parent);
dialog = XtCreateManagedWidget("dialog", dialogWidgetClass, popup,
NULL, 0);
XawDialogAddButton(dialog, "dismiss", DestroyPopupPrompt,
(XtPointer) dialog);
XtPopupSpringLoaded(popup);
}
/*
* pops up a message to the effect that a feature is not implemented
*/
void
NotImplemented(w)
Widget w;
{
SeTransMsg("notImplemented", w);
}
void
SeSetValue(widget, name, value)
Widget widget;
String name;
XtArgVal value;
{
Arg args;
XtSetArg(args, name, value);
XtSetValues(widget, &args, 1);
}
/*
* returns a widget's height
*/
Dimension
SeWidgetHeight(widget)
Widget widget;
{
Dimension height;
Arg args;
XtSetArg(args, XtNheight, &height);
XtGetValues(widget, &args, 1);
return height;
}
/*
* sets a widget's height
*/
void
SeSetWidgetHeight(widget, height)
Widget widget;
Dimension height;
{
Arg args;
XtSetArg(args, XtNheight, height);
XtSetValues(widget, &args, 1);
}
/*
* returns a widget's width
*/
Dimension
SeWidgetWidth(widget)
Widget widget;
{
Dimension width;
Arg args;
XtSetArg(args, XtNwidth, &width);
XtGetValues(widget, &args, 1);
return width;
}
/*
* sets a widget's width
*/
void
SeSetWidgetWidth(widget, width)
Widget widget;
Dimension width;
{
Arg args;
XtSetArg(args, XtNwidth, width);
XtSetValues(widget, &args, 1);
}
/*
* sets the status message
*/
void
SetStatusMessage(msg)
String msg;
{
SeSetLabel(statusMessage, msg);
/* XFlush(XtDisplay(statusMessage));*/
}
/*
* similar to the above, but accepts a formmat string
*/
void
SetStatusMessagef(fmt, a, b, c)
String fmt,
a,
b,
c;
{
char buffer[REG_BUF];
sprintf(buffer, fmt, a, b, c);
SetStatusMessage(buffer);
}
/*
* beeps the bell
*/
void
SeBeep(widget)
Widget widget;
{
XBell(XtDisplay(widget), 10);
}
void
Beep()
{
XBell(XtDisplay(topLevel), 10);
}
/*
* displays a file in a popup
*/
void
SeDisplayFile(parent, geomParent, file_name)
Widget parent;
Widget geomParent;
XtPointer file_name;
{
Widget popup,
form;
if (geomParent == NULL)
geomParent = parent;
popup = SeAddPopupOffset("display", parent, geomParent);
form = SeAddForm("form", popup);
XtVaCreateManagedWidget("text", asciiTextWidgetClass, form, XtNtype,
XawAsciiFile, XtNstring, (String) file_name,
NULL);
SeAddButton("dismiss", form, DestroyShellCallBack);
XtPopup(popup, XtGrabExclusive);
}
/*
* pops up a file for editing
*/
void
EditFile(parent, file_name)
Widget parent;
XtPointer file_name;
{
Widget popup,
form,
text;
popup = AddSimplePopup("edit", parent);
form = SeAddForm("form", popup);
text = XtVaCreateManagedWidget("text", asciiTextWidgetClass, form, XtNtype,
XawAsciiFile, XtNstring, (String) file_name, NULL);
SeAddButtonWCD("save", form, SeEditSaveFile, text);
SeAddButton("dismiss", form, DestroyShellCallBack);
PopupCentered(popup, parent);
}
/*
* saves the file being edited
*/
void
SeEditSaveFile(widget, text)
Widget widget;
XtPointer text;
{
Widget textSource;
Arg args;
XtSetArg(args, XtNtextSource, &textSource);
XtGetValues(text, &args, 1);
if (XawAsciiSave(textSource) != True)
SePopupMsg(widget, "File Save Failed");
}
jmp_buf MainLoopEnv;
void
SeAppMainLoop(app_context)
XtAppContext app_context;
{
DoMainLoop = True;
while (DoMainLoop)
XtAppProcessEvent(app_context, XtIMAll);
}
void
StopMainLoop()
{
DoMainLoop = False;
}
void
SeAppMSleep(app_context, msec)
XtAppContext app_context;
unsigned long msec;
{
Widget widget = statusMessage;
XtAppAddTimeOut(app_context, msec, (XtTimerCallbackProc) StopMainLoop, NULL);
XtAddGrab(widget, True, False);
SeAppMainLoop(app_context);
XtRemoveGrab(widget);
}