]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gbsizer.h
Remove duplicate item about Trac changes from release tech note.
[wxWidgets.git] / include / wx / gbsizer.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/gbsizer.h
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
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
13
14 #ifndef __WXGBSIZER_H__
15 #define __WXGBSIZER_H__
16
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
24 // oriented while grids and tables are usually thought of as (row,col) so some
25 // confusion would definitely result in using wxPoint...
26 //
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
31 class WXDLLIMPEXP_CORE wxGBPosition
32 {
33 public:
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; }
43
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
47 private:
48 int m_row;
49 int m_col;
50 };
51
52
53 class WXDLLIMPEXP_CORE wxGBSpan
54 {
55 public:
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 }
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; }
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 }
85
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
89 private:
90 void Init()
91 {
92 m_rowspan =
93 m_colspan = 1;
94 }
95
96 int m_rowspan;
97 int m_colspan;
98 };
99
100
101 extern WXDLLIMPEXP_DATA_CORE(const wxGBSpan) wxDefaultSpan;
102
103
104 //---------------------------------------------------------------------------
105 // wxGBSizerItem
106 //---------------------------------------------------------------------------
107
108 class WXDLLIMPEXP_FWD_CORE wxGridBagSizer;
109
110
111 class WXDLLIMPEXP_CORE wxGBSizerItem : public wxSizerItem
112 {
113 public:
114 // spacer
115 wxGBSizerItem( int width,
116 int height,
117 const wxGBPosition& pos,
118 const wxGBSpan& span=wxDefaultSpan,
119 int flag=0,
120 int border=0,
121 wxObject* userData=NULL);
122
123 // window
124 wxGBSizerItem( wxWindow *window,
125 const wxGBPosition& pos,
126 const wxGBSpan& span=wxDefaultSpan,
127 int flag=0,
128 int border=0,
129 wxObject* userData=NULL );
130
131 // subsizer
132 wxGBSizerItem( wxSizer *sizer,
133 const wxGBPosition& pos,
134 const wxGBSpan& span=wxDefaultSpan,
135 int flag=0,
136 int border=0,
137 wxObject* userData=NULL );
138
139 // default ctor
140 wxGBSizerItem();
141
142
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
163 // Returns true if this item and the other item intersect
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
172
173 wxGridBagSizer* GetGBSizer() const { return m_gbsizer; }
174 void SetGBSizer(wxGridBagSizer* sizer) { m_gbsizer = sizer; }
175
176
177 protected:
178 wxGBPosition m_pos;
179 wxGBSpan m_span;
180 wxGridBagSizer* m_gbsizer; // so SetPos/SetSpan can check for intersects
181
182
183 private:
184 DECLARE_DYNAMIC_CLASS(wxGBSizerItem)
185 wxDECLARE_NO_COPY_CLASS(wxGBSizerItem);
186 };
187
188
189 //---------------------------------------------------------------------------
190 // wxGridBagSizer
191 //---------------------------------------------------------------------------
192
193
194 class WXDLLIMPEXP_CORE wxGridBagSizer : public wxFlexGridSizer
195 {
196 public:
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.
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 );
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
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;
230
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);
254
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
261
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
266
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
273
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
278
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
291
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.
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 );
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.
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 );
311
312
313 protected:
314 wxGBPosition FindEmptyCell();
315 void AdjustForOverflow();
316
317 wxSize m_emptyCellSize;
318
319
320 private:
321
322 DECLARE_CLASS(wxGridBagSizer)
323 wxDECLARE_NO_COPY_CLASS(wxGridBagSizer);
324 };
325
326 //---------------------------------------------------------------------------
327 #endif