Right-To-Left Languages Window and Gadgets Support!

Share your advanced PureBasic knowledge/code with the community.
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Right-To-Left Languages Window and Gadgets Support!

Post 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  
Last edited by Pantcho!! on Wed May 17, 2006 7:19 am, edited 2 times in total.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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:
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

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

Post 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)
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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:
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

Yup :D
well.. admit it, it could be quite funny!
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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:
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

yup :D
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post 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:
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Post by Pantcho!! »

Hey josku_x, salam alaeykom ;)

Va!n i know hebrew, not arabic ;)
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post 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:
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

lol <- !desrever ro tfeL oT thgiR -> lol

But (as mentioned elsewhere) - thanks for this!
@}--`--,-- A rose by any other name ..
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post 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
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

thx for sharing, nice tip to support more than 1 language and align .
SPAMINATOR NR.1
Post Reply