Difference between revisions of "BidiMode"

From Free Pascal wiki
Jump to navigationJump to search
Line 66: Line 66:
 
   TApplication
 
   TApplication
  
TApplication must also have a BidiMode property because it a parent for all Forms, and i plan to make new property "AutoFlipControl",  
+
TApplication must also have a BidiMode property because it is a parent for all Forms, and i plan to make new property "AutoFlipControls",  
  
   AutoFlipControl:Boolean;
+
   AutoFlipControls:Boolean;
  
When Application.AutoFlipControl is True and change the Application.BidiMode value Application object send to all form to FlipControls.
+
When Application.AutoFlipControls is True and change the Application.BidiMode value Application object send to all form to FlipControls.
it is usefull when changing the language from "Left To Right" language like as English to Arabic and vise versa.
+
it is useful when changing the language from "Left To Right" language like as English to Arabic and vise versa.
  
 
===Phase 3: Canvas and Graphic===
 
===Phase 3: Canvas and Graphic===

Revision as of 23:53, 8 June 2007

There is a languages like as (Arabic, Hebrew, Farsi ...) reading the words from right to left, and also the open the books from the right.

Not just reading the words, it is every thing depend on the order (positions), for application there is a Menus and Controls that placed on the form it must have position from the right.

TODO:picture of sample to compare

Add BidiMode or RightToLeft support to LCL components

Most of OS now support RightToLeft but there is controls not supported yet or there is controls make by native language like as (TLabel, TGrid). so we have 3 kinds of control

  1. Standard Controls: it easy to make it just add some flag to switch it to RightToLeft (TEdit, TList, TComboBox, TCheckBox).
  2. Standard Controls not supported in OS: There is no idea just waiting the OS developers to implement it to support (TListView, TTreeView), or use native controls already support it.
  3. Native Controls: more hard work for make it Support RightToLeft, or we must add new control already have this features (TLabel, TGrid).

Make application Right to Left order have 4 phases

Phase 1: Add BidiMode property to TControl

TBidiMode already declaired in Classes

 property BiDiMode: TBiDiMode read FBiDiMode write SetBiDiMode stored IsBiDiModeStored;
 property ParentBiDiMode: Boolean read FParentBiDiMode write SetParentBiDiMode default True;

BidiMode must not stored if ParentBidiMode = True

 function TControl.IsBiDiModeStored: Boolean;
 begin
   Result := not ParentBiDiMode;
 end;

Add virtual functions

 function IsRightToLeft:Boolean; virtual;
 function UseRightToLeftAlignment: Boolean; virtual;
 function UseRightToLeftReading: Boolean; virtual;
 function UseRightToLeftScrollBar: Boolean; virtual;
 BiDiMode property in public and must published in every control need to RightToLeft

In delphi there is UseRightToLeftAlignment and UseRightToLeftReading and UseRightToLeftScrollBar but there is a Alignment property in TLabel, TEdit not have but we can implement an Alignment for it, so i will not use this technique for now.

Phase 2: Modify Standard controls that supported by OS

Add RightToLeft to Standard controls,

done here for Win32

 TForm {done}
 TButton {done}
 TEdit {done}
 TListBox {done}
 TComboBox {done}
 TCheckBox {done}
 TStaticText {done}
 TGroupBox {done}
 TRadioButton {done} (in Win32 need RecreateWnd in SetBidiMode)
 TRadioGroup {when write FlipControl function with be done}
 TCheckGroup 
 TScrollbar {not supported by Win32} Delphi emulate it by change the position with virtual position.
 TMenu/TMenuItem {done}
   there is a bug in windows

With Menus in Lazarus Win32 the developers force to make it OWNERDRAW, We want to modify DrawMenuItem functions {done}.

 TApplication

TApplication must also have a BidiMode property because it is a parent for all Forms, and i plan to make new property "AutoFlipControls",

 AutoFlipControls:Boolean;

When Application.AutoFlipControls is True and change the Application.BidiMode value Application object send to all form to FlipControls. it is useful when changing the language from "Left To Right" language like as English to Arabic and vise versa.

Phase 3: Canvas and Graphic

Native controls use a Canvas to draw it self, small control use TextOut, but the big one must redraw it from the Right.

TODO: add image for right to left Grid.

 TLabel {done}
 TGrid {oh my god}

Before make TLabel work RightToLeft we must add to Canvas.TextStyle a new property "RightToLeft", TextOut and TextRect functions will use this property.

Delphi use CanvasOrientation for mirror the control and maked RightToLeft, i hate use this because it flip the shadow and images (like as the Check) it is make the control ugly.

 For now TGrid can wait.

Phase 4: Functions and Utils useful for multi language application

Like as

 FlipControls; virtual;
 Change Right to Left and Left to Right in this properties (Left, Align, Anchors and Alignment)
 if We compare with Delphi(TM) Anchors and Alignment was excepted
 Detect language is RightToLeft from current language

How to test RightToLeft reading

Create new form, then add TButton or TEdit set the caption to OK? you must add ? or ! or . to the last word with out space, now set the BidiMode to bdRightToLeft, you will see the ? in the left of word.