]> git.saurik.com Git - wxWidgets.git/blame - src/common/gbsizer.cpp
No changes, just get rid of some wxT()s in wxString unit test.
[wxWidgets.git] / src / common / gbsizer.cpp
CommitLineData
20b35a69 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/common/gbsizer.cpp
20b35a69
RD
3// Purpose: wxGridBagSizer: A sizer that can lay out items in a grid,
4// with items at specified cells, and with the option of row
5// and/or column spanning
6//
7// Author: Robin Dunn
8// Created: 03-Nov-2003
9// RCS-ID: $Id$
10// Copyright: (c) Robin Dunn
65571936 11// Licence: wxWindows licence
20b35a69
RD
12/////////////////////////////////////////////////////////////////////////////
13
20b35a69
RD
14// For compilers that support precompilation, includes "wx.h".
15#include "wx/wxprec.h"
16
17#ifdef __BORLANDC__
18 #pragma hdrstop
19#endif
20
21#include "wx/gbsizer.h"
22
23//---------------------------------------------------------------------------
24
1b52f7ab 25IMPLEMENT_DYNAMIC_CLASS(wxGBSizerItem, wxSizerItem)
20b35a69
RD
26IMPLEMENT_CLASS(wxGridBagSizer, wxFlexGridSizer)
27
28const wxGBSpan wxDefaultSpan;
29
30//---------------------------------------------------------------------------
31// wxGBSizerItem
32//---------------------------------------------------------------------------
33
34wxGBSizerItem::wxGBSizerItem( int width,
35 int height,
36 const wxGBPosition& pos,
37 const wxGBSpan& span,
38 int flag,
39 int border,
40 wxObject* userData)
41 : wxSizerItem(width, height, 0, flag, border, userData),
42 m_pos(pos),
43 m_span(span),
3ff632ce 44 m_gbsizer(NULL)
20b35a69
RD
45{
46}
47
48
49wxGBSizerItem::wxGBSizerItem( wxWindow *window,
50 const wxGBPosition& pos,
51 const wxGBSpan& span,
52 int flag,
53 int border,
54 wxObject* userData )
55 : wxSizerItem(window, 0, flag, border, userData),
56 m_pos(pos),
57 m_span(span),
3ff632ce 58 m_gbsizer(NULL)
20b35a69
RD
59{
60}
61
62
63wxGBSizerItem::wxGBSizerItem( wxSizer *sizer,
64 const wxGBPosition& pos,
65 const wxGBSpan& span,
66 int flag,
67 int border,
68 wxObject* userData )
69 : wxSizerItem(sizer, 0, flag, border, userData),
70 m_pos(pos),
71 m_span(span),
3ff632ce 72 m_gbsizer(NULL)
20b35a69
RD
73{
74}
75
1b52f7ab
RD
76wxGBSizerItem::wxGBSizerItem()
77 : wxSizerItem(),
78 m_pos(-1,-1),
3ff632ce 79 m_gbsizer(NULL)
1b52f7ab
RD
80{
81}
20b35a69
RD
82
83//---------------------------------------------------------------------------
84
85
86void wxGBSizerItem::GetPos(int& row, int& col) const
87{
88 row = m_pos.GetRow();
89 col = m_pos.GetCol();
90}
91
92void wxGBSizerItem::GetSpan(int& rowspan, int& colspan) const
93{
94 rowspan = m_span.GetRowspan();
95 colspan = m_span.GetColspan();
96}
97
98
99bool wxGBSizerItem::SetPos( const wxGBPosition& pos )
100{
3ff632ce 101 if (m_gbsizer)
20b35a69 102 {
3ff632ce 103 wxCHECK_MSG( !m_gbsizer->CheckForIntersection(pos, m_span, this), false,
20b35a69
RD
104 wxT("An item is already at that position") );
105 }
106 m_pos = pos;
107 return true;
108}
109
110bool wxGBSizerItem::SetSpan( const wxGBSpan& span )
111{
3ff632ce 112 if (m_gbsizer)
20b35a69 113 {
3ff632ce 114 wxCHECK_MSG( !m_gbsizer->CheckForIntersection(m_pos, span, this), false,
20b35a69
RD
115 wxT("An item is already at that position") );
116 }
117 m_span = span;
118 return true;
119}
120
121
122inline bool InRange(int val, int min, int max)
123{
124 return (val >= min && val <= max);
125}
126
127bool wxGBSizerItem::Intersects(const wxGBSizerItem& other)
128{
129 return Intersects(other.GetPos(), other.GetSpan());
130}
131
132bool wxGBSizerItem::Intersects(const wxGBPosition& pos, const wxGBSpan& span)
133{
134
135 int row, col, endrow, endcol;
136 int otherrow, othercol, otherendrow, otherendcol;
137
138 GetPos(row, col);
139 GetEndPos(endrow, endcol);
140
141 otherrow = pos.GetRow();
142 othercol = pos.GetCol();
143 otherendrow = otherrow + span.GetRowspan() - 1;
144 otherendcol = othercol + span.GetColspan() - 1;
145
146 // is the other item's start or end in the range of this one?
147 if (( InRange(otherrow, row, endrow) && InRange(othercol, col, endcol) ) ||
148 ( InRange(otherendrow, row, endrow) && InRange(otherendcol, col, endcol) ))
149 return true;
150
151 // is this item's start or end in the range of the other one?
152 if (( InRange(row, otherrow, otherendrow) && InRange(col, othercol, otherendcol) ) ||
153 ( InRange(endrow, otherrow, otherendrow) && InRange(endcol, othercol, otherendcol) ))
154 return true;
155
156 return false;
157}
158
159
160void wxGBSizerItem::GetEndPos(int& row, int& col)
161{
162 row = m_pos.GetRow() + m_span.GetRowspan() - 1;
163 col = m_pos.GetCol() + m_span.GetColspan() - 1;
164}
165
166
167//---------------------------------------------------------------------------
168// wxGridBagSizer
169//---------------------------------------------------------------------------
170
171wxGridBagSizer::wxGridBagSizer(int vgap, int hgap )
172 : wxFlexGridSizer(1, vgap, hgap),
173 m_emptyCellSize(10,20)
5d3e7b52 174
20b35a69
RD
175{
176}
177
178
56eee37f
WS
179wxSizerItem* wxGridBagSizer::Add( wxWindow *window,
180 const wxGBPosition& pos, const wxGBSpan& span,
181 int flag, int border, wxObject* userData )
20b35a69
RD
182{
183 wxGBSizerItem* item = new wxGBSizerItem(window, pos, span, flag, border, userData);
184 if ( Add(item) )
56eee37f 185 return item;
20b35a69
RD
186 else
187 {
188 delete item;
d3b9f782 189 return NULL;
20b35a69
RD
190 }
191}
192
56eee37f 193wxSizerItem* wxGridBagSizer::Add( wxSizer *sizer,
20b35a69
RD
194 const wxGBPosition& pos, const wxGBSpan& span,
195 int flag, int border, wxObject* userData )
196{
197 wxGBSizerItem* item = new wxGBSizerItem(sizer, pos, span, flag, border, userData);
198 if ( Add(item) )
56eee37f 199 return item;
20b35a69
RD
200 else
201 {
202 delete item;
d3b9f782 203 return NULL;
20b35a69
RD
204 }
205}
206
56eee37f 207wxSizerItem* wxGridBagSizer::Add( int width, int height,
20b35a69
RD
208 const wxGBPosition& pos, const wxGBSpan& span,
209 int flag, int border, wxObject* userData )
210{
211 wxGBSizerItem* item = new wxGBSizerItem(width, height, pos, span, flag, border, userData);
212 if ( Add(item) )
56eee37f 213 return item;
20b35a69
RD
214 else
215 {
216 delete item;
d3b9f782 217 return NULL;
20b35a69
RD
218 }
219}
220
56eee37f 221wxSizerItem* wxGridBagSizer::Add( wxGBSizerItem *item )
20b35a69 222{
56eee37f 223 wxCHECK_MSG( !CheckForIntersection(item), NULL,
3ff632ce
RD
224 wxT("An item is already at that position") );
225 m_children.Append(item);
226 item->SetGBSizer(this);
20b35a69
RD
227 if ( item->GetWindow() )
228 item->GetWindow()->SetContainingSizer( this );
229
47676835
VZ
230 // extend the number of rows/columns of the underlying wxFlexGridSizer if
231 // necessary
232 int row, col;
233 item->GetEndPos(row, col);
234 row++;
235 col++;
236
237 if ( row > GetRows() )
238 SetRows(row);
239 if ( col > GetCols() )
240 SetCols(col);
241
56eee37f 242 return item;
20b35a69
RD
243}
244
245
246
247//---------------------------------------------------------------------------
248
6217b9aa
RD
249wxSize wxGridBagSizer::GetCellSize(int row, int col) const
250{
251 wxCHECK_MSG( (row < m_rows) && (col < m_cols),
252 wxDefaultSize,
253 wxT("Invalid cell."));
254 return wxSize( m_colWidths[col], m_rowHeights[row] );
255}
256
257
20b35a69
RD
258wxGBPosition wxGridBagSizer::GetItemPosition(wxWindow *window)
259{
260 wxGBPosition badpos(-1,-1);
261 wxGBSizerItem* item = FindItem(window);
262 wxCHECK_MSG(item, badpos, wxT("Failed to find item."));
263 return item->GetPos();
264}
265
266
267wxGBPosition wxGridBagSizer::GetItemPosition(wxSizer *sizer)
268{
269 wxGBPosition badpos(-1,-1);
270 wxGBSizerItem* item = FindItem(sizer);
271 wxCHECK_MSG(item, badpos, wxT("Failed to find item."));
272 return item->GetPos();
273}
274
275
276wxGBPosition wxGridBagSizer::GetItemPosition(size_t index)
277{
278 wxGBPosition badpos(-1,-1);
279 wxSizerItemList::compatibility_iterator node = m_children.Item( index );
9a83f860 280 wxCHECK_MSG( node, badpos, wxT("Failed to find item.") );
5d3e7b52 281 wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
20b35a69
RD
282 return item->GetPos();
283}
284
285
286
287bool wxGridBagSizer::SetItemPosition(wxWindow *window, const wxGBPosition& pos)
288{
289 wxGBSizerItem* item = FindItem(window);
290 wxCHECK_MSG(item, false, wxT("Failed to find item."));
291 return item->SetPos(pos);
292}
293
294
295bool wxGridBagSizer::SetItemPosition(wxSizer *sizer, const wxGBPosition& pos)
296{
297 wxGBSizerItem* item = FindItem(sizer);
298 wxCHECK_MSG(item, false, wxT("Failed to find item."));
299 return item->SetPos(pos);
300}
301
302
303bool wxGridBagSizer::SetItemPosition(size_t index, const wxGBPosition& pos)
304{
305 wxSizerItemList::compatibility_iterator node = m_children.Item( index );
9a83f860 306 wxCHECK_MSG( node, false, wxT("Failed to find item.") );
5d3e7b52 307 wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
20b35a69
RD
308 return item->SetPos(pos);
309}
310
311
312
313wxGBSpan wxGridBagSizer::GetItemSpan(wxWindow *window)
314{
20b35a69 315 wxGBSizerItem* item = FindItem(window);
46e2a1b8 316 wxCHECK_MSG( item, wxGBSpan::Invalid(), wxT("Failed to find item.") );
20b35a69
RD
317 return item->GetSpan();
318}
319
320
321wxGBSpan wxGridBagSizer::GetItemSpan(wxSizer *sizer)
322{
20b35a69 323 wxGBSizerItem* item = FindItem(sizer);
46e2a1b8 324 wxCHECK_MSG( item, wxGBSpan::Invalid(), wxT("Failed to find item.") );
20b35a69
RD
325 return item->GetSpan();
326}
327
328
329wxGBSpan wxGridBagSizer::GetItemSpan(size_t index)
330{
20b35a69 331 wxSizerItemList::compatibility_iterator node = m_children.Item( index );
46e2a1b8 332 wxCHECK_MSG( node, wxGBSpan::Invalid(), wxT("Failed to find item.") );
5d3e7b52 333 wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
20b35a69
RD
334 return item->GetSpan();
335}
336
337
338
339bool wxGridBagSizer::SetItemSpan(wxWindow *window, const wxGBSpan& span)
340{
341 wxGBSizerItem* item = FindItem(window);
342 wxCHECK_MSG(item, false, wxT("Failed to find item."));
343 return item->SetSpan(span);
344}
345
346
347bool wxGridBagSizer::SetItemSpan(wxSizer *sizer, const wxGBSpan& span)
348{
349 wxGBSizerItem* item = FindItem(sizer);
350 wxCHECK_MSG(item, false, wxT("Failed to find item."));
351 return item->SetSpan(span);
352}
353
354
355bool wxGridBagSizer::SetItemSpan(size_t index, const wxGBSpan& span)
356{
357 wxSizerItemList::compatibility_iterator node = m_children.Item( index );
9a83f860 358 wxCHECK_MSG( node, false, wxT("Failed to find item.") );
5d3e7b52 359 wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
20b35a69
RD
360 return item->SetSpan(span);
361}
362
363
364
365
366wxGBSizerItem* wxGridBagSizer::FindItem(wxWindow* window)
367{
368 wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
369 while (node)
370 {
371 wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
372 if ( item->GetWindow() == window )
373 return item;
374 node = node->GetNext();
375 }
376 return NULL;
377}
378
379
380wxGBSizerItem* wxGridBagSizer::FindItem(wxSizer* sizer)
381{
382 wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
383 while (node)
384 {
385 wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
386 if ( item->GetSizer() == sizer )
387 return item;
388 node = node->GetNext();
389 }
390 return NULL;
391}
392
393
394
395
396wxGBSizerItem* wxGridBagSizer::FindItemAtPosition(const wxGBPosition& pos)
397{
398 wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
399 while (node)
400 {
401 wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
402 if ( item->Intersects(pos, wxDefaultSpan) )
403 return item;
404 node = node->GetNext();
405 }
406 return NULL;
407}
408
409
410
411
3ac7b44c
RD
412wxGBSizerItem* wxGridBagSizer::FindItemAtPoint(const wxPoint& pt)
413{
414 wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
415 while (node)
416 {
417 wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
418 wxRect rect(item->GetPosition(), item->GetSize());
419 rect.Inflate(m_hgap, m_vgap);
22a35096 420 if ( rect.Contains(pt) )
3ac7b44c
RD
421 return item;
422 node = node->GetNext();
423 }
424 return NULL;
425}
426
427
428
429
20b35a69
RD
430wxGBSizerItem* wxGridBagSizer::FindItemWithData(const wxObject* userData)
431{
432 wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
433 while (node)
434 {
435 wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
436 if ( item->GetUserData() == userData )
437 return item;
438 node = node->GetNext();
439 }
440 return NULL;
441}
442
443
444
445
446//---------------------------------------------------------------------------
447
448// Figure out what all the min row heights and col widths are, and calculate
449// min size from that.
450wxSize wxGridBagSizer::CalcMin()
451{
452 int idx;
5d3e7b52 453
20b35a69
RD
454 if (m_children.GetCount() == 0)
455 return m_emptyCellSize;
456
457 m_rowHeights.Empty();
458 m_colWidths.Empty();
459
460 wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
461 while (node)
462 {
463 wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
464 if ( item->IsShown() )
465 {
466 int row, col, endrow, endcol;
5d3e7b52 467
20b35a69
RD
468 item->GetPos(row, col);
469 item->GetEndPos(endrow, endcol);
470
25e3f0c6 471 // fill heights and widths up to this item if needed
16c7d85b 472 while ( (int)m_rowHeights.GetCount() <= endrow )
20b35a69 473 m_rowHeights.Add(m_emptyCellSize.GetHeight());
16c7d85b 474 while ( (int)m_colWidths.GetCount() <= endcol )
20b35a69
RD
475 m_colWidths.Add(m_emptyCellSize.GetWidth());
476
477 // See if this item increases the size of its row(s) or col(s)
478 wxSize size(item->CalcMin());
479 for (idx=row; idx <= endrow; idx++)
480 m_rowHeights[idx] = wxMax(m_rowHeights[idx], size.GetHeight() / (endrow-row+1));
481 for (idx=col; idx <= endcol; idx++)
482 m_colWidths[idx] = wxMax(m_colWidths[idx], size.GetWidth() / (endcol-col+1));
483 }
484 node = node->GetNext();
485 }
486
6a079bc1 487 AdjustForOverflow();
20b35a69
RD
488 AdjustForFlexDirection();
489
490 // Now traverse the heights and widths arrays calcing the totals, including gaps
491 int width = 0;
6217b9aa
RD
492 m_cols = m_colWidths.GetCount();
493 for (idx=0; idx < m_cols; idx++)
494 width += m_colWidths[idx] + ( idx == m_cols-1 ? 0 : m_hgap );
20b35a69
RD
495
496 int height = 0;
6217b9aa
RD
497 m_rows = m_rowHeights.GetCount();
498 for (idx=0; idx < m_rows; idx++)
499 height += m_rowHeights[idx] + ( idx == m_rows-1 ? 0 : m_vgap );
20b35a69 500
ba763a45
RD
501 m_calculatedMinSize = wxSize(width, height);
502 return m_calculatedMinSize;
20b35a69
RD
503}
504
505
506
507void wxGridBagSizer::RecalcSizes()
508{
509 if (m_children.GetCount() == 0)
510 return;
511
20b35a69
RD
512 wxPoint pt( GetPosition() );
513 wxSize sz( GetSize() );
5d3e7b52 514
6217b9aa
RD
515 m_rows = m_rowHeights.GetCount();
516 m_cols = m_colWidths.GetCount();
20b35a69
RD
517 int idx, width, height;
518
3b170aa8 519 AdjustForGrowables(sz);
20b35a69
RD
520
521 // Find the start positions on the window of the rows and columns
522 wxArrayInt rowpos;
6217b9aa 523 rowpos.Add(0, m_rows);
20b35a69 524 int y = pt.y;
6217b9aa 525 for (idx=0; idx < m_rows; idx++)
20b35a69
RD
526 {
527 height = m_rowHeights[idx] + m_vgap;
528 rowpos[idx] = y;
529 y += height;
530 }
531
532 wxArrayInt colpos;
6217b9aa 533 colpos.Add(0, m_cols);
20b35a69 534 int x = pt.x;
6217b9aa 535 for (idx=0; idx < m_cols; idx++)
20b35a69
RD
536 {
537 width = m_colWidths[idx] + m_hgap;
538 colpos[idx] = x;
539 x += width;
540 }
541
542
543 // Now iterate the children, setting each child's dimensions
544 wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
545 while (node)
546 {
547 int row, col, endrow, endcol;
548 wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
20b35a69 549
af579c91
RD
550 if ( item->IsShown() )
551 {
552 item->GetPos(row, col);
553 item->GetEndPos(endrow, endcol);
5d3e7b52 554
af579c91
RD
555 height = 0;
556 for(idx=row; idx <= endrow; idx++)
557 height += m_rowHeights[idx];
558 height += (endrow - row) * m_vgap; // add a vgap for every row spanned
5d3e7b52 559
af579c91
RD
560 width = 0;
561 for (idx=col; idx <= endcol; idx++)
562 width += m_colWidths[idx];
563 width += (endcol - col) * m_hgap; // add a hgap for every col spanned
564
565 SetItemBounds(item, colpos[col], rowpos[row], width, height);
566 }
20b35a69
RD
567
568 node = node->GetNext();
5d3e7b52 569 }
20b35a69
RD
570}
571
572
6a079bc1
RD
573// Sometimes CalcMin can result in some rows or cols having too much space in
574// them because as it traverses the items it makes some assumptions when
575// items span to other cells. But those assumptions can become invalid later
576// on when other items are fitted into the same rows or columns that the
577// spanning item occupies. This method tries to find those situations and
578// fixes them.
579void wxGridBagSizer::AdjustForOverflow()
580{
581 int row, col;
03647350 582
53524ca0 583 for (row=0; row<(int)m_rowHeights.GetCount(); row++)
6a079bc1
RD
584 {
585 int rowExtra=INT_MAX;
586 int rowHeight = m_rowHeights[row];
53524ca0 587 for (col=0; col<(int)m_colWidths.GetCount(); col++)
6a079bc1
RD
588 {
589 wxGBPosition pos(row,col);
590 wxGBSizerItem* item = FindItemAtPosition(pos);
bbb51766 591 if ( !item || !item->IsShown() )
6a079bc1
RD
592 continue;
593
594 int endrow, endcol;
595 item->GetEndPos(endrow, endcol);
03647350 596
6a079bc1
RD
597 // If the item starts in this position and doesn't span rows, then
598 // just look at the whole item height
599 if ( item->GetPos() == pos && endrow == row )
600 {
72da4057 601 int itemHeight = item->CalcMin().GetHeight();
6a079bc1
RD
602 rowExtra = wxMin(rowExtra, rowHeight - itemHeight);
603 continue;
604 }
605
606 // Otherwise, only look at spanning items if they end on this row
607 if ( endrow == row )
608 {
609 // first deduct the portions of the item that are on prior rows
72da4057 610 int itemHeight = item->CalcMin().GetHeight();
6a079bc1
RD
611 for (int r=item->GetPos().GetRow(); r<row; r++)
612 itemHeight -= (m_rowHeights[r] + GetHGap());
613
614 if ( itemHeight < 0 )
615 itemHeight = 0;
03647350 616
6a079bc1
RD
617 // and check how much is left
618 rowExtra = wxMin(rowExtra, rowHeight - itemHeight);
619 }
620 }
621 if ( rowExtra && rowExtra != INT_MAX )
622 m_rowHeights[row] -= rowExtra;
623 }
624
625 // Now do the same thing for columns
53524ca0 626 for (col=0; col<(int)m_colWidths.GetCount(); col++)
6a079bc1
RD
627 {
628 int colExtra=INT_MAX;
629 int colWidth = m_colWidths[col];
53524ca0 630 for (row=0; row<(int)m_rowHeights.GetCount(); row++)
6a079bc1
RD
631 {
632 wxGBPosition pos(row,col);
633 wxGBSizerItem* item = FindItemAtPosition(pos);
bbb51766 634 if ( !item || !item->IsShown() )
6a079bc1
RD
635 continue;
636
637 int endrow, endcol;
638 item->GetEndPos(endrow, endcol);
03647350 639
6a079bc1
RD
640 if ( item->GetPos() == pos && endcol == col )
641 {
72da4057 642 int itemWidth = item->CalcMin().GetWidth();
6a079bc1
RD
643 colExtra = wxMin(colExtra, colWidth - itemWidth);
644 continue;
645 }
646
647 if ( endcol == col )
648 {
72da4057 649 int itemWidth = item->CalcMin().GetWidth();
6a079bc1
RD
650 for (int c=item->GetPos().GetCol(); c<col; c++)
651 itemWidth -= (m_colWidths[c] + GetVGap());
652
653 if ( itemWidth < 0 )
654 itemWidth = 0;
03647350 655
6a079bc1
RD
656 colExtra = wxMin(colExtra, colWidth - itemWidth);
657 }
658 }
659 if ( colExtra && colExtra != INT_MAX )
660 m_colWidths[col] -= colExtra;
661 }
662
03647350 663
6a079bc1 664}
20b35a69
RD
665
666//---------------------------------------------------------------------------
667
668bool wxGridBagSizer::CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem)
669{
670 return CheckForIntersection(item->GetPos(), item->GetSpan(), excludeItem);
671}
672
673bool wxGridBagSizer::CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem)
674{
675 wxSizerItemList::compatibility_iterator node = m_children.GetFirst();
676 while (node)
677 {
678 wxGBSizerItem* item = (wxGBSizerItem*)node->GetData();
679 node = node->GetNext();
680
681 if ( excludeItem && item == excludeItem )
682 continue;
5d3e7b52 683
20b35a69
RD
684 if ( item->Intersects(pos, span) )
685 return true;
686
687 }
688 return false;
689}
690
691
692// Assumes a 10x10 grid, and returns the first empty cell found. This is
693// really stupid but it is only used by the Add methods that match the base
694// class virtuals, which should normally not be used anyway...
695wxGBPosition wxGridBagSizer::FindEmptyCell()
696{
697 int row, col;
698
699 for (row=0; row<10; row++)
700 for (col=0; col<10; col++)
701 {
702 wxGBPosition pos(row, col);
703 if ( !CheckForIntersection(pos, wxDefaultSpan) )
704 return pos;
705 }
706 return wxGBPosition(-1, -1);
707}
708
709
710//---------------------------------------------------------------------------
711
712// The Add base class virtuals should not be used with this class, but
713// we'll try to make them automatically select a location for the item
714// anyway.
715
56eee37f 716wxSizerItem* wxGridBagSizer::Add( wxWindow *window, int, int flag, int border, wxObject* userData )
20b35a69 717{
56eee37f 718 return Add(window, FindEmptyCell(), wxDefaultSpan, flag, border, userData);
20b35a69
RD
719}
720
56eee37f 721wxSizerItem* wxGridBagSizer::Add( wxSizer *sizer, int, int flag, int border, wxObject* userData )
20b35a69 722{
56eee37f 723 return Add(sizer, FindEmptyCell(), wxDefaultSpan, flag, border, userData);
20b35a69
RD
724}
725
56eee37f 726wxSizerItem* wxGridBagSizer::Add( int width, int height, int, int flag, int border, wxObject* userData )
20b35a69 727{
56eee37f 728 return Add(width, height, FindEmptyCell(), wxDefaultSpan, flag, border, userData);
20b35a69
RD
729}
730
731
732
733// The Insert nad Prepend base class virtuals that are not appropriate for
734// this class and should not be used. Their implementation in this class
735// simply fails.
736
56eee37f
WS
737wxSizerItem* wxGridBagSizer::Add( wxSizerItem * )
738{
739 wxFAIL_MSG(wxT("Invalid Add form called."));
d3b9f782 740 return NULL;
56eee37f 741}
20b35a69 742
56eee37f
WS
743wxSizerItem* wxGridBagSizer::Prepend( wxWindow *, int, int, int, wxObject* )
744{
745 wxFAIL_MSG(wxT("Prepend should not be used with wxGridBagSizer."));
d3b9f782 746 return NULL;
56eee37f 747}
20b35a69 748
56eee37f
WS
749wxSizerItem* wxGridBagSizer::Prepend( wxSizer *, int, int, int, wxObject* )
750{
751 wxFAIL_MSG(wxT("Prepend should not be used with wxGridBagSizer."));
d3b9f782 752 return NULL;
56eee37f 753}
20b35a69 754
56eee37f
WS
755wxSizerItem* wxGridBagSizer::Prepend( int, int, int, int, int, wxObject* )
756{
757 wxFAIL_MSG(wxT("Prepend should not be used with wxGridBagSizer."));
d3b9f782 758 return NULL;
56eee37f 759}
20b35a69 760
56eee37f
WS
761wxSizerItem* wxGridBagSizer::Prepend( wxSizerItem * )
762{
763 wxFAIL_MSG(wxT("Prepend should not be used with wxGridBagSizer."));
d3b9f782 764 return NULL;
56eee37f 765}
20b35a69
RD
766
767
56eee37f
WS
768wxSizerItem* wxGridBagSizer::Insert( size_t, wxWindow *, int, int, int, wxObject* )
769{
770 wxFAIL_MSG(wxT("Insert should not be used with wxGridBagSizer."));
d3b9f782 771 return NULL;
56eee37f 772}
20b35a69 773
56eee37f
WS
774wxSizerItem* wxGridBagSizer::Insert( size_t, wxSizer *, int, int, int, wxObject* )
775{
776 wxFAIL_MSG(wxT("Insert should not be used with wxGridBagSizer."));
d3b9f782 777 return NULL;
56eee37f 778}
20b35a69 779
56eee37f
WS
780wxSizerItem* wxGridBagSizer::Insert( size_t, int, int, int, int, int, wxObject* )
781{
782 wxFAIL_MSG(wxT("Insert should not be used with wxGridBagSizer."));
d3b9f782 783 return NULL;
56eee37f 784}
20b35a69 785
56eee37f
WS
786wxSizerItem* wxGridBagSizer::Insert( size_t, wxSizerItem * )
787{
788 wxFAIL_MSG(wxT("Insert should not be used with wxGridBagSizer."));
d3b9f782 789 return NULL;
56eee37f 790}
20b35a69
RD
791
792
793//---------------------------------------------------------------------------
794//---------------------------------------------------------------------------