]> andersk Git - moira.git/blob - clients/mmoira/formup.c
correct lint problems
[moira.git] / clients / mmoira / formup.c
1 /* $Header$ */
2
3 #include        <stdio.h>
4 #include        <strings.h>
5 #include        <X11/StringDefs.h>
6 #include        <X11/IntrinsicP.h>
7 #include        <X11/Shell.h>
8 #include        <X11/Core.h>
9 #include        <X11/CoreP.h>
10 #include        <Xm/Xm.h>
11 #include        <Xm/BulletinB.h>
12 #include        <Xm/BulletinBP.h>
13 #include        <Xm/Label.h>
14 #include        <Xm/Text.h>
15 #include        <Xm/TextP.h>
16 #include        <Xm/PushB.h>
17 #include        <Xm/PushBG.h>
18 #include        <Xm/CascadeB.h>
19 #include        <Xm/ToggleB.h>
20 #include        <Xm/ToggleBG.h>
21 #include        <Xm/RowColumn.h>
22 #include        <Xm/RowColumnP.h>
23 #include        <Xm/Separator.h>
24 #include        <Xm/Traversal.h>
25 #include        "mmoira.h"
26
27 static char rcsid[] = "$Header$";
28
29 #ifndef MAX
30 #define MAX(a,b)        ((a > b) ? a : b)
31 #endif
32 #ifndef MIN
33 #define MIN(a,b)        ((a < b) ? a : b)
34 #endif
35
36 int     hpad = 10;
37 int     vpad = 5;
38
39 void    manage_widget();
40 Widget  CreateForm();
41 Widget  CreateMenu();
42 Widget  BuildMenuTree();
43 Widget  MakeRadioField();
44 int     button_callback();
45 void    radio_callback();
46 void    string_callback();
47 void    boolean_callback();
48 void    menu_callback();
49 void    newvalue();
50 void    MoiraFocusOut();
51 EntryForm *WidgetToForm();
52
53 extern void     UpdateForm();
54 extern int      PopupErrorMessage();
55 extern void     PopupHelpWindow();
56 extern int      AppendToLog();
57 extern void     MakeWatchCursor();
58 extern void     MakeNormalCursor();
59 extern Widget   SetupLogWidget();
60
61 static XtActionsRec myactions[] = {
62     { "MoiraFocusOut", MoiraFocusOut },
63 };
64
65
66 void
67 manage_widget(w, widget, call_data)
68 Widget  w, widget;
69 XmAnyCallbackStruct     *call_data;
70 {
71         XtManageChild(widget);  
72 }
73
74 int
75 button_callback(w, client_data, call_data)
76 Widget          w;
77 EntryForm       *client_data;
78 XmAnyCallbackStruct     *call_data;
79 {
80         XtUnmanageChild(client_data->formpointer);
81 }
82
83
84 Widget
85 BuildMenuTree(topW, spec)
86 Widget          topW;
87 MenuItem        *spec;
88 {
89         return (CreateMenu(topW, spec->submenu, XmHORIZONTAL));
90 }
91
92 /*
93 ** Read the specification and put up a menu to match...
94 */
95
96 Widget
97 CreateMenu(parent, spec, orientation)
98 Widget          parent;
99 MenuItem        **spec;
100 int             orientation;
101 {
102         Widget          menuparent;
103         MenuItem        *curmenuitem;
104         Widget          childbutton, childmenu;
105         Arg             wargs[10];
106         int             n;
107         XmString        label;          /* !@#$%^ compound string required */
108
109         label = XmStringCreate( "Complete junk", XmSTRING_DEFAULT_CHARSET);
110
111         n = 0;
112         XtSetArg(wargs[n], XmNlabelString, label);      n++;
113
114         if (orientation == XmHORIZONTAL) {
115                 XtSetArg(wargs[n], XmNspacing, 5);      n++;
116                 menuparent = XmCreateMenuBar(   parent, "randommenu", 
117                                         wargs, n);
118                 XtManageChild(menuparent);
119         }
120         else
121                 menuparent = XmCreatePulldownMenu(parent, "randommenu", 
122                                                 wargs, n);
123
124         for (   curmenuitem = (*spec);
125                 curmenuitem;
126                 spec++, curmenuitem = (*spec)) {
127
128 #ifdef  DEBUG
129                 printf ("Making entry:  %s\n", curmenuitem->label);
130 #endif
131                 label = XmStringCreate( curmenuitem->label,
132                                         XmSTRING_DEFAULT_CHARSET);
133                 n = 0;
134                 XtSetArg(wargs[n], XmNlabelString, label);      n++;
135                 if (curmenuitem->accel) {
136                     XtSetArg(wargs[n], XmNmnemonic, *(curmenuitem->accel)); n++;
137                 }
138
139                 if (curmenuitem->submenu) {
140 #ifdef  DEBUG
141                         printf ("It has a submenu, which I'm recursing on...\n");
142 #endif
143                         childmenu = CreateMenu( menuparent, 
144                                                 curmenuitem->submenu,
145                                                 XmVERTICAL);
146                         XtSetArg(wargs[n], XmNsubMenuId, childmenu);    n++;
147
148                         childbutton = XtCreateManagedWidget(    "child",
149                                         xmCascadeButtonWidgetClass,
150                                         menuparent, wargs, n);
151
152                 }
153
154                 else {
155                         childbutton = XtCreateManagedWidget(    "child",
156                                         xmPushButtonGadgetClass,
157                                         menuparent, wargs, n);
158
159                         XtAddCallback(  childbutton, 
160                                         XmNactivateCallback, 
161                                         menu_callback, curmenuitem);
162                 }
163         }
164
165         return (menuparent);
166 }
167
168 /*
169 ** Read the specification and put up a form to match...
170 */
171
172 Widget
173 CreateForm(parent, spec)
174 Widget          parent;
175 EntryForm       *spec;
176 {
177         Widget          bb;
178         Arg             wargs[10];
179         int             n;
180         XmString        label;          /* compound string required */
181         Dimension       height_so_far = 0, width_so_far = 0;
182         Dimension       height, width;
183         Widget          titleW, instructionW;
184         Position        x, y;
185         Widget          shellparent;
186
187         if (spec->formpointer) {
188                 UpdateForm(spec);
189                 return(spec->formpointer);
190         }
191
192         height_so_far = vpad;
193
194 #define GETSIZE(foo)    n = 0; \
195                         XtSetArg(wargs[n], XtNwidth, &width);   n++; \
196                         XtSetArg(wargs[n], XtNheight, &height); n++; \
197                         XtGetValues (foo, wargs, n); \
198
199 #define STORESIZE       if (width > width_so_far) width_so_far = width;\
200                         height_so_far += height + vpad;
201
202
203         n = 0;
204         XtSetArg(wargs[n], XmNautoUnmanage, False);             n++;
205         bb = XmCreateBulletinBoardDialog(parent, spec->formname, wargs, n);
206         MapWidgetToForm(bb, spec);
207
208         spec->formpointer = bb;
209
210 #ifdef FORMTITLES
211         label = XmStringCreate(spec->formname, XmSTRING_DEFAULT_CHARSET);
212         n = 0;
213         XtSetArg(wargs[n], XmNlabelString, label);              n++;
214         XtSetArg(wargs[n], XtNx, 0);                            n++;
215         XtSetArg(wargs[n], XtNy, 0);                            n++;
216         titleW = XtCreateManagedWidget( "title",
217                                 xmLabelWidgetClass,
218                                 bb, wargs, n);
219         GETSIZE(titleW);
220         STORESIZE;
221 #endif
222
223         label = XmStringCreate(spec->instructions, XmSTRING_DEFAULT_CHARSET);
224         n = 0;
225         XtSetArg(wargs[n], XmNlabelString, label);              n++;
226         XtSetArg(wargs[n], XtNx, 0);                            n++;
227         XtSetArg(wargs[n], XtNy, height_so_far);                n++;
228         instructionW = XtCreateManagedWidget(   "instructions",
229                                 xmLabelWidgetClass,
230                                 bb, wargs, n);
231         GETSIZE(instructionW);
232         STORESIZE;
233
234         height = height_so_far;
235         width = width_so_far;
236         MakeInputLines(bb, &height, &width, spec);
237         STORESIZE;
238
239         height = height_so_far;
240         width = width_so_far;
241         MakeButtons(bb, &height, &width, spec);
242         STORESIZE;
243
244 /*
245 ** Center the title of the form
246 */
247 #ifdef FORMTITLES
248         n = 0;
249         XtSetArg(wargs[n], XtNwidth, &width);                   n++;
250         XtGetValues (titleW, wargs, n);
251
252         x = (width_so_far - width) / 2;
253
254         n = 0;
255         XtSetArg(wargs[n], XtNx, x);                            n++;
256         XtSetValues (titleW, wargs, n);
257 #endif
258         n = 0;
259         XtSetArg(wargs[n], XtNwidth, &width);                   n++;
260         XtGetValues (instructionW, wargs, n);
261
262         x = (width_so_far - width) / 2;
263
264         n = 0;
265         XtSetArg(wargs[n], XtNx, x);                            n++;
266         XtSetValues (instructionW, wargs, n);
267
268         return((Widget) bb);
269 }
270
271 /*
272 ** Pheight and pwidth start with the values-to-date of the bboard so far.
273 ** Return your height and width in them when you're done.
274 **
275 ** Positioning the widgets happens in two phases: 
276 **      First, we set their y-positions as we create them.
277 **      After they're created, we go back and adjust the x-positions
278 **      according to the widest left side noted.
279 */
280
281 MakeInputLines(parent, pheight, pwidth, spec)
282 Widget          parent;
283 Dimension       *pheight;
284 Dimension       *pwidth;
285 EntryForm       *spec;
286 {
287         UserPrompt      *current;
288         XmString        label;          /* compound string required */
289         Arg             wargs[10];
290         int             i, n;
291         Widget          child;
292         Dimension       width, height, maxleftwidth = 0, maxrightwidth = 0;
293         Dimension       localy, leftheight = 0, rightheight = 0;
294         UserPrompt      **myinputlines = spec->inputlines;
295         int             foo = 30;
296         Widget          children[20];
297         static XtTranslations trans = NULL;
298 #define newtrans "<FocusOut>: focusOut() MoiraFocusOut()"
299
300
301         for (   current = (*myinputlines), localy = 0,  i = 0;
302                 current; 
303                 myinputlines++, current = (*myinputlines), i++) {
304
305
306 #ifdef  DEBUG
307                 printf ("Making entry %d: %s of type %d\n", 
308                                 i, current->prompt, current->type);
309 #endif
310 /*
311 ** First, make the prompt
312 */
313                 if (current->type == FT_KEYWORD) {
314                     char *p;
315
316                     p = index(current->prompt, '|');
317                     if (p) {
318                         *p++ = 0;
319                         current->keyword_name = p;
320                     }
321                 }
322
323                 label = XmStringCreate( current->prompt, 
324                                         XmSTRING_DEFAULT_CHARSET);
325                 n = 0;
326                 XtSetArg(wargs[n], XmNlabelString, label);      n++;
327                 XtSetArg(wargs[n], XtNy, localy + *pheight);    n++;
328                 child = XtCreateManagedWidget(  "prompt",
329                                 xmLabelWidgetClass,
330                                 parent, wargs, n);
331
332                 GETSIZE(child);
333                 leftheight = height;
334                 if (width > maxleftwidth)
335                         maxleftwidth = width;
336
337                 if (current->type == FT_KEYWORD && current->keyword_name) {
338                     label = XmStringCreate("add new value",
339                                            XmSTRING_DEFAULT_CHARSET);
340                     n = 0;
341                     XtSetArg(wargs[n], XmNlabelString, label);  n++;
342                     XtSetArg(wargs[n], XtNy, localy + *pheight + height); n++;
343                     XtSetArg(wargs[n], XtNx, height); n++;
344                     child = XtCreateManagedWidget("newvalue",
345                                                   xmPushButtonWidgetClass,
346                                                   parent, wargs, n);
347                     XtAddCallback(child, XmNactivateCallback,
348                                   newvalue, current);
349
350                     GETSIZE(child);
351                     leftheight += height;
352                     if (width + height > maxleftwidth)
353                       maxleftwidth = width + height;
354                 }
355 /*
356 ** Second, make the input widget
357 */
358                 n = 0;
359                 XtSetArg(wargs[n], XtNy, localy + *pheight);    n++;
360                 XtSetArg(wargs[n], XmNtraversalOn, True);       n++;
361                 XtSetArg(wargs[n], XtNsensitive, 
362                         !(current->insensitive));               n++;
363                 switch (current->type) {
364                 case FT_STRING:
365                         children[i] = XtCreateManagedWidget(    "textwidget",
366                                                 xmTextWidgetClass,
367                                                 parent, wargs, n);
368                         XtAddCallback(  children[i], XmNvalueChangedCallback,
369                                 string_callback, current);
370                         if (trans == NULL) {
371                             XtAppAddActions(XtWidgetToApplicationContext(children[i]),
372                                             myactions, XtNumber(myactions));
373
374                             trans = XtParseTranslationTable(newtrans);
375                         }
376                         XtOverrideTranslations(children[i], trans);
377                         if (current->returnvalue.stringvalue) {
378                                 XmTextSetString (children[i], current->returnvalue.stringvalue);
379                         }
380                         GETSIZE (children[i]);
381                         rightheight = height;
382                         if (width > maxrightwidth)
383                                 maxrightwidth = width;
384                         break;
385
386                 case FT_BOOLEAN:
387                         XtSetArg(wargs[n], XmNset,
388                                  current->returnvalue.booleanvalue ? True : False);     n++;
389
390                         if (current->returnvalue.booleanvalue)
391                                 label = XmStringCreate( "(True)", XmSTRING_DEFAULT_CHARSET);
392                         else
393                                 label = XmStringCreate( "(False)", XmSTRING_DEFAULT_CHARSET);
394                         XtSetArg(wargs[n], XmNlabelString, label);      n++;
395
396                         children[i] = XtCreateManagedWidget(    "ignore this",
397                                                 xmToggleButtonWidgetClass,
398                                                 parent, wargs, n);
399
400                         XtAddCallback(  children[i], XmNvalueChangedCallback,
401                                 boolean_callback, current);
402
403                         GETSIZE (children[i]);
404                         rightheight = height;
405                         if (width > maxrightwidth)
406                                 maxrightwidth = width;
407                         break;
408
409                 case FT_KEYWORD:
410                         children[i] = 
411                                 MakeRadioField(parent, current,
412                                                &rightheight, spec);
413                         XtManageChild(children[i]);
414                         XtSetValues(children[i], wargs, n);
415                         GETSIZE (children[i]);
416                         if (width > maxrightwidth)
417                                 maxrightwidth = width;
418                         break;
419
420                 default:
421                         printf ("Sorry, don't recognize that type\n");
422                         break;
423                 }
424                 XmAddTabGroup(children[i]);
425                 MapWidgetToForm(children[i], spec);
426                 current->parent = (caddr_t) spec;
427
428                 current->mywidget = children[i];
429
430                 localy += MAX(rightheight, leftheight) + vpad;
431         }
432
433 /*
434 ** Now slide the input widgets right as far as the widest prompt.
435 */
436         n = 0;
437         XtSetArg(wargs[n], XtNx, maxleftwidth + hpad);  n++;
438         for (; i; i--)
439                 XtSetValues (children[i - 1], wargs, n);
440
441         *pheight = localy - vpad;
442         *pwidth = maxleftwidth + maxrightwidth + hpad;
443 }
444
445 /*
446 ** All the junk about keeping track of the sum of the children's heights
447 ** is because the !#$% RowColumn widget doesn't sum them for us, NOR
448 ** does it accept SetValues on its XtNHeight!  Thanks, Motif!
449 */
450
451 Widget
452 MakeRadioField(parent, prompt, pheight, spec)
453 Widget          parent;
454 UserPrompt      *prompt;
455 Dimension       *pheight;
456 EntryForm       *spec;
457 {
458         Widget  radioparent, child = NULL;
459         char    *current;
460         Arg     wargs[10];
461         int     count, n;
462         XmString        label;  /* accursed compound string required */
463         Dimension       height, width;
464         char    **keywords, *null[2];
465
466         if (!prompt->keywords) {
467                 fprintf (stderr, "Warning:  No list of keywords for widget\n");
468                 prompt->keywords = null;
469                 null[0] = NULL;
470         }
471         for (   count = 0, keywords = prompt->keywords;
472                 *keywords; 
473                 keywords++, count++);
474
475 /*
476 ** Although the XmNnumColumns resource is documented as actually
477 ** representing the number of _rows_ when XmNorientation is set to XmVERTICAL,
478 ** it doesn't.  So I need to count the items myself and manually set the
479 ** number of columns to get a maximum of five rows.  There's no XmNnumRows
480 ** resource.  Thanks, Motif!
481 */
482
483         n = 0;
484         XtSetArg(wargs[n], XmNspacing, 0);      n++;
485
486         if (count > 5) {
487                 XtSetArg(wargs[n], XmNnumColumns, 1 + (count-1) / 5);           n++;
488                 XtSetArg(wargs[n], XmNorientation, XmVERTICAL); n++;
489                 XtSetArg(wargs[n], XmNpacking, XmPACK_COLUMN);  n++;
490         }
491         radioparent = XmCreateRadioBox(parent, "radio", wargs, n);
492
493         keywords = prompt->keywords;
494         for (current=(*keywords); current; keywords++, current=(*keywords)) {
495                 n = 0;
496                 label = XmStringCreate(current, XmSTRING_DEFAULT_CHARSET);
497                 XtSetArg(wargs[n], XmNlabelString, label);      n++;
498                 if ((prompt->returnvalue.stringvalue) &&
499                         (!strcmp (current, prompt->returnvalue.stringvalue))) {
500                         XtSetArg(wargs[n], XmNset, True);       n++;
501                 }
502                 else {
503                         XtSetArg(wargs[n], XmNset, False);      n++;
504                 }
505                 child = XtCreateManagedWidget(  current,
506                                                 xmToggleButtonWidgetClass,
507                                                 radioparent, wargs, n);
508                 MapWidgetToForm(child, spec);
509
510                 XtAddCallback(  child, XmNvalueChangedCallback,
511                                 radio_callback, prompt);
512
513         }
514 /*
515 ** Assume all child widgets are the same height.  Increase height by
516 ** five times this, or the actual number of children, whichever is lesser.
517 */
518
519         if (child) {
520             GETSIZE (child);
521         } else
522           height = 10;
523         *pheight = (height * MIN(5, count)) + vpad; 
524
525         return(radioparent);
526 }
527
528
529 /* This is called when the list of keywords changes.  The old radio box
530  * will be destroyed and a new one created.
531  */
532
533 RemakeRadioField(form, field)
534 EntryForm *form;
535 int field;
536 {
537     Dimension x, y, parent_y, oldheight, newheight;
538     Arg wargs[4];
539     Widget w;
540     XmBulletinBoardWidget bb;
541     XmRowColumnWidget rc;
542     static XtTranslations trans = NULL;
543     extern char form_override_table[];
544     int i;
545
546     XtSetArg(wargs[0], XtNx, &x);
547     XtSetArg(wargs[1], XtNy, &y);
548     XtSetArg(wargs[2], XtNheight, &oldheight);
549     XtGetValues(form->inputlines[field]->mywidget, wargs, 3);
550     XtUnmanageChild(form->inputlines[field]->mywidget);
551     form->inputlines[field]->mywidget = w =
552       MakeRadioField(form->formpointer, form->inputlines[field],
553                      &newheight, form);
554     XtSetArg(wargs[0], XtNx, x);
555     XtSetArg(wargs[1], XtNy, y);
556     XtSetValues(w, wargs, 2);
557     MapWidgetToForm(w, form);
558     XmAddTabGroup(w);
559     if (newheight > oldheight) {
560         bb = (XmBulletinBoardWidget) form->formpointer;
561         parent_y = y;
562         for (i = 0; i < bb->composite.num_children; i++) {
563             XtSetArg(wargs[0], XtNy, &y);
564             XtGetValues(bb->composite.children[i], wargs, 1);
565             if (y > parent_y) {
566                 y = (y + newheight) - oldheight;
567                 XtSetArg(wargs[0], XtNy, y);
568                 XtSetValues(bb->composite.children[i], wargs, 1);
569             }
570         }
571     }
572
573     if (trans == NULL)
574       trans = XtParseTranslationTable(form_override_table);
575     XtOverrideTranslations(w, trans);
576     rc = (XmRowColumnWidget) w;
577     for (i = 0; i < rc->composite.num_children; i++)
578       XtOverrideTranslations(rc->composite.children[i], trans);
579
580     XtManageChild(w);
581 }
582
583
584 MakeButtons(parent, pheight, pwidth, spec)
585 Widget          parent;
586 Dimension       *pheight;
587 Dimension       *pwidth;
588 EntryForm       *spec;
589 {
590         BottomButton    *current;
591         XmString        label;          /* compound string required */
592         Arg             wargs[10];
593         int             i, n;
594         Dimension       newwidth, width = 25;
595         Widget          newbutton;
596         BottomButton    **buttons = spec->buttons;
597
598         *pheight += vpad;
599
600         n = 0;
601         XtSetArg(wargs[n], XtNy, *pheight);                     n++;
602         XtSetArg(wargs[n], XtNx, 0);                            n++;
603         XtSetArg(wargs[n], XtNwidth, *pwidth);                  n++;
604         XtCreateManagedWidget(  "separator",
605                                 xmSeparatorWidgetClass,
606                                 parent, wargs, n);
607         *pheight += vpad;
608
609         for (   current=(*buttons); 
610                 current; 
611                 buttons++, current=(*buttons)) {
612
613 #ifdef  DEBUG
614                 printf ("Making a button labeled %s\n", current->label);
615 #endif
616                 label = XmStringCreate( current->label, 
617                                         XmSTRING_DEFAULT_CHARSET);
618                 n = 0;
619                 XtSetArg(wargs[n], XtNy, (*pheight));                   n++;
620                 XtSetArg(wargs[n], XtNx, width);                        n++;
621                 XtSetArg(wargs[n], XmNlabelString, label);              n++;
622
623                 newbutton = XtCreateManagedWidget(      current->label,
624                                                 xmPushButtonWidgetClass,
625                                                 parent, wargs, n);
626
627                 XtAddCallback(newbutton, XmNactivateCallback,
628                               (XtCallbackProc) current->returnfunction,
629                               spec);
630                 n = 0;
631                 XtSetArg(wargs[n], XtNwidth, &newwidth);                n++;
632                 XtGetValues (newbutton, wargs, n);
633
634                 width += (newwidth + hpad);
635         }
636
637         (*pheight) += 100;
638 }
639
640 void
641 radio_callback(w, client_data, call_data)
642 Widget  w;
643 XmAnyCallbackStruct     *client_data;
644 XmAnyCallbackStruct     *call_data;
645 {
646         Arg             wargs[10];
647         int             n;
648         Boolean         is_set;
649
650         UserPrompt      *prompt = (UserPrompt *) client_data;
651
652         n = 0;
653         XtSetArg(wargs[n], XmNset, &is_set);    n++;
654         XtGetValues (w, wargs, n);
655
656         if (!is_set)
657                 return;
658
659 /*
660 ** Since Motif insists on using !@#$% Compound Strings as the text for
661 ** its label widgets, but doesn't provide a way of getting a char* back
662 ** from a !@#$% Compound String, I can't retrieve the label of the button 
663 ** that was hit. 
664 **
665 ** Fortunately, I was smart enough to use the button label as the name 
666 ** of the widget, and I can extract it via XtName().  Thanks, Motif!
667 */
668         if (prompt->returnvalue.stringvalue &&
669                         (strcmp(prompt->returnvalue.stringvalue, XtName(w)))) {
670                 strcpy(prompt->returnvalue.stringvalue, XtName(w));
671                 if (prompt->valuechanged)
672                   (*prompt->valuechanged)(WidgetToForm(w), prompt);
673         }
674
675 }
676
677 void
678 boolean_callback(w, client_data, call_data)
679 Widget  w;
680 XmAnyCallbackStruct     *client_data;
681 XmAnyCallbackStruct     *call_data;
682 {
683         Arg             wargs[10];
684         int             n;
685         Boolean         is_set;
686         UserPrompt      *current = (UserPrompt *)client_data;
687         XmString        label;
688
689         n = 0;
690         XtSetArg(wargs[n], XmNset, &is_set);                    n++;
691         XtGetValues (w, wargs, n);
692
693         current->returnvalue.booleanvalue = is_set;
694
695         if (is_set)
696                 label = XmStringCreate( "(True)", XmSTRING_DEFAULT_CHARSET);
697         else
698                 label = XmStringCreate( "(False)", XmSTRING_DEFAULT_CHARSET);
699         n = 0;
700         XtSetArg(wargs[n], XmNlabelString, label);              n++;
701         XtSetValues (w, wargs, n);
702
703         if (current->valuechanged)
704           (*current->valuechanged)(WidgetToForm(w), current);
705
706 #if DEBUG
707         printf ("boolean_callback:  button %x is %s\n", 
708                         w, (is_set ? "True" : "False"));
709 #endif
710 }
711
712 void
713 menu_callback(w, client_data, call_data)
714 Widget  w;
715 XmAnyCallbackStruct     *client_data;
716 XmAnyCallbackStruct     *call_data;
717 {
718         MenuItem        *itemhit = (MenuItem *) client_data;
719
720 /*      printf  ("menu_callback: item '%s', op %d and string '%s'\n", 
721                         itemhit->label, 
722                         itemhit->operation, 
723                         itemhit->form);
724         XtManageChild(entryformwidget); 
725 */
726         MoiraMenuRequest(itemhit);
727 }
728
729
730 void
731 string_callback(w, client_data, call_data)
732 Widget  w;
733 XmAnyCallbackStruct     *client_data;
734 XmAnyCallbackStruct     *call_data;
735 {
736         UserPrompt      *current = (UserPrompt *)client_data;
737         char            *newvalue;
738
739         newvalue = XmTextGetString(w);
740
741         if (strcmp(current->returnvalue.stringvalue, newvalue)) {
742 /*              printf ("Replacing old value of selection, '%s', with '%s'\n",
743                                 current->returnvalue.stringvalue,
744                                 newvalue);
745                 strcpy(current->returnvalue.stringvalue, newvalue);
746                 if (current->valuechanged)
747                   (*current->valuechanged)(WidgetToForm(w), current);
748 */      }
749         XtFree(newvalue);
750 }
751
752
753 void MoiraFocusOut(w, event, p, n)
754 Widget w;
755 XEvent *event;
756 String *p;
757 Cardinal *n;
758 {
759     char  *newvalue;
760     UserPrompt *current = NULL;
761     EntryForm *f;
762     XmTextRec *tr = (XmTextRec *)w;
763     int i;
764
765     if (tr->core.self != w || tr->core.widget_class != xmTextWidgetClass)
766       return;
767     newvalue = XmTextGetString(w);
768     f = WidgetToForm(w);
769     for (i = 0; f->inputlines[i]; i++)
770       if (f->inputlines[i]->mywidget == w) 
771         current = f->inputlines[i];
772     if (current == NULL) {
773         fprintf(stderr, "Couldn't find prompt structure!\n");
774         return;
775     }
776
777     if (strcmp(current->returnvalue.stringvalue, newvalue)) {
778         strcpy(current->returnvalue.stringvalue, newvalue);
779         if (current->valuechanged)
780           (*current->valuechanged)(f, current);
781     }
782     XtFree(newvalue);
783 }
784
785
786 void
787 newvalue(w, client_data, call_data)
788 Widget  w;
789 XmAnyCallbackStruct     *client_data;
790 XmAnyCallbackStruct     *call_data;
791 {
792     UserPrompt  *current = (UserPrompt *)client_data;
793     EntryForm   *form, *f;
794     int i;
795     static MenuItem mi;
796
797     if (current->keyword_name == NULL) {
798         PopupErrorMessage("Sorry, that keyword cannot be changed.", NULL);
799         return;
800     }
801     form = (EntryForm *)current->parent;
802     for (i = 0; form->inputlines[i]; i++)
803       if (form->inputlines[i] == current)
804         break;
805     f = GetAndClearForm("add_new_value");
806     mi.operation = MM_NEW_VALUE;
807     mi.query = "add_alias";
808     mi.argc = 3;
809     mi.form = form->formname;
810     mi.accel = (char *) i;
811     f->menu = &mi;
812     f->extrastuff = current->keyword_name;
813     DisplayForm(f);
814 }
815
816
817 /* WARNING: This routine uses Motif internal undocumented routines.
818  * It was the only way to get carriage return to Do The Right Thing.
819  * If you are in a single-item tab group, this routine will call
820  * MoiraFormComplete() (same as pressing OK on the bottom of the form).
821  * otherwise, it advances the focus the same as pressing TAB.
822  */
823
824 void EnterPressed(w, event, argv, count)
825 Widget w;
826 XEvent *event;
827 char **argv;
828 Cardinal *count;
829 {
830     Widget next;
831     EntryForm *form;
832
833     next = _XmFindNextTabGroup(w);
834     if (next == w) {
835         MoiraFocusOut(w, event, argv, count);
836         form = WidgetToForm(w);
837         MoiraFormComplete(NULL, form);
838     } else {
839         _XmMgrTraversal(w, XmTRAVERSE_NEXT_TAB_GROUP);
840     }
841 }
842
843
844 void CancelForm(w, event, argv, count)
845 Widget w;
846 XEvent *event;
847 char **argv;
848 Cardinal *count;
849 {
850     EntryForm *form;
851
852     form = WidgetToForm(w);
853     if (form)
854       XtUnmanageChild(form->formpointer);    
855 }
856
857
858 void ExecuteForm(w, event, argv, count)
859 Widget w;
860 XEvent *event;
861 char **argv;
862 Cardinal *count;
863 {
864     EntryForm *form;
865
866     form = WidgetToForm(w);
867     if (form) {
868         MoiraFocusOut(w, event, argv, count);
869         MoiraFormComplete(NULL, form);
870     }
871 }
872
873
874 void DoHelp(w, event, argv, count)
875 Widget w;
876 XEvent *event;
877 char **argv;
878 Cardinal *count;
879 {
880     EntryForm *form;
881
882     form = WidgetToForm(w);
883     if (form)
884       help(form->formname);
885 }
886
887
888 extern struct hash *create_hash();
889 static struct hash *WFmap = NULL;
890
891 MapWidgetToForm(w, f)
892 Widget *w;
893 EntryForm *f;
894 {
895     if (WFmap == NULL) {
896         WFmap = create_hash(101);
897     }
898     hash_store(WFmap, w, f);
899 }
900
901 EntryForm *WidgetToForm(w)
902 Widget *w;
903 {
904     return((EntryForm *) hash_lookup(WFmap, w));
905 }
This page took 0.131555 seconds and 5 git commands to generate.