implement wxSpinCtrl::Reparent() to properly reparent both the spin button and the text control part (slightly modified patch 1914190)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52543 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -288,6 +288,7 @@ All (GUI):
|
|||||||
- Added wxWindow::HasFocus().
|
- Added wxWindow::HasFocus().
|
||||||
- Added wxGLCanvas::IsDisplaySupported().
|
- Added wxGLCanvas::IsDisplaySupported().
|
||||||
- Added wxApp::SetNativeTheme() (Stefan H.).
|
- Added wxApp::SetNativeTheme() (Stefan H.).
|
||||||
|
- Made wxSpinCtrl::Reparent() in MSW and generic versions (Angelo Mottola)
|
||||||
|
|
||||||
wxGTK:
|
wxGTK:
|
||||||
|
|
||||||
|
@@ -74,6 +74,7 @@ public:
|
|||||||
// forward these functions to all subcontrols
|
// forward these functions to all subcontrols
|
||||||
virtual bool Enable(bool enable = true);
|
virtual bool Enable(bool enable = true);
|
||||||
virtual bool Show(bool show = true);
|
virtual bool Show(bool show = true);
|
||||||
|
virtual bool Reparent(wxWindow *newParent);
|
||||||
|
|
||||||
// get the subcontrols
|
// get the subcontrols
|
||||||
wxTextCtrl *GetText() const { return m_text; }
|
wxTextCtrl *GetText() const { return m_text; }
|
||||||
|
@@ -73,6 +73,8 @@ public:
|
|||||||
virtual bool Enable(bool enable = true);
|
virtual bool Enable(bool enable = true);
|
||||||
virtual bool Show(bool show = true);
|
virtual bool Show(bool show = true);
|
||||||
|
|
||||||
|
virtual bool Reparent(wxWindowBase *newParent);
|
||||||
|
|
||||||
// wxSpinButton doesn't accept focus, but we do
|
// wxSpinButton doesn't accept focus, but we do
|
||||||
virtual bool AcceptsFocus() const { return wxWindow::AcceptsFocus(); }
|
virtual bool AcceptsFocus() const { return wxWindow::AcceptsFocus(); }
|
||||||
|
|
||||||
|
@@ -265,6 +265,17 @@ bool wxSpinCtrl::Show(bool show)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxSpinCtrl::Reparent(wxWindow *newParent)
|
||||||
|
{
|
||||||
|
if ( m_btn )
|
||||||
|
{
|
||||||
|
m_btn->Reparent(newParent);
|
||||||
|
m_text->Reparent(newParent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// value and range access
|
// value and range access
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -537,6 +537,46 @@ bool wxSpinCtrl::Show(bool show)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxSpinCtrl::Reparent(wxWindowBase *newParent)
|
||||||
|
{
|
||||||
|
// Reparenting both the updown control and its buddy does not seem to work:
|
||||||
|
// they continue to be connected somehow, but visually there is no feedback
|
||||||
|
// on the buddy edit control. To avoid this problem, we reparent the buddy
|
||||||
|
// window normally, but we recreate the updown control and reassign its
|
||||||
|
// buddy.
|
||||||
|
|
||||||
|
if ( !wxWindowBase::Reparent(newParent) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
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
|
||||||
|
UnsubclassWin();
|
||||||
|
if ( !::DestroyWindow(GetHwnd()) )
|
||||||
|
wxLogLastError(wxT("DestroyWindow"));
|
||||||
|
|
||||||
|
// create and initialize the new one
|
||||||
|
if ( !wxSpinButton::Create(GetParent(), GetId(),
|
||||||
|
btnRect.GetPosition(), btnRect.GetSize(),
|
||||||
|
GetWindowStyle(), GetName()) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
SetValue(value);
|
||||||
|
SetRange(m_min, m_max);
|
||||||
|
SetInitialSize(size);
|
||||||
|
|
||||||
|
// associate it with the buddy control again
|
||||||
|
::SetParent(GetBuddyHwnd(), GetHwndOf(GetParent()));
|
||||||
|
(void)::SendMessage(GetHwnd(), UDM_SETBUDDY, (WPARAM)GetBuddyHwnd(), 0);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool wxSpinCtrl::Enable(bool enable)
|
bool wxSpinCtrl::Enable(bool enable)
|
||||||
{
|
{
|
||||||
if ( !wxControl::Enable(enable) )
|
if ( !wxControl::Enable(enable) )
|
||||||
|
Reference in New Issue
Block a user