comparison dwt/widgets/Table.d @ 255:5a30aa9820f3

removed tango.stdc.stringz imports and allow null for arrays and string arguments.
author Frank Benoit <benoit@tionex.de>
date Sun, 15 Jun 2008 22:32:20 +0200
parents ce446666f5a2
children c0d810de7093
comparison
equal deleted inserted replaced
254:8bca790583c3 255:5a30aa9820f3
38 import dwt.widgets.Event; 38 import dwt.widgets.Event;
39 import dwt.widgets.Control; 39 import dwt.widgets.Control;
40 import dwt.widgets.TypedListener; 40 import dwt.widgets.TypedListener;
41 import dwt.dwthelper.utils; 41 import dwt.dwthelper.utils;
42 42
43 static import tango.stdc.stringz;
44 import tango.util.Convert; 43 import tango.util.Convert;
45 44
46 /** 45 /**
47 * Instances of this class implement a selectable user interface 46 * Instances of this class implement a selectable user interface
48 * object that displays a list of images and strings and issues 47 * object that displays a list of images and strings and issues
474 * 473 *
475 * @param indices the array of indices of the items 474 * @param indices the array of indices of the items
476 * 475 *
477 * @exception IllegalArgumentException <ul> 476 * @exception IllegalArgumentException <ul>
478 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> 477 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
479 * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
480 * </ul> 478 * </ul>
481 * @exception DWTException <ul> 479 * @exception DWTException <ul>
482 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 480 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
483 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 481 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
484 * </ul> 482 * </ul>
488 * 486 *
489 * @since 3.0 487 * @since 3.0
490 */ 488 */
491 public void clear (int [] indices) { 489 public void clear (int [] indices) {
492 checkWidget (); 490 checkWidget ();
493 if (indices is null) error (DWT.ERROR_NULL_ARGUMENT); 491 // DWT extension: allow null for zero length string
492 //if (indices is null) error (DWT.ERROR_NULL_ARGUMENT);
494 if (indices.length is 0) return; 493 if (indices.length is 0) return;
495 for (int i=0; i<indices.length; i++) { 494 for (int i=0; i<indices.length; i++) {
496 if (!(0 <= indices [i] && indices [i] < itemCount)) { 495 if (!(0 <= indices [i] && indices [i] < itemCount)) {
497 error (DWT.ERROR_INVALID_RANGE); 496 error (DWT.ERROR_INVALID_RANGE);
498 } 497 }
939 * was not selected, it remains deselected. Indices that are out 938 * was not selected, it remains deselected. Indices that are out
940 * of range and duplicate indices are ignored. 939 * of range and duplicate indices are ignored.
941 * 940 *
942 * @param indices the array of indices for the items to deselect 941 * @param indices the array of indices for the items to deselect
943 * 942 *
944 * @exception IllegalArgumentException <ul>
945 * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li>
946 * </ul>
947 * @exception DWTException <ul> 943 * @exception DWTException <ul>
948 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 944 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
949 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 945 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
950 * </ul> 946 * </ul>
951 */ 947 */
952 public void deselect (int [] indices) { 948 public void deselect (int [] indices) {
953 checkWidget(); 949 checkWidget();
954 if (indices is null) error (DWT.ERROR_NULL_ARGUMENT); 950 // DWT extension: allow null for zero length string
951 //if (indices is null) error (DWT.ERROR_NULL_ARGUMENT);
955 bool fixColumn = showFirstColumn (); 952 bool fixColumn = showFirstColumn ();
956 auto selection = OS.gtk_tree_view_get_selection (handle); 953 auto selection = OS.gtk_tree_view_get_selection (handle);
957 OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); 954 OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED);
958 for (int i=0; i<indices.length; i++) { 955 for (int i=0; i<indices.length; i++) {
959 int index = indices[i]; 956 int index = indices[i];
2127 * </ul> 2124 * </ul>
2128 */ 2125 */
2129 public bool isSelected (int index) { 2126 public bool isSelected (int index) {
2130 checkWidget(); 2127 checkWidget();
2131 auto selection = OS.gtk_tree_view_get_selection (handle); 2128 auto selection = OS.gtk_tree_view_get_selection (handle);
2132 char* buffer = tango.stdc.stringz.toStringz( to!(String)(index)); 2129 char* buffer = toStringz( to!(String)(index));
2133 auto path = OS.gtk_tree_path_new_from_string (buffer); 2130 auto path = OS.gtk_tree_path_new_from_string (buffer);
2134 bool answer = cast(bool)OS.gtk_tree_selection_path_is_selected (selection, path); 2131 bool answer = cast(bool)OS.gtk_tree_selection_path_is_selected (selection, path);
2135 OS.gtk_tree_path_free (path); 2132 OS.gtk_tree_path_free (path);
2136 return answer; 2133 return answer;
2137 } 2134 }
2308 * 2305 *
2309 * @param indices the array of indices of the items 2306 * @param indices the array of indices of the items
2310 * 2307 *
2311 * @exception IllegalArgumentException <ul> 2308 * @exception IllegalArgumentException <ul>
2312 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> 2309 * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
2313 * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li>
2314 * </ul> 2310 * </ul>
2315 * @exception DWTException <ul> 2311 * @exception DWTException <ul>
2316 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 2312 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
2317 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 2313 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2318 * </ul> 2314 * </ul>
2319 */ 2315 */
2320 public void remove (int [] indices) { 2316 public void remove (int [] indices) {
2321 checkWidget(); 2317 checkWidget();
2322 if (indices is null) error (DWT.ERROR_NULL_ARGUMENT); 2318 // DWT extension: allow null for zero length string
2319 //if (indices is null) error (DWT.ERROR_NULL_ARGUMENT);
2323 if (indices.length is 0) return; 2320 if (indices.length is 0) return;
2324 int [] newIndices = new int [indices.length]; 2321 int [] newIndices = new int [indices.length];
2325 System.arraycopy (indices, 0, newIndices, 0, indices.length); 2322 System.arraycopy (indices, 0, newIndices, 0, indices.length);
2326 sort (newIndices); 2323 sort (newIndices);
2327 int start = newIndices [newIndices.length - 1], end = newIndices [0]; 2324 int start = newIndices [newIndices.length - 1], end = newIndices [0];
2753 * then all indices are ignored. 2750 * then all indices are ignored.
2754 * </p> 2751 * </p>
2755 * 2752 *
2756 * @param indices the array of indices for the items to select 2753 * @param indices the array of indices for the items to select
2757 * 2754 *
2758 * @exception IllegalArgumentException <ul>
2759 * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
2760 * </ul>
2761 * @exception DWTException <ul> 2755 * @exception DWTException <ul>
2762 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 2756 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
2763 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 2757 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2764 * </ul> 2758 * </ul>
2765 * 2759 *
2766 * @see Table#setSelection(int[]) 2760 * @see Table#setSelection(int[])
2767 */ 2761 */
2768 public void select (int [] indices) { 2762 public void select (int [] indices) {
2769 checkWidget (); 2763 checkWidget ();
2770 if (indices is null) error (DWT.ERROR_NULL_ARGUMENT); 2764 // DWT extension: allow null for zero length string
2765 //if (indices is null) error (DWT.ERROR_NULL_ARGUMENT);
2771 int length = indices.length; 2766 int length = indices.length;
2772 if (length is 0 || ((style & DWT.SINGLE) !is 0 && length > 1)) return; 2767 if (length is 0 || ((style & DWT.SINGLE) !is 0 && length > 1)) return;
2773 bool fixColumn = showFirstColumn (); 2768 bool fixColumn = showFirstColumn ();
2774 auto selection = OS.gtk_tree_view_get_selection (handle); 2769 auto selection = OS.gtk_tree_view_get_selection (handle);
2775 OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED); 2770 OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, null, null, udCHANGED);
2878 * @exception DWTException <ul> 2873 * @exception DWTException <ul>
2879 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 2874 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
2880 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 2875 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
2881 * </ul> 2876 * </ul>
2882 * @exception IllegalArgumentException <ul> 2877 * @exception IllegalArgumentException <ul>
2883 * <li>ERROR_NULL_ARGUMENT - if the item order is null</li>
2884 * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li> 2878 * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li>
2885 * </ul> 2879 * </ul>
2886 * 2880 *
2887 * @see Table#getColumnOrder() 2881 * @see Table#getColumnOrder()
2888 * @see TableColumn#getMoveable() 2882 * @see TableColumn#getMoveable()
2891 * 2885 *
2892 * @since 3.1 2886 * @since 3.1
2893 */ 2887 */
2894 public void setColumnOrder (int [] order) { 2888 public void setColumnOrder (int [] order) {
2895 checkWidget (); 2889 checkWidget ();
2896 if (order is null) error (DWT.ERROR_NULL_ARGUMENT); 2890 // DWT extension: allow null for zero length string
2891 //if (order is null) error (DWT.ERROR_NULL_ARGUMENT);
2897 if (columnCount is 0) { 2892 if (columnCount is 0) {
2898 if (order.length > 0) error (DWT.ERROR_INVALID_ARGUMENT); 2893 if (order.length > 0) error (DWT.ERROR_INVALID_ARGUMENT);
2899 return; 2894 return;
2900 } 2895 }
2901 if (order.length !is columnCount) error (DWT.ERROR_INVALID_ARGUMENT); 2896 if (order.length !is columnCount) error (DWT.ERROR_INVALID_ARGUMENT);
3167 * then all indices are ignored. 3162 * then all indices are ignored.
3168 * </p> 3163 * </p>
3169 * 3164 *
3170 * @param indices the indices of the items to select 3165 * @param indices the indices of the items to select
3171 * 3166 *
3172 * @exception IllegalArgumentException <ul>
3173 * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li>
3174 * </ul>
3175 * @exception DWTException <ul> 3167 * @exception DWTException <ul>
3176 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 3168 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
3177 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 3169 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
3178 * </ul> 3170 * </ul>
3179 * 3171 *
3180 * @see Table#deselectAll() 3172 * @see Table#deselectAll()
3181 * @see Table#select(int[]) 3173 * @see Table#select(int[])
3182 */ 3174 */
3183 public void setSelection (int [] indices) { 3175 public void setSelection (int [] indices) {
3184 checkWidget (); 3176 checkWidget ();
3185 if (indices is null) error (DWT.ERROR_NULL_ARGUMENT); 3177 // DWT extension: allow null for zero length string
3178 //if (indices is null) error (DWT.ERROR_NULL_ARGUMENT);
3186 deselectAll (); 3179 deselectAll ();
3187 int length = indices.length; 3180 int length = indices.length;
3188 if (length is 0 || ((style & DWT.SINGLE) !is 0 && length > 1)) return; 3181 if (length is 0 || ((style & DWT.SINGLE) !is 0 && length > 1)) return;
3189 bool fixColumn = showFirstColumn (); 3182 bool fixColumn = showFirstColumn ();
3190 selectFocusIndex (indices [0]); 3183 selectFocusIndex (indices [0]);
3231 * </p> 3224 * </p>
3232 * 3225 *
3233 * @param items the array of items 3226 * @param items the array of items
3234 * 3227 *
3235 * @exception IllegalArgumentException <ul> 3228 * @exception IllegalArgumentException <ul>
3236 * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li>
3237 * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li> 3229 * <li>ERROR_INVALID_ARGUMENT - if one of the items has been disposed</li>
3238 * </ul> 3230 * </ul>
3239 * @exception DWTException <ul> 3231 * @exception DWTException <ul>
3240 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 3232 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
3241 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 3233 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
3245 * @see Table#select(int[]) 3237 * @see Table#select(int[])
3246 * @see Table#setSelection(int[]) 3238 * @see Table#setSelection(int[])
3247 */ 3239 */
3248 public void setSelection (TableItem [] items) { 3240 public void setSelection (TableItem [] items) {
3249 checkWidget (); 3241 checkWidget ();
3250 if (items is null) error (DWT.ERROR_NULL_ARGUMENT); 3242 // DWT extension: allow null for zero length string
3243 //if (items is null) error (DWT.ERROR_NULL_ARGUMENT);
3251 bool fixColumn = showFirstColumn (); 3244 bool fixColumn = showFirstColumn ();
3252 deselectAll (); 3245 deselectAll ();
3253 int length = items.length; 3246 int length = items.length;
3254 if (!(length is 0 || ((style & DWT.SINGLE) !is 0 && length > 1))) { 3247 if (!(length is 0 || ((style & DWT.SINGLE) !is 0 && length > 1))) {
3255 bool first = true; 3248 bool first = true;