[gdl] Keep hidden widgets in the layout
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gdl] Keep hidden widgets in the layout
- Date: Tue, 17 Jul 2012 20:33:19 +0000 (UTC)
commit 2a20820128f6df1c06554a44c604d8d17f8a678b
Author: SÃbastien Granjoux <seb sfo free fr>
Date: Fri Jul 13 17:55:09 2012 +0200
Keep hidden widgets in the layout
Previously hidden widgets were removed from the layout which makes very difficult to restore them at the same place
gdl/gdl-dock-bar.c | 1 -
gdl/gdl-dock-item.c | 115 ++++---------------------------------------------
gdl/gdl-dock-object.c | 65 +++++++++++++++++++---------
3 files changed, 54 insertions(+), 127 deletions(-)
---
diff --git a/gdl/gdl-dock-bar.c b/gdl/gdl-dock-bar.c
index 563ee8e..bf4f364 100644
--- a/gdl/gdl-dock-bar.c
+++ b/gdl/gdl-dock-bar.c
@@ -269,7 +269,6 @@ gdl_dock_bar_item_clicked (GtkWidget *button,
GDL_DOCK_OBJECT_UNSET_FLAGS (item, GDL_DOCK_ICONIFIED);
gdl_dock_item_show_item (item);
- gdl_dock_bar_remove_item (dockbar, item);
gtk_widget_queue_resize (GTK_WIDGET (controller));
}
diff --git a/gdl/gdl-dock-item.c b/gdl/gdl-dock-item.c
index 0ff0b5e..a1bbbe1 100644
--- a/gdl/gdl-dock-item.c
+++ b/gdl/gdl-dock-item.c
@@ -1565,11 +1565,8 @@ gdl_dock_item_dock (GdlDockObject *object,
gtk_container_add (GTK_CONTAINER (parent), GTK_WIDGET (new_parent));
/* show automatic object */
- if (gtk_widget_get_visible (GTK_WIDGET (object)))
- {
- gtk_widget_show (GTK_WIDGET (new_parent));
- GDL_DOCK_OBJECT_UNSET_FLAGS (object, GDL_DOCK_IN_REFLOW);
- }
+ gtk_widget_show (GTK_WIDGET (new_parent));
+ GDL_DOCK_OBJECT_UNSET_FLAGS (object, GDL_DOCK_IN_REFLOW);
gdl_dock_object_thaw (new_parent);
/* use extra docking parameter */
@@ -1593,7 +1590,7 @@ gdl_dock_item_dock (GdlDockObject *object,
}
requestor_parent = gdl_dock_object_get_parent_object (requestor);
- if (GDL_IS_DOCK_NOTEBOOK (requestor_parent))
+ if (GDL_IS_DOCK_NOTEBOOK (requestor_parent) && gtk_widget_get_visible (GTK_WIDGET (requestor)))
{
/* Activate the page we just added */
GdlDockItem* notebook = GDL_DOCK_ITEM (gdl_dock_object_get_parent_object (requestor));
@@ -1841,6 +1838,7 @@ gdl_dock_item_new (const gchar *name,
"behavior", behavior,
NULL));
GDL_DOCK_OBJECT_UNSET_FLAGS (item, GDL_DOCK_AUTOMATIC);
+ gtk_widget_show (GTK_WIDGET (item));
return GTK_WIDGET (item);
}
@@ -2160,73 +2158,18 @@ gdl_dock_item_unbind (GdlDockItem *item)
* gdl_dock_item_hide_item:
* @item: The dock item to hide.
*
- * This function hides the dock item. When dock items are hidden they
- * are completely removed from the layout.
+ * This function hides the dock item. Since version 3.6, when dock items
+ * are hidden they are not removed from the layout.
*
* The dock item close button causes the panel to be hidden.
**/
void
gdl_dock_item_hide_item (GdlDockItem *item)
{
- GtkAllocation allocation;
-
g_return_if_fail (item != NULL);
- if (!GDL_DOCK_OBJECT_ATTACHED (item))
- /* already hidden/detached */
- return;
-
- /* if the object is manual, create a new placeholder to be able to
- restore the position later */
- if (!GDL_DOCK_OBJECT_AUTOMATIC (item)) {
- if (item->priv->ph)
- g_object_unref (item->priv->ph);
-
- gboolean isFloating = FALSE;
- gint width=0, height=0, x=0, y = 0;
-
- if (GDL_IS_DOCK (gdl_dock_object_get_parent_object (GDL_DOCK_OBJECT (item))))
- {
- GdlDock* dock = GDL_DOCK (gdl_dock_object_get_parent_object (GDL_DOCK_OBJECT (item)));
- g_object_get (dock,
- "floating", &isFloating,
- "width", &width,
- "height",&height,
- "floatx",&x,
- "floaty",&y,
- NULL);
- } else {
- gtk_widget_get_allocation (GTK_WIDGET (item), &allocation);
- item->priv->preferred_width = allocation.width;
- item->priv->preferred_height = allocation.height;
- }
- item->priv->ph = GDL_DOCK_PLACEHOLDER (
- g_object_new (GDL_TYPE_DOCK_PLACEHOLDER,
- "sticky", FALSE,
- "host", item,
- "width", width,
- "height", height,
- "floating", isFloating,
- "floatx", x,
- "floaty", y,
- NULL));
- g_object_ref_sink (item->priv->ph);
- }
-
- gdl_dock_object_freeze (GDL_DOCK_OBJECT (item));
-
- /* hide our children first, so they can also set placeholders */
- if (gdl_dock_object_is_compound (GDL_DOCK_OBJECT (item)))
- gtk_container_foreach (GTK_CONTAINER (item),
- (GtkCallback) gdl_dock_item_hide_item,
- NULL);
-
- /* detach the item recursively */
- gdl_dock_object_detach (GDL_DOCK_OBJECT (item), TRUE);
-
gtk_widget_hide (GTK_WIDGET (item));
-
- gdl_dock_object_thaw (GDL_DOCK_OBJECT (item));
+ return;
}
/**
@@ -2260,49 +2203,9 @@ gdl_dock_item_show_item (GdlDockItem *item)
g_return_if_fail (item != NULL);
GDL_DOCK_OBJECT_UNSET_FLAGS (item, GDL_DOCK_ICONIFIED);
-
- if (item->priv->ph) {
- gboolean isFloating=FALSE;
- gint width = 0, height = 0, x= 0, y = 0;
- g_object_get (G_OBJECT(item->priv->ph),
- "width", &width,
- "height", &height,
- "floating",&isFloating,
- "floatx", &x,
- "floaty", &y,
- NULL);
- if (isFloating) {
- GdlDockObject *controller =
- gdl_dock_master_get_controller (GDL_DOCK_OBJECT_GET_MASTER (item));
- gdl_dock_add_floating_item (GDL_DOCK (controller),
- item, x, y, width, height);
- } else {
- gtk_container_add (GTK_CONTAINER (item->priv->ph),
- GTK_WIDGET (item));
- }
- g_object_unref (item->priv->ph);
- item->priv->ph = NULL;
-
- } else if (gdl_dock_object_is_bound (GDL_DOCK_OBJECT (item))) {
- GdlDockObject *toplevel;
-
- toplevel = gdl_dock_master_get_controller
- (GDL_DOCK_OBJECT_GET_MASTER (item));
-
- if (item->behavior & GDL_DOCK_ITEM_BEH_NEVER_FLOATING) {
- g_warning("Object %s has no default position and flag GDL_DOCK_ITEM_BEH_NEVER_FLOATING is set.\n",
- GDL_DOCK_OBJECT(item)->name);
- } else if (toplevel) {
- gdl_dock_object_dock (toplevel, GDL_DOCK_OBJECT (item),
- GDL_DOCK_FLOATING, NULL);
- } else
- g_warning("There is no toplevel window. GdlDockItem %s cannot be shown.\n", GDL_DOCK_OBJECT(item)->name);
-
- } else
- g_warning("GdlDockItem %s is not bound. It cannot be shown.\n",
- GDL_DOCK_OBJECT(item)->name);
-
+ GDL_DOCK_OBJECT_SET_FLAGS (item, GDL_DOCK_ATTACHED);
gtk_widget_show (GTK_WIDGET (item));
+ return;
}
/**
diff --git a/gdl/gdl-dock-object.c b/gdl/gdl-dock-object.c
index ee60ddf..f5c5190 100644
--- a/gdl/gdl-dock-object.c
+++ b/gdl/gdl-dock-object.c
@@ -362,10 +362,8 @@ gdl_dock_object_destroy (GtkWidget *dock_object)
object->reduce_pending = FALSE;
gdl_dock_object_thaw (object);
}
- if (GDL_DOCK_OBJECT_ATTACHED (object)) {
- /* detach ourselves */
- gdl_dock_object_detach (object, FALSE);
- }
+ /* detach ourselves */
+ gdl_dock_object_detach (object, FALSE);
/* finally unbind us */
if (object->master)
@@ -375,6 +373,35 @@ gdl_dock_object_destroy (GtkWidget *dock_object)
}
static void
+gdl_dock_object_foreach_is_visible (GdlDockObject *object,
+ gpointer user_data)
+{
+ gboolean *visible = (gboolean *)user_data;
+
+ if (!*visible && gtk_widget_get_visible (GTK_WIDGET (object))) *visible = TRUE;
+}
+
+static void
+gdl_dock_object_update_parent_visibility (GdlDockObject *object)
+{
+ GdlDockObject *parent;
+
+ g_return_if_fail (object != NULL);
+
+ parent = gdl_dock_object_get_parent_object (object);
+ if (parent && GDL_DOCK_OBJECT_AUTOMATIC (parent))
+ {
+ gboolean visible = FALSE;
+
+ gtk_container_foreach (GTK_CONTAINER (parent),
+ (GtkCallback) gdl_dock_object_foreach_is_visible,
+ &visible);
+ gtk_widget_set_visible (GTK_WIDGET (parent), visible);
+ }
+ g_signal_emit_by_name (GDL_DOCK_OBJECT (object)->master, "layout-changed");
+}
+
+static void
gdl_dock_object_foreach_automatic (GdlDockObject *object,
gpointer user_data)
{
@@ -387,23 +414,20 @@ gdl_dock_object_foreach_automatic (GdlDockObject *object,
static void
gdl_dock_object_show (GtkWidget *widget)
{
- if (gdl_dock_object_is_compound (GDL_DOCK_OBJECT (widget))) {
- gtk_container_foreach (GTK_CONTAINER (widget),
- (GtkCallback) gdl_dock_object_foreach_automatic,
- gtk_widget_show);
- }
GTK_WIDGET_CLASS (gdl_dock_object_parent_class)->show (widget);
+
+ /* Update visibility of automatic parents */
+ gdl_dock_object_update_parent_visibility (GDL_DOCK_OBJECT (widget));
}
static void
gdl_dock_object_hide (GtkWidget *widget)
{
- if (gdl_dock_object_is_compound (GDL_DOCK_OBJECT (widget))) {
- gtk_container_foreach (GTK_CONTAINER (widget),
- (GtkCallback) gdl_dock_object_foreach_automatic,
- gtk_widget_hide);
- }
- GTK_WIDGET_CLASS (gdl_dock_object_parent_class)->hide (widget);
+ GTK_WIDGET_CLASS (gdl_dock_object_parent_class)->hide (widget);
+
+ /* Update visibility of automatic parents */
+ gdl_dock_object_update_parent_visibility (GDL_DOCK_OBJECT (widget));
+ GDL_DOCK_OBJECT_UNSET_FLAGS (GDL_DOCK_OBJECT (widget), GDL_DOCK_ATTACHED);
}
static void
@@ -558,7 +582,7 @@ gdl_dock_object_detach (GdlDockObject *object,
if (!GDL_IS_DOCK_OBJECT (object))
return;
- if (!GDL_DOCK_OBJECT_ATTACHED (object))
+ if (!GDL_DOCK_OBJECT_ATTACHED (object) && (gtk_widget_get_parent (GTK_WIDGET (object)) == NULL))
return;
/* freeze the object to avoid reducing while detaching children */
@@ -731,8 +755,7 @@ gdl_dock_object_dock (GdlDockObject *object,
/* detach the requestor before docking */
g_object_ref (requestor);
- if (GDL_DOCK_OBJECT_ATTACHED (requestor))
- gdl_dock_object_detach (requestor, FALSE);
+ gdl_dock_object_detach (requestor, FALSE);
if (position != GDL_DOCK_NONE)
g_signal_emit (object, gdl_dock_object_signals [DOCK], 0,
@@ -740,6 +763,9 @@ gdl_dock_object_dock (GdlDockObject *object,
g_object_unref (requestor);
gdl_dock_object_thaw (object);
+
+ /* Update visibility of automatic parents */
+ gdl_dock_object_update_parent_visibility (GDL_DOCK_OBJECT (requestor));
}
/**
@@ -788,8 +814,7 @@ gdl_dock_object_unbind (GdlDockObject *object)
g_object_ref (object);
/* detach the object first */
- if (GDL_DOCK_OBJECT_ATTACHED (object))
- gdl_dock_object_detach (object, TRUE);
+ gdl_dock_object_detach (object, TRUE);
if (object->master) {
GObject *master = object->master;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]