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