summaryrefslogtreecommitdiff
path: root/eel
diff options
context:
space:
mode:
authorraveit65 <[email protected]>2016-10-16 07:36:03 +0200
committerlukefromdc <[email protected]>2016-10-16 14:07:29 -0400
commita79bec599478cf32134105c75e73775ba74f9013 (patch)
tree8185687df88ef7af9032c33fc1f5c96370545221 /eel
parent625a06c0a0781025693a6299b721b6bc7a065c1a (diff)
downloadcaja-a79bec599478cf32134105c75e73775ba74f9013.tar.bz2
caja-a79bec599478cf32134105c75e73775ba74f9013.tar.xz
Gtk+-2: add eel_gtk_adjustment* functions again
This reverts https://github.com/mate-desktop/caja/commit/f02d495 for gtk2 fixes https://github.com/mate-desktop/caja/issues/659
Diffstat (limited to 'eel')
-rw-r--r--eel/eel-gtk-extensions.c34
-rw-r--r--eel/eel-gtk-extensions.h7
2 files changed, 40 insertions, 1 deletions
diff --git a/eel/eel-gtk-extensions.c b/eel/eel-gtk-extensions.c
index e451bdbf..4969d7aa 100644
--- a/eel/eel-gtk-extensions.c
+++ b/eel/eel-gtk-extensions.c
@@ -353,6 +353,40 @@ eel_gtk_menu_tool_button_get_button (GtkMenuToolButton *tool_button)
return button;
}
+#if !GTK_CHECK_VERSION (3, 0, 0)
+/* The standard gtk_adjustment_set_value ignores page size, which
+ * disagrees with the logic used by scroll bars, for example.
+ */
+void
+eel_gtk_adjustment_set_value (GtkAdjustment *adjustment,
+ float value)
+{
+ float upper_page_start, clamped_value;
+
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+
+ upper_page_start = MAX (gtk_adjustment_get_upper (adjustment) -
+ gtk_adjustment_get_page_size (adjustment),
+ gtk_adjustment_get_lower (adjustment));
+ clamped_value = CLAMP (value, gtk_adjustment_get_lower (adjustment), upper_page_start);
+ if (clamped_value != gtk_adjustment_get_value (adjustment))
+ {
+ gtk_adjustment_set_value (adjustment, clamped_value);
+ gtk_adjustment_value_changed (adjustment);
+ }
+}
+
+/* Clamp a value if the minimum or maximum has changed. */
+void
+eel_gtk_adjustment_clamp_value (GtkAdjustment *adjustment)
+{
+ g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
+
+ eel_gtk_adjustment_set_value (adjustment,
+ gtk_adjustment_get_value (adjustment));
+}
+#endif
+
/**
* eel_gtk_label_make_bold.
*
diff --git a/eel/eel-gtk-extensions.h b/eel/eel-gtk-extensions.h
index aec680f3..fd85c2db 100644
--- a/eel/eel-gtk-extensions.h
+++ b/eel/eel-gtk-extensions.h
@@ -63,7 +63,12 @@ GtkWidget * eel_gtk_menu_tool_button_get_button (GtkMenuTo
/* GtkLabel */
void eel_gtk_label_make_bold (GtkLabel *label);
-
+#if !GTK_CHECK_VERSION (3, 0, 0)
+/* GtkAdjustment */
+void eel_gtk_adjustment_set_value (GtkAdjustment *adjustment,
+ float value);
+void eel_gtk_adjustment_clamp_value (GtkAdjustment *adjustment);
+#endif
/* GtkTreeView */
void eel_gtk_tree_view_set_activate_on_single_click (GtkTreeView *tree_view,
gboolean should_activate);