Page 1 of 1

Right-To-Left Languages Window and Gadgets Support!

Posted: Tue May 16, 2006 2:30 pm
by Pantcho!!
Code updated for 5.20+

I've been searching for such of this functions to make a local programs with PB in my language which is hebrew.
There are other Right to left languages such as arabic.

So i just had to post this in case another PB user search for this method. :P

Big thanks to thefool and va!n :wink:


*edit: thanks nco2k*

Code: Select all

;========================================
;Right-To-Left Window, Menus and gadgets!
;Enable you to localize your apps in PB!
;========================================
;By Pantcho 2006
;Big thanks for thefool !!
;MessageBox RTL constants by va!n
;A little event loop grabbed from PB examples ;)

;===============================
;RTL msg box constants
#MB_RIGHT      = $80000
#MB_RTLREADING = $100000


Procedure RTLwindow(WinNum, Switch)
  If Switch = 1
    SetWindowLong_(WindowID(WinNum),#GWL_EXSTYLE,#WS_EX_LAYOUTRTL | 0)
  ElseIf Switch = 0
    SetWindowLong_(WindowID(WinNum),#GWL_EXSTYLE,0)
  EndIf
  ; Window Refresh Is Required
  SetWindowPos_(WindowID(WinNum), 0, -1 , -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE | #SWP_NOZORDER  | #SWP_FRAMECHANGED | #SWP_SHOWWINDOW)
EndProcedure

Procedure RTLgadget(GadgetNum, Switch)
  If Switch = 1
    SetWindowLong_(GadgetID(GadgetNum),#GWL_EXSTYLE,#WS_EX_LAYOUTRTL | 0)
  ElseIf Switch = 0
    SetWindowLong_(GadgetID(GadgetNum),#GWL_EXSTYLE,0)
  EndIf
EndProcedure

If OpenWindow(0, 0, 0 ,200, 200, "RTL window Title", #PB_Window_ScreenCentered|#PB_Window_SystemMenu )

  If CreateMenu(0, WindowID(0))
    MenuTitle("File")
      MenuItem( 1, "&Load...")
      MenuItem( 2, "Save")
      MenuItem( 3, "Save As...")
      MenuBar()
      OpenSubMenu("Recents")
        MenuItem( 5, "C:\Autoexec.bat")
        MenuItem( 6, "D:\Test.txt")
        OpenSubMenu("Even more !")
          MenuItem( 12, "Test")
        CloseSubMenu()
        MenuItem( 13, "C:\Ok.bat")
      CloseSubMenu()
      MenuBar()
      MenuItem( 7, "&Quit")

    MenuTitle("Edition")
      MenuItem( 8, "Cut")
      MenuItem( 9, "Copy")
      MenuItem(10, "Paste")
     
    MenuTitle("?")
      MenuItem(11, "About")
  EndIf
  DisableMenuItem(0, 3, 1)
  DisableMenuItem(0, 13, 1)
  ButtonGadget(1,10,30,80,20,"RTL")
  ButtonGadget(2,10,60,80,20,"LRT - normal")
  ListViewGadget(3,100,30,90,120)
  For x = 1 To 30
    AddGadgetItem(3,-1,"Text "+ Str(X))
  Next x
 
 
  Repeat

    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        If EventGadget() = 1
          RTLwindow(0,1)
          RTLgadget(3,1)
        ElseIf EventGadget() = 2
          RTLwindow(0,0)
          RTLgadget(3,0)
        EndIf
   

      Case #PB_Event_Menu

        Select EventMenu()

          Case 11 
            MessageRequester("About", "Cool RTL MessageBox!", #MB_RIGHT|#MB_RTLREADING )
           
          Default
            MessageRequester("Info", "MenuItem: "+Str(EventMenu()), #MB_RIGHT|#MB_RTLREADING )

        EndSelect

      Case #PB_Event_CloseWindow
        Quit = 1

    EndSelect

  Until Quit = 1

EndIf

End  

Posted: Tue May 16, 2006 2:37 pm
by josku_x
I have read the message where thefool introduced the very simple method of using Right-To-Left reading order with your gadgets. I think there should be a cross-platform constant in PB that lets you use either RTL or LTR with your gadgets. (#PB_Gadget_RightToLeft, #PB_Gadget_LeftToRight)

Maybe you should post a request for that in the Feature requests forum-

BTW: I'm arabic :wink:

Re: Right-To-Left Languages Window and Gadgets Support!

Posted: Tue May 16, 2006 3:21 pm
by thefool
Pantcho!! wrote: Big thanks to thefool
No problem. Now i have an idea for next years 1st April joke (turning all windows right to left hehe)

Posted: Tue May 16, 2006 3:34 pm
by josku_x
That would be easy to do!

First you call EnumWindows_() and in its callback you call EnumChildWindows_() for each found window handle, set the child windows to RTL and you get some MAD mails :wink:

Posted: Tue May 16, 2006 3:35 pm
by thefool
Yup :D
well.. admit it, it could be quite funny!

Posted: Tue May 16, 2006 3:53 pm
by josku_x
Then you reply to the mails telling that they have to pay you to get a fix for the *problem*.. You could get rich :lol:

Posted: Tue May 16, 2006 4:08 pm
by thefool
yup :D

Posted: Tue May 16, 2006 5:26 pm
by va!n
hehe.... nice example... i totally forgot to use "SetWindowLong_" for solving your problem... i thought about how to do it and that it may not be possible with SendMessage_ only... now i got it back ^^

Btw, one thing would be very interested for me... if people wanting to write software for your region, would it be ok when the text is in english and the alignments from right to left like in your example? If so, does the text "Open File" must be for example "Open File ..." or "... eliF nepO" or "... File Open" ?

اشكركم جزيل الشكر علي مساعدتي علي فهم و :wink:

Posted: Tue May 16, 2006 10:07 pm
by Pantcho!!
Hey josku_x, salam alaeykom ;)

Va!n i know hebrew, not arabic ;)

Posted: Tue May 16, 2006 10:17 pm
by josku_x
اشكركم جزيل الشكر علي مساعدتي علي فهم و
:lol:
Are you arabic?

EDIT: va!n: If the text is english, it's only aligned to the right, but it won't be modified. So don't worry of an arabic PB editor with the command ()wodniWnepO :wink:

Posted: Tue May 16, 2006 11:40 pm
by Dare2
lol <- !desrever ro tfeL oT thgiR -> lol

But (as mentioned elsewhere) - thanks for this!

Posted: Wed May 17, 2006 3:14 am
by nco2k
bug in line 23:

Code: Select all

SetWindowPos_(Hwnd, 0, -1 , -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE | #SWP_NOZORDER  | #SWP_FRAMECHANGED | #SWP_SHOWWINDOW)
Hwnd should be WindowID(WinNum):

Code: Select all

SetWindowPos_(WindowID(WinNum), 0, -1 , -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE | #SWP_NOZORDER  | #SWP_FRAMECHANGED | #SWP_SHOWWINDOW)
and there is also no real need for #SWP_SHOWWINDOW.

c ya,
nco2k

Posted: Wed May 17, 2006 7:53 am
by Rings
thx for sharing, nice tip to support more than 1 language and align .