Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java')
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java131
1 files changed, 96 insertions, 35 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java
index e84bc03bf9..bb0b6d99b4 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java
@@ -1,8 +1,8 @@
package org.eclipse.swt.widgets;
/*
- * Licensed Materials - Property of IBM,
- * (c) Copyright IBM Corp. 1998, 2001 All Rights Reserved
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved
*/
import org.eclipse.swt.internal.*;
@@ -21,7 +21,7 @@ import org.eclipse.swt.events.*;
* <dt><b>Events:</b></dt>
* <dd>DefaultSelection, Modify, Verify</dd>
* </dl>
- * <p>
+ * </p>
* IMPORTANT: This class is <em>not</em> intended to be subclassed.
*/
@@ -95,6 +95,10 @@ public void addModifyListener (ModifyListener listener) {
* be notified when the control is selected, by sending
* it one of the messages defined in the <code>SelectionListener</code>
* interface.
+ * <p>
+ * <code>widgetSelected</code> is not called for texts.
+ * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text.
+ * </p>
*
* @param listener the listener which should be notified
*
@@ -108,6 +112,7 @@ public void addModifyListener (ModifyListener listener) {
*
* @see SelectionListener
* @see #removeSelectionListener
+ * @see SelectionEvent
*/
public void addSelectionListener (SelectionListener listener) {
checkWidget ();
@@ -148,6 +153,7 @@ public void addVerifyListener (VerifyListener listener) {
* <p>
* The new text is appended to the text at
* the end of the widget.
+ * </p>
*
* @param string the string to be appended
*
@@ -177,15 +183,12 @@ public void append (String string) {
static int checkStyle (int style) {
if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL);
if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) {
- return style | SWT.MULTI;
- }
+ if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) return style | SWT.MULTI;
return style | SWT.SINGLE;
}
/**
* Clears the selection.
- * <p>
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
@@ -268,6 +271,7 @@ public Point computeSize (int wHint, int hHint, boolean changed) {
* Copies the selected text.
* <p>
* The current selection is copied to the clipboard.
+ * </p>
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
@@ -294,6 +298,7 @@ void createWidget () {
* <p>
* The current selection is first copied to the
* clipboard and then deleted from the widget.
+ * </p>
*
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
@@ -316,6 +321,7 @@ int defaultBackground () {
* Gets the line number of the caret.
* <p>
* The line number of the caret is returned.
+ * </p>
*
* @return the line number
*
@@ -336,6 +342,7 @@ public int getCaretLineNumber () {
* Gets the location the caret.
* <p>
* The location of the caret is returned.
+ * </p>
*
* @return a point, the location of the caret
*
@@ -377,6 +384,7 @@ public Point getCaretLocation () {
* Gets the position of the caret.
* <p>
* The character position of the caret is returned.
+ * </p>
*
* @return the position of the caret
*
@@ -400,7 +408,7 @@ public int getCaretPosition () {
/**
* Gets the number of characters.
- * <p>
+ *
* @return number of characters in the widget
*
* @exception SWTException <ul>
@@ -444,6 +452,7 @@ String getClipboardText () {
* The double click flag enables or disables the
* default action of the text widget when the user
* double clicks.
+ * </p>
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
@@ -461,6 +470,7 @@ public boolean getDoubleClickEnabled () {
* The echo character is the character that is
* displayed when the user enters text or the
* text is changed by the programmer.
+ * </p>
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
@@ -476,7 +486,6 @@ public char getEchoChar () {
/**
* Gets the editable state.
- * <p>
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
@@ -491,7 +500,7 @@ public boolean getEditable () {
/**
* Gets the number of lines.
- * <p>
+ *
* @return the number of lines in the widget
*
* @exception SWTException <ul>
@@ -506,7 +515,7 @@ public int getLineCount () {
/**
* Gets the line delimiter.
- * <p>
+ *
* @return a string that is the line delimiter
*
* @exception SWTException <ul>
@@ -521,7 +530,7 @@ public String getLineDelimiter () {
/**
* Gets the height of a line.
- * <p>
+ *
* @return the height of a row of text
*
* @exception SWTException <ul>
@@ -548,6 +557,7 @@ public int getLineHeight () {
* Indexing is zero based. The range of
* a selection is from 0..N where N is
* the number of characters in the widget.
+ * </p>
*
* @return the start and end of the selection
*
@@ -569,7 +579,7 @@ public Point getSelection () {
/**
* Gets the number of selected characters.
- * <p>
+ *
* @return the number of selected characters.
*
* @exception SWTException <ul>
@@ -585,7 +595,6 @@ public int getSelectionCount () {
/**
* Gets the selected text.
- * <p>
*
* @return the selected text
*
@@ -611,6 +620,7 @@ public String getSelectionText () {
* 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>
*
* @return the number of tab characters
*
@@ -641,6 +651,7 @@ int getTabWidth (int tabs) {
* Gets the widget text.
* <p>
* The text for a text widget is the characters in the widget.
+ * </p>
*
* @return the widget text
*
@@ -665,6 +676,7 @@ public String getText () {
* Indexing is zero based. The range of
* a selection is from 0..N-1 where N is
* the number of characters in the widget.
+ * </p>
*
* @param start the start of the range
* @param end the end of the range
@@ -687,10 +699,11 @@ public String getText (int start, int end) {
}
/**
- * Returns the maximum number of characters that the receiver
- * is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Text.LIMIT</code>.
+ * Returns the maximum number of characters that the receiver is capable of holding.
+ * <p>
+ * If this has not been changed by <code>setTextLimit()</code>,
+ * it will be the constant <code>Text.LIMIT</code>.
+ * </p>
*
* @return the text limit
*
@@ -706,8 +719,10 @@ public int getTextLimit () {
/**
* Returns the zero-relative index of the line which is currently
- * at the top of the receiver. This index can change when lines are
- * scrolled or new lines are added or removed.
+ * at the top of the receiver.
+ * <p>
+ * This index can change when lines are scrolled or new lines are added or removed.
+ * </p>
*
* @return the index of the top line
*
@@ -731,9 +746,10 @@ public int getTopIndex () {
* some platforms, a text widget can be scrolled by
* pixels instead of lines so that a partial line
* is displayed at the top of the widget.
- * <p>
+ * </p><p>
* The top pixel changes when the widget is scrolled.
* The top pixel does not include the widget trimming.
+ * </p>
*
* @return the pixel position of the top line
*
@@ -770,6 +786,7 @@ boolean getWrap () {
* Inserts a string.
* <p>
* The old selection is replaced with the new text.
+ * </p>
*
* @param string the string
*
@@ -833,6 +850,7 @@ int mbcsToWcsPos (int mbcsPos) {
* <p>
* The selected text is deleted from the widget
* and new text inserted from the clipboard.
+ * </p>
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
@@ -1028,11 +1046,12 @@ boolean sendKeyEvent (int type, int msg, int wParam, int lParam, Event event) {
/**
* Sets the double click enabled flag.
* <p>
- * @param doubleClick the new double click flag
- *
* 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>
@@ -1047,11 +1066,12 @@ public void setDoubleClickEnabled (boolean doubleClick) {
/**
* Sets the echo character.
* <p>
- * @param echo the new echo character
- *
* The echo character is the character that is
* displayed when the user enters text or the
* text is changed by the programmer.
+ * </p>
+ *
+ * @param echo the new echo character
*
* @exception SWTException <ul>
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
@@ -1072,7 +1092,7 @@ public void setEchoChar (char echo) {
/**
* Sets the editable state.
- * <p>
+ *
* @param editable the new editable state
*
* @exception SWTException <ul>
@@ -1096,11 +1116,10 @@ public void setFont (Font font) {
/**
* 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
@@ -1108,6 +1127,7 @@ public void setFont (Font font) {
* from other functions that address character
* position such as getText () that use the
* regular array indexing rules.
+ * </p>
*
* @param start new caret position
*
@@ -1128,11 +1148,10 @@ public void setSelection (int start) {
/**
* 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
@@ -1140,6 +1159,7 @@ public void setSelection (int start) {
* 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
@@ -1185,11 +1205,10 @@ public void setRedraw (boolean redraw) {
/**
* 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
@@ -1197,6 +1216,7 @@ public void setRedraw (boolean redraw) {
* from other functions that address character
* position such as getText () that use the
* usual array indexing rules.
+ * </p>
*
* @param selection the point
*
@@ -1220,6 +1240,7 @@ public void setSelection (Point selection) {
* 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
*
@@ -1243,7 +1264,7 @@ void setTabStops (int tabs) {
* number of space widths, depending on the font.
*/
int width = (getTabWidth (tabs) * 4) / (OS.GetDialogBaseUnits () & 0xFFFF);
- OS.SendMessage (handle, OS.EM_SETTABSTOPS, 1, new short [] {(short) width});
+ OS.SendMessage (handle, OS.EM_SETTABSTOPS, 1, new int [] {width});
}
/**
@@ -1335,10 +1356,13 @@ void setWrap (boolean wrap) {
}
/**
- * Shows the selection. If the selection is already showing
+ * Shows the selection.
+ * <p>
+ * If the selection is already showing
* in the receiver, this method simply returns. Otherwise,
* lines are scrolled until the selection is visible.
- *
+ * </p>
+ *
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
@@ -1591,6 +1615,43 @@ LRESULT WM_PASTE (int wParam, int lParam) {
return result;
}
+LRESULT WM_SIZE (int wParam, int lParam) {
+ LRESULT result = super.WM_SIZE (wParam, lParam);
+ // widget may be disposed at this point
+ if (handle == 0) return result;
+
+ /*
+ * 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 left 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 save the
+ * current selection, set the selection to the start
+ * of the text and then restore the selection. This
+ * will cause the text widget recompute the left
+ * scroll position.
+ *
+ * NOTE: Currently, this work around is only applied
+ * to single line text widgets that are not visible.
+ * If the widget is resized when it is visible, this
+ * is fine because the user has already seen that the
+ * text is scrolled.
+ */
+ int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
+ if ((bits & OS.ES_MULTILINE) != 0) return result;
+ if (OS.IsWindowVisible (handle)) return result;
+ int [] start = new int [1], end = new int [1];
+ OS.SendMessage (handle, OS.EM_GETSEL, start, end);
+ if (start [0] == 0 && end [0] == 0) return result;
+ OS.SendMessage (handle, OS.EM_SETSEL, 0, 0);
+ OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]);
+ return result;
+}
+
LRESULT WM_UNDO (int wParam, int lParam) {
LRESULT result = super.WM_UNDO (wParam, lParam);
if (result != null) return result;

Back to the top