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

Linux Cross Reference
Tina5/tina-tools/tinatool/wdgts/gtk/wdgtsGtk_tw_fglobal.c

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

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :  TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/wdgts/gtk/wdgtsGtk_tw_fglobal.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.3 $
 39  * CVS Id  :  $Id: wdgtsGtk_tw_fglobal.c,v 1.3 2007/02/15 01:55:50 paul Exp $
 40  *
 41  * Author  :  a.lacey@man.ac.uk, giob@man.ac.uk
 42  *
 43  *********
 44 */
 45 /** 
 46  *  @file  wdgtsGtk_tw_fglobal.c
 47  *  @brief Define and create GTK float entry field and its associated callbacks.
 48  *
 49  *  Functions to create a GTK float entry field and to define its use by linking it into the TINA 
 50  *  the TINA callback system using a Tw_callback struct.  Also defines the callback functions
 51  *  invoked when the buttons are used.  Note that a float entry field in GTK is just a text
 52  *  entry field, but TINA handles it differently.
 53  *
 54  *  Note that the functions in this file are duplicated for each widget set (xv, GTK, xm, etc ...).
 55  *
 56  */
 57 
 58 #include "wdgtsGtk_tw_fglobal.h"
 59 
 60 #if HAVE_CONFIG_H
 61 #   include <config.h>
 62 #endif
 63 
 64 #include <stdio.h>
 65 #include <string.h>
 66 #include <gtk/gtk.h>
 67 #include <tinatool/wdgts/gtk/wdgts_GtkDef.h>
 68 #include <tinatool/wdgts/gtk/wdgtsGtk_tw_command.h>
 69 #include <tinatool/wdgts/gtk/wdgtsGtk_tw_tool.h>
 70 
 71 /**
 72  * @brief Copy float from entry widget to stored callback data field.  
 73  * @param twc Pointer to Tw_callback associated with this float entry widget.
 74  * 
 75  * Callback function for float entry widgets.  Each of these has an associated 
 76  * Tw_callback, and this function copies the current widget float into the data  
 77  * field of the Tw_callback.
 78  *
 79  * Note that this callback is not invoked directly by the widget, but via a call
 80  * to tw_text_callback (in wdgtsGtk_tw_command.c).
 81  *
 82  */
 83 static void fglobal_call(Tw_callback * twc)
 84 {
 85   double   x; 
 86   double  *ptr = (double *) twc->data1;
 87   char    *string = (char *) gtk_entry_get_text(GTK_ENTRY(twc->widget));
 88 
 89   if (sscanf(string, "%lf", &x) == 1)
 90     *ptr = x;
 91 }
 92 
 93 /**
 94  * @brief   Replay float entry from current macro file.  
 95  * @param   twc   Pointer to Tw_callback associated with this widget.
 96  * @param   args  Pointer to required data, stored in the macro file.
 97  * 
 98  */
 99 static void fglobal_cmnd(Tw_callback * twc, char *args)
100 {
101   double  *ptr = (double *) twc->data1;
102   char     string[64];
103 
104   (void) sscanf(args, "%*s %lf", ptr);
105   (void) sscanf(args, "%*s %s", string);
106   gtk_entry_set_text(GTK_ENTRY(twc->widget), string);
107 }
108 
109 /**
110  * @brief  Record float entry in current macro file.  
111  * @param  fp   Pointer to current macro file.
112  * @param  twc  Pointer to Tw_callback associated with this widget.
113  *
114  */
115 static void fglobal_prnt(FILE * fp, Tw_callback * twc)
116 {
117   double  x = *(double *) twc->data1;
118 
119   (void) fprintf(fp, "%s %g\n", twc->name, x);
120 }
121 
122 /**
123  * @brief  Create new float entry field and its associated callback struct.  
124  * @param  name    String to be used as entry field identifier and label.
125  * @param  ptr     Pointer to storage for float entered in the field.
126  * @param  nchars  Maximum number of characters for input field.
127  * @return Tw_callback  Pointer to new Tw_callback associated with this entry field.
128  * 
129  * Creates new hbox for float entry field, and packs field and label in it.  
130  *
131  * Invokes callback for each keypress, via call to tw_text_callback 
132  * (in wdgtsGtk_tw_command.c).
133  *
134  */
135 Tw_callback *tw_fglobal(char *name, double *ptr, int nchars)
136 {
137   GtkWidget *panel= tw_get_panel();
138   GtkWidget *box;
139   GtkWidget *ftxlabel;
140   GtkWidget *ftxentry;
141 
142   char    string[32];
143   double  value;
144 
145   Tw_callback *twc;
146   char   *fullname = tw_extend_fullname(tw_get_toolname(), name);
147 
148   box = gtk_hbox_new(FALSE, 8);
149   gtk_container_add(GTK_CONTAINER(panel), box);
150   gtk_widget_show(box);
151 
152   ftxlabel = gtk_label_new(name);
153   ftxentry = gtk_entry_new();
154   gtk_widget_set_usize(ftxentry, (10+6*nchars), 22);
155   gtk_box_pack_start(GTK_BOX(box), ftxlabel, FALSE, FALSE, 0);
156   gtk_box_pack_start(GTK_BOX(box), ftxentry, FALSE, FALSE, 0);
157   gtk_widget_show(ftxlabel);
158   gtk_widget_show(ftxentry);
159   
160   value = *ptr;
161   (void) sprintf(string, "%g", value);
162   if (!strchr(string, '.') && !strchr(string, 'e'))
163   {
164     /* Ensure at least one decimal place is shown */
165     (void) sprintf(string, "%.1f", value);
166   }
167   gtk_entry_set_text(GTK_ENTRY(ftxentry), string);
168 
169   twc = tw_callback_make(fullname, ftxentry,
170                          fglobal_call, fglobal_cmnd, fglobal_prnt, (void (*) ()) NULL,
171                          (void *) ptr, NULL);
172 
173   /*  Invoke callback for GTK entry "changed" event (i.e. for each keypress) */
174   gtk_signal_connect(GTK_OBJECT(ftxentry), "changed",
175                      GTK_SIGNAL_FUNC(tw_gtk_callback),
176                      (gpointer) twc);
177   
178   return (twc);
179 }
180 
181 /**
182  * @brief Reset float entry field when value has been altered.  
183  * @param twc    Pointer to Tw_callback associated with this text entry widget.
184  * 
185  * NOTE: NOT TESTED YET - GAB 10 Oct 2003.
186  *
187  */
188 void tw_fglobal_reset(Tw_callback * twc)
189 {
190   double *val;
191   char    string[64];
192 
193   if (twc == NULL)
194     return;
195 
196   val = (double *) twc->data1;
197   (void) sprintf(string, "%g", *val);
198   if (!strchr(string, '.') && !strchr(string, 'e'))
199   {
200     /* Ensure at least one decimal place is shown (JB 2/3/93) */
201     (void) sprintf(string, "%.1f", *val);
202   }
203   gtk_entry_set_text(GTK_ENTRY(twc->widget), string);
204 }
205 
206 

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