Sign in Join
Wiki copytemporary

BidiMode: what changed

Revision 1 to 2. 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
2424` For Example`\
2525` in bdLeftToRight:`\
2626`   Menu1, Menu2, Menu2`\
2727` in bdRightToLeft: `\
2828`   Menu3, Menu2, Menu1`
2929
3030That 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
3131
3232` in bdLeftToRight:`\
3333`   Word1 Word2 Word2`\
3434` in bdRightToLeft: `\
3535`   Word3 Word2 Word1`
3636
3737We 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.
3838
3939For testing purpose I used English word with a symbol to test Right To Left text reading
4040
4141E.g. *Word?*
4242
4343For special states or for more compatibility with Delphi there are other values (possible? used? handy?)
4444
4545##### bdRightToLeftNoAlign
4646
4747It is Right to Left but not reversed (except the Alignment property), but in Lazarus worked when use FlipControls
4848
4949##### bdRightToLeftReadingOnly
5050
5151It is Right to Left text reading only; scrollbar and alignment do not take effect (*??? remain left to right???*).
5252
5353### ParentBidiMode
5454
5555If this is True the control inherits the BidiMode value from its parent.
5656
5757### BidiMode for developers
5858
5959When 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
6060
6161``` pascal
6262function UseRightToLeftAlignment: Boolean; virtual;
6363function UseRightToLeftReading: Boolean; virtual;
6464function UseRightToLeftScrollBar: Boolean;
6565function IsRightToLeft: Boolean;
6666```
6767
6868Because 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.
6969
7070Not 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.
7171
72-<figure>
73-<img src="BidiMode_Sample_1.png" title="Sample 1" />
74-<figcaption>Sample 1</figcaption>
75-</figure>
72+![](/wiki-images/2/24/BidiMode_Sample_1.png)
7673
7774## Add BidiMode support to LCL components
7875
7976Most 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:
8077
81781. Standard Controls: it is easy to enable RTL support: just add some flag to switch it to RightToLeft (TEdit, TList, TComboBox, TCheckBox).
82792. 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.
83803. Native Controls: hard work is needed to make it Support RightToLeft, or we must add new controls that already have this features (TLabel, TGrid).
8481
8582### Add BidiMode property to TControl
8683
8784*TBidiMode is already declared in Classes*
8885
8986``` pascal
9087property BiDiMode: TBiDiMode read FBiDiMode write SetBiDiMode stored IsBiDiModeStored;
9188property ParentBiDiMode: Boolean read FParentBiDiMode write SetParentBiDiMode default True;
9289```
9390
9491BidiMode must not be stored if ParentBidiMode = True
9592
9693``` pascal
9794function TControl.IsBiDiModeStored: Boolean;
9895begin
9996 Result := not ParentBiDiMode;
10097end;
10198```
10299
103100**Override BidiMode functions**
104101
105102``` pascal
106103function IsRightToLeft:Boolean; override;
107104function UseRightToLeftAlignment: Boolean; override;
108105function UseRightToLeftReading: Boolean; override;
109106function UseRightToLeftScrollBar: Boolean; override;
110107```
111108
112109*BiDiMode property is public and must published in every control need to RightToLeft*
113110
114111### Bidi Controls Road Map
115112
116113GTK2 You must build LCL with OPT=-dGTK2 OPT=-dGTK_2_8
117114
118115| Component | win32 | gtk2 | carbon | qt | wince | cocoa |
119116|----|----|----|----|----|----|----|
120117| TForm | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
121118| TLabel | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
122119| TButton | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
123120| TEdit | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
124121| TListBox | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
125122| TComboBox | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
126123| TCheckBox | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
127124| TStaticText | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
128125| TGroupBox | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
129126| TRadioButton | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
130127| Menus | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
131128| TBitBtn | Partially Implemented | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
132129| TSpeedBtn | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
133130| TRadioGroup | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
134131| TCheckGroup | Working | Working | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
135132| TGrid | Working | Partially Implemented | Not Implemented | Not Implemented | Not Implemented | Not Implemented |
136133
137134### Functions and Utils useful for multi language application
138135
139136` `**`TControl.FlipControls; virtual`**\
140137` Change Right to Left and Left to Right in this properties (Left, Align, Anchors and Alignment)`
141138
142139## How to test RightToLeft reading
143140
144141Create 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.
145142
146143# BiDi support of the widgetsets
147144
148145## Carbon
149146
150147Write me.
151148
152149## fpGui
153150
154151Write me.
155152
156153## Gtk1
157154
158155Has almost no BiDi support. Is deprecated by Lazarus anyway, so no new development at all.
159156
160157## Gtk2
161158
162159In 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.
163160
164161## Qt
165162
166163Write me.
167164
168165## Windows
169166
170-In Windows 7 you can switch in TMemo, TEdit, TComboBox the base direction with Left-<span class="kbd">Ctrl</span>+Right-<span class="kbd">Shift</span> to RTL (right to left) and Right-<span class="kbd">Ctrl</span>+Left-<span class="kbd">Shift</span> to LTR (left to right). This also works in the IDE for most things, like in the Property Editor and the Strings Editor Dialog.
167+In 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.
171168
172169# References
173170
174171- [Unicode Bidirectional Algorithm](http://www.unicode.org/reports/tr9/)
175172- [Design and Implementation of a Win32 Text Editor](http://www.catch22.net/book/export/html/14)
176173
177174---
178175*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).*
179176Category: LCL
180177Category: Lazarus
181178Category: Lazarus internals
182179Category: Localization

Back to history