r7040 - in hippo-canvas/trunk: common/hippo linux/hippo python



Author: hp
Date: 2007-12-12 12:57:29 -0600 (Wed, 12 Dec 2007)
New Revision: 7040

Modified:
   hippo-canvas/trunk/common/hippo/hippo-canvas-box.c
   hippo-canvas/trunk/common/hippo/hippo-canvas-item.c
   hippo-canvas/trunk/common/hippo/hippo-canvas-item.h
   hippo-canvas/trunk/common/hippo/hippo-event.h
   hippo-canvas/trunk/linux/hippo/hippo-canvas-helper.c
   hippo-canvas/trunk/linux/hippo/hippo-canvas-helper.h
   hippo-canvas/trunk/linux/hippo/hippo-canvas-window.c
   hippo-canvas/trunk/linux/hippo/hippo-canvas.c
   hippo-canvas/trunk/python/hippo.defs
   hippo-canvas/trunk/python/hippo.override
Log:
add scroll event support

Modified: hippo-canvas/trunk/common/hippo/hippo-canvas-box.c
===================================================================
--- hippo-canvas/trunk/common/hippo/hippo-canvas-box.c	2007-12-12 18:07:42 UTC (rev 7039)
+++ hippo-canvas/trunk/common/hippo/hippo-canvas-box.c	2007-12-12 18:57:29 UTC (rev 7040)
@@ -100,6 +100,8 @@
                                                                 HippoEvent         *event);
 static gboolean           hippo_canvas_box_motion_notify_event (HippoCanvasItem    *item,
                                                                 HippoEvent         *event);
+static gboolean           hippo_canvas_box_scroll_event        (HippoCanvasItem    *item,
+                                                                HippoEvent         *event);
 static void               hippo_canvas_box_request_changed     (HippoCanvasItem    *item);
 static gboolean           hippo_canvas_box_get_needs_request   (HippoCanvasItem    *canvas_item);
 static char*              hippo_canvas_box_get_tooltip         (HippoCanvasItem    *item,
@@ -223,6 +225,7 @@
     klass->button_press_event = hippo_canvas_box_button_press_event;
     klass->button_release_event = hippo_canvas_box_button_release_event;
     klass->motion_notify_event = hippo_canvas_box_motion_notify_event;
+    klass->scroll_event = hippo_canvas_box_scroll_event;
     klass->request_changed = hippo_canvas_box_request_changed;
     klass->get_needs_request = hippo_canvas_box_get_needs_request;
     klass->get_tooltip = hippo_canvas_box_get_tooltip;
@@ -3346,6 +3349,14 @@
         } else {
             return FALSE;
         }
+    } else if (event->type == HIPPO_EVENT_SCROLL) {
+        child = find_child_at_point(box, event->x, event->y);
+        if (child != NULL) {
+            return hippo_canvas_item_process_event(child->public.item,
+                                                   event, child->x, child->y);
+        } else {
+            return FALSE;
+        }
     } else {
         return FALSE;
     } 
@@ -3427,6 +3438,18 @@
     return handled;
 }
 
+static gboolean
+hippo_canvas_box_scroll_event (HippoCanvasItem    *item,
+                               HippoEvent         *event)
+{
+    HippoCanvasBox *box = HIPPO_CANVAS_BOX(item);
+    gboolean handled;
+    
+    handled = forward_event (box, event);
+
+    return handled;
+}
+
 static void
 hippo_canvas_box_request_changed(HippoCanvasItem *item)
 {

Modified: hippo-canvas/trunk/common/hippo/hippo-canvas-item.c
===================================================================
--- hippo-canvas/trunk/common/hippo/hippo-canvas-item.c	2007-12-12 18:07:42 UTC (rev 7039)
+++ hippo-canvas/trunk/common/hippo/hippo-canvas-item.c	2007-12-12 18:57:29 UTC (rev 7040)
@@ -16,6 +16,7 @@
     BUTTON_PRESS_EVENT,
     BUTTON_RELEASE_EVENT,
     MOTION_NOTIFY_EVENT,
+    SCROLL_EVENT,
     KEY_PRESS_EVENT,
     ACTIVATED,
     TOOLTIP_CHANGED,
@@ -155,7 +156,22 @@
                           g_signal_accumulator_true_handled, NULL,
                           hippo_canvas_marshal_BOOLEAN__BOXED,
                           G_TYPE_BOOLEAN, 1, HIPPO_TYPE_EVENT);
+
         /**
+         * HippoCanvasItem::scroll-event
+         *
+         * Signal emitted when the mouse wheel or other mechanism requests scrolling.
+         */                
+        signals[SCROLL_EVENT] =
+            g_signal_new ("scroll-event",
+                          HIPPO_TYPE_CANVAS_ITEM,
+                          G_SIGNAL_RUN_LAST,
+                          G_STRUCT_OFFSET(HippoCanvasItemIface, scroll_event),
+                          g_signal_accumulator_true_handled, NULL,
+                          hippo_canvas_marshal_BOOLEAN__BOXED,
+                          G_TYPE_BOOLEAN, 1, HIPPO_TYPE_EVENT);
+        
+        /**
          * HippoCanvasItem::key-press-event
          *
          * Signal emitted when a key is pressed while the canvas item is focused.
@@ -481,7 +497,27 @@
     return result;
 }
 
+gboolean
+hippo_canvas_item_emit_scroll_event (HippoCanvasItem     *canvas_item,
+                                     int                  x,
+                                     int                  y,
+                                     HippoScrollDirection direction)
+{
+    HippoEvent event;
+    gboolean result;
+    
+    g_return_val_if_fail(HIPPO_IS_CANVAS_ITEM(canvas_item), FALSE);
 
+    event.type = HIPPO_EVENT_SCROLL;
+    event.x = x;
+    event.y = y;    
+    event.u.scroll.direction = direction;
+    
+    result = hippo_canvas_item_process_event(canvas_item, &event, 0, 0);
+
+    return result;
+}
+
 gboolean
 hippo_canvas_item_emit_key_press_event (HippoCanvasItem  *canvas_item,
                                         HippoKey          key,
@@ -597,6 +633,9 @@
     case HIPPO_EVENT_KEY_PRESS:
         g_signal_emit(canvas_item, signals[KEY_PRESS_EVENT], 0, &translated, &handled);
         break;
+    case HIPPO_EVENT_SCROLL:
+        g_signal_emit(canvas_item, signals[SCROLL_EVENT], 0, &translated, &handled);
+        break;
         /* don't add a default, you'll break the compiler warnings */
     }
 

Modified: hippo-canvas/trunk/common/hippo/hippo-canvas-item.h
===================================================================
--- hippo-canvas/trunk/common/hippo/hippo-canvas-item.h	2007-12-12 18:07:42 UTC (rev 7039)
+++ hippo-canvas/trunk/common/hippo/hippo-canvas-item.h	2007-12-12 18:57:29 UTC (rev 7040)
@@ -80,6 +80,8 @@
     HippoCanvasPointer     (* get_pointer)          (HippoCanvasItem *canvas_item,
                                                      int              x,
                                                      int              y);
+    gboolean               (* scroll_event)         (HippoCanvasItem *canvas_item,
+                                                     HippoEvent      *event);    
 };
 
 GType                 hippo_canvas_item_get_type           (void) G_GNUC_CONST;
@@ -141,6 +143,10 @@
                                                       HippoKey          key,
                                                       gunichar          character,
                                                       guint             modifiers);
+gboolean hippo_canvas_item_emit_scroll_event         (HippoCanvasItem     *canvas_item,
+                                                      int                  x,
+                                                      int                  y,
+                                                      HippoScrollDirection direction);
 void     hippo_canvas_item_emit_activated            (HippoCanvasItem *canvas_item);
 void     hippo_canvas_item_emit_paint_needed         (HippoCanvasItem *canvas_item,
                                                       int              x,

Modified: hippo-canvas/trunk/common/hippo/hippo-event.h
===================================================================
--- hippo-canvas/trunk/common/hippo/hippo-event.h	2007-12-12 18:07:42 UTC (rev 7039)
+++ hippo-canvas/trunk/common/hippo/hippo-event.h	2007-12-12 18:57:29 UTC (rev 7040)
@@ -15,6 +15,7 @@
     HIPPO_EVENT_BUTTON_RELEASE,
     HIPPO_EVENT_MOTION_NOTIFY,
     HIPPO_EVENT_KEY_PRESS,
+    HIPPO_EVENT_SCROLL
 } HippoEventType;
 
 typedef enum {
@@ -23,6 +24,13 @@
     HIPPO_MOTION_DETAIL_WITHIN
 } HippoMotionDetail;
 
+typedef enum {
+    HIPPO_SCROLL_UP,
+    HIPPO_SCROLL_DOWN,
+    HIPPO_SCROLL_LEFT,
+    HIPPO_SCROLL_RIGHT
+} HippoScrollDirection;
+
 typedef struct _HippoEvent HippoEvent;
 
 typedef enum {
@@ -62,6 +70,9 @@
             gunichar character; /* 0 if no translation */
             guint modifiers;
         } key;
+        struct {
+            HippoScrollDirection direction;
+        } scroll;
     } u;
 };
 

Modified: hippo-canvas/trunk/linux/hippo/hippo-canvas-helper.c
===================================================================
--- hippo-canvas/trunk/linux/hippo/hippo-canvas-helper.c	2007-12-12 18:07:42 UTC (rev 7039)
+++ hippo-canvas/trunk/linux/hippo/hippo-canvas-helper.c	2007-12-12 18:57:29 UTC (rev 7040)
@@ -625,6 +625,29 @@
     return FALSE;
 }
 
+gboolean
+hippo_canvas_helper_scroll (HippoCanvasHelper *helper,
+                            GdkEventScroll    *event)
+{
+    int window_x, window_y;    
+    
+    if (helper->root == NULL)
+        return FALSE;
+
+    get_root_item_window_coords(helper, &window_x, &window_y);
+    
+    g_assert(GDK_SCROLL_UP == HIPPO_SCROLL_UP);
+    g_assert(GDK_SCROLL_DOWN == HIPPO_SCROLL_DOWN);
+    g_assert(GDK_SCROLL_LEFT == HIPPO_SCROLL_LEFT);
+    g_assert(GDK_SCROLL_RIGHT == HIPPO_SCROLL_RIGHT);
+    
+    hippo_canvas_item_emit_scroll_event(helper->root,
+                                        event->x - window_x, event->y - window_y,
+                                        event->direction);
+    
+    return FALSE;
+}
+
 void
 hippo_canvas_helper_realize(HippoCanvasHelper *helper)
 {

Modified: hippo-canvas/trunk/linux/hippo/hippo-canvas-helper.h
===================================================================
--- hippo-canvas/trunk/linux/hippo/hippo-canvas-helper.h	2007-12-12 18:07:42 UTC (rev 7039)
+++ hippo-canvas/trunk/linux/hippo/hippo-canvas-helper.h	2007-12-12 18:57:29 UTC (rev 7040)
@@ -14,7 +14,7 @@
 
 #define HIPPO_CANVAS_EVENT_MASK (GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | \
                                  GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |          \
-                                 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK)
+                                 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK)
 
 typedef struct _HippoCanvasHelper      HippoCanvasHelper;
 typedef struct _HippoCanvasHelperClass HippoCanvasHelperClass;
@@ -58,7 +58,10 @@
             	       	                           GdkEventCrossing  *event);
 gboolean  hippo_canvas_helper_motion_notify       (HippoCanvasHelper *widget,
             	       	                           GdkEventMotion    *event);
+gboolean  hippo_canvas_helper_scroll              (HippoCanvasHelper *widget,
+            	       	                           GdkEventScroll    *event);
 
+
 void  hippo_canvas_helper_realize           (HippoCanvasHelper    *widget);
 /* Caller should chain up to GtkContainer::unmap after calling */
 void  hippo_canvas_helper_unmap             (HippoCanvasHelper    *widget);

Modified: hippo-canvas/trunk/linux/hippo/hippo-canvas-window.c
===================================================================
--- hippo-canvas/trunk/linux/hippo/hippo-canvas-window.c	2007-12-12 18:07:42 UTC (rev 7039)
+++ hippo-canvas/trunk/linux/hippo/hippo-canvas-window.c	2007-12-12 18:57:29 UTC (rev 7040)
@@ -32,7 +32,10 @@
                                                           GdkEventCrossing  *event);
 static gboolean  hippo_canvas_window_motion_notify       (GtkWidget         *widget,
                                                           GdkEventMotion    *event);
+static gboolean  hippo_canvas_window_scroll              (GtkWidget         *widget,
+                                                          GdkEventScroll    *event);
 
+
 struct _HippoCanvasWindow {
     GtkWindow parent;
 
@@ -73,6 +76,7 @@
     widget_class->motion_notify_event = hippo_canvas_window_motion_notify;
     widget_class->enter_notify_event = hippo_canvas_window_enter_notify;
     widget_class->leave_notify_event = hippo_canvas_window_leave_notify;
+    widget_class->scroll_event = hippo_canvas_window_scroll;
 }
 
 static void
@@ -235,6 +239,21 @@
         return FALSE;
 }
 
+static gboolean
+hippo_canvas_window_scroll(GtkWidget         *widget,
+                           GdkEventScroll    *event)
+{
+    HippoCanvasWindow *canvas_window = HIPPO_CANVAS_WINDOW(widget);
+
+    if (canvas_window->helper == NULL)
+        return FALSE; /* we've already been destroyed */
+    
+    if (event->window == widget->window)
+        return hippo_canvas_helper_scroll(canvas_window->helper, event);
+    else
+        return FALSE;
+}
+
 void
 hippo_canvas_window_set_root(HippoCanvasWindow *canvas_window,
                              HippoCanvasItem   *item)

Modified: hippo-canvas/trunk/linux/hippo/hippo-canvas.c
===================================================================
--- hippo-canvas/trunk/linux/hippo/hippo-canvas.c	2007-12-12 18:07:42 UTC (rev 7039)
+++ hippo-canvas/trunk/linux/hippo/hippo-canvas.c	2007-12-12 18:57:29 UTC (rev 7040)
@@ -40,7 +40,10 @@
             	       	                           GdkEventCrossing  *event);
 static gboolean  hippo_canvas_motion_notify       (GtkWidget         *widget,
             	       	                           GdkEventMotion    *event);
+static gboolean  hippo_canvas_scroll              (GtkWidget         *widget,
+            	       	                           GdkEventScroll    *event);
 
+
 static void  hippo_canvas_realize           (GtkWidget    *widget);
 static void  hippo_canvas_unmap             (GtkWidget    *widget);
 static void  hippo_canvas_hierarchy_changed (GtkWidget    *widget,
@@ -109,6 +112,7 @@
     widget_class->motion_notify_event = hippo_canvas_motion_notify;
     widget_class->enter_notify_event = hippo_canvas_enter_notify;
     widget_class->leave_notify_event = hippo_canvas_leave_notify;
+    widget_class->scroll_event = hippo_canvas_scroll;    
 
     widget_class->realize = hippo_canvas_realize;
     widget_class->unmap = hippo_canvas_unmap;
@@ -319,6 +323,21 @@
         return FALSE;
 }
 
+static gboolean
+hippo_canvas_scroll(GtkWidget         *widget,
+                    GdkEventScroll    *event)
+{
+    HippoCanvas *canvas = HIPPO_CANVAS(widget);
+
+    if (canvas->helper == NULL)
+        return FALSE; /* we've already been destroyed */
+    
+    if (event->window == widget->window)
+        return hippo_canvas_helper_scroll(canvas->helper, event);
+    else
+        return FALSE;
+}
+
 static void
 hippo_canvas_realize(GtkWidget    *widget)
 {

Modified: hippo-canvas/trunk/python/hippo.defs
===================================================================
--- hippo-canvas/trunk/python/hippo.defs	2007-12-12 18:07:42 UTC (rev 7039)
+++ hippo-canvas/trunk/python/hippo.defs	2007-12-12 18:57:29 UTC (rev 7040)
@@ -221,6 +221,7 @@
     '("button-release" "HIPPO_EVENT_BUTTON_RELEASE")
     '("motion-notify" "HIPPO_EVENT_MOTION_NOTIFY")
     '("key-press" "HIPPO_EVENT_KEY_PRESS")
+    '("scroll" "HIPPO_EVENT_SCROLL")
   )
 )
 
@@ -235,6 +236,18 @@
   )
 )
 
+(define-enum ScrollDirection
+  (in-module "Hippo")
+  (c-name "HippoScrollDirection")
+  (gtype-id "HIPPO_TYPE_SCROLL_DIRECTION")
+  (values
+    '("up" "HIPPO_SCROLL_UP")
+    '("down" "HIPPO_SCROLL_DOWN")
+    '("left" "HIPPO_SCROLL_LEFT")
+    '("right" "HIPPO_SCROLL_RIGHT")
+  )
+)
+
 (define-enum Key
   (in-module "Hippo")
   (c-name "HippoKey")
@@ -1163,6 +1176,22 @@
   )
 )
 
+(define-virtual scroll_event
+  (of-object "HippoCanvasItem")
+  (return-type "gboolean")
+  (parameters
+    '("HippoEvent*" "event")
+  )
+)
+
+(define-virtual motion_notify_event
+  (of-object "HippoCanvasItem")
+  (return-type "gboolean")
+  (parameters
+    '("HippoEvent*" "event")
+  )
+)
+
 (define-virtual get_context
   (of-object "HippoCanvasItem")
   (c-name "hippo_canvas_item_get_context")

Modified: hippo-canvas/trunk/python/hippo.override
===================================================================
--- hippo-canvas/trunk/python/hippo.override	2007-12-12 18:07:42 UTC (rev 7039)
+++ hippo-canvas/trunk/python/hippo.override	2007-12-12 18:57:29 UTC (rev 7040)
@@ -696,7 +696,13 @@
             return pyg_enum_from_gtype(HIPPO_TYPE_KEY, event->u.key.key);
         else if (!strcmp(attr, "character"))
             return PyInt_FromLong(event->u.key.character); /* FIXME this should probably return a string? */
-        break;        
+        break;
+    case HIPPO_EVENT_SCROLL:
+        if (!strcmp(attr, "__members__"))
+            return Py_BuildValue("[ssss]", "type", "x", "y", "direction");
+        else if (!strcmp(attr, "direction"))
+            return pyg_enum_from_gtype(HIPPO_TYPE_SCROLL_DIRECTION, event->u.scroll.direction);
+        break;
         /* No default, hides compiler warnings */
     }
     Py_INCREF(Py_None);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]