Fix setting RTL direction for wxTextCtrl without wxTE_RICH in wxMSW.

Plain EDIT text controls don't support WS_EX_LAYOUTRTL, use WS_EX_RTLREADING
for them instead.

See #11583.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77658 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-09-10 16:51:42 +00:00
parent 6ea435350e
commit 060cf2666d
3 changed files with 92 additions and 0 deletions

View File

@@ -1013,6 +1013,58 @@ inline long wxSetWindowExStyle(const wxWindowMSW *win, long style)
return ::SetWindowLong(GetHwndOf(win), GWL_EXSTYLE, style); return ::SetWindowLong(GetHwndOf(win), GWL_EXSTYLE, style);
} }
// Update layout direction flag for an EDIT control.
//
// Returns true if anything changed or false if the direction flag was already
// set to the desired direction (which can't be wxLayout_Default).
inline bool wxUpdateEditLayoutDirection(WXHWND hWnd, wxLayoutDirection dir)
{
wxCHECK_MSG( hWnd, false,
wxS("Can't set layout direction for invalid window") );
static const LONG_PTR
EDIT_RTL_EX_FLAGS = WS_EX_RIGHT | WS_EX_RTLREADING | WS_EX_LEFTSCROLLBAR;
const LONG_PTR styleOld = ::GetWindowLongPtr(hWnd, GWL_EXSTYLE);
LONG_PTR styleNew = styleOld;
switch ( dir )
{
case wxLayout_LeftToRight:
styleNew &= ~EDIT_RTL_EX_FLAGS;
break;
case wxLayout_RightToLeft:
styleNew |= EDIT_RTL_EX_FLAGS;
break;
case wxLayout_Default:
wxFAIL_MSG(wxS("Invalid layout direction"));
}
if ( styleNew == styleOld )
return false;
::SetWindowLongPtr(hWnd, GWL_EXSTYLE, styleNew);
return true;
}
// Companion of the above function checking if an EDIT control uses RTL.
inline wxLayoutDirection wxGetEditLayoutDirection(WXHWND hWnd)
{
wxCHECK_MSG( hWnd, wxLayout_Default, wxS("invalid window") );
// While we set 3 style bits above, we're only really interested in one of
// them here. In particularly, don't check for WS_EX_RIGHT as it can be set
// for a right-aligned control even if it doesn't use RTL. And while we
// could test WS_EX_LEFTSCROLLBAR, this doesn't really seem useful.
const LONG_PTR style = ::GetWindowLongPtr(hWnd, GWL_EXSTYLE);
return style & WS_EX_RTLREADING ? wxLayout_RightToLeft
: wxLayout_LeftToRight;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// functions mapping HWND to wxWindow // functions mapping HWND to wxWindow
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -101,6 +101,11 @@ public:
return wxTextCtrlBase::HitTest(pt, col, row); return wxTextCtrlBase::HitTest(pt, col, row);
} }
#ifndef __WXWINCE__
virtual void SetLayoutDirection(wxLayoutDirection dir) wxOVERRIDE;
virtual wxLayoutDirection GetLayoutDirection() const wxOVERRIDE;
#endif // !__WXWINCE__
// Caret handling (Windows only) // Caret handling (Windows only)
bool ShowNativeCaret(bool show = true); bool ShowNativeCaret(bool show = true);
bool HideNativeCaret() { return ShowNativeCaret(false); } bool HideNativeCaret() { return ShowNativeCaret(false); }

View File

@@ -1793,6 +1793,41 @@ void wxTextCtrl::SetMaxLength(unsigned long len)
} }
} }
#ifndef __WXWINCE__
// ----------------------------------------------------------------------------
// RTL support
// ----------------------------------------------------------------------------
void wxTextCtrl::SetLayoutDirection(wxLayoutDirection dir)
{
// We only need to handle this specifically for plain EDIT controls, rich
// edit ones behave like any other window.
if ( IsRich() )
{
wxTextCtrlBase::SetLayoutDirection(dir);
}
else
{
if ( wxUpdateEditLayoutDirection(GetHwnd(), dir) )
{
// Update text layout by forcing the control to redo it, a simple
// Refresh() is not enough.
SendSizeEvent();
Refresh();
}
}
}
wxLayoutDirection wxTextCtrl::GetLayoutDirection() const
{
// Just as above, we need to handle plain EDIT controls specially.
return IsRich() ? wxTextCtrlBase::GetLayoutDirection()
: wxGetEditLayoutDirection(GetHwnd());
}
#endif // !__WXWINCE__
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Undo/redo // Undo/redo
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------