Mercurial > projects > dwt-mac
comparison dwt/widgets/Text.d @ 123:63a09873578e
Fixed compile errors
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Thu, 15 Jan 2009 23:08:54 +0100 |
parents | c7f7f4d7091a |
children | 38807a925e24 |
comparison
equal
deleted
inserted
replaced
122:2e671fa40eec | 123:63a09873578e |
---|---|
85 * @see <a href="http://www.eclipse.org/swt/snippets/#text">Text snippets</a> | 85 * @see <a href="http://www.eclipse.org/swt/snippets/#text">Text snippets</a> |
86 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> | 86 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> |
87 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | 87 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
88 */ | 88 */ |
89 public class Text : Scrollable { | 89 public class Text : Scrollable { |
90 | |
91 alias Scrollable.setBackground setBackground; | |
92 alias Scrollable.setFont setFont; | |
93 alias Scrollable.setForeground setForeground; | |
94 | |
90 int textLimit, tabs = 8; | 95 int textLimit, tabs = 8; |
91 char echoCharacter; | 96 char echoCharacter; |
92 bool doubleClick, receivingFocus; | 97 bool doubleClick, receivingFocus; |
93 String hiddenText, message; | 98 String hiddenText, message; |
94 NSRange* selectionRange; | 99 NSRange* selectionRange; |
95 NSRange selectionRangeStruct; | 100 NSRange selectionRangeStruct; |
96 | 101 |
97 /** | 102 /** |
98 * The maximum number of characters that can be entered | 103 * The maximum number of characters that can be entered |
99 * into a text widget. | 104 * into a text widget. |
100 * <p> | 105 * <p> |
101 * Note that this value is platform dependent, based upon | 106 * Note that this value is platform dependent, based upon |
102 * the native widget implementation. | 107 * the native widget implementation. |
103 * </p> | 108 * </p> |
104 */ | 109 */ |
105 public static const int LIMIT; | 110 public static const int LIMIT; |
106 | 111 |
107 /** | 112 /** |
108 * The delimiter used by multi-line text widgets. When text | 113 * The delimiter used by multi-line text widgets. When text |
109 * is queried and from the widget, it will be delimited using | 114 * is queried and from the widget, it will be delimited using |
110 * this delimiter. | 115 * this delimiter. |
111 */ | 116 */ |
112 public static const String DELIMITER; | 117 public static const String DELIMITER; |
113 static const wchar PASSWORD = '\u2022'; | 118 static const wchar PASSWORD = '\u2022'; |
114 | 119 |
115 /* | 120 /* |
116 * These values can be different on different platforms. | 121 * These values can be different on different platforms. |
117 * Therefore they are not initialized in the declaration | 122 * Therefore they are not initialized in the declaration |
118 * to stop the compiler from inlining. | 123 * to stop the compiler from inlining. |
119 */ | 124 */ |
120 static this () { | 125 static this () { |
121 LIMIT = 0x7FFFFFFF; | 126 LIMIT = 0x7FFFFFFF; |
122 DELIMITER = "\r"; | 127 DELIMITER = "\r"; |
123 } | 128 } |
124 | 129 |
125 /** | 130 /** |
126 * Constructs a new instance of this class given its parent | 131 * Constructs a new instance of this class given its parent |
127 * and a style value describing its behavior and appearance. | 132 * and a style value describing its behavior and appearance. |
128 * <p> | 133 * <p> |
156 public this (Composite parent, int style) { | 161 public this (Composite parent, int style) { |
157 textLimit = LIMIT; | 162 textLimit = LIMIT; |
158 | 163 |
159 super (parent, checkStyle (style)); | 164 super (parent, checkStyle (style)); |
160 if ((style & DWT.SEARCH) !is 0) { | 165 if ((style & DWT.SEARCH) !is 0) { |
161 // int inAttributesToSet = (style & DWT.CANCEL) !is 0 ? OS.kHISearchFieldAttributesCancel : 0; | 166 // int inAttributesToSet = (style & DWT.CANCEL) !is 0 ? OS.kHISearchFieldAttributesCancel : 0; |
162 // OS.HISearchFieldChangeAttributes (handle, inAttributesToSet, 0); | 167 // OS.HISearchFieldChangeAttributes (handle, inAttributesToSet, 0); |
163 /* | 168 /* |
164 * Ensure that DWT.CANCEL is set. | 169 * Ensure that DWT.CANCEL is set. |
165 * NOTE: CANCEL has the same value as H_SCROLL so it is | 170 * NOTE: CANCEL has the same value as H_SCROLL so it is |
166 * necessary to first clear these bits to avoid a scroll | 171 * necessary to first clear these bits to avoid a scroll |
167 * bar and then reset the bit using the original style | 172 * bar and then reset the bit using the original style |
168 * supplied by the programmer. | 173 * supplied by the programmer. |
169 */ | 174 */ |
170 if ((style & DWT.CANCEL) !is 0) this.style |= DWT.CANCEL; | 175 if ((style & DWT.CANCEL) !is 0) this.style |= DWT.CANCEL; |
171 } | 176 } |
172 } | 177 } |
173 | 178 |
174 /** | 179 /** |
426 } | 431 } |
427 NSTextAlignment align_ = OS.NSLeftTextAlignment; | 432 NSTextAlignment align_ = OS.NSLeftTextAlignment; |
428 if ((style & DWT.CENTER) !is 0) align_ = OS.NSCenterTextAlignment; | 433 if ((style & DWT.CENTER) !is 0) align_ = OS.NSCenterTextAlignment; |
429 if ((style & DWT.RIGHT) !is 0) align_ = OS.NSRightTextAlignment; | 434 if ((style & DWT.RIGHT) !is 0) align_ = OS.NSRightTextAlignment; |
430 widget.setAlignment (align_); | 435 widget.setAlignment (align_); |
431 // widget.setTarget(widget); | 436 // widget.setTarget(widget); |
432 // widget.setAction(OS.sel_sendSelection); | 437 // widget.setAction(OS.sel_sendSelection); |
433 view = widget; | 438 view = widget; |
434 } else { | 439 } else { |
435 NSScrollView scrollWidget = cast(NSScrollView) (new SWTScrollView ()).alloc (); | 440 NSScrollView scrollWidget = cast(NSScrollView) (new SWTScrollView ()).alloc (); |
436 scrollWidget.initWithFrame (NSRect ()); | 441 scrollWidget.initWithFrame (NSRect ()); |
437 scrollWidget.setHasVerticalScroller ((style & DWT.VERTICAL) !is 0); | 442 scrollWidget.setHasVerticalScroller ((style & DWT.VERTICAL) !is 0); |
445 | 450 |
446 NSSize size = NSSize (); | 451 NSSize size = NSSize (); |
447 size.width = size.height = Float.MAX_VALUE; | 452 size.width = size.height = Float.MAX_VALUE; |
448 widget.setMaxSize (size); | 453 widget.setMaxSize (size); |
449 widget.setAutoresizingMask (OS.NSViewWidthSizable | OS.NSViewHeightSizable); | 454 widget.setAutoresizingMask (OS.NSViewWidthSizable | OS.NSViewHeightSizable); |
450 | 455 |
451 if ((style & DWT.WRAP) is 0) { | 456 if ((style & DWT.WRAP) is 0) { |
452 NSTextContainer textContainer = widget.textContainer (); | 457 NSTextContainer textContainer = widget.textContainer (); |
453 widget.setHorizontallyResizable (true); | 458 widget.setHorizontallyResizable (true); |
454 textContainer.setWidthTracksTextView (false); | 459 textContainer.setWidthTracksTextView (false); |
455 NSSize csize = NSSize (); | 460 NSSize csize = NSSize (); |
456 csize.width = csize.height = Float.MAX_VALUE; | 461 csize.width = csize.height = Float.MAX_VALUE; |
457 textContainer.setContainerSize (csize); | 462 textContainer.setContainerSize (csize); |
458 } | 463 } |
459 | 464 |
460 NSTextAlignment align_ = OS.NSLeftTextAlignment; | 465 NSTextAlignment align_ = OS.NSLeftTextAlignment; |
461 if ((style & DWT.CENTER) !is 0) align_ = OS.NSCenterTextAlignment; | 466 if ((style & DWT.CENTER) !is 0) align_ = OS.NSCenterTextAlignment; |
462 if ((style & DWT.RIGHT) !is 0) align_ = OS.NSRightTextAlignment; | 467 if ((style & DWT.RIGHT) !is 0) align_ = OS.NSRightTextAlignment; |
463 widget.setAlignment (align_); | 468 widget.setAlignment (align_); |
464 | 469 |
465 // widget.setTarget(widget); | 470 // widget.setTarget(widget); |
466 // widget.setAction(OS.sel_sendSelection); | 471 // widget.setAction(OS.sel_sendSelection); |
467 widget.setRichText (false); | 472 widget.setRichText (false); |
468 widget.setDelegate(widget); | 473 widget.setDelegate(widget); |
469 | 474 |
470 view = widget; | 475 view = widget; |
471 scrollView = scrollWidget; | 476 scrollView = scrollWidget; |
596 checkWidget (); | 601 checkWidget (); |
597 if ((style & DWT.SINGLE) !is 0) { | 602 if ((style & DWT.SINGLE) !is 0) { |
598 //TODO - caret location for unicode text | 603 //TODO - caret location for unicode text |
599 return new Point (0, 0); | 604 return new Point (0, 0); |
600 } | 605 } |
601 // NSText | 606 // NSText |
602 // NSRange range = (cast(NSTextView)view).selectedRange(); | 607 // NSRange range = (cast(NSTextView)view).selectedRange(); |
603 return null; | 608 return null; |
604 } | 609 } |
605 | 610 |
606 /** | 611 /** |
607 * Returns the character position of the caret. | 612 * Returns the character position of the caret. |
708 if ((style & DWT.SINGLE) !is 0) { | 713 if ((style & DWT.SINGLE) !is 0) { |
709 str = (new NSTextFieldCell ((cast(NSTextField) view).cell ())).title (); | 714 str = (new NSTextFieldCell ((cast(NSTextField) view).cell ())).title (); |
710 } else { | 715 } else { |
711 str = (cast(NSTextView)view).textStorage().string(); | 716 str = (cast(NSTextView)view).textStorage().string(); |
712 } | 717 } |
713 | 718 |
714 NSUInteger length_ = str.length (); | 719 NSUInteger length_ = str.length (); |
715 char [] buffer = new char [length_]; | 720 char [] buffer = new char [length_]; |
716 if (hiddenText !is null) { | 721 if (hiddenText !is null) { |
717 hiddenText.getChars (0, length_, buffer, 0); | 722 hiddenText.getChars (0, length_, buffer, 0); |
718 } else { | 723 } else { |
728 if ((style & DWT.SINGLE) !is 0) { | 733 if ((style & DWT.SINGLE) !is 0) { |
729 str = (new NSTextFieldCell ((cast(NSTextField) view).cell ())).title (); | 734 str = (new NSTextFieldCell ((cast(NSTextField) view).cell ())).title (); |
730 } else { | 735 } else { |
731 str = (cast(NSTextView)view).textStorage().string(); | 736 str = (cast(NSTextView)view).textStorage().string(); |
732 } | 737 } |
733 | 738 |
734 int length = cast(int)/*64*/str.length (); | 739 int length = cast(int)/*64*/str.length (); |
735 end = Math.min (end, length - 1); | 740 end = Math.min (end, length - 1); |
736 if (start > end) return new char [0]; | 741 if (start > end) return new char [0]; |
737 start = Math.max (0, start); | 742 start = Math.max (0, start); |
738 NSRange range = NSRange (); | 743 NSRange range = NSRange (); |
837 checkWidget (); | 842 checkWidget (); |
838 return message; | 843 return message; |
839 } | 844 } |
840 | 845 |
841 int getPosition (int x, int y) { | 846 int getPosition (int x, int y) { |
842 // checkWidget (); | 847 // checkWidget (); |
843 //TODO | 848 //TODO |
844 return 0; | 849 return 0; |
845 } | 850 } |
846 | 851 |
847 /*public*/ int getPosition (Point point) { | 852 /*public*/ int getPosition (Point point) { |
1434 * </ul> | 1439 * </ul> |
1435 */ | 1440 */ |
1436 public void setEchoChar (char echo) { | 1441 public void setEchoChar (char echo) { |
1437 checkWidget (); | 1442 checkWidget (); |
1438 if ((style & DWT.MULTI) !is 0) return; | 1443 if ((style & DWT.MULTI) !is 0) return; |
1439 // if (txnObject is 0) { | 1444 // if (txnObject is 0) { |
1440 // if ((style & DWT.PASSWORD) is 0) { | 1445 // if ((style & DWT.PASSWORD) is 0) { |
1441 // Point selection = getSelection (); | 1446 // Point selection = getSelection (); |
1442 // String text = getText (); | 1447 // String text = getText (); |
1443 // echoCharacter = echo; | 1448 // echoCharacter = echo; |
1444 // setEditText (text); | 1449 // setEditText (text); |
1445 // setSelection (selection); | 1450 // setSelection (selection); |
1446 // } | 1451 // } |
1447 // } else { | 1452 // } else { |
1448 // OS.TXNEchoMode (txnObject, echo, OS.kTextEncodingMacUnicode, echo !is '\0'); | 1453 // OS.TXNEchoMode (txnObject, echo, OS.kTextEncodingMacUnicode, echo !is '\0'); |
1449 // } | 1454 // } |
1450 echoCharacter = echo; | 1455 echoCharacter = echo; |
1451 } | 1456 } |
1452 | 1457 |
1453 /** | 1458 /** |
1454 * Sets the editable state. | 1459 * Sets the editable state. |
1557 */ | 1562 */ |
1558 public void setMessage (String message) { | 1563 public void setMessage (String message) { |
1559 checkWidget (); | 1564 checkWidget (); |
1560 //if (message is null) error (DWT.ERROR_NULL_ARGUMENT); | 1565 //if (message is null) error (DWT.ERROR_NULL_ARGUMENT); |
1561 this.message = message; | 1566 this.message = message; |
1562 // if ((style & DWT.SEARCH) !is 0) { | 1567 // if ((style & DWT.SEARCH) !is 0) { |
1563 // char [] buffer = new char [message.length ()]; | 1568 // char [] buffer = new char [message.length ()]; |
1564 // message.getChars (0, buffer.length, buffer, 0); | 1569 // message.getChars (0, buffer.length, buffer, 0); |
1565 // int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length); | 1570 // int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length); |
1566 // if (ptr is 0) error (DWT.ERROR_CANNOT_SET_TEXT); | 1571 // if (ptr is 0) error (DWT.ERROR_CANNOT_SET_TEXT); |
1567 // OS.HISearchFieldSetDescriptiveText (handle, ptr); | 1572 // OS.HISearchFieldSetDescriptiveText (handle, ptr); |
1568 // OS.CFRelease (ptr); | 1573 // OS.CFRelease (ptr); |
1569 // } | 1574 // } |
1570 } | 1575 } |
1571 | 1576 |
1572 /** | 1577 /** |
1573 * Sets the selection. | 1578 * Sets the selection. |
1574 * <p> | 1579 * <p> |
1700 * </ul> | 1705 * </ul> |
1701 */ | 1706 */ |
1702 public void setTabs (int tabs) { | 1707 public void setTabs (int tabs) { |
1703 checkWidget (); | 1708 checkWidget (); |
1704 if (this.tabs is tabs) return; | 1709 if (this.tabs is tabs) return; |
1705 // if (txnObject is 0) return; | 1710 // if (txnObject is 0) return; |
1706 // this.tabs = tabs; | 1711 // this.tabs = tabs; |
1707 // TXNTab tab = new TXNTab (); | 1712 // TXNTab tab = new TXNTab (); |
1708 // tab.value = cast(short) (textExtent (new char[]{' '}, 0).x * tabs); | 1713 // tab.value = cast(short) (textExtent (new char[]{' '}, 0).x * tabs); |
1709 // int [] tags = new int [] {OS.kTXNTabSettingsTag}; | 1714 // int [] tags = new int [] {OS.kTXNTabSettingsTag}; |
1710 // int [] datas = new int [1]; | 1715 // int [] datas = new int [1]; |
1711 // OS.memmove (datas, tab, TXNTab.sizeof); | 1716 // OS.memmove (datas, tab, TXNTab.sizeof); |
1712 // OS.TXNSetTXNObjectControls (txnObject, false, tags.length, tags, datas); | 1717 // OS.TXNSetTXNObjectControls (txnObject, false, tags.length, tags, datas); |
1713 } | 1718 } |
1714 | 1719 |
1715 /** | 1720 /** |
1716 * Sets the contents of the receiver to the given string. If the receiver has style | 1721 * Sets the contents of the receiver to the given string. If the receiver has style |
1717 * SINGLE and the argument contains multiple lines of text, the result of this | 1722 * SINGLE and the argument contains multiple lines of text, the result of this |
1787 */ | 1792 */ |
1788 public void setTopIndex (int index) { | 1793 public void setTopIndex (int index) { |
1789 checkWidget (); | 1794 checkWidget (); |
1790 if ((style & DWT.SINGLE) !is 0) return; | 1795 if ((style & DWT.SINGLE) !is 0) return; |
1791 //TODO no working | 1796 //TODO no working |
1792 // NSTextView widget = cast(NSTextView) view; | 1797 // NSTextView widget = cast(NSTextView) view; |
1793 // NSRange range = NSRange (); | 1798 // NSRange range = NSRange (); |
1794 // NSRect rect = widget.firstRectForCharacterRange (range); | 1799 // NSRect rect = widget.firstRectForCharacterRange (range); |
1795 // view.scrollRectToVisible (rect); | 1800 // view.scrollRectToVisible (rect); |
1796 } | 1801 } |
1797 | 1802 |
1798 /** | 1803 /** |
1799 * Shows the selection. | 1804 * Shows the selection. |
1800 * <p> | 1805 * <p> |
1829 postEvent (DWT.Modify); | 1834 postEvent (DWT.Modify); |
1830 } | 1835 } |
1831 | 1836 |
1832 NSRange textView_willChangeSelectionFromCharacterRange_toCharacterRange (objc.id id, objc.SEL sel, objc.id aTextView, objc.id oldSelectedCharRange, objc.id newSelectedCharRange) { | 1837 NSRange textView_willChangeSelectionFromCharacterRange_toCharacterRange (objc.id id, objc.SEL sel, objc.id aTextView, objc.id oldSelectedCharRange, objc.id newSelectedCharRange) { |
1833 /* | 1838 /* |
1834 * If the selection is changing as a result of the receiver getting focus | 1839 * If the selection is changing as a result of the receiver getting focus |
1835 * then return the receiver's last selection range, otherwise the full | 1840 * then return the receiver's last selection range, otherwise the full |
1836 * text will be automatically selected. | 1841 * text will be automatically selected. |
1837 */ | 1842 */ |
1838 if (receivingFocus && selectionRange !is null) return selectionRangeStruct; | 1843 if (receivingFocus && selectionRange !is null) return selectionRangeStruct; |
1839 | 1844 |
1840 /* allow the selection change to proceed */ | 1845 /* allow the selection change to proceed */ |
1841 NSRange result = NSRange (); | 1846 NSRange result = NSRange (); |
1842 OS.memmove(&result, newSelectedCharRange, NSRange.sizeof); | 1847 OS.memmove(&result, newSelectedCharRange, NSRange.sizeof); |
1843 return result; | 1848 return result; |
1844 } | 1849 } |