]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gbsizer.h
Calling sizerItem->SetWindow shoudl set the minsize too.
[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
11// Licence: wxWindows licence
12/////////////////////////////////////////////////////////////////////////////
13
14#ifndef __WXGBSIZER_H__
15#define __WXGBSIZER_H__
16
17#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
18#pragma interface "gbsizer.h"
19#endif
20
21#include "wx/sizer.h"
22
23
24//---------------------------------------------------------------------------
25// Classes to represent a position in the grid and a size of an item in the
26// grid, IOW, the number of rows and columns it occupies. I chose to use these
27// instead of wxPoint and wxSize because they are (x,y) and usually pixel
28// oriented whild grids and tables are usually thought of as (row,col) so some
29// confusion would definitly result in using wxPoint...
30//
31// NOTE: This should probably be refactored to a common RowCol data type which
32// is used for this and also for wxGridCellCoords.
33//---------------------------------------------------------------------------
34
35class WXDLLEXPORT wxGBPosition
36{
37public:
38 wxGBPosition() : m_row(0), m_col(0) {}
39 wxGBPosition(int row, int col) : m_row(row), m_col(col) {}
40
41 // default copy ctor and assignment operator are okay.
42
43 int GetRow() const { return m_row; }
44 int GetCol() const { return m_col; }
45 void SetRow(int row) { m_row = row; }
46 void SetCol(int col) { m_col = col; }
47
48 bool operator==(const wxGBPosition& p) const { return m_row == p.m_row && m_col == p.m_col; }
49 bool operator!=(const wxGBPosition& p) const { return !(*this == p); }
50
51private:
52 int m_row;
53 int m_col;
54};
55
56
57class WXDLLEXPORT wxGBSpan
58{
59public:
60 wxGBSpan() : m_rowspan(1), m_colspan(1) {}
61 wxGBSpan(int rowspan, int colspan) : m_rowspan(rowspan), m_colspan(colspan) {}
62
63 // default copy ctor and assignment operator are okay.
64
65 int GetRowspan() const { return m_rowspan; }
66 int GetColspan() const { return m_colspan; }
67 void SetRowspan(int rowspan) { m_rowspan = rowspan; }
68 void SetColspan(int colspan) { m_colspan = colspan; }
69
70 bool operator==(const wxGBSpan& o) const { return m_rowspan == o.m_rowspan && m_colspan == o.m_colspan; }
71 bool operator!=(const wxGBSpan& o) const { return !(*this == o); }
72
73private:
74 int m_rowspan;
75 int m_colspan;
76};
77
78
79WXDLLEXPORT_DATA(extern const wxGBSpan) wxDefaultSpan;
80
81
82//---------------------------------------------------------------------------
83// wxGBSizerItem
84//---------------------------------------------------------------------------
85
86class WXDLLEXPORT wxGridBagSizer;
87
88
89class WXDLLEXPORT wxGBSizerItem : public wxSizerItem
90{
91public:
92 // spacer
93 wxGBSizerItem( int width,
94 int height,
95 const wxGBPosition& pos,
96 const wxGBSpan& span,
97 int flag,
98 int border,
99 wxObject* userData);
100
101 // window
102 wxGBSizerItem( wxWindow *window,
103 const wxGBPosition& pos,
104 const wxGBSpan& span,
105 int flag,
106 int border,
107 wxObject* userData );
108
109 // subsizer
110 wxGBSizerItem( wxSizer *sizer,
111 const wxGBPosition& pos,
112 const wxGBSpan& span,
113 int flag,
114 int border,
115 wxObject* userData );
116
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
146
147 wxGridBagSizer* GetSizer() const { return m_sizer; }
148 void SetSizer(wxGridBagSizer* sizer) { m_sizer = sizer; }
149
150
151protected:
152 wxGBPosition m_pos;
153 wxGBSpan m_span;
154 wxGridBagSizer* m_sizer;
155
156
157private:
158 DECLARE_CLASS(wxGBSizerItem)
159 DECLARE_NO_COPY_CLASS(wxGBSizerItem)
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.
175 bool 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 bool 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 bool 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 bool Add( wxGBSizerItem *item );
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
201 // Get the grid position of the specified item (non-recursive)
202 wxGBPosition GetItemPosition(wxWindow *window);
203 wxGBPosition GetItemPosition(wxSizer *sizer);
204 wxGBPosition GetItemPosition(size_t index);
205
206 // Set the grid position of the specified item. Returns true on success.
207 // If the move is not allowed (because an item is already there) then
208 // false is returned. (non-recursive)
209 bool SetItemPosition(wxWindow *window, const wxGBPosition& pos);
210 bool SetItemPosition(wxSizer *sizer, const wxGBPosition& pos);
211 bool SetItemPosition(size_t index, const wxGBPosition& pos);
212
213 // Get the row/col spanning of the specified item (non-recursive)
214 wxGBSpan GetItemSpan(wxWindow *window);
215 wxGBSpan GetItemSpan(wxSizer *sizer);
216 wxGBSpan GetItemSpan(size_t index);
217
218 // Set the row/col spanning of the specified item. Returns true on
219 // success. If the move is not allowed (because an item is already there)
220 // then false is returned. (non-recursive)
221 bool SetItemSpan(wxWindow *window, const wxGBSpan& span);
222 bool SetItemSpan(wxSizer *sizer, const wxGBSpan& span);
223 bool SetItemSpan(size_t index, const wxGBSpan& span);
224
225
226 // Find the sizer item for the given window or subsizer, returns NULL if
227 // not found. (non-recursive)
228 wxGBSizerItem* FindItem(wxWindow* window);
229 wxGBSizerItem* FindItem(wxSizer* sizer);
230
231
232 // Return the sizer item for the given grid cell, or NULL if there is no
233 // item at that position. (non-recursive)
234 wxGBSizerItem* FindItemAtPosition(const wxGBPosition& pos);
235
236
237 // Return the sizer item that has a matching user data (it only compares
238 // pointer values) or NULL if not found. (non-recursive)
239 wxGBSizerItem* FindItemWithData(const wxObject* userData);
240
241
242 // These are what make the sizer do size calculations and layout
243 virtual void RecalcSizes();
244 virtual wxSize CalcMin();
245
246
247 // Look at all items and see if any intersect (or would overlap) the given
248 // item. Returns true if so, false if there would be no overlap. If an
249 // excludeItem is given then it will not be checked for intersection, for
250 // example it may be the item we are checking the position of.
251 bool CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem = NULL);
252 bool CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem = NULL);
253
254
255 // The Add base class virtuals should not be used with this class, but
256 // we'll try to make them automatically select a location for the item
257 // anyway.
258 virtual void Add( wxWindow *window, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
259 virtual void Add( wxSizer *sizer, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
260 virtual void Add( int width, int height, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
261
262 // The Insert and Prepend base class virtuals that are not appropriate for
263 // this class and should not be used. Their implementation in this class
264 // simply fails.
265 virtual void Add( wxSizerItem *item );
266 virtual void Insert( size_t index, wxWindow *window, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
267 virtual void Insert( size_t index, wxSizer *sizer, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
268 virtual void Insert( size_t index, int width, int height, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
269 virtual void Insert( size_t index, wxSizerItem *item );
270 virtual void Prepend( wxWindow *window, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
271 virtual void Prepend( wxSizer *sizer, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
272 virtual void Prepend( int width, int height, int proportion = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
273 virtual void Prepend( wxSizerItem *item );
274
275
276protected:
277 wxGBPosition FindEmptyCell();
278
279 wxSize m_emptyCellSize;
280
281
282private:
283
284 DECLARE_CLASS(wxGridBagSizer)
285 DECLARE_NO_COPY_CLASS(wxGridBagSizer)
286};
287
288//---------------------------------------------------------------------------
289#endif