]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/sizer.h
experimental --inplace flag implementation
[wxWidgets.git] / include / wx / sizer.h
... / ...
CommitLineData
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// (c) 2003, Ron Lee
10// Licence: wxWindows licence
11/////////////////////////////////////////////////////////////////////////////
12
13#ifndef __WXSIZER_H__
14#define __WXSIZER_H__
15
16#if defined(__GNUG__) && !defined(__APPLE__)
17#pragma interface "sizer.h"
18#endif
19
20#include "wx/defs.h"
21
22#include "wx/window.h"
23#include "wx/frame.h"
24#include "wx/dialog.h"
25
26//---------------------------------------------------------------------------
27// classes
28//---------------------------------------------------------------------------
29
30class wxSizerItem;
31class wxSizer;
32class wxBoxSizer;
33
34//---------------------------------------------------------------------------
35// wxSizerItem
36//---------------------------------------------------------------------------
37
38class WXDLLEXPORT wxSizerItem: public wxObject
39{
40public:
41 // spacer
42 wxSizerItem( int width,
43 int height,
44 int proportion,
45 int flag,
46 int border,
47 wxObject* userData);
48
49 // window
50 wxSizerItem( wxWindow *window,
51 int proportion,
52 int flag,
53 int border,
54 wxObject* userData );
55
56 // subsizer
57 wxSizerItem( wxSizer *sizer,
58 int proportion,
59 int flag,
60 int border,
61 wxObject* userData );
62
63 ~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 SetInitSize( int x, int y )
78 { m_minSize.x = x; m_minSize.y = y; }
79
80 void SetRatio( int width, int height )
81 // if either of dimensions is zero, ratio is assumed to be 1
82 // to avoid "divide by zero" errors
83 { m_ratio = (width && height) ? ((float) width / (float) height) : 1; }
84 void SetRatio( wxSize size )
85 { m_ratio = (size.x && size.y) ? ((float) size.x / (float) size.y) : 1; }
86 void SetRatio( float ratio )
87 { m_ratio = ratio; }
88 float GetRatio() const
89 { return m_ratio; }
90
91 bool IsWindow() const;
92 bool IsSizer() const;
93 bool IsSpacer() const;
94
95 // Deprecated in 2.6, use {G,S}etProportion instead.
96 wxDEPRECATED( void SetOption( int option ) );
97 wxDEPRECATED( int GetOption() const );
98
99 void SetProportion( int proportion )
100 { m_proportion = proportion; }
101 int GetProportion() const
102 { return m_proportion; }
103 void SetFlag( int flag )
104 { m_flag = flag; }
105 int GetFlag() const
106 { return m_flag; }
107 void SetBorder( int border )
108 { m_border = border; }
109 int GetBorder() const
110 { return m_border; }
111
112 wxWindow *GetWindow() const
113 { return m_window; }
114 void SetWindow( wxWindow *window )
115 { m_window = window; }
116 wxSizer *GetSizer() const
117 { return m_sizer; }
118 void SetSizer( wxSizer *sizer )
119 { m_sizer = sizer; }
120 const wxSize &GetSpacer() const
121 { return m_size; }
122 void SetSpacer( const wxSize &size )
123 { m_size = size; m_minSize = size; }
124
125 void Show ( bool show );
126 bool IsShown() const
127 { return m_show; }
128
129 wxObject* GetUserData() const
130 { return m_userData; }
131 wxPoint GetPosition() const
132 { return m_pos; }
133
134protected:
135 wxWindow *m_window;
136 wxSizer *m_sizer;
137 wxSize m_size;
138 wxPoint m_pos;
139 wxSize m_minSize;
140 int m_proportion;
141 int m_border;
142 int m_flag;
143
144 // If true, then this item is considered in the layout
145 // calculation. Otherwise, it is skipped over.
146 bool m_show;
147
148 // Aspect ratio can always be calculated from m_size,
149 // but this would cause precision loss when the window
150 // is shrunk. It is safer to preserve the initial value.
151 float m_ratio;
152
153 wxObject *m_userData;
154
155private:
156 DECLARE_CLASS(wxSizerItem);
157 DECLARE_NO_COPY_CLASS(wxSizerItem)
158};
159
160WX_DECLARE_EXPORTED_LIST( wxSizerItem, wxSizerItemList );
161
162
163//---------------------------------------------------------------------------
164// wxSizer
165//---------------------------------------------------------------------------
166
167class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer
168{
169public:
170 wxSizer();
171 ~wxSizer();
172
173 /* These should be called Append() really. */
174 virtual void Add( wxWindow *window,
175 int proportion = 0,
176 int flag = 0,
177 int border = 0,
178 wxObject* userData = NULL );
179 virtual void Add( wxSizer *sizer,
180 int proportion = 0,
181 int flag = 0,
182 int border = 0,
183 wxObject* userData = NULL );
184 virtual void Add( int width,
185 int height,
186 int proportion = 0,
187 int flag = 0,
188 int border = 0,
189 wxObject* userData = NULL );
190 virtual void Add( wxSizerItem *item );
191
192 virtual void Insert( size_t index,
193 wxWindow *window,
194 int proportion = 0,
195 int flag = 0,
196 int border = 0,
197 wxObject* userData = NULL );
198 virtual void Insert( size_t index,
199 wxSizer *sizer,
200 int proportion = 0,
201 int flag = 0,
202 int border = 0,
203 wxObject* userData = NULL );
204 virtual void Insert( size_t index,
205 int width,
206 int height,
207 int proportion = 0,
208 int flag = 0,
209 int border = 0,
210 wxObject* userData = NULL );
211 virtual void Insert( size_t index,
212 wxSizerItem *item );
213
214 virtual void Prepend( wxWindow *window,
215 int proportion = 0,
216 int flag = 0,
217 int border = 0,
218 wxObject* userData = NULL );
219 virtual void Prepend( wxSizer *sizer,
220 int proportion = 0,
221 int flag = 0,
222 int border = 0,
223 wxObject* userData = NULL );
224 virtual void Prepend( int width,
225 int height,
226 int proportion = 0,
227 int flag = 0,
228 int border = 0,
229 wxObject* userData = NULL );
230 virtual void Prepend( wxSizerItem *item );
231
232 // Deprecated in 2.6 since historically it does not delete the window,
233 // use Detach instead.
234 wxDEPRECATED( virtual bool Remove( wxWindow *window ) );
235 virtual bool Remove( wxSizer *sizer );
236 virtual bool Remove( size_t index );
237
238 virtual bool Detach( wxWindow *window );
239 virtual bool Detach( wxSizer *sizer );
240 virtual bool Detach( size_t index );
241
242 virtual void Clear( bool delete_windows=false );
243 virtual void DeleteWindows();
244
245 void SetMinSize( int width, int height )
246 { DoSetMinSize( width, height ); }
247 void SetMinSize( wxSize size )
248 { DoSetMinSize( size.x, size.y ); }
249
250 /* Searches recursively */
251 bool SetItemMinSize( wxWindow *window, int width, int height )
252 { return DoSetItemMinSize( window, width, height ); }
253 bool SetItemMinSize( wxWindow *window, wxSize size )
254 { return DoSetItemMinSize( window, size.x, size.y ); }
255
256 /* Searches recursively */
257 bool SetItemMinSize( wxSizer *sizer, int width, int height )
258 { return DoSetItemMinSize( sizer, width, height ); }
259 bool SetItemMinSize( wxSizer *sizer, wxSize size )
260 { return DoSetItemMinSize( sizer, size.x, size.y ); }
261
262 bool SetItemMinSize( size_t index, int width, int height )
263 { return DoSetItemMinSize( index, width, height ); }
264 bool SetItemMinSize( size_t index, wxSize size )
265 { return DoSetItemMinSize( index, size.x, size.y ); }
266
267 wxSize GetSize() const
268 { return m_size; }
269 wxPoint GetPosition() const
270 { return m_position; }
271
272 /* Calculate the minimal size or return m_minSize if bigger. */
273 wxSize GetMinSize();
274
275 virtual void RecalcSizes() = 0;
276 virtual wxSize CalcMin() = 0;
277
278 virtual void Layout();
279
280 wxSize Fit( wxWindow *window );
281 void FitInside( wxWindow *window );
282 void SetSizeHints( wxWindow *window );
283 void SetVirtualSizeHints( wxWindow *window );
284
285 wxSizerItemList& GetChildren()
286 { return m_children; }
287
288 void SetDimension( int x, int y, int width, int height );
289
290 // Manage whether individual scene items are considered
291 // in the layout calculations or not.
292 void Show( wxWindow *window, bool show = true );
293 void Show( wxSizer *sizer, bool show = true );
294 void Show( size_t index, bool show = true );
295
296 void Hide( wxSizer *sizer )
297 { Show( sizer, false ); }
298 void Hide( wxWindow *window )
299 { Show( window, false ); }
300 void Hide( size_t index )
301 { Show( index, false ); }
302
303 bool IsShown( wxWindow *window ) const;
304 bool IsShown( wxSizer *sizer ) const;
305 bool IsShown( size_t index ) const;
306
307 // Recursively call wxWindow::Show () on all sizer items.
308 void ShowItems (bool show);
309
310protected:
311 wxSize m_size;
312 wxSize m_minSize;
313 wxPoint m_position;
314 wxSizerItemList m_children;
315
316 wxSize GetMaxWindowSize( wxWindow *window ) const;
317 wxSize GetMinWindowSize( wxWindow *window );
318 wxSize GetMaxClientSize( wxWindow *window ) const;
319 wxSize GetMinClientSize( wxWindow *window );
320 wxSize FitSize( wxWindow *window );
321 wxSize VirtualFitSize( wxWindow *window );
322
323 virtual void DoSetMinSize( int width, int height );
324 virtual bool DoSetItemMinSize( wxWindow *window, int width, int height );
325 virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height );
326 virtual bool DoSetItemMinSize( size_t index, int width, int height );
327
328private:
329 DECLARE_CLASS(wxSizer);
330};
331
332//---------------------------------------------------------------------------
333// wxGridSizer
334//---------------------------------------------------------------------------
335
336class WXDLLEXPORT wxGridSizer: public wxSizer
337{
338public:
339 wxGridSizer( int rows, int cols, int vgap, int hgap );
340 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
341
342 void RecalcSizes();
343 wxSize CalcMin();
344
345 void SetCols( int cols ) { m_cols = cols; }
346 void SetRows( int rows ) { m_rows = rows; }
347 void SetVGap( int gap ) { m_vgap = gap; }
348 void SetHGap( int gap ) { m_hgap = gap; }
349 int GetCols() const { return m_cols; }
350 int GetRows() const { return m_rows; }
351 int GetVGap() const { return m_vgap; }
352 int GetHGap() const { return m_hgap; }
353
354protected:
355 int m_rows;
356 int m_cols;
357 int m_vgap;
358 int m_hgap;
359
360 // return the number of total items and the number of columns and rows
361 int CalcRowsCols(int& rows, int& cols) const;
362
363 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
364
365private:
366 DECLARE_CLASS(wxGridSizer);
367};
368
369//---------------------------------------------------------------------------
370// wxFlexGridSizer
371//---------------------------------------------------------------------------
372
373class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
374{
375public:
376 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
377 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
378 ~wxFlexGridSizer();
379
380 void RecalcSizes();
381 wxSize CalcMin();
382
383 void AddGrowableRow( size_t idx );
384 void RemoveGrowableRow( size_t idx );
385 void AddGrowableCol( size_t idx );
386 void RemoveGrowableCol( size_t idx );
387
388protected:
389 int *m_rowHeights;
390 int *m_colWidths;
391 wxArrayInt m_growableRows;
392 wxArrayInt m_growableCols;
393
394 void CreateArrays();
395
396private:
397 DECLARE_CLASS(wxFlexGridSizer);
398 DECLARE_NO_COPY_CLASS(wxFlexGridSizer)
399};
400
401//---------------------------------------------------------------------------
402// wxBoxSizer
403//---------------------------------------------------------------------------
404
405class WXDLLEXPORT wxBoxSizer: public wxSizer
406{
407public:
408 wxBoxSizer( int orient );
409
410 void RecalcSizes();
411 wxSize CalcMin();
412
413 int GetOrientation() const
414 { return m_orient; }
415
416 void SetOrientation(int orient)
417 { m_orient = orient; }
418
419protected:
420 int m_orient;
421 int m_stretchable;
422 int m_minWidth;
423 int m_minHeight;
424 int m_fixedWidth;
425 int m_fixedHeight;
426
427private:
428 DECLARE_CLASS(wxBoxSizer);
429};
430
431//---------------------------------------------------------------------------
432// wxStaticBoxSizer
433//---------------------------------------------------------------------------
434
435#if wxUSE_STATBOX
436
437class WXDLLEXPORT wxStaticBox;
438
439class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
440{
441public:
442 wxStaticBoxSizer( wxStaticBox *box, int orient );
443
444 void RecalcSizes();
445 wxSize CalcMin();
446
447 wxStaticBox *GetStaticBox() const
448 { return m_staticBox; }
449
450protected:
451 wxStaticBox *m_staticBox;
452
453private:
454 DECLARE_CLASS(wxStaticBoxSizer);
455 DECLARE_NO_COPY_CLASS(wxStaticBoxSizer)
456};
457
458#endif // wxUSE_STATBOX
459
460//---------------------------------------------------------------------------
461// wxNotebookSizer
462//---------------------------------------------------------------------------
463
464#if wxUSE_NOTEBOOK
465
466class WXDLLEXPORT wxNotebook;
467
468class WXDLLEXPORT wxNotebookSizer: public wxSizer
469{
470public:
471 wxNotebookSizer( wxNotebook *nb );
472
473 void RecalcSizes();
474 wxSize CalcMin();
475
476 wxNotebook *GetNotebook() const
477 { return m_notebook; }
478
479protected:
480 wxNotebook *m_notebook;
481
482private:
483 DECLARE_CLASS(wxNotebookSizer);
484 DECLARE_NO_COPY_CLASS(wxNotebookSizer)
485};
486
487#endif // wxUSE_NOTEBOOK
488
489
490#endif
491 // __WXSIZER_H__