diff options
author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-08-10 13:50:20 +0200 |
---|---|---|
committer | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-08-10 13:50:20 +0200 |
commit | 207f3bc210e8c27bfb24fc9636d6d023d0ee3c2d (patch) | |
tree | da23a617240e0e8ec8238fa18bffed29d2acf8f6 /pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils | |
parent | 0a1cb4c9b20ca2b95e076961c51e0a4108f38d7e (diff) | |
download | pdf-over-207f3bc210e8c27bfb24fc9636d6d023d0ee3c2d.tar.gz pdf-over-207f3bc210e8c27bfb24fc9636d6d023d0ee3c2d.tar.bz2 pdf-over-207f3bc210e8c27bfb24fc9636d6d023d0ee3c2d.zip |
scroll parent scrolledcomposite on combo boxes, cf. #116
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils')
-rw-r--r-- | pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTUtils.java | 25 |
1 files changed, 25 insertions, 0 deletions
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); |