Sign in Join
Wiki copytemporary

BidiMode: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11Some languages (Arabic, Hebrew, Farsi ...) write the characters from the right to the left, and adequate support for this must be implemented on Lazarus.
22
33#### BidiMode
44
55BidiMode can have these settings:
66
77``` pascal
88bdLeftToRight
99bdRightToLeft
1010bdRightToLeftNoAlign
1111bdRightToLeftReadingOnly
1212```
1313
1414##### bdLeftToRight
1515
1616Default of BidiMode, which means read and order is normal "Left To Right"
1717
1818##### bdRightToLeft
1919
2020Makes a control Right To Left reading text and right alignment depend a kind of the control,
2121
2222In Delphi if there is Alignment property effect by reverse taLeft to taRight and vise versa, but in Lazarus we will reverse the alignment with FlipControls function, which is more consistent with Anchors and Align properties. Also bdRightToLeft takes a Scrollbar at the left and if there is a cell or menus they must ordered from the right.
2323
24-` For Example`\
25-` in bdLeftToRight:`\
26-`   Menu1, Menu2, Menu2`\
27-` in bdRightToLeft: `\
28-`   Menu3, Menu2, Menu1`
24+```
25+ For Example
26+ in bdLeftToRight:
27+ Menu1, Menu2, Menu2
28+ in bdRightToLeft:
29+ Menu3, Menu2, Menu1
30+```
2931
3032That means not just Right Alignment; it is Right To Left Order. bdRightToLeft must effect the text reading as depend on the OS if it is supported, the sentence words take as like Cells
3133
32-` in bdLeftToRight:`\
33-`   Word1 Word2 Word2`\
34-` in bdRightToLeft: `\
35-`   Word3 Word2 Word1`
34+```
35+ in bdLeftToRight:
36+ Word1 Word2 Word2
37+ in bdRightToLeft:
38+ Word3 Word2 Word1
39+```
3640
3741We are reading the Word1 first then Word2, We read from the Right to Left, but Draw Text is more complicated than normal Cells; in fact the function that draws the text cares about English/Latin words and draws it Left To Right, so if we mixed both languages in the same sentence, the draw function draws continual English words in Left To Right order to make it readable, but symbols like ? or ! are considered as Right To Left characters.
3842
3943For testing purpose I used English word with a symbol to test Right To Left text reading
4044
4145E.g. *Word?*
4246
4347For special states or for more compatibility with Delphi there are other values (possible? used? handy?)
4448
4549##### bdRightToLeftNoAlign
4650
4751It is Right to Left but not reversed (except the Alignment property), but in Lazarus worked when use FlipControls
4852
4953##### bdRightToLeftReadingOnly
5054
5155It is Right to Left text reading only; scrollbar and alignment do not take effect (*??? remain left to right???*).
5256
5357### ParentBidiMode
5458
5559If this is True the control inherits the BidiMode value from its parent.
5660
5761### BidiMode for developers
5862
5963When you build you own controls and try to make your control support Right to Left or BidiMode, you must not access the BiDiMode property directly. Instead you must use
6064
6165``` pascal
6266function UseRightToLeftAlignment: Boolean; virtual;
6367function UseRightToLeftReading: Boolean; virtual;
6468function UseRightToLeftScrollBar: Boolean;
6569function IsRightToLeft: Boolean;
6670```
6771
6872Because some controls do not need to make changes to the alignment - for example TButton it always is centered, or TMainMenu which always is right aligned if it is Right to Left.
6973
7074Not just reading the words and cells, everything depends on the order (positions). For an application there is a Menus and Controls that when placed on the form must have positions starting from the right. It is like looking at a LeftToRight Form in a mirror. The flow of the Form must be from Right To Left.
7175
7276![](/wiki-images/2/24/BidiMode_Sample_1.png)
7377
7478## Add BidiMode support to LCL components
7579
7680Most OSes now support RightToLeft but there are controls that are not supported yet or there is controls made by native language (*custom drawn?*) such as (TLabel, TGrid). So we have 3 kinds of control:
7781
78821. Standard Controls: it is easy to enable RTL support: just add some flag to switch it to RightToLeft (TEdit, TList, TComboBox, TCheckBox).
79832. Standard Controls not supported by the OS: There is no idea just waiting the OS developers to implement it to support (TListView, TTreeView), or use native controls that already support it.
80843. Native Controls: hard work is needed to make it Support RightToLeft, or we must add new controls that already have this features (TLabel, TGrid).
8185
8286### Add BidiMode property to TControl
8387
8488*TBidiMode is already declared in Classes*
8589
8690``` pascal
8791property BiDiMode: TBiDiMode read FBiDiMode write SetBiDiMode stored IsBiDiModeStored;
8892property ParentBiDiMode: Boolean read FParentBiDiMode write SetParentBiDiMode default True;
8993```
9094
9195BidiMode must not be stored if ParentBidiMode = True
9296
9397``` pascal
9498function TControl.IsBiDiModeStored: Boolean;
9599begin
96100 Result := not ParentBiDiMode;
97101end;
98102```
99103
100104**Override BidiMode functions**
101105
102106``` pascal
103107function IsRightToLeft:Boolean; override;
104108function UseRightToLeftAlignment: Boolean; override;
105109function UseRightToLeftReading: Boolean; override;
106110function UseRightToLeftScrollBar: Boolean; override;
107111```
108112
109113*BiDiMode property is public and must published in every control need to RightToLeft*
110114
111115### Bidi Controls Road Map
112116
113117GTK2 You must build LCL with OPT=-dGTK2 OPT=-dGTK_2_8
114118
115119| Component | win32 | gtk2 | carbon | qt | wince | cocoa |
116120|----|----|----|----|----|----|----|
117121| TForm | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
118122| TLabel | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
119123| TButton | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
120124| TEdit | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
121125| TListBox | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
122126| TComboBox | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
123127| TCheckBox | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
124128| TStaticText | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
125129| TGroupBox | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
126130| TRadioButton | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
127131| Menus | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
128132| TBitBtn | Partially Implemented | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
129133| TSpeedBtn | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
130134| TRadioGroup | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
131135| TCheckGroup | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
132136| TGrid | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
133137
134138### Functions and Utils useful for multi language application
135139
136-` `**`TControl.FlipControls; virtual`**\
137-` Change Right to Left and Left to Right in this properties (Left, Align, Anchors and Alignment)`
140+```
141+ TControl.FlipControls; virtual
142+ Change Right to Left and Left to Right in this properties (Left, Align, Anchors and Alignment)
143+```
138144
139145## How to test RightToLeft reading
140146
141147Create a new form, then add a TButton or TEdit. Set the caption to **OK?**. You must add **?** or **!** or **.** to the last word without a space. Now set the BidiMode to bdRightToLeft, and you should see the ? in the left of word if it works.
142148
143149# BiDi support of the widgetsets
144150
145151## Carbon
146152
147153Write me.
148154
149155## fpGui
150156
151157Write me.
152158
153159## Gtk1
154160
155161Has almost no BiDi support. Is deprecated by Lazarus anyway, so no new development at all.
156162
157163## Gtk2
158164
159165In TMemo, TEdit, TComboBox the popup menu contains the two sub menus *Input Methods* and *Insert Unicode Control character*. Gtk2 uses for text rendering the **Pango** library, which has excellent Unicode support.
160166
161167## Qt
162168
163169Write me.
164170
165171## Windows
166172
167173In Windows 7 you can switch in TMemo, TEdit, TComboBox the base direction with Left-`Ctrl`+Right-`Shift` to RTL (right to left) and Right-`Ctrl`+Left-`Shift` to LTR (left to right). This also works in the IDE for most things, like in the Property Editor and the Strings Editor Dialog.
168174
169175# References
170176
171177- [Unicode Bidirectional Algorithm](http://www.unicode.org/reports/tr9/)
172178- [Design and Implementation of a Win32 Text Editor](http://www.catch22.net/book/export/html/14)
173179
174180---
175181*From the Free Pascal wiki, page "BidiMode", as it stood on 2020-02-07 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
176182Category: LCL
177183Category: Lazarus
178184Category: Lazarus internals
179185Category: Localization

Back to history