[evolution/express] Don't hardcode a width, but compute a suitable one
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/express] Don't hardcode a width, but compute a suitable one
- Date: Thu, 18 Mar 2010 19:38:56 +0000 (UTC)
commit a92b760a71fa95d9f3a5c4c8c106e141f92b2043
Author: Federico Mena Quintero <federico novell com>
Date: Thu Mar 18 12:47:32 2010 -0600
Don't hardcode a width, but compute a suitable one
We do this by measuring a template string, which contains a sample name for an email account.
This is what normally gets displayed in the folder tree, so such a sample string
should give a reasonable width.
Signed-off-by: Federico Mena Quintero <federico novell com>
modules/mail/e-mail-shell-sidebar.c | 46 +++++++++++++++++++++++++++++++++++
modules/mail/e-mail-shell-view.c | 17 +------------
2 files changed, 47 insertions(+), 16 deletions(-)
---
diff --git a/modules/mail/e-mail-shell-sidebar.c b/modules/mail/e-mail-shell-sidebar.c
index 70b59ad..30dd9d5 100644
--- a/modules/mail/e-mail-shell-sidebar.c
+++ b/modules/mail/e-mail-shell-sidebar.c
@@ -178,6 +178,47 @@ mail_shell_sidebar_constructed (GObject *object)
shell_sidebar);
}
+static void
+mail_shell_sidebar_size_request (GtkWidget *widget, GtkRequisition *requisition)
+{
+ /* We override the normal size-request handler so that we can
+ * spit out a treeview with a suitable width. We measure the length
+ * of a typical string and use that as the requisition's width.
+ *
+ * EMFolderTreeClass, our parent class, is based on GtkTreeView, which
+ * doesn't really have a good way of figuring out a minimum width for
+ * the tree. This is really GTK+'s fault at large, as it only has
+ * "minimum size / allocated size", instead of "minimum size / preferred
+ * size / allocated size". Hopefully the extended-layout branch of GTK+
+ * will get merged soon and then we can remove this crap.
+ */
+
+ PangoLayout *layout;
+ PangoRectangle ink_rect;
+ GtkStyle *style;
+ int border;
+
+ GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
+
+ /* This string is a mockup only; it doesn't need to be translated */
+ layout = gtk_widget_create_pango_layout (widget, "typical account mailservice com");
+ pango_layout_get_pixel_extents (layout, &ink_rect, NULL);
+ g_object_unref (layout);
+
+ style = gtk_widget_get_style (widget);
+
+ border = 2 * style->xthickness + 4; /* Thickness of frame shadow plus some slack for padding */
+ requisition->width = MAX (requisition->width, ink_rect.width + border);
+}
+
+static void
+mail_shell_sidebar_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+{
+ GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
+ g_print ("EMailShellSidebar allocation: %dx%d\n", allocation->width, allocation->height);
+}
+
+
static guint32
mail_shell_sidebar_check_state (EShellSidebar *shell_sidebar)
{
@@ -194,6 +235,7 @@ static void
mail_shell_sidebar_class_init (EMailShellSidebarClass *class)
{
GObjectClass *object_class;
+ GtkWidgetClass *widget_class;
EShellSidebarClass *shell_sidebar_class;
parent_class = g_type_class_peek_parent (class);
@@ -204,6 +246,10 @@ mail_shell_sidebar_class_init (EMailShellSidebarClass *class)
object_class->dispose = mail_shell_sidebar_dispose;
object_class->constructed = mail_shell_sidebar_constructed;
+ widget_class = GTK_WIDGET_CLASS (class);
+ widget_class->size_request = mail_shell_sidebar_size_request;
+ widget_class->size_allocate = mail_shell_sidebar_size_allocate;
+
shell_sidebar_class = E_SHELL_SIDEBAR_CLASS (class);
shell_sidebar_class->check_state = mail_shell_sidebar_check_state;
diff --git a/modules/mail/e-mail-shell-view.c b/modules/mail/e-mail-shell-view.c
index aae451c..c342985 100644
--- a/modules/mail/e-mail-shell-view.c
+++ b/modules/mail/e-mail-shell-view.c
@@ -933,21 +933,6 @@ mail_shell_view_update_actions (EShellView *shell_view)
e_mail_shell_view_update_popup_labels (mail_shell_view);
}
-/* Vmethod implementation for EShellView::new_shell_sidebar. We create a mail
- * folder tree for the mailer.
- */
-static GtkWidget *
-new_shell_sidebar (EShellView *shell_view)
-{
- GtkWidget *sidebar;
- PangoLayout *layout;
-
- sidebar = e_mail_shell_sidebar_new (shell_view);
- gtk_widget_set_size_request (sidebar, 300, -1);
-
- return sidebar;
-}
-
static void
mail_shell_view_class_init (EMailShellViewClass *class,
GTypeModule *type_module)
@@ -972,7 +957,7 @@ mail_shell_view_class_init (EMailShellViewClass *class,
shell_view_class->search_options = "/mail-search-options";
shell_view_class->search_rules = "searchtypes.xml";
shell_view_class->new_shell_content = e_mail_shell_content_new;
- shell_view_class->new_shell_sidebar = new_shell_sidebar;
+ shell_view_class->new_shell_sidebar = e_mail_shell_sidebar_new;
shell_view_class->toggled = mail_shell_view_toggled;
shell_view_class->execute_search = mail_shell_view_execute_search;
shell_view_class->update_actions = mail_shell_view_update_actions;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]