Mercurial > projects > dwt-win
comparison dwt/widgets/Text.d @ 212:ab60f3309436
reverted the char[] to String and use the an alias.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 05 May 2008 00:12:38 +0200 |
parents | ee3ee677f5fc |
children | 36f5cb12e1a2 |
comparison
equal
deleted
inserted
replaced
211:ff59aeb96cac | 212:ab60f3309436 |
---|---|
57 alias Scrollable.sendKeyEvent sendKeyEvent; | 57 alias Scrollable.sendKeyEvent sendKeyEvent; |
58 alias Scrollable.setBounds setBounds; | 58 alias Scrollable.setBounds setBounds; |
59 | 59 |
60 int tabs, oldStart, oldEnd; | 60 int tabs, oldStart, oldEnd; |
61 bool doubleClick, ignoreModify, ignoreVerify, ignoreCharacter; | 61 bool doubleClick, ignoreModify, ignoreVerify, ignoreCharacter; |
62 char[] message; | 62 String message; |
63 | 63 |
64 /** | 64 /** |
65 * The maximum number of characters that can be entered | 65 * The maximum number of characters that can be entered |
66 * into a text widget. | 66 * into a text widget. |
67 * <p> | 67 * <p> |
78 /** | 78 /** |
79 * The delimiter used by multi-line text widgets. When text | 79 * The delimiter used by multi-line text widgets. When text |
80 * is queried and from the widget, it will be delimited using | 80 * is queried and from the widget, it will be delimited using |
81 * this delimiter. | 81 * this delimiter. |
82 */ | 82 */ |
83 public static const char[] DELIMITER = "\r\n"; | 83 public static const String DELIMITER = "\r\n"; |
84 | 84 |
85 /* | 85 /* |
86 * This code is intentionally commented. | 86 * This code is intentionally commented. |
87 */ | 87 */ |
88 // static final char PASSWORD; | 88 // static final char PASSWORD; |
280 * @exception DWTException <ul> | 280 * @exception DWTException <ul> |
281 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 281 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
282 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 282 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
283 * </ul> | 283 * </ul> |
284 */ | 284 */ |
285 public void append (char[] string) { | 285 public void append (String string) { |
286 checkWidget (); | 286 checkWidget (); |
287 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 287 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
288 string = Display.withCrLf (string); | 288 string = Display.withCrLf (string); |
289 int length = OS.GetWindowTextLength (handle); | 289 int length = OS.GetWindowTextLength (handle); |
290 if (hooks (DWT.Verify) || filters (DWT.Verify)) { | 290 if (hooks (DWT.Verify) || filters (DWT.Verify)) { |
809 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 809 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
810 * </ul> | 810 * </ul> |
811 * | 811 * |
812 * @see #DELIMITER | 812 * @see #DELIMITER |
813 */ | 813 */ |
814 public char[] getLineDelimiter () { | 814 public String getLineDelimiter () { |
815 checkWidget (); | 815 checkWidget (); |
816 return DELIMITER; | 816 return DELIMITER; |
817 } | 817 } |
818 | 818 |
819 /** | 819 /** |
874 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 874 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
875 * </ul> | 875 * </ul> |
876 * | 876 * |
877 * @since 3.3 | 877 * @since 3.3 |
878 */ | 878 */ |
879 public char[] getMessage () { | 879 public String getMessage () { |
880 checkWidget (); | 880 checkWidget (); |
881 return message; | 881 return message; |
882 } | 882 } |
883 | 883 |
884 /** | 884 /** |
961 * @exception DWTException <ul> | 961 * @exception DWTException <ul> |
962 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 962 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
963 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 963 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
964 * </ul> | 964 * </ul> |
965 */ | 965 */ |
966 public char[] getSelectionText () { | 966 public String getSelectionText () { |
967 checkWidget (); | 967 checkWidget (); |
968 int length = OS.GetWindowTextLength (handle); | 968 int length = OS.GetWindowTextLength (handle); |
969 if (length is 0) return ""; | 969 if (length is 0) return ""; |
970 int start, end; | 970 int start, end; |
971 OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); | 971 OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); |
1021 * @exception DWTException <ul> | 1021 * @exception DWTException <ul> |
1022 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 1022 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
1023 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1023 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1024 * </ul> | 1024 * </ul> |
1025 */ | 1025 */ |
1026 public char[] getText () { | 1026 public String getText () { |
1027 checkWidget (); | 1027 checkWidget (); |
1028 int length_ = OS.GetWindowTextLength (handle); | 1028 int length_ = OS.GetWindowTextLength (handle); |
1029 if (length_ is 0) return ""; | 1029 if (length_ is 0) return ""; |
1030 TCHAR[] buffer = NewTCHARs (getCodePage (), length_ + 1); | 1030 TCHAR[] buffer = NewTCHARs (getCodePage (), length_ + 1); |
1031 OS.GetWindowText (handle, buffer.ptr, length_ + 1); | 1031 OS.GetWindowText (handle, buffer.ptr, length_ + 1); |
1048 * @exception DWTException <ul> | 1048 * @exception DWTException <ul> |
1049 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 1049 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
1050 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1050 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1051 * </ul> | 1051 * </ul> |
1052 */ | 1052 */ |
1053 public char[] getText (int start, int end) { | 1053 public String getText (int start, int end) { |
1054 checkWidget (); | 1054 checkWidget (); |
1055 if (!(start <= end && 0 <= end)) return ""; | 1055 if (!(start <= end && 0 <= end)) return ""; |
1056 int length = OS.GetWindowTextLength (handle); | 1056 int length = OS.GetWindowTextLength (handle); |
1057 if (!OS.IsUnicode && OS.IsDBLocale) length = mbcsToWcsPos (length); | 1057 if (!OS.IsUnicode && OS.IsDBLocale) length = mbcsToWcsPos (length); |
1058 start = Math.max (0, start); | 1058 start = Math.max (0, start); |
1153 * @exception DWTException <ul> | 1153 * @exception DWTException <ul> |
1154 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 1154 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
1155 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1155 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1156 * </ul> | 1156 * </ul> |
1157 */ | 1157 */ |
1158 public void insert (char[] string) { | 1158 public void insert (String string) { |
1159 checkWidget (); | 1159 checkWidget (); |
1160 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 1160 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
1161 string = Display.withCrLf (string); | 1161 string = Display.withCrLf (string); |
1162 if (hooks (DWT.Verify) || filters (DWT.Verify)) { | 1162 if (hooks (DWT.Verify) || filters (DWT.Verify)) { |
1163 int start, end; | 1163 int start, end; |
1186 if (mbcsPos <= 0) return 0; | 1186 if (mbcsPos <= 0) return 0; |
1187 if (OS.IsUnicode) return mbcsPos; | 1187 if (OS.IsUnicode) return mbcsPos; |
1188 int cp = getCodePage (); | 1188 int cp = getCodePage (); |
1189 int wcsTotal = 0, mbcsTotal = 0; | 1189 int wcsTotal = 0, mbcsTotal = 0; |
1190 char [] buffer = new char [128]; | 1190 char [] buffer = new char [128]; |
1191 char[] delimiter = getLineDelimiter(); | 1191 String delimiter = getLineDelimiter(); |
1192 int delimiterSize = delimiter.length; | 1192 int delimiterSize = delimiter.length; |
1193 int count = OS.SendMessageA (handle, OS.EM_GETLINECOUNT, 0, 0); | 1193 int count = OS.SendMessageA (handle, OS.EM_GETLINECOUNT, 0, 0); |
1194 for (int line=0; line<count; line++) { | 1194 for (int line=0; line<count; line++) { |
1195 int wcsSize = 0; | 1195 int wcsSize = 0; |
1196 int linePos = OS.SendMessageA (handle, OS.EM_LINEINDEX, line, 0); | 1196 int linePos = OS.SendMessageA (handle, OS.EM_LINEINDEX, line, 0); |
1370 if (OS.GetKeyState (OS.VK_LBUTTON) < 0) { | 1370 if (OS.GetKeyState (OS.VK_LBUTTON) < 0) { |
1371 if (handle is OS.GetCapture()) return true; | 1371 if (handle is OS.GetCapture()) return true; |
1372 } | 1372 } |
1373 | 1373 |
1374 /* Verify the character */ | 1374 /* Verify the character */ |
1375 char[] oldText = ""; | 1375 String oldText = ""; |
1376 int start, end; | 1376 int start, end; |
1377 OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); | 1377 OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); |
1378 switch (key) { | 1378 switch (key) { |
1379 case 0x08: /* Bs */ | 1379 case 0x08: /* Bs */ |
1380 if (start is end ) { | 1380 if (start is end ) { |
1421 default: /* Tab and other characters */ | 1421 default: /* Tab and other characters */ |
1422 if (key !is '\t' && key < 0x20) return true; | 1422 if (key !is '\t' && key < 0x20) return true; |
1423 oldText = [key]; | 1423 oldText = [key]; |
1424 break; | 1424 break; |
1425 } | 1425 } |
1426 char[] newText = verifyText (oldText, start, end, event); | 1426 String newText = verifyText (oldText, start, end, event); |
1427 if (newText is null) return false; | 1427 if (newText is null) return false; |
1428 if (newText is oldText) return true; | 1428 if (newText is oldText) return true; |
1429 newText = Display.withCrLf (newText); | 1429 newText = Display.withCrLf (newText); |
1430 TCHAR* buffer = StrToTCHARz (getCodePage (), newText); | 1430 TCHAR* buffer = StrToTCHARz (getCodePage (), newText); |
1431 OS.SendMessage (handle, OS.EM_SETSEL, start, end); | 1431 OS.SendMessage (handle, OS.EM_SETSEL, start, end); |
1603 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1603 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1604 * </ul> | 1604 * </ul> |
1605 * | 1605 * |
1606 * @since 3.3 | 1606 * @since 3.3 |
1607 */ | 1607 */ |
1608 public void setMessage (char[] message) { | 1608 public void setMessage (String message) { |
1609 checkWidget (); | 1609 checkWidget (); |
1610 if (message is null) error (DWT.ERROR_NULL_ARGUMENT); | 1610 if (message is null) error (DWT.ERROR_NULL_ARGUMENT); |
1611 this.message = message; | 1611 this.message = message; |
1612 if (OS.COMCTL32_MAJOR >= 6) { | 1612 if (OS.COMCTL32_MAJOR >= 6) { |
1613 if ((style & DWT.SEARCH) !is 0) { | 1613 if ((style & DWT.SEARCH) !is 0) { |
1821 * @exception DWTException <ul> | 1821 * @exception DWTException <ul> |
1822 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 1822 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
1823 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1823 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1824 * </ul> | 1824 * </ul> |
1825 */ | 1825 */ |
1826 public void setText (char[] string) { | 1826 public void setText (String string) { |
1827 checkWidget (); | 1827 checkWidget (); |
1828 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 1828 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
1829 string = Display.withCrLf (string); | 1829 string = Display.withCrLf (string); |
1830 if (hooks (DWT.Verify) || filters (DWT.Verify)) { | 1830 if (hooks (DWT.Verify) || filters (DWT.Verify)) { |
1831 int length = OS.GetWindowTextLength (handle); | 1831 int length = OS.GetWindowTextLength (handle); |
1917 public void showSelection () { | 1917 public void showSelection () { |
1918 checkWidget (); | 1918 checkWidget (); |
1919 OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0); | 1919 OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0); |
1920 } | 1920 } |
1921 | 1921 |
1922 char[] verifyText (char[] string, int start, int end, Event keyEvent) { | 1922 String verifyText (String string, int start, int end, Event keyEvent) { |
1923 if (ignoreVerify) return string; | 1923 if (ignoreVerify) return string; |
1924 Event event = new Event (); | 1924 Event event = new Event (); |
1925 event.text = string; | 1925 event.text = string; |
1926 event.start = start; | 1926 event.start = start; |
1927 event.end = end; | 1927 event.end = end; |
1949 if (wcsPos <= 0) return 0; | 1949 if (wcsPos <= 0) return 0; |
1950 if (OS.IsUnicode) return wcsPos; | 1950 if (OS.IsUnicode) return wcsPos; |
1951 int cp = getCodePage (); | 1951 int cp = getCodePage (); |
1952 int wcsTotal = 0, mbcsTotal = 0; | 1952 int wcsTotal = 0, mbcsTotal = 0; |
1953 char [] buffer = new char [128]; | 1953 char [] buffer = new char [128]; |
1954 char[] delimiter = getLineDelimiter (); | 1954 String delimiter = getLineDelimiter (); |
1955 int delimiterSize = delimiter.length; | 1955 int delimiterSize = delimiter.length; |
1956 int count = OS.SendMessageA (handle, OS.EM_GETLINECOUNT, 0, 0); | 1956 int count = OS.SendMessageA (handle, OS.EM_GETLINECOUNT, 0, 0); |
1957 for (int line=0; line<count; line++) { | 1957 for (int line=0; line<count; line++) { |
1958 int wcsSize = 0; | 1958 int wcsSize = 0; |
1959 int linePos = OS.SendMessageA (handle, OS.EM_LINEINDEX, line, 0); | 1959 int linePos = OS.SendMessageA (handle, OS.EM_LINEINDEX, line, 0); |
2020 bits |= OS.ES_MULTILINE | OS.ES_NOHIDESEL | OS.ES_AUTOVSCROLL; | 2020 bits |= OS.ES_MULTILINE | OS.ES_NOHIDESEL | OS.ES_AUTOVSCROLL; |
2021 if ((style & DWT.WRAP) !is 0) bits &= ~(OS.WS_HSCROLL | OS.ES_AUTOHSCROLL); | 2021 if ((style & DWT.WRAP) !is 0) bits &= ~(OS.WS_HSCROLL | OS.ES_AUTOHSCROLL); |
2022 return bits; | 2022 return bits; |
2023 } | 2023 } |
2024 | 2024 |
2025 override char[] windowClass () { | 2025 override String windowClass () { |
2026 return TCHARsToStr(EditClass); | 2026 return TCHARsToStr(EditClass); |
2027 } | 2027 } |
2028 | 2028 |
2029 override int windowProc () { | 2029 override int windowProc () { |
2030 return cast(int)EditProc; | 2030 return cast(int)EditProc; |
2290 LRESULT wmClipboard (int msg, int wParam, int lParam) { | 2290 LRESULT wmClipboard (int msg, int wParam, int lParam) { |
2291 if ((style & DWT.READ_ONLY) !is 0) return null; | 2291 if ((style & DWT.READ_ONLY) !is 0) return null; |
2292 if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return null; | 2292 if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return null; |
2293 bool call = false; | 2293 bool call = false; |
2294 int start, end; | 2294 int start, end; |
2295 char[] newText = null; | 2295 String newText = null; |
2296 switch (msg) { | 2296 switch (msg) { |
2297 case OS.WM_CLEAR: | 2297 case OS.WM_CLEAR: |
2298 case OS.WM_CUT: | 2298 case OS.WM_CUT: |
2299 OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); | 2299 OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); |
2300 if (start !is end ) { | 2300 if (start !is end ) { |
2327 } | 2327 } |
2328 break; | 2328 break; |
2329 default: | 2329 default: |
2330 } | 2330 } |
2331 if (newText !is null) { | 2331 if (newText !is null) { |
2332 char[] oldText = newText; | 2332 String oldText = newText; |
2333 newText = verifyText (newText, start, end, null); | 2333 newText = verifyText (newText, start, end, null); |
2334 if (newText is null) return LRESULT.ZERO; | 2334 if (newText is null) return LRESULT.ZERO; |
2335 if (newText !=/*eq*/oldText) { | 2335 if (newText !=/*eq*/oldText) { |
2336 if (call) { | 2336 if (call) { |
2337 callWindowProc (handle, msg, wParam, lParam); | 2337 callWindowProc (handle, msg, wParam, lParam); |