[evolution/wip/webkit2] Try to not scroll the EAttachmentBar content with an upper limit



commit 0dff97d4a317f6fcdc86f7115afcf8d2caba175e
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jul 11 12:31:15 2016 +0200

    Try to not scroll the EAttachmentBar content with an upper limit
    
    Added style property to define the upper limit, with default of 150px,
    which can be either -1, to never scroll, or anything from 50px up.
    
    Just write into ~/.config/gtk-3.0/gtk.css:
    EAttachmentBar {
                -EAttachmentBar-max-content-height: 80px;
    }

 e-util/e-attachment-bar.c |   85 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 74 insertions(+), 11 deletions(-)
---
diff --git a/e-util/e-attachment-bar.c b/e-util/e-attachment-bar.c
index b34b469..e5da99f 100644
--- a/e-util/e-attachment-bar.c
+++ b/e-util/e-attachment-bar.c
@@ -50,6 +50,8 @@ struct _EAttachmentBarPrivate {
        GtkWidget *status_label;
        GtkWidget *save_all_button;
        GtkWidget *save_one_button;
+       GtkWidget *icon_scrolled_window; /* not referenced */
+       GtkWidget *tree_scrolled_window; /* not referenced */
 
        gint active_view;
        guint expanded : 1;
@@ -119,6 +121,43 @@ attachment_bar_update_status (EAttachmentBar *bar)
 }
 
 static void
+attachment_bar_notify_vadjustment_upper_cb (GObject *object,
+                                           GParamSpec *param,
+                                           gpointer user_data)
+{
+       EAttachmentBar *bar = user_data;
+       GtkAdjustment *adjustment;
+       gint max_upper, max_content_height = -2;
+       gint request_height = -1;
+
+       g_return_if_fail (E_IS_ATTACHMENT_BAR (bar));
+
+       adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW 
(bar->priv->icon_scrolled_window));
+       max_upper = gtk_adjustment_get_upper (adjustment);
+
+       adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW 
(bar->priv->tree_scrolled_window));
+       max_upper = MAX (max_upper, gtk_adjustment_get_upper (adjustment));
+
+       gtk_widget_style_get (GTK_WIDGET (bar), "max-content-height", &max_content_height, NULL);
+
+       if ((max_content_height >= 0 && max_content_height < 50) || max_content_height <= -2)
+               max_content_height = 50;
+
+       if (max_content_height == -1) {
+               request_height = max_upper;
+       } else if (max_content_height < max_upper) {
+               request_height = max_content_height;
+       } else {
+               request_height = max_upper;
+       }
+
+       gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (bar->priv->icon_scrolled_window),
+               request_height);
+       gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (bar->priv->tree_scrolled_window),
+               request_height);
+}
+
+static void
 attachment_bar_set_store (EAttachmentBar *bar,
                           EAttachmentStore *store)
 {
@@ -534,6 +573,10 @@ e_attachment_bar_class_init (EAttachmentBarClass *class)
        widget_class->button_release_event = attachment_bar_button_release_event;
        widget_class->motion_notify_event = attachment_bar_motion_notify_event;
 
+       #if GTK_CHECK_VERSION (3, 20, 0)
+       gtk_widget_class_set_css_name (widget_class, G_OBJECT_CLASS_NAME (class));
+       #endif
+
        g_object_class_install_property (
                object_class,
                PROP_ACTIVE_VIEW,
@@ -574,6 +617,15 @@ e_attachment_bar_class_init (EAttachmentBarClass *class)
 
        g_object_class_override_property (
                object_class, PROP_EDITABLE, "editable");
+
+       gtk_widget_class_install_style_property (
+               widget_class,
+               g_param_spec_int (
+                       "max-content-height",
+                       "Max Content Height",
+                       NULL,
+                       -1, G_MAXINT, 150,
+                       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 }
 
 static void
@@ -597,8 +649,9 @@ e_attachment_bar_init (EAttachmentBar *bar)
        EAttachmentView *view;
        GtkSizeGroup *size_group;
        GtkWidget *container;
-       GtkWidget *widget, *scrolled_window;
+       GtkWidget *widget;
        GtkAction *action;
+       GtkAdjustment *adjustment;
 
        bar->priv = E_ATTACHMENT_BAR_GET_PRIVATE (bar);
 
@@ -627,15 +680,16 @@ e_attachment_bar_init (EAttachmentBar *bar)
 
        container = widget;
 
-       scrolled_window = gtk_scrolled_window_new (NULL, NULL);
-       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, 
GTK_POLICY_AUTOMATIC);
-       gtk_container_add (GTK_CONTAINER (container), scrolled_window);
-       gtk_widget_show (scrolled_window);
+       widget = gtk_scrolled_window_new (NULL, NULL);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (widget), GTK_POLICY_AUTOMATIC, 
GTK_POLICY_AUTOMATIC);
+       gtk_container_add (GTK_CONTAINER (container), widget);
+       bar->priv->icon_scrolled_window = widget;
+       gtk_widget_show (widget);
 
        widget = e_attachment_icon_view_new ();
        gtk_widget_set_can_focus (widget, TRUE);
        gtk_icon_view_set_model (GTK_ICON_VIEW (widget), bar->priv->model);
-       gtk_container_add (GTK_CONTAINER (scrolled_window), widget);
+       gtk_container_add (GTK_CONTAINER (bar->priv->icon_scrolled_window), widget);
        bar->priv->icon_view = g_object_ref (widget);
        gtk_widget_show (widget);
 
@@ -649,15 +703,16 @@ e_attachment_bar_init (EAttachmentBar *bar)
 
        container = widget;
 
-       scrolled_window = gtk_scrolled_window_new (NULL, NULL);
-       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, 
GTK_POLICY_AUTOMATIC);
-       gtk_container_add (GTK_CONTAINER (container), scrolled_window);
-       gtk_widget_show (scrolled_window);
+       widget = gtk_scrolled_window_new (NULL, NULL);
+       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (widget), GTK_POLICY_AUTOMATIC, 
GTK_POLICY_AUTOMATIC);
+       gtk_container_add (GTK_CONTAINER (container), widget);
+       bar->priv->tree_scrolled_window = widget;
+       gtk_widget_show (widget);
 
        widget = e_attachment_tree_view_new ();
        gtk_widget_set_can_focus (widget, TRUE);
        gtk_tree_view_set_model (GTK_TREE_VIEW (widget), bar->priv->model);
-       gtk_container_add (GTK_CONTAINER (scrolled_window), widget);
+       gtk_container_add (GTK_CONTAINER (bar->priv->tree_scrolled_window), widget);
        bar->priv->tree_view = g_object_ref (widget);
        gtk_widget_show (widget);
 
@@ -737,6 +792,14 @@ e_attachment_bar_init (EAttachmentBar *bar)
        gtk_widget_show (widget);
 
        g_object_unref (size_group);
+
+       adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW 
(bar->priv->icon_scrolled_window));
+       e_signal_connect_notify (adjustment, "notify::upper",
+               G_CALLBACK (attachment_bar_notify_vadjustment_upper_cb), bar);
+
+       adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW 
(bar->priv->tree_scrolled_window));
+       e_signal_connect_notify (adjustment, "notify::upper",
+               G_CALLBACK (attachment_bar_notify_vadjustment_upper_cb), bar);
 }
 
 GtkWidget *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]