Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 332282

Summary: The styledtext caret position is incorrect when switch Orientation
Product: [Eclipse Project] Platform Reporter: yanghang
Component: SWTAssignee: Felipe Heidrich <eclipse.felipe>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipse.felipe
Version: 3.4.2   
Target Milestone: 3.7 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on: 29779    
Bug Blocks:    
Attachments:
Description Flags
original size
none
change bigger
none
change smaller
none
sample code none

Description yanghang CLA 2010-12-10 03:54:08 EST
Build Identifier: SWT3.4.2

switch styledtext Orientation, and resize styledtext size, the caret position is incorrect.

Reproducible: Always

Steps to Reproduce:
1. launch my sample code
2. press CTRL+G to swith Orientation from LTR to RTL
3. resize the shell

Bug:
if change size smaller, the caret is lost;
if change size bigger, the caret is not at line end
Comment 1 yanghang CLA 2010-12-10 03:55:45 EST
Created attachment 184927 [details]
original size
Comment 2 yanghang CLA 2010-12-10 03:57:37 EST
Created attachment 184928 [details]
change bigger
Comment 3 yanghang CLA 2010-12-10 03:58:35 EST
Created attachment 184929 [details]
change smaller
Comment 4 yanghang CLA 2010-12-10 10:04:47 EST
Created attachment 184957 [details]
sample code
Comment 5 Felipe Heidrich CLA 2010-12-10 15:06:56 EST
I suspect this is a bug in Windows and should be fixed when we finish Bug 29779.
Comment 6 Felipe Heidrich CLA 2010-12-10 16:08:45 EST
The bug is here: Canvas
LRESULT WM_WINDOWPOSCHANGED (int /*long*/ wParam, int /*long*/ lParam) {
	LRESULT result  = super.WM_WINDOWPOSCHANGED (wParam, lParam);
	//if (result != null) return result;
	/*
	* Bug in Windows.  When a window with style WS_EX_LAYOUTRTL
	* that contains a caret is resized, Windows does not move the
	* caret in relation to the mirrored origin in the top right.
	* The fix is to hide the caret in WM_WINDOWPOSCHANGING and
	* show the caret in WM_WINDOWPOSCHANGED.
	*/
	boolean isFocus = (style & SWT.RIGHT_TO_LEFT) != 0 && caret != null && caret.isFocusCaret ();
	if (isFocus) caret.setFocus ();
	return result;
}

Set orientation for StyledText does not update the style field.
So this (style & SWT.RIGHT_TO_LEFT) != 0 still returns false after StyledText#setOrientation(SWT.RIGHT_TO_LEFT)

This will be fixed when we fix Bug 29779.
If we don't fix Bug 29779, we can fix this bug by adding:
int style = getStyle(); before the test.
Comment 7 Felipe Heidrich CLA 2010-12-23 14:40:19 EST
Fixed in HEAD.