UTF in dialog boxes

Discussions related to mouse, keyboard, fonts and Graphical User Interface
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

UTF in dialog boxes

Post by KenDown »

I need to use various Welsh characters in my dialog boxes, in particular vowels with circumflex. When I put the string into a static or edit box with SYS"SetDlgItemText" or read a string from an edit box with SYS"GetDlgItemText", instead of lower-case 'a' with a circumflex over it, I get â and similar for other letters.

I would be grateful for any guidance.

I have enabled Unicode in the BB4W editor and used the appropriate value in VDU 23. I have tried using SYS"WideCharToMultiByte" but the trouble is that I don't really know what I am doing with that, so can't tell whether it isn't working, it isn't what I need, or I am using it wrong.

Thanks.
Hated Moron

Re: UTF in dialog boxes

Post by Hated Moron »

KenDown wrote: Fri 02 Dec 2022, 20:02 I have enabled Unicode in the BB4W editor and used the appropriate value in VDU 23.
In addition to those it will be necessary to use either the WINLIB2U or WINLIB5U library to create the Unicode control(s).
I have tried using SYS"WideCharToMultiByte" but the trouble is that I don't really know what I am doing with that
There's a page at the Wiki showing how to call that function.
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Re: UTF in dialog boxes

Post by KenDown »

Hmmm. Bother. I had forgotten the WinLib2U - I have a feeling you have pointed it out to me before, but it doesn't appear to make any difference.

In my dialogue box I have a check box:

PROC_checkbox(dialog%,"",100,10,40,56,10,0)

into which I wish to insert this string:

categorie$="Ysbryd Glân"
SYS"SetDlgItemText",!dialog%,100,categorie$

Even with WinLib2U the check box still appears with "Ysbryd Glân"

Sorry to be so thick.
Hated Moron

Re: UTF in dialog boxes

Post by Hated Moron »

KenDown wrote: Fri 02 Dec 2022, 20:02 I need to use various Welsh characters in my dialog boxes, in particular vowels with circumflex.
Taking a step back, which particular Welsh characters are missing from the ANSI character set? The only vowels with a circumflex which are not available, as far as I know, are Ŷŷ, and Ŵŵ i.e. capital and lowercase Y and W with a circumflex. Are they why you need Unicode?
Hated Moron

Re: UTF in dialog boxes

Post by Hated Moron »

KenDown wrote: Sat 03 Dec 2022, 20:57 In my dialogue box I have a check box:
PROC_checkbox(dialog%,"",100,10,40,56,10,0)

into which I wish to insert this string:

categorie$="Ysbryd Glân"
If you don't want to change the text dynamically (and changing the name of a checkbox could be argued to be questionable UI design), this should 'just work', since you're using WINLIB2U to create a Unicode control:

Code: Select all

categorie$="Ysbryd Glân"
PROC_checkbox(dialog%,categorie$,100,10,40,56,10,0)
If you do want to change the associated text dynamically, for this particular string you don't need to use Unicode at all (since â is available in the ANSI character set), so you can turn off all your Unicode settings and just use the regular code:

Code: Select all

categorie$="Ysbryd Glân"
SYS "SetDlgItemText", !dialog%, 100, categorie$
The slightly more complicated case is when you want to change the text dynamically and it contains a character not in the ANSI set. Depending on how pedantic you are about Welsh accents (and I'm no expert) and you wanted to write Tŷ Sanctaidd or Dŵr Sanctaidd then you would need to do something like this:

Code: Select all

categorie$="Dŵr Sanctaidd"
SYS "SetDlgItemTextW", !dialog%, 100, FNwide(categorie$)
where FNwide is:

Code: Select all

DEF FNwide(a$)
LOCAL S%, u$
SYS "MultiByteToWideChar", &FDE9, 0, a$, LEN(a$), 0, 0 TO S%
u$ = STRING$(S%*2, CHR$0)
SYS "MultiByteToWideChar", &FDE9, 0, a$, LEN(a$), u$, S%
= u$ + CHR$0 + CHR$0
KenDown
Posts: 327
Joined: Wed 04 Apr 2018, 06:36

Re: UTF in dialog boxes

Post by KenDown »

Oh that is brilliant! Thanks a million.

I have a file of hymns in which categories are defined - Praise, Worship, Children, Christmas, and so on. My program creates a dialog box with 40 check boxes, then reads in the file, extracting the categories as it goes. It makes sure there is only one instance of each, sorts the categories into alphabetical order, and then sticks one category in each check box. The user (me) can then quickly select a hymn, see which category it comes under, add a new category, delete the category, etc.

So yes, the putting of the categories into the checkboxes is done dynamically, especially when the user creates a new category.

Just as an experiment, I altered your FNwide slightly as follows:

Code: Select all

DEFFNwide(a$):LOCALS%,u$
SYS"MultiByteToWideChar",&FDE9,0,a$,LEN(a$),0,0TOS%
u$=STRING$(S%*2+2,CHR$0)
SYS"MultiByteToWideChar",&FDE9,0,a$,LEN(a$),u$,S%
=u$
In other words, I have added the two character zeroes when defining u$ rather than when returning the value. It seems to work but is it likely to cause any problems I'm not smart enough to foresee?

Once again, thank you so much.