]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: sizer.h | |
3 | // Purpose: provide wxSizer class for layouting | |
4 | // Author: Robert Roebling and Robin Dunn | |
5 | // Modified by: Ron Lee | |
6 | // Created: | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Robin Dunn, Dirk Holtwick and Robert Roebling | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef __WXSIZER_H__ | |
13 | #define __WXSIZER_H__ | |
14 | ||
15 | #if defined(__GNUG__) && !defined(__APPLE__) | |
16 | #pragma interface "sizer.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | #include "wx/window.h" | |
22 | #include "wx/frame.h" | |
23 | #include "wx/dialog.h" | |
24 | ||
25 | //--------------------------------------------------------------------------- | |
26 | // classes | |
27 | //--------------------------------------------------------------------------- | |
28 | ||
29 | class wxSizerItem; | |
30 | class wxSizer; | |
31 | class wxBoxSizer; | |
32 | ||
33 | //--------------------------------------------------------------------------- | |
34 | // wxSizerItem | |
35 | //--------------------------------------------------------------------------- | |
36 | ||
37 | class WXDLLEXPORT wxSizerItem: public wxObject | |
38 | { | |
39 | public: | |
40 | // spacer | |
41 | wxSizerItem( int width, int height, int option, int flag, int border, wxObject* userData); | |
42 | ||
43 | // window | |
44 | wxSizerItem( wxWindow *window, int option, int flag, int border, wxObject* userData ); | |
45 | ||
46 | // subsizer | |
47 | wxSizerItem( wxSizer *sizer, int option, int flag, int border, wxObject* userData ); | |
48 | ||
49 | ~wxSizerItem(); | |
50 | ||
51 | virtual void DeleteWindows(); | |
52 | ||
53 | // Enable deleting the SizerItem without destroying the contained sizer. | |
54 | void DetachSizer() | |
55 | { m_sizer = 0; } | |
56 | ||
57 | virtual wxSize GetSize(); | |
58 | virtual wxSize CalcMin(); | |
59 | virtual void SetDimension( wxPoint pos, wxSize size ); | |
60 | ||
61 | wxSize GetMinSize() | |
62 | { return m_minSize; } | |
63 | ||
64 | void SetRatio( int width, int height ) | |
65 | // if either of dimensions is zero, ratio is assumed to be 1 | |
66 | // to avoid "divide by zero" errors | |
67 | { m_ratio = (width && height) ? ((float) width / (float) height) : 1; } | |
68 | void SetRatio( wxSize size ) | |
69 | { m_ratio = (size.x && size.y) ? ((float) size.x / (float) size.y) : 1; } | |
70 | void SetRatio( float ratio ) | |
71 | { m_ratio = ratio; } | |
72 | float GetRatio() const | |
73 | { return m_ratio; } | |
74 | ||
75 | bool IsWindow(); | |
76 | bool IsSizer(); | |
77 | bool IsSpacer(); | |
78 | ||
79 | void SetInitSize( int x, int y ) | |
80 | { m_minSize.x = x; m_minSize.y = y; } | |
81 | void SetOption( int option ) | |
82 | { m_option = option; } | |
83 | void SetFlag( int flag ) | |
84 | { m_flag = flag; } | |
85 | void SetBorder( int border ) | |
86 | { m_border = border; } | |
87 | void Show ( bool show ) | |
88 | { m_show = show; } | |
89 | ||
90 | wxWindow *GetWindow() const | |
91 | { return m_window; } | |
92 | void SetWindow( wxWindow *window ) | |
93 | { m_window = window; } | |
94 | wxSizer *GetSizer() const | |
95 | { return m_sizer; } | |
96 | void SetSizer( wxSizer *sizer ) | |
97 | { m_sizer = sizer; } | |
98 | int GetOption() const | |
99 | { return m_option; } | |
100 | int GetFlag() const | |
101 | { return m_flag; } | |
102 | int GetBorder() const | |
103 | { return m_border; } | |
104 | bool IsShown() const | |
105 | { return m_show; } | |
106 | wxObject* GetUserData() | |
107 | { return m_userData; } | |
108 | wxPoint GetPosition() | |
109 | { return m_pos; } | |
110 | ||
111 | protected: | |
112 | wxWindow *m_window; | |
113 | wxSizer *m_sizer; | |
114 | wxSize m_size; | |
115 | wxPoint m_pos; | |
116 | wxSize m_minSize; | |
117 | int m_option; | |
118 | int m_border; | |
119 | int m_flag; | |
120 | ||
121 | // If TRUE, then this item is considered in the layout | |
122 | // calculation. Otherwise, it is skipped over. | |
123 | bool m_show; | |
124 | // als: aspect ratio can always be calculated from m_size, | |
125 | // but this would cause precision loss when the window | |
126 | // is shrinked. it is safer to preserve initial value. | |
127 | float m_ratio; | |
128 | ||
129 | wxObject *m_userData; | |
130 | ||
131 | private: | |
132 | DECLARE_CLASS(wxSizerItem); | |
133 | DECLARE_NO_COPY_CLASS(wxSizerItem) | |
134 | }; | |
135 | ||
136 | //--------------------------------------------------------------------------- | |
137 | // wxSizer | |
138 | //--------------------------------------------------------------------------- | |
139 | ||
140 | class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer | |
141 | { | |
142 | public: | |
143 | wxSizer(); | |
144 | ~wxSizer(); | |
145 | ||
146 | /* These should be called Append() really. */ | |
147 | virtual void Add( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
148 | virtual void Add( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
149 | virtual void Add( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
150 | ||
151 | virtual void Insert( int before, wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
152 | virtual void Insert( int before, wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
153 | virtual void Insert( int before, int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
154 | ||
155 | virtual void Prepend( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
156 | virtual void Prepend( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
157 | virtual void Prepend( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL ); | |
158 | ||
159 | // Remove will delete a sizer, but not a window. | |
160 | virtual bool Remove( wxWindow *window ); | |
161 | virtual bool Remove( wxSizer *sizer ); | |
162 | virtual bool Remove( int pos ); | |
163 | ||
164 | // Detach will never destroy a sizer or window. | |
165 | virtual bool Detach( wxWindow *window ) | |
166 | { return Remove( window ); } | |
167 | virtual bool Detach( wxSizer *sizer ); | |
168 | virtual bool Detach( int pos ); | |
169 | ||
170 | virtual void Clear( bool delete_windows=FALSE ); | |
171 | virtual void DeleteWindows(); | |
172 | ||
173 | void SetMinSize( int width, int height ) | |
174 | { DoSetMinSize( width, height ); } | |
175 | void SetMinSize( wxSize size ) | |
176 | { DoSetMinSize( size.x, size.y ); } | |
177 | ||
178 | /* Searches recursively */ | |
179 | bool SetItemMinSize( wxWindow *window, int width, int height ) | |
180 | { return DoSetItemMinSize( window, width, height ); } | |
181 | bool SetItemMinSize( wxWindow *window, wxSize size ) | |
182 | { return DoSetItemMinSize( window, size.x, size.y ); } | |
183 | ||
184 | /* Searches recursively */ | |
185 | bool SetItemMinSize( wxSizer *sizer, int width, int height ) | |
186 | { return DoSetItemMinSize( sizer, width, height ); } | |
187 | bool SetItemMinSize( wxSizer *sizer, wxSize size ) | |
188 | { return DoSetItemMinSize( sizer, size.x, size.y ); } | |
189 | ||
190 | bool SetItemMinSize( int pos, int width, int height ) | |
191 | { return DoSetItemMinSize( pos, width, height ); } | |
192 | bool SetItemMinSize( int pos, wxSize size ) | |
193 | { return DoSetItemMinSize( pos, size.x, size.y ); } | |
194 | ||
195 | wxSize GetSize() | |
196 | { return m_size; } | |
197 | wxPoint GetPosition() | |
198 | { return m_position; } | |
199 | ||
200 | /* Calculate the minimal size or return m_minSize if bigger. */ | |
201 | wxSize GetMinSize(); | |
202 | ||
203 | virtual void RecalcSizes() = 0; | |
204 | virtual wxSize CalcMin() = 0; | |
205 | ||
206 | virtual void Layout(); | |
207 | ||
208 | wxSize Fit( wxWindow *window ); | |
209 | void FitInside( wxWindow *window ); | |
210 | void SetSizeHints( wxWindow *window ); | |
211 | void SetVirtualSizeHints( wxWindow *window ); | |
212 | ||
213 | wxList& GetChildren() | |
214 | { return m_children; } | |
215 | ||
216 | void SetDimension( int x, int y, int width, int height ); | |
217 | ||
218 | // Manage whether individual windows or sub-sizers are considered | |
219 | // in the layout calculations or not. | |
220 | void Show( wxWindow *window, bool show = TRUE ); | |
221 | void Hide( wxWindow *window ) | |
222 | { Show (window, FALSE); } | |
223 | void Show( wxSizer *sizer, bool show = TRUE ); | |
224 | void Hide( wxSizer *sizer ) | |
225 | { Show (sizer, FALSE); } | |
226 | ||
227 | bool IsShown( wxWindow *window ); | |
228 | bool IsShown( wxSizer *sizer ); | |
229 | ||
230 | // Recursively call wxWindow::Show () on all sizer items. | |
231 | void ShowItems (bool show); | |
232 | ||
233 | protected: | |
234 | wxSize m_size; | |
235 | wxSize m_minSize; | |
236 | wxPoint m_position; | |
237 | wxList m_children; | |
238 | ||
239 | wxSize GetMaxWindowSize( wxWindow *window ); | |
240 | wxSize GetMinWindowSize( wxWindow *window ); | |
241 | wxSize GetMaxClientSize( wxWindow *window ); | |
242 | wxSize GetMinClientSize( wxWindow *window ); | |
243 | wxSize FitSize( wxWindow *window ); | |
244 | wxSize VirtualFitSize( wxWindow *window ); | |
245 | ||
246 | virtual void DoSetMinSize( int width, int height ); | |
247 | virtual bool DoSetItemMinSize( wxWindow *window, int width, int height ); | |
248 | virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height ); | |
249 | virtual bool DoSetItemMinSize( int pos, int width, int height ); | |
250 | ||
251 | private: | |
252 | DECLARE_CLASS(wxSizer); | |
253 | }; | |
254 | ||
255 | //--------------------------------------------------------------------------- | |
256 | // wxGridSizer | |
257 | //--------------------------------------------------------------------------- | |
258 | ||
259 | class WXDLLEXPORT wxGridSizer: public wxSizer | |
260 | { | |
261 | public: | |
262 | wxGridSizer( int rows, int cols, int vgap, int hgap ); | |
263 | wxGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
264 | ||
265 | void RecalcSizes(); | |
266 | wxSize CalcMin(); | |
267 | ||
268 | void SetCols( int cols ) { m_cols = cols; } | |
269 | void SetRows( int rows ) { m_rows = rows; } | |
270 | void SetVGap( int gap ) { m_vgap = gap; } | |
271 | void SetHGap( int gap ) { m_hgap = gap; } | |
272 | int GetCols() { return m_cols; } | |
273 | int GetRows() { return m_rows; } | |
274 | int GetVGap() { return m_vgap; } | |
275 | int GetHGap() { return m_hgap; } | |
276 | ||
277 | protected: | |
278 | int m_rows; | |
279 | int m_cols; | |
280 | int m_vgap; | |
281 | int m_hgap; | |
282 | ||
283 | // return the number of total items and the number of columns and rows | |
284 | int CalcRowsCols(int& rows, int& cols) const; | |
285 | ||
286 | void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ); | |
287 | ||
288 | private: | |
289 | DECLARE_CLASS(wxGridSizer); | |
290 | }; | |
291 | ||
292 | //--------------------------------------------------------------------------- | |
293 | // wxFlexGridSizer | |
294 | //--------------------------------------------------------------------------- | |
295 | ||
296 | class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer | |
297 | { | |
298 | public: | |
299 | wxFlexGridSizer( int rows, int cols, int vgap, int hgap ); | |
300 | wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 ); | |
301 | ~wxFlexGridSizer(); | |
302 | ||
303 | void RecalcSizes(); | |
304 | wxSize CalcMin(); | |
305 | ||
306 | void AddGrowableRow( size_t idx ); | |
307 | void RemoveGrowableRow( size_t idx ); | |
308 | void AddGrowableCol( size_t idx ); | |
309 | void RemoveGrowableCol( size_t idx ); | |
310 | ||
311 | protected: | |
312 | int *m_rowHeights; | |
313 | int *m_colWidths; | |
314 | wxArrayInt m_growableRows; | |
315 | wxArrayInt m_growableCols; | |
316 | ||
317 | void CreateArrays(); | |
318 | ||
319 | private: | |
320 | DECLARE_CLASS(wxFlexGridSizer); | |
321 | DECLARE_NO_COPY_CLASS(wxFlexGridSizer) | |
322 | }; | |
323 | ||
324 | //--------------------------------------------------------------------------- | |
325 | // wxBoxSizer | |
326 | //--------------------------------------------------------------------------- | |
327 | ||
328 | class WXDLLEXPORT wxBoxSizer: public wxSizer | |
329 | { | |
330 | public: | |
331 | wxBoxSizer( int orient ); | |
332 | ||
333 | void RecalcSizes(); | |
334 | wxSize CalcMin(); | |
335 | ||
336 | int GetOrientation() | |
337 | { return m_orient; } | |
338 | ||
339 | void SetOrientation(int orient) | |
340 | { m_orient = orient; } | |
341 | ||
342 | protected: | |
343 | int m_orient; | |
344 | int m_stretchable; | |
345 | int m_minWidth; | |
346 | int m_minHeight; | |
347 | int m_fixedWidth; | |
348 | int m_fixedHeight; | |
349 | ||
350 | private: | |
351 | DECLARE_CLASS(wxBoxSizer); | |
352 | }; | |
353 | ||
354 | //--------------------------------------------------------------------------- | |
355 | // wxStaticBoxSizer | |
356 | //--------------------------------------------------------------------------- | |
357 | ||
358 | #if wxUSE_STATBOX | |
359 | ||
360 | class WXDLLEXPORT wxStaticBox; | |
361 | ||
362 | class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer | |
363 | { | |
364 | public: | |
365 | wxStaticBoxSizer( wxStaticBox *box, int orient ); | |
366 | ||
367 | void RecalcSizes(); | |
368 | wxSize CalcMin(); | |
369 | ||
370 | wxStaticBox *GetStaticBox() | |
371 | { return m_staticBox; } | |
372 | ||
373 | protected: | |
374 | wxStaticBox *m_staticBox; | |
375 | ||
376 | private: | |
377 | DECLARE_CLASS(wxStaticBoxSizer); | |
378 | DECLARE_NO_COPY_CLASS(wxStaticBoxSizer) | |
379 | }; | |
380 | ||
381 | #endif // wxUSE_STATBOX | |
382 | ||
383 | //--------------------------------------------------------------------------- | |
384 | // wxNotebookSizer | |
385 | //--------------------------------------------------------------------------- | |
386 | ||
387 | #if wxUSE_NOTEBOOK | |
388 | ||
389 | class WXDLLEXPORT wxNotebook; | |
390 | ||
391 | class WXDLLEXPORT wxNotebookSizer: public wxSizer | |
392 | { | |
393 | public: | |
394 | wxNotebookSizer( wxNotebook *nb ); | |
395 | ||
396 | void RecalcSizes(); | |
397 | wxSize CalcMin(); | |
398 | ||
399 | wxNotebook *GetNotebook() | |
400 | { return m_notebook; } | |
401 | ||
402 | protected: | |
403 | wxNotebook *m_notebook; | |
404 | ||
405 | private: | |
406 | DECLARE_CLASS(wxNotebookSizer); | |
407 | DECLARE_NO_COPY_CLASS(wxNotebookSizer) | |
408 | }; | |
409 | ||
410 | #endif // wxUSE_NOTEBOOK | |
411 | ||
412 | ||
413 | #endif | |
414 | // __WXSIZER_H__ |