]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/sizer.h
fixed warnings after GetFont prototype change
[wxWidgets.git] / include / wx / sizer.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: sizer.h
3// Purpose: provide wxSizer class for layout
4// Author: Robert Roebling and Robin Dunn
5// Modified by: Ron Lee
6// Created:
7// RCS-ID: $Id$
8// Copyright: (c) Robin Dunn, Robert Roebling
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef __WXSIZER_H__
13#define __WXSIZER_H__
14
15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
29class wxSizerItem;
30class wxSizer;
31class wxBoxSizer;
32
33//---------------------------------------------------------------------------
34// wxSizerItem
35//---------------------------------------------------------------------------
36
37class WXDLLEXPORT wxSizerItem: public wxObject
38{
39public:
40 // spacer
41 wxSizerItem( int width,
42 int height,
43 int proportion,
44 int flag,
45 int border,
46 wxObject* userData);
47
48 // window
49 wxSizerItem( wxWindow *window,
50 int proportion,
51 int flag,
52 int border,
53 wxObject* userData );
54
55 // subsizer
56 wxSizerItem( wxSizer *sizer,
57 int proportion,
58 int flag,
59 int border,
60 wxObject* userData );
61
62 wxSizerItem();
63 virtual ~wxSizerItem();
64
65 virtual void DeleteWindows();
66
67 // Enable deleting the SizerItem without destroying the contained sizer.
68 void DetachSizer()
69 { m_sizer = 0; }
70
71 virtual wxSize GetSize() const;
72 virtual wxSize CalcMin();
73 virtual void SetDimension( wxPoint pos, wxSize size );
74
75 wxSize GetMinSize() const
76 { return m_minSize; }
77 void SetMinSize(const wxSize& size)
78 {
79 if (IsWindow() && !(m_flag & wxFIXED_MINSIZE))
80 m_window->SetSizeHints(size);
81 m_minSize = size;
82 }
83 void SetMinSize( int x, int y )
84 { SetMinSize(wxSize(x, y)); }
85 void SetInitSize( int x, int y )
86 { SetMinSize(wxSize(x, y)); }
87
88 void SetRatio( int width, int height )
89 // if either of dimensions is zero, ratio is assumed to be 1
90 // to avoid "divide by zero" errors
91 { m_ratio = (width && height) ? ((float) width / (float) height) : 1; }
92 void SetRatio( wxSize size )
93 { m_ratio = (size.x && size.y) ? ((float) size.x / (float) size.y) : 1; }
94 void SetRatio( float ratio )
95 { m_ratio = ratio; }
96 float GetRatio() const
97 { return m_ratio; }
98
99 bool IsWindow() const;
100 bool IsSizer() const;
101 bool IsSpacer() const;
102
103 // Deprecated in 2.6, use {G,S}etProportion instead.
104 wxDEPRECATED( void SetOption( int option ) );
105 wxDEPRECATED( int GetOption() const );
106
107 void SetProportion( int proportion )
108 { m_proportion = proportion; }
109 int GetProportion() const
110 { return m_proportion; }
111 void SetFlag( int flag )
112 { m_flag = flag; }
113 int GetFlag() const
114 { return m_flag; }
115 void SetBorder( int border )
116 { m_border = border; }
117 int GetBorder() const
118 { return m_border; }
119
120 wxWindow *GetWindow() const
121 { return m_window; }
122 void SetWindow( wxWindow *window )
123 { m_window = window; m_minSize = window->GetSize(); }
124 wxSizer *GetSizer() const
125 { return m_sizer; }
126 void SetSizer( wxSizer *sizer )
127 { m_sizer = sizer; }
128 const wxSize &GetSpacer() const
129 { return m_size; }
130 void SetSpacer( const wxSize &size )
131 { m_size = size; m_minSize = size; }
132
133 void Show ( bool show );
134 bool IsShown() const
135 { return m_show; }
136
137 wxObject* GetUserData() const
138 { return m_userData; }
139 wxPoint GetPosition() const
140 { return m_pos; }
141
142protected:
143 wxWindow *m_window;
144 wxSizer *m_sizer;
145 wxSize m_size;
146 wxPoint m_pos;
147 wxSize m_minSize;
148 int m_proportion;
149 int m_border;
150 int m_flag;
151
152 // If true, then this item is considered in the layout
153 // calculation. Otherwise, it is skipped over.
154 bool m_show;
155
156 // Aspect ratio can always be calculated from m_size,
157 // but this would cause precision loss when the window
158 // is shrunk. It is safer to preserve the initial value.
159 float m_ratio;
160
161 wxObject *m_userData;
162
163private:
164 DECLARE_CLASS(wxSizerItem)
165 DECLARE_NO_COPY_CLASS(wxSizerItem)
166};
167
168WX_DECLARE_EXPORTED_LIST( wxSizerItem, wxSizerItemList );
169
170
171//---------------------------------------------------------------------------
172// wxSizer
173//---------------------------------------------------------------------------
174
175class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer
176{
177public:
178 wxSizer();
179 ~wxSizer();
180
181 /* These should be called Append() really. */
182 virtual void Add( wxWindow *window,
183 int proportion = 0,
184 int flag = 0,
185 int border = 0,
186 wxObject* userData = NULL );
187 virtual void Add( wxSizer *sizer,
188 int proportion = 0,
189 int flag = 0,
190 int border = 0,
191 wxObject* userData = NULL );
192 virtual void Add( int width,
193 int height,
194 int proportion = 0,
195 int flag = 0,
196 int border = 0,
197 wxObject* userData = NULL );
198 virtual void Add( wxSizerItem *item );
199
200 virtual void Insert( size_t index,
201 wxWindow *window,
202 int proportion = 0,
203 int flag = 0,
204 int border = 0,
205 wxObject* userData = NULL );
206 virtual void Insert( size_t index,
207 wxSizer *sizer,
208 int proportion = 0,
209 int flag = 0,
210 int border = 0,
211 wxObject* userData = NULL );
212 virtual void Insert( size_t index,
213 int width,
214 int height,
215 int proportion = 0,
216 int flag = 0,
217 int border = 0,
218 wxObject* userData = NULL );
219 virtual void Insert( size_t index,
220 wxSizerItem *item );
221
222 virtual void Prepend( wxWindow *window,
223 int proportion = 0,
224 int flag = 0,
225 int border = 0,
226 wxObject* userData = NULL );
227 virtual void Prepend( wxSizer *sizer,
228 int proportion = 0,
229 int flag = 0,
230 int border = 0,
231 wxObject* userData = NULL );
232 virtual void Prepend( int width,
233 int height,
234 int proportion = 0,
235 int flag = 0,
236 int border = 0,
237 wxObject* userData = NULL );
238 virtual void Prepend( wxSizerItem *item );
239
240 // Deprecated in 2.6 since historically it does not delete the window,
241 // use Detach instead.
242 wxDEPRECATED( virtual bool Remove( wxWindow *window ) );
243 virtual bool Remove( wxSizer *sizer );
244 virtual bool Remove( int index );
245
246 virtual bool Detach( wxWindow *window );
247 virtual bool Detach( wxSizer *sizer );
248 virtual bool Detach( int index );
249
250 virtual void Clear( bool delete_windows = false );
251 virtual void DeleteWindows();
252
253 void SetMinSize( int width, int height )
254 { DoSetMinSize( width, height ); }
255 void SetMinSize( wxSize size )
256 { DoSetMinSize( size.x, size.y ); }
257
258 /* Searches recursively */
259 bool SetItemMinSize( wxWindow *window, int width, int height )
260 { return DoSetItemMinSize( window, width, height ); }
261 bool SetItemMinSize( wxWindow *window, wxSize size )
262 { return DoSetItemMinSize( window, size.x, size.y ); }
263
264 /* Searches recursively */
265 bool SetItemMinSize( wxSizer *sizer, int width, int height )
266 { return DoSetItemMinSize( sizer, width, height ); }
267 bool SetItemMinSize( wxSizer *sizer, wxSize size )
268 { return DoSetItemMinSize( sizer, size.x, size.y ); }
269
270 bool SetItemMinSize( size_t index, int width, int height )
271 { return DoSetItemMinSize( index, width, height ); }
272 bool SetItemMinSize( size_t index, wxSize size )
273 { return DoSetItemMinSize( index, size.x, size.y ); }
274
275 wxSize GetSize() const
276 { return m_size; }
277 wxPoint GetPosition() const
278 { return m_position; }
279
280 /* Calculate the minimal size or return m_minSize if bigger. */
281 wxSize GetMinSize();
282
283 virtual void RecalcSizes() = 0;
284 virtual wxSize CalcMin() = 0;
285
286 virtual void Layout();
287
288 wxSize Fit( wxWindow *window );
289 void FitInside( wxWindow *window );
290 void SetSizeHints( wxWindow *window );
291 void SetVirtualSizeHints( wxWindow *window );
292
293 wxSizerItemList& GetChildren()
294 { return m_children; }
295
296 void SetDimension( int x, int y, int width, int height );
297
298 // Manage whether individual scene items are considered
299 // in the layout calculations or not.
300 void Show( wxWindow *window, bool show = true );
301 void Show( wxSizer *sizer, bool show = true );
302 void Show( size_t index, bool show = true );
303
304 void Hide( wxSizer *sizer )
305 { Show( sizer, false ); }
306 void Hide( wxWindow *window )
307 { Show( window, false ); }
308 void Hide( size_t index )
309 { Show( index, false ); }
310
311 bool IsShown( wxWindow *window ) const;
312 bool IsShown( wxSizer *sizer ) const;
313 bool IsShown( size_t index ) const;
314
315 // Recursively call wxWindow::Show () on all sizer items.
316 virtual void ShowItems (bool show);
317
318protected:
319 wxSize m_size;
320 wxSize m_minSize;
321 wxPoint m_position;
322 wxSizerItemList m_children;
323
324 wxSize GetMaxWindowSize( wxWindow *window ) const;
325 wxSize GetMinWindowSize( wxWindow *window );
326 wxSize GetMaxClientSize( wxWindow *window ) const;
327 wxSize GetMinClientSize( wxWindow *window );
328 wxSize FitSize( wxWindow *window );
329 wxSize VirtualFitSize( wxWindow *window );
330
331 virtual void DoSetMinSize( int width, int height );
332 virtual bool DoSetItemMinSize( wxWindow *window, int width, int height );
333 virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height );
334 virtual bool DoSetItemMinSize( size_t index, int width, int height );
335
336private:
337 DECLARE_CLASS(wxSizer)
338};
339
340//---------------------------------------------------------------------------
341// wxGridSizer
342//---------------------------------------------------------------------------
343
344class WXDLLEXPORT wxGridSizer: public wxSizer
345{
346public:
347 wxGridSizer( int rows, int cols, int vgap, int hgap );
348 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
349
350 virtual void RecalcSizes();
351 virtual wxSize CalcMin();
352
353 void SetCols( int cols ) { m_cols = cols; }
354 void SetRows( int rows ) { m_rows = rows; }
355 void SetVGap( int gap ) { m_vgap = gap; }
356 void SetHGap( int gap ) { m_hgap = gap; }
357 int GetCols() const { return m_cols; }
358 int GetRows() const { return m_rows; }
359 int GetVGap() const { return m_vgap; }
360 int GetHGap() const { return m_hgap; }
361
362protected:
363 int m_rows;
364 int m_cols;
365 int m_vgap;
366 int m_hgap;
367
368 // return the number of total items and the number of columns and rows
369 int CalcRowsCols(int& rows, int& cols) const;
370
371 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
372
373private:
374 DECLARE_CLASS(wxGridSizer)
375};
376
377//---------------------------------------------------------------------------
378// wxFlexGridSizer
379//---------------------------------------------------------------------------
380
381// the bevaiour for resizing wxFlexGridSizer cells in the "non-flexible"
382// direction
383enum wxFlexSizerGrowMode
384{
385 // don't resize the cells in non-flexible direction at all
386 wxFLEX_GROWMODE_NONE,
387
388 // uniformly resize only the specified ones (default)
389 wxFLEX_GROWMODE_SPECIFIED,
390
391 // uniformly resize all cells
392 wxFLEX_GROWMODE_ALL
393};
394
395class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
396{
397public:
398 // ctors/dtor
399 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
400 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
401 virtual ~wxFlexGridSizer();
402
403
404 // set the rows/columns which will grow (the others will remain of the
405 // constant initial size)
406 void AddGrowableRow( size_t idx, int proportion = 0 );
407 void RemoveGrowableRow( size_t idx );
408 void AddGrowableCol( size_t idx, int proportion = 0 );
409 void RemoveGrowableCol( size_t idx );
410
411
412 // the sizer cells may grow in both directions, not grow at all or only
413 // grow in one direction but not the other
414
415 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
416 void SetFlexibleDirection(int direction) { m_flexDirection = direction; }
417 int GetFlexibleDirection() const { return m_flexDirection; }
418
419 // note that the grow mode only applies to the direction which is not
420 // flexible
421 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode) { m_growMode = mode; }
422 wxFlexSizerGrowMode GetNonFlexibleGrowMode() const { return m_growMode; }
423
424 // Read-only access to the row heights and col widths arrays
425 const wxArrayInt& GetRowHeights() const { return m_rowHeights; }
426 const wxArrayInt& GetColWidths() const { return m_colWidths; }
427
428 // implementation
429 virtual void RecalcSizes();
430 virtual wxSize CalcMin();
431
432protected:
433 void AdjustForFlexDirection();
434 void AdjustForGrowables(const wxSize& sz, const wxSize& minsz,
435 int nrows, int ncols);
436
437 // the heights/widths of all rows/columns
438 wxArrayInt m_rowHeights,
439 m_colWidths;
440
441 // indices of the growable columns and rows
442 wxArrayInt m_growableRows,
443 m_growableCols;
444
445 // proportion values of the corresponding growable rows and columns
446 wxArrayInt m_growableRowsProportions,
447 m_growableColsProportions;
448
449 // parameters describing whether the growable cells should be resized in
450 // both directions or only one
451 int m_flexDirection;
452 wxFlexSizerGrowMode m_growMode;
453
454private:
455 DECLARE_CLASS(wxFlexGridSizer)
456 DECLARE_NO_COPY_CLASS(wxFlexGridSizer)
457};
458
459//---------------------------------------------------------------------------
460// wxBoxSizer
461//---------------------------------------------------------------------------
462
463class WXDLLEXPORT wxBoxSizer: public wxSizer
464{
465public:
466 wxBoxSizer( int orient );
467
468 void RecalcSizes();
469 wxSize CalcMin();
470
471 int GetOrientation() const
472 { return m_orient; }
473
474 void SetOrientation(int orient)
475 { m_orient = orient; }
476
477protected:
478 int m_orient;
479 int m_stretchable;
480 int m_minWidth;
481 int m_minHeight;
482 int m_fixedWidth;
483 int m_fixedHeight;
484
485private:
486 DECLARE_CLASS(wxBoxSizer)
487};
488
489//---------------------------------------------------------------------------
490// wxStaticBoxSizer
491//---------------------------------------------------------------------------
492
493#if wxUSE_STATBOX
494
495class WXDLLEXPORT wxStaticBox;
496
497class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
498{
499public:
500 wxStaticBoxSizer( wxStaticBox *box, int orient );
501
502 void RecalcSizes();
503 wxSize CalcMin();
504
505 wxStaticBox *GetStaticBox() const
506 { return m_staticBox; }
507
508 // override to hide/show the static box as well
509 virtual void ShowItems (bool show);
510
511protected:
512 wxStaticBox *m_staticBox;
513
514private:
515 DECLARE_CLASS(wxStaticBoxSizer)
516 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer)
517};
518
519#endif // wxUSE_STATBOX
520
521
522#if WXWIN_COMPATIBILITY_2_4
523// NB: wxBookCtrlSizer and wxNotebookSizer are deprecated, they
524// don't do anything. wxBookCtrl::DoGetBestSize does the job now.
525
526// ----------------------------------------------------------------------------
527// wxBookCtrlSizer
528// ----------------------------------------------------------------------------
529
530#if wxUSE_BOOKCTRL
531
532// this sizer works with wxNotebook/wxListbook/... and sizes the control to
533// fit its pages
534class WXDLLEXPORT wxBookCtrl;
535
536class WXDLLEXPORT wxBookCtrlSizer : public wxSizer
537{
538public:
539 wxDEPRECATED( wxBookCtrlSizer(wxBookCtrl *bookctrl) );
540
541 wxBookCtrl *GetControl() const { return m_bookctrl; }
542
543 virtual void RecalcSizes();
544 virtual wxSize CalcMin();
545
546protected:
547 // this protected ctor lets us mark the real one above as deprecated
548 // and still has warning-free build of the library itself:
549 wxBookCtrlSizer() {}
550
551 wxBookCtrl *m_bookctrl;
552
553private:
554 DECLARE_CLASS(wxBookCtrlSizer)
555 DECLARE_NO_COPY_CLASS(wxBookCtrlSizer)
556};
557
558
559#if wxUSE_NOTEBOOK
560
561// before wxBookCtrl we only had wxNotebookSizer, keep it for backwards
562// compatibility
563class WXDLLEXPORT wxNotebook;
564
565class WXDLLEXPORT wxNotebookSizer : public wxBookCtrlSizer
566{
567public:
568 wxDEPRECATED( wxNotebookSizer(wxNotebook *nb) );
569
570 wxNotebook *GetNotebook() const { return (wxNotebook *)m_bookctrl; }
571
572private:
573 DECLARE_CLASS(wxNotebookSizer)
574 DECLARE_NO_COPY_CLASS(wxNotebookSizer)
575};
576
577#endif // wxUSE_NOTEBOOK
578
579#endif // wxUSE_BOOKCTRL
580
581#endif // WXWIN_COMPATIBILITY_2_4
582
583
584#endif // __WXSIZER_H__
585