[glade3/offscreen-design-layout] 2011-01-13 Juan Pablo Ugarte <juanpablougarte gmail com>



commit 36eb6a8b159090a45a456ecfca1965a4d6520f10
Author: Juan Pablo Ugarte <jp synctv com>
Date:   Thu Jan 13 19:20:40 2011 -0300

    2011-01-13  Juan Pablo Ugarte <juanpablougarte gmail com>
    
      * gladeui/glade-widget-adaptor.c: added GtkWidget::event signal clash override
        for every registered class to marshal events to the corresponding GladeDesignLayout
    
      * gladeui/glade-design-layout.[ch]:
        o added new function derived from glade_design_layout_widget_event(),
          glade_design_layout_do_event() to marshall events from the override class handler
        o removed placeholder from glade_design_layout_find_inside_container()
    
      * gladeui/glade-widget.[ch]: moved IS_GLADE_WIDGET_EVENT macro to header.

 gladeui/glade-design-layout.c  |   84 ++++++++++++++++++++++++++--------------
 gladeui/glade-design-layout.h  |    3 +
 gladeui/glade-widget-adaptor.c |   31 +++++++++++++++
 gladeui/glade-widget.c         |    6 ---
 gladeui/glade-widget.h         |    5 ++
 5 files changed, 94 insertions(+), 35 deletions(-)
---
diff --git a/gladeui/glade-design-layout.c b/gladeui/glade-design-layout.c
index a10afa1..470555b 100644
--- a/gladeui/glade-design-layout.c
+++ b/gladeui/glade-design-layout.c
@@ -306,7 +306,6 @@ typedef struct
   GtkWidget *toplevel;
   gint x;
   gint y;
-  GtkWidget *placeholder;
   GladeWidget *gwidget;
 } GladeFindInContainerData;
 
@@ -321,25 +320,19 @@ glade_design_layout_find_inside_container (GtkWidget * widget,
   if (data->gwidget || !gtk_widget_get_mapped (widget))
     return;
 
-//  gtk_widget_translate_coordinates (data->toplevel, widget, data->x, data->y, &x, &y);
-  x = data->x;
-  y = data->y;
+  gtk_widget_translate_coordinates (data->toplevel, widget, data->x, data->y, &x, &y);
+
   gtk_widget_get_allocation (widget, &allocation);
 
   if (x >= 0 && x < allocation.width && y >= 0 && y < allocation.height)
     {
-      if (GLADE_IS_PLACEHOLDER (widget))
-        data->placeholder = widget;
-      else
-        {
-          if (GTK_IS_CONTAINER (widget))
-            gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback)
-                                  glade_design_layout_find_inside_container,
-                                  data);
+      if (GTK_IS_CONTAINER (widget))
+        gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback)
+                              glade_design_layout_find_inside_container,
+                              data);
 
-          if (!data->gwidget)
-            data->gwidget = glade_widget_get_from_gobject (widget);
-        }
+      if (!data->gwidget)
+        data->gwidget = glade_widget_get_from_gobject (widget);
     }
 }
 
@@ -537,7 +530,6 @@ glade_design_layout_size_allocate (GtkWidget * widget,
       child_allocation.width = MAX (requisition.width, child_width);
       child_allocation.height = MAX (requisition.height, child_height);
 
-      /* FIXME: here we make the offscreen bigger because otherwise it gets clipped, need to investigate further */
       if (gtk_widget_get_realized (widget))
         gdk_window_move_resize (priv->offscreen_window,
                                 child_allocation.x,
@@ -700,21 +692,21 @@ glade_design_layout_draw (GtkWidget * widget, cairo_t * cr)
           /* Draw selection */
           if (priv->project)
             {
-                GList *widgets = glade_project_selection_get (priv->project);
+              GList *widgets = glade_project_selection_get (priv->project);
 
-                if (widgets)
+              if (widgets)
                 {
-                    child = widgets->data;
-                    gtk_widget_get_allocation (child, &child_allocation);
-                    gdk_cairo_set_source_color (cr,
-                                                &gtk_widget_get_style (widget)->bg[GTK_STATE_SELECTED]);
-                    cairo_rectangle (cr,
-                                     child_allocation.x + offset,
-                                     child_allocation.y + offset,
-                                     child_allocation.width,
-                                     child_allocation.height);
-                    cairo_clip (cr);
-                    cairo_paint_with_alpha (cr, .32);
+                  gtk_widget_get_allocation (widgets->data, &child_allocation);
+
+                  gdk_cairo_set_source_color (cr,
+                                              &gtk_widget_get_style (widget)->bg[GTK_STATE_SELECTED]);
+                  cairo_rectangle (cr,
+                                   child_allocation.x + offset,
+                                   child_allocation.y + offset,
+                                   child_allocation.width,
+                                   child_allocation.height);
+                  cairo_clip (cr);
+                  cairo_paint_with_alpha (cr, .32);
                 }
             }
         }
@@ -968,8 +960,42 @@ glade_design_layout_class_init (GladeDesignLayoutClass * klass)
   g_type_class_add_private (object_class, sizeof (GladeDesignLayoutPrivate));
 }
 
+/* Public API */
+
 GtkWidget *
 glade_design_layout_new (void)
 {
   return g_object_new (GLADE_TYPE_DESIGN_LAYOUT, NULL);
 }
+
+/**
+ * glade_design_layout_do_event:
+ * @layout:        A #GladeDesignLayout
+ * @event:         the #GdkEvent
+ *
+ * This is called internally by a #GladeWidget recieving an event,
+ * it will marshall the event to the proper #GladeWidget according
+ * to its position in @layout.
+ *
+ * Returns: Whether or not the event was handled by the retrieved #GladeWidget
+ */
+gboolean
+glade_design_layout_do_event (GladeDesignLayout * layout, GdkEvent * event)
+{
+  GladeFindInContainerData data = { 0, };
+  GtkWidget *child;
+
+  if ((child = gtk_bin_get_child (GTK_BIN (layout))) == NULL)
+    return FALSE;
+
+  data.toplevel = GTK_WIDGET (layout);
+  gtk_widget_get_pointer (GTK_WIDGET (layout), &data.x, &data.y);
+
+  glade_design_layout_find_inside_container (child, &data);
+
+  /* Then we try a GladeWidget */
+  if (data.gwidget)
+      return glade_widget_event (data.gwidget, event);
+
+  return FALSE;
+}
diff --git a/gladeui/glade-design-layout.h b/gladeui/glade-design-layout.h
index 9f6bb4d..52748e2 100644
--- a/gladeui/glade-design-layout.h
+++ b/gladeui/glade-design-layout.h
@@ -63,6 +63,9 @@ GType        glade_design_layout_get_type     (void) G_GNUC_CONST;
 
 GtkWidget   *glade_design_layout_new          (void);
 
+gboolean     glade_design_layout_do_event     (GladeDesignLayout * layout,
+                                               GdkEvent * event);
+
 G_END_DECLS
 
 #endif /* __GLADE_DESIGN_LAYOUT_H__ */
diff --git a/gladeui/glade-widget-adaptor.c b/gladeui/glade-widget-adaptor.c
index c2da225..eed52ca 100644
--- a/gladeui/glade-widget-adaptor.c
+++ b/gladeui/glade-widget-adaptor.c
@@ -1661,6 +1661,33 @@ glade_widget_adaptor_list_adaptors (void)
   return adaptors;
 }
 
+static gboolean 
+on_widget_event (GtkWidget *widget, GdkEvent *event)
+{
+  gboolean retval;
+
+  /* We are only interested in button press and release events */
+  if (IS_GLADE_WIDGET_EVENT(event->type) && !GLADE_IS_PLACEHOLDER (widget))
+    {
+      GtkWidget *parent = widget;
+      do
+        {
+
+          if (GLADE_IS_DESIGN_LAYOUT (parent))
+            {
+              if (glade_design_layout_do_event (GLADE_DESIGN_LAYOUT (parent), event))
+                return TRUE;
+              break;
+            }
+        }
+      while ((parent = gtk_widget_get_parent (parent)));
+    }
+
+  /* Chain up */
+  g_signal_chain_from_overridden_handler (widget, event, &retval);
+  return retval;
+}
+
 /**
  * glade_widget_adaptor_register:
  * @adaptor: A #GladeWidgetAdaptor
@@ -1686,6 +1713,10 @@ glade_widget_adaptor_register (GladeWidgetAdaptor * adaptor)
 
   g_hash_table_insert (adaptor_hash,
                        g_memdup (&adaptor->priv->type, sizeof (GType)), adaptor);
+
+  if (g_type_is_a (adaptor->priv->type, GTK_TYPE_WIDGET))
+    g_signal_override_class_handler ("event", adaptor->priv->type,
+                                     G_CALLBACK (on_widget_event));
 }
 
 static GladePackingDefault *
diff --git a/gladeui/glade-widget.c b/gladeui/glade-widget.c
index c1715fc..728ebd3 100644
--- a/gladeui/glade-widget.c
+++ b/gladeui/glade-widget.c
@@ -197,12 +197,6 @@ static guint glade_widget_signals[LAST_SIGNAL] = { 0 };
 
 static GQuark glade_widget_name_quark = 0;
 
-
-#define IS_GLADE_WIDGET_EVENT(event)		 \
-	((event) == GDK_BUTTON_PRESS ||		 \
-	 (event) == GDK_BUTTON_RELEASE ||	 \
-	 (event) == GDK_MOTION_NOTIFY)
-
 G_DEFINE_TYPE (GladeWidget, glade_widget, G_TYPE_INITIALLY_UNOWNED)
 /*******************************************************************************
                            GladeWidget class methods
diff --git a/gladeui/glade-widget.h b/gladeui/glade-widget.h
index c985f62..0786a25 100644
--- a/gladeui/glade-widget.h
+++ b/gladeui/glade-widget.h
@@ -56,6 +56,11 @@ struct _GladeWidgetClass
   void   (* glade_reserved8)   (void);
 };
 
+#define IS_GLADE_WIDGET_EVENT(event)		 \
+	((event) == GDK_BUTTON_PRESS ||		 \
+	 (event) == GDK_BUTTON_RELEASE ||	 \
+	 (event) == GDK_MOTION_NOTIFY)
+
 /*******************************************************************************
                                   General api
  *******************************************************************************/



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