1 /*********************************************************************/
2 /* bibView: Administration of BibTeX-Databases */
3 /* (Verwaltung von BibTeX-Literaturdatenbanken) */
4 /* */
5 /* Module: gui_widg.c */
6 /* */
7 /* GUI: Widgets and misc functions */
8 /* - Notice/Warning/Error windows */
9 /* */
10 /* Author: Holger Martin, martinh@informatik.tu-muenchen.de */
11 /* Peter M. Urban, urban@informatik.tu-muenchen.de */
12 /* */
13 /* History: */
14 /* 12.05.91 PMU created */
15 /* 05.26.92 Version 1.0 released */
16 /* */
17 /* Copyright 1992 TU MUENCHEN */
18 /* See ./Copyright for complete rights and liability information. */
19 /* */
20 /*********************************************************************/
21
22 #include <stdio.h>
23 #include <X11/Intrinsic.h>
24 #include <X11/StringDefs.h>
25 #include <X11/Shell.h>
26 #include <X11/Xaw/Form.h>
27 #include <X11/Xaw/Paned.h>
28 #include <X11/Xaw/Box.h>
29 #include <X11/Xaw/Command.h>
30 #include <X11/Xaw/Dialog.h>
31 #include <X11/Xaw/Viewport.h>
32 #include <X11/Xaw/List.h>
33 #include "bibview.h"
34
35
36 /* imported global variables */
37 /* ------------------------- */
38 extern Widget topLevel, desktop, mainMenu;
39 extern Pixmap errorPixmap;
40 extern Pixmap warnPixmap;
41 extern Pixmap noticePixmap;
42 extern Pixmap confirmPixmap;
43 extern Pixmap progInfoPixmap;
44 extern Pixmap questPixmap;
45
46
47 /* exported global variables */
48 /* ------------------------- */
49
50
51 /* local global variables */
52 /* ---------------------- */
53 static Widget selShell;
54 static BibPtr *bibptrArgv;
55 static String *bibselArgv;
56 static int bibselArgc;
57
58
59 /* local function prototypes */
60 /* ------------------------- */
61 static void selectBibOK (Widget w, XtPointer ClientData, XtPointer CallData);
62 static void selectBibCancel (Widget w, XtPointer ClientData, XtPointer CallData);
63 static void closeMsgWin (Widget w, XtPointer clientData, XtPointer callData);
64 static void closeProgInfoWin (Widget w, XtPointer clientData, XtPointer callData);
65
66
67 /*********************************************************************/
68 /* guwSelectBib: */
69 /* Display List of opened bibs to select one */
70 /*********************************************************************/
71 Errcode
guwSelectBib(String head,CtlFuncPtr ctlFunc)72 guwSelectBib(String head, CtlFuncPtr ctlFunc)
73 {
74 static Widget selForm, selLabel, selVport, selList, selQuit;
75 BibPtr bp;
76 Position dx, dy, x, y;
77 int i = 0;
78
79 /* check number of opened bibs */
80 if ((bibselArgc = gubNoOfOpenBibs()) == 0)
81 return(ERR_NOBIBOPEN);
82
83 /* create argv for list */
84 if ((bibselArgv = (String *)XtCalloc(bibselArgc, sizeof(String))) == NULL)
85 return(ERR_NOMALLOC);
86 if ((bibptrArgv = (BibPtr *)XtCalloc(bibselArgc, sizeof(BibPtr))) == NULL) {
87 XtFree((char *)bibselArgv);
88 return(ERR_NOMALLOC);
89 }
90 bp = glbFirstBibListEl();
91 i = 0;
92 while (bp != NULL) {
93 bibptrArgv[i] = bp;
94 bibselArgv[i] = bp->filepath;
95 bp = glbNextBibListEl(bp);
96 i++;
97 }
98
99 /* display window */
100 XtVaGetValues(desktop,
101 XtNx, &dx,
102 XtNy, &dy, NULL);
103 XtTranslateCoords(desktop,
104 (Position)dx + SUBWIN_MARGIN,
105 (Position)dy + SUBWIN_MARGIN,
106 &x, &y);
107 selShell = XtVaCreatePopupShell("bibselShell",
108 transientShellWidgetClass, topLevel,
109 XtNx, x, XtNy, y, NULL);
110 selForm = XtVaCreateManagedWidget("bibselWin",
111 formWidgetClass, selShell, NULL);
112 selLabel = XtVaCreateManagedWidget(head,
113 labelWidgetClass, selForm,
114 XtNborderWidth, 0,
115 XtNleft, XtChainLeft,
116 XtNtop, XtChainTop, NULL);
117 selVport = XtVaCreateManagedWidget("bibselVport",
118 viewportWidgetClass, selForm,
119 XtNallowVert, True,
120 XtNfromVert, selLabel, NULL);
121 selList = XtVaCreateManagedWidget("bibselLst",
122 listWidgetClass, selVport,
123 XtNnumberStrings, bibselArgc,
124 XtNlist, bibselArgv,
125 XtNforceColumns, True,
126 XtNdefaultColumns, 1, NULL);
127 selQuit = XtVaCreateManagedWidget("cancel",
128 commandWidgetClass, selForm,
129 XtNfromVert, selVport,
130 XtNleft, XtChainLeft, NULL);
131
132 XtAddCallback(selList, XtNcallback, selectBibOK, (XtPointer)ctlFunc);
133 XtAddCallback(selQuit, XtNcallback, selectBibCancel, NULL);
134
135 XtSetSensitive(mainMenu, FALSE);
136 gubSetSensitive(NULL, FALSE);
137 XtPopup(selShell, XtGrabNonexclusive);
138 return(OK);
139 }
140
141
142 /*********************************************************************/
143 /* selectBibOK: */
144 /* Callback for select bib list entries */
145 /*********************************************************************/
146 static void
selectBibOK(Widget w,XtPointer clientData,XtPointer callData)147 selectBibOK (Widget w, XtPointer clientData, XtPointer callData)
148 {
149 XawListReturnStruct *item = (XawListReturnStruct*)callData;
150 CtlFuncPtr ctlFunc = (CtlFuncPtr)clientData;
151 BibPtr bp;
152
153 XtPopdown(selShell);
154 XSync(XtDisplay(selShell), 1);
155 XtSetSensitive(mainMenu, TRUE);
156 gubSetSensitive(NULL, TRUE);
157
158 bp = bibptrArgv[item->list_index];
159 XtFree((char *)bibptrArgv);
160 XtFree((char *)bibselArgv);
161 (ctlFunc) (bp);
162 }
163
164
165 /*********************************************************************/
166 /* selectBibCancel: */
167 /* Callback for Cancel button of select bib shell */
168 /*********************************************************************/
169 static void
selectBibCancel(Widget w,XtPointer ClientData,XtPointer CallData)170 selectBibCancel (Widget w, XtPointer ClientData, XtPointer CallData)
171 {
172
173 XtPopdown(selShell);
174 XtFree((char *)bibptrArgv);
175 XtFree((char *)bibselArgv);
176 XtSetSensitive(mainMenu, TRUE);
177 gubSetSensitive(NULL, TRUE);
178 }
179
180 /*********************************************************************/
181 /* guwConfirmClose: */
182 /* Opens dialogbox for user to confirm closing without saving */
183 /*********************************************************************/
184 void
guwConfirmClose(Position x,Position y,XtCallbackProc p1,XtCallbackProc p2)185 guwConfirmClose (Position x, Position y, XtCallbackProc p1, XtCallbackProc p2)
186 {
187 static Widget conShell, conDialog, conOKButton, conQuitButton;
188
189 conShell = XtVaCreatePopupShell("confirmQuitShell",
190 transientShellWidgetClass, topLevel,
191 XtNx, x, XtNy, y, NULL);
192 conDialog = XtVaCreateManagedWidget("confirmQuitBox",
193 dialogWidgetClass, conShell,
194 XtNicon, questPixmap, NULL);
195 conOKButton = XtVaCreateManagedWidget("ok",
196 commandWidgetClass, conDialog, NULL);
197 conQuitButton = XtVaCreateManagedWidget("cancel",
198 commandWidgetClass, conDialog, NULL);
199 XtAddCallback(conQuitButton, XtNcallback, p1, conShell);
200 XtAddCallback(conOKButton, XtNcallback, p2, conShell);
201
202 XtSetSensitive(mainMenu, FALSE);
203 gubSetSensitive(NULL, FALSE);
204 XtPopup(conShell, XtGrabNonexclusive);
205 }
206
207
208 /*********************************************************************/
209 /* guwConfirmDelete: */
210 /* Opens dialogbox for user to confirm deleting an entry */
211 /*********************************************************************/
212 void
guwConfirmDelete(Position x,Position y,XtCallbackProc p1,XtCallbackProc p2)213 guwConfirmDelete (Position x, Position y, XtCallbackProc p1, XtCallbackProc p2)
214 {
215 static Widget conShell, conDialog, conOKButton, conQuitButton;
216
217 conShell = XtVaCreatePopupShell("confirmDeleteShell",
218 transientShellWidgetClass, topLevel,
219 XtNx, x, XtNy, y, NULL);
220 conDialog = XtVaCreateManagedWidget("confirmDeleteBox",
221 dialogWidgetClass, conShell,
222 XtNicon, questPixmap, NULL);
223 conOKButton = XtVaCreateManagedWidget("ok",
224 commandWidgetClass, conDialog, NULL);
225 conQuitButton = XtVaCreateManagedWidget("cancel",
226 commandWidgetClass, conDialog, NULL);
227 XtAddCallback(conQuitButton, XtNcallback, p1, conShell);
228 XtAddCallback(conOKButton, XtNcallback, p2, conShell);
229
230 XtSetSensitive(mainMenu, FALSE);
231 gubSetSensitive(NULL, FALSE);
232 XtPopup(conShell, XtGrabNonexclusive);
233 }
234
235
236 /*********************************************************************/
237 /* guwError: */
238 /* Display error message in a popup shell on desktop */
239 /*********************************************************************/
240 void
guwError(Errcode errcode)241 guwError (Errcode errcode)
242 {
243 static Widget errShell, errForm, errIcon, errType, errText, errOKButton;
244 char textLabel[20];
245 Window rw, cw;
246 int xw, yw;
247 int x, y;
248 unsigned int key_buttons;
249
250 XQueryPointer(XtDisplay(topLevel),
251 DefaultRootWindow(XtDisplay(topLevel)),
252 &rw, &cw, &x, &y, &xw, &yw, &key_buttons);
253
254 errShell = XtVaCreatePopupShell("errorShell",
255 transientShellWidgetClass, topLevel,
256 XtNx, x, XtNy, y, NULL);
257 errForm = XtVaCreateManagedWidget("errorWin",
258 formWidgetClass, errShell, NULL);
259 errIcon = XtVaCreateManagedWidget("errorIcon",
260 labelWidgetClass, errForm,
261 XtNborderWidth, 0,
262 XtNtop, XtChainTop,
263 XtNleft, XtChainLeft,
264 XtNbitmap, errorPixmap, NULL);
265 errType = XtVaCreateManagedWidget("type",
266 labelWidgetClass, errForm,
267 XtNjustify, XtJustifyLeft,
268 XtNborderWidth, 0,
269 XtNtop, XtChainTop,
270 XtNfromHoriz, errIcon, NULL);
271 sprintf(textLabel, "msgText%d", abs((int)errcode));
272 errText = XtVaCreateManagedWidget(textLabel,
273 labelWidgetClass, errForm,
274 XtNjustify, XtJustifyLeft,
275 XtNborderWidth, 0,
276 XtNfromVert, errType,
277 XtNfromHoriz, errIcon, NULL);
278 errOKButton = XtVaCreateManagedWidget("ok",
279 commandWidgetClass, errForm,
280 XtNfromVert, errText,
281 XtNbottom, XtChainBottom,
282 XtNfromHoriz, errIcon, NULL);
283
284 XtAddCallback(errOKButton, XtNcallback, closeMsgWin, errShell);
285
286 XtSetSensitive(mainMenu, FALSE);
287 gubSetSensitive(NULL, FALSE);
288 if (cotBeepOnError())
289 XBell(XtDisplay(topLevel), 100);
290 XtPopup(errShell, XtGrabNonexclusive);
291 }
292
293
294 /*********************************************************************/
295 /* guwWarning: */
296 /* Display warning message in a popup shell on desktop */
297 /*********************************************************************/
298 void
guwWarning(Errcode errcode)299 guwWarning (Errcode errcode)
300 {
301 static Widget warnShell, warnForm, warnIcon,
302 warnType, warnText, warnOKButton;
303 char textLabel[20],
304 warnLabel[120];
305 Window rw, cw;
306 int xw, yw;
307 int x, y;
308 unsigned int key_buttons;
309
310 XQueryPointer(XtDisplay(topLevel),
311 DefaultRootWindow(XtDisplay(topLevel)),
312 &rw, &cw, &x, &y, &xw, &yw, &key_buttons);
313
314 warnShell = XtVaCreatePopupShell("warnShell",
315 transientShellWidgetClass, topLevel,
316 XtNx, x, XtNy, y, NULL);
317 warnForm = XtVaCreateManagedWidget("warnWin",
318 formWidgetClass, warnShell, NULL);
319 warnIcon = XtVaCreateManagedWidget("warnIcon",
320 labelWidgetClass, warnForm,
321 XtNborderWidth, 0,
322 XtNtop, XtChainTop,
323 XtNleft, XtChainLeft,
324 XtNbitmap, warnPixmap, NULL);
325 warnType = XtVaCreateManagedWidget("type",
326 labelWidgetClass, warnForm,
327 XtNjustify, XtJustifyLeft,
328 XtNborderWidth, 0,
329 XtNtop, XtChainTop,
330 XtNfromHoriz, warnIcon, NULL);
331 sprintf(textLabel, "msgText%d", abs((int)errcode));
332 if (errcode >= 200){
333 #ifdef GERMAN
334 sprintf(warnLabel, "Karte unvollstaendig: kein %s",
335 glbFldToName(errcode-200));
336 #else
337 sprintf(warnLabel, "Card incomplete: no %s", glbFldToName(errcode-200));
338 #endif
339 warnText = XtVaCreateManagedWidget(textLabel,
340 labelWidgetClass, warnForm,
341 XtNjustify, XtJustifyLeft,
342 XtNborderWidth, 0,
343 XtNfromVert, warnType,
344 XtNlabel, warnLabel,
345 XtNfromHoriz, warnIcon, NULL);
346 }
347 else
348 warnText = XtVaCreateManagedWidget(textLabel,
349 labelWidgetClass, warnForm,
350 XtNjustify, XtJustifyLeft,
351 XtNborderWidth, 0,
352 XtNfromVert, warnType,
353 XtNfromHoriz, warnIcon, NULL);
354 warnOKButton = XtVaCreateManagedWidget("ok",
355 commandWidgetClass, warnForm,
356 XtNfromVert, warnText,
357 XtNbottom, XtChainBottom,
358 XtNfromHoriz, warnIcon, NULL);
359
360 XtAddCallback(warnOKButton, XtNcallback, closeMsgWin, warnShell);
361
362 XtSetSensitive(mainMenu, FALSE);
363 gubSetSensitive(NULL, FALSE);
364 if (cotBeepOnError())
365 XBell(XtDisplay(topLevel), 100);
366 XtPopup(warnShell, XtGrabNonexclusive);
367 }
368
369
370 /*********************************************************************/
371 /* guwNotice: */
372 /* Display notice message in a popup shell on desktop */
373 /*********************************************************************/
374 void
guwNotice(Errcode errcode)375 guwNotice (Errcode errcode)
376 {
377 static Widget noticeShell, noticeForm, noticeIcon, noticeType,
378 noticeText, noticeOKButton;
379 char textLabel[20];
380 Window rw, cw;
381 int xw, yw;
382 int x, y;
383 unsigned int key_buttons;
384
385 XQueryPointer(XtDisplay(topLevel),
386 DefaultRootWindow(XtDisplay(topLevel)),
387 &rw, &cw, &x, &y, &xw, &yw, &key_buttons);
388
389 noticeShell = XtVaCreatePopupShell("noticeShell",
390 transientShellWidgetClass, topLevel,
391 XtNx, x, XtNy, y, NULL);
392 noticeForm = XtVaCreateManagedWidget("noticeWin",
393 formWidgetClass, noticeShell, NULL);
394 noticeIcon = XtVaCreateManagedWidget("noticeIcon",
395 labelWidgetClass, noticeForm,
396 XtNborderWidth, 0,
397 XtNtop, XtChainTop,
398 XtNleft, XtChainLeft,
399 XtNbitmap, noticePixmap, NULL);
400 noticeType = XtVaCreateManagedWidget("type",
401 labelWidgetClass, noticeForm,
402 XtNborderWidth, 0,
403 XtNjustify, XtJustifyLeft,
404 XtNtop, XtChainTop,
405 XtNfromHoriz, noticeIcon, NULL);
406 sprintf(textLabel, "msgText%d", abs((int)errcode));
407 noticeText = XtVaCreateManagedWidget(textLabel,
408 labelWidgetClass, noticeForm,
409 XtNborderWidth, 0,
410 XtNjustify, XtJustifyLeft,
411 XtNfromVert, noticeType,
412 XtNfromHoriz, noticeIcon, NULL);
413 noticeOKButton = XtVaCreateManagedWidget("ok",
414 commandWidgetClass, noticeForm,
415 XtNfromVert, noticeText,
416 XtNbottom, XtChainBottom,
417 XtNfromHoriz, noticeIcon, NULL);
418
419 XtAddCallback(noticeOKButton, XtNcallback, closeMsgWin, noticeShell);
420
421 XtSetSensitive(mainMenu, FALSE);
422 gubSetSensitive(NULL, FALSE);
423 if (cotBeepOnError())
424 XBell(XtDisplay(topLevel), 100);
425 XtPopup(noticeShell, XtGrabNonexclusive);
426 }
427
428
429 /*********************************************************************/
430 /* CloseMsgWin: */
431 /* Callback function for OK button in message windows */
432 /*********************************************************************/
433 static void
closeMsgWin(Widget w,XtPointer clientData,XtPointer callData)434 closeMsgWin (Widget w, XtPointer clientData, XtPointer callData)
435 {
436 Widget shell = (Widget)clientData;
437
438 XtSetSensitive(mainMenu, TRUE);
439 gubSetSensitive(NULL, TRUE);
440 XtPopdown(shell);
441 }
442
443
444 /*********************************************************************/
445 /* guwProgInfo: */
446 /* Display programm information */
447 /*********************************************************************/
448 void
guwProgInfo(Widget w,XtPointer clientData,XtPointer callData)449 guwProgInfo (Widget w, XtPointer clientData, XtPointer callData)
450 {
451 static Widget piShell, piIcon;
452 Position dx, dy, x, y;
453
454 XtVaGetValues(desktop,
455 XtNx, &dx,
456 XtNy, &dy, NULL);
457 XtTranslateCoords(desktop,
458 (Position)dx + SUBWIN_MARGIN,
459 (Position)dy + SUBWIN_MARGIN,
460 &x, &y);
461 piShell = XtVaCreatePopupShell("progInfoShell",
462 transientShellWidgetClass, topLevel,
463 XtNx, x, XtNy, y, NULL);
464 piIcon = XtVaCreateManagedWidget("progInfo",
465 commandWidgetClass, piShell,
466 XtNbitmap, progInfoPixmap, NULL);
467
468 XtAddCallback(piIcon, XtNcallback, closeProgInfoWin, piShell);
469 XtPopup(piShell, XtGrabNonexclusive);
470 }
471
472
473 /*********************************************************************/
474 /* CloseProgInfoWin: */
475 /* Callback function for OK button in message windows */
476 /*********************************************************************/
477 static void
closeProgInfoWin(Widget w,XtPointer clientData,XtPointer callData)478 closeProgInfoWin (Widget w, XtPointer clientData, XtPointer callData)
479 {
480 Widget shell = (Widget)clientData;
481
482 XtPopdown(shell);
483 }
484
485
486