Display unicode on button?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Display unicode on button?

Post by purplex88 »

I am getting this result when I try to use unicode:

2019-05-01_13-24-40.png
2019-05-01_13-24-40.png (7.1 KiB) Viewed 1657 times

Code: Select all

buttonLoad = new wxButton(this, 1650, L"Привет");
buttonLoad->Bind(wxEVT_BUTTON, &MyFrame::OnHello, this);
Is it possible use this or do I need to recompile wxWidgets for russian / cyrillic ?

Using wxWidgets 3.1 + Windows 8.1
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: Display unicode on button?

Post by Kvaz1r »

purplex88 wrote: Wed May 01, 2019 7:59 am I am getting this result when I try to use unicode:
If you have Unicode build of wxWidgets it shouldn't be a problem at all. But maybe the reason in "wrong" encoding your source file.

Edit:
which IDE do you use? If CodeBlocks + wxSmith here separate topic - Code::Blocks + wxSmith и русские буквы
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Display unicode on button?

Post by purplex88 »

Yes, right. I had to use different encoding for source file. Thanks, it worked correctly.

Any idea if I need to change locale? How will that be useful?

I am using Visual C++ 2015.
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: Display unicode on button?

Post by Kvaz1r »

purplex88 wrote: Wed May 01, 2019 8:27 am Any idea if I need to change locale? How will that be useful?
I don't know I'd never used this way. Maybe it will work if your default locale non-cyrillic, but to be honest i don't know much about locales. I also use VisualStudio and all work out of the box.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Display unicode on button?

Post by doublemax »

Changing the locale is primarily used for stuff like: correct date/time format, decimal point ("." or ",") and if you want to support multiple languages through wxTranslations.
Use the source, Luke!
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Display unicode on button?

Post by purplex88 »

@doublemax. That means I can just completely avoid using locale settings, if I don't care about commas or decimal points etc? and Unicode and displaying characters in different languages will still work.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Display unicode on button?

Post by doublemax »

purplex88 wrote: Wed May 01, 2019 8:43 am @doublemax. That means I can just completely avoid using locale settings, if I don't care about commas or decimal points etc? and Unicode and displaying characters in different languages will still work.
Yes. You just have to be aware of the locale dependent automatic conversion of 8 bit characters to Unicode like in your other thread. But as long as you avoid that, you're fine.
Use the source, Luke!
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Display unicode on button?

Post by purplex88 »

I see, you mean avoid

Code: Select all

wxString::wxString (const char * psz) 
and use

Code: Select all

wxString::wxString(const char*, const wxMBConv&)
so I can completely ignore locale and use wxString safely independent of locale.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Display unicode on button?

Post by doublemax »

When using string literals just use "L" or "wxT()" to create wide characters (16 bit under Windows).

Code: Select all

L"Привет"
When using 8bit text from external sources (e.g. files you're loading), try to use always use UTF8 encoding.
Use the source, Luke!
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Display unicode on button?

Post by purplex88 »

I see. Suppose the file I was loading was saved using ANSI Windows 1252:

Can I specify the second argument in:

Code: Select all

wxString::wxString(const char*, const wxMBConv&)
to handle that CP-1252 encoding to build wxString?

It seems wxMBConv accepts only unicode (UTF-8, UTF-16, UTF-32) parameters.
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: Display unicode on button?

Post by Kvaz1r »

purplex88 wrote: Wed May 01, 2019 9:17 am I see. Suppose the file I was loading was saved using ANSI Windows 1252:

Can I specify the second argument in:

Code: Select all

wxString::wxString(const char*, const wxMBConv&)
to handle that CP-1252 encoding to build wxString?

It seems wxMBConv accepts only unicode (UTF-8, UTF-16, UTF-32) parameters.
Yes. But there is wxCSConv. In this case you can use example from topic - DOS string to wxString
replaced cp866 with cp1252
purplex88
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 247
Joined: Mon Feb 24, 2014 3:14 pm

Re: Display unicode on button?

Post by purplex88 »

Thanks, I will do experiments with these now. I want to avoid this ANSI mess as much as possible though!
Post Reply