MSW: Fix dialog default positions under RTL locales
Toplevel windows use their parent's coordinate system as the reference frame, not desktop's, so need to be adjusted accordingly if its mirrored. Without these changes, default-positioned wxDialogs would end to the right side of the parent window's right border (instead of being slightly inside the window) and changing their size would move them as well.
This commit is contained in:
@@ -451,10 +451,11 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent,
|
|||||||
memset(dlgTemplate, 0, dlgsize);
|
memset(dlgTemplate, 0, dlgsize);
|
||||||
|
|
||||||
// these values are arbitrary, they won't be used normally anyhow
|
// these values are arbitrary, they won't be used normally anyhow
|
||||||
|
const LONG baseUnits = ::GetDialogBaseUnits();
|
||||||
dlgTemplate->x = 34;
|
dlgTemplate->x = 34;
|
||||||
dlgTemplate->y = 22;
|
dlgTemplate->y = 22;
|
||||||
dlgTemplate->cx = 144;
|
dlgTemplate->cx = ::MulDiv(sizeReal.x, 4, LOWORD(baseUnits));
|
||||||
dlgTemplate->cy = 75;
|
dlgTemplate->cy = ::MulDiv(sizeReal.y, 8, HIWORD(baseUnits));
|
||||||
|
|
||||||
// reuse the code in MSWGetStyle() but correct the results slightly for
|
// reuse the code in MSWGetStyle() but correct the results slightly for
|
||||||
// the dialog
|
// the dialog
|
||||||
|
@@ -1822,6 +1822,26 @@ wxWindowMSW::DoMoveSibling(WXHWND hwnd, int x, int y, int width, int height)
|
|||||||
|
|
||||||
// otherwise (or if deferring failed) move the window in place immediately
|
// otherwise (or if deferring failed) move the window in place immediately
|
||||||
#endif // wxUSE_DEFERRED_SIZING
|
#endif // wxUSE_DEFERRED_SIZING
|
||||||
|
|
||||||
|
// toplevel window's coordinates are mirrored if the TLW is a child of another
|
||||||
|
// RTL window and changing width without moving the position would enlarge the
|
||||||
|
// window in the wrong direction, so we need to adjust for it
|
||||||
|
if ( IsTopLevel() )
|
||||||
|
{
|
||||||
|
// note that this may be different from GetParent() for wxDialogs
|
||||||
|
HWND tlwParent = ::GetParent((HWND)hwnd);
|
||||||
|
if ( tlwParent && (::GetWindowLong(tlwParent, GWL_EXSTYLE) & WS_EX_LAYOUTRTL) != 0 )
|
||||||
|
{
|
||||||
|
RECT old;
|
||||||
|
::GetWindowRect((HWND) hwnd, &old);
|
||||||
|
if ( old.left == x && old.right - old.left != width )
|
||||||
|
{
|
||||||
|
x -= width - (old.right - old.left);
|
||||||
|
}
|
||||||
|
// else: not a simple resize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( !::MoveWindow((HWND)hwnd, x, y, width, height, IsShown()) )
|
if ( !::MoveWindow((HWND)hwnd, x, y, width, height, IsShown()) )
|
||||||
{
|
{
|
||||||
wxLogLastError(wxT("MoveWindow"));
|
wxLogLastError(wxT("MoveWindow"));
|
||||||
@@ -1967,10 +1987,25 @@ void wxWindowMSW::DoSetClientSize(int width, int height)
|
|||||||
const int widthWin = rectWin.right - rectWin.left,
|
const int widthWin = rectWin.right - rectWin.left,
|
||||||
heightWin = rectWin.bottom - rectWin.top;
|
heightWin = rectWin.bottom - rectWin.top;
|
||||||
|
|
||||||
|
if ( IsTopLevel() )
|
||||||
|
{
|
||||||
|
// toplevel window's coordinates are mirrored if the TLW is a child of another
|
||||||
|
// RTL window and changing width without moving the position would enlarge the
|
||||||
|
// window in the wrong direction, so we need to adjust for it
|
||||||
|
|
||||||
|
// note that this may be different from GetParent() for wxDialogs
|
||||||
|
HWND tlwParent = ::GetParent(GetHwnd());
|
||||||
|
if ( tlwParent && (::GetWindowLong(tlwParent, GWL_EXSTYLE) & WS_EX_LAYOUTRTL) != 0 )
|
||||||
|
{
|
||||||
|
const int diffWidth = width - (rectClient.right - rectClient.left);
|
||||||
|
rectWin.left -= diffWidth;
|
||||||
|
rectWin.right -= diffWidth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// MoveWindow positions the child windows relative to the parent, so
|
// MoveWindow positions the child windows relative to the parent, so
|
||||||
// adjust if necessary
|
// adjust if necessary
|
||||||
if ( !IsTopLevel() )
|
|
||||||
{
|
|
||||||
wxWindow *parent = GetParent();
|
wxWindow *parent = GetParent();
|
||||||
if ( parent )
|
if ( parent )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user