comparison dwt/widgets/Combo.d @ 7:e831403a80a9

Add 'cast' to casts
author Frank Benoit <benoit@tionex.de>
date Wed, 27 Aug 2008 14:30:35 +0200
parents 1a8b3cb347e0
children d8635bb48c7c
comparison
equal deleted inserted replaced
6:b903c16b6f48 7:e831403a80a9
141 public void add (String string) { 141 public void add (String string) {
142 checkWidget (); 142 checkWidget ();
143 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 143 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
144 NSString str = NSString.stringWith(string); 144 NSString str = NSString.stringWith(string);
145 if ((style & DWT.READ_ONLY) !is 0) { 145 if ((style & DWT.READ_ONLY) !is 0) {
146 NSMenu nsMenu = ((NSPopUpButton)view).menu(); 146 NSMenu nsMenu = (cast(NSPopUpButton)view).menu();
147 NSMenuItem nsItem = (NSMenuItem)new NSMenuItem().alloc(); 147 NSMenuItem nsItem = cast(NSMenuItem)new NSMenuItem().alloc();
148 nsItem.initWithTitle(str, 0, NSString.stringWith("")); 148 nsItem.initWithTitle(str, 0, NSString.stringWith(""));
149 nsMenu.addItem(nsItem); 149 nsMenu.addItem(nsItem);
150 nsItem.release(); 150 nsItem.release();
151 } else { 151 } else {
152 ((NSComboBox)view).addItemWithObjectValue(str); 152 (cast(NSComboBox)view).addItemWithObjectValue(str);
153 } 153 }
154 } 154 }
155 155
156 /** 156 /**
157 * Adds the argument to the receiver's list at the given 157 * Adds the argument to the receiver's list at the given
181 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 181 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
182 int count = getItemCount (); 182 int count = getItemCount ();
183 if (0 > index || index > count) error (DWT.ERROR_INVALID_RANGE); 183 if (0 > index || index > count) error (DWT.ERROR_INVALID_RANGE);
184 NSString str = NSString.stringWith(string); 184 NSString str = NSString.stringWith(string);
185 if ((style & DWT.READ_ONLY) !is 0) { 185 if ((style & DWT.READ_ONLY) !is 0) {
186 NSMenu nsMenu = ((NSPopUpButton)view).menu(); 186 NSMenu nsMenu = (cast(NSPopUpButton)view).menu();
187 NSMenuItem nsItem = (NSMenuItem)new NSMenuItem().alloc(); 187 NSMenuItem nsItem = cast(NSMenuItem)new NSMenuItem().alloc();
188 nsItem.initWithTitle(str, 0, NSString.stringWith("")); 188 nsItem.initWithTitle(str, 0, NSString.stringWith(""));
189 nsMenu.insertItem(nsItem, index); 189 nsMenu.insertItem(nsItem, index);
190 nsItem.release(); 190 nsItem.release();
191 } else { 191 } else {
192 ((NSComboBox)view).insertItemWithObjectValue(str, index); 192 (cast(NSComboBox)view).insertItemWithObjectValue(str, index);
193 } 193 }
194 } 194 }
195 195
196 /** 196 /**
197 * Adds the listener to the collection of listeners who will 197 * Adds the listener to the collection of listeners who will
342 } 342 }
343 343
344 public Point computeSize (int wHint, int hHint, bool changed) { 344 public Point computeSize (int wHint, int hHint, bool changed) {
345 checkWidget (); 345 checkWidget ();
346 int width = 0, height = 0; 346 int width = 0, height = 0;
347 NSControl widget = (NSControl)view; 347 NSControl widget = cast(NSControl)view;
348 NSRect oldRect = widget.frame(); 348 NSRect oldRect = widget.frame();
349 widget.sizeToFit(); 349 widget.sizeToFit();
350 NSRect newRect = widget.frame(); 350 NSRect newRect = widget.frame();
351 widget.setFrame (oldRect); 351 widget.setFrame (oldRect);
352 width = (int)newRect.width; 352 width = cast(int)newRect.width;
353 height = (int)newRect.height; 353 height = cast(int)newRect.height;
354 if (wHint !is DWT.DEFAULT) width = wHint; 354 if (wHint !is DWT.DEFAULT) width = wHint;
355 if (hHint !is DWT.DEFAULT) height = hHint; 355 if (hHint !is DWT.DEFAULT) height = hHint;
356 return new Point (width, height); 356 return new Point (width, height);
357 } 357 }
358 358
376 // copyToClipboard (getText (selection.x, selection.y)); 376 // copyToClipboard (getText (selection.x, selection.y));
377 } 377 }
378 378
379 void createHandle () { 379 void createHandle () {
380 if ((style & DWT.READ_ONLY) !is 0) { 380 if ((style & DWT.READ_ONLY) !is 0) {
381 NSPopUpButton widget = (NSPopUpButton)new SWTPopUpButton().alloc(); 381 NSPopUpButton widget = cast(NSPopUpButton)new SWTPopUpButton().alloc();
382 widget.initWithFrame(new NSRect(), false); 382 widget.initWithFrame(new NSRect(), false);
383 widget.menu().setAutoenablesItems(false); 383 widget.menu().setAutoenablesItems(false);
384 widget.setTarget(widget); 384 widget.setTarget(widget);
385 widget.setAction(OS.sel_sendSelection); 385 widget.setAction(OS.sel_sendSelection);
386 widget.setTag(jniRef); 386 widget.setTag(jniRef);
387 view = widget; 387 view = widget;
388 parent.view.addSubview_(widget); 388 parent.view.addSubview_(widget);
389 } else { 389 } else {
390 NSComboBox widget = (NSComboBox)new SWTComboBox().alloc(); 390 NSComboBox widget = cast(NSComboBox)new SWTComboBox().alloc();
391 widget.initWithFrame(new NSRect()); 391 widget.initWithFrame(new NSRect());
392 widget.setTag(jniRef); 392 widget.setTag(jniRef);
393 widget.setDelegate(widget); 393 widget.setDelegate(widget);
394 view = widget; 394 view = widget;
395 parent.contentView().addSubview_(widget); 395 parent.contentView().addSubview_(widget);
457 public void deselect (int index) { 457 public void deselect (int index) {
458 checkWidget (); 458 checkWidget ();
459 if (index is -1) return; 459 if (index is -1) return;
460 if (index is getSelectionIndex ()) { 460 if (index is getSelectionIndex ()) {
461 if ((style & DWT.READ_ONLY) !is 0) { 461 if ((style & DWT.READ_ONLY) !is 0) {
462 ((NSPopUpButton)view).selectItem(null); 462 (cast(NSPopUpButton)view).selectItem(null);
463 sendEvent (DWT.Modify); 463 sendEvent (DWT.Modify);
464 } else { 464 } else {
465 ((NSComboBox)view).deselectItemAtIndex(index); 465 (cast(NSComboBox)view).deselectItemAtIndex(index);
466 } 466 }
467 } 467 }
468 } 468 }
469 469
470 /** 470 /**
482 * @see #clearSelection 482 * @see #clearSelection
483 */ 483 */
484 public void deselectAll () { 484 public void deselectAll () {
485 checkWidget (); 485 checkWidget ();
486 if ((style & DWT.READ_ONLY) !is 0) { 486 if ((style & DWT.READ_ONLY) !is 0) {
487 ((NSPopUpButton)view).selectItem(null); 487 (cast(NSPopUpButton)view).selectItem(null);
488 sendEvent (DWT.Modify); 488 sendEvent (DWT.Modify);
489 } else { 489 } else {
490 setText (""); 490 setText ("");
491 } 491 }
492 } 492 }
493 493
494 int getCharCount() { 494 int getCharCount() {
495 NSString str; 495 NSString str;
496 if ((style & DWT.READ_ONLY) !is 0) { 496 if ((style & DWT.READ_ONLY) !is 0) {
497 str = ((NSPopUpButton)view).titleOfSelectedItem(); 497 str = (cast(NSPopUpButton)view).titleOfSelectedItem();
498 } else { 498 } else {
499 str = new NSCell(((NSComboBox)view).cell()).title(); 499 str = new NSCell((cast(NSComboBox)view).cell()).title();
500 } 500 }
501 return str.length(); 501 return str.length();
502 } 502 }
503 503
504 /** 504 /**
521 checkWidget (); 521 checkWidget ();
522 int count = getItemCount (); 522 int count = getItemCount ();
523 if (0 > index || index >= count) error (DWT.ERROR_INVALID_RANGE); 523 if (0 > index || index >= count) error (DWT.ERROR_INVALID_RANGE);
524 NSString str; 524 NSString str;
525 if ((style & DWT.READ_ONLY) !is 0) { 525 if ((style & DWT.READ_ONLY) !is 0) {
526 str = ((NSPopUpButton)view).itemTitleAtIndex(index); 526 str = (cast(NSPopUpButton)view).itemTitleAtIndex(index);
527 } else { 527 } else {
528 str = new NSString(((NSComboBox)view).itemObjectValueAtIndex(index)); 528 str = new NSString((cast(NSComboBox)view).itemObjectValueAtIndex(index));
529 } 529 }
530 if (str is null) error(DWT.ERROR_CANNOT_GET_ITEM); 530 if (str is null) error(DWT.ERROR_CANNOT_GET_ITEM);
531 char[] buffer = new char[str.length()]; 531 char[] buffer = new char[str.length()];
532 str.getCharacters_(buffer); 532 str.getCharacters_(buffer);
533 return new String (buffer); 533 return new String (buffer);
544 * </ul> 544 * </ul>
545 */ 545 */
546 public int getItemCount () { 546 public int getItemCount () {
547 checkWidget (); 547 checkWidget ();
548 if ((style & DWT.READ_ONLY) !is 0) { 548 if ((style & DWT.READ_ONLY) !is 0) {
549 return ((NSPopUpButton)view).numberOfItems(); 549 return (cast(NSPopUpButton)view).numberOfItems();
550 } else { 550 } else {
551 return ((NSComboBox)view).numberOfItems(); 551 return (cast(NSComboBox)view).numberOfItems();
552 } 552 }
553 } 553 }
554 554
555 /** 555 /**
556 * Returns the height of the area which would be used to 556 * Returns the height of the area which would be used to
641 // ControlEditTextSelectionRec selection; 641 // ControlEditTextSelectionRec selection;
642 // if (this.selection !is null) { 642 // if (this.selection !is null) {
643 // selection = this.selection; 643 // selection = this.selection;
644 // } else { 644 // } else {
645 // selection = new ControlEditTextSelectionRec (); 645 // selection = new ControlEditTextSelectionRec ();
646 // OS.GetControlData (handle, (short) OS.kHIComboBoxEditTextPart, OS.kControlEditTextSelectionTag, 4, selection, null); 646 // OS.GetControlData (handle, cast(short) OS.kHIComboBoxEditTextPart, OS.kControlEditTextSelectionTag, 4, selection, null);
647 // } 647 // }
648 // return new Point (selection.selStart, selection.selEnd); 648 // return new Point (selection.selStart, selection.selEnd);
649 return null; 649 return null;
650 } 650 }
651 } 651 }
662 * </ul> 662 * </ul>
663 */ 663 */
664 public int getSelectionIndex () { 664 public int getSelectionIndex () {
665 checkWidget (); 665 checkWidget ();
666 if ((style & DWT.READ_ONLY) !is 0) { 666 if ((style & DWT.READ_ONLY) !is 0) {
667 return ((NSPopUpButton)view).indexOfSelectedItem(); 667 return (cast(NSPopUpButton)view).indexOfSelectedItem();
668 } else { 668 } else {
669 return ((NSComboBox)view).indexOfSelectedItem(); 669 return (cast(NSComboBox)view).indexOfSelectedItem();
670 } 670 }
671 } 671 }
672 672
673 /** 673 /**
674 * Returns a string containing a copy of the contents of the 674 * Returns a string containing a copy of the contents of the
688 } 688 }
689 689
690 String getText (int start, int end) { 690 String getText (int start, int end) {
691 NSString str; 691 NSString str;
692 if ((style & DWT.READ_ONLY) !is 0) { 692 if ((style & DWT.READ_ONLY) !is 0) {
693 str = ((NSPopUpButton)view).titleOfSelectedItem(); 693 str = (cast(NSPopUpButton)view).titleOfSelectedItem();
694 } else { 694 } else {
695 str = new NSCell(((NSComboBox)view).cell()).title(); 695 str = new NSCell((cast(NSComboBox)view).cell()).title();
696 } 696 }
697 if (str is null) return ""; 697 if (str is null) return "";
698 int length = str.length(); 698 int length = str.length();
699 char[] buffer = new char[length]; 699 char[] buffer = new char[length];
700 str.getCharacters_(buffer); 700 str.getCharacters_(buffer);
761 public int getVisibleItemCount () { 761 public int getVisibleItemCount () {
762 checkWidget (); 762 checkWidget ();
763 if ((style & DWT.READ_ONLY) !is 0) { 763 if ((style & DWT.READ_ONLY) !is 0) {
764 return getItemCount (); 764 return getItemCount ();
765 } else { 765 } else {
766 return ((NSComboBox)view).numberOfVisibleItems(); 766 return (cast(NSComboBox)view).numberOfVisibleItems();
767 } 767 }
768 } 768 }
769 769
770 /** 770 /**
771 * Searches the receiver's list starting at the first item 771 * Searches the receiver's list starting at the first item
877 checkWidget (); 877 checkWidget ();
878 if (index is -1) error (DWT.ERROR_INVALID_RANGE); 878 if (index is -1) error (DWT.ERROR_INVALID_RANGE);
879 int count = getItemCount (); 879 int count = getItemCount ();
880 if (0 > index || index >= count) error (DWT.ERROR_INVALID_RANGE); 880 if (0 > index || index >= count) error (DWT.ERROR_INVALID_RANGE);
881 if ((style & DWT.READ_ONLY) !is 0) { 881 if ((style & DWT.READ_ONLY) !is 0) {
882 ((NSPopUpButton)view).removeItemAtIndex(index); 882 (cast(NSPopUpButton)view).removeItemAtIndex(index);
883 } else { 883 } else {
884 ((NSComboBox)view).removeItemAtIndex(index); 884 (cast(NSComboBox)view).removeItemAtIndex(index);
885 } 885 }
886 } 886 }
887 887
888 /** 888 /**
889 * Removes the items from the receiver's list which are 889 * Removes the items from the receiver's list which are
948 * </ul> 948 * </ul>
949 */ 949 */
950 public void removeAll () { 950 public void removeAll () {
951 checkWidget (); 951 checkWidget ();
952 if ((style & DWT.READ_ONLY) !is 0) { 952 if ((style & DWT.READ_ONLY) !is 0) {
953 ((NSPopUpButton)view).removeAllItems(); 953 (cast(NSPopUpButton)view).removeAllItems();
954 } else { 954 } else {
955 setText ("", true); 955 setText ("", true);
956 ((NSComboBox)view).removeAllItems(); 956 (cast(NSComboBox)view).removeAllItems();
957 } 957 }
958 } 958 }
959 959
960 /** 960 /**
961 * Removes the listener from the collection of listeners who will 961 * Removes the listener from the collection of listeners who will
1047 public void select (int index) { 1047 public void select (int index) {
1048 checkWidget (); 1048 checkWidget ();
1049 int count = getItemCount (); 1049 int count = getItemCount ();
1050 if (0 <= index && index < count) { 1050 if (0 <= index && index < count) {
1051 if ((style & DWT.READ_ONLY) !is 0) { 1051 if ((style & DWT.READ_ONLY) !is 0) {
1052 ((NSPopUpButton)view).selectItemAtIndex(index); 1052 (cast(NSPopUpButton)view).selectItemAtIndex(index);
1053 sendEvent (DWT.Modify); 1053 sendEvent (DWT.Modify);
1054 } else { 1054 } else {
1055 ((NSComboBox)view).selectItemAtIndex(index); 1055 (cast(NSComboBox)view).selectItemAtIndex(index);
1056 } 1056 }
1057 } 1057 }
1058 } 1058 }
1059 1059
1060 //bool sendKeyEvent (int type, Event event) { 1060 //bool sendKeyEvent (int type, Event event) {
1122 if (color is null) { 1122 if (color is null) {
1123 return; // TODO reset to OS default 1123 return; // TODO reset to OS default
1124 } else { 1124 } else {
1125 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); 1125 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1);
1126 } 1126 }
1127 ((NSTextField)view).setBackgroundColor(nsColor); 1127 (cast(NSTextField)view).setBackgroundColor(nsColor);
1128 } 1128 }
1129 1129
1130 void setForeground (float [] color) { 1130 void setForeground (float [] color) {
1131 NSColor nsColor; 1131 NSColor nsColor;
1132 if (color is null) { 1132 if (color is null) {
1133 return; // TODO reset to OS default 1133 return; // TODO reset to OS default
1134 } else { 1134 } else {
1135 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); 1135 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1);
1136 } 1136 }
1137 ((NSTextField)view).setTextColor(nsColor); 1137 (cast(NSTextField)view).setTextColor(nsColor);
1138 } 1138 }
1139 1139
1140 /** 1140 /**
1141 * Sets the text of the item in the receiver's list at the given 1141 * Sets the text of the item in the receiver's list at the given
1142 * zero-relative index to the string argument. 1142 * zero-relative index to the string argument.
1158 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 1158 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
1159 int count = getItemCount (); 1159 int count = getItemCount ();
1160 if (0 > index || index >= count) error (DWT.ERROR_INVALID_RANGE); 1160 if (0 > index || index >= count) error (DWT.ERROR_INVALID_RANGE);
1161 NSString str = NSString.stringWith(string); 1161 NSString str = NSString.stringWith(string);
1162 if ((style & DWT.READ_ONLY) !is 0) { 1162 if ((style & DWT.READ_ONLY) !is 0) {
1163 NSMenuItem nsItem = ((NSPopUpButton)view).itemAtIndex(index); 1163 NSMenuItem nsItem = (cast(NSPopUpButton)view).itemAtIndex(index);
1164 nsItem.setTitle(str); 1164 nsItem.setTitle(str);
1165 } else { 1165 } else {
1166 NSComboBox widget = (NSComboBox)view; 1166 NSComboBox widget = cast(NSComboBox)view;
1167 widget.insertItemWithObjectValue(str, index); 1167 widget.insertItemWithObjectValue(str, index);
1168 widget.removeItemAtIndex(index + 1); 1168 widget.removeItemAtIndex(index + 1);
1169 } 1169 }
1170 } 1170 }
1171 1171
1192 removeAll(); 1192 removeAll();
1193 if (items.length is 0) return; 1193 if (items.length is 0) return;
1194 for (int i= 0; i < items.length; i++) { 1194 for (int i= 0; i < items.length; i++) {
1195 NSString str = NSString.stringWith(items[i]); 1195 NSString str = NSString.stringWith(items[i]);
1196 if ((style & DWT.READ_ONLY) !is 0) { 1196 if ((style & DWT.READ_ONLY) !is 0) {
1197 NSMenu nsMenu = ((NSPopUpButton)view).menu(); 1197 NSMenu nsMenu = (cast(NSPopUpButton)view).menu();
1198 NSMenuItem nsItem = (NSMenuItem)new NSMenuItem().alloc(); 1198 NSMenuItem nsItem = cast(NSMenuItem)new NSMenuItem().alloc();
1199 nsItem.initWithTitle(str, 0, NSString.stringWith("")); 1199 nsItem.initWithTitle(str, 0, NSString.stringWith(""));
1200 nsMenu.addItem(nsItem); 1200 nsMenu.addItem(nsItem);
1201 nsItem.release(); 1201 nsItem.release();
1202 } else { 1202 } else {
1203 ((NSComboBox)view).addItemWithObjectValue(str); 1203 (cast(NSComboBox)view).addItemWithObjectValue(str);
1204 } 1204 }
1205 } 1205 }
1206 } 1206 }
1207 1207
1208 /*public*/ void setListVisible (bool visible) { 1208 /*public*/ void setListVisible (bool visible) {
1209 checkWidget (); 1209 checkWidget ();
1210 if ((style & DWT.READ_ONLY) !is 0) { 1210 if ((style & DWT.READ_ONLY) !is 0) {
1211 ((NSPopUpButton)view).setPullsDown(visible); 1211 (cast(NSPopUpButton)view).setPullsDown(visible);
1212 } else { 1212 } else {
1213 } 1213 }
1214 } 1214 }
1215 1215
1216 /** 1216 /**
1252 if (selection is null) error (DWT.ERROR_NULL_ARGUMENT); 1252 if (selection is null) error (DWT.ERROR_NULL_ARGUMENT);
1253 if ((style & DWT.READ_ONLY) is 0) { 1253 if ((style & DWT.READ_ONLY) is 0) {
1254 // int length = getCharCount (); 1254 // int length = getCharCount ();
1255 // int start = selection.x, end = selection.y; 1255 // int start = selection.x, end = selection.y;
1256 // ControlEditTextSelectionRec sel = new ControlEditTextSelectionRec (); 1256 // ControlEditTextSelectionRec sel = new ControlEditTextSelectionRec ();
1257 // sel.selStart = (short) Math.min (Math.max (Math.min (start, end), 0), length); 1257 // sel.selStart = cast(short) Math.min (Math.max (Math.min (start, end), 0), length);
1258 // sel.selEnd = (short) Math.min (Math.max (Math.max (start, end), 0), length); 1258 // sel.selEnd = cast(short) Math.min (Math.max (Math.max (start, end), 0), length);
1259 // if (hasFocus ()) { 1259 // if (hasFocus ()) {
1260 // OS.SetControlData (handle, OS.kHIComboBoxEditTextPart, OS.kControlEditTextSelectionTag, 4, sel); 1260 // OS.SetControlData (handle, OS.kHIComboBoxEditTextPart, OS.kControlEditTextSelectionTag, 4, sel);
1261 // } else { 1261 // } else {
1262 // this.selection = sel; 1262 // this.selection = sel;
1263 // } 1263 // }
1303 if (index !is -1 && index !is getSelectionIndex ()) { 1303 if (index !is -1 && index !is getSelectionIndex ()) {
1304 select (index); 1304 select (index);
1305 if (notify) sendEvent (DWT.Modify); 1305 if (notify) sendEvent (DWT.Modify);
1306 } 1306 }
1307 } else { 1307 } else {
1308 new NSCell(((NSComboBox)view).cell()).setTitle(NSString.stringWith(string)); 1308 new NSCell((cast(NSComboBox)view).cell()).setTitle(NSString.stringWith(string));
1309 if (notify) sendEvent (DWT.Modify); 1309 if (notify) sendEvent (DWT.Modify);
1310 } 1310 }
1311 } 1311 }
1312 1312
1313 /** 1313 /**
1357 checkWidget (); 1357 checkWidget ();
1358 if (count < 0) return; 1358 if (count < 0) return;
1359 if ((style & DWT.READ_ONLY) !is 0) { 1359 if ((style & DWT.READ_ONLY) !is 0) {
1360 //TODO 1360 //TODO
1361 } else { 1361 } else {
1362 ((NSComboBox)view).setNumberOfVisibleItems(count); 1362 (cast(NSComboBox)view).setNumberOfVisibleItems(count);
1363 } 1363 }
1364 } 1364 }
1365 1365
1366 String verifyText (String string, int start, int end, Event keyEvent) { 1366 String verifyText (String string, int start, int end, Event keyEvent) {
1367 Event event = new Event (); 1367 Event event = new Event ();