]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gbsizer.h
Use wxGetTranslation() instead of _() in the public headers.
[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 // Copyright: (c) Robin Dunn
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef __WXGBSIZER_H__
14 #define __WXGBSIZER_H__
15
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
23 // oriented while grids and tables are usually thought of as (row,col) so some
24 // confusion would definitely result in using wxPoint...
25 //
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
30 class WXDLLIMPEXP_CORE wxGBPosition
31 {
32 public:
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; }
42
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
46 private:
47 int m_row;
48 int m_col;
49 };
50
51
52 class WXDLLIMPEXP_CORE wxGBSpan
53 {
54 public:
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 }
66
67 // default copy ctor and assignment operator are okay.
68
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
77 int GetRowspan() const { return m_rowspan; }
78 int GetColspan() const { return m_colspan; }
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 }
92
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
96 private:
97 // This private ctor is used by Invalid() only.
98 wxGBSpan(struct InvalidCtorTag*)
99 {
100 m_rowspan =
101 m_colspan = -1;
102 }
103
104 void Init()
105 {
106 m_rowspan =
107 m_colspan = 1;
108 }
109
110 int m_rowspan;
111 int m_colspan;
112 };
113
114
115 extern WXDLLIMPEXP_DATA_CORE(const wxGBSpan) wxDefaultSpan;
116
117
118 //---------------------------------------------------------------------------
119 // wxGBSizerItem
120 //---------------------------------------------------------------------------
121
122 class WXDLLIMPEXP_FWD_CORE wxGridBagSizer;
123
124
125 class WXDLLIMPEXP_CORE wxGBSizerItem : public wxSizerItem
126 {
127 public:
128 // spacer
129 wxGBSizerItem( int width,
130 int height,
131 const wxGBPosition& pos,
132 const wxGBSpan& span=wxDefaultSpan,
133 int flag=0,
134 int border=0,
135 wxObject* userData=NULL);
136
137 // window
138 wxGBSizerItem( wxWindow *window,
139 const wxGBPosition& pos,
140 const wxGBSpan& span=wxDefaultSpan,
141 int flag=0,
142 int border=0,
143 wxObject* userData=NULL );
144
145 // subsizer
146 wxGBSizerItem( wxSizer *sizer,
147 const wxGBPosition& pos,
148 const wxGBSpan& span=wxDefaultSpan,
149 int flag=0,
150 int border=0,
151 wxObject* userData=NULL );
152
153 // default ctor
154 wxGBSizerItem();
155
156
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
177 // Returns true if this item and the other item intersect
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
186
187 wxGridBagSizer* GetGBSizer() const { return m_gbsizer; }
188 void SetGBSizer(wxGridBagSizer* sizer) { m_gbsizer = sizer; }
189
190
191 protected:
192 wxGBPosition m_pos;
193 wxGBSpan m_span;
194 wxGridBagSizer* m_gbsizer; // so SetPos/SetSpan can check for intersects
195
196
197 private:
198 DECLARE_DYNAMIC_CLASS(wxGBSizerItem)
199 wxDECLARE_NO_COPY_CLASS(wxGBSizerItem);
200 };
201
202
203 //---------------------------------------------------------------------------
204 // wxGridBagSizer
205 //---------------------------------------------------------------------------
206
207
208 class WXDLLIMPEXP_CORE wxGridBagSizer : public wxFlexGridSizer
209 {
210 public:
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.
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 );
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
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;
244
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);
268
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
275
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
280
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
287
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
292
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
305
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.
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 );
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.
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 );
325
326
327 protected:
328 wxGBPosition FindEmptyCell();
329 void AdjustForOverflow();
330
331 wxSize m_emptyCellSize;
332
333
334 private:
335
336 DECLARE_CLASS(wxGridBagSizer)
337 wxDECLARE_NO_COPY_CLASS(wxGridBagSizer);
338 };
339
340 //---------------------------------------------------------------------------
341 #endif