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
This commit is contained in:
Vadim Zeitlin
2014-12-05 22:18:25 +00:00
parent 59086bd01a
commit f1fd45892f
6 changed files with 50 additions and 8 deletions

View File

@@ -74,6 +74,17 @@ public:
// in the previous GetRegisteredClassName() calls // in the previous GetRegisteredClassName() calls
static bool IsRegisteredClassName(const wxString& name); 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: protected:
int m_printMode; // wxPRINT_WINDOWS, wxPRINT_POSTSCRIPT int m_printMode; // wxPRINT_WINDOWS, wxPRINT_POSTSCRIPT

View File

@@ -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 #endif // wxUSE_EXCEPTIONS

View File

@@ -2913,7 +2913,7 @@ void wxMSWDCImpl::SetLayoutDirection(wxLayoutDirection dir)
{ {
if ( dir == wxLayout_Default ) if ( dir == wxLayout_Default )
{ {
dir = wxTheApp->GetLayoutDirection(); dir = wxApp::MSWGetDefaultLayout(GetWindow());
if ( dir == wxLayout_Default ) if ( dir == wxLayout_Default )
return; return;
} }

View File

@@ -538,7 +538,7 @@ int wxMessageDialog::ShowMessageBox()
msStyle |= MB_TOPMOST; msStyle |= MB_TOPMOST;
#ifndef __WXWINCE__ #ifndef __WXWINCE__
if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) if ( wxApp::MSWGetDefaultLayout(m_parent) == wxLayout_RightToLeft )
msStyle |= MB_RTLREADING | MB_RIGHT; msStyle |= MB_RTLREADING | MB_RIGHT;
#endif #endif
@@ -552,7 +552,7 @@ int wxMessageDialog::ShowMessageBox()
// (unfortunately this only works in Unicode builds) // (unfortunately this only works in Unicode builds)
wxString message = GetFullMessage(); wxString message = GetFullMessage();
#if wxUSE_UNICODE #if wxUSE_UNICODE
if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) if ( wxApp::MSWGetDefaultLayout(m_parent) == wxLayout_RightToLeft )
{ {
// NB: not all compilers support \u escapes // NB: not all compilers support \u escapes
static const wchar_t wchRLM = 0x200f; 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 // use the top level window as parent if none specified
tdc.hwndParent = parent ? GetHwndOf(parent) : NULL; tdc.hwndParent = parent ? GetHwndOf(parent) : NULL;
if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) if ( wxApp::MSWGetDefaultLayout(parent) == wxLayout_RightToLeft )
tdc.dwFlags |= TDF_RTL_LAYOUT; tdc.dwFlags |= TDF_RTL_LAYOUT;
// If we have both the main and extended messages, just use them as // If we have both the main and extended messages, just use them as

View File

@@ -267,7 +267,7 @@ WXHWND wxToolTip::GetToolTipCtrl()
if ( !ms_hwndTT ) if ( !ms_hwndTT )
{ {
WXDWORD exflags = 0; WXDWORD exflags = 0;
if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) if ( wxApp::MSWGetDefaultLayout() == wxLayout_RightToLeft )
{ {
exflags |= WS_EX_LAYOUTRTL; exflags |= WS_EX_LAYOUTRTL;
} }

View File

@@ -518,7 +518,7 @@ bool wxTopLevelWindowMSW::CreateFrame(const wxString& title,
const wxSize sz = IsAlwaysMaximized() ? wxDefaultSize : size; const wxSize sz = IsAlwaysMaximized() ? wxDefaultSize : size;
#ifndef __WXWINCE__ #ifndef __WXWINCE__
if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) if ( wxApp::MSWGetDefaultLayout(m_parent) == wxLayout_RightToLeft )
exflags |= WS_EX_LAYOUTRTL; exflags |= WS_EX_LAYOUTRTL;
#endif #endif
@@ -585,7 +585,7 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent,
dlgTemplate->style |= WS_POPUP; dlgTemplate->style |= WS_POPUP;
#ifndef __WXWINCE__ #ifndef __WXWINCE__
if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) if ( wxApp::MSWGetDefaultLayout(m_parent) == wxLayout_RightToLeft )
{ {
dlgTemplate->dwExtendedStyle |= WS_EX_LAYOUTRTL; dlgTemplate->dwExtendedStyle |= WS_EX_LAYOUTRTL;
} }
@@ -870,7 +870,7 @@ void wxTopLevelWindowMSW::Restore()
void wxTopLevelWindowMSW::SetLayoutDirection(wxLayoutDirection dir) void wxTopLevelWindowMSW::SetLayoutDirection(wxLayoutDirection dir)
{ {
if ( dir == wxLayout_Default ) if ( dir == wxLayout_Default )
dir = wxTheApp->GetLayoutDirection(); dir = wxApp::MSWGetDefaultLayout(m_parent);
if ( dir != wxLayout_Default ) if ( dir != wxLayout_Default )
wxTopLevelWindowBase::SetLayoutDirection(dir); wxTopLevelWindowBase::SetLayoutDirection(dir);