]> git.saurik.com Git - wxWidgets.git/blame - include/wx/sizer.h
added support for appearance brushes
[wxWidgets.git] / include / wx / sizer.h
CommitLineData
5279a24d
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: sizer.h
0c0d686f 3// Purpose: provide wxSizer class for layouting
5279a24d
RR
4// Author: Robert Roebling and Robin Dunn
5// Modified by:
0c0d686f 6// Created:
5279a24d
RR
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#ifdef __GNUG__
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
3417c2cd
RR
29class wxSizerItem;
30class wxSizer;
92afa2b1 31class wxBoxSizer;
5279a24d
RR
32
33//---------------------------------------------------------------------------
3417c2cd 34// wxSizerItem
5279a24d
RR
35//---------------------------------------------------------------------------
36
3417c2cd 37class WXDLLEXPORT wxSizerItem: public wxObject
5279a24d
RR
38{
39public:
df5ddbca
RR
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();
84f7908b
RR
50
51 virtual void DeleteWindows();
df5ddbca
RR
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; }
2aab8f16 66 void SetRatio( float ratio )
df5ddbca 67 { m_ratio = ratio; }
2aab8f16 68 float GetRatio() const
df5ddbca
RR
69 { return m_ratio; }
70
71 bool IsWindow();
72 bool IsSizer();
73 bool IsSpacer();
2aab8f16 74
df5ddbca
RR
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
84 wxWindow *GetWindow() const
85 { return m_window; }
86 void SetWindow( wxWindow *window )
87 { m_window = window; }
88 wxSizer *GetSizer() const
89 { return m_sizer; }
90 void SetSizer( wxSizer *sizer )
91 { m_sizer = sizer; }
92 int GetOption() const
93 { return m_option; }
94 int GetFlag() const
95 { return m_flag; }
96 int GetBorder() const
97 { return m_border; }
98 wxObject* GetUserData()
99 { return m_userData; }
100 wxPoint GetPosition()
101 { return m_pos; }
0c0d686f 102
c62ac5b6 103protected:
df5ddbca
RR
104 wxWindow *m_window;
105 wxSizer *m_sizer;
106 wxSize m_size;
107 wxPoint m_pos;
108 wxSize m_minSize;
109 int m_option;
110 int m_border;
111 int m_flag;
112 // als: aspect ratio can always be calculated from m_size,
113 // but this would cause precision loss when the window
114 // is shrinked. it is safer to preserve initial value.
115 float m_ratio;
116 wxObject *m_userData;
2aab8f16 117
df5ddbca
RR
118private:
119 DECLARE_CLASS(wxSizerItem);
c62ac5b6 120};
5279a24d
RR
121
122//---------------------------------------------------------------------------
3417c2cd 123// wxSizer
5279a24d
RR
124//---------------------------------------------------------------------------
125
2aab8f16 126class WXDLLEXPORT wxSizer: public wxObject, public wxClientDataContainer
5279a24d
RR
127{
128public:
f6bcfd97
BP
129 wxSizer();
130 ~wxSizer();
131
132 /* These should be called Append() really. */
133 virtual void Add( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
134 virtual void Add( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
135 virtual void Add( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
136
137 virtual void Insert( int before, wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
138 virtual void Insert( int before, wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
139 virtual void Insert( int before, int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
140
141 virtual void Prepend( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
142 virtual void Prepend( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
143 virtual void Prepend( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
144
145 virtual bool Remove( wxWindow *window );
146 virtual bool Remove( wxSizer *sizer );
147 virtual bool Remove( int pos );
84f7908b
RR
148
149 virtual void Clear( bool delete_windows=FALSE );
150 virtual void DeleteWindows();
f6bcfd97
BP
151
152 void SetMinSize( int width, int height )
153 { DoSetMinSize( width, height ); }
154 void SetMinSize( wxSize size )
155 { DoSetMinSize( size.x, size.y ); }
1e6feb95 156
f6bcfd97
BP
157 /* Searches recursively */
158 bool SetItemMinSize( wxWindow *window, int width, int height )
159 { return DoSetItemMinSize( window, width, height ); }
160 bool SetItemMinSize( wxWindow *window, wxSize size )
161 { return DoSetItemMinSize( window, size.x, size.y ); }
1e6feb95 162
f6bcfd97
BP
163 /* Searches recursively */
164 bool SetItemMinSize( wxSizer *sizer, int width, int height )
165 { return DoSetItemMinSize( sizer, width, height ); }
166 bool SetItemMinSize( wxSizer *sizer, wxSize size )
167 { return DoSetItemMinSize( sizer, size.x, size.y ); }
1e6feb95 168
f6bcfd97
BP
169 bool SetItemMinSize( int pos, int width, int height )
170 { return DoSetItemMinSize( pos, width, height ); }
171 bool SetItemMinSize( int pos, wxSize size )
172 { return DoSetItemMinSize( pos, size.x, size.y ); }
1e6feb95 173
f6bcfd97
BP
174 wxSize GetSize()
175 { return m_size; }
176 wxPoint GetPosition()
177 { return m_position; }
1e6feb95 178
f6bcfd97
BP
179 /* Calculate the minimal size or return m_minSize if bigger. */
180 wxSize GetMinSize();
181
182 virtual void RecalcSizes() = 0;
183 virtual wxSize CalcMin() = 0;
184
185 virtual void Layout();
186
187 void Fit( wxWindow *window );
188 void SetSizeHints( wxWindow *window );
189
190 wxList& GetChildren()
191 { return m_children; }
192
193 void SetDimension( int x, int y, int width, int height );
0c0d686f 194
f6bcfd97
BP
195protected:
196 wxSize m_size;
197 wxSize m_minSize;
198 wxPoint m_position;
199 wxList m_children;
200
65ba4113 201 wxSize GetMaxWindowSize( wxWindow *window );
f6bcfd97 202 wxSize GetMinWindowSize( wxWindow *window );
65ba4113
GT
203 wxSize FitSize( wxWindow *window );
204
f6bcfd97
BP
205 virtual void DoSetMinSize( int width, int height );
206 virtual bool DoSetItemMinSize( wxWindow *window, int width, int height );
207 virtual bool DoSetItemMinSize( wxSizer *sizer, int width, int height );
208 virtual bool DoSetItemMinSize( int pos, int width, int height );
1e6feb95 209
f6bcfd97
BP
210private:
211 DECLARE_CLASS(wxSizer);
212};
c62ac5b6 213
f6bcfd97
BP
214//---------------------------------------------------------------------------
215// wxGridSizer
216//---------------------------------------------------------------------------
0c0d686f 217
f6bcfd97
BP
218class WXDLLEXPORT wxGridSizer: public wxSizer
219{
220public:
221 wxGridSizer( int rows, int cols, int vgap, int hgap );
222 wxGridSizer( int cols, int vgap = 0, int hgap = 0 );
1e6feb95 223
f6bcfd97
BP
224 void RecalcSizes();
225 wxSize CalcMin();
226
227 void SetCols( int cols ) { m_cols = cols; }
228 void SetRows( int rows ) { m_rows = rows; }
229 void SetVGap( int gap ) { m_vgap = gap; }
230 void SetHGap( int gap ) { m_hgap = gap; }
231 int GetCols() { return m_cols; }
232 int GetRows() { return m_rows; }
233 int GetVGap() { return m_vgap; }
234 int GetHGap() { return m_hgap; }
1e6feb95 235
f6bcfd97
BP
236protected:
237 int m_rows;
238 int m_cols;
239 int m_vgap;
240 int m_hgap;
1e6feb95 241
f6bcfd97 242 void SetItemBounds( wxSizerItem *item, int x, int y, int w, int h );
1e6feb95 243
f6bcfd97
BP
244private:
245 DECLARE_CLASS(wxGridSizer);
246};
5279a24d 247
f6bcfd97
BP
248//---------------------------------------------------------------------------
249// wxFlexGridSizer
250//---------------------------------------------------------------------------
0c0d686f 251
f6bcfd97
BP
252class WXDLLEXPORT wxFlexGridSizer: public wxGridSizer
253{
254public:
255 wxFlexGridSizer( int rows, int cols, int vgap, int hgap );
256 wxFlexGridSizer( int cols, int vgap = 0, int hgap = 0 );
257 ~wxFlexGridSizer();
1e6feb95 258
f6bcfd97
BP
259 void RecalcSizes();
260 wxSize CalcMin();
1e6feb95 261
f6bcfd97
BP
262 void AddGrowableRow( size_t idx );
263 void RemoveGrowableRow( size_t idx );
264 void AddGrowableCol( size_t idx );
265 void RemoveGrowableCol( size_t idx );
0c0d686f 266
c62ac5b6 267protected:
f6bcfd97
BP
268 int *m_rowHeights;
269 int *m_colWidths;
270 wxArrayInt m_growableRows;
271 wxArrayInt m_growableCols;
1e6feb95 272
f6bcfd97 273 void CreateArrays();
1e6feb95 274
f6bcfd97
BP
275private:
276 DECLARE_CLASS(wxFlexGridSizer);
c62ac5b6
RR
277};
278
279//---------------------------------------------------------------------------
92afa2b1 280// wxBoxSizer
c62ac5b6
RR
281//---------------------------------------------------------------------------
282
92afa2b1 283class WXDLLEXPORT wxBoxSizer: public wxSizer
61d514bb
RR
284{
285public:
f6bcfd97 286 wxBoxSizer( int orient );
0c0d686f 287
f6bcfd97
BP
288 void RecalcSizes();
289 wxSize CalcMin();
0c0d686f 290
f6bcfd97
BP
291 int GetOrientation()
292 { return m_orient; }
0c0d686f 293
61d514bb
RR
294protected:
295 int m_orient;
296 int m_stretchable;
297 int m_minWidth;
298 int m_minHeight;
299 int m_fixedWidth;
300 int m_fixedHeight;
1e6feb95 301
f6bcfd97
BP
302private:
303 DECLARE_CLASS(wxBoxSizer);
61d514bb 304};
0c0d686f 305
27ea1d8a
RR
306//---------------------------------------------------------------------------
307// wxStaticBoxSizer
308//---------------------------------------------------------------------------
309
1e6feb95
VZ
310#if wxUSE_STATBOX
311
312class WXDLLEXPORT wxStaticBox;
313
27ea1d8a
RR
314class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
315{
316public:
f6bcfd97 317 wxStaticBoxSizer( wxStaticBox *box, int orient );
0c0d686f 318
f6bcfd97
BP
319 void RecalcSizes();
320 wxSize CalcMin();
0c0d686f 321
f6bcfd97
BP
322 wxStaticBox *GetStaticBox()
323 { return m_staticBox; }
0c0d686f 324
27ea1d8a 325protected:
f6bcfd97 326 wxStaticBox *m_staticBox;
1e6feb95 327
f6bcfd97
BP
328private:
329 DECLARE_CLASS(wxStaticBoxSizer);
27ea1d8a
RR
330};
331
1e6feb95
VZ
332#endif // wxUSE_STATBOX
333
83edc0a5
RR
334//---------------------------------------------------------------------------
335// wxNotebookSizer
336//---------------------------------------------------------------------------
337
65e4f9b9
VS
338#if wxUSE_NOTEBOOK
339
1e6feb95
VZ
340class WXDLLEXPORT wxNotebook;
341
83edc0a5
RR
342class WXDLLEXPORT wxNotebookSizer: public wxSizer
343{
83edc0a5 344public:
f6bcfd97 345 wxNotebookSizer( wxNotebook *nb );
83edc0a5 346
f6bcfd97
BP
347 void RecalcSizes();
348 wxSize CalcMin();
83edc0a5 349
f6bcfd97
BP
350 wxNotebook *GetNotebook()
351 { return m_notebook; }
83edc0a5
RR
352
353protected:
f6bcfd97 354 wxNotebook *m_notebook;
1e6feb95 355
f6bcfd97
BP
356private:
357 DECLARE_CLASS(wxNotebookSizer);
83edc0a5
RR
358};
359
1e6feb95 360#endif // wxUSE_NOTEBOOK
65e4f9b9
VS
361
362
5279a24d
RR
363#endif
364 // __WXSIZER_H__