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

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

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