Fix GetBestSize() for hidden controls in wxGTK

gtk_widget_get_preferred_size() return zero size if the GTK widget is
hidden, so show it temporarily in order to find its real preferred size.

Add a unit test checking that the best size of a hidden wxChoice is now
determined correctly.

Closes https://github.com/wxWidgets/wxWidgets/pull/1587
This commit is contained in:
Ilya Sinitsyn
2019-10-03 22:22:44 +07:00
committed by Vadim Zeitlin
parent 612634fffd
commit 85b37bea49
2 changed files with 43 additions and 0 deletions

View File

@@ -36,9 +36,11 @@ private:
CPPUNIT_TEST_SUITE( ChoiceTestCase );
wxITEM_CONTAINER_TESTS();
CPPUNIT_TEST( Sort );
CPPUNIT_TEST( GetBestSize );
CPPUNIT_TEST_SUITE_END();
void Sort();
void GetBestSize();
wxChoice* m_choice;
@@ -89,4 +91,33 @@ void ChoiceTestCase::Sort()
#endif
}
void ChoiceTestCase::GetBestSize()
{
wxArrayString testitems;
testitems.Add("1");
testitems.Add("11");
m_choice->Append(testitems);
SECTION("Normal best size")
{
// nothing to do here
}
// Ensure that the hidden control return a valid best size too.
SECTION("Hidden best size")
{
m_choice->Hide();
}
wxYield();
m_choice->InvalidateBestSize();
const wxSize bestSize = m_choice->GetBestSize();
CHECK(bestSize.GetWidth() > m_choice->FromDIP(30));
CHECK(bestSize.GetWidth() < m_choice->FromDIP(120));
CHECK(bestSize.GetHeight() > m_choice->FromDIP(15));
CHECK(bestSize.GetHeight() < m_choice->FromDIP(35));
}
#endif //wxUSE_CHOICE