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