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

Linux Cross Reference
Tina5/tina-tools/tinatool/wdgts/gtk2/wdgtsGtk_tw_button.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_button.c,v $
 37  * Date    :  $Date: 2009/03/27 16:01:50 $
 38  * Version :  $Revision: 1.4 $
 39  * CVS Id  :  $Id: wdgtsGtk_tw_button.c,v 1.4 2009/03/27 16:01:50 paul Exp $
 40  *
 41  * Author  :  a.lacey@man.ac.uk, giob@man.ac.uk, paul.bromiley@manchester.ac.uk
 42  *
 43  *********
 44 */
 45 /** 
 46  *  @file  wdgtsGtk_tw_button.c
 47  *  @brief Define and create GTK button and its associated callbacks.
 48  *
 49  *  Functions to create a GTK button and to define its use by linking it into the TINA 
 50  *  callback system using a Tw_callback struct.  The Tw_callback is passed as data in
 51  *  the gtk_signal_connect() call, and allows a range of functions to be associated with
 52  *  a single button.  
 53  *  Also defines the callback functions invoked when the button is used. 
 54  *
 55  *  Note that the functions in this file are duplicated for each widget set 
 56  *  (xv, GTK, xm, etc ...).
 57  *
 58  */
 59 
 60 #include "wdgtsGtk_tw_button.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 <tina/sys/sysDef.h>
 69 #include <tina/sys/sysPro.h>
 70 #include <tinatool/tlbase/tlbaseDef.h>
 71 #include <tinatool/tlbase/tlbasePro.h>
 72 #include <tinatool/wdgts/gtk2/wdgts_GtkDef.h>
 73 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_tool.h>
 74 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_command.h>
 75 
 76 
 77 /**
 78  * @brief  Invoke button function.  
 79  * @param  twc  Pointer to Tw_callback associated with this button.
 80  * 
 81  * Uses data2 field of Tw_callback to set the appropriate tool. 
 82  * (Via global variable in wdgtsGtk_tw_tool.c)
 83  *
 84  */
 85 static void button_call(Tw_callback *twc)
 86 {
 87     tw_set_tool((GtkWidget *)twc->data2);
 88     (*twc->func)(twc->data1);
 89 }
 90 
 91 /**
 92  * @brief  Replay button function from current macro file.  
 93  * @param  twc  Pointer to Tw_callback associated with this button.
 94  */
 95 static void button_cmnd(Tw_callback *twc)
 96 {
 97     tw_set_tool((GtkWidget *)twc->data2);
 98     (*twc->func)(twc->data1);
 99 }
100 
101 /**
102  * @brief  Record name of button in current macro file.  
103  * @param  fp   Pointer to current macro file.
104  * @param  twc  Pointer to Tw_callback associated with this button.
105  * 
106  * Records button press for macro replay facility. 
107  *
108  */
109 static void button_prnt(FILE * fp, Tw_callback *twc)
110 {
111     (void) fprintf(fp, "%s\n", twc->name);
112 }
113 
114 /**
115  * @brief  Create new GTK button and its associated callback struct.  
116  * @param  name  String to be used as button identifier and label.
117  * @param  func  Pointer to function to be invoked by button press.
118  * @param  data  Pointer to data required by func.
119  * 
120  * Creates new button and packs in current hbox.  Stores name of current tool
121  * in the associated Tw_callback (required to reset tool as current in case user 
122  * has been playing with other tools.
123  *
124  * Invokes callback for each button press, via call to tw_text_callback 
125  * (in wdgtsGtk_tw_command.c).
126  *
127  */
128 void tw_button(char *name, void (*func)(), void *data)
129 {
130   Tw_callback *twc;
131   GtkWidget   *tool  = tw_get_tool();
132   GtkWidget   *panel = tw_get_panel();
133   GtkWidget   *button;
134   GtkWidget   *buttox;
135   char        *fullname = tw_extend_fullname(tw_get_toolname(), name);
136 
137   /* Pack all buttons into a vbox inside the current hbox: this prevents the  
138      buttons expanding to fill the full vertical range of the current hbox, 
139      which causes them to be larger vertically if there is a choice or check 
140      list in the current hbox. PAB 27/03/2009 */
141 
142   buttox = gtk_vbox_new (FALSE, 0);
143   gtk_box_pack_start(GTK_BOX(panel), buttox, FALSE, FALSE, 0);
144   gtk_widget_show(buttox);
145 
146   button = gtk_button_new_with_label(name);
147   gtk_box_pack_end(GTK_BOX(buttox), button, FALSE, FALSE, 0);
148   gtk_widget_show(button);
149 
150   /* Special case of the file browser widget, which should not be 
151      started when running a macro.  Any button called scan or Scan
152      will NOT be added to macro files.  PAB 24/03/2009 */
153 
154   if (strcmp("scan", name)==0||strcmp("Scan", name)==0)
155   {
156     twc = tw_callback_make(fullname, button, button_call, button_cmnd, 
157                            NULL, func, data, (void *)tool);
158   }
159   else
160   {
161     twc = tw_callback_make(fullname, button, button_call, button_cmnd, 
162                            button_prnt, func, data, (void *)tool);
163   }
164 
165   gtk_signal_connect(GTK_OBJECT(button), "clicked", 
166                      GTK_SIGNAL_FUNC(tw_gtk_callback),
167                      (gpointer)twc);
168 }
169 
170 
171 /**
172  * @brief  Not used - consider removing - GAB 9 Oct 2003.  
173  *
174  * This is to define a button with an icon picture as well as a label.
175  * Tina has never used the Xv function so it is not implemented here.
176  */
177 Panel_item tw_icon_button(char *name, int w, int h, short *image_bits,
178                           void (*func) (/* * ???  */ ), int data)
179 {
180   return (0);
181 }
182 
183 /**
184  * @brief  Not used - consider removing - GAB 9 Oct 2003.  
185  *
186  */
187 void tw_button_reset_image(Panel_item button, int w, int h, short *image_bits)
188 {
189 }
190 
191 #ifdef INTERRUPT_BUTTON
192 
193 /**
194  * @brief  Not used - consider removing - GAB 9 Oct 2003.  
195  *
196  * This is to define an interrupt button to stop long calculations.
197  * Tina has never used the Xv function so it is not implemented here.
198  */
199 void tw_interrupt_button(void)
200 {
201 }
202 
203 /**
204  * @brief  Not used - consider removing - GAB 9 Oct 2003.  
205  *
206  */
207 void interrupt_button_data_get(Display ** display, Window * window)
208 {
209 }
210 #endif  /* INTERRUPT_BUTTON */
211 

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