comparison dwt/widgets/Spinner.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents ab60f3309436
children e2affbeb686d
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
30 30
31 import dwt.dwthelper.utils; 31 import dwt.dwthelper.utils;
32 import tango.text.convert.Integer : toString; 32 import tango.text.convert.Integer : toString;
33 static import tango.text.Text; 33 static import tango.text.Text;
34 alias tango.text.Text.Text!(char) StringBuffer; 34 alias tango.text.Text.Text!(char) StringBuffer;
35 import tango.util.Convert;
35 36
36 /** 37 /**
37 * Instances of this class are selectable user interface 38 * Instances of this class are selectable user interface
38 * objects that allow the user to enter and modify numeric 39 * objects that allow the user to enter and modify numeric
39 * values. 40 * values.
84 OS.GetClassInfo (null, UpDownClass.ptr, &lpWndClass); 85 OS.GetClassInfo (null, UpDownClass.ptr, &lpWndClass);
85 UpDownProc = lpWndClass.lpfnWndProc; 86 UpDownProc = lpWndClass.lpfnWndProc;
86 static_this_completed = true; 87 static_this_completed = true;
87 } 88 }
88 } 89 }
89 90 /**
91 * the operating system limit for the number of characters
92 * that the text field in an instance of this class can hold
93 *
94 * @since 3.4
95 */
96 public static int LIMIT;
97
98 /*
99 * These values can be different on different platforms.
100 * Therefore they are not initialized in the declaration
101 * to stop the compiler from inlining.
102 */
103 static this() {
104 LIMIT = OS.IsWinNT ? 0x7FFFFFFF : 0x7FFF;
105 }
90 106
91 /** 107 /**
92 * Constructs a new instance of this class given its parent 108 * Constructs a new instance of this class given its parent
93 * and a style value describing its behavior and appearance. 109 * and a style value describing its behavior and appearance.
94 * <p> 110 * <p>
171 handle, 187 handle,
172 null, 188 null,
173 hInstance, 189 hInstance,
174 null); 190 null);
175 if (hwndText is null) error (DWT.ERROR_NO_HANDLES); 191 if (hwndText is null) error (DWT.ERROR_NO_HANDLES);
176 OS.SetWindowLong (hwndText, OS.GWL_ID, cast(int) hwndText); 192 OS.SetWindowLongPtr (hwndText, OS.GWLP_ID, cast(LONG_PTR)hwndText);
177 int upDownStyle = OS.WS_CHILD | OS.WS_VISIBLE | OS.UDS_AUTOBUDDY; 193 int upDownStyle = OS.WS_CHILD | OS.WS_VISIBLE | OS.UDS_AUTOBUDDY;
178 if ((style & DWT.WRAP) !is 0) upDownStyle |= OS.UDS_WRAP; 194 if ((style & DWT.WRAP) !is 0) upDownStyle |= OS.UDS_WRAP;
179 if ((style & DWT.BORDER) !is 0) { 195 if ((style & DWT.BORDER) !is 0) {
180 if ((style & DWT.RIGHT_TO_LEFT) !is 0) { 196 if ((style & DWT.RIGHT_TO_LEFT) !is 0) {
181 upDownStyle |= OS.UDS_ALIGNLEFT; 197 upDownStyle |= OS.UDS_ALIGNLEFT;
194 hInstance, 210 hInstance,
195 null); 211 null);
196 if (hwndUpDown is null) error (DWT.ERROR_NO_HANDLES); 212 if (hwndUpDown is null) error (DWT.ERROR_NO_HANDLES);
197 int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE; 213 int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE;
198 SetWindowPos (hwndText, hwndUpDown, 0, 0, 0, 0, flags); 214 SetWindowPos (hwndText, hwndUpDown, 0, 0, 0, 0, flags);
199 OS.SetWindowLong (hwndUpDown, OS.GWL_ID, cast(int) hwndUpDown); 215 OS.SetWindowLongPtr (hwndUpDown, OS.GWLP_ID, cast(LONG_PTR)hwndUpDown);
200 if (OS.IsDBLocale) { 216 if (OS.IsDBLocale) {
201 auto hIMC = OS.ImmGetContext (handle); 217 auto hIMC = OS.ImmGetContext (handle);
202 OS.ImmAssociateContext (hwndText, hIMC); 218 OS.ImmAssociateContext (hwndText, hIMC);
203 OS.ImmAssociateContext (hwndUpDown, hIMC); 219 OS.ImmAssociateContext (hwndUpDown, hIMC);
204 OS.ImmReleaseContext (handle, hIMC); 220 OS.ImmReleaseContext (handle, hIMC);
363 * The preferred height of a single-line text widget 379 * The preferred height of a single-line text widget
364 * has been hand-crafted to be the same height as 380 * has been hand-crafted to be the same height as
365 * the single-line text widget in an editable combo 381 * the single-line text widget in an editable combo
366 * box. 382 * box.
367 */ 383 */
368 int margins = OS.SendMessage (hwndText, OS.EM_GETMARGINS, 0, 0); 384 int /*long*/ margins = OS.SendMessage (hwndText, OS.EM_GETMARGINS, 0, 0);
369 x -= margins & 0xFFFF; 385 x -= OS.LOWORD (margins);
370 width += (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF); 386 width += OS.LOWORD (margins) + OS.HIWORD (margins);
371 if ((style & DWT.BORDER) !is 0) { 387 if ((style & DWT.BORDER) !is 0) {
372 x -= 1; 388 x -= 1;
373 y -= 1; 389 y -= 1;
374 width += 2; 390 width += 2;
375 height += 2; 391 height += 2;
536 * </ul> 552 * </ul>
537 */ 553 */
538 public int getSelection () { 554 public int getSelection () {
539 checkWidget (); 555 checkWidget ();
540 static if (OS.IsWinCE) { 556 static if (OS.IsWinCE) {
541 return OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0) & 0xFFFF; 557 return OS.LOWORD (OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0));
542 } else { 558 } else {
543 return OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0); 559 return OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
544 } 560 }
545 } 561 }
546 562
547 int getSelectionText () { 563 int getSelectionText (bool [] parseFail) {
548 int length_ = OS.GetWindowTextLength (hwndText); 564 int length_ = OS.GetWindowTextLength (hwndText);
549 TCHAR[] buffer = NewTCHARs (getCodePage (), length_ + 1); 565 TCHAR[] buffer = NewTCHARs (getCodePage (), length_ + 1);
550 OS.GetWindowText (hwndText, buffer.ptr, length_ + 1); 566 OS.GetWindowText (hwndText, buffer.ptr, length_ + 1);
551 String string = TCHARsToStr( buffer[ 0 .. length_] ); 567 String string = TCHARsToStr( buffer[ 0 .. length_] );
552 try { 568 try {
553 int value; 569 int value;
554 if (digits > 0) { 570 if (digits > 0) {
555 String decimalSeparator = getDecimalSeparator (); 571 String decimalSeparator = getDecimalSeparator ();
556 int index = string.indexOf (decimalSeparator); 572 int index = string.indexOf (decimalSeparator);
557 if (index !is -1) { 573 if (index !is -1) {
558 String wholePart = string.substring (0, index); 574 int startIndex = string.startsWith ("+") || string.startsWith ("-") ? 1 : 0;
575 String wholePart = startIndex !is index ? string.substring (startIndex, index) : "0";
559 String decimalPart = string.substring (index + 1); 576 String decimalPart = string.substring (index + 1);
560 if (decimalPart.length > digits) { 577 if (decimalPart.length > digits) {
561 decimalPart = decimalPart.substring (0, digits); 578 decimalPart = decimalPart.substring (0, digits);
562 } else { 579 } else {
563 int i = digits - decimalPart.length; 580 int i = digits - decimalPart.length;
567 } 584 }
568 int wholeValue = Integer.parseInt (wholePart); 585 int wholeValue = Integer.parseInt (wholePart);
569 int decimalValue = Integer.parseInt (decimalPart); 586 int decimalValue = Integer.parseInt (decimalPart);
570 for (int i = 0; i < digits; i++) wholeValue *= 10; 587 for (int i = 0; i < digits; i++) wholeValue *= 10;
571 value = wholeValue + decimalValue; 588 value = wholeValue + decimalValue;
589 if (string.startsWith ("-")) value = -value;
572 } else { 590 } else {
573 value = Integer.parseInt (string); 591 value = Integer.parseInt (string);
592 for (int i = 0; i < digits; i++) value *= 10;
574 } 593 }
575 } else { 594 } else {
576 value = Integer.parseInt (string); 595 value = Integer.parseInt (string);
577 } 596 }
578 int max, min; 597 int max, min;
579 OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, &min, &max); 598 OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, &min, &max);
580 if (min <= value && value <= max) return value; 599 if (min <= value && value <= max) return value;
581 } catch (NumberFormatException e) { 600 } catch (NumberFormatException e) {
582 } 601 }
602 parseFail [0] = true;
583 return -1; 603 return -1;
604 }
605
606 /**
607 * Returns a string containing a copy of the contents of the
608 * receiver's text field, or an empty string if there are no
609 * contents.
610 *
611 * @return the receiver's text
612 *
613 * @exception DWTException <ul>
614 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
615 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
616 * </ul>
617 *
618 * @since 3.4
619 */
620 public String getText () {
621 checkWidget ();
622 int length_ = OS.GetWindowTextLength (hwndText);
623 if (length_ is 0) return "";
624 TCHAR[] buffer = NewTCHARs (getCodePage (), length_ + 1);
625 OS.GetWindowText (hwndText, buffer.ptr, length_ + 1);
626 return TCHARsToStr( buffer[0 .. length_] );
627 }
628
629 /**
630 * Returns the maximum number of characters that the receiver's
631 * text field is capable of holding. If this has not been changed
632 * by <code>setTextLimit()</code>, it will be the constant
633 * <code>Spinner.LIMIT</code>.
634 *
635 * @return the text limit
636 *
637 * @exception DWTException <ul>
638 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
639 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
640 * </ul>
641 *
642 * @see #LIMIT
643 *
644 * @since 3.4
645 */
646 public int getTextLimit () {
647 checkWidget ();
648 return OS.SendMessage (hwndText, OS.EM_GETLIMITTEXT, 0, 0) & 0x7FFFFFFF;
584 } 649 }
585 650
586 int mbcsToWcsPos (int mbcsPos) { 651 int mbcsToWcsPos (int mbcsPos) {
587 if (mbcsPos <= 0) return 0; 652 if (mbcsPos <= 0) return 0;
588 if (OS.IsUnicode) return mbcsPos; 653 if (OS.IsUnicode) return mbcsPos;
815 if (value < 0) error (DWT.ERROR_INVALID_ARGUMENT); 880 if (value < 0) error (DWT.ERROR_INVALID_ARGUMENT);
816 if (value is this.digits) return; 881 if (value is this.digits) return;
817 this.digits = value; 882 this.digits = value;
818 int pos; 883 int pos;
819 static if (OS.IsWinCE) { 884 static if (OS.IsWinCE) {
820 pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0) & 0xFFFF; 885 pos = OS.LOWORD (OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0));
821 } else { 886 } else {
822 pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0); 887 pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
823 } 888 }
824 setSelection (pos, false, true, false); 889 setSelection (pos, false, true, false);
825 } 890 }
874 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 939 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
875 * </ul> 940 * </ul>
876 */ 941 */
877 public void setMaximum (int value) { 942 public void setMaximum (int value) {
878 checkWidget (); 943 checkWidget ();
879 if (value < 0) return;
880 int min; 944 int min;
881 OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, &min, null); 945 OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, &min, null);
882 if (value <= min) return; 946 if (value <= min) return;
883 int pos; 947 int pos;
884 static if (OS.IsWinCE) { 948 static if (OS.IsWinCE) {
885 pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0) & 0xFFFF; 949 pos = OS.LOWORD (OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0));
886 } else { 950 } else {
887 pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0); 951 pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
888 } 952 }
889 OS.SendMessage (hwndUpDown , OS.UDM_SETRANGE32, min, value); 953 OS.SendMessage (hwndUpDown , OS.UDM_SETRANGE32, min, value);
890 if (pos > value) setSelection (value, true, true, false); 954 if (pos > value) setSelection (value, true, true, false);
891 } 955 }
892 956
893 /** 957 /**
894 * Sets the minimum value that the receiver will allow. This new 958 * Sets the minimum value that the receiver will allow. This new
895 * value will be ignored if it is negative or is not less than the receiver's 959 * value will be ignored if it is not less than the receiver's
896 * current maximum value. If the new minimum is applied then the receiver's 960 * current maximum value. If the new minimum is applied then the receiver's
897 * selection value will be adjusted if necessary to fall within its new range. 961 * selection value will be adjusted if necessary to fall within its new range.
898 * 962 *
899 * @param value the new minimum, which must be nonnegative and less than the current maximum 963 * @param value the new minimum, which must be less than the current maximum
900 * 964 *
901 * @exception DWTException <ul> 965 * @exception DWTException <ul>
902 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 966 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
903 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 967 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
904 * </ul> 968 * </ul>
905 */ 969 */
906 public void setMinimum (int value) { 970 public void setMinimum (int value) {
907 checkWidget (); 971 checkWidget ();
908 if (value < 0) return;
909 int max; 972 int max;
910 OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, null, &max); 973 OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, null, &max);
911 if (value >= max) return; 974 if (value >= max) return;
912 int pos; 975 int pos;
913 static if (OS.IsWinCE) { 976 static if (OS.IsWinCE) {
914 pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0) & 0xFFFF; 977 pos = OS.LOWORD (OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0));
915 } else { 978 } else {
916 pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0); 979 pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
917 } 980 }
918 OS.SendMessage (hwndUpDown , OS.UDM_SETRANGE32, value, max); 981 OS.SendMessage (hwndUpDown , OS.UDM_SETRANGE32, value, max);
919 if (pos < value) setSelection (value, true, true, false); 982 if (pos < value) setSelection (value, true, true, false);
961 void setSelection (int value, bool setPos, bool setText, bool notify) { 1024 void setSelection (int value, bool setPos, bool setText, bool notify) {
962 if (setPos) { 1025 if (setPos) {
963 OS.SendMessage (hwndUpDown , OS.IsWinCE ? OS.UDM_SETPOS : OS.UDM_SETPOS32, 0, value); 1026 OS.SendMessage (hwndUpDown , OS.IsWinCE ? OS.UDM_SETPOS : OS.UDM_SETPOS32, 0, value);
964 } 1027 }
965 if (setText) { 1028 if (setText) {
966 String string = .toString( value ); 1029 String string;
967 if (digits > 0) { 1030 if (digits is 0) {
1031 string = .toString (value);
1032 } else {
1033 string = to!(String)(Math.abs (value));
968 String decimalSeparator = getDecimalSeparator (); 1034 String decimalSeparator = getDecimalSeparator ();
969 int index = string.length - digits; 1035 int index = string.length - digits;
970 StringBuffer buffer = new StringBuffer (); 1036 StringBuffer buffer = new StringBuffer ();
1037 if (value < 0) buffer.append ("-");
971 if (index > 0) { 1038 if (index > 0) {
972 buffer.append (string.substring (0, index)); 1039 buffer.append (string.substring (0, index));
973 buffer.append (decimalSeparator); 1040 buffer.append (decimalSeparator);
974 buffer.append (string.substring (index)); 1041 buffer.append (string.substring (index));
975 } else { 1042 } else {
985 string = verifyText (string, 0, length_, null); 1052 string = verifyText (string, 0, length_, null);
986 if (string is null) return; 1053 if (string is null) return;
987 } 1054 }
988 TCHAR* buffer = StrToTCHARz (getCodePage (), string); 1055 TCHAR* buffer = StrToTCHARz (getCodePage (), string);
989 OS.SetWindowText (hwndText, buffer); 1056 OS.SetWindowText (hwndText, buffer);
1057 OS.SendMessage (hwndText, OS.EM_SETSEL, 0, -1);
1058 if (!OS.IsWinCE) {
1059 OS.NotifyWinEvent (OS.EVENT_OBJECT_FOCUS, hwndText, OS.OBJID_CLIENT, 0);
1060 }
990 } 1061 }
991 if (notify) postEvent (DWT.Selection); 1062 if (notify) postEvent (DWT.Selection);
1063 }
1064
1065 /**
1066 * Sets the maximum number of characters that the receiver's
1067 * text field is capable of holding to be the argument.
1068 * <p>
1069 * To reset this value to the default, use <code>setTextLimit(Spinner.LIMIT)</code>.
1070 * Specifying a limit value larger than <code>Spinner.LIMIT</code> sets the
1071 * receiver's limit to <code>Spinner.LIMIT</code>.
1072 * </p>
1073 * @param limit new text limit
1074 *
1075 * @exception IllegalArgumentException <ul>
1076 * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li>
1077 * </ul>
1078 * @exception DWTException <ul>
1079 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1080 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1081 * </ul>
1082 *
1083 * @see #LIMIT
1084 *
1085 * @since 3.4
1086 */
1087 public void setTextLimit (int limit) {
1088 checkWidget ();
1089 if (limit is 0) error (DWT.ERROR_CANNOT_BE_ZERO);
1090 OS.SendMessage (hwndText, OS.EM_SETLIMITTEXT, limit, 0);
992 } 1091 }
993 1092
994 override void setToolTipText (Shell shell, String string) { 1093 override void setToolTipText (Shell shell, String string) {
995 shell.setToolTipText (hwndText, string); 1094 shell.setToolTipText (hwndText, string);
996 shell.setToolTipText (hwndUpDown, string); 1095 shell.setToolTipText (hwndUpDown, string);
1019 * 1118 *
1020 * @since 3.2 1119 * @since 3.2
1021 */ 1120 */
1022 public void setValues (int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) { 1121 public void setValues (int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) {
1023 checkWidget (); 1122 checkWidget ();
1024 if (minimum < 0) return;
1025 if (maximum <= minimum) return; 1123 if (maximum <= minimum) return;
1026 if (digits < 0) return; 1124 if (digits < 0) return;
1027 if (increment < 1) return; 1125 if (increment < 1) return;
1028 if (pageIncrement < 1) return; 1126 if (pageIncrement < 1) return;
1029 selection = Math.min (Math.max (minimum, selection), maximum); 1127 selection = Math.min (Math.max (minimum, selection), maximum);
1034 setSelection (selection, true, true, false); 1132 setSelection (selection, true, true, false);
1035 } 1133 }
1036 1134
1037 override void subclass () { 1135 override void subclass () {
1038 super.subclass (); 1136 super.subclass ();
1039 int newProc = display.windowProc; 1137 int /*long*/ newProc = display.windowProc;
1040 OS.SetWindowLong (hwndText, OS.GWL_WNDPROC, newProc); 1138 OS.SetWindowLongPtr (hwndText, OS.GWLP_WNDPROC, newProc);
1041 OS.SetWindowLong (hwndUpDown, OS.GWL_WNDPROC, newProc); 1139 OS.SetWindowLongPtr (hwndUpDown, OS.GWLP_WNDPROC, newProc);
1042 } 1140 }
1043 1141
1044 override void unsubclass () { 1142 override void unsubclass () {
1045 super.unsubclass (); 1143 super.unsubclass ();
1046 OS.SetWindowLong (hwndText, OS.GWL_WNDPROC, cast(int) EditProc); 1144 OS.SetWindowLongPtr (hwndText, OS.GWLP_WNDPROC, cast(LONG_PTR)EditProc);
1047 OS.SetWindowLong (hwndUpDown, OS.GWL_WNDPROC, cast(int) UpDownProc); 1145 OS.SetWindowLongPtr (hwndUpDown, OS.GWLP_WNDPROC, cast(LONG_PTR)UpDownProc);
1048 } 1146 }
1049 1147
1050 String verifyText (String string, int start, int end, Event keyEvent) { 1148 String verifyText (String string, int start, int end, Event keyEvent) {
1051 Event event = new Event (); 1149 Event event = new Event ();
1052 event.text = string; 1150 event.text = string;
1063 index = string.indexOf (decimalSeparator); 1161 index = string.indexOf (decimalSeparator);
1064 if (index !is -1) { 1162 if (index !is -1) {
1065 string = string.substring (0, index) ~ string.substring (index + 1); 1163 string = string.substring (0, index) ~ string.substring (index + 1);
1066 } 1164 }
1067 index = 0; 1165 index = 0;
1166 }
1167 if (string.length > 0) {
1168 int min;
1169 OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, &min, null);
1170 if (min < 0 && string.charAt (0) is '-') index++;
1068 } 1171 }
1069 while (index < string.length ) { 1172 while (index < string.length ) {
1070 if (!CharacterIsDigit (string.charAt (index))) break; 1173 if (!CharacterIsDigit (string.charAt (index))) break;
1071 index++; 1174 index++;
1072 } 1175 }
1155 return null; 1258 return null;
1156 } 1259 }
1157 1260
1158 override LRESULT WM_SETFOCUS (int wParam, int lParam) { 1261 override LRESULT WM_SETFOCUS (int wParam, int lParam) {
1159 OS.SetFocus (hwndText); 1262 OS.SetFocus (hwndText);
1263 OS.SendMessage (hwndText, OS.EM_SETSEL, 0, -1);
1160 return null; 1264 return null;
1161 } 1265 }
1162 1266
1163 override LRESULT WM_SETFONT (int wParam, int lParam) { 1267 override LRESULT WM_SETFONT (int wParam, int lParam) {
1164 LRESULT result = super.WM_SETFONT (wParam, lParam); 1268 LRESULT result = super.WM_SETFONT (wParam, lParam);
1168 } 1272 }
1169 1273
1170 override LRESULT WM_SIZE (int wParam, int lParam) { 1274 override LRESULT WM_SIZE (int wParam, int lParam) {
1171 LRESULT result = super.WM_SIZE (wParam, lParam); 1275 LRESULT result = super.WM_SIZE (wParam, lParam);
1172 if (isDisposed ()) return result; 1276 if (isDisposed ()) return result;
1173 int width = lParam & 0xFFFF, height = lParam >> 16; 1277 int width = OS.LOWORD (lParam), height = OS.HIWORD (lParam);
1174 int upDownWidth = OS.GetSystemMetrics (OS.SM_CXVSCROLL); 1278 int upDownWidth = OS.GetSystemMetrics (OS.SM_CXVSCROLL);
1175 int textWidth = width - upDownWidth; 1279 int textWidth = width - upDownWidth;
1176 int border = OS.GetSystemMetrics (OS.SM_CXEDGE); 1280 int border = OS.GetSystemMetrics (OS.SM_CXEDGE);
1177 int flags = OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE; 1281 int flags = OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE;
1178 SetWindowPos (hwndText, null, 0, 0, textWidth + border, height, flags); 1282 SetWindowPos (hwndText, null, 0, 0, textWidth + border, height, flags);
1267 } 1371 }
1268 return null; 1372 return null;
1269 } 1373 }
1270 1374
1271 override LRESULT wmCommandChild (int wParam, int lParam) { 1375 override LRESULT wmCommandChild (int wParam, int lParam) {
1272 int code = wParam >> 16; 1376 int code = OS.HIWORD (wParam);
1273 switch (code) { 1377 switch (code) {
1274 case OS.EN_CHANGE: 1378 case OS.EN_CHANGE:
1275 if (ignoreModify) break; 1379 if (ignoreModify) break;
1276 int value = getSelectionText (); 1380 bool [] parseFail = new bool [1];
1277 if (value !is -1) { 1381 int value = getSelectionText (parseFail);
1382 if (!parseFail [0]) {
1278 int pos; 1383 int pos;
1279 static if (OS.IsWinCE) { 1384 static if (OS.IsWinCE) {
1280 pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0) & 0xFFFF; 1385 pos = OS.LOWORD (OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0));
1281 } else { 1386 } else {
1282 pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0); 1387 pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
1283 } 1388 }
1284 if (pos !is value) setSelection (value, true, false, true); 1389 if (pos !is value) setSelection (value, true, false, true);
1285 } 1390 }
1305 case OS.VK_PRIOR: delta = pageIncrement; break; 1410 case OS.VK_PRIOR: delta = pageIncrement; break;
1306 case OS.VK_NEXT: delta = -pageIncrement; break; 1411 case OS.VK_NEXT: delta = -pageIncrement; break;
1307 default: 1412 default:
1308 } 1413 }
1309 if (delta !is 0) { 1414 if (delta !is 0) {
1310 int value = getSelectionText (); 1415 bool [1] parseFail;
1311 if (value !is -1) { 1416 int value = getSelectionText (parseFail);
1417 if (parseFail [0]) {
1312 static if (OS.IsWinCE) { 1418 static if (OS.IsWinCE) {
1313 value = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0) & 0xFFFF; 1419 value = OS.LOWORD (OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0));
1314 } else { 1420 } else {
1315 value = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0); 1421 value = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
1316 } 1422 }
1317 } 1423 }
1318 int newValue = value + delta; 1424 int newValue = value + delta;
1335 } 1441 }
1336 return result; 1442 return result;
1337 } 1443 }
1338 1444
1339 override LRESULT wmKillFocus (HWND hwnd, int wParam, int lParam) { 1445 override LRESULT wmKillFocus (HWND hwnd, int wParam, int lParam) {
1340 int value = getSelectionText (); 1446 bool [1] parseFail;
1341 if (value is -1) { 1447 int value = getSelectionText (parseFail);
1448 if (parseFail [0]) {
1342 static if (OS.IsWinCE) { 1449 static if (OS.IsWinCE) {
1343 value = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0) & 0xFFFF; 1450 value = OS.LOWORD (OS.SendMessage (hwndUpDown, OS.UDM_GETPOS, 0, 0));
1344 } else { 1451 } else {
1345 value = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0); 1452 value = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0);
1346 } 1453 }
1347 setSelection (value, false, true, false); 1454 setSelection (value, false, true, false);
1348 } 1455 }
1378 } 1485 }
1379 return super.wmNotifyChild (hdr, wParam, lParam); 1486 return super.wmNotifyChild (hdr, wParam, lParam);
1380 } 1487 }
1381 1488
1382 override LRESULT wmScrollChild (int wParam, int lParam) { 1489 override LRESULT wmScrollChild (int wParam, int lParam) {
1383 int code = wParam & 0xFFFF; 1490 int code = OS.LOWORD (wParam);
1384 switch (code) { 1491 switch (code) {
1385 case OS.SB_THUMBPOSITION: 1492 case OS.SB_THUMBPOSITION:
1386 postEvent (DWT.Selection); 1493 postEvent (DWT.Selection);
1387 break; 1494 break;
1388 default: 1495 default: