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