[V4.60]Chinese chars in stringgadget

Mac OSX specific forum
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

[V4.60]Chinese chars in stringgadget

Post by michel51 »

Hello list,

the following code is from examples and a little bit modified:

Code: Select all

URL$ = "http://www.purebasic.com"

CompilerIf #PB_Compiler_Unicode
  AsciiURL$ = Space(Len(URL$))
  PokeS(@AsciiURL$, URL$, -1, #PB_Ascii)
  URL$ = AsciiURL$
CompilerEndIf

Procedure ResizeWebWindow()
  ResizeGadget(10, #PB_Ignore, #PB_Ignore, WindowWidth(0), WindowHeight(0)-52)
  ResizeGadget(4, #PB_Ignore, #PB_Ignore, WindowWidth(0)-185, #PB_Ignore)
  ResizeGadget(5, WindowWidth(0)-25, #PB_Ignore, #PB_Ignore, #PB_Ignore)
  ResizeGadget(6, #PB_Ignore, #PB_Ignore, WindowWidth(0), #PB_Ignore)
EndProcedure


If OpenWindow(0, 100, 200, 500, 300, "PureBasic MiniBrowser v1.0", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
  
  CreateStatusBar(0, WindowID(0))
  AddStatusBarField(#PB_Ignore)
  StatusBarText(0, 0, "Welcome to the world's smallest Browser ! :)", 0)
  
  ButtonGadget(1,   0, 0, 50, 25, "Back")
  ButtonGadget(2,  50, 0, 50, 25, "Next")
  ButtonGadget(3, 100, 0, 50, 25, "Stop")
  
  StringGadget(4, 155, 5, 0, 20, URL$)
  
  ButtonGadget(5, 0, 0, 25, 25, "Go")
  
  Frame3DGadget(6, 0, 30, 0, 2, "", 2) ; Nice little separator
  
  If WebGadget(10, 0, 31, 0, 0, URL$) = 0 : MessageRequester("Error", "ATL.dll not found", 0) : End : EndIf
  
  AddKeyboardShortcut(0, #PB_Shortcut_Return, 0)
  
  ResizeWebWindow()
  
  Repeat
      Event = WaitWindowEvent()
      
      Select Event
        Case #PB_Event_Gadget
          
          Select EventGadget()
            Case 1
              SetGadgetState(10, #PB_Web_Back)
              
            Case 2
              SetGadgetState(10, #PB_Web_Forward)
              
            Case 3
              SetGadgetState(10, #PB_Web_Stop)
              
            Case 5
              SetGadgetText(10, GetGadgetText(4))
              
          EndSelect      
          
        Case #PB_Event_Menu ; We only have one shortcut
          SetGadgetText(10, GetGadgetText(4))
          
        Case #PB_Event_SizeWindow
          ResizeWebWindow()
          
      EndSelect
      
  Until Event = #PB_Event_CloseWindow
  
EndIf
If I run this in ascii mode, website is shown and the stringgadget shows the url.
But if I run the code in unicode, website ist shown :!: , but the stringgadget only shows chinese charakters. :(

What is wrong? May be the converting from ascii to unicode/utf8?
Or is the stringgadget not able to work with unicode? Then it's a bug.

Any help?
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: [V4.60]Chinese chars in stringgadget

Post by luis »

Code: Select all

;CompilerIf #PB_Compiler_Unicode
;  AsciiURL$ = Space(Len(URL$))
;  PokeS(@AsciiURL$, URL$, -1, #PB_Ascii)
;  URL$ = AsciiURL$
;CompilerEndIf
Just remove this code... why is it there ?

In unicode mode that code force a ascii (single byte) interpretation of a unicode string inside another string that it's still unicode. When you access that string the bytes are interpreted as unicode resulting in pseudo-random unicode characters.

Oh sorry (just noticed it's the OSX forum). I'm trying it under Windows (removing that code works) and I don't see the need for that, but not having a Mac I'll keep my mouth shout and leave !
"Have you tried turning it off and on again ?"
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Re: [V4.60]Chinese chars in stringgadget

Post by michel51 »

luis wrote:Oh sorry (just noticed it's the OSX forum). I'm trying it under Windows (removing that code works) and I don't see the need for that, but not having a Mac I'll keep my mouth shout and leave !
Hi Luis,

Your'e right, it's the Mac forum.
And if I don't convert the url into utf8, the webgadget will not work as expected. The site will not be shown with unicode compiling.

Thanks for Your repost.
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
User avatar
Shardik
Addict
Addict
Posts: 2076
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: [V4.60]Chinese chars in stringgadget

Post by Shardik »

michel51 wrote:And if I don't convert the url into utf8, the webgadget will not work as expected. The site will not be shown with uniode compiling.
michel51,

sorry, but I am currently at vacation on Madeira for two weeks and I have no Mac OS for testing purposes...
But I would propose that you should use the conversion of the URL to ASCII for Unicode compilation only for the WebGadget (where it seems to be a bug that you have to do the conversion to ASCII). To display the URL in the StringGadget you should use the Unicode URL for Unicode compilation... :wink:
User avatar
michel51
Enthusiast
Enthusiast
Posts: 290
Joined: Mon Nov 21, 2005 10:21 pm
Location: Germany

Re: [V4.60]Chinese chars in stringgadget

Post by michel51 »

Shardik wrote: sorry, but I am currently at vacation on Madeira for two weeks and I have no Mac OS for testing purposes...
But I would propose that you should use the conversion of the URL to ASCII for Unicode compilation only for the WebGadget (where it seems to be a bug that you have to do the conversion to ASCII). To display the URL in the StringGadget you should use the Unicode URL for Unicode compilation... :wink:
Hi Shardik,

restful holidays for you.
Thanks for your repost. You're right, with a conversion to unicode the stringgadget works.
Here the modified code:

Code: Select all


URL$ = "http://www.purebasic.com"
URL1$ = URL$    ; another variable for stringgadget to convert into unicode

CompilerIf #PB_Compiler_Unicode
  AsciiURL$ = Space(Len(URL$))
  
  PokeS(@AsciiURL$, URL$, -1, #PB_UTF8)      ; here converting for the webgadget (utf8)
  URL$ = AsciiURL$

  PokeS(@AsciiURL$, URL1$, -1, #PB_Unicode)  ; here converting for the stringgadget (unicode)
  URL1$ = AsciiURL$
CompilerEndIf

Procedure ResizeWebWindow()
  ResizeGadget(10, #PB_Ignore, #PB_Ignore, WindowWidth(0), WindowHeight(0)-52)
  ResizeGadget(4, #PB_Ignore, #PB_Ignore, WindowWidth(0)-185, #PB_Ignore)
  ResizeGadget(5, WindowWidth(0)-25, #PB_Ignore, #PB_Ignore, #PB_Ignore)
  ResizeGadget(6, #PB_Ignore, #PB_Ignore, WindowWidth(0), #PB_Ignore)
EndProcedure


If OpenWindow(0, 100, 200, 500, 300, "PureBasic MiniBrowser v1.0", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget)
  
  CreateStatusBar(0, WindowID(0))
  AddStatusBarField(#PB_Ignore)
  StatusBarText(0, 0, "Welcome to the world's smallest Browser ! :)", 0)
  
  ButtonGadget(1,   0, 0, 50, 25, "Back")
  ButtonGadget(2,  50, 0, 50, 25, "Next")
  ButtonGadget(3, 100, 0, 50, 25, "Stop")
  
  StringGadget(4, 155, 5, 0, 20, URL1$)   ; use unicode converted variable
  
  ButtonGadget(5, 0, 0, 25, 25, "Go")
  
  Frame3DGadget(6, 0, 30, 0, 2, "", 2) ; Nice little separator
  
  If WebGadget(10, 0, 31, 0, 0, URL$) = 0 : MessageRequester("Error", "ATL.dll not found", 0) : End : EndIf
  
  AddKeyboardShortcut(0, #PB_Shortcut_Return, 0)
  
  ResizeWebWindow()
  
  Repeat
      Event = WaitWindowEvent()
      
      Select Event
        Case #PB_Event_Gadget
          
          Select EventGadget()
            Case 1
              SetGadgetState(10, #PB_Web_Back)
              
            Case 2
              SetGadgetState(10, #PB_Web_Forward)
              
            Case 3
              SetGadgetState(10, #PB_Web_Stop)
              
            Case 5
              SetGadgetText(10, GetGadgetText(4))
              
          EndSelect      
          
        Case #PB_Event_Menu ; We only have one shortcut
          SetGadgetText(10, GetGadgetText(4))
          
        Case #PB_Event_SizeWindow
          ResizeWebWindow()
          
      EndSelect
      
  Until Event = #PB_Event_CloseWindow
  
EndIf
I don't find a better solution.

But it's a little bit crazy, that I have to use 2 different variables, one for the stringgadget and one for the webgadget, with different converted items while compiling in unicode option.
This should be equal for all variables. Either ascii mode or unicode mode for all vars.

Because you're a Mac guru you may test this if you are back home.
michel51

Mac OS X Snow Leopard (10.6.8 ) Intel
PureBasic V 5.21(x64), V 5.22beta
Post Reply