Recent

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

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Help with MSWindows and RightToLeft Images
« on: March 07, 2013, 01:51:15 pm »
I am hoping that someone with a better understanding of WinAPI can help me solve this problem.

I use the following code to mirror TWinControls for RightToLeftLayout and it works well in most cases although there are still a few problems ('Themes' MUST be disabled for this to work):

Code: [Select]
procedure RTLCtrl(ACtrl: TObject);
{ Make TWinControl RightToLeft - MSWindows ONLY! }
begin
{$IfDef MSWindows}
  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;

The major problem is that it also mirrors the image on controls like TSpeedButton.

I have read the information at http://msdn.microsoft.com/en-us/goglobal/bb688119.aspx#EDC and tried to find a way to overcome this, but so far I have failed.

If anyone could help me with this I would really appreciate it.

Edit:  The specific part of the whitepaper I am trying to acheive is "SetLayout(hdc, LAYOUT_RTL | LAYOUT_BITMAPORIENTATIONPRESERVED);"
« Last Edit: March 07, 2013, 02:11:26 pm by Avishai »
Lazarus Trunk / fpc 2.6.2 / Win32

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Help with MSWindows and RightToLeft Images
« Reply #1 on: March 08, 2013, 01:45:13 pm »
LAYOUT_BITMAPORIENTATIONPRESERVED: Disables mirroring of bitmaps that are drawn by META_BITBLT and META_STRETCHBLT operations, when the layout is right-to-left.

Are you sure that TSpeedButton draws image by one of this methods? And why shouldn't it get mirrored at all?
Lazarus 1.7 (SVN) FPC 3.0.0

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #2 on: March 08, 2013, 02:08:40 pm »
I was only using TSpeedButton as an example.  But I think you can see the problem in the attachment.  It is using a TImage, but I have the same problem with TSpeedButton or any control.  Anyway from what I have been reading on MS whitepapers, I should be able to control mirroring of images on any control.
Lazarus Trunk / fpc 2.6.2 / Win32

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Help with MSWindows and RightToLeft Images
« Reply #3 on: March 08, 2013, 10:22:42 pm »
I should be able to control mirroring of images on any control.
You want to mirror the image? An example: Undo is usually represented by a leftward arrow and Redo by an arrow to the right. Undo's position is left of Redo. Wouldn't it be strange to have images flipped?
Of course the icon should be aligned right to the text. But if the image needs to be adjusted too, I would recommend to use a appropriate, perhaps localized icon set.

Sorry that I challenge your task only. I'm using Linux so I have no idea what to do for Windows.
Lazarus 1.7 (SVN) FPC 3.0.0

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #4 on: March 08, 2013, 11:05:42 pm »
Ocye, thanks for your response. Making things RightToLeft in an environment that isn't yet prepared for it can be challenging.  But I'm hoping to help Lazarus become as good at RightToLeft as it is at LeftToRight.  It's going to take a lot of work, especially on MSWindows because the specifications are demanding.  The Form and all controls must work from Right To Left and mirroring manages most of this but when it comes to images, each image must be controlled separately.  The best approach may be with 'Tag' for the moment until a fully developed approach is in place.  But if I can't control which images are mirrored and which are not then I can't have a truly RightToLeft application.  Just a confusing mix.  This is a TBitBtn that has been mirrored. 
« Last Edit: March 10, 2013, 04:06:00 am by Avishai »
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 #5 on: March 09, 2013, 07:36:47 am »
The Form and all controls must work from Right To Left and mirroring manages most of this but when it comes to images, each image must be controlled separately.  The best approach may be with 'Tag' for the moment until a fully developed approach is in place.  But if I can't control which images are mirrored and which are not then I can't have a truly RightToLeft application.
Rather than using tag and having to adapt that, perhaps getting a patch in for the Lazarus .lfm format for a visual component/image property of something like MirrorRTL would be a good idea?
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 #6 on: March 10, 2013, 01:56:59 pm »
Thank BigChimp.  What I hope to do is formulate a somewhat complete concept that addresses all of the major issues of LeftToRight <> RightToLeft and then present it to Lazarus.  But your suggestion will definitely be part of it.  The Lazarus Development Team can then refine the concept or replace it with one they think will work out better.  So far I'm still in the experimental stage trying to identify some of the more subtle issues.
« Last Edit: March 10, 2013, 03:43:59 pm by Avishai »
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 #7 on: March 10, 2013, 02:25:36 pm »
Thanks Avishai - that makes sense!
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

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Help with MSWindows and RightToLeft Images
« Reply #8 on: March 11, 2013, 12:08:20 pm »
Now I understand. And we are in line: Thou shall not manipulate icons!

LCL uses MaskBlt for message dialog icons, as far as I see. According to MSDN's globalization page is "...another way to prevent a bitmap from being mirrored ... to define NOMIR-RORBITMAP in calls to BitBlt and StretchBlt." What happens if you hack TPromptDialog.Paint() at promptdialog.inc with something like MaskBlt(..., NOMIRRORBITMAP);?
Lazarus 1.7 (SVN) FPC 3.0.0

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #9 on: March 11, 2013, 06:26:39 pm »
I'm in way over my head on this issue :(  I've been looking for days and I'm no closer than I was a week ago.  NOMIRRORBITMAP seems to be what I need, but I can't figure out how to use it. %)
Lazarus Trunk / fpc 2.6.2 / Win32

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Help with MSWindows and RightToLeft Images
« Reply #10 on: March 12, 2013, 01:50:57 pm »
NOMIRRORBITMAP seems to be what I need, but I can't figure out how to use it. %)
Search for the LCL source file promptdialog.inc. At this file, find the procedure Paint() and edit the line with MaskBlt(). Rebuild all and keep fingers crossed  8)
Lazarus 1.7 (SVN) FPC 3.0.0

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #11 on: March 12, 2013, 04:00:33 pm »
Thanks Ocye,  I tried that and got compile errors.  I had to add "Windows, Win32Extra" to the uses statement of Dialogs.pas and that caused other errors.
Lazarus Trunk / fpc 2.6.2 / Win32

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #12 on: March 13, 2013, 11:01:40 pm »
Well, I finally got it to compile, but I can't see any change.  I also just noticed that if I set TForm.BorderStyle := bsDialog and BorderIcons.biHelp := True, the "?" is mirrored :(  It's getting harder instead of easier.  One step forward - ten steps backward.  If I can't solve this problem, I'm really stuck.
Lazarus Trunk / fpc 2.6.2 / Win32

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Help with MSWindows and RightToLeft Images
« Reply #13 on: March 14, 2013, 09:41:06 am »
So take a step back: What's wrong with BiDiMode?
Lazarus 1.7 (SVN) FPC 3.0.0

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Help with MSWindows and RightToLeft Images
« Reply #14 on: April 04, 2013, 05:20:21 pm »
Sorry I haven't answered before, but I was in the US for my son's wedding :) 

Anyway, to answer your question about BiDiMode, there are too many components that it does not mirror.  TForm is not mirrored for one.  Also TPageControl and a lot of others.  Trying to use BiDiMode, you end up with a salad of RightToLeft and LeftToRight.  It's confusing and very amateurish.  No RightToLeft person would accept it. 

I've spoken to other Israelis about it and they tell me that they took a look at Lazarus and then moved on to something that can handle true RightToLeft, mostly MS Visual Studio.  I'm sure that's just as true in the Arab world as well.  I can't blame them with the current state of Lazarus and RightToLeft, but Lazarus is losing in the RightToLeft world.   That world includes billions of people.

If MS Visual Studio (and others) can handle RightToLeft and Lazarus can not, then Lazarus is not even in the race.
Lazarus Trunk / fpc 2.6.2 / Win32

 

TinyPortal © 2005-2018