]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: gbsizer.h | |
e54c96f1 | 3 | // Purpose: interface of wxGBPosition |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
526954c5 | 6 | // Licence: wxWindows licence |
23324ae1 FM |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
9 | /** | |
10 | @class wxGBPosition | |
7c913512 | 11 | |
3d2cf884 BP |
12 | This class represents the position of an item in a virtual grid of rows and |
13 | columns managed by a wxGridBagSizer. | |
7c913512 | 14 | |
23324ae1 | 15 | @library{wxcore} |
3d2cf884 | 16 | @category{winlayout} |
23324ae1 | 17 | */ |
7c913512 | 18 | class wxGBPosition |
23324ae1 FM |
19 | { |
20 | public: | |
23324ae1 | 21 | /** |
3d2cf884 | 22 | Default constructor, setting the row and column to (0,0). |
23324ae1 FM |
23 | */ |
24 | wxGBPosition(); | |
3d2cf884 BP |
25 | /** |
26 | Construct a new wxGBPosition, setting the row and column. | |
27 | */ | |
7c913512 | 28 | wxGBPosition(int row, int col); |
23324ae1 FM |
29 | |
30 | /** | |
31 | Get the current column value. | |
32 | */ | |
328f5751 | 33 | int GetCol() const; |
23324ae1 FM |
34 | |
35 | /** | |
36 | Get the current row value. | |
37 | */ | |
328f5751 | 38 | int GetRow() const; |
23324ae1 FM |
39 | |
40 | /** | |
41 | Set a new column value. | |
42 | */ | |
43 | void SetCol(int col); | |
44 | ||
45 | /** | |
46 | Set a new row value. | |
47 | */ | |
48 | void SetRow(int row); | |
49 | ||
50 | /** | |
fc910c50 | 51 | Compare inequality of two wxGBPositions. |
23324ae1 | 52 | */ |
fc910c50 | 53 | bool operator!=(const wxGBPosition& p) const; |
23324ae1 FM |
54 | |
55 | /** | |
56 | Compare equality of two wxGBPositions. | |
57 | */ | |
3d2cf884 | 58 | bool operator==(const wxGBPosition& p) const; |
23324ae1 FM |
59 | }; |
60 | ||
61 | ||
e54c96f1 | 62 | |
23324ae1 FM |
63 | /** |
64 | @class wxGridBagSizer | |
7c913512 | 65 | |
3d2cf884 BP |
66 | A wxSizer that can lay out items in a virtual grid like a wxFlexGridSizer |
67 | but in this case explicit positioning of the items is allowed using | |
68 | wxGBPosition, and items can optionally span more than one row and/or column | |
69 | using wxGBSpan. | |
7c913512 | 70 | |
23324ae1 FM |
71 | @library{wxcore} |
72 | @category{winlayout} | |
73 | */ | |
74 | class wxGridBagSizer : public wxFlexGridSizer | |
75 | { | |
76 | public: | |
77 | /** | |
78 | Constructor, with optional parameters to specify the gap between the | |
79 | rows and columns. | |
80 | */ | |
81 | wxGridBagSizer(int vgap = 0, int hgap = 0); | |
82 | ||
83 | //@{ | |
84 | /** | |
3d2cf884 BP |
85 | Adds the given item to the given position. |
86 | ||
d29a9a8a | 87 | @return A valid pointer if the item was successfully placed at the |
3d2cf884 | 88 | given position, or @NULL if something was already there. |
23324ae1 FM |
89 | */ |
90 | wxSizerItem* Add(wxWindow* window, const wxGBPosition& pos, | |
91 | const wxGBSpan& span = wxDefaultSpan, | |
3d2cf884 | 92 | int flag = 0, int border = 0, wxObject* userData = NULL); |
7c913512 FM |
93 | wxSizerItem* Add(wxSizer* sizer, const wxGBPosition& pos, |
94 | const wxGBSpan& span = wxDefaultSpan, | |
3d2cf884 | 95 | int flag = 0, int border = 0, wxObject* userData = NULL); |
faadbe6f VZ |
96 | wxSizerItem* Add(wxGBSizerItem* item); |
97 | ||
98 | /** | |
99 | Adds a spacer to the given position. | |
100 | @a width and @a height specify the dimension of the spacer to be added. | |
101 | ||
102 | @return A valid pointer if the spacer was successfully placed at the | |
103 | given position, or @NULL if something was already there. | |
104 | */ | |
3d2cf884 | 105 | wxSizerItem* Add(int width, int height, const wxGBPosition& pos, |
7c913512 | 106 | const wxGBSpan& span = wxDefaultSpan, |
3d2cf884 | 107 | int flag = 0, int border = 0, wxObject* userData = NULL); |
23324ae1 | 108 | |
faadbe6f | 109 | //@} |
23324ae1 FM |
110 | /** |
111 | Called when the managed size of the sizer is needed or when layout | |
112 | needs done. | |
113 | */ | |
114 | wxSize CalcMin(); | |
115 | ||
116 | //@{ | |
117 | /** | |
118 | Look at all items and see if any intersect (or would overlap) the given | |
119 | item. Returns @true if so, @false if there would be no overlap. If an | |
3d2cf884 BP |
120 | @a excludeItem is given then it will not be checked for intersection, |
121 | for example it may be the item we are checking the position of. | |
23324ae1 FM |
122 | */ |
123 | bool CheckForIntersection(wxGBSizerItem* item, | |
4cc4bfaf | 124 | wxGBSizerItem* excludeItem = NULL); |
3d2cf884 | 125 | bool CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, |
4cc4bfaf | 126 | wxGBSizerItem* excludeItem = NULL); |
23324ae1 FM |
127 | //@} |
128 | ||
129 | //@{ | |
130 | /** | |
131 | Find the sizer item for the given window or subsizer, returns @NULL if | |
132 | not found. (non-recursive) | |
133 | */ | |
134 | wxGBSizerItem* FindItem(wxWindow* window); | |
7c913512 | 135 | wxGBSizerItem* FindItem(wxSizer* sizer); |
23324ae1 FM |
136 | //@} |
137 | ||
138 | /** | |
139 | Return the sizer item located at the point given in pt, or @NULL if | |
3d2cf884 BP |
140 | there is no item at that point. The (x,y) coordinates in @a pt |
141 | correspond to the client coordinates of the window using the sizer for | |
23324ae1 FM |
142 | layout. (non-recursive) |
143 | */ | |
144 | wxGBSizerItem* FindItemAtPoint(const wxPoint& pt); | |
145 | ||
146 | /** | |
147 | Return the sizer item for the given grid cell, or @NULL if there is no | |
148 | item at that position. (non-recursive) | |
149 | */ | |
150 | wxGBSizerItem* FindItemAtPosition(const wxGBPosition& pos); | |
151 | ||
152 | /** | |
153 | Return the sizer item that has a matching user data (it only compares | |
154 | pointer values) or @NULL if not found. (non-recursive) | |
155 | */ | |
156 | wxGBSizerItem* FindItemWithData(const wxObject* userData); | |
157 | ||
158 | /** | |
3d2cf884 BP |
159 | Get the size of the specified cell, including hgap and vgap. Only valid |
160 | after window layout has been performed. | |
23324ae1 | 161 | */ |
328f5751 | 162 | wxSize GetCellSize(int row, int col) const; |
23324ae1 FM |
163 | |
164 | /** | |
165 | Get the size used for cells in the grid with no item. | |
166 | */ | |
328f5751 | 167 | wxSize GetEmptyCellSize() const; |
23324ae1 FM |
168 | |
169 | //@{ | |
170 | /** | |
171 | Get the grid position of the specified item. | |
172 | */ | |
173 | wxGBPosition GetItemPosition(wxWindow* window); | |
7c913512 FM |
174 | wxGBPosition GetItemPosition(wxSizer* sizer); |
175 | wxGBPosition GetItemPosition(size_t index); | |
23324ae1 FM |
176 | //@} |
177 | ||
178 | //@{ | |
179 | /** | |
3d2cf884 | 180 | Get the row/col spanning of the specified item. |
23324ae1 FM |
181 | */ |
182 | wxGBSpan GetItemSpan(wxWindow* window); | |
7c913512 FM |
183 | wxGBSpan GetItemSpan(wxSizer* sizer); |
184 | wxGBSpan GetItemSpan(size_t index); | |
23324ae1 FM |
185 | //@} |
186 | ||
187 | /** | |
188 | Called when the managed size of the sizer is needed or when layout | |
189 | needs done. | |
190 | */ | |
191 | void RecalcSizes(); | |
192 | ||
193 | /** | |
194 | Set the size used for cells in the grid with no item. | |
195 | */ | |
196 | void SetEmptyCellSize(const wxSize& sz); | |
197 | ||
198 | //@{ | |
199 | /** | |
200 | Set the grid position of the specified item. Returns @true on success. | |
201 | If the move is not allowed (because an item is already there) then | |
202 | @false is returned. | |
203 | */ | |
204 | bool SetItemPosition(wxWindow* window, const wxGBPosition& pos); | |
7c913512 FM |
205 | bool SetItemPosition(wxSizer* sizer, const wxGBPosition& pos); |
206 | bool SetItemPosition(size_t index, const wxGBPosition& pos); | |
23324ae1 FM |
207 | //@} |
208 | ||
209 | //@{ | |
210 | /** | |
211 | Set the row/col spanning of the specified item. Returns @true on | |
212 | success. If the move is not allowed (because an item is already there) | |
213 | then @false is returned. | |
214 | */ | |
215 | bool SetItemSpan(wxWindow* window, const wxGBSpan& span); | |
7c913512 FM |
216 | bool SetItemSpan(wxSizer* sizer, const wxGBSpan& span); |
217 | bool SetItemSpan(size_t index, const wxGBSpan& span); | |
23324ae1 FM |
218 | //@} |
219 | }; | |
220 | ||
221 | ||
e54c96f1 | 222 | |
23324ae1 FM |
223 | /** |
224 | @class wxGBSizerItem | |
7c913512 | 225 | |
3d2cf884 BP |
226 | The wxGBSizerItem class is used by the wxGridBagSizer for tracking the |
227 | items in the sizer. It adds grid position and spanning information to the | |
d13b34d3 | 228 | normal wxSizerItem by adding wxGBPosition and wxGBSpan attributes. Most of |
3d2cf884 BP |
229 | the time you will not need to use a wxGBSizerItem directly in your code, |
230 | but there are a couple of cases where it is handy. | |
7c913512 | 231 | |
23324ae1 | 232 | @library{wxcore} |
3d2cf884 | 233 | @category{winlayout} |
23324ae1 FM |
234 | */ |
235 | class wxGBSizerItem : public wxSizerItem | |
236 | { | |
237 | public: | |
23324ae1 | 238 | /** |
3d2cf884 | 239 | Construct a sizer item for tracking a spacer. |
23324ae1 FM |
240 | */ |
241 | wxGBSizerItem(int width, int height, const wxGBPosition& pos, | |
5eb16fe2 RD |
242 | const wxGBSpan& span=wxDefaultSpan, int flag=0, int border=0, |
243 | wxObject* userData=NULL); | |
3d2cf884 BP |
244 | /** |
245 | Construct a sizer item for tracking a window. | |
246 | */ | |
7c913512 | 247 | wxGBSizerItem(wxWindow* window, const wxGBPosition& pos, |
5eb16fe2 RD |
248 | const wxGBSpan& span=wxDefaultSpan, int flag=0, int border=0, |
249 | wxObject* userData=NULL); | |
3d2cf884 BP |
250 | /** |
251 | Construct a sizer item for tracking a subsizer. | |
252 | */ | |
7c913512 | 253 | wxGBSizerItem(wxSizer* sizer, const wxGBPosition& pos, |
5eb16fe2 RD |
254 | const wxGBSpan& span=wxDefaultSpan, int flag=0, int border=0, |
255 | wxObject* userData=NULL); | |
23324ae1 FM |
256 | |
257 | /** | |
3d2cf884 | 258 | Get the row and column of the endpoint of this item. |
23324ae1 FM |
259 | */ |
260 | void GetEndPos(int& row, int& col); | |
261 | ||
262 | //@{ | |
263 | /** | |
264 | Get the grid position of the item. | |
265 | */ | |
328f5751 | 266 | wxGBPosition GetPos() const; |
3d2cf884 | 267 | void GetPos(int& row, int& col) const; |
23324ae1 FM |
268 | //@} |
269 | ||
270 | //@{ | |
271 | /** | |
272 | Get the row and column spanning of the item. | |
273 | */ | |
328f5751 | 274 | wxGBSpan GetSpan() const; |
3d2cf884 | 275 | void GetSpan(int& rowspan, int& colspan) const; |
23324ae1 FM |
276 | //@} |
277 | ||
23324ae1 | 278 | /** |
d13b34d3 | 279 | Returns @true if this item and the @a other item intersect. |
23324ae1 FM |
280 | */ |
281 | bool Intersects(const wxGBSizerItem& other); | |
3d2cf884 BP |
282 | /** |
283 | Returns @true if the given pos/span would intersect with this item. | |
284 | */ | |
285 | bool Intersects(const wxGBPosition& pos, const wxGBSpan& span); | |
23324ae1 FM |
286 | |
287 | /** | |
3d2cf884 BP |
288 | If the item is already a member of a sizer then first ensure that there |
289 | is no other item that would intersect with this one at the new | |
23324ae1 FM |
290 | position, then set the new position. Returns @true if the change is |
291 | successful and after the next Layout the item will be moved. | |
292 | */ | |
293 | bool SetPos(const wxGBPosition& pos); | |
294 | ||
295 | /** | |
3d2cf884 BP |
296 | If the item is already a member of a sizer then first ensure that there |
297 | is no other item that would intersect with this one with its new | |
23324ae1 FM |
298 | spanning size, then set the new spanning. Returns @true if the change |
299 | is successful and after the next Layout the item will be resized. | |
300 | */ | |
301 | bool SetSpan(const wxGBSpan& span); | |
5eb16fe2 RD |
302 | |
303 | ||
304 | wxGridBagSizer* GetGBSizer() const; | |
305 | void SetGBSizer(wxGridBagSizer* sizer); | |
23324ae1 FM |
306 | }; |
307 | ||
308 | ||
e54c96f1 | 309 | |
23324ae1 FM |
310 | /** |
311 | @class wxGBSpan | |
7c913512 | 312 | |
3d2cf884 BP |
313 | This class is used to hold the row and column spanning attributes of items |
314 | in a wxGridBagSizer. | |
7c913512 | 315 | |
23324ae1 | 316 | @library{wxcore} |
3d2cf884 | 317 | @category{winlayout} |
23324ae1 | 318 | */ |
7c913512 | 319 | class wxGBSpan |
23324ae1 FM |
320 | { |
321 | public: | |
23324ae1 | 322 | /** |
3d2cf884 BP |
323 | Default constructor, setting the rowspan and colspan to (1,1) meaning |
324 | that the item occupies one cell in each direction. | |
23324ae1 FM |
325 | */ |
326 | wxGBSpan(); | |
3d2cf884 BP |
327 | /** |
328 | Construct a new wxGBSpan, setting the @a rowspan and @a colspan. | |
329 | */ | |
7c913512 | 330 | wxGBSpan(int rowspan, int colspan); |
23324ae1 FM |
331 | |
332 | /** | |
333 | Get the current colspan value. | |
334 | */ | |
328f5751 | 335 | int GetColspan() const; |
23324ae1 FM |
336 | |
337 | /** | |
338 | Get the current rowspan value. | |
339 | */ | |
328f5751 | 340 | int GetRowspan() const; |
23324ae1 FM |
341 | |
342 | /** | |
343 | Set a new colspan value. | |
344 | */ | |
345 | void SetColspan(int colspan); | |
346 | ||
347 | /** | |
348 | Set a new rowspan value. | |
349 | */ | |
350 | void SetRowspan(int rowspan); | |
351 | ||
352 | /** | |
fc910c50 | 353 | Compare inequality of two wxGBSpans. |
23324ae1 | 354 | */ |
fc910c50 | 355 | bool operator!=(const wxGBSpan& o) const; |
23324ae1 FM |
356 | |
357 | /** | |
358 | Compare equality of two wxGBSpans. | |
359 | */ | |
3d2cf884 | 360 | bool operator==(const wxGBSpan& o) const; |
23324ae1 | 361 | }; |
e54c96f1 | 362 | |
5eb16fe2 RD |
363 | |
364 | const wxGBSpan wxDefaultSpan; |