summaryrefslogtreecommitdiff
path: root/gtk/gtkscrolledwindow.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2015-11-06 23:28:22 -0500
committerMatthias Clasen <mclasen@redhat.com>2015-11-06 23:28:22 -0500
commit353bfb009255943eafaf852e817b21e874ccfe3b (patch)
tree267ae3fa74954a10d0314c8c25f5739fa3fc0339 /gtk/gtkscrolledwindow.c
parentf900bec4fa3cfab89e119d552d93a978628ed4f6 (diff)
downloadgtk+-353bfb009255943eafaf852e817b21e874ccfe3b.tar.gz
scrolledwindow: Set positional classes on scrollbars
This might be useful for some themes.
Diffstat (limited to 'gtk/gtkscrolledwindow.c')
-rw-r--r--gtk/gtkscrolledwindow.c73
1 files changed, 69 insertions, 4 deletions
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 622def1183..ef55d40534 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -109,12 +109,17 @@
* # CSS nodes
*
* GtkScrolledWindow has a main CSS node with name scrolledwindow.
- * It uses transient subnodes with names overshoot and undershoot to
+ *
+ * It uses subnodes with names overshoot and undershoot to
* draw the overflow and underflow indications. These nodes get
* the .left, .right, .top or .bottom style class added depending
- * on where the indication is drawn. If both scrollbars are visible,
- * the area where they meet is drawn with a transient subnode named
- * junction.
+ * on where the indication is drawn.
+ *
+ * GtkScrolledWindow also sets the positional style classes (.left,
+ * .right, .top, .bottom) on the scrollbars.
+ *
+ * If both scrollbars are visible, the area where they meet is drawn
+ * with a subnode named junction.
*/
@@ -429,6 +434,62 @@ gtk_scrolled_window_leave_notify (GtkWidget *widget,
}
static void
+update_scrollbar_positions (GtkScrolledWindow *scrolled_window)
+{
+ GtkScrolledWindowPrivate *priv = scrolled_window->priv;
+ GtkStyleContext *context;
+ gboolean is_rtl;
+
+ if (priv->hscrollbar != NULL)
+ {
+ context = gtk_widget_get_style_context (priv->hscrollbar);
+ if (priv->window_placement == GTK_CORNER_TOP_LEFT ||
+ priv->window_placement == GTK_CORNER_TOP_RIGHT)
+ {
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_BOTTOM);
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_TOP);
+ }
+ else
+ {
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BOTTOM);
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOP);
+ }
+ }
+
+ if (priv->vscrollbar != NULL)
+ {
+ context = gtk_widget_get_style_context (priv->vscrollbar);
+ is_rtl = gtk_widget_get_direction (GTK_WIDGET (scrolled_window)) == GTK_TEXT_DIR_RTL;
+ if ((is_rtl &&
+ (priv->window_placement == GTK_CORNER_TOP_RIGHT ||
+ priv->window_placement == GTK_CORNER_BOTTOM_RIGHT)) ||
+ (!is_rtl &&
+ (priv->window_placement == GTK_CORNER_TOP_LEFT ||
+ priv->window_placement == GTK_CORNER_BOTTOM_LEFT)))
+ {
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_RIGHT);
+ }
+ else
+ {
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_LEFT);
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
+ }
+ }
+}
+
+static void
+gtk_scrolled_window_direction_changed (GtkWidget *widget,
+ GtkTextDirection previous_dir)
+{
+ GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
+
+ update_scrollbar_positions (scrolled_window);
+
+ GTK_WIDGET_CLASS (gtk_scrolled_window_parent_class)->direction_changed (widget, previous_dir);
+}
+
+static void
gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
@@ -457,6 +518,7 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
widget_class->realize = gtk_scrolled_window_realize;
widget_class->unrealize = gtk_scrolled_window_unrealize;
widget_class->leave_notify_event = gtk_scrolled_window_leave_notify;
+ widget_class->direction_changed = gtk_scrolled_window_direction_changed;
container_class->add = gtk_scrolled_window_add;
container_class->remove = gtk_scrolled_window_remove;
@@ -1470,6 +1532,7 @@ gtk_scrolled_window_set_hadjustment (GtkScrolledWindow *scrolled_window,
gtk_widget_set_parent (priv->hscrollbar, GTK_WIDGET (scrolled_window));
g_object_ref (priv->hscrollbar);
gtk_widget_show (priv->hscrollbar);
+ update_scrollbar_positions (scrolled_window);
}
else
{
@@ -1537,6 +1600,7 @@ gtk_scrolled_window_set_vadjustment (GtkScrolledWindow *scrolled_window,
gtk_widget_set_parent (priv->vscrollbar, GTK_WIDGET (scrolled_window));
g_object_ref (priv->vscrollbar);
gtk_widget_show (priv->vscrollbar);
+ update_scrollbar_positions (scrolled_window);
}
else
{
@@ -1730,6 +1794,7 @@ gtk_scrolled_window_set_placement_internal (GtkScrolledWindow *scrolled_window,
if (priv->window_placement != window_placement)
{
priv->window_placement = window_placement;
+ update_scrollbar_positions (scrolled_window);
gtk_widget_queue_resize (GTK_WIDGET (scrolled_window));