]> andersk Git - moira.git/blob - clients/mmoira/formup.c
moved translations to resources
[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
299         for (   current = (*myinputlines), localy = 0,  i = 0;
300                 current; 
301                 myinputlines++, current = (*myinputlines), i++) {
302
303
304 #ifdef  DEBUG
305                 printf ("Making entry %d: %s of type %d\n", 
306                                 i, current->prompt, current->type);
307 #endif
308 /*
309 ** First, make the prompt
310 */
311                 if (current->type == FT_KEYWORD) {
312                     char *p;
313
314                     p = index(current->prompt, '|');
315                     if (p) {
316                         *p++ = 0;
317                         current->keyword_name = p;
318                     }
319                 }
320
321                 label = XmStringCreate( current->prompt, 
322                                         XmSTRING_DEFAULT_CHARSET);
323                 n = 0;
324                 XtSetArg(wargs[n], XmNlabelString, label);      n++;
325                 XtSetArg(wargs[n], XtNy, localy + *pheight);    n++;
326                 child = XtCreateManagedWidget(  "prompt",
327                                 xmLabelWidgetClass,
328                                 parent, wargs, n);
329
330                 GETSIZE(child);
331                 leftheight = height;
332                 if (width > maxleftwidth)
333                         maxleftwidth = width;
334
335                 if (current->type == FT_KEYWORD && current->keyword_name) {
336                     label = XmStringCreate("add new value",
337                                            XmSTRING_DEFAULT_CHARSET);
338                     n = 0;
339                     XtSetArg(wargs[n], XmNlabelString, label);  n++;
340                     XtSetArg(wargs[n], XtNy, localy + *pheight + height); n++;
341                     XtSetArg(wargs[n], XtNx, height); n++;
342                     child = XtCreateManagedWidget("newvalue",
343                                                   xmPushButtonWidgetClass,
344                                                   parent, wargs, n);
345                     XtAddCallback(child, XmNactivateCallback,
346                                   newvalue, current);
347
348                     GETSIZE(child);
349                     leftheight += height;
350                     if (width + height > maxleftwidth)
351                       maxleftwidth = width + height;
352                 }
353 /*
354 ** Second, make the input widget
355 */
356                 n = 0;
357                 XtSetArg(wargs[n], XtNy, localy + *pheight);    n++;
358                 XtSetArg(wargs[n], XmNtraversalOn, True);       n++;
359                 XtSetArg(wargs[n], XtNsensitive, 
360                         !(current->insensitive));               n++;
361                 switch (current->type) {
362                 case FT_STRING:
363                         children[i] = XtCreateManagedWidget(    "textwidget",
364                                                 xmTextWidgetClass,
365                                                 parent, wargs, n);
366                         XtAddCallback(  children[i], XmNvalueChangedCallback,
367                                 string_callback, current);
368                         if (trans == NULL) {
369                             XtAppAddActions(XtWidgetToApplicationContext(children[i]),
370                                             myactions, XtNumber(myactions));
371
372                             trans = XtParseTranslationTable(resources.text_trans);
373                         }
374                         XtOverrideTranslations(children[i], trans);
375                         if (current->returnvalue.stringvalue) {
376                                 XmTextSetString (children[i], current->returnvalue.stringvalue);
377                         }
378                         GETSIZE (children[i]);
379                         rightheight = height;
380                         if (width > maxrightwidth)
381                                 maxrightwidth = width;
382                         break;
383
384                 case FT_BOOLEAN:
385                         XtSetArg(wargs[n], XmNset,
386                                  current->returnvalue.booleanvalue ? True : False);     n++;
387
388                         if (current->returnvalue.booleanvalue)
389                                 label = XmStringCreate( "(True)", XmSTRING_DEFAULT_CHARSET);
390                         else
391                                 label = XmStringCreate( "(False)", XmSTRING_DEFAULT_CHARSET);
392                         XtSetArg(wargs[n], XmNlabelString, label);      n++;
393
394                         children[i] = XtCreateManagedWidget(    "ignore this",
395                                                 xmToggleButtonWidgetClass,
396                                                 parent, wargs, n);
397
398                         XtAddCallback(  children[i], XmNvalueChangedCallback,
399                                 boolean_callback, current);
400
401                         GETSIZE (children[i]);
402                         rightheight = height;
403                         if (width > maxrightwidth)
404                                 maxrightwidth = width;
405                         break;
406
407                 case FT_KEYWORD:
408                         children[i] = 
409                                 MakeRadioField(parent, current,
410                                                &rightheight, spec);
411                         XtManageChild(children[i]);
412                         XtSetValues(children[i], wargs, n);
413                         GETSIZE (children[i]);
414                         if (width > maxrightwidth)
415                                 maxrightwidth = width;
416                         break;
417
418                 default:
419                         printf ("Sorry, don't recognize that type\n");
420                         break;
421                 }
422                 XmAddTabGroup(children[i]);
423                 MapWidgetToForm(children[i], spec);
424                 current->parent = (caddr_t) spec;
425
426                 current->mywidget = children[i];
427
428                 localy += MAX(rightheight, leftheight) + vpad;
429         }
430
431 /*
432 ** Now slide the input widgets right as far as the widest prompt.
433 */
434         n = 0;
435         XtSetArg(wargs[n], XtNx, maxleftwidth + hpad);  n++;
436         for (; i; i--)
437                 XtSetValues (children[i - 1], wargs, n);
438
439         *pheight = localy - vpad;
440         *pwidth = maxleftwidth + maxrightwidth + hpad;
441 }
442
443 /*
444 ** All the junk about keeping track of the sum of the children's heights
445 ** is because the !#$% RowColumn widget doesn't sum them for us, NOR
446 ** does it accept SetValues on its XtNHeight!  Thanks, Motif!
447 */
448
449 Widget
450 MakeRadioField(parent, prompt, pheight, spec)
451 Widget          parent;
452 UserPrompt      *prompt;
453 Dimension       *pheight;
454 EntryForm       *spec;
455 {
456         Widget  radioparent, child = NULL;
457         char    *current;
458         Arg     wargs[10];
459         int     count, n;
460         XmString        label;  /* accursed compound string required */
461         Dimension       height, width;
462         char    **keywords, *null[2];
463
464         if (!prompt->keywords) {
465                 fprintf (stderr, "Warning:  No list of keywords for widget\n");
466                 prompt->keywords = null;
467                 null[0] = NULL;
468         }
469         for (   count = 0, keywords = prompt->keywords;
470                 *keywords; 
471                 keywords++, count++);
472
473 /*
474 ** Although the XmNnumColumns resource is documented as actually
475 ** representing the number of _rows_ when XmNorientation is set to XmVERTICAL,
476 ** it doesn't.  So I need to count the items myself and manually set the
477 ** number of columns to get a maximum of five rows.  There's no XmNnumRows
478 ** resource.  Thanks, Motif!
479 */
480
481         n = 0;
482         XtSetArg(wargs[n], XmNspacing, 0);      n++;
483
484         if (count > 5) {
485                 XtSetArg(wargs[n], XmNnumColumns, 1 + (count-1) / 5);           n++;
486                 XtSetArg(wargs[n], XmNorientation, XmVERTICAL); n++;
487                 XtSetArg(wargs[n], XmNpacking, XmPACK_COLUMN);  n++;
488         }
489         radioparent = XmCreateRadioBox(parent, "radio", wargs, n);
490
491         keywords = prompt->keywords;
492         for (current=(*keywords); current; keywords++, current=(*keywords)) {
493                 n = 0;
494                 label = XmStringCreate(current, XmSTRING_DEFAULT_CHARSET);
495                 XtSetArg(wargs[n], XmNlabelString, label);      n++;
496                 if ((prompt->returnvalue.stringvalue) &&
497                         (!strcmp (current, prompt->returnvalue.stringvalue))) {
498                         XtSetArg(wargs[n], XmNset, True);       n++;
499                 }
500                 else {
501                         XtSetArg(wargs[n], XmNset, False);      n++;
502                 }
503                 child = XtCreateManagedWidget(  current,
504                                                 xmToggleButtonWidgetClass,
505                                                 radioparent, wargs, n);
506                 MapWidgetToForm(child, spec);
507
508                 XtAddCallback(  child, XmNvalueChangedCallback,
509                                 radio_callback, prompt);
510
511         }
512 /*
513 ** Assume all child widgets are the same height.  Increase height by
514 ** five times this, or the actual number of children, whichever is lesser.
515 */
516
517         if (child) {
518             GETSIZE (child);
519         } else
520           height = 10;
521         *pheight = (height * MIN(5, count)) + vpad; 
522
523         return(radioparent);
524 }
525
526
527 /* This is called when the list of keywords changes.  The old radio box
528  * will be destroyed and a new one created.
529  */
530
531 RemakeRadioField(form, field)
532 EntryForm *form;
533 int field;
534 {
535     Dimension x, y, parent_y, oldheight, newheight;
536     Arg wargs[4];
537     Widget w;
538     XmBulletinBoardWidget bb;
539     XmRowColumnWidget rc;
540     static XtTranslations trans = NULL;
541     extern char form_override_table[];
542     int i;
543
544     XtSetArg(wargs[0], XtNx, &x);
545     XtSetArg(wargs[1], XtNy, &y);
546     XtSetArg(wargs[2], XtNheight, &oldheight);
547     XtGetValues(form->inputlines[field]->mywidget, wargs, 3);
548     XtUnmanageChild(form->inputlines[field]->mywidget);
549     form->inputlines[field]->mywidget = w =
550       MakeRadioField(form->formpointer, form->inputlines[field],
551                      &newheight, form);
552     XtSetArg(wargs[0], XtNx, x);
553     XtSetArg(wargs[1], XtNy, y);
554     XtSetValues(w, wargs, 2);
555     MapWidgetToForm(w, form);
556     XmAddTabGroup(w);
557     if (newheight > oldheight) {
558         bb = (XmBulletinBoardWidget) form->formpointer;
559         parent_y = y;
560         for (i = 0; i < bb->composite.num_children; i++) {
561             XtSetArg(wargs[0], XtNy, &y);
562             XtGetValues(bb->composite.children[i], wargs, 1);
563             if (y > parent_y) {
564                 y = (y + newheight) - oldheight;
565                 XtSetArg(wargs[0], XtNy, y);
566                 XtSetValues(bb->composite.children[i], wargs, 1);
567             }
568         }
569     }
570
571     if (trans == NULL)
572       trans = XtParseTranslationTable(resources.form_trans);
573     XtOverrideTranslations(w, trans);
574     rc = (XmRowColumnWidget) w;
575     for (i = 0; i < rc->composite.num_children; i++)
576       XtOverrideTranslations(rc->composite.children[i], trans);
577
578     XtManageChild(w);
579 }
580
581
582 MakeButtons(parent, pheight, pwidth, spec)
583 Widget          parent;
584 Dimension       *pheight;
585 Dimension       *pwidth;
586 EntryForm       *spec;
587 {
588         BottomButton    *current;
589         XmString        label;          /* compound string required */
590         Arg             wargs[10];
591         int             i, n;
592         Dimension       newwidth, width = 25;
593         Widget          newbutton;
594         BottomButton    **buttons = spec->buttons;
595
596         *pheight += vpad;
597
598         n = 0;
599         XtSetArg(wargs[n], XtNy, *pheight);                     n++;
600         XtSetArg(wargs[n], XtNx, 0);                            n++;
601         XtSetArg(wargs[n], XtNwidth, *pwidth);                  n++;
602         XtCreateManagedWidget(  "separator",
603                                 xmSeparatorWidgetClass,
604                                 parent, wargs, n);
605         *pheight += vpad;
606
607         for (   current=(*buttons); 
608                 current; 
609                 buttons++, current=(*buttons)) {
610
611 #ifdef  DEBUG
612                 printf ("Making a button labeled %s\n", current->label);
613 #endif
614                 label = XmStringCreate( current->label, 
615                                         XmSTRING_DEFAULT_CHARSET);
616                 n = 0;
617                 XtSetArg(wargs[n], XtNy, (*pheight));                   n++;
618                 XtSetArg(wargs[n], XtNx, width);                        n++;
619                 XtSetArg(wargs[n], XmNlabelString, label);              n++;
620
621                 newbutton = XtCreateManagedWidget(      current->label,
622                                                 xmPushButtonWidgetClass,
623                                                 parent, wargs, n);
624
625                 XtAddCallback(newbutton, XmNactivateCallback,
626                               (XtCallbackProc) current->returnfunction,
627                               spec);
628                 n = 0;
629                 XtSetArg(wargs[n], XtNwidth, &newwidth);                n++;
630                 XtGetValues (newbutton, wargs, n);
631
632                 width += (newwidth + hpad);
633         }
634
635         (*pheight) += 100;
636 }
637
638 void
639 radio_callback(w, client_data, call_data)
640 Widget  w;
641 XmAnyCallbackStruct     *client_data;
642 XmAnyCallbackStruct     *call_data;
643 {
644         Arg             wargs[10];
645         int             n;
646         Boolean         is_set;
647
648         UserPrompt      *prompt = (UserPrompt *) client_data;
649
650         n = 0;
651         XtSetArg(wargs[n], XmNset, &is_set);    n++;
652         XtGetValues (w, wargs, n);
653
654         if (!is_set)
655                 return;
656
657 /*
658 ** Since Motif insists on using !@#$% Compound Strings as the text for
659 ** its label widgets, but doesn't provide a way of getting a char* back
660 ** from a !@#$% Compound String, I can't retrieve the label of the button 
661 ** that was hit. 
662 **
663 ** Fortunately, I was smart enough to use the button label as the name 
664 ** of the widget, and I can extract it via XtName().  Thanks, Motif!
665 */
666         if (prompt->returnvalue.stringvalue &&
667                         (strcmp(prompt->returnvalue.stringvalue, XtName(w)))) {
668                 strcpy(prompt->returnvalue.stringvalue, XtName(w));
669                 if (prompt->valuechanged)
670                   (*prompt->valuechanged)(WidgetToForm(w), prompt);
671         }
672
673 }
674
675 void
676 boolean_callback(w, client_data, call_data)
677 Widget  w;
678 XmAnyCallbackStruct     *client_data;
679 XmAnyCallbackStruct     *call_data;
680 {
681         Arg             wargs[10];
682         int             n;
683         Boolean         is_set;
684         UserPrompt      *current = (UserPrompt *)client_data;
685         XmString        label;
686
687         n = 0;
688         XtSetArg(wargs[n], XmNset, &is_set);                    n++;
689         XtGetValues (w, wargs, n);
690
691         current->returnvalue.booleanvalue = is_set;
692
693         if (is_set)
694                 label = XmStringCreate( "(True)", XmSTRING_DEFAULT_CHARSET);
695         else
696                 label = XmStringCreate( "(False)", XmSTRING_DEFAULT_CHARSET);
697         n = 0;
698         XtSetArg(wargs[n], XmNlabelString, label);              n++;
699         XtSetValues (w, wargs, n);
700
701         if (current->valuechanged)
702           (*current->valuechanged)(WidgetToForm(w), current);
703
704 #if DEBUG
705         printf ("boolean_callback:  button %x is %s\n", 
706                         w, (is_set ? "True" : "False"));
707 #endif
708 }
709
710 void
711 menu_callback(w, client_data, call_data)
712 Widget  w;
713 XmAnyCallbackStruct     *client_data;
714 XmAnyCallbackStruct     *call_data;
715 {
716         MenuItem        *itemhit = (MenuItem *) client_data;
717
718 /*      printf  ("menu_callback: item '%s', op %d and string '%s'\n", 
719                         itemhit->label, 
720                         itemhit->operation, 
721                         itemhit->form);
722         XtManageChild(entryformwidget); 
723 */
724         MoiraMenuRequest(itemhit);
725 }
726
727
728 void
729 string_callback(w, client_data, call_data)
730 Widget  w;
731 XmAnyCallbackStruct     *client_data;
732 XmAnyCallbackStruct     *call_data;
733 {
734         UserPrompt      *current = (UserPrompt *)client_data;
735         char            *newvalue;
736
737         newvalue = XmTextGetString(w);
738
739         if (strcmp(current->returnvalue.stringvalue, newvalue)) {
740 /*              printf ("Replacing old value of selection, '%s', with '%s'\n",
741                                 current->returnvalue.stringvalue,
742                                 newvalue);
743                 strcpy(current->returnvalue.stringvalue, newvalue);
744                 if (current->valuechanged)
745                   (*current->valuechanged)(WidgetToForm(w), current);
746 */      }
747         XtFree(newvalue);
748 }
749
750
751 void MoiraFocusOut(w, event, p, n)
752 Widget w;
753 XEvent *event;
754 String *p;
755 Cardinal *n;
756 {
757     char  *newvalue;
758     UserPrompt *current = NULL;
759     EntryForm *f;
760     XmTextRec *tr = (XmTextRec *)w;
761     int i;
762
763     if (tr->core.self != w || tr->core.widget_class != xmTextWidgetClass)
764       return;
765     newvalue = XmTextGetString(w);
766     f = WidgetToForm(w);
767     for (i = 0; f->inputlines[i]; i++)
768       if (f->inputlines[i]->mywidget == w) 
769         current = f->inputlines[i];
770     if (current == NULL) {
771         fprintf(stderr, "Couldn't find prompt structure!\n");
772         return;
773     }
774
775     if (strcmp(current->returnvalue.stringvalue, newvalue)) {
776         strcpy(current->returnvalue.stringvalue, newvalue);
777         if (current->valuechanged)
778           (*current->valuechanged)(f, current);
779     }
780     XtFree(newvalue);
781 }
782
783
784 void
785 newvalue(w, client_data, call_data)
786 Widget  w;
787 XmAnyCallbackStruct     *client_data;
788 XmAnyCallbackStruct     *call_data;
789 {
790     UserPrompt  *current = (UserPrompt *)client_data;
791     EntryForm   *form, *f;
792     int i;
793     static MenuItem mi;
794
795     if (current->keyword_name == NULL) {
796         PopupErrorMessage("Sorry, that keyword cannot be changed.", NULL);
797         return;
798     }
799     form = (EntryForm *)current->parent;
800     for (i = 0; form->inputlines[i]; i++)
801       if (form->inputlines[i] == current)
802         break;
803     f = GetAndClearForm("add_new_value");
804     mi.operation = MM_NEW_VALUE;
805     mi.query = "add_alias";
806     mi.argc = 3;
807     mi.form = form->formname;
808     mi.accel = (char *) i;
809     f->menu = &mi;
810     f->extrastuff = current->keyword_name;
811     DisplayForm(f);
812 }
813
814
815 /* WARNING: This routine uses Motif internal undocumented routines.
816  * It was the only way to get carriage return to Do The Right Thing.
817  * If you are in a single-item tab group, this routine will call
818  * MoiraFormComplete() (same as pressing OK on the bottom of the form).
819  * otherwise, it advances the focus the same as pressing TAB.
820  */
821
822 void EnterPressed(w, event, argv, count)
823 Widget w;
824 XEvent *event;
825 char **argv;
826 Cardinal *count;
827 {
828     Widget next;
829     EntryForm *form;
830
831     next = _XmFindNextTabGroup(w);
832     if (next == w) {
833         MoiraFocusOut(w, event, argv, count);
834         form = WidgetToForm(w);
835         MoiraFormComplete(NULL, form);
836     } else {
837         _XmMgrTraversal(w, XmTRAVERSE_NEXT_TAB_GROUP);
838     }
839 }
840
841
842 void CancelForm(w, event, argv, count)
843 Widget w;
844 XEvent *event;
845 char **argv;
846 Cardinal *count;
847 {
848     EntryForm *form;
849
850     form = WidgetToForm(w);
851     if (form)
852       XtUnmanageChild(form->formpointer);    
853 }
854
855
856 void ExecuteForm(w, event, argv, count)
857 Widget w;
858 XEvent *event;
859 char **argv;
860 Cardinal *count;
861 {
862     EntryForm *form;
863
864     form = WidgetToForm(w);
865     if (form) {
866         MoiraFocusOut(w, event, argv, count);
867         MoiraFormComplete(NULL, form);
868     }
869 }
870
871
872 void DoHelp(w, event, argv, count)
873 Widget w;
874 XEvent *event;
875 char **argv;
876 Cardinal *count;
877 {
878     EntryForm *form;
879
880     form = WidgetToForm(w);
881     if (form)
882       help(form->formname);
883 }
884
885
886 extern struct hash *create_hash();
887 static struct hash *WFmap = NULL;
888
889 MapWidgetToForm(w, f)
890 Widget *w;
891 EntryForm *f;
892 {
893     if (WFmap == NULL) {
894         WFmap = create_hash(101);
895     }
896     hash_store(WFmap, w, f);
897 }
898
899 EntryForm *WidgetToForm(w)
900 Widget *w;
901 {
902     return((EntryForm *) hash_lookup(WFmap, w));
903 }
This page took 0.108639 seconds and 5 git commands to generate.