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:
@@ -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
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user