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

Linux Cross Reference
Tina5/tina-tools/tinatool/wdgts/gtk2/wdgtsGtk_tw_sglobal.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_sglobal.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.2 $
 39  * CVS Id  :  $Id: wdgtsGtk_tw_sglobal.c,v 1.2 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_sglobal.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  *
 53  *  Note that the functions in this file are duplicated for each widget set (xv, GTK, xm, etc ...).
 54  *
 55  */
 56 
 57 #include "wdgtsGtk_tw_sglobal.h"
 58 
 59 #if HAVE_CONFIG_H
 60 #   include <config.h>
 61 #endif
 62 
 63 #include <stdio.h>
 64 #include <string.h>
 65 #include <gtk/gtk.h>
 66 #include <tinatool/wdgts/gtk2/wdgts_GtkDef.h>
 67 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_command.h>
 68 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_tool.h>
 69 
 70 
 71 /**
 72  * @brief Copy text from entry widget to stored callback data field.  
 73  * @param twc Pointer to Tw_callback associated with this text entry widget.
 74  * 
 75  * Callback function for text entry widgets.  Each of these has an associated 
 76  * Tw_callback, and this function uses a setter function stored in the data field 
 77  * of the Tw_callback to copy the current widget text to the desired variable.
 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 sglobal_call(Tw_callback * twc)
 84 {
 85   char   *ptr    = (char *) twc->data1;
 86   char   *string = (char *) gtk_entry_get_text(GTK_ENTRY(twc->widget));
 87 
 88   (void) strcpy(ptr, string);
 89 }
 90 
 91 /**
 92  * @brief   Replay text entry from current macro file.  
 93  * @param   twc   Pointer to Tw_callback associated with this widget.
 94  * @param   args  Pointer to required data, stored in the macro file.
 95  * 
 96  */
 97 static void sglobal_cmnd(Tw_callback * twc, char *args)
 98 {
 99   char   *ptr = (char *) twc->data1;
100 
101   (void) sscanf(args, "%*s %s", ptr);
102   gtk_entry_set_text(GTK_ENTRY(twc->widget), (const gchar *) ptr);
103 }
104 
105 /**
106  * @brief  Record text entry in current macro file.  
107  * @param  fp   Pointer to current macro file.
108  * @param  twc  Pointer to Tw_callback associated with this widget.
109  *
110  */
111 static void sglobal_prnt(FILE *fp, Tw_callback *twc)
112 {
113     char   *ptr = (char *) twc->data1;
114 
115     (void) fprintf(fp, "%s %s\n", twc->name, ptr);
116 }
117 
118 /**
119  * @brief  Create new text entry field and its associated callback struct.  
120  * @param  name    String to be used as entry field identifier and label.
121  * @param  ptr     Pointer to storage for text entered in the field.
122  * @param  nchars  Maximum number of characters for input field.
123  * @return Tw_callback  Pointer to new Tw_callback associated with this entry field.
124  * 
125  * Creates new hbox for text entry field, and packs field and label in it.
126  *
127  * Invokes callback for each keypress, via call to tw_text_callback 
128  * (in wdgtsGtk_tw_command.c).
129  *
130  */
131 Tw_callback   *tw_sglobal(char *name, char *ptr, int nchars)
132 {
133   GtkWidget    *panel= tw_get_panel();
134   GtkWidget    *box;
135   GtkWidget    *stxlabel;
136   GtkWidget    *stxentry;
137 
138   Tw_callback  *twc;
139   char         *fullname = tw_extend_fullname(tw_get_toolname(), name);
140 
141   box = gtk_hbox_new(FALSE, 8);
142   gtk_container_add(GTK_CONTAINER(panel), box);
143   gtk_widget_show(box); 
144         
145   stxlabel = gtk_label_new(name);
146   stxentry = gtk_entry_new();
147   gtk_widget_set_usize(stxentry, (10+6*nchars), 22);
148   gtk_box_pack_start(GTK_BOX(box), stxlabel, FALSE, FALSE, 0);
149   gtk_box_pack_start(GTK_BOX(box), stxentry, FALSE, FALSE, 0);
150   gtk_widget_show(stxlabel);
151   gtk_widget_show(stxentry);
152 
153   twc = tw_callback_make(fullname, stxentry,
154                          sglobal_call, sglobal_cmnd, sglobal_prnt, (void (*) ()) NULL,
155                          (void *) ptr, NULL);
156 
157   /*  Invoke callback for GTK entry "changed" event (i.e. for each keypress) */
158   gtk_signal_connect(GTK_OBJECT(stxentry), "changed",
159                      GTK_SIGNAL_FUNC(tw_gtk_callback),
160                      (gpointer) twc);
161   
162   return (twc);
163 }
164 
165 /**
166  * @brief Reset text entry field when text has been altered.  
167  * @param twc  Pointer to Tw_callback associated with this text entry widget.
168  * 
169  * NOTE: NOT TESTED YET - GAB 9 Oct 2003.
170  *
171  */
172 void tw_sglobal_reset(Tw_callback * twc)
173 {
174   char   *string;
175  
176   if (twc == NULL)
177     return;
178   string = (char *) twc->data1;
179   gtk_entry_set_text(GTK_ENTRY(twc->widget), string);
180 }
181 

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