[gtk+/widget-expand-3] Support GtkWidget expand properties in GtkNotebook



commit f0e7c9fc6481ba86122321ae0637e3a47486f780
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Oct 11 15:23:03 2010 -0400

    Support GtkWidget expand properties in GtkNotebook
    
    We expand a tab if either tab-expand is set, or the generic widget
    expand property in the correct direction is set. And we do not
    propagate expand flags from tab labels to the notebook, only
    the expand flags from the pages.

 gtk/gtknotebook.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 7ad2704..8128ebf 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -536,6 +536,39 @@ gtk_object_handled_accumulator (GSignalInvocationHint *ihint,
 }
 
 static void
+gtk_notebook_compute_expand (GtkContainer *container,
+                             gboolean     *hexpand_p,
+                             gboolean     *vexpand_p)
+{
+  GtkNotebook *notebook = GTK_NOTEBOOK (container);
+  GtkNotebookPrivate *priv = notebook->priv;
+  gboolean hexpand;
+  gboolean vexpand;
+  GList *list;
+  GtkNotebookPage *page;
+
+  hexpand = FALSE;
+  vexpand = FALSE;
+
+  for (list = priv->children; list; list = list->next)
+    {
+      page = list->data;
+
+      hexpand = hexpand ||
+        gtk_widget_compute_expand (page->child, GTK_ORIENTATION_HORIZONTAL);
+
+      vexpand = vexpand ||
+        gtk_widget_compute_expand (page->child, GTK_ORIENTATION_VERTICAL);
+
+      if (hexpand & vexpand)
+        break;
+    }
+
+  *hexpand_p = hexpand;
+  *vexpand_p = vexpand;
+}
+
+static void
 gtk_notebook_class_init (GtkNotebookClass *class)
 {
   GObjectClass   *gobject_class = G_OBJECT_CLASS (class);
@@ -573,6 +606,7 @@ gtk_notebook_class_init (GtkNotebookClass *class)
   widget_class->drag_drop = gtk_notebook_drag_drop;
   widget_class->drag_data_get = gtk_notebook_drag_data_get;
   widget_class->drag_data_received = gtk_notebook_drag_data_received;
+  widget_class->compute_expand = gtk_notebook_compute_expand;
 
   container_class->add = gtk_notebook_add;
   container_class->remove = gtk_notebook_remove;
@@ -5393,9 +5427,14 @@ gtk_notebook_calculate_shown_tabs (GtkNotebook *notebook,
     }
   else /* !show_arrows */
     {
+      GtkOrientation tab_expand_orientation;
       gint c = 0;
       *n = 0;
 
+      if (priv->tab_pos == GTK_POS_TOP || priv->tab_pos == GTK_POS_BOTTOM)
+        tab_expand_orientation = GTK_ORIENTATION_HORIZONTAL;
+      else
+        tab_expand_orientation = GTK_ORIENTATION_VERTICAL;
       *remaining_space = max - min - tab_overlap - tab_space;
       children = priv->children;
       priv->first_tab = gtk_notebook_search_page (notebook, NULL,
@@ -5411,7 +5450,8 @@ gtk_notebook_calculate_shown_tabs (GtkNotebook *notebook,
 
 	  c++;
 
-	  if (page->expand)
+	  if (page->expand ||
+              (gtk_widget_compute_expand (page->tab_label, tab_expand_orientation)))
 	    (*n)++;
 	}
 
@@ -5471,6 +5511,7 @@ gtk_notebook_calculate_tabs_allocation (GtkNotebook  *notebook,
   guint border_width;
   gboolean gap_left, packing_changed;
   GtkAllocation child_allocation = { 0, };
+  GtkOrientation tab_expand_orientation;
 
   widget = GTK_WIDGET (notebook);
   container = GTK_CONTAINER (notebook);
@@ -5520,6 +5561,11 @@ gtk_notebook_calculate_tabs_allocation (GtkNotebook  *notebook,
   bottom_y = top_y + priv->cur_page->allocation.height;
   gap_left = packing_changed = FALSE;
 
+  if (priv->tab_pos == GTK_POS_TOP || priv->tab_pos == GTK_POS_BOTTOM)
+    tab_expand_orientation = GTK_ORIENTATION_HORIZONTAL;
+  else
+    tab_expand_orientation = GTK_ORIENTATION_VERTICAL;
+
   while (*children && *children != last_child)
     {
       page = (*children)->data;
@@ -5546,7 +5592,7 @@ gtk_notebook_calculate_tabs_allocation (GtkNotebook  *notebook,
 	continue;
 
       tab_extra_space = 0;
-      if (*expanded_tabs && (showarrow || page->expand || priv->homogeneous))
+      if (*expanded_tabs && (showarrow || page->expand || gtk_widget_compute_expand (page->tab_label, tab_expand_orientation) || priv->homogeneous))
 	{
 	  tab_extra_space = *remaining_space / *expanded_tabs;
 	  *remaining_space -= tab_extra_space;



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