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