Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-05

BidiMode improvments patch

10 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Zaher Dirkey

First, I know i touch a sensitive code but we can discuss about it.

1 - Added TVisualCompont it is between TLCLComponent and and TControl, it has a properties and methods that have visual effect but still it will use it for BidiMode and ParentBidimode
TMenu, TPopupMenu, TScreen, TTrayIcon and TPopupNotifier and any component need bidimode , TTheme and TToolbar...

Now it can detect if the Component was inherited from TVisualComponent to make loop when BidiMode changed in the form/control.

Remove duplicating of implement the same code in both TControl and TMenu and every TComponent need the BidiMode.

I kept UseRightToLeftScrollBar in TControl

TApplicationProperties must *not* inherit it from TVisualComponent it is like TApplication have no ParentBidiMode

Fix: TLabel alignment when BidiMode = bdRightToLeft (compatible with Delphi)

2 - Add: in FlipChildren now flip the Anchors also.

3- Added: AutoFlipChildren to TApplication, now when change the BidiMode of Applcication it change the BidiMode of Forms and FlipChildren for it.

4 - I removed this code from application.inc (see below) in TApplication.Create, because :
* BidiMode of Application depend on developer choice not depend on system locale.
* What if i built an English tools/application then run it in right to left system locale, it will be launch as RightToLeft while it is not designed for that.
* If we use a multinlanguage, BidiMode changed depend on the language chosen by user, while every developer has own translation model/library not only GetText.
it make confused with BidiMode of TForm when the form has ParentBidiMode Also it force to compile GetText while i am not use GetText. --------------- this code i commented temporary
{$ifndef wince}// remove ifdef when gettext is fixed

  GetLanguageIDs(LangDefault, LangFallback);
  if LangDefault  '' then
    FBidiMode := BidiModeMap[IsRTLLang(LangDefault)]
  else
    FBidiMode := BidiModeMap[IsRTLLang(LangFallback)];
  {$else}
    FBidiMode := bdLeftToRight;
  {$endif}

--------------

If you not like TVisualCompont i can merge the code of BidiMode of it to TLCLComponent, but not all components have ParentBidiMode Like as TScreen, TApplicationProperties for example.

Zaher Dirkey -------------- next part -------------- A non-text attachment was scrubbed... Name: VisualComponent.patch Type: application/octet-stream Size: 34685 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20090525/0f9e3bb8/attachment-0001.obj>

Reply by email

Paul Ishenin
to Zaher Dirkey
Zaher Dirkey wrote 21 lines
First, I know i touch a sensitive code but we can discuss about it. 1 - Added TVisualCompont it is between TLCLComponent and and TControl, it has a properties and methods that have visual effect but still it will use it for BidiMode and ParentBidimode TMenu, TPopupMenu, TScreen, TTrayIcon and TPopupNotifier and any component need bidimode , TTheme and TToolbar... Now it can detect if the Component was inherited from TVisualComponent to make loop when BidiMode changed in the form/control. Remove duplicating of implement the same code in both TControl and TMenu and every TComponent need the BidiMode. I kept UseRightToLeftScrollBar in TControl TApplicationProperties must *not* inherit it from TVisualComponent it is like TApplication have no ParentBidiMode Fix: TLabel alignment when BidiMode = bdRightToLeft (compatible with Delphi)

I would leave class hierarchi as is. It is not a big problem to copy property BidiMode to the TMenu, TTrayIcon or anything else.

Show quoted text 6 lines
2 - Add: in FlipChildren now flip the Anchors also. 3- Added: AutoFlipChildren to TApplication, now when change the BidiMode of Applcication it change the BidiMode of Forms and FlipChildren for it.

This can Mattias review mostly.

Show quoted text 28 lines
4 - I removed this code from application.inc (see below) in TApplication.Create, because : * BidiMode of Application depend on developer choice not depend on system locale. * What if i built an English tools/application then run it in right to left system locale, it will be launch as RightToLeft while it is not designed for that. * If we use a multinlanguage, BidiMode changed depend on the language chosen by user, while every developer has own translation model/library not only GetText. it make confused with BidiMode of TForm when the form has ParentBidiMode Also it force to compile GetText while i am not use GetText. --------------- this code i commented temporary {$ifndef wince}// remove ifdef when gettext is fixed GetLanguageIDs(LangDefault, LangFallback); if LangDefault '' then FBidiMode := BidiModeMap[IsRTLLang(LangDefault)] else FBidiMode := BidiModeMap[IsRTLLang(LangFallback)]; {$else} FBidiMode := bdLeftToRight; {$endif} -------------- If you not like TVisualCompont i can merge the code of BidiMode of it to TLCLComponent, but not all components have ParentBidiMode Like as TScreen, TApplicationProperties for example.

This is ok. That code was there temporary. It waited for better solution.

Best regards,
Paul Ishenin.

Reply by email

Zaher Dirkey
to Paul Ishenin
Paul Ishenin wrote
I would leave class hierarchi as is. It is not a big problem to copy property BidiMode to the TMenu, TTrayIcon or anything else.

Not just copy the code.
When TForm or TApplication has BidiMode changed it pass to owned components to change the BidiMode

-------------------
procedure TCustomForm.BiDiModeChanged;
var
  i:Integer;
begin
  inherited;
  for i := 0 to ComponentCount - 1 do
  begin
    if (Components[i] is TVisualComponent) and not (Components[i] is
TCustomControl) then //TCustomControl already has this notification
      (Components[i] as TVisualComponent).ParentBiDiModeChanged;
  end;
end;
procedure TApplication.BidiModeChanged;
var
  i: Integer;
begin
  for i := 0 to ComponentCount -1 do
  begin
    if (Components[i] is TVisualComponent) then
    begin
      (Components[i] as TVisualComponent).ParentBidiModeChanged;
      if AutoFlipChildren and (Components[i] is TWinControl) then
        (Components[i] as TWinControl).FlipChildren(True);
    end;
  end;
end;
-------------------
And lookup to old code.
-------
procedure TCustomForm.CMBiDiModeChanged(var Message: TLMessage);
var
  i:Integer;
  lMessage:TLMessage;
begin
  inherited;
  //send CM_PARENTBIDIMODECHANGED to All Component owned by Form
{ This way is usefull for other TMenu components that need BidiMode of
form changed
  Like as TToolbar }
  lMessage.msg := CM_PARENTBIDIMODECHANGED;
  lMessage.wParam := 0;
  lMessage.lParam := 0;
  lMessage.Result := 0;
  for i := 0 to ComponentCount - 1 do
  begin
    if not (Components[i] is TCustomControl) then//TCustomControl
already has this notification
      Components[i].Dispatch(lMessage);
//the old way
//    if Components[i] is TMenu then
//      TMenu(Components[i]).ParentBiDiModeChanged;
  end;
end;
-------
And Delphi only check TMenu, that make problems when i tried to add
BidiMode to TB2K (and it is done by many hacks before years), for that
i prepare lazarus to not fall in the same hole (Arabic aphorism :) ).

Reply by email

Zaher Dirkey
to Zaher Dirkey

Hi Paul, Another idea
Make TMainMenu and most Components which inherited form TComponent take their BidiMode from the Owner, i mean MainMenu be right to left depend on BidiMode of the Form, and then i will remove the BidiMode/ParentBidiMode properties from this components.

In fact who need to make the Menu left to right while the form or the application is right to left!.

That help me to not copy that procedures/methods between components.

---------------
My progress that i work

Fix: TStaticText.Alignment to switch when bidimode changed more Delphi compatiple
Fix: ListBox, ComboBox when has owner draw, draw the text in correct alignment Add: BidiMode to TBitBtn, TSpeedBtn now it support RtlReading and the glyph switched right or left.
Add: BidiMode to TColorListBox, TColorBox

Add: TGrid partial (80%) completed

TRadioGroup and TCheckGroup done by Lazarus team ChildSizing.

Zaher Dirkey

Reply by email

Hans-Peter Diettrich
to Zaher Dirkey
Show quoted text 8 lines
Hi Paul, Another idea Make TMainMenu and most Components which inherited form TComponent take their BidiMode from the Owner, i mean MainMenu be right to left depend on BidiMode of the Form, and then i will remove the BidiMode/ParentBidiMode properties from this components. In fact who need to make the Menu left to right while the form or the application is right to left!.

IMO it doesn't matter whether the mode is stored in the control, or read from the parent. A change must trigger appropriate actions in any case.

DoDi

Reply by email

Paul Ishenin
to Zaher Dirkey: Hi Paul, Another idea Make TMainMenu and most Components which inherited form TComponent…
Zaher Dirkey wrote 7 lines
Make TMainMenu and most Components which inherited form TComponent take their BidiMode from the Owner, i mean MainMenu be right to left depend on BidiMode of the Form, and then i will remove the BidiMode/ParentBidiMode properties from this components. In fact who need to make the Menu left to right while the form or the application is right to left!.

If we do so then be sure later we'll have a bug report. I see no problem to copy parts of TControl bidi mode code to the TMenu component.

Best regards,
Paul Ishenin.

Reply by email

Zaher Dirkey
to Paul Ishenin

Hi, thanks for the replay
@Paul
If it is just TMenu i have no problem, but there are a another components (TTrayIcon, ...), and some components i have plan to create it in my job.

@Hans
The trigger will be done by dispatch message CM_PARENTBIDIMODECHANGED, but i am who prefer to call virtual methods instead of perform messages to components.

Thanks in advance.

Zaher Dirkey

Reply by email

Paul Ishenin
to Zaher Dirkey
Zaher Dirkey wrote 6 lines
Hi, thanks for the replay @Paul If it is just TMenu i have no problem, but there are a another components (TTrayIcon, ...), and some components i have plan to create it in my job.

It is not a problem to create this code for TMenu, TTrayIcon and TApplication. As I remember all others are TControl descendant.

Show quoted text 5 lines
@Hans The trigger will be done by dispatch message CM_PARENTBIDIMODECHANGED, but i am who prefer to call virtual methods instead of perform messages to components.

We can prefere anything but some third-party controls can depend on this message. Therefore I see no reason to reimplement it using virtual methods.

Best regards,
Paul Ishenin.

Reply by email

Zaher Dirkey
to Zaher Dirkey

Hi again

I have some functions used to make the controls draw Right To Left Can i put it in
1 - Controls.pas unit
2 - Make a new unit "BidiUtils.pas" and then use it in this controls units

-------
function BidiFlipAnchors(Anchors: TAnchors; Flip: Boolean): TAnchors;
function BidiFlipAlignment(Alignment: TAlignment; Flip: Boolean): TAlignment;
function BidiFlipRect(const Rect: TRect; const ParentRect: TRect;
const Flip: Boolean): TRect;
function BidiFlipPoint(P: TPoint; const ParentRect: TRect; const Flip:
Boolean): TPoint;
function BidiFlipX(X: Integer; const Width: Integer; const Flip:
Boolean): Integer;
function BidiFlipX(X: Integer; const ParentRect: TRect; const Flip:
Boolean): Integer;
-------
Zaher Dirkey

Reply by email