[gimp] app: Move docks to image window in 'Single-window mode'



commit fcf5895575f5b23a9c82aeabc4ffccb994dc1fa9
Author: Martin Nordholts <martinn src gnome org>
Date:   Sun Oct 4 02:09:53 2009 +0200

    app: Move docks to image window in 'Single-window mode'
    
    When 'Single-window mode is enabled, move the toolbox and existing
    docks into the image window. Needs a lot of more work but is
    functional enough for curious people.
    
    Implemented by adding a new GimpUIConfigurer component that has global
    knowledge. There is a single application instance of this
    component. It subscribes to changes in the single-window-mode config
    property and adjusts the UI accordingly.

 app/gui/Makefile.am         |    2 +
 app/gui/gimpuiconfigurer.c  |  249 +++++++++++++++++++++++++++++++++++++++++++
 app/gui/gimpuiconfigurer.h  |   57 ++++++++++
 app/gui/gui.c               |   24 ++++-
 app/widgets/widgets-types.h |    1 +
 5 files changed, 331 insertions(+), 2 deletions(-)
---
diff --git a/app/gui/Makefile.am b/app/gui/Makefile.am
index 5fbade1..47f96a3 100644
--- a/app/gui/Makefile.am
+++ b/app/gui/Makefile.am
@@ -21,6 +21,8 @@ libappgui_a_sources = \
 	color-history.h		\
 	gimpdbusservice.c	\
 	gimpdbusservice.h	\
+	gimpuiconfigurer.c	\
+	gimpuiconfigurer.h	\
 	gui.c			\
 	gui.h			\
 	gui-message.c		\
diff --git a/app/gui/gimpuiconfigurer.c b/app/gui/gimpuiconfigurer.c
new file mode 100644
index 0000000..fafaac2
--- /dev/null
+++ b/app/gui/gimpuiconfigurer.c
@@ -0,0 +1,249 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpuiconfigurer.c
+ * Copyright (C) 2009 Martin Nordholts <martinn src gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+
+#include "gui-types.h"
+
+#include "core/gimp.h"
+
+#include "widgets/gimpdialogfactory.h"
+#include "widgets/gimpdock.h"
+#include "widgets/gimpdockcolumns.h"
+#include "widgets/gimpdockwindow.h"
+
+#include "display/gimpimagewindow.h"
+
+#include "dialogs/dialogs.h"
+
+#include "gimpuiconfigurer.h"
+
+
+enum
+{
+  PROP_0,
+  PROP_GIMP
+};
+
+
+struct _GimpUIConfigurerPrivate
+{
+  Gimp *gimp;
+};
+
+
+static void  gimp_ui_configurer_set_property                (GObject           *object,
+                                                             guint              property_id,
+                                                             const GValue      *value,
+                                                             GParamSpec        *pspec);
+static void  gimp_ui_configurer_get_property                (GObject           *object,
+                                                             guint              property_id,
+                                                             GValue            *value,
+                                                             GParamSpec        *pspec);
+static void  gimp_ui_configurer_move_docks_to_columns       (GimpUIConfigurer  *ui_configurer,
+                                                             GimpDialogFactory *dialog_factory,
+                                                             GimpDockColumns   *dock_columns);
+static void  gimp_ui_configurer_configure_for_single_window (GimpUIConfigurer  *ui_configurer);
+static void  gimp_ui_configurer_configure_for_multi_window  (GimpUIConfigurer  *ui_configurer);
+
+
+G_DEFINE_TYPE (GimpUIConfigurer, gimp_ui_configurer, GIMP_TYPE_OBJECT)
+
+#define parent_class gimp_ui_configurer_parent_class
+
+
+static void
+gimp_ui_configurer_class_init (GimpUIConfigurerClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->set_property = gimp_ui_configurer_set_property;
+  object_class->get_property = gimp_ui_configurer_get_property;
+
+  g_object_class_install_property (object_class, PROP_GIMP,
+                                   g_param_spec_object ("gimp", NULL, NULL,
+                                                        GIMP_TYPE_GIMP,
+                                                        GIMP_PARAM_READWRITE |
+                                                        G_PARAM_CONSTRUCT_ONLY));
+  g_type_class_add_private (klass,
+                            sizeof (GimpUIConfigurerPrivate));
+}
+
+static void
+gimp_ui_configurer_init (GimpUIConfigurer *ui_configurer)
+{
+  ui_configurer->p = G_TYPE_INSTANCE_GET_PRIVATE (ui_configurer,
+                                                  GIMP_TYPE_UI_CONFIGURER,
+                                                  GimpUIConfigurerPrivate);
+}
+
+static void
+gimp_ui_configurer_set_property (GObject      *object,
+                                 guint         property_id,
+                                 const GValue *value,
+                                 GParamSpec   *pspec)
+{
+  GimpUIConfigurer *ui_configurer = GIMP_UI_CONFIGURER (object);
+
+  switch (property_id)
+    {
+    case PROP_GIMP:
+      ui_configurer->p->gimp = g_value_get_object (value); /* don't ref */
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_ui_configurer_get_property (GObject    *object,
+                                 guint       property_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
+{
+  GimpUIConfigurer *ui_configurer = GIMP_UI_CONFIGURER (object);
+
+  switch (property_id)
+    {
+    case PROP_GIMP:
+      g_value_set_object (value, ui_configurer->p->gimp);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+      break;
+    }
+}
+
+static void
+gimp_ui_configurer_move_docks_to_columns (GimpUIConfigurer  *ui_configurer,
+                                          GimpDialogFactory *dialog_factory,
+                                          GimpDockColumns   *dock_columns)
+{
+  GList *iter        = NULL;
+  GList *for_removal = NULL;
+
+  for (iter = dialog_factory->open_dialogs; iter; iter = iter->next)
+    {
+      GimpDockWindow *dock_window = NULL;
+      GimpDock       *dock        = NULL;
+
+      if (!GIMP_IS_DOCK_WINDOW (iter->data))
+        continue;
+
+      dock_window = GIMP_DOCK_WINDOW (iter->data);
+      dock        = gimp_dock_window_get_dock (dock_window);
+
+      /* Move the dock from the image window to the dock columns
+       * widget. Note that we need a ref while the dock is parentless
+       */
+      g_object_ref (dock);
+      gtk_container_remove (GTK_CONTAINER (dock_window), GTK_WIDGET (dock));
+      gimp_dock_columns_add_dock (dock_columns, dock);
+      g_object_unref (dock);
+
+      /* Queue for removal from the dialog factory. (We can't remove
+       * while we iterate)
+       */
+      for_removal = g_list_prepend (for_removal, dock_window);
+    }
+
+  for (iter = for_removal; iter; iter = iter->next)
+    {
+      GtkWidget *dock_window = GTK_WIDGET (iter->data);
+
+      /* Kill the dock window, we don't need it any longer */
+      gimp_dialog_factory_remove_dialog (dialog_factory, dock_window);
+      gtk_widget_destroy (GTK_WIDGET (dock_window));
+    }
+}
+
+static void
+gimp_ui_configurer_configure_for_single_window (GimpUIConfigurer *ui_configurer)
+{
+  Gimp    *gimp        = GIMP (ui_configurer->p->gimp);
+  GList   *iter        = NULL;
+  gboolean docks_moved = FALSE;
+
+  for (iter = gimp_get_image_window_iter (gimp);
+       iter;
+       iter = g_list_next (iter))
+    {
+      GimpImageWindow *image_window = GIMP_IMAGE_WINDOW (iter->data);
+
+      /* Move all docks to the first image window */
+      if (! docks_moved)
+        {
+          GimpDockColumns *left_docks  = gimp_image_window_get_left_docks (image_window);
+          GimpDockColumns *right_docks = gimp_image_window_get_right_docks (image_window);
+
+          /* First move the toolbox to the left side of the image
+           * window
+           */
+          gimp_ui_configurer_move_docks_to_columns (ui_configurer,
+                                                    global_toolbox_factory,
+                                                    left_docks);
+
+          /* Then move the other docks to the right side of the image
+           * window
+           */
+          gimp_ui_configurer_move_docks_to_columns (ui_configurer,
+                                                    global_dock_factory,
+                                                    right_docks);
+
+          /* Don't do it again */
+          docks_moved = TRUE;
+        }
+
+      /* FIXME: Move all displays to a single window */
+      gimp_image_window_set_show_docks (image_window, TRUE);
+    }
+}
+
+static void
+gimp_ui_configurer_configure_for_multi_window (GimpUIConfigurer *ui_configurer)
+{
+  Gimp  *gimp = GIMP (ui_configurer->p->gimp);
+  GList *iter = NULL;
+
+  for (iter = gimp_get_image_window_iter (gimp);
+       iter;
+       iter = g_list_next (iter))
+    {
+      GimpImageWindow *image_window = GIMP_IMAGE_WINDOW (iter->data);
+
+      /* FIXME: Move all displays to a multiple windows */
+      gimp_image_window_set_show_docks (image_window, FALSE);
+    }
+}
+
+void
+gimp_ui_configurer_configure (GimpUIConfigurer *ui_configurer,
+                              gboolean          single_window_mode)
+{
+  if (single_window_mode)
+    gimp_ui_configurer_configure_for_single_window (ui_configurer);
+  else
+    gimp_ui_configurer_configure_for_multi_window (ui_configurer);
+}
diff --git a/app/gui/gimpuiconfigurer.h b/app/gui/gimpuiconfigurer.h
new file mode 100644
index 0000000..d68ded9
--- /dev/null
+++ b/app/gui/gimpuiconfigurer.h
@@ -0,0 +1,57 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpuiconfigurer.h
+ * Copyright (C) 2009 Martin Nordholts <martinn src gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_UI_CONFIGURER_H__
+#define __GIMP_UI_CONFIGURER_H__
+
+
+#include "core/gimpobject.h"
+
+
+#define GIMP_TYPE_UI_CONFIGURER              (gimp_ui_configurer_get_type ())
+#define GIMP_UI_CONFIGURER(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_UI_CONFIGURER, GimpUIConfigurer))
+#define GIMP_UI_CONFIGURER_CLASS(vtable)     (G_TYPE_CHECK_CLASS_CAST ((vtable), GIMP_TYPE_UI_CONFIGURER, GimpUIConfigurerClass))
+#define GIMP_IS_UI_CONFIGURER(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_UI_CONFIGURER))
+#define GIMP_IS_UI_CONFIGURER_CLASS(vtable)  (G_TYPE_CHECK_CLASS_TYPE ((vtable), GIMP_TYPE_UI_CONFIGURER))
+#define GIMP_UI_CONFIGURER_GET_CLASS(inst)   (G_TYPE_INSTANCE_GET_CLASS ((inst), GIMP_TYPE_UI_CONFIGURER, GimpUIConfigurerClass))
+
+
+typedef struct _GimpUIConfigurerClass   GimpUIConfigurerClass;
+typedef struct _GimpUIConfigurerPrivate GimpUIConfigurerPrivate;
+
+struct _GimpUIConfigurer
+{
+  GimpObject parent_instance;
+
+  GimpUIConfigurerPrivate *p;
+};
+
+struct _GimpUIConfigurerClass
+{
+  GimpObjectClass parent_class;
+};
+
+
+GType         gimp_ui_configurer_get_type  (void) G_GNUC_CONST;
+void          gimp_ui_configurer_configure (GimpUIConfigurer *ui_configurer,
+                                            gboolean          single_window_mode);
+
+
+#endif  /* __GIMP_UI_CONFIGURER_H__ */
diff --git a/app/gui/gui.c b/app/gui/gui.c
index 7bf7aa4..978ce81 100644
--- a/app/gui/gui.c
+++ b/app/gui/gui.c
@@ -72,6 +72,7 @@
 #include "dialogs/dialogs.h"
 
 #include "color-history.h"
+#include "gimpuiconfigurer.h"
 #include "gui.h"
 #include "gui-unique.h"
 #include "gui-vtable.h"
@@ -115,6 +116,9 @@ static void       gui_show_help_button_notify   (GimpGuiConfig      *gui_config,
 static void       gui_user_manual_notify        (GimpGuiConfig      *gui_config,
                                                  GParamSpec         *pspec,
                                                  Gimp               *gimp);
+static void       gui_single_window_mode_notify (GimpGuiConfig      *gui_config,
+                                                 GParamSpec         *pspec,
+                                                 GimpUIConfigurer   *ui_configurer);
 static void       gui_tearoff_menus_notify      (GimpGuiConfig      *gui_config,
                                                  GParamSpec         *pspec,
                                                  GtkUIManager       *manager);
@@ -136,8 +140,9 @@ static void       gui_display_remove            (GimpContainer      *displays);
 
 /*  private variables  */
 
-static Gimp          *the_gui_gimp     = NULL;
-static GimpUIManager *image_ui_manager = NULL;
+static Gimp             *the_gui_gimp     = NULL;
+static GimpUIManager    *image_ui_manager = NULL;
+static GimpUIConfigurer *ui_configurer    = NULL;
 
 
 /*  public functions  */
@@ -446,6 +451,10 @@ gui_restore_after_callback (Gimp               *gimp,
   if (gui_config->restore_accels)
     menus_restore (gimp);
 
+  ui_configurer = g_object_new (GIMP_TYPE_UI_CONFIGURER,
+                                "gimp", gimp,
+                                NULL);
+
   image_ui_manager = gimp_menu_factory_manager_new (global_menu_factory,
                                                     "<Image>",
                                                     gimp,
@@ -499,6 +508,9 @@ gui_restore_after_callback (Gimp               *gimp,
   }
 #endif /* GDK_WINDOWING_QUARTZ */
 
+  g_signal_connect_object (gui_config, "notify::single-window-mode",
+                           G_CALLBACK (gui_single_window_mode_notify),
+                           ui_configurer, 0);
   g_signal_connect_object (gui_config, "notify::tearoff-menus",
                            G_CALLBACK (gui_tearoff_menus_notify),
                            image_ui_manager, 0);
@@ -660,6 +672,14 @@ gui_user_manual_notify (GimpGuiConfig *gui_config,
 }
 
 static void
+gui_single_window_mode_notify (GimpGuiConfig      *gui_config,
+                               GParamSpec         *pspec,
+                               GimpUIConfigurer   *ui_configurer)
+{
+  gimp_ui_configurer_configure (ui_configurer,
+                                gui_config->single_window_mode);
+}
+static void
 gui_tearoff_menus_notify (GimpGuiConfig *gui_config,
                           GParamSpec    *pspec,
                           GtkUIManager  *manager)
diff --git a/app/widgets/widgets-types.h b/app/widgets/widgets-types.h
index c3439f3..49b0957 100644
--- a/app/widgets/widgets-types.h
+++ b/app/widgets/widgets-types.h
@@ -220,6 +220,7 @@ typedef struct _GimpCellRendererViewable     GimpCellRendererViewable;
 /*  misc utilities & constructors  */
 
 typedef struct _GimpDialogFactory            GimpDialogFactory;
+typedef struct _GimpUIConfigurer             GimpUIConfigurer;
 
 
 /*  session management objects and structs  */



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