Recent

Author Topic: Make TForm RightToLeft  (Read 11857 times)

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Make TForm RightToLeft
« on: March 05, 2011, 01:36:48 pm »
Hello,
I'm trying to make a Form that is a true RightToLeft Form.  I have the following code that only works up to a point.  It does mirror the Form, but for some reason the Form Client area is Black and I can't change it.  Also the Form Caption ends up on the Left side when it should be on the Right.  The only "solution" I have found so far is to put a TPanel on the Form and set it's Align property to alClient and make it the Parent of all other controls.  That "fixes" the color problem, but it doesn't help with the Form Caption alignment.  If anyone can help with these two points, I would be very much appreciative.

procedure TForm1.FormCreate(Sender: TObject);
{Make Form RightToLeft}
const
  Frm_FIRST = $1000;
  Frm_GETHEADER = Frm_FIRST + 31;
var
  header: thandle;
begin
  header:= SendMessage (Form1.Handle, Frm_GETHEADER, 0, 0);
  SetWindowLong (header, GWL_EXSTYLE,
                 GetWindowLong (header, GWL_EXSTYLE)  or
                 WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);

  SetWindowLong (Form1.Handle, GWL_EXSTYLE,
                 GetWindowLong (Form1.Handle, GWL_EXSTYLE)  or
                 WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);
  Form1.invalidate;
end;

initialization
  with Application do begin
    NonBiDiKeyboard:= SysLocale.DefaultLCID;
    BiDiKeyboard:= LangHeb;
    SysLocale.MiddleEast := True;
    BiDiMode := bdRightToLeft;
    ActivateKeyboardLayout(LangDef, 0);
  end;
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Make TForm RightToLeft
« Reply #1 on: March 05, 2011, 01:46:29 pm »
I found a solution to the Form Caption Alignment.  Setting the Form BiDMode to bdLeftToRight and the Panel BiDiMode to RightToLeft takes care of that problem.  It's just a workaround and not a true solution, but it's working.
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Make TForm RightToLeft
« Reply #2 on: March 05, 2011, 02:55:27 pm »
This seems to be better code, but it gives the same results.

procedure TForm1.FormCreate(Sender: TObject);
var
  Params: TCreateParams;
begin
  CreateParams(Params);
end;

procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.ExStyle :=
    WS_EX_LEFT or WS_EX_RTLREADING or WS_EX_LEFTSCROLLBAR or WS_EX_LAYOUT_RTL;
end;
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Make TForm RightToLeft
« Reply #3 on: March 05, 2011, 07:52:23 pm »
OK, I'm down to this, but I still have the problem of the unchangeable BLACK Client Area of the Form.  I've tried everything I can think of.  I have a suspicion that it's the line Frm_GETHEADER = $101F;  But I don't even have a clue of what to change it to;

procedure TForm1.MakeFormRightToLeft(Sender: TObject);
{Make Form RightToLeft}
const
  Frm_GETHEADER = $101F;
var
  Header: Thandle;
begin
  with Sender as TForm do begin
    Header:= SendMessage (Handle, Frm_GETHEADER, 0, 0);
     SetWindowLong (Header, GWL_EXSTYLE,
          GetWindowLong (Header, GWL_EXSTYLE) or
          WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);

     SetWindowLong (Handle, GWL_EXSTYLE,
          GetWindowLong (Handle, GWL_EXSTYLE) or
          WS_EX_LAYOUTRTL or WS_EX_NOINHERITLAYOUT);
     invalidate;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  MakeFormRightToLeft(Sender);
end;
Lazarus Trunk / fpc 2.6.2 / Win32

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
Re: Make TForm RightToLeft
« Reply #4 on: March 08, 2011, 11:24:26 am »
Hi,
first WS_EX_LAYOUTRTL not supported with all platforms, and it is also bad idea even in Windows, Microsoft made it in win98 to quick solve some problem with RTL but it is not used by its application like Office.
WS_EX_LAYOUTRTL have some bugs with some components like TreeView, ListView and PageControls

So we do not use WS_EX_LAYOUTRTL please.

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Make TForm RightToLeft
« Reply #5 on: March 08, 2011, 11:36:47 am »
Thanks for the information and taking the time to respond.  However I still need to mirror the Form and my client only uses Window platforms.  If you can suggest a better or cleaner way to do this, I would truly like to hear it.  It would be great if my program could be cross-platform.

On another note, I want to thank all of the members and developers with Lazarus.  This is an inspiring group of people.  I wish I could help, but I have neither the time not the skills.  All of you are amazing. :D
Lazarus Trunk / fpc 2.6.2 / Win32

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
Re: Make TForm RightToLeft
« Reply #6 on: March 08, 2011, 02:30:19 pm »
Can you make screenshot to show you problem before and after resolve it.

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Make TForm RightToLeft
« Reply #7 on: March 08, 2011, 02:51:41 pm »
You will notice that the Form is Mirrored with Close, Maximize and Minimize buttons of the Left and the Icon and Caption on the Right.  I have yet to find a "proper" way to change the black client area to any other color. This is an "after shot" only.  The "before shot" looks like any blank Lazarus Form before doing anything to it.
Lazarus Trunk / fpc 2.6.2 / Win32

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
Re: Make TForm RightToLeft
« Reply #8 on: March 08, 2011, 04:31:41 pm »
Hmm, only the caption bar, I will try to make it in the Win32 wedgetset for the forms only that have Application.BidiMode = bdRightToLeft.

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Make TForm RightToLeft
« Reply #9 on: March 08, 2011, 04:37:27 pm »
This is only a quick thought and I haven't thought it through, but a program might have both RightToLeft and LeftToRight Forms.  It would be nice if the TForm BiDiMode was the one that determined the Caption Bar.
Lazarus Trunk / fpc 2.6.2 / Win32

Zaher

  • Hero Member
  • *****
  • Posts: 683
    • parmaja.org
Re: Make TForm RightToLeft
« Reply #10 on: March 08, 2011, 04:48:53 pm »
Ok, First i will try to add it.
But for me i dislike make Caption bar drawing RTL, my windows is LTR and i like make X button always in the right for all application, maybe make it as option for the developer.

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Make TForm RightToLeft
« Reply #11 on: March 08, 2011, 04:53:57 pm »
Thank you Zaher for taking the time to look at this.  If it was my choice, I wouldn't care much.  But clients have their minds set and there isn't much I can do about that.
Lazarus Trunk / fpc 2.6.2 / Win32

 

TinyPortal © 2005-2018