notebook: Rewrite size request function for wfh

This commit is contained in:
Benjamin Otte 2011-06-01 23:31:04 +02:00
parent d7519e6ca2
commit 4d78e9c8af

View File

@ -2159,21 +2159,43 @@ gtk_notebook_get_preferred_tabs_size (GtkNotebook *notebook,
} }
} }
static void
get_preferred_size_for_size (GtkWidget *widget,
GtkOrientation orientation,
gint size,
gint *minimum,
gint *natural)
{
if (orientation == GTK_ORIENTATION_HORIZONTAL)
if (size < 0)
gtk_widget_get_preferred_width (widget, minimum, natural);
else
gtk_widget_get_preferred_width_for_height (widget, size, minimum, natural);
else
if (size < 0)
gtk_widget_get_preferred_height (widget, minimum, natural);
else
gtk_widget_get_preferred_height_for_width (widget, size, minimum, natural);
}
static void static void
gtk_notebook_size_request (GtkWidget *widget, gtk_notebook_size_request (GtkWidget *widget,
GtkRequisition *requisition) GtkOrientation orientation,
gint size,
gint *minimum,
gint *natural)
{ {
GtkNotebook *notebook = GTK_NOTEBOOK (widget); GtkNotebook *notebook = GTK_NOTEBOOK (widget);
GtkNotebookPrivate *priv = notebook->priv; GtkNotebookPrivate *priv = notebook->priv;
GtkNotebookPage *page; GtkNotebookPage *page;
GList *children; GList *children;
GtkRequisition child_requisition; gint child_minimum, child_natural;
gboolean switch_page = FALSE; gboolean switch_page = FALSE;
gint vis_pages; gint vis_pages;
guint border_width; guint border_width;
requisition->width = 0; *minimum = 0;
requisition->height = 0; *natural = 0;
for (children = priv->children, vis_pages = 0; children; for (children = priv->children, vis_pages = 0; children;
children = children->next) children = children->next)
@ -2184,13 +2206,14 @@ gtk_notebook_size_request (GtkWidget *widget,
if (gtk_widget_get_visible (page->child)) if (gtk_widget_get_visible (page->child))
{ {
vis_pages++; vis_pages++;
gtk_widget_get_preferred_size (page->child, get_preferred_size_for_size (page->child,
&child_requisition, NULL); orientation,
size,
&child_minimum,
&child_natural);
requisition->width = MAX (requisition->width, *minimum = MAX (*minimum, child_minimum);
child_requisition.width); *natural = MAX (*natural, child_natural);
requisition->height = MAX (requisition->height,
child_requisition.height);
if (priv->menu && page->menu_label) if (priv->menu && page->menu_label)
{ {
@ -2221,16 +2244,48 @@ gtk_notebook_size_request (GtkWidget *widget,
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
gtk_style_context_get_padding (context, 0, &notebook_padding); gtk_style_context_get_padding (context, 0, &notebook_padding);
requisition->width += notebook_padding.left + notebook_padding.right; if (orientation == GTK_ORIENTATION_HORIZONTAL)
requisition->height += notebook_padding.top + notebook_padding.bottom; {
*minimum += notebook_padding.left + notebook_padding.right;
*natural += notebook_padding.left + notebook_padding.right;
}
else
{
*minimum += notebook_padding.top + notebook_padding.bottom;
*natural += notebook_padding.top + notebook_padding.bottom;
}
if (priv->show_tabs) if (priv->show_tabs)
{ {
GtkRequisition tabs_requisition; GtkRequisition tabs_requisition;
gtk_notebook_get_preferred_tabs_size (notebook, &tabs_requisition); gtk_notebook_get_preferred_tabs_size (notebook, &tabs_requisition);
requisition->width += tabs_requisition.width; if (orientation == GTK_ORIENTATION_HORIZONTAL)
requisition->height += tabs_requisition.height; {
if (priv->tab_pos == GTK_POS_TOP || priv->tab_pos == GTK_POS_BOTTOM)
{
*minimum = MAX (*minimum, tabs_requisition.width);
*natural = MAX (*minimum, *natural);
}
else
{
*minimum += tabs_requisition.width;
*natural += tabs_requisition.width;
}
}
else
{
if (priv->tab_pos == GTK_POS_LEFT || priv->tab_pos == GTK_POS_RIGHT)
{
*minimum = MAX (*minimum, tabs_requisition.height);
*natural = MAX (*minimum, *natural);
}
else
{
*minimum += tabs_requisition.height;
*natural += tabs_requisition.height;
}
}
} }
else else
{ {
@ -2247,8 +2302,8 @@ gtk_notebook_size_request (GtkWidget *widget,
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget)); border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
requisition->width += border_width * 2; *minimum += border_width * 2;
requisition->height += border_width * 2; *natural += border_width * 2;
if (switch_page) if (switch_page)
{ {
@ -2267,8 +2322,7 @@ gtk_notebook_size_request (GtkWidget *widget,
} }
else if (gtk_widget_get_visible (widget)) else if (gtk_widget_get_visible (widget))
{ {
requisition->width = border_width * 2; *minimum = border_width * 2;
requisition->height = border_width * 2;
} }
} }
if (vis_pages && !priv->cur_page) if (vis_pages && !priv->cur_page)
@ -2288,11 +2342,7 @@ gtk_notebook_get_preferred_width (GtkWidget *widget,
gint *minimum, gint *minimum,
gint *natural) gint *natural)
{ {
GtkRequisition requisition; gtk_notebook_size_request (widget, GTK_ORIENTATION_HORIZONTAL, -1, minimum, natural);
gtk_notebook_size_request (widget, &requisition);
*minimum = *natural = requisition.width;
} }
static void static void
@ -2300,11 +2350,7 @@ gtk_notebook_get_preferred_height (GtkWidget *widget,
gint *minimum, gint *minimum,
gint *natural) gint *natural)
{ {
GtkRequisition requisition; gtk_notebook_size_request (widget, GTK_ORIENTATION_VERTICAL, -1, minimum, natural);
gtk_notebook_size_request (widget, &requisition);
*minimum = *natural = requisition.height;
} }
static void static void