X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5d3e7b52d84580c28df8f754b81363502f917ac7..1f0acb435592470b421b80df854fbbb08cd2853f:/include/wx/gbsizer.h?ds=sidebyside diff --git a/include/wx/gbsizer.h b/include/wx/gbsizer.h index 54b03abe35..f0012b7a44 100644 --- a/include/wx/gbsizer.h +++ b/include/wx/gbsizer.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: gbsizer.h +// Name: wx/gbsizer.h // Purpose: wxGridBagSizer: A sizer that can lay out items in a grid, // with items at specified cells, and with the option of row // and/or column spanning @@ -14,10 +14,6 @@ #ifndef __WXGBSIZER_H__ #define __WXGBSIZER_H__ -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma interface "gbsizer.h" -#endif - #include "wx/sizer.h" @@ -32,7 +28,7 @@ // is used for this and also for wxGridCellCoords. //--------------------------------------------------------------------------- -class WXDLLEXPORT wxGBPosition +class WXDLLIMPEXP_CORE wxGBPosition { public: wxGBPosition() : m_row(0), m_col(0) {} @@ -54,39 +50,65 @@ private: }; -class WXDLLEXPORT wxGBSpan +class WXDLLIMPEXP_CORE wxGBSpan { public: - wxGBSpan() : m_rowspan(1), m_colspan(1) {} - wxGBSpan(int rowspan, int colspan) : m_rowspan(rowspan), m_colspan(colspan) {} + wxGBSpan() { Init(); } + wxGBSpan(int rowspan, int colspan) + { + // Initialize the members to valid values as not doing it may result in + // infinite loop in wxGBSizer code if the user passed 0 for any of + // them, see #12934. + Init(); + + SetRowspan(rowspan); + SetColspan(colspan); + } // default copy ctor and assignment operator are okay. int GetRowspan() const { return m_rowspan; } int GetColspan() const { return m_colspan; } - void SetRowspan(int rowspan) { m_rowspan = rowspan; } - void SetColspan(int colspan) { m_colspan = colspan; } + void SetRowspan(int rowspan) + { + wxCHECK_RET( rowspan > 0, "Row span should be strictly positive" ); + + m_rowspan = rowspan; + } + + void SetColspan(int colspan) + { + wxCHECK_RET( colspan > 0, "Column span should be strictly positive" ); + + m_colspan = colspan; + } bool operator==(const wxGBSpan& o) const { return m_rowspan == o.m_rowspan && m_colspan == o.m_colspan; } bool operator!=(const wxGBSpan& o) const { return !(*this == o); } private: + void Init() + { + m_rowspan = + m_colspan = 1; + } + int m_rowspan; int m_colspan; }; -WXDLLEXPORT_DATA(extern const wxGBSpan) wxDefaultSpan; +extern WXDLLIMPEXP_DATA_CORE(const wxGBSpan) wxDefaultSpan; //--------------------------------------------------------------------------- // wxGBSizerItem //--------------------------------------------------------------------------- -class WXDLLEXPORT wxGridBagSizer; +class WXDLLIMPEXP_FWD_CORE wxGridBagSizer; -class WXDLLEXPORT wxGBSizerItem : public wxSizerItem +class WXDLLIMPEXP_CORE wxGBSizerItem : public wxSizerItem { public: // spacer @@ -138,7 +160,7 @@ public: // is successful and after the next Layout the item will be resized. bool SetSpan( const wxGBSpan& span ); - // Returns true if this item and the other item instersect + // Returns true if this item and the other item intersect bool Intersects(const wxGBSizerItem& other); // Returns true if the given pos/span would intersect with this item. @@ -160,7 +182,7 @@ protected: private: DECLARE_DYNAMIC_CLASS(wxGBSizerItem) - DECLARE_NO_COPY_CLASS(wxGBSizerItem) + wxDECLARE_NO_COPY_CLASS(wxGBSizerItem); }; @@ -169,33 +191,33 @@ private: //--------------------------------------------------------------------------- -class WXDLLEXPORT wxGridBagSizer : public wxFlexGridSizer +class WXDLLIMPEXP_CORE wxGridBagSizer : public wxFlexGridSizer { public: wxGridBagSizer(int vgap = 0, int hgap = 0 ); // The Add methods return true if the item was successfully placed at the // given position, false if something was already there. - bool Add( wxWindow *window, - const wxGBPosition& pos, - const wxGBSpan& span = wxDefaultSpan, - int flag = 0, - int border = 0, - wxObject* userData = NULL ); - bool Add( wxSizer *sizer, - const wxGBPosition& pos, - const wxGBSpan& span = wxDefaultSpan, - int flag = 0, - int border = 0, - wxObject* userData = NULL ); - bool Add( int width, - int height, - const wxGBPosition& pos, - const wxGBSpan& span = wxDefaultSpan, - int flag = 0, - int border = 0, - wxObject* userData = NULL ); - bool Add( wxGBSizerItem *item ); + wxSizerItem* Add( wxWindow *window, + const wxGBPosition& pos, + const wxGBSpan& span = wxDefaultSpan, + int flag = 0, + int border = 0, + wxObject* userData = NULL ); + wxSizerItem* Add( wxSizer *sizer, + const wxGBPosition& pos, + const wxGBSpan& span = wxDefaultSpan, + int flag = 0, + int border = 0, + wxObject* userData = NULL ); + wxSizerItem* Add( int width, + int height, + const wxGBPosition& pos, + const wxGBSpan& span = wxDefaultSpan, + int flag = 0, + int border = 0, + wxObject* userData = NULL ); + wxSizerItem* Add( wxGBSizerItem *item ); // Get/Set the size used for cells in the grid with no item. @@ -270,26 +292,27 @@ public: // The Add base class virtuals should not be used with this class, but // we'll try to make them automatically select a location for the item // anyway. - virtual void Add( wxWindow *window, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); - virtual void Add( wxSizer *sizer, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); - virtual void Add( int width, int height, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); + virtual wxSizerItem* Add( wxWindow *window, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); + virtual wxSizerItem* Add( wxSizer *sizer, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); + virtual wxSizerItem* Add( int width, int height, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); // The Insert and Prepend base class virtuals that are not appropriate for // this class and should not be used. Their implementation in this class // simply fails. - virtual void Add( wxSizerItem *item ); - virtual void Insert( size_t index, wxWindow *window, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); - virtual void Insert( size_t index, wxSizer *sizer, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); - virtual void Insert( size_t index, int width, int height, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); - virtual void Insert( size_t index, wxSizerItem *item ); - virtual void Prepend( wxWindow *window, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); - virtual void Prepend( wxSizer *sizer, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); - virtual void Prepend( int width, int height, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); - virtual void Prepend( wxSizerItem *item ); + virtual wxSizerItem* Add( wxSizerItem *item ); + virtual wxSizerItem* Insert( size_t index, wxWindow *window, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); + virtual wxSizerItem* Insert( size_t index, wxSizer *sizer, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); + virtual wxSizerItem* Insert( size_t index, int width, int height, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); + virtual wxSizerItem* Insert( size_t index, wxSizerItem *item ); + virtual wxSizerItem* Prepend( wxWindow *window, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); + virtual wxSizerItem* Prepend( wxSizer *sizer, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); + virtual wxSizerItem* Prepend( int width, int height, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); + virtual wxSizerItem* Prepend( wxSizerItem *item ); protected: wxGBPosition FindEmptyCell(); + void AdjustForOverflow(); wxSize m_emptyCellSize; @@ -297,7 +320,7 @@ protected: private: DECLARE_CLASS(wxGridBagSizer) - DECLARE_NO_COPY_CLASS(wxGridBagSizer) + wxDECLARE_NO_COPY_CLASS(wxGridBagSizer); }; //---------------------------------------------------------------------------