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

Linux Cross Reference
Tina6/tina-tools/tinatool/wdgts/gtk2/wdgtsGtk_tw_svalue.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/gtk2/wdgtsGtk_tw_svalue.c,v $
 37  * Date    :  $Date: 2008/12/02 22:04:19 $
 38  * Version :  $Revision: 1.3 $
 39  * CVS Id  :  $Id: wdgtsGtk_tw_svalue.c,v 1.3 2008/12/02 22:04:19 paul Exp $
 40  *
 41  * Author  :  a.lacey@man.ac.uk, giob@man.ac.uk
 42  *
 43  *********
 44 */
 45 /** 
 46  *  @file  wdgtsGtk_tw_svalue.c
 47  *  @brief Define and create GTK text entry field and its associated callbacks.
 48  *
 49  *  Functions to create a GTK text entry field and to define its use by linking it into 
 50  *  the TINA callback system using a Tw_callback struct.  Also defines the callback functions
 51  *  invoked when the entry field is used.  
 52  *  tw_svalue differs from tw_sglobal in that the latter uses a pointer to locate the global
 53  *  data whereas the former uses setter and getter functions.  Both forms are used in the Xv
 54  *  Tina and both are retained to maximise cross-compatibility in the Gtk Tina.
 55  *
 56  *  Note that the functions in this file are duplicated for each widget set (xv, GTK, xm, etc ...).
 57  *
 58  */
 59 
 60 #include "wdgtsGtk_tw_svalue.h"
 61 
 62 #if HAVE_CONFIG_H
 63 #   include <config.h>
 64 #endif
 65 
 66 #include <stdio.h>
 67 #include <sys/param.h>
 68 #include <gtk/gtk.h>
 69 #include <tinatool/wdgts/gtk2/wdgts_GtkDef.h>
 70 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_command.h>
 71 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_tool.h>
 72 
 73 
 74 /**
 75  * @brief Copy text from entry widget to stored callback data field.  
 76  * @param twc  Pointer to Tw_callback associated with this integer entry widget.
 77  * 
 78  * Callback function for text entry widgets.  Each of these has an associated 
 79  * Tw_callback, and this function uses a setter function stored in the data field 
 80  * of the Tw_callback to copy the current widget integer to the desired variable.
 81  *
 82  * Note that this callback is not invoked directly by the widget, but via a call
 83  * to tw_text_callback (in wdgtsGtk_tw_command.c).
 84  */
 85 static void svalue_call(Tw_callback * twc)
 86 {
 87   void (*set)() = (void (*) ()) twc->data2;
 88   char  *string = (char *) gtk_entry_get_text(GTK_ENTRY(twc->widget));
 89 
 90   (*set) (string);
 91 }
 92 
 93 /**
 94  * @brief   Replay text 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 svalue_cmnd(Tw_callback * twc, char *args)
100 {
101   void (*set)() = (void (*) ()) twc->data2;
102   char   string[64];
103 
104   (void) sscanf(args, "%*s %s", string);
105   (*set) (string);
106   gtk_entry_set_text(GTK_ENTRY(twc->widget), string);
107 }
108 
109 /**
110  * @brief  Record text 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 svalue_prnt(FILE * fp, Tw_callback * twc)
116 {
117   /* char *(*get)() = (char (*) ()) twc->data1; */
118   char *(*get)() = (char * (*) ()) twc->data1; /* JD, 2015.01.26 */
119 
120   (void) fprintf(fp, "%s %s\n", twc->name, (*get)());
121 }
122 
123 
124 /**
125  * @brief  Create new text entry field and its associated callback struct.  
126  * @param  name    String to be used as entry field identifier and label.
127  * @param  get()   Pointer to getter function for text entered in the field.
128  * @param  set()   Pointer to setter function for text entered in the field.
129  * @param  nchars  Maximum number of characters for input field.
130  * @return Tw_callback  Pointer to new Tw_callback associated with this entry field.
131  * 
132  * Creates new hbox for text entry field, and packs field and label in it.  
133  *
134  * Invokes callback for each keypress, via call to tw_text_callback 
135  * (in wdgtsGtk_tw_command.c).
136  *
137  */
138 Tw_callback *tw_svalue(char *name, char *(*get)(), void (*set)(), int nchars)
139 {
140   GtkWidget *panel= tw_get_panel();
141   GtkWidget *box;
142   GtkWidget *stxlabel;
143   GtkWidget *stxentry;
144 
145   Tw_callback  *twc;
146   char         *fullname = tw_extend_fullname(tw_get_toolname(), name);
147 
148   char    *string;
149 
150   box = gtk_hbox_new(FALSE, 8);
151   gtk_container_add(GTK_CONTAINER(panel), box);
152   gtk_widget_show(box); 
153         
154   stxlabel = gtk_label_new(name);
155   stxentry = gtk_entry_new();
156   gtk_widget_set_usize(stxentry, (10+6*nchars), 22);
157   gtk_box_pack_start(GTK_BOX(box), stxlabel, FALSE, FALSE, 0);
158   gtk_box_pack_start(GTK_BOX(box), stxentry, FALSE, FALSE, 0);
159   gtk_widget_show(stxlabel);
160   gtk_widget_show(stxentry);
161   
162   string = (get) ();
163   gtk_entry_set_text(GTK_ENTRY(stxentry), string);
164 
165   twc = tw_callback_make(fullname, stxentry,
166                          svalue_call, svalue_cmnd, svalue_prnt, (void (*) ()) NULL,
167                          (void *) get, (void *) set);
168 
169   /*  Invoke callback for GTK entry "changed" event (i.e. for each keypress) */
170   gtk_signal_connect(GTK_OBJECT(stxentry), "changed",
171                      GTK_SIGNAL_FUNC(tw_gtk_callback),
172                      (gpointer) twc);
173   
174   return (twc);
175 }
176 
177 /**
178  * @brief Reset text entry field when value has been altered in the program.  
179  * @param twc    Pointer to Tw_callback associated with this text entry widget.
180  * 
181  * NOTE: NOT TESTED YET - GAB 10 Oct 2003.
182  * Fixed+tested+working - PAB 12/03/2010.
183  *
184  */
185 void tw_svalue_reset(Tw_callback * twc)
186 {
187   char  *(*get)();
188   char   *pstring=NULL;
189   char string[MAXPATHLEN];
190 
191   if (twc == NULL) return;
192 
193   get = (char *(*)()) twc->data1;
194   pstring = get();
195   (void) sprintf(string, "%s", pstring);
196   gtk_entry_set_text(GTK_ENTRY(twc->widget), string);
197 }
198 

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