Commit Graph

71396 Commits

Author SHA1 Message Date
Vadim Zeitlin
4d32fd481c Move wxLocaleIdent implementation out of line
No real changes, just don't make all wxLocaleIdent setters inline, this
is not necessary as none of these methods are performance-critical.

This commit is best viewed with --color-moved git option.
2021-09-05 00:15:39 +02:00
Vadim Zeitlin
5233014a71 Add missing CHECK() to wxUILocale test case for MSW/Mac
Don't forget to check that the locale is actually supported, as
expected, under these platforms.
2021-09-05 00:15:39 +02:00
Vadim Zeitlin
44a5cf78d1 Allow rescaling larger images in Win64 builds
Use wxUIntPtr rather than (unsigned) long in wxImage::ResampleNearest()
as long is still 32 bits under Win64 and so doesn't allow the code there
to work with images larger than 2^16 in either direction, when it could
be allowed in this case.

Document the current limits on the size of the image and add a unit test
checking that resizing images of size greater than 2^16 works in 64 bits.

See #18550.
2021-09-04 18:59:33 +01:00
Vadim Zeitlin
07015d29a8 Correct comment for wxUILocaleImplUnix::m_locale
This member is not allocated on demand any more, but is only null for
the default locale object.
2021-09-04 19:17:57 +02:00
Vadim Zeitlin
7a7bc5dad2 Move wxLocaleIdent to wx/uilocale.h
No real changes, just move this class declaration as it seems more
logical to have it in the same header with wxUILocale which is the only
place where it's used.

This commit is best viewed with --color-moved git option.
2021-09-04 19:00:49 +02:00
Vadim Zeitlin
c489cd9398 Fix formatting and slightly update wxGTK install instructions
The only real change is that the part about building wxGTK under Cygwin
was removed, it wasn't very useful and shouldn't distract from other,
more important, information here.
2021-09-04 17:17:27 +01:00
Vadim Zeitlin
f2cd6344af Clarify comments in the private uilocale.h
No real changes.

Co-Authored-By: Václav Slavík <vaclav@slavik.io>
2021-09-04 15:13:53 +02:00
Vadim Zeitlin
4c9c5d08cb Refactor Unix locale creation code
Just extract the code trying to find the matching locale into its own
function.

This commit is best viewed with --color-moved git option.
2021-09-04 15:04:17 +02:00
Vadim Zeitlin
39e1cae617 Merge branch 'osx-bitmap-image'
Avoid crash in wxButton when setting invalid pressed bitmap in wxOSX and
other button bitmaps-related improvements.

See https://github.com/wxWidgets/wxWidgets/pull/2508
2021-09-04 12:28:25 +02:00
Vadim Zeitlin
89552a02f5 Remove unnecessary checks before calling GetNSImage()
Now that this function is guaranteed to return NULL if the bitmap is
invalid, the code can be simplified to rely on it.

No real changes.
2021-09-03 21:35:03 +02:00
Vadim Zeitlin
2574b9172e Rename wxBitmap::GetImage() to OSXGetImage()
Make it more clear that this function is specific to Mac ports.
2021-09-03 21:32:52 +02:00
Vadim Zeitlin
be923dc9fe Use wxBitmap::GetNSImage() in Cocoa code
Use Cocoa-specific function rather than generically-named GetImage().

No real changes.
2021-09-03 21:27:58 +02:00
Vadim Zeitlin
6f4c57260b Use wxBitmap::GetUIImage() in wxiOS code
It looks like this should be the right function to use, rather than the
more generic GetImage() which is going to be renamed in the upcoming
commits.
2021-09-03 21:26:05 +02:00
Vadim Zeitlin
0f79f69d88 Return empty bitmaps from wxButton if not explicitly set in wxMSW
Do this for consistency with the other ports and because this seems more
useful anyhow.

Update the documentation to make this behaviour more clear and document
this change as a (minor) incompatibility in wxMSW.

Also add more unit tests to check for this behaviour. Note this also
fixes the problem with the unit test added in the grandparent commit
under MSW.
2021-09-03 21:22:05 +02:00
Vadim Zeitlin
169a33c238 Remove always true check from assert in MSW wxAnyButton code
The bitmap here is always valid as the invalid case is handled in the
beginning of the function.
2021-09-03 19:57:59 +01:00
Vadim Zeitlin
f45fe496c0 Fix crash in wxOSX when calling Disable() before Create()
This is explicitly allowed and we even have a unit test checking for
this, but the test crashed under macOS.

Fix this by simply doing nothing in wxWindow::DoEnable() if the window
is not created yet.
2021-09-03 00:39:42 +02:00
Vadim Zeitlin
ff4cd70412 Avoid crash in wxBitmap::GetImage() for invalid bitmaps
Just return NULL from this (wxOSX private, in spite of not using a
port-specific prefix) method.

This fixes crash in wxButton::SetBitmapXXX(wxNullBitmap), as shown by
the new test case which used to crash but doesn't do it any longer.

Closes #19257.
2021-09-03 00:28:58 +02:00
Artur Wieczorek
0455e25302 Set window postion explicitly in clipping box test for wxClientDC
Set window position explictly to (0, 0) to avoid unwanted clipping
if defualt position selected by the system would place it (partially)
outside of the parent window.
2021-09-02 19:26:30 +02:00
Artur Wieczorek
cf881ad03a Fix creating CGContext from drawing context
Save initial affine transformations for just created CGContext
(like it's done in all wxMacCoreGraphicsContext ctors) to properly
manage user-defined transformations in SetTransform(),
GetTransform().
2021-09-02 19:25:29 +02:00
Vadim Zeitlin
303d899cc0 Make STL-based wxList more compatible with the default one
This is done to fix the build error in STL builds after the previous
commit, as using Find() or DeleteObject() with a pointer of the "base
type" worked when using wxWindowList in the default build, but not in
the STL build, so this commit avoids this mismatch by allowing to use a
base class pointer where it is safe to do so, i.e. where it can be done
without a downcast, as there doesn't seem to be any reason to have this
difference between the builds in this case.

Note that there is still a difference between Append() and Insert()
methods which (correctly) require the pointer of right type in STL build
but still accept a pointer of the base type in the default build for
compatibility reasons.

In particular, this means that one of the casts removed in the last
commit from wxWindowBase code needs to be restored, as Append() still
requires a wxWindow and not just a wxWindowBase.
2021-09-02 00:52:50 +02:00
Vadim Zeitlin
ebe4796f6c Remove unnecessary casts to wxWindow when using wxTopLevelWindows
This list uses wxWindowBase for its elements, so downcasts are
unnecessary and actually harmful as the downcast performed in the dtor
results in undefined behaviour because the object is not a wxWindow any
more by then (thanks to UBSAN for detecting this).
2021-09-01 21:23:23 +02:00
Vadim Zeitlin
836f5abc3d Try to improve CompareStrings() documentation
Explain why this function should be used and give an example of how this
function works in different locales.
2021-09-01 18:12:07 +02:00
Vadim Zeitlin
e6cebb27f1 Use wxCFStringRef for conversion between wxString and NSString
No real changes, just avoid converting to NSString by reusing
wxCFStringRef.
2021-09-01 18:12:07 +02:00
Vadim Zeitlin
27594dcd81 Use NSLocale rather than CFLocale functions for consistency
We need to use [NSString compare:options:range:locale:], as there is no
corresponding CFString function, so use NSLocale functions rather than
CFLocale ones too, for consistency.

No real changes.
2021-09-01 18:12:07 +02:00
Vadim Zeitlin
b306cfba26 Disable non-trivial CompareStrings() tests in ANSI build
UTF-8 strings can't be used in this case and we don't care enough about
this deprecated build to bother with using Latin-1 just for it.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
3f8fd90c31 Support creating Unix wxUILocale for languages without region
Unlike MSW and macOS, creating wxUILocale for e.g. "en" doesn't
necessarily succeed under Linux even if "en_US" is available, so try to
find a working language+region combination if just language doesn't
work.

This requires access to the languages database, so add a private
wxGetLanguageInfos() to avoid having to depend on wxLocale just for
this.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
e92da29272 Replace wxLocale::ms_languagesDB dynamic array with a wxVector
There is no reason to use the macro-based classes for this array as
there are no compatibility constraints here, so use a simple vector
instead.

Note that we need an extra boolean variable now that we don't use a
pointer because we can't just check whether the vector is empty, as this
would return in infinite recursion when InitLanguagesDB() calls
AddLanguage() which, in turn, calls CreateLanguagesDB().
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
5bf11d94a7 Always succeed in CreateForLanguage(wxLANGUAGE_ENGLISH)
This is required for wxLocale compatibility, as using wxLANGUAGE_ENGLISH
is supposed to be the same as using "C" locale (even if it isn't,
really) at wxLocale level.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
c835d1afa6 Install locales used in wxUILocale tests on the CI system
Ensure that the tests are run instead of being skipped.

Also merge "Set environment variables" and "Before install" steps into a
single "Set up" step to avoid adding yet another separate step for
locale installation.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
b14137a355 Skip tests using unsupported locales under Unix systems
At least under Linux it's common not to have all the supported locales
installed, so check that a locale is available to avoid test failures if
it isn't.

We still rely on all the locales we use being available under MSW and
macOS, as this should be always the case.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
32316af106 Add wxUILocale::IsSupported()
This function can now be implemented relatively straightforwardly
(although it does require an extra check under Mac), so add it, as it
can be generally useful and we're also going to need it for our own
tests in the upcoming commit.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
aa4cce8f7d Leave NULL impl pointer in wxUILocale if locale is not supported
This finally seems better than always creating some kind of impl object,
even if the locale isn't supported at all and makes all ports behave
consistently, as previously CreateForLocale() only returned NULL in
wxOSX implementation if the locale was unrecognized, but now all ports
do this (at least when locale_t and related functions are available
under Unix).

Also stop returning bool from Use(), as this resulted in initializing
wxLocale with any non-default language to fail under Mac: just ignore
the error here, as we always did it until now, because there is nothing
we can do about it anyhow.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
e3ff6dc056 Create wxGetStdCLocaleInfo() function
Extract it from existing MSW-only code and make it available in all
ports so that we could use it as a fallback in wxUILocale if everything
else fails.

No real changes yet.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
babcd16bc4 Disable CompareStrings() tests failing under Wine
There isn't much we can do about it, although perhaps these tests could
be re-enabled once https://bugs.winehq.org/show_bug.cgi?id=9583 is
fixed.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
ae81d9d207 Implement wxUILocale::CompareStrings() for Unix systems
This required changing CompareStrings() to be a method of wxUILocale
object, rather than just as a static function, as we must only allocate
the locale_t object once, and not during each to this function, as this
could make it unusably slow when using it as a comparison function when
sorting a large list of strings.

This is also more efficient under Mac, where we can similarly allocate
NSLocale only once and even marginally more efficient under MSW, where
we don't have to construct the locale string during each call. And,
under all platforms, it also simplifies code by separating this function
implementation from the initialization of wxUILocaleImpl.

Also document that case-insensitive comparison is not available under
Unix and adjust the tests accordingly.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
45f9908e05 Allow creating wxUILocale objects for any locale
Creating such objects (without using them for the UI) is supported under
all platforms, so allow doing it.

Note that this is only supported under Unix systems when locale_t and
related functionality is available, but this should be the case just
about everywhere by now.

Add a test (or, rather, replace an existing test which was disabled by
default) checking that we can now get locale information about any
locale, not necessarily the currently used one.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
07e79b7736 Provide name-based wxUILocale implementation for post-XP MSW
Use the recommended name-based NLS API rather than legacy functions
taking LCID.

Preserve compatibility with Windows XP by keeping the old code for now,
but it will be removed after 3.2.0.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
608718dd9c Separate creating wxUILocaleImpl from using it
Add Use() virtual function which can be used if the newly created
wxUILocaleImpl object should be used as the default UI locale.

Currently Use() is always called after creating a new wxUILocaleImpl, so
adding a separate function just seems to complicate matters needlessly,
but this won't be the case any more soon, when wxUILocaleImpl could be
created for using them for other purposes than making them the default.

No real changes yet.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
45ffc40fc2 Use nl_langinfo() in wxUILocaleImplUnix::GetInfo()
This function can be used for all GetInfo() items, so using it is
simpler than the code in the Unix version of wxLocale::GetInfo() which
uses either it or localeconv(), and there should be no real drawbacks to
using it nowadays as it should be available everywhere.

No real changes yet.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
592e1678ce Add charset support to wxLocaleIdent and accessors
Charset is important for Unix systems as some locales may not be
available without it, e.g. "xx_XX" may not be supported, but
"xx_XX.utf8" could be.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
20e3697f00 Change wxLocaleIdent ctor to take char* rather than wxString
This is convenient, as it allows using a simple string such as "en" as
an argument to the functions taking wxLocaleIdent and rely on implicit
conversion, whereas previously explicitly writing either wxString("en")
or wxLocaleIdent("en") would be necessary.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
ddd60d5a39 Add link to ISO 639 language codes to the documentation
This can be useful as not all of them are really obvious.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
e27497774a Optionally use case-insensitive comparison in CompareStrings()
Harmonize Mac and MSW versions by using case-sensitive comparison in
both of them by default, but allowing to use a flag to use
case-insensitive comparison instead.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
5f8483b49d Use wxRESERVED_PARAM for the reserved parameters for clarity
No real changes.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
df710b263b Rename "locale_id" parameter to conform to the usual convention
No real changes.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
59e4e098b7 Add minimal tests for wxUILocale::CompareStrings()
Test the new function in a couple of different locales.
2021-09-01 18:11:40 +02:00
Vadim Zeitlin
abdf251b42 Convert intltest.cpp to UTF-8 encoding
Don't use Latin-1 for this file, this encoding is obsolete.

No real changes, the only non-ASCII character in this file was in a
comment anyhow.
2021-09-01 18:11:39 +02:00
Alexander Koshelev
c8269210a2 Add wxUILocale::CompareStrings() function
This function allows comparing strings using the sort order of the
specified locale, represented by the new wxLocaleIdent class.

It is implemented using CompareStringEx()[1] under MSW and
NSString::compare:options:range:locale:[2] under macOS, generic
implementation for the other platforms is upcoming.

[1]: https://docs.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-comparestringex
[2]: https://developer.apple.com/documentation/foundation/nsstring/1414561-compare?language=objc
2021-09-01 18:11:33 +02:00
Vadim Zeitlin
9f43ec03e6 Rename Mac uilocale.cpp to uilocale.mm
No real changes yet, just prepare for using Objective-C code in this
file.
2021-09-01 17:42:53 +02:00
Vadim Zeitlin
4878e1e72c Merge branch 'ci-mac'
Define all Mac CI jobs in the same file and update the badges in the
README to show badges for Unix/MSW/Mac builds separately.

See https://github.com/wxWidgets/wxWidgets/pull/2504
2021-08-29 00:43:36 +02:00