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