Mercurial > projects > dwt-mac
comparison dwt/widgets/Text.d @ 139:86fc761a24ae
Fixes #11
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Thu, 04 Jun 2009 23:23:10 +0200 |
parents | 3d9eb62cd2e3 |
children | 834420cb1486 |
comparison
equal
deleted
inserted
replaced
138:3d9eb62cd2e3 | 139:86fc761a24ae |
---|---|
56 import dwt.widgets.Composite; | 56 import dwt.widgets.Composite; |
57 import dwt.widgets.Event; | 57 import dwt.widgets.Event; |
58 import dwt.widgets.Scrollable; | 58 import dwt.widgets.Scrollable; |
59 import dwt.widgets.TypedListener; | 59 import dwt.widgets.TypedListener; |
60 | 60 |
61 import mambo.io; | |
62 | |
63 /** | 61 /** |
64 * Instances of this class are selectable user interface | 62 * Instances of this class are selectable user interface |
65 * objects that allow the user to enter and modify text. | 63 * objects that allow the user to enter and modify text. |
66 * Text controls can be either single or multi-line. | 64 * Text controls can be either single or multi-line. |
67 * When a text control is created with a border, the | 65 * When a text control is created with a border, the |
96 alias Scrollable.setFont setFont; | 94 alias Scrollable.setFont setFont; |
97 alias Scrollable.setForeground setForeground; | 95 alias Scrollable.setForeground setForeground; |
98 alias Scrollable.translateTraversal translateTraversal; | 96 alias Scrollable.translateTraversal translateTraversal; |
99 | 97 |
100 int textLimit, tabs = 8; | 98 int textLimit, tabs = 8; |
101 char echoCharacter; | 99 wchar echoCharacter; |
102 bool doubleClick, receivingFocus; | 100 bool doubleClick, receivingFocus; |
103 wchar[] hiddenText, message; | 101 wchar[] hiddenText, message; |
104 NSRange* selectionRange; | 102 NSRange* selectionRange; |
105 NSRange selectionRangeStruct; | 103 NSRange selectionRangeStruct; |
106 | 104 |
117 /** | 115 /** |
118 * The delimiter used by multi-line text widgets. When text | 116 * The delimiter used by multi-line text widgets. When text |
119 * is queried and from the widget, it will be delimited using | 117 * is queried and from the widget, it will be delimited using |
120 * this delimiter. | 118 * this delimiter. |
121 */ | 119 */ |
122 public static const String DELIMITER; | 120 public static const wchar[] DELIMITER; |
123 static const wchar PASSWORD = '\u2022'; | 121 static const wchar PASSWORD = '\u2022'; |
124 | 122 |
125 /* | 123 /* |
126 * These values can be different on different platforms. | 124 * These values can be different on different platforms. |
127 * Therefore they are not initialized in the declaration | 125 * Therefore they are not initialized in the declaration |
282 * @exception DWTException <ul> | 280 * @exception DWTException <ul> |
283 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 281 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
284 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 282 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
285 * </ul> | 283 * </ul> |
286 */ | 284 */ |
287 public void append (String string) { | 285 public void append (String stri) { |
286 wchar[] string = stri.toString16(); | |
288 checkWidget (); | 287 checkWidget (); |
289 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 288 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
290 if (hooks (DWT.Verify) || filters (DWT.Verify)) { | 289 if (hooks (DWT.Verify) || filters (DWT.Verify)) { |
291 int charCount = getCharCount (); | 290 int charCount = getCharCount (); |
292 string = verifyText (string, charCount, charCount, null); | 291 string = verifyText (string, charCount, charCount, null); |
293 if (string is null) return; | 292 if (string is null) return; |
294 } | 293 } |
295 NSString str = NSString.stringWith (string); | 294 NSString str = NSString.stringWith16 (string); |
296 if ((style & DWT.SINGLE) !is 0) { | 295 if ((style & DWT.SINGLE) !is 0) { |
297 setSelection (getCharCount ()); | 296 setSelection (getCharCount ()); |
298 insertEditText (string); | 297 insertEditText (string); |
299 } else { | 298 } else { |
300 NSTextView widget = cast(NSTextView) view; | 299 NSTextView widget = cast(NSTextView) view; |
502 */ | 501 */ |
503 public void cut () { | 502 public void cut () { |
504 checkWidget (); | 503 checkWidget (); |
505 if ((style & DWT.READ_ONLY) !is 0) return; | 504 if ((style & DWT.READ_ONLY) !is 0) return; |
506 bool cut = true; | 505 bool cut = true; |
507 char [] oldText = null; | 506 wchar [] oldText = null; |
508 Point oldSelection = getSelection (); | 507 Point oldSelection = getSelection (); |
509 if (hooks (DWT.Verify) || filters (DWT.Verify)) { | 508 if (hooks (DWT.Verify) || filters (DWT.Verify)) { |
510 if (oldSelection.x !is oldSelection.y) { | 509 if (oldSelection.x !is oldSelection.y) { |
511 oldText = getEditText (oldSelection.x, oldSelection.y - 1); | 510 oldText = getEditText (oldSelection.x, oldSelection.y - 1); |
512 String newText = verifyText ("", oldSelection.x, oldSelection.y, null); | 511 wchar[] newText = verifyText ("", oldSelection.x, oldSelection.y, null); |
513 if (newText is null) return; | 512 if (newText is null) return; |
514 if (newText.length () !is 0) { | 513 if (newText.length () !is 0) { |
515 copyToClipboard (oldText); | 514 copyToClipboard (oldText); |
516 if ((style & DWT.SINGLE) !is 0) { | 515 if ((style & DWT.SINGLE) !is 0) { |
517 insertEditText (newText); | 516 insertEditText (newText); |
518 } else { | 517 } else { |
519 NSTextView widget = cast(NSTextView) view; | 518 NSTextView widget = cast(NSTextView) view; |
520 widget.replaceCharactersInRange (widget.selectedRange (), NSString.stringWith (newText)); | 519 widget.replaceCharactersInRange (widget.selectedRange (), NSString.stringWith16 (newText)); |
521 } | 520 } |
522 cut = false; | 521 cut = false; |
523 } | 522 } |
524 } | 523 } |
525 } | 524 } |
693 * | 692 * |
694 * @see #setEchoChar | 693 * @see #setEchoChar |
695 */ | 694 */ |
696 public char getEchoChar () { | 695 public char getEchoChar () { |
697 checkWidget (); | 696 checkWidget (); |
698 return echoCharacter; | 697 return toChar(echoCharacter); |
699 } | 698 } |
700 | 699 |
701 /** | 700 /** |
702 * Returns the editable state. | 701 * Returns the editable state. |
703 * | 702 * |
711 public bool getEditable () { | 710 public bool getEditable () { |
712 checkWidget (); | 711 checkWidget (); |
713 return (style & DWT.READ_ONLY) is 0; | 712 return (style & DWT.READ_ONLY) is 0; |
714 } | 713 } |
715 | 714 |
716 char [] getEditText () { | 715 wchar [] getEditText () { |
717 NSString str = null; | 716 NSString str = null; |
718 if ((style & DWT.SINGLE) !is 0) { | 717 if ((style & DWT.SINGLE) !is 0) { |
719 str = (new NSTextFieldCell ((cast(NSTextField) view).cell ())).title (); | 718 str = (new NSTextFieldCell ((cast(NSTextField) view).cell ())).title (); |
720 } else { | 719 } else { |
721 str = (cast(NSTextView)view).textStorage().string(); | 720 str = (cast(NSTextView)view).textStorage().string(); |
728 } else { | 727 } else { |
729 NSRange range = NSRange (); | 728 NSRange range = NSRange (); |
730 range.length = length_; | 729 range.length = length_; |
731 str.getCharacters (buffer.ptr, range); | 730 str.getCharacters (buffer.ptr, range); |
732 } | 731 } |
733 return dwt.dwthelper.utils.toString(buffer); | 732 return buffer;//.fromString16(); |
734 } | 733 } |
735 | 734 |
736 char [] getEditText (int start, int end) { | 735 wchar [] getEditText (int start, int end) { |
737 NSString str = null; | 736 NSString str = null; |
738 if ((style & DWT.SINGLE) !is 0) { | 737 if ((style & DWT.SINGLE) !is 0) { |
739 str = (new NSTextFieldCell ((cast(NSTextField) view).cell ())).title (); | 738 str = (new NSTextFieldCell ((cast(NSTextField) view).cell ())).title (); |
740 } else { | 739 } else { |
741 str = (cast(NSTextView)view).textStorage().string(); | 740 str = (cast(NSTextView)view).textStorage().string(); |
742 } | 741 } |
743 | 742 |
744 int length = cast(int)/*64*/str.length (); | 743 int length = cast(int)/*64*/str.length (); |
745 end = Math.min (end, length - 1); | 744 end = Math.min (end, length - 1); |
746 if (start > end) return new char [0]; | 745 if (start > end) return new wchar [0]; |
747 start = Math.max (0, start); | 746 start = Math.max (0, start); |
748 NSRange range = NSRange (); | 747 NSRange range = NSRange (); |
749 range.location = start; | 748 range.location = start; |
750 range.length = Math.max (0, end - start + 1); | 749 range.length = Math.max (0, end - start + 1); |
751 wchar [] buffer = new wchar [range.length]; | 750 wchar [] buffer = new wchar [range.length]; |
752 if (hiddenText !is null) { | 751 if (hiddenText !is null) { |
753 hiddenText.getChars (cast(int)/*64*/range.location, cast(int)/*64*/(range.location + range.length), buffer, 0); | 752 hiddenText.getChars (cast(int)/*64*/range.location, cast(int)/*64*/(range.location + range.length), buffer, 0); |
754 } else { | 753 } else { |
755 str.getCharacters (buffer.ptr, range); | 754 str.getCharacters (buffer.ptr, range); |
756 } | 755 } |
757 return dwt.dwthelper.utils.toString(buffer); | 756 return buffer;//.fromString16(); |
758 } | 757 } |
759 | 758 |
760 /** | 759 /** |
761 * Returns the number of lines. | 760 * Returns the number of lines. |
762 * | 761 * |
785 * | 784 * |
786 * @see #DELIMITER | 785 * @see #DELIMITER |
787 */ | 786 */ |
788 public String getLineDelimiter () { | 787 public String getLineDelimiter () { |
789 checkWidget (); | 788 checkWidget (); |
790 return DELIMITER; | 789 return DELIMITER.fromString16(); |
791 } | 790 } |
792 | 791 |
793 /** | 792 /** |
794 * Returns the height of a line. | 793 * Returns the height of a line. |
795 * | 794 * |
843 * | 842 * |
844 * @since 3.3 | 843 * @since 3.3 |
845 */ | 844 */ |
846 public String getMessage () { | 845 public String getMessage () { |
847 checkWidget (); | 846 checkWidget (); |
848 return dwt.dwthelper.utils.toString(message); | 847 return message.fromString16(); |
849 } | 848 } |
850 | 849 |
851 int getPosition (int x, int y) { | 850 int getPosition (int x, int y) { |
852 // checkWidget (); | 851 // checkWidget (); |
853 //TODO | 852 //TODO |
927 public String getSelectionText () { | 926 public String getSelectionText () { |
928 checkWidget (); | 927 checkWidget (); |
929 if ((style & DWT.SINGLE) !is 0) { | 928 if ((style & DWT.SINGLE) !is 0) { |
930 Point selection = getSelection (); | 929 Point selection = getSelection (); |
931 if (selection.x is selection.y) return ""; | 930 if (selection.x is selection.y) return ""; |
932 return new_String (getEditText (selection.x, selection.y - 1)); | 931 return new_String (getEditText (selection.x, selection.y - 1).fromString16()); |
933 } else { | 932 } else { |
934 NSTextView widget = cast(NSTextView) view; | 933 NSTextView widget = cast(NSTextView) view; |
935 NSRange range = widget.selectedRange (); | 934 NSRange range = widget.selectedRange (); |
936 NSString str = widget.textStorage ().string (); | 935 NSString str = widget.textStorage ().string (); |
937 wchar[] buffer = new wchar [range.length]; | 936 wchar[] buffer = new wchar [range.length]; |
938 str.getCharacters (buffer.ptr, range); | 937 str.getCharacters (buffer.ptr, range); |
939 return dwt.dwthelper.utils.toString(buffer); | 938 return buffer.fromString16(); |
940 } | 939 } |
941 } | 940 } |
942 | 941 |
943 /** | 942 /** |
944 * Returns the number of tabs. | 943 * Returns the number of tabs. |
976 */ | 975 */ |
977 public String getText () { | 976 public String getText () { |
978 checkWidget (); | 977 checkWidget (); |
979 NSString str; | 978 NSString str; |
980 if ((style & DWT.SINGLE) !is 0) { | 979 if ((style & DWT.SINGLE) !is 0) { |
981 return new_String (getEditText ()); | 980 return new_String (getEditText ().fromString16()); |
982 } else { | 981 } else { |
983 str = (cast(NSTextView)view).textStorage ().string (); | 982 str = (cast(NSTextView)view).textStorage ().string (); |
984 } | 983 } |
985 return str.getString(); | 984 return str.getString(); |
985 } | |
986 | |
987 private wchar[] getText16 () { | |
988 checkWidget (); | |
989 NSString str; | |
990 if ((style & DWT.SINGLE) !is 0) { | |
991 return getEditText ().dup; | |
992 } else { | |
993 str = (cast(NSTextView)view).textStorage ().string (); | |
994 } | |
995 return str.getString16(); | |
986 } | 996 } |
987 | 997 |
988 /** | 998 /** |
989 * Returns a range of text. Returns an empty string if the | 999 * Returns a range of text. Returns an empty string if the |
990 * start of the range is greater than the end. | 1000 * start of the range is greater than the end. |
1005 */ | 1015 */ |
1006 public String getText (int start, int end) { | 1016 public String getText (int start, int end) { |
1007 checkWidget (); | 1017 checkWidget (); |
1008 if (!(start <= end && 0 <= end)) return ""; //$NON-NLS-1$ | 1018 if (!(start <= end && 0 <= end)) return ""; //$NON-NLS-1$ |
1009 if ((style & DWT.SINGLE) !is 0) { | 1019 if ((style & DWT.SINGLE) !is 0) { |
1010 return new_String (getEditText (start, end)); | 1020 return new_String (getEditText (start, end).fromString16()); |
1011 } | 1021 } |
1012 NSTextStorage storage = (cast(NSTextView) view).textStorage (); | 1022 NSTextStorage storage = (cast(NSTextView) view).textStorage (); |
1013 end = Math.min (end, cast(int)/*64*/storage.length () - 1); | 1023 end = Math.min (end, cast(int)/*64*/storage.length () - 1); |
1014 if (start > end) return ""; //$NON-NLS-1$ | 1024 if (start > end) return ""; //$NON-NLS-1$ |
1015 start = Math.max (0, start); | 1025 start = Math.max (0, start); |
1103 * @exception DWTException <ul> | 1113 * @exception DWTException <ul> |
1104 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 1114 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
1105 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1115 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1106 * </ul> | 1116 * </ul> |
1107 */ | 1117 */ |
1108 public void insert (String string) { | 1118 public void insert (String stri) { |
1119 wchar[] string = stri.toString16(); | |
1109 checkWidget (); | 1120 checkWidget (); |
1110 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 1121 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
1111 if (hooks (DWT.Verify) || filters (DWT.Verify)) { | 1122 if (hooks (DWT.Verify) || filters (DWT.Verify)) { |
1112 Point selection = getSelection (); | 1123 Point selection = getSelection (); |
1113 string = verifyText (string, selection.x, selection.y, null); | 1124 string = verifyText (string, selection.x, selection.y, null); |
1114 if (string is null) return; | 1125 if (string is null) return; |
1115 } | 1126 } |
1116 if ((style & DWT.SINGLE) !is 0) { | 1127 if ((style & DWT.SINGLE) !is 0) { |
1117 insertEditText (string); | 1128 insertEditText (string); |
1118 } else { | 1129 } else { |
1119 NSString str = NSString.stringWith (string); | 1130 NSString str = NSString.stringWith16 (string); |
1120 NSTextView widget = cast(NSTextView) view; | 1131 NSTextView widget = cast(NSTextView) view; |
1121 NSRange range = widget.selectedRange (); | 1132 NSRange range = widget.selectedRange (); |
1122 widget.textStorage ().replaceCharactersInRange (range, str); | 1133 widget.textStorage ().replaceCharactersInRange (range, str); |
1123 } | 1134 } |
1124 if (string.length () !is 0) sendEvent (DWT.Modify); | 1135 if (string.length () !is 0) sendEvent (DWT.Modify); |
1125 } | 1136 } |
1126 | 1137 |
1127 void insertEditText (String string) { | 1138 void insertEditText (wchar[] string) { |
1128 int length_ = string.length (); | 1139 int length_ = string.length (); |
1129 Point selection = getSelection (); | 1140 Point selection = getSelection (); |
1130 if (hasFocus () && hiddenText is null) { | 1141 if (hasFocus () && hiddenText is null) { |
1131 if (textLimit !is LIMIT) { | 1142 if (textLimit !is LIMIT) { |
1132 int charCount = getCharCount(); | 1143 int charCount = getCharCount(); |
1133 if (charCount - (selection.y - selection.x) + length_ > textLimit) { | 1144 if (charCount - (selection.y - selection.x) + length_ > textLimit) { |
1134 length_ = textLimit - charCount + (selection.y - selection.x); | 1145 length_ = textLimit - charCount + (selection.y - selection.x); |
1135 } | 1146 } |
1136 } | 1147 } |
1137 char [] buffer = new char [length_]; | 1148 wchar [] buffer = new wchar [length_]; |
1138 string.getChars (0, buffer.length, buffer, 0); | 1149 string.getChars (0, buffer.length, buffer, 0); |
1139 NSString nsstring = NSString.stringWithCharacters (buffer.toString16().ptr, buffer.length); | 1150 NSString nsstring = NSString.stringWithCharacters (buffer.ptr, buffer.length); |
1140 NSText editor = (cast(NSTextField) view).currentEditor (); | 1151 NSText editor = (cast(NSTextField) view).currentEditor (); |
1141 editor.replaceCharactersInRange (editor.selectedRange (), nsstring); | 1152 editor.replaceCharactersInRange (editor.selectedRange (), nsstring); |
1142 selectionRange = null; | 1153 selectionRange = null; |
1143 } else { | 1154 } else { |
1144 String oldText = getText (); | 1155 wchar[] oldText = getText16 (); |
1145 if (textLimit !is LIMIT) { | 1156 if (textLimit !is LIMIT) { |
1146 int charCount = oldText.length (); | 1157 int charCount = oldText.length (); |
1147 if (charCount - (selection.y - selection.x) + length_ > textLimit) { | 1158 if (charCount - (selection.y - selection.x) + length_ > textLimit) { |
1148 string = string.substring(0, textLimit - charCount + (selection.y - selection.x)); | 1159 string = string.substring(0, textLimit - charCount + (selection.y - selection.x)); |
1149 } | 1160 } |
1150 } | 1161 } |
1151 String newText = oldText.substring (0, selection.x) ~ string ~ oldText.substring (selection.y); | 1162 wchar[] newText = oldText.substring (0, selection.x) ~ string ~ oldText.substring (selection.y); |
1152 setEditText (newText); | 1163 setEditText (newText); |
1153 setSelection (selection.x + string.length ()); | 1164 setSelection (selection.x + string.length ()); |
1154 } | 1165 } |
1155 } | 1166 } |
1156 | 1167 |
1168 */ | 1179 */ |
1169 public void paste () { | 1180 public void paste () { |
1170 checkWidget (); | 1181 checkWidget (); |
1171 if ((style & DWT.READ_ONLY) !is 0) return; | 1182 if ((style & DWT.READ_ONLY) !is 0) return; |
1172 bool paste = true; | 1183 bool paste = true; |
1173 String oldText = null; | 1184 wchar[] oldText = null; |
1174 if (hooks (DWT.Verify) || filters (DWT.Verify)) { | 1185 if (hooks (DWT.Verify) || filters (DWT.Verify)) { |
1175 oldText = getClipboardText (); | 1186 oldText = getClipboardText16 (); |
1176 if (oldText !is null) { | 1187 if (oldText !is null) { |
1177 Point selection = getSelection (); | 1188 Point selection = getSelection (); |
1178 String newText = verifyText (oldText, selection.x, selection.y, null); | 1189 wchar[] newText = verifyText (oldText, selection.x, selection.y, null); |
1179 if (newText is null) return; | 1190 if (newText is null) return; |
1180 if (!newText.equals (oldText)) { | 1191 if (!newText.equals (oldText)) { |
1181 if ((style & DWT.SINGLE) !is 0) { | 1192 if ((style & DWT.SINGLE) !is 0) { |
1182 insertEditText (newText); | 1193 insertEditText (newText); |
1183 } else { | 1194 } else { |
1184 NSTextView textView = cast(NSTextView) view; | 1195 NSTextView textView = cast(NSTextView) view; |
1185 textView.replaceCharactersInRange (textView.selectedRange (), NSString.stringWith (newText)); | 1196 textView.replaceCharactersInRange (textView.selectedRange (), NSString.stringWith16 (newText)); |
1186 } | 1197 } |
1187 paste = false; | 1198 paste = false; |
1188 } | 1199 } |
1189 } | 1200 } |
1190 } | 1201 } |
1191 if (paste) { | 1202 if (paste) { |
1192 if ((style & DWT.SINGLE) !is 0) { | 1203 if ((style & DWT.SINGLE) !is 0) { |
1193 if (oldText is null) oldText = getClipboardText (); | 1204 if (oldText is null) oldText = getClipboardText16 (); |
1194 insertEditText (oldText); | 1205 insertEditText (oldText); |
1195 } else { | 1206 } else { |
1196 //TODO check text limit | 1207 //TODO check text limit |
1197 (cast(NSTextView) view).paste (null); | 1208 (cast(NSTextView) view).paste (null); |
1198 } | 1209 } |
1337 postEvent (DWT.DefaultSelection); | 1348 postEvent (DWT.DefaultSelection); |
1338 default: | 1349 default: |
1339 } | 1350 } |
1340 } | 1351 } |
1341 if ((stateMask & DWT.COMMAND) !is 0) return result; | 1352 if ((stateMask & DWT.COMMAND) !is 0) return result; |
1342 String oldText = ""; | 1353 wchar[] oldText = ""; |
1343 int charCount = getCharCount (); | 1354 int charCount = getCharCount (); |
1344 Point selection = getSelection (); | 1355 Point selection = getSelection (); |
1345 int start = selection.x, end = selection.y; | 1356 int start = selection.x, end = selection.y; |
1346 ushort keyCode = nsEvent.keyCode (); | 1357 ushort keyCode = nsEvent.keyCode (); |
1347 NSString characters = nsEvent.charactersIgnoringModifiers(); | 1358 NSString characters = nsEvent.charactersIgnoringModifiers(); |
1348 char character = cast(char) characters.characterAtIndex(0); | 1359 wchar character = characters.characterAtIndex(0); |
1349 switch (keyCode) { | 1360 switch (keyCode) { |
1350 case 51: /* Backspace */ | 1361 case 51: /* Backspace */ |
1351 if (start is end) { | 1362 if (start is end) { |
1352 if (start is 0) return true; | 1363 if (start is 0) return true; |
1353 start = Math.max (0, start - 1); | 1364 start = Math.max (0, start - 1); |
1365 break; | 1376 break; |
1366 default: | 1377 default: |
1367 if (character !is '\t' && character < 0x20) return true; | 1378 if (character !is '\t' && character < 0x20) return true; |
1368 oldText = new_String ([character]); | 1379 oldText = new_String ([character]); |
1369 } | 1380 } |
1370 String newText = verifyText (oldText, start, end, nsEvent); | 1381 wchar[] newText = verifyText (oldText, start, end, nsEvent); |
1371 if (newText is null) return false; | 1382 if (newText is null) return false; |
1372 if (charCount - (end - start) + newText.length () > textLimit) { | 1383 if (charCount - (end - start) + newText.length () > textLimit) { |
1373 return false; | 1384 return false; |
1374 } | 1385 } |
1375 result = newText is oldText; | 1386 result = newText is oldText; |
1376 if (newText !is oldText || hiddenText !is null) { | 1387 if (newText !is oldText || hiddenText !is null) { |
1377 if ((style & DWT.SINGLE) !is 0) { | 1388 if ((style & DWT.SINGLE) !is 0) { |
1378 insertEditText (newText); | 1389 insertEditText (newText); |
1379 } else { | 1390 } else { |
1380 NSString str = NSString.stringWith (newText); | 1391 NSString str = NSString.stringWith16 (newText); |
1381 NSTextView widget = cast(NSTextView) view; | 1392 NSTextView widget = cast(NSTextView) view; |
1382 NSRange range = widget.selectedRange (); | 1393 NSRange range = widget.selectedRange (); |
1383 widget.textStorage ().replaceCharactersInRange (range, str); | 1394 widget.textStorage ().replaceCharactersInRange (range, str); |
1384 } | 1395 } |
1385 if (newText.length () !is 0) sendEvent (DWT.Modify); | 1396 if (newText.length () !is 0) sendEvent (DWT.Modify); |
1457 // setSelection (selection); | 1468 // setSelection (selection); |
1458 // } | 1469 // } |
1459 // } else { | 1470 // } else { |
1460 // OS.TXNEchoMode (txnObject, echo, OS.kTextEncodingMacUnicode, echo !is '\0'); | 1471 // OS.TXNEchoMode (txnObject, echo, OS.kTextEncodingMacUnicode, echo !is '\0'); |
1461 // } | 1472 // } |
1462 echoCharacter = echo; | 1473 echoCharacter = toWChar(echo); |
1463 } | 1474 } |
1464 | 1475 |
1465 /** | 1476 /** |
1466 * Sets the editable state. | 1477 * Sets the editable state. |
1467 * | 1478 * |
1484 } else { | 1495 } else { |
1485 (cast(NSTextView) view).setEditable (editable); | 1496 (cast(NSTextView) view).setEditable (editable); |
1486 } | 1497 } |
1487 } | 1498 } |
1488 | 1499 |
1489 void setEditText (String string) { | 1500 void setEditText (wchar[] string) { |
1490 char [] buffer; | 1501 wchar [] buffer; |
1491 if ((style & DWT.PASSWORD) is 0 && echoCharacter !is '\0') { | 1502 if ((style & DWT.PASSWORD) && echoCharacter !is '\0') { |
1492 hiddenText = string.toString16(); | 1503 hiddenText = string; |
1493 buffer = new char [Math.min(hiddenText.length (), textLimit)]; | 1504 buffer = new wchar [Math.min(hiddenText.length (), textLimit)]; |
1494 for (int i = 0; i < buffer.length; i++) buffer [i] = echoCharacter; | 1505 for (int i = 0; i < buffer.length; i++) buffer [i] = echoCharacter; |
1495 } else { | 1506 } else { |
1496 hiddenText = null; | 1507 hiddenText = null; |
1497 buffer = new char [Math.min(string.length (), textLimit)]; | 1508 buffer = new wchar [Math.min(string.length (), textLimit)]; |
1498 string.getChars (0, buffer.length, buffer, 0); | 1509 string.getChars (0, buffer.length, buffer, 0); |
1499 } | 1510 } |
1500 NSString nsstring = NSString.stringWithCharacters (buffer.toString16().ptr, buffer.length); | 1511 NSString nsstring = NSString.stringWithCharacters (buffer.ptr, buffer.length); |
1501 (new NSCell ((cast(NSTextField) view).cell ())).setTitle (nsstring); | 1512 (new NSCell ((cast(NSTextField) view).cell ())).setTitle (nsstring); |
1502 selectionRange = null; | 1513 selectionRange = null; |
1503 } | 1514 } |
1504 | 1515 |
1505 void setFont(NSFont font) { | 1516 void setFont(NSFont font) { |
1737 * @exception DWTException <ul> | 1748 * @exception DWTException <ul> |
1738 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | 1749 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
1739 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | 1750 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
1740 * </ul> | 1751 * </ul> |
1741 */ | 1752 */ |
1742 public void setText (String string) { | 1753 public void setText (String stri) { |
1754 wchar[] string = stri.toString16(); | |
1743 checkWidget (); | 1755 checkWidget (); |
1744 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 1756 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
1745 if (hooks (DWT.Verify) || filters (DWT.Verify)) { | 1757 if (hooks (DWT.Verify) || filters (DWT.Verify)) { |
1746 string = verifyText (string, 0, getCharCount (), null); | 1758 string = verifyText (string, 0, getCharCount (), null); |
1747 if (string is null) return; | 1759 if (string is null) return; |
1748 } | 1760 } |
1749 if ((style & DWT.SINGLE) !is 0) { | 1761 if ((style & DWT.SINGLE) !is 0) { |
1750 setEditText (string); | 1762 setEditText (string); |
1751 } else { | 1763 } else { |
1752 NSString str = NSString.stringWith (string); | 1764 NSString str = NSString.stringWith16 (string); |
1753 (cast(NSTextView) view).setString (str); | 1765 (cast(NSTextView) view).setString (str); |
1754 } | 1766 } |
1755 sendEvent (DWT.Modify); | 1767 sendEvent (DWT.Modify); |
1756 } | 1768 } |
1757 | 1769 |
1869 } | 1881 } |
1870 } | 1882 } |
1871 return bits; | 1883 return bits; |
1872 } | 1884 } |
1873 | 1885 |
1874 String verifyText (String string, int start, int end, NSEvent keyEvent) { | 1886 wchar[] verifyText (wchar[] string, int start, int end, NSEvent keyEvent) { |
1875 Event event = new Event (); | 1887 Event event = new Event (); |
1876 if (keyEvent !is null) setKeyState(event, DWT.MouseDown, keyEvent); | 1888 if (keyEvent !is null) setKeyState(event, DWT.MouseDown, keyEvent); |
1877 event.text = string; | 1889 event.text = string.fromString16(); |
1878 event.start = start; | 1890 event.start = start; |
1879 event.end = end; | 1891 event.end = end; |
1880 /* | 1892 /* |
1881 * It is possible (but unlikely), that application | 1893 * It is possible (but unlikely), that application |
1882 * code could have disposed the widget in the verify | 1894 * code could have disposed the widget in the verify |
1883 * event. If this happens, answer null to cancel | 1895 * event. If this happens, answer null to cancel |
1884 * the operation. | 1896 * the operation. |
1885 */ | 1897 */ |
1886 sendEvent (DWT.Verify, event); | 1898 sendEvent (DWT.Verify, event); |
1887 if (!event.doit || isDisposed ()) return null; | 1899 if (!event.doit || isDisposed ()) return null; |
1888 return event.text; | 1900 return event.text.toString16(); |
1889 } | 1901 } |
1890 | 1902 |
1891 } | 1903 } |