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

Linux Cross Reference
Tina6/tina-tools/tinatool/wdgts/gtk2/wdgtsGtk_tw_tool.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_tool.c,v $
 37  * Date    :  $Date: 2009/05/13 15:38:15 $
 38  * Version :  $Revision: 1.5 $
 39  * CVS Id  :  $Id: wdgtsGtk_tw_tool.c,v 1.5 2009/05/13 15:38:15 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_tool.c
 47  *  @brief Define and create a Tina windows top level tool.
 48  *
 49  *  Functions to create a GTK Window.
 50  *
 51  *  And to do lots of additional stuff ,... 
 52  *
 53  *  Note that the functions in this file are duplicated for each widget set 
 54  *  (xv, GTK, xm, etc ...).
 55  */
 56 
 57 #include "wdgtsGtk_tw_tool.h"
 58 
 59 #if HAVE_CONFIG_H
 60 #   include <config.h>
 61 #endif
 62 
 63 #include <stdio.h>
 64 #include <gtk/gtk.h>
 65 #include <tina/sys/sysGen_format.h>
 66 #include <tinatool/wdgts/gtk2/wdgts_GtkDef.h>
 67 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_tool.h>
 68 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_command.h>
 69 
 70 #include "wdgtsGtk_tw_init.h"
 71 #include "wdgtsGtk_tw_sv_btn.h"
 72 
 73 static GtkWidget  *tool    = NULL;
 74 static GtkWidget  *toptool = NULL;
 75 static GtkWidget  *hbox    = NULL;
 76 static GtkWidget  *vbox    = NULL;
 77 static GtkWidget  *menubox = NULL;
 78 
 79 static char  *toolname = NULL;
 80 
 81 static int    tool_width;          /** Width in pixels of tool frame */
 82 static int    tool_xpos;           /** Top left x in pixels of tool frame */
 83 static int    tool_ypos;           /** Top left y in pixels of tool frame */
 84 
 85 
 86 /**
 87  * @brief   Used in Motif Tina for interrupt handling.  
 88  * 
 89  * Will only be implemented in GTK Tina if it proves necessary. 
 90  */
 91 void tw_active_tool_data_set(Display * display, Window window)
 92 {
 93 }
 94 
 95 
 96 /**
 97  * @brief   Used in Motif Tina for interrupt handling.  
 98  * 
 99  * Will only be implemented in GTK Tina if it proves necessary. 
100  */
101 void tw_active_tool_data_get(Display ** display, Window * window)
102 {
103 }
104 
105 /**
106  * @brief   Getter for tool width.  
107  * @return  int  Current width of tool in pixels.
108  */
109 int tw_get_width(void)
110 {
111   return (tool_width);
112 }
113 
114 /**
115  * @brief   Setter for tool width.  
116  * @param   w  New width for tool in pixels.
117  * 
118  * Used to reset tool width if user instantiates a canvas or text area wider than 
119  * that of the  tool
120  */
121 void tw_set_width(int w)
122 {
123   tool_width = w;
124 }
125 
126 /**
127  * @brief   Getter for menubox.  
128  * @return  GtkWidget *  Pointer to menubox of current tool.
129  * 
130  * Used to reset tool width if user instantiates a canvas or text area wider than 
131  * the top level tool. 
132  */
133 GtkWidget  *tw_get_menubox(void)
134 {
135   return (menubox);
136 }
137 
138 /** Start of macro stuff */
139 
140 /**
141  * @brief   Set the top-left co-ordinates of the given widget.  
142  * @param   user_tool   Pointer to GTK widget.
143  * @param   x           Integer requisition for x-position.
144  * @param   y           Integer requisition for y-position.
145  * 
146  * GTK uses the concept of a position requisition, i.e. this function
147  * requests n x,y position but the actual co-ordinates are allocated by 
148  * the window manager and stored in the GtkAllocation associated with 
149  * the GtkWidget. 
150  */
151 void tw_set_pos(GtkWidget *user_tool, int x, int y)
152 {
153   gtk_widget_set_uposition(user_tool, (gint)x, (gint)y);
154 }
155 
156 /**
157  * @brief   Get the allocated dimensions of a tool window.  
158  * @param   user_tool  Pointer to tool window for which to get dimensions.
159  * @param   x          Pointer to integer x of top left.
160  * @param   y          Pointer to integer y of top left.
161  * @param   w          Pointer to integer tool window width.
162  * @param   h          Pointer to integer tool window height.
163  * 
164  * This uses the GtkAllocation associated with the GtkWidget, to 
165  * retrieve the actual dimensions allocated by the window manager. 
166  */
167 void tw_get_geom(GtkWidget *user_tool, int *x, int *y, int *w, int *h)
168 {
169   gdk_window_get_root_origin(user_tool->window, (gint *)x, (gint *)y);
170 
171   *w = (int)user_tool->allocation.width;
172   *h = (int)user_tool->allocation.height;
173 }
174 
175 /**
176  * @brief   Set the requisition dimensions of a tool window.  
177  * @param   user_tool  Pointer to tool window for which to get dimensions.
178  * @param   x          Integer x of top left.
179  * @param   y          Integer y of top left.
180  * @param   w          Integer tool window width.
181  * @param   h          Integer tool window height.
182  * 
183  * GTK only requests dimensions, window manager allocates as appropriate.
184  * x and y required for compatibility, but not used. 
185  */
186 void tw_set_geom(GtkWidget *user_tool, int x, int y, int w, int h)
187 {
188   if(user_tool == toptool)
189     gtk_window_set_default_size(GTK_WINDOW(user_tool), (gint) w, (gint) h);
190   else
191     /* gtk_widget_set_usize(user_tool, (gint) w, (gint) h); Old version from GTK+1 */
192     gtk_window_resize(GTK_WINDOW(user_tool), (gint) w, (gint) h);
193   tw_set_pos(user_tool, x, y);
194 }
195 
196 /**
197  * @brief   Restore tool window "geometry" from macro file.  
198  * @param   twc   Pointer to Tw_callback for this tool window.
199  * @param   args  Stored data from macro file.
200  * 
201  * Not tested and probably wrong, but never mind. 
202  * GAB 20 Nov 2003.
203  */
204 static void tool_cmnd(Tw_callback *twc, char *args)
205 {
206   int     x, y, w, h, closed;
207 
208   (void) sscanf(args, "%*s %d %d %d %d %d",
209                   &x, &y, &w, &h, &closed);
210   tw_set_geom((GtkWidget *)twc->widget, x, y, w, h);
211 }
212 
213 /**
214  * @brief   Store tool window "geometry" in macro file.  
215  * @param   fp   File pointer to macro file.
216  * @param   twc  Pointer to Tw_callback for this tool window.
217  *
218  * Not tested and probably wrong, but never mind. 
219  * GAB 20 Nov 2003.
220  */
221 static void tool_prnt(FILE *fp, Tw_callback *twc)
222 {
223   int   x, y, w, h, closed = 0;
224   int   x_top, y_top;
225 
226   tw_get_geom(toptool, &x_top, &y_top, &w, &h);
227   tw_get_geom((GtkWidget *)twc->widget, &x, &y, &w, &h);
228   if (((x_top + x) == 0) && ((y_top + y) == 0))
229   {
230     format("poorly defined location from xv_get() for %s \n", twc->name);
231     format("append macro and reposition \n");
232     x = 0;
233     y = 0;
234   }
235   (void) fprintf(fp, "%s %d %d %d %d %d\n",
236                      twc->name, x, y, w, h, closed);
237 }
238 
239 /** 
240  * End of macro stuff
241  */
242 
243 
244 /**
245  * Start of tool & panel handling
246  */
247 
248 /**
249  * @brief   Getter for toptool handle.  
250  * @return  GtkWidget *   Pointer to current value of static toptool handle.
251  */
252 GtkWidget *tw_get_toptool(void)
253 {
254   return (toptool);
255 }
256 
257 /**
258  * @brief   Getter for tool handle.  
259  * @return  GtkWidget *   Pointer to current value of static tool handle.
260  */
261 GtkWidget *tw_get_tool(void)
262 {
263   return (tool);
264 }
265 
266 /**
267  * @brief   Setter for tool handle.  
268  * @param   newtool   Pointer to new value for static tool handle.
269  */
270 void tw_set_tool(GtkWidget *newtool)
271 {
272   tool = newtool;
273 }
274 
275 /**
276  * @brief   Start a new row in the tool.  
277  * 
278  * In GTK this means simply packing a new hbox into the tool's vbox. 
279  */
280 void tw_newrow(void)
281 {
282   hbox = gtk_hbox_new(FALSE, 5);
283   gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 2);
284   gtk_widget_show(hbox);
285 }
286 
287 /**
288  * @brief   Getter for current panel (hbox) handle.  
289  * @return  GtkWidget *   Pointer to current value of static hbox handle.
290  */
291 GtkWidget *tw_get_panel(void)
292 {  
293   return(hbox);
294 }
295 
296 /**
297  * @brief   Getter for current window container (vbox) handle.  
298  * @return  GtkWidget *   Pointer to current value of static vbox handle.
299  */
300 GtkWidget *tw_get_vbox(void)
301 {  
302   return(vbox);
303 }
304 
305 /**
306  * @brief   Setter for current panel (hbox) handle.  
307  * @param   newtool   Pointer to new value for static hbox handle.
308  */
309 void tw_set_panel(GtkWidget *newpanel)
310 {
311   hbox = newpanel;
312 }
313 
314 /**
315  * @brief   Does nothing, but called from tools level so keep.  
316  * 
317  * Apparently used in Motif Tina. 
318  */
319 void tw_no_panel(void)
320 {
321 }
322 
323 /**
324  * @brief   Setter for current toolname.  
325  * @param   newtool   String value of new toolname.
326  */
327 void tw_set_toolname(char *name)
328 {
329   toolname = name;
330 }
331 
332 /**
333  * @brief   Getter for current toolname.  
334  * @return  char *   String value of current toolname.
335  */
336 char *tw_get_toolname(void)
337 {
338   return (toolname);
339 }
340 
341 /**
342  * @brief   If the tool is hidden, show it.  
343  * @param   tool   Pointer to the tool to be shown.
344  *
345  * A rare example of Tina DBC - only called if the tool already exists. 
346  */
347 void tw_show_tool(GtkWidget *user_tool)
348 {
349   gtk_widget_show(user_tool);
350 }
351 
352 /* Callback to quit tinatool */
353 /**
354  * @brief   Quit if delete signal from toptool otherwise hide tool.  
355  * @param   widget  Pointer to tool window from which delete signal was emitted.
356  * @param   event   Pointer to GdkEvent structure (not used).
357  * @param   data    Pointer to incoming data (not used).
358  * @return  gboolean   FALSE if quitting, TRUE otherwise.
359  * 
360  * The params event and data are required by the GTK delete event callback
361  * prototype, but not used in GTK Tina. 
362  */
363 gboolean tw_delete_event( GtkWidget *widget,
364                           GdkEvent  *event,
365                           gpointer   data )
366 {
367   if(widget == toptool)
368   {
369     gtk_main_quit();
370     return(FALSE);
371   }
372   else
373   {
374     gtk_widget_hide(widget);
375     return(TRUE);
376   }
377 }
378 
379 /**
380  * @brief   Create new top level Tina Windows tool.  
381  * @param   name    String name for tool & for title bar.
382  * @param   x       Integer x position in pixels (not used!).
383  * @param   y       Integer y position in pixels (not used!).
384  * @return  GtkWidget *    Pointer to a new GtkWindow.
385  */
386 GtkWidget *tw_tool_remote(char *name, int x, int y)
387 {
388   Tw_callback *twc;
389   GtkWidget   *label;
390 
391   tool_xpos = x;    /** Positioning and sizing done in tw_end_tool ... */
392   tool_ypos = y;    /** ... in Xv tina.  We don't use yet but ... */
393 
394   tool = gtk_window_new(GTK_WINDOW_TOPLEVEL);
395   /* gtk_window_set_policy(GTK_WINDOW(tool), TRUE, TRUE, TRUE); Deprecated function in GTK2*/
396   gtk_window_set_resizable(GTK_WINDOW(tool), TRUE);
397 
398   if (toptool == NULL)
399   {
400     toptool = tool;
401   }
402 
403   vbox = gtk_vbox_new(FALSE, 0);
404   hbox = gtk_hbox_new(FALSE, 5);
405 
406   menubox = gtk_hbox_new(FALSE, 5);
407   gtk_box_pack_start(GTK_BOX(vbox), menubox, FALSE, FALSE, 0);
408   gtk_widget_show(menubox);
409 
410   gtk_window_set_title (GTK_WINDOW (tool), name);
411   gtk_container_set_border_width (GTK_CONTAINER (tool), 5);
412   gtk_signal_connect (GTK_OBJECT (tool), "delete_event",
413                       GTK_SIGNAL_FUNC (tw_delete_event), NULL);
414 
415   gtk_container_add(GTK_CONTAINER(tool), vbox);
416   gtk_widget_show(vbox);
417   gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 2);
418   gtk_widget_show(hbox);
419 
420   toolname = tw_extend_fullname(name, (char *) NULL);
421   twc = tw_callback_make(toolname, tool,
422                          (void (*)()) NULL, tool_cmnd, tool_prnt, (void (*)()) NULL,
423                          NULL, NULL);
424   tw_register_callfrom(twc);
425 
426   return (tool);
427 }
428 
429 /**
430  * @brief   Wrapper for tw_tool_remote.  
431  * @param   name  String name for tool & for title bar.
432  * @param   x     Integer x position in pixels (not used!).
433  * @param   y     Integer y position in pixels (not used!).
434  * @return  GtkWidget *    Pointer to a new GtkWindow.
435  *
436  * The attempt to use GTK notebook pages is not yet implemented and
437  * will not be implemented unless there is lots of time to spare..
438  */
439 GtkWidget *tw_tool(char *name, int x, int y)
440 {
441   return (tw_tool_remote(name, x, y));
442 }
443 
444 /**
445  * @brief  Reset the name displayed in the title bar of anyOld_tool.  
446  * @param  anyOld_tool  Pointer to widget.
447  * @param  name         String name to be displayed.
448  *
449  * In Xv Tina the first param is called tool.  This confuses idiots like me
450  * who look at the static variable also called tool.  So I changed the name.
451  * GAB 14 Nov 2003.
452  */
453 void tw_tool_title_reset(void *anyOld_tool, char *name)
454 {
455   if (anyOld_tool == NULL)
456     return;
457   gtk_window_set_title (GTK_WINDOW (anyOld_tool), name);
458 }
459 
460 /**
461  * @brief   Show the current tool window.  
462  * 
463  * Could be done elsewhere but this is backward compatible. 
464  */
465 void tw_end_tool(void)
466 {
467 /*
468  *  In Xv Tina some placing & resizing stuff goes here.
469  *  Don't think we need it, but can use it if we need to.
470  *  It's of most use with the macro stuff so do together.
471  */
472   tw_set_pos(tool, tool_xpos, tool_ypos);
473   gtk_widget_show(tool);        
474 }
475 
476 
477 /**
478  * @brief   Start GTK main loop and initialise Tina macro record/replay.  
479  */
480 void tw_main_loop(void)
481 {
482   char   *tw_get_progname();
483 
484   if ((int) tw_recover() & (int) tw_save())
485   {
486     tw_read_call_file(tw_get_progname());
487     tw_open_call_file(tw_get_progname(),"a");
488   } 
489   else 
490     if (tw_recover())
491       tw_read_call_file(tw_get_progname());
492   else 
493     if (tw_save())
494       tw_open_call_file(tw_get_progname(),"w");
495 
496   gtk_main();
497 }
498 
499 
500 

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