File: gui_widg.c

package info (click to toggle)
bibview 2.2-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,252 kB
  • ctags: 1,588
  • sloc: ansic: 15,149; yacc: 1,145; makefile: 297; lex: 221; sh: 17
file content (485 lines) | stat: -rw-r--r-- 17,312 bytes parent folder | download | duplicates (3)
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
/*********************************************************************/
/*  bibView: Administration of BibTeX-Databases                      */
/*           (Verwaltung von BibTeX-Literaturdatenbanken)            */
/*                                                                   */
/*  Module:  gui_widg.c                                              */
/*                                                                   */
/*             GUI: Widgets and misc functions                       */
/*             - Notice/Warning/Error windows                        */
/*                                                                   */
/*  Author:  Holger Martin,  martinh@informatik.tu-muenchen.de       */
/*           Peter M. Urban, urban@informatik.tu-muenchen.de         */
/*                                                                   */
/*  History:                                                         */
/*    12.05.91  PMU  created                                         */
/*    05.26.92       Version 1.0 released                            */
/*                                                                   */
/*  Copyright 1992 TU MUENCHEN                                       */
/*    See ./Copyright for complete rights and liability information. */
/*                                                                   */
/*********************************************************************/

#include <stdio.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Paned.h>
#include <X11/Xaw/Box.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Dialog.h>
#include <X11/Xaw/Viewport.h>
#include <X11/Xaw/List.h>
#include "bibview.h"


/* imported global variables */
/* ------------------------- */
extern Widget topLevel, desktop, mainMenu;
extern Pixmap errorPixmap;
extern Pixmap warnPixmap;
extern Pixmap noticePixmap;
extern Pixmap confirmPixmap;
extern Pixmap progInfoPixmap;
extern Pixmap questPixmap;


/* exported global variables */
/* ------------------------- */


/* local global variables */
/* ---------------------- */
static Widget selShell;
static BibPtr *bibptrArgv;
static String *bibselArgv;
static int    bibselArgc;


/* local function prototypes */
/* ------------------------- */
static void selectBibOK (Widget w, XtPointer ClientData, XtPointer CallData);
static void selectBibCancel (Widget w, XtPointer ClientData, XtPointer CallData);
static void closeMsgWin (Widget w, XtPointer clientData, XtPointer callData);
static void closeProgInfoWin (Widget w, XtPointer clientData, XtPointer callData);


/*********************************************************************/
/* guwSelectBib:                                                     */
/*    Display List of opened bibs to select one                      */
/*********************************************************************/
Errcode
guwSelectBib(String head, CtlFuncPtr ctlFunc)
{
static Widget selForm, selLabel, selVport, selList, selQuit;
BibPtr bp;
Position dx, dy, x, y;
int i = 0;

   /* check number of opened bibs */
   if ((bibselArgc = gubNoOfOpenBibs()) == 0)
      return(ERR_NOBIBOPEN);

   /* create argv for list */
   if ((bibselArgv = (String *)XtCalloc(bibselArgc, sizeof(String))) == NULL) 
      return(ERR_NOMALLOC);
   if ((bibptrArgv = (BibPtr *)XtCalloc(bibselArgc, sizeof(BibPtr))) == NULL) {
      XtFree((char *)bibselArgv);
      return(ERR_NOMALLOC);
   }
   bp = glbFirstBibListEl();
   i = 0;
   while (bp != NULL) {
      bibptrArgv[i] = bp;
      bibselArgv[i] = bp->filepath;
      bp = glbNextBibListEl(bp);
      i++;
   }

   /* display window */
   XtVaGetValues(desktop,
                 XtNx, &dx,
                 XtNy, &dy, NULL);
   XtTranslateCoords(desktop,
                     (Position)dx + SUBWIN_MARGIN,
                     (Position)dy + SUBWIN_MARGIN,
                     &x, &y);
   selShell = XtVaCreatePopupShell("bibselShell",
	        transientShellWidgetClass, topLevel, 
		XtNx, x, XtNy, y, NULL);
   selForm  = XtVaCreateManagedWidget("bibselWin",
	        formWidgetClass, selShell, NULL);
   selLabel = XtVaCreateManagedWidget(head,
	        labelWidgetClass, selForm,
		XtNborderWidth, 0,
	        XtNleft, XtChainLeft,
	        XtNtop, XtChainTop, NULL);
   selVport = XtVaCreateManagedWidget("bibselVport",
		viewportWidgetClass, selForm,
		XtNallowVert, True,
		XtNfromVert, selLabel, NULL);
   selList  = XtVaCreateManagedWidget("bibselLst",
		listWidgetClass, selVport,
		XtNnumberStrings, bibselArgc,
		XtNlist, bibselArgv, 
		XtNforceColumns, True,
		XtNdefaultColumns, 1, NULL);
   selQuit  = XtVaCreateManagedWidget("cancel",
	        commandWidgetClass, selForm, 
		XtNfromVert, selVport,
		XtNleft, XtChainLeft, NULL);

   XtAddCallback(selList, XtNcallback, selectBibOK, (XtPointer)ctlFunc);
   XtAddCallback(selQuit, XtNcallback, selectBibCancel, NULL);

   XtSetSensitive(mainMenu, FALSE);
   gubSetSensitive(NULL, FALSE);
   XtPopup(selShell, XtGrabNonexclusive);
   return(OK);
}


/*********************************************************************/
/* selectBibOK:                                                      */
/*    Callback for select bib list entries                           */
/*********************************************************************/
static void
selectBibOK (Widget w, XtPointer clientData, XtPointer callData)
{
XawListReturnStruct *item = (XawListReturnStruct*)callData;
CtlFuncPtr ctlFunc = (CtlFuncPtr)clientData;
BibPtr bp;

   XtPopdown(selShell);
   XSync(XtDisplay(selShell), 1);
   XtSetSensitive(mainMenu, TRUE);
   gubSetSensitive(NULL, TRUE);

   bp = bibptrArgv[item->list_index];
   XtFree((char *)bibptrArgv);
   XtFree((char *)bibselArgv);
   (ctlFunc) (bp);
}


/*********************************************************************/
/* selectBibCancel:                                                  */
/*    Callback for Cancel button of select bib shell                 */
/*********************************************************************/
static void
selectBibCancel (Widget w, XtPointer ClientData, XtPointer CallData)
{

   XtPopdown(selShell);
   XtFree((char *)bibptrArgv);
   XtFree((char *)bibselArgv);
   XtSetSensitive(mainMenu, TRUE);
   gubSetSensitive(NULL, TRUE);
}

/*********************************************************************/
/* guwConfirmClose:                                                  */
/*    Opens dialogbox for user to confirm closing without saving     */
/*********************************************************************/
void
guwConfirmClose (Position x, Position y, XtCallbackProc p1, XtCallbackProc p2)
{
static Widget conShell, conDialog, conOKButton, conQuitButton;

   conShell = XtVaCreatePopupShell("confirmQuitShell",
	        transientShellWidgetClass, topLevel, 
		XtNx, x, XtNy, y, NULL);
   conDialog = XtVaCreateManagedWidget("confirmQuitBox",
	         dialogWidgetClass, conShell, 
		 XtNicon, questPixmap, NULL);
   conOKButton = XtVaCreateManagedWidget("ok",
	           commandWidgetClass, conDialog, NULL);
   conQuitButton = XtVaCreateManagedWidget("cancel",
	           commandWidgetClass, conDialog, NULL);
   XtAddCallback(conQuitButton, XtNcallback, p1, conShell);
   XtAddCallback(conOKButton, XtNcallback, p2, conShell);

   XtSetSensitive(mainMenu, FALSE);
   gubSetSensitive(NULL, FALSE);
   XtPopup(conShell, XtGrabNonexclusive);
}


/*********************************************************************/
/* guwConfirmDelete:                                                 */
/*    Opens dialogbox for user to confirm deleting an entry          */
/*********************************************************************/
void
guwConfirmDelete (Position x, Position y, XtCallbackProc p1, XtCallbackProc p2)
{
static Widget conShell, conDialog, conOKButton, conQuitButton;

   conShell = XtVaCreatePopupShell("confirmDeleteShell",
	        transientShellWidgetClass, topLevel, 
		XtNx, x, XtNy, y, NULL);
   conDialog = XtVaCreateManagedWidget("confirmDeleteBox",
	         dialogWidgetClass, conShell, 
		 XtNicon, questPixmap, NULL);
   conOKButton = XtVaCreateManagedWidget("ok",
	           commandWidgetClass, conDialog, NULL);
   conQuitButton = XtVaCreateManagedWidget("cancel",
	           commandWidgetClass, conDialog, NULL);
   XtAddCallback(conQuitButton, XtNcallback, p1, conShell);
   XtAddCallback(conOKButton, XtNcallback, p2, conShell);

   XtSetSensitive(mainMenu, FALSE);
   gubSetSensitive(NULL, FALSE);
   XtPopup(conShell, XtGrabNonexclusive);
}


/*********************************************************************/
/* guwError:                                                         */
/*    Display error message in a popup shell on desktop              */
/*********************************************************************/
void
guwError (Errcode errcode)
{
static Widget errShell, errForm, errIcon, errType, errText, errOKButton;
char textLabel[20];
Window rw, cw;
int xw, yw;
int x, y;
unsigned int key_buttons;

   XQueryPointer(XtDisplay(topLevel), 
		 DefaultRootWindow(XtDisplay(topLevel)),
		 &rw, &cw, &x, &y, &xw, &yw, &key_buttons);
		 
   errShell = XtVaCreatePopupShell("errorShell",
	        transientShellWidgetClass, topLevel, 
		XtNx, x, XtNy, y, NULL);
   errForm = XtVaCreateManagedWidget("errorWin",
	       formWidgetClass, errShell, NULL);
   errIcon = XtVaCreateManagedWidget("errorIcon",
	       labelWidgetClass, errForm, 
	       XtNborderWidth, 0,
	       XtNtop, XtChainTop,
	       XtNleft, XtChainLeft,
	       XtNbitmap, errorPixmap, NULL);
   errType = XtVaCreateManagedWidget("type",
	       labelWidgetClass, errForm, 
	       XtNjustify, XtJustifyLeft,
	       XtNborderWidth, 0,
	       XtNtop, XtChainTop,
	       XtNfromHoriz, errIcon, NULL);
   sprintf(textLabel, "msgText%d", abs((int)errcode));
   errText = XtVaCreateManagedWidget(textLabel,
	       labelWidgetClass, errForm, 
	       XtNjustify, XtJustifyLeft,
	       XtNborderWidth, 0,
	       XtNfromVert, errType,
	       XtNfromHoriz, errIcon, NULL);
   errOKButton = XtVaCreateManagedWidget("ok",
	           commandWidgetClass, errForm, 
		   XtNfromVert, errText,
		   XtNbottom, XtChainBottom, 
		   XtNfromHoriz, errIcon, NULL);

   XtAddCallback(errOKButton, XtNcallback, closeMsgWin, errShell);

   XtSetSensitive(mainMenu, FALSE);
   gubSetSensitive(NULL, FALSE);
   if (cotBeepOnError())
      XBell(XtDisplay(topLevel), 100);
   XtPopup(errShell, XtGrabNonexclusive);
}


/*********************************************************************/
/* guwWarning:                                                       */
/*    Display warning message in a popup shell on desktop            */
/*********************************************************************/
void
guwWarning (Errcode errcode)
{
static Widget warnShell, warnForm, warnIcon, 
	      warnType, warnText, warnOKButton;
char textLabel[20],
     warnLabel[120];
Window rw, cw;
int xw, yw;
int x, y;
unsigned int key_buttons;

   XQueryPointer(XtDisplay(topLevel), 
		 DefaultRootWindow(XtDisplay(topLevel)),
		 &rw, &cw, &x, &y, &xw, &yw, &key_buttons);
		 
   warnShell    = XtVaCreatePopupShell("warnShell",
	            transientShellWidgetClass, topLevel, 
		    XtNx, x, XtNy, y, NULL);
   warnForm     = XtVaCreateManagedWidget("warnWin",
	            formWidgetClass, warnShell, NULL);
   warnIcon     = XtVaCreateManagedWidget("warnIcon",
	            labelWidgetClass, warnForm, 
	            XtNborderWidth, 0,
	            XtNtop, XtChainTop,
	            XtNleft, XtChainLeft,
	            XtNbitmap, warnPixmap, NULL);
   warnType     = XtVaCreateManagedWidget("type",
	            labelWidgetClass, warnForm, 
		    XtNjustify, XtJustifyLeft,
	            XtNborderWidth, 0,
	            XtNtop, XtChainTop,
	            XtNfromHoriz, warnIcon, NULL);
   sprintf(textLabel, "msgText%d", abs((int)errcode));
   if (errcode >= 200){
   #ifdef GERMAN
      sprintf(warnLabel, "Karte unvollstaendig: kein %s", 
			 glbFldToName(errcode-200));
   #else
      sprintf(warnLabel, "Card incomplete: no %s", glbFldToName(errcode-200));
   #endif
      warnText     = XtVaCreateManagedWidget(textLabel,
  	               labelWidgetClass, warnForm, 
		       XtNjustify, XtJustifyLeft,
	               XtNborderWidth, 0,
	               XtNfromVert, warnType,
	               XtNlabel, warnLabel,
	               XtNfromHoriz, warnIcon, NULL);
      }
   else 
   warnText     = XtVaCreateManagedWidget(textLabel,
	            labelWidgetClass, warnForm, 
		    XtNjustify, XtJustifyLeft,
	            XtNborderWidth, 0,
	            XtNfromVert, warnType,
	            XtNfromHoriz, warnIcon, NULL);
   warnOKButton = XtVaCreateManagedWidget("ok",
	            commandWidgetClass, warnForm, 
		    XtNfromVert, warnText,
		    XtNbottom, XtChainBottom, 
		    XtNfromHoriz, warnIcon, NULL);

   XtAddCallback(warnOKButton, XtNcallback, closeMsgWin, warnShell);

   XtSetSensitive(mainMenu, FALSE);
   gubSetSensitive(NULL, FALSE);
   if (cotBeepOnError())
      XBell(XtDisplay(topLevel), 100);
   XtPopup(warnShell, XtGrabNonexclusive);
}


/*********************************************************************/
/* guwNotice:                                                        */
/*    Display notice message in a popup shell on desktop             */
/*********************************************************************/
void
guwNotice (Errcode errcode)
{
static Widget noticeShell, noticeForm, noticeIcon, noticeType, 
	      noticeText, noticeOKButton;
char textLabel[20];
Window rw, cw;
int xw, yw;
int x, y;
unsigned int key_buttons;

   XQueryPointer(XtDisplay(topLevel), 
		 DefaultRootWindow(XtDisplay(topLevel)),
		 &rw, &cw, &x, &y, &xw, &yw, &key_buttons);
   
   noticeShell    = XtVaCreatePopupShell("noticeShell",
	              transientShellWidgetClass, topLevel, 
		      XtNx, x, XtNy, y, NULL);
   noticeForm     = XtVaCreateManagedWidget("noticeWin",
	              formWidgetClass, noticeShell, NULL);
   noticeIcon     = XtVaCreateManagedWidget("noticeIcon",
	              labelWidgetClass, noticeForm, 
	              XtNborderWidth, 0,
	              XtNtop, XtChainTop,
	              XtNleft, XtChainLeft,
	              XtNbitmap, noticePixmap, NULL);
   noticeType     = XtVaCreateManagedWidget("type",
	              labelWidgetClass, noticeForm, 
	              XtNborderWidth, 0,
		      XtNjustify, XtJustifyLeft,
	              XtNtop, XtChainTop,
	              XtNfromHoriz, noticeIcon, NULL);
   sprintf(textLabel, "msgText%d", abs((int)errcode));
   noticeText     = XtVaCreateManagedWidget(textLabel,
	              labelWidgetClass, noticeForm, 
	              XtNborderWidth, 0,
		      XtNjustify, XtJustifyLeft,
	              XtNfromVert, noticeType,
	              XtNfromHoriz, noticeIcon, NULL);
   noticeOKButton = XtVaCreateManagedWidget("ok",
	              commandWidgetClass, noticeForm, 
		      XtNfromVert, noticeText,
		      XtNbottom, XtChainBottom, 
		      XtNfromHoriz, noticeIcon, NULL);

   XtAddCallback(noticeOKButton, XtNcallback, closeMsgWin, noticeShell);

   XtSetSensitive(mainMenu, FALSE);
   gubSetSensitive(NULL, FALSE);
   if (cotBeepOnError())
      XBell(XtDisplay(topLevel), 100);
   XtPopup(noticeShell, XtGrabNonexclusive);
}


/*********************************************************************/
/* CloseMsgWin:                                                      */
/*    Callback function for OK button in message windows             */
/*********************************************************************/
static void
closeMsgWin (Widget w, XtPointer clientData, XtPointer callData)
{
Widget shell = (Widget)clientData;

   XtSetSensitive(mainMenu, TRUE);
   gubSetSensitive(NULL, TRUE);
   XtPopdown(shell);
}


/*********************************************************************/
/* guwProgInfo:                                                      */
/*    Display programm information                                   */
/*********************************************************************/
void
guwProgInfo (Widget w, XtPointer clientData, XtPointer callData)
{
static Widget piShell, piIcon;
Position dx, dy, x, y;

   XtVaGetValues(desktop,
                 XtNx, &dx,
                 XtNy, &dy, NULL);
   XtTranslateCoords(desktop,
                     (Position)dx + SUBWIN_MARGIN,
                     (Position)dy + SUBWIN_MARGIN,
                     &x, &y);
   piShell  = XtVaCreatePopupShell("progInfoShell",
	        transientShellWidgetClass, topLevel, 
		XtNx, x, XtNy, y, NULL);
   piIcon  = XtVaCreateManagedWidget("progInfo",
	       commandWidgetClass, piShell, 
	       XtNbitmap, progInfoPixmap, NULL);

   XtAddCallback(piIcon, XtNcallback, closeProgInfoWin, piShell);
   XtPopup(piShell, XtGrabNonexclusive);
}


/*********************************************************************/
/* CloseProgInfoWin:                                                 */
/*    Callback function for OK button in message windows             */
/*********************************************************************/
static void
closeProgInfoWin (Widget w, XtPointer clientData, XtPointer callData)
{
Widget shell = (Widget)clientData;

   XtPopdown(shell);
}