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

Linux Cross Reference
Tina4/src/Xv/tw_fvalue.c

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

  1 /**@(#)
  2 **/
  3 #include <stdio.h>
  4 #include <math.h>
  5 #include <tina/sys.h>
  6 #include <tina/math.h>
  7 #include <tina/tw.h>
  8 #include <tina/tv.h>
  9 #include <tina/tvfuncs.h>
 10 #include <tina/tv_screen.h>
 11 #include <xview/xview.h>
 12 #include <xview/frame.h>
 13 #include <xview/panel.h>
 14 #include <xview/textsw.h>
 15 #include <xview/font.h>
 16 #include <xview/canvas.h>
 17 #include <xview/cms.h>
 18 #include <xview/xv_xrect.h>
 19 #include <xview/openmenu.h>
 20 #include <tina/Xvfuncs.h>
 21 #include <tina/X11funcs.h>
 22 
 23 
 24 
 25 static void fvalue_call(Tw_callback * twc)
 26 {
 27     double  x;
 28     void    (*set) () = (void (*) ()) twc->data2;
 29     char   *string = (char *) xv_get(twc->window, PANEL_VALUE);
 30 
 31     if (sscanf(string, "%lf", &x) == 1)
 32         (*set) (x);
 33 }
 34 
 35 static void fvalue_cmnd(Tw_callback * twc, char *args)
 36 {
 37     double  x;
 38     void    (*set) () = (void (*) ()) twc->data2;
 39     char    string[64];
 40 
 41     (void) sscanf(args, "%*s %lf", &x);
 42     (*set) (x);
 43     (void) sscanf(args, "%*s %s", string);
 44     xv_set(twc->window, PANEL_VALUE, string, NULL);
 45 }
 46 
 47 static void fvalue_prnt(FILE * fp, Tw_callback * twc)
 48 {
 49     int     (*get) () = (int (*) ()) twc->data1;
 50 
 51     (void) fprintf(fp, "%s %lf\n", twc->name, (*get) ());
 52 }
 53 
 54 Tw_callback *tw_fvalue(char *name, double (*get) ( /* ??? */ ), void (*set) ( /* ??? */ ), int nchars)
 55 {
 56     Panel_item text;
 57     Panel   panel = tw_get_panel();
 58     Bool    newrow = tw_get_newrow();
 59     int     row;
 60     char    string[32];
 61     Tw_callback *twc;
 62     char   *fullname = tw_extend_fullname(tw_get_toolname(), name);
 63     double  val = (*get) ();
 64 
 65     (void) sprintf(string, "%g", val);
 66     if (!strchr(string, '.') && !strchr(string, 'e'))
 67     {
 68         /* Ensure at least one decimal place is shown (JB 2/3/93) */
 69         (void) sprintf(string, "%.1f", val);
 70     }
 71     text = xv_create(panel, PANEL_TEXT,
 72                      PANEL_LABEL_STRING, name,
 73                      PANEL_VALUE_DISPLAY_LENGTH, nchars,
 74                      PANEL_VALUE, string,
 75                      PANEL_NOTIFY_LEVEL, PANEL_ALL,
 76                      NULL);
 77 
 78     twc = tw_callback_make(fullname, text,
 79                            fvalue_call, fvalue_cmnd, fvalue_prnt, (void (*) ()) NULL, (void *) get,
 80                            (void *) set);
 81 
 82     xv_set(text,
 83            PANEL_NOTIFY_PROC, tw_text_callback,
 84            PANEL_CLIENT_DATA, twc,
 85            NULL);
 86 
 87     if (newrow)
 88     {
 89         row = tw_get_row();
 90         xv_set(text,
 91                XV_X, xv_col(panel, 0),
 92                XV_Y, xv_row(panel, row),
 93                NULL);
 94         tw_set_newrow(false);
 95     }
 96     return (twc);
 97 }
 98 
 99 void    tw_fvalue_reset(Tw_callback * twc)
100 {
101     double  (*get) (), val;
102     char    string[64];
103 
104     if (twc == NULL)
105         return;
106 
107     get = (double (*) ()) twc->data1;
108     val = get();
109     (void) sprintf(string, "%g", val);
110     if (!strchr(string, '.') && !strchr(string, 'e'))
111     {
112         /* Ensure at least one decimal place is shown (JB 2/3/93) */
113         (void) sprintf(string, "%.1f", val);
114     }
115     xv_set(twc->window, PANEL_VALUE, string, NULL);
116 }
117 

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