Mercurial > projects > dwt-mac
comparison dwt/widgets/Text.d @ 90:c7f7f4d7091a
All widgets are ported
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Tue, 30 Dec 2008 18:54:31 +0100 |
parents | 681769fb5a7a |
children | 63a09873578e |
comparison
equal
deleted
inserted
replaced
89:8e3c85e1733d | 90:c7f7f4d7091a |
---|---|
48 import dwt.internal.cocoa.SWTSearchField; | 48 import dwt.internal.cocoa.SWTSearchField; |
49 import dwt.internal.cocoa.SWTSecureTextField; | 49 import dwt.internal.cocoa.SWTSecureTextField; |
50 import dwt.internal.cocoa.SWTTextField; | 50 import dwt.internal.cocoa.SWTTextField; |
51 import dwt.internal.cocoa.SWTTextView; | 51 import dwt.internal.cocoa.SWTTextView; |
52 | 52 |
53 import dwt.internal.c.Carbon; | 53 import Carbon = dwt.internal.c.Carbon; |
54 import dwt.internal.objc.cocoa.Cocoa; | 54 import dwt.internal.objc.cocoa.Cocoa; |
55 import objc = dwt.internal.objc.runtime; | 55 import objc = dwt.internal.objc.runtime; |
56 import dwt.widgets.Composite; | 56 import dwt.widgets.Composite; |
57 import dwt.widgets.Event; | |
57 import dwt.widgets.Scrollable; | 58 import dwt.widgets.Scrollable; |
58 import dwt.widgets.TypedListener; | 59 import dwt.widgets.TypedListener; |
59 | 60 |
60 /** | 61 /** |
61 * Instances of this class are selectable user interface | 62 * Instances of this class are selectable user interface |
84 * @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> |
85 * @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> |
86 * @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> |
87 */ | 88 */ |
88 public class Text : Scrollable { | 89 public class Text : Scrollable { |
89 int textLimit = LIMIT, tabs = 8; | 90 int textLimit, tabs = 8; |
90 char echoCharacter; | 91 char echoCharacter; |
91 bool doubleClick, receivingFocus; | 92 bool doubleClick, receivingFocus; |
92 String hiddenText, message; | 93 String hiddenText, message; |
93 NSRange selectionRange; | 94 NSRange* selectionRange; |
95 NSRange selectionRangeStruct; | |
94 | 96 |
95 /** | 97 /** |
96 * The maximum number of characters that can be entered | 98 * The maximum number of characters that can be entered |
97 * into a text widget. | 99 * into a text widget. |
98 * <p> | 100 * <p> |
150 * @see DWT#WRAP | 152 * @see DWT#WRAP |
151 * @see Widget#checkSubclass | 153 * @see Widget#checkSubclass |
152 * @see Widget#getStyle | 154 * @see Widget#getStyle |
153 */ | 155 */ |
154 public this (Composite parent, int style) { | 156 public this (Composite parent, int style) { |
157 textLimit = LIMIT; | |
158 | |
155 super (parent, checkStyle (style)); | 159 super (parent, checkStyle (style)); |
156 if ((style & DWT.SEARCH) !is 0) { | 160 if ((style & DWT.SEARCH) !is 0) { |
157 // int inAttributesToSet = (style & DWT.CANCEL) !is 0 ? OS.kHISearchFieldAttributesCancel : 0; | 161 // int inAttributesToSet = (style & DWT.CANCEL) !is 0 ? OS.kHISearchFieldAttributesCancel : 0; |
158 // OS.HISearchFieldChangeAttributes (handle, inAttributesToSet, 0); | 162 // OS.HISearchFieldChangeAttributes (handle, inAttributesToSet, 0); |
159 /* | 163 /* |
1128 selectionRange = null; | 1132 selectionRange = null; |
1129 } else { | 1133 } else { |
1130 String oldText = getText (); | 1134 String oldText = getText (); |
1131 if (textLimit !is LIMIT) { | 1135 if (textLimit !is LIMIT) { |
1132 int charCount = oldText.length (); | 1136 int charCount = oldText.length (); |
1133 if (charCount - (selection.y - selection.x) + length > textLimit) { | 1137 if (charCount - (selection.y - selection.x) + length_ > textLimit) { |
1134 string = string.substring(0, textLimit - charCount + (selection.y - selection.x)); | 1138 string = string.substring(0, textLimit - charCount + (selection.y - selection.x)); |
1135 } | 1139 } |
1136 } | 1140 } |
1137 String newText = oldText.substring (0, selection.x) + string + oldText.substring (selection.y); | 1141 String newText = oldText.substring (0, selection.x) ~ string ~ oldText.substring (selection.y); |
1138 setEditText (newText); | 1142 setEditText (newText); |
1139 setSelection (selection.x + string.length ()); | 1143 setSelection (selection.x + string.length ()); |
1140 } | 1144 } |
1141 } | 1145 } |
1142 | 1146 |
1347 if ((style & DWT.SINGLE) !is 0) return true; | 1351 if ((style & DWT.SINGLE) !is 0) return true; |
1348 oldText = DELIMITER; | 1352 oldText = DELIMITER; |
1349 break; | 1353 break; |
1350 default: | 1354 default: |
1351 if (character !is '\t' && character < 0x20) return true; | 1355 if (character !is '\t' && character < 0x20) return true; |
1352 oldText = new String ([character]); | 1356 oldText = new_String ([character]); |
1353 } | 1357 } |
1354 String newText = verifyText (oldText, start, end, nsEvent); | 1358 String newText = verifyText (oldText, start, end, nsEvent); |
1355 if (newText is null) return false; | 1359 if (newText is null) return false; |
1356 if (charCount - (end - start) + newText.length () > textLimit) { | 1360 if (charCount - (end - start) + newText.length () > textLimit) { |
1357 return false; | 1361 return false; |
1369 if (newText.length () !is 0) sendEvent (DWT.Modify); | 1373 if (newText.length () !is 0) sendEvent (DWT.Modify); |
1370 } | 1374 } |
1371 return result; | 1375 return result; |
1372 } | 1376 } |
1373 | 1377 |
1374 void setBackground (CGFloat [] color) { | 1378 void setBackground (Carbon.CGFloat [] color) { |
1375 NSColor nsColor; | 1379 NSColor nsColor; |
1376 if (color is null) { | 1380 if (color is null) { |
1377 return; // TODO reset to OS default | 1381 return; // TODO reset to OS default |
1378 } else { | 1382 } else { |
1379 nsColor = NSColor.colorWithDeviceRed (color [0], color [1], color [2], 1); | 1383 nsColor = NSColor.colorWithDeviceRed (color [0], color [1], color [2], 1); |
1492 return; | 1496 return; |
1493 } | 1497 } |
1494 super.setFont (font); | 1498 super.setFont (font); |
1495 } | 1499 } |
1496 | 1500 |
1497 void setForeground (CGFloat [] color) { | 1501 void setForeground (Carbon.CGFloat [] color) { |
1498 NSColor nsColor; | 1502 NSColor nsColor; |
1499 if (color is null) { | 1503 if (color is null) { |
1500 return; // TODO reset to OS default | 1504 return; // TODO reset to OS default |
1501 } else { | 1505 } else { |
1502 nsColor = NSColor.colorWithDeviceRed (color [0], color [1], color [2], 1); | 1506 nsColor = NSColor.colorWithDeviceRed (color [0], color [1], color [2], 1); |
1623 if ((style & DWT.SINGLE) !is 0) { | 1627 if ((style & DWT.SINGLE) !is 0) { |
1624 NSString str = (new NSCell ((cast(NSTextField) view).cell ())).title (); | 1628 NSString str = (new NSCell ((cast(NSTextField) view).cell ())).title (); |
1625 int length = cast(int)/*64*/str.length (); | 1629 int length = cast(int)/*64*/str.length (); |
1626 int selStart = Math.min (Math.max (Math.min (start, end), 0), length); | 1630 int selStart = Math.min (Math.max (Math.min (start, end), 0), length); |
1627 int selEnd = Math.min (Math.max (Math.max (start, end), 0), length); | 1631 int selEnd = Math.min (Math.max (Math.max (start, end), 0), length); |
1628 selectionRange = NSRange (); | 1632 selectionRangeStruct = NSRange (); |
1633 selectionRange = &selectionRangeStruct; | |
1629 selectionRange.location = selStart; | 1634 selectionRange.location = selStart; |
1630 selectionRange.length = selEnd - selStart; | 1635 selectionRange.length = selEnd - selStart; |
1631 if (this is display.getFocusControl ()) { | 1636 if (this is display.getFocusControl ()) { |
1632 NSText editor = view.window ().fieldEditor (false, view); | 1637 NSText editor = view.window ().fieldEditor (false, view); |
1633 editor.setSelectedRange (selectionRange); | 1638 editor.setSelectedRange (selectionRangeStruct); |
1634 } | 1639 } |
1635 } else { | 1640 } else { |
1636 int length = cast(int)/*64*/(cast(NSTextView) view).textStorage ().length (); | 1641 int length = cast(int)/*64*/(cast(NSTextView) view).textStorage ().length (); |
1637 int selStart = Math.min (Math.max (Math.min (start, end), 0), length); | 1642 int selStart = Math.min (Math.max (Math.min (start, end), 0), length); |
1638 int selEnd = Math.min (Math.max (Math.max (start, end), 0), length); | 1643 int selEnd = Math.min (Math.max (Math.max (start, end), 0), length); |
1814 } | 1819 } |
1815 | 1820 |
1816 void textViewDidChangeSelection(objc.id id, objc.SEL sel, objc.id aNotification) { | 1821 void textViewDidChangeSelection(objc.id id, objc.SEL sel, objc.id aNotification) { |
1817 NSNotification notification = new NSNotification (aNotification); | 1822 NSNotification notification = new NSNotification (aNotification); |
1818 NSText editor = new NSText (notification.object ().id); | 1823 NSText editor = new NSText (notification.object ().id); |
1819 selectionRange = editor.selectedRange (); | 1824 selectionRangeStruct = editor.selectedRange (); |
1825 selectionRange = &selectionRangeStruct; | |
1820 } | 1826 } |
1821 | 1827 |
1822 void textDidChange (objc.id id, objc.SEL sel, objc.id aNotification) { | 1828 void textDidChange (objc.id id, objc.SEL sel, objc.id aNotification) { |
1823 postEvent (DWT.Modify); | 1829 postEvent (DWT.Modify); |
1824 } | 1830 } |
1827 /* | 1833 /* |
1828 * If the selection is changing as a result of the receiver getting focus | 1834 * If the selection is changing as a result of the receiver getting focus |
1829 * then return the receiver's last selection range, otherwise the full | 1835 * then return the receiver's last selection range, otherwise the full |
1830 * text will be automatically selected. | 1836 * text will be automatically selected. |
1831 */ | 1837 */ |
1832 if (receivingFocus && selectionRange !is null) return selectionRange; | 1838 if (receivingFocus && selectionRange !is null) return selectionRangeStruct; |
1833 | 1839 |
1834 /* allow the selection change to proceed */ | 1840 /* allow the selection change to proceed */ |
1835 NSRange result = NSRange (); | 1841 NSRange result = NSRange (); |
1836 OS.memmove(&result, newSelectedCharRange, NSRange.sizeof); | 1842 OS.memmove(&result, newSelectedCharRange, NSRange.sizeof); |
1837 return result; | 1843 return result; |