diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2011-09-04 23:45:25 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2011-10-06 20:16:21 +0800 |
commit | 0e064de971dd8b5e565558cd14efdca8ae4dbcb0 (patch) | |
tree | 12e8b8975e524abeed91c6612834f7499c59cadf | |
parent | 224f26b84d9c12b0dd1d337f51c14b6ebb901007 (diff) | |
download | gsoc2013-evolution-0e064de971dd8b5e565558cd14efdca8ae4dbcb0.tar gsoc2013-evolution-0e064de971dd8b5e565558cd14efdca8ae4dbcb0.tar.gz gsoc2013-evolution-0e064de971dd8b5e565558cd14efdca8ae4dbcb0.tar.bz2 gsoc2013-evolution-0e064de971dd8b5e565558cd14efdca8ae4dbcb0.tar.lz gsoc2013-evolution-0e064de971dd8b5e565558cd14efdca8ae4dbcb0.tar.xz gsoc2013-evolution-0e064de971dd8b5e565558cd14efdca8ae4dbcb0.tar.zst gsoc2013-evolution-0e064de971dd8b5e565558cd14efdca8ae4dbcb0.zip |
EAttachmentPaned: Add "resize-toplevel" property.
Similiar to the new GtkExpander:resize-toplevel property in GTK+ 3.2,
but adapted to the fact that EAttachmentPaned's expander has no direct
child widget, and instead acts on the child widget in the lower pane.
CompEditor now uses this to fix the weird vertical resizing behavior
when its attachment bar is expanded and then collapsed again.
-rw-r--r-- | calendar/gui/dialogs/comp-editor.c | 7 | ||||
-rw-r--r-- | widgets/misc/e-attachment-paned.c | 122 | ||||
-rw-r--r-- | widgets/misc/e-attachment-paned.h | 5 |
3 files changed, 116 insertions, 18 deletions
diff --git a/calendar/gui/dialogs/comp-editor.c b/calendar/gui/dialogs/comp-editor.c index 0375e546e6..4fa0250838 100644 --- a/calendar/gui/dialogs/comp-editor.c +++ b/calendar/gui/dialogs/comp-editor.c @@ -2112,17 +2112,14 @@ comp_editor_init (CompEditor *editor) GTK_STYLE_CLASS_PRIMARY_TOOLBAR); widget = e_attachment_paned_new (); + e_attachment_paned_set_resize_toplevel ( + E_ATTACHMENT_PANED (widget), TRUE); gtk_container_set_border_width (GTK_CONTAINER (widget), 6); gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0); priv->attachment_view = g_object_ref (widget); gtk_widget_show (widget); if (express_mode) { - e_attachment_paned_set_expanded ( - E_ATTACHMENT_PANED (widget), TRUE); - e_attachment_paned_set_expanded ( - E_ATTACHMENT_PANED (widget), FALSE); - widget = e_attachment_paned_get_view_combo ( E_ATTACHMENT_PANED (widget)); gtk_widget_hide (widget); diff --git a/widgets/misc/e-attachment-paned.c b/widgets/misc/e-attachment-paned.c index b842aecf8d..2903c84227 100644 --- a/widgets/misc/e-attachment-paned.c +++ b/widgets/misc/e-attachment-paned.c @@ -53,7 +53,8 @@ struct _EAttachmentPanedPrivate { GtkWidget *content_area; gint active_view; - guint expanded : 1; + gboolean expanded; + gboolean resize_toplevel; }; enum { @@ -61,7 +62,8 @@ enum { PROP_ACTIVE_VIEW, PROP_DRAGGING, PROP_EDITABLE, - PROP_EXPANDED + PROP_EXPANDED, + PROP_RESIZE_TOPLEVEL }; /* Forward Declarations */ @@ -87,6 +89,9 @@ attachment_paned_notify_cb (EAttachmentPaned *paned, GParamSpec *pspec, GtkExpander *expander) { + GtkAllocation toplevel_allocation; + GtkWidget *toplevel; + GtkWidget *child; GtkLabel *label; const gchar *text; @@ -99,6 +104,47 @@ attachment_paned_notify_cb (EAttachmentPaned *paned, text = _("Show Attachment _Bar"); gtk_label_set_text_with_mnemonic (label, text); + + /* Resize the top-level window if required conditions are met. + * This is based on gtk_expander_resize_toplevel(), but adapted + * to the fact our GtkExpander has no direct child widget. */ + + if (!e_attachment_paned_get_resize_toplevel (paned)) + return; + + if (!gtk_widget_get_realized (GTK_WIDGET (paned))) + return; + + child = gtk_paned_get_child2 (GTK_PANED (paned)); + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (paned)); + + if (toplevel == NULL) + return; + + if (!gtk_widget_get_realized (GTK_WIDGET (toplevel))) + return; + + gtk_widget_get_allocation (toplevel, &toplevel_allocation); + + if (gtk_expander_get_expanded (expander)) { + GtkRequisition child_requisition; + + gtk_widget_get_preferred_size ( + child, &child_requisition, NULL); + + toplevel_allocation.height += child_requisition.height; + } else { + GtkAllocation child_allocation; + + gtk_widget_get_allocation (child, &child_allocation); + + toplevel_allocation.height -= child_allocation.height; + } + + gtk_window_resize ( + GTK_WINDOW (toplevel), + toplevel_allocation.width, + toplevel_allocation.height); } static void @@ -177,6 +223,12 @@ attachment_paned_set_property (GObject *object, E_ATTACHMENT_PANED (object), g_value_get_boolean (value)); return; + + case PROP_RESIZE_TOPLEVEL: + e_attachment_paned_set_resize_toplevel ( + E_ATTACHMENT_PANED (object), + g_value_get_boolean (value)); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -191,25 +243,36 @@ attachment_paned_get_property (GObject *object, switch (property_id) { case PROP_ACTIVE_VIEW: g_value_set_int ( - value, e_attachment_paned_get_active_view ( + value, + e_attachment_paned_get_active_view ( E_ATTACHMENT_PANED (object))); return; case PROP_DRAGGING: g_value_set_boolean ( - value, e_attachment_view_get_dragging ( + value, + e_attachment_view_get_dragging ( E_ATTACHMENT_VIEW (object))); return; case PROP_EDITABLE: g_value_set_boolean ( - value, e_attachment_view_get_editable ( + value, + e_attachment_view_get_editable ( E_ATTACHMENT_VIEW (object))); return; case PROP_EXPANDED: g_value_set_boolean ( - value, e_attachment_paned_get_expanded ( + value, + e_attachment_paned_get_expanded ( + E_ATTACHMENT_PANED (object))); + return; + + case PROP_RESIZE_TOPLEVEL: + g_value_set_boolean ( + value, + e_attachment_paned_get_resize_toplevel ( E_ATTACHMENT_PANED (object))); return; } @@ -494,7 +557,14 @@ e_attachment_paned_class_init (EAttachmentPanedClass *class) NUM_VIEWS, 0, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); + + g_object_class_override_property ( + object_class, PROP_DRAGGING, "dragging"); + + g_object_class_override_property ( + object_class, PROP_EDITABLE, "editable"); g_object_class_install_property ( object_class, @@ -505,13 +575,20 @@ e_attachment_paned_class_init (EAttachmentPanedClass *class) NULL, FALSE, G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); - - g_object_class_override_property ( - object_class, PROP_DRAGGING, "dragging"); + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); - g_object_class_override_property ( - object_class, PROP_EDITABLE, "editable"); + g_object_class_install_property ( + object_class, + PROP_RESIZE_TOPLEVEL, + g_param_spec_boolean ( + "resize-toplevel", + "Resize-Toplevel", + NULL, + FALSE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS)); } static void @@ -768,6 +845,25 @@ e_attachment_paned_set_expanded (EAttachmentPaned *paned, g_object_notify (G_OBJECT (paned), "expanded"); } +gboolean +e_attachment_paned_get_resize_toplevel (EAttachmentPaned *paned) +{ + g_return_val_if_fail (E_IS_ATTACHMENT_PANED (paned), FALSE); + + return paned->priv->resize_toplevel; +} + +void +e_attachment_paned_set_resize_toplevel (EAttachmentPaned *paned, + gboolean resize_toplevel) +{ + g_return_if_fail (E_IS_ATTACHMENT_PANED (paned)); + + paned->priv->resize_toplevel = resize_toplevel; + + g_object_notify (G_OBJECT (paned), "resize-toplevel"); +} + void e_attachment_paned_drag_data_received (EAttachmentPaned *paned, GdkDragContext *context, diff --git a/widgets/misc/e-attachment-paned.h b/widgets/misc/e-attachment-paned.h index a9022a7bc6..7daffd5508 100644 --- a/widgets/misc/e-attachment-paned.h +++ b/widgets/misc/e-attachment-paned.h @@ -70,6 +70,11 @@ void e_attachment_paned_set_active_view gboolean e_attachment_paned_get_expanded (EAttachmentPaned *paned); void e_attachment_paned_set_expanded (EAttachmentPaned *paned, gboolean expanded); +gboolean e_attachment_paned_get_resize_toplevel + (EAttachmentPaned *paned); +void e_attachment_paned_set_resize_toplevel + (EAttachmentPaned *paned, + gboolean resize_toplevel); void e_attachment_paned_drag_data_received (EAttachmentPaned *paned, GdkDragContext *context, |