I'm not sure when EXSTYLE was introduced in MSWindows. But I think RightToLeftLayout was introduced in Vista sp2. So I guess it is a windows version issue.
Ok, it is supported in recent versions only.
Maybe you didn't understand my question about EXSTYLE and SetWindowLong.
Basically I am asking "what does RightToLeftLayout in Windows do?". Does it adjust individual controls?
If yes, then you don't need to do it in your application or library.
If no, then what is it good for as it does nothing apparently?
You may have noticed that I activate RightToLeftLayout only at run-time. I could mirror the Form at design-time, but something in Lazarus is broken there as well. Example: Add a TPanel to a TForm then add a TEdit to the TPanel. It looks right, but for some unknown reason the TEdit.Parent is the TForm and you must change the Parent manually. Doable, but not practical.
The designer calculates the control positions dynamically.
If you mirror controls inside a TCustomControl handler, it very likely breaks things (as it did).
The right design is to build RightToLeft support into LCL layout engine, as I explained earlier.
All of the issues I have found seem to be because Lazarus followed Delphi and Delphi never really designed to handle RightToLeft. The result 'appears' to be that Lazarus wasn't developed to handle it either, which is understandable. It wasn't that long ago that RightToLeft on computers wasn't doable at all so almost all development was done in the Western world. Now things are changing.
Now, studying Lazarus code, BiDiMode already has lots of support.
Look for method "SetBiDiMode". It is implemented for many widgetsets, for example for TWin32WSWinControl in Windows:
class procedure TWin32WSWinControl.SetBiDiMode(const AWinControl : TWinControl;
UseRightToLeftAlign, UseRightToLeftReading, UseRightToLeftScrollBar : Boolean);
var
FlagsEx: dword;
begin
if not WSCheckHandleAllocated(AWinControl, 'SetBiDiMode') then
Exit;
FlagsEx := GetWindowLong(AWinControl.Handle, GWL_EXSTYLE);
FlagsEx := FlagsEx and not (WS_EX_RTLREADING or WS_EX_RIGHT or WS_EX_LEFTSCROLLBAR);
if UseRightToLeftAlign then
FlagsEx := FlagsEx or WS_EX_RIGHT;
if UseRightToLeftReading then
FlagsEx := FlagsEx or WS_EX_RTLREADING ;
if UseRightToLeftScrollBar then
FlagsEx := FlagsEx or WS_EX_LEFTSCROLLBAR;
SetWindowLong(AWinControl.Handle, GWL_EXSTYLE, FlagsEx);
end;
It clearly does the same what your global function does and more.
You wrote that BiDiMode is not for the same purpose as RightToLeftLayout. I am still saying that they are for the same purpose but BiDiMode is poorly implemented.
Or, can you point a use case where the current BiDiMode should be used instead of your new RightToLeftLayout?
For example what should TForm.BiDiMode do? I guess it should always mirror the layout. (?)
Its current behavior can be considered a bug and should be fixed, even it is not Delphi compatible then.
A flag in TApplication might be more logical but BiDiMode and ParentBiDiMode are not bad either if they worked correctly.
If you implement a new flag, say TApplication.RightToLeftLayout which directly competes and overlaps with BiDiMode, I believe any depeloper will ask the same question as I do:
Why not improve BiDiMode instead?
If they had different purposes then they both should exist. From your writing I understood BiDiMode is simply broken and not useful as it is. IMO the logical solution is to improve it.
I got the impression you have not studied the code in Lazarus and LCL much before hacking your functions.
The problem you try to solve is so integral part of LCL that you really must study it.
Otherwise you end up doing some ugly hack, but later realize it was already implemented properly somewhere else. I know the feeling, I have done it many times myself.
Everybody can create new code but undertanding and modifying existing code is a challenge. (...or let's say everybody
wants to create new code).
It is important to keep the design good. In a big project it is especially important.
Quick hacks tend to cumulate. Later you must do a new hack on top of old hack ...
As for anchoring, the approach I am using takes care of that. Things are still anchored to the Left, but because the canvas is flipped, Left is now Right and Right is now Left.
Earlier I understood it created a problem by flipping images (?)
BTW, there is no MS Visual Studio for Linux. Microsoft likes its own OS only.
I still believe RightToLeft support is built into .NET. You can check if Mono has it, too.
Juha