[gimp] app: Add gimp_dock_columns_new() and GimpContext property



commit bc5da21ba275e9c87975c25bd00524c7b04f80dc
Author: Martin Nordholts <martinn src gnome org>
Date:   Thu Jan 7 19:13:13 2010 +0100

    app: Add gimp_dock_columns_new() and GimpContext property
    
    Add and use gimp_dock_columns_new() and add a GimpContext property to
    GimpDockColumns. Also move the widget construction from _init() to
    _constructor() in GimpDockWindow so we have a context object to pass
    to gimp_dock_columns_new().

 app/display/gimpimagewindow.c |    8 +-
 app/widgets/gimpdockcolumns.c |  103 ++++++++++++++++++++++++++---
 app/widgets/gimpdockcolumns.h |    1 +
 app/widgets/gimpdockwindow.c  |  144 ++++++++++++++++++++---------------------
 4 files changed, 169 insertions(+), 87 deletions(-)
---
diff --git a/app/display/gimpimagewindow.c b/app/display/gimpimagewindow.c
index 26b5018..60d721d 100644
--- a/app/display/gimpimagewindow.c
+++ b/app/display/gimpimagewindow.c
@@ -310,7 +310,8 @@ gimp_image_window_constructor (GType                  type,
   gtk_widget_show (private->left_hpane);
 
   /* Create the left dock columns widget */
-  private->left_docks = g_object_new (GIMP_TYPE_DOCK_COLUMNS, NULL);
+  private->left_docks =
+    gimp_dock_columns_new (gimp_get_user_context (private->gimp));
   gimp_dock_columns_set_context (GIMP_DOCK_COLUMNS (private->left_docks),
                                  gimp_get_user_context (private->gimp));
   gtk_paned_pack1 (GTK_PANED (private->left_hpane), private->left_docks,
@@ -339,9 +340,8 @@ gimp_image_window_constructor (GType                  type,
   gtk_widget_show (private->notebook);
 
   /* Create the right dock columns widget */
-  private->right_docks = g_object_new (GIMP_TYPE_DOCK_COLUMNS, NULL);
-  gimp_dock_columns_set_context (GIMP_DOCK_COLUMNS (private->right_docks),
-                                 gimp_get_user_context (private->gimp));
+  private->right_docks =
+    gimp_dock_columns_new (gimp_get_user_context (private->gimp));
   gtk_paned_pack2 (GTK_PANED (private->right_hpane), private->right_docks,
                    FALSE, FALSE);
   if (config->single_window_mode)
diff --git a/app/widgets/gimpdockcolumns.c b/app/widgets/gimpdockcolumns.c
index 17c55d4..f3fbb17 100644
--- a/app/widgets/gimpdockcolumns.c
+++ b/app/widgets/gimpdockcolumns.c
@@ -43,6 +43,13 @@
 
 #include "gimp-log.h"
 
+
+enum
+{
+  PROP_0,
+  PROP_CONTEXT
+};
+
 enum
 {
   DOCK_ADDED,
@@ -61,16 +68,24 @@ struct _GimpDockColumnsPrivate
 };
 
 
-static gboolean  gimp_dock_columns_dropped_cb        (GtkWidget         *source,
-                                                      gint               insert_index,
-                                                      gpointer           data);
-static void      gimp_dock_columns_real_dock_added   (GimpDockColumns   *dock_columns,
-                                                      GimpDock          *dock);
-static void      gimp_dock_columns_real_dock_removed (GimpDockColumns   *dock_columns,
-                                                      GimpDock          *dock);
-static void      gimp_dock_columns_dock_book_removed (GimpDockColumns   *dock_columns,
-                                                      GimpDockbook      *dockbook,
-                                                      GimpDock          *dock);
+static void      gimp_dock_columns_set_property      (GObject         *object,
+                                                      guint            property_id,
+                                                      const GValue    *value,
+                                                      GParamSpec      *pspec);
+static void      gimp_dock_columns_get_property      (GObject         *object,
+                                                      guint            property_id,
+                                                      GValue          *value,
+                                                      GParamSpec      *pspec);
+static gboolean  gimp_dock_columns_dropped_cb        (GtkWidget       *source,
+                                                      gint             insert_index,
+                                                      gpointer         data);
+static void      gimp_dock_columns_real_dock_added   (GimpDockColumns *dock_columns,
+                                                      GimpDock        *dock);
+static void      gimp_dock_columns_real_dock_removed (GimpDockColumns *dock_columns,
+                                                      GimpDock        *dock);
+static void      gimp_dock_columns_dock_book_removed (GimpDockColumns *dock_columns,
+                                                      GimpDockbook    *dockbook,
+                                                      GimpDock        *dock);
 
 
 G_DEFINE_TYPE (GimpDockColumns, gimp_dock_columns, GTK_TYPE_HBOX)
@@ -83,9 +98,21 @@ static guint dock_columns_signals[LAST_SIGNAL] = { 0 };
 static void
 gimp_dock_columns_class_init (GimpDockColumnsClass *klass)
 {
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->set_property = gimp_dock_columns_set_property;
+  object_class->get_property = gimp_dock_columns_get_property;
+
   klass->dock_added   = gimp_dock_columns_real_dock_added;
   klass->dock_removed = gimp_dock_columns_real_dock_removed;
 
+  g_object_class_install_property (object_class, PROP_CONTEXT,
+                                   g_param_spec_object ("context",
+                                                        NULL, NULL,
+                                                        GIMP_TYPE_CONTEXT,
+                                                        GIMP_PARAM_WRITABLE |
+                                                        G_PARAM_CONSTRUCT_ONLY));
+
   dock_columns_signals[DOCK_ADDED] =
     g_signal_new ("dock-added",
                   G_TYPE_FROM_CLASS (klass),
@@ -125,6 +152,46 @@ gimp_dock_columns_init (GimpDockColumns *dock_columns)
   gtk_widget_show (dock_columns->p->paned_hbox);
 }
 
+static void
+gimp_dock_columns_set_property (GObject      *object,
+                                guint         property_id,
+                                const GValue *value,
+                                GParamSpec   *pspec)
+{
+  GimpDockColumns *dock_columns = GIMP_DOCK_COLUMNS (object);
+
+  switch (property_id)
+    {
+    case PROP_CONTEXT:
+      dock_columns->p->context = g_value_get_object (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_dock_columns_get_property (GObject    *object,
+                                guint       property_id,
+                                GValue     *value,
+                                GParamSpec *pspec)
+{
+  GimpDockColumns *dock_columns = GIMP_DOCK_COLUMNS (object);
+
+  switch (property_id)
+    {
+    case PROP_CONTEXT:
+      g_value_set_object (value, dock_columns->p->context);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
 static gboolean
 gimp_dock_columns_dropped_cb (GtkWidget         *source,
                               gint               insert_index,
@@ -186,6 +253,22 @@ gimp_dock_columns_dock_book_removed (GimpDockColumns *dock_columns,
 
 
 /**
+ * gimp_dock_columns_new:
+ * @context:
+ *
+ * Returns: A new #GimpDockColumns.
+ **/
+GtkWidget *
+gimp_dock_columns_new (GimpContext *context)
+{
+  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
+
+  return g_object_new (GIMP_TYPE_DOCK_COLUMNS,
+                       "context", context,
+                       NULL);
+}
+
+/**
  * gimp_dock_columns_add_dock:
  * @dock_columns:
  * @dock:
diff --git a/app/widgets/gimpdockcolumns.h b/app/widgets/gimpdockcolumns.h
index 7f6d71a..15ad465 100644
--- a/app/widgets/gimpdockcolumns.h
+++ b/app/widgets/gimpdockcolumns.h
@@ -58,6 +58,7 @@ struct _GimpDockColumnsClass
 
 
 GType               gimp_dock_columns_get_type       (void) G_GNUC_CONST;
+GtkWidget         * gimp_dock_columns_new            (GimpContext     *context);
 void                gimp_dock_columns_add_dock       (GimpDockColumns *dock_columns,
                                                       GimpDock        *dock,
                                                       gint             index);
diff --git a/app/widgets/gimpdockwindow.c b/app/widgets/gimpdockwindow.c
index 7094bc5..13d316b 100644
--- a/app/widgets/gimpdockwindow.c
+++ b/app/widgets/gimpdockwindow.c
@@ -246,63 +246,6 @@ gimp_dock_window_init (GimpDockWindow *dock_window)
   /* Misc */
   gtk_window_set_resizable (GTK_WINDOW (dock_window), TRUE);
   gtk_window_set_focus_on_map (GTK_WINDOW (dock_window), FALSE);
-
-  /* Setup widget hierarchy */
-  {
-    GtkWidget *vbox = NULL;
-
-    /* Top-level GtkVBox */
-    vbox = gtk_vbox_new (FALSE, 0);
-    gtk_container_add (GTK_CONTAINER (dock_window), vbox);
-    gtk_widget_show (vbox);
-
-    /* Image selection menu */
-    {
-      GtkWidget *hbox = NULL;
-
-      /* GtkHBox */
-      hbox = gtk_hbox_new (FALSE, 2);
-      gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
-      if (dock_window->p->show_image_menu)
-        gtk_widget_show (hbox);
-
-      /* Image combo */
-      dock_window->p->image_combo = gimp_container_combo_box_new (NULL, NULL, 16, 1);
-      gtk_box_pack_start (GTK_BOX (hbox), dock_window->p->image_combo, TRUE, TRUE, 0);
-      g_signal_connect (dock_window->p->image_combo, "destroy",
-                        G_CALLBACK (gtk_widget_destroyed),
-                        &dock_window->p->image_combo);
-      gimp_help_set_help_data (dock_window->p->image_combo,
-                               NULL, GIMP_HELP_DOCK_IMAGE_MENU);
-      gtk_widget_show (dock_window->p->image_combo);
-
-      /* Auto button */
-      dock_window->p->auto_button = gtk_toggle_button_new_with_label (_("Auto"));
-      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dock_window->p->auto_button),
-                                    dock_window->p->auto_follow_active);
-      gtk_box_pack_start (GTK_BOX (hbox), dock_window->p->auto_button, FALSE, FALSE, 0);
-      gtk_widget_show (dock_window->p->auto_button);
-
-      g_signal_connect (dock_window->p->auto_button, "clicked",
-                        G_CALLBACK (gimp_dock_window_auto_clicked),
-                        dock_window);
-
-      gimp_help_set_help_data (dock_window->p->auto_button,
-                               _("When enabled the dialog automatically "
-                                 "follows the image you are working on."),
-                               GIMP_HELP_DOCK_AUTO_BUTTON);
-    }
-
-    /* GimpDockColumns */
-    dock_window->p->dock_columns =g_object_new (GIMP_TYPE_DOCK_COLUMNS, NULL);
-    gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (dock_window->p->dock_columns),
-                        TRUE, TRUE, 0);
-    gtk_widget_show (GTK_WIDGET (dock_window->p->dock_columns));
-    g_signal_connect_object (dock_window->p->dock_columns, "dock-removed",
-                             G_CALLBACK (gimp_dock_window_dock_removed),
-                             dock_window,
-                             G_CONNECT_SWAPPED);
-  }
 }
 
 static GObject *
@@ -334,13 +277,6 @@ gimp_dock_window_constructor (GType                  type,
   dock_window->p->image_container   = gimp->images;
   dock_window->p->display_container = gimp->displays;
 
-  /* Let the GimpDockColumns mirror the context so that a GimpDock can
-   * get it when inside a dock window. We do the same thing in the
-   * GimpImageWindow so docks can get the GimpContext there as well
-   */
-  gimp_dock_columns_set_context (dock_window->p->dock_columns,
-                                 dock_window->p->context);
-
   /* Setup hints */
   gimp_window_set_hint (GTK_WINDOW (dock_window), config->dock_window_hint);
 
@@ -378,18 +314,68 @@ gimp_dock_window_constructor (GType                  type,
   gimp_context_set_parent (dock_window->p->context,
                            gimp_dialog_factory_get_context (dock_window->p->dialog_factory));
 
-  if (dock_window->p->auto_follow_active)
+  /* Setup widget hierarchy */
+  {
+    GtkWidget *vbox = NULL;
+
+    /* Top-level GtkVBox */
+    vbox = gtk_vbox_new (FALSE, 0);
+    gtk_container_add (GTK_CONTAINER (dock_window), vbox);
+    gtk_widget_show (vbox);
+
+    /* Image selection menu */
     {
-      if (gimp_context_get_display (gimp_dialog_factory_get_context (dock_window->p->dialog_factory)))
-        gimp_context_copy_property (gimp_dialog_factory_get_context (dock_window->p->dialog_factory),
-                                    dock_window->p->context,
-                                    GIMP_CONTEXT_PROP_DISPLAY);
-      else
-        gimp_context_copy_property (gimp_dialog_factory_get_context (dock_window->p->dialog_factory),
-                                    dock_window->p->context,
-                                    GIMP_CONTEXT_PROP_IMAGE);
+      GtkWidget *hbox = NULL;
+
+      /* GtkHBox */
+      hbox = gtk_hbox_new (FALSE, 2);
+      gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+      if (dock_window->p->show_image_menu)
+        gtk_widget_show (hbox);
+
+      /* Image combo */
+      dock_window->p->image_combo = gimp_container_combo_box_new (NULL, NULL, 16, 1);
+      gtk_box_pack_start (GTK_BOX (hbox), dock_window->p->image_combo, TRUE, TRUE, 0);
+      g_signal_connect (dock_window->p->image_combo, "destroy",
+                        G_CALLBACK (gtk_widget_destroyed),
+                        &dock_window->p->image_combo);
+      gimp_help_set_help_data (dock_window->p->image_combo,
+                               NULL, GIMP_HELP_DOCK_IMAGE_MENU);
+      gtk_widget_show (dock_window->p->image_combo);
+
+      /* Auto button */
+      dock_window->p->auto_button = gtk_toggle_button_new_with_label (_("Auto"));
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dock_window->p->auto_button),
+                                    dock_window->p->auto_follow_active);
+      gtk_box_pack_start (GTK_BOX (hbox), dock_window->p->auto_button, FALSE, FALSE, 0);
+      gtk_widget_show (dock_window->p->auto_button);
+
+      g_signal_connect (dock_window->p->auto_button, "clicked",
+                        G_CALLBACK (gimp_dock_window_auto_clicked),
+                        dock_window);
+
+      gimp_help_set_help_data (dock_window->p->auto_button,
+                               _("When enabled the dialog automatically "
+                                 "follows the image you are working on."),
+                               GIMP_HELP_DOCK_AUTO_BUTTON);
     }
 
+    /* GimpDockColumns */
+    /* Let the GimpDockColumns mirror the context so that a GimpDock can
+     * get it when inside a dock window. We do the same thing in the
+     * GimpImageWindow so docks can get the GimpContext there as well
+     */
+    dock_window->p->dock_columns =
+      GIMP_DOCK_COLUMNS (gimp_dock_columns_new (dock_window->p->context));
+    gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (dock_window->p->dock_columns),
+                        TRUE, TRUE, 0);
+    gtk_widget_show (GTK_WIDGET (dock_window->p->dock_columns));
+    g_signal_connect_object (dock_window->p->dock_columns, "dock-removed",
+                             G_CALLBACK (gimp_dock_window_dock_removed),
+                             dock_window,
+                             G_CONNECT_SWAPPED);
+  }
+
   g_signal_connect_object (gimp_dialog_factory_get_context (dock_window->p->dialog_factory), "display-changed",
                            G_CALLBACK (gimp_dock_window_factory_display_changed),
                            dock_window,
@@ -413,6 +399,18 @@ gimp_dock_window_constructor (GType                  type,
   gimp_help_connect (GTK_WIDGET (dock_window), gimp_standard_help_func,
                      GIMP_HELP_DOCK, NULL);
 
+  if (dock_window->p->auto_follow_active)
+    {
+      if (gimp_context_get_display (gimp_dialog_factory_get_context (dock_window->p->dialog_factory)))
+        gimp_context_copy_property (gimp_dialog_factory_get_context (dock_window->p->dialog_factory),
+                                    dock_window->p->context,
+                                    GIMP_CONTEXT_PROP_DISPLAY);
+      else
+        gimp_context_copy_property (gimp_dialog_factory_get_context (dock_window->p->dialog_factory),
+                                    dock_window->p->context,
+                                    GIMP_CONTEXT_PROP_IMAGE);
+    }
+
   /* Done! */
   return object;
 }



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