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

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

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

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

~ [ 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.