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

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

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

  1 /**@(#)
  2 **/
  3 #include <stdio.h>
  4 #include <tina/sys.h>
  5 #include <tina/math.h>
  6 #include <tina/tv.h>
  7 #include  <tina/mtw.h>
  8 #include  <tina/tv_screen.h>
  9 #include <tina/Xmfuncs.h>
 10 
 11 static void fglobal_call(Tw_callback * twc)
 12 {
 13     double  x, *ptr = (double *) twc->data1;
 14     char   *string = XmTextGetString(twc->widget);
 15 
 16     if (sscanf(string, "%lf", &x) == 1)
 17         *ptr = x;
 18     XtFree(string);
 19 }
 20 
 21 static void fglobal_cmnd(Tw_callback * twc, char *args)
 22 {
 23     double *ptr = (double *) twc->data1;
 24     char    string[64];
 25 
 26     (void) sscanf(args, "%*s %lf", ptr);
 27     (void) sscanf(args, "%*s %s", string);
 28     tw_text_set(twc->widget, string);
 29 }
 30 
 31 static void fglobal_prnt(FILE * fp, Tw_callback * twc)
 32 {
 33     double  x = *(double *) twc->data1;
 34 
 35     (void) fprintf(fp, "%s %lf\n", twc->name, x);
 36 }
 37 
 38 void *tw_fglobal(char *name, double *ptr, int nchars)
 39 {
 40     char    string[64];
 41     XmString xmstring;
 42     int     nargs;
 43     Arg     wargs[1];
 44     int     w, h;
 45     Tw_callback *twc;
 46     Widget  panel = tw_get_panel(), label, text;
 47     char   *fullname = tw_extend_fullname(tw_get_toolname(), name);
 48 
 49     xmstring = XmStringCreate(name, XmSTRING_DEFAULT_CHARSET);
 50     nargs = 0;
 51     XtSetArg(wargs[nargs], XmNlabelString, xmstring);
 52     nargs++;
 53     label = XtCreateManagedWidget("twlabel", xmLabelWidgetClass,
 54                                   panel, wargs, nargs);
 55     XmStringFree(xmstring);
 56 
 57     w = tw_charwidth(2.0 + strlen(name));
 58     h = tw_charheight(1.0);
 59     tw_set_entry(label, w, h);
 60 
 61     nargs = 0;
 62     XtSetArg(wargs[nargs], XmNcolumns, nchars);
 63     nargs++;
 64     text = XtCreateManagedWidget("twtext", xmTextWidgetClass,
 65                                  panel, wargs, nargs);
 66     (void) sprintf(string, "%g", *ptr);
 67     if (!strchr(string, '.') && !strchr(string, 'e'))
 68     {
 69         /* Ensure at least one decimal place is shown (JB 2/3/93) */
 70         (void) sprintf(string, "%.1f", *ptr);
 71     }
 72     XmTextSetString(text, string);
 73 
 74     twc = tw_callback_make(fullname, tw_get_tool(), text, fglobal_call, fglobal_cmnd,
 75                        fglobal_prnt, (void (*) ()) NULL, (void *) ptr,
 76                            NULL);
 77     XtAddCallback(text, XmNvalueChangedCallback, (void *) tw_callback, (XtPointer) twc);
 78 
 79     w = tw_charwidth(4.0 + nchars);
 80     h = tw_charheight(2.5);
 81     tw_set_entry(text, w, h);
 82     return (twc);
 83 }
 84 
 85 void    tw_fglobal_reset(void *ptwc)
 86 {
 87     Tw_callback *twc;
 88     double x;
 89     char string[64];
 90 
 91     if(!ptwc)
 92       return;
 93     
 94     twc = ptwc;
 95     x = *(double *) twc->data1;
 96       
 97     sprintf(string, "%g", x);
 98     if (!strchr(string, '.') && !strchr(string, 'e'))
 99         sprintf(string, "%.1f", x);
100     XmTextSetString(twc->widget, string);
101 }
102 
103 

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