Grow and shrink tabs dynamically to available space

Fixes: https://bugs.launchpad.net/midori/+bug/735993
This commit is contained in:
Tomasz Szatkowski 2011-03-23 20:41:40 +01:00 committed by Christian Dywan
parent 6e2d9fdcc2
commit a9a5b38c29
2 changed files with 43 additions and 7 deletions

View file

@ -1462,6 +1462,31 @@ midori_browser_tab_destroy_cb (GtkWidget* widget,
return FALSE;
}
static void
_midori_browser_update_notebook (MidoriBrowser* browser)
{
guint i;
gint new_size = 0;
gint n = gtk_notebook_get_n_pages (GTK_NOTEBOOK(browser->notebook));
const gint max_size = 150;
const gint min_size = 32;
GtkAllocation notebook_size;
gtk_widget_get_allocation (browser->notebook, &notebook_size);
if (n > 0) new_size = notebook_size.width / n - 7;
if (new_size < min_size) new_size = min_size;
if (new_size > max_size) new_size = max_size;
for (i = 0; i < n; i++)
{
GtkWidget* view;
GtkWidget* label;
view = gtk_notebook_get_nth_page (GTK_NOTEBOOK(browser->notebook), i);
label = gtk_notebook_get_tab_label (GTK_NOTEBOOK(browser->notebook), view);
gtk_widget_set_size_request (label, new_size, -1);
}
}
static void
_midori_browser_add_tab (MidoriBrowser* browser,
GtkWidget* view)
@ -1540,6 +1565,7 @@ _midori_browser_add_tab (MidoriBrowser* browser,
G_CALLBACK (midori_browser_tab_destroy_cb), browser);
_midori_browser_update_actions (browser);
_midori_browser_update_notebook (browser);
}
static void
@ -1547,6 +1573,7 @@ _midori_browser_remove_tab (MidoriBrowser* browser,
GtkWidget* view)
{
gtk_widget_destroy (view);
_midori_browser_update_notebook (browser);
}
/**
@ -5199,6 +5226,14 @@ midori_browser_size_allocate_cb (MidoriBrowser* browser,
}
}
static void
gtk_notebook_size_allocated_cb (GtkWidget* widget,
GdkRectangle* allocation,
MidoriBrowser* browser)
{
_midori_browser_update_notebook (browser);
}
static void
midori_browser_destroy_cb (MidoriBrowser* browser)
{
@ -5215,6 +5250,9 @@ midori_browser_destroy_cb (MidoriBrowser* browser)
g_signal_handlers_disconnect_by_func (browser->notebook,
midori_browser_notebook_reorder_tab_cb,
NULL);
g_signal_handlers_disconnect_by_func (browser->notebook,
gtk_notebook_size_allocated_cb,
NULL);
gtk_container_foreach (GTK_CONTAINER (browser->notebook),
(GtkCallback) gtk_widget_destroy, NULL);
}
@ -5934,6 +5972,9 @@ midori_browser_init (MidoriBrowser* browser)
g_signal_connect (browser->notebook, "page-reordered",
G_CALLBACK (midori_browser_notebook_page_reordered_cb),
browser);
g_signal_connect (browser->notebook, "size-allocate",
G_CALLBACK (gtk_notebook_size_allocated_cb),
browser);
g_signal_connect_after (browser->notebook, "button-press-event",
G_CALLBACK (midori_browser_notebook_button_press_event_after_cb),
browser);

View file

@ -4591,18 +4591,13 @@ midori_view_update_tab_title (GtkWidget* label,
gint size,
gdouble angle)
{
gint width;
sokoke_widget_get_text_size (label, "M", &width, NULL);
if (angle == 0.0 || angle == 360.0)
{
gtk_widget_set_size_request (label, width * size, -1);
if (gtk_label_get_ellipsize (GTK_LABEL (label)) != PANGO_ELLIPSIZE_START)
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
}
else
{
gtk_widget_set_size_request (label, -1, width * size);
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_NONE);
}
gtk_label_set_angle (GTK_LABEL (label), angle);
@ -4767,13 +4762,13 @@ midori_view_get_proxy_tab_label (MidoriView* view)
if (katze_object_get_boolean (view->settings, "close-buttons-left"))
{
gtk_box_pack_end (GTK_BOX (hbox), view->tab_icon, FALSE, FALSE, 0);
gtk_box_pack_end (GTK_BOX (hbox), view->tab_title, FALSE, TRUE, 0);
gtk_box_pack_end (GTK_BOX (hbox), view->tab_title, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), align, FALSE, FALSE, 0);
}
else
{
gtk_box_pack_start (GTK_BOX (hbox), view->tab_icon, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), view->tab_title, FALSE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), view->tab_title, TRUE, TRUE, 0);
gtk_box_pack_end (GTK_BOX (hbox), align, FALSE, FALSE, 0);
}
gtk_widget_show_all (GTK_WIDGET (event_box));