Reposition wxSpinCtrl correctly after reparenting it in wxMSW.
The position of wxSpinCtrl after reparenting was wrong because we didn't remember the old position early enough. There also was a more minor bug which resulted in the position not being set correctly if (any of its components) was -1 before reparenting. Closes #12633. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65966 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -594,16 +594,15 @@ bool wxSpinCtrl::Reparent(wxWindowBase *newParent)
|
|||||||
// window normally, but we recreate the updown control and reassign its
|
// window normally, but we recreate the updown control and reassign its
|
||||||
// buddy.
|
// buddy.
|
||||||
|
|
||||||
|
// Get the position before changing the parent as it would be offset after
|
||||||
|
// changing it.
|
||||||
|
const wxRect rect = GetRect();
|
||||||
|
|
||||||
if ( !wxWindowBase::Reparent(newParent) )
|
if ( !wxWindowBase::Reparent(newParent) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
newParent->GetChildren().DeleteObject(this);
|
newParent->GetChildren().DeleteObject(this);
|
||||||
|
|
||||||
// preserve the old values
|
|
||||||
const wxSize size = GetSize();
|
|
||||||
int value = GetValue();
|
|
||||||
const wxRect btnRect = wxRectFromRECT(wxGetWindowRect(GetHwnd()));
|
|
||||||
|
|
||||||
// destroy the old spin button after detaching it from this wxWindow object
|
// destroy the old spin button after detaching it from this wxWindow object
|
||||||
// (notice that m_hWnd will be reset by UnsubclassWin() so save it first)
|
// (notice that m_hWnd will be reset by UnsubclassWin() so save it first)
|
||||||
const HWND hwndOld = GetHwnd();
|
const HWND hwndOld = GetHwnd();
|
||||||
@@ -615,13 +614,17 @@ bool wxSpinCtrl::Reparent(wxWindowBase *newParent)
|
|||||||
|
|
||||||
// create and initialize the new one
|
// create and initialize the new one
|
||||||
if ( !wxSpinButton::Create(GetParent(), GetId(),
|
if ( !wxSpinButton::Create(GetParent(), GetId(),
|
||||||
btnRect.GetPosition(), btnRect.GetSize(),
|
rect.GetPosition(), rect.GetSize(),
|
||||||
GetWindowStyle(), GetName()) )
|
GetWindowStyle(), GetName()) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SetValue(value);
|
// reapply our values to wxSpinButton
|
||||||
|
wxSpinButton::SetValue(GetValue());
|
||||||
SetRange(m_min, m_max);
|
SetRange(m_min, m_max);
|
||||||
SetInitialSize(size);
|
|
||||||
|
// also set the size again with wxSIZE_ALLOW_MINUS_ONE flag: this is
|
||||||
|
// necessary if our original position used -1 for either x or y
|
||||||
|
SetSize(rect, wxSIZE_ALLOW_MINUS_ONE);
|
||||||
|
|
||||||
// associate it with the buddy control again
|
// associate it with the buddy control again
|
||||||
::SetParent(GetBuddyHwnd(), GetHwndOf(GetParent()));
|
::SetParent(GetBuddyHwnd(), GetHwndOf(GetParent()));
|
||||||
|
Reference in New Issue
Block a user