Changeset 65:66203354c9d3
- Timestamp:
- 02/04/08 09:39:21
(1 year ago)
- Author:
- Frank Benoit <benoit@tionex.de>
- branch:
- default
- Message:
Spinner
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r57 |
r65 |
|
| 63 | 63 | return tango.text.Unicode.isWhitespace( c ); |
|---|
| 64 | 64 | } |
|---|
| | 65 | bool CharacterIsDigit( dchar c ){ |
|---|
| | 66 | return tango.text.Unicode.isDigit( c ); |
|---|
| | 67 | } |
|---|
| 65 | 68 | |
|---|
| 66 | 69 | public int indexOf( char[] str, char searched ){ |
|---|
| … | … | |
| 74 | 77 | if( res is str.length ) res = -1; |
|---|
| 75 | 78 | return res; |
|---|
| | 79 | } |
|---|
| | 80 | |
|---|
| | 81 | public int indexOf(char[] str, char[] ch){ |
|---|
| | 82 | return indexOf( str, ch, 0 ); |
|---|
| 76 | 83 | } |
|---|
| 77 | 84 | |
|---|
| r63 |
r65 |
|
| 1888 | 1888 | public static const int UISF_HIDEACCEL = 0x2; |
|---|
| 1889 | 1889 | public static const int UISF_HIDEFOCUS = 0x1; |
|---|
| 1890 | | public static const char[] UPDOWN_CLASS = "msctls_updown32"; //$NON-NLS-1$ |
|---|
| | 1890 | public static const TCHAR[] UPDOWN_CLASS = "msctls_updown32"; //$NON-NLS-1$ |
|---|
| 1891 | 1891 | public static const int USP_E_SCRIPT_NOT_IN_FONT = 0x80040200; |
|---|
| 1892 | 1892 | public static const int VERTRES = 0xa; |
|---|
| r54 |
r65 |
|
| 11 | 11 | module dwt.widgets.Spinner; |
|---|
| 12 | 12 | |
|---|
| 13 | | import dwt.widgets.Composite; |
|---|
| 14 | | class Spinner : Composite { |
|---|
| 15 | | } |
|---|
| 16 | | /++ |
|---|
| 17 | 13 | import dwt.DWT; |
|---|
| 18 | 14 | import dwt.DWTException; |
|---|
| … | … | |
| 23 | 19 | import dwt.graphics.Point; |
|---|
| 24 | 20 | import dwt.graphics.Rectangle; |
|---|
| 25 | | import dwt.internal.win32.LRESULT; |
|---|
| 26 | | import dwt.internal.win32.NMHDR; |
|---|
| 27 | | import dwt.internal.win32.NMUPDOWN; |
|---|
| 28 | 21 | import dwt.internal.win32.OS; |
|---|
| 29 | | import dwt.internal.win32.RECT; |
|---|
| 30 | | import dwt.internal.win32.TCHAR; |
|---|
| 31 | | import dwt.internal.win32.TEXTMETRIC; |
|---|
| 32 | | import dwt.internal.win32.TEXTMETRICA; |
|---|
| 33 | | import dwt.internal.win32.TEXTMETRICW; |
|---|
| 34 | | import dwt.internal.win32.UDACCEL; |
|---|
| 35 | | import dwt.internal.win32.WNDCLASS; |
|---|
| | 22 | |
|---|
| | 23 | import dwt.widgets.Composite; |
|---|
| | 24 | import dwt.widgets.TypedListener; |
|---|
| | 25 | import dwt.widgets.Event; |
|---|
| | 26 | import dwt.widgets.Shell; |
|---|
| | 27 | |
|---|
| | 28 | |
|---|
| | 29 | import dwt.dwthelper.utils; |
|---|
| | 30 | import dwt.dwthelper.Integer; |
|---|
| | 31 | import tango.text.convert.Integer : toString; |
|---|
| | 32 | static import tango.text.Text; |
|---|
| | 33 | alias tango.text.Text.Text!(char) StringBuffer; |
|---|
| 36 | 34 | |
|---|
| 37 | 35 | /** |
|---|
| … | … | |
| 55 | 53 | * @since 3.1 |
|---|
| 56 | 54 | */ |
|---|
| 57 | | public class Spinner extends Composite { |
|---|
| | 55 | public class Spinner : Composite { |
|---|
| 58 | 56 | |
|---|
| 59 | 57 | alias Composite.computeSize computeSize; |
|---|
| … | … | |
| 63 | 61 | alias Composite.windowProc windowProc; |
|---|
| 64 | 62 | |
|---|
| 65 | | int hwndText, hwndUpDown; |
|---|
| | 63 | HWND hwndText, hwndUpDown; |
|---|
| 66 | 64 | bool ignoreModify; |
|---|
| 67 | 65 | int pageIncrement, digits; |
|---|
| 68 | | static final int EditProc; |
|---|
| 69 | | static final TCHAR EditClass = new TCHAR (0, "EDIT", true); |
|---|
| 70 | | static final int UpDownProc; |
|---|
| 71 | | static final TCHAR UpDownClass = new TCHAR (0, OS.UPDOWN_CLASS, true); |
|---|
| 72 | | static { |
|---|
| 73 | | WNDCLASS lpWndClass = new WNDCLASS (); |
|---|
| 74 | | OS.GetClassInfo (0, EditClass, lpWndClass); |
|---|
| | 66 | static const WNDPROC EditProc; |
|---|
| | 67 | static const TCHAR[] EditClass = "EDIT"; |
|---|
| | 68 | static const WNDPROC UpDownProc; |
|---|
| | 69 | static const TCHAR[] UpDownClass = OS.UPDOWN_CLASS; |
|---|
| | 70 | static this() { |
|---|
| | 71 | WNDCLASS lpWndClass; |
|---|
| | 72 | OS.GetClassInfo (null, EditClass.ptr, &lpWndClass); |
|---|
| 75 | 73 | EditProc = lpWndClass.lpfnWndProc; |
|---|
| 76 | | OS.GetClassInfo (0, UpDownClass, lpWndClass); |
|---|
| | 74 | OS.GetClassInfo (null, UpDownClass.ptr, &lpWndClass); |
|---|
| 77 | 75 | UpDownProc = lpWndClass.lpfnWndProc; |
|---|
| 78 | 76 | } |
|---|
| … | … | |
| 107 | 105 | * @see Widget#getStyle |
|---|
| 108 | 106 | */ |
|---|
| 109 | | public Spinner (Composite parent, int style) { |
|---|
| | 107 | public this (Composite parent, int style) { |
|---|
| 110 | 108 | super (parent, checkStyle (style)); |
|---|
| 111 | 109 | } |
|---|
| 112 | 110 | |
|---|
| 113 | | override int callWindowProc (int hwnd, int msg, int wParam, int lParam) { |
|---|
| 114 | | if (handle is 0) return 0; |
|---|
| | 111 | override LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { |
|---|
| | 112 | if (handle is null) return LRESULT.ZERO; |
|---|
| 115 | 113 | if (hwnd is hwndText) { |
|---|
| 116 | | return OS.CallWindowProc (EditProc, hwnd, msg, wParam, lParam); |
|---|
| | 114 | return cast(LRESULT) OS.CallWindowProc (EditProc, hwnd, msg, wParam, lParam); |
|---|
| 117 | 115 | } |
|---|
| 118 | 116 | if (hwnd is hwndUpDown) { |
|---|
| 119 | | return OS.CallWindowProc (UpDownProc, hwnd, msg, wParam, lParam); |
|---|
| 120 | | } |
|---|
| 121 | | return OS.DefWindowProc (handle, msg, wParam, lParam); |
|---|
| | 117 | return cast(LRESULT) OS.CallWindowProc (UpDownProc, hwnd, msg, wParam, lParam); |
|---|
| | 118 | } |
|---|
| | 119 | return cast(LRESULT) OS.DefWindowProc (handle, msg, wParam, lParam); |
|---|
| 122 | 120 | } |
|---|
| 123 | 121 | |
|---|
| … | … | |
| 133 | 131 | } |
|---|
| 134 | 132 | |
|---|
| 135 | | override bool checkHandle (int hwnd) { |
|---|
| | 133 | override bool checkHandle (HWND hwnd) { |
|---|
| 136 | 134 | return hwnd is handle || hwnd is hwndText || hwnd is hwndUpDown; |
|---|
| 137 | 135 | } |
|---|
| … | … | |
| 144 | 142 | super.createHandle (); |
|---|
| 145 | 143 | state &= ~(CANVAS | THEME_BACKGROUND); |
|---|
| 146 | | int hInstance = OS.GetModuleHandle (null); |
|---|
| | 144 | auto hInstance = OS.GetModuleHandle (null); |
|---|
| 147 | 145 | int textExStyle = (style & DWT.BORDER) !is 0 ? OS.WS_EX_CLIENTEDGE : 0; |
|---|
| 148 | 146 | int textStyle = OS.WS_CHILD | OS.WS_VISIBLE | OS.ES_AUTOHSCROLL | OS.WS_CLIPSIBLINGS; |
|---|
| … | … | |
| 153 | 151 | hwndText = OS.CreateWindowEx ( |
|---|
| 154 | 152 | textExStyle, |
|---|
| 155 | | EditClass, |
|---|
| | 153 | EditClass.ptr, |
|---|
| 156 | 154 | null, |
|---|
| 157 | 155 | textStyle, |
|---|
| 158 | 156 | 0, 0, 0, 0, |
|---|
| 159 | 157 | handle, |
|---|
| 160 | | 0, |
|---|
| | 158 | null, |
|---|
| 161 | 159 | hInstance, |
|---|
| 162 | 160 | null); |
|---|
| 163 | | if (hwndText is 0) error (DWT.ERROR_NO_HANDLES); |
|---|
| 164 | | OS.SetWindowLong (hwndText, OS.GWL_ID, hwndText); |
|---|
| | 161 | if (hwndText is null) error (DWT.ERROR_NO_HANDLES); |
|---|
| | 162 | OS.SetWindowLong (hwndText, OS.GWL_ID, cast(int) hwndText); |
|---|
| 165 | 163 | int upDownStyle = OS.WS_CHILD | OS.WS_VISIBLE | OS.UDS_AUTOBUDDY; |
|---|
| 166 | 164 | if ((style & DWT.WRAP) !is 0) upDownStyle |= OS.UDS_WRAP; |
|---|
| … | … | |
| 174 | 172 | hwndUpDown = OS.CreateWindowEx ( |
|---|
| 175 | 173 | 0, |
|---|
| 176 | | UpDownClass, |
|---|
| | 174 | UpDownClass.ptr, |
|---|
| 177 | 175 | null, |
|---|
| 178 | 176 | upDownStyle, |
|---|
| 179 | 177 | 0, 0, 0, 0, |
|---|
| 180 | 178 | handle, |
|---|
| 181 | | 0, |
|---|
| | 179 | null, |
|---|
| 182 | 180 | hInstance, |
|---|
| 183 | 181 | null); |
|---|
| 184 | | if (hwndUpDown is 0) error (DWT.ERROR_NO_HANDLES); |
|---|
| | 182 | if (hwndUpDown is null) error (DWT.ERROR_NO_HANDLES); |
|---|
| 185 | 183 | int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE; |
|---|
| 186 | 184 | SetWindowPos (hwndText, hwndUpDown, 0, 0, 0, 0, flags); |
|---|
| 187 | | OS.SetWindowLong (hwndUpDown, OS.GWL_ID, hwndUpDown); |
|---|
| | 185 | OS.SetWindowLong (hwndUpDown, OS.GWL_ID, cast(int) hwndUpDown); |
|---|
| 188 | 186 | if (OS.IsDBLocale) { |
|---|
| 189 | | int hIMC = OS.ImmGetContext (handle); |
|---|
| | 187 | auto hIMC = OS.ImmGetContext (handle); |
|---|
| 190 | 188 | OS.ImmAssociateContext (hwndText, hIMC); |
|---|
| 191 | 189 | OS.ImmAssociateContext (hwndUpDown, hIMC); |
|---|
| … | … | |
| 196 | 194 | pageIncrement = 10; |
|---|
| 197 | 195 | digits = 0; |
|---|
| 198 | | TCHAR buffer = new TCHAR (getCodePage (), "0", true); |
|---|
| | 196 | TCHAR* buffer = StrToTCHARz (getCodePage (), "0"); |
|---|
| 199 | 197 | OS.SetWindowText (hwndText, buffer); |
|---|
| 200 | 198 | } |
|---|
| … | … | |
| 284 | 282 | } |
|---|
| 285 | 283 | |
|---|
| 286 | | override int borderHandle () { |
|---|
| | 284 | override HWND borderHandle () { |
|---|
| 287 | 285 | return hwndText; |
|---|
| 288 | 286 | } |
|---|
| … | … | |
| 292 | 290 | int width = 0, height = 0; |
|---|
| 293 | 291 | if (wHint is DWT.DEFAULT || hHint is DWT.DEFAULT) { |
|---|
| 294 | | int newFont, oldFont = 0; |
|---|
| 295 | | int hDC = OS.GetDC (hwndText); |
|---|
| 296 | | newFont = OS.SendMessage (hwndText, OS.WM_GETFONT, 0, 0); |
|---|
| 297 | | if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| 298 | | TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA (); |
|---|
| 299 | | OS.GetTextMetrics (hDC, tm); |
|---|
| | 292 | HFONT newFont, oldFont; |
|---|
| | 293 | auto hDC = OS.GetDC (hwndText); |
|---|
| | 294 | newFont = cast(HFONT) OS.SendMessage (hwndText, OS.WM_GETFONT, 0, 0); |
|---|
| | 295 | if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| | 296 | TEXTMETRIC tm; |
|---|
| | 297 | OS.GetTextMetrics (hDC, &tm); |
|---|
| 300 | 298 | height = tm.tmHeight; |
|---|
| 301 | | RECT rect = new RECT (); |
|---|
| 302 | | int [] max = new int [1]; |
|---|
| 303 | | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, null, max); |
|---|
| 304 | | String string = String.valueOf (max [0]); |
|---|
| | 299 | RECT rect; |
|---|
| | 300 | int max; |
|---|
| | 301 | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, null, &max); |
|---|
| | 302 | char[] string = .toString( max ); |
|---|
| 305 | 303 | if (digits > 0) { |
|---|
| 306 | 304 | StringBuffer buffer = new StringBuffer (); |
|---|
| 307 | 305 | buffer.append (string); |
|---|
| 308 | 306 | buffer.append (getDecimalSeparator ()); |
|---|
| 309 | | int count = digits - string.length (); |
|---|
| | 307 | int count = digits - string.length; |
|---|
| 310 | 308 | while (count >= 0) { |
|---|
| 311 | 309 | buffer.append ("0"); |
|---|
| … | … | |
| 314 | 312 | string = buffer.toString (); |
|---|
| 315 | 313 | } |
|---|
| 316 | | TCHAR buffer = new TCHAR (getCodePage (), string, false); |
|---|
| | 314 | TCHAR[] buffer = StrToTCHARs (getCodePage (), string, false); |
|---|
| 317 | 315 | int flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_NOPREFIX; |
|---|
| 318 | | OS.DrawText (hDC, buffer, buffer.length (), rect, flags); |
|---|
| | 316 | OS.DrawText (hDC, buffer.ptr, buffer.length, &rect, flags); |
|---|
| 319 | 317 | width = rect.right - rect.left; |
|---|
| 320 | | if (newFont !is 0) OS.SelectObject (hDC, oldFont); |
|---|
| | 318 | if (newFont !is null ) OS.SelectObject (hDC, oldFont); |
|---|
| 321 | 319 | OS.ReleaseDC (hwndText, hDC); |
|---|
| 322 | 320 | } |
|---|
| … | … | |
| 340 | 338 | |
|---|
| 341 | 339 | /* Get the trim of the text control */ |
|---|
| 342 | | RECT rect = new RECT (); |
|---|
| 343 | | OS.SetRect (rect, x, y, x + width, y + height); |
|---|
| | 340 | RECT rect; |
|---|
| | 341 | OS.SetRect (&rect, x, y, x + width, y + height); |
|---|
| 344 | 342 | int bits0 = OS.GetWindowLong (hwndText, OS.GWL_STYLE); |
|---|
| 345 | 343 | int bits1 = OS.GetWindowLong (hwndText, OS.GWL_EXSTYLE); |
|---|
| 346 | | OS.AdjustWindowRectEx (rect, bits0, false, bits1); |
|---|
| | 344 | OS.AdjustWindowRectEx (&rect, bits0, false, bits1); |
|---|
| 347 | 345 | width = rect.right - rect.left; |
|---|
| 348 | 346 | height = rect.bottom - rect.top; |
|---|
| … | … | |
| 418 | 416 | |
|---|
| 419 | 417 | override bool hasFocus () { |
|---|
| 420 | | int hwndFocus = OS.GetFocus (); |
|---|
| | 418 | auto hwndFocus = OS.GetFocus (); |
|---|
| 421 | 419 | if (hwndFocus is handle) return true; |
|---|
| 422 | 420 | if (hwndFocus is hwndText) return true; |
|---|
| … | … | |
| 440 | 438 | } |
|---|
| 441 | 439 | |
|---|
| 442 | | String getDecimalSeparator () { |
|---|
| 443 | | TCHAR tchar = new TCHAR (getCodePage (), 4); |
|---|
| 444 | | int size = OS.GetLocaleInfo (OS.LOCALE_USER_DEFAULT, OS.LOCALE_SDECIMAL, tchar, 4); |
|---|
| 445 | | return size !is 0 ? tchar.toString (0, size - 1) : "."; |
|---|
| | 440 | char[] getDecimalSeparator () { |
|---|
| | 441 | TCHAR[] tchar = NewTCHARs (getCodePage (), 4); |
|---|
| | 442 | int size = OS.GetLocaleInfo (OS.LOCALE_USER_DEFAULT, OS.LOCALE_SDECIMAL, tchar.ptr, 4); |
|---|
| | 443 | return size !is 0 ? TCHARsToStr( tchar[0 .. size] ) : "."; |
|---|
| 446 | 444 | } |
|---|
| 447 | 445 | |
|---|
| … | … | |
| 459 | 457 | public int getIncrement () { |
|---|
| 460 | 458 | checkWidget (); |
|---|
| 461 | | UDACCEL udaccel = new UDACCEL (); |
|---|
| 462 | | OS.SendMessage (hwndUpDown, OS.UDM_GETACCEL, 1, udaccel); |
|---|
| | 459 | UDACCEL udaccel; |
|---|
| | 460 | OS.SendMessage (hwndUpDown, OS.UDM_GETACCEL, 1, &udaccel); |
|---|
| 463 | 461 | return udaccel.nInc; |
|---|
| 464 | 462 | } |
|---|
| … | … | |
| 476 | 474 | public int getMaximum () { |
|---|
| 477 | 475 | checkWidget (); |
|---|
| 478 | | int [] max = new int [1]; |
|---|
| 479 | | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, null, max); |
|---|
| 480 | | return max [0]; |
|---|
| | 476 | int max; |
|---|
| | 477 | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, null, &max); |
|---|
| | 478 | return max; |
|---|
| 481 | 479 | } |
|---|
| 482 | 480 | |
|---|
| … | … | |
| 493 | 491 | public int getMinimum () { |
|---|
| 494 | 492 | checkWidget (); |
|---|
| 495 | | int [] min = new int [1]; |
|---|
| 496 | | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, min, null); |
|---|
| 497 | | return min [0]; |
|---|
| | 493 | int min; |
|---|
| | 494 | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, &min, null); |
|---|
| | 495 | return min; |
|---|
| 498 | 496 | } |
|---|
| 499 | 497 | |
|---|
| … | … | |
| 534 | 532 | |
|---|
| 535 | 533 | int getSelectionText () { |
|---|
| 536 | | int length = OS.GetWindowTextLength (hwndText); |
|---|
| 537 | | TCHAR buffer = new TCHAR (getCodePage (), length + 1); |
|---|
| 538 | | OS.GetWindowText (hwndText, buffer, length + 1); |
|---|
| 539 | | String string = buffer.toString (0, length); |
|---|
| | 534 | int length_ = OS.GetWindowTextLength (hwndText); |
|---|
| | 535 | TCHAR[] buffer = NewTCHARs (getCodePage (), length_ + 1); |
|---|
| | 536 | OS.GetWindowText (hwndText, buffer.ptr, length_ + 1); |
|---|
| | 537 | char[] string = TCHARsToStr( buffer[ 0 .. length_] ); |
|---|
| 540 | 538 | try { |
|---|
| 541 | 539 | int value; |
|---|
| 542 | 540 | if (digits > 0) { |
|---|
| 543 | | String decimalSeparator = getDecimalSeparator (); |
|---|
| | 541 | char[] decimalSeparator = getDecimalSeparator (); |
|---|
| 544 | 542 | int index = string.indexOf (decimalSeparator); |
|---|
| 545 | 543 | if (index !is -1) { |
|---|
| 546 | | String wholePart = string.substring (0, index); |
|---|
| 547 | | String decimalPart = string.substring (index + 1); |
|---|
| 548 | | if (decimalPart.length () > digits) { |
|---|
| | 544 | char[] wholePart = string.substring (0, index); |
|---|
| | 545 | char[] decimalPart = string.substring (index + 1); |
|---|
| | 546 | if (decimalPart.length > digits) { |
|---|
| 549 | 547 | decimalPart = decimalPart.substring (0, digits); |
|---|
| 550 | 548 | } else { |
|---|
| 551 | | int i = digits - decimalPart.length (); |
|---|
| | 549 | int i = digits - decimalPart.length; |
|---|
| 552 | 550 | for (int j = 0; j < i; j++) { |
|---|
| 553 | | decimalPart = decimalPart + "0"; |
|---|
| | 551 | decimalPart = decimalPart ~ "0"; |
|---|
| 554 | 552 | } |
|---|
| 555 | 553 | } |
|---|
| … | … | |
| 564 | 562 | value = Integer.parseInt (string); |
|---|
| 565 | 563 | } |
|---|
| 566 | | int [] max = new int [1], min = new int [1]; |
|---|
| 567 | | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, min, max); |
|---|
| 568 | | if (min [0] <= value && value <= max [0]) return value; |
|---|
| | 564 | int max, min; |
|---|
| | 565 | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, &min, &max); |
|---|
| | 566 | if (min <= value && value <= max) return value; |
|---|
| 569 | 567 | } catch (NumberFormatException e) { |
|---|
| 570 | 568 | } |
|---|
| … | … | |
| 578 | 576 | if (mbcsSize is 0) return 0; |
|---|
| 579 | 577 | if (mbcsPos >= mbcsSize) return mbcsSize; |
|---|
| 580 | | byte [] buffer = new byte [mbcsSize + 1]; |
|---|
| 581 | | OS.GetWindowTextA (hwndText, buffer, mbcsSize + 1); |
|---|
| 582 | | return OS.MultiByteToWideChar (getCodePage (), OS.MB_PRECOMPOSED, buffer, mbcsPos, null, 0); |
|---|
| | 578 | char [] buffer = new char [mbcsSize + 1]; |
|---|
| | 579 | OS.GetWindowTextA (hwndText, buffer.ptr, mbcsSize + 1); |
|---|
| | 580 | return OS.MultiByteToWideChar (getCodePage (), OS.MB_PRECOMPOSED, buffer.ptr, mbcsPos, null, 0); |
|---|
| 583 | 581 | } |
|---|
| 584 | 582 | |
|---|
| … | … | |
| 609 | 607 | override void releaseHandle () { |
|---|
| 610 | 608 | super.releaseHandle (); |
|---|
| 611 | | hwndText = hwndUpDown = 0; |
|---|
| | 609 | hwndText = hwndUpDown = null; |
|---|
| 612 | 610 | } |
|---|
| 613 | 611 | |
|---|
| … | … | |
| 721 | 719 | |
|---|
| 722 | 720 | /* Verify the character */ |
|---|
| 723 | | String oldText = ""; |
|---|
| 724 | | int [] start = new int [1], end = new int [1]; |
|---|
| 725 | | OS.SendMessage (hwndText, OS.EM_GETSEL, start, end); |
|---|
| | 721 | char[] oldText = ""; |
|---|
| | 722 | int start, end; |
|---|
| | 723 | OS.SendMessage (hwndText, OS.EM_GETSEL, &start, &end); |
|---|
| 726 | 724 | switch (key) { |
|---|
| 727 | 725 | case 0x08: /* Bs */ |
|---|
| 728 | | if (start [0] is end [0]) { |
|---|
| 729 | | if (start [0] is 0) return true; |
|---|
| 730 | | start [0] = start [0] - 1; |
|---|
| | 726 | if (start is end) { |
|---|
| | 727 | if (start is 0) return true; |
|---|
| | 728 | start = start - 1; |
|---|
| 731 | 729 | if (!OS.IsUnicode && OS.IsDBLocale) { |
|---|
| 732 | | int [] newStart = new int [1], newEnd = new int [1]; |
|---|
| 733 | | OS.SendMessage (hwndText, OS.EM_SETSEL, start [0], end [0]); |
|---|
| 734 | | OS.SendMessage (hwndText, OS.EM_GETSEL, newStart, newEnd); |
|---|
| 735 | | if (start [0] !is newStart [0]) start [0] = start [0] - 1; |
|---|
| | 730 | int newStart, newEnd; |
|---|
| | 731 | OS.SendMessage (hwndText, OS.EM_SETSEL, start, end); |
|---|
| | 732 | OS.SendMessage (hwndText, OS.EM_GETSEL, &newStart, &newEnd); |
|---|
| | 733 | if (start !is newStart) start = start - 1; |
|---|
| 736 | 734 | } |
|---|
| 737 | | start [0] = Math.max (start [0], 0); |
|---|
| | 735 | start = Math.max (start, 0); |
|---|
| 738 | 736 | } |
|---|
| 739 | 737 | break; |
|---|
| 740 | 738 | case 0x7F: /* Del */ |
|---|
| 741 | | if (start [0] is end [0]) { |
|---|
| 742 | | int length = OS.GetWindowTextLength (hwndText); |
|---|
| 743 | | if (start [0] is length) return true; |
|---|
| 744 | | end [0] = end [0] + 1; |
|---|
| | 739 | if (start is end) { |
|---|
| | 740 | int length_ = OS.GetWindowTextLength (hwndText); |
|---|
| | 741 | if (start is length_) return true; |
|---|
| | 742 | end = end + 1; |
|---|
| 745 | 743 | if (!OS.IsUnicode && OS.IsDBLocale) { |
|---|
| 746 | | int [] newStart = new int [1], newEnd = new int [1]; |
|---|
| 747 | | OS.SendMessage (hwndText, OS.EM_SETSEL, start [0], end [0]); |
|---|
| 748 | | OS.SendMessage (hwndText, OS.EM_GETSEL, newStart, newEnd); |
|---|
| 749 | | if (end [0] !is newEnd [0]) end [0] = end [0] + 1; |
|---|
| | 744 | int newStart, newEnd; |
|---|
| | 745 | OS.SendMessage (hwndText, OS.EM_SETSEL, start, end); |
|---|
| | 746 | OS.SendMessage (hwndText, OS.EM_GETSEL, &newStart, &newEnd); |
|---|
| | 747 | if (end !is newEnd) end = end + 1; |
|---|
| 750 | 748 | } |
|---|
| 751 | | end [0] = Math.min (end [0], length); |
|---|
| | 749 | end = Math.min (end, length_); |
|---|
| 752 | 750 | } |
|---|
| 753 | 751 | break; |
|---|
| … | … | |
| 756 | 754 | default: /* Tab and other characters */ |
|---|
| 757 | 755 | if (key !is '\t' && key < 0x20) return true; |
|---|
| 758 | | oldText = new String (new char [] {key}); |
|---|
| | 756 | oldText = [key]; |
|---|
| 759 | 757 | break; |
|---|
| 760 | 758 | } |
|---|
| 761 | | String newText = verifyText (oldText, start [0], end [0], event); |
|---|
| | 759 | char[] newText = verifyText (oldText, start, end, event); |
|---|
| 762 | 760 | if (newText is null) return false; |
|---|
| 763 | 761 | if (newText is oldText) return true; |
|---|
| 764 | | TCHAR buffer = new TCHAR (getCodePage (), newText, true); |
|---|
| 765 | | OS.SendMessage (hwndText, OS.EM_SETSEL, start [0], end [0]); |
|---|
| | 762 | TCHAR* buffer = StrToTCHARz (getCodePage (), newText); |
|---|
| | 763 | OS.SendMessage (hwndText, OS.EM_SETSEL, start, end); |
|---|
| 766 | 764 | OS.SendMessage (hwndText, OS.EM_REPLACESEL, 0, buffer); |
|---|
| 767 | 765 | return false; |
|---|
| 768 | 766 | } |
|---|
| 769 | 767 | |
|---|
| 770 | | override void setBackgroundImage (int hBitmap) { |
|---|
| | 768 | override void setBackgroundImage (HBITMAP hBitmap) { |
|---|
| 771 | 769 | super.setBackgroundImage (hBitmap); |
|---|
| 772 | 770 | OS.InvalidateRect (hwndText, null, true); |
|---|
| … | … | |
| 832 | 830 | checkWidget (); |
|---|
| 833 | 831 | if (value < 1) return; |
|---|
| 834 | | int hHeap = OS.GetProcessHeap (); |
|---|
| 835 | | int count = OS.SendMessage (hwndUpDown, OS.UDM_GETACCEL, 0, (UDACCEL)null); |
|---|
| 836 | | int udaccels = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, UDACCEL.sizeof * count); |
|---|
| | 832 | auto hHeap = OS.GetProcessHeap (); |
|---|
| | 833 | int count = OS.SendMessage (hwndUpDown, OS.UDM_GETACCEL, 0, cast(UDACCEL*)null); |
|---|
| | 834 | auto udaccels = cast(UDACCEL*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, UDACCEL.sizeof * count); |
|---|
| 837 | 835 | OS.SendMessage (hwndUpDown, OS.UDM_GETACCEL, count, udaccels); |
|---|
| 838 | 836 | int first = -1; |
|---|
| 839 | | UDACCEL udaccel = new UDACCEL (); |
|---|
| | 837 | UDACCEL udaccel; |
|---|
| 840 | 838 | for (int i = 0; i < count; i++) { |
|---|
| 841 | | int offset = udaccels + (i * UDACCEL.sizeof); |
|---|
| 842 | | OS.MoveMemory (udaccel, offset, UDACCEL.sizeof); |
|---|
| | 839 | void* offset = &udaccels + i; |
|---|
| | 840 | OS.MoveMemory (&udaccel, offset, UDACCEL.sizeof); |
|---|
| 843 | 841 | if (first is -1) first = udaccel.nInc; |
|---|
| 844 | 842 | udaccel.nInc = udaccel.nInc * value / first; |
|---|
| 845 | | OS.MoveMemory (offset, udaccel, UDACCEL.sizeof); |
|---|
| 846 | | } |
|---|
| 847 | | OS.SendMessage (hwndUpDown, OS.UDM_SETACCEL, count, udaccels); |
|---|
| 848 | | OS.HeapFree (hHeap, 0, udaccels); |
|---|
| | 843 | OS.MoveMemory (&offset, &udaccel, UDACCEL.sizeof); |
|---|
| | 844 | } |
|---|
| | 845 | OS.SendMessage (hwndUpDown, OS.UDM_SETACCEL, count, &udaccels); |
|---|
| | 846 | OS.HeapFree (hHeap, 0, &udaccels); |
|---|
| 849 | 847 | } |
|---|
| 850 | 848 | |
|---|
| … | … | |
| 865 | 863 | checkWidget (); |
|---|
| 866 | 864 | if (value < 0) return; |
|---|
| 867 | | int [] min = new int [1]; |
|---|
| 868 | | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, min, null); |
|---|
| 869 | | if (value <= min [0]) return; |
|---|
| | 865 | int min; |
|---|
| | 866 | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, &min, null); |
|---|
| | 867 | if (value <= min) return; |
|---|
| 870 | 868 | int pos; |
|---|
| 871 | 869 | if (OS.IsWinCE) { |
|---|
| … | … | |
| 874 | 872 | pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0); |
|---|
| 875 | 873 | } |
|---|
| 876 | | OS.SendMessage (hwndUpDown , OS.UDM_SETRANGE32, min [0], value); |
|---|
| | 874 | OS.SendMessage (hwndUpDown , OS.UDM_SETRANGE32, min, value); |
|---|
| 877 | 875 | if (pos > value) setSelection (value, true, true, false); |
|---|
| 878 | 876 | } |
|---|
| … | … | |
| 894 | 892 | checkWidget (); |
|---|
| 895 | 893 | if (value < 0) return; |
|---|
| 896 | | int [] max = new int [1]; |
|---|
| 897 | | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, null, max); |
|---|
| 898 | | if (value >= max [0]) return; |
|---|
| | 894 | int max; |
|---|
| | 895 | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, null, &max); |
|---|
| | 896 | if (value >= max) return; |
|---|
| 899 | 897 | int pos; |
|---|
| 900 | 898 | if (OS.IsWinCE) { |
|---|
| … | … | |
| 903 | 901 | pos = OS.SendMessage (hwndUpDown, OS.UDM_GETPOS32, 0, 0); |
|---|
| 904 | 902 | } |
|---|
| 905 | | OS.SendMessage (hwndUpDown , OS.UDM_SETRANGE32, value, max [0]); |
|---|
| | 903 | OS.SendMessage (hwndUpDown , OS.UDM_SETRANGE32, value, max); |
|---|
| 906 | 904 | if (pos < value) setSelection (value, true, true, false); |
|---|
| 907 | 905 | } |
|---|
| … | … | |
| 940 | 938 | public void setSelection (int value) { |
|---|
| 941 | 939 | checkWidget (); |
|---|
| 942 | | int [] max = new int [1], min = new int [1]; |
|---|
| 943 | | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, min, max); |
|---|
| 944 | | value = Math.min (Math.max (min [0], value), max [0]); |
|---|
| | 940 | int max, min; |
|---|
| | 941 | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, &min, &max); |
|---|
| | 942 | value = Math.min (Math.max (min, value), max ); |
|---|
| 945 | 943 | setSelection (value, true, true, false); |
|---|
| 946 | 944 | } |
|---|
| … | … | |
| 951 | 949 | } |
|---|
| 952 | 950 | if (setText) { |
|---|
| 953 | | String string = String.valueOf (value); |
|---|
| | 951 | char[] string = .toString( value ); |
|---|
| 954 | 952 | if (digits > 0) { |
|---|
| 955 | | String decimalSeparator = getDecimalSeparator (); |
|---|
| 956 | | int index = string.length () - digits; |
|---|
| | 953 | char[] decimalSeparator = getDecimalSeparator (); |
|---|
| | 954 | int index = string.length - digits; |
|---|
| 957 | 955 | StringBuffer buffer = new StringBuffer (); |
|---|
| 958 | 956 | if (index > 0) { |
|---|
| … | … | |
| 969 | 967 | } |
|---|
| 970 | 968 | if (hooks (DWT.Verify) || filters (DWT.Verify)) { |
|---|
| 971 | | int length = OS.GetWindowTextLength (hwndText); |
|---|
| 972 | | string = verifyText (string, 0, length, null); |
|---|
| | 969 | int length_ = OS.GetWindowTextLength (hwndText); |
|---|
| | 970 | string = verifyText (string, 0, length_, null); |
|---|
| 973 | 971 | if (string is null) return; |
|---|
| 974 | 972 | } |
|---|
| 975 | | TCHAR buffer = new TCHAR (getCodePage (), string, true); |
|---|
| | 973 | TCHAR* buffer = StrToTCHARz (getCodePage (), string); |
|---|
| 976 | 974 | OS.SetWindowText (hwndText, buffer); |
|---|
| 977 | 975 | } |
|---|
| … | … | |
| 979 | 977 | } |
|---|
| 980 | 978 | |
|---|
| 981 | | override void setToolTipText (Shell shell, String string) { |
|---|
| | 979 | override void setToolTipText (Shell shell, char[] string) { |
|---|
| 982 | 980 | shell.setToolTipText (hwndText, string); |
|---|
| 983 | 981 | shell.setToolTipText (hwndUpDown, string); |
|---|
| … | … | |
| 1031 | 1029 | override void unsubclass () { |
|---|
| 1032 | 1030 | super.unsubclass (); |
|---|
| 1033 | | OS.SetWindowLong (hwndText, OS.GWL_WNDPROC, EditProc); |
|---|
| 1034 | | OS.SetWindowLong (hwndUpDown, OS.GWL_WNDPROC, UpDownProc); |
|---|
| 1035 | | } |
|---|
| 1036 | | |
|---|
| 1037 | | String verifyText (String string, int start, int end, Event keyEvent) { |
|---|
| | 1031 | OS.SetWindowLong (hwndText, OS.GWL_WNDPROC, cast(int) EditProc); |
|---|
| | 1032 | OS.SetWindowLong (hwndUpDown, OS.GWL_WNDPROC, cast(int) UpDownProc); |
|---|
| | 1033 | } |
|---|
| | 1034 | |
|---|
| | 1035 | char[] verifyText (char[] string, int start, int end, Event keyEvent) { |
|---|
| 1038 | 1036 | Event event = new Event (); |
|---|
| 1039 | 1037 | event.text = string; |
|---|
| … | … | |
| 1047 | 1045 | int index = 0; |
|---|
| 1048 | 1046 | if (digits > 0) { |
|---|
| 1049 | | String decimalSeparator = getDecimalSeparator (); |
|---|
| | 1047 | char[] decimalSeparator = getDecimalSeparator (); |
|---|
| 1050 | 1048 | index = string.indexOf (decimalSeparator); |
|---|
| 1051 | 1049 | if (index !is -1) { |
|---|
| 1052 | | string = string.substring (0, index) + string.substring (index + 1); |
|---|
| | 1050 | string = string[0 .. index] ~ string[ index + 1 .. $ ]; |
|---|
| 1053 | 1051 | } |
|---|
| 1054 | 1052 | index = 0; |
|---|
| 1055 | 1053 | } |
|---|
| 1056 | | while (index < string.length ()) { |
|---|
| 1057 | | if (!Character.isDigit (string.charAt (index))) break; |
|---|
| | 1054 | while (index < string.length ) { |
|---|
| | 1055 | if (!CharacterIsDigit (string.charAt (index))) break; |
|---|
| 1058 | 1056 | index++; |
|---|
| 1059 | 1057 | } |
|---|
| 1060 | | event.doit = index is string.length (); |
|---|
| | 1058 | event.doit = index is string.length ; |
|---|
| 1061 | 1059 | if (!OS.IsUnicode && OS.IsDBLocale) { |
|---|
| 1062 | 1060 | event.start = mbcsToWcsPos (start); |
|---|
| … | … | |
| 1072 | 1070 | } |
|---|
| 1073 | 1071 | |
|---|
| 1074 | | override int windowProc (int hwnd, int msg, int wParam, int lParam) { |
|---|
| | 1072 | override int windowProc (HWND hwnd, int msg, int wParam, int lParam) { |
|---|
| 1075 | 1073 | if (hwnd is hwndText || hwnd is hwndUpDown) { |
|---|
| 1076 | | LRESULT result = null; |
|---|
| | 1074 | LRESULT result = LRESULT.NULL; |
|---|
| 1077 | 1075 | switch (msg) { |
|---|
| 1078 | 1076 | /* Keyboard messages */ |
|---|
| … | … | |
| 1126 | 1124 | break; |
|---|
| 1127 | 1125 | } |
|---|
| 1128 | | if (result !is null) return result.value; |
|---|
| | 1126 | if (result !is LRESULT.NULL) return result; |
|---|
| 1129 | 1127 | return callWindowProc (hwnd, msg, wParam, lParam); |
|---|
| 1130 | 1128 | } |
|---|
| … | … | |
| 1134 | 1132 | override LRESULT WM_ERASEBKGND (int wParam, int lParam) { |
|---|
| 1135 | 1133 | super.WM_ERASEBKGND (wParam, lParam); |
|---|
| 1136 | | drawBackground (wParam); |
|---|
| | 1134 | drawBackground (cast(HANDLE)wParam); |
|---|
| 1137 | 1135 | return LRESULT.ONE; |
|---|
| 1138 | 1136 | } |
|---|
| 1139 | 1137 | |
|---|
| 1140 | 1138 | override LRESULT WM_KILLFOCUS (int wParam, int lParam) { |
|---|
| 1141 | | return null; |
|---|
| | 1139 | return LRESULT.NULL; |
|---|
| 1142 | 1140 | } |
|---|
| 1143 | 1141 | |
|---|
| 1144 | 1142 | override LRESULT WM_SETFOCUS (int wParam, int lParam) { |
|---|
| 1145 | 1143 | OS.SetFocus (hwndText); |
|---|
| 1146 | | return null; |
|---|
| | 1144 | return LRESULT.NULL; |
|---|
| 1147 | 1145 | } |
|---|
| 1148 | 1146 | |
|---|
| 1149 | 1147 | override LRESULT WM_SETFONT (int wParam, int lParam) { |
|---|
| 1150 | 1148 | LRESULT result = super.WM_SETFONT (wParam, lParam); |
|---|
| 1151 | | if (result !is null) return result; |
|---|
| | 1149 | if (result !is LRESULT.NULL) return result; |
|---|
| 1152 | 1150 | OS.SendMessage (hwndText, OS.WM_SETFONT, wParam, lParam); |
|---|
| 1153 | 1151 | return result; |
|---|
| … | … | |
| 1162 | 1160 | int border = OS.GetSystemMetrics (OS.SM_CXEDGE); |
|---|
| 1163 | 1161 | int flags = OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE; |
|---|
| 1164 | | SetWindowPos (hwndText, 0, 0, 0, textWidth + border, height, flags); |
|---|
| 1165 | | SetWindowPos (hwndUpDown, 0, textWidth, 0, upDownWidth, height, flags); |
|---|
| | 1162 | SetWindowPos (hwndText, null, 0, 0, textWidth + border, height, flags); |
|---|
| | 1163 | SetWindowPos (hwndUpDown, null, textWidth, 0, upDownWidth, height, flags); |
|---|
| 1166 | 1164 | return result; |
|---|
| 1167 | 1165 | } |
|---|
| 1168 | 1166 | |
|---|
| 1169 | | override LRESULT wmChar (int hwnd, int wParam, int lParam) { |
|---|
| | 1167 | override LRESULT wmChar (HWND hwnd, int wParam, int lParam) { |
|---|
| 1170 | 1168 | LRESULT result = super.wmChar (hwnd, wParam, lParam); |
|---|
| 1171 | | if (result !is null) return result; |
|---|
| | 1169 | if (result !is LRESULT.NULL) return result; |
|---|
| 1172 | 1170 | /* |
|---|
| 1173 | 1171 | * Feature in Windows. For some reason, when the |
|---|
| … | … | |
| 1187 | 1185 | } |
|---|
| 1188 | 1186 | |
|---|
| 1189 | | LRESULT wmClipboard (int hwndText, int msg, int wParam, int lParam) { |
|---|
| 1190 | | if ((style & DWT.READ_ONLY) !is 0) return null; |
|---|
| | 1187 | LRESULT wmClipboard (HWND hwndText, int msg, int wParam, int lParam) { |
|---|
| | 1188 | if ((style & DWT.READ_ONLY) !is 0) return LRESULT.NULL; |
|---|
| 1191 | 1189 | // if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return null; |
|---|
| 1192 | 1190 | bool call = false; |
|---|
| 1193 | | int [] start = new int [1], end = new int [1]; |
|---|
| 1194 | | String newText = null; |
|---|
| | 1191 | int start, end; |
|---|
| | 1192 | char[] newText = null; |
|---|
| 1195 | 1193 | switch (msg) { |
|---|
| 1196 | 1194 | case OS.WM_CLEAR: |
|---|
| 1197 | 1195 | case OS.WM_CUT: |
|---|
| 1198 | | OS.SendMessage (hwndText, OS.EM_GETSEL, start, end); |
|---|
| 1199 | | if (start [0] !is end [0]) { |
|---|
| | 1196 | OS.SendMessage (hwndText, OS.EM_GETSEL, &start, &end); |
|---|
| | 1197 | if (start !is end) { |
|---|
| 1200 | 1198 | newText = ""; |
|---|
| 1201 | 1199 | call = true; |
|---|
| … | … | |
| 1203 | 1201 | break; |
|---|
| 1204 | 1202 | case OS.WM_PASTE: |
|---|
| 1205 | | OS.SendMessage (hwndText, OS.EM_GETSEL, start, end); |
|---|
| | 1203 | OS.SendMessage (hwndText, OS.EM_GETSEL, &start, &end); |
|---|
| 1206 | 1204 | newText = getClipboardText (); |
|---|
| 1207 | 1205 | break; |
|---|
| … | … | |
| 1210 | 1208 | if (OS.SendMessage (hwndText, OS.EM_CANUNDO, 0, 0) !is 0) { |
|---|
| 1211 | 1209 | ignoreModify = true; |
|---|
| 1212 | | OS.SendMessage (hwndText, OS.EM_GETSEL, start, end); |
|---|
| | 1210 | OS.SendMessage (hwndText, OS.EM_GETSEL, &start, &end); |
|---|
| 1213 | 1211 | OS.CallWindowProc (EditProc, hwndText, msg, wParam, lParam); |
|---|
| 1214 | | int length = OS.GetWindowTextLength (hwndText); |
|---|
| 1215 | | int [] newStart = new int [1], newEnd = new int [1]; |
|---|
| 1216 | | OS.SendMessage (hwndText, OS.EM_GETSEL, newStart, newEnd); |
|---|
| 1217 | | if (length !is 0 && newStart [0] !is newEnd [0]) { |
|---|
| 1218 | | TCHAR buffer = new TCHAR (getCodePage (), length + 1); |
|---|
| 1219 | | OS.GetWindowText (hwndText, buffer, length + 1); |
|---|
| 1220 | | newText = buffer.toString (newStart [0], newEnd [0] - newStart [0]); |
|---|
| | 1212 | int length_ = OS.GetWindowTextLength (hwndText); |
|---|
| | 1213 | int newStart, newEnd; |
|---|
| | 1214 | OS.SendMessage (hwndText, OS.EM_GETSEL, &newStart, &newEnd); |
|---|
| | 1215 | if (length_ !is 0 && newStart !is newEnd ) { |
|---|
| | 1216 | TCHAR[] buffer = NewTCHARs (getCodePage (), length_ + 1); |
|---|
| | 1217 | OS.GetWindowText (hwndText, buffer.ptr, length_ + 1); |
|---|
| | 1218 | newText = TCHARsToStr( buffer[ newStart .. newEnd - newStart ] ); |
|---|
| 1221 | 1219 | } else { |
|---|
| 1222 | 1220 | newText = ""; |
|---|
| … | … | |
| 1228 | 1226 | } |
|---|
| 1229 | 1227 | if (newText !is null) { |
|---|
| 1230 | | String oldText = newText; |
|---|
| 1231 | | newText = verifyText (newText, start [0], end [0], null); |
|---|
| | 1228 | char[] oldText = newText; |
|---|
| | 1229 | newText = verifyText (newText, start, end, null); |
|---|
| 1232 | 1230 | if (newText is null) return LRESULT.ZERO; |
|---|
| 1233 | | if (!newText.equals (oldText)) { |
|---|
| | 1231 | if ( newText !=/*eq*/ oldText ) { |
|---|
| 1234 | 1232 | if (call) { |
|---|
| 1235 | 1233 | OS.CallWindowProc (EditProc, hwndText, msg, wParam, lParam); |
|---|
| 1236 | 1234 | } |
|---|
| 1237 | | TCHAR buffer = new TCHAR (getCodePage (), newText, true); |
|---|
| | 1235 | TCHAR[] buffer = StrToTCHARs (getCodePage (), newText, true); |
|---|
| 1238 | 1236 | if (msg is OS.WM_SETTEXT) { |
|---|
| 1239 | | int hHeap = OS.GetProcessHeap (); |
|---|
| 1240 | | int byteCount = buffer.length () * TCHAR.sizeof; |
|---|
| 1241 | | int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); |
|---|
| 1242 | | OS.MoveMemory (pszText, buffer, byteCount); |
|---|
| 1243 | | int code = OS.CallWindowProc (EditProc, hwndText, msg, wParam, pszText); |
|---|
| | 1237 | auto hHeap = OS.GetProcessHeap (); |
|---|
| | 1238 | int byteCount = buffer.length * TCHAR.sizeof; |
|---|
| | 1239 | auto pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); |
|---|
| | 1240 | OS.MoveMemory (pszText, buffer.ptr, byteCount); |
|---|
| | 1241 | int code = OS.CallWindowProc (EditProc, hwndText, msg, wParam, cast(int) pszText); |
|---|
| 1244 | 1242 | OS.HeapFree (hHeap, 0, pszText); |
|---|
| 1245 | | return new LRESULT (code); |
|---|
| | 1243 | return cast(LRESULT) (code); |
|---|
| 1246 | 1244 | } else { |
|---|
| 1247 | | OS.SendMessage (hwndText, OS.EM_REPLACESEL, 0, buffer); |
|---|
| | 1245 | OS.SendMessage (hwndText, OS.EM_REPLACESEL, 0, buffer.ptr); |
|---|
| 1248 | 1246 | return LRESULT.ZERO; |
|---|
| 1249 | 1247 | } |
|---|
| 1250 | 1248 | } |
|---|
| 1251 | 1249 | } |
|---|
| 1252 | | return null; |
|---|
| | 1250 | return LRESULT.NULL; |
|---|
| 1253 | 1251 | } |
|---|
| 1254 | 1252 | |
|---|
| … | … | |
| 1275 | 1273 | } |
|---|
| 1276 | 1274 | |
|---|
| 1277 | | override LRESULT wmKeyDown (int hwnd, int wParam, int lParam) { |
|---|
| | 1275 | override LRESULT wmKeyDown (HWND hwnd, int wParam, int lParam) { |
|---|
| 1278 | 1276 | LRESULT result = super.wmKeyDown (hwnd, wParam, lParam); |
|---|
| 1279 | | if (result !is null) return result; |
|---|
| | 1277 | if (result !is LRESULT.NULL) return result; |
|---|
| 1280 | 1278 | |
|---|
| 1281 | 1279 | /* Increment the value */ |
|---|
| 1282 | | UDACCEL udaccel = new UDACCEL (); |
|---|
| 1283 | | OS.SendMessage (hwndUpDown, OS.UDM_GETACCEL, 1, udaccel); |
|---|
| | 1280 | UDACCEL udaccel; |
|---|
| | 1281 | OS.SendMessage (hwndUpDown, OS.UDM_GETACCEL, 1, &udaccel); |
|---|
| 1284 | 1282 | int delta = 0; |
|---|
| 1285 | 1283 | switch (wParam) { |
|---|
| … | … | |
| 1299 | 1297 | } |
|---|
| 1300 | 1298 | int newValue = value + delta; |
|---|
| 1301 | | int [] max = new int [1], min = new int [1]; |
|---|
| 1302 | | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, min, max); |
|---|
| | 1299 | int max, min; |
|---|
| | 1300 | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, &min, &max); |
|---|
| 1303 | 1301 | if ((style & DWT.WRAP) !is 0) { |
|---|
| 1304 | | if (newValue < min [0]) newValue = max [0]; |
|---|
| 1305 | | if (newValue > max [0]) newValue = min [0]; |
|---|
| | 1302 | if (newValue < min ) newValue = max; |
|---|
| | 1303 | if (newValue > max ) newValue = min; |
|---|
| 1306 | 1304 | } |
|---|
| 1307 | | newValue = Math.min (Math.max (min [0], newValue), max [0]); |
|---|
| | 1305 | newValue = Math.min (Math.max (min , newValue), max ); |
|---|
| 1308 | 1306 | if (value !is newValue) setSelection (newValue, true, true, true); |
|---|
| 1309 | 1307 | } |
|---|
| … | … | |
| 1318 | 1316 | } |
|---|
| 1319 | 1317 | |
|---|
| 1320 | | override LRESULT wmKillFocus (int hwnd, int wParam, int lParam) { |
|---|
| | 1318 | override LRESULT wmKillFocus (HWND hwnd, int wParam, int lParam) { |
|---|
| 1321 | 1319 | int value = getSelectionText (); |
|---|
| 1322 | 1320 | if (value is -1) { |
|---|
| … | … | |
| 1331 | 1329 | } |
|---|
| 1332 | 1330 | |
|---|
| 1333 | | override LRESULT wmNotifyChild (NMHDR hdr, int wParam, int lParam) { |
|---|
| | 1331 | override LRESULT wmNotifyChild (NMHDR* hdr, int wParam, int lParam) { |
|---|
| 1334 | 1332 | switch (hdr.code) { |
|---|
| 1335 | 1333 | case OS.UDN_DELTAPOS: |
|---|
| 1336 | | NMUPDOWN lpnmud = new NMUPDOWN (); |
|---|
| 1337 | | OS.MoveMemory (lpnmud, lParam, NMUPDOWN.sizeof); |
|---|
| | 1334 | NMUPDOWN* lpnmud = cast(NMUPDOWN*)lParam; |
|---|
| | 1335 | //OS.MoveMemory (lpnmud, lParam, NMUPDOWN.sizeof); |
|---|
| 1338 | 1336 | int value = lpnmud.iPos + lpnmud.iDelta; |
|---|
| 1339 | | int [] max = new int [1], min = new int [1]; |
|---|
| 1340 | | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, min, max); |
|---|
| | 1337 | int max, min; |
|---|
| | 1338 | OS.SendMessage (hwndUpDown , OS.UDM_GETRANGE32, &min, &max); |
|---|
| 1341 | 1339 | if ((style & DWT.WRAP) !is 0) { |
|---|
| 1342 | | if (value < min [0]) value = max [0]; |
|---|
| 1343 | | if (value > max [0]) value = min [0]; |
|---|
| | 1340 | if (value < min ) value = max ; |
|---|
| | 1341 | if (value > max ) value = min ; |
|---|
| 1344 | 1342 | } |
|---|
| 1345 | 1343 | /* |
|---|
| … | … | |
| 1351 | 1349 | * from running. |
|---|
| 1352 | 1350 | */ |
|---|
| 1353 | | value = Math.min (Math.max (min [0], value), max [0]); |
|---|
| | 1351 | value = Math.min (Math.max (min , value), max ); |
|---|
| 1354 | 1352 | if (value !is lpnmud.iPos) { |
|---|
| 1355 | 1353 | setSelection (value, true, true, true); |
|---|
| … | … | |
| 1371 | 1369 | |
|---|
| 1372 | 1370 | } |
|---|
| 1373 | | ++/ |
|---|
| | 1371 | |
|---|
| r56 |
r65 |
|
| 10914 | 10914 | alias NM_UPDOWNW TNMUPDOWN; |
|---|
| 10915 | 10915 | alias NM_UPDOWNW* PNMUPDOWN; |
|---|
| | 10916 | alias NM_UPDOWNW NMUPDOWN; |
|---|
| 10916 | 10917 | |
|---|
| 10917 | 10918 | struct NONCLIENTMETRICS |
|---|