if (end [0] == lineStart - DELIMITER.length ()) { end [0] = end [0] + DELIMITER.length (); } else { end [0] = end [0] + 1; if (OS.IsDBLocale) { int [] newStart = new int [1], newEnd = new int [1]; OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]); OS.SendMessage (handle, OS.EM_GETSEL, newStart, newEnd); if (end [0] != newEnd [0]) end [0] = end [0] + 1; } } end [0] = Math.min (end [0], length); } break; case '\r': /* Return */ if ((style & SWT.SINGLE) != 0) return true; oldText = DELIMITER; break; default: /* Tab and other characters */ if (key != '\t' && key < 0x20) return true; oldText = new String (new char [] {key}); break; } String newText = verifyText (oldText, start [0], end [0], event); if (newText == null) return false; if (newText == oldText) return true; newText = Display.withCrLf (newText); TCHAR buffer = new TCHAR (getCodePage (), newText, true); OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]); /* * Feature in Windows. When an edit control with ES_MULTILINE * style that does not have the WS_VSCROLL style is full (i.e. * there is no space at the end to draw any more characters), * EM_REPLACESEL sends a WM_CHAR with a backspace character * to remove any further text that is added. This is an * implementation detail of the edit control that is unexpected * and can cause endless recursion when EM_REPLACESEL is sent * from a WM_CHAR handler. The fix is to ignore calling the * handler from WM_CHAR. */ ignoreCharacter = true; OS.SendMessage (handle, OS.EM_REPLACESEL, 0, buffer); ignoreCharacter = false; return false;}void setBounds (int x, int y, int width, int height, int flags) { /* * Feature in Windows. When the caret is moved, * the text widget scrolls to show the new location. * This means that the text widget may be scrolled * to the right in order to show the caret when the * widget is not large enough to show both the caret * location and all the text. Unfortunately, when * the text widget is resized such that all the text * and the caret could be visible, Windows does not * scroll the widget back. The fix is to resize the * text widget, set the selection to the start of the * text and then restore the selection. This will * cause the text widget compute the correct scroll * position. */ if ((flags & OS.SWP_NOSIZE) == 0 && width != 0) { RECT rect = new RECT (); OS.GetWindowRect (handle, rect); if (rect.right - rect.left == 0) { int [] start = new int [1], end = new int [1]; OS.SendMessage (handle, OS.EM_GETSEL, start, end); if (start [0] != 0 || end [0] != 0) { SetWindowPos (handle, 0, x, y, width, height, flags); OS.SendMessage (handle, OS.EM_SETSEL, 0, 0); OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]); return; } } } super.setBounds (x, y, width, height, flags);}/** * Sets the double click enabled flag. * <p> * The double click flag enables or disables the * default action of the text widget when the user * double clicks. * </p> * * @param doubleClick the new double click flag * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setDoubleClickEnabled (boolean doubleClick) { checkWidget (); this.doubleClick = doubleClick;}/** * Sets the echo character. * <p> * The echo character is the character that is * displayed when the user enters text or the * text is changed by the programmer. Setting * the echo character to '\0' clears the echo * character and redraws the original text. * If for any reason the echo character is invalid, * the default echo character for the platform * is used. * </p> * * @param echo the new echo character * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setEchoChar (char echo) { checkWidget (); if ((style & SWT.MULTI) != 0) return; if (echo != 0) { if ((echo = (char) Display.wcsToMbcs (echo, getCodePage ())) == 0) echo = '*'; } OS.SendMessage (handle, OS.EM_SETPASSWORDCHAR, echo, 0); /* * Bug in Windows. When the password character is changed, * Windows does not redraw to show the new password character. * The fix is to force a redraw when the character is set. */ OS.InvalidateRect (handle, null, true);}/** * Sets the editable state. * * @param editable the new editable state * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setEditable (boolean editable) { checkWidget (); style &= ~SWT.READ_ONLY; if (!editable) style |= SWT.READ_ONLY; OS.SendMessage (handle, OS.EM_SETREADONLY, editable ? 0 : 1, 0);}public void setFont (Font font) { checkWidget (); super.setFont (font); setTabStops (tabs);}/** * Sets the orientation of the receiver, which must be one * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>. * <p> * * @param orientation new orientation style * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @since 2.1.2 */public void setOrientation (int orientation) { checkWidget(); if (OS.IsWinCE) return; if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) return; int flags = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT; if ((orientation & flags) == 0 || (orientation & flags) == flags) return; style &= ~flags; style |= orientation & flags; int bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE); if ((style & SWT.RIGHT_TO_LEFT) != 0) { bits |= OS.WS_EX_RTLREADING | OS.WS_EX_LEFTSCROLLBAR; } else { bits &= ~(OS.WS_EX_RTLREADING | OS.WS_EX_LEFTSCROLLBAR); } OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits); fixAlignment ();}/** * Sets the selection. * <p> * Indexing is zero based. The range of * a selection is from 0..N where N is * the number of characters in the widget. * </p><p> * Text selections are specified in terms of * caret positions. In a text widget that * contains N characters, there are N+1 caret * positions, ranging from 0..N. This differs * from other functions that address character * position such as getText () that use the * regular array indexing rules. * </p> * * @param start new caret position * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setSelection (int start) { checkWidget (); if (OS.IsDBLocale) start = wcsToMbcsPos (start); OS.SendMessage (handle, OS.EM_SETSEL, start, start); OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);}/** * Sets the selection. * <p> * Indexing is zero based. The range of * a selection is from 0..N where N is * the number of characters in the widget. * </p><p> * Text selections are specified in terms of * caret positions. In a text widget that * contains N characters, there are N+1 caret * positions, ranging from 0..N. This differs * from other functions that address character * position such as getText () that use the * usual array indexing rules. * </p> * * @param start the start of the range * @param end the end of the range * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setSelection (int start, int end) { checkWidget (); if (OS.IsDBLocale) { start = wcsToMbcsPos (start); end = wcsToMbcsPos (end); } OS.SendMessage (handle, OS.EM_SETSEL, start, end); OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0);}public void setRedraw (boolean redraw) { checkWidget (); super.setRedraw (redraw); /* * Feature in Windows. When WM_SETREDRAW is used to turn * redraw off, the edit control is not scrolled to show the * i-beam. The fix is to detect that the i-beam has moved * while redraw is turned off and force it to be visible * when redraw is restored. */ if (drawCount != 0) return; int [] start = new int [1], end = new int [1]; OS.SendMessage (handle, OS.EM_GETSEL, start, end); if (!redraw) { oldStart = start [0]; oldEnd = end [0]; } else { if (oldStart == start [0] && oldEnd == end [0]) return; OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0); }}/** * Sets the selection. * <p> * Indexing is zero based. The range of * a selection is from 0..N where N is * the number of characters in the widget. * </p><p> * Text selections are specified in terms of * caret positions. In a text widget that * contains N characters, there are N+1 caret * positions, ranging from 0..N. This differs * from other functions that address character * position such as getText () that use the * usual array indexing rules. * </p> * * @param selection the point * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the point is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setSelection (Point selection) { checkWidget (); if (selection == null) error (SWT.ERROR_NULL_ARGUMENT); setSelection (selection.x, selection.y);}/** * Sets the number of tabs. * <p> * Tab stop spacing is specified in terms of the * space (' ') character. The width of a single * tab stop is the pixel width of the spaces. * </p> * * @param tabs the number of tabs * * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setTabs (int tabs) { checkWidget (); if (tabs < 0) return; setTabStops (this.tabs = tabs);}void setTabStops (int tabs) { /* * Feature in Windows. Windows expects the tab spacing in * dialog units so we must convert from space widths. Due * to round off error, the tab spacing may not be the exact * number of space widths, depending on the font. */ int width = (getTabWidth (tabs) * 4) / (OS.GetDialogBaseUnits () & 0xFFFF); OS.SendMessage (handle, OS.EM_SETTABSTOPS, 1, new int [] {width});}/** * Sets the contents of the receiver to the given string. If the receiver has style * SINGLE and the argument contains multiple lines of text, the result of this * operation is undefined and may vary from platform to platform. * * @param string the new text * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the string is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setText (String string) { checkWidget (); if (string == null) error (SWT.ERROR_NULL_ARGUMENT); string = Display.withCrLf (string); if (hooks (SWT.Verify) || filters (SWT.Verify)) { int length = OS.GetWindowTextLength (handle); string = verifyText (string, 0, length, null); if (string == null) return; } TCHAR buffer = new TCHAR (getCodePage (), string, true); OS.SetWindowText (handle, buffer); /* * Bug in Windows. When the widget is multi line * text widget, it does not send a WM_COMMAND with * control code EN_CHANGE from SetWindowText () to * notify the application that the text has changed. * The fix is to send the event. */ if ((style & SWT.MULTI) != 0) { sendEvent (SWT.Modify); // widget could be disposed at this point }}/** * Sets the maximum number of characters that the receiver * is capable of holding to be the argument. * <p> * Instead of trying to set the text limit to zero, consider * creating a read-only text widget. * </p><p> * To reset this value to the default, use <code>setTextLimit(Text.LIMIT)</code>. * </p> * * @param limit new text limit * * @exception IllegalArgumentException <ul> * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li> * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setTextLimit (int limit) { checkWidget (); if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); OS.SendMessage (handle, OS.EM_SETLIMITTEXT, limit, 0);}