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

Linux Cross Reference
Tina5/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 <gtk/gtk.h>
 68 #include <tinatool/wdgts/gtk2/wdgts_GtkDef.h>
 69 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_command.h>
 70 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_tool.h>
 71 
 72 
 73 /**
 74  * @brief Copy text from entry widget to stored callback data field.  
 75  * @param twc  Pointer to Tw_callback associated with this integer entry widget.
 76  * 
 77  * Callback function for text entry widgets.  Each of these has an associated 
 78  * Tw_callback, and this function uses a setter function stored in the data field 
 79  * of the Tw_callback to copy the current widget integer to the desired variable.
 80  *
 81  * Note that this callback is not invoked directly by the widget, but via a call
 82  * to tw_text_callback (in wdgtsGtk_tw_command.c).
 83  */
 84 static void svalue_call(Tw_callback * twc)
 85 {
 86   void (*set)() = (void (*) ()) twc->data2;
 87   char  *string = (char *) gtk_entry_get_text(GTK_ENTRY(twc->widget));
 88 
 89   (*set) (string);
 90 }
 91 
 92 /**
 93  * @brief   Replay text entry from current macro file.  
 94  * @param   twc   Pointer to Tw_callback associated with this widget.
 95  * @param   args  Pointer to required data, stored in the macro file.
 96  * 
 97  */
 98 static void svalue_cmnd(Tw_callback * twc, char *args)
 99 {
100   void (*set)() = (void (*) ()) twc->data2;
101   char   string[64];
102 
103   (void) sscanf(args, "%*s %s", string);
104   (*set) (string);
105   gtk_entry_set_text(GTK_ENTRY(twc->widget), string);
106 }
107 
108 /**
109  * @brief  Record text entry in current macro file.  
110  * @param  fp   Pointer to current macro file.
111  * @param  twc  Pointer to Tw_callback associated with this widget.
112  *
113  */
114 static void svalue_prnt(FILE * fp, Tw_callback * twc)
115 {
116   char *(*get)() = (char (*) ()) twc->data1;
117 
118   (void) fprintf(fp, "%s %s\n", twc->name, (*get)());
119 }
120 
121 
122 /**
123  * @brief  Create new text entry field and its associated callback struct.  
124  * @param  name    String to be used as entry field identifier and label.
125  * @param  get()   Pointer to getter function for text entered in the field.
126  * @param  set()   Pointer to setter function for text entered in the field.
127  * @param  nchars  Maximum number of characters for input field.
128  * @return Tw_callback  Pointer to new Tw_callback associated with this entry field.
129  * 
130  * Creates new hbox for text entry field, and packs field and label in it.  
131  *
132  * Invokes callback for each keypress, via call to tw_text_callback 
133  * (in wdgtsGtk_tw_command.c).
134  *
135  */
136 Tw_callback *tw_svalue(char *name, char *(*get)(), void (*set)(), int nchars)
137 {
138   GtkWidget *panel= tw_get_panel();
139   GtkWidget *box;
140   GtkWidget *stxlabel;
141   GtkWidget *stxentry;
142 
143   Tw_callback  *twc;
144   char         *fullname = tw_extend_fullname(tw_get_toolname(), name);
145 
146   char    *string;
147 
148   box = gtk_hbox_new(FALSE, 8);
149   gtk_container_add(GTK_CONTAINER(panel), box);
150   gtk_widget_show(box); 
151         
152   stxlabel = gtk_label_new(name);
153   stxentry = gtk_entry_new();
154   gtk_widget_set_usize(stxentry, (10+6*nchars), 22);
155   gtk_box_pack_start(GTK_BOX(box), stxlabel, FALSE, FALSE, 0);
156   gtk_box_pack_start(GTK_BOX(box), stxentry, FALSE, FALSE, 0);
157   gtk_widget_show(stxlabel);
158   gtk_widget_show(stxentry);
159   
160   string = (get) ();
161   gtk_entry_set_text(GTK_ENTRY(stxentry), string);
162 
163   twc = tw_callback_make(fullname, stxentry,
164                          svalue_call, svalue_cmnd, svalue_prnt, (void (*) ()) NULL,
165                          (void *) get, (void *) set);
166 
167   /*  Invoke callback for GTK entry "changed" event (i.e. for each keypress) */
168   gtk_signal_connect(GTK_OBJECT(stxentry), "changed",
169                      GTK_SIGNAL_FUNC(tw_gtk_callback),
170                      (gpointer) twc);
171   
172   return (twc);
173 }
174 
175 /**
176  * @brief Reset text entry field when value has been altered in the program.  
177  * @param twc    Pointer to Tw_callback associated with this text entry widget.
178  * 
179  * NOTE: NOT TESTED YET - GAB 10 Oct 2003.
180  *
181  */
182 void tw_svalue_reset(Tw_callback * twc)
183 {
184   char  *(*get)();
185   char   *string;
186 
187   if (twc == NULL)
188     return;
189 
190   get = (char *(*)()) twc->data1;
191   string = get();
192   gtk_entry_set_text(GTK_ENTRY(twc->widget), string);
193 }
194 

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