]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/common/sizer.cpp | |
3 | // Purpose: provide new wxSizer class for layout | |
4 | // Author: Robert Roebling and Robin Dunn, contributions by | |
5 | // Dirk Holtwick, Ron Lee | |
6 | // Modified by: Ron Lee | |
7 | // Created: | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) Robin Dunn, Robert Roebling | |
10 | // Licence: wxWindows licence | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // For compilers that support precompilation, includes "wx.h". | |
14 | #include "wx/wxprec.h" | |
15 | ||
16 | #ifdef __BORLANDC__ | |
17 | #pragma hdrstop | |
18 | #endif | |
19 | ||
20 | #include "wx/sizer.h" | |
21 | #include "wx/private/flagscheck.h" | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/string.h" | |
25 | #include "wx/intl.h" | |
26 | #include "wx/math.h" | |
27 | #include "wx/utils.h" | |
28 | #include "wx/settings.h" | |
29 | #include "wx/button.h" | |
30 | #include "wx/statbox.h" | |
31 | #include "wx/toplevel.h" | |
32 | #endif // WX_PRECOMP | |
33 | ||
34 | #include "wx/display.h" | |
35 | #include "wx/listimpl.cpp" | |
36 | ||
37 | ||
38 | //--------------------------------------------------------------------------- | |
39 | ||
40 | IMPLEMENT_CLASS(wxSizerItem, wxObject) | |
41 | IMPLEMENT_CLASS(wxSizer, wxObject) | |
42 | IMPLEMENT_CLASS(wxGridSizer, wxSizer) | |
43 | IMPLEMENT_CLASS(wxFlexGridSizer, wxGridSizer) | |
44 | IMPLEMENT_CLASS(wxBoxSizer, wxSizer) | |
45 | #if wxUSE_STATBOX | |
46 | IMPLEMENT_CLASS(wxStaticBoxSizer, wxBoxSizer) | |
47 | #endif | |
48 | #if wxUSE_BUTTON | |
49 | IMPLEMENT_CLASS(wxStdDialogButtonSizer, wxBoxSizer) | |
50 | #endif | |
51 | ||
52 | WX_DEFINE_EXPORTED_LIST( wxSizerItemList ) | |
53 | ||
54 | /* | |
55 | TODO PROPERTIES | |
56 | sizeritem | |
57 | object | |
58 | object_ref | |
59 | minsize | |
60 | option | |
61 | flag | |
62 | border | |
63 | spacer | |
64 | option | |
65 | flag | |
66 | borfder | |
67 | boxsizer | |
68 | orient | |
69 | staticboxsizer | |
70 | orient | |
71 | label | |
72 | gridsizer | |
73 | rows | |
74 | cols | |
75 | vgap | |
76 | hgap | |
77 | flexgridsizer | |
78 | rows | |
79 | cols | |
80 | vgap | |
81 | hgap | |
82 | growablerows | |
83 | growablecols | |
84 | minsize | |
85 | */ | |
86 | ||
87 | // ---------------------------------------------------------------------------- | |
88 | // wxSizerItem | |
89 | // ---------------------------------------------------------------------------- | |
90 | ||
91 | // check for flags conflicts | |
92 | static const int SIZER_FLAGS_MASK = | |
93 | wxADD_FLAG(wxCENTRE, | |
94 | wxADD_FLAG(wxHORIZONTAL, | |
95 | wxADD_FLAG(wxVERTICAL, | |
96 | wxADD_FLAG(wxLEFT, | |
97 | wxADD_FLAG(wxRIGHT, | |
98 | wxADD_FLAG(wxUP, | |
99 | wxADD_FLAG(wxDOWN, | |
100 | wxADD_FLAG(wxALIGN_NOT, | |
101 | wxADD_FLAG(wxALIGN_CENTER_HORIZONTAL, | |
102 | wxADD_FLAG(wxALIGN_RIGHT, | |
103 | wxADD_FLAG(wxALIGN_BOTTOM, | |
104 | wxADD_FLAG(wxALIGN_CENTER_VERTICAL, | |
105 | wxADD_FLAG(wxFIXED_MINSIZE, | |
106 | wxADD_FLAG(wxRESERVE_SPACE_EVEN_IF_HIDDEN, | |
107 | wxADD_FLAG(wxSTRETCH_NOT, | |
108 | wxADD_FLAG(wxSHRINK, | |
109 | wxADD_FLAG(wxGROW, | |
110 | wxADD_FLAG(wxSHAPED, | |
111 | 0)))))))))))))))))); | |
112 | ||
113 | #define ASSERT_VALID_SIZER_FLAGS(f) wxASSERT_VALID_FLAGS(f, SIZER_FLAGS_MASK) | |
114 | ||
115 | ||
116 | void wxSizerItem::Init(const wxSizerFlags& flags) | |
117 | { | |
118 | Init(); | |
119 | ||
120 | m_proportion = flags.GetProportion(); | |
121 | m_flag = flags.GetFlags(); | |
122 | m_border = flags.GetBorderInPixels(); | |
123 | ||
124 | ASSERT_VALID_SIZER_FLAGS( m_flag ); | |
125 | } | |
126 | ||
127 | wxSizerItem::wxSizerItem() | |
128 | { | |
129 | Init(); | |
130 | ||
131 | m_proportion = 0; | |
132 | m_border = 0; | |
133 | m_flag = 0; | |
134 | m_id = wxID_NONE; | |
135 | } | |
136 | ||
137 | // window item | |
138 | void wxSizerItem::DoSetWindow(wxWindow *window) | |
139 | { | |
140 | wxCHECK_RET( window, wxT("NULL window in wxSizerItem::SetWindow()") ); | |
141 | ||
142 | m_kind = Item_Window; | |
143 | m_window = window; | |
144 | ||
145 | // window doesn't become smaller than its initial size, whatever happens | |
146 | m_minSize = window->GetSize(); | |
147 | ||
148 | if ( m_flag & wxFIXED_MINSIZE ) | |
149 | window->SetMinSize(m_minSize); | |
150 | ||
151 | // aspect ratio calculated from initial size | |
152 | SetRatio(m_minSize); | |
153 | } | |
154 | ||
155 | wxSizerItem::wxSizerItem(wxWindow *window, | |
156 | int proportion, | |
157 | int flag, | |
158 | int border, | |
159 | wxObject* userData) | |
160 | : m_kind(Item_None), | |
161 | m_proportion(proportion), | |
162 | m_border(border), | |
163 | m_flag(flag), | |
164 | m_id(wxID_NONE), | |
165 | m_userData(userData) | |
166 | { | |
167 | ASSERT_VALID_SIZER_FLAGS( m_flag ); | |
168 | ||
169 | DoSetWindow(window); | |
170 | } | |
171 | ||
172 | // sizer item | |
173 | void wxSizerItem::DoSetSizer(wxSizer *sizer) | |
174 | { | |
175 | m_kind = Item_Sizer; | |
176 | m_sizer = sizer; | |
177 | } | |
178 | ||
179 | wxSizerItem::wxSizerItem(wxSizer *sizer, | |
180 | int proportion, | |
181 | int flag, | |
182 | int border, | |
183 | wxObject* userData) | |
184 | : m_kind(Item_None), | |
185 | m_sizer(NULL), | |
186 | m_proportion(proportion), | |
187 | m_border(border), | |
188 | m_flag(flag), | |
189 | m_id(wxID_NONE), | |
190 | m_ratio(0.0), | |
191 | m_userData(userData) | |
192 | { | |
193 | ASSERT_VALID_SIZER_FLAGS( m_flag ); | |
194 | ||
195 | DoSetSizer(sizer); | |
196 | ||
197 | // m_minSize is set later | |
198 | } | |
199 | ||
200 | // spacer item | |
201 | void wxSizerItem::DoSetSpacer(const wxSize& size) | |
202 | { | |
203 | m_kind = Item_Spacer; | |
204 | m_spacer = new wxSizerSpacer(size); | |
205 | m_minSize = size; | |
206 | SetRatio(size); | |
207 | } | |
208 | ||
209 | wxSizerItem::wxSizerItem(int width, | |
210 | int height, | |
211 | int proportion, | |
212 | int flag, | |
213 | int border, | |
214 | wxObject* userData) | |
215 | : m_kind(Item_None), | |
216 | m_sizer(NULL), | |
217 | m_minSize(width, height), // minimal size is the initial size | |
218 | m_proportion(proportion), | |
219 | m_border(border), | |
220 | m_flag(flag), | |
221 | m_id(wxID_NONE), | |
222 | m_userData(userData) | |
223 | { | |
224 | ASSERT_VALID_SIZER_FLAGS( m_flag ); | |
225 | ||
226 | DoSetSpacer(wxSize(width, height)); | |
227 | } | |
228 | ||
229 | wxSizerItem::~wxSizerItem() | |
230 | { | |
231 | delete m_userData; | |
232 | Free(); | |
233 | } | |
234 | ||
235 | void wxSizerItem::Free() | |
236 | { | |
237 | switch ( m_kind ) | |
238 | { | |
239 | case Item_None: | |
240 | break; | |
241 | ||
242 | case Item_Window: | |
243 | m_window->SetContainingSizer(NULL); | |
244 | break; | |
245 | ||
246 | case Item_Sizer: | |
247 | delete m_sizer; | |
248 | break; | |
249 | ||
250 | case Item_Spacer: | |
251 | delete m_spacer; | |
252 | break; | |
253 | ||
254 | case Item_Max: | |
255 | default: | |
256 | wxFAIL_MSG( wxT("unexpected wxSizerItem::m_kind") ); | |
257 | } | |
258 | ||
259 | m_kind = Item_None; | |
260 | } | |
261 | ||
262 | wxSize wxSizerItem::GetSpacer() const | |
263 | { | |
264 | wxSize size; | |
265 | if ( m_kind == Item_Spacer ) | |
266 | size = m_spacer->GetSize(); | |
267 | ||
268 | return size; | |
269 | } | |
270 | ||
271 | ||
272 | wxSize wxSizerItem::GetSize() const | |
273 | { | |
274 | wxSize ret; | |
275 | switch ( m_kind ) | |
276 | { | |
277 | case Item_None: | |
278 | break; | |
279 | ||
280 | case Item_Window: | |
281 | ret = m_window->GetSize(); | |
282 | break; | |
283 | ||
284 | case Item_Sizer: | |
285 | ret = m_sizer->GetSize(); | |
286 | break; | |
287 | ||
288 | case Item_Spacer: | |
289 | ret = m_spacer->GetSize(); | |
290 | break; | |
291 | ||
292 | case Item_Max: | |
293 | default: | |
294 | wxFAIL_MSG( wxT("unexpected wxSizerItem::m_kind") ); | |
295 | } | |
296 | ||
297 | if (m_flag & wxWEST) | |
298 | ret.x += m_border; | |
299 | if (m_flag & wxEAST) | |
300 | ret.x += m_border; | |
301 | if (m_flag & wxNORTH) | |
302 | ret.y += m_border; | |
303 | if (m_flag & wxSOUTH) | |
304 | ret.y += m_border; | |
305 | ||
306 | return ret; | |
307 | } | |
308 | ||
309 | bool wxSizerItem::InformFirstDirection(int direction, int size, int availableOtherDir) | |
310 | { | |
311 | // The size that come here will be including borders. Child items should get it | |
312 | // without borders. | |
313 | if( size>0 ) | |
314 | { | |
315 | if( direction==wxHORIZONTAL ) | |
316 | { | |
317 | if (m_flag & wxWEST) | |
318 | size -= m_border; | |
319 | if (m_flag & wxEAST) | |
320 | size -= m_border; | |
321 | } | |
322 | else if( direction==wxVERTICAL ) | |
323 | { | |
324 | if (m_flag & wxNORTH) | |
325 | size -= m_border; | |
326 | if (m_flag & wxSOUTH) | |
327 | size -= m_border; | |
328 | } | |
329 | } | |
330 | ||
331 | bool didUse = false; | |
332 | // Pass the information along to the held object | |
333 | if (IsSizer()) | |
334 | { | |
335 | didUse = GetSizer()->InformFirstDirection(direction,size,availableOtherDir); | |
336 | if (didUse) | |
337 | m_minSize = GetSizer()->CalcMin(); | |
338 | } | |
339 | else if (IsWindow()) | |
340 | { | |
341 | didUse = GetWindow()->InformFirstDirection(direction,size,availableOtherDir); | |
342 | if (didUse) | |
343 | m_minSize = m_window->GetEffectiveMinSize(); | |
344 | ||
345 | // This information is useful for items with wxSHAPED flag, since | |
346 | // we can request an optimal min size for such an item. Even if | |
347 | // we overwrite the m_minSize member here, we can read it back from | |
348 | // the owned window (happens automatically). | |
349 | if( (m_flag & wxSHAPED) && (m_flag & wxEXPAND) && direction ) | |
350 | { | |
351 | if( !wxIsNullDouble(m_ratio) ) | |
352 | { | |
353 | wxCHECK_MSG( (m_proportion==0), false, wxT("Shaped item, non-zero proportion in wxSizerItem::InformFirstDirection()") ); | |
354 | if( direction==wxHORIZONTAL && !wxIsNullDouble(m_ratio) ) | |
355 | { | |
356 | // Clip size so that we don't take too much | |
357 | if( availableOtherDir>=0 && int(size/m_ratio)-m_minSize.y>availableOtherDir ) | |
358 | size = int((availableOtherDir+m_minSize.y)*m_ratio); | |
359 | m_minSize = wxSize(size,int(size/m_ratio)); | |
360 | } | |
361 | else if( direction==wxVERTICAL ) | |
362 | { | |
363 | // Clip size so that we don't take too much | |
364 | if( availableOtherDir>=0 && int(size*m_ratio)-m_minSize.x>availableOtherDir ) | |
365 | size = int((availableOtherDir+m_minSize.x)/m_ratio); | |
366 | m_minSize = wxSize(int(size*m_ratio),size); | |
367 | } | |
368 | didUse = true; | |
369 | } | |
370 | } | |
371 | } | |
372 | ||
373 | return didUse; | |
374 | } | |
375 | ||
376 | wxSize wxSizerItem::CalcMin() | |
377 | { | |
378 | if (IsSizer()) | |
379 | { | |
380 | m_minSize = m_sizer->GetMinSize(); | |
381 | ||
382 | // if we have to preserve aspect ratio _AND_ this is | |
383 | // the first-time calculation, consider ret to be initial size | |
384 | if ( (m_flag & wxSHAPED) && wxIsNullDouble(m_ratio) ) | |
385 | SetRatio(m_minSize); | |
386 | } | |
387 | else if ( IsWindow() ) | |
388 | { | |
389 | // Since the size of the window may change during runtime, we | |
390 | // should use the current minimal/best size. | |
391 | m_minSize = m_window->GetEffectiveMinSize(); | |
392 | } | |
393 | ||
394 | return GetMinSizeWithBorder(); | |
395 | } | |
396 | ||
397 | wxSize wxSizerItem::GetMinSizeWithBorder() const | |
398 | { | |
399 | wxSize ret = m_minSize; | |
400 | ||
401 | if (m_flag & wxWEST) | |
402 | ret.x += m_border; | |
403 | if (m_flag & wxEAST) | |
404 | ret.x += m_border; | |
405 | if (m_flag & wxNORTH) | |
406 | ret.y += m_border; | |
407 | if (m_flag & wxSOUTH) | |
408 | ret.y += m_border; | |
409 | ||
410 | return ret; | |
411 | } | |
412 | ||
413 | ||
414 | void wxSizerItem::SetDimension( const wxPoint& pos_, const wxSize& size_ ) | |
415 | { | |
416 | wxPoint pos = pos_; | |
417 | wxSize size = size_; | |
418 | if (m_flag & wxSHAPED) | |
419 | { | |
420 | // adjust aspect ratio | |
421 | int rwidth = (int) (size.y * m_ratio); | |
422 | if (rwidth > size.x) | |
423 | { | |
424 | // fit horizontally | |
425 | int rheight = (int) (size.x / m_ratio); | |
426 | // add vertical space | |
427 | if (m_flag & wxALIGN_CENTER_VERTICAL) | |
428 | pos.y += (size.y - rheight) / 2; | |
429 | else if (m_flag & wxALIGN_BOTTOM) | |
430 | pos.y += (size.y - rheight); | |
431 | // use reduced dimensions | |
432 | size.y =rheight; | |
433 | } | |
434 | else if (rwidth < size.x) | |
435 | { | |
436 | // add horizontal space | |
437 | if (m_flag & wxALIGN_CENTER_HORIZONTAL) | |
438 | pos.x += (size.x - rwidth) / 2; | |
439 | else if (m_flag & wxALIGN_RIGHT) | |
440 | pos.x += (size.x - rwidth); | |
441 | size.x = rwidth; | |
442 | } | |
443 | } | |
444 | ||
445 | // This is what GetPosition() returns. Since we calculate | |
446 | // borders afterwards, GetPosition() will be the left/top | |
447 | // corner of the surrounding border. | |
448 | m_pos = pos; | |
449 | ||
450 | if (m_flag & wxWEST) | |
451 | { | |
452 | pos.x += m_border; | |
453 | size.x -= m_border; | |
454 | } | |
455 | if (m_flag & wxEAST) | |
456 | { | |
457 | size.x -= m_border; | |
458 | } | |
459 | if (m_flag & wxNORTH) | |
460 | { | |
461 | pos.y += m_border; | |
462 | size.y -= m_border; | |
463 | } | |
464 | if (m_flag & wxSOUTH) | |
465 | { | |
466 | size.y -= m_border; | |
467 | } | |
468 | ||
469 | if (size.x < 0) | |
470 | size.x = 0; | |
471 | if (size.y < 0) | |
472 | size.y = 0; | |
473 | ||
474 | m_rect = wxRect(pos, size); | |
475 | ||
476 | switch ( m_kind ) | |
477 | { | |
478 | case Item_None: | |
479 | wxFAIL_MSG( wxT("can't set size of uninitialized sizer item") ); | |
480 | break; | |
481 | ||
482 | case Item_Window: | |
483 | { | |
484 | // Use wxSIZE_FORCE_EVENT here since a sizer item might | |
485 | // have changed alignment or some other property which would | |
486 | // not change the size of the window. In such a case, no | |
487 | // wxSizeEvent would normally be generated and thus the | |
488 | // control wouldn't get layed out correctly here. | |
489 | #if 1 | |
490 | m_window->SetSize(pos.x, pos.y, size.x, size.y, | |
491 | wxSIZE_ALLOW_MINUS_ONE|wxSIZE_FORCE_EVENT ); | |
492 | #else | |
493 | m_window->SetSize(pos.x, pos.y, size.x, size.y, | |
494 | wxSIZE_ALLOW_MINUS_ONE ); | |
495 | #endif | |
496 | break; | |
497 | } | |
498 | case Item_Sizer: | |
499 | m_sizer->SetDimension(pos, size); | |
500 | break; | |
501 | ||
502 | case Item_Spacer: | |
503 | m_spacer->SetSize(size); | |
504 | break; | |
505 | ||
506 | case Item_Max: | |
507 | default: | |
508 | wxFAIL_MSG( wxT("unexpected wxSizerItem::m_kind") ); | |
509 | } | |
510 | } | |
511 | ||
512 | void wxSizerItem::DeleteWindows() | |
513 | { | |
514 | switch ( m_kind ) | |
515 | { | |
516 | case Item_None: | |
517 | case Item_Spacer: | |
518 | break; | |
519 | ||
520 | case Item_Window: | |
521 | //We are deleting the window from this sizer - normally | |
522 | //the window destroys the sizer associated with it, | |
523 | //which might destroy this, which we don't want | |
524 | m_window->SetContainingSizer(NULL); | |
525 | m_window->Destroy(); | |
526 | //Putting this after the switch will result in a spacer | |
527 | //not being deleted properly on destruction | |
528 | m_kind = Item_None; | |
529 | break; | |
530 | ||
531 | case Item_Sizer: | |
532 | m_sizer->DeleteWindows(); | |
533 | break; | |
534 | ||
535 | case Item_Max: | |
536 | default: | |
537 | wxFAIL_MSG( wxT("unexpected wxSizerItem::m_kind") ); | |
538 | } | |
539 | ||
540 | } | |
541 | ||
542 | void wxSizerItem::Show( bool show ) | |
543 | { | |
544 | switch ( m_kind ) | |
545 | { | |
546 | case Item_None: | |
547 | wxFAIL_MSG( wxT("can't show uninitialized sizer item") ); | |
548 | break; | |
549 | ||
550 | case Item_Window: | |
551 | m_window->Show(show); | |
552 | break; | |
553 | ||
554 | case Item_Sizer: | |
555 | m_sizer->Show(show); | |
556 | break; | |
557 | ||
558 | case Item_Spacer: | |
559 | m_spacer->Show(show); | |
560 | break; | |
561 | ||
562 | case Item_Max: | |
563 | default: | |
564 | wxFAIL_MSG( wxT("unexpected wxSizerItem::m_kind") ); | |
565 | } | |
566 | } | |
567 | ||
568 | bool wxSizerItem::IsShown() const | |
569 | { | |
570 | if ( m_flag & wxRESERVE_SPACE_EVEN_IF_HIDDEN ) | |
571 | return true; | |
572 | ||
573 | switch ( m_kind ) | |
574 | { | |
575 | case Item_None: | |
576 | // we may be called from CalcMin(), just return false so that we're | |
577 | // not used | |
578 | break; | |
579 | ||
580 | case Item_Window: | |
581 | return m_window->IsShown(); | |
582 | ||
583 | case Item_Sizer: | |
584 | // arbitrarily decide that if at least one of our elements is | |
585 | // shown, so are we (this arbitrariness is the reason for | |
586 | // deprecating this function) | |
587 | { | |
588 | // Some apps (such as dialog editors) depend on an empty sizer still | |
589 | // being laid out correctly and reporting the correct size and position. | |
590 | if (m_sizer->GetChildren().GetCount() == 0) | |
591 | return true; | |
592 | ||
593 | for ( wxSizerItemList::compatibility_iterator | |
594 | node = m_sizer->GetChildren().GetFirst(); | |
595 | node; | |
596 | node = node->GetNext() ) | |
597 | { | |
598 | if ( node->GetData()->IsShown() ) | |
599 | return true; | |
600 | } | |
601 | } | |
602 | return false; | |
603 | ||
604 | case Item_Spacer: | |
605 | return m_spacer->IsShown(); | |
606 | ||
607 | case Item_Max: | |
608 | default: | |
609 | wxFAIL_MSG( wxT("unexpected wxSizerItem::m_kind") ); | |
610 | } | |
611 | ||
612 | return false; | |
613 | } | |
614 | ||
615 | #if WXWIN_COMPATIBILITY_2_6 | |
616 | void wxSizerItem::SetOption( int option ) | |
617 | { | |
618 | SetProportion( option ); | |
619 | } | |
620 | ||
621 | int wxSizerItem::GetOption() const | |
622 | { | |
623 | return GetProportion(); | |
624 | } | |
625 | #endif // WXWIN_COMPATIBILITY_2_6 | |
626 | ||
627 | ||
628 | //--------------------------------------------------------------------------- | |
629 | // wxSizer | |
630 | //--------------------------------------------------------------------------- | |
631 | ||
632 | wxSizer::~wxSizer() | |
633 | { | |
634 | WX_CLEAR_LIST(wxSizerItemList, m_children); | |
635 | } | |
636 | ||
637 | wxSizerItem* wxSizer::Insert( size_t index, wxSizerItem *item ) | |
638 | { | |
639 | m_children.Insert( index, item ); | |
640 | ||
641 | if ( item->GetWindow() ) | |
642 | item->GetWindow()->SetContainingSizer( this ); | |
643 | ||
644 | if ( item->GetSizer() ) | |
645 | item->GetSizer()->SetContainingWindow( m_containingWindow ); | |
646 | ||
647 | return item; | |
648 | } | |
649 | ||
650 | void wxSizer::SetContainingWindow(wxWindow *win) | |
651 | { | |
652 | if ( win == m_containingWindow ) | |
653 | return; | |
654 | ||
655 | m_containingWindow = win; | |
656 | ||
657 | // set the same window for all nested sizers as well, they also are in the | |
658 | // same window | |
659 | for ( wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
660 | node; | |
661 | node = node->GetNext() ) | |
662 | { | |
663 | wxSizerItem *const item = node->GetData(); | |
664 | wxSizer *const sizer = item->GetSizer(); | |
665 | ||
666 | if ( sizer ) | |
667 | { | |
668 | sizer->SetContainingWindow(win); | |
669 | } | |
670 | } | |
671 | } | |
672 | ||
673 | #if WXWIN_COMPATIBILITY_2_6 | |
674 | bool wxSizer::Remove( wxWindow *window ) | |
675 | { | |
676 | return Detach( window ); | |
677 | } | |
678 | #endif // WXWIN_COMPATIBILITY_2_6 | |
679 | ||
680 | bool wxSizer::Remove( wxSizer *sizer ) | |
681 | { | |
682 | wxASSERT_MSG( sizer, wxT("Removing NULL sizer") ); | |
683 | ||
684 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
685 | while (node) | |
686 | { | |
687 | wxSizerItem *item = node->GetData(); | |
688 | ||
689 | if (item->GetSizer() == sizer) | |
690 | { | |
691 | delete item; | |
692 | m_children.Erase( node ); | |
693 | return true; | |
694 | } | |
695 | ||
696 | node = node->GetNext(); | |
697 | } | |
698 | ||
699 | return false; | |
700 | } | |
701 | ||
702 | bool wxSizer::Remove( int index ) | |
703 | { | |
704 | wxCHECK_MSG( index >= 0 && (size_t)index < m_children.GetCount(), | |
705 | false, | |
706 | wxT("Remove index is out of range") ); | |
707 | ||
708 | wxSizerItemList::compatibility_iterator node = m_children.Item( index ); | |
709 | ||
710 | wxCHECK_MSG( node, false, wxT("Failed to find child node") ); | |
711 | ||
712 | delete node->GetData(); | |
713 | m_children.Erase( node ); | |
714 | ||
715 | return true; | |
716 | } | |
717 | ||
718 | bool wxSizer::Detach( wxSizer *sizer ) | |
719 | { | |
720 | wxASSERT_MSG( sizer, wxT("Detaching NULL sizer") ); | |
721 | ||
722 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
723 | while (node) | |
724 | { | |
725 | wxSizerItem *item = node->GetData(); | |
726 | ||
727 | if (item->GetSizer() == sizer) | |
728 | { | |
729 | item->DetachSizer(); | |
730 | delete item; | |
731 | m_children.Erase( node ); | |
732 | return true; | |
733 | } | |
734 | node = node->GetNext(); | |
735 | } | |
736 | ||
737 | return false; | |
738 | } | |
739 | ||
740 | bool wxSizer::Detach( wxWindow *window ) | |
741 | { | |
742 | wxASSERT_MSG( window, wxT("Detaching NULL window") ); | |
743 | ||
744 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
745 | while (node) | |
746 | { | |
747 | wxSizerItem *item = node->GetData(); | |
748 | ||
749 | if (item->GetWindow() == window) | |
750 | { | |
751 | delete item; | |
752 | m_children.Erase( node ); | |
753 | return true; | |
754 | } | |
755 | node = node->GetNext(); | |
756 | } | |
757 | ||
758 | return false; | |
759 | } | |
760 | ||
761 | bool wxSizer::Detach( int index ) | |
762 | { | |
763 | wxCHECK_MSG( index >= 0 && (size_t)index < m_children.GetCount(), | |
764 | false, | |
765 | wxT("Detach index is out of range") ); | |
766 | ||
767 | wxSizerItemList::compatibility_iterator node = m_children.Item( index ); | |
768 | ||
769 | wxCHECK_MSG( node, false, wxT("Failed to find child node") ); | |
770 | ||
771 | wxSizerItem *item = node->GetData(); | |
772 | ||
773 | if ( item->IsSizer() ) | |
774 | item->DetachSizer(); | |
775 | ||
776 | delete item; | |
777 | m_children.Erase( node ); | |
778 | return true; | |
779 | } | |
780 | ||
781 | bool wxSizer::Replace( wxWindow *oldwin, wxWindow *newwin, bool recursive ) | |
782 | { | |
783 | wxASSERT_MSG( oldwin, wxT("Replacing NULL window") ); | |
784 | wxASSERT_MSG( newwin, wxT("Replacing with NULL window") ); | |
785 | ||
786 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
787 | while (node) | |
788 | { | |
789 | wxSizerItem *item = node->GetData(); | |
790 | ||
791 | if (item->GetWindow() == oldwin) | |
792 | { | |
793 | item->AssignWindow(newwin); | |
794 | newwin->SetContainingSizer( this ); | |
795 | return true; | |
796 | } | |
797 | else if (recursive && item->IsSizer()) | |
798 | { | |
799 | if (item->GetSizer()->Replace( oldwin, newwin, true )) | |
800 | return true; | |
801 | } | |
802 | ||
803 | node = node->GetNext(); | |
804 | } | |
805 | ||
806 | return false; | |
807 | } | |
808 | ||
809 | bool wxSizer::Replace( wxSizer *oldsz, wxSizer *newsz, bool recursive ) | |
810 | { | |
811 | wxASSERT_MSG( oldsz, wxT("Replacing NULL sizer") ); | |
812 | wxASSERT_MSG( newsz, wxT("Replacing with NULL sizer") ); | |
813 | ||
814 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
815 | while (node) | |
816 | { | |
817 | wxSizerItem *item = node->GetData(); | |
818 | ||
819 | if (item->GetSizer() == oldsz) | |
820 | { | |
821 | item->AssignSizer(newsz); | |
822 | return true; | |
823 | } | |
824 | else if (recursive && item->IsSizer()) | |
825 | { | |
826 | if (item->GetSizer()->Replace( oldsz, newsz, true )) | |
827 | return true; | |
828 | } | |
829 | ||
830 | node = node->GetNext(); | |
831 | } | |
832 | ||
833 | return false; | |
834 | } | |
835 | ||
836 | bool wxSizer::Replace( size_t old, wxSizerItem *newitem ) | |
837 | { | |
838 | wxCHECK_MSG( old < m_children.GetCount(), false, wxT("Replace index is out of range") ); | |
839 | wxASSERT_MSG( newitem, wxT("Replacing with NULL item") ); | |
840 | ||
841 | wxSizerItemList::compatibility_iterator node = m_children.Item( old ); | |
842 | ||
843 | wxCHECK_MSG( node, false, wxT("Failed to find child node") ); | |
844 | ||
845 | wxSizerItem *item = node->GetData(); | |
846 | node->SetData(newitem); | |
847 | delete item; | |
848 | ||
849 | return true; | |
850 | } | |
851 | ||
852 | void wxSizer::Clear( bool delete_windows ) | |
853 | { | |
854 | // First clear the ContainingSizer pointers | |
855 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
856 | while (node) | |
857 | { | |
858 | wxSizerItem *item = node->GetData(); | |
859 | ||
860 | if (item->IsWindow()) | |
861 | item->GetWindow()->SetContainingSizer( NULL ); | |
862 | node = node->GetNext(); | |
863 | } | |
864 | ||
865 | // Destroy the windows if needed | |
866 | if (delete_windows) | |
867 | DeleteWindows(); | |
868 | ||
869 | // Now empty the list | |
870 | WX_CLEAR_LIST(wxSizerItemList, m_children); | |
871 | } | |
872 | ||
873 | void wxSizer::DeleteWindows() | |
874 | { | |
875 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
876 | while (node) | |
877 | { | |
878 | wxSizerItem *item = node->GetData(); | |
879 | ||
880 | item->DeleteWindows(); | |
881 | node = node->GetNext(); | |
882 | } | |
883 | } | |
884 | ||
885 | wxSize wxSizer::ComputeFittingClientSize(wxWindow *window) | |
886 | { | |
887 | wxCHECK_MSG( window, wxDefaultSize, "window can't be NULL" ); | |
888 | ||
889 | // take the min size by default and limit it by max size | |
890 | wxSize size = GetMinClientSize(window); | |
891 | wxSize sizeMax; | |
892 | ||
893 | wxTopLevelWindow *tlw = wxDynamicCast(window, wxTopLevelWindow); | |
894 | if ( tlw ) | |
895 | { | |
896 | // hack for small screen devices where TLWs are always full screen | |
897 | if ( tlw->IsAlwaysMaximized() ) | |
898 | { | |
899 | return tlw->GetClientSize(); | |
900 | } | |
901 | ||
902 | // limit the window to the size of the display it is on | |
903 | int disp = wxDisplay::GetFromWindow(window); | |
904 | if ( disp == wxNOT_FOUND ) | |
905 | { | |
906 | // or, if we don't know which one it is, of the main one | |
907 | disp = 0; | |
908 | } | |
909 | ||
910 | sizeMax = wxDisplay(disp).GetClientArea().GetSize(); | |
911 | ||
912 | // space for decorations and toolbars etc. | |
913 | sizeMax = tlw->WindowToClientSize(sizeMax); | |
914 | } | |
915 | else | |
916 | { | |
917 | sizeMax = GetMaxClientSize(window); | |
918 | } | |
919 | ||
920 | if ( sizeMax.x != wxDefaultCoord && size.x > sizeMax.x ) | |
921 | size.x = sizeMax.x; | |
922 | if ( sizeMax.y != wxDefaultCoord && size.y > sizeMax.y ) | |
923 | size.y = sizeMax.y; | |
924 | ||
925 | return size; | |
926 | } | |
927 | ||
928 | wxSize wxSizer::ComputeFittingWindowSize(wxWindow *window) | |
929 | { | |
930 | wxCHECK_MSG( window, wxDefaultSize, "window can't be NULL" ); | |
931 | ||
932 | return window->ClientToWindowSize(ComputeFittingClientSize(window)); | |
933 | } | |
934 | ||
935 | wxSize wxSizer::Fit( wxWindow *window ) | |
936 | { | |
937 | wxCHECK_MSG( window, wxDefaultSize, "window can't be NULL" ); | |
938 | ||
939 | // set client size | |
940 | window->SetClientSize(ComputeFittingClientSize(window)); | |
941 | ||
942 | // return entire size | |
943 | return window->GetSize(); | |
944 | } | |
945 | ||
946 | void wxSizer::FitInside( wxWindow *window ) | |
947 | { | |
948 | wxSize size; | |
949 | if (window->IsTopLevel()) | |
950 | size = VirtualFitSize( window ); | |
951 | else | |
952 | size = GetMinClientSize( window ); | |
953 | ||
954 | window->SetVirtualSize( size ); | |
955 | } | |
956 | ||
957 | void wxSizer::Layout() | |
958 | { | |
959 | // (re)calculates minimums needed for each item and other preparations | |
960 | // for layout | |
961 | CalcMin(); | |
962 | ||
963 | // Applies the layout and repositions/resizes the items | |
964 | RecalcSizes(); | |
965 | } | |
966 | ||
967 | void wxSizer::SetSizeHints( wxWindow *window ) | |
968 | { | |
969 | // Preserve the window's max size hints, but set the | |
970 | // lower bound according to the sizer calculations. | |
971 | ||
972 | // This is equivalent to calling Fit(), except that we need to set | |
973 | // the size hints _in between_ the two steps performed by Fit | |
974 | // (1. ComputeFittingClientSize, 2. SetClientSize). That's because | |
975 | // otherwise SetClientSize() could have no effect if there already are | |
976 | // size hints in effect that forbid requested client size. | |
977 | ||
978 | const wxSize clientSize = ComputeFittingClientSize(window); | |
979 | ||
980 | window->SetMinClientSize(clientSize); | |
981 | window->SetClientSize(clientSize); | |
982 | } | |
983 | ||
984 | #if WXWIN_COMPATIBILITY_2_8 | |
985 | void wxSizer::SetVirtualSizeHints( wxWindow *window ) | |
986 | { | |
987 | FitInside( window ); | |
988 | } | |
989 | #endif // WXWIN_COMPATIBILITY_2_8 | |
990 | ||
991 | // TODO on mac we need a function that determines how much free space this | |
992 | // min size contains, in order to make sure that we have 20 pixels of free | |
993 | // space around the controls | |
994 | wxSize wxSizer::GetMaxClientSize( wxWindow *window ) const | |
995 | { | |
996 | return window->WindowToClientSize(window->GetMaxSize()); | |
997 | } | |
998 | ||
999 | wxSize wxSizer::GetMinClientSize( wxWindow *WXUNUSED(window) ) | |
1000 | { | |
1001 | return GetMinSize(); // Already returns client size. | |
1002 | } | |
1003 | ||
1004 | wxSize wxSizer::VirtualFitSize( wxWindow *window ) | |
1005 | { | |
1006 | wxSize size = GetMinClientSize( window ); | |
1007 | wxSize sizeMax = GetMaxClientSize( window ); | |
1008 | ||
1009 | // Limit the size if sizeMax != wxDefaultSize | |
1010 | ||
1011 | if ( size.x > sizeMax.x && sizeMax.x != wxDefaultCoord ) | |
1012 | size.x = sizeMax.x; | |
1013 | if ( size.y > sizeMax.y && sizeMax.y != wxDefaultCoord ) | |
1014 | size.y = sizeMax.y; | |
1015 | ||
1016 | return size; | |
1017 | } | |
1018 | ||
1019 | wxSize wxSizer::GetMinSize() | |
1020 | { | |
1021 | wxSize ret( CalcMin() ); | |
1022 | if (ret.x < m_minSize.x) ret.x = m_minSize.x; | |
1023 | if (ret.y < m_minSize.y) ret.y = m_minSize.y; | |
1024 | return ret; | |
1025 | } | |
1026 | ||
1027 | void wxSizer::DoSetMinSize( int width, int height ) | |
1028 | { | |
1029 | m_minSize.x = width; | |
1030 | m_minSize.y = height; | |
1031 | } | |
1032 | ||
1033 | bool wxSizer::DoSetItemMinSize( wxWindow *window, int width, int height ) | |
1034 | { | |
1035 | wxASSERT_MSG( window, wxT("SetMinSize for NULL window") ); | |
1036 | ||
1037 | // Is it our immediate child? | |
1038 | ||
1039 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
1040 | while (node) | |
1041 | { | |
1042 | wxSizerItem *item = node->GetData(); | |
1043 | ||
1044 | if (item->GetWindow() == window) | |
1045 | { | |
1046 | item->SetMinSize( width, height ); | |
1047 | return true; | |
1048 | } | |
1049 | node = node->GetNext(); | |
1050 | } | |
1051 | ||
1052 | // No? Search any subsizers we own then | |
1053 | ||
1054 | node = m_children.GetFirst(); | |
1055 | while (node) | |
1056 | { | |
1057 | wxSizerItem *item = node->GetData(); | |
1058 | ||
1059 | if ( item->GetSizer() && | |
1060 | item->GetSizer()->DoSetItemMinSize( window, width, height ) ) | |
1061 | { | |
1062 | // A child sizer found the requested windw, exit. | |
1063 | return true; | |
1064 | } | |
1065 | node = node->GetNext(); | |
1066 | } | |
1067 | ||
1068 | return false; | |
1069 | } | |
1070 | ||
1071 | bool wxSizer::DoSetItemMinSize( wxSizer *sizer, int width, int height ) | |
1072 | { | |
1073 | wxASSERT_MSG( sizer, wxT("SetMinSize for NULL sizer") ); | |
1074 | ||
1075 | // Is it our immediate child? | |
1076 | ||
1077 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
1078 | while (node) | |
1079 | { | |
1080 | wxSizerItem *item = node->GetData(); | |
1081 | ||
1082 | if (item->GetSizer() == sizer) | |
1083 | { | |
1084 | item->GetSizer()->DoSetMinSize( width, height ); | |
1085 | return true; | |
1086 | } | |
1087 | node = node->GetNext(); | |
1088 | } | |
1089 | ||
1090 | // No? Search any subsizers we own then | |
1091 | ||
1092 | node = m_children.GetFirst(); | |
1093 | while (node) | |
1094 | { | |
1095 | wxSizerItem *item = node->GetData(); | |
1096 | ||
1097 | if ( item->GetSizer() && | |
1098 | item->GetSizer()->DoSetItemMinSize( sizer, width, height ) ) | |
1099 | { | |
1100 | // A child found the requested sizer, exit. | |
1101 | return true; | |
1102 | } | |
1103 | node = node->GetNext(); | |
1104 | } | |
1105 | ||
1106 | return false; | |
1107 | } | |
1108 | ||
1109 | bool wxSizer::DoSetItemMinSize( size_t index, int width, int height ) | |
1110 | { | |
1111 | wxSizerItemList::compatibility_iterator node = m_children.Item( index ); | |
1112 | ||
1113 | wxCHECK_MSG( node, false, wxT("Failed to find child node") ); | |
1114 | ||
1115 | wxSizerItem *item = node->GetData(); | |
1116 | ||
1117 | if (item->GetSizer()) | |
1118 | { | |
1119 | // Sizers contains the minimal size in them, if not calculated ... | |
1120 | item->GetSizer()->DoSetMinSize( width, height ); | |
1121 | } | |
1122 | else | |
1123 | { | |
1124 | // ... but the minimal size of spacers and windows is stored via the item | |
1125 | item->SetMinSize( width, height ); | |
1126 | } | |
1127 | ||
1128 | return true; | |
1129 | } | |
1130 | ||
1131 | wxSizerItem* wxSizer::GetItem( wxWindow *window, bool recursive ) | |
1132 | { | |
1133 | wxASSERT_MSG( window, wxT("GetItem for NULL window") ); | |
1134 | ||
1135 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
1136 | while (node) | |
1137 | { | |
1138 | wxSizerItem *item = node->GetData(); | |
1139 | ||
1140 | if (item->GetWindow() == window) | |
1141 | { | |
1142 | return item; | |
1143 | } | |
1144 | else if (recursive && item->IsSizer()) | |
1145 | { | |
1146 | wxSizerItem *subitem = item->GetSizer()->GetItem( window, true ); | |
1147 | if (subitem) | |
1148 | return subitem; | |
1149 | } | |
1150 | ||
1151 | node = node->GetNext(); | |
1152 | } | |
1153 | ||
1154 | return NULL; | |
1155 | } | |
1156 | ||
1157 | wxSizerItem* wxSizer::GetItem( wxSizer *sizer, bool recursive ) | |
1158 | { | |
1159 | wxASSERT_MSG( sizer, wxT("GetItem for NULL sizer") ); | |
1160 | ||
1161 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
1162 | while (node) | |
1163 | { | |
1164 | wxSizerItem *item = node->GetData(); | |
1165 | ||
1166 | if (item->GetSizer() == sizer) | |
1167 | { | |
1168 | return item; | |
1169 | } | |
1170 | else if (recursive && item->IsSizer()) | |
1171 | { | |
1172 | wxSizerItem *subitem = item->GetSizer()->GetItem( sizer, true ); | |
1173 | if (subitem) | |
1174 | return subitem; | |
1175 | } | |
1176 | ||
1177 | node = node->GetNext(); | |
1178 | } | |
1179 | ||
1180 | return NULL; | |
1181 | } | |
1182 | ||
1183 | wxSizerItem* wxSizer::GetItem( size_t index ) | |
1184 | { | |
1185 | wxCHECK_MSG( index < m_children.GetCount(), | |
1186 | NULL, | |
1187 | wxT("GetItem index is out of range") ); | |
1188 | ||
1189 | return m_children.Item( index )->GetData(); | |
1190 | } | |
1191 | ||
1192 | wxSizerItem* wxSizer::GetItemById( int id, bool recursive ) | |
1193 | { | |
1194 | // This gets a sizer item by the id of the sizer item | |
1195 | // and NOT the id of a window if the item is a window. | |
1196 | ||
1197 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
1198 | while (node) | |
1199 | { | |
1200 | wxSizerItem *item = node->GetData(); | |
1201 | ||
1202 | if (item->GetId() == id) | |
1203 | { | |
1204 | return item; | |
1205 | } | |
1206 | else if (recursive && item->IsSizer()) | |
1207 | { | |
1208 | wxSizerItem *subitem = item->GetSizer()->GetItemById( id, true ); | |
1209 | if (subitem) | |
1210 | return subitem; | |
1211 | } | |
1212 | ||
1213 | node = node->GetNext(); | |
1214 | } | |
1215 | ||
1216 | return NULL; | |
1217 | } | |
1218 | ||
1219 | bool wxSizer::Show( wxWindow *window, bool show, bool recursive ) | |
1220 | { | |
1221 | wxSizerItem *item = GetItem( window, recursive ); | |
1222 | ||
1223 | if ( item ) | |
1224 | { | |
1225 | item->Show( show ); | |
1226 | return true; | |
1227 | } | |
1228 | ||
1229 | return false; | |
1230 | } | |
1231 | ||
1232 | bool wxSizer::Show( wxSizer *sizer, bool show, bool recursive ) | |
1233 | { | |
1234 | wxSizerItem *item = GetItem( sizer, recursive ); | |
1235 | ||
1236 | if ( item ) | |
1237 | { | |
1238 | item->Show( show ); | |
1239 | return true; | |
1240 | } | |
1241 | ||
1242 | return false; | |
1243 | } | |
1244 | ||
1245 | bool wxSizer::Show( size_t index, bool show) | |
1246 | { | |
1247 | wxSizerItem *item = GetItem( index ); | |
1248 | ||
1249 | if ( item ) | |
1250 | { | |
1251 | item->Show( show ); | |
1252 | return true; | |
1253 | } | |
1254 | ||
1255 | return false; | |
1256 | } | |
1257 | ||
1258 | void wxSizer::ShowItems( bool show ) | |
1259 | { | |
1260 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
1261 | while (node) | |
1262 | { | |
1263 | node->GetData()->Show( show ); | |
1264 | node = node->GetNext(); | |
1265 | } | |
1266 | } | |
1267 | ||
1268 | bool wxSizer::IsShown( wxWindow *window ) const | |
1269 | { | |
1270 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
1271 | while (node) | |
1272 | { | |
1273 | wxSizerItem *item = node->GetData(); | |
1274 | ||
1275 | if (item->GetWindow() == window) | |
1276 | { | |
1277 | return item->IsShown(); | |
1278 | } | |
1279 | node = node->GetNext(); | |
1280 | } | |
1281 | ||
1282 | wxFAIL_MSG( wxT("IsShown failed to find sizer item") ); | |
1283 | ||
1284 | return false; | |
1285 | } | |
1286 | ||
1287 | bool wxSizer::IsShown( wxSizer *sizer ) const | |
1288 | { | |
1289 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
1290 | while (node) | |
1291 | { | |
1292 | wxSizerItem *item = node->GetData(); | |
1293 | ||
1294 | if (item->GetSizer() == sizer) | |
1295 | { | |
1296 | return item->IsShown(); | |
1297 | } | |
1298 | node = node->GetNext(); | |
1299 | } | |
1300 | ||
1301 | wxFAIL_MSG( wxT("IsShown failed to find sizer item") ); | |
1302 | ||
1303 | return false; | |
1304 | } | |
1305 | ||
1306 | bool wxSizer::IsShown( size_t index ) const | |
1307 | { | |
1308 | wxCHECK_MSG( index < m_children.GetCount(), | |
1309 | false, | |
1310 | wxT("IsShown index is out of range") ); | |
1311 | ||
1312 | return m_children.Item( index )->GetData()->IsShown(); | |
1313 | } | |
1314 | ||
1315 | ||
1316 | //--------------------------------------------------------------------------- | |
1317 | // wxGridSizer | |
1318 | //--------------------------------------------------------------------------- | |
1319 | ||
1320 | wxGridSizer::wxGridSizer( int cols, int vgap, int hgap ) | |
1321 | : m_rows( cols == 0 ? 1 : 0 ), | |
1322 | m_cols( cols ), | |
1323 | m_vgap( vgap ), | |
1324 | m_hgap( hgap ) | |
1325 | { | |
1326 | } | |
1327 | ||
1328 | wxGridSizer::wxGridSizer( int cols, const wxSize& gap ) | |
1329 | : m_rows( cols == 0 ? 1 : 0 ), | |
1330 | m_cols( cols ), | |
1331 | m_vgap( gap.GetHeight() ), | |
1332 | m_hgap( gap.GetWidth() ) | |
1333 | { | |
1334 | } | |
1335 | ||
1336 | wxGridSizer::wxGridSizer( int rows, int cols, int vgap, int hgap ) | |
1337 | : m_rows( rows || cols ? rows : 1 ), | |
1338 | m_cols( cols ), | |
1339 | m_vgap( vgap ), | |
1340 | m_hgap( hgap ) | |
1341 | { | |
1342 | } | |
1343 | ||
1344 | wxGridSizer::wxGridSizer( int rows, int cols, const wxSize& gap ) | |
1345 | : m_rows( rows || cols ? rows : 1 ), | |
1346 | m_cols( cols ), | |
1347 | m_vgap( gap.GetHeight() ), | |
1348 | m_hgap( gap.GetWidth() ) | |
1349 | { | |
1350 | } | |
1351 | ||
1352 | wxSizerItem *wxGridSizer::Insert(size_t index, wxSizerItem *item) | |
1353 | { | |
1354 | // if only the number of columns or the number of rows is specified for a | |
1355 | // sizer, arbitrarily many items can be added to it but if both of them are | |
1356 | // fixed, then the sizer can't have more than that many items -- check for | |
1357 | // this here to ensure that we detect errors as soon as possible | |
1358 | if ( m_cols && m_rows ) | |
1359 | { | |
1360 | const int nitems = m_children.GetCount(); | |
1361 | if ( nitems == m_cols*m_rows ) | |
1362 | { | |
1363 | wxFAIL_MSG( | |
1364 | wxString::Format( | |
1365 | "too many items (%d > %d*%d) in grid sizer (maybe you " | |
1366 | "should omit the number of either rows or columns?)", | |
1367 | nitems + 1, m_cols, m_rows) | |
1368 | ); | |
1369 | ||
1370 | // additionally, continuing to use the specified number of columns | |
1371 | // and rows is not a good idea as callers of CalcRowsCols() expect | |
1372 | // that all sizer items can fit into m_cols/m_rows-sized arrays | |
1373 | // which is not the case if there are too many items and results in | |
1374 | // crashes, so let it compute the number of rows automatically by | |
1375 | // forgetting the (wrong) number of rows specified (this also has a | |
1376 | // nice side effect of giving only one assert even if there are | |
1377 | // many more items than allowed in this sizer) | |
1378 | m_rows = 0; | |
1379 | } | |
1380 | } | |
1381 | ||
1382 | return wxSizer::Insert(index, item); | |
1383 | } | |
1384 | ||
1385 | int wxGridSizer::CalcRowsCols(int& nrows, int& ncols) const | |
1386 | { | |
1387 | const int nitems = m_children.GetCount(); | |
1388 | if ( m_cols && m_rows ) | |
1389 | { | |
1390 | ncols = m_cols; | |
1391 | nrows = m_rows; | |
1392 | ||
1393 | // this should be impossible because the too high number of items | |
1394 | // should have been detected by Insert() above | |
1395 | wxASSERT_MSG( nitems <= ncols*nrows, "logic error in wxGridSizer" ); | |
1396 | } | |
1397 | else if ( m_cols ) | |
1398 | { | |
1399 | ncols = m_cols; | |
1400 | nrows = (nitems + m_cols - 1) / m_cols; | |
1401 | } | |
1402 | else if ( m_rows ) | |
1403 | { | |
1404 | ncols = (nitems + m_rows - 1) / m_rows; | |
1405 | nrows = m_rows; | |
1406 | } | |
1407 | else // 0 columns, 0 rows? | |
1408 | { | |
1409 | wxFAIL_MSG( wxT("grid sizer must have either rows or columns fixed") ); | |
1410 | ||
1411 | nrows = | |
1412 | ncols = 0; | |
1413 | } | |
1414 | ||
1415 | return nitems; | |
1416 | } | |
1417 | ||
1418 | void wxGridSizer::RecalcSizes() | |
1419 | { | |
1420 | int nitems, nrows, ncols; | |
1421 | if ( (nitems = CalcRowsCols(nrows, ncols)) == 0 ) | |
1422 | return; | |
1423 | ||
1424 | wxSize sz( GetSize() ); | |
1425 | wxPoint pt( GetPosition() ); | |
1426 | ||
1427 | int w = (sz.x - (ncols - 1) * m_hgap) / ncols; | |
1428 | int h = (sz.y - (nrows - 1) * m_vgap) / nrows; | |
1429 | ||
1430 | int x = pt.x; | |
1431 | for (int c = 0; c < ncols; c++) | |
1432 | { | |
1433 | int y = pt.y; | |
1434 | for (int r = 0; r < nrows; r++) | |
1435 | { | |
1436 | int i = r * ncols + c; | |
1437 | if (i < nitems) | |
1438 | { | |
1439 | wxSizerItemList::compatibility_iterator node = m_children.Item( i ); | |
1440 | ||
1441 | wxASSERT_MSG( node, wxT("Failed to find SizerItemList node") ); | |
1442 | ||
1443 | SetItemBounds( node->GetData(), x, y, w, h); | |
1444 | } | |
1445 | y = y + h + m_vgap; | |
1446 | } | |
1447 | x = x + w + m_hgap; | |
1448 | } | |
1449 | } | |
1450 | ||
1451 | wxSize wxGridSizer::CalcMin() | |
1452 | { | |
1453 | int nrows, ncols; | |
1454 | if ( CalcRowsCols(nrows, ncols) == 0 ) | |
1455 | return wxSize(); | |
1456 | ||
1457 | // Find the max width and height for any component | |
1458 | int w = 0; | |
1459 | int h = 0; | |
1460 | ||
1461 | wxSizerItemList::compatibility_iterator node = m_children.GetFirst(); | |
1462 | while (node) | |
1463 | { | |
1464 | wxSizerItem *item = node->GetData(); | |
1465 | wxSize sz( item->CalcMin() ); | |
1466 | ||
1467 | w = wxMax( w, sz.x ); | |
1468 | h = wxMax( h, sz.y ); | |
1469 | ||
1470 | node = node->GetNext(); | |
1471 | } | |
1472 | ||
1473 | // In case we have a nested sizer with a two step algo , give it | |
1474 | // a chance to adjust to that (we give it width component) | |
1475 | node = m_children.GetFirst(); | |
1476 | bool didChangeMinSize = false; | |
1477 | while (node) | |
1478 | { | |
1479 | wxSizerItem *item = node->GetData(); | |
1480 | didChangeMinSize |= item->InformFirstDirection( wxHORIZONTAL, w, -1 ); | |
1481 | ||
1482 | node = node->GetNext(); | |
1483 | } | |
1484 | ||
1485 | // And redo iteration in case min size changed | |
1486 | if( didChangeMinSize ) | |
1487 | { | |
1488 | node = m_children.GetFirst(); | |
1489 | w = h = 0; | |
1490 | while (node) | |
1491 | { | |
1492 | wxSizerItem *item = node->GetData(); | |
1493 | wxSize sz( item->GetMinSizeWithBorder() ); | |
1494 | ||
1495 | w = wxMax( w, sz.x ); | |
1496 | h = wxMax( h, sz.y ); | |
1497 | ||
1498 | node = node->GetNext(); | |
1499 | } | |
1500 | } | |
1501 | ||
1502 | return wxSize( ncols * w + (ncols-1) * m_hgap, | |
1503 | nrows * h + (nrows-1) * m_vgap ); | |
1504 | } | |
1505 | ||
1506 | void wxGridSizer::SetItemBounds( wxSizerItem *item, int x, int y, int w, int h ) | |
1507 | { | |
1508 | wxPoint pt( x,y ); | |
1509 | wxSize sz( item->GetMinSizeWithBorder() ); | |
1510 | int flag = item->GetFlag(); | |
1511 | ||
1512 | if ((flag & wxEXPAND) || (flag & wxSHAPED)) | |
1513 | { | |
1514 | sz = wxSize(w, h); | |
1515 | } | |
1516 | else | |
1517 | { | |
1518 | if (flag & wxALIGN_CENTER_HORIZONTAL) | |
1519 | { | |
1520 | pt.x = x + (w - sz.x) / 2; | |
1521 | } | |
1522 | else if (flag & wxALIGN_RIGHT) | |
1523 | { | |
1524 | pt.x = x + (w - sz.x); | |
1525 | } | |
1526 | ||
1527 | if (flag & wxALIGN_CENTER_VERTICAL) | |
1528 | { | |
1529 | pt.y = y + (h - sz.y) / 2; | |
1530 | } | |
1531 | else if (flag & wxALIGN_BOTTOM) | |
1532 | { | |
1533 | pt.y = y + (h - sz.y); | |
1534 | } | |
1535 | } | |
1536 | ||
1537 | item->SetDimension(pt, sz); | |
1538 | } | |
1539 | ||
1540 | //--------------------------------------------------------------------------- | |
1541 | // wxFlexGridSizer | |
1542 | //--------------------------------------------------------------------------- | |
1543 | ||
1544 | wxFlexGridSizer::wxFlexGridSizer( int cols, int vgap, int hgap ) | |
1545 | : wxGridSizer( cols, vgap, hgap ), | |
1546 | m_flexDirection(wxBOTH), | |
1547 | m_growMode(wxFLEX_GROWMODE_SPECIFIED) | |
1548 | { | |
1549 | } | |
1550 | ||
1551 | wxFlexGridSizer::wxFlexGridSizer( int cols, const wxSize& gap ) | |
1552 | : wxGridSizer( cols, gap ), | |
1553 | m_flexDirection(wxBOTH), | |
1554 | m_growMode(wxFLEX_GROWMODE_SPECIFIED) | |
1555 | { | |
1556 | } | |
1557 | ||
1558 | wxFlexGridSizer::wxFlexGridSizer( int rows, int cols, int vgap, int hgap ) | |
1559 | : wxGridSizer( rows, cols, vgap, hgap ), | |
1560 | m_flexDirection(wxBOTH), | |
1561 | m_growMode(wxFLEX_GROWMODE_SPECIFIED) | |
1562 | { | |
1563 | } | |
1564 | ||
1565 | wxFlexGridSizer::wxFlexGridSizer( int rows, int cols, const wxSize& gap ) | |
1566 | : wxGridSizer( rows, cols, gap ), | |
1567 | m_flexDirection(wxBOTH), | |
1568 | m_growMode(wxFLEX_GROWMODE_SPECIFIED) | |
1569 | { | |
1570 | } | |
1571 | ||
1572 | wxFlexGridSizer::~wxFlexGridSizer() | |
1573 | { | |
1574 | } | |
1575 | ||
1576 | void wxFlexGridSizer::RecalcSizes() | |
1577 | { | |
1578 | int nrows, ncols; | |
1579 | if ( !CalcRowsCols(nrows, ncols) ) | |
1580 | return; | |
1581 | ||
1582 | const wxPoint pt(GetPosition()); | |
1583 | const wxSize sz(GetSize()); | |
1584 | ||
1585 | AdjustForGrowables(sz); | |
1586 | ||
1587 | wxSizerItemList::const_iterator i = m_children.begin(); | |
1588 | const wxSizerItemList::const_iterator end = m_children.end(); | |
1589 | ||
1590 | int y = 0; | |
1591 | for ( int r = 0; r < nrows; r++ ) | |
1592 | { | |
1593 | if ( m_rowHeights[r] == -1 ) | |
1594 | { | |
1595 | // this row is entirely hidden, skip it | |
1596 | for ( int c = 0; c < ncols; c++ ) | |
1597 | { | |
1598 | if ( i == end ) | |
1599 | return; | |
1600 | ||
1601 | ++i; | |
1602 | } | |
1603 | ||
1604 | continue; | |
1605 | } | |
1606 | ||
1607 | const int hrow = m_rowHeights[r]; | |
1608 | int h = sz.y - y; // max remaining height, don't overflow it | |
1609 | if ( hrow < h ) | |
1610 | h = hrow; | |
1611 | ||
1612 | int x = 0; | |
1613 | for ( int c = 0; c < ncols && i != end; c++, ++i ) | |
1614 | { | |
1615 | const int wcol = m_colWidths[c]; | |
1616 | ||
1617 | if ( wcol == -1 ) | |
1618 | continue; | |
1619 | ||
1620 | int w = sz.x - x; // max possible value, ensure we don't overflow | |
1621 | if ( wcol < w ) | |
1622 | w = wcol; | |
1623 | ||
1624 | SetItemBounds(*i, pt.x + x, pt.y + y, w, h); | |
1625 | ||
1626 | x += wcol + m_hgap; | |
1627 | } | |
1628 | ||
1629 | if ( i == end ) | |
1630 | return; | |
1631 | ||
1632 | y += hrow + m_vgap; | |
1633 | } | |
1634 | } | |
1635 | ||
1636 | // helper function used in CalcMin() to sum up the sizes of non-hidden items | |
1637 | static int SumArraySizes(const wxArrayInt& sizes, int gap) | |
1638 | { | |
1639 | // Sum total minimum size, including gaps between rows/columns. | |
1640 | // -1 is used as a magic number meaning empty row/column. | |
1641 | int total = 0; | |
1642 | ||
1643 | const size_t count = sizes.size(); | |
1644 | for ( size_t n = 0; n < count; n++ ) | |
1645 | { | |
1646 | if ( sizes[n] != -1 ) | |
1647 | { | |
1648 | if ( total ) | |
1649 | total += gap; // separate from the previous column | |
1650 | ||
1651 | total += sizes[n]; | |
1652 | } | |
1653 | } | |
1654 | ||
1655 | return total; | |
1656 | } | |
1657 | ||
1658 | void wxFlexGridSizer::FindWidthsAndHeights(int nrows, int ncols) | |
1659 | { | |
1660 | // We have to recalculate the sizes in case the item minimum size has | |
1661 | // changed since the previous layout, or the item has been hidden using | |
1662 | // wxSizer::Show(). If all the items in a row/column are hidden, the final | |
1663 | // dimension of the row/column will be -1, indicating that the column | |
1664 | // itself is hidden. | |
1665 | m_rowHeights.assign(nrows, -1); | |
1666 | m_colWidths.assign(ncols, -1); | |
1667 | ||
1668 | // n is the index of the item in left-to-right top-to-bottom order | |
1669 | size_t n = 0; | |
1670 | for ( wxSizerItemList::iterator i = m_children.begin(); | |
1671 | i != m_children.end(); | |
1672 | ++i, ++n ) | |
1673 | { | |
1674 | wxSizerItem * const item = *i; | |
1675 | if ( item->IsShown() ) | |
1676 | { | |
1677 | // NOTE: Not doing the calculation here, this is just | |
1678 | // for finding max values. | |
1679 | const wxSize sz(item->GetMinSizeWithBorder()); | |
1680 | ||
1681 | const int row = n / ncols; | |
1682 | const int col = n % ncols; | |
1683 | ||
1684 | if ( sz.y > m_rowHeights[row] ) | |
1685 | m_rowHeights[row] = sz.y; | |
1686 | if ( sz.x > m_colWidths[col] ) | |
1687 | m_colWidths[col] = sz.x; | |
1688 | } | |
1689 | } | |
1690 | ||
1691 | AdjustForFlexDirection(); | |
1692 | ||
1693 | m_calculatedMinSize = wxSize(SumArraySizes(m_colWidths, m_hgap), | |
1694 | SumArraySizes(m_rowHeights, m_vgap)); | |
1695 | } | |
1696 | ||
1697 | wxSize wxFlexGridSizer::CalcMin() | |
1698 | { | |
1699 | int nrows, | |
1700 | ncols; | |
1701 | ||
1702 | // Number of rows/columns can change as items are added or removed. | |
1703 | if ( !CalcRowsCols(nrows, ncols) ) | |
1704 | return wxSize(); | |
1705 | ||
1706 | ||
1707 | // We have to recalculate the sizes in case the item minimum size has | |
1708 | // changed since the previous layout, or the item has been hidden using | |
1709 | // wxSizer::Show(). If all the items in a row/column are hidden, the final | |
1710 | // dimension of the row/column will be -1, indicating that the column | |
1711 | // itself is hidden. | |
1712 | m_rowHeights.assign(nrows, -1); | |
1713 | m_colWidths.assign(ncols, -1); | |
1714 | ||
1715 | for ( wxSizerItemList::iterator i = m_children.begin(); | |
1716 | i != m_children.end(); | |
1717 | ++i) | |
1718 | { | |
1719 | wxSizerItem * const item = *i; | |
1720 | if ( item->IsShown() ) | |
1721 | { | |
1722 | item->CalcMin(); | |
1723 | } | |
1724 | } | |
1725 | ||
1726 | // The stage of looking for max values in each row/column has been | |
1727 | // made a separate function, since it's reused in AdjustForGrowables. | |
1728 | FindWidthsAndHeights(nrows,ncols); | |
1729 | ||
1730 | return m_calculatedMinSize; | |
1731 | } | |
1732 | ||
1733 | void wxFlexGridSizer::AdjustForFlexDirection() | |
1734 | { | |
1735 | // the logic in CalcMin works when we resize flexibly in both directions | |
1736 | // but maybe this is not the case | |
1737 | if ( m_flexDirection != wxBOTH ) | |
1738 | { | |
1739 | // select the array corresponding to the direction in which we do *not* | |
1740 | // resize flexibly | |
1741 | wxArrayInt& array = m_flexDirection == wxVERTICAL ? m_colWidths | |
1742 | : m_rowHeights; | |
1743 | ||
1744 | const size_t count = array.GetCount(); | |
1745 | ||
1746 | // find the largest value in this array | |
1747 | size_t n; | |
1748 | int largest = 0; | |
1749 | ||
1750 | for ( n = 0; n < count; ++n ) | |
1751 | { | |
1752 | if ( array[n] > largest ) | |
1753 | largest = array[n]; | |
1754 | } | |
1755 | ||
1756 | // and now fill it with the largest value | |
1757 | for ( n = 0; n < count; ++n ) | |
1758 | { | |
1759 | // don't touch hidden rows | |
1760 | if ( array[n] != -1 ) | |
1761 | array[n] = largest; | |
1762 | } | |
1763 | } | |
1764 | } | |
1765 | ||
1766 | // helper of AdjustForGrowables() which is called for rows/columns separately | |
1767 | // | |
1768 | // parameters: | |
1769 | // delta: the extra space, we do nothing unless it's positive | |
1770 | // growable: indices or growable rows/cols in sizes array | |
1771 | // sizes: the height/widths of rows/cols to adjust | |
1772 | // proportions: proportions of the growable rows/cols or NULL if they all | |
1773 | // should be assumed to have proportion of 1 | |
1774 | static void | |
1775 | DoAdjustForGrowables(int delta, | |
1776 | const wxArrayInt& growable, | |
1777 | wxArrayInt& sizes, | |
1778 | const wxArrayInt *proportions) | |
1779 | { | |
1780 | if ( delta <= 0 ) | |
1781 | return; | |
1782 | ||
1783 | // total sum of proportions of all non-hidden rows | |
1784 | int sum_proportions = 0; | |
1785 | ||
1786 | // number of currently shown growable rows | |
1787 | int num = 0; | |
1788 | ||
1789 | const int max_idx = sizes.size(); | |
1790 | ||
1791 | const size_t count = growable.size(); | |
1792 | size_t idx; | |
1793 | for ( idx = 0; idx < count; idx++ ) | |
1794 | { | |
1795 | // Since the number of rows/columns can change as items are | |
1796 | // inserted/deleted, we need to verify at runtime that the | |
1797 | // requested growable rows/columns are still valid. | |
1798 | if ( growable[idx] >= max_idx ) | |
1799 | continue; | |
1800 | ||
1801 | // If all items in a row/column are hidden, that row/column will | |
1802 | // have a dimension of -1. This causes the row/column to be | |
1803 | // hidden completely. | |
1804 | if ( sizes[growable[idx]] == -1 ) | |
1805 | continue; | |
1806 | ||
1807 | if ( proportions ) | |
1808 | sum_proportions += (*proportions)[idx]; | |
1809 | ||
1810 | num++; | |
1811 | } | |
1812 | ||
1813 | if ( !num ) | |
1814 | return; | |
1815 | ||
1816 | // the remaining extra free space, adjusted during each iteration | |
1817 | for ( idx = 0; idx < count; idx++ ) | |
1818 | { | |
1819 | if ( growable[idx] >= max_idx ) | |
1820 | continue; | |
1821 | ||
1822 | if ( sizes[ growable[idx] ] == -1 ) | |
1823 | continue; | |
1824 | ||
1825 | int cur_delta; | |
1826 | if ( sum_proportions == 0 ) | |
1827 | { | |
1828 | // no growable rows -- divide extra space evenly among all | |
1829 | cur_delta = delta/num; | |
1830 | num--; | |
1831 | } | |
1832 | else // allocate extra space proportionally | |
1833 | { | |
1834 | const int cur_prop = (*proportions)[idx]; | |
1835 | cur_delta = (delta*cur_prop)/sum_proportions; | |
1836 | sum_proportions -= cur_prop; | |
1837 | } | |
1838 | ||
1839 | sizes[growable[idx]] += cur_delta; | |
1840 | delta -= cur_delta; | |
1841 | } | |
1842 | } | |
1843 | ||
1844 | void wxFlexGridSizer::AdjustForGrowables(const wxSize& sz) | |
1845 | { | |
1846 | #if wxDEBUG_LEVEL | |
1847 | // by the time this function is called, the sizer should be already fully | |
1848 | // initialized and hence the number of its columns and rows is known and we | |
1849 | // can check that all indices in m_growableCols/Rows are valid (see also | |
1850 | // comments in AddGrowableCol/Row()) | |
1851 | if ( !m_rows || !m_cols ) | |
1852 | { | |
1853 | int nrows, ncols; | |
1854 | CalcRowsCols(nrows, ncols); | |
1855 | ||
1856 | if ( !m_rows ) | |
1857 | { | |
1858 | for ( size_t n = 0; n < m_growableRows.size(); n++ ) | |
1859 | { | |
1860 | wxASSERT_MSG( m_growableRows[n] < nrows, | |
1861 | "invalid growable row index" ); | |
1862 | } | |
1863 | } | |
1864 | ||
1865 | if ( !m_cols ) | |
1866 | { | |
1867 | for ( size_t n = 0; n < m_growableCols.size(); n++ ) | |
1868 | { | |
1869 | wxASSERT_MSG( m_growableCols[n] < ncols, | |
1870 | "invalid growable column index" ); | |
1871 | } | |
1872 | } | |
1873 | } | |
1874 | #endif // wxDEBUG_LEVEL | |
1875 | ||
1876 | ||
1877 | if ( (m_flexDirection & wxHORIZONTAL) || (m_growMode != wxFLEX_GROWMODE_NONE) ) | |
1878 | { | |
1879 | DoAdjustForGrowables | |
1880 | ( | |
1881 | sz.x - m_calculatedMinSize.x, | |
1882 | m_growableCols, | |
1883 | m_colWidths, | |
1884 | m_growMode == wxFLEX_GROWMODE_SPECIFIED ? &m_growableColsProportions | |
1885 | : NULL | |
1886 | ); | |
1887 | ||
1888 | // This gives nested objects that benefit from knowing one size | |
1889 | // component in advance the chance to use that. | |
1890 | bool didAdjustMinSize = false; | |
1891 | int nrows, ncols; | |
1892 | CalcRowsCols(nrows, ncols); | |
1893 | ||
1894 | // Iterate over all items and inform about column width | |
1895 | size_t n = 0; | |
1896 | for ( wxSizerItemList::iterator i = m_children.begin(); | |
1897 | i != m_children.end(); | |
1898 | ++i, ++n ) | |
1899 | { | |
1900 | const int col = n % ncols; | |
1901 | didAdjustMinSize |= (*i)->InformFirstDirection(wxHORIZONTAL, m_colWidths[col], sz.y - m_calculatedMinSize.y); | |
1902 | } | |
1903 | ||
1904 | // Only redo if info was actually used | |
1905 | if( didAdjustMinSize ) | |
1906 | { | |
1907 | DoAdjustForGrowables | |
1908 | ( | |
1909 | sz.x - m_calculatedMinSize.x, | |
1910 | m_growableCols, | |
1911 | m_colWidths, | |
1912 | m_growMode == wxFLEX_GROWMODE_SPECIFIED ? &m_growableColsProportions | |
1913 | : NULL | |
1914 | ); | |
1915 | } | |
1916 | } | |
1917 | ||
1918 | if ( (m_flexDirection & wxVERTICAL) || (m_growMode != wxFLEX_GROWMODE_NONE) ) | |
1919 | { | |
1920 | // pass NULL instead of proportions if the grow mode is ALL as we | |
1921 | // should treat all rows as having proportion of 1 then | |
1922 | DoAdjustForGrowables | |
1923 | ( | |
1924 | sz.y - m_calculatedMinSize.y, | |
1925 | m_growableRows, | |
1926 | m_rowHeights, | |
1927 | m_growMode == wxFLEX_GROWMODE_SPECIFIED ? &m_growableRowsProportions | |
1928 | : NULL | |
1929 | ); | |
1930 | } | |
1931 | } | |
1932 | ||
1933 | bool wxFlexGridSizer::IsRowGrowable( size_t idx ) | |
1934 | { | |
1935 | return m_growableRows.Index( idx ) != wxNOT_FOUND; | |
1936 | } | |
1937 | ||
1938 | bool wxFlexGridSizer::IsColGrowable( size_t idx ) | |
1939 | { | |
1940 | return m_growableCols.Index( idx ) != wxNOT_FOUND; | |
1941 | } | |
1942 | ||
1943 | void wxFlexGridSizer::AddGrowableRow( size_t idx, int proportion ) | |
1944 | { | |
1945 | int nrows, ncols; | |
1946 | CalcRowsCols(nrows, ncols); | |
1947 | ||
1948 | wxASSERT_MSG( !IsRowGrowable( idx ), | |
1949 | "AddGrowableRow() called for growable row" ); | |
1950 | ||
1951 | // notice that we intentionally don't check the index validity here in (the | |
1952 | // common) case when the number of rows was not specified in the ctor -- in | |
1953 | // this case it will be computed only later, when all items are added to | |
1954 | // the sizer, and the check will be done in AdjustForGrowables() | |
1955 | wxCHECK_RET( !m_rows || idx < (size_t)m_rows, "invalid row index" ); | |
1956 | ||
1957 | m_growableRows.Add( idx ); | |
1958 | m_growableRowsProportions.Add( proportion ); | |
1959 | } | |
1960 | ||
1961 | void wxFlexGridSizer::AddGrowableCol( size_t idx, int proportion ) | |
1962 | { | |
1963 | int nrows, ncols; | |
1964 | CalcRowsCols(nrows, ncols); | |
1965 | ||
1966 | wxASSERT_MSG( !IsColGrowable( idx ), | |
1967 | "AddGrowableCol() called for growable column" ); | |
1968 | ||
1969 | // see comment in AddGrowableRow(): although it's less common to omit the | |
1970 | // specification of the number of columns, it still can also happen | |
1971 | wxCHECK_RET( !m_cols || idx < (size_t)ncols, "invalid column index" ); | |
1972 | ||
1973 | m_growableCols.Add( idx ); | |
1974 | m_growableColsProportions.Add( proportion ); | |
1975 | } | |
1976 | ||
1977 | // helper function for RemoveGrowableCol/Row() | |
1978 | static void | |
1979 | DoRemoveFromArrays(size_t idx, wxArrayInt& items, wxArrayInt& proportions) | |
1980 | { | |
1981 | const size_t count = items.size(); | |
1982 | for ( size_t n = 0; n < count; n++ ) | |
1983 | { | |
1984 | if ( (size_t)items[n] == idx ) | |
1985 | { | |
1986 | items.RemoveAt(n); | |
1987 | proportions.RemoveAt(n); | |
1988 | return; | |
1989 | } | |
1990 | } | |
1991 | ||
1992 | wxFAIL_MSG( wxT("column/row is already not growable") ); | |
1993 | } | |
1994 | ||
1995 | void wxFlexGridSizer::RemoveGrowableCol( size_t idx ) | |
1996 | { | |
1997 | DoRemoveFromArrays(idx, m_growableCols, m_growableColsProportions); | |
1998 | } | |
1999 | ||
2000 | void wxFlexGridSizer::RemoveGrowableRow( size_t idx ) | |
2001 | { | |
2002 | DoRemoveFromArrays(idx, m_growableRows, m_growableRowsProportions); | |
2003 | } | |
2004 | ||
2005 | //--------------------------------------------------------------------------- | |
2006 | // wxBoxSizer | |
2007 | //--------------------------------------------------------------------------- | |
2008 | ||
2009 | void wxBoxSizer::RecalcSizes() | |
2010 | { | |
2011 | if ( m_children.empty() ) | |
2012 | return; | |
2013 | ||
2014 | const wxCoord totalMinorSize = GetSizeInMinorDir(m_size); | |
2015 | ||
2016 | // the amount of free space which we should redistribute among the | |
2017 | // stretchable items (i.e. those with non zero proportion) | |
2018 | int delta = GetSizeInMajorDir(m_size) - GetSizeInMajorDir(m_minSize); | |
2019 | ||
2020 | ||
2021 | // Inform child items about the size in minor direction, that can | |
2022 | // change how much free space we have in major dir and how to distribute it. | |
2023 | int majorMinSum = 0; | |
2024 | wxSizerItemList::const_iterator i ; | |
2025 | for ( i = m_children.begin(); | |
2026 | i != m_children.end(); | |
2027 | ++i ) | |
2028 | { | |
2029 | wxSizerItem * const item = *i; | |
2030 | ||
2031 | if ( !item->IsShown() ) | |
2032 | continue; | |
2033 | ||
2034 | wxSize szMinPrev = item->GetMinSizeWithBorder(); | |
2035 | item->InformFirstDirection(m_orient^wxBOTH,totalMinorSize,delta); | |
2036 | wxSize szMin = item->GetMinSizeWithBorder(); | |
2037 | int deltaChange = GetSizeInMajorDir(szMin-szMinPrev); | |
2038 | if( deltaChange ) | |
2039 | { | |
2040 | // Since we passed available space along to the item, it should not | |
2041 | // take too much, so delta should not become negative. | |
2042 | delta -= deltaChange; | |
2043 | } | |
2044 | majorMinSum += GetSizeInMajorDir(item->GetMinSizeWithBorder()); | |
2045 | } | |
2046 | // And update our min size | |
2047 | SizeInMajorDir(m_minSize) = majorMinSum; | |
2048 | ||
2049 | ||
2050 | // might have a new delta now | |
2051 | delta = GetSizeInMajorDir(m_size) - GetSizeInMajorDir(m_minSize); | |
2052 | ||
2053 | // the position at which we put the next child | |
2054 | wxPoint pt(m_position); | |
2055 | ||
2056 | int totalProportion = m_totalProportion; | |
2057 | for ( i = m_children.begin(); | |
2058 | i != m_children.end(); | |
2059 | ++i ) | |
2060 | { | |
2061 | wxSizerItem * const item = *i; | |
2062 | ||
2063 | if ( !item->IsShown() ) | |
2064 | continue; | |
2065 | ||
2066 | const wxSize sizeThis(item->GetMinSizeWithBorder()); | |
2067 | ||
2068 | // adjust the size in the major direction using the proportion | |
2069 | wxCoord majorSize = GetSizeInMajorDir(sizeThis); | |
2070 | ||
2071 | // if there is not enough space, don't try to distribute negative space | |
2072 | // among the children, this would result in overlapping windows which | |
2073 | // we don't want | |
2074 | if ( delta > 0 ) | |
2075 | { | |
2076 | const int propItem = item->GetProportion(); | |
2077 | if ( propItem ) | |
2078 | { | |
2079 | const int deltaItem = (delta * propItem) / totalProportion; | |
2080 | ||
2081 | majorSize += deltaItem; | |
2082 | ||
2083 | delta -= deltaItem; | |
2084 | totalProportion -= propItem; | |
2085 | } | |
2086 | } | |
2087 | ||
2088 | ||
2089 | // apply the alignment in the minor direction | |
2090 | wxPoint posChild(pt); | |
2091 | ||
2092 | wxCoord minorSize = GetSizeInMinorDir(sizeThis); | |
2093 | const int flag = item->GetFlag(); | |
2094 | if ( flag & (wxEXPAND | wxSHAPED) ) | |
2095 | { | |
2096 | minorSize = totalMinorSize; | |
2097 | } | |
2098 | else if ( flag & (IsVertical() ? wxALIGN_RIGHT : wxALIGN_BOTTOM) ) | |
2099 | { | |
2100 | PosInMinorDir(posChild) += totalMinorSize - minorSize; | |
2101 | } | |
2102 | // NB: wxCENTRE is used here only for backwards compatibility, | |
2103 | // wxALIGN_CENTRE should be used in new code | |
2104 | else if ( flag & (wxCENTER | (IsVertical() ? wxALIGN_CENTRE_HORIZONTAL : wxALIGN_CENTRE_VERTICAL))) | |
2105 | { | |
2106 | PosInMinorDir(posChild) += (totalMinorSize - minorSize) / 2; | |
2107 | } | |
2108 | ||
2109 | ||
2110 | // apply RTL adjustment for horizontal sizers: | |
2111 | if ( !IsVertical() && m_containingWindow ) | |
2112 | { | |
2113 | posChild.x = m_containingWindow->AdjustForLayoutDirection | |
2114 | ( | |
2115 | posChild.x, | |
2116 | majorSize, | |
2117 | m_size.x | |
2118 | ); | |
2119 | } | |
2120 | ||
2121 | // finally set size of this child and advance to the next one | |
2122 | item->SetDimension(posChild, SizeFromMajorMinor(majorSize, minorSize)); | |
2123 | ||
2124 | PosInMajorDir(pt) += majorSize; | |
2125 | } | |
2126 | } | |
2127 | ||
2128 | wxSize wxBoxSizer::CalcMin() | |
2129 | { | |
2130 | m_totalProportion = 0; | |
2131 | m_minSize = wxSize(0, 0); | |
2132 | ||
2133 | // calculate the minimal sizes for all items and count sum of proportions | |
2134 | for ( wxSizerItemList::const_iterator i = m_children.begin(); | |
2135 | i != m_children.end(); | |
2136 | ++i ) | |
2137 | { | |
2138 | wxSizerItem * const item = *i; | |
2139 | ||
2140 | if ( !item->IsShown() ) | |
2141 | continue; | |
2142 | ||
2143 | const wxSize sizeMinThis = item->CalcMin(); | |
2144 | SizeInMajorDir(m_minSize) += GetSizeInMajorDir(sizeMinThis); | |
2145 | if ( GetSizeInMinorDir(sizeMinThis) > GetSizeInMinorDir(m_minSize) ) | |
2146 | SizeInMinorDir(m_minSize) = GetSizeInMinorDir(sizeMinThis); | |
2147 | ||
2148 | m_totalProportion += item->GetProportion(); | |
2149 | } | |
2150 | ||
2151 | return m_minSize; | |
2152 | } | |
2153 | ||
2154 | //--------------------------------------------------------------------------- | |
2155 | // wxStaticBoxSizer | |
2156 | //--------------------------------------------------------------------------- | |
2157 | ||
2158 | #if wxUSE_STATBOX | |
2159 | ||
2160 | wxStaticBoxSizer::wxStaticBoxSizer( wxStaticBox *box, int orient ) | |
2161 | : wxBoxSizer( orient ), | |
2162 | m_staticBox( box ) | |
2163 | { | |
2164 | wxASSERT_MSG( box, wxT("wxStaticBoxSizer needs a static box") ); | |
2165 | ||
2166 | // do this so that our Detach() is called if the static box is destroyed | |
2167 | // before we are | |
2168 | m_staticBox->SetContainingSizer(this); | |
2169 | } | |
2170 | ||
2171 | wxStaticBoxSizer::wxStaticBoxSizer(int orient, wxWindow *win, const wxString& s) | |
2172 | : wxBoxSizer(orient), | |
2173 | m_staticBox(new wxStaticBox(win, wxID_ANY, s)) | |
2174 | { | |
2175 | // same as above | |
2176 | m_staticBox->SetContainingSizer(this); | |
2177 | } | |
2178 | ||
2179 | wxStaticBoxSizer::~wxStaticBoxSizer() | |
2180 | { | |
2181 | delete m_staticBox; | |
2182 | } | |
2183 | ||
2184 | void wxStaticBoxSizer::RecalcSizes() | |
2185 | { | |
2186 | int top_border, other_border; | |
2187 | m_staticBox->GetBordersForSizer(&top_border, &other_border); | |
2188 | ||
2189 | m_staticBox->SetSize( m_position.x, m_position.y, m_size.x, m_size.y ); | |
2190 | ||
2191 | wxSize old_size( m_size ); | |
2192 | m_size.x -= 2*other_border; | |
2193 | m_size.y -= top_border + other_border; | |
2194 | ||
2195 | wxPoint old_pos( m_position ); | |
2196 | if (m_staticBox->GetChildren().GetCount() > 0) | |
2197 | { | |
2198 | #if defined( __WXGTK20__ ) | |
2199 | // if the wxStaticBox has created a wxPizza to contain its children | |
2200 | // (see wxStaticBox::AddChild) then we need to place the items it contains | |
2201 | // in the wxBoxSizer::RecalcSizes() call below using coordinates relative | |
2202 | // to the top-left corner of the staticbox: | |
2203 | m_position.x = m_position.y = 0; | |
2204 | #else | |
2205 | // if the wxStaticBox has childrens, then these windows must be placed | |
2206 | // by the wxBoxSizer::RecalcSizes() call below using coordinates relative | |
2207 | // to the top-left corner of the staticbox (but unlike wxGTK, we need | |
2208 | // to keep in count the static borders here!): | |
2209 | m_position.x = other_border; | |
2210 | m_position.y = top_border; | |
2211 | #endif | |
2212 | } | |
2213 | else | |
2214 | { | |
2215 | // the windows contained in the staticbox have been created as siblings of the | |
2216 | // staticbox (this is the "old" way of staticbox contents creation); in this | |
2217 | // case we need to position them with coordinates relative to our common parent | |
2218 | m_position.x += other_border; | |
2219 | m_position.y += top_border; | |
2220 | } | |
2221 | ||
2222 | wxBoxSizer::RecalcSizes(); | |
2223 | ||
2224 | m_position = old_pos; | |
2225 | m_size = old_size; | |
2226 | } | |
2227 | ||
2228 | wxSize wxStaticBoxSizer::CalcMin() | |
2229 | { | |
2230 | int top_border, other_border; | |
2231 | m_staticBox->GetBordersForSizer(&top_border, &other_border); | |
2232 | ||
2233 | wxSize ret( wxBoxSizer::CalcMin() ); | |
2234 | ret.x += 2*other_border; | |
2235 | ||
2236 | // ensure that we're wide enough to show the static box label (there is no | |
2237 | // need to check for the static box best size in vertical direction though) | |
2238 | const int boxWidth = m_staticBox->GetBestSize().x; | |
2239 | if ( ret.x < boxWidth ) | |
2240 | ret.x = boxWidth; | |
2241 | ||
2242 | ret.y += other_border + top_border; | |
2243 | ||
2244 | return ret; | |
2245 | } | |
2246 | ||
2247 | void wxStaticBoxSizer::ShowItems( bool show ) | |
2248 | { | |
2249 | m_staticBox->Show( show ); | |
2250 | wxBoxSizer::ShowItems( show ); | |
2251 | } | |
2252 | ||
2253 | bool wxStaticBoxSizer::Detach( wxWindow *window ) | |
2254 | { | |
2255 | // avoid deleting m_staticBox in our dtor if it's being detached from the | |
2256 | // sizer (which can happen because it's being already destroyed for | |
2257 | // example) | |
2258 | if ( window == m_staticBox ) | |
2259 | { | |
2260 | m_staticBox = NULL; | |
2261 | return true; | |
2262 | } | |
2263 | ||
2264 | return wxSizer::Detach( window ); | |
2265 | } | |
2266 | ||
2267 | #endif // wxUSE_STATBOX | |
2268 | ||
2269 | //--------------------------------------------------------------------------- | |
2270 | // wxStdDialogButtonSizer | |
2271 | //--------------------------------------------------------------------------- | |
2272 | ||
2273 | #if wxUSE_BUTTON | |
2274 | ||
2275 | wxStdDialogButtonSizer::wxStdDialogButtonSizer() | |
2276 | : wxBoxSizer(wxHORIZONTAL) | |
2277 | { | |
2278 | // Vertical buttons with lots of space on either side | |
2279 | // looks rubbish on WinCE, so let's not do this for now. | |
2280 | // If we are going to use vertical buttons, we should | |
2281 | // put the sizer to the right of other controls in the dialog, | |
2282 | // and that's beyond the scope of this sizer. | |
2283 | #ifndef __WXWINCE__ | |
2284 | bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); | |
2285 | // If we have a PDA screen, put yes/no button over | |
2286 | // all other buttons, otherwise on the left side. | |
2287 | if (is_pda) | |
2288 | m_orient = wxVERTICAL; | |
2289 | #endif | |
2290 | ||
2291 | m_buttonAffirmative = NULL; | |
2292 | m_buttonApply = NULL; | |
2293 | m_buttonNegative = NULL; | |
2294 | m_buttonCancel = NULL; | |
2295 | m_buttonHelp = NULL; | |
2296 | } | |
2297 | ||
2298 | void wxStdDialogButtonSizer::AddButton(wxButton *mybutton) | |
2299 | { | |
2300 | switch (mybutton->GetId()) | |
2301 | { | |
2302 | case wxID_OK: | |
2303 | case wxID_YES: | |
2304 | case wxID_SAVE: | |
2305 | m_buttonAffirmative = mybutton; | |
2306 | break; | |
2307 | case wxID_APPLY: | |
2308 | m_buttonApply = mybutton; | |
2309 | break; | |
2310 | case wxID_NO: | |
2311 | m_buttonNegative = mybutton; | |
2312 | break; | |
2313 | case wxID_CANCEL: | |
2314 | case wxID_CLOSE: | |
2315 | m_buttonCancel = mybutton; | |
2316 | break; | |
2317 | case wxID_HELP: | |
2318 | case wxID_CONTEXT_HELP: | |
2319 | m_buttonHelp = mybutton; | |
2320 | break; | |
2321 | default: | |
2322 | break; | |
2323 | } | |
2324 | } | |
2325 | ||
2326 | void wxStdDialogButtonSizer::SetAffirmativeButton( wxButton *button ) | |
2327 | { | |
2328 | m_buttonAffirmative = button; | |
2329 | } | |
2330 | ||
2331 | void wxStdDialogButtonSizer::SetNegativeButton( wxButton *button ) | |
2332 | { | |
2333 | m_buttonNegative = button; | |
2334 | } | |
2335 | ||
2336 | void wxStdDialogButtonSizer::SetCancelButton( wxButton *button ) | |
2337 | { | |
2338 | m_buttonCancel = button; | |
2339 | } | |
2340 | ||
2341 | void wxStdDialogButtonSizer::Realize() | |
2342 | { | |
2343 | #ifdef __WXMAC__ | |
2344 | Add(0, 0, 0, wxLEFT, 6); | |
2345 | if (m_buttonHelp) | |
2346 | Add((wxWindow*)m_buttonHelp, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 6); | |
2347 | ||
2348 | if (m_buttonNegative){ | |
2349 | // HIG POLICE BULLETIN - destructive buttons need extra padding | |
2350 | // 24 pixels on either side | |
2351 | Add((wxWindow*)m_buttonNegative, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 12); | |
2352 | } | |
2353 | ||
2354 | // extra whitespace between help/negative and cancel/ok buttons | |
2355 | Add(0, 0, 1, wxEXPAND, 0); | |
2356 | ||
2357 | if (m_buttonCancel){ | |
2358 | Add((wxWindow*)m_buttonCancel, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 6); | |
2359 | // Cancel or help should be default | |
2360 | // m_buttonCancel->SetDefaultButton(); | |
2361 | } | |
2362 | ||
2363 | // Ugh, Mac doesn't really have apply dialogs, so I'll just | |
2364 | // figure the best place is between Cancel and OK | |
2365 | if (m_buttonApply) | |
2366 | Add((wxWindow*)m_buttonApply, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 6); | |
2367 | ||
2368 | if (m_buttonAffirmative){ | |
2369 | Add((wxWindow*)m_buttonAffirmative, 0, wxALIGN_CENTRE | wxLEFT, 6); | |
2370 | ||
2371 | if (m_buttonAffirmative->GetId() == wxID_SAVE){ | |
2372 | // these buttons have set labels under Mac so we should use them | |
2373 | m_buttonAffirmative->SetLabel(_("Save")); | |
2374 | if (m_buttonNegative) | |
2375 | m_buttonNegative->SetLabel(_("Don't Save")); | |
2376 | } | |
2377 | } | |
2378 | ||
2379 | // Extra space around and at the right | |
2380 | Add(12, 40); | |
2381 | #elif defined(__WXGTK20__) | |
2382 | Add(0, 0, 0, wxLEFT, 9); | |
2383 | if (m_buttonHelp) | |
2384 | Add((wxWindow*)m_buttonHelp, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 3); | |
2385 | ||
2386 | // extra whitespace between help and cancel/ok buttons | |
2387 | Add(0, 0, 1, wxEXPAND, 0); | |
2388 | ||
2389 | if (m_buttonNegative){ | |
2390 | Add((wxWindow*)m_buttonNegative, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 3); | |
2391 | } | |
2392 | ||
2393 | // according to HIG, in explicit apply windows the order is: | |
2394 | // [ Help Apply Cancel OK ] | |
2395 | if (m_buttonApply) | |
2396 | Add((wxWindow*)m_buttonApply, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 3); | |
2397 | ||
2398 | if (m_buttonCancel){ | |
2399 | Add((wxWindow*)m_buttonCancel, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 3); | |
2400 | // Cancel or help should be default | |
2401 | // m_buttonCancel->SetDefaultButton(); | |
2402 | } | |
2403 | ||
2404 | if (m_buttonAffirmative) | |
2405 | Add((wxWindow*)m_buttonAffirmative, 0, wxALIGN_CENTRE | wxLEFT, 6); | |
2406 | #elif defined(__WXMSW__) | |
2407 | // Windows | |
2408 | ||
2409 | // right-justify buttons | |
2410 | Add(0, 0, 1, wxEXPAND, 0); | |
2411 | ||
2412 | if (m_buttonAffirmative){ | |
2413 | Add((wxWindow*)m_buttonAffirmative, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonAffirmative->ConvertDialogToPixels(wxSize(2, 0)).x); | |
2414 | } | |
2415 | ||
2416 | if (m_buttonNegative){ | |
2417 | Add((wxWindow*)m_buttonNegative, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonNegative->ConvertDialogToPixels(wxSize(2, 0)).x); | |
2418 | } | |
2419 | ||
2420 | if (m_buttonCancel){ | |
2421 | Add((wxWindow*)m_buttonCancel, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonCancel->ConvertDialogToPixels(wxSize(2, 0)).x); | |
2422 | } | |
2423 | if (m_buttonApply) | |
2424 | Add((wxWindow*)m_buttonApply, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonApply->ConvertDialogToPixels(wxSize(2, 0)).x); | |
2425 | ||
2426 | if (m_buttonHelp) | |
2427 | Add((wxWindow*)m_buttonHelp, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonHelp->ConvertDialogToPixels(wxSize(2, 0)).x); | |
2428 | #else | |
2429 | // GTK+1 and any other platform | |
2430 | ||
2431 | // Add(0, 0, 0, wxLEFT, 5); // Not sure what this was for but it unbalances the dialog | |
2432 | if (m_buttonHelp) | |
2433 | Add((wxWindow*)m_buttonHelp, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonHelp->ConvertDialogToPixels(wxSize(4, 0)).x); | |
2434 | ||
2435 | // extra whitespace between help and cancel/ok buttons | |
2436 | Add(0, 0, 1, wxEXPAND, 0); | |
2437 | ||
2438 | if (m_buttonApply) | |
2439 | Add((wxWindow*)m_buttonApply, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonApply->ConvertDialogToPixels(wxSize(4, 0)).x); | |
2440 | ||
2441 | if (m_buttonAffirmative){ | |
2442 | Add((wxWindow*)m_buttonAffirmative, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonAffirmative->ConvertDialogToPixels(wxSize(4, 0)).x); | |
2443 | } | |
2444 | ||
2445 | if (m_buttonNegative){ | |
2446 | Add((wxWindow*)m_buttonNegative, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonNegative->ConvertDialogToPixels(wxSize(4, 0)).x); | |
2447 | } | |
2448 | ||
2449 | if (m_buttonCancel){ | |
2450 | Add((wxWindow*)m_buttonCancel, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, m_buttonCancel->ConvertDialogToPixels(wxSize(4, 0)).x); | |
2451 | // Cancel or help should be default | |
2452 | // m_buttonCancel->SetDefaultButton(); | |
2453 | } | |
2454 | ||
2455 | #endif | |
2456 | } | |
2457 | ||
2458 | #endif // wxUSE_BUTTON |