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 | |
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
4 files changed, 33 insertions, 8 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java index 6d68bb4c..dd2275ec 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java @@ -177,7 +177,7 @@ public class AdvancedConfigurationComposite extends ConfigurationCompositeBase { this.cmbBKUAuswahl = new Combo(this.grpBkuAuswahl, SWT.READ_ONLY); SWTUtils.anchor(cmbBKUAuswahl).right(100,-5).top(0).left(0,5); SWTUtils.setFontHeight(cmbBKUAuswahl, Constants.TEXT_SIZE_NORMAL); - SWTUtils.disableEventDefault(cmbBKUAuswahl, SWT.MouseVerticalWheel); + SWTUtils.scrollPassthrough(cmbBKUAuswahl); this.bkuStrings = Arrays.stream(BKUs.values()).map(s -> Messages.getString("BKU."+s)).collect(Collectors.toList()); this.cmbBKUAuswahl.setItems(bkuStrings.toArray(new String[0])); @@ -254,7 +254,7 @@ public class AdvancedConfigurationComposite extends ConfigurationCompositeBase { SWTUtils.anchor(cmbLocaleAuswahl).right(100,-5).top(0).left(0,5); SWTUtils.setFontHeight(cmbLocaleAuswahl, Constants.TEXT_SIZE_NORMAL);; this.cmbLocaleAuswahl.setItems(Arrays.stream(Constants.SUPPORTED_LOCALES).map(l -> l.getDisplayLanguage()).toArray(String[]::new)); - SWTUtils.disableEventDefault(cmbLocaleAuswahl, SWT.MouseVerticalWheel); + SWTUtils.scrollPassthrough(cmbLocaleAuswahl); SWTUtils.addSelectionListener(cmbLocaleAuswahl, e -> { Locale currentLocale = configurationContainer.interfaceLocale; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java index 19eba137..862fc424 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java @@ -141,7 +141,7 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { this.cmbKeystoreType = new Combo(grpKeystore, SWT.READ_ONLY); SWTUtils.anchor(cmbKeystoreType).top(lblKeystoreType, 5).left(0,15).right(btnLoad, -5); SWTUtils.setFontHeight(cmbKeystoreType, Constants.TEXT_SIZE_NORMAL); - SWTUtils.disableEventDefault(cmbKeystoreType, SWT.MouseVerticalWheel); + SWTUtils.scrollPassthrough(cmbKeystoreType); this.lblKeystoreAlias = new Label(grpKeystore, SWT.NONE); SWTUtils.anchor(lblKeystoreAlias).top(cmbKeystoreType, 5).left(0, 5); @@ -150,7 +150,7 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { this.cmbKeystoreAlias = new Combo(grpKeystore, SWT.NONE); SWTUtils.anchor(cmbKeystoreAlias).top(lblKeystoreAlias, 5).left(0,15).right(100,-5); SWTUtils.setFontHeight(cmbKeystoreAlias, Constants.TEXT_SIZE_NORMAL); - SWTUtils.disableEventDefault(cmbKeystoreAlias, SWT.MouseVerticalWheel); + SWTUtils.scrollPassthrough(cmbKeystoreAlias); this.lblKeystorePassStoreType = new Label(this.grpKeystore, SWT.NONE); SWTUtils.anchor(lblKeystorePassStoreType).top(cmbKeystoreAlias, 5).left(0,5); @@ -159,7 +159,7 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { this.cmbKeystorePassStoreType = new Combo(grpKeystore, SWT.READ_ONLY); SWTUtils.anchor(cmbKeystorePassStoreType).top(lblKeystorePassStoreType, 5).left(0,15).right(100,-5); SWTUtils.setFontHeight(cmbKeystorePassStoreType, Constants.TEXT_SIZE_NORMAL); - SWTUtils.disableEventDefault(cmbKeystorePassStoreType, SWT.MouseVerticalWheel); + SWTUtils.scrollPassthrough(cmbKeystorePassStoreType); this.lblKeystoreStorePass = new Label(grpKeystore, SWT.NONE); SWTUtils.anchor(lblKeystoreStorePass).top(cmbKeystorePassStoreType, 5).left(0,5); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java index 4c636489..94362b54 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java @@ -165,7 +165,7 @@ public class SimpleConfigurationComposite extends ConfigurationCompositeBase { this.cmbSignatureProfiles = new Combo(this.grpSignatureProfile, SWT.READ_ONLY); SWTUtils.anchor(cmbSignatureProfiles).left(0,10).right(100,-10).top(0,10).bottom(100,-10); SWTUtils.setFontHeight(cmbSignatureProfiles, Constants.TEXT_SIZE_NORMAL); - SWTUtils.disableEventDefault(cmbSignatureProfiles, SWT.MouseVerticalWheel); + SWTUtils.scrollPassthrough(cmbSignatureProfiles); this.cmbSignatureProfiles.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { @@ -186,7 +186,7 @@ public class SimpleConfigurationComposite extends ConfigurationCompositeBase { this.cmbSignatureLang = new Combo(this.grpSignatureLang, SWT.READ_ONLY); SWTUtils.anchor(cmbSignatureLang).left(0,10).right(100,-10).top(0,10).bottom(100,-10); SWTUtils.setFontHeight(cmbSignatureLang, Constants.TEXT_SIZE_NORMAL); - SWTUtils.disableEventDefault(cmbSignatureLang, SWT.MouseVerticalWheel); + SWTUtils.scrollPassthrough(cmbSignatureLang); this.cmbSignatureLang.setItems(Arrays.stream(Constants.SUPPORTED_LOCALES).map(l -> l.getDisplayLanguage()).toArray(String[]::new)); this.cmbSignatureLang.addSelectionListener(new SelectionAdapter() { @@ -271,7 +271,7 @@ public class SimpleConfigurationComposite extends ConfigurationCompositeBase { sclLogoOnlyTargetSize.setMaximum(200); sclLogoOnlyTargetSize.setIncrement(1); sclLogoOnlyTargetSize.setPageIncrement(10); - SWTUtils.disableEventDefault(sclLogoOnlyTargetSize, SWT.MouseVerticalWheel); + SWTUtils.scrollPassthrough(sclLogoOnlyTargetSize); SWTUtils.addSelectionListener(sclLogoOnlyTargetSize, e -> { configurationContainer.logoOnlyTargetSize = sclLogoOnlyTargetSize.getSelection(); 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); |