[gimp] app: Make GimpDockbook instance data private



commit 2ac7cedbfcfb65326020b5b4bacc87395cbb94c9
Author: Martin Nordholts <martinn src gnome org>
Date:   Sun Sep 13 16:30:09 2009 +0200

    app: Make GimpDockbook instance data private
    
    Make GimpDockbook instance data private and add necessary getters and
    setters.

 app/actions/dockable-actions.c  |    9 +++-
 app/actions/dockable-commands.c |   21 +++++----
 app/widgets/gimpdialogfactory.c |    2 +-
 app/widgets/gimpdock.c          |   10 ++--
 app/widgets/gimpdockable.c      |    4 +-
 app/widgets/gimpdockbook.c      |   92 ++++++++++++++++++++++++++++-----------
 app/widgets/gimpdockbook.h      |   17 ++++---
 app/widgets/gimpdockseparator.c |    2 +-
 8 files changed, 102 insertions(+), 55 deletions(-)
---
diff --git a/app/actions/dockable-actions.c b/app/actions/dockable-actions.c
index 0de2180..863445d 100644
--- a/app/actions/dockable-actions.c
+++ b/app/actions/dockable-actions.c
@@ -194,6 +194,7 @@ dockable_actions_update (GimpActionGroup *group,
   GimpDockable           *dockable;
   GimpDockbook           *dockbook;
   GimpDocked             *docked;
+  GimpDock               *dock;
   GimpDialogFactoryEntry *entry;
   GimpContainerView      *view;
   GimpViewType            view_type           = -1;
@@ -227,6 +228,8 @@ dockable_actions_update (GimpActionGroup *group,
     }
 
   docked = GIMP_DOCKED (gtk_bin_get_child (GTK_BIN (dockable)));
+  dock   = gimp_dockbook_get_dock (dockbook);
+
 
   gimp_dialog_factory_from_widget (GTK_WIDGET (dockable), &entry);
 
@@ -245,12 +248,12 @@ dockable_actions_update (GimpActionGroup *group,
       if (substring)
         {
           memcpy (substring, "list", 4);
-          if (gimp_dialog_factory_find_entry (gimp_dock_get_dialog_factory (dockbook->dock),
+          if (gimp_dialog_factory_find_entry (gimp_dock_get_dialog_factory (dock),
                                               identifier))
             list_view_available = TRUE;
 
           memcpy (substring, "grid", 4);
-          if (gimp_dialog_factory_find_entry (gimp_dock_get_dialog_factory (dockbook->dock),
+          if (gimp_dialog_factory_find_entry (gimp_dock_get_dialog_factory (dock),
                                               identifier))
             grid_view_available = TRUE;
         }
@@ -266,7 +269,7 @@ dockable_actions_update (GimpActionGroup *group,
   tab_style = dockable->tab_style;
 
   n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (dockbook));
-  n_books = g_list_length (gimp_dock_get_dockbooks (dockbook->dock));
+  n_books = g_list_length (gimp_dock_get_dockbooks (dock));
 
 #define SET_ACTIVE(action,active) \
         gimp_action_group_set_action_active (group, action, (active) != 0)
diff --git a/app/actions/dockable-commands.c b/app/actions/dockable-commands.c
index 7bcb6ef..9696d35 100644
--- a/app/actions/dockable-commands.c
+++ b/app/actions/dockable-commands.c
@@ -54,6 +54,7 @@ dockable_add_tab_cmd_callback (GtkAction   *action,
   if (value)
     {
       GtkWidget *dockable;
+      GimpDock  *dock;
       gchar     *identifier;
       gchar     *p;
 
@@ -64,10 +65,10 @@ dockable_add_tab_cmd_callback (GtkAction   *action,
       if (p)
         *p = '\0';
 
-      dockable =
-        gimp_dialog_factory_dockable_new (gimp_dock_get_dialog_factory (dockbook->dock),
-                                          dockbook->dock,
-                                          identifier, -1);
+      dock     = gimp_dockbook_get_dock (dockbook);
+      dockable = gimp_dialog_factory_dockable_new (gimp_dock_get_dialog_factory (dock),
+                                                   dock,
+                                                   identifier, -1);
 
       g_free (identifier);
 
@@ -165,6 +166,7 @@ dockable_toggle_view_cmd_callback (GtkAction *action,
             {
               GimpContainerView *old_view;
               GtkWidget         *new_dockable;
+              GimpDock          *dock;
               gint               view_size = -1;
 
               if (view_type == GIMP_VIEW_TYPE_LIST)
@@ -177,12 +179,11 @@ dockable_toggle_view_cmd_callback (GtkAction *action,
               if (old_view)
                 view_size = gimp_container_view_get_view_size (old_view, NULL);
 
-
-              new_dockable =
-                gimp_dialog_factory_dockable_new (gimp_dock_get_dialog_factory (dockbook->dock),
-                                                  dockbook->dock,
-                                                  identifier,
-                                                  view_size);
+              dock         = gimp_dockbook_get_dock (dockbook);
+              new_dockable = gimp_dialog_factory_dockable_new (gimp_dock_get_dialog_factory (dock),
+                                                               dock,
+                                                               identifier,
+                                                               view_size);
 
               if (new_dockable)
                 {
diff --git a/app/widgets/gimpdialogfactory.c b/app/widgets/gimpdialogfactory.c
index 8c150da..450ae4a 100644
--- a/app/widgets/gimpdialogfactory.c
+++ b/app/widgets/gimpdialogfactory.c
@@ -547,7 +547,7 @@ gimp_dialog_factory_dialog_new_internal (GimpDialogFactory *factory,
     {
       GimpDockable *dockable = GIMP_DOCKABLE (dialog);
 
-      if (dockable->dockbook && dockable->dockbook->dock)
+      if (dockable->dockbook && gimp_dockbook_get_dock (dockable->dockbook))
         {
           GtkNotebook *notebook = GTK_NOTEBOOK (dockable->dockbook);
           gint         num      = gtk_notebook_page_num (notebook, dialog);
diff --git a/app/widgets/gimpdock.c b/app/widgets/gimpdock.c
index 12ac265..b9556de 100644
--- a/app/widgets/gimpdock.c
+++ b/app/widgets/gimpdock.c
@@ -435,7 +435,7 @@ gimp_dock_remove (GimpDock     *dock,
   g_return_if_fail (GIMP_IS_DOCK (dock));
   g_return_if_fail (GIMP_IS_DOCKABLE (dockable));
   g_return_if_fail (dockable->dockbook != NULL);
-  g_return_if_fail (dockable->dockbook->dock == dock);
+  g_return_if_fail (gimp_dockbook_get_dock (dockable->dockbook) == dock);
 
   gimp_dockbook_remove (dockable->dockbook, dockable);
 }
@@ -449,14 +449,14 @@ gimp_dock_add_book (GimpDock     *dock,
 
   g_return_if_fail (GIMP_IS_DOCK (dock));
   g_return_if_fail (GIMP_IS_DOCKBOOK (dockbook));
-  g_return_if_fail (dockbook->dock == NULL);
+  g_return_if_fail (gimp_dockbook_get_dock (dockbook) == NULL);
 
   old_length = g_list_length (dock->p->dockbooks);
 
   if (index >= old_length || index < 0)
     index = old_length;
 
-  dockbook->dock  = dock;
+  gimp_dockbook_set_dock (dockbook, dock);
   dock->p->dockbooks = g_list_insert (dock->p->dockbooks, dockbook, index);
 
   if (old_length == 0)
@@ -539,12 +539,12 @@ gimp_dock_remove_book (GimpDock     *dock,
   g_return_if_fail (GIMP_IS_DOCK (dock));
   g_return_if_fail (GIMP_IS_DOCKBOOK (dockbook));
 
-  g_return_if_fail (dockbook->dock == dock);
+  g_return_if_fail (gimp_dockbook_get_dock (dockbook) == dock);
 
   old_length = g_list_length (dock->p->dockbooks);
   index      = g_list_index (dock->p->dockbooks, dockbook);
 
-  dockbook->dock  = NULL;
+  gimp_dockbook_set_dock (dockbook, NULL);
   dock->p->dockbooks = g_list_remove (dock->p->dockbooks, dockbook);
 
   g_object_ref (dockbook);
diff --git a/app/widgets/gimpdockable.c b/app/widgets/gimpdockable.c
index 9f1ef4e..7f2adb7 100644
--- a/app/widgets/gimpdockable.c
+++ b/app/widgets/gimpdockable.c
@@ -998,7 +998,7 @@ gimp_dockable_detach (GimpDockable *dockable)
   g_return_if_fail (GIMP_IS_DOCKABLE (dockable));
   g_return_if_fail (GIMP_IS_DOCKBOOK (dockable->dockbook));
 
-  src_dock = dockable->dockbook->dock;
+  src_dock = gimp_dockbook_get_dock (dockable->dockbook);
 
   dock = gimp_dialog_factory_dock_new (gimp_dock_get_dialog_factory (src_dock),
                                        gtk_widget_get_screen (GTK_WIDGET (dockable)));
@@ -1164,7 +1164,7 @@ gimp_dockable_menu_end (GimpDockable *dockable)
 static gboolean
 gimp_dockable_show_menu (GimpDockable *dockable)
 {
-  GimpUIManager *dockbook_ui_manager = dockable->dockbook->ui_manager;
+  GimpUIManager *dockbook_ui_manager = gimp_dockbook_get_ui_manager (dockable->dockbook);
   GimpUIManager *dialog_ui_manager;
   const gchar   *dialog_ui_path;
   gpointer       dialog_popup_data;
diff --git a/app/widgets/gimpdockbook.c b/app/widgets/gimpdockbook.c
index 40aeb49..2e3df1c 100644
--- a/app/widgets/gimpdockbook.c
+++ b/app/widgets/gimpdockbook.c
@@ -60,6 +60,15 @@ enum
   LAST_SIGNAL
 };
 
+struct _GimpDockbookPrivate
+{
+  GimpDock      *dock;
+  GimpUIManager *ui_manager;
+
+  guint          tab_hover_timeout;
+  GimpDockable  *tab_hover_dockable;
+};
+
 
 static void      gimp_dockbook_dispose            (GObject        *object);
 static void      gimp_dockbook_finalize           (GObject        *object);
@@ -183,13 +192,18 @@ gimp_dockbook_class_init (GimpDockbookClass *klass)
                                                               GTK_TYPE_ICON_SIZE,
                                                               DEFAULT_TAB_ICON_SIZE,
                                                               GIMP_PARAM_READABLE));
+
+  g_type_class_add_private (klass, sizeof (GimpDockbookPrivate));
 }
 
 static void
 gimp_dockbook_init (GimpDockbook *dockbook)
 {
-  dockbook->dock       = NULL;
-  dockbook->ui_manager = NULL;
+  dockbook->p = G_TYPE_INSTANCE_GET_PRIVATE (dockbook,
+                                             GIMP_TYPE_DOCKBOOK,
+                                             GimpDockbookPrivate);
+  dockbook->p->dock       = NULL;
+  dockbook->p->ui_manager = NULL;
 
   gtk_notebook_popup_enable (GTK_NOTEBOOK (dockbook));
   gtk_notebook_set_scrollable (GTK_NOTEBOOK (dockbook), TRUE);
@@ -216,10 +230,10 @@ gimp_dockbook_finalize (GObject *object)
 {
   GimpDockbook *dockbook = GIMP_DOCKBOOK (object);
 
-  if (dockbook->ui_manager)
+  if (dockbook->p->ui_manager)
     {
-      g_object_unref (dockbook->ui_manager);
-      dockbook->ui_manager = NULL;
+      g_object_unref (dockbook->p->ui_manager);
+      dockbook->p->ui_manager = NULL;
     }
 
   G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -318,7 +332,7 @@ gimp_dockbook_new (GimpMenuFactory *menu_factory)
 
   dockbook = g_object_new (GIMP_TYPE_DOCKBOOK, NULL);
 
-  dockbook->ui_manager = gimp_menu_factory_manager_new (menu_factory,
+  dockbook->p->ui_manager = gimp_menu_factory_manager_new (menu_factory,
                                                         "<Dockable>",
                                                         dockbook,
                                                         FALSE);
@@ -329,6 +343,32 @@ gimp_dockbook_new (GimpMenuFactory *menu_factory)
   return GTK_WIDGET (dockbook);
 }
 
+GimpDock *
+gimp_dockbook_get_dock (GimpDockbook *dockbook)
+{
+  g_return_val_if_fail (GIMP_IS_DOCKBOOK (dockbook), NULL);
+
+  return dockbook->p->dock;
+}
+
+void
+gimp_dockbook_set_dock (GimpDockbook *dockbook,
+                        GimpDock     *dock)
+{
+  g_return_if_fail (GIMP_IS_DOCKBOOK (dockbook));
+  g_return_if_fail (dock == NULL || GIMP_IS_DOCK (dock));
+
+  dockbook->p->dock = dock;
+}
+
+GimpUIManager *
+gimp_dockbook_get_ui_manager (GimpDockbook *dockbook)
+{
+  g_return_val_if_fail (GIMP_IS_DOCKBOOK (dockbook), NULL);
+
+  return dockbook->p->ui_manager;
+}
+
 void
 gimp_dockbook_add (GimpDockbook *dockbook,
                    GimpDockable *dockable,
@@ -338,7 +378,7 @@ gimp_dockbook_add (GimpDockbook *dockbook,
   GtkWidget *menu_widget;
 
   g_return_if_fail (GIMP_IS_DOCKBOOK (dockbook));
-  g_return_if_fail (dockbook->dock != NULL);
+  g_return_if_fail (dockbook->p->dock != NULL);
   g_return_if_fail (GIMP_IS_DOCKABLE (dockable));
   g_return_if_fail (dockable->dockbook == NULL);
 
@@ -347,7 +387,7 @@ gimp_dockbook_add (GimpDockbook *dockbook,
   g_return_if_fail (GTK_IS_WIDGET (tab_widget));
 
   menu_widget = gimp_dockable_get_tab_widget (dockable,
-                                              gimp_dock_get_context (dockbook->dock),
+                                              gimp_dock_get_context (dockbook->p->dock),
                                               GIMP_TAB_STYLE_ICON_BLURB,
                                               MENU_WIDGET_ICON_SIZE);
 
@@ -373,7 +413,7 @@ gimp_dockbook_add (GimpDockbook *dockbook,
 
   dockable->dockbook = dockbook;
 
-  gimp_dockable_set_context (dockable, gimp_dock_get_context (dockbook->dock));
+  gimp_dockable_set_context (dockable, gimp_dock_get_context (dockbook->p->dock));
 
   g_signal_connect (dockable, "notify::locked",
                     G_CALLBACK (gimp_dockbook_tab_locked_notify),
@@ -398,7 +438,7 @@ gimp_dockbook_remove (GimpDockbook *dockbook,
                                         G_CALLBACK (gimp_dockbook_tab_locked_notify),
                                         dockbook);
 
-  if (dockbook->tab_hover_dockable == dockable)
+  if (dockbook->p->tab_hover_dockable == dockable)
     gimp_dockbook_remove_tab_timeout (dockbook);
 
   dockable->dockbook = NULL;
@@ -414,7 +454,7 @@ gimp_dockbook_remove (GimpDockbook *dockbook,
   children = gtk_container_get_children (GTK_CONTAINER (dockbook));
 
   if (! g_list_length (children))
-    gimp_dock_remove_book (dockbook->dock, dockbook);
+    gimp_dock_remove_book (dockbook->p->dock, dockbook);
 
   g_list_free (children);
 }
@@ -432,7 +472,7 @@ gimp_dockbook_create_tab_widget (GimpDockbook *dockbook,
                         NULL);
 
   tab_widget = gimp_dockable_get_tab_widget (dockable,
-                                             gimp_dock_get_context (dockbook->dock),
+                                             gimp_dock_get_context (dockbook->p->dock),
                                              dockable->tab_style,
                                              tab_size);
 
@@ -450,8 +490,8 @@ gimp_dockbook_create_tab_widget (GimpDockbook *dockbook,
     }
 
   /* EEK */
-  if (GIMP_IS_DOCK_WINDOW (dockbook->dock) &&
-      gimp_dock_window_get_ui_manager (GIMP_DOCK_WINDOW (dockbook->dock)))
+  if (GIMP_IS_DOCK_WINDOW (dockbook->p->dock) &&
+      gimp_dock_window_get_ui_manager (GIMP_DOCK_WINDOW (dockbook->p->dock)))
     {
       const gchar *dialog_id;
 
@@ -463,7 +503,7 @@ gimp_dockbook_create_tab_widget (GimpDockbook *dockbook,
           GimpActionGroup *group;
 
           group = gimp_ui_manager_get_action_group
-            (gimp_dock_window_get_ui_manager (GIMP_DOCK_WINDOW (dockbook->dock)), "dialogs");
+            (gimp_dock_window_get_ui_manager (GIMP_DOCK_WINDOW (dockbook->p->dock)), "dialogs");
 
           if (group)
             {
@@ -690,8 +730,8 @@ gimp_dockbook_tab_drag_motion (GtkWidget      *widget,
   GtkTargetList *target_list;
   GdkAtom        target_atom;
 
-  if (! dockbook->tab_hover_timeout ||
-      dockbook->tab_hover_dockable != dockable)
+  if (! dockbook->p->tab_hover_timeout ||
+      dockbook->p->tab_hover_dockable != dockable)
     {
       gint page_num;
 
@@ -790,22 +830,22 @@ static void
 gimp_dockbook_add_tab_timeout (GimpDockbook *dockbook,
                                GimpDockable *dockable)
 {
-  dockbook->tab_hover_timeout =
+  dockbook->p->tab_hover_timeout =
     g_timeout_add (TAB_HOVER_TIMEOUT,
                    (GSourceFunc) gimp_dockbook_tab_timeout,
                    dockbook);
 
-  dockbook->tab_hover_dockable = dockable;
+  dockbook->p->tab_hover_dockable = dockable;
 }
 
 static void
 gimp_dockbook_remove_tab_timeout (GimpDockbook *dockbook)
 {
-  if (dockbook->tab_hover_timeout)
+  if (dockbook->p->tab_hover_timeout)
     {
-      g_source_remove (dockbook->tab_hover_timeout);
-      dockbook->tab_hover_timeout  = 0;
-      dockbook->tab_hover_dockable = NULL;
+      g_source_remove (dockbook->p->tab_hover_timeout);
+      dockbook->p->tab_hover_timeout  = 0;
+      dockbook->p->tab_hover_dockable = NULL;
     }
 }
 
@@ -817,11 +857,11 @@ gimp_dockbook_tab_timeout (GimpDockbook *dockbook)
   GDK_THREADS_ENTER ();
 
   page_num = gtk_notebook_page_num (GTK_NOTEBOOK (dockbook),
-                                    GTK_WIDGET (dockbook->tab_hover_dockable));
+                                    GTK_WIDGET (dockbook->p->tab_hover_dockable));
   gtk_notebook_set_current_page (GTK_NOTEBOOK (dockbook), page_num);
 
-  dockbook->tab_hover_timeout  = 0;
-  dockbook->tab_hover_dockable = NULL;
+  dockbook->p->tab_hover_timeout  = 0;
+  dockbook->p->tab_hover_dockable = NULL;
 
   GDK_THREADS_LEAVE ();
 
diff --git a/app/widgets/gimpdockbook.h b/app/widgets/gimpdockbook.h
index 689accb..ed9b56c 100644
--- a/app/widgets/gimpdockbook.h
+++ b/app/widgets/gimpdockbook.h
@@ -30,7 +30,8 @@
 #define GIMP_DOCKBOOK_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_DOCKBOOK, GimpDockbookClass))
 
 
-typedef struct _GimpDockbookClass  GimpDockbookClass;
+typedef struct _GimpDockbookClass    GimpDockbookClass;
+typedef struct _GimpDockbookPrivate  GimpDockbookPrivate;
 
 /**
  * Holds GimpDockables which are presented on different tabs using
@@ -38,13 +39,9 @@ typedef struct _GimpDockbookClass  GimpDockbookClass;
  */
 struct _GimpDockbook
 {
-  GtkNotebook    parent_instance;
+  GtkNotebook parent_instance;
 
-  GimpDock      *dock;
-  GimpUIManager *ui_manager;
-
-  guint          tab_hover_timeout;
-  GimpDockable  *tab_hover_dockable;
+  GimpDockbookPrivate *p;
 };
 
 struct _GimpDockbookClass
@@ -64,6 +61,12 @@ GType       gimp_dockbook_get_type          (void) G_GNUC_CONST;
 
 GtkWidget * gimp_dockbook_new               (GimpMenuFactory  *menu_factory);
 
+GimpDock  * gimp_dockbook_get_dock          (GimpDockbook     *dockbook);
+void        gimp_dockbook_set_dock          (GimpDockbook     *dockbook,
+                                             GimpDock         *dock);
+GimpUIManager *
+            gimp_dockbook_get_ui_manager    (GimpDockbook     *dockbook);
+
 void        gimp_dockbook_add               (GimpDockbook     *dockbook,
                                              GimpDockable     *dockable,
                                              gint              position);
diff --git a/app/widgets/gimpdockseparator.c b/app/widgets/gimpdockseparator.c
index 841f741..0df7e9c 100644
--- a/app/widgets/gimpdockseparator.c
+++ b/app/widgets/gimpdockseparator.c
@@ -208,7 +208,7 @@ gimp_dock_separator_drag_drop (GtkWidget      *widget,
           /*  if dropping to the same dock, take care that we don't try
            *  to reorder the *only* dockable in the dock
            */
-          if (dockable->dockbook->dock == dock)
+          if (gimp_dockbook_get_dock (dockable->dockbook) == dock)
             {
               GList *children;
               gint   n_books;



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