comparison dwt/widgets/Combo.d @ 238:380bad9f6852

reverted char[] to String
author Frank Benoit <benoit@tionex.de>
date Mon, 05 May 2008 00:42:55 +0200
parents 08789b28bdf3
children ce446666f5a2
comparison
equal deleted inserted replaced
237:98b80b00af79 238:380bad9f6852
77 77
78 GtkWidget* buttonHandle, entryHandle, listHandle, textRenderer; 78 GtkWidget* buttonHandle, entryHandle, listHandle, textRenderer;
79 int lastEventTime, visibleCount = 5; 79 int lastEventTime, visibleCount = 5;
80 GdkEventKey* gdkEventKey; 80 GdkEventKey* gdkEventKey;
81 int fixStart = -1, fixEnd = -1; 81 int fixStart = -1, fixEnd = -1;
82 char[][] items; 82 String[] items;
83 bool ignoreSelect, lockText; 83 bool ignoreSelect, lockText;
84 84
85 static const int INNER_BORDER = 2; 85 static const int INNER_BORDER = 2;
86 86
87 /** 87 /**
146 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 146 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
147 * </ul> 147 * </ul>
148 * 148 *
149 * @see #add(String,int) 149 * @see #add(String,int)
150 */ 150 */
151 public void add (char[] string) { 151 public void add (String string) {
152 checkWidget(); 152 checkWidget();
153 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 153 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
154 add (string, items.length); 154 add (string, items.length);
155 } 155 }
156 156
175 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 175 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
176 * </ul> 176 * </ul>
177 * 177 *
178 * @see #add(String) 178 * @see #add(String)
179 */ 179 */
180 public void add (char[] string, int index) { 180 public void add (String string, int index) {
181 checkWidget(); 181 checkWidget();
182 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 182 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
183 if (!(0 <= index && index <= items.length)) { 183 if (!(0 <= index && index <= items.length)) {
184 error (DWT.ERROR_INVALID_RANGE); 184 error (DWT.ERROR_INVALID_RANGE);
185 } 185 }
186 char[] [] newItems = new char[][]( items.length + 1 ); 186 String [] newItems = new String[]( items.length + 1 );
187 System.arraycopy (items, 0, newItems, 0, index); 187 System.arraycopy (items, 0, newItems, 0, index);
188 newItems [index] = string; 188 newItems [index] = string;
189 System.arraycopy (items, index, newItems, index + 1, items.length - index); 189 System.arraycopy (items, index, newItems, index + 1, items.length - index);
190 items = newItems; 190 items = newItems;
191 char* buffer = toStringz(string); 191 char* buffer = toStringz(string);
772 * @exception DWTException <ul> 772 * @exception DWTException <ul>
773 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 773 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
774 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 774 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
775 * </ul> 775 * </ul>
776 */ 776 */
777 public char[] getItem (int index) { 777 public String getItem (int index) {
778 checkWidget(); 778 checkWidget();
779 if (!(0 <= index && index < items.length)) { 779 if (!(0 <= index && index < items.length)) {
780 error (DWT.ERROR_INVALID_RANGE); 780 error (DWT.ERROR_INVALID_RANGE);
781 } 781 }
782 return items [index]; 782 return items [index];
827 * @exception DWTException <ul> 827 * @exception DWTException <ul>
828 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 828 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
829 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 829 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
830 * </ul> 830 * </ul>
831 */ 831 */
832 public char[] [] getItems () { 832 public String [] getItems () {
833 checkWidget(); 833 checkWidget();
834 char[] [] result = new char[][](items.length); 834 String [] result = new String[](items.length);
835 System.arraycopy (items, 0, result, 0, items.length); 835 System.arraycopy (items, 0, result, 0, items.length);
836 return result; 836 return result;
837 } 837 }
838 838
839 /** 839 /**
935 * @exception DWTException <ul> 935 * @exception DWTException <ul>
936 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 936 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
937 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 937 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
938 * </ul> 938 * </ul>
939 */ 939 */
940 public char[] getText () { 940 public String getText () {
941 checkWidget(); 941 checkWidget();
942 if (entryHandle !is null) { 942 if (entryHandle !is null) {
943 auto str = OS.gtk_entry_get_text (entryHandle); 943 auto str = OS.gtk_entry_get_text (entryHandle);
944 if (str is null) return ""; 944 if (str is null) return "";
945 return fromStringz(str).dup; 945 return fromStringz(str).dup;
947 int index = OS.gtk_combo_box_get_active (handle); 947 int index = OS.gtk_combo_box_get_active (handle);
948 return index !is -1 ? getItem (index) : ""; 948 return index !is -1 ? getItem (index) : "";
949 } 949 }
950 } 950 }
951 951
952 char[] getText (int start, int stop) { 952 String getText (int start, int stop) {
953 /* 953 /*
954 * NOTE: The current implementation uses substring () 954 * NOTE: The current implementation uses substring ()
955 * which can reference a potentially large character 955 * which can reference a potentially large character
956 * array. 956 * array.
957 */ 957 */
1046 return 0; 1046 return 0;
1047 } 1047 }
1048 } else { 1048 } else {
1049 if (!ignoreSelect) { 1049 if (!ignoreSelect) {
1050 auto ptr = OS.gtk_entry_get_text (entryHandle); 1050 auto ptr = OS.gtk_entry_get_text (entryHandle);
1051 char[] text = fromStringz(ptr).dup; 1051 String text = fromStringz(ptr).dup;
1052 for (int i = 0; i < items.length; i++) { 1052 for (int i = 0; i < items.length; i++) {
1053 if (items [i] ==/*eq*/ text) { 1053 if (items [i] ==/*eq*/ text) {
1054 postEvent (DWT.Selection); 1054 postEvent (DWT.Selection);
1055 break; 1055 break;
1056 } 1056 }
1123 OS.gtk_list_unselect_item (listHandle, 0); 1123 OS.gtk_list_unselect_item (listHandle, 0);
1124 OS.g_signal_stop_emission_by_name (entryHandle, OS.delete_text.ptr); 1124 OS.g_signal_stop_emission_by_name (entryHandle, OS.delete_text.ptr);
1125 return 0; 1125 return 0;
1126 } 1126 }
1127 if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return 0; 1127 if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return 0;
1128 char[] newText = verifyText ("", cast(int)/*64*/start_pos, cast(int)/*64*/end_pos); 1128 String newText = verifyText ("", cast(int)/*64*/start_pos, cast(int)/*64*/end_pos);
1129 if (newText is null) { 1129 if (newText is null) {
1130 OS.g_signal_stop_emission_by_name (entryHandle, OS.delete_text.ptr); 1130 OS.g_signal_stop_emission_by_name (entryHandle, OS.delete_text.ptr);
1131 } else { 1131 } else {
1132 if (newText.length > 0) { 1132 if (newText.length > 0) {
1133 int pos; 1133 int pos;
1154 OS.g_signal_stop_emission_by_name (entryHandle, OS.insert_text.ptr); 1154 OS.g_signal_stop_emission_by_name (entryHandle, OS.insert_text.ptr);
1155 return 0; 1155 return 0;
1156 } 1156 }
1157 if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return 0; 1157 if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return 0;
1158 if (new_text is null || new_text_length is 0) return 0; 1158 if (new_text is null || new_text_length is 0) return 0;
1159 char[] oldText = new_text[0..new_text_length]; 1159 String oldText = new_text[0..new_text_length];
1160 int pos; 1160 int pos;
1161 pos = position; 1161 pos = position;
1162 if (pos is -1) { 1162 if (pos is -1) {
1163 auto ptr = OS.gtk_entry_get_text (entryHandle); 1163 auto ptr = OS.gtk_entry_get_text (entryHandle);
1164 pos = fromStringz(ptr).length; 1164 pos = fromStringz(ptr).length;
1165 } 1165 }
1166 char[] newText = verifyText (oldText, pos, pos); 1166 String newText = verifyText (oldText, pos, pos);
1167 if (newText !is oldText) { 1167 if (newText !is oldText) {
1168 int newStart, newEnd; 1168 int newStart, newEnd;
1169 OS.gtk_editable_get_selection_bounds (entryHandle, &newStart, &newEnd); 1169 OS.gtk_editable_get_selection_bounds (entryHandle, &newStart, &newEnd);
1170 if (newText !is null) { 1170 if (newText !is null) {
1171 if (newStart !is newEnd) { 1171 if (newStart !is newEnd) {
1214 * @exception DWTException <ul> 1214 * @exception DWTException <ul>
1215 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 1215 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1216 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1216 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1217 * </ul> 1217 * </ul>
1218 */ 1218 */
1219 public int indexOf (char[] string) { 1219 public int indexOf (String string) {
1220 checkWidget(); 1220 checkWidget();
1221 return indexOf (string, 0); 1221 return indexOf (string, 0);
1222 } 1222 }
1223 1223
1224 /** 1224 /**
1238 * @exception DWTException <ul> 1238 * @exception DWTException <ul>
1239 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 1239 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1240 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1240 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1241 * </ul> 1241 * </ul>
1242 */ 1242 */
1243 public int indexOf (char[] string, int start) { 1243 public int indexOf (String string, int start) {
1244 checkWidget(); 1244 checkWidget();
1245 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 1245 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
1246 if (!(0 <= start && start < items.length)) return -1; 1246 if (!(0 <= start && start < items.length)) return -1;
1247 for (int i=start; i<items.length; i++) { 1247 for (int i=start; i<items.length; i++) {
1248 if (string==/*eq*/items [i]) return i; 1248 if (string==/*eq*/items [i]) return i;
1323 public void remove (int index) { 1323 public void remove (int index) {
1324 checkWidget(); 1324 checkWidget();
1325 if (!(0 <= index && index < items.length)) { 1325 if (!(0 <= index && index < items.length)) {
1326 error (DWT.ERROR_INVALID_RANGE); 1326 error (DWT.ERROR_INVALID_RANGE);
1327 } 1327 }
1328 char[] [] oldItems = items; 1328 String [] oldItems = items;
1329 char[] [] newItems = new char[][]( oldItems.length - 1 ); 1329 String [] newItems = new String[]( oldItems.length - 1 );
1330 System.arraycopy (oldItems, 0, newItems, 0, index); 1330 System.arraycopy (oldItems, 0, newItems, 0, index);
1331 System.arraycopy (oldItems, index + 1, newItems, index, oldItems.length - index - 1); 1331 System.arraycopy (oldItems, index + 1, newItems, index, oldItems.length - index - 1);
1332 items = newItems; 1332 items = newItems;
1333 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { 1333 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) {
1334 if (OS.gtk_combo_box_get_active (handle) is index) clearText (); 1334 if (OS.gtk_combo_box_get_active (handle) is index) clearText ();
1369 checkWidget(); 1369 checkWidget();
1370 if (start > end) return; 1370 if (start > end) return;
1371 if (!(0 <= start && start <= end && end < items.length)) { 1371 if (!(0 <= start && start <= end && end < items.length)) {
1372 error (DWT.ERROR_INVALID_RANGE); 1372 error (DWT.ERROR_INVALID_RANGE);
1373 } 1373 }
1374 char[] [] oldItems = items; 1374 String [] oldItems = items;
1375 char[] [] newItems = new char[][](oldItems.length - (end - start + 1)); 1375 String [] newItems = new String[](oldItems.length - (end - start + 1));
1376 System.arraycopy (oldItems, 0, newItems, 0, start); 1376 System.arraycopy (oldItems, 0, newItems, 0, start);
1377 System.arraycopy (oldItems, end + 1, newItems, start, oldItems.length - end - 1); 1377 System.arraycopy (oldItems, end + 1, newItems, start, oldItems.length - end - 1);
1378 items = newItems; 1378 items = newItems;
1379 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { 1379 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) {
1380 int index = OS.gtk_combo_box_get_active (handle); 1380 int index = OS.gtk_combo_box_get_active (handle);
1416 * @exception DWTException <ul> 1416 * @exception DWTException <ul>
1417 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 1417 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1418 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1418 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1419 * </ul> 1419 * </ul>
1420 */ 1420 */
1421 public void remove (char[] string) { 1421 public void remove (String string) {
1422 checkWidget(); 1422 checkWidget();
1423 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 1423 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
1424 int index = indexOf (string, 0); 1424 int index = indexOf (string, 0);
1425 if (index is -1) error (DWT.ERROR_INVALID_ARGUMENT); 1425 if (index is -1) error (DWT.ERROR_INVALID_ARGUMENT);
1426 remove (index); 1426 remove (index);
1639 * @exception DWTException <ul> 1639 * @exception DWTException <ul>
1640 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 1640 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1641 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1641 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1642 * </ul> 1642 * </ul>
1643 */ 1643 */
1644 public void setItem (int index, char[] string) { 1644 public void setItem (int index, String string) {
1645 checkWidget(); 1645 checkWidget();
1646 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 1646 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
1647 if (!(0 <= index && index < items.length)) { 1647 if (!(0 <= index && index < items.length)) {
1648 error (DWT.ERROR_INVALID_ARGUMENT); 1648 error (DWT.ERROR_INVALID_ARGUMENT);
1649 } 1649 }
1675 * @exception DWTException <ul> 1675 * @exception DWTException <ul>
1676 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 1676 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1677 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1677 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1678 * </ul> 1678 * </ul>
1679 */ 1679 */
1680 public void setItems (char[] [] items) { 1680 public void setItems (String [] items) {
1681 checkWidget(); 1681 checkWidget();
1682 if (items is null) error (DWT.ERROR_NULL_ARGUMENT); 1682 if (items is null) error (DWT.ERROR_NULL_ARGUMENT);
1683 for (int i=0; i<items.length; i++) { 1683 for (int i=0; i<items.length; i++) {
1684 if (items [i] is null) error (DWT.ERROR_INVALID_ARGUMENT); 1684 if (items [i] is null) error (DWT.ERROR_INVALID_ARGUMENT);
1685 } 1685 }
1686 int count = this.items.length; 1686 int count = this.items.length;
1687 this.items = new char[][](items.length); 1687 this.items = new String[](items.length);
1688 System.arraycopy (items, 0, this.items, 0, items.length); 1688 System.arraycopy (items, 0, this.items, 0, items.length);
1689 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) { 1689 if (OS.GTK_VERSION >= OS.buildVERSION (2, 4, 0)) {
1690 clearText (); 1690 clearText ();
1691 for (int i = count - 1; i >= 0; i--) { 1691 for (int i = count - 1; i >= 0; i--) {
1692 OS.gtk_combo_box_remove_text (handle, i); 1692 OS.gtk_combo_box_remove_text (handle, i);
1693 } 1693 }
1694 for (int i = 0; i < items.length; i++) { 1694 for (int i = 0; i < items.length; i++) {
1695 char[] string = items [i]; 1695 String string = items [i];
1696 char* buffer = toStringz(string); 1696 char* buffer = toStringz(string);
1697 OS.gtk_combo_box_insert_text (handle, i, buffer); 1697 OS.gtk_combo_box_insert_text (handle, i, buffer);
1698 } 1698 }
1699 } else { 1699 } else {
1700 lockText = ignoreSelect = true; 1700 lockText = ignoreSelect = true;
1702 auto font = getFontDescription (); 1702 auto font = getFontDescription ();
1703 GdkColor* color = getForegroundColor (); 1703 GdkColor* color = getForegroundColor ();
1704 int direction = OS.gtk_widget_get_direction (handle); 1704 int direction = OS.gtk_widget_get_direction (handle);
1705 int i = 0; 1705 int i = 0;
1706 while (i < items.length) { 1706 while (i < items.length) {
1707 char[] string = items [i]; 1707 String string = items [i];
1708 char * buffer = toStringz(string); 1708 char * buffer = toStringz(string);
1709 auto item = OS.gtk_list_item_new_with_label (buffer); 1709 auto item = OS.gtk_list_item_new_with_label (buffer);
1710 auto label = OS.gtk_bin_get_child (item); 1710 auto label = OS.gtk_bin_get_child (item);
1711 setForegroundColor (label, color); 1711 setForegroundColor (label, color);
1712 OS.gtk_widget_modify_font (label, font); 1712 OS.gtk_widget_modify_font (label, font);
1822 * @exception DWTException <ul> 1822 * @exception DWTException <ul>
1823 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 1823 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1824 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1824 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1825 * </ul> 1825 * </ul>
1826 */ 1826 */
1827 public void setText (char[] string) { 1827 public void setText (String string) {
1828 checkWidget(); 1828 checkWidget();
1829 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 1829 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
1830 if ((style & DWT.READ_ONLY) !is 0) { 1830 if ((style & DWT.READ_ONLY) !is 0) {
1831 int index = indexOf (string); 1831 int index = indexOf (string);
1832 if (index is -1) return; 1832 if (index is -1) return;
1888 checkWidget(); 1888 checkWidget();
1889 if (limit is 0) error (DWT.ERROR_CANNOT_BE_ZERO); 1889 if (limit is 0) error (DWT.ERROR_CANNOT_BE_ZERO);
1890 if (entryHandle !is null) OS.gtk_entry_set_max_length (entryHandle, limit); 1890 if (entryHandle !is null) OS.gtk_entry_set_max_length (entryHandle, limit);
1891 } 1891 }
1892 1892
1893 override void setToolTipText (Shell shell, char[] newString) { 1893 override void setToolTipText (Shell shell, String newString) {
1894 if (entryHandle !is null) shell.setToolTipText (entryHandle, newString); 1894 if (entryHandle !is null) shell.setToolTipText (entryHandle, newString);
1895 if (buttonHandle !is null) shell.setToolTipText (buttonHandle, newString); 1895 if (buttonHandle !is null) shell.setToolTipText (buttonHandle, newString);
1896 } 1896 }
1897 1897
1898 /** 1898 /**
1937 default: 1937 default:
1938 } 1938 }
1939 return super.translateTraversal (keyEvent); 1939 return super.translateTraversal (keyEvent);
1940 } 1940 }
1941 1941
1942 char[] verifyText (char[] string, int start, int end) { 1942 String verifyText (String string, int start, int end) {
1943 if (string.length is 0 && start is end) return null; 1943 if (string.length is 0 && start is end) return null;
1944 Event event = new Event (); 1944 Event event = new Event ();
1945 event.text = string; 1945 event.text = string;
1946 event.start = start; 1946 event.start = start;
1947 event.end = end; 1947 event.end = end;