diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java index f0c0180359..f14cb53fbd 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java @@ -15,6 +15,8 @@ package org.eclipse.swt.widgets; +import java.util.List; + import org.eclipse.swt.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; @@ -22,6 +24,7 @@ import org.eclipse.swt.internal.win32.*; import org.eclipse.swt.internal.win32.version.*; + /** * Instances of this class represent a selectable user interface object that * issues notification when pressed and released. @@ -265,6 +268,23 @@ long callWindowProc (long hwnd, int msg, long wParam, long lParam) { return OS.CallWindowProc (ButtonProc, hwnd, msg, wParam, lParam); } +private static StyleProcessor STYLE_PROCESSOR = new StyleProcessor(); + +static { + StyleProcessor processor = new StyleProcessor(); + + if (COMMAND_LINK) { + processor.someOf("COMMAND"); + } else { + processor.oneOf("PUSH, ARROW, CHECK, RADIO, TOGGLE"); + } + processor.ifOneOf("PUSH, TOGGLE").thenOneOf("CENTER, LEFT, RIGHT") + .ifOneOf("CHECK, RADIO").thenOneOf("LEFT, RIGHT, CENTER") + .ifOneOf("ARROW").thenOneOf("UP, DOWN, LEFT, RIGHT"); + + STYLE_PROCESSOR = processor; +} + static int checkStyle (int style) { style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, COMMAND_LINK ? SWT.COMMAND : 0); if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) { @@ -278,6 +298,11 @@ static int checkStyle (int style) { return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0); } return style; + +} + +List getStyles() { + return STYLE_PROCESSOR.process(this.style); } void click () { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/StyleProcessor.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/StyleProcessor.java new file mode 100644 index 0000000000..81de65495d --- /dev/null +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/StyleProcessor.java @@ -0,0 +1,141 @@ +package org.eclipse.swt.widgets; + +import java.util.*; + +import org.eclipse.swt.*; + +class StyleProcessor { + + + private static class Rule { + ArrayList ifOneOf; + ArrayList thenOneOf; + ArrayList thenSomeOf; + + Rule(ArrayList ifOneOf) { + this.ifOneOf = ifOneOf; + this.thenOneOf = new ArrayList<>(); + this.thenSomeOf = new ArrayList<>(); + } + } + + private ArrayList rules = new ArrayList<>(); + private ArrayList> oneOfArr = new ArrayList<>(); + private ArrayList someOfArr = new ArrayList<>(); + private Rule currentRule = null; + + public StyleProcessor oneOf(String styles) { + String[] tempHolder = styles.split(", "); + + oneOfArr.add(new ArrayList<>(Arrays.asList(tempHolder))); + + return this; + } + + public StyleProcessor someOf(String styles) { + String[] tempHolder = styles.split(", "); + + someOfArr.addAll(Arrays.asList(tempHolder)); + + return this; + } + + public StyleProcessor ifOneOf(String styles) { + String[] tempHolder = styles.split(", "); + ArrayList tempList = new ArrayList<>(Arrays.asList(tempHolder)); + currentRule = new Rule(tempList); + rules.add(currentRule); + return this; + } + + + public StyleProcessor thenOneOf(String styles) { + if (currentRule == null) { + throw new IllegalStateException("No 'ifOneOf' defined before 'thenOneOf'"); + } + currentRule.thenOneOf.addAll(Arrays.asList(styles.split(", "))); + return this; + } + + + public StyleProcessor thenSomeOf(String styles) { + if (currentRule == null) { + throw new IllegalStateException("No 'ifOneOf' defined before 'thenSomeOf'"); + } + currentRule.thenSomeOf.addAll(Arrays.asList(styles.split(", "))); + return this; + } + + + + public ArrayList process(int style) { + ArrayList finalList = new ArrayList<>(); + for (ArrayList a: oneOfArr) { + for (String s: a) { + try { + if ((style & SWT.class.getField(s).getInt(null)) != 0) { + finalList.add(s); + break; + } + } catch (NoSuchFieldException | IllegalAccessException e) { + System.out.println("Invalid Style: " + s); + } + } + } + + for (String s : someOfArr) { + try { + if ((style & SWT.class.getField(s).getInt(null)) != 0) { + finalList.add(s); + } + } catch (NoSuchFieldException | IllegalAccessException e) { + System.out.println("Invalid Style: " + s); + } + } + + for (Rule rule : rules) { + boolean matched = false; + + for (String condition : rule.ifOneOf) { + try { + int flag = SWT.class.getField(condition).getInt(null); + if ((style & flag) != 0) { + matched = true; + break; + } + } catch (NoSuchFieldException | IllegalAccessException e) { + System.out.println("Invalid condition: " + condition); + } + } + + if (matched) { + for (String s : rule.thenOneOf) { + try { + int flag = SWT.class.getField(s).getInt(null); + if ((style & flag) != 0) { + finalList.add(s); + break; + } + } catch (NoSuchFieldException | IllegalAccessException e) { + System.out.println("Invalid thenOneOf: " + s); + } + } + + for (String s : rule.thenSomeOf) { + try { + int flag = SWT.class.getField(s).getInt(null); + if ((style & flag) != 0) { + finalList.add(s); + } + } catch (NoSuchFieldException | IllegalAccessException e) { + System.out.println("Invalid thenSomeOf: " + s);; + } + } + } + } + + return finalList; + } + + +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java index 537ca15058..c28cf910a1 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java @@ -14,7 +14,7 @@ package org.eclipse.swt.widgets; -import java.util.*; +import java.util.List; import org.eclipse.swt.*; import org.eclipse.swt.events.*; @@ -626,7 +626,21 @@ void applySegments () { ignoreVerify = oldIgnoreVerify; } +private static StyleProcessor STYLE_PROCESSOR = new StyleProcessor(); + +static { + StyleProcessor processor = new StyleProcessor(); + + processor.oneOf("SINGLE, MULTI") + .oneOf("LEFT, CENTER, RIGHT") + .someOf("BORDER, SEARCH").ifOneOf("MULTI").thenSomeOf("H_SCROLL, V_SCROLL, WRAP") + .ifOneOf("SINGLE").thenSomeOf("PASSWORD"); + + STYLE_PROCESSOR = processor; +} + static int checkStyle (int style) { + System.out.println(STYLE_PROCESSOR.process(style)); if ((style & SWT.SINGLE) != 0 && (style & SWT.MULTI) != 0) { style &= ~SWT.MULTI; } @@ -651,6 +665,11 @@ static int checkStyle (int style) { return style | SWT.SINGLE; } + +List getStyles() { + return STYLE_PROCESSOR.process(this.style); +} + void clearSegments (boolean applyText) { if (clearSegmentsCount++ != 0) return; if (segments == null) return;