[cheese] thumbnav: update scrollbar policy in size-request callback



commit 2b117ff2e8dae5deac2dc1e1fb3409e11b525343
Author: Filippo Argiolas <filippo argiolas gmail com>
Date:   Mon Aug 10 17:19:54 2009 +0200

    thumbnav: update scrollbar policy in size-request callback
    
    See source code comments for a detailed explanation. This fixes the
    issue that caused the window to grow huge when switching mode.

 src/cheese-window.c |   15 +++++++++++++++
 src/eog-thumb-nav.c |   29 ++++++++++++++++++++---------
 src/eog-thumb-nav.h |    7 +++++++
 3 files changed, 42 insertions(+), 9 deletions(-)
---
diff --git a/src/cheese-window.c b/src/cheese-window.c
index 3576e2c..e7e08c2 100644
--- a/src/cheese-window.c
+++ b/src/cheese-window.c
@@ -359,6 +359,21 @@ cheese_window_thumb_view_size_req_cb (GtkWidget      *widget,
     gtk_widget_set_size_request (widget, -1, -1);
   }
 
+  /* set scrollbar policy. Can't be done in the
+   * eog_thumb_nav_set_vertical because the icon view relayouts on
+   * idle after changing the "column" property. So if you set NEVER
+   * policy before the relayout the window gets as bigger as many
+   * items you've got */
+  if (eog_thumb_nav_is_vertical (cheese_window->thumb_nav)) {
+    eog_thumb_nav_set_policy (EOG_THUMB_NAV (cheese_window->thumb_nav),
+                              GTK_POLICY_NEVER,
+                              GTK_POLICY_AUTOMATIC);
+  } else {
+    eog_thumb_nav_set_policy (EOG_THUMB_NAV (cheese_window->thumb_nav),
+                              GTK_POLICY_AUTOMATIC,
+                              GTK_POLICY_NEVER);
+  }
+
   /* at this time the toplevel window has still no size requisition,
    * wait for its next size-request */
   if (cheese_window->needs_resizing) {
diff --git a/src/eog-thumb-nav.c b/src/eog-thumb-nav.c
index 7907fef..89e3956 100644
--- a/src/eog-thumb-nav.c
+++ b/src/eog-thumb-nav.c
@@ -360,9 +360,9 @@ eog_thumb_nav_constructor (GType type,
     gtk_widget_show_all (priv->sw);
   }
 
-   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->sw),
-                                   GTK_POLICY_AUTOMATIC,
-                                   GTK_POLICY_NEVER);
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->sw),
+                                  GTK_POLICY_NEVER,
+                                  GTK_POLICY_NEVER);
 
   return object;
 }
@@ -649,6 +649,23 @@ eog_thumb_nav_set_show_buttons (EogThumbNav *nav, gboolean show_buttons)
   }
 }
 
+void
+eog_thumb_nav_set_policy (EogThumbNav *nav,
+                          GtkPolicyType hscrollbar_policy,
+                          GtkPolicyType vscrollbar_policy)
+{
+  EogThumbNavPrivate *priv = EOG_THUMB_NAV_GET_PRIVATE (nav);
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->sw),
+                                  hscrollbar_policy,
+                                  vscrollbar_policy);
+}
+
+gboolean
+eog_thumb_nav_is_vertical (EogThumbNav *nav)
+{
+  EogThumbNavPrivate *priv = EOG_THUMB_NAV_GET_PRIVATE (nav);
+  return priv->vertical;
+}
 
 void
 eog_thumb_nav_set_vertical (EogThumbNav *nav, gboolean vertical)
@@ -683,9 +700,6 @@ eog_thumb_nav_set_vertical (EogThumbNav *nav, gboolean vertical)
     gtk_container_remove (GTK_CONTAINER (nav), priv->button_right);
     gtk_adjustment_value_changed (priv->vadj);
     priv->vertical = TRUE;
-    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->sw),
-                                    GTK_POLICY_NEVER,
-                                    GTK_POLICY_AUTOMATIC);
   } else {
     g_return_if_fail (!gtk_widget_get_parent (priv->button_left));
     g_return_if_fail (!gtk_widget_get_parent (priv->button_right));
@@ -704,9 +718,6 @@ eog_thumb_nav_set_vertical (EogThumbNav *nav, gboolean vertical)
     gtk_container_remove (GTK_CONTAINER (priv->vbox), priv->button_down);
     gtk_adjustment_value_changed (priv->hadj);
     priv->vertical = FALSE;
-    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->sw),
-                                    GTK_POLICY_AUTOMATIC,
-                                    GTK_POLICY_NEVER);
   }
   gtk_widget_show_all (GTK_WIDGET (nav));
 }
diff --git a/src/eog-thumb-nav.h b/src/eog-thumb-nav.h
index 55a4a21..314fea0 100644
--- a/src/eog-thumb-nav.h
+++ b/src/eog-thumb-nav.h
@@ -60,9 +60,16 @@ gboolean         eog_thumb_nav_get_show_buttons  (EogThumbNav       *nav);
 
 void             eog_thumb_nav_set_show_buttons  (EogThumbNav       *nav,
                                                   gboolean           show_buttons);
+
+gboolean         eog_thumb_nav_is_vertical       (EogThumbNav       *nav);
+
 void             eog_thumb_nav_set_vertical      (EogThumbNav       *nav,
                                                   gboolean           vertical);
 
+void            eog_thumb_nav_set_policy         (EogThumbNav *nav,
+                                                  GtkPolicyType hscrollbar_policy,
+                                                  GtkPolicyType vscrollbar_policy);
+
 G_END_DECLS
 
 #endif /* __EOG_THUMB_NAV_H__ */



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