From d390bee8a2135dd9cb64130e959840268539fe45 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 21 Jul 2018 14:03:47 +0200 Subject: [PATCH 1/2] Allow comparing wxString with wide strings in non-Unicode build This fixes a compilation error in wxMSW private fonts support implementation, which compares wxString with a wide string but, unlike a local fix there, makes sense more broadly and should reduce the likelihood of similar errors in the future. It also makes comparisons with narrow C strings more efficient in the default, Unicode, build by using wxString::Cmp() method instead of creating a temporary wxString, as was done before. See #18172. --- include/wx/string.h | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/include/wx/string.h b/include/wx/string.h index c05eeac92e..68651f35e3 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -3839,9 +3839,11 @@ public: // wxString comparison functions: operator versions are always case sensitive // --------------------------------------------------------------------------- +// comparison with C-style narrow and wide strings. #define wxCMP_WXCHAR_STRING(p, s, op) 0 op s.Cmp(p) -wxDEFINE_ALL_COMPARISONS(const wxChar *, const wxString&, wxCMP_WXCHAR_STRING) +wxDEFINE_ALL_COMPARISONS(const wchar_t *, const wxString&, wxCMP_WXCHAR_STRING) +wxDEFINE_ALL_COMPARISONS(const char *, const wxString&, wxCMP_WXCHAR_STRING) #undef wxCMP_WXCHAR_STRING @@ -3930,17 +3932,6 @@ inline bool wxString::iterator::operator<=(const const_iterator& i) const inline bool wxString::iterator::operator>=(const const_iterator& i) const { return i <= *this; } -// comparison with C string in Unicode build -#if wxUSE_UNICODE - -#define wxCMP_CHAR_STRING(p, s, op) wxString(p) op s - -wxDEFINE_ALL_COMPARISONS(const char *, const wxString&, wxCMP_CHAR_STRING) - -#undef wxCMP_CHAR_STRING - -#endif // wxUSE_UNICODE - // we also need to provide the operators for comparison with wxCStrData to // resolve ambiguity between operator(const wxChar *,const wxString &) and // operator(const wxChar *, const wxChar *) for "p == s.c_str()" From d605405ca1cdebc260569018686e03fb28434b9a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 21 Jul 2018 14:07:32 +0200 Subject: [PATCH 2/2] Fix building wxMSW GDI+ graphics code in non-Unicode build Use wc_str() with GDI+ function which always takes wide strings, even in non-Unicode build. Closes #18172. --- docs/changes.txt | 1 + src/msw/graphics.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index 7936144c7b..94c3ce14eb 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -118,6 +118,7 @@ wxMSW: - Fix positioning windows at positions >= SHORT_MAX (Cătălin Răceanu). - Honour alignment flags for multiline buttons using custom colours too. - Support MSVC auto-linking when using monolithic build too (PB). +- Fix build in ANSI (non-Unicode) mode. wxOSX: diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index f7c014d9d4..8d752b8ab6 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -2335,7 +2335,7 @@ void wxGDIPlusRenderer::Load() for ( size_t i = 0 ; i < n; i++ ) { const wxString& fname = privateFonts[i]; - gs_privateFonts->AddFontFile(fname.t_str()); + gs_privateFonts->AddFontFile(fname.wc_str()); } gs_pFontFamily = new Gdiplus::FontFamily[n];