From 207f3bc210e8c27bfb24fc9636d6d023d0ee3c2d Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Wed, 10 Aug 2022 13:50:20 +0200 Subject: scroll parent scrolledcomposite on combo boxes, cf. #116 --- .../java/at/asit/pdfover/gui/utils/SWTUtils.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTUtils.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTUtils.java index 980710e3..ef93e3e9 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTUtils.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTUtils.java @@ -4,13 +4,17 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.function.Consumer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Event; import org.slf4j.Logger; @@ -62,6 +66,27 @@ public final class SWTUtils { c.addListener(event, (Event e) -> { e.doit = false; }); } + public static void scrollPassthrough(Control c) { + c.addListener(SWT.MouseVerticalWheel, (Event e) -> { + // disable default handling + e.doit = false; + + // find containing ScrolledComposite + Composite target = c.getParent(); + while ((target != null) && !(target instanceof ScrolledComposite)) + target = target.getParent(); + + if (target == null) + return; + + // scroll containing ScrolledComposite + ScrolledComposite sTarget = (ScrolledComposite)target; + Point origin = sTarget.getOrigin(); + origin.y -= (e.count * 10); + sTarget.setOrigin(origin); + }); + } + public static void setFontHeight(Control c, int height) { FontData[] fD = c.getFont().getFontData(); fD[0].setHeight(height); -- cgit v1.2.3