comparison dwt/widgets/Text.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
249 string = verifyText (string, charCount, charCount, null); 249 string = verifyText (string, charCount, charCount, null);
250 if (string is null) return; 250 if (string is null) return;
251 } 251 }
252 NSString str = NSString.stringWith(string); 252 NSString str = NSString.stringWith(string);
253 if ((style & DWT.SINGLE) !is 0) { 253 if ((style & DWT.SINGLE) !is 0) {
254 // new NSTextFieldCell(((NSTextField)view).cell()).title(). 254 // new NSTextFieldCell((cast(NSTextField)view).cell()).title().
255 } else { 255 } else {
256 NSTextView widget = (NSTextView)view; 256 NSTextView widget = cast(NSTextView)view;
257 NSMutableString mutableString = widget.textStorage().mutableString(); 257 NSMutableString mutableString = widget.textStorage().mutableString();
258 mutableString.appendString(str); 258 mutableString.appendString(str);
259 NSRange range = new NSRange(); 259 NSRange range = new NSRange();
260 range.location = mutableString.length(); 260 range.location = mutableString.length();
261 widget.scrollRangeToVisible(range); 261 widget.scrollRangeToVisible(range);
299 299
300 public Point computeSize (int wHint, int hHint, bool changed) { 300 public Point computeSize (int wHint, int hHint, bool changed) {
301 checkWidget(); 301 checkWidget();
302 int width = 0, height = 0; 302 int width = 0, height = 0;
303 if ((style & DWT.SINGLE) !is 0) { 303 if ((style & DWT.SINGLE) !is 0) {
304 NSTextField widget = (NSTextField)view; 304 NSTextField widget = cast(NSTextField)view;
305 NSRect oldRect = widget.frame(); 305 NSRect oldRect = widget.frame();
306 widget.sizeToFit(); 306 widget.sizeToFit();
307 NSRect newRect = widget.frame(); 307 NSRect newRect = widget.frame();
308 widget.setFrame (oldRect); 308 widget.setFrame (oldRect);
309 width = (int)newRect.width; 309 width = cast(int)newRect.width;
310 height = (int)newRect.height; 310 height = cast(int)newRect.height;
311 } else { 311 } else {
312 NSTextView widget = (NSTextView)view; 312 NSTextView widget = cast(NSTextView)view;
313 NSRect oldRect = widget.frame(); 313 NSRect oldRect = widget.frame();
314 widget.sizeToFit(); 314 widget.sizeToFit();
315 NSRect newRect = widget.frame(); 315 NSRect newRect = widget.frame();
316 widget.setFrame (oldRect); 316 widget.setFrame (oldRect);
317 width = (int)newRect.width; 317 width = cast(int)newRect.width;
318 height = (int)newRect.height; 318 height = cast(int)newRect.height;
319 } 319 }
320 if (width <= 0) width = DEFAULT_WIDTH; 320 if (width <= 0) width = DEFAULT_WIDTH;
321 if (height <= 0) height = DEFAULT_HEIGHT; 321 if (height <= 0) height = DEFAULT_HEIGHT;
322 if (wHint !is DWT.DEFAULT) width = wHint; 322 if (wHint !is DWT.DEFAULT) width = wHint;
323 if (hHint !is DWT.DEFAULT) height = hHint; 323 if (hHint !is DWT.DEFAULT) height = hHint;
341 public void copy () { 341 public void copy () {
342 checkWidget (); 342 checkWidget ();
343 if ((style & DWT.SINGLE) !is 0) { 343 if ((style & DWT.SINGLE) !is 0) {
344 344
345 } else { 345 } else {
346 ((NSTextView)view).copy(); 346 (cast(NSTextView)view).copy();
347 } 347 }
348 } 348 }
349 349
350 void createHandle () { 350 void createHandle () {
351 if ((style & DWT.SINGLE) !is 0) { 351 if ((style & DWT.SINGLE) !is 0) {
352 NSTextField widget; 352 NSTextField widget;
353 if ((style & DWT.PASSWORD) !is 0) { 353 if ((style & DWT.PASSWORD) !is 0) {
354 widget = (NSTextField)new NSSecureTextField().alloc(); 354 widget = cast(NSTextField)new NSSecureTextField().alloc();
355 } else if ((style & DWT.SEARCH) !is 0) { 355 } else if ((style & DWT.SEARCH) !is 0) {
356 widget = (NSTextField)new NSSearchField().alloc(); 356 widget = cast(NSTextField)new NSSearchField().alloc();
357 } else { 357 } else {
358 widget = (NSTextField)new SWTTextField().alloc(); 358 widget = cast(NSTextField)new SWTTextField().alloc();
359 } 359 }
360 widget.initWithFrame(new NSRect()); 360 widget.initWithFrame(new NSRect());
361 widget.setSelectable(true); 361 widget.setSelectable(true);
362 widget.setEditable((style & DWT.READ_ONLY) is 0); 362 widget.setEditable((style & DWT.READ_ONLY) is 0);
363 if ((style & DWT.BORDER) is 0) widget.setBordered(false); 363 if ((style & DWT.BORDER) is 0) widget.setBordered(false);
369 // widget.setAction(OS.sel_sendSelection); 369 // widget.setAction(OS.sel_sendSelection);
370 widget.setTag(jniRef); 370 widget.setTag(jniRef);
371 view = widget; 371 view = widget;
372 parent.contentView().addSubview_(widget); 372 parent.contentView().addSubview_(widget);
373 } else { 373 } else {
374 SWTScrollView scrollWidget = (SWTScrollView)new SWTScrollView().alloc(); 374 SWTScrollView scrollWidget = cast(SWTScrollView)new SWTScrollView().alloc();
375 scrollWidget.initWithFrame(new NSRect()); 375 scrollWidget.initWithFrame(new NSRect());
376 scrollWidget.setHasVerticalScroller((style & DWT.VERTICAL) !is 0); 376 scrollWidget.setHasVerticalScroller((style & DWT.VERTICAL) !is 0);
377 scrollWidget.setHasHorizontalScroller((style & DWT.HORIZONTAL) !is 0); 377 scrollWidget.setHasHorizontalScroller((style & DWT.HORIZONTAL) !is 0);
378 scrollWidget.setAutoresizesSubviews(true); 378 scrollWidget.setAutoresizesSubviews(true);
379 scrollWidget.setTag(jniRef); 379 scrollWidget.setTag(jniRef);
380 380
381 SWTTextView widget = (SWTTextView)new SWTTextView().alloc(); 381 SWTTextView widget = cast(SWTTextView)new SWTTextView().alloc();
382 widget.initWithFrame(new NSRect()); 382 widget.initWithFrame(new NSRect());
383 widget.setEditable((style & DWT.READ_ONLY) is 0); 383 widget.setEditable((style & DWT.READ_ONLY) is 0);
384 if ((style & DWT.BORDER) is 0) widget.setFocusRingType(OS.NSFocusRingTypeNone); 384 if ((style & DWT.BORDER) is 0) widget.setFocusRingType(OS.NSFocusRingTypeNone);
385 385
386 NSSize size = new NSSize(); 386 NSSize size = new NSSize();
435 checkWidget(); 435 checkWidget();
436 if ((style & DWT.READ_ONLY) !is 0) return; 436 if ((style & DWT.READ_ONLY) !is 0) return;
437 if ((style & DWT.SINGLE) !is 0) { 437 if ((style & DWT.SINGLE) !is 0) {
438 438
439 } else { 439 } else {
440 ((NSTextView)view).cut(null); 440 (cast(NSTextView)view).cut(null);
441 } 441 }
442 // bool cut = true; 442 // bool cut = true;
443 // char [] oldText = null; 443 // char [] oldText = null;
444 // Point oldSelection = getSelection (); 444 // Point oldSelection = getSelection ();
445 // if (hooks (DWT.Verify) || filters (DWT.Verify)) { 445 // if (hooks (DWT.Verify) || filters (DWT.Verify)) {
541 if ((style & DWT.SINGLE) !is 0) { 541 if ((style & DWT.SINGLE) !is 0) {
542 //TODO - caret location for unicode text 542 //TODO - caret location for unicode text
543 return new Point (0, 0); 543 return new Point (0, 0);
544 } 544 }
545 // NSText 545 // NSText
546 NSRange range = ((NSTextView)view).selectedRange(); 546 NSRange range = (cast(NSTextView)view).selectedRange();
547 System.out.println(range.location + " " + range.length); 547 System.out.println(range.location + " " + range.length);
548 return null; 548 return null;
549 } 549 }
550 550
551 /** 551 /**
565 checkWidget(); 565 checkWidget();
566 if ((style & DWT.SINGLE) !is 0) { 566 if ((style & DWT.SINGLE) !is 0) {
567 //TODO 567 //TODO
568 return 0; 568 return 0;
569 } else { 569 } else {
570 NSRange range = ((NSTextView)view).selectedRange(); 570 NSRange range = (cast(NSTextView)view).selectedRange();
571 return range.location; 571 return range.location;
572 } 572 }
573 } 573 }
574 574
575 /** 575 /**
583 * </ul> 583 * </ul>
584 */ 584 */
585 public int getCharCount () { 585 public int getCharCount () {
586 checkWidget (); 586 checkWidget ();
587 if ((style & DWT.SINGLE) !is 0) { 587 if ((style & DWT.SINGLE) !is 0) {
588 return new NSCell(((NSControl)view).cell()).title().length(); 588 return new NSCell((cast(NSControl)view).cell()).title().length();
589 } else { 589 } else {
590 //TODO 590 //TODO
591 return 0; 591 return 0;
592 } 592 }
593 } 593 }
660 * </ul> 660 * </ul>
661 */ 661 */
662 public int getLineCount () { 662 public int getLineCount () {
663 checkWidget(); 663 checkWidget();
664 if ((style & DWT.SINGLE) !is 0) return 1; 664 if ((style & DWT.SINGLE) !is 0) return 1;
665 return ((NSTextView)view).textStorage().paragraphs().count(); 665 return (cast(NSTextView)view).textStorage().paragraphs().count();
666 } 666 }
667 667
668 /** 668 /**
669 * Returns the line delimiter. 669 * Returns the line delimiter.
670 * 670 *
771 * </ul> 771 * </ul>
772 */ 772 */
773 public Point getSelection () { 773 public Point getSelection () {
774 checkWidget(); 774 checkWidget();
775 if ((style & DWT.SINGLE) !is 0) { 775 if ((style & DWT.SINGLE) !is 0) {
776 // new NSTextFieldCell(((NSTextField)view).cell()).title(). 776 // new NSTextFieldCell((cast(NSTextField)view).cell()).title().
777 return new Point(0, 0); 777 return new Point(0, 0);
778 } else { 778 } else {
779 NSTextView widget = (NSTextView)view; 779 NSTextView widget = cast(NSTextView)view;
780 NSRange range = widget.selectedRange(); 780 NSRange range = widget.selectedRange();
781 return new Point(range.location, range.location + range.length); 781 return new Point(range.location, range.location + range.length);
782 } 782 }
783 } 783 }
784 784
793 * </ul> 793 * </ul>
794 */ 794 */
795 public int getSelectionCount () { 795 public int getSelectionCount () {
796 checkWidget(); 796 checkWidget();
797 if ((style & DWT.SINGLE) !is 0) { 797 if ((style & DWT.SINGLE) !is 0) {
798 // new NSTextFieldCell(((NSTextField)view).cell()).title(). 798 // new NSTextFieldCell((cast(NSTextField)view).cell()).title().
799 return -1; 799 return -1;
800 } else { 800 } else {
801 NSTextView widget = (NSTextView)view; 801 NSTextView widget = cast(NSTextView)view;
802 NSRange range = widget.selectedRange(); 802 NSRange range = widget.selectedRange();
803 return range.length; 803 return range.length;
804 } 804 }
805 } 805 }
806 806
818 checkWidget(); 818 checkWidget();
819 if ((style & DWT.SINGLE) !is 0) { 819 if ((style & DWT.SINGLE) !is 0) {
820 //TODO 820 //TODO
821 return ""; 821 return "";
822 } else { 822 } else {
823 NSTextView widget = (NSTextView)view; 823 NSTextView widget = cast(NSTextView)view;
824 NSRange range = widget.selectedRange(); 824 NSRange range = widget.selectedRange();
825 NSString str = widget.textStorage().string(); 825 NSString str = widget.textStorage().string();
826 char[] buffer = new char[range.length]; 826 char[] buffer = new char[range.length];
827 str.getCharacters_range_(buffer, range); 827 str.getCharacters_range_(buffer, range);
828 return new String(buffer); 828 return new String(buffer);
865 */ 865 */
866 public String getText () { 866 public String getText () {
867 checkWidget(); 867 checkWidget();
868 NSString str; 868 NSString str;
869 if ((style & DWT.SINGLE) !is 0) { 869 if ((style & DWT.SINGLE) !is 0) {
870 str = new NSTextFieldCell(((NSTextField)view).cell()).title(); 870 str = new NSTextFieldCell((cast(NSTextField)view).cell()).title();
871 } else { 871 } else {
872 str = ((NSTextView)view).textStorage().string(); 872 str = (cast(NSTextView)view).textStorage().string();
873 } 873 }
874 if (str is null) return ""; 874 if (str is null) return "";
875 char[] buffer = new char[str.length()]; 875 char[] buffer = new char[str.length()];
876 str.getCharacters_(buffer); 876 str.getCharacters_(buffer);
877 return new String(buffer); 877 return new String(buffer);
897 */ 897 */
898 public String getText (int start, int end) { 898 public String getText (int start, int end) {
899 checkWidget (); 899 checkWidget ();
900 NSString str; 900 NSString str;
901 if ((style & DWT.SINGLE) !is 0) { 901 if ((style & DWT.SINGLE) !is 0) {
902 str = new NSTextFieldCell(((NSTextField)view).cell()).title(); 902 str = new NSTextFieldCell((cast(NSTextField)view).cell()).title();
903 903
904 } else { 904 } else {
905 str = null; 905 str = null;
906 // return getTXNText (OS.kTXNStartOffset, OS.kTXNEndOffset); 906 // return getTXNText (OS.kTXNStartOffset, OS.kTXNEndOffset);
907 } 907 }
1002 Point selection = getSelection (); 1002 Point selection = getSelection ();
1003 string = verifyText (string, selection.x, selection.y, null); 1003 string = verifyText (string, selection.x, selection.y, null);
1004 if (string is null) return; 1004 if (string is null) return;
1005 } 1005 }
1006 if ((style & DWT.SINGLE) !is 0) { 1006 if ((style & DWT.SINGLE) !is 0) {
1007 // new NSTextFieldCell(((NSTextField)view).cell()).title(). 1007 // new NSTextFieldCell((cast(NSTextField)view).cell()).title().
1008 } else { 1008 } else {
1009 // 1009 //
1010 NSString str = NSString.stringWith(string); 1010 NSString str = NSString.stringWith(string);
1011 NSTextView widget = (NSTextView)view; 1011 NSTextView widget = cast(NSTextView)view;
1012 NSRange range = widget.selectedRange(); 1012 NSRange range = widget.selectedRange();
1013 widget.textStorage().replaceCharactersInRange_withString_(range, str); 1013 widget.textStorage().replaceCharactersInRange_withString_(range, str);
1014 } 1014 }
1015 if (string.length () !is 0) sendEvent (DWT.Modify); 1015 if (string.length () !is 0) sendEvent (DWT.Modify);
1016 } 1016 }
1155 public void selectAll () { 1155 public void selectAll () {
1156 checkWidget(); 1156 checkWidget();
1157 if ((style & DWT.SINGLE) !is 0) { 1157 if ((style & DWT.SINGLE) !is 0) {
1158 setSelection (0, getCharCount ()); 1158 setSelection (0, getCharCount ());
1159 } else { 1159 } else {
1160 ((NSTextView)view).selectAll(null); 1160 (cast(NSTextView)view).selectAll(null);
1161 } 1161 }
1162 } 1162 }
1163 1163
1164 bool sendKeyEvent (int type, Event event) { 1164 bool sendKeyEvent (int type, Event event) {
1165 if (!super.sendKeyEvent (type, event)) { 1165 if (!super.sendKeyEvent (type, event)) {
1229 return; // TODO reset to OS default 1229 return; // TODO reset to OS default
1230 } else { 1230 } else {
1231 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); 1231 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1);
1232 } 1232 }
1233 if ((style & DWT.SINGLE) !is 0) { 1233 if ((style & DWT.SINGLE) !is 0) {
1234 ((NSTextField)view).setBackgroundColor(nsColor); 1234 (cast(NSTextField)view).setBackgroundColor(nsColor);
1235 } else { 1235 } else {
1236 ((NSTextView)view).setBackgroundColor(nsColor); 1236 (cast(NSTextView)view).setBackgroundColor(nsColor);
1237 } 1237 }
1238 } 1238 }
1239 1239
1240 /** 1240 /**
1241 * Sets the double click enabled flag. 1241 * Sets the double click enabled flag.
1314 style &= ~DWT.READ_ONLY; 1314 style &= ~DWT.READ_ONLY;
1315 } else { 1315 } else {
1316 style |= DWT.READ_ONLY; 1316 style |= DWT.READ_ONLY;
1317 } 1317 }
1318 if ((style & DWT.SINGLE) !is 0) { 1318 if ((style & DWT.SINGLE) !is 0) {
1319 ((NSTextField)view).setEditable(editable); 1319 (cast(NSTextField)view).setEditable(editable);
1320 } else { 1320 } else {
1321 ((NSTextView)view).setEditable(editable); 1321 (cast(NSTextView)view).setEditable(editable);
1322 } 1322 }
1323 } 1323 }
1324 1324
1325 void setForeground (float [] color) { 1325 void setForeground (float [] color) {
1326 NSColor nsColor; 1326 NSColor nsColor;
1328 return; // TODO reset to OS default 1328 return; // TODO reset to OS default
1329 } else { 1329 } else {
1330 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1); 1330 nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1);
1331 } 1331 }
1332 if ((style & DWT.SINGLE) !is 0) { 1332 if ((style & DWT.SINGLE) !is 0) {
1333 ((NSTextField)view).setTextColor(nsColor); 1333 (cast(NSTextField)view).setTextColor(nsColor);
1334 } else { 1334 } else {
1335 ((NSTextView)view).setTextColor_(nsColor); 1335 (cast(NSTextView)view).setTextColor_(nsColor);
1336 } 1336 }
1337 } 1337 }
1338 1338
1339 /** 1339 /**
1340 * Sets the orientation of the receiver, which must be one 1340 * Sets the orientation of the receiver, which must be one
1449 public void setSelection (int start, int end) { 1449 public void setSelection (int start, int end) {
1450 checkWidget(); 1450 checkWidget();
1451 if ((style & DWT.SINGLE) !is 0) { 1451 if ((style & DWT.SINGLE) !is 0) {
1452 // int length = getCharCount (); 1452 // int length = getCharCount ();
1453 // ControlEditTextSelectionRec selection = new ControlEditTextSelectionRec (); 1453 // ControlEditTextSelectionRec selection = new ControlEditTextSelectionRec ();
1454 // selection.selStart = (short) Math.min (Math.max (Math.min (start, end), 0), length); 1454 // selection.selStart = cast(short) Math.min (Math.max (Math.min (start, end), 0), length);
1455 // selection.selEnd = (short) Math.min (Math.max (Math.max (start, end), 0), length); 1455 // selection.selEnd = cast(short) Math.min (Math.max (Math.max (start, end), 0), length);
1456 // if (hasFocus ()) { 1456 // if (hasFocus ()) {
1457 // OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection); 1457 // OS.SetControlData (handle, OS.kControlEntireControl, OS.kControlEditTextSelectionTag, 4, selection);
1458 // } else { 1458 // } else {
1459 // this.selection = selection; 1459 // this.selection = selection;
1460 // } 1460 // }
1461 } else { 1461 } else {
1462 //TODO - range test 1462 //TODO - range test
1463 NSRange range = new NSRange (); 1463 NSRange range = new NSRange ();
1464 range.location = start; 1464 range.location = start;
1465 range.length = end - start + 1; 1465 range.length = end - start + 1;
1466 ((NSTextView)view).setSelectedRange (range); 1466 (cast(NSTextView)view).setSelectedRange (range);
1467 } 1467 }
1468 } 1468 }
1469 1469
1470 /** 1470 /**
1471 * Sets the selection to the range specified 1471 * Sets the selection to the range specified
1522 checkWidget(); 1522 checkWidget();
1523 if (this.tabs is tabs) return; 1523 if (this.tabs is tabs) return;
1524 // if (txnObject is 0) return; 1524 // if (txnObject is 0) return;
1525 // this.tabs = tabs; 1525 // this.tabs = tabs;
1526 // TXNTab tab = new TXNTab (); 1526 // TXNTab tab = new TXNTab ();
1527 // tab.value = (short) (textExtent (new char[]{' '}, 0).x * tabs); 1527 // tab.value = cast(short) (textExtent (new char[]{' '}, 0).x * tabs);
1528 // int [] tags = new int [] {OS.kTXNTabSettingsTag}; 1528 // int [] tags = new int [] {OS.kTXNTabSettingsTag};
1529 // int [] datas = new int [1]; 1529 // int [] datas = new int [1];
1530 // OS.memmove (datas, tab, TXNTab.sizeof); 1530 // OS.memmove (datas, tab, TXNTab.sizeof);
1531 // OS.TXNSetTXNObjectControls (txnObject, false, tags.length, tags, datas); 1531 // OS.TXNSetTXNObjectControls (txnObject, false, tags.length, tags, datas);
1532 } 1532 }
1553 string = verifyText (string, 0, getCharCount (), null); 1553 string = verifyText (string, 0, getCharCount (), null);
1554 if (string is null) return; 1554 if (string is null) return;
1555 } 1555 }
1556 NSString str = NSString.stringWith(string); 1556 NSString str = NSString.stringWith(string);
1557 if ((style & DWT.SINGLE) !is 0) { 1557 if ((style & DWT.SINGLE) !is 0) {
1558 new NSCell(((NSTextField)view).cell()).setTitle(str); 1558 new NSCell((cast(NSTextField)view).cell()).setTitle(str);
1559 } else { 1559 } else {
1560 ((NSTextView)view).setString(str); 1560 (cast(NSTextView)view).setString(str);
1561 } 1561 }
1562 sendEvent (DWT.Modify); 1562 sendEvent (DWT.Modify);
1563 } 1563 }
1564 1564
1565 /** 1565 /**
1606 */ 1606 */
1607 public void setTopIndex (int index) { 1607 public void setTopIndex (int index) {
1608 checkWidget(); 1608 checkWidget();
1609 if ((style & DWT.SINGLE) !is 0) return; 1609 if ((style & DWT.SINGLE) !is 0) return;
1610 //TODO no working 1610 //TODO no working
1611 NSTextView widget = (NSTextView)view; 1611 NSTextView widget = cast(NSTextView)view;
1612 NSRange range = new NSRange(); 1612 NSRange range = new NSRange();
1613 NSRect rect = widget.firstRectForCharacterRange(range); 1613 NSRect rect = widget.firstRectForCharacterRange(range);
1614 view.scrollRectToVisible(rect); 1614 view.scrollRectToVisible(rect);
1615 } 1615 }
1616 1616
1630 public void showSelection () { 1630 public void showSelection () {
1631 checkWidget(); 1631 checkWidget();
1632 if ((style & DWT.SINGLE) !is 0) { 1632 if ((style & DWT.SINGLE) !is 0) {
1633 setSelection (getSelection()); 1633 setSelection (getSelection());
1634 } else { 1634 } else {
1635 NSTextView widget = (NSTextView)view; 1635 NSTextView widget = cast(NSTextView)view;
1636 widget.scrollRangeToVisible(widget.selectedRange()); 1636 widget.scrollRangeToVisible(widget.selectedRange());
1637 } 1637 }
1638 } 1638 }
1639 1639
1640 int traversalCode (int key, NSEvent theEvent) { 1640 int traversalCode (int key, NSEvent theEvent) {