diff options
author | Felipe Heidrich <Felipe_Heidrich@ca.ibm.com> | 2011-10-03 16:46:15 -0400 |
---|---|---|
committer | Felipe Heidrich <Felipe_Heidrich@ca.ibm.com> | 2011-10-03 16:46:31 -0400 |
commit | 9a39dee83784b3c2bfe7d6bc90a74b8510926e15 (patch) | |
tree | 5e165bef732810a2e4440751aae2cda6701746d8 /bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets | |
parent | 7f1ea0d7cac5eadd71c5b3d7f25af0ee2a0eaff5 (diff) | |
download | eclipse.platform.swt-9a39dee83784b3c2bfe7d6bc90a74b8510926e15.tar.gz eclipse.platform.swt-9a39dee83784b3c2bfe7d6bc90a74b8510926e15.tar.xz eclipse.platform.swt-9a39dee83784b3c2bfe7d6bc90a74b8510926e15.zip |
bug 44072: review win32
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets')
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java | 76 | ||||
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Text.java | 1 |
2 files changed, 66 insertions, 11 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java index 6cc4641aa2..b0a8cc3d41 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Combo.java @@ -657,10 +657,34 @@ boolean dragDetect (int /*long*/ hwnd, int x, int y, boolean filter, boolean [] return super.dragDetect (hwnd, x, y, filter, detect, consume); } -public Point getCaretLocation() { - checkWidget(); - int position = getCaretPosition(); - int hwndText = OS.GetDlgItem(handle, CBID_EDIT); +/** + * Returns a point describing the location of the caret relative + * to the receiver. + * + * @return a point, the location of the caret + * + * @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 3.8 + */ +public Point getCaretLocation () { + checkWidget (); + /* + * Bug in Windows. For some reason, Windows is unable + * to return the pixel coordinates of the last character + * in the widget. The fix is to temporarily insert a + * space, query the coordinates and delete the space. + * The selection is always an i-beam in this case because + * this is the only time the start of the selection can + * be equal to the last character position in the widget. + * If EM_POSFROMCHAR fails for any other reason, return + * pixel coordinates (0,0). + */ + int position = getCaretPosition (); + int hwndText = OS.GetDlgItem (handle, CBID_EDIT); int /*long*/ caretPos = OS.SendMessage (hwndText, OS.EM_POSFROMCHAR, position, 0); if (caretPos == -1) { caretPos = 0; @@ -669,6 +693,17 @@ public Point getCaretLocation() { int [] start = new int [1], end = new int [1]; OS.SendMessage (hwndText, OS.EM_GETSEL, start, end); OS.SendMessage (hwndText, OS.EM_SETSEL, position, position); + /* + * 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 = ignoreModify = true; OS.SendMessage (hwndText, OS.EM_REPLACESEL, 0, new TCHAR (cp, " ", true)); caretPos = OS.SendMessage (hwndText, OS.EM_POSFROMCHAR, position, 0); @@ -682,14 +717,38 @@ public Point getCaretLocation() { return new Point (OS.GET_X_LPARAM (caretPos), OS.GET_Y_LPARAM (caretPos)); } -public int getCaretPosition() { - checkWidget(); +/** + * Returns the character position of the caret. + * <p> + * Indexing is zero based. + * </p> + * + * @return the position of the caret + * + * @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 3.8 + */ +public int getCaretPosition () { + checkWidget (); int [] start = new int [1], end = new int [1]; int /*long*/ hwndText = OS.GetDlgItem (handle, CBID_EDIT); OS.SendMessage (hwndText, OS.EM_GETSEL, start, end); + /* + * In Windows, there is no API to get the position of the caret + * when the selection is not an i-beam. The best that can be done + * is to query the pixel position of the current caret and compare + * it to the pixel position of the start and end of the selection. + * + * NOTE: This does not work when the i-beam belongs to another + * control. In this case, guess that the i-beam is at the start + * of the selection. + */ int caret = start [0]; if (start [0] != end [0]) { - if (!OS.IsWinCE) { int idThread = OS.GetWindowThreadProcessId (hwndText, null); GUITHREADINFO lpgui = new GUITHREADINFO (); @@ -714,13 +773,10 @@ public int getCaretPosition() { } if (!OS.IsUnicode && OS.IsDBLocale) { caret = mbcsToWcsPos (caret); - } return caret; } - - /** * Returns the item at the given, zero-relative index in the * receiver's list. Throws an exception if the index is out 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 8252a09309..38f0451215 100644 --- 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 @@ -763,7 +763,6 @@ public int getCaretPosition () { * of the selection. */ int caret = start [0]; - //System.out.println(caret); if (start [0] != end [0]) { int startLine = (int)/*64*/OS.SendMessage (handle, OS.EM_LINEFROMCHAR, start [0], 0); int endLine = (int)/*64*/OS.SendMessage (handle, OS.EM_LINEFROMCHAR, end [0], 0); |