comparison dwt/widgets/Combo.d @ 62:10eaa644646f

Ported dwt.widgets.Combo
author Jacob Carlborg <doob@me.com>
date Tue, 23 Dec 2008 22:21:02 +0100
parents cfa563df4fdd
children c7f7f4d7091a
comparison
equal deleted inserted replaced
61:c74ba20de292 62:10eaa644646f
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 *
11 * Port to the D programming language:
12 * Jacob Carlborg <doob@me.com>
10 *******************************************************************************/ 13 *******************************************************************************/
11 module dwt.widgets.Combo; 14 module dwt.widgets.Combo;
12 15
13 import dwt.dwthelper.utils; 16 import dwt.dwthelper.utils;
14 17
39 import dwt.internal.cocoa.NSTextFieldCell; 42 import dwt.internal.cocoa.NSTextFieldCell;
40 import dwt.internal.cocoa.OS; 43 import dwt.internal.cocoa.OS;
41 import dwt.internal.cocoa.SWTComboBox; 44 import dwt.internal.cocoa.SWTComboBox;
42 import dwt.internal.cocoa.SWTPopUpButton; 45 import dwt.internal.cocoa.SWTPopUpButton;
43 46
47 import dwt.internal.c.Carbon;
48 import objc = dwt.internal.objc.runtime;
49 import dwt.widgets.Composite;
50 import dwt.widgets.TypedListener;
51
44 /** 52 /**
45 * Instances of this class are controls that allow the user 53 * Instances of this class are controls that allow the user
46 * to choose an item from a list of items, or optionally 54 * to choose an item from a list of items, or optionally
47 * enter a new value by typing it into an editable text 55 * enter a new value by typing it into an editable text
48 * field. Often, <code>Combo</code>s are used in the same place 56 * field. Often, <code>Combo</code>s are used in the same place
86 94
87 /** 95 /**
88 * the operating system limit for the number of characters 96 * the operating system limit for the number of characters
89 * that the text field in an instance of this class can hold 97 * that the text field in an instance of this class can hold
90 */ 98 */
91 public static final int LIMIT; 99 public static const int LIMIT;
92 100
93 /* 101 /*
94 * These values can be different on different platforms. 102 * These values can be different on different platforms.
95 * Therefore they are not initialized in the declaration 103 * Therefore they are not initialized in the declaration
96 * to stop the compiler from inlining. 104 * to stop the compiler from inlining.
97 */ 105 */
98 static { 106 static this () {
99 LIMIT = 0x7FFFFFFF; 107 LIMIT = 0x7FFFFFFF;
100 } 108 }
101 109
102 110
103 /** 111 /**
153 checkWidget (); 161 checkWidget ();
154 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 162 if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
155 NSString str = NSString.stringWith(string); 163 NSString str = NSString.stringWith(string);
156 if ((style & DWT.READ_ONLY) !is 0) { 164 if ((style & DWT.READ_ONLY) !is 0) {
157 NSMenu nsMenu = (cast(NSPopUpButton)view).menu(); 165 NSMenu nsMenu = (cast(NSPopUpButton)view).menu();
158 NSMenuItem nsItem = cast(NSMenuItem)new NSMenuItem().alloc(); 166 NSMenuItem nsItem = cast(NSMenuItem)(new NSMenuItem()).alloc();
159 nsItem.initWithTitle(str, 0, NSString.stringWith("")); 167 nsItem.initWithTitle(str, null, NSString.stringWith(""));
160 nsMenu.addItem(nsItem); 168 nsMenu.addItem(nsItem);
161 nsItem.release(); 169 nsItem.release();
162 } else { 170 } else {
163 (cast(NSComboBox)view).addItemWithObjectValue(str); 171 (cast(NSComboBox)view).addItemWithObjectValue(str);
164 } 172 }
193 int count = getItemCount (); 201 int count = getItemCount ();
194 if (0 > index || index > count) error (DWT.ERROR_INVALID_RANGE); 202 if (0 > index || index > count) error (DWT.ERROR_INVALID_RANGE);
195 NSString str = NSString.stringWith(string); 203 NSString str = NSString.stringWith(string);
196 if ((style & DWT.READ_ONLY) !is 0) { 204 if ((style & DWT.READ_ONLY) !is 0) {
197 NSMenu nsMenu = (cast(NSPopUpButton)view).menu(); 205 NSMenu nsMenu = (cast(NSPopUpButton)view).menu();
198 NSMenuItem nsItem = cast(NSMenuItem)new NSMenuItem().alloc(); 206 NSMenuItem nsItem = cast(NSMenuItem)(new NSMenuItem()).alloc();
199 nsItem.initWithTitle(str, 0, NSString.stringWith("")); 207 nsItem.initWithTitle(str, null, NSString.stringWith(""));
200 nsMenu.insertItem(nsItem, index); 208 nsMenu.insertItem(nsItem, index);
201 nsItem.release(); 209 nsItem.release();
202 } else { 210 } else {
203 (cast(NSComboBox)view).insertItemWithObjectValue(str, index); 211 (cast(NSComboBox)view).insertItemWithObjectValue(str, index);
204 } 212 }
288 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); 296 if (listener is null) error (DWT.ERROR_NULL_ARGUMENT);
289 TypedListener typedListener = new TypedListener (listener); 297 TypedListener typedListener = new TypedListener (listener);
290 addListener (DWT.Verify, typedListener); 298 addListener (DWT.Verify, typedListener);
291 } 299 }
292 300
293 bool becomeFirstResponder (int /*long*/ id, int /*long*/ sel) { 301 bool becomeFirstResponder (objc.id id, objc.SEL sel) {
294 receivingFocus = true; 302 receivingFocus = true;
295 bool result = super.becomeFirstResponder (id, sel); 303 bool result = super.becomeFirstResponder (id, sel);
296 receivingFocus = false; 304 receivingFocus = false;
297 return result; 305 return result;
298 } 306 }
361 369
362 public Point computeSize (int wHint, int hHint, bool changed) { 370 public Point computeSize (int wHint, int hHint, bool changed) {
363 checkWidget (); 371 checkWidget ();
364 int width = 0, height = 0; 372 int width = 0, height = 0;
365 NSControl widget = cast(NSControl)view; 373 NSControl widget = cast(NSControl)view;
366 NSRect rect = new NSRect (); 374 NSRect rect = NSRect ();
367 rect.width = rect.height = Float.MAX_VALUE; 375 rect.width = rect.height = Float.MAX_VALUE;
368 NSSize size = widget.cell ().cellSizeForBounds (rect); 376 NSSize size = widget.cell ().cellSizeForBounds (rect);
369 width = (int)Math.ceil (size.width); 377 width = cast(int)Math.ceil (size.width);
370 height = cast(int)Math.ceil (size.height); 378 height = cast(int)Math.ceil (size.height);
371 /* 379 /*
372 * Feature in Cocoa. Attempting to create an NSComboBox with a 380 * Feature in Cocoa. Attempting to create an NSComboBox with a
373 * height > 27 spews a very long warning message to stdout and 381 * height > 27 spews a very long warning message to stdout and
374 * often draws the combo incorrectly. The workaround is to limit 382 * often draws the combo incorrectly. The workaround is to limit
402 copyToClipboard (getText (selection.x, selection.y)); 410 copyToClipboard (getText (selection.x, selection.y));
403 } 411 }
404 412
405 void createHandle () { 413 void createHandle () {
406 if ((style & DWT.READ_ONLY) !is 0) { 414 if ((style & DWT.READ_ONLY) !is 0) {
407 NSPopUpButton widget = cast(NSPopUpButton)new SWTPopUpButton().alloc(); 415 NSPopUpButton widget = cast(NSPopUpButton)(new SWTPopUpButton()).alloc();
408 widget.initWithFrame(NSRect(), false); 416 widget.initWithFrame(NSRect(), false);
409 widget.menu().setAutoenablesItems(false); 417 widget.menu().setAutoenablesItems(false);
410 widget.setTarget(widget); 418 widget.setTarget(widget);
411 widget.setAction(OS.sel_sendSelection); 419 widget.setAction(OS.sel_sendSelection);
412 view = widget; 420 view = widget;
413 } else { 421 } else {
414 NSComboBox widget = cast(NSComboBox)new SWTComboBox().alloc(); 422 NSComboBox widget = cast(NSComboBox)(new SWTComboBox()).alloc();
415 widget.initWithFrame(NSRect()); 423 widget.initWithFrame(NSRect());
416 widget.setDelegate(widget); 424 widget.setDelegate(widget);
417 view = widget; 425 view = widget;
418 } 426 }
419 } 427 }
465 } 473 }
466 474
467 475
468 void deregister() { 476 void deregister() {
469 super.deregister(); 477 super.deregister();
470 display.removeWidget(((NSControl)view).cell()); 478 display.removeWidget((cast(NSControl)view).cell());
471 } 479 }
472 480
473 /** 481 /**
474 * Deselects the item at the given zero-relative index in the receiver's 482 * Deselects the item at the given zero-relative index in the receiver's
475 * list. If the item at the index was already deselected, it remains 483 * list. If the item at the index was already deselected, it remains
517 } else { 525 } else {
518 setText (""); 526 setText ("");
519 } 527 }
520 } 528 }
521 529
522 int getCharCount() { 530 NSUInteger getCharCount() {
523 NSString str; 531 NSString str;
524 if ((style & DWT.READ_ONLY) !is 0) { 532 if ((style & DWT.READ_ONLY) !is 0) {
525 str = (cast(NSPopUpButton)view).titleOfSelectedItem(); 533 str = (cast(NSPopUpButton)view).titleOfSelectedItem();
526 } else { 534 } else {
527 str = new NSCell((cast(NSComboBox)view).cell()).title(); 535 str = (new NSCell((cast(NSComboBox)view).cell())).title();
528 } 536 }
529 return (int)/*64*/str.length(); 537 return str.length();
530 } 538 }
531 539
532 /** 540 /**
533 * Returns the item at the given, zero-relative index in the 541 * Returns the item at the given, zero-relative index in the
534 * receiver's list. Throws an exception if the index is out 542 * receiver's list. Throws an exception if the index is out
611 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 619 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
612 * </ul> 620 * </ul>
613 */ 621 */
614 public String [] getItems () { 622 public String [] getItems () {
615 checkWidget (); 623 checkWidget ();
616 int count = getItemCount (); 624 NSUInteger count = getItemCount ();
617 String [] result = new String [count]; 625 String [] result = new String [count];
618 for (int i=0; i<count; i++) result [i] = getItem (i); 626 for (NSUInteger i=0; i<count; i++) result [i] = getItem (i);
619 return result; 627 return result;
620 } 628 }
621 629
622 int getMininumHeight () { 630 int getMininumHeight () {
623 return getTextHeight (); 631 return getTextHeight ();
660 * </ul> 668 * </ul>
661 */ 669 */
662 public Point getSelection () { 670 public Point getSelection () {
663 checkWidget (); 671 checkWidget ();
664 if ((style & DWT.READ_ONLY) !is 0) { 672 if ((style & DWT.READ_ONLY) !is 0) {
665 return new Point (0, getCharCount ()); 673 return new Point (0, cast(int) getCharCount ());
666 } else { 674 } else {
667 if (selectionRange is null) { 675 if (selectionRange is null) {
668 NSString str = new NSTextFieldCell (((NSTextField) view).cell ()).title (); 676 NSString str = (new NSTextFieldCell ((cast(NSTextField) view).cell ())).title ();
669 return new Point((int)/*64*/str.length (), (int)/*64*/str.length ()); 677 return new Point(cast(int)/*64*/str.length (), cast(int)/*64*/str.length ());
670 } 678 }
671 return new Point((int)/*64*/selectionRange.location, (int)/*64*/(selectionRange.location + selectionRange.length)); 679 return new Point(cast(int)/*64*/selectionRange.location, cast(int)/*64*/(selectionRange.location + selectionRange.length));
672 } 680 }
673 } 681 }
674 682
675 /** 683 /**
676 * Returns the zero-relative index of the item which is currently 684 * Returns the zero-relative index of the item which is currently
704 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 712 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
705 * </ul> 713 * </ul>
706 */ 714 */
707 public String getText () { 715 public String getText () {
708 checkWidget (); 716 checkWidget ();
709 return new String (getText(0, -1)); 717 return new_String (getText(0, -1));
710 } 718 }
711 719
712 char [] getText (int start, int end) { 720 wchar [] getText (int start, int end) {
713 NSString str; 721 NSString str;
714 if ((style & DWT.READ_ONLY) !is 0) { 722 if ((style & DWT.READ_ONLY) !is 0) {
715 str = (cast(NSPopUpButton)view).titleOfSelectedItem(); 723 str = (cast(NSPopUpButton)view).titleOfSelectedItem();
716 } else { 724 } else {
717 str = new NSCell((cast(NSComboBox)view).cell()).title(); 725 str = (new NSCell((cast(NSComboBox)view).cell())).title();
718 } 726 }
719 if (str is null) return new char[0]; 727 if (str is null) return new wchar[0];
720 NSRange range = new NSRange (); 728 NSRange range = NSRange ();
721 range.location = start; 729 range.location = start;
722 if (end is -1) { 730 if (end is -1) {
723 int /*long*/ length = str.length(); 731 NSUInteger length = str.length();
724 range.length = length - start; 732 range.length = length - start;
725 } else { 733 } else {
726 range.length = end - start; 734 range.length = end - start;
727 } 735 }
728 char [] buffer= new char [(int)/*64*/range.length]; 736 wchar [] buffer= new wchar [range.length];
729 str.getCharacters(buffer, range); 737 str.getCharacters(buffer.ptr, range);
730 return buffer; 738 return buffer;
731 } 739 }
732 740
733 /** 741 /**
734 * Returns the height of the receivers's text field. 742 * Returns the height of the receivers's text field.
844 } 852 }
845 return -1; 853 return -1;
846 } 854 }
847 855
848 void insertEditText (String string) { 856 void insertEditText (String string) {
849 int length = string.length (); 857 NSUInteger length = string.length ();
850 Point selection = getSelection (); 858 Point selection = getSelection ();
851 if (hasFocus ()) { 859 if (hasFocus ()) {
852 if (textLimit !is LIMIT) { 860 if (textLimit !is LIMIT) {
853 int charCount = getCharCount(); 861 int charCount = getCharCount();
854 if (charCount - (selection.y - selection.x) + length > textLimit) { 862 if (charCount - (selection.y - selection.x) + length > textLimit) {
855 length = textLimit - charCount + (selection.y - selection.x); 863 length = textLimit - charCount + (selection.y - selection.x);
856 } 864 }
857 } 865 }
858 char [] buffer = new char [length]; 866 wchar [] buffer = new wchar [length];
859 string.getChars (0, buffer.length, buffer, 0); 867 string.getChars (0, buffer.length, buffer, 0);
860 NSString nsstring = NSString.stringWithCharacters (buffer, buffer.length); 868 NSString nsstring = NSString.stringWithCharacters (buffer.ptr, buffer.length);
861 NSText editor = ((NSTextField) view).currentEditor (); 869 NSText editor = (cast(NSTextField) view).currentEditor ();
862 editor.replaceCharactersInRange (editor.selectedRange (), nsstring); 870 editor.replaceCharactersInRange (editor.selectedRange (), nsstring);
863 selectionRange = null; 871 selectionRange = null;
864 } else { 872 } else {
865 String oldText = getText (); 873 String oldText = getText ();
866 if (textLimit !is LIMIT) { 874 if (textLimit !is LIMIT) {
869 string = string.substring(0, textLimit - charCount + (selection.y - selection.x)); 877 string = string.substring(0, textLimit - charCount + (selection.y - selection.x));
870 } 878 }
871 } 879 }
872 String newText = oldText.substring (0, selection.x) + string + oldText.substring (selection.y); 880 String newText = oldText.substring (0, selection.x) + string + oldText.substring (selection.y);
873 NSString nsstring = NSString.stringWith(newText); 881 NSString nsstring = NSString.stringWith(newText);
874 new NSCell (((NSTextField) view).cell ()).setTitle (nsstring); 882 (new NSCell ((cast(NSTextField) view).cell ())).setTitle (nsstring);
875 selectionRange = null; 883 selectionRange = null;
876 setSelection (new Point(selection.x + string.length (), 0)); 884 setSelection (new Point(selection.x + string.length (), 0));
877 } 885 }
878 } 886 }
879 887
916 sendEvent (DWT.Modify); 924 sendEvent (DWT.Modify);
917 } 925 }
918 926
919 void register() { 927 void register() {
920 super.register(); 928 super.register();
921 display.addWidget(((NSControl)view).cell(), this); 929 display.addWidget((cast(NSControl)view).cell(), this);
922 } 930 }
923 931
924 void releaseWidget () { 932 void releaseWidget () {
925 super.releaseWidget (); 933 super.releaseWidget ();
926 selectionRange = null; 934 selectionRange = null;
1186 1194
1187 bool sendKeyEvent (NSEvent nsEvent, int type) { 1195 bool sendKeyEvent (NSEvent nsEvent, int type) {
1188 bool result = super.sendKeyEvent (nsEvent, type); 1196 bool result = super.sendKeyEvent (nsEvent, type);
1189 if (!result) return result; 1197 if (!result) return result;
1190 int stateMask = 0; 1198 int stateMask = 0;
1191 int /*long*/ modifierFlags = nsEvent.modifierFlags(); 1199 NSUInteger modifierFlags = nsEvent.modifierFlags();
1192 if ((modifierFlags & OS.NSAlternateKeyMask) !is 0) stateMask |= DWT.ALT; 1200 if ((modifierFlags & OS.NSAlternateKeyMask) !is 0) stateMask |= DWT.ALT;
1193 if ((modifierFlags & OS.NSShiftKeyMask) !is 0) stateMask |= DWT.SHIFT; 1201 if ((modifierFlags & OS.NSShiftKeyMask) !is 0) stateMask |= DWT.SHIFT;
1194 if ((modifierFlags & OS.NSControlKeyMask) !is 0) stateMask |= DWT.CONTROL; 1202 if ((modifierFlags & OS.NSControlKeyMask) !is 0) stateMask |= DWT.CONTROL;
1195 if ((modifierFlags & OS.NSCommandKeyMask) !is 0) stateMask |= DWT.COMMAND; 1203 if ((modifierFlags & OS.NSCommandKeyMask) !is 0) stateMask |= DWT.COMMAND;
1196 if (type !is DWT.KeyDown) return result; 1204 if (type !is DWT.KeyDown) return result;
1197 if (stateMask is DWT.COMMAND) { 1205 if (stateMask is DWT.COMMAND) {
1198 short keyCode = nsEvent.keyCode (); 1206 ushort keyCode = nsEvent.keyCode ();
1199 switch (keyCode) { 1207 switch (keyCode) {
1200 case 7: /* X */ 1208 case 7: /* X */
1201 cut (); 1209 cut ();
1202 return false; 1210 return false;
1203 case 8: /* C */ 1211 case 8: /* C */
1207 paste (); 1215 paste ();
1208 return false; 1216 return false;
1209 } 1217 }
1210 } 1218 }
1211 if ((style & DWT.SINGLE) !is 0) { 1219 if ((style & DWT.SINGLE) !is 0) {
1212 short keyCode = nsEvent.keyCode (); 1220 ushort keyCode = nsEvent.keyCode ();
1213 switch (keyCode) { 1221 switch (keyCode) {
1214 case 76: /* KP Enter */ 1222 case 76: /* KP Enter */
1215 case 36: /* Return */ 1223 case 36: /* Return */
1216 postEvent (DWT.DefaultSelection); 1224 postEvent (DWT.DefaultSelection);
1217 } 1225 }
1220 if ((stateMask & DWT.COMMAND) !is 0) return result; 1228 if ((stateMask & DWT.COMMAND) !is 0) return result;
1221 String oldText = ""; 1229 String oldText = "";
1222 int charCount = getCharCount (); 1230 int charCount = getCharCount ();
1223 Point selection = getSelection (); 1231 Point selection = getSelection ();
1224 int start = selection.x, end = selection.y; 1232 int start = selection.x, end = selection.y;
1225 short keyCode = nsEvent.keyCode (); 1233 ushort keyCode = nsEvent.keyCode ();
1226 NSString characters = nsEvent.charactersIgnoringModifiers(); 1234 NSString characters = nsEvent.charactersIgnoringModifiers();
1227 char character = (char) characters.characterAtIndex(0); 1235 wchar character = characters.characterAtIndex(0);
1228 switch (keyCode) { 1236 switch (keyCode) {
1229 case 51: /* Backspace */ 1237 case 51: /* Backspace */
1230 if (start is end) { 1238 if (start is end) {
1231 if (start is 0) return true; 1239 if (start is 0) return true;
1232 start = Math.max (0, start - 1); 1240 start = Math.max (0, start - 1);
1238 end = Math.min (end + 1, charCount); 1246 end = Math.min (end + 1, charCount);
1239 } 1247 }
1240 break; 1248 break;
1241 default: 1249 default:
1242 if (character !is '\t' && character < 0x20) return true; 1250 if (character !is '\t' && character < 0x20) return true;
1243 oldText = new String (new char [] {character}); 1251 oldText = new_String ([character]);
1244 } 1252 }
1245 String newText = verifyText (oldText, start, end, nsEvent); 1253 String newText = verifyText (oldText, start, end, nsEvent);
1246 if (newText is null) return false; 1254 if (newText is null) return false;
1247 if (charCount - (end - start) + newText.length () > textLimit) { 1255 if (charCount - (end - start) + newText.length () > textLimit) {
1248 return false; 1256 return false;
1253 if (newText.length () !is 0) sendEvent (DWT.Modify); 1261 if (newText.length () !is 0) sendEvent (DWT.Modify);
1254 } 1262 }
1255 return result; 1263 return result;
1256 } 1264 }
1257 1265
1258 void setBackground (float [] color) { 1266 void setBackground (CGFloat [] color) {
1259 NSColor nsColor; 1267 NSColor nsColor;
1260 if (color is null) { 1268 if (color is null) {
1261 return; // TODO reset to OS default 1269 return; // TODO reset to OS default
1262 } else { 1270 } else {
1263 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); 1271 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1);
1276 * often draws the combo incorrectly. The workaround is to limit 1284 * often draws the combo incorrectly. The workaround is to limit
1277 * the height of editable Combos to the height that is required 1285 * the height of editable Combos to the height that is required
1278 * to display their text. 1286 * to display their text.
1279 */ 1287 */
1280 if ((style & DWT.READ_ONLY) is 0) { 1288 if ((style & DWT.READ_ONLY) is 0) {
1281 NSControl widget = (NSControl)view; 1289 NSControl widget = cast(NSControl)view;
1282 NSRect rect = new NSRect (); 1290 NSRect rect = NSRect ();
1283 rect.width = rect.height = Float.MAX_VALUE; 1291 rect.width = rect.height = Float.MAX_VALUE;
1284 NSSize size = widget.cell ().cellSizeForBounds (rect); 1292 NSSize size = widget.cell ().cellSizeForBounds (rect);
1285 height = Math.min (height, (int)Math.ceil (size.height)); 1293 height = Math.min (height, cast(int)Math.ceil (size.height));
1286 } 1294 }
1287 super.setBounds (x, y, width, height, move, resize); 1295 super.setBounds (x, y, width, height, move, resize);
1288 } 1296 }
1289 1297
1290 void setForeground (float [] color) { 1298 void setForeground (CGFloat [] color) {
1291 NSColor nsColor; 1299 NSColor nsColor;
1292 if (color is null) { 1300 if (color is null) {
1293 return; // TODO reset to OS default 1301 return; // TODO reset to OS default
1294 } else { 1302 } else {
1295 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); 1303 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1);
1317 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 1325 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1318 * </ul> 1326 * </ul>
1319 */ 1327 */
1320 public void setItem (int index, String string) { 1328 public void setItem (int index, String string) {
1321 checkWidget (); 1329 checkWidget ();
1322 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); 1330 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
1323 int count = getItemCount (); 1331 int count = getItemCount ();
1324 if (0 > index || index >= count) error (DWT.ERROR_INVALID_RANGE); 1332 if (0 > index || index >= count) error (DWT.ERROR_INVALID_RANGE);
1325 NSString str = NSString.stringWith(string); 1333 NSString str = NSString.stringWith(string);
1326 if ((style & DWT.READ_ONLY) !is 0) { 1334 if ((style & DWT.READ_ONLY) !is 0) {
1327 NSMenuItem nsItem = (cast(NSPopUpButton)view).itemAtIndex(index); 1335 NSMenuItem nsItem = (cast(NSPopUpButton)view).itemAtIndex(index);
1357 if (items.length is 0) return; 1365 if (items.length is 0) return;
1358 for (int i= 0; i < items.length; i++) { 1366 for (int i= 0; i < items.length; i++) {
1359 NSString str = NSString.stringWith(items[i]); 1367 NSString str = NSString.stringWith(items[i]);
1360 if ((style & DWT.READ_ONLY) !is 0) { 1368 if ((style & DWT.READ_ONLY) !is 0) {
1361 NSMenu nsMenu = (cast(NSPopUpButton)view).menu(); 1369 NSMenu nsMenu = (cast(NSPopUpButton)view).menu();
1362 NSMenuItem nsItem = cast(NSMenuItem)new NSMenuItem().alloc(); 1370 NSMenuItem nsItem = cast(NSMenuItem)(new NSMenuItem()).alloc();
1363 nsItem.initWithTitle(str, 0, NSString.stringWith("")); 1371 nsItem.initWithTitle(str, null, NSString.stringWith(""));
1364 nsMenu.addItem(nsItem); 1372 nsMenu.addItem(nsItem);
1365 nsItem.release(); 1373 nsItem.release();
1366 } else { 1374 } else {
1367 (cast(NSComboBox)view).addItemWithObjectValue(str); 1375 (cast(NSComboBox)view).addItemWithObjectValue(str);
1368 } 1376 }
1431 */ 1439 */
1432 public void setSelection (Point selection) { 1440 public void setSelection (Point selection) {
1433 checkWidget (); 1441 checkWidget ();
1434 if (selection is null) error (DWT.ERROR_NULL_ARGUMENT); 1442 if (selection is null) error (DWT.ERROR_NULL_ARGUMENT);
1435 if ((style & DWT.READ_ONLY) is 0) { 1443 if ((style & DWT.READ_ONLY) is 0) {
1436 NSString str = new NSCell(((NSComboBox)view).cell()).title(); 1444 NSString str = (new NSCell((cast(NSComboBox)view).cell())).title();
1437 int length = (int)/*64*/str.length(); 1445 NSUInteger length = str.length();
1438 int start = Math.min (Math.max (Math.min (selection.x, selection.y), 0), length); 1446 NSUInteger start = Math.min (Math.max (Math.min (selection.x, selection.y), 0), length);
1439 int end = Math.min (Math.max (Math.max (selection.x, selection.y), 0), length); 1447 NSUInteger end = Math.min (Math.max (Math.max (selection.x, selection.y), 0), length);
1440 selectionRange = NSRange(); 1448 selectionRange = NSRange();
1441 selectionRange.location = start; 1449 selectionRange.location = start;
1442 selectionRange.length = end - start; 1450 selectionRange.length = end - start;
1443 if (this is display.getFocusControl ()) { 1451 if (this is display.getFocusControl ()) {
1444 NSText editor = view.window().fieldEditor(false, view); 1452 NSText editor = view.window().fieldEditor(false, view);
1486 if (index !is -1 && index !is getSelectionIndex ()) { 1494 if (index !is -1 && index !is getSelectionIndex ()) {
1487 select (index); 1495 select (index);
1488 if (notify) sendEvent (DWT.Modify); 1496 if (notify) sendEvent (DWT.Modify);
1489 } 1497 }
1490 } else { 1498 } else {
1491 new NSCell((cast(NSComboBox)view).cell()).setTitle(NSString.stringWith(string)); 1499 (new NSCell((cast(NSComboBox)view).cell())).setTitle(NSString.stringWith(string));
1492 if (notify) sendEvent (DWT.Modify); 1500 if (notify) sendEvent (DWT.Modify);
1493 } 1501 }
1494 selectionRange = null; 1502 selectionRange = null;
1495 } 1503 }
1496 1504
1545 } else { 1553 } else {
1546 (cast(NSComboBox)view).setNumberOfVisibleItems(count); 1554 (cast(NSComboBox)view).setNumberOfVisibleItems(count);
1547 } 1555 }
1548 } 1556 }
1549 1557
1550 void textViewDidChangeSelection(int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) { 1558 void textViewDidChangeSelection(objc.id id, objc.SEL sel, objc.id aNotification) {
1551 NSNotification notification = new NSNotification(aNotification); 1559 NSNotification notification = new NSNotification(aNotification);
1552 NSText editor = new NSText(notification.object().id); 1560 NSText editor = new NSText(notification.object().id);
1553 selectionRange = editor.selectedRange(); 1561 selectionRange = editor.selectedRange();
1554 } 1562 }
1555 1563
1556 void textDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) { 1564 void textDidChange (objc.id id, objc.SEL sel, objc.id aNotification) {
1557 postEvent (DWT.Modify); 1565 postEvent (DWT.Modify);
1558 } 1566 }
1559 1567
1560 NSRange textView_willChangeSelectionFromCharacterRange_toCharacterRange(int /*long*/ id, int /*long*/ sel, int /*long*/ aTextView, int /*long*/ oldSelectedCharRange, int /*long*/ newSelectedCharRange) { 1568 NSRange textView_willChangeSelectionFromCharacterRange_toCharacterRange(objc.id id, objc.SEL sel, objc.id aTextView, objc.id oldSelectedCharRange, objc.id newSelectedCharRange) {
1561 /* 1569 /*
1562 * If the selection is changing as a result of the receiver getting focus 1570 * If the selection is changing as a result of the receiver getting focus
1563 * then return the receiver's last selection range, otherwise the full 1571 * then return the receiver's last selection range, otherwise the full
1564 * text will be automatically selected. 1572 * text will be automatically selected.
1565 */ 1573 */
1566 if (receivingFocus && selectionRange !is null) return selectionRange; 1574 if (receivingFocus && selectionRange !is null) return selectionRange;
1567 1575
1568 /* allow the selection change to proceed */ 1576 /* allow the selection change to proceed */
1569 NSRange result = NSRange(); 1577 NSRange result = NSRange();
1570 OS.memmove(result, newSelectedCharRange, NSRange.sizeof); 1578 OS.memmove(&result, newSelectedCharRange, NSRange.sizeof);
1571 return result; 1579 return result;
1572 } 1580 }
1573 1581
1574 String verifyText (String string, int start, int end, NSEvent keyEvent) { 1582 String verifyText (String string, int start, int end, NSEvent keyEvent) {
1575 Event event = new Event (); 1583 Event event = new Event ();