Fix setting layout direction for wxComboBox in wxMSW.
The EDIT control used by the native combobox is different from normal EDIT controls and has to be handled specially. We also need to explicitly forward WS_EX_LAYOUTRTL to the dropdown window as it doesn't inherit it from the combobox itself automatically. See #11583. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77754 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
da41c5d9bb
commit
e5755015e7
@ -126,6 +126,8 @@ public:
|
||||
virtual bool SetHint(const wxString& hint);
|
||||
#endif // wxUSE_UXTHEME
|
||||
|
||||
virtual void SetLayoutDirection(wxLayoutDirection dir) wxOVERRIDE;
|
||||
|
||||
protected:
|
||||
#if wxUSE_TOOLTIPS
|
||||
virtual void DoSetToolTip(wxToolTip *tip);
|
||||
|
@ -1013,29 +1013,28 @@ inline long wxSetWindowExStyle(const wxWindowMSW *win, long 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)
|
||||
// Common helper of wxUpdate{,Edit}LayoutDirection() below: sets or clears the
|
||||
// given flag(s) depending on wxLayoutDirection and returns true if the flags
|
||||
// really changed.
|
||||
inline bool
|
||||
wxUpdateExStyleForLayoutDirection(WXHWND hWnd,
|
||||
wxLayoutDirection dir,
|
||||
LONG_PTR flagsForRTL)
|
||||
{
|
||||
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;
|
||||
styleNew &= ~flagsForRTL;
|
||||
break;
|
||||
|
||||
case wxLayout_RightToLeft:
|
||||
styleNew |= EDIT_RTL_EX_FLAGS;
|
||||
styleNew |= flagsForRTL;
|
||||
break;
|
||||
|
||||
case wxLayout_Default:
|
||||
@ -1050,6 +1049,28 @@ inline bool wxUpdateEditLayoutDirection(WXHWND hWnd, wxLayoutDirection dir)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Update layout direction flag for a generic window.
|
||||
//
|
||||
// See below for the special version that must be used with EDIT controls.
|
||||
//
|
||||
// Returns true if the layout direction did change.
|
||||
inline bool wxUpdateLayoutDirection(WXHWND hWnd, wxLayoutDirection dir)
|
||||
{
|
||||
return wxUpdateExStyleForLayoutDirection(hWnd, dir, WS_EX_LAYOUTRTL);
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
return wxUpdateExStyleForLayoutDirection(hWnd, dir,
|
||||
WS_EX_RIGHT |
|
||||
WS_EX_RTLREADING |
|
||||
WS_EX_LEFTSCROLLBAR);
|
||||
}
|
||||
|
||||
// Companion of the above function checking if an EDIT control uses RTL.
|
||||
inline wxLayoutDirection wxGetEditLayoutDirection(WXHWND hWnd)
|
||||
{
|
||||
|
@ -707,4 +707,38 @@ wxWindow *wxComboBox::MSWFindItem(long id, WXHWND hWnd) const
|
||||
return wxChoice::MSWFindItem(id, hWnd);
|
||||
}
|
||||
|
||||
void wxComboBox::SetLayoutDirection(wxLayoutDirection dir)
|
||||
{
|
||||
#ifndef __WXWINCE__
|
||||
// Edit field and drop-down list must be handled explicitly.
|
||||
|
||||
// Edit field is a special EDIT control (e.g. it always returns null
|
||||
// extended style flags), so its layout direction should be set using the
|
||||
// same extended flag as for ordinary window but reset simply with
|
||||
// alignment flags.
|
||||
if ( dir == wxLayout_RightToLeft )
|
||||
{
|
||||
wxUpdateLayoutDirection(GetEditHWND(), dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
LONG_PTR style = ::GetWindowLongPtr(GetEditHWND(), GWL_STYLE);
|
||||
if ( !(style & ES_CENTER) )
|
||||
{
|
||||
style &= ~ES_RIGHT;
|
||||
::SetWindowLongPtr(GetEditHWND(), GWL_STYLE, style);
|
||||
}
|
||||
}
|
||||
|
||||
// Layout for the drop-down list also must be set explicitly.
|
||||
WinStruct<COMBOBOXINFO> info;
|
||||
if ( ::GetComboBoxInfo(GetHwnd(), &info) )
|
||||
{
|
||||
wxUpdateLayoutDirection(info.hwndList, dir);
|
||||
}
|
||||
#endif // !__WXWINCE__
|
||||
|
||||
wxChoice::SetLayoutDirection(dir);
|
||||
}
|
||||
|
||||
#endif // wxUSE_COMBOBOX
|
||||
|
@ -1135,31 +1135,8 @@ void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir)
|
||||
#ifdef __WXWINCE__
|
||||
wxUnusedVar(dir);
|
||||
#else
|
||||
wxCHECK_RET( GetHwnd(),
|
||||
wxT("layout direction must be set after window creation") );
|
||||
|
||||
LONG styleOld = wxGetWindowExStyle(this);
|
||||
|
||||
LONG styleNew = styleOld;
|
||||
switch ( dir )
|
||||
if ( wxUpdateLayoutDirection(GetHwnd(), dir) )
|
||||
{
|
||||
case wxLayout_LeftToRight:
|
||||
styleNew &= ~WS_EX_LAYOUTRTL;
|
||||
break;
|
||||
|
||||
case wxLayout_RightToLeft:
|
||||
styleNew |= WS_EX_LAYOUTRTL;
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG(wxT("unsupported layout direction"));
|
||||
break;
|
||||
}
|
||||
|
||||
if ( styleNew != styleOld )
|
||||
{
|
||||
wxSetWindowExStyle(this, styleNew);
|
||||
|
||||
// Update layout: whether we have children or are drawing something, we
|
||||
// need to redo it with the new layout.
|
||||
SendSizeEvent();
|
||||
|
Loading…
Reference in New Issue
Block a user