For now at least, this is ONLY for Windows. Hopefully we can find a way to do this in other OS's, or better still, actually fix the Controls for BiDiMode. But this is a start in that direction.
I have been experimenting trying to find a way to improve Lazarus support for RightToLeft Languages/Controls. I have found some interesting things, but of course, there are some very big problems and I am hoping to get some feedback from other 'RightToLeft' programmers.
I can now 'Flip' any TWinControl and with some of them, they seem to work perfectly, others 'sort of' work, and other just don't work at all.
For ANY of this to work, you MUST TURN OFF THEMES!!! Go to 'Project Options' and there is a checkbox to turn Themes OFF. Otherwise TWinControl.Canvas becomes totally unusable if you use the method that I have found. Hopefully this will soon be resolved. It is already in BugTracker for quite awhile.
The main 'workhorse' is:
Add Windows to the uses statement.
procedure RTLCtrl(ACtrl: TObject);
{ Make TWinControl RightToLeft - Windows ONLY! }
begin
if ACtrl is TWinControl then
with ACtrl as TWinControl do begin
if TWinControl(ACtrl).IsRightToLeft then
TWinControl(ACtrl).BiDiMode:= bdLeftToRight; // See Note 1.
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE)
or WS_EX_LEFT
or WS_EX_RTLREADING
//or WS_EX_LEFTSCROLLBAR //See Note 2.
or WS_EX_LAYOUTRTL
or WS_EX_NOINHERITLAYOUT);
end;
end;
I use the TForm.OnShow method to 'Flip' everything. This is an example:
procedure TForm1.FormShow(Sender: TObject);
begin
RTLCtrl(Form1);
RTLCtrl(PageControl1);
RTLCtrl(TreeView1);
RTLCtrl(Calendar1);
RTLCtrl(ShellTreeView1);
RTLCtrl(HeaderControl1);
RTLCtrl(ToggleBox1);
RTLCtrl(StaticText1);
RTLCtrl(CheckListBox1);
RTLCtrl(ScrollBox1);
end;
Note 1. This line looks totally wrong, but without it Controls with vertical Scrollbars stay Right aligned. I have not figured out a way to solve this yet.
Note 2. According to MS, this should move vertical ScrollBars to the Left, but I guess they get 'flipped' twice and end up on the Right.