From: Vadim Zeitlin Date: Wed, 27 Mar 2013 23:10:25 +0000 (+0000) Subject: Fix assert when constructing invalid wxGBSpan inside wxWidgets itself. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/46e2a1b8c21b4a2f3675153d029be1e57fc11d76 Fix assert when constructing invalid wxGBSpan inside wxWidgets itself. Various wxGridBagSizer methods returning wxGBSpan asserted when trying to construct an invalid wxGBSpan as its components must now (since r66964) be positive. Fix this by adding a special new method to wxGBSpan for constructing such invalid spans and use it now. Closes #15124. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73731 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gbsizer.h b/include/wx/gbsizer.h index 9ee4d48635..d9120a607b 100644 --- a/include/wx/gbsizer.h +++ b/include/wx/gbsizer.h @@ -67,6 +67,14 @@ public: // default copy ctor and assignment operator are okay. + // Factor constructor creating an invalid wxGBSpan: this is mostly supposed + // to be used as return value for functions returning wxGBSpan in case of + // errors. + static wxGBSpan Invalid() + { + return wxGBSpan(NULL); + } + int GetRowspan() const { return m_rowspan; } int GetColspan() const { return m_colspan; } void SetRowspan(int rowspan) @@ -87,6 +95,13 @@ public: bool operator!=(const wxGBSpan& o) const { return !(*this == o); } private: + // This private ctor is used by Invalid() only. + wxGBSpan(struct InvalidCtorTag*) + { + m_rowspan = + m_colspan = -1; + } + void Init() { m_rowspan = diff --git a/src/common/gbsizer.cpp b/src/common/gbsizer.cpp index 773c0f0ebc..7f91a1c40d 100644 --- a/src/common/gbsizer.cpp +++ b/src/common/gbsizer.cpp @@ -312,27 +312,24 @@ bool wxGridBagSizer::SetItemPosition(size_t index, const wxGBPosition& pos) wxGBSpan wxGridBagSizer::GetItemSpan(wxWindow *window) { - wxGBSpan badspan(-1,-1); wxGBSizerItem* item = FindItem(window); - wxCHECK_MSG( item, badspan, wxT("Failed to find item.") ); + wxCHECK_MSG( item, wxGBSpan::Invalid(), wxT("Failed to find item.") ); return item->GetSpan(); } wxGBSpan wxGridBagSizer::GetItemSpan(wxSizer *sizer) { - wxGBSpan badspan(-1,-1); wxGBSizerItem* item = FindItem(sizer); - wxCHECK_MSG( item, badspan, wxT("Failed to find item.") ); + wxCHECK_MSG( item, wxGBSpan::Invalid(), wxT("Failed to find item.") ); return item->GetSpan(); } wxGBSpan wxGridBagSizer::GetItemSpan(size_t index) { - wxGBSpan badspan(-1,-1); wxSizerItemList::compatibility_iterator node = m_children.Item( index ); - wxCHECK_MSG( node, badspan, wxT("Failed to find item.") ); + wxCHECK_MSG( node, wxGBSpan::Invalid(), wxT("Failed to find item.") ); wxGBSizerItem* item = (wxGBSizerItem*)node->GetData(); return item->GetSpan(); }