[gtk+/wip/overlay-scrollbar] Introduce a helper function
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/overlay-scrollbar] Introduce a helper function
- Date: Thu, 9 Oct 2014 03:38:08 +0000 (UTC)
commit ca5e57a6bcc28fd8a12a5d4810f18c36d377f134
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Oct 7 22:59:07 2014 -0400
Introduce a helper function
Instead of making assumptions about enum value ordering,
introduce a helper function to determine policy values
for which the scrollbar may be visible.
gtk/gtkscrolledwindow.c | 28 ++++++++++++++++------------
1 files changed, 16 insertions(+), 12 deletions(-)
---
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 1fadf01..f8434ec 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -584,6 +584,12 @@ may_vscroll (GtkScrolledWindow *scrolled_window)
return priv->vscrollbar_visible || priv->vscrollbar_policy == GTK_POLICY_EXTERNAL;
}
+static inline gboolean
+policy_may_be_visible (GtkPolicyType policy)
+{
+ return policy == GTK_POLICY_ALWAYS || policy == GTK_POLICY_AUTOMATIC;
+}
+
static void
scrolled_window_drag_begin_cb (GtkScrolledWindow *scrolled_window,
gdouble start_x,
@@ -2158,21 +2164,21 @@ gtk_scrolled_window_size_allocate (GtkWidget *widget,
}
else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
{
- priv->hscrollbar_visible = priv->hscrollbar_policy < GTK_POLICY_NEVER;
+ priv->hscrollbar_visible = policy_may_be_visible (priv->hscrollbar_policy);
priv->vscrollbar_visible = child_scroll_height > allocation->height -
(priv->hscrollbar_visible ? sb_height + sb_spacing : 0);
}
}
else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
{
- priv->vscrollbar_visible = priv->vscrollbar_policy < GTK_POLICY_NEVER;
+ priv->vscrollbar_visible = policy_may_be_visible (priv->vscrollbar_policy);
if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC)
priv->hscrollbar_visible =
child_scroll_width > allocation->width -
(priv->vscrollbar_visible ? 0 : sb_width + sb_spacing);
else
- priv->hscrollbar_visible = priv->hscrollbar_policy < GTK_POLICY_NEVER;
+ priv->hscrollbar_visible = policy_may_be_visible (priv->hscrollbar_policy);
}
}
else /* GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT */
@@ -2219,21 +2225,21 @@ gtk_scrolled_window_size_allocate (GtkWidget *widget,
}
else /* priv->vscrollbar_policy != GTK_POLICY_AUTOMATIC */
{
- priv->vscrollbar_visible = priv->vscrollbar_policy < GTK_POLICY_NEVER;
+ priv->vscrollbar_visible = policy_may_be_visible (priv->vscrollbar_policy);
priv->hscrollbar_visible = child_scroll_width > allocation->width -
(priv->vscrollbar_visible ? sb_width + sb_spacing : 0);
}
}
else /* priv->hscrollbar_policy != GTK_POLICY_AUTOMATIC */
{
- priv->hscrollbar_visible = priv->hscrollbar_policy < GTK_POLICY_NEVER;
+ priv->hscrollbar_visible = policy_may_be_visible (priv->hscrollbar_policy);
if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC)
priv->vscrollbar_visible =
child_scroll_height > allocation->height -
(priv->hscrollbar_visible ? 0 : sb_height + sb_spacing);
else
- priv->vscrollbar_visible = priv->vscrollbar_policy < GTK_POLICY_NEVER;
+ priv->vscrollbar_visible = policy_may_be_visible (priv->vscrollbar_policy);
}
}
@@ -2958,7 +2964,7 @@ gtk_scrolled_window_get_preferred_size (GtkWidget *widget,
natural_req.width = MAX (natural_req.width, min_content_width);
extra_width = -1;
}
- else if (priv->vscrollbar_policy < GTK_POLICY_NEVER)
+ else if (policy_may_be_visible (priv->vscrollbar_policy))
{
minimum_req.width += vscrollbar_requisition.width;
natural_req.width += vscrollbar_requisition.width;
@@ -2986,7 +2992,7 @@ gtk_scrolled_window_get_preferred_size (GtkWidget *widget,
natural_req.height = MAX (natural_req.height, min_content_height);
extra_height = -1;
}
- else if (priv->vscrollbar_policy < GTK_POLICY_NEVER)
+ else if (policy_may_be_visible (priv->vscrollbar_policy))
{
minimum_req.height += vscrollbar_requisition.height;
natural_req.height += vscrollbar_requisition.height;
@@ -2995,8 +3001,7 @@ gtk_scrolled_window_get_preferred_size (GtkWidget *widget,
}
}
- if (priv->hscrollbar_policy == GTK_POLICY_AUTOMATIC ||
- priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
+ if (policy_may_be_visible (priv->hscrollbar_policy))
{
minimum_req.width = MAX (minimum_req.width, hscrollbar_requisition.width);
natural_req.width = MAX (natural_req.width, hscrollbar_requisition.width);
@@ -3004,8 +3009,7 @@ gtk_scrolled_window_get_preferred_size (GtkWidget *widget,
extra_height = scrollbar_spacing + hscrollbar_requisition.height;
}
- if (priv->vscrollbar_policy == GTK_POLICY_AUTOMATIC ||
- priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
+ if (policy_may_be_visible (priv->vscrollbar_policy))
{
minimum_req.height = MAX (minimum_req.height, vscrollbar_requisition.height);
natural_req.height = MAX (natural_req.height, vscrollbar_requisition.height);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]