]>
Commit | Line | Data |
---|---|---|
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 | ||
27ea1d8a RR |
29 | class wxStaticBox; |
30 | ||
3417c2cd RR |
31 | class wxSizerItem; |
32 | class wxSizer; | |
92afa2b1 | 33 | class wxBoxSizer; |
27ea1d8a | 34 | class wxStaticBoxSizer; |
5279a24d RR |
35 | |
36 | //--------------------------------------------------------------------------- | |
3417c2cd | 37 | // wxSizerItem |
5279a24d RR |
38 | //--------------------------------------------------------------------------- |
39 | ||
3417c2cd | 40 | class WXDLLEXPORT wxSizerItem: public wxObject |
5279a24d | 41 | { |
0c0d686f | 42 | DECLARE_CLASS(wxSizerItem); |
5279a24d RR |
43 | public: |
44 | // spacer | |
0c0d686f | 45 | wxSizerItem( int width, int height, int option, int flag, int border, wxObject* userData); |
5279a24d RR |
46 | |
47 | // window | |
0c0d686f | 48 | wxSizerItem( wxWindow *window, int option, int flag, int border, wxObject* userData ); |
5279a24d RR |
49 | |
50 | // subsizer | |
0c0d686f RD |
51 | wxSizerItem( wxSizer *sizer, int option, int flag, int border, wxObject* userData ); |
52 | ||
53 | ~wxSizerItem(); | |
5279a24d | 54 | |
c62ac5b6 RR |
55 | virtual wxSize GetSize(); |
56 | virtual wxSize CalcMin(); | |
57 | virtual void SetDimension( wxPoint pos, wxSize size ); | |
0c0d686f | 58 | |
be2577e4 RD |
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 | ||
5279a24d | 68 | bool IsWindow(); |
3417c2cd | 69 | bool IsSizer(); |
5279a24d | 70 | bool IsSpacer(); |
0c0d686f RD |
71 | |
72 | wxWindow *GetWindow() const | |
5279a24d | 73 | { return m_window; } |
0c0d686f | 74 | wxSizer *GetSizer() const |
5279a24d RR |
75 | { return m_sizer; } |
76 | int GetOption() const | |
77 | { return m_option; } | |
d597fcb7 RR |
78 | int GetFlag() const |
79 | { return m_flag; } | |
80 | int GetBorder() const | |
81 | { return m_border; } | |
0c0d686f RD |
82 | wxObject* GetUserData() |
83 | { return m_userData; } | |
84 | ||
c62ac5b6 | 85 | protected: |
5279a24d | 86 | wxWindow *m_window; |
3417c2cd | 87 | wxSizer *m_sizer; |
d597fcb7 | 88 | wxSize m_size; |
5279a24d RR |
89 | wxSize m_minSize; |
90 | int m_option; | |
d597fcb7 RR |
91 | int m_border; |
92 | int m_flag; | |
be2577e4 RD |
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; | |
0c0d686f | 97 | wxObject *m_userData; |
c62ac5b6 | 98 | }; |
5279a24d RR |
99 | |
100 | //--------------------------------------------------------------------------- | |
3417c2cd | 101 | // wxSizer |
5279a24d RR |
102 | //--------------------------------------------------------------------------- |
103 | ||
3417c2cd | 104 | class WXDLLEXPORT wxSizer: public wxObject |
5279a24d | 105 | { |
0c0d686f | 106 | DECLARE_CLASS(wxSizer); |
5279a24d | 107 | public: |
3417c2cd RR |
108 | wxSizer(); |
109 | ~wxSizer(); | |
0c0d686f RD |
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 | ||
42b4e99e RR |
119 | virtual bool Remove( wxWindow *window ); |
120 | virtual bool Remove( wxSizer *sizer ); | |
121 | virtual bool Remove( int pos ); | |
0c0d686f | 122 | |
c62ac5b6 | 123 | void SetDimension( int x, int y, int width, int height ); |
0c0d686f | 124 | |
5279a24d RR |
125 | wxSize GetSize() |
126 | { return m_size; } | |
127 | wxPoint GetPosition() | |
128 | { return m_position; } | |
129 | wxSize GetMinSize() | |
130 | { return CalcMin(); } | |
c62ac5b6 | 131 | |
5279a24d RR |
132 | virtual void RecalcSizes() = 0; |
133 | virtual wxSize CalcMin() = 0; | |
0c0d686f | 134 | |
c62ac5b6 | 135 | virtual void Layout(); |
5279a24d RR |
136 | |
137 | void Fit( wxWindow *window ); | |
138 | void SetSizeHints( wxWindow *window ); | |
0c0d686f RD |
139 | |
140 | wxList& GetChildren() | |
141 | { return m_children; } | |
142 | ||
c62ac5b6 | 143 | protected: |
5279a24d RR |
144 | wxSize m_size; |
145 | wxPoint m_position; | |
146 | wxList m_children; | |
0c0d686f | 147 | |
5279a24d | 148 | wxSize GetMinWindowSize( wxWindow *window ); |
c62ac5b6 RR |
149 | }; |
150 | ||
151 | //--------------------------------------------------------------------------- | |
92afa2b1 | 152 | // wxBoxSizer |
c62ac5b6 RR |
153 | //--------------------------------------------------------------------------- |
154 | ||
92afa2b1 | 155 | class WXDLLEXPORT wxBoxSizer: public wxSizer |
61d514bb | 156 | { |
0c0d686f | 157 | DECLARE_CLASS(wxBoxSizer); |
61d514bb | 158 | public: |
92afa2b1 | 159 | wxBoxSizer( int orient ); |
0c0d686f | 160 | |
61d514bb RR |
161 | void RecalcSizes(); |
162 | wxSize CalcMin(); | |
0c0d686f | 163 | |
61d514bb RR |
164 | int GetOrientation() |
165 | { return m_orient; } | |
0c0d686f | 166 | |
61d514bb RR |
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 | }; | |
0c0d686f | 175 | |
27ea1d8a RR |
176 | //--------------------------------------------------------------------------- |
177 | // wxStaticBoxSizer | |
178 | //--------------------------------------------------------------------------- | |
179 | ||
180 | class WXDLLEXPORT wxStaticBoxSizer: public wxBoxSizer | |
181 | { | |
0c0d686f | 182 | DECLARE_CLASS(wxStaticBoxSizer); |
27ea1d8a RR |
183 | public: |
184 | wxStaticBoxSizer( wxStaticBox *box, int orient ); | |
0c0d686f | 185 | |
27ea1d8a RR |
186 | void RecalcSizes(); |
187 | wxSize CalcMin(); | |
0c0d686f | 188 | |
27ea1d8a RR |
189 | wxStaticBox *GetStaticBox() |
190 | { return m_staticBox; } | |
0c0d686f | 191 | |
27ea1d8a RR |
192 | protected: |
193 | wxStaticBox *m_staticBox; | |
194 | }; | |
195 | ||
5279a24d RR |
196 | #endif |
197 | // __WXSIZER_H__ |