Fix some issues with action widgets

We need to hide/show them depending on show_tabs, and we should
not grow the notebooks requisition unless we have to. Reported
in bug 601412.
This commit is contained in:
Matthias Clasen 2010-01-18 01:20:50 -05:00 committed by Tristan Van Berkom
parent c31f02b455
commit 2091807b24

View File

@ -1746,16 +1746,14 @@ gtk_notebook_map (GtkWidget *widget)
!GTK_WIDGET_MAPPED (notebook->cur_page->child)) !GTK_WIDGET_MAPPED (notebook->cur_page->child))
gtk_widget_map (notebook->cur_page->child); gtk_widget_map (notebook->cur_page->child);
if (notebook->show_tabs) for (i = 0; i < N_ACTION_WIDGETS; i++)
{
for (i = 0; i < 2; i++)
{ {
if (priv->action_widget[i] && if (priv->action_widget[i] &&
GTK_WIDGET_VISIBLE (priv->action_widget[i]) && GTK_WIDGET_VISIBLE (priv->action_widget[i]) &&
GTK_WIDGET_CHILD_VISIBLE (priv->action_widget[i]) &&
!GTK_WIDGET_MAPPED (priv->action_widget[i])) !GTK_WIDGET_MAPPED (priv->action_widget[i]))
gtk_widget_map (priv->action_widget[i]); gtk_widget_map (priv->action_widget[i]);
} }
}
if (notebook->scrollable) if (notebook->scrollable)
gtk_notebook_pages_allocate (notebook); gtk_notebook_pages_allocate (notebook);
@ -1922,6 +1920,8 @@ gtk_notebook_size_request (GtkWidget *widget,
gint tab_max = 0; gint tab_max = 0;
gint padding; gint padding;
gint i; gint i;
gint action_width = 0;
gint action_height = 0;
for (children = notebook->children; children; for (children = notebook->children; children;
children = children->next) children = children->next)
@ -2017,16 +2017,16 @@ gtk_notebook_size_request (GtkWidget *widget,
widget->requisition.width < tab_width) widget->requisition.width < tab_width)
tab_width = tab_max + 2 * (scroll_arrow_hlength + arrow_spacing); tab_width = tab_max + 2 * (scroll_arrow_hlength + arrow_spacing);
action_width += action_widget_requisition[ACTION_WIDGET_START].width;
action_width += action_widget_requisition[ACTION_WIDGET_END].width;
if (notebook->homogeneous && !notebook->scrollable) if (notebook->homogeneous && !notebook->scrollable)
widget->requisition.width = MAX (widget->requisition.width, widget->requisition.width = MAX (widget->requisition.width,
vis_pages * tab_max + vis_pages * tab_max +
tab_overlap); tab_overlap + action_width);
else else
widget->requisition.width = MAX (widget->requisition.width, widget->requisition.width = MAX (widget->requisition.width,
tab_width + tab_overlap); tab_width + tab_overlap + action_width);
widget->requisition.width += action_widget_requisition[ACTION_WIDGET_START].width;
widget->requisition.width += action_widget_requisition[ACTION_WIDGET_END].width;
widget->requisition.height += tab_height; widget->requisition.height += tab_height;
break; break;
case GTK_POS_LEFT: case GTK_POS_LEFT:
@ -2067,15 +2067,17 @@ gtk_notebook_size_request (GtkWidget *widget,
if (notebook->scrollable && vis_pages > 1 && if (notebook->scrollable && vis_pages > 1 &&
widget->requisition.height < tab_height) widget->requisition.height < tab_height)
tab_height = tab_max + (2 * scroll_arrow_vlength + arrow_spacing); tab_height = tab_max + (2 * scroll_arrow_vlength + arrow_spacing);
action_height += action_widget_requisition[ACTION_WIDGET_START].height;
action_height += action_widget_requisition[ACTION_WIDGET_END].height;
if (notebook->homogeneous && !notebook->scrollable) if (notebook->homogeneous && !notebook->scrollable)
widget->requisition.height = widget->requisition.height =
MAX (widget->requisition.height, MAX (widget->requisition.height,
vis_pages * tab_max + tab_overlap); vis_pages * tab_max + tab_overlap + action_height);
else else
widget->requisition.height = widget->requisition.height =
MAX (widget->requisition.height, MAX (widget->requisition.height,
tab_height + tab_overlap); tab_height + tab_overlap + action_height);
if (!notebook->homogeneous || notebook->scrollable) if (!notebook->homogeneous || notebook->scrollable)
vis_pages = 1; vis_pages = 1;
@ -2083,8 +2085,6 @@ gtk_notebook_size_request (GtkWidget *widget,
vis_pages * tab_max + vis_pages * tab_max +
tab_overlap); tab_overlap);
widget->requisition.height += action_widget_requisition[ACTION_WIDGET_START].height;
widget->requisition.height += action_widget_requisition[ACTION_WIDGET_END].height;
widget->requisition.width += tab_width; widget->requisition.width += tab_width;
break; break;
} }
@ -6881,11 +6881,15 @@ void
gtk_notebook_set_show_tabs (GtkNotebook *notebook, gtk_notebook_set_show_tabs (GtkNotebook *notebook,
gboolean show_tabs) gboolean show_tabs)
{ {
GtkNotebookPrivate *priv;
GtkNotebookPage *page; GtkNotebookPage *page;
GList *children; GList *children;
gint i;
g_return_if_fail (GTK_IS_NOTEBOOK (notebook)); g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
priv = GTK_NOTEBOOK_GET_PRIVATE (notebook);
show_tabs = show_tabs != FALSE; show_tabs = show_tabs != FALSE;
if (notebook->show_tabs == show_tabs) if (notebook->show_tabs == show_tabs)
@ -6916,6 +6920,13 @@ gtk_notebook_set_show_tabs (GtkNotebook *notebook,
GTK_WIDGET_SET_FLAGS (notebook, GTK_CAN_FOCUS); GTK_WIDGET_SET_FLAGS (notebook, GTK_CAN_FOCUS);
gtk_notebook_update_labels (notebook); gtk_notebook_update_labels (notebook);
} }
for (i = 0; i < N_ACTION_WIDGETS; i++)
{
if (priv->action_widget[i])
gtk_widget_set_child_visible (priv->action_widget[i], show_tabs);
}
gtk_widget_queue_resize (GTK_WIDGET (notebook)); gtk_widget_queue_resize (GTK_WIDGET (notebook));
g_object_notify (G_OBJECT (notebook), "show-tabs"); g_object_notify (G_OBJECT (notebook), "show-tabs");
@ -7976,10 +7987,8 @@ gtk_notebook_set_action_widget (GtkNotebook *notebook,
if (widget) if (widget)
{ {
gtk_widget_set_child_visible (widget, notebook->show_tabs);
gtk_widget_set_parent (widget, GTK_WIDGET (notebook)); gtk_widget_set_parent (widget, GTK_WIDGET (notebook));
if (GTK_WIDGET_REALIZED (GTK_WIDGET (notebook)))
gtk_widget_realize (widget);
} }
gtk_widget_queue_resize (GTK_WIDGET (notebook)); gtk_widget_queue_resize (GTK_WIDGET (notebook));