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

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

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