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

Linux Cross Reference
Tina6/tina-tools/tinatool/wdgts/gtk2/wdgtsGtk_tw_screen.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_screen.c,v $
 37  * Date    :  $Date: 2009/03/23 15:41:27 $
 38  * Version :  $Revision: 1.3 $
 39  * CVS Id  :  $Id: wdgtsGtk_tw_screen.c,v 1.3 2009/03/23 15:41:27 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_screen.c
 47  *  @brief Functions to manage the use of a GTK drawing area.
 48  *
 49  *  . 
 50  *
 51  *  Note that the functions in this file are duplicated for each widget set 
 52  *  (xv, GTK, xm, etc ...).
 53  */
 54 
 55 #include "wdgtsGtk_tw_screen.h"
 56 
 57 #if HAVE_CONFIG_H
 58 #   include <config.h>
 59 #endif
 60 
 61 #include<tina/sys/sysPro.h> /* TEMP: to get format */
 62 
 63 #include <stdio.h>
 64 #include <gtk/gtk.h>
 65 #include <tinatool/gphx/gphxDef.h>
 66 /*#include <tinatool/gphx/gdk2/gphx_GdkPro.h>*/
 67 #include <tinatool/draw/drawTv_tv.h>
 68 #include <tinatool/draw/drawTv_size.h>
 69 #include <tinatool/draw/drawTv_activity.h>
 70 /* #include <tinatool/wdgts/gtk2/wdgts_GtkPro.h>  */
 71 
 72 /* Try out the rgb thing - GAB 27 Oct 2003 */
 73 #include <gdk/gdkrgb.h>
 74 
 75 #define IMAGE_WIDTH     256
 76 #define IMAGE_HEIGHT    256
 77 
 78 #include <tinatool/tlbase/tlbaseDef.h>
 79 #include <tinatool/tlbase/tlbasePro.h>
 80 
 81 
 82 /* Called by GDK on expose event.  Parameter list is GDK specific */
 83 /* Redraw the screen from the backing pixmap */
 84 /**
 85  * @brief   .  
 86  * @param   .
 87  * @return  .
 88  * 
 89  * . 
 90  */
 91 static void repaint_proc(GtkWidget *widget, GdkEventExpose *event, gpointer tv_data)
 92 {
 93   Tv_screen *tv_screen = (Tv_screen *) tv_data;
 94 
 95     if (tv_screen && tv_screen->tv)
 96     {
 97         tv_repaint(tv_screen->tv);
 98     }
 99 }
100 
101 
102 /* Called by XView on resize event.  Parameter list is XView specific
103  * Not in yet - GAB 20 Nov 2003 
104  */
105 static void resize_proc(GtkWidget *widget, GdkEventConfigure *event, gpointer tv_data)
106 {
107     Tv_screen *tv_screen = (Tv_screen *) tv_data;
108 
109     if (tv_screen)
110     {
111         tv_resize(tv_screen->tv, TV_SCREEN_REPAINT_IF_SMALLER);
112         /* Repaint event generated if canvas gets BIGGER, calls
113          * tv_repaint, so don't need to call tv_repaint here if bigger */
114     }
115 }
116 
117 
118 /**
119  * @brief   Handle mouse events in tv_screen.
120  * @param   widget Gtk pointer to the tv_screen widget.
121  * @param   event Desription of the event.
122  * @param   data TINA pointer to the tv_screen.
123  * 
124  * Notes: Meaning of an event (eg mouse SELECT) depends on the tv->activity (zoom, roi, 
125  * pick mouse).
126  *
127  */
128 static void tv_screen_activity_proc(GtkWidget *widget, GdkEvent *event, gpointer data)
129 {
130   Tv_screen *tv_screen = (Tv_screen *) data;
131   Tv        *tv;
132   int        state;             
133   Ipos       pos = {Ipos_id};
134 
135   if (tv_screen)
136   {
137     if (event->type == GDK_ENTER_NOTIFY)
138     {
139       /* Grab the keyboard focus, so that key presses are processed by the canvas */
140       /* gtk_widget_grab_focus(widget); */
141     }
142     if ((tv = tv_screen->tv) &&
143         (state = mouse_get_state(event, &pos)) != BAD_STATE)
144     {
145       tv_activity_proc(tv, state, pos);
146     }
147   }
148 }
149 
150 
151 /**
152  * @brief   Handle keyboard events in tv_screen.
153  * @param   widget Gtk pointer to the tv_screen widget.
154  * @param   event Desription of the event.
155  * @param   data TINA pointer to the tv_screen.
156  * 
157  * Notes: mouse events are handled by pre-defining a function for each possible event.
158  * However, the keyboard has a huge number of possible events, of which only a few will
159  * ever be defined.  Therefore, we pass the key directly to the user function and let 
160  * the user sort it out.
161  *
162  */
163 static void tv_screen_keyboard_proc(GtkWidget *widget, GdkEventKey *event, gpointer data)
164 {
165   Tv_screen *tv_screen = (Tv_screen *) data;
166   Tv        *tv=NULL;
167   int       keycode;
168 
169   if (tv_screen)
170   {
171     tv = tv_screen->tv;
172 
173     if(tv!=NULL && tv->keyboard_func!=NULL)
174     {
175        /* The gtk keycode corresponds to an entry in the list in gphx_GdkDef.h, which defines
176         * a corresponding name for TINA.  If another widget set is added in future, then a
177         * similar list must be implemented for that widget set. PAB 26/03/2010.
178         */
179 
180         keycode = event->keyval;
181         tv->keyboard_func(tv, keycode);
182     }
183   }
184 }
185 
186 
187 /**
188  * @brief   .  
189  * @param   tv_screen  .
190  * @param   width      .
191  * @param   height     .
192  * 
193  * . 
194  */
195 void tv_screen_set_size(Tv_screen *tv_screen, int width, int height)
196 {
197   GtkWidget     *widget;
198   int            x, y;
199   int            w, h;
200   int            dw, dh;
201 
202   if (tv_screen == NULL)
203     return;
204 
205   if (width == tv_screen->width && height == tv_screen->height)
206     return;
207 
208   widget = GTK_WIDGET(tv_screen->owner);
209 
210   tv_screen_save_size(tv_screen);
211   tw_get_geom(widget, &x, &y, &w, &h);  
212                         
213   dw = w - tv_screen->width;
214   dh = h - tv_screen->height;
215   w = dw + width;
216   h = dh + height;
217         
218   tw_set_geom(widget, (gint)x, (gint)y, (gint)w, (gint)h);
219   tv_screen_save_size(tv_screen);
220 }
221 
222 
223 /**
224  * @brief   .  
225  * @param   .
226  * @return  .
227  * 
228  * . 
229  */
230 void canvas_upgrade(void *canvas_ptr, void *owner_ptr, Tv_screen *tv_screen)
231 {
232   GdkGCValues *gc_values;
233 
234   GtkWidget   *canvas = GTK_WIDGET(canvas_ptr);   /* GTK Drawing Area */
235   GtkWidget   *owner  = GTK_WIDGET(owner_ptr);    /* GTK Window owning canvas */
236 
237   if (canvas == NULL || tv_screen == NULL)
238     return;
239         
240   tv_screen->tv     = NULL;
241   tv_screen->owner  = owner_ptr;
242   tv_screen->canvas = canvas_ptr;
243 
244   tv_screen->window = (GdkWindow *) canvas->window;
245 
246   tv_screen->colormap = NULL;
247   tv_screen->visual   = gdk_rgb_get_visual();
248 
249   gtk_widget_add_events (canvas, GDK_EXPOSURE_MASK
250                                  | GDK_BUTTON_MOTION_MASK
251                                  | GDK_POINTER_MOTION_HINT_MASK
252                                  | GDK_BUTTON_PRESS_MASK
253                                  | GDK_BUTTON_RELEASE_MASK
254                                  | GDK_ENTER_NOTIFY_MASK
255                                  | GDK_LEAVE_NOTIFY_MASK
256                                  | GDK_KEY_PRESS_MASK);
257 
258  /* 
259   * Allow the drawing area to have focus: neccessary for receiving keyboard events. 
260   * Note that this is a deprecated way of doing it, used to ensure compatibility 
261   * with Gtk version < 2.18 (e.g. in opensuse 10.3).  If this ever needs to be replaced,
262   * the correct call is:
263   *
264   * gtk_widget_set_can_focus(canvas);
265   * 
266   */
267 
268   gtk_widget_set(canvas, "can-focus", TRUE, NULL);
269 
270   gtk_signal_connect (GTK_OBJECT (canvas), "expose_event",
271                       (GtkSignalFunc) repaint_proc, (gpointer) tv_screen);
272   gtk_signal_connect (GTK_OBJECT (canvas), "configure_event",
273                       (GtkSignalFunc) resize_proc, (gpointer) tv_screen);
274   gtk_signal_connect (GTK_OBJECT (canvas), "button_press_event",
275                       (GtkSignalFunc) tv_screen_activity_proc, (gpointer) tv_screen);
276   gtk_signal_connect (GTK_OBJECT (canvas), "button_release_event",
277                       (GtkSignalFunc) tv_screen_activity_proc, (gpointer) tv_screen);
278   gtk_signal_connect (GTK_OBJECT (canvas), "enter_notify_event",
279                       (GtkSignalFunc) tv_screen_activity_proc, (gpointer) tv_screen);
280   gtk_signal_connect (GTK_OBJECT (canvas), "leave_notify_event",
281                       (GtkSignalFunc) tv_screen_activity_proc, (gpointer) tv_screen);
282   gtk_signal_connect (GTK_OBJECT (canvas), "motion_notify_event",
283                       (GtkSignalFunc) tv_screen_activity_proc, (gpointer) tv_screen);
284   gtk_signal_connect (GTK_OBJECT (owner), "key_press_event",
285                       (GtkSignalFunc) tv_screen_keyboard_proc, (gpointer) tv_screen);
286 
287 /*
288  *  Can't store GC values directly in tv_screen->gcvalues because passing a NULL
289  *  creates a GC with no associated values struct.
290  */
291 
292   gc_values = (GdkGCValues *) g_malloc(sizeof(GdkGCValues));
293   tv_screen->gc = gdk_gc_new_with_values(canvas->window, gc_values, 0);
294   gdk_gc_copy(tv_screen->gc, canvas->style->fg_gc[GTK_STATE_NORMAL]);
295 
296   tv_screen_save_size(tv_screen);
297 }
298 
299 

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