Added class to handle selection inside wxGrid
[wxWidgets.git] / src / generic / gridsel.cpp
1 ///////////////////////////////////////////////////////////////////////////
2 // Name: generic/gridsel.cpp
3 // Purpose: wxGridSelection
4 // Author: Stefan Neis
5 // Modified by:
6 // Created: 20/02/1999
7 // RCS-ID: $$
8 // Copyright: (c) Stefan Neis (Stefan.Neis@t-online.de)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "gridsel.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx/wx.h".
25 #include "wx/wxprec.h"
26
27 #include "wx/defs.h"
28
29 #ifdef __BORLANDC__
30 #pragma hdrstop
31 #endif
32
33 #include "wx/generic/gridsel.h"
34
35 wxGridSelection::wxGridSelection( wxGrid * grid,
36 wxGridSelection::wxGridSelectionModes sel )
37 {
38 m_grid = grid;
39 m_selectionMode = sel;
40 }
41
42 bool wxGridSelection::IsSelection()
43 {
44 return ( m_cellSelection.GetCount() || m_blockSelectionTopLeft.GetCount() ||
45 m_rowSelection.GetCount() || m_colSelection.GetCount() );
46 }
47
48 bool wxGridSelection::IsInSelection ( int row, int col )
49 {
50 size_t count;
51 if ( m_selectionMode != wxGridSelection::wxGridSelectRows &&
52 m_selectionMode != wxGridSelection::wxGridSelectColumns )
53 {
54 count = m_cellSelection.GetCount();
55 for ( size_t n = 0; n < count; n++ )
56 {
57 wxGridCellCoords& coords = m_cellSelection[n];
58 if ( row == coords.GetRow() && col == coords.GetCol() )
59 return true;
60 }
61 }
62 count = m_blockSelectionTopLeft.GetCount();
63 for ( size_t n = 0; n < count; n++ )
64 {
65 wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
66 wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
67 if ( BlockContainsCell(coords1.GetRow(), coords1.GetCol(),
68 coords2.GetRow(), coords2.GetCol(),
69 row, col ) )
70 return true;
71 }
72 if ( m_selectionMode != wxGridSelection::wxGridSelectColumns )
73 {
74 size_t count = m_rowSelection.GetCount();
75 for ( size_t n = 0; n < count; n++ )
76 {
77 if ( row == m_rowSelection[n] )
78 return true;
79 }
80 }
81 if ( m_selectionMode != wxGridSelection::wxGridSelectRows )
82 {
83 size_t count = m_colSelection.GetCount();
84 for ( size_t n = 0; n < count; n++ )
85 {
86 if ( col == m_colSelection[n] )
87 return true;
88 }
89 }
90 return false;
91 }
92
93 void wxGridSelection::SelectRow( int row, bool addToSelected = FALSE )
94 {
95 if ( m_selectionMode == wxGridSelection::wxGridSelectColumns )
96 return;
97 size_t count;
98
99 // Remove single cells contained in newly selected block.
100 if ( m_selectionMode != wxGridSelection::wxGridSelectRows &&
101 m_selectionMode != wxGridSelection::wxGridSelectColumns )
102 {
103 count = m_cellSelection.GetCount();
104 for ( size_t n = 0; n < count; n++ )
105 {
106 wxGridCellCoords& coords = m_cellSelection[n];
107 if ( BlockContainsCell( row, 0, row, m_grid->GetNumberCols() - 1,
108 coords.GetRow(), coords.GetCol() ) )
109 {
110 m_cellSelection.RemoveAt(n);
111 n--; count--;
112 }
113 }
114 }
115
116 // If possible, merge row with existing selected block
117 count = m_blockSelectionTopLeft.GetCount();
118 for ( size_t n = 0; n < count; n++ )
119 {
120 wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
121 wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
122 if ( coords1.GetRow() == row && row == coords2.GetRow() )
123 {
124 m_blockSelectionTopLeft.RemoveAt(n);
125 m_blockSelectionBottomRight.RemoveAt(n);
126 n--; count--;
127 }
128 else if ( coords1.GetCol() == 0 &&
129 coords2.GetCol() == m_grid->GetNumberCols() - 1 )
130 {
131 if ( coords1.GetRow() <= row && row <= coords2.GetRow() )
132 return;
133 else if ( coords1.GetRow() == row + 1)
134 {
135 coords1.SetRow(row);
136 return;
137 }
138 else if ( coords2.GetRow() == row - 1)
139 {
140 coords2.SetRow(row);
141 return;
142 }
143 }
144 }
145
146 // Check whether row is already selected.
147 count = m_rowSelection.GetCount();
148 for ( size_t n = 0; n < count; n++ )
149 {
150 if ( row == m_rowSelection[n] )
151 return;
152 }
153
154 // Add row to selection
155 m_rowSelection.Add(row);
156 }
157
158 void wxGridSelection::SelectCol( int col, bool addToSelected = FALSE )
159 {
160 if ( m_selectionMode == wxGridSelection::wxGridSelectRows )
161 return;
162 size_t count;
163
164 // Remove single cells contained in newly selected block.
165 if ( m_selectionMode != wxGridSelection::wxGridSelectRows &&
166 m_selectionMode != wxGridSelection::wxGridSelectColumns )
167 {
168 count = m_cellSelection.GetCount();
169 for ( size_t n = 0; n < count; n++ )
170 {
171 wxGridCellCoords& coords = m_cellSelection[n];
172 if ( BlockContainsCell( 0, col, m_grid->GetNumberRows() - 1, col,
173 coords.GetRow(), coords.GetCol() ) )
174 {
175 m_cellSelection.RemoveAt(n);
176 n--; count--;
177 }
178 }
179 }
180
181 // If possible, merge col with existing selected block
182 count = m_blockSelectionTopLeft.GetCount();
183 for ( size_t n = 0; n < count; n++ )
184 {
185 wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
186 wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
187 if ( coords1.GetCol() == col && col == coords2.GetCol() )
188 {
189 m_blockSelectionTopLeft.RemoveAt(n);
190 m_blockSelectionBottomRight.RemoveAt(n);
191 n--; count--;
192 }
193 else if ( coords1.GetRow() == 0 &&
194 coords2.GetRow() == m_grid->GetNumberRows() - 1 )
195 {
196 if ( coords1.GetCol() <= col && col <= coords2.GetCol() )
197 return;
198 else if ( coords1.GetCol() == col + 1)
199 {
200 coords1.SetCol(col);
201 return;
202 }
203 else if ( coords2.GetCol() == col - 1)
204 {
205 coords2.SetCol(col);
206 return;
207 }
208 }
209 }
210
211 // Check whether col is already selected.
212 count = m_colSelection.GetCount();
213 for ( size_t n = 0; n < count; n++ )
214 {
215 if ( col == m_colSelection[n] )
216 return;
217 }
218
219 // Add col to selection
220 m_colSelection.Add(col);
221 }
222
223 void wxGridSelection::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol )
224 {
225 // Fix the coordinates of the block if potentially needed
226 if ( m_selectionMode == wxGridSelection::wxGridSelectRows )
227 {
228 leftCol = 0;
229 rightCol = m_grid->GetNumberCols() - 1;
230 }
231 else if ( m_selectionMode == wxGridSelection::wxGridSelectColumns )
232 {
233 topRow = 0;
234 bottomRow = m_grid->GetNumberRows() - 1;
235 }
236
237 // Handle single cell selection in SelectCell.
238 if ( topRow == bottomRow && leftCol == rightCol )
239 SelectCell( topRow, leftCol );
240
241 size_t count;
242 // Remove single cells contained in newly selected block.
243 if ( m_selectionMode != wxGridSelection::wxGridSelectRows &&
244 m_selectionMode != wxGridSelection::wxGridSelectColumns )
245 {
246 count = m_cellSelection.GetCount();
247 for ( size_t n = 0; n < count; n++ )
248 {
249 wxGridCellCoords& coords = m_cellSelection[n];
250 if ( BlockContainsCell( topRow, leftCol, bottomRow, rightCol,
251 coords.GetRow(), coords.GetCol() ) )
252 {
253 m_cellSelection.RemoveAt(n);
254 n--; count--;
255 }
256 }
257 }
258
259 // If a block containing the selection is already selected, return,
260 // if a block contained in the selection is found, remove it.
261
262 count = m_blockSelectionTopLeft.GetCount();
263 for ( size_t n = 0; n < count; n++ )
264 {
265 wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
266 wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
267 switch ( BlockContain( coords1.GetRow(), coords1.GetCol(),
268 coords2.GetRow(), coords2.GetCol(),
269 topRow, leftCol, bottomRow, rightCol ) )
270 {
271 case 1:
272 return;
273 case -1:
274 m_blockSelectionTopLeft.RemoveAt(n);
275 m_blockSelectionBottomRight.RemoveAt(n);
276 n--; count--;
277 default:
278 ;
279 }
280 }
281
282 // If a row containing the selection is already selected, return,
283 // if a row contained in newly selected block is found, remove it.
284 if ( m_selectionMode != wxGridSelection::wxGridSelectColumns )
285 {
286 size_t count = m_rowSelection.GetCount();
287 for ( size_t n = 0; n < count; n++ )
288 {
289 switch ( BlockContain( m_rowSelection[n], 0,
290 m_rowSelection[n], m_grid->GetNumberCols()-1,
291 topRow, leftCol, bottomRow, rightCol ) )
292 {
293 case 1:
294 return;
295 case -1:
296 m_rowSelection.RemoveAt(n);
297 n--; count--;
298 default:
299 ;
300 }
301 }
302 }
303 if ( m_selectionMode != wxGridSelection::wxGridSelectRows )
304 {
305 size_t count = m_colSelection.GetCount();
306 for ( size_t n = 0; n < count; n++ )
307 {
308 switch ( BlockContain( 0, m_colSelection[n],
309 m_grid->GetNumberRows()-1, m_colSelection[n],
310 topRow, leftCol, bottomRow, rightCol ) )
311 {
312 case 1:
313 return;
314 case -1:
315 m_colSelection.RemoveAt(n);
316 n--; count--;
317 default:
318 ;
319 }
320 }
321 }
322 m_blockSelectionTopLeft.Add( wxGridCellCoords( topRow, leftCol ) );
323 m_blockSelectionBottomRight.Add( wxGridCellCoords( bottomRow, rightCol ) );
324 }
325
326 void wxGridSelection::SelectCell( int row, int col)
327 {
328 if ( m_selectionMode == wxGridSelection::wxGridSelectRows )
329 SelectBlock(row, 0, row, m_grid->GetNumberCols() - 1 );
330 else if ( m_selectionMode == wxGridSelection::wxGridSelectColumns )
331 SelectBlock(0, col, m_grid->GetNumberRows() - 1, col );
332 else if ( IsInSelection ( row, col ) )
333 return;
334 m_cellSelection.Add( wxGridCellCoords( row, col ) );
335 }
336
337 void wxGridSelection::ToggleCellSelection( int row, int col)
338 {
339 if ( !IsInSelection ( row, col ) )
340 SelectCell( row, col );
341 size_t count;
342
343 // Maybe we want to toggle a member of m_cellSelection.
344 // Then it can't be contained in rows/cols/block, and we
345 // just have to remove it from m_cellSelection.
346
347 if ( m_selectionMode != wxGridSelection::wxGridSelectRows &&
348 m_selectionMode != wxGridSelection::wxGridSelectColumns )
349 {
350 count = m_cellSelection.GetCount();
351 for ( size_t n = 0; n < count; n++ )
352 {
353 wxGridCellCoords& coords = m_cellSelection[n];
354 if ( row == coords.GetRow() && col == coords.GetCol() )
355 {
356 m_cellSelection.RemoveAt(n);
357 n--; count--;
358 wxRect r;
359 r = m_grid->BlockToDeviceRect( m_cellSelection[n],
360 m_cellSelection[n] );
361 if ( !m_grid->GetBatchCount() )
362 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
363 return;
364 }
365 }
366 }
367
368 // remove a cell from the middle of a block (the really ugly case)
369 count = m_blockSelectionTopLeft.GetCount();
370 for ( size_t n = 0; n < count; n++ )
371 {
372 wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
373 wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
374 int topRow = coords1.GetRow();
375 int leftCol = coords1.GetCol();
376 int bottomRow = coords2.GetRow();
377 int rightCol = coords2.GetCol();
378 if ( BlockContainsCell( topRow, leftCol, bottomRow, rightCol,
379 row, col ) )
380 {
381 // remove the block
382 m_blockSelectionTopLeft.RemoveAt(n);
383 m_blockSelectionBottomRight.RemoveAt(n);
384 n--; count--;
385 // add up to 4 smaller blocks and set update region
386 if ( m_selectionMode != wxGridSelection::wxGridSelectColumns )
387 {
388 if ( topRow < row )
389 SelectBlock( topRow, leftCol, row - 1, rightCol );
390 if ( bottomRow > row )
391 SelectBlock( row + 1, leftCol, bottomRow, rightCol );
392 }
393 if ( m_selectionMode != wxGridSelection::wxGridSelectRows )
394 {
395 if ( leftCol < col )
396 SelectBlock( row, leftCol, row, col - 1 );
397 if ( rightCol > col )
398 SelectBlock( row, col + 1, row, rightCol );
399 }
400 }
401 }
402
403 // remove a cell from a row, adding up to two new blocks
404 if ( m_selectionMode != wxGridSelection::wxGridSelectColumns )
405 {
406 size_t count = m_rowSelection.GetCount();
407 for ( size_t n = 0; n < count; n++ )
408 {
409 if ( m_rowSelection[n] == row )
410 {
411 m_rowSelection.RemoveAt(n);
412 n--; count--;
413 if (m_selectionMode == wxGridSelection::wxGridSelectCells)
414 {
415 if ( col > 0 )
416 SelectBlock( row, 0, row, col - 1 );
417 if ( col < m_grid->GetNumberCols() - 1 )
418 SelectBlock( row, col + 1, row, m_grid->GetNumberCols() - 1 );
419 }
420 }
421 }
422 }
423
424 // remove a cell from a column, adding up to two new blocks
425 if ( m_selectionMode != wxGridSelection::wxGridSelectRows )
426 {
427 size_t count = m_colSelection.GetCount();
428 for ( size_t n = 0; n < count; n++ )
429 {
430 if ( m_colSelection[n] == col )
431 {
432 m_colSelection.RemoveAt(n);
433 n--; count--;
434 if (m_selectionMode == wxGridSelection::wxGridSelectCells)
435 {
436 if ( row > 0 )
437 SelectBlock( 0, col, row - 1, col );
438 if ( row < m_grid->GetNumberRows() - 1 )
439 SelectBlock( row + 1, col, m_grid->GetNumberRows() - 1, col );
440 }
441 }
442 }
443 }
444 wxRect r;
445 switch (m_selectionMode)
446 {
447 case wxGridSelection::wxGridSelectCells:
448 r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, col ),
449 wxGridCellCoords( row, col ) );
450 break;
451 case wxGridSelection::wxGridSelectRows:
452 r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, 0 ),
453 wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ) );
454 break;
455 case wxGridSelection::wxGridSelectColumns:
456 r = m_grid->BlockToDeviceRect( wxGridCellCoords( 0, col ),
457 wxGridCellCoords( m_grid->GetNumberRows() - 1, col ) );
458 break;
459 }
460 if ( !m_grid->GetBatchCount() )
461 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
462 }
463
464 void wxGridSelection::ClearSelection()
465 {
466 size_t n;
467 if ( m_selectionMode != wxGridSelection::wxGridSelectRows &&
468 m_selectionMode != wxGridSelection::wxGridSelectColumns )
469 {
470
471 while( ( n = m_cellSelection.GetCount() ) > 0)
472 {
473 wxRect r;
474 r = m_grid->BlockToDeviceRect( m_cellSelection[n],
475 m_cellSelection[n] );
476 m_cellSelection.RemoveAt(n);
477 if ( !m_grid->GetBatchCount() )
478 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
479 }
480 }
481 while( ( n = m_blockSelectionTopLeft.GetCount() ) > 0)
482 {
483 wxRect r;
484 r = m_grid->BlockToDeviceRect( m_blockSelectionTopLeft[n],
485 m_blockSelectionBottomRight[n] );
486 m_blockSelectionTopLeft.RemoveAt(n);
487 m_blockSelectionBottomRight.RemoveAt(n);
488 if ( !m_grid->GetBatchCount() )
489 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
490 }
491 if ( m_selectionMode != wxGridSelection::wxGridSelectColumns )
492 {
493 while( ( n = m_rowSelection.GetCount() ) > 0)
494 {
495 int & row = m_rowSelection[n];
496 wxRect r;
497 r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, 0 ),
498 wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ) );
499 m_rowSelection.RemoveAt(n);
500 if ( !m_grid->GetBatchCount() )
501 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
502 }
503 }
504 if ( m_selectionMode != wxGridSelection::wxGridSelectRows )
505 {
506 while( ( n = m_colSelection.GetCount() ) > 0)
507 {
508 int & col = m_colSelection[n];
509 wxRect r;
510 r = m_grid->BlockToDeviceRect( wxGridCellCoords( 0, col ),
511 wxGridCellCoords( m_grid->GetNumberRows() - 1, col ) );
512 m_colSelection.RemoveAt(n);
513 if ( !m_grid->GetBatchCount() )
514 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
515 }
516 }
517 }
518
519
520 void wxGridSelection::UpdateRows( size_t pos, int numRows )
521 {
522 size_t count = m_cellSelection.GetCount();
523 for ( size_t n = 0; n < count; n++ )
524 {
525 wxGridCellCoords& coords = m_cellSelection[n];
526 wxCoord row = coords.GetRow();
527 if ((size_t)row >= pos)
528 {
529 if (numRows > 0)
530 {
531 // If rows inserted, increase row counter where necessary
532 coords.SetRow(row + numRows);
533 }
534 else if (numRows < 0)
535 {
536 // If rows deleted ...
537 if ((size_t)row >= pos - numRows)
538 {
539 // ...either decrement row counter (if row still exists)...
540 coords.SetRow(row + numRows);
541 }
542 else
543 {
544 // ...or remove the attribute
545 m_cellSelection.RemoveAt(n);
546 n--; count--;
547 }
548 }
549 }
550 }
551
552 count = m_blockSelectionTopLeft.GetCount();
553 for ( size_t n = 0; n < count; n++ )
554 {
555 wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
556 wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
557 wxCoord row1 = coords1.GetRow();
558 wxCoord row2 = coords2.GetRow();
559 if ((size_t)row2 >= pos)
560 {
561 if (numRows > 0)
562 {
563 // If rows inserted, increase row counter where necessary
564 coords2.SetRow(row2 + numRows);
565 if ( (size_t)row1 >= pos )
566 coords1.SetRow(row1 + numRows);
567 }
568 else if (numRows < 0)
569 {
570 // If rows deleted ...
571 if ((size_t)row2 >= pos - numRows)
572 {
573 // ...either decrement row counter (if row still exists)...
574 coords2.SetRow(row2 + numRows);
575 if ( (size_t) row1 >= pos)
576 coords1.SetRow( wxMax(row1 + numRows, (int) pos) );
577
578 }
579 else
580 {
581 if ( (size_t) row1 >= pos)
582 {
583 // ...or remove the attribute
584 m_blockSelectionTopLeft.RemoveAt(n);
585 m_blockSelectionBottomRight.RemoveAt(n);
586 n--; count--;
587 }
588 else
589 coords2.SetRow(pos);
590 }
591 }
592 }
593 }
594
595 count = m_rowSelection.GetCount();
596 for ( size_t n = 0; n < count; n++ )
597 {
598 int & rowOrCol = m_rowSelection[n];
599 if ( (size_t)rowOrCol >= pos )
600 {
601 if ( numRows > 0 )
602 {
603 // If rows inserted, include row counter where necessary
604 rowOrCol += numRows;
605 }
606 else if ( numRows < 0)
607 {
608 // If rows deleted, either decrement row counter (if row still exists)
609 if ((size_t)rowOrCol >= pos - numRows)
610 rowOrCol += numRows;
611 else
612 {
613 m_rowSelection.RemoveAt(n);
614 n--; count--;
615 }
616 }
617 }
618 }
619 }
620
621 void wxGridSelection::UpdateCols( size_t pos, int numCols )
622 {
623 size_t count = m_cellSelection.GetCount();
624 for ( size_t n = 0; n < count; n++ )
625 {
626 wxGridCellCoords& coords = m_cellSelection[n];
627 wxCoord col = coords.GetCol();
628 if ((size_t)col >= pos)
629 {
630 if (numCols > 0)
631 {
632 // If rows inserted, increase row counter where necessary
633 coords.SetCol(col + numCols);
634 }
635 else if (numCols < 0)
636 {
637 // If rows deleted ...
638 if ((size_t)col >= pos - numCols)
639 {
640 // ...either decrement row counter (if row still exists)...
641 coords.SetCol(col + numCols);
642 }
643 else
644 {
645 // ...or remove the attribute
646 m_cellSelection.RemoveAt(n);
647 n--; count--;
648 }
649 }
650 }
651 }
652
653 count = m_blockSelectionTopLeft.GetCount();
654 for ( size_t n = 0; n < count; n++ )
655 {
656 wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
657 wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
658 wxCoord col1 = coords1.GetCol();
659 wxCoord col2 = coords2.GetCol();
660 if ((size_t)col2 >= pos)
661 {
662 if (numCols > 0)
663 {
664 // If rows inserted, increase row counter where necessary
665 coords2.SetCol(col2 + numCols);
666 if ( (size_t)col1 >= pos )
667 coords1.SetCol(col1 + numCols);
668 }
669 else if (numCols < 0)
670 {
671 // If cols deleted ...
672 if ((size_t)col2 >= pos - numCols)
673 {
674 // ...either decrement col counter (if col still exists)...
675 coords2.SetCol(col2 + numCols);
676 if ( (size_t) col1 >= pos)
677 coords1.SetCol( wxMax(col1 + numCols, (int) pos) );
678
679 }
680 else
681 {
682 if ( (size_t) col1 >= pos)
683 {
684 // ...or remove the attribute
685 m_blockSelectionTopLeft.RemoveAt(n);
686 m_blockSelectionBottomRight.RemoveAt(n);
687 n--; count--;
688 }
689 else
690 coords2.SetCol(pos);
691 }
692 }
693 }
694 }
695
696 count = m_colSelection.GetCount();
697 for ( size_t n = 0; n < count; n++ )
698 {
699 int & rowOrCol = m_colSelection[n];
700 if ( (size_t)rowOrCol >= pos )
701 {
702 if ( numCols > 0 )
703 {
704 // If cols inserted, include col counter where necessary
705 rowOrCol += numCols;
706 }
707 else if ( numCols < 0)
708 {
709 // If cols deleted, either decrement col counter (if col still exists)
710 if ((size_t)rowOrCol >= pos - numCols)
711 rowOrCol += numCols;
712 else
713 {
714 m_colSelection.RemoveAt(n);
715 n--; count--;
716 }
717 }
718 }
719 }
720 }
721
722 int wxGridSelection::BlockContain( int topRow1, int leftCol1,
723 int bottomRow1, int rightCol1,
724 int topRow2, int leftCol2,
725 int bottomRow2, int rightCol2 )
726 // returns 1, if Block1 contains Block2,
727 // -1, if Block2 contains Block1,
728 // 0, otherwise
729 {
730 if ( topRow1 <= topRow2 && bottomRow2 <= bottomRow1 &&
731 leftCol1 <= leftCol2 && rightCol2 <= rightCol1 )
732 return 1;
733 else if ( topRow2 <= topRow1 && bottomRow1 <= bottomRow2 &&
734 leftCol2 <= leftCol1 && rightCol1 <= rightCol2 )
735 return -1;
736 return 0;
737 }