diff --git a/interface/wx/window.h b/interface/wx/window.h index 6f2df316f8..93f603c50a 100644 --- a/interface/wx/window.h +++ b/interface/wx/window.h @@ -1493,9 +1493,14 @@ public: void SetClientSize(const wxRect& rect); /** - This normally does not need to be called by user code. - It is called when a window is added to a sizer, and is used so the window - can remove itself from the sizer when it is destroyed. + Used by wxSizer internally to notify the window about being managed by + the given sizer. + + This method should not be called from outside the library, unless + you're implementing a custom sizer class -- and in the latter case you + must call this method with the pointer to the sizer itself whenever a + window is added to it and with @NULL argument when the window is + removed from it. */ void SetContainingSizer(wxSizer* sizer); diff --git a/tests/controls/windowtest.cpp b/tests/controls/windowtest.cpp index 926c6cafd7..a9ff914f5d 100644 --- a/tests/controls/windowtest.cpp +++ b/tests/controls/windowtest.cpp @@ -26,6 +26,7 @@ #include "wx/uiaction.h" #include "wx/caret.h" #include "wx/cshelp.h" +#include "wx/scopedptr.h" #include "wx/tooltip.h" class WindowTestCase @@ -379,3 +380,19 @@ TEST_CASE_METHOD(WindowTestCase, "Window::FindWindowBy", "[window]") CHECK( wxWindow::FindWindowByName("noname") == NULL ); CHECK( wxWindow::FindWindowByLabel("nolabel") == NULL ); } + +TEST_CASE_METHOD(WindowTestCase, "Window::SizerErrors", "[window][sizer][error]") +{ + wxWindow* const child = new wxWindow(m_window, wxID_ANY); + wxScopedPtr const sizer1(new wxBoxSizer(wxHORIZONTAL)); + wxScopedPtr const sizer2(new wxBoxSizer(wxHORIZONTAL)); + + REQUIRE_NOTHROW( sizer1->Add(child) ); + CHECK_THROWS_AS( sizer1->Add(child), TestAssertFailure ); + CHECK_THROWS_AS( sizer2->Add(child), TestAssertFailure ); + + CHECK_NOTHROW( sizer1->Detach(child) ); + CHECK_NOTHROW( sizer2->Add(child) ); + + REQUIRE_NOTHROW( delete child ); +}