From f1fd45892f74e0d4641b2c3d8e6fcb57a2bea8e6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 5 Dec 2014 22:18:25 +0000 Subject: [PATCH] Fall back to default process layout direction in wxMSW. Add helper wxApp::MSWGetDefaultLayout() static method and use it instead of wxTheApp->GetLayoutDirection() in wxMSW code. This serves two purposes: first, wxMessageDialog doesn't crash when it's shown before wxTheApp is created (or after it's destroyed) any more. And second, we use the correct layout direction if the main application has enabled it by calling SetProcessDefaultLayout() or using two U+200E characters in the beginning of its "FileDescription" resource field by default now. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78236 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/app.h | 11 +++++++++++ src/msw/app.cpp | 31 +++++++++++++++++++++++++++++++ src/msw/dc.cpp | 2 +- src/msw/msgdlg.cpp | 6 +++--- src/msw/tooltip.cpp | 2 +- src/msw/toplevel.cpp | 6 +++--- 6 files changed, 50 insertions(+), 8 deletions(-) diff --git a/include/wx/msw/app.h b/include/wx/msw/app.h index b1b65da13e..c5f6c2756d 100644 --- a/include/wx/msw/app.h +++ b/include/wx/msw/app.h @@ -74,6 +74,17 @@ public: // in the previous GetRegisteredClassName() calls static bool IsRegisteredClassName(const wxString& name); + // Return the layout direction to use for a window by default. + // + // If the parent is specified, use the same layout direction as it uses. + // Otherwise use the default global layout, either from wxTheApp, if it + // exists, or Windows itself. + // + // Notice that this normally should not be used for the child windows as + // they already inherit, just dialogs such as wxMessageDialog may want to + // use it. + static wxLayoutDirection MSWGetDefaultLayout(wxWindow* parent = NULL); + protected: int m_printMode; // wxPRINT_WINDOWS, wxPRINT_POSTSCRIPT diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 787e077df6..b62af00565 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -1008,4 +1008,35 @@ terminate the program,\r\n\ } } +// ---------------------------------------------------------------------------- +// Layout direction +// ---------------------------------------------------------------------------- + +/* static */ +wxLayoutDirection wxApp::MSWGetDefaultLayout(wxWindow* parent) +{ + wxLayoutDirection dir = wxLayout_Default; + + if ( parent ) + dir = parent->GetLayoutDirection(); + + if ( dir == wxLayout_Default ) + { + if ( wxTheApp ) + dir = wxTheApp->GetLayoutDirection(); + } + + if ( dir == wxLayout_Default ) + { + DWORD dwLayout; + if ( ::GetProcessDefaultLayout(&dwLayout) ) + { + dir = dwLayout == LAYOUT_RTL ? wxLayout_RightToLeft + : wxLayout_LeftToRight; + } + } + + return dir; +} + #endif // wxUSE_EXCEPTIONS diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index c18f0edbc6..8c3e241194 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -2913,7 +2913,7 @@ void wxMSWDCImpl::SetLayoutDirection(wxLayoutDirection dir) { if ( dir == wxLayout_Default ) { - dir = wxTheApp->GetLayoutDirection(); + dir = wxApp::MSWGetDefaultLayout(GetWindow()); if ( dir == wxLayout_Default ) return; } diff --git a/src/msw/msgdlg.cpp b/src/msw/msgdlg.cpp index ed3354f4fc..021b59ce11 100644 --- a/src/msw/msgdlg.cpp +++ b/src/msw/msgdlg.cpp @@ -538,7 +538,7 @@ int wxMessageDialog::ShowMessageBox() msStyle |= MB_TOPMOST; #ifndef __WXWINCE__ - if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) + if ( wxApp::MSWGetDefaultLayout(m_parent) == wxLayout_RightToLeft ) msStyle |= MB_RTLREADING | MB_RIGHT; #endif @@ -552,7 +552,7 @@ int wxMessageDialog::ShowMessageBox() // (unfortunately this only works in Unicode builds) wxString message = GetFullMessage(); #if wxUSE_UNICODE - if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) + if ( wxApp::MSWGetDefaultLayout(m_parent) == wxLayout_RightToLeft ) { // NB: not all compilers support \u escapes static const wchar_t wchRLM = 0x200f; @@ -702,7 +702,7 @@ void wxMSWTaskDialogConfig::MSWCommonTaskDialogInit(TASKDIALOGCONFIG &tdc) // use the top level window as parent if none specified tdc.hwndParent = parent ? GetHwndOf(parent) : NULL; - if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) + if ( wxApp::MSWGetDefaultLayout(parent) == wxLayout_RightToLeft ) tdc.dwFlags |= TDF_RTL_LAYOUT; // If we have both the main and extended messages, just use them as diff --git a/src/msw/tooltip.cpp b/src/msw/tooltip.cpp index 394ae2b17f..1ca0a44200 100644 --- a/src/msw/tooltip.cpp +++ b/src/msw/tooltip.cpp @@ -267,7 +267,7 @@ WXHWND wxToolTip::GetToolTipCtrl() if ( !ms_hwndTT ) { WXDWORD exflags = 0; - if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) + if ( wxApp::MSWGetDefaultLayout() == wxLayout_RightToLeft ) { exflags |= WS_EX_LAYOUTRTL; } diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index 028660b1f6..3fda42856d 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -518,7 +518,7 @@ bool wxTopLevelWindowMSW::CreateFrame(const wxString& title, const wxSize sz = IsAlwaysMaximized() ? wxDefaultSize : size; #ifndef __WXWINCE__ - if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) + if ( wxApp::MSWGetDefaultLayout(m_parent) == wxLayout_RightToLeft ) exflags |= WS_EX_LAYOUTRTL; #endif @@ -585,7 +585,7 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent, dlgTemplate->style |= WS_POPUP; #ifndef __WXWINCE__ - if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) + if ( wxApp::MSWGetDefaultLayout(m_parent) == wxLayout_RightToLeft ) { dlgTemplate->dwExtendedStyle |= WS_EX_LAYOUTRTL; } @@ -870,7 +870,7 @@ void wxTopLevelWindowMSW::Restore() void wxTopLevelWindowMSW::SetLayoutDirection(wxLayoutDirection dir) { if ( dir == wxLayout_Default ) - dir = wxTheApp->GetLayoutDirection(); + dir = wxApp::MSWGetDefaultLayout(m_parent); if ( dir != wxLayout_Default ) wxTopLevelWindowBase::SetLayoutDirection(dir);