~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/Xm/tw_choice.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 **/
  3 #include <tina/tv.h>
  4 #include <tina/sysfuncs.h>
  5 #include  <tina/mtw.h>
  6 #include  <tina/tv_screen.h>
  7 #include <tina/Xmfuncs.h>
  8 
  9 static char *choicename;
 10 
 11 static void choice_call(Tw_callback * twc)
 12 {
 13     int     pos = (int) twc->data1;
 14 
 15     (*twc->func) (pos);
 16 }
 17 
 18 static void choice_cmnd(Tw_callback * twc, char *args)
 19 {
 20     int     pos;
 21     int     nargs;
 22     Arg     wargs[1];
 23 
 24     (void) sscanf(args, "%*s %d", &pos);
 25     twc->data1 = (void *) pos;
 26     (*twc->func) (pos);
 27 
 28     nargs = 0;
 29     XtSetArg(wargs[nargs], XmNset, True);
 30     nargs++;
 31     XtSetValues(twc->widget, wargs, nargs);
 32 }
 33 
 34 static void choice_prnt(FILE * fp, Tw_callback * twc)
 35 {
 36     (void) fprintf(fp, "%s %d\n", twc->name, (int) twc->data1);
 37 }
 38 
 39 static Widget tw_choice_label(char *name)
 40 {
 41     Widget  panel = tw_get_panel();
 42     Widget  label;
 43     XmString xmstring;
 44     int     nargs;
 45     Arg     wargs[1];
 46 
 47     label = XtCreateManagedWidget("twlabel", xmLabelWidgetClass,
 48                                   panel, (ArgList) NULL, 0);
 49     xmstring = XmStringCreate(name, XmSTRING_DEFAULT_CHARSET);
 50     nargs = 0;
 51     XtSetArg(wargs[nargs], XmNlabelString, xmstring);
 52     nargs++;
 53     XtSetValues(label, wargs, nargs);
 54     XmStringFree(xmstring);
 55     return (label);
 56 }
 57 
 58 static void *tw_choice_add(Widget box, char *name, void (*func) ( /* ??? */ ), int pos, int *value, double *width)
 59 {
 60     XmString xmstring;
 61     int     nargs;
 62     Arg     wargs[3];
 63     Tw_callback *twc;
 64     Widget  button;
 65     char   *fullname = tw_extend_fullname(choicename, name);
 66 
 67     nargs = 0;
 68     xmstring = XmStringCreate(name, XmSTRING_DEFAULT_CHARSET);
 69     XtSetArg(wargs[nargs], XmNlabelString, xmstring);
 70     nargs++;
 71     if (pos == *value)
 72     {
 73         XtSetArg(wargs[nargs], XmNset, True);
 74         nargs++;
 75     }
 76     button = XtCreateManagedWidget("twtoggle", xmToggleButtonWidgetClass,
 77                                    box, wargs, nargs);
 78     XmStringFree(xmstring);
 79 
 80     twc = tw_callback_make(fullname, tw_get_tool(), button,
 81                            choice_call, choice_cmnd, choice_prnt, func, (void *) pos, (void *) value);
 82     XtAddCallback(button, XmNvalueChangedCallback, (void *) tw_callback, (XtPointer) twc);
 83 
 84     *width += strlen(name) + 4.0;
 85     return(twc);
 86 }
 87 
 88 void *tw_choice(char *name,...)
 89 {
 90     va_list ap;
 91     int     nargs;
 92     Arg     wargs[10];
 93     Widget  label, choice, panel = tw_get_panel();
 94     void    (*func) ();
 95     int     i, w, h, *value;
 96     double  width;
 97     List *twlist = NULL, *lptr;
 98     Tw_callback *twc;
 99 
100     nargs = 0;
101     XtSetArg(wargs[nargs], XmNentryClass, xmToggleButtonWidgetClass);
102     nargs++;
103     XtSetArg(wargs[nargs], XmNorientation, XmHORIZONTAL);
104     nargs++;
105     choice = XmCreateRadioBox(panel, "twchoice", wargs, nargs);
106 
107     va_start(ap, name);
108 
109     label = tw_choice_label(name);
110 
111     choicename = tw_extend_fullname(tw_get_toolname(), name);
112 
113     w = tw_charwidth(2.0 + strlen(name));
114     h = tw_charheight(1.5);
115     tw_set_entry(label, w, h);
116 
117     func = (void (*) ()) va_arg(ap, void *);
118     width = 0.0;
119     value = (int *) ralloc(sizeof(int));
120     *value = va_arg(ap, int);
121     for (i = 0; (name = va_arg(ap, char *)) != NULL; i++)
122     {
123         void *twc = tw_choice_add(choice, name, func, i, value, &width);
124         twlist = ref_addtostart(twlist, twc, 0);
125     }
126     twlist = list_reverse(twlist);
127     va_end(ap);
128     XtManageChild(choice);
129 
130     w = tw_charwidth(width);
131     h = tw_charheight(2.5);
132     tw_set_entry(choice, w, h);
133 
134     /** initialise choice **/
135     (*func) (*value);
136     for(lptr = twlist, i = 0; lptr != NULL; lptr = lptr->next, i++)
137     {
138         twc = lptr->to;
139         nargs = 0;
140         XtSetArg(wargs[nargs], XmNset, (i == *value)? True: False);
141         nargs++;
142         XtSetValues(twc->widget, wargs, nargs);
143     }
144 
145     rfree((void *) choicename);
146     return(twlist);
147 }
148 
149 void tw_choice_reset(void *ptr, int val)
150 {
151     List *twlist = ptr, *lptr;
152     Tw_callback *twc;
153     int     nargs, i;
154     Arg     wargs[1];
155     for(lptr = twlist, i = 0; lptr != NULL; lptr = lptr->next, i++)
156     {
157         twc = lptr->to;
158         nargs = 0;
159         XtSetArg(wargs[nargs], XmNset, (i == val)? True: False);
160         nargs++;
161         XtSetValues(twc->widget, wargs, nargs);
162     }
163 }
164 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.