Added wxNotebookSizer
[wxWidgets.git] / include / wx / sizer.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: sizer.h
3 // Purpose: provide wxSizer class for layouting
4 // Author: Robert Roebling and Robin Dunn
5 // Modified by:
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 #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
29 class wxStaticBox;
30 class wxNotebook;
31
32 class wxSizerItem;
33 class wxSizer;
34 class wxBoxSizer;
35 class wxStaticBoxSizer;
36
37 //---------------------------------------------------------------------------
38 // wxSizerItem
39 //---------------------------------------------------------------------------
40
41 class WXDLLEXPORT wxSizerItem: public wxObject
42 {
43 DECLARE_CLASS(wxSizerItem);
44 public:
45 // spacer
46 wxSizerItem( int width, int height, int option, int flag, int border, wxObject* userData);
47
48 // window
49 wxSizerItem( wxWindow *window, int option, int flag, int border, wxObject* userData );
50
51 // subsizer
52 wxSizerItem( wxSizer *sizer, int option, int flag, int border, wxObject* userData );
53
54 ~wxSizerItem();
55
56 virtual wxSize GetSize();
57 virtual wxSize CalcMin();
58 virtual void SetDimension( wxPoint pos, wxSize size );
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 ) { m_ratio = ratio; }
67 float GetRatio() const { return m_ratio; }
68
69 bool IsWindow();
70 bool IsSizer();
71 bool IsSpacer();
72
73 wxWindow *GetWindow() const
74 { return m_window; }
75 wxSizer *GetSizer() const
76 { return m_sizer; }
77 int GetOption() const
78 { return m_option; }
79 int GetFlag() const
80 { return m_flag; }
81 int GetBorder() const
82 { return m_border; }
83 wxObject* GetUserData()
84 { return m_userData; }
85
86 protected:
87 wxWindow *m_window;
88 wxSizer *m_sizer;
89 wxSize m_size;
90 wxSize m_minSize;
91 int m_option;
92 int m_border;
93 int m_flag;
94 // als: aspect ratio can always be calculated from m_size,
95 // but this would cause precision loss when the window
96 // is shrinked. it is safer to preserve initial value.
97 float m_ratio;
98 wxObject *m_userData;
99 };
100
101 //---------------------------------------------------------------------------
102 // wxSizer
103 //---------------------------------------------------------------------------
104
105 class WXDLLEXPORT wxSizer: public wxObject
106 {
107 DECLARE_CLASS(wxSizer);
108 public:
109 wxSizer();
110 ~wxSizer();
111
112 virtual void Add( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
113 virtual void Add( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
114 virtual void Add( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
115
116 virtual void Prepend( wxWindow *window, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
117 virtual void Prepend( wxSizer *sizer, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
118 virtual void Prepend( int width, int height, int option = 0, int flag = 0, int border = 0, wxObject* userData = NULL );
119
120 virtual bool Remove( wxWindow *window );
121 virtual bool Remove( wxSizer *sizer );
122 virtual bool Remove( int pos );
123
124 void SetDimension( int x, int y, int width, int height );
125
126 wxSize GetSize()
127 { return m_size; }
128 wxPoint GetPosition()
129 { return m_position; }
130 wxSize GetMinSize()
131 { return CalcMin(); }
132
133 virtual void RecalcSizes() = 0;
134 virtual wxSize CalcMin() = 0;
135
136 virtual void Layout();
137
138 void Fit( wxWindow *window );
139 void SetSizeHints( wxWindow *window );
140
141 wxList& GetChildren()
142 { return m_children; }
143
144 protected:
145 wxSize m_size;
146 wxPoint m_position;
147 wxList m_children;
148
149 wxSize GetMinWindowSize( wxWindow *window );
150 };
151
152 //---------------------------------------------------------------------------
153 // wxBoxSizer
154 //---------------------------------------------------------------------------
155
156 class WXDLLEXPORT wxBoxSizer: public wxSizer
157 {
158 DECLARE_CLASS(wxBoxSizer);
159 public:
160 wxBoxSizer( int orient );
161
162 void RecalcSizes();
163 wxSize CalcMin();
164
165 int GetOrientation()
166 { return m_orient; }
167
168 protected:
169 int m_orient;
170 int m_stretchable;
171 int m_minWidth;
172 int m_minHeight;
173 int m_fixedWidth;
174 int m_fixedHeight;
175 };
176
177 //---------------------------------------------------------------------------
178 // wxStaticBoxSizer
179 //---------------------------------------------------------------------------
180
181 class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer
182 {
183 DECLARE_CLASS(wxStaticBoxSizer);
184 public:
185 wxStaticBoxSizer( wxStaticBox *box, int orient );
186
187 void RecalcSizes();
188 wxSize CalcMin();
189
190 wxStaticBox *GetStaticBox()
191 { return m_staticBox; }
192
193 protected:
194 wxStaticBox *m_staticBox;
195 };
196
197 //---------------------------------------------------------------------------
198 // wxNotebookSizer
199 //---------------------------------------------------------------------------
200
201 class WXDLLEXPORT wxNotebookSizer: public wxSizer
202 {
203 DECLARE_CLASS(wxNotebookSizer);
204 public:
205 wxNotebookSizer( wxNotebook *nb );
206
207 void RecalcSizes();
208 wxSize CalcMin();
209
210 wxNotebook *GetNotebook()
211 { return m_notebook; }
212
213 protected:
214 wxNotebook *m_notebook;
215 };
216
217 #endif
218 // __WXSIZER_H__