1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
/*
* File: msgwin.c
* Purpose: Implement the message box.
* Author: Lars Wirzenius
* Version: "@(#)SeX:$Id: msgwin.c,v 1.3 1996/10/16 06:34:24 liw Exp $"
*/
#include <assert.h>
#include <ctype.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/Scrollbar.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Label.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Box.h>
#include <X11/Xaw/AsciiText.h>
#include <publib.h>
#include "msgwin.h"
#include "cmd.h"
#include "win.h"
#include "x.h"
#include "error.h"
/*
* Structure: msgwin
* Purpose: Descriptor for the message box.
* Fields: shell the top level widget for the dialog
*/
struct msgwin {
struct win *win;
Widget shell, msg, dismiss;
unsigned positioned:1;
};
/*
* Prototypes for local functions.
*/
static void delete_ep(Widget);
static void do_dismiss(Widget, XtPointer, XtPointer);
int msgwin_create(struct msgwin **ep, struct win *win) {
Widget form;
XtTranslations trans;
const int buttondist = 10;
*ep = malloc(sizeof(struct msgwin));
if (*ep == NULL) {
error(win, "malloc failed, can't create msgwin");
return -1;
}
(*ep)->win = win;
(*ep)->positioned = 0;
(*ep)->shell = XtVaCreatePopupShell("msgwin",
transientShellWidgetClass, win_toplevel(win),
XtNallowShellResize, True,
XtNinput, True,
NULL);
form = XtVaCreateManagedWidget(
"form",
formWidgetClass,
(*ep)->shell,
XtNresizable, True,
NULL);
(*ep)->msg = XtVaCreateManagedWidget(
"msg",
labelWidgetClass,
form,
XtNlabel, "Message has not been set yet (bug?)",
XtNwidth, 300,
XtNborderWidth, 0,
XtNtop, XtChainTop,
XtNbottom, XtChainTop,
XtNleft, XtChainLeft,
XtNright, XtChainRight,
NULL);
(*ep)->dismiss = XtVaCreateManagedWidget(
"dismiss",
commandWidgetClass,
form,
XtNlabel, "Dismiss",
XtNfromVert, (*ep)->msg,
XtNvertDistance, buttondist,
XtNtop, XtChainTop,
XtNbottom, XtChainTop,
XtNleft, XtChainLeft,
XtNright, XtChainLeft,
XtNinput, True,
NULL);
XtAddCallback((*ep)->dismiss, XtNcallback, do_dismiss, *ep);
trans = XtParseTranslationTable(
"<Key>Return: dismiss_message() \n"
"<Key>Escape: dismiss_message() \n");
XtOverrideTranslations((*ep)->dismiss, trans);
XtRealizeWidget((*ep)->shell);
x_set_wm_protocols((*ep)->shell, delete_ep);
XtSetKeyboardFocus((*ep)->shell, (*ep)->dismiss);
return 0;
}
void msgwin_destroy(struct msgwin *mw) {
XtDestroyWidget(mw->shell);
}
/*
* Function: msgwin_popup
* Purpose: Pop up a dialog box.
* Arguments: ep the dialog box
* Return: Nothing.
*/
void msgwin_popup(struct msgwin *ep) {
Position x, y;
Dimension width, height;
Widget top;
if (!ep->positioned) {
top = win_toplevel(ep->win);
XtVaGetValues(top, XtNwidth, &width, XtNheight, &height, NULL);
XtTranslateCoords(top, (Position) 30, (Position) 30, &x, &y);
XtVaSetValues(ep->shell, XtNx, x, XtNy, y, NULL);
ep->positioned = 1;
}
XtPopup(ep->shell, XtGrabNone);
}
/*
* Function: msgwin_popdown
* Purpose: Close a dialog box.
* Arguments: ep the dialog
* Return: Nothing.
*/
void msgwin_popdown(struct msgwin *ep) {
XtPopdown(ep->shell);
}
/*
* Function: msgwin_contains
* Purpose: Check whether a dialog contains a widget.
* Arguments: ep the dialog
* wid the widget
* Return: True or false.
*/
int msgwin_contains(struct msgwin *ep, Widget wid) {
return ep->shell == wid || ep->msg == wid || ep->dismiss == wid;
}
/*
* Function: msgwin_set
* Purpose: Set message displayed in message window.
* Arguments: mw the message window
* str the message
* Return: Nothing.
*/
void msgwin_set(struct msgwin *mw, const char *str) {
XtVaSetValues(mw->msg, XtNlabel, str, XtNwidth, 9*strlen(str), NULL);
}
/***********************************************************************
* Local functions follow.
*/
/*
* Function: delete_ep
* Purpose: React to WM_DELETE by closing the dialog box.
* Arguments: wid the widget that got WM_DELETE
* Return: Nothing.
*/
static void delete_ep(Widget wid) {
XtPopdown(wid);
}
/*
* Pop down a dialog box.
*/
static void do_dismiss(Widget w, XtPointer client_data, XtPointer foo) {
msgwin_popdown((struct msgwin *) client_data);
}
|