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