Sign in Join
Wiki copytemporary

BidiMode: what changed

Revision 3 to 4. 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-```
24+```text
2525 For Example
2626 in bdLeftToRight:
2727 Menu1, Menu2, Menu2
2828 in bdRightToLeft:
2929 Menu3, Menu2, Menu1
3030```
3131
3232That 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
3333
34-```
34+```text
3535 in bdLeftToRight:
3636 Word1 Word2 Word2
3737 in bdRightToLeft:
3838 Word3 Word2 Word1
3939```
4040
4141We 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.
4242
4343For testing purpose I used English word with a symbol to test Right To Left text reading
4444
4545E.g. *Word?*
4646
4747For special states or for more compatibility with Delphi there are other values (possible? used? handy?)
4848
4949##### bdRightToLeftNoAlign
5050
5151It is Right to Left but not reversed (except the Alignment property), but in Lazarus worked when use FlipControls
5252
5353##### bdRightToLeftReadingOnly
5454
5555It is Right to Left text reading only; scrollbar and alignment do not take effect (*??? remain left to right???*).
5656
5757### ParentBidiMode
5858
5959If this is True the control inherits the BidiMode value from its parent.
6060
6161### BidiMode for developers
6262
6363When 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
6464
6565``` pascal
6666function UseRightToLeftAlignment: Boolean; virtual;
6767function UseRightToLeftReading: Boolean; virtual;
6868function UseRightToLeftScrollBar: Boolean;
6969function IsRightToLeft: Boolean;
7070```
7171
7272Because 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.
7373
7474Not 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.
7575
7676![](/wiki-images/2/24/BidiMode_Sample_1.png)
7777
7878## Add BidiMode support to LCL components
7979
8080Most 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:
8181
82821. Standard Controls: it is easy to enable RTL support: just add some flag to switch it to RightToLeft (TEdit, TList, TComboBox, TCheckBox).
83832. 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.
84843. Native Controls: hard work is needed to make it Support RightToLeft, or we must add new controls that already have this features (TLabel, TGrid).
8585
8686### Add BidiMode property to TControl
8787
8888*TBidiMode is already declared in Classes*
8989
9090``` pascal
9191property BiDiMode: TBiDiMode read FBiDiMode write SetBiDiMode stored IsBiDiModeStored;
9292property ParentBiDiMode: Boolean read FParentBiDiMode write SetParentBiDiMode default True;
9393```
9494
9595BidiMode must not be stored if ParentBidiMode = True
9696
9797``` pascal
9898function TControl.IsBiDiModeStored: Boolean;
9999begin
100100 Result := not ParentBiDiMode;
101101end;
102102```
103103
104104**Override BidiMode functions**
105105
106106``` pascal
107107function IsRightToLeft:Boolean; override;
108108function UseRightToLeftAlignment: Boolean; override;
109109function UseRightToLeftReading: Boolean; override;
110110function UseRightToLeftScrollBar: Boolean; override;
111111```
112112
113113*BiDiMode property is public and must published in every control need to RightToLeft*
114114
115115### Bidi Controls Road Map
116116
117117GTK2 You must build LCL with OPT=-dGTK2 OPT=-dGTK_2_8
118118
119119| Component | win32 | gtk2 | carbon | qt | wince | cocoa |
120120|----|----|----|----|----|----|----|
121121| TForm | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
122122| TLabel | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
123123| TButton | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
124124| TEdit | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
125125| TListBox | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
126126| TComboBox | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
127127| TCheckBox | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
128128| TStaticText | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
129129| TGroupBox | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
130130| TRadioButton | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
131131| Menus | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
132132| TBitBtn | Partially Implemented | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
133133| TSpeedBtn | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
134134| TRadioGroup | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
135135| TCheckGroup | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
136136| TGrid | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
137137
138138### Functions and Utils useful for multi language application
139139
140-```
140+```text
141141 TControl.FlipControls; virtual
142142 Change Right to Left and Left to Right in this properties (Left, Align, Anchors and Alignment)
143143```
144144
145145## How to test RightToLeft reading
146146
147147Create 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.
148148
149149# BiDi support of the widgetsets
150150
151151## Carbon
152152
153153Write me.
154154
155155## fpGui
156156
157157Write me.
158158
159159## Gtk1
160160
161161Has almost no BiDi support. Is deprecated by Lazarus anyway, so no new development at all.
162162
163163## Gtk2
164164
165165In 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.
166166
167167## Qt
168168
169169Write me.
170170
171171## Windows
172172
173173In 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.
174174
175175# References
176176
177177- [Unicode Bidirectional Algorithm](http://www.unicode.org/reports/tr9/)
178178- [Design and Implementation of a Win32 Text Editor](http://www.catch22.net/book/export/html/14)
179179
180180---
181181*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).*
182182Category: LCL
183183Category: Lazarus
184184Category: Lazarus internals
185185Category: Localization

Back to history