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



commit 6d53ae42073f9d0e09e58e8a908b15b06d69c56d
Author: Juan Pablo Ugarte <jp synctv com>
Date:   Sat Jan 22 14:27:09 2011 -0300

    2011-01-22  Juan Pablo Ugarte <juanpablougarte gmail com>
    
      * gladeui/glade-design-layout.[ch]:
        o added glade_design_layout_selection_set() (removed project dependency)
        o removed PointerRegion enum
        o reworked cursors pointer in an array to ease seting them
        o reemplazed glade_design_layout_get_pointer_region () with gdl_get_activity_from_pointer()
        o removed call to gtk_widget_size_allocate() in glade_design_layout_update_child()
          fixes rendering glith while resizing
        o precompute child offset to optimize from-embeder to-embeder handlers
        o draw "pretty" selection
    
      * gladeui/glade-design-view.c: set layout selection on project's selection-changed signal
    
      * gladeui/glade-app.[ch]:
        o added glade_app_do_event()
        o set custom gdk event handler to marshal event to GladeDesignLayouts using
          glade_design_layout_do_event()
    
      * gladeui/glade-utils.[ch]: removed unused function glade_util_draw_selection_nodes()
    
      * gladeui/glade-widget-adaptor.c: removed g_signal_override_class_handler() event marshalling hack.

 gladeui/glade-app.c            |   40 +++++++++++++++++++++
 gladeui/glade-app.h            |    2 +
 gladeui/glade-design-view.c    |    9 +++++
 gladeui/glade-utils.c          |   74 ----------------------------------------
 gladeui/glade-utils.h          |    2 -
 gladeui/glade-widget-adaptor.c |   31 -----------------
 6 files changed, 51 insertions(+), 107 deletions(-)
---
diff --git a/gladeui/glade-app.c b/gladeui/glade-app.c
index e71f4be..1f21d4b 100644
--- a/gladeui/glade-app.c
+++ b/gladeui/glade-app.c
@@ -300,6 +300,14 @@ glade_app_init (GladeApp * app)
 }
 
 static void
+glade_app_event_handler (GdkEvent *event, gpointer data)
+{
+  if (glade_app_do_event (event)) return;
+
+  gtk_main_do_event (event);
+}
+
+static void
 glade_app_class_init (GladeAppClass * klass)
 {
 	GObjectClass *object_class;
@@ -350,6 +358,8 @@ glade_app_class_init (GladeAppClass * klass)
                   G_TYPE_NONE, 1, G_TYPE_OBJECT);  
 
   g_type_class_add_private (klass, sizeof (GladeAppPrivate));
+
+  gdk_event_handler_set (glade_app_event_handler, NULL, NULL);
 }
 
 /*****************************************************************
@@ -357,6 +367,36 @@ glade_app_class_init (GladeAppClass * klass)
  *****************************************************************/
 
 /**
+ * glade_app_do_event:
+ * @event: the event to process.
+ *
+ * This function has to be called in an event handler for widget selection to work.
+ * See gdk_event_handler_set()
+ *
+ * Returns: true if the event was handled.
+ */ 
+gboolean
+glade_app_do_event (GdkEvent *event)
+{
+  GdkWindow *window = event->any.window;
+  GtkWidget *layout;
+  gpointer widget;
+
+  if (window == NULL) return FALSE;
+    
+  gdk_window_get_user_data (window, &widget);
+
+  /* As a slight optimization we could replace gtk_widget_get_ancestor()
+   * with a custom function that only iterates trought parents with windows.
+   */
+  if (widget && IS_GLADE_WIDGET_EVENT (event->type) &&
+      (layout = gtk_widget_get_ancestor (widget, GLADE_TYPE_DESIGN_LAYOUT)))
+    return glade_design_layout_do_event (GLADE_DESIGN_LAYOUT (layout), event);
+
+  return FALSE;
+}
+
+/**
  * glade_app_config_save
  *
  * Saves the GKeyFile to "g_get_user_config_dir()/GLADE_CONFIG_FILENAME"
diff --git a/gladeui/glade-app.h b/gladeui/glade-app.h
index b129612..9a93677 100644
--- a/gladeui/glade-app.h
+++ b/gladeui/glade-app.h
@@ -69,6 +69,8 @@ GladeApp*          glade_app_get                  (void);
 GKeyFile*          glade_app_get_config           (void);
 gint               glade_app_config_save          (void);
 
+gboolean           glade_app_do_event             (GdkEvent *event);
+
 gboolean           glade_app_get_catalog_version  (const gchar   *name, 
 						   gint          *major, 
 						   gint          *minor);
diff --git a/gladeui/glade-design-view.c b/gladeui/glade-design-view.c
index dcf44e2..0f9d0df 100644
--- a/gladeui/glade-design-view.c
+++ b/gladeui/glade-design-view.c
@@ -106,6 +106,13 @@ glade_design_view_load_progress (GladeProject * project,
 }
 
 static void
+glade_design_view_selection_changed (GladeProject * project, GladeDesignView * view)
+{
+  GladeDesignLayout *layout = glade_design_view_get_layout (view);
+  glade_design_layout_selection_set (layout, glade_project_selection_get (project));
+}
+
+static void
 glade_design_view_set_project (GladeDesignView * view, GladeProject * project)
 {
   g_return_if_fail (GLADE_IS_PROJECT (project));
@@ -118,6 +125,8 @@ glade_design_view_set_project (GladeDesignView * view, GladeProject * project)
                     G_CALLBACK (glade_design_view_parse_finished), view);
   g_signal_connect (project, "load-progress",
                     G_CALLBACK (glade_design_view_load_progress), view);
+  g_signal_connect (project, "selection-changed",
+                    G_CALLBACK (glade_design_view_selection_changed), view);
 
   g_object_set_data (G_OBJECT (view->priv->project), GLADE_DESIGN_VIEW_KEY,
                      view);
diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c
index feae3f7..a8023ea 100644
--- a/gladeui/glade-utils.c
+++ b/gladeui/glade-utils.c
@@ -53,7 +53,6 @@
 #include <shellapi.h>
 #endif
 
-#define GLADE_UTIL_SELECTION_NODE_SIZE 7
 #define GLADE_UTIL_COPY_BUFFSIZE       1024
 
 
@@ -564,79 +563,6 @@ glade_util_duplicate_underscores (const gchar * name)
   return underscored_name;
 }
 
-static void
-glade_util_draw_nodes (cairo_t * cr, GdkColor * color,
-                       gint x, gint y, gint width, gint height)
-{
-  if (width > GLADE_UTIL_SELECTION_NODE_SIZE &&
-      height > GLADE_UTIL_SELECTION_NODE_SIZE)
-    {
-      glade_utils_cairo_draw_rectangle (cr, color, TRUE,
-                                        x, y,
-                                        GLADE_UTIL_SELECTION_NODE_SIZE,
-                                        GLADE_UTIL_SELECTION_NODE_SIZE);
-      glade_utils_cairo_draw_rectangle (cr, color, TRUE,
-                                        x,
-                                        y + height -
-                                        GLADE_UTIL_SELECTION_NODE_SIZE,
-                                        GLADE_UTIL_SELECTION_NODE_SIZE,
-                                        GLADE_UTIL_SELECTION_NODE_SIZE);
-      glade_utils_cairo_draw_rectangle (cr, color, TRUE,
-                                        x + width -
-                                        GLADE_UTIL_SELECTION_NODE_SIZE, y,
-                                        GLADE_UTIL_SELECTION_NODE_SIZE,
-                                        GLADE_UTIL_SELECTION_NODE_SIZE);
-      glade_utils_cairo_draw_rectangle (cr, color, TRUE,
-                                        x + width -
-                                        GLADE_UTIL_SELECTION_NODE_SIZE,
-                                        y + height -
-                                        GLADE_UTIL_SELECTION_NODE_SIZE,
-                                        GLADE_UTIL_SELECTION_NODE_SIZE,
-                                        GLADE_UTIL_SELECTION_NODE_SIZE);
-    }
-
-  glade_utils_cairo_draw_rectangle (cr, color, FALSE, x, y, width - 1,
-                                    height - 1);
-}
-
-/**
- * glade_util_draw_selection_nodes:
- * @widget: a #GtkWidget
- * @cr: the #cairo_t to draw with
- *
- * Draws selection on @widget if @widget is selected.
- */
-void
-glade_util_draw_selection_nodes (GtkWidget * widget, cairo_t * cr)
-{
-  GladeWidget *gwidget;
-  GladeProject *project;
-  GdkColor *color;
-  GtkAllocation allocation;
-
-  g_return_if_fail (GTK_IS_WIDGET (widget));
-  
-  gwidget = glade_widget_get_from_gobject (widget);
-  if (!gwidget)
-    return;
-
-  project = glade_widget_get_project (gwidget);
-  g_return_if_fail (GLADE_IS_PROJECT (project));
-
-  if (!glade_project_is_selected (project, G_OBJECT (widget)))
-    return;
-
-  cairo_save (cr);
-
-  color = &(gtk_widget_get_style (widget)->black);
-
-  gtk_widget_get_allocation (widget, &allocation);
-  glade_util_draw_nodes (cr, color,
-			 0, 0, allocation.width, allocation.height);
-
-  cairo_restore (cr);
-}
-
 /*
  * taken from gtk... maybe someday we can convince them to
  * expose gtk_container_get_all_children
diff --git a/gladeui/glade-utils.h b/gladeui/glade-utils.h
index 78a165e..3f0d42c 100644
--- a/gladeui/glade-utils.h
+++ b/gladeui/glade-utils.h
@@ -97,8 +97,6 @@ void              glade_utils_cairo_draw_rectangle (cairo_t *cr,
 						    gint width,
 						    gint height);
 
-void              glade_util_draw_selection_nodes (GtkWidget* expose_widget, cairo_t *cr);
-
 /* Lists */
 GList            *glade_util_purify_list           (GList        *list);
 GList            *glade_util_added_in_list         (GList        *old_list,
diff --git a/gladeui/glade-widget-adaptor.c b/gladeui/glade-widget-adaptor.c
index 87c9d66..ef06f80 100644
--- a/gladeui/glade-widget-adaptor.c
+++ b/gladeui/glade-widget-adaptor.c
@@ -1668,33 +1668,6 @@ 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
@@ -1720,10 +1693,6 @@ 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 *



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