From f93b95e549591cc8302d894e44641f42751b7f67 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 30 May 2009 17:00:12 +0100 Subject: [PATCH] Ensure a minimum size of tabs in the chat window When there are a lot of tabs in the chat window it's not useful to resize them such that only the ellipsis is actually visible. To prevent this make the notebook scrollable and ensure the tabs are width enough to contain approximately 12 characters. --- src/empathy-chat-window.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/empathy-chat-window.c b/src/empathy-chat-window.c index 1912b1b9..248a408a 100644 --- a/src/empathy-chat-window.c +++ b/src/empathy-chat-window.c @@ -161,15 +161,32 @@ chat_window_close_clicked_cb (GtkAction *action, } static void -chat_window_close_button_style_set_cb (GtkWidget *button, +chat_tab_style_set_cb (GtkWidget *hbox, GtkStyle *previous_style, gpointer user_data) { - gint h, w; + GtkWidget *button; + int char_width, h, w; + PangoContext *context; + PangoFontMetrics *metrics; + + button = g_object_get_data (G_OBJECT (user_data), + "chat-window-tab-close-button"); + context = gtk_widget_get_pango_context (hbox); + + metrics = pango_context_get_metrics (context, hbox->style->font_desc, + pango_context_get_language (context)); + char_width = pango_font_metrics_get_approximate_char_width (metrics); + pango_font_metrics_unref (metrics); gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button), GTK_ICON_SIZE_MENU, &w, &h); + /* Request at least about 12 chars width plus at least space for the status + * image and the close button */ + gtk_widget_set_size_request (hbox, + 12 * PANGO_PIXELS (char_width) + 2 * w, -1); + gtk_widget_set_size_request (button, w, h); } @@ -243,12 +260,10 @@ chat_window_create_label (EmpathyChatWindow *window, gtk_box_pack_start (GTK_BOX (hbox), event_box, TRUE, TRUE, 0); gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0); - /* React to theme changes and also used to setup the initial size - * correctly. - */ - g_signal_connect (close_button, + /* React to theme changes and also setup the size correctly. */ + g_signal_connect (hbox, "style-set", - G_CALLBACK (chat_window_close_button_style_set_cb), + G_CALLBACK (chat_tab_style_set_cb), chat); g_signal_connect (close_button, @@ -1353,7 +1368,8 @@ empathy_chat_window_init (EmpathyChatWindow *window) priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL); priv->notebook = gtk_notebook_new (); - gtk_notebook_set_group (GTK_NOTEBOOK (priv->notebook), "EmpathyChatWindow"); + gtk_notebook_set_group (GTK_NOTEBOOK (priv->notebook), "EmpathyChatWindow"); + gtk_notebook_set_scrollable (GTK_NOTEBOOK (priv->notebook), TRUE); gtk_box_pack_start (GTK_BOX (chat_vbox), priv->notebook, TRUE, TRUE, 0); gtk_widget_show (priv->notebook); -- 2.39.2