comparison dwt/widgets/Combo.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
182 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 182 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
183 * </ul> 183 * </ul>
184 * 184 *
185 * @see #add(String,int) 185 * @see #add(String,int)
186 */ 186 */
187 public void add (char[] string) { 187 public void add (String string) {
188 checkWidget (); 188 checkWidget ();
189 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 189 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
190 auto buffer = StrToTCHARs( getCodePage(), string, true ); 190 auto buffer = StrToTCHARs( getCodePage(), string, true );
191 int result = OS.SendMessage (handle, OS.CB_ADDSTRING, 0, buffer.ptr ); 191 int result = OS.SendMessage (handle, OS.CB_ADDSTRING, 0, buffer.ptr );
192 if (result is OS.CB_ERR) error (DWT.ERROR_ITEM_NOT_ADDED); 192 if (result is OS.CB_ERR) error (DWT.ERROR_ITEM_NOT_ADDED);
215 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 215 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
216 * </ul> 216 * </ul>
217 * 217 *
218 * @see #add(String) 218 * @see #add(String)
219 */ 219 */
220 public void add (char[] string, int index) { 220 public void add (String string, int index) {
221 checkWidget (); 221 checkWidget ();
222 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 222 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
223 int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); 223 int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0);
224 if (!(0 <= index && index <= count)) { 224 if (!(0 <= index && index <= count)) {
225 error (DWT.ERROR_INVALID_RANGE); 225 error (DWT.ERROR_INVALID_RANGE);
340 340
341 int CBTProc (int nCode, int wParam, int lParam) { 341 int CBTProc (int nCode, int wParam, int lParam) {
342 if (nCode is OS.HCBT_CREATEWND) { 342 if (nCode is OS.HCBT_CREATEWND) {
343 TCHAR[128] buffer = 0; 343 TCHAR[128] buffer = 0;
344 OS.GetClassName (cast(HANDLE)wParam, buffer.ptr, buffer.length ); 344 OS.GetClassName (cast(HANDLE)wParam, buffer.ptr, buffer.length );
345 char[] className = TCHARzToStr(buffer.ptr); 345 String className = TCHARzToStr(buffer.ptr);
346 if (className=="Edit" || className=="EDIT") { //$NON-NLS-1$ //$NON-NLS-2$ 346 if (className=="Edit" || className=="EDIT") { //$NON-NLS-1$ //$NON-NLS-2$
347 int bits = OS.GetWindowLong (cast(HANDLE)wParam, OS.GWL_STYLE); 347 int bits = OS.GetWindowLong (cast(HANDLE)wParam, OS.GWL_STYLE);
348 OS.SetWindowLong (cast(HANDLE)wParam, OS.GWL_STYLE, bits & ~OS.ES_NOHIDESEL); 348 OS.SetWindowLong (cast(HANDLE)wParam, OS.GWL_STYLE, bits & ~OS.ES_NOHIDESEL);
349 } 349 }
350 } 350 }
667 * @exception DWTException <ul> 667 * @exception DWTException <ul>
668 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 668 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
669 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 669 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
670 * </ul> 670 * </ul>
671 */ 671 */
672 public char[] getItem (int index) { 672 public String getItem (int index) {
673 checkWidget (); 673 checkWidget ();
674 int length_ = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, index, 0); 674 int length_ = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, index, 0);
675 if (length_ !is OS.CB_ERR) { 675 if (length_ !is OS.CB_ERR) {
676 TCHAR[] buffer = new TCHAR[ length_ + 1]; 676 TCHAR[] buffer = new TCHAR[ length_ + 1];
677 int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, index, buffer.ptr); 677 int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, index, buffer.ptr);
732 * @exception DWTException <ul> 732 * @exception DWTException <ul>
733 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 733 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
734 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 734 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
735 * </ul> 735 * </ul>
736 */ 736 */
737 public char[] [] getItems () { 737 public String [] getItems () {
738 checkWidget (); 738 checkWidget ();
739 int count = getItemCount (); 739 int count = getItemCount ();
740 char[] [] result = new char[] [count]; 740 String [] result = new String [count];
741 for (int i=0; i<count; i++) result [i] = getItem (i); 741 for (int i=0; i<count; i++) result [i] = getItem (i);
742 return result; 742 return result;
743 } 743 }
744 744
745 /** 745 /**
767 return OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) !is 0; 767 return OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) !is 0;
768 } 768 }
769 return true; 769 return true;
770 } 770 }
771 771
772 override char[] getNameText () { 772 override String getNameText () {
773 return getText (); 773 return getText ();
774 } 774 }
775 775
776 /** 776 /**
777 * Returns the orientation of the receiver. 777 * Returns the orientation of the receiver.
850 * @exception DWTException <ul> 850 * @exception DWTException <ul>
851 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 851 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
852 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 852 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
853 * </ul> 853 * </ul>
854 */ 854 */
855 public char[] getText () { 855 public String getText () {
856 checkWidget (); 856 checkWidget ();
857 int length_ = OS.GetWindowTextLength (handle); 857 int length_ = OS.GetWindowTextLength (handle);
858 if (length_ is 0) return ""; 858 if (length_ is 0) return "";
859 TCHAR[] buffer = new TCHAR[ length_ + 1]; 859 TCHAR[] buffer = new TCHAR[ length_ + 1];
860 OS.GetWindowText (handle, buffer.ptr, length_ + 1); 860 OS.GetWindowText (handle, buffer.ptr, length_ + 1);
953 * @exception DWTException <ul> 953 * @exception DWTException <ul>
954 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 954 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
955 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 955 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
956 * </ul> 956 * </ul>
957 */ 957 */
958 public int indexOf (char[] string) { 958 public int indexOf (String string) {
959 return indexOf (string, 0); 959 return indexOf (string, 0);
960 } 960 }
961 961
962 /** 962 /**
963 * Searches the receiver's list starting at the given, 963 * Searches the receiver's list starting at the given,
976 * @exception DWTException <ul> 976 * @exception DWTException <ul>
977 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 977 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
978 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 978 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
979 * </ul> 979 * </ul>
980 */ 980 */
981 public int indexOf (char[] string, int start) { 981 public int indexOf (String string, int start) {
982 checkWidget (); 982 checkWidget ();
983 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 983 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
984 984
985 /* 985 /*
986 * Bug in Windows. For some reason, CB_FINDSTRINGEXACT 986 * Bug in Windows. For some reason, CB_FINDSTRINGEXACT
1199 * @exception DWTException <ul> 1199 * @exception DWTException <ul>
1200 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 1200 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1201 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1201 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1202 * </ul> 1202 * </ul>
1203 */ 1203 */
1204 public void remove (char[] string) { 1204 public void remove (String string) {
1205 checkWidget (); 1205 checkWidget ();
1206 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 1206 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
1207 int index = indexOf (string, 0); 1207 int index = indexOf (string, 0);
1208 if (index is -1) error (DWT.ERROR_INVALID_ARGUMENT); 1208 if (index is -1) error (DWT.ERROR_INVALID_ARGUMENT);
1209 remove (index); 1209 remove (index);
1336 if (OS.GetKeyState (OS.VK_LBUTTON) < 0) { 1336 if (OS.GetKeyState (OS.VK_LBUTTON) < 0) {
1337 return true; 1337 return true;
1338 } 1338 }
1339 1339
1340 /* Verify the character */ 1340 /* Verify the character */
1341 char[] oldText = ""; 1341 String oldText = "";
1342 int start, end; 1342 int start, end;
1343 auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); 1343 auto hwndText = OS.GetDlgItem (handle, CBID_EDIT);
1344 if (hwndText is null) return true; 1344 if (hwndText is null) return true;
1345 OS.SendMessage (hwndText, OS.EM_GETSEL, start, end); 1345 OS.SendMessage (hwndText, OS.EM_GETSEL, start, end);
1346 switch (key) { 1346 switch (key) {
1376 default: /* Tab and other characters */ 1376 default: /* Tab and other characters */
1377 if (key !is '\t' && key < 0x20) return true; 1377 if (key !is '\t' && key < 0x20) return true;
1378 oldText = [key]; 1378 oldText = [key];
1379 break; 1379 break;
1380 } 1380 }
1381 char[] newText = verifyText (oldText, start, end, event); 1381 String newText = verifyText (oldText, start, end, event);
1382 if (newText is null) return false; 1382 if (newText is null) return false;
1383 if (newText is oldText) return true; 1383 if (newText is oldText) return true;
1384 TCHAR* buffer = StrToTCHARz( newText ); 1384 TCHAR* buffer = StrToTCHARz( newText );
1385 OS.SendMessage (hwndText, OS.EM_SETSEL, start, end); 1385 OS.SendMessage (hwndText, OS.EM_SETSEL, start, end);
1386 OS.SendMessage (hwndText, OS.EM_REPLACESEL, 0, buffer); 1386 OS.SendMessage (hwndText, OS.EM_REPLACESEL, 0, buffer);
1503 * @exception DWTException <ul> 1503 * @exception DWTException <ul>
1504 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 1504 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1505 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1505 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1506 * </ul> 1506 * </ul>
1507 */ 1507 */
1508 public void setItem (int index, char[] string) { 1508 public void setItem (int index, String string) {
1509 checkWidget (); 1509 checkWidget ();
1510 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 1510 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
1511 int selection = getSelectionIndex (); 1511 int selection = getSelectionIndex ();
1512 remove (index, false); 1512 remove (index, false);
1513 if (isDisposed ()) return; 1513 if (isDisposed ()) return;
1527 * @exception DWTException <ul> 1527 * @exception DWTException <ul>
1528 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 1528 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1529 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1529 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1530 * </ul> 1530 * </ul>
1531 */ 1531 */
1532 public void setItems (char[] [] items) { 1532 public void setItems (String [] items) {
1533 checkWidget (); 1533 checkWidget ();
1534 if (items is null) error (DWT.ERROR_NULL_ARGUMENT); 1534 if (items is null) error (DWT.ERROR_NULL_ARGUMENT);
1535 for (int i=0; i<items.length; i++) { 1535 for (int i=0; i<items.length; i++) {
1536 if (items [i] is null) error (DWT.ERROR_INVALID_ARGUMENT); 1536 if (items [i] is null) error (DWT.ERROR_INVALID_ARGUMENT);
1537 } 1537 }
1547 setScrollWidth (0); 1547 setScrollWidth (0);
1548 } 1548 }
1549 OS.SendMessage (handle, OS.CB_RESETCONTENT, 0, 0); 1549 OS.SendMessage (handle, OS.CB_RESETCONTENT, 0, 0);
1550 int codePage = getCodePage (); 1550 int codePage = getCodePage ();
1551 for (int i=0; i<items.length; i++) { 1551 for (int i=0; i<items.length; i++) {
1552 char[] string = items [i]; 1552 String string = items [i];
1553 TCHAR* buffer = StrToTCHARz( string ); 1553 TCHAR* buffer = StrToTCHARz( string );
1554 int code = OS.SendMessage (handle, OS.CB_ADDSTRING, 0, buffer); 1554 int code = OS.SendMessage (handle, OS.CB_ADDSTRING, 0, buffer);
1555 if (code is OS.CB_ERR) error (DWT.ERROR_ITEM_NOT_ADDED); 1555 if (code is OS.CB_ERR) error (DWT.ERROR_ITEM_NOT_ADDED);
1556 if (code is OS.CB_ERRSPACE) error (DWT.ERROR_ITEM_NOT_ADDED); 1556 if (code is OS.CB_ERRSPACE) error (DWT.ERROR_ITEM_NOT_ADDED);
1557 if ((style & DWT.H_SCROLL) !is 0) { 1557 if ((style & DWT.H_SCROLL) !is 0) {
1801 * @exception DWTException <ul> 1801 * @exception DWTException <ul>
1802 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 1802 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1803 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1803 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1804 * </ul> 1804 * </ul>
1805 */ 1805 */
1806 public void setText (char[] string) { 1806 public void setText (String string) {
1807 checkWidget (); 1807 checkWidget ();
1808 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 1808 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
1809 if ((style & DWT.READ_ONLY) !is 0) { 1809 if ((style & DWT.READ_ONLY) !is 0) {
1810 int index = indexOf (string); 1810 int index = indexOf (string);
1811 if (index !is -1) select (index); 1811 if (index !is -1) select (index);
1848 checkWidget (); 1848 checkWidget ();
1849 if (limit is 0) error (DWT.ERROR_CANNOT_BE_ZERO); 1849 if (limit is 0) error (DWT.ERROR_CANNOT_BE_ZERO);
1850 OS.SendMessage (handle, OS.CB_LIMITTEXT, limit, 0); 1850 OS.SendMessage (handle, OS.CB_LIMITTEXT, limit, 0);
1851 } 1851 }
1852 1852
1853 override void setToolTipText (Shell shell, char[] string) { 1853 override void setToolTipText (Shell shell, String string) {
1854 auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); 1854 auto hwndText = OS.GetDlgItem (handle, CBID_EDIT);
1855 auto hwndList = OS.GetDlgItem (handle, CBID_LIST); 1855 auto hwndList = OS.GetDlgItem (handle, CBID_LIST);
1856 if (hwndText !is null) shell.setToolTipText (hwndText, string); 1856 if (hwndText !is null) shell.setToolTipText (hwndText, string);
1857 if (hwndList !is null) shell.setToolTipText (hwndList, string); 1857 if (hwndList !is null) shell.setToolTipText (hwndList, string);
1858 shell.setToolTipText (handle, string); 1858 shell.setToolTipText (handle, string);
1950 if (hwndList !is null && ListProc !is null) { 1950 if (hwndList !is null && ListProc !is null) {
1951 OS.SetWindowLong (hwndList, OS.GWL_WNDPROC, cast(int) ListProc); 1951 OS.SetWindowLong (hwndList, OS.GWL_WNDPROC, cast(int) ListProc);
1952 } 1952 }
1953 } 1953 }
1954 1954
1955 char[] verifyText (char[] string, int start, int end, Event keyEvent) { 1955 String verifyText (String string, int start, int end, Event keyEvent) {
1956 Event event = new Event (); 1956 Event event = new Event ();
1957 event.text = string; 1957 event.text = string;
1958 event.start = start; 1958 event.start = start;
1959 event.end = end; 1959 event.end = end;
1960 if (keyEvent !is null) { 1960 if (keyEvent !is null) {
2004 if ((style & DWT.SIMPLE) !is 0) return bits | OS.CBS_SIMPLE; 2004 if ((style & DWT.SIMPLE) !is 0) return bits | OS.CBS_SIMPLE;
2005 if ((style & DWT.READ_ONLY) !is 0) return bits | OS.CBS_DROPDOWNLIST; 2005 if ((style & DWT.READ_ONLY) !is 0) return bits | OS.CBS_DROPDOWNLIST;
2006 return bits | OS.CBS_DROPDOWN; 2006 return bits | OS.CBS_DROPDOWN;
2007 } 2007 }
2008 2008
2009 override char[] windowClass () { 2009 override String windowClass () {
2010 return TCHARzToStr( ComboClass ); 2010 return TCHARzToStr( ComboClass );
2011 } 2011 }
2012 2012
2013 override int windowProc () { 2013 override int windowProc () {
2014 return cast(int) ComboProc; 2014 return cast(int) ComboProc;
2074 } 2074 }
2075 } 2075 }
2076 if (msg is OS.CB_SETCURSEL) { 2076 if (msg is OS.CB_SETCURSEL) {
2077 if ((style & DWT.READ_ONLY) !is 0) { 2077 if ((style & DWT.READ_ONLY) !is 0) {
2078 if (hooks (DWT.Verify) || filters (DWT.Verify)) { 2078 if (hooks (DWT.Verify) || filters (DWT.Verify)) {
2079 char[] oldText = getText (), newText = null; 2079 String oldText = getText (), newText = null;
2080 if (wParam is -1) { 2080 if (wParam is -1) {
2081 newText = ""; 2081 newText = "";
2082 } else { 2082 } else {
2083 if (0 <= wParam && wParam < getItemCount ()) { 2083 if (0 <= wParam && wParam < getItemCount ()) {
2084 newText = getItem (wParam); 2084 newText = getItem (wParam);
2270 LRESULT wmClipboard (HWND hwndText, int msg, int wParam, int lParam) { 2270 LRESULT wmClipboard (HWND hwndText, int msg, int wParam, int lParam) {
2271 if ((style & DWT.READ_ONLY) !is 0) return null; 2271 if ((style & DWT.READ_ONLY) !is 0) return null;
2272 if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return null; 2272 if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return null;
2273 bool call = false; 2273 bool call = false;
2274 int start, end; 2274 int start, end;
2275 char[] newText = null; 2275 String newText = null;
2276 switch (msg) { 2276 switch (msg) {
2277 case OS.WM_CLEAR: 2277 case OS.WM_CLEAR:
2278 case OS.WM_CUT: 2278 case OS.WM_CUT:
2279 OS.SendMessage (hwndText, OS.EM_GETSEL, &start, &end); 2279 OS.SendMessage (hwndText, OS.EM_GETSEL, &start, &end);
2280 if (start !is end ) { 2280 if (start !is end ) {
2316 newText = TCHARzToStr( cast(TCHAR*)lParam ); 2316 newText = TCHARzToStr( cast(TCHAR*)lParam );
2317 break; 2317 break;
2318 default: 2318 default:
2319 } 2319 }
2320 if (newText !is null) { 2320 if (newText !is null) {
2321 char[] oldText = newText; 2321 String oldText = newText;
2322 newText = verifyText (newText, start, end, null); 2322 newText = verifyText (newText, start, end, null);
2323 if (newText is null) return LRESULT.ZERO; 2323 if (newText is null) return LRESULT.ZERO;
2324 if (newText!=/*eq*/oldText) { 2324 if (newText!=/*eq*/oldText) {
2325 if (call) { 2325 if (call) {
2326 OS.CallWindowProc (EditProc, hwndText, msg, wParam, lParam); 2326 OS.CallWindowProc (EditProc, hwndText, msg, wParam, lParam);