1 
2 /*
3    Module to create and deal with popup Options box.
4 */
5 
6 
7 #include "xreduce.h"
8 #include "main.h"
9 #include "widgets.h"
10 #include "xredplus.h"
11 #include "rarrow.xbm"
12 #include "message.h"
13 #include "font.h"
14 #include "input.h"
15 #include "manager.h"
16 #include "printer.h"
17 #include "verbal.h"
18 #include "file.h"
19 
20 #define NO_OF_TOGGLES    7	/* was 8 with Page Mode */
21 #define TOGGLE_VERT_DIST 4
22 
23 void OptHistLengthCommand();
24 void OptTogglePaging();
25 void OptToggleGreek();
26 void OptToggleMonoRv();
27 void OptToggleGraphics();
28 void OptToggleBracketMatch();
29 void OptToggleForceBrackets();
30 void OptPrintScreen();
31 void OptFontSelection();
32 
33 Pixmap        followOnArrow;
34 
35 static Widget        optionButton;
36 static Dimension     maxStripWidth;
37 static Widget        options;
38 static Widget        optionBox;
39 static Widget        optTitleLabel;
40 static Widget        optMessageLabel;
41 static Widget        optOkButton;
42 static Widget        optHistLengthSubPopUp;
43 static Widget        optHistLengthDialog;
44 static Widget        optHistLengthDialogYesButton;
45 static Widget        optHistLengthDialogNoButton;
46 static Widget        referenceWidget;
47 
48 static Boolean       relativeFN;
49 static OptToggleSet  optToggleButtons[NO_OF_TOGGLES];
50 static OptToggleDesc optToggleNames[] = {
51   {
52     "optHistLengthCommand",
53      OptHistLengthCommand,
54 /*
55   }, {
56     "optTogglePaging",
57      OptTogglePaging,
58 */
59   }, {
60     "optToggleGreek",
61      OptToggleGreek,
62   }, {
63     "optToggleMonoRv",
64      OptToggleMonoRv,
65   }, {
66     "optToggleGraphics",
67      OptToggleGraphics,
68   }, {
69     "optToggleBracketMatch",
70      OptToggleBracketMatch,
71   }, {
72     "optToggleForceBrackets",
73      OptToggleForceBrackets,
74   }, {
75     "optFontSelection",
76      OptFontSelection,
77   },
78 };
79 
80 typedef enum {
81   optHistLengthCommandN = 0,
82 /*  optTogglePagingN, */
83   optToggleGreekN,
84   optToggleMonoRvN,
85   optToggleGraphicsN,
86   optToggleBracketMatchN,
87   optToggleForceBracketsN,
88   optFontSelectionN
89   } OptButtonNumber;
90 
91 
92 
SetOptionButtonFonts(fontStructp)93 void SetOptionButtonFonts(fontStructp)
94   XFontStruct *fontStructp;
95 {
96   Arg arg;
97   int i;
98 
99   XtSetArg(arg, XtNfont, fontStructp);
100 
101   XtSetValues(                 optionButton, &arg, 1);
102   XtSetValues(                optTitleLabel, &arg, 1);
103   XtSetValues(              optMessageLabel, &arg, 1);
104   XtSetValues(                  optOkButton, &arg, 1);
105   XtSetValues( optHistLengthDialogYesButton, &arg, 1);
106   XtSetValues(  optHistLengthDialogNoButton, &arg, 1);
107 
108   XRedSizeLabelForLabel(optionButton,NULL,NULL);
109 
110   for (i = 0; i < NO_OF_TOGGLES; i++) {
111     XtSetValues( optToggleButtons[i].label,  &arg, 1);
112     XtSetValues( optToggleButtons[i].toggle, &arg, 1);
113   }
114 
115   SetFileButtonFonts(fontStructp);
116 }
117 
118 
SizeOptionButtonsSuitably(wdp,thp)119 void SizeOptionButtonsSuitably(wdp, thp)
120   Dimension *wdp;
121   Dimension *thp;
122 {
123   Arg       arg[4];
124   int       i;
125   int       j;
126   Dimension wd;
127   Dimension h1;
128   Dimension h2;
129   Dimension bh;
130   Dimension th;
131 
132   XRedSizeLabelForLabel(optMessageLabel,&wd,NULL);
133   if (wd > maxStripWidth) maxStripWidth = wd;
134 
135   i = 0; XtSetArg(arg[i], XtNwidth,  maxStripWidth); i++;
136   XtSetValues(optTitleLabel,         arg, i);
137   XtSetValues(optMessageLabel,       arg, i);
138   XtSetValues(optOkButton,           arg, i);
139 
140   i = 0; XtSetArg(arg[i], XtNheight,      &h1); i++;
141          XtSetArg(arg[i], XtNborderWidth, &h2); i++;
142   XtGetValues(optMessageLabel,       arg, i);
143 
144   i = 0; XtSetArg(arg[i], XtNvSpace, &bh); i++;
145   XtGetValues(optionBox,             arg, i);
146 
147   th = 3 * h1 + 6 * h2 + 4 * bh;
148 
149   for (j = 0; j < NO_OF_TOGGLES; j++) {
150 
151     XRedSizeLabelForLabel(optToggleButtons[j].toggle,&wd,NULL);
152 
153     XtSetArg(arg[0], XtNwidth, maxStripWidth - wd - 14);
154     XtSetValues(optToggleButtons[j].label,  arg, 1);
155 
156     i = 0; XtSetArg(arg[i], XtNheight,       &h1); i++;
157            XtSetArg(arg[i], XtNborderWidth,  &h2); i++;
158     XtGetValues(optToggleButtons[j].label,  arg, i);
159 
160     th = th + 2 * h2 + h1 + bh + TOGGLE_VERT_DIST + 4;
161     i = 0; XtSetArg(arg[i], XtNborderWidth,  &h2); i++;
162     XtGetValues(optToggleButtons[j].form,   arg, i);
163 
164     th = th + 2 * h2 + 1;
165   }
166 
167   wd = ((bh > 5) ? 2*bh : 10) + maxStripWidth;
168 
169   if (wdp != NULL) *wdp = wd;
170   if (thp != NULL) *thp = th;
171 }
172 
173 
174 /*ARGSUSED*/
OptionButton(w,popup,call_data)175 void OptionButton(w, popup, call_data)
176   Widget  w;
177   Widget  popup;
178   caddr_t call_data;
179 {
180   Arg       arg[4];
181   int       i;
182   Dimension wd;
183   Dimension th;
184   Position  x;
185   Position  y;
186   Atom      wmPrtcls[2];
187 
188   SizeOptionButtonsSuitably(&wd,&th);
189   XRedTranslateCoords(referenceWidget, 50, 50, &x, &y, wd, th);
190   XtRealizeWidget(popup);
191 
192   i = 0; XtSetArg(arg[i], XtNwidth,  wd); i++;
193          XtSetArg(arg[i], XtNheight, th); i++;
194   XtSetValues(optionBox, arg, i);
195   XtSetValues(popup,     arg, i);
196 
197   i = 0; XtSetArg(arg[i], XtNx, x); i++;
198          XtSetArg(arg[i], XtNy, y); i++;
199   XtSetValues(popup, arg, i);
200 
201   XtPopup(popup, XtGrabNone);
202   XRaiseWindow(XtDisplay(popup), XtWindow(popup));
203 
204   wmPrtcls[0] =
205     XInternAtom(XtDisplay(popup), "WM_DELETE_WINDOW", False);
206   wmPrtcls[1] =
207     XInternAtom(XtDisplay(popup), "WM_SAVE_YOURSELF", False);
208 
209   XtOverrideTranslations
210     (popup,
211      XtParseTranslationTable("<Message>WM_PROTOCOLS: reduce-option-done()"));
212 
213   XSetWMProtocols(XtDisplay(popup), XtWindow(popup), wmPrtcls, 2);
214 }
215 
216 
InstateDatum(toggleSet,datum)217 void InstateDatum(toggleSet, datum)
218   Widget toggleSet;
219   char * datum;
220 {
221   Arg arg[3];
222   int i;
223 
224   i = 0; XtSetArg(arg[i], XtNlabel, datum); i++;
225   XtSetValues(toggleSet, arg, i);
226 }
227 
228 
InstateBooleanValue(toggleSetN,datum)229 void InstateBooleanValue(toggleSetN, datum)
230   OptButtonNumber toggleSetN;
231   Boolean         datum;
232 {
233   Arg arg[3];
234   int i;
235 
236   i = 0; XtSetArg(arg[i], XtNstate, datum); i++;
237   XtSetValues( optToggleButtons[(int)toggleSetN].toggle, arg, i);
238   InstateDatum(optToggleButtons[(int)toggleSetN].toggle, datum ? "Yes":" No ");
239 }
240 
241 
242 /*ARGSUSED*/
OptHistLengthOK(w,dialog,m)243 void OptHistLengthOK(w, dialog, m)
244   Widget  w;
245   Widget  dialog;
246   caddr_t m;
247 {
248   Arg  arg[3];
249   int  i;
250   int  newHistLength;
251   char newLengthText[20];
252   char complaint[50];
253 
254   newHistLength = atoi(XawDialogGetValueString(dialog));
255 
256   if (newHistLength < REDUCE_HISTORY_MIN_MAX ||
257       newHistLength > REDUCE_HISTORY_MAX_MAX) {
258 
259     if (newHistLength < REDUCE_HISTORY_MIN_MAX)
260       sprintf(complaint, "Minimum is %d", REDUCE_HISTORY_MIN_MAX);
261     else
262       sprintf(complaint, "Maximum is %d", REDUCE_HISTORY_MAX_MAX);
263 
264     i = 0; XtSetArg(arg[i], XtNlabel, complaint); i++;
265     XtSetValues(dialog, arg, i);
266 
267     XBell(XtDisplay(referenceWidget),80);
268 
269   } else {
270 
271     app_data.reduceHistoryMax = newHistLength;
272 
273     sprintf(newLengthText,"%d",newHistLength);
274     InstateDatum(optToggleButtons[(int)optHistLengthCommandN].toggle,
275 		 newLengthText);
276 
277     XtSetSensitive(w, False);
278     XtPopdown(optHistLengthSubPopUp);
279     XtSetSensitive(w, True);
280     XtSetSensitive(optionBox, True);
281 /*    XtUnrealizeWidget(optHistLengthSubPopUp); */
282   }
283 }
284 
285 
286 /*ARGSUSED*/
OptHistLengthCancel(w,dialog,m)287 void OptHistLengthCancel(w, dialog, m)
288   Widget  w;
289   Widget  dialog;
290   caddr_t m;
291 {
292   XtSetSensitive(w, False);
293   XtPopdown(optHistLengthSubPopUp);
294   XtSetSensitive(w, True);
295   XtSetSensitive(optionBox, True);
296 /*  XtUnrealizeWidget(optHistLengthSubPopUp); */
297 }
298 
299 
300 /*ARGSUSED*/
OptHistLengthCommand(w,n,m)301 void OptHistLengthCommand(w, n, m)
302   Widget  w;
303   caddr_t n, m;
304 {
305   Widget    label;
306   Position  x;
307   Position  y;
308   Arg       arg[5];
309   int       i;
310 
311   i = 0; XtSetArg(arg[i], XtNlabel, "Number of lines on history:"); i++;
312          XtSetArg(arg[i], XtNvalue,                            ""); i++;
313   XtSetValues(optHistLengthDialog, arg, i);
314 
315   XRedTranslateCoords(w, 15, 12, &x, &y, 200, 200);
316   i = 0; XtSetArg(arg[i], XtNx,                                 x); i++;
317          XtSetArg(arg[i], XtNy,                                 y); i++;
318   XtSetValues(optHistLengthSubPopUp, arg, i);
319 
320   XtRealizeWidget(optHistLengthSubPopUp);
321 
322   if ((label = XtNameToWidget(optHistLengthDialog, "label")) == NULL)
323        label = optHistLengthDialogNoButton;
324 
325   XRedSizeLabelForLabel(label,                       NULL, NULL);
326   XRedSizeLabelForLabel(optHistLengthDialogNoButton, NULL, NULL);
327 
328   XtSetSensitive(optionBox, False);
329   XtPopup(optHistLengthSubPopUp, XtGrabNonexclusive);
330   XRaiseWindow(XtDisplay(optHistLengthSubPopUp),
331 	       XtWindow(optHistLengthSubPopUp));
332 }
333 
334 
335 
336 /*ARGSUSED*/
337 /*
338 void OptTogglePaging(w, n, m)
339   Widget w;
340   caddr_t n, m;
341 {
342   app_data.pageMode = !(app_data.pageMode);
343   if (!app_data.pageMode) SwitchPageModeBackOff();
344   InstateBooleanValue(optTogglePagingN, app_data.pageMode);
345 }
346 */
347 
348 
349 /*ARGSUSED*/
OptToggleGreek(w,n,m)350 void OptToggleGreek(w, n, m)
351   Widget  w;
352   caddr_t n, m;
353 {
354   app_data.useGreekFont = !(app_data.useGreekFont);
355   setupGraphics(referenceWidget);
356 
357   InstateBooleanValue(optToggleGreekN, app_data.useGreekFont);
358 }
359 
360 
361 /*ARGSUSED*/
OptToggleMonoRv(w,n,m)362 void OptToggleMonoRv(w, n, m)
363   Widget  w;
364   caddr_t n, m;
365 {
366   app_data.reverseGraph = !(app_data.reverseGraph);
367   setupGraphics(referenceWidget);
368 
369   InstateBooleanValue(optToggleMonoRvN, app_data.reverseGraph);
370 }
371 
372 
373 /*ARGSUSED*/
OptToggleGraphics(w,n,m)374 void OptToggleGraphics(w, n, m)
375   Widget  w;
376   caddr_t n, m;
377 {
378   if (app_data.useGraphics) {
379     VerbalVerbatim(True);
380     PlaceUrgentItemOnPending("lisp x!-g!-n!!()$  %% XR Graphic Command\n",
381 			     "[ Graphics switched OFF ]\n");
382   } else {
383     VerbalVerbatim(False);
384     PlaceUrgentItemOnPending("lisp x!-g!-y!!()$  %% XR Graphic Command\n",
385 			     "[ Graphics switched ON ]\n");
386   }
387 
388   app_data.useGraphics = !(app_data.useGraphics);
389   InstateBooleanValue(optToggleGraphicsN, app_data.useGraphics);
390 }
391 
392 
393 /*ARGSUSED*/
OptToggleBracketMatch(w,n,m)394 void OptToggleBracketMatch(w, n, m)
395   Widget  w;
396   caddr_t n, m;
397 {
398   app_data.matchBrackets = !(app_data.matchBrackets);
399   InstateBooleanValue(optToggleBracketMatchN, app_data.matchBrackets);
400 }
401 
402 
403 /*ARGSUSED*/
OptToggleForceBrackets(w,n,m)404 void OptToggleForceBrackets(w, n, m)
405   Widget  w;
406   caddr_t n, m;
407 {
408   app_data.forceBracketMatch = !(app_data.forceBracketMatch);
409   InstateBooleanValue(optToggleForceBracketsN, app_data.forceBracketMatch);
410 }
411 
412 
413 /* ARGSUSED */
OptPrintScreen(w,n,m)414 void OptPrintScreen(w, n, m)
415   Widget  w;
416   caddr_t n, m;
417 {
418   PrintInstall(optionBox);
419 }
420 
421 
422 /*ARGSUSED*/
OptFontSelection(w,n,m)423 void OptFontSelection(w, n, m)
424   Widget  w;
425   caddr_t n, m;
426 {
427   if (fontSelectorActive)
428     XBell(XtDisplay(referenceWidget), 50);
429   else installFontSelector();
430 
431 }
432 
433 
434 /*ARGSUSED*/
OptOkButton(w,popup,m)435 void OptOkButton(w, popup, m)
436   Widget  w;
437   Widget  popup;
438   caddr_t m;
439 {
440   XtSetSensitive(w, False);
441   XtPopdown(popup);
442   XtSetSensitive(w, True);
443   /* XtUnrealizeWidget(popup); */
444 }
445 
446 
447 /* ARGSUSED */
OptOkButtonAction(w,event)448 void OptOkButtonAction(w, event)
449   Widget        w;
450   XButtonEvent *event;
451 {
452   OptOkButton(optOkButton, options, 0);
453 }
454 
455 
456 
OptToggleCallback(w,n,m)457 void OptToggleCallback(w, n, m)
458   Widget  w;
459   Widget  n;
460   caddr_t m;
461 {
462   int i = 0;
463 
464   XtSetSensitive(w, False);
465   while (i < NO_OF_TOGGLES && w != optToggleButtons[i].toggle) ++i;
466   if    (i < NO_OF_TOGGLES) optToggleButtons[i].callback(w, n, m);
467   XtSetSensitive(w, True);
468 }
469 
470 
MakeToggleSet(name,parent,callback,datum)471 OptToggleSet MakeToggleSet(name, parent, callback, datum)
472   char         * name;
473   Widget         parent;
474   XtCallbackProc callback;
475   char         * datum;
476 {
477   Arg          arg[5];
478   OptToggleSet newToggleSet;
479   Dimension    wd;
480   Dimension    wdt;
481   int          i;
482   int          nLen;
483   char       * boxName;
484   char       * toggleName;
485 
486   nLen = strlen(name);
487 
488      boxName = (char *)XtMalloc(nLen + 2);
489   toggleName = (char *)XtMalloc(nLen + 2);
490 
491   strcpy(    boxName, name );
492   strcpy( toggleName, name );
493 
494      boxName[ nLen     ] = 'B';
495      boxName[ nLen + 1 ] = 0x0;
496   toggleName[ nLen     ] = 'T';
497   toggleName[ nLen + 1 ] = 0x0;
498 
499   newToggleSet.form     = XtCreateManagedWidget(boxName,
500 						formWidgetClass,
501 						parent,
502 						NULL, 0);
503 
504   newToggleSet.label    = XtCreateManagedWidget(name,
505 						labelWidgetClass,
506 						newToggleSet.form,
507 						NULL, 0);
508 
509   newToggleSet.toggle   = XtCreateManagedWidget(toggleName,
510 						commandWidgetClass,
511 						newToggleSet.form,
512 						NULL, 0);
513 
514   newToggleSet.callback = callback;
515 
516   XtAddCallback(newToggleSet.toggle, XtNcallback,
517 		OptToggleCallback, newToggleSet.label);
518 
519   i = 0; XtSetArg(arg[i], XtNlabel,                    "  "); i++;
520          XtSetArg(arg[i], XtNfromHoriz,  newToggleSet.label); i++;
521          XtSetArg(arg[i], XtNvertDistance, TOGGLE_VERT_DIST); i++;
522          XtSetArg(arg[i], XtNborderWidth,                 0); i++;
523          XtSetArg(arg[i], XtNfont,               buttonFont); i++;
524   XtSetValues(newToggleSet.toggle, arg, i);
525 
526   if (datum != NULL) {
527 
528     InstateDatum(newToggleSet.toggle, datum);
529   }
530 
531   i = 0; XtSetArg(arg[i], XtNwidth,                    &wd); i++;
532   XtGetValues(newToggleSet.label,  arg, i); wdt  = wd;
533   XtGetValues(newToggleSet.toggle, arg, i); wdt += wd;
534 
535   i = 0; XtSetArg(arg[i], XtNjustify,         XtJustifyLeft); i++;
536          XtSetArg(arg[i], XtNvertDistance, TOGGLE_VERT_DIST); i++;
537          XtSetArg(arg[i], XtNborderWidth,                 0); i++;
538          XtSetArg(arg[i], XtNfont,               buttonFont); i++;
539   XtSetValues(newToggleSet.label,  arg, i);
540 
541   if ((wdt + 10) > maxStripWidth) maxStripWidth = wdt + 10;
542 
543   XtFree(    boxName );
544   XtFree( toggleName );
545 
546   return newToggleSet;
547 }
548 
549 
550 
createOptionMenu(topLevel,parent)551 void createOptionMenu(topLevel,parent)
552   Widget topLevel;
553   Widget parent;
554 {
555   Arg       arg[4];
556   int       i;
557   char      datumSpace[20];
558   char    * datum;
559 
560   optionButton           = XtCreateManagedWidget("optionButton",
561 						 commandWidgetClass,
562 						 parent,
563 						 NULL, 0);
564 
565   options                =    XtCreatePopupShell("options",
566 						 transientShellWidgetClass,
567 						 optionButton,
568 						 NULL, 0);
569 
570   optionBox              = XtCreateManagedWidget("optionBox",
571 						 boxWidgetClass,
572 						 options,
573 						 NULL, 0);
574 
575   optTitleLabel          = XtCreateManagedWidget("optTitleLabel",
576 						 labelWidgetClass,
577 						 optionBox,
578 						 NULL, 0);
579 
580   optMessageLabel        = XtCreateManagedWidget("optMessageLabel",
581 						 labelWidgetClass,
582 						 optionBox,
583 						 NULL, 0);
584 
585   /*
586   i = 0; XtSetArg(arg[i], XtNwidth, &maxStripWidth); i++;
587   XtGetValues(optMessageLabel, arg, i);
588   */
589 
590   for (i = 0; i < NO_OF_TOGGLES; i++) {
591     if (i == (int)optHistLengthCommandN) {
592 
593       sprintf(datumSpace,"%d",app_data.reduceHistoryMax);
594       datum = datumSpace;
595 
596     } else datum = NULL;
597 
598     optToggleButtons[i] = MakeToggleSet(optToggleNames[i].name,
599 					optionBox,
600 					optToggleNames[i].callback,
601 					datum);
602   }
603 
604   i = 0; XtSetArg(arg[i], XtNfont, buttonFont); i++;
605   XtSetValues(optionButton, arg, i);
606 
607   optOkButton                  = XtCreateManagedWidget("optOkButton",
608 						       commandWidgetClass,
609 						       optionBox,
610 						       arg, i);
611 
612   optHistLengthSubPopUp =
613     XtCreatePopupShell("subPopUp",
614 		       transientShellWidgetClass,
615 		       optToggleButtons[(int)optHistLengthCommandN].toggle,
616 		       NULL, 0);
617 
618   optHistLengthDialog          = XtCreateManagedWidget("optHistLengthDialog",
619 						       dialogWidgetClass,
620 						       optHistLengthSubPopUp,
621 						       NULL, 0);
622 
623   optHistLengthDialogYesButton = XtCreateManagedWidget("yesButton",
624 						       commandWidgetClass,
625 						       optHistLengthDialog,
626 						       arg, i);
627 
628   optHistLengthDialogNoButton  = XtCreateManagedWidget("noButton",
629 						       commandWidgetClass,
630 						       optHistLengthDialog,
631 						       arg, i);
632 
633   XtAddCallback(optHistLengthDialogYesButton, XtNcallback,
634 		OptHistLengthOK,     optHistLengthDialog);
635   XtAddCallback(optHistLengthDialogNoButton,  XtNcallback,
636 		OptHistLengthCancel, optHistLengthDialog);
637 
638   i = 0; XtSetArg(arg[i], XtNfont, buttonFont); i++;
639   XtSetValues(optTitleLabel,   arg, i);
640   XtSetValues(optMessageLabel, arg, i);
641   XtSetValues(optOkButton,     arg, i);
642 
643   followOnArrow = XCreateBitmapFromData(XtDisplay(topLevel),
644 					RootWindowOfScreen(XtScreen(topLevel)),
645 					rarrow_bits,
646 					rarrow_width, rarrow_height);
647 
648   i = 0; XtSetArg(arg[i], XtNbitmap, followOnArrow); i++;
649   XtSetValues(optToggleButtons[(int)optFontSelectionN].toggle, arg, i);
650 
651 /*  InstateBooleanValue(optTogglePagingN,        app_data.pageMode); */
652   InstateBooleanValue(optToggleGreekN,         app_data.useGreekFont);
653   InstateBooleanValue(optToggleMonoRvN,        app_data.reverseGraph);
654   InstateBooleanValue(optToggleBracketMatchN,  app_data.matchBrackets);
655   InstateBooleanValue(optToggleForceBracketsN, app_data.forceBracketMatch);
656   InstateBooleanValue(optToggleGraphicsN,      True);
657 
658   XtAddCallback( optionButton, XtNcallback, OptionButton, options );
659   XtAddCallback(  optOkButton, XtNcallback,  OptOkButton, options );
660 
661   referenceWidget = topLevel;
662 }
663 
664