Commit Graph

367 Commits

Author SHA1 Message Date
Vadim Zeitlin
d3a1abaab2 Untangle Mac and POSIX code in wxLocale::GetSystemLanguage()
Most of the code in this function was Unix-specific and didn't make
sense for Mac, where we never have to apply the workarounds in it nor
deal with languages specified without the territory etc, so separate Mac
branch using CoreFouundation API from the rest of the Unix code to make
things more understandable.

No real changes.
2021-08-20 23:37:28 +02:00
Vadim Zeitlin
59a4505a5f Use Core Foundation for testing locale availability under Mac
Using setlocale() is not the right way to do it there, try checking if
the locale is supported by Core Foundation instead of whether it's
supported by the Unix layer which is neglected and not used under Mac.
2021-08-20 22:02:46 +02:00
Vadim Zeitlin
8f20dd3490 Remove obsolete AIX workaround from wxLocale code
This code, added back in 420de418ea (workaround for buggy setlocale()
under AIX (without this wxLocale didn't work at all), 2005-09-18), is
probably irrelevant anyhow because AIX 5.2 must not be used any more,
but also seems to have lost its purpose at some time during the
intervening years, as we don't use "retloc" as argument to setlocale()
anyhow, so it is doubly safe to simply remove it.
2021-08-20 22:02:46 +02:00
Vadim Zeitlin
b9cbe6770f Add wxUILocale with minimal functionality
Use it in the sample to show what (little) it can do right now.
2021-08-20 22:02:46 +02:00
Vadim Zeitlin
33ae58e457 Allow using wxLOCALE_CAT_DEFAULT for numeric or money locale info
Make GetInfo() return information for numbers by default in the Unix
version too instead of asserting, as this is more consistent with the
MSW and Mac versions and also seems more useful.
2021-08-07 18:04:22 +02:00
Václav Slavík
3417c8e48b Fix passing of default language to wxTranslations
wxTranslations needs the information that user's default language is
used; in particular, it may choose to use a cascade of user-preferred
languages to choose the best UI language.

This was accidentally broken by
18bf718f60 which changed the logic to
fill shortName from the builtin database. This consequently changed
wxTranslations to use only the single detected language and ignore
user's preference cascade.

Closes https://github.com/wxWidgets/wxWidgets/pull/2385
2021-05-31 16:35:38 +02:00
Vadim Zeitlin
1c8af332cf Only set wxLocale as active once it has been fully initialized
Previously wxLocale object was set as the global local as soon as it was
created, even when the default ctor was used, i.e. the locale wasn't
really changed at all. This was always wrong, but only started to result
in visible problems since the changes of c6d6ec9295 (Merge branch
'msw-fix-decimal-point' of https://github.com/vslavik/wxWidgets,
2021-04-18) as we now could use the existing but not yet active locale
when checking for the decimal separator mismatch, resulting in spurious
asserts.

Fix this by postponing the call to wxSetLocale() and the rest of what
was previously done in the ctor until Init() is called (which is done by
all non default ctors).

Closes https://github.com/wxWidgets/wxWidgets/pull/2350

Closes #19154.
2021-04-27 14:09:41 +02:00
Václav Slavík
b466e3c769 Restore Win32 locale in wxLocale destructor 2021-04-17 15:12:45 +02:00
Václav Slavík
c9e2143a7a Fix wxLocale::GetInfo() for unknown Windows locales
wxWidgets may be unaware of the locale being used and may be unable to
get correct information from its languages database. For example, en-AT
locale, supported by Windows 10 and using "," for decimal point, would
be interpreted as en-US by wx, and return "." here.

The other situation, when wx supports a locale that the OS doesn't,
shouldn't make a difference here because in that case, CRT wouldn't
support the locale either and CRT formatting functions wouldn't be set
to use it.

See also somewhat related 9fc78c8167.
2021-04-17 15:12:45 +02:00
Vadim Zeitlin
e9ea0f53f6 Refactor platform checks in wxLocale::Init()
Avoid the need for ugly WX_NO_LOCALE_SUPPORT macro at the cost of a
couple of extra #ifs, which seems to be a worthy trade-off.

This also allows making the code calling setlocale("") for the default
language platform-independent.

No real changes.
2021-03-02 22:07:44 +01:00
Vadim Zeitlin
502114261a Handle wxLANGUAGE_DEFAULT in wxLocale specially under MSW too
Even if we do know about the system language, it's still better to let
OS/CRT handle it, as we may not know enough about it. E.g. "system
language" may actually be a mix of the different languages and formats
and we don't handle this case at all, while OS/CRT do just fine.
2021-03-02 22:07:44 +01:00
Vadim Zeitlin
9c4ab145e9 Add SetThreadUILanguage() wrapper
Make it possible to reuse the code dynamically loading this function
from elsewhere.

No real changes.
2021-03-02 22:07:44 +01:00
Vadim Zeitlin
9600c29ff2 Fix default language determination in wxLocale under MSW
We must use GetUserDefaultUILanguage() and not GetUserDefaultLCID().
Although still not ideal, this is much better when the UI language and
the locale differ: when everything is in some language, it's better to
use this language and wrong date/number format than use correct
date/number format but a wrong language.

See #11594.
2021-03-02 22:07:44 +01:00
Vadim Zeitlin
d03f193719 Recognize "ll_LL" as at language "ll" in GetSystemLanguage()
If we can't find an exact match for the system locale in the database,
try to at least find the corresponding language.

This is almost certainly what the intention of the original code was, as
otherwise the entire loop was useless because it couldn't find anything
that wouldn't have been found in the loop just above.

This allows to correctly load German translations when using unsupported
locale such as "de_IT", for example.

See #19082.
2021-02-28 23:39:20 +01:00
Vadim Zeitlin
73b41dda91 Remove redundant #if/#endif in Unix locale code
Put both Unix-only functions inside the same #ifdef __UNIX__.

No real changes.
2021-02-28 22:50:35 +01:00
Vadim Zeitlin
2e8e0197d7 Add wxSetlocaleTryAll() helper to simplify Unix locale code
Define the function calling setlocale("xx_YY") first and then just
setlocale("xx") if the former failed, instead of doing the same thing
manually in 3 different places.

Also avoid attempting the second setlocale() call completely if there is
no "_YY" part in the first place.

No real changes.
2021-02-28 22:48:52 +01:00
Vadim Zeitlin
91ec900034 Explicitly disallow wxLANGUAGE_UNKNOWN in wxLocale::Init()
This value doesn't make here, so be upfront about it.
2021-02-28 20:04:33 +01:00
Vadim Zeitlin
18bf718f60 Support wxLANGUAGE_DEFAULT in wxLocale even when it is unknown
Don't give an error if we can't recognize the current system language,
as we may still be able to use it even in this case.

Closes #19082.
2021-02-28 20:00:27 +01:00
Vadim Zeitlin
3e395f9b5f Micro optimization for wxLANGUAGE_UNKNOWN in GetLanguageInfo()
Don't bother iterating over all the languages if we can be sure we're
not going to find anything anyhow.
2021-02-28 01:12:57 +01:00
Vadim Zeitlin
d029279227 Rename local variable to a more consistent name
Call the info->CanonicalName "shortName", as it's done in many other
places in the code instead of using "locale" for it here, even though we
do use it as a name of locale.

No real changes.
2021-02-28 01:11:34 +01:00
Vadim Zeitlin
7b6894ea41 Reuse Unix branch of wxLocale::Init() for macOS too
There doesn't seem to be any reason to partially duplicate Unix-specific
code in a separate Mac branch when we can just use the same code. Parts
of it which are not necessary under Mac, such as trying ".UTF-8" locales
in wxSetlocaleTryUTF8(), can be separately disabled there (even though
they are harmless), but other parts are probably needed, e.g. setting
Norwegian locale failed under macOS before because we didn't translate
nb_NO that we use to no_NO actually supported under macOS.
2021-02-28 01:02:59 +01:00
Vadim Zeitlin
0aba9fe112 Remove useless fallback from wxLocale::Init()
There is no need to try setting "loc.UTF-8" and "loc.UTF8" when we had
just called wxSetlocaleTryUTF8() which tried these variants and also
their lower-case equivalents already.
2021-02-27 17:52:08 +01:00
dsr
7d7c43c4c3 Use localeconv() under Android, it's available there now
As of NDK21d, localeconv() is available under Android and can be used in
wxQt there.
2021-01-27 18:09:43 +01:00
Maarten Bent
a6d309447a Fix unreachable-code-return and unreachable-code-break warning 2020-12-23 17:03:06 +01:00
PB
a6d4799de9 Remove BCC-specific conditionally compiled code 2020-10-13 18:40:31 +02:00
PB
f57f214122 Remove BCC-specific hdrstop pragma from everywhere 2020-10-12 21:58:37 +02:00
Maarten Bent
1607ec48c3 Fix -Wunused-function warning 2020-04-27 00:33:02 +02:00
Stefan Csomor
f83577df45 Changing datatransfer implementation from CFPasteboard to NSPasteboard API (#1264)
* changing datatransfer from CFPasteboard to NSPasteboard API

* factoring and cleaning up

* Switching back naming

* missed file

* getting wxCFStringRef to be independent of system headers

* add unichar include

* using wxCFStringRef in header

* moving to private headers, change method name

* adapting to lesser content in cfstring.h

* Removing malloc/free usage

* use wxScopedArray throughout

* using wxMemoryBuffer instead of char[]

* fixing nonprecomp headers

* missing forward decl in non-precomp builds
2019-10-08 06:32:44 +02:00
Vadim Zeitlin
194870fe5e Recognize system UTF-8 encoding under MSW too
Recent versions of Windows 10 (finally!) allow to set up UTF-8 as the
system encoding, so recognize when it is returned by GetACP() in
wxLocale::GetSystemEncoding() and GetSystemEncodingName().
2019-09-27 19:34:32 +02:00
Vadim Zeitlin
7feaa024b3 Add support for code page 1361 (Johab Korean)
As with the previous commit, recognize the system CP1361 encoding, which
can be mapped to an existing wxFONTENCODING_CP1361 constant.
2019-09-27 19:31:38 +02:00
Vadim Zeitlin
5dbfff839e Add support for code page 1258 (Vietnamese)
There doesn't seem to be any good reason to not support this one, when
we support (or at least recognize) all the other CP125x encodings.
2019-09-27 19:30:22 +02:00
Vadim Zeitlin
35d9b0f056 Rewrite a chain of "if"s as a switch
No real changes, just make the code a bit more maintainable and easier
to read.
2019-09-27 19:29:42 +02:00
Vadim Zeitlin
17041075b4 Fix wxLanguageInfo::GetLocaleName()
This function could (and did) return completely wrong results because
the value of the pointer returned by setlocale() could be (and was)
changed by the subsequent call to setlocale() with different arguments.

Fix the problem by copying the returned value into wxString immediately,
without any intervening setlocale() calls.
2017-12-10 02:32:54 +01:00
Vadim Zeitlin
0bae199ffe Merge branch 'msw-locale'
Fixes for setting locale under MSW when using older compilers and minor
simplifications and optimizations in wxLocale code.

See https://github.com/wxWidgets/wxWidgets/pull/517
2017-07-16 15:04:16 +02:00
Vadim Zeitlin
019e9d041f Fix setting locale under MSW when using locale name
Previously, all MSW-specific stuff like calling SetThreadLocale() and
SetThreadUILanguage() was only done when initializing wxLocale from a
wxLanguage value, but not when using a string name for it.

Fix this by implicitly calling Init(wxLanguage) from Init(wxString) if
we can find the language corresponding to the given name, and if the
other parameter is not incompatible with it.
2017-07-16 15:03:24 +02:00
Vadim Zeitlin
8cb4e70064 Refactor wxLocale initialization code
Don't call wxSetlocale() in DoInit() any more, this was redundant when
it was called from Init(wxLanguage) overload.

Add new DoCommonPostInit() called from both Init() overloads after
setting the locale in whichever way they do it to avoid code
duplication.

As a side effect of this change, the error message given if the locale
can't be set is the same now independently of the ctor/Init() overload
used (previously it differed depending on whether a wxLanguage or the
name of the language as string was passed) and it's always logged using
wxLogWarning() and not it in one case and wxLogError() in the other one.
2017-07-16 15:03:22 +02:00
Vadim Zeitlin
2deca99789 Don't duplicate "ret" flag in wxLocale::Init()
Simplify the code by just using "retloc != NULL" as success indicator
until the call to DoInit() instead of keeping a separate "bool ret"
variable in sync with "retloc".
2017-07-16 15:03:20 +02:00
Vadim Zeitlin
8713d73466 Avoid at least some unnecessary setlocale() calls
Instead of calling wxLanguageInfo::GetLocaleName(), which called
setlocale() at least thrice (first to query the current locale, second
to try to change it and third to restore the original locale) and then
calling setlocale() again if it succeeded, use the new TrySetLocale()
method which calls setlocale() just once and doesn't require calling it
again in the caller.

This makes the code slightly more efficient but, more importantly,
shorter and more clear.
2017-07-16 15:03:17 +02:00
Vadim Zeitlin
1003cf3e92 Remove unnecessary c_str() calls in wxLocale code
Pass wxString directly to wxLogWarning(), there is no need for c_str()
since wx 3.0 any more.
2017-07-16 15:03:15 +02:00
Vadim Zeitlin
9104e6fc9a Avoid unnecessary copies in wxLocale code
Micro-optimization: don't copy the strings unnecessarily when using just
a const reference is sufficient.
2017-07-16 15:03:12 +02:00
Vadim Zeitlin
ca3d86155c Get rid of another unused variable in wxLocale::Init()
This one was defined and used only once, just remove it completely.
2017-07-16 15:03:10 +02:00
Vadim Zeitlin
2d170d1bb6 Get rid of common "locale" variable in wxLocale::Init()
Try to make code less confusing by avoiding defining a variable in
platform-independent part of the code and then actually using it only in
platform-specific code.
2017-07-16 15:03:08 +02:00
Vadim Zeitlin
9b387434a0 Remove unnecessary checks for wxLANGUAGE_DEFAULT
Simplify the code by not checking for language == wxLANGUAGE_DEFAULT in
wxLocale::Init(): this can't happen because we use the system language
when passed wxLANGUAGE_DEFAULT as parameter and return false immediately
if we can't determine the system language.
2017-07-16 15:03:05 +02:00
Vadim Zeitlin
7836dfbc77 Make wxLanguageInfo::GetLocaleName() consistent across platforms
Check that the locale can be indeed set to the given string in Unix
version too, there doesn't seem to be any good reason to do it for MSW
only.
2017-07-16 15:03:03 +02:00
Vadim Zeitlin
2e2682116f Try to return valid name from MSW wxLanguageInfo::GetLocaleName()
Check if setlocale() really works with the name of the returned locale
and return empty string if it doesn't.

This fixes problem with setting locale when using old MSVC or MinGW CRT
under new (Vista+) MSW versions, as the CRT doesn't support the locale
names returned by LOCALE_SNAME and we need to fall back on
LOCALE_SENGLANGUAGE.
2017-07-16 15:03:00 +02:00
Lauri Nurmi
05ced5ce01 Handle stand-alone weekday and month names in macOS date formats
macOS returns "cccc" (stand-alone weekday name) as a part of the
preferred date+time format for Finnish, and possiblly others. This was
not handled at all by wxTranslateFromUnicodeFormat(), and the user
saw the raw "cccc".

Similarly, handle stand-alone month name ("LLLL").

Closes https://github.com/wxWidgets/wxWidgets/pull/518
2017-07-15 18:08:21 +02:00
JulianSmart
f14d702e4a Limit LOCALE_SNAME avoidance to VS2010 2017-05-30 19:23:32 +01:00
JulianSmart
91cb0b4875 Restore previous GetLocaleName behaviour except for Norwegian Bokmål since wxLocale::Init fails otherwise for VS2010 2017-05-29 13:18:13 +01:00
Paul Cornett
a0cb7c1291 Avoid using stale nl_langinfo() pointer
See #17813
2017-03-02 07:48:08 -08:00
Paul Cornett
6169ced23f Remove returns of wxEmptyString 2017-02-18 11:26:40 -08:00