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