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);