]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gbsizer.h
remove DoSetSize override, unneeded after r72001
[wxWidgets.git] / include / wx / gbsizer.h
CommitLineData
20b35a69 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: wx/gbsizer.h
20b35a69
RD
3// Purpose: wxGridBagSizer: A sizer that can lay out items in a grid,
4// with items at specified cells, and with the option of row
5// and/or column spanning
6//
7// Author: Robin Dunn
8// Created: 03-Nov-2003
9// RCS-ID: $Id$
10// Copyright: (c) Robin Dunn
65571936 11// Licence: wxWindows licence
20b35a69
RD
12/////////////////////////////////////////////////////////////////////////////
13
14#ifndef __WXGBSIZER_H__
15#define __WXGBSIZER_H__
16
20b35a69
RD
17#include "wx/sizer.h"
18
19
20//---------------------------------------------------------------------------
21// Classes to represent a position in the grid and a size of an item in the
22// grid, IOW, the number of rows and columns it occupies. I chose to use these
23// instead of wxPoint and wxSize because they are (x,y) and usually pixel
3ac7b44c
RD
24// oriented while grids and tables are usually thought of as (row,col) so some
25// confusion would definitely result in using wxPoint...
5d3e7b52 26//
20b35a69
RD
27// NOTE: This should probably be refactored to a common RowCol data type which
28// is used for this and also for wxGridCellCoords.
29//---------------------------------------------------------------------------
30
53a2db12 31class WXDLLIMPEXP_CORE wxGBPosition
20b35a69
RD
32{
33public:
34 wxGBPosition() : m_row(0), m_col(0) {}
35 wxGBPosition(int row, int col) : m_row(row), m_col(col) {}
36
37 // default copy ctor and assignment operator are okay.
38
39 int GetRow() const { return m_row; }
40 int GetCol() const { return m_col; }
41 void SetRow(int row) { m_row = row; }
42 void SetCol(int col) { m_col = col; }
5d3e7b52 43
20b35a69
RD
44 bool operator==(const wxGBPosition& p) const { return m_row == p.m_row && m_col == p.m_col; }
45 bool operator!=(const wxGBPosition& p) const { return !(*this == p); }
46
47private:
48 int m_row;
49 int m_col;
50};
51
52
53a2db12 53class WXDLLIMPEXP_CORE wxGBSpan
20b35a69
RD
54{
55public:
1b3b63ed
VZ
56 wxGBSpan() { Init(); }
57 wxGBSpan(int rowspan, int colspan)
58 {
59 // Initialize the members to valid values as not doing it may result in
60 // infinite loop in wxGBSizer code if the user passed 0 for any of
61 // them, see #12934.
62 Init();
63
64 SetRowspan(rowspan);
65 SetColspan(colspan);
66 }
20b35a69
RD
67
68 // default copy ctor and assignment operator are okay.
69
70 int GetRowspan() const { return m_rowspan; }
71 int GetColspan() const { return m_colspan; }
1b3b63ed
VZ
72 void SetRowspan(int rowspan)
73 {
74 wxCHECK_RET( rowspan > 0, "Row span should be strictly positive" );
75
76 m_rowspan = rowspan;
77 }
78
79 void SetColspan(int colspan)
80 {
81 wxCHECK_RET( colspan > 0, "Column span should be strictly positive" );
82
83 m_colspan = colspan;
84 }
5d3e7b52 85
20b35a69
RD
86 bool operator==(const wxGBSpan& o) const { return m_rowspan == o.m_rowspan && m_colspan == o.m_colspan; }
87 bool operator!=(const wxGBSpan& o) const { return !(*this == o); }
88
89private:
1b3b63ed
VZ
90 void Init()
91 {
92 m_rowspan =
93 m_colspan = 1;
94 }
95
20b35a69
RD
96 int m_rowspan;
97 int m_colspan;
98};
99
5d3e7b52 100
53a2db12 101extern WXDLLIMPEXP_DATA_CORE(const wxGBSpan) wxDefaultSpan;
20b35a69
RD
102
103
104//---------------------------------------------------------------------------
105// wxGBSizerItem
106//---------------------------------------------------------------------------
107
b5dbe15d 108class WXDLLIMPEXP_FWD_CORE wxGridBagSizer;
20b35a69
RD
109
110
53a2db12 111class WXDLLIMPEXP_CORE wxGBSizerItem : public wxSizerItem
20b35a69
RD
112{
113public:
114 // spacer
115 wxGBSizerItem( int width,
116 int height,
117 const wxGBPosition& pos,
5eb16fe2
RD
118 const wxGBSpan& span=wxDefaultSpan,
119 int flag=0,
120 int border=0,
121 wxObject* userData=NULL);
20b35a69
RD
122
123 // window
124 wxGBSizerItem( wxWindow *window,
125 const wxGBPosition& pos,
5eb16fe2
RD
126 const wxGBSpan& span=wxDefaultSpan,
127 int flag=0,
128 int border=0,
129 wxObject* userData=NULL );
20b35a69
RD
130
131 // subsizer
132 wxGBSizerItem( wxSizer *sizer,
133 const wxGBPosition& pos,
5eb16fe2
RD
134 const wxGBSpan& span=wxDefaultSpan,
135 int flag=0,
136 int border=0,
137 wxObject* userData=NULL );
20b35a69 138
1b52f7ab
RD
139 // default ctor
140 wxGBSizerItem();
141
5d3e7b52 142
20b35a69
RD
143 // Get the grid position of the item
144 wxGBPosition GetPos() const { return m_pos; }
145 void GetPos(int& row, int& col) const;
146
147 // Get the row and column spanning of the item
148 wxGBSpan GetSpan() const { return m_span; }
149 void GetSpan(int& rowspan, int& colspan) const;
150
151 // If the item is already a member of a sizer then first ensure that there
152 // is no other item that would intersect with this one at the new
153 // position, then set the new position. Returns true if the change is
154 // successful and after the next Layout the item will be moved.
155 bool SetPos( const wxGBPosition& pos );
156
157 // If the item is already a member of a sizer then first ensure that there
158 // is no other item that would intersect with this one with its new
159 // spanning size, then set the new spanning. Returns true if the change
160 // is successful and after the next Layout the item will be resized.
161 bool SetSpan( const wxGBSpan& span );
162
d13b34d3 163 // Returns true if this item and the other item intersect
20b35a69
RD
164 bool Intersects(const wxGBSizerItem& other);
165
166 // Returns true if the given pos/span would intersect with this item.
167 bool Intersects(const wxGBPosition& pos, const wxGBSpan& span);
168
169 // Get the row and column of the endpoint of this item
170 void GetEndPos(int& row, int& col);
171
5d3e7b52 172
3ff632ce
RD
173 wxGridBagSizer* GetGBSizer() const { return m_gbsizer; }
174 void SetGBSizer(wxGridBagSizer* sizer) { m_gbsizer = sizer; }
5d3e7b52
WS
175
176
20b35a69
RD
177protected:
178 wxGBPosition m_pos;
179 wxGBSpan m_span;
3ff632ce 180 wxGridBagSizer* m_gbsizer; // so SetPos/SetSpan can check for intersects
20b35a69 181
5d3e7b52
WS
182
183private:
1b52f7ab 184 DECLARE_DYNAMIC_CLASS(wxGBSizerItem)
c0c133e1 185 wxDECLARE_NO_COPY_CLASS(wxGBSizerItem);
20b35a69
RD
186};
187
188
189//---------------------------------------------------------------------------
190// wxGridBagSizer
191//---------------------------------------------------------------------------
192
193
53a2db12 194class WXDLLIMPEXP_CORE wxGridBagSizer : public wxFlexGridSizer
20b35a69
RD
195{
196public:
197 wxGridBagSizer(int vgap = 0, int hgap = 0 );
198
199 // The Add methods return true if the item was successfully placed at the
200 // given position, false if something was already there.
56eee37f
WS
201 wxSizerItem* Add( wxWindow *window,
202 const wxGBPosition& pos,
203 const wxGBSpan& span = wxDefaultSpan,
204 int flag = 0,
205 int border = 0,
206 wxObject* userData = NULL );
207 wxSizerItem* Add( wxSizer *sizer,
208 const wxGBPosition& pos,
209 const wxGBSpan& span = wxDefaultSpan,
210 int flag = 0,
211 int border = 0,
212 wxObject* userData = NULL );
213 wxSizerItem* Add( int width,
214 int height,
215 const wxGBPosition& pos,
216 const wxGBSpan& span = wxDefaultSpan,
217 int flag = 0,
218 int border = 0,
219 wxObject* userData = NULL );
220 wxSizerItem* Add( wxGBSizerItem *item );
20b35a69
RD
221
222
223 // Get/Set the size used for cells in the grid with no item.
224 wxSize GetEmptyCellSize() const { return m_emptyCellSize; }
225 void SetEmptyCellSize(const wxSize& sz) { m_emptyCellSize = sz; }
226
6217b9aa
RD
227 // Get the size of the specified cell, including hgap and vgap. Only
228 // valid after a Layout.
229 wxSize GetCellSize(int row, int col) const;
5d3e7b52 230
20b35a69
RD
231 // Get the grid position of the specified item (non-recursive)
232 wxGBPosition GetItemPosition(wxWindow *window);
233 wxGBPosition GetItemPosition(wxSizer *sizer);
234 wxGBPosition GetItemPosition(size_t index);
235
236 // Set the grid position of the specified item. Returns true on success.
237 // If the move is not allowed (because an item is already there) then
238 // false is returned. (non-recursive)
239 bool SetItemPosition(wxWindow *window, const wxGBPosition& pos);
240 bool SetItemPosition(wxSizer *sizer, const wxGBPosition& pos);
241 bool SetItemPosition(size_t index, const wxGBPosition& pos);
242
243 // Get the row/col spanning of the specified item (non-recursive)
244 wxGBSpan GetItemSpan(wxWindow *window);
245 wxGBSpan GetItemSpan(wxSizer *sizer);
246 wxGBSpan GetItemSpan(size_t index);
247
248 // Set the row/col spanning of the specified item. Returns true on
249 // success. If the move is not allowed (because an item is already there)
250 // then false is returned. (non-recursive)
251 bool SetItemSpan(wxWindow *window, const wxGBSpan& span);
252 bool SetItemSpan(wxSizer *sizer, const wxGBSpan& span);
253 bool SetItemSpan(size_t index, const wxGBSpan& span);
5d3e7b52 254
20b35a69
RD
255
256 // Find the sizer item for the given window or subsizer, returns NULL if
257 // not found. (non-recursive)
258 wxGBSizerItem* FindItem(wxWindow* window);
259 wxGBSizerItem* FindItem(wxSizer* sizer);
260
5d3e7b52 261
20b35a69
RD
262 // Return the sizer item for the given grid cell, or NULL if there is no
263 // item at that position. (non-recursive)
264 wxGBSizerItem* FindItemAtPosition(const wxGBPosition& pos);
265
5d3e7b52 266
3ac7b44c
RD
267 // Return the sizer item located at the point given in pt, or NULL if
268 // there is no item at that point. The (x,y) coordinates in pt correspond
269 // to the client coordinates of the window using the sizer for
270 // layout. (non-recursive)
271 wxGBSizerItem* FindItemAtPoint(const wxPoint& pt);
272
5d3e7b52 273
20b35a69
RD
274 // Return the sizer item that has a matching user data (it only compares
275 // pointer values) or NULL if not found. (non-recursive)
276 wxGBSizerItem* FindItemWithData(const wxObject* userData);
277
5d3e7b52 278
20b35a69
RD
279 // These are what make the sizer do size calculations and layout
280 virtual void RecalcSizes();
281 virtual wxSize CalcMin();
282
283
284 // Look at all items and see if any intersect (or would overlap) the given
285 // item. Returns true if so, false if there would be no overlap. If an
286 // excludeItem is given then it will not be checked for intersection, for
287 // example it may be the item we are checking the position of.
288 bool CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem = NULL);
289 bool CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem = NULL);
290
5d3e7b52 291
20b35a69
RD
292 // The Add base class virtuals should not be used with this class, but
293 // we'll try to make them automatically select a location for the item
294 // anyway.
56eee37f
WS
295 virtual wxSizerItem* Add( wxWindow *window, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
296 virtual wxSizerItem* Add( wxSizer *sizer, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
297 virtual wxSizerItem* Add( int width, int height, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
20b35a69
RD
298
299 // The Insert and Prepend base class virtuals that are not appropriate for
300 // this class and should not be used. Their implementation in this class
301 // simply fails.
56eee37f
WS
302 virtual wxSizerItem* Add( wxSizerItem *item );
303 virtual wxSizerItem* Insert( size_t index, wxWindow *window, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
304 virtual wxSizerItem* Insert( size_t index, wxSizer *sizer, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
305 virtual wxSizerItem* Insert( size_t index, int width, int height, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
306 virtual wxSizerItem* Insert( size_t index, wxSizerItem *item );
307 virtual wxSizerItem* Prepend( wxWindow *window, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
308 virtual wxSizerItem* Prepend( wxSizer *sizer, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
309 virtual wxSizerItem* Prepend( int width, int height, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
310 virtual wxSizerItem* Prepend( wxSizerItem *item );
20b35a69 311
5d3e7b52 312
20b35a69
RD
313protected:
314 wxGBPosition FindEmptyCell();
6a079bc1 315 void AdjustForOverflow();
20b35a69
RD
316
317 wxSize m_emptyCellSize;
5d3e7b52
WS
318
319
20b35a69
RD
320private:
321
322 DECLARE_CLASS(wxGridBagSizer)
c0c133e1 323 wxDECLARE_NO_COPY_CLASS(wxGridBagSizer);
20b35a69
RD
324};
325
326//---------------------------------------------------------------------------
327#endif