Recent

Author Topic: Help with MSWindows and RightToLeft Images  (Read 21733 times)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Help with MSWindows and RightToLeft Images
« Reply #30 on: April 09, 2013, 02:51:35 pm »
Further to Juha's point: as I think I said before, MonoDevelop on Linux is the IDE for Mono (the cross platform open source .Net implementation)...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #31 on: April 09, 2013, 04:59:29 pm »
Thanks JuhaManninen, I really value your input.  It makes me rethink some things.

I will try to explain about RightToLeftLayout VS. BiDiMode, but I am not an expert so I may not have the full picture. 

BiDiMode implements RightToLeft for Text ONLY.  That is it supports R2L languages.  But it has no effect beyond that.

RightToLeftLayout only effects TWinControls (that is you can only call it for TWinControls, but anything that is painted on it's canvas is mirrored).  RightToLeftLayout changes the origin and direct of the canvas + implements RightToLeft for Text.  In Lazarus, for LeftToRight, the origen is at Top-Left (X=0, Y=0) and X increases to the Right.  RightToLeftLayout reverses the canvas making (X=0, Y=0) at the Top-Right and increases to the Left.  The result is that if TLabel.Left:= 10, it would be 10 from the right.  So anything painted on the canvas is painted R2L and requires no code changes.  It is also anchored akLeft, which is now the Right side of the Form.  ScrollBars are made R2L as well.  The TWinControl becomes a true R2L control in all respects.  When I use RightToLeftLayout, I leave BiDiMode:= bdLeftToRight.  You must call RightToLeftLayout for each TWinControl, but that's a simple loop if the entire Form is R2L.

Quote
The right design is to build RightToLeft support into LCL layout engine, as I explained earlier.

I'm only guessing now, but I think it might take a lot of unnecessary code to fix R2L for controls like TPageControl, but RightToLeftLayout does it with only a few lines of code.  I'm basing this on what I THINK had to be done to TStringGrid to get it to support R2L.  But when I use RightToLeftLayout TStringGrid works almost perfectly.  I say almost because the in-place editor stays L2R.  I haven't even tried to find out where to fix that yet.  Too many other things to look at first.

Quote
Now, studying Lazarus code, BiDiMode already has lots of support.
Look for method "SetBiDiMode". It is implemented for many widgetsets, for example for TWin32WSWinControl in Windows:

I have looked at this code.  It is using WINAPI calls.

Quote
It clearly does the same what your global function does and more.
You wrote that BiDiMode is not for the same purpose as RightToLeftLayout. I am still saying that they are for the same purpose but BiDiMode is poorly implemented.

BiDiMode does less.  It does not reverse the canvas.  That means that you have to reverse the logic for painting, such as TBarChart (I think that woud require a fair amount of code).  Changing the functionality of BiDiMode would break Delphi compatibility and I think there would be some screaming.  If you have a multilingual Form then using BiDiMode as it is now might be the best solution.  Right now I use TApplication.BiDiMode as a trigger but it could easily be TApplication.RightToLeftLayout.  But with the Lazarus code modifications that I have made, TApplication.BiDiMode:= bdRightToLeft results in all Forms in the app. being mirrored with no additional code.  Sometimes that doesn't work out too well because as it is now, that means I can't use standard Lazarus Dialog boxes and have to create my own (a lot of additional code.  But I have to do it anyway because I have to change the language of the Text and in some cases, the layout).

I have spent countless hours combing through Lazarus code trying to find ways to patch it, but there is a TON of code!  I have very good documentation of any changes I have made.  And yes, I have made changes and then found others ways to accomplish my goals without modifying Lazarus.  Most of my changes should be made to Lazarus directly but they can't be made until the very major problem with Themes is found and fixed.  And that problem is way beyond my ability.

Quote
Earlier I understood it created a problem by flipping images (?)

Yes, images are a problem that I still have not found a solution for but MS says the solution is there, I just haven't figured out how to do it.

As for .NET, I have successfully ignored it this long and I like it that way.  I could say more but I think I'll keep my mouth shut.

I will continue with my experiments and hopefully find more solutions.  Reporting to Mantis has been disappointing.  At times it seems that there isn't a lot of interest in R2L.  And now I can't even get in to Lazarus on my Hebrew login, only my English login (which I reported to Mantis a while back), so testing is limited.  I need to ensure that what works in English login also works in Hebrew login.


« Last Edit: April 09, 2013, 05:14:27 pm by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4715
  • I like bugs.
Re: Help with MSWindows and RightToLeft Images
« Reply #32 on: April 09, 2013, 06:29:15 pm »
Ok, interesting.
I start to understand slowly that the Windows system setting for RightToLeftLayout does not automatically do anything to traditional WinAPI applications or their GUI controls.
For .NET apps it may do things automatically but it is irrelevent here.
Mono is not interesting here either because it is not truly cross-platform for GUI apps and it may not implement all the features that .NET does.

Quote
If you have a multilingual Form then using BiDiMode as it is now might be the best solution.

Ok, the current BiDiMode behavior is needed in some situatios.

For your new experiments:
When you flip the whole canvas, not only glyph images get mirrored but also all canvas drawing commands (lines, circles etc.) draw a mirrored picture.
Is that desired?
If not then flipping the canvas is not a good idea and RightToLeft must be done the hard way.
Maybe somebody can test with a Visual Studio app with RightToLeft settings.
If flipping the canvas is the right choice then a cross-platform solution must be designed. It would be OK to implement only Windows support initially though.

The person implementing it must know RightToLeft requirements and a language, but also LCL internals.
I guess there is no such person and thus you have not got much help.

Quote
I have looked at this code.  It is using WINAPI calls.

Yes, it is part of widgetset bindings for Windows.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #33 on: April 09, 2013, 07:02:47 pm »
Quote
When you flip the whole canvas, not only glyph images get mirrored but also all canvas drawing commands (lines, circles etc.) draw a mirrored picture.
Is that desired?

It depends on the image.  Sometime you need to mirror the image and sometimes not.  If it draws Text backward then, no it's not desired.  But if for example it displays an arrow point to the Left (Back Arrow) for L2R then yes it should mirror the arrow.  TPanel Shadows should be mirrored... The list is long for 'YES' and very short for 'NO'.  That's the reason for my original post.  MS says that there is a way to control it individually, but I can't figure out how to do it.

Quote
The person implementing it must know RightToLeft requirements and a language, but also LCL internals.
I guess there is no such person and thus you have not got much help.

I totally agree.  And I understand why I haven't gotten a huge amount of help.  I would be of no help at all for Far Eastern languages.  I no nothing about them.  I wish I could get the Technion (Israeli technical universary) interested in Lazarus, but I have no contacts there.
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #34 on: April 14, 2013, 12:28:52 pm »
I just had a chance to look at Delphi 10.  I didn't have much time, but I was able to check a couple of things.

1. Delphi doesn't have the problem with Themes and RightToLeftLayout.

2. Delphi glyphs work fine with RightToLeftLayout in Menus and SpeedButtons, unlike Lazarus.  But they are still mirrored.

I don't know what they're doing, but at least for these 2 issues, they're doing something right. 

But as far as my original post, Delphi has the same issue with mirrored images.  By the way, that includes the Lazarus splash screen on a Hebrew locale.  The splash screen is mirrored, including backward text.  It looks very amateurish.

Edit:  I just tried something to see what would happen.  I set the TForm Icon to a direction sensitive image on a RightToLeftLayout Lazarus form.  The icon was NOT mirrored.  That tells me that it can be controlled, but I can't figure out how to do it.
« Last Edit: April 14, 2013, 12:45:22 pm by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #35 on: April 15, 2013, 03:04:39 pm »
This code creates a RightToLeft TStringGrid for MSWindows ONLY.  Leave BiDiMode:= bdLeftToRight:

Code: [Select]
uses Windows;

procedure RTLCtrl(ACtrl: TObject);
{ Make TWinControl RightToLeft - MSWindows ONLY! }
const
  RightToLeftLayout = $400000;
  NoInheritLayout = $00100000;
begin
{$IfDef Windows}
  if ACtrl is TWinControl then
    with TWinControl(ACtrl) do begin
      SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE)
        or RightToLeftLayout or NoInheritLayout);
  end;
{$EndIf}
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.BidiMode:= bdRightToLeft;
  if Application.IsRightToLeft then begin
    RtlCtrl(Form1);
    RtlCtrl(StringGrid1);
  end;
end;

procedure TForm1.StringGrid1GetEditText(Sender: TObject; ACol, ARow: Integer;
  var Value: string);
begin
  if Application.IsRightToLeft then
    StringGrid1.InplaceEditor.BiDiMode:= bdRightToLeft;
  //I don't like this but I haven't found another way yet.
end;

procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
// Reverse Right and Left Arrow Keys
begin
  if Application.IsRightToLeft then begin
    case Key of
      VK_Left: Key:= VK_Right;
      VK_Right: Key:= VK_Left;
    end;
  end;
end;

I've read the code implementing BiDiMode and it is significant.  I think Mr. Reyes is the maintainer of TStringGrid and I know that he could do a much better job of coding than I have.  It would be interesting to see what he could do with RightToLeftLayout.
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #36 on: April 20, 2013, 06:54:00 am »
I've been playing around with MS Visual Studio Express just to see what it takes to create a RightToLeft App.  It's absurdly easy.  This is what Lazarus should be like for RightToLeft.

All I had to do was set Form.RightToLeft = Yes and Form.RightToLeftLayou = True and in Design-Time, the Form was mirrored.  After that, it was exactly like designing a LeftToRight Form except you worked from the Right Edge instead of the Left Edge.  Coordinates and Anchors were also from the Right.

In my opinion, Lazarus needs a RightToLeft person on the development team.  If Lazarus was as good at RightToLeft as Visual Studio, I think it would completely dominate in the RightToLeft World.

Edit:  I just checked and Images are NOT mirrored in Visual Studio.
« Last Edit: April 20, 2013, 07:09:45 am by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Help with MSWindows and RightToLeft Images
« Reply #37 on: April 20, 2013, 08:05:46 am »
just to make things a bit more clear on the RTL front I have found this on MSDN I do not know if any of you have read it http://msdn.microsoft.com/en-us/goglobal/bb688119.aspx. The support for RTL in win api is there but it requires special handling for custom drawn controls (as expected), those controls include any TGraphicControl descendant in lcl including TSpeedbutton, TImage etc.
I assume that the problem with the editors appearing in the wrong position in TStringGrid comes from the fact that lcl does not support the windows world coordination system and fights against it. I haven't looked in to the problem to make sure or to find a way to bypass it,  it might be as easy as overriding a method or simple writing an event to take the existing coordinates and convert them to rtl.
In any case in your position I would define and use the setlayout calls instead of setwindowlong.
« Last Edit: April 20, 2013, 08:07:51 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #38 on: April 20, 2013, 08:20:58 am »
Hey Taazz, it's always good to hear from you :)

I found a way to properly place the editor in TStringGrid, but the fact is that TStringGrid.BiDiMode:= bdRightToLeft works as it should so I'm not too sure it's worth tinkering with unless Lazarus takes the RightToLeftLayout approach globally.

procedure TForm1.StringGrid1GetEditText(Sender: TObject; ACol, ARow: Integer;
  var Value: string);
begin
  if Application.IsRightToLeft then
    StringGrid1.InplaceEditor.BiDiMode:= bdRightToLeft;
end;

I tried setlayout but I was never able to get it to work.  If you have some code that you would like to share I love to see it.

What I am seeing with Visual Studio is that both BiDiMode and RightToLeftLayout are needed, at least in MSWindows.  I have no idea about any other platforms.

Note to self: I REALLY don't like Visual Studio.  But to see how they do things has been illuminating.
Lazarus Trunk / fpc 2.6.2 / Win32

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Help with MSWindows and RightToLeft Images
« Reply #39 on: April 20, 2013, 09:02:55 am »
In my opinion, Lazarus needs a RightToLeft person on the development team.  If Lazarus was as good at RightToLeft as Visual Studio, I think it would completely dominate in the RightToLeft World.
I'm afraid that person needs to be you. You have the need, the experience with right to left etc. Not saying somebody might not help you (I've noticed the Laz devs are very helpful), but I think you're the one that needs to dive into how LCL works...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #40 on: April 20, 2013, 10:27:46 am »
Wow!  Thanks BigChimp, I'm really flattered :)  But I'm not the guy for such a task.  I don't have the programming skills for that.  I'm just a self taught hack.  And my familiarity with Lazarus is very superficial.  I've already done about as much as I'm capable of.  Apart from that, I know nothing about any OS other that MSWindows.
Lazarus Trunk / fpc 2.6.2 / Win32

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Help with MSWindows and RightToLeft Images
« Reply #41 on: April 20, 2013, 10:39:10 am »
I know the feeling... not that formally trained either ;) And I don't know Lazarus/LCL either, but with help of people like Juha and Mattias, I still got some patches in...

The big plus you have is that you know exactly what is needed, how other environments (VS) implement it. Even if you only implement it for Windows only, it will already help a lot of people...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #42 on: April 20, 2013, 10:54:26 am »
Presently, none of what I have done can be implemented even for MSWindows.  Not until the problem with 'Themes' is resolved.  I've spent many hours trying to find that problem and fix it, but I'm no closer now than the moment I started.  And that means I can't offer any patches.

I'm willing to share any knowledge/code I have from all of my experiments with anyone that wants it, but it all depends on disabling Themes, so it's pretty much a 'no-starter'.
Lazarus Trunk / fpc 2.6.2 / Win32

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Help with MSWindows and RightToLeft Images
« Reply #43 on: April 20, 2013, 04:38:33 pm »
I'd still put in the patches that you do have into mantis, along with the bug (no RTL support in LCL)... At least that way, the stuff is safe. Then indicate these patches depend on theme support being fixed...

But perhaps I'm simplistic.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #44 on: April 20, 2013, 05:15:04 pm »
I already have a long list of comments/code in Mantis.  But they aren't patches because it's hard to say which file they should end up in.  Also, for the most part they can't be acted on without the fix to Themes so they just sit there.
Lazarus Trunk / fpc 2.6.2 / Win32

 

TinyPortal © 2005-2018