summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/scroll-utils.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
commitcca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch)
tree146f39ded1c938019e1ed42d30923c2ac9e86789 /src/ui/widget/scroll-utils.cpp
parentInitial commit. (diff)
downloadinkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.tar.xz
inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.zip
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/ui/widget/scroll-utils.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/ui/widget/scroll-utils.cpp b/src/ui/widget/scroll-utils.cpp
new file mode 100644
index 0000000..5822a15
--- /dev/null
+++ b/src/ui/widget/scroll-utils.cpp
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Authors:
+ * Thomas Holder
+ *
+ * Copyright (C) 2020 authors
+ *
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+
+#include "scroll-utils.h"
+
+#include <gtkmm/scrolledwindow.h>
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+/**
+ * Get the first ancestor which is scrollable.
+ */
+Gtk::Widget *get_scrollable_ancestor(Gtk::Widget *widget)
+{
+ auto parent = widget->get_parent();
+ if (!parent) {
+ return nullptr;
+ }
+ if (auto scrollable = dynamic_cast<Gtk::ScrolledWindow *>(parent)) {
+ return scrollable;
+ }
+ return get_scrollable_ancestor(parent);
+}
+
+/**
+ * Return true if scrolling is allowed.
+ *
+ * Scrolling is allowed for any of:
+ * - Shift modifier is pressed
+ * - Widget has focus
+ * - Widget has no scrollable ancestor
+ */
+bool scrolling_allowed(Gtk::Widget *widget, GdkEventScroll *event)
+{
+ bool const shift = event && (event->state & GDK_SHIFT_MASK);
+ return shift || //
+ widget->has_focus() || //
+ get_scrollable_ancestor(widget) == nullptr;
+}
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:softtabstop=4:fileencoding=utf-8:textwidth=99 :