Two wrongs don't make a right, and two rights can make it wrong

by Michael S. Kaplan, published on 2007/03/11 03:01 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2007/03/11/1857043.aspx


The CreateWindowEx function has several flags that as documented are clearly related to right-to-left scripts:

WS_EX_LAYOUTRTL
Arabic and Hebrew versions of Windows 98/Me, Windows 2000/XP: Creates a window whose horizontal origin is on the right edge. Increasing horizontal values advance to the left.

WS_EX_LEFTSCROLLBAR
If the shell language is Hebrew, Arabic, or another language that supports reading order alignment, the vertical scroll bar (if present) is to the left of the client area. For other languages, the style is ignored.
 
WS_EX_RIGHT
The window has generic "right-aligned" properties. This depends on the window class. This style has an effect only if the shell language is Hebrew, Arabic, or another language that supports reading-order alignment; otherwise, the style is ignored.
Using the WS_EX_RIGHT style for static or edit controls has the same effect as using the SS_RIGHT or ES_RIGHT style, respectively. Using this style with button controls has the same effect as using BS_RIGHT and BS_RIGHTBUTTON styles.

WS_EX_RTLREADING
If the shell language is Hebrew, Arabic, or another language that supports reading-order alignment, the window text is displayed using right-to-left reading-order properties. For other languages, the style is ignored.

In the minds of most developers who trying to support the input of right-to-left languages, it is quite an understatement to claim that the proper use of these flags can be quite confusing, not least of all because some of it is actually wrong in quite a few cases of every version of Windows >= Windows 2000 (where one can support right-to-left scripts even when the "Shell language" is not itself a right-to-left script.

This particular aspect of the Windows CreateWindowEx SDK topic (and its various and sundry CE cousins) may not be the single most obvious case of documentation that should be overhauled to remove anachronistic ambiguity, confusion, and inaccuracy, but it is probably in the top five.

I'll try to make some suggestions here another day, but for now I'll quote some words from Tom Moore, a developer in Office who was recently helping someone who was having to deal with some confusing results due to the strange potential interaction of these flags:

...please try using only the WS_EX_LAYOUTRTL flag, without the WS_EX_RTLREADING flag.  Because WS_EX_LAYOUTRTL will take care of both layout and reading order with the single flag.  If you were to use both of the flags together, that would take care of layout, but the reading order would end up being left-to-right again, since the two flags will cancel each other out regarding the reading order, by reversing it twice.

Tom is 100% correct here -- if you include both the WS_EX_LAYOUTRTL and WS_EX_RTLREADING extended style flags together, you will end up with a right-to-left layout with a left-to-right reading order, which makes it obvious that these are not simple "right-to-left" flags when it comes to reading order; they are more "flip the reading order" flags.

So in the end, two RIGHTs in this case are almost certain to make for a WRONG... a WRONG result, that is!

I'll cover some of the additional issues with the documentation of these different flags and their interaction in future posts....

 

This post brought to you by R (U+0052, a.k.a. LATIN CAPITAL LETTER R)


Ally on 31 Oct 2008 7:57 PM:

Thanks for the tips - I had to revise our app when I was told we needed to support Arabic.


Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day