|
20 | 20 | import org.eclipse.swt.events.SelectionListener;
|
21 | 21 | import org.eclipse.swt.events.VerifyListener;
|
22 | 22 | import org.eclipse.swt.graphics.Color;
|
| 23 | +import org.eclipse.swt.graphics.Font; |
23 | 24 | import org.eclipse.swt.graphics.Point;
|
24 | 25 | import org.eclipse.swt.graphics.Rectangle;
|
25 | 26 | import org.eclipse.swt.internal.ResizeSystem;
|
@@ -86,15 +87,19 @@ public class Combo extends Composite {
|
86 | 87 | private boolean isSimple;
|
87 | 88 | private int itemCount;
|
88 | 89 | private int maxWidth = 0;
|
89 |
| - |
| 90 | + private String textValue; |
| 91 | + |
90 | 92 | private Object hDropDownClick;
|
91 | 93 | private Object hEditKeyUp;
|
92 | 94 | private Object hEditShow;
|
93 | 95 | private Object hTextChange;
|
94 | 96 | private Object hTextBlur;
|
95 | 97 | private Object hTextMouseUp;
|
96 | 98 | private Object hTextKeyUp;
|
97 |
| - |
| 99 | + private Object hModifyFocus; |
| 100 | + private Object hModifyBlur; |
| 101 | + private Object hModifyKeyUp; |
| 102 | + |
98 | 103 | /**
|
99 | 104 | * the operating system limit for the number of characters
|
100 | 105 | * that the text field in an instance of this class can hold
|
@@ -668,8 +673,71 @@ void hookFocusOut() {
|
668 | 673 | }
|
669 | 674 |
|
670 | 675 | void hookModify() {
|
671 |
| - super.hookModify(); |
672 |
| - Clazz.addEvent(textInput, "change", hModify); |
| 676 | + if (hModifyKeyUp != null) { |
| 677 | + return; |
| 678 | + } |
| 679 | + hModifyKeyUp = new RunnableCompatibility() { |
| 680 | + public void run() { |
| 681 | + if ((style & SWT.READ_ONLY) != 0 |
| 682 | + /* |
| 683 | + * I have changed !hooks (SWT.Verify) && !filters (SWT.Verify)) to |
| 684 | + * hooks (SWT.Verify) && !filters (SWT.Verify)) |
| 685 | + * I do not know what is the rational behind the first. |
| 686 | + */ |
| 687 | + || (hooks (SWT.Verify) && !filters (SWT.Verify))) { |
| 688 | + toReturn(true); |
| 689 | + return ; |
| 690 | + } |
| 691 | + String newText = textInput.value; |
| 692 | + if (newText != null) { |
| 693 | + newText = verifyText (newText, 0, 0, null); |
| 694 | + if (newText == null) { |
| 695 | + toReturn(true); |
| 696 | + return ; |
| 697 | + } |
| 698 | + if (textValue != textInput.value) { |
| 699 | + textValue = textInput.value; |
| 700 | + Event e = new Event(); |
| 701 | + e.type = SWT.Modify; |
| 702 | + e.item = Combo.this; |
| 703 | + e.widget = Combo.this; |
| 704 | + sendEvent(e); |
| 705 | + toReturn(e.doit); |
| 706 | + } |
| 707 | + } |
| 708 | + } |
| 709 | + }; |
| 710 | + Clazz.addEvent(textInput, "keyup", hModifyKeyUp); |
| 711 | + Clazz.addEvent(textInput, "change", hModifyKeyUp); |
| 712 | + |
| 713 | + hModifyBlur = new RunnableCompatibility() { |
| 714 | + public void run() { |
| 715 | + OS.removeCSSClass(handle, "text-focus"); |
| 716 | + Event e = new Event(); |
| 717 | + e.type = SWT.FocusOut; |
| 718 | + e.item = Combo.this; |
| 719 | + e.widget = Combo.this; |
| 720 | + sendEvent(e); |
| 721 | + toReturn(e.doit); |
| 722 | + } |
| 723 | + }; |
| 724 | + Clazz.addEvent(textInput, "blur", hModifyBlur); |
| 725 | + |
| 726 | + hModifyFocus = new RunnableCompatibility() { |
| 727 | + public void run() { |
| 728 | + OS.addCSSClass(handle, "text-focus"); |
| 729 | + Event e = new Event(); |
| 730 | + e.type = SWT.FocusIn; |
| 731 | + e.item = Combo.this; |
| 732 | + e.widget = Combo.this; |
| 733 | + sendEvent(e); |
| 734 | + toReturn(e.doit); |
| 735 | + } |
| 736 | + }; |
| 737 | + Clazz.addEvent(textInput, "focus", hModifyFocus); |
| 738 | + |
| 739 | +// super.hookModify(); |
| 740 | +// Clazz.addEvent(textInput, "change", hModify); |
673 | 741 | }
|
674 | 742 |
|
675 | 743 | void hookSelection() {
|
@@ -1766,6 +1834,7 @@ void setBounds (int x, int y, int width, int height, int flags) {
|
1766 | 1834 | textInput.style.width = Math.max(0, width - buttonWidth - 3) + "px";
|
1767 | 1835 | textInput.style.height = Math.max(0, height - 4) + "px";
|
1768 | 1836 | textInput.style.lineHeight = Math.max(0, height - 4) + "px";
|
| 1837 | + textInput.style.marginTop = "0"; |
1769 | 1838 | } else if (OS.isSafari || OS.isChrome) {
|
1770 | 1839 | textInput.style.marginTop = "0";
|
1771 | 1840 | } else if (OS.isIE) {
|
@@ -2080,6 +2149,13 @@ public void setSelection (Point selection) {
|
2080 | 2149 | Text.setTextSelection(textInput, selection.x + 1, selection.y + 2);
|
2081 | 2150 | }
|
2082 | 2151 |
|
| 2152 | +public void setFont(Font font) { |
| 2153 | + super.setFont(font); |
| 2154 | + Element handle = fontHandle(); |
| 2155 | + selectInput.style.fontFamily = handle.style.fontFamily; |
| 2156 | + selectInput.style.fontSize = handle.style.fontSize; |
| 2157 | +} |
| 2158 | + |
2083 | 2159 | /**
|
2084 | 2160 | * Sets the contents of the receiver's text field to the
|
2085 | 2161 | * given string.
|
@@ -2122,11 +2198,15 @@ public void setText (String string, boolean modify) {
|
2122 | 2198 | /*
|
2123 | 2199 | TCHAR buffer = new TCHAR (getCodePage (), string, true);
|
2124 | 2200 | if (OS.SetWindowText (handle, buffer)) {
|
2125 |
| - */ |
2126 | 2201 | if(modify){
|
2127 | 2202 | sendEvent (SWT.Modify);
|
2128 | 2203 | // widget could be disposed at this point
|
2129 | 2204 | }
|
| 2205 | + */ |
| 2206 | + if (textValue != string) { |
| 2207 | + textValue = string; |
| 2208 | + sendEvent(SWT.Modify); |
| 2209 | + } |
2130 | 2210 | }
|
2131 | 2211 |
|
2132 | 2212 | /**
|
@@ -2759,9 +2839,24 @@ protected void releaseHandle() {
|
2759 | 2839 | if (hFocusOut != null) {
|
2760 | 2840 | Clazz.removeEvent(textInput, "blur", hFocusOut);
|
2761 | 2841 | }
|
2762 |
| - if (hModify != null) { |
2763 |
| - Clazz.removeEvent(textInput, "change", hModify); |
| 2842 | +// if (hModify != null) { |
| 2843 | +// Clazz.removeEvent(textInput, "change", hModify); |
| 2844 | +// } |
| 2845 | + |
| 2846 | + if (hModifyBlur != null) { |
| 2847 | + Clazz.removeEvent(textInput, "blur", hModifyBlur); |
| 2848 | + hModifyBlur = null; |
| 2849 | + } |
| 2850 | + if (hModifyFocus != null) { |
| 2851 | + Clazz.removeEvent(textInput, "focus", hModifyFocus); |
| 2852 | + hModifyFocus = null; |
2764 | 2853 | }
|
| 2854 | + if (hModifyKeyUp != null) { |
| 2855 | + Clazz.removeEvent(textInput, "change", hModifyKeyUp); |
| 2856 | + Clazz.removeEvent(textInput, "keyup", hModifyKeyUp); |
| 2857 | + hModifyKeyUp = null; |
| 2858 | + } |
| 2859 | + |
2765 | 2860 | Clazz.removeEvent(textInput, "dblclick", hEditShow);
|
2766 | 2861 | hEditShow = null;
|
2767 | 2862 | Clazz.removeEvent(textInput, "keyup", hEditKeyUp);
|
|
0 commit comments