1 ///////////////////////////////////////////////////////////////////////////
2 // Name: generic/gridsel.cpp
3 // Purpose: wxGridSelection
8 // Copyright: (c) Stefan Neis (Stefan.Neis@t-online.de)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "gridsel.h"
24 // For compilers that support precompilation, includes "wx/wx.h".
25 #include "wx/wxprec.h"
33 #if defined(wxUSE_NEW_GRID) && (wxUSE_NEW_GRID)
35 #include "wx/generic/gridsel.h"
37 // Some explanation for the members of the class:
38 // m_cellSelection stores individual selected cells
39 // -- this is only used if m_selectionMode == wxGridSelectCells
40 // m_blockSelectionTopLeft and m_blockSelectionBottomRight
41 // store the upper left and lower right corner of selected Blocks
42 // m_rowSelection and m_colSelection store individual selected
43 // rows and columns; maybe those are superfluous and should be
46 wxGridSelection::wxGridSelection( wxGrid
* grid
,
47 wxGrid::wxGridSelectionModes sel
)
50 m_selectionMode
= sel
;
53 bool wxGridSelection::IsSelection()
55 return ( m_cellSelection
.GetCount() || m_blockSelectionTopLeft
.GetCount() ||
56 m_rowSelection
.GetCount() || m_colSelection
.GetCount() );
59 bool wxGridSelection::IsInSelection ( int row
, int col
)
63 // First check whether the given cell is individually selected
64 // (if m_selectionMode is wxGridSelectCells).
65 if ( m_selectionMode
== wxGrid::wxGridSelectCells
)
67 count
= m_cellSelection
.GetCount();
68 for ( size_t n
= 0; n
< count
; n
++ )
70 wxGridCellCoords
& coords
= m_cellSelection
[n
];
71 if ( row
== coords
.GetRow() && col
== coords
.GetCol() )
76 // Now check whether the given cell is
77 // contained in one of the selected blocks.
78 count
= m_blockSelectionTopLeft
.GetCount();
79 for ( size_t n
= 0; n
< count
; n
++ )
81 wxGridCellCoords
& coords1
= m_blockSelectionTopLeft
[n
];
82 wxGridCellCoords
& coords2
= m_blockSelectionBottomRight
[n
];
83 if ( BlockContainsCell(coords1
.GetRow(), coords1
.GetCol(),
84 coords2
.GetRow(), coords2
.GetCol(),
89 // Now check whether the given cell is
90 // contained in one of the selected rows
91 // (unless we are in column selection mode).
92 if ( m_selectionMode
!= wxGrid::wxGridSelectColumns
)
94 size_t count
= m_rowSelection
.GetCount();
95 for ( size_t n
= 0; n
< count
; n
++ )
97 if ( row
== m_rowSelection
[n
] )
102 // Now check whether the given cell is
103 // contained in one of the selected columns
104 // (unless we are in row selection mode).
105 if ( m_selectionMode
!= wxGrid::wxGridSelectRows
)
107 size_t count
= m_colSelection
.GetCount();
108 for ( size_t n
= 0; n
< count
; n
++ )
110 if ( col
== m_colSelection
[n
] )
117 // Change the selection mode
118 void wxGridSelection::SetSelectionMode(wxGrid::wxGridSelectionModes selmode
)
120 // if selection mode is unchanged return immediately
121 if (selmode
== m_selectionMode
)
124 if ( m_selectionMode
!= wxGrid::wxGridSelectCells
)
126 // if changing form row to column selection
127 // or vice versa, clear the selection.
128 if ( selmode
!= wxGrid::wxGridSelectCells
)
131 m_selectionMode
= selmode
;
135 // if changing from cell selection to something else,
136 // promote selected cells/blocks to whole rows/columns.
138 while ( ( n
= m_cellSelection
.GetCount() ) > 0 )
141 wxGridCellCoords
& coords
= m_cellSelection
[n
];
142 int row
= coords
.GetRow();
143 int col
= coords
.GetCol();
144 m_cellSelection
.RemoveAt(n
);
145 if (selmode
== wxGrid::wxGridSelectRows
)
147 else // selmode == wxGridSelectColumns)
150 while( ( n
= m_blockSelectionTopLeft
.GetCount() ) > 0)
153 wxGridCellCoords
& coords
= m_blockSelectionTopLeft
[n
];
154 int topRow
= coords
.GetRow();
155 int leftCol
= coords
.GetCol();
156 coords
= m_blockSelectionBottomRight
[n
];
157 int bottomRow
= coords
.GetRow();
158 int rightCol
= coords
.GetCol();
159 if (selmode
== wxGrid::wxGridSelectRows
)
161 if (leftCol
!= 0 || rightCol
!= m_grid
->GetNumberCols() - 1 )
163 m_blockSelectionTopLeft
.RemoveAt(n
);
164 m_blockSelectionBottomRight
.RemoveAt(n
);
165 SelectBlock( topRow
, 0,
166 bottomRow
, m_grid
->GetNumberCols() - 1 );
169 else // selmode == wxGridSelectColumns)
171 if (topRow
!= 0 || bottomRow
!= m_grid
->GetNumberRows() - 1 )
173 m_blockSelectionTopLeft
.RemoveAt(n
);
174 m_blockSelectionBottomRight
.RemoveAt(n
);
175 SelectBlock( 0, leftCol
,
176 m_grid
->GetNumberRows() - 1, rightCol
);
183 void wxGridSelection::SelectRow( int row
, bool addToSelected
)
185 if ( m_selectionMode
== wxGrid::wxGridSelectColumns
)
189 // Remove single cells contained in newly selected block.
190 if ( m_selectionMode
== wxGrid::wxGridSelectCells
)
192 count
= m_cellSelection
.GetCount();
193 for ( n
= 0; n
< count
; n
++ )
195 wxGridCellCoords
& coords
= m_cellSelection
[n
];
196 if ( BlockContainsCell( row
, 0, row
, m_grid
->GetNumberCols() - 1,
197 coords
.GetRow(), coords
.GetCol() ) )
199 m_cellSelection
.RemoveAt(n
);
205 // Simplify list of selected blocks (if possible)
206 count
= m_blockSelectionTopLeft
.GetCount();
208 for ( n
= 0; n
< count
; n
++ )
210 wxGridCellCoords
& coords1
= m_blockSelectionTopLeft
[n
];
211 wxGridCellCoords
& coords2
= m_blockSelectionBottomRight
[n
];
213 // Remove block if it is a subset of the row
214 if ( coords1
.GetRow() == row
&& row
== coords2
.GetRow() )
216 m_blockSelectionTopLeft
.RemoveAt(n
);
217 m_blockSelectionBottomRight
.RemoveAt(n
);
220 else if ( coords1
.GetCol() == 0 &&
221 coords2
.GetCol() == m_grid
->GetNumberCols() - 1 )
223 // silently return, if row is contained in block
224 if ( coords1
.GetRow() <= row
&& row
<= coords2
.GetRow() )
226 // expand block, if it touched row
227 else if ( coords1
.GetRow() == row
+ 1)
232 else if ( coords2
.GetRow() == row
- 1)
240 // Unless we successfully handled the row,
241 // check whether row is already selected.
244 count
= m_rowSelection
.GetCount();
245 for ( n
= 0; n
< count
; n
++ )
247 if ( row
== m_rowSelection
[n
] )
251 // Add row to selection
252 m_rowSelection
.Add(row
);
256 wxRect r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( row
, 0 ),
257 wxGridCellCoords( row
, m_grid
->GetNumberCols() - 1 ) );
258 if ( !m_grid
->GetBatchCount() )
259 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
261 // Possibly send event here? This would imply that no event is sent,
262 // if the row already was part of the selection.
265 void wxGridSelection::SelectCol( int col
, bool addToSelected
)
267 if ( m_selectionMode
== wxGrid::wxGridSelectRows
)
271 // Remove single cells contained in newly selected block.
272 if ( m_selectionMode
== wxGrid::wxGridSelectCells
)
274 count
= m_cellSelection
.GetCount();
275 for ( n
= 0; n
< count
; n
++ )
277 wxGridCellCoords
& coords
= m_cellSelection
[n
];
278 if ( BlockContainsCell( 0, col
, m_grid
->GetNumberRows() - 1, col
,
279 coords
.GetRow(), coords
.GetCol() ) )
281 m_cellSelection
.RemoveAt(n
);
287 // Simplify list of selected blocks (if possible)
288 count
= m_blockSelectionTopLeft
.GetCount();
290 for ( n
= 0; n
< count
; n
++ )
292 wxGridCellCoords
& coords1
= m_blockSelectionTopLeft
[n
];
293 wxGridCellCoords
& coords2
= m_blockSelectionBottomRight
[n
];
295 // Remove block if it is a subset of the column
296 if ( coords1
.GetCol() == col
&& col
== coords2
.GetCol() )
298 m_blockSelectionTopLeft
.RemoveAt(n
);
299 m_blockSelectionBottomRight
.RemoveAt(n
);
302 else if ( coords1
.GetRow() == 0 &&
303 coords2
.GetRow() == m_grid
->GetNumberRows() - 1 )
305 // silently return, if row is contained in block
306 if ( coords1
.GetCol() <= col
&& col
<= coords2
.GetCol() )
308 // expand block, if it touched col
309 else if ( coords1
.GetCol() == col
+ 1)
314 else if ( coords2
.GetCol() == col
- 1)
322 // Unless we successfully handled the column,
323 // Check whether col is already selected.
326 count
= m_colSelection
.GetCount();
327 for ( n
= 0; n
< count
; n
++ )
329 if ( col
== m_colSelection
[n
] )
333 // Add col to selection
334 m_colSelection
.Add(col
);
338 wxRect r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( 0, col
),
339 wxGridCellCoords( m_grid
->GetNumberRows() - 1, col
) );
340 if ( !m_grid
->GetBatchCount() )
341 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
343 // Possibly send event here? This would imply that no event is sent,
344 // if the row already was part of the selection.
347 void wxGridSelection::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
349 // Fix the coordinates of the block if potentially needed
350 if ( m_selectionMode
== wxGrid::wxGridSelectRows
)
353 rightCol
= m_grid
->GetNumberCols() - 1;
355 else if ( m_selectionMode
== wxGrid::wxGridSelectColumns
)
358 bottomRow
= m_grid
->GetNumberRows() - 1;
361 // Handle single cell selection in SelectCell.
362 if ( topRow
== bottomRow
&& leftCol
== rightCol
)
363 SelectCell( topRow
, leftCol
);
366 // Remove single cells contained in newly selected block.
367 if ( m_selectionMode
== wxGrid::wxGridSelectCells
)
369 count
= m_cellSelection
.GetCount();
370 for ( n
= 0; n
< count
; n
++ )
372 wxGridCellCoords
& coords
= m_cellSelection
[n
];
373 if ( BlockContainsCell( topRow
, leftCol
, bottomRow
, rightCol
,
374 coords
.GetRow(), coords
.GetCol() ) )
376 m_cellSelection
.RemoveAt(n
);
382 // If a block containing the selection is already selected, return,
383 // if a block contained in the selection is found, remove it.
385 count
= m_blockSelectionTopLeft
.GetCount();
386 for ( n
= 0; n
< count
; n
++ )
388 wxGridCellCoords
& coords1
= m_blockSelectionTopLeft
[n
];
389 wxGridCellCoords
& coords2
= m_blockSelectionBottomRight
[n
];
390 switch ( BlockContain( coords1
.GetRow(), coords1
.GetCol(),
391 coords2
.GetRow(), coords2
.GetCol(),
392 topRow
, leftCol
, bottomRow
, rightCol
) )
397 m_blockSelectionTopLeft
.RemoveAt(n
);
398 m_blockSelectionBottomRight
.RemoveAt(n
);
405 // If a row containing the selection is already selected, return,
406 // if a row contained in newly selected block is found, remove it.
407 if ( m_selectionMode
!= wxGrid::wxGridSelectColumns
)
409 count
= m_rowSelection
.GetCount();
410 for ( n
= 0; n
< count
; n
++ )
412 switch ( BlockContain( m_rowSelection
[n
], 0,
413 m_rowSelection
[n
], m_grid
->GetNumberCols()-1,
414 topRow
, leftCol
, bottomRow
, rightCol
) )
419 m_rowSelection
.RemoveAt(n
);
426 if ( m_selectionMode
!= wxGrid::wxGridSelectRows
)
428 count
= m_colSelection
.GetCount();
429 for ( n
= 0; n
< count
; n
++ )
431 switch ( BlockContain( 0, m_colSelection
[n
],
432 m_grid
->GetNumberRows()-1, m_colSelection
[n
],
433 topRow
, leftCol
, bottomRow
, rightCol
) )
438 m_colSelection
.RemoveAt(n
);
445 m_blockSelectionTopLeft
.Add( wxGridCellCoords( topRow
, leftCol
) );
446 m_blockSelectionBottomRight
.Add( wxGridCellCoords( bottomRow
, rightCol
) );
449 wxRect r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( topRow
, leftCol
),
450 wxGridCellCoords( bottomRow
, rightCol
) );
451 if ( !m_grid
->GetBatchCount() )
452 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
454 // Possibly send event?
457 void wxGridSelection::SelectCell( int row
, int col
)
459 if ( m_selectionMode
== wxGrid::wxGridSelectRows
)
460 SelectBlock(row
, 0, row
, m_grid
->GetNumberCols() - 1 );
461 else if ( m_selectionMode
== wxGrid::wxGridSelectColumns
)
462 SelectBlock(0, col
, m_grid
->GetNumberRows() - 1, col
);
463 else if ( IsInSelection ( row
, col
) )
465 m_cellSelection
.Add( wxGridCellCoords( row
, col
) );
468 wxRect r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( row
, col
),
469 wxGridCellCoords( row
, col
) );
470 if ( !m_grid
->GetBatchCount() )
471 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
473 // Possibly send event?
476 void wxGridSelection::ToggleCellSelection( int row
, int col
)
478 // if the cell is not selected, select it
479 if ( !IsInSelection ( row
, col
) )
481 SelectCell( row
, col
);
485 // otherwise deselect it. This can be simple or more or
486 // less difficult, depending on how the cell is selected.
489 // The simplest case: The cell is contained in m_cellSelection
490 // Then it can't be contained in rows/cols/block (since those
491 // would remove the cell from m_cellSelection on creation), so
492 // we just have to remove it from m_cellSelection.
494 if ( m_selectionMode
== wxGrid::wxGridSelectCells
)
496 count
= m_cellSelection
.GetCount();
497 for ( n
= 0; n
< count
; n
++ )
499 wxGridCellCoords
& coords
= m_cellSelection
[n
];
500 if ( row
== coords
.GetRow() && col
== coords
.GetCol() )
503 r
= m_grid
->BlockToDeviceRect( m_cellSelection
[n
],
504 m_cellSelection
[n
] );
505 m_cellSelection
.RemoveAt(n
);
507 if ( !m_grid
->GetBatchCount() )
508 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
514 // The most difficult case: The cell is member of one or even several
515 // blocks. Split each such block in up to 4 new parts, that don't
516 // contain the cell to be selected, like this:
517 // |---------------------------|
521 // |---------------------------|
522 // | part 3 |x| part 4 |
523 // |---------------------------|
527 // |---------------------------|
528 // (The x marks the newly deselected cell).
529 // Note: in row selection mode, we only need part1 and part2;
530 // in column selection mode, we only need part 3 and part4,
531 // which are expanded to whole columns automatically!
533 count
= m_blockSelectionTopLeft
.GetCount();
534 for ( n
= 0; n
< count
; n
++ )
536 wxGridCellCoords
& coords1
= m_blockSelectionTopLeft
[n
];
537 wxGridCellCoords
& coords2
= m_blockSelectionBottomRight
[n
];
538 int topRow
= coords1
.GetRow();
539 int leftCol
= coords1
.GetCol();
540 int bottomRow
= coords2
.GetRow();
541 int rightCol
= coords2
.GetCol();
542 if ( BlockContainsCell( topRow
, leftCol
, bottomRow
, rightCol
,
546 m_blockSelectionTopLeft
.RemoveAt(n
);
547 m_blockSelectionBottomRight
.RemoveAt(n
);
549 // add up to 4 smaller blocks and set update region
550 if ( m_selectionMode
!= wxGrid::wxGridSelectColumns
)
553 SelectBlock( topRow
, leftCol
, row
- 1, rightCol
);
554 if ( bottomRow
> row
)
555 SelectBlock( row
+ 1, leftCol
, bottomRow
, rightCol
);
557 if ( m_selectionMode
!= wxGrid::wxGridSelectRows
)
560 SelectBlock( row
, leftCol
, row
, col
- 1 );
561 if ( rightCol
> col
)
562 SelectBlock( row
, col
+ 1, row
, rightCol
);
567 // remove a cell from a row, adding up to two new blocks
568 if ( m_selectionMode
!= wxGrid::wxGridSelectColumns
)
570 count
= m_rowSelection
.GetCount();
571 for ( n
= 0; n
< count
; n
++ )
573 if ( m_rowSelection
[n
] == row
)
575 m_rowSelection
.RemoveAt(n
);
577 if (m_selectionMode
== wxGrid::wxGridSelectCells
)
580 SelectBlock( row
, 0, row
, col
- 1 );
581 if ( col
< m_grid
->GetNumberCols() - 1 )
582 SelectBlock( row
, col
+ 1, row
, m_grid
->GetNumberCols() - 1 );
588 // remove a cell from a column, adding up to two new blocks
589 if ( m_selectionMode
!= wxGrid::wxGridSelectRows
)
591 count
= m_colSelection
.GetCount();
592 for ( n
= 0; n
< count
; n
++ )
594 if ( m_colSelection
[n
] == col
)
596 m_colSelection
.RemoveAt(n
);
598 if (m_selectionMode
== wxGrid::wxGridSelectCells
)
601 SelectBlock( 0, col
, row
- 1, col
);
602 if ( row
< m_grid
->GetNumberRows() - 1 )
603 SelectBlock( row
+ 1, col
, m_grid
->GetNumberRows() - 1, col
);
609 // Refresh the screen; according to m_selectionMode, we
610 // need to either update only the cell, or the whole row/column.
612 switch (m_selectionMode
)
614 case wxGrid::wxGridSelectCells
:
615 r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( row
, col
),
616 wxGridCellCoords( row
, col
) );
618 case wxGrid::wxGridSelectRows
:
619 r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( row
, 0 ),
620 wxGridCellCoords( row
, m_grid
->GetNumberCols() - 1 ) );
622 case wxGrid::wxGridSelectColumns
:
623 r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( 0, col
),
624 wxGridCellCoords( m_grid
->GetNumberRows() - 1, col
) );
627 if ( !m_grid
->GetBatchCount() )
628 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
631 void wxGridSelection::ClearSelection()
633 // Should this send deselection events?
636 // deselect all invidiual cells and update the screen
637 if ( m_selectionMode
== wxGrid::wxGridSelectCells
)
640 while( ( n
= m_cellSelection
.GetCount() ) > 0)
644 r
= m_grid
->BlockToDeviceRect( m_cellSelection
[n
],
645 m_cellSelection
[n
] );
646 m_cellSelection
.RemoveAt(n
);
647 if ( !m_grid
->GetBatchCount() )
648 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
652 // deselect all blocks and update the screen
653 while( ( n
= m_blockSelectionTopLeft
.GetCount() ) > 0)
657 r
= m_grid
->BlockToDeviceRect( m_blockSelectionTopLeft
[n
],
658 m_blockSelectionBottomRight
[n
] );
659 m_blockSelectionTopLeft
.RemoveAt(n
);
660 m_blockSelectionBottomRight
.RemoveAt(n
);
661 if ( !m_grid
->GetBatchCount() )
662 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
665 // deselect all rows and update the screen
666 if ( m_selectionMode
!= wxGrid::wxGridSelectColumns
)
668 while( ( n
= m_rowSelection
.GetCount() ) > 0)
671 int & row
= m_rowSelection
[n
];
673 r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( row
, 0 ),
674 wxGridCellCoords( row
, m_grid
->GetNumberCols() - 1 ) );
675 m_rowSelection
.RemoveAt(n
);
676 if ( !m_grid
->GetBatchCount() )
677 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
681 // deselect all columns and update the screen
682 if ( m_selectionMode
!= wxGrid::wxGridSelectRows
)
684 while( ( n
= m_colSelection
.GetCount() ) > 0)
687 int & col
= m_colSelection
[n
];
689 r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( 0, col
),
690 wxGridCellCoords( m_grid
->GetNumberRows() - 1, col
) );
691 m_colSelection
.RemoveAt(n
);
692 if ( !m_grid
->GetBatchCount() )
693 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
699 void wxGridSelection::UpdateRows( size_t pos
, int numRows
)
701 size_t count
= m_cellSelection
.GetCount();
703 for ( n
= 0; n
< count
; n
++ )
705 wxGridCellCoords
& coords
= m_cellSelection
[n
];
706 wxCoord row
= coords
.GetRow();
707 if ((size_t)row
>= pos
)
711 // If rows inserted, increase row counter where necessary
712 coords
.SetRow(row
+ numRows
);
714 else if (numRows
< 0)
716 // If rows deleted ...
717 if ((size_t)row
>= pos
- numRows
)
719 // ...either decrement row counter (if row still exists)...
720 coords
.SetRow(row
+ numRows
);
724 // ...or remove the attribute
725 m_cellSelection
.RemoveAt(n
);
732 count
= m_blockSelectionTopLeft
.GetCount();
733 for ( n
= 0; n
< count
; n
++ )
735 wxGridCellCoords
& coords1
= m_blockSelectionTopLeft
[n
];
736 wxGridCellCoords
& coords2
= m_blockSelectionBottomRight
[n
];
737 wxCoord row1
= coords1
.GetRow();
738 wxCoord row2
= coords2
.GetRow();
739 if ((size_t)row2
>= pos
)
743 // If rows inserted, increase row counter where necessary
744 coords2
.SetRow(row2
+ numRows
);
745 if ( (size_t)row1
>= pos
)
746 coords1
.SetRow(row1
+ numRows
);
748 else if (numRows
< 0)
750 // If rows deleted ...
751 if ((size_t)row2
>= pos
- numRows
)
753 // ...either decrement row counter (if row still exists)...
754 coords2
.SetRow(row2
+ numRows
);
755 if ( (size_t) row1
>= pos
)
756 coords1
.SetRow( wxMax(row1
+ numRows
, (int) pos
) );
761 if ( (size_t) row1
>= pos
)
763 // ...or remove the attribute
764 m_blockSelectionTopLeft
.RemoveAt(n
);
765 m_blockSelectionBottomRight
.RemoveAt(n
);
775 count
= m_rowSelection
.GetCount();
776 for ( n
= 0; n
< count
; n
++ )
778 int & rowOrCol
= m_rowSelection
[n
];
779 if ( (size_t)rowOrCol
>= pos
)
783 // If rows inserted, include row counter where necessary
786 else if ( numRows
< 0)
788 // If rows deleted, either decrement row counter (if row still exists)
789 if ((size_t)rowOrCol
>= pos
- numRows
)
793 m_rowSelection
.RemoveAt(n
);
801 void wxGridSelection::UpdateCols( size_t pos
, int numCols
)
803 size_t count
= m_cellSelection
.GetCount();
805 for ( n
= 0; n
< count
; n
++ )
807 wxGridCellCoords
& coords
= m_cellSelection
[n
];
808 wxCoord col
= coords
.GetCol();
809 if ((size_t)col
>= pos
)
813 // If rows inserted, increase row counter where necessary
814 coords
.SetCol(col
+ numCols
);
816 else if (numCols
< 0)
818 // If rows deleted ...
819 if ((size_t)col
>= pos
- numCols
)
821 // ...either decrement row counter (if row still exists)...
822 coords
.SetCol(col
+ numCols
);
826 // ...or remove the attribute
827 m_cellSelection
.RemoveAt(n
);
834 count
= m_blockSelectionTopLeft
.GetCount();
835 for ( n
= 0; n
< count
; n
++ )
837 wxGridCellCoords
& coords1
= m_blockSelectionTopLeft
[n
];
838 wxGridCellCoords
& coords2
= m_blockSelectionBottomRight
[n
];
839 wxCoord col1
= coords1
.GetCol();
840 wxCoord col2
= coords2
.GetCol();
841 if ((size_t)col2
>= pos
)
845 // If rows inserted, increase row counter where necessary
846 coords2
.SetCol(col2
+ numCols
);
847 if ( (size_t)col1
>= pos
)
848 coords1
.SetCol(col1
+ numCols
);
850 else if (numCols
< 0)
852 // If cols deleted ...
853 if ((size_t)col2
>= pos
- numCols
)
855 // ...either decrement col counter (if col still exists)...
856 coords2
.SetCol(col2
+ numCols
);
857 if ( (size_t) col1
>= pos
)
858 coords1
.SetCol( wxMax(col1
+ numCols
, (int) pos
) );
863 if ( (size_t) col1
>= pos
)
865 // ...or remove the attribute
866 m_blockSelectionTopLeft
.RemoveAt(n
);
867 m_blockSelectionBottomRight
.RemoveAt(n
);
877 count
= m_colSelection
.GetCount();
878 for ( n
= 0; n
< count
; n
++ )
880 int & rowOrCol
= m_colSelection
[n
];
881 if ( (size_t)rowOrCol
>= pos
)
885 // If cols inserted, include col counter where necessary
888 else if ( numCols
< 0)
890 // If cols deleted, either decrement col counter (if col still exists)
891 if ((size_t)rowOrCol
>= pos
- numCols
)
895 m_colSelection
.RemoveAt(n
);
903 int wxGridSelection::BlockContain( int topRow1
, int leftCol1
,
904 int bottomRow1
, int rightCol1
,
905 int topRow2
, int leftCol2
,
906 int bottomRow2
, int rightCol2
)
907 // returns 1, if Block1 contains Block2,
908 // -1, if Block2 contains Block1,
911 if ( topRow1
<= topRow2
&& bottomRow2
<= bottomRow1
&&
912 leftCol1
<= leftCol2
&& rightCol2
<= rightCol1
)
914 else if ( topRow2
<= topRow1
&& bottomRow1
<= bottomRow2
&&
915 leftCol2
<= leftCol1
&& rightCol1
<= rightCol2
)