]> git.saurik.com Git - wxWidgets.git/blob - src/generic/gridsel.cpp
Added extended selection support.
[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 wxGrid::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 != wxGrid::wxGridSelectRows &&
52 m_selectionMode != wxGrid::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 != wxGrid::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 != wxGrid::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 == wxGrid::wxGridSelectColumns )
96 return;
97 size_t count;
98
99 // Remove single cells contained in newly selected block.
100 if ( m_selectionMode != wxGrid::wxGridSelectRows &&
101 m_selectionMode != wxGrid::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 // Update View:
158 wxRect r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, 0 ),
159 wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ) );
160 if ( !m_grid->GetBatchCount() )
161 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
162 }
163
164 void wxGridSelection::SelectCol( int col, bool addToSelected = FALSE )
165 {
166 if ( m_selectionMode == wxGrid::wxGridSelectRows )
167 return;
168 size_t count;
169
170 // Remove single cells contained in newly selected block.
171 if ( m_selectionMode != wxGrid::wxGridSelectRows &&
172 m_selectionMode != wxGrid::wxGridSelectColumns )
173 {
174 count = m_cellSelection.GetCount();
175 for ( size_t n = 0; n < count; n++ )
176 {
177 wxGridCellCoords& coords = m_cellSelection[n];
178 if ( BlockContainsCell( 0, col, m_grid->GetNumberRows() - 1, col,
179 coords.GetRow(), coords.GetCol() ) )
180 {
181 m_cellSelection.RemoveAt(n);
182 n--; count--;
183 }
184 }
185 }
186
187 // If possible, merge col with existing selected block
188 count = m_blockSelectionTopLeft.GetCount();
189 for ( size_t n = 0; n < count; n++ )
190 {
191 wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
192 wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
193 if ( coords1.GetCol() == col && col == coords2.GetCol() )
194 {
195 m_blockSelectionTopLeft.RemoveAt(n);
196 m_blockSelectionBottomRight.RemoveAt(n);
197 n--; count--;
198 }
199 else if ( coords1.GetRow() == 0 &&
200 coords2.GetRow() == m_grid->GetNumberRows() - 1 )
201 {
202 if ( coords1.GetCol() <= col && col <= coords2.GetCol() )
203 return;
204 else if ( coords1.GetCol() == col + 1)
205 {
206 coords1.SetCol(col);
207 return;
208 }
209 else if ( coords2.GetCol() == col - 1)
210 {
211 coords2.SetCol(col);
212 return;
213 }
214 }
215 }
216
217 // Check whether col is already selected.
218 count = m_colSelection.GetCount();
219 for ( size_t n = 0; n < count; n++ )
220 {
221 if ( col == m_colSelection[n] )
222 return;
223 }
224
225 // Add col to selection
226 m_colSelection.Add(col);
227
228 // Update View:
229 wxRect r = m_grid->BlockToDeviceRect( wxGridCellCoords( 0, col ),
230 wxGridCellCoords( m_grid->GetNumberRows() - 1, col ) );
231 if ( !m_grid->GetBatchCount() )
232 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
233 }
234
235 void wxGridSelection::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol )
236 {
237 // Fix the coordinates of the block if potentially needed
238 if ( m_selectionMode == wxGrid::wxGridSelectRows )
239 {
240 leftCol = 0;
241 rightCol = m_grid->GetNumberCols() - 1;
242 }
243 else if ( m_selectionMode == wxGrid::wxGridSelectColumns )
244 {
245 topRow = 0;
246 bottomRow = m_grid->GetNumberRows() - 1;
247 }
248
249 // Handle single cell selection in SelectCell.
250 if ( topRow == bottomRow && leftCol == rightCol )
251 SelectCell( topRow, leftCol );
252
253 size_t count;
254 // Remove single cells contained in newly selected block.
255 if ( m_selectionMode != wxGrid::wxGridSelectRows &&
256 m_selectionMode != wxGrid::wxGridSelectColumns )
257 {
258 count = m_cellSelection.GetCount();
259 for ( size_t n = 0; n < count; n++ )
260 {
261 wxGridCellCoords& coords = m_cellSelection[n];
262 if ( BlockContainsCell( topRow, leftCol, bottomRow, rightCol,
263 coords.GetRow(), coords.GetCol() ) )
264 {
265 m_cellSelection.RemoveAt(n);
266 n--; count--;
267 }
268 }
269 }
270
271 // If a block containing the selection is already selected, return,
272 // if a block contained in the selection is found, remove it.
273
274 count = m_blockSelectionTopLeft.GetCount();
275 for ( size_t n = 0; n < count; n++ )
276 {
277 wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
278 wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
279 switch ( BlockContain( coords1.GetRow(), coords1.GetCol(),
280 coords2.GetRow(), coords2.GetCol(),
281 topRow, leftCol, bottomRow, rightCol ) )
282 {
283 case 1:
284 return;
285 case -1:
286 m_blockSelectionTopLeft.RemoveAt(n);
287 m_blockSelectionBottomRight.RemoveAt(n);
288 n--; count--;
289 default:
290 ;
291 }
292 }
293
294 // If a row containing the selection is already selected, return,
295 // if a row contained in newly selected block is found, remove it.
296 if ( m_selectionMode != wxGrid::wxGridSelectColumns )
297 {
298 size_t count = m_rowSelection.GetCount();
299 for ( size_t n = 0; n < count; n++ )
300 {
301 switch ( BlockContain( m_rowSelection[n], 0,
302 m_rowSelection[n], m_grid->GetNumberCols()-1,
303 topRow, leftCol, bottomRow, rightCol ) )
304 {
305 case 1:
306 return;
307 case -1:
308 m_rowSelection.RemoveAt(n);
309 n--; count--;
310 default:
311 ;
312 }
313 }
314 }
315 if ( m_selectionMode != wxGrid::wxGridSelectRows )
316 {
317 size_t count = m_colSelection.GetCount();
318 for ( size_t n = 0; n < count; n++ )
319 {
320 switch ( BlockContain( 0, m_colSelection[n],
321 m_grid->GetNumberRows()-1, m_colSelection[n],
322 topRow, leftCol, bottomRow, rightCol ) )
323 {
324 case 1:
325 return;
326 case -1:
327 m_colSelection.RemoveAt(n);
328 n--; count--;
329 default:
330 ;
331 }
332 }
333 }
334 m_blockSelectionTopLeft.Add( wxGridCellCoords( topRow, leftCol ) );
335 m_blockSelectionBottomRight.Add( wxGridCellCoords( bottomRow, rightCol ) );
336
337 // Update View:
338 wxRect r = m_grid->BlockToDeviceRect( wxGridCellCoords( topRow, leftCol ),
339 wxGridCellCoords( bottomRow, rightCol ) );
340 if ( !m_grid->GetBatchCount() )
341 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
342 }
343
344 void wxGridSelection::SelectCell( int row, int col)
345 {
346 if ( m_selectionMode == wxGrid::wxGridSelectRows )
347 SelectBlock(row, 0, row, m_grid->GetNumberCols() - 1 );
348 else if ( m_selectionMode == wxGrid::wxGridSelectColumns )
349 SelectBlock(0, col, m_grid->GetNumberRows() - 1, col );
350 else if ( IsInSelection ( row, col ) )
351 return;
352 m_cellSelection.Add( wxGridCellCoords( row, col ) );
353
354 wxRect r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, col ),
355 wxGridCellCoords( row, col ) );
356 if ( !m_grid->GetBatchCount() )
357 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
358 }
359
360 void wxGridSelection::ToggleCellSelection( int row, int col)
361 {
362 if ( !IsInSelection ( row, col ) )
363 {
364 SelectCell( row, col );
365 return;
366 }
367 size_t count;
368
369 // Maybe we want to toggle a member of m_cellSelection.
370 // Then it can't be contained in rows/cols/block, and we
371 // just have to remove it from m_cellSelection.
372
373 if ( m_selectionMode != wxGrid::wxGridSelectRows &&
374 m_selectionMode != wxGrid::wxGridSelectColumns )
375 {
376 count = m_cellSelection.GetCount();
377 for ( size_t n = 0; n < count; n++ )
378 {
379 wxGridCellCoords& coords = m_cellSelection[n];
380 if ( row == coords.GetRow() && col == coords.GetCol() )
381 {
382 wxRect r;
383 r = m_grid->BlockToDeviceRect( m_cellSelection[n],
384 m_cellSelection[n] );
385 m_cellSelection.RemoveAt(n);
386 n--; count--;
387 if ( !m_grid->GetBatchCount() )
388 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
389 return;
390 }
391 }
392 }
393
394 // remove a cell from the middle of a block (the really ugly case)
395 count = m_blockSelectionTopLeft.GetCount();
396 for ( size_t n = 0; n < count; n++ )
397 {
398 wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
399 wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
400 int topRow = coords1.GetRow();
401 int leftCol = coords1.GetCol();
402 int bottomRow = coords2.GetRow();
403 int rightCol = coords2.GetCol();
404 if ( BlockContainsCell( topRow, leftCol, bottomRow, rightCol,
405 row, col ) )
406 {
407 // remove the block
408 m_blockSelectionTopLeft.RemoveAt(n);
409 m_blockSelectionBottomRight.RemoveAt(n);
410 n--; count--;
411 // add up to 4 smaller blocks and set update region
412 if ( m_selectionMode != wxGrid::wxGridSelectColumns )
413 {
414 if ( topRow < row )
415 SelectBlock( topRow, leftCol, row - 1, rightCol );
416 if ( bottomRow > row )
417 SelectBlock( row + 1, leftCol, bottomRow, rightCol );
418 }
419 if ( m_selectionMode != wxGrid::wxGridSelectRows )
420 {
421 if ( leftCol < col )
422 SelectBlock( row, leftCol, row, col - 1 );
423 if ( rightCol > col )
424 SelectBlock( row, col + 1, row, rightCol );
425 }
426 }
427 }
428
429 // remove a cell from a row, adding up to two new blocks
430 if ( m_selectionMode != wxGrid::wxGridSelectColumns )
431 {
432 size_t count = m_rowSelection.GetCount();
433 for ( size_t n = 0; n < count; n++ )
434 {
435 if ( m_rowSelection[n] == row )
436 {
437 m_rowSelection.RemoveAt(n);
438 n--; count--;
439 if (m_selectionMode == wxGrid::wxGridSelectCells)
440 {
441 if ( col > 0 )
442 SelectBlock( row, 0, row, col - 1 );
443 if ( col < m_grid->GetNumberCols() - 1 )
444 SelectBlock( row, col + 1, row, m_grid->GetNumberCols() - 1 );
445 }
446 }
447 }
448 }
449
450 // remove a cell from a column, adding up to two new blocks
451 if ( m_selectionMode != wxGrid::wxGridSelectRows )
452 {
453 size_t count = m_colSelection.GetCount();
454 for ( size_t n = 0; n < count; n++ )
455 {
456 if ( m_colSelection[n] == col )
457 {
458 m_colSelection.RemoveAt(n);
459 n--; count--;
460 if (m_selectionMode == wxGrid::wxGridSelectCells)
461 {
462 if ( row > 0 )
463 SelectBlock( 0, col, row - 1, col );
464 if ( row < m_grid->GetNumberRows() - 1 )
465 SelectBlock( row + 1, col, m_grid->GetNumberRows() - 1, col );
466 }
467 }
468 }
469 }
470 wxRect r;
471 switch (m_selectionMode)
472 {
473 case wxGrid::wxGridSelectCells:
474 r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, col ),
475 wxGridCellCoords( row, col ) );
476 break;
477 case wxGrid::wxGridSelectRows:
478 r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, 0 ),
479 wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ) );
480 break;
481 case wxGrid::wxGridSelectColumns:
482 r = m_grid->BlockToDeviceRect( wxGridCellCoords( 0, col ),
483 wxGridCellCoords( m_grid->GetNumberRows() - 1, col ) );
484 break;
485 }
486 if ( !m_grid->GetBatchCount() )
487 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
488 }
489
490 void wxGridSelection::ClearSelection()
491 {
492 size_t n;
493 if ( m_selectionMode != wxGrid::wxGridSelectRows &&
494 m_selectionMode != wxGrid::wxGridSelectColumns )
495 {
496
497 while( ( n = m_cellSelection.GetCount() ) > 0)
498 {
499 wxRect r;
500 n--;
501 r = m_grid->BlockToDeviceRect( m_cellSelection[n],
502 m_cellSelection[n] );
503 m_cellSelection.RemoveAt(n);
504 if ( !m_grid->GetBatchCount() )
505 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
506 }
507 }
508 while( ( n = m_blockSelectionTopLeft.GetCount() ) > 0)
509 {
510 wxRect r;
511 n--;
512 r = m_grid->BlockToDeviceRect( m_blockSelectionTopLeft[n],
513 m_blockSelectionBottomRight[n] );
514 m_blockSelectionTopLeft.RemoveAt(n);
515 m_blockSelectionBottomRight.RemoveAt(n);
516 if ( !m_grid->GetBatchCount() )
517 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
518 }
519 if ( m_selectionMode != wxGrid::wxGridSelectColumns )
520 {
521 while( ( n = m_rowSelection.GetCount() ) > 0)
522 {
523 n--;
524 int & row = m_rowSelection[n];
525 wxRect r;
526 r = m_grid->BlockToDeviceRect( wxGridCellCoords( row, 0 ),
527 wxGridCellCoords( row, m_grid->GetNumberCols() - 1 ) );
528 m_rowSelection.RemoveAt(n);
529 if ( !m_grid->GetBatchCount() )
530 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
531 }
532 }
533 if ( m_selectionMode != wxGrid::wxGridSelectRows )
534 {
535 while( ( n = m_colSelection.GetCount() ) > 0)
536 {
537 n--;
538 int & col = m_colSelection[n];
539 wxRect r;
540 r = m_grid->BlockToDeviceRect( wxGridCellCoords( 0, col ),
541 wxGridCellCoords( m_grid->GetNumberRows() - 1, col ) );
542 m_colSelection.RemoveAt(n);
543 if ( !m_grid->GetBatchCount() )
544 ((wxWindow *)m_grid->m_gridWin)->Refresh( FALSE, &r );
545 }
546 }
547 }
548
549
550 void wxGridSelection::UpdateRows( size_t pos, int numRows )
551 {
552 size_t count = m_cellSelection.GetCount();
553 for ( size_t n = 0; n < count; n++ )
554 {
555 wxGridCellCoords& coords = m_cellSelection[n];
556 wxCoord row = coords.GetRow();
557 if ((size_t)row >= pos)
558 {
559 if (numRows > 0)
560 {
561 // If rows inserted, increase row counter where necessary
562 coords.SetRow(row + numRows);
563 }
564 else if (numRows < 0)
565 {
566 // If rows deleted ...
567 if ((size_t)row >= pos - numRows)
568 {
569 // ...either decrement row counter (if row still exists)...
570 coords.SetRow(row + numRows);
571 }
572 else
573 {
574 // ...or remove the attribute
575 m_cellSelection.RemoveAt(n);
576 n--; count--;
577 }
578 }
579 }
580 }
581
582 count = m_blockSelectionTopLeft.GetCount();
583 for ( size_t n = 0; n < count; n++ )
584 {
585 wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
586 wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
587 wxCoord row1 = coords1.GetRow();
588 wxCoord row2 = coords2.GetRow();
589 if ((size_t)row2 >= pos)
590 {
591 if (numRows > 0)
592 {
593 // If rows inserted, increase row counter where necessary
594 coords2.SetRow(row2 + numRows);
595 if ( (size_t)row1 >= pos )
596 coords1.SetRow(row1 + numRows);
597 }
598 else if (numRows < 0)
599 {
600 // If rows deleted ...
601 if ((size_t)row2 >= pos - numRows)
602 {
603 // ...either decrement row counter (if row still exists)...
604 coords2.SetRow(row2 + numRows);
605 if ( (size_t) row1 >= pos)
606 coords1.SetRow( wxMax(row1 + numRows, (int) pos) );
607
608 }
609 else
610 {
611 if ( (size_t) row1 >= pos)
612 {
613 // ...or remove the attribute
614 m_blockSelectionTopLeft.RemoveAt(n);
615 m_blockSelectionBottomRight.RemoveAt(n);
616 n--; count--;
617 }
618 else
619 coords2.SetRow(pos);
620 }
621 }
622 }
623 }
624
625 count = m_rowSelection.GetCount();
626 for ( size_t n = 0; n < count; n++ )
627 {
628 int & rowOrCol = m_rowSelection[n];
629 if ( (size_t)rowOrCol >= pos )
630 {
631 if ( numRows > 0 )
632 {
633 // If rows inserted, include row counter where necessary
634 rowOrCol += numRows;
635 }
636 else if ( numRows < 0)
637 {
638 // If rows deleted, either decrement row counter (if row still exists)
639 if ((size_t)rowOrCol >= pos - numRows)
640 rowOrCol += numRows;
641 else
642 {
643 m_rowSelection.RemoveAt(n);
644 n--; count--;
645 }
646 }
647 }
648 }
649 }
650
651 void wxGridSelection::UpdateCols( size_t pos, int numCols )
652 {
653 size_t count = m_cellSelection.GetCount();
654 for ( size_t n = 0; n < count; n++ )
655 {
656 wxGridCellCoords& coords = m_cellSelection[n];
657 wxCoord col = coords.GetCol();
658 if ((size_t)col >= pos)
659 {
660 if (numCols > 0)
661 {
662 // If rows inserted, increase row counter where necessary
663 coords.SetCol(col + numCols);
664 }
665 else if (numCols < 0)
666 {
667 // If rows deleted ...
668 if ((size_t)col >= pos - numCols)
669 {
670 // ...either decrement row counter (if row still exists)...
671 coords.SetCol(col + numCols);
672 }
673 else
674 {
675 // ...or remove the attribute
676 m_cellSelection.RemoveAt(n);
677 n--; count--;
678 }
679 }
680 }
681 }
682
683 count = m_blockSelectionTopLeft.GetCount();
684 for ( size_t n = 0; n < count; n++ )
685 {
686 wxGridCellCoords& coords1 = m_blockSelectionTopLeft[n];
687 wxGridCellCoords& coords2 = m_blockSelectionBottomRight[n];
688 wxCoord col1 = coords1.GetCol();
689 wxCoord col2 = coords2.GetCol();
690 if ((size_t)col2 >= pos)
691 {
692 if (numCols > 0)
693 {
694 // If rows inserted, increase row counter where necessary
695 coords2.SetCol(col2 + numCols);
696 if ( (size_t)col1 >= pos )
697 coords1.SetCol(col1 + numCols);
698 }
699 else if (numCols < 0)
700 {
701 // If cols deleted ...
702 if ((size_t)col2 >= pos - numCols)
703 {
704 // ...either decrement col counter (if col still exists)...
705 coords2.SetCol(col2 + numCols);
706 if ( (size_t) col1 >= pos)
707 coords1.SetCol( wxMax(col1 + numCols, (int) pos) );
708
709 }
710 else
711 {
712 if ( (size_t) col1 >= pos)
713 {
714 // ...or remove the attribute
715 m_blockSelectionTopLeft.RemoveAt(n);
716 m_blockSelectionBottomRight.RemoveAt(n);
717 n--; count--;
718 }
719 else
720 coords2.SetCol(pos);
721 }
722 }
723 }
724 }
725
726 count = m_colSelection.GetCount();
727 for ( size_t n = 0; n < count; n++ )
728 {
729 int & rowOrCol = m_colSelection[n];
730 if ( (size_t)rowOrCol >= pos )
731 {
732 if ( numCols > 0 )
733 {
734 // If cols inserted, include col counter where necessary
735 rowOrCol += numCols;
736 }
737 else if ( numCols < 0)
738 {
739 // If cols deleted, either decrement col counter (if col still exists)
740 if ((size_t)rowOrCol >= pos - numCols)
741 rowOrCol += numCols;
742 else
743 {
744 m_colSelection.RemoveAt(n);
745 n--; count--;
746 }
747 }
748 }
749 }
750 }
751
752 int wxGridSelection::BlockContain( int topRow1, int leftCol1,
753 int bottomRow1, int rightCol1,
754 int topRow2, int leftCol2,
755 int bottomRow2, int rightCol2 )
756 // returns 1, if Block1 contains Block2,
757 // -1, if Block2 contains Block1,
758 // 0, otherwise
759 {
760 if ( topRow1 <= topRow2 && bottomRow2 <= bottomRow1 &&
761 leftCol1 <= leftCol2 && rightCol2 <= rightCol1 )
762 return 1;
763 else if ( topRow2 <= topRow1 && bottomRow1 <= bottomRow2 &&
764 leftCol2 <= leftCol1 && rightCol1 <= rightCol2 )
765 return -1;
766 return 0;
767 }