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