Mercurial > projects > dwt-win
comparison dwt/widgets/Combo.d @ 239:43b41c7fe84a
work on allow null strings and arrays
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 20 Jun 2008 16:27:36 +0200 |
parents | e2affbeb686d |
children | fd9c62a2998e |
comparison
equal
deleted
inserted
replaced
238:efe25e7c8a96 | 239:43b41c7fe84a |
---|---|
172 /** | 172 /** |
173 * Adds the argument to the end of the receiver's list. | 173 * Adds the argument to the end of the receiver's list. |
174 * | 174 * |
175 * @param string the new item | 175 * @param string the new item |
176 * | 176 * |
177 * @exception IllegalArgumentException <ul> | |
178 * <li>ERROR_NULL_ARGUMENT - if the string is null</li> | |
179 * </ul> | |
180 * @exception DWTException <ul> | 177 * @exception DWTException <ul> |
181 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 178 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
182 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 179 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
183 * </ul> | 180 * </ul> |
184 * | 181 * |
185 * @see #add(String,int) | 182 * @see #add(String,int) |
186 */ | 183 */ |
187 public void add (String string) { | 184 public void add (String string) { |
188 checkWidget (); | 185 checkWidget (); |
189 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 186 // DWT extension: allow null string |
187 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | |
190 auto buffer = StrToTCHARs( getCodePage(), string, true ); | 188 auto buffer = StrToTCHARs( getCodePage(), string, true ); |
191 int result = OS.SendMessage (handle, OS.CB_ADDSTRING, 0, buffer.ptr ); | 189 int result = OS.SendMessage (handle, OS.CB_ADDSTRING, 0, buffer.ptr ); |
192 if (result is OS.CB_ERR) error (DWT.ERROR_ITEM_NOT_ADDED); | 190 if (result is OS.CB_ERR) error (DWT.ERROR_ITEM_NOT_ADDED); |
193 if (result is OS.CB_ERRSPACE) error (DWT.ERROR_ITEM_NOT_ADDED); | 191 if (result is OS.CB_ERRSPACE) error (DWT.ERROR_ITEM_NOT_ADDED); |
194 if ((style & DWT.H_SCROLL) !is 0) setScrollWidth (buffer, true); | 192 if ((style & DWT.H_SCROLL) !is 0) setScrollWidth (buffer, true); |
205 * | 203 * |
206 * @param string the new item | 204 * @param string the new item |
207 * @param index the index for the item | 205 * @param index the index for the item |
208 * | 206 * |
209 * @exception IllegalArgumentException <ul> | 207 * @exception IllegalArgumentException <ul> |
210 * <li>ERROR_NULL_ARGUMENT - if the string is null</li> | |
211 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li> | 208 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li> |
212 * </ul> | 209 * </ul> |
213 * @exception DWTException <ul> | 210 * @exception DWTException <ul> |
214 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 211 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
215 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 212 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
217 * | 214 * |
218 * @see #add(String) | 215 * @see #add(String) |
219 */ | 216 */ |
220 public void add (String string, int index) { | 217 public void add (String string, int index) { |
221 checkWidget (); | 218 checkWidget (); |
222 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 219 // DWT extension: allow null string |
220 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | |
223 int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); | 221 int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); |
224 if (!(0 <= index && index <= count)) { | 222 if (!(0 <= index && index <= count)) { |
225 error (DWT.ERROR_INVALID_RANGE); | 223 error (DWT.ERROR_INVALID_RANGE); |
226 } | 224 } |
227 auto buffer = StrToTCHARs( getCodePage(), string, true ); | 225 auto buffer = StrToTCHARs( getCodePage(), string, true ); |
977 * is found, returns -1. | 975 * is found, returns -1. |
978 * | 976 * |
979 * @param string the search item | 977 * @param string the search item |
980 * @return the index of the item | 978 * @return the index of the item |
981 * | 979 * |
982 * @exception IllegalArgumentException <ul> | |
983 * <li>ERROR_NULL_ARGUMENT - if the string is null</li> | |
984 * </ul> | |
985 * @exception DWTException <ul> | 980 * @exception DWTException <ul> |
986 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 981 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
987 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 982 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
988 * </ul> | 983 * </ul> |
989 */ | 984 */ |
1000 * | 995 * |
1001 * @param string the search item | 996 * @param string the search item |
1002 * @param start the zero-relative index at which to begin the search | 997 * @param start the zero-relative index at which to begin the search |
1003 * @return the index of the item | 998 * @return the index of the item |
1004 * | 999 * |
1005 * @exception IllegalArgumentException <ul> | |
1006 * <li>ERROR_NULL_ARGUMENT - if the string is null</li> | |
1007 * </ul> | |
1008 * @exception DWTException <ul> | 1000 * @exception DWTException <ul> |
1009 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 1001 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
1010 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1002 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1011 * </ul> | 1003 * </ul> |
1012 */ | 1004 */ |
1013 public int indexOf (String string, int start) { | 1005 public int indexOf (String string, int start) { |
1014 checkWidget (); | 1006 checkWidget (); |
1015 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 1007 // DWT externsion: allow null string |
1008 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | |
1016 | 1009 |
1017 /* | 1010 /* |
1018 * Bug in Windows. For some reason, CB_FINDSTRINGEXACT | 1011 * Bug in Windows. For some reason, CB_FINDSTRINGEXACT |
1019 * will not find empty strings even though it is legal | 1012 * will not find empty strings even though it is legal |
1020 * to insert an empty string into a combo. The fix is | 1013 * to insert an empty string into a combo. The fix is |
1021 * to search the combo, an item at a time. | 1014 * to search the combo, an item at a time. |
1022 */ | 1015 */ |
1023 if (string.length is 0) { | 1016 if (string.length is 0) { |
1024 int count = getItemCount (); | 1017 int count = getItemCount (); |
1025 for (int i=start; i<count; i++) { | 1018 for (int i=start; i<count; i++) { |
1026 if (string==/*eq*/getItem (i)) return i; | 1019 if (string.equals (getItem (i))) return i; |
1027 } | 1020 } |
1028 return -1; | 1021 return -1; |
1029 } | 1022 } |
1030 | 1023 |
1031 /* Use CB_FINDSTRINGEXACT to search for the item */ | 1024 /* Use CB_FINDSTRINGEXACT to search for the item */ |
1223 * and removes that item from the list. | 1216 * and removes that item from the list. |
1224 * | 1217 * |
1225 * @param string the item to remove | 1218 * @param string the item to remove |
1226 * | 1219 * |
1227 * @exception IllegalArgumentException <ul> | 1220 * @exception IllegalArgumentException <ul> |
1228 * <li>ERROR_NULL_ARGUMENT - if the string is null</li> | |
1229 * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li> | 1221 * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li> |
1230 * </ul> | 1222 * </ul> |
1231 * @exception DWTException <ul> | 1223 * @exception DWTException <ul> |
1232 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 1224 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
1233 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1225 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1234 * </ul> | 1226 * </ul> |
1235 */ | 1227 */ |
1236 public void remove (String string) { | 1228 public void remove (String string) { |
1237 checkWidget (); | 1229 checkWidget (); |
1238 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 1230 // DWT extension: allow null string |
1231 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | |
1239 int index = indexOf (string, 0); | 1232 int index = indexOf (string, 0); |
1240 if (index is -1) error (DWT.ERROR_INVALID_ARGUMENT); | 1233 if (index is -1) error (DWT.ERROR_INVALID_ARGUMENT); |
1241 remove (index); | 1234 remove (index); |
1242 } | 1235 } |
1243 | 1236 |
1528 * @param index the index for the item | 1521 * @param index the index for the item |
1529 * @param string the new text for the item | 1522 * @param string the new text for the item |
1530 * | 1523 * |
1531 * @exception IllegalArgumentException <ul> | 1524 * @exception IllegalArgumentException <ul> |
1532 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> | 1525 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> |
1533 * <li>ERROR_NULL_ARGUMENT - if the string is null</li> | |
1534 * </ul> | 1526 * </ul> |
1535 * @exception DWTException <ul> | 1527 * @exception DWTException <ul> |
1536 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 1528 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
1537 * <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> |
1538 * </ul> | 1530 * </ul> |
1539 */ | 1531 */ |
1540 public void setItem (int index, String string) { | 1532 public void setItem (int index, String string) { |
1541 checkWidget (); | 1533 checkWidget (); |
1542 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 1534 // DWT extension: allow null string |
1535 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | |
1543 int selection = getSelectionIndex (); | 1536 int selection = getSelectionIndex (); |
1544 remove (index, false); | 1537 remove (index, false); |
1545 if (isDisposed ()) return; | 1538 if (isDisposed ()) return; |
1546 add (string, index); | 1539 add (string, index); |
1547 if (selection !is -1) select (selection); | 1540 if (selection !is -1) select (selection); |
1551 * Sets the receiver's list to be the given array of items. | 1544 * Sets the receiver's list to be the given array of items. |
1552 * | 1545 * |
1553 * @param items the array of items | 1546 * @param items the array of items |
1554 * | 1547 * |
1555 * @exception IllegalArgumentException <ul> | 1548 * @exception IllegalArgumentException <ul> |
1556 * <li>ERROR_NULL_ARGUMENT - if the items array is null</li> | |
1557 * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li> | 1549 * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li> |
1558 * </ul> | 1550 * </ul> |
1559 * @exception DWTException <ul> | 1551 * @exception DWTException <ul> |
1560 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 1552 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
1561 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1553 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1562 * </ul> | 1554 * </ul> |
1563 */ | 1555 */ |
1564 public void setItems (String [] items) { | 1556 public void setItems (String [] items) { |
1565 checkWidget (); | 1557 checkWidget (); |
1566 if (items is null) error (DWT.ERROR_NULL_ARGUMENT); | 1558 // DWT extension: allow null string |
1559 //if (items is null) error (DWT.ERROR_NULL_ARGUMENT); | |
1567 for (int i=0; i<items.length; i++) { | 1560 for (int i=0; i<items.length; i++) { |
1568 if (items [i] is null) error (DWT.ERROR_INVALID_ARGUMENT); | 1561 if (items [i] is null) error (DWT.ERROR_INVALID_ARGUMENT); |
1569 } | 1562 } |
1570 RECT rect; | 1563 RECT rect; |
1571 HDC hDC; | 1564 HDC hDC; |
1802 * display incorrectly. | 1795 * display incorrectly. |
1803 * </p> | 1796 * </p> |
1804 * | 1797 * |
1805 * @param string the new text | 1798 * @param string the new text |
1806 * | 1799 * |
1807 * @exception IllegalArgumentException <ul> | |
1808 * <li>ERROR_NULL_ARGUMENT - if the string is null</li> | |
1809 * </ul> | |
1810 * @exception DWTException <ul> | 1800 * @exception DWTException <ul> |
1811 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 1801 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
1812 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1802 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1813 * </ul> | 1803 * </ul> |
1814 */ | 1804 */ |
1815 public void setText (String string) { | 1805 public void setText (String string) { |
1816 checkWidget (); | 1806 checkWidget (); |
1817 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 1807 // DWT externsion: allow null string |
1808 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | |
1818 if ((style & DWT.READ_ONLY) !is 0) { | 1809 if ((style & DWT.READ_ONLY) !is 0) { |
1819 int index = indexOf (string); | 1810 int index = indexOf (string); |
1820 if (index !is -1) select (index); | 1811 if (index !is -1) select (index); |
1821 return; | 1812 return; |
1822 } | 1813 } |