]>
Commit | Line | Data |
---|---|---|
5279a24d RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: sizer.cpp | |
1044a386 | 3 | // Purpose: provide new wxSizer class for layout |
5279a24d | 4 | // Author: Robert Roebling and Robin Dunn |
566d84a7 | 5 | // Modified by: Ron Lee |
0c0d686f | 6 | // Created: |
5279a24d RR |
7 | // RCS-ID: $Id$ |
8 | // Copyright: (c) Robin Dunn, Dirk Holtwick and Robert Roebling | |
12a3f227 | 9 | // (c) 2003, Ron Lee |
5279a24d RR |
10 | // Licence: wxWindows licence |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
5279a24d | 13 | #ifdef __GNUG__ |
c62ac5b6 | 14 | #pragma implementation "sizer.h" |
5279a24d RR |
15 | #endif |
16 | ||
77671fd2 VZ |
17 | // For compilers that support precompilation, includes "wx.h". |
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
5279a24d | 24 | #include "wx/sizer.h" |
61d514bb | 25 | #include "wx/utils.h" |
27ea1d8a | 26 | #include "wx/statbox.h" |
83edc0a5 | 27 | #include "wx/notebook.h" |
12a3f227 | 28 | #include <wx/listimpl.cpp> |
5279a24d | 29 | |
0c0d686f RD |
30 | //--------------------------------------------------------------------------- |
31 | ||
799ea011 GD |
32 | IMPLEMENT_ABSTRACT_CLASS(wxSizerItem, wxObject) |
33 | IMPLEMENT_ABSTRACT_CLASS(wxSizer, wxObject) | |
34 | IMPLEMENT_ABSTRACT_CLASS(wxGridSizer, wxSizer) | |
35 | IMPLEMENT_ABSTRACT_CLASS(wxFlexGridSizer, wxGridSizer) | |
36 | IMPLEMENT_ABSTRACT_CLASS(wxBoxSizer, wxSizer) | |
1e6feb95 | 37 | #if wxUSE_STATBOX |
799ea011 | 38 | IMPLEMENT_ABSTRACT_CLASS(wxStaticBoxSizer, wxBoxSizer) |
1e6feb95 | 39 | #endif |
60be2f47 | 40 | #if wxUSE_NOTEBOOK |
799ea011 | 41 | IMPLEMENT_ABSTRACT_CLASS(wxNotebookSizer, wxSizer) |
60be2f47 | 42 | #endif |
0c0d686f | 43 | |
12a3f227 RL |
44 | WX_DEFINE_EXPORTED_LIST( wxSizerItemList ); |
45 | ||
46 | ||
5279a24d | 47 | //--------------------------------------------------------------------------- |
3417c2cd | 48 | // wxSizerItem |
5279a24d RR |
49 | //--------------------------------------------------------------------------- |
50 | ||
12a3f227 RL |
51 | wxSizerItem::wxSizerItem( int width, int height, int proportion, int flag, int border, wxObject* userData ) |
52 | : m_window( NULL ) | |
53 | , m_sizer( NULL ) | |
00976fe5 RL |
54 | , m_size( wxSize( width, height ) ) // size is set directly |
55 | , m_minSize( m_size ) // minimal size is the initial size | |
12a3f227 | 56 | , m_proportion( proportion ) |
00976fe5 RL |
57 | , m_border( border ) |
58 | , m_flag( flag ) | |
12a3f227 | 59 | , m_show( true ) |
00976fe5 | 60 | , m_userData( userData ) |
5279a24d | 61 | { |
00976fe5 | 62 | SetRatio( m_size ); |
5279a24d RR |
63 | } |
64 | ||
12a3f227 | 65 | wxSizerItem::wxSizerItem( wxWindow *window, int proportion, int flag, int border, wxObject* userData ) |
00976fe5 | 66 | : m_window( window ) |
12a3f227 | 67 | , m_sizer( NULL ) |
00976fe5 | 68 | , m_minSize( window->GetSize() ) // minimal size is the initial size |
12a3f227 | 69 | , m_proportion( proportion ) |
00976fe5 RL |
70 | , m_border( border ) |
71 | , m_flag( flag ) | |
12a3f227 | 72 | , m_show( true ) |
00976fe5 | 73 | , m_userData( userData ) |
5279a24d | 74 | { |
be2577e4 | 75 | // aspect ratio calculated from initial size |
00976fe5 | 76 | SetRatio( m_minSize ); |
be2577e4 | 77 | |
00976fe5 | 78 | // m_size is calculated later |
5279a24d RR |
79 | } |
80 | ||
12a3f227 RL |
81 | wxSizerItem::wxSizerItem( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData ) |
82 | : m_window( NULL ) | |
00976fe5 | 83 | , m_sizer( sizer ) |
12a3f227 | 84 | , m_proportion( proportion ) |
00976fe5 RL |
85 | , m_border( border ) |
86 | , m_flag( flag ) | |
12a3f227 RL |
87 | , m_show( true ) |
88 | , m_ratio( 0.0 ) | |
00976fe5 | 89 | , m_userData( userData ) |
5279a24d | 90 | { |
00976fe5 RL |
91 | // m_minSize is calculated later |
92 | // m_size is calculated later | |
5279a24d RR |
93 | } |
94 | ||
0c0d686f RD |
95 | wxSizerItem::~wxSizerItem() |
96 | { | |
97 | if (m_userData) | |
98 | delete m_userData; | |
96fdbb60 | 99 | if (m_sizer) |
0c0d686f RD |
100 | delete m_sizer; |
101 | } | |
102 | ||
103 | ||
3417c2cd | 104 | wxSize wxSizerItem::GetSize() |
5279a24d | 105 | { |
d597fcb7 | 106 | wxSize ret; |
3417c2cd | 107 | if (IsSizer()) |
d597fcb7 RR |
108 | ret = m_sizer->GetSize(); |
109 | else | |
c62ac5b6 | 110 | if (IsWindow()) |
d597fcb7 RR |
111 | ret = m_window->GetSize(); |
112 | else ret = m_size; | |
0c0d686f | 113 | |
d597fcb7 RR |
114 | if (m_flag & wxWEST) |
115 | ret.x += m_border; | |
116 | if (m_flag & wxEAST) | |
117 | ret.x += m_border; | |
118 | if (m_flag & wxNORTH) | |
119 | ret.y += m_border; | |
120 | if (m_flag & wxSOUTH) | |
121 | ret.y += m_border; | |
0c0d686f | 122 | |
d597fcb7 | 123 | return ret; |
5279a24d RR |
124 | } |
125 | ||
3417c2cd | 126 | wxSize wxSizerItem::CalcMin() |
c62ac5b6 | 127 | { |
d597fcb7 | 128 | wxSize ret; |
3417c2cd | 129 | if (IsSizer()) |
be2577e4 | 130 | { |
f6bcfd97 | 131 | ret = m_sizer->GetMinSize(); |
d13d8d4e | 132 | |
be2577e4 RD |
133 | // if we have to preserve aspect ratio _AND_ this is |
134 | // the first-time calculation, consider ret to be initial size | |
d13d8d4e VZ |
135 | if ((m_flag & wxSHAPED) && !m_ratio) |
136 | SetRatio(ret); | |
be2577e4 | 137 | } |
d597fcb7 | 138 | else |
d13d8d4e VZ |
139 | { |
140 | if ( IsWindow() && (m_flag & wxADJUST_MINSIZE) ) | |
141 | { | |
2b5f62a0 VZ |
142 | // By user request, keep the minimal size for this item |
143 | // in sync with the largest of BestSize and any user supplied | |
144 | // minimum size hint. Useful in cases where the item is | |
145 | // changeable -- static text labels, etc. | |
146 | m_minSize = m_window->GetAdjustedBestSize(); | |
d13d8d4e VZ |
147 | } |
148 | ||
149 | ret = m_minSize; | |
150 | } | |
0c0d686f | 151 | |
d597fcb7 RR |
152 | if (m_flag & wxWEST) |
153 | ret.x += m_border; | |
154 | if (m_flag & wxEAST) | |
155 | ret.x += m_border; | |
156 | if (m_flag & wxNORTH) | |
157 | ret.y += m_border; | |
158 | if (m_flag & wxSOUTH) | |
159 | ret.y += m_border; | |
0c0d686f | 160 | |
d597fcb7 | 161 | return ret; |
c62ac5b6 RR |
162 | } |
163 | ||
3417c2cd | 164 | void wxSizerItem::SetDimension( wxPoint pos, wxSize size ) |
c62ac5b6 | 165 | { |
cdddaeea | 166 | if (m_flag & wxSHAPED) |
d597fcb7 | 167 | { |
be2577e4 RD |
168 | // adjust aspect ratio |
169 | int rwidth = (int) (size.y * m_ratio); | |
cdddaeea VZ |
170 | if (rwidth > size.x) |
171 | { | |
be2577e4 RD |
172 | // fit horizontally |
173 | int rheight = (int) (size.x / m_ratio); | |
174 | // add vertical space | |
175 | if (m_flag & wxALIGN_CENTER_VERTICAL) | |
176 | pos.y += (size.y - rheight) / 2; | |
177 | else if (m_flag & wxALIGN_BOTTOM) | |
178 | pos.y += (size.y - rheight); | |
179 | // use reduced dimensions | |
180 | size.y =rheight; | |
cdddaeea VZ |
181 | } |
182 | else if (rwidth < size.x) | |
183 | { | |
be2577e4 RD |
184 | // add horizontal space |
185 | if (m_flag & wxALIGN_CENTER_HORIZONTAL) | |
186 | pos.x += (size.x - rwidth) / 2; | |
187 | else if (m_flag & wxALIGN_RIGHT) | |
188 | pos.x += (size.x - rwidth); | |
189 | size.x = rwidth; | |
190 | } | |
191 | } | |
33ac7e6f | 192 | |
cdddaeea VZ |
193 | // This is what GetPosition() returns. Since we calculate |
194 | // borders afterwards, GetPosition() will be the left/top | |
195 | // corner of the surrounding border. | |
196 | m_pos = pos; | |
197 | ||
198 | if (m_flag & wxWEST) | |
199 | { | |
200 | pos.x += m_border; | |
201 | size.x -= m_border; | |
202 | } | |
203 | if (m_flag & wxEAST) | |
204 | { | |
205 | size.x -= m_border; | |
206 | } | |
207 | if (m_flag & wxNORTH) | |
208 | { | |
209 | pos.y += m_border; | |
210 | size.y -= m_border; | |
211 | } | |
212 | if (m_flag & wxSOUTH) | |
213 | { | |
214 | size.y -= m_border; | |
215 | } | |
0c0d686f | 216 | |
3417c2cd | 217 | if (IsSizer()) |
c62ac5b6 | 218 | m_sizer->SetDimension( pos.x, pos.y, size.x, size.y ); |
0c0d686f | 219 | |
c62ac5b6 | 220 | if (IsWindow()) |
b919f007 | 221 | m_window->SetSize( pos.x, pos.y, size.x, size.y, wxSIZE_ALLOW_MINUS_ONE ); |
d597fcb7 RR |
222 | |
223 | m_size = size; | |
c62ac5b6 RR |
224 | } |
225 | ||
84f7908b RR |
226 | void wxSizerItem::DeleteWindows() |
227 | { | |
228 | if (m_window) | |
229 | m_window->Destroy(); | |
be90c029 | 230 | |
84f7908b RR |
231 | if (m_sizer) |
232 | m_sizer->DeleteWindows(); | |
233 | } | |
234 | ||
3417c2cd | 235 | bool wxSizerItem::IsWindow() |
5279a24d RR |
236 | { |
237 | return (m_window != NULL); | |
238 | } | |
239 | ||
3417c2cd | 240 | bool wxSizerItem::IsSizer() |
5279a24d RR |
241 | { |
242 | return (m_sizer != NULL); | |
243 | } | |
244 | ||
3417c2cd | 245 | bool wxSizerItem::IsSpacer() |
5279a24d RR |
246 | { |
247 | return (m_window == NULL) && (m_sizer == NULL); | |
248 | } | |
249 | ||
12a3f227 RL |
250 | void wxSizerItem::Show( bool show ) |
251 | { | |
252 | m_show = show; | |
253 | ||
254 | if( IsWindow() ) | |
255 | m_window->Show( show ); | |
256 | else if( IsSizer() ) | |
257 | m_sizer->ShowItems( show ); | |
258 | ||
259 | // ... nothing else to do to hide/show spacers | |
260 | } | |
261 | ||
262 | void wxSizerItem::SetOption( int option ) | |
263 | { | |
264 | SetProportion( option ); | |
265 | } | |
266 | ||
267 | int wxSizerItem::GetOption() const | |
268 | { | |
269 | return GetProportion(); | |
270 | } | |
271 | ||
272 | ||
5279a24d | 273 | //--------------------------------------------------------------------------- |
3417c2cd | 274 | // wxSizer |
5279a24d RR |
275 | //--------------------------------------------------------------------------- |
276 | ||
3417c2cd | 277 | wxSizer::wxSizer() |
12a3f227 | 278 | : m_minSize( wxSize( 0, 0 ) ) |
5279a24d | 279 | { |
12a3f227 | 280 | m_children.DeleteContents( true ); |
5279a24d RR |
281 | } |
282 | ||
3417c2cd | 283 | wxSizer::~wxSizer() |
5279a24d | 284 | { |
be90c029 | 285 | Clear(); |
5279a24d | 286 | } |
0c0d686f | 287 | |
12a3f227 | 288 | void wxSizer::Add( wxWindow *window, int proportion, int flag, int border, wxObject* userData ) |
5279a24d | 289 | { |
12a3f227 RL |
290 | m_children.Append( new wxSizerItem( window, proportion, flag, border, userData ) ); |
291 | window->SetContainingSizer( this ); | |
5279a24d RR |
292 | } |
293 | ||
12a3f227 | 294 | void wxSizer::Add( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData ) |
5279a24d | 295 | { |
12a3f227 | 296 | m_children.Append( new wxSizerItem( sizer, proportion, flag, border, userData ) ); |
5279a24d RR |
297 | } |
298 | ||
12a3f227 | 299 | void wxSizer::Add( int width, int height, int proportion, int flag, int border, wxObject* userData ) |
5279a24d | 300 | { |
12a3f227 | 301 | m_children.Append( new wxSizerItem( width, height, proportion, flag, border, userData ) ); |
5279a24d RR |
302 | } |
303 | ||
12a3f227 | 304 | void wxSizer::Add( wxSizerItem *item ) |
42b4e99e | 305 | { |
12a3f227 RL |
306 | m_children.Append( item ); |
307 | ||
308 | if( item->GetWindow() ) | |
309 | item->GetWindow()->SetContainingSizer( this ); | |
42b4e99e RR |
310 | } |
311 | ||
12a3f227 | 312 | void wxSizer::Prepend( wxWindow *window, int proportion, int flag, int border, wxObject* userData ) |
42b4e99e | 313 | { |
12a3f227 RL |
314 | m_children.Insert( new wxSizerItem( window, proportion, flag, border, userData ) ); |
315 | window->SetContainingSizer( this ); | |
42b4e99e RR |
316 | } |
317 | ||
12a3f227 | 318 | void wxSizer::Prepend( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData ) |
42b4e99e | 319 | { |
12a3f227 | 320 | m_children.Insert( new wxSizerItem( sizer, proportion, flag, border, userData ) ); |
f35aa3da RR |
321 | } |
322 | ||
12a3f227 | 323 | void wxSizer::Prepend( int width, int height, int proportion, int flag, int border, wxObject* userData ) |
f35aa3da | 324 | { |
12a3f227 | 325 | m_children.Insert( new wxSizerItem( width, height, proportion, flag, border, userData ) ); |
f35aa3da RR |
326 | } |
327 | ||
12a3f227 | 328 | void wxSizer::Prepend( wxSizerItem *item ) |
f35aa3da | 329 | { |
12a3f227 RL |
330 | m_children.Insert( item ); |
331 | ||
332 | if( item->GetWindow() ) | |
333 | item->GetWindow()->SetContainingSizer( this ); | |
f35aa3da RR |
334 | } |
335 | ||
12a3f227 RL |
336 | void wxSizer::Insert( size_t index, |
337 | wxWindow *window, | |
338 | int proportion, | |
339 | int flag, | |
340 | int border, | |
341 | wxObject* userData ) | |
f35aa3da | 342 | { |
12a3f227 RL |
343 | m_children.Insert( index, |
344 | new wxSizerItem( window, proportion, flag, border, userData ) ); | |
345 | window->SetContainingSizer( this ); | |
42b4e99e RR |
346 | } |
347 | ||
12a3f227 RL |
348 | void wxSizer::Insert( size_t index, |
349 | wxSizer *sizer, | |
350 | int proportion, | |
351 | int flag, | |
352 | int border, | |
353 | wxObject* userData ) | |
42b4e99e | 354 | { |
12a3f227 RL |
355 | m_children.Insert( index, |
356 | new wxSizerItem( sizer, proportion, flag, border, userData ) ); | |
357 | } | |
0c0d686f | 358 | |
12a3f227 RL |
359 | void wxSizer::Insert( size_t index, |
360 | int width, | |
361 | int height, | |
362 | int proportion, | |
363 | int flag, | |
364 | int border, | |
365 | wxObject* userData ) | |
366 | { | |
367 | m_children.Insert( index, | |
368 | new wxSizerItem( width, height, proportion, flag, border, userData ) ); | |
369 | } | |
370 | ||
371 | void wxSizer::Insert( size_t index, wxSizerItem *item ) | |
372 | { | |
373 | m_children.Insert( index, item ); | |
0c0d686f | 374 | |
12a3f227 RL |
375 | if( item->GetWindow() ) |
376 | item->GetWindow()->SetContainingSizer( this ); | |
377 | } | |
378 | ||
379 | bool wxSizer::Remove( wxWindow *window ) | |
380 | { | |
381 | return Detach( window ); | |
42b4e99e RR |
382 | } |
383 | ||
384 | bool wxSizer::Remove( wxSizer *sizer ) | |
385 | { | |
12a3f227 | 386 | wxASSERT_MSG( sizer, _T("Removing NULL sizer") ); |
0c0d686f | 387 | |
12a3f227 | 388 | wxSizerItemList::Node *node = m_children.GetFirst(); |
42b4e99e RR |
389 | while (node) |
390 | { | |
12a3f227 RL |
391 | wxSizerItem *item = node->GetData(); |
392 | ||
3ca6a5f0 | 393 | if (item->GetSizer() == sizer) |
12a3f227 RL |
394 | return m_children.DeleteNode( node ); |
395 | ||
396 | node = node->GetNext(); | |
42b4e99e | 397 | } |
0c0d686f | 398 | |
12a3f227 | 399 | return false; |
42b4e99e RR |
400 | } |
401 | ||
12a3f227 | 402 | bool wxSizer::Remove( size_t index ) |
42b4e99e | 403 | { |
12a3f227 RL |
404 | wxCHECK_MSG( index < m_children.GetCount(), |
405 | false, | |
406 | _T("Remove index is out of range") ); | |
0c0d686f | 407 | |
12a3f227 | 408 | wxSizerItemList::Node *node = m_children.Item( index ); |
0c0d686f | 409 | |
12a3f227 RL |
410 | wxCHECK_MSG( node, false, _T("Failed to find child node") ); |
411 | ||
412 | return m_children.DeleteNode( node ); | |
42b4e99e | 413 | } |
0c0d686f | 414 | |
00976fe5 RL |
415 | bool wxSizer::Detach( wxSizer *sizer ) |
416 | { | |
12a3f227 | 417 | wxASSERT_MSG( sizer, _T("Detaching NULL sizer") ); |
00976fe5 | 418 | |
12a3f227 | 419 | wxSizerItemList::Node *node = m_children.GetFirst(); |
00976fe5 RL |
420 | while (node) |
421 | { | |
12a3f227 RL |
422 | wxSizerItem *item = node->GetData(); |
423 | ||
00976fe5 RL |
424 | if (item->GetSizer() == sizer) |
425 | { | |
96fdbb60 | 426 | item->DetachSizer(); |
12a3f227 RL |
427 | return m_children.DeleteNode( node ); |
428 | } | |
429 | node = node->GetNext(); | |
430 | } | |
431 | ||
432 | return false; | |
433 | } | |
434 | ||
435 | bool wxSizer::Detach( wxWindow *window ) | |
436 | { | |
437 | wxASSERT_MSG( window, _T("Detaching NULL window") ); | |
438 | ||
439 | wxSizerItemList::Node *node = m_children.GetFirst(); | |
440 | while (node) | |
441 | { | |
442 | wxSizerItem *item = node->GetData(); | |
443 | ||
444 | if (item->GetWindow() == window) | |
445 | { | |
446 | item->GetWindow()->SetContainingSizer( NULL ); | |
447 | return m_children.DeleteNode( node ); | |
00976fe5 | 448 | } |
12a3f227 | 449 | node = node->GetNext(); |
00976fe5 RL |
450 | } |
451 | ||
12a3f227 | 452 | return false; |
00976fe5 RL |
453 | } |
454 | ||
12a3f227 | 455 | bool wxSizer::Detach( size_t index ) |
00976fe5 | 456 | { |
12a3f227 RL |
457 | wxCHECK_MSG( index < m_children.GetCount(), |
458 | false, | |
459 | _T("Detach index is out of range") ); | |
460 | ||
461 | wxSizerItemList::Node *node = m_children.Item( index ); | |
00976fe5 | 462 | |
12a3f227 | 463 | wxCHECK_MSG( node, false, _T("Failed to find child node") ); |
00976fe5 | 464 | |
12a3f227 RL |
465 | node->GetData()->DetachSizer(); |
466 | ||
467 | return m_children.DeleteNode( node ); | |
00976fe5 RL |
468 | } |
469 | ||
84f7908b RR |
470 | void wxSizer::Clear( bool delete_windows ) |
471 | { | |
be90c029 | 472 | // First clear the ContainingSizer pointers |
12a3f227 | 473 | wxSizerItemList::Node *node = m_children.GetFirst(); |
be90c029 RD |
474 | while (node) |
475 | { | |
12a3f227 RL |
476 | wxSizerItem *item = node->GetData(); |
477 | ||
be90c029 | 478 | if (item->IsWindow()) |
12a3f227 RL |
479 | item->GetWindow()->SetContainingSizer( NULL ); |
480 | node = node->GetNext(); | |
be90c029 RD |
481 | } |
482 | ||
483 | // Destroy the windows if needed | |
84f7908b RR |
484 | if (delete_windows) |
485 | DeleteWindows(); | |
be90c029 RD |
486 | |
487 | // Now empty the list | |
84f7908b RR |
488 | m_children.Clear(); |
489 | } | |
490 | ||
491 | void wxSizer::DeleteWindows() | |
492 | { | |
12a3f227 | 493 | wxSizerItemList::Node *node = m_children.GetFirst(); |
84f7908b RR |
494 | while (node) |
495 | { | |
12a3f227 RL |
496 | wxSizerItem *item = node->GetData(); |
497 | ||
84f7908b | 498 | item->DeleteWindows(); |
12a3f227 | 499 | node = node->GetNext(); |
84f7908b RR |
500 | } |
501 | } | |
502 | ||
e5251d4f | 503 | wxSize wxSizer::Fit( wxWindow *window ) |
5279a24d | 504 | { |
9ef2e675 GT |
505 | wxSize size; |
506 | if (window->IsTopLevel()) | |
507 | size = FitSize( window ); | |
508 | else | |
509 | size = GetMinWindowSize( window ); | |
510 | ||
77424cfb | 511 | window->SetSize( size ); |
e5251d4f VZ |
512 | |
513 | return size; | |
5279a24d RR |
514 | } |
515 | ||
566d84a7 RL |
516 | void wxSizer::FitInside( wxWindow *window ) |
517 | { | |
518 | wxSize size; | |
519 | if (window->IsTopLevel()) | |
520 | size = VirtualFitSize( window ); | |
521 | else | |
522 | size = GetMinClientSize( window ); | |
523 | ||
524 | window->SetVirtualSize( size ); | |
525 | } | |
526 | ||
3417c2cd | 527 | void wxSizer::Layout() |
c62ac5b6 | 528 | { |
42b4e99e | 529 | CalcMin(); |
c62ac5b6 RR |
530 | RecalcSizes(); |
531 | } | |
532 | ||
3417c2cd | 533 | void wxSizer::SetSizeHints( wxWindow *window ) |
5279a24d | 534 | { |
34c3ffca RL |
535 | // Preserve the window's max size hints, but set the |
536 | // lower bound according to the sizer calculations. | |
537 | ||
e5251d4f VZ |
538 | wxSize size = Fit( window ); |
539 | ||
34c3ffca RL |
540 | window->SetSizeHints( size.x, |
541 | size.y, | |
542 | window->GetMaxWidth(), | |
543 | window->GetMaxHeight() ); | |
5279a24d RR |
544 | } |
545 | ||
566d84a7 RL |
546 | void wxSizer::SetVirtualSizeHints( wxWindow *window ) |
547 | { | |
548 | // Preserve the window's max size hints, but set the | |
549 | // lower bound according to the sizer calculations. | |
550 | ||
551 | FitInside( window ); | |
552 | wxSize size( window->GetVirtualSize() ); | |
553 | window->SetVirtualSizeHints( size.x, | |
554 | size.y, | |
555 | window->GetMaxWidth(), | |
556 | window->GetMaxHeight() ); | |
557 | } | |
558 | ||
34c3ffca | 559 | wxSize wxSizer::GetMaxWindowSize( wxWindow *window ) |
65ba4113 | 560 | { |
34c3ffca | 561 | return window->GetMaxSize(); |
65ba4113 GT |
562 | } |
563 | ||
3417c2cd | 564 | wxSize wxSizer::GetMinWindowSize( wxWindow *window ) |
5279a24d | 565 | { |
12a3f227 RL |
566 | wxSize minSize( GetMinSize() ); |
567 | wxSize size( window->GetSize() ); | |
568 | wxSize client_size( window->GetClientSize() ); | |
569 | ||
77671fd2 | 570 | return wxSize( minSize.x+size.x-client_size.x, |
0c0d686f | 571 | minSize.y+size.y-client_size.y ); |
5279a24d RR |
572 | } |
573 | ||
65ba4113 GT |
574 | // Return a window size that will fit within the screens dimensions |
575 | wxSize wxSizer::FitSize( wxWindow *window ) | |
576 | { | |
577 | wxSize size = GetMinWindowSize( window ); | |
578 | wxSize sizeMax = GetMaxWindowSize( window ); | |
579 | ||
34c3ffca RL |
580 | // Limit the size if sizeMax != wxDefaultSize |
581 | ||
582 | if ( size.x > sizeMax.x && sizeMax.x != -1 ) | |
65ba4113 | 583 | size.x = sizeMax.x; |
34c3ffca | 584 | if ( size.y > sizeMax.y && sizeMax.y != -1 ) |
65ba4113 GT |
585 | size.y = sizeMax.y; |
586 | ||
587 | return size; | |
588 | } | |
589 | ||
566d84a7 RL |
590 | wxSize wxSizer::GetMaxClientSize( wxWindow *window ) |
591 | { | |
592 | wxSize maxSize( window->GetMaxSize() ); | |
593 | ||
594 | if( maxSize != wxDefaultSize ) | |
595 | { | |
596 | wxSize size( window->GetSize() ); | |
597 | wxSize client_size( window->GetClientSize() ); | |
598 | ||
599 | return wxSize( maxSize.x + client_size.x - size.x, | |
600 | maxSize.y + client_size.y - size.y ); | |
601 | } | |
602 | else | |
603 | return wxDefaultSize; | |
604 | } | |
605 | ||
1b0674f7 | 606 | wxSize wxSizer::GetMinClientSize( wxWindow *WXUNUSED(window) ) |
566d84a7 RL |
607 | { |
608 | return GetMinSize(); // Already returns client size. | |
609 | } | |
610 | ||
611 | wxSize wxSizer::VirtualFitSize( wxWindow *window ) | |
612 | { | |
613 | wxSize size = GetMinClientSize( window ); | |
614 | wxSize sizeMax = GetMaxClientSize( window ); | |
615 | ||
616 | // Limit the size if sizeMax != wxDefaultSize | |
617 | ||
618 | if ( size.x > sizeMax.x && sizeMax.x != -1 ) | |
619 | size.x = sizeMax.x; | |
620 | if ( size.y > sizeMax.y && sizeMax.y != -1 ) | |
621 | size.y = sizeMax.y; | |
622 | ||
623 | return size; | |
624 | } | |
625 | ||
3417c2cd | 626 | void wxSizer::SetDimension( int x, int y, int width, int height ) |
5279a24d RR |
627 | { |
628 | m_position.x = x; | |
629 | m_position.y = y; | |
630 | m_size.x = width; | |
631 | m_size.y = height; | |
2b5f62a0 | 632 | Layout(); |
5279a24d RR |
633 | } |
634 | ||
f6bcfd97 | 635 | wxSize wxSizer::GetMinSize() |
3ca6a5f0 | 636 | { |
f6bcfd97 BP |
637 | wxSize ret( CalcMin() ); |
638 | if (ret.x < m_minSize.x) ret.x = m_minSize.x; | |
639 | if (ret.y < m_minSize.y) ret.y = m_minSize.y; | |
3ca6a5f0 | 640 | return ret; |
f6bcfd97 BP |
641 | } |
642 | ||
643 | void wxSizer::DoSetMinSize( int width, int height ) | |
644 | { | |
645 | m_minSize.x = width; | |
646 | m_minSize.y = height; | |
647 | } | |
648 | ||
649 | bool wxSizer::DoSetItemMinSize( wxWindow *window, int width, int height ) | |
650 | { | |
12a3f227 RL |
651 | wxASSERT_MSG( window, _T("SetMinSize for NULL window") ); |
652 | ||
653 | // Is it our immediate child? | |
f6bcfd97 | 654 | |
12a3f227 | 655 | wxSizerItemList::Node *node = m_children.GetFirst(); |
f6bcfd97 BP |
656 | while (node) |
657 | { | |
12a3f227 RL |
658 | wxSizerItem *item = node->GetData(); |
659 | ||
3ca6a5f0 BP |
660 | if (item->GetWindow() == window) |
661 | { | |
f6bcfd97 | 662 | item->SetInitSize( width, height ); |
12a3f227 | 663 | return true; |
3ca6a5f0 | 664 | } |
12a3f227 | 665 | node = node->GetNext(); |
f6bcfd97 BP |
666 | } |
667 | ||
12a3f227 RL |
668 | // No? Search any subsizers we own then |
669 | ||
670 | node = m_children.GetFirst(); | |
f6bcfd97 BP |
671 | while (node) |
672 | { | |
12a3f227 RL |
673 | wxSizerItem *item = node->GetData(); |
674 | ||
675 | if ( item->GetSizer() && | |
676 | item->GetSizer()->DoSetItemMinSize( window, width, height ) ) | |
3ca6a5f0 | 677 | { |
12a3f227 RL |
678 | // A child sizer found the requested windw, exit. |
679 | return true; | |
3ca6a5f0 | 680 | } |
12a3f227 | 681 | node = node->GetNext(); |
f6bcfd97 BP |
682 | } |
683 | ||
12a3f227 | 684 | return false; |
f6bcfd97 BP |
685 | } |
686 | ||
687 | bool wxSizer::DoSetItemMinSize( wxSizer *sizer, int width, int height ) | |
688 | { | |
12a3f227 | 689 | wxASSERT_MSG( sizer, _T("SetMinSize for NULL sizer") ); |
f6bcfd97 | 690 | |
12a3f227 RL |
691 | // Is it our immediate child? |
692 | ||
693 | wxSizerItemList::Node *node = m_children.GetFirst(); | |
f6bcfd97 BP |
694 | while (node) |
695 | { | |
12a3f227 RL |
696 | wxSizerItem *item = node->GetData(); |
697 | ||
3ca6a5f0 BP |
698 | if (item->GetSizer() == sizer) |
699 | { | |
f6bcfd97 | 700 | item->GetSizer()->DoSetMinSize( width, height ); |
12a3f227 | 701 | return true; |
3ca6a5f0 | 702 | } |
12a3f227 | 703 | node = node->GetNext(); |
f6bcfd97 BP |
704 | } |
705 | ||
12a3f227 RL |
706 | // No? Search any subsizers we own then |
707 | ||
708 | node = m_children.GetFirst(); | |
f6bcfd97 BP |
709 | while (node) |
710 | { | |
12a3f227 RL |
711 | wxSizerItem *item = node->GetData(); |
712 | ||
713 | if ( item->GetSizer() && | |
714 | item->GetSizer()->DoSetItemMinSize( sizer, width, height ) ) | |
3ca6a5f0 | 715 | { |
12a3f227 RL |
716 | // A child found the requested sizer, exit. |
717 | return true; | |
3ca6a5f0 | 718 | } |
12a3f227 | 719 | node = node->GetNext(); |
f6bcfd97 BP |
720 | } |
721 | ||
12a3f227 | 722 | return false; |
f6bcfd97 BP |
723 | } |
724 | ||
12a3f227 | 725 | bool wxSizer::DoSetItemMinSize( size_t index, int width, int height ) |
f6bcfd97 | 726 | { |
12a3f227 RL |
727 | wxSizerItemList::Node *node = m_children.Item( index ); |
728 | ||
729 | wxCHECK_MSG( node, false, _T("Failed to find child node") ); | |
730 | ||
731 | wxSizerItem *item = node->GetData(); | |
f6bcfd97 | 732 | |
f6bcfd97 BP |
733 | if (item->GetSizer()) |
734 | { | |
0ca5105b | 735 | // Sizers contains the minimal size in them, if not calculated ... |
f6bcfd97 BP |
736 | item->GetSizer()->DoSetMinSize( width, height ); |
737 | } | |
738 | else | |
739 | { | |
0ca5105b | 740 | // ... but the minimal size of spacers and windows in stored in them |
f6bcfd97 BP |
741 | item->SetInitSize( width, height ); |
742 | } | |
743 | ||
12a3f227 | 744 | return true; |
f6bcfd97 BP |
745 | } |
746 | ||
12a3f227 | 747 | void wxSizer::Show( wxWindow *window, bool show ) |
2b5f62a0 | 748 | { |
12a3f227 RL |
749 | wxASSERT_MSG( window, _T("Show for NULL window") ); |
750 | ||
751 | wxSizerItemList::Node *node = m_children.GetFirst(); | |
2b5f62a0 VZ |
752 | while (node) |
753 | { | |
12a3f227 | 754 | wxSizerItem *item = node->GetData(); |
2b5f62a0 | 755 | |
12a3f227 | 756 | if (item->GetWindow() == window) |
2b5f62a0 | 757 | { |
12a3f227 RL |
758 | item->Show( show ); |
759 | break; | |
2b5f62a0 | 760 | } |
12a3f227 | 761 | node = node->GetNext(); |
2b5f62a0 VZ |
762 | } |
763 | } | |
764 | ||
12a3f227 | 765 | void wxSizer::Show( wxSizer *sizer, bool show ) |
2b5f62a0 | 766 | { |
12a3f227 RL |
767 | wxASSERT_MSG( sizer, _T("Show for NULL sizer") ); |
768 | ||
769 | wxSizerItemList::Node *node = m_children.GetFirst(); | |
2b5f62a0 VZ |
770 | while (node) |
771 | { | |
12a3f227 | 772 | wxSizerItem *item = node->GetData(); |
2b5f62a0 | 773 | |
12a3f227 | 774 | if (item->GetSizer() == sizer) |
2b5f62a0 | 775 | { |
12a3f227 RL |
776 | item->Show( show ); |
777 | break; | |
2b5f62a0 | 778 | } |
12a3f227 | 779 | node = node->GetNext(); |
2b5f62a0 VZ |
780 | } |
781 | } | |
782 | ||
12a3f227 | 783 | void wxSizer::Show( size_t index, bool show ) |
2b5f62a0 | 784 | { |
12a3f227 RL |
785 | wxCHECK_RET( index < m_children.GetCount(), |
786 | _T("Show index is out of range") ); | |
2b5f62a0 | 787 | |
12a3f227 RL |
788 | m_children.Item( index )->GetData()->Show( show ); |
789 | } | |
2b5f62a0 | 790 | |
12a3f227 RL |
791 | void wxSizer::ShowItems( bool show ) |
792 | { | |
793 | wxSizerItemList::Node *node = m_children.GetFirst(); | |
794 | while (node) | |
795 | { | |
796 | node->GetData()->Show( show ); | |
797 | node = node->GetNext(); | |
2b5f62a0 VZ |
798 | } |
799 | } | |
800 | ||
12a3f227 | 801 | bool wxSizer::IsShown( wxWindow *window ) |
2b5f62a0 | 802 | { |
12a3f227 | 803 | wxSizerItemList::Node *node = m_children.GetFirst(); |
2b5f62a0 VZ |
804 | while (node) |
805 | { | |
12a3f227 | 806 | wxSizerItem *item = node->GetData(); |
2b5f62a0 | 807 | |
12a3f227 | 808 | if (item->GetWindow() == window) |
2b5f62a0 VZ |
809 | { |
810 | return item->IsShown(); | |
811 | } | |
12a3f227 | 812 | node = node->GetNext(); |
2b5f62a0 VZ |
813 | } |
814 | ||
12a3f227 RL |
815 | wxFAIL_MSG( _T("IsShown failed to find sizer item") ); |
816 | ||
817 | return false; | |
2b5f62a0 VZ |
818 | } |
819 | ||
12a3f227 | 820 | bool wxSizer::IsShown( wxSizer *sizer ) |
2b5f62a0 | 821 | { |
12a3f227 | 822 | wxSizerItemList::Node *node = m_children.GetFirst(); |
2b5f62a0 VZ |
823 | while (node) |
824 | { | |
12a3f227 | 825 | wxSizerItem *item = node->GetData(); |
2b5f62a0 | 826 | |
12a3f227 | 827 | if (item->GetSizer() == sizer) |
2b5f62a0 VZ |
828 | { |
829 | return item->IsShown(); | |
830 | } | |
12a3f227 | 831 | node = node->GetNext(); |
2b5f62a0 VZ |
832 | } |
833 | ||
12a3f227 RL |
834 | wxFAIL_MSG( _T("IsShown failed to find sizer item") ); |
835 | ||
836 | return false; | |
2b5f62a0 VZ |
837 | } |
838 | ||
12a3f227 RL |
839 | bool wxSizer::IsShown( size_t index ) |
840 | { | |
841 | wxCHECK_MSG( index < m_children.GetCount(), | |
842 | false, | |
843 | _T("IsShown index is out of range") ); | |
844 | ||
845 | return m_children.Item( index )->GetData()->IsShown(); | |
846 | } | |
847 | ||
848 | ||
f6bcfd97 BP |
849 | //--------------------------------------------------------------------------- |
850 | // wxGridSizer | |
851 | //--------------------------------------------------------------------------- | |
852 | ||
853 | wxGridSizer::wxGridSizer( int rows, int cols, int vgap, int hgap ) | |
12a3f227 RL |
854 | : m_rows( rows ) |
855 | , m_cols( cols ) | |
856 | , m_vgap( vgap ) | |
857 | , m_hgap( hgap ) | |
f6bcfd97 | 858 | { |
f6bcfd97 BP |
859 | } |
860 | ||
861 | wxGridSizer::wxGridSizer( int cols, int vgap, int hgap ) | |
12a3f227 RL |
862 | : m_rows( 0 ) |
863 | , m_cols( cols ) | |
864 | , m_vgap( vgap ) | |
865 | , m_hgap( hgap ) | |
f6bcfd97 | 866 | { |
f6bcfd97 BP |
867 | } |
868 | ||
0ca5105b | 869 | int wxGridSizer::CalcRowsCols(int& nrows, int& ncols) const |
f6bcfd97 | 870 | { |
f6bcfd97 | 871 | int nitems = m_children.GetCount(); |
2b5f62a0 | 872 | if ( nitems) |
0ca5105b VZ |
873 | { |
874 | if ( m_cols ) | |
875 | { | |
876 | ncols = m_cols; | |
877 | nrows = (nitems + m_cols - 1) / m_cols; | |
878 | } | |
879 | else if ( m_rows ) | |
880 | { | |
881 | ncols = (nitems + m_rows - 1) / m_rows; | |
882 | nrows = m_rows; | |
883 | } | |
884 | else // 0 columns, 0 rows? | |
885 | { | |
886 | wxFAIL_MSG( _T("grid sizer must have either rows or columns fixed") ); | |
f6bcfd97 | 887 | |
0ca5105b VZ |
888 | nrows = ncols = 0; |
889 | } | |
890 | } | |
891 | ||
892 | return nitems; | |
893 | } | |
894 | ||
895 | void wxGridSizer::RecalcSizes() | |
896 | { | |
897 | int nitems, nrows, ncols; | |
898 | if ( (nitems = CalcRowsCols(nrows, ncols)) == 0 ) | |
899 | return; | |
f6bcfd97 BP |
900 | |
901 | wxSize sz( GetSize() ); | |
902 | wxPoint pt( GetPosition() ); | |
3ca6a5f0 BP |
903 | |
904 | int w = (sz.x - (ncols - 1) * m_hgap) / ncols; | |
905 | int h = (sz.y - (nrows - 1) * m_vgap) / nrows; | |
f6bcfd97 BP |
906 | |
907 | int x = pt.x; | |
908 | for (int c = 0; c < ncols; c++) | |
909 | { | |
910 | int y = pt.y; | |
911 | for (int r = 0; r < nrows; r++) | |
912 | { | |
913 | int i = r * ncols + c; | |
914 | if (i < nitems) | |
915 | { | |
12a3f227 RL |
916 | wxSizerItemList::Node *node = m_children.Item( i ); |
917 | ||
918 | wxASSERT_MSG( node, _T("Failed to find SizerItemList node") ); | |
3ca6a5f0 | 919 | |
12a3f227 | 920 | SetItemBounds( node->GetData(), x, y, w, h); |
f6bcfd97 BP |
921 | } |
922 | y = y + h + m_vgap; | |
923 | } | |
924 | x = x + w + m_hgap; | |
925 | } | |
926 | } | |
927 | ||
928 | wxSize wxGridSizer::CalcMin() | |
929 | { | |
0ca5105b VZ |
930 | int nitems, nrows, ncols; |
931 | if ( (nitems = CalcRowsCols(nrows, ncols)) == 0 ) | |
932 | return wxSize(10, 10); | |
f6bcfd97 | 933 | |
4f469fb5 | 934 | // Find the max width and height for any component |
f6bcfd97 BP |
935 | int w = 0; |
936 | int h = 0; | |
3ca6a5f0 | 937 | |
12a3f227 | 938 | wxSizerItemList::Node *node = m_children.GetFirst(); |
f6bcfd97 BP |
939 | while (node) |
940 | { | |
12a3f227 RL |
941 | wxSizerItem *item = node->GetData(); |
942 | wxSize sz( item->CalcMin() ); | |
943 | ||
f6bcfd97 BP |
944 | w = wxMax( w, sz.x ); |
945 | h = wxMax( h, sz.y ); | |
3ca6a5f0 | 946 | |
12a3f227 | 947 | node = node->GetNext(); |
f6bcfd97 | 948 | } |
3ca6a5f0 | 949 | |
12a3f227 RL |
950 | return wxSize( ncols * w + (ncols-1) * m_hgap, |
951 | nrows * h + (nrows-1) * m_vgap ); | |
f6bcfd97 BP |
952 | } |
953 | ||
954 | void wxGridSizer::SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ) | |
955 | { | |
956 | wxPoint pt( x,y ); | |
957 | wxSize sz( item->CalcMin() ); | |
958 | int flag = item->GetFlag(); | |
959 | ||
960 | if ((flag & wxEXPAND) || (flag & wxSHAPED)) | |
961 | { | |
962 | sz = wxSize(w, h); | |
963 | } | |
964 | else | |
965 | { | |
966 | if (flag & wxALIGN_CENTER_HORIZONTAL) | |
967 | { | |
968 | pt.x = x + (w - sz.x) / 2; | |
969 | } | |
970 | else if (flag & wxALIGN_RIGHT) | |
971 | { | |
972 | pt.x = x + (w - sz.x); | |
973 | } | |
3ca6a5f0 | 974 | |
f6bcfd97 BP |
975 | if (flag & wxALIGN_CENTER_VERTICAL) |
976 | { | |
977 | pt.y = y + (h - sz.y) / 2; | |
978 | } | |
979 | else if (flag & wxALIGN_BOTTOM) | |
980 | { | |
981 | pt.y = y + (h - sz.y); | |
982 | } | |
983 | } | |
3ca6a5f0 | 984 | |
f6bcfd97 BP |
985 | item->SetDimension(pt, sz); |
986 | } | |
987 | ||
988 | //--------------------------------------------------------------------------- | |
989 | // wxFlexGridSizer | |
990 | //--------------------------------------------------------------------------- | |
991 | ||
992 | wxFlexGridSizer::wxFlexGridSizer( int rows, int cols, int vgap, int hgap ) | |
993 | : wxGridSizer( rows, cols, vgap, hgap ) | |
12a3f227 RL |
994 | , m_rowHeights( NULL ) |
995 | , m_colWidths( NULL ) | |
3ca6a5f0 | 996 | { |
f6bcfd97 BP |
997 | } |
998 | ||
999 | wxFlexGridSizer::wxFlexGridSizer( int cols, int vgap, int hgap ) | |
3ca6a5f0 | 1000 | : wxGridSizer( cols, vgap, hgap ) |
12a3f227 RL |
1001 | , m_rowHeights( NULL ) |
1002 | , m_colWidths( NULL ) | |
3ca6a5f0 | 1003 | { |
f6bcfd97 | 1004 | } |
3ca6a5f0 | 1005 | |
f6bcfd97 BP |
1006 | wxFlexGridSizer::~wxFlexGridSizer() |
1007 | { | |
1008 | if (m_rowHeights) | |
1009 | delete[] m_rowHeights; | |
1010 | if (m_colWidths) | |
1011 | delete[] m_colWidths; | |
1012 | } | |
1013 | ||
1014 | void wxFlexGridSizer::CreateArrays() | |
1015 | { | |
1016 | if (m_rowHeights) | |
1017 | delete[] m_rowHeights; | |
1018 | if (m_colWidths) | |
1019 | delete[] m_colWidths; | |
3ca6a5f0 | 1020 | |
0ca5105b VZ |
1021 | int nitems, nrows, ncols; |
1022 | if ( (nitems = CalcRowsCols(nrows, ncols)) == 0 ) | |
1023 | { | |
1024 | m_rowHeights = | |
1025 | m_colWidths = NULL; | |
1026 | } | |
f6bcfd97 BP |
1027 | |
1028 | m_rowHeights = new int[nrows]; | |
1029 | m_colWidths = new int[ncols]; | |
0ca5105b | 1030 | |
f6bcfd97 BP |
1031 | for (int col = 0; col < ncols; col++) |
1032 | m_colWidths[ col ] = 0; | |
1033 | for (int row = 0; row < nrows; row++) | |
1034 | m_rowHeights[ row ] = 0; | |
1035 | } | |
1036 | ||
1037 | void wxFlexGridSizer::RecalcSizes() | |
1038 | { | |
0ca5105b VZ |
1039 | int nitems, nrows, ncols; |
1040 | if ( (nitems = CalcRowsCols(nrows, ncols)) == 0 ) | |
f6bcfd97 BP |
1041 | return; |
1042 | ||
f6bcfd97 BP |
1043 | wxSize sz( GetSize() ); |
1044 | wxSize minsz( CalcMin() ); | |
1045 | wxPoint pt( GetPosition() ); | |
1046 | int delta; | |
4f469fb5 RR |
1047 | size_t idx,num; |
1048 | wxArrayInt temp; | |
0ca5105b | 1049 | |
4f469fb5 RR |
1050 | // Transfer only those rows into temp which exist in the sizer |
1051 | // ignoring the superflouus ones. This prevents a segfault when | |
1052 | // calling AddGrowableRow( 3 ) if the sizer only has 2 rows. | |
1053 | for (idx = 0; idx < m_growableRows.GetCount(); idx++) | |
1054 | if (m_growableRows[idx] < nrows) | |
1055 | temp.Add( m_growableRows[idx] ); | |
1056 | num = temp.GetCount(); | |
1057 | ||
1058 | if ((num > 0) && (sz.y > minsz.y)) | |
f6bcfd97 | 1059 | { |
4f469fb5 RR |
1060 | delta = (sz.y - minsz.y) / num; |
1061 | for (idx = 0; idx < num; idx++) | |
1062 | m_rowHeights[ temp[idx] ] += delta; | |
f6bcfd97 | 1063 | } |
3ca6a5f0 | 1064 | |
2e9c65bf | 1065 | temp.Empty(); |
0ca5105b | 1066 | // See above |
4f469fb5 RR |
1067 | for (idx = 0; idx < m_growableCols.GetCount(); idx++) |
1068 | if (m_growableCols[idx] < ncols) | |
1069 | temp.Add( m_growableCols[idx] ); | |
1070 | num = temp.GetCount(); | |
0ca5105b | 1071 | |
4f469fb5 | 1072 | if ((num > 0) && (sz.x > minsz.x)) |
f6bcfd97 | 1073 | { |
4f469fb5 RR |
1074 | delta = (sz.x - minsz.x) / num; |
1075 | for (idx = 0; idx < num; idx++) | |
1076 | m_colWidths[ temp[idx] ] += delta; | |
f6bcfd97 | 1077 | } |
3ca6a5f0 | 1078 | |
f6bcfd97 BP |
1079 | sz = wxSize( pt.x + sz.x, pt.y + sz.y ); |
1080 | ||
1081 | int x = pt.x; | |
1082 | for (int c = 0; c < ncols; c++) | |
1083 | { | |
1084 | int y = pt.y; | |
1085 | for (int r = 0; r < nrows; r++) | |
1086 | { | |
1087 | int i = r * ncols + c; | |
1088 | if (i < nitems) | |
1089 | { | |
12a3f227 RL |
1090 | wxSizerItemList::Node *node = m_children.Item( i ); |
1091 | ||
1092 | wxASSERT_MSG( node, _T("Failed to find node") ); | |
3ca6a5f0 | 1093 | |
f6bcfd97 BP |
1094 | int w = wxMax( 0, wxMin( m_colWidths[c], sz.x - x ) ); |
1095 | int h = wxMax( 0, wxMin( m_rowHeights[r], sz.y - y ) ); | |
3ca6a5f0 | 1096 | |
12a3f227 | 1097 | SetItemBounds( node->GetData(), x, y, w, h); |
f6bcfd97 BP |
1098 | } |
1099 | y = y + m_rowHeights[r] + m_vgap; | |
1100 | } | |
1101 | x = x + m_colWidths[c] + m_hgap; | |
1102 | } | |
1103 | } | |
1104 | ||
1105 | wxSize wxFlexGridSizer::CalcMin() | |
1106 | { | |
0ca5105b VZ |
1107 | int nitems, nrows, ncols; |
1108 | if ( (nitems = CalcRowsCols(nrows, ncols)) == 0 ) | |
f6bcfd97 BP |
1109 | return wxSize(10,10); |
1110 | ||
f6bcfd97 | 1111 | CreateArrays(); |
3ca6a5f0 | 1112 | |
12a3f227 RL |
1113 | int i = 0; |
1114 | wxSizerItemList::Node *node = m_children.GetFirst(); | |
1115 | ||
f6bcfd97 BP |
1116 | while (node) |
1117 | { | |
12a3f227 RL |
1118 | wxSizerItem *item = node->GetData(); |
1119 | wxSize sz( item->CalcMin() ); | |
1120 | int row = i / ncols; | |
1121 | int col = i % ncols; | |
1122 | ||
f6bcfd97 BP |
1123 | m_rowHeights[ row ] = wxMax( sz.y, m_rowHeights[ row ] ); |
1124 | m_colWidths[ col ] = wxMax( sz.x, m_colWidths[ col ] ); | |
3ca6a5f0 | 1125 | |
12a3f227 | 1126 | node = node->GetNext(); |
f6bcfd97 BP |
1127 | i++; |
1128 | } | |
3ca6a5f0 | 1129 | |
f6bcfd97 | 1130 | int width = 0; |
0ca5105b | 1131 | for (int col = 0; col < ncols; col++) |
f6bcfd97 | 1132 | width += m_colWidths[ col ]; |
3ca6a5f0 | 1133 | |
f6bcfd97 | 1134 | int height = 0; |
0ca5105b | 1135 | for (int row = 0; row < nrows; row++) |
f6bcfd97 | 1136 | height += m_rowHeights[ row ]; |
3ca6a5f0 | 1137 | |
f6bcfd97 BP |
1138 | return wxSize( width + (ncols-1) * m_hgap, |
1139 | height + (nrows-1) * m_vgap); | |
1140 | } | |
1141 | ||
1142 | void wxFlexGridSizer::AddGrowableRow( size_t idx ) | |
1143 | { | |
1144 | m_growableRows.Add( idx ); | |
1145 | } | |
1146 | ||
3ca6a5f0 | 1147 | void wxFlexGridSizer::RemoveGrowableRow( size_t WXUNUSED(idx) ) |
f6bcfd97 BP |
1148 | { |
1149 | } | |
1150 | ||
1151 | void wxFlexGridSizer::AddGrowableCol( size_t idx ) | |
1152 | { | |
1153 | m_growableCols.Add( idx ); | |
1154 | } | |
1155 | ||
3ca6a5f0 | 1156 | void wxFlexGridSizer::RemoveGrowableCol( size_t WXUNUSED(idx) ) |
f6bcfd97 BP |
1157 | { |
1158 | } | |
1159 | ||
c62ac5b6 | 1160 | //--------------------------------------------------------------------------- |
92afa2b1 | 1161 | // wxBoxSizer |
61d514bb RR |
1162 | //--------------------------------------------------------------------------- |
1163 | ||
92afa2b1 | 1164 | wxBoxSizer::wxBoxSizer( int orient ) |
12a3f227 | 1165 | : m_orient( orient ) |
61d514bb | 1166 | { |
61d514bb RR |
1167 | } |
1168 | ||
92afa2b1 | 1169 | void wxBoxSizer::RecalcSizes() |
61d514bb RR |
1170 | { |
1171 | if (m_children.GetCount() == 0) | |
61d514bb | 1172 | return; |
0c0d686f | 1173 | |
61d514bb RR |
1174 | int delta = 0; |
1175 | int extra = 0; | |
1176 | if (m_stretchable) | |
1177 | { | |
1178 | if (m_orient == wxHORIZONTAL) | |
1179 | { | |
1180 | delta = (m_size.x - m_fixedWidth) / m_stretchable; | |
1181 | extra = (m_size.x - m_fixedWidth) % m_stretchable; | |
3ca6a5f0 BP |
1182 | } |
1183 | else | |
1184 | { | |
61d514bb RR |
1185 | delta = (m_size.y - m_fixedHeight) / m_stretchable; |
1186 | extra = (m_size.y - m_fixedHeight) % m_stretchable; | |
3ca6a5f0 | 1187 | } |
61d514bb | 1188 | } |
0c0d686f | 1189 | |
61d514bb | 1190 | wxPoint pt( m_position ); |
0c0d686f | 1191 | |
12a3f227 | 1192 | wxSizerItemList::Node *node = m_children.GetFirst(); |
61d514bb RR |
1193 | while (node) |
1194 | { | |
12a3f227 RL |
1195 | wxSizerItem *item = node->GetData(); |
1196 | ||
2b5f62a0 | 1197 | if (item->IsShown()) |
3ca6a5f0 | 1198 | { |
2b5f62a0 | 1199 | int weight = 1; |
12a3f227 RL |
1200 | if (item->GetProportion()) |
1201 | weight = item->GetProportion(); | |
3ca6a5f0 | 1202 | |
2b5f62a0 | 1203 | wxSize size( item->CalcMin() ); |
3ca6a5f0 | 1204 | |
2b5f62a0 | 1205 | if (m_orient == wxVERTICAL) |
3ca6a5f0 | 1206 | { |
2b5f62a0 | 1207 | wxCoord height = size.y; |
12a3f227 | 1208 | if (item->GetProportion()) |
2b5f62a0 VZ |
1209 | { |
1210 | height = (delta * weight) + extra; | |
1211 | extra = 0; // only the first item will get the remainder as extra size | |
1212 | } | |
1213 | ||
1214 | wxPoint child_pos( pt ); | |
1215 | wxSize child_size( wxSize( size.x, height) ); | |
1216 | ||
1217 | if (item->GetFlag() & (wxEXPAND | wxSHAPED)) | |
1218 | child_size.x = m_size.x; | |
1219 | else if (item->GetFlag() & wxALIGN_RIGHT) | |
1220 | child_pos.x += m_size.x - size.x; | |
1221 | else if (item->GetFlag() & (wxCENTER | wxALIGN_CENTER_HORIZONTAL)) | |
1222 | // XXX wxCENTER is added for backward compatibility; | |
1223 | // wxALIGN_CENTER should be used in new code | |
1224 | child_pos.x += (m_size.x - size.x) / 2; | |
1225 | ||
1226 | item->SetDimension( child_pos, child_size ); | |
1227 | ||
1228 | pt.y += height; | |
1229 | } | |
1230 | else | |
1231 | { | |
1232 | wxCoord width = size.x; | |
12a3f227 | 1233 | if (item->GetProportion()) |
2b5f62a0 VZ |
1234 | { |
1235 | width = (delta * weight) + extra; | |
1236 | extra = 0; // only the first item will get the remainder as extra size | |
1237 | } | |
1238 | ||
1239 | wxPoint child_pos( pt ); | |
1240 | wxSize child_size( wxSize(width, size.y) ); | |
1241 | ||
1242 | if (item->GetFlag() & (wxEXPAND | wxSHAPED)) | |
1243 | child_size.y = m_size.y; | |
1244 | else if (item->GetFlag() & wxALIGN_BOTTOM) | |
1245 | child_pos.y += m_size.y - size.y; | |
1246 | else if (item->GetFlag() & (wxCENTER | wxALIGN_CENTER_VERTICAL)) | |
1247 | // XXX wxCENTER is added for backward compatibility; | |
1248 | // wxALIGN_CENTER should be used in new code | |
1249 | child_pos.y += (m_size.y - size.y) / 2; | |
1250 | ||
1251 | item->SetDimension( child_pos, child_size ); | |
1252 | ||
1253 | pt.x += width; | |
3ca6a5f0 | 1254 | } |
3ca6a5f0 BP |
1255 | } |
1256 | ||
12a3f227 | 1257 | node = node->GetNext(); |
61d514bb RR |
1258 | } |
1259 | } | |
1260 | ||
92afa2b1 | 1261 | wxSize wxBoxSizer::CalcMin() |
61d514bb RR |
1262 | { |
1263 | if (m_children.GetCount() == 0) | |
c7a9fa36 | 1264 | return wxSize(10,10); |
0c0d686f | 1265 | |
61d514bb RR |
1266 | m_stretchable = 0; |
1267 | m_minWidth = 0; | |
1268 | m_minHeight = 0; | |
1269 | m_fixedWidth = 0; | |
1270 | m_fixedHeight = 0; | |
0c0d686f | 1271 | |
f98de448 | 1272 | // Find how long each stretch unit needs to be |
12a3f227 RL |
1273 | int stretchSize = 1; |
1274 | wxSizerItemList::Node *node = m_children.GetFirst(); | |
1275 | ||
61d514bb | 1276 | while (node) |
f98de448 | 1277 | { |
12a3f227 RL |
1278 | wxSizerItem *item = node->GetData(); |
1279 | ||
1280 | if (item->IsShown() && item->GetProportion() != 0) | |
f98de448 | 1281 | { |
12a3f227 | 1282 | int stretch = item->GetProportion(); |
f98de448 RD |
1283 | wxSize size( item->CalcMin() ); |
1284 | int sizePerStretch; | |
1285 | // Integer division rounded up is (a + b - 1) / b | |
1286 | if (m_orient == wxHORIZONTAL) | |
1287 | sizePerStretch = ( size.x + stretch - 1 ) / stretch; | |
1288 | else | |
1289 | sizePerStretch = ( size.y + stretch - 1 ) / stretch; | |
1290 | if (sizePerStretch > stretchSize) | |
1291 | stretchSize = sizePerStretch; | |
1292 | } | |
12a3f227 | 1293 | node = node->GetNext(); |
f98de448 | 1294 | } |
12a3f227 | 1295 | |
4f469fb5 RR |
1296 | // Calculate overall minimum size |
1297 | node = m_children.GetFirst(); | |
f98de448 | 1298 | while (node) |
61d514bb | 1299 | { |
12a3f227 RL |
1300 | wxSizerItem *item = node->GetData(); |
1301 | ||
2b5f62a0 | 1302 | if (item->IsShown()) |
f98de448 | 1303 | { |
12a3f227 | 1304 | m_stretchable += item->GetProportion(); |
3ca6a5f0 | 1305 | |
2b5f62a0 | 1306 | wxSize size( item->CalcMin() ); |
12a3f227 | 1307 | if (item->GetProportion() != 0) |
2b5f62a0 VZ |
1308 | { |
1309 | if (m_orient == wxHORIZONTAL) | |
12a3f227 | 1310 | size.x = stretchSize * item->GetProportion(); |
2b5f62a0 | 1311 | else |
12a3f227 | 1312 | size.y = stretchSize * item->GetProportion(); |
2b5f62a0 | 1313 | } |
3ca6a5f0 | 1314 | |
2b5f62a0 | 1315 | if (m_orient == wxHORIZONTAL) |
3ca6a5f0 | 1316 | { |
2b5f62a0 VZ |
1317 | m_minWidth += size.x; |
1318 | m_minHeight = wxMax( m_minHeight, size.y ); | |
3ca6a5f0 BP |
1319 | } |
1320 | else | |
33ac7e6f | 1321 | { |
2b5f62a0 VZ |
1322 | m_minHeight += size.y; |
1323 | m_minWidth = wxMax( m_minWidth, size.x ); | |
3ca6a5f0 | 1324 | } |
3ca6a5f0 | 1325 | |
12a3f227 | 1326 | if (item->GetProportion() == 0) |
2b5f62a0 VZ |
1327 | { |
1328 | if (m_orient == wxVERTICAL) | |
1329 | { | |
1330 | m_fixedHeight += size.y; | |
1331 | m_fixedWidth = wxMax( m_fixedWidth, size.x ); | |
1332 | } | |
1333 | else | |
1334 | { | |
1335 | m_fixedWidth += size.x; | |
1336 | m_fixedHeight = wxMax( m_fixedHeight, size.y ); | |
1337 | } | |
1338 | } | |
1339 | } | |
12a3f227 | 1340 | node = node->GetNext(); |
61d514bb | 1341 | } |
0c0d686f | 1342 | |
61d514bb RR |
1343 | return wxSize( m_minWidth, m_minHeight ); |
1344 | } | |
27ea1d8a RR |
1345 | |
1346 | //--------------------------------------------------------------------------- | |
1347 | // wxStaticBoxSizer | |
1348 | //--------------------------------------------------------------------------- | |
1349 | ||
1e6feb95 VZ |
1350 | #if wxUSE_STATBOX |
1351 | ||
27ea1d8a | 1352 | wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox *box, int orient ) |
12a3f227 RL |
1353 | : wxBoxSizer( orient ) |
1354 | , m_staticBox( box ) | |
27ea1d8a | 1355 | { |
223d09f6 | 1356 | wxASSERT_MSG( box, wxT("wxStaticBoxSizer needs a static box") ); |
27ea1d8a | 1357 | } |
0c0d686f | 1358 | |
12a3f227 RL |
1359 | static void GetStaticBoxBorders( wxStaticBox *box, |
1360 | int *borderTop, | |
1361 | int *borderOther) | |
84028727 VZ |
1362 | { |
1363 | // this has to be done platform by platform as there is no way to | |
1364 | // guess the thickness of a wxStaticBox border | |
1365 | #ifdef __WXGTK__ | |
1366 | if ( box->GetLabel().IsEmpty() ) | |
1367 | *borderTop = 5; | |
1368 | else | |
1369 | #endif // __WXGTK__ | |
1370 | *borderTop = 15; | |
4f469fb5 | 1371 | (void)box; |
84028727 VZ |
1372 | *borderOther = 5; |
1373 | } | |
1374 | ||
27ea1d8a RR |
1375 | void wxStaticBoxSizer::RecalcSizes() |
1376 | { | |
84028727 VZ |
1377 | int top_border, other_border; |
1378 | GetStaticBoxBorders(m_staticBox, &top_border, &other_border); | |
27ea1d8a RR |
1379 | |
1380 | m_staticBox->SetSize( m_position.x, m_position.y, m_size.x, m_size.y ); | |
0c0d686f | 1381 | |
27ea1d8a RR |
1382 | wxPoint old_pos( m_position ); |
1383 | m_position.x += other_border; | |
1384 | m_position.y += top_border; | |
1385 | wxSize old_size( m_size ); | |
1386 | m_size.x -= 2*other_border; | |
1387 | m_size.y -= top_border + other_border; | |
0c0d686f | 1388 | |
27ea1d8a | 1389 | wxBoxSizer::RecalcSizes(); |
0c0d686f | 1390 | |
27ea1d8a RR |
1391 | m_position = old_pos; |
1392 | m_size = old_size; | |
1393 | } | |
1394 | ||
1395 | wxSize wxStaticBoxSizer::CalcMin() | |
1396 | { | |
84028727 VZ |
1397 | int top_border, other_border; |
1398 | GetStaticBoxBorders(m_staticBox, &top_border, &other_border); | |
0c0d686f | 1399 | |
27ea1d8a | 1400 | wxSize ret( wxBoxSizer::CalcMin() ); |
cae31b8b | 1401 | ret.x += 2*other_border; |
27ea1d8a | 1402 | ret.y += other_border + top_border; |
0c0d686f | 1403 | |
27ea1d8a RR |
1404 | return ret; |
1405 | } | |
83edc0a5 | 1406 | |
1e6feb95 VZ |
1407 | #endif // wxUSE_STATBOX |
1408 | ||
83edc0a5 RR |
1409 | //--------------------------------------------------------------------------- |
1410 | // wxNotebookSizer | |
1411 | //--------------------------------------------------------------------------- | |
1412 | ||
60be2f47 VS |
1413 | #if wxUSE_NOTEBOOK |
1414 | ||
83edc0a5 | 1415 | wxNotebookSizer::wxNotebookSizer( wxNotebook *nb ) |
12a3f227 | 1416 | : m_notebook( nb ) |
83edc0a5 RR |
1417 | { |
1418 | wxASSERT_MSG( nb, wxT("wxNotebookSizer needs a notebook") ); | |
83edc0a5 RR |
1419 | } |
1420 | ||
1421 | void wxNotebookSizer::RecalcSizes() | |
1422 | { | |
1423 | m_notebook->SetSize( m_position.x, m_position.y, m_size.x, m_size.y ); | |
1424 | } | |
1425 | ||
1426 | wxSize wxNotebookSizer::CalcMin() | |
1427 | { | |
1e6feb95 VZ |
1428 | wxSize sizeBorder = m_notebook->CalcSizeFromPage(wxSize(0, 0)); |
1429 | ||
1430 | sizeBorder.x += 5; | |
1431 | sizeBorder.y += 5; | |
3ca6a5f0 | 1432 | |
83edc0a5 | 1433 | if (m_notebook->GetChildren().GetCount() == 0) |
1e6feb95 VZ |
1434 | { |
1435 | return wxSize(sizeBorder.x + 10, sizeBorder.y + 10); | |
1436 | } | |
83edc0a5 RR |
1437 | |
1438 | int maxX = 0; | |
1439 | int maxY = 0; | |
1440 | ||
1441 | wxWindowList::Node *node = m_notebook->GetChildren().GetFirst(); | |
1442 | while (node) | |
1443 | { | |
1444 | wxWindow *item = node->GetData(); | |
3ca6a5f0 BP |
1445 | wxSizer *itemsizer = item->GetSizer(); |
1446 | ||
1447 | if (itemsizer) | |
1448 | { | |
83edc0a5 | 1449 | wxSize subsize( itemsizer->CalcMin() ); |
83edc0a5 | 1450 | |
1e6feb95 VZ |
1451 | if (subsize.x > maxX) |
1452 | maxX = subsize.x; | |
1453 | if (subsize.y > maxY) | |
1454 | maxY = subsize.y; | |
3ca6a5f0 BP |
1455 | } |
1456 | ||
1457 | node = node->GetNext(); | |
83edc0a5 RR |
1458 | } |
1459 | ||
1e6feb95 | 1460 | return wxSize( maxX, maxY ) + sizeBorder; |
83edc0a5 RR |
1461 | } |
1462 | ||
60be2f47 | 1463 | #endif // wxUSE_NOTEBOOK |
34c3ffca RL |
1464 | |
1465 | // vi:sts=4:sw=4:et |