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)
151 for (n
= 0; n
< m_blockSelectionTopLeft
.GetCount(); n
++)
152 // Note that m_blockSelectionTopLeft's size may be changing!
154 wxGridCellCoords
& coords
= m_blockSelectionTopLeft
[n
];
155 int topRow
= coords
.GetRow();
156 int leftCol
= coords
.GetCol();
157 coords
= m_blockSelectionBottomRight
[n
];
158 int bottomRow
= coords
.GetRow();
159 int rightCol
= coords
.GetCol();
160 if (selmode
== wxGrid::wxGridSelectRows
)
162 if (leftCol
!= 0 || rightCol
!= m_grid
->GetNumberCols() - 1 )
164 m_blockSelectionTopLeft
.RemoveAt(n
);
165 m_blockSelectionBottomRight
.RemoveAt(n
);
166 SelectBlock( topRow
, 0,
167 bottomRow
, m_grid
->GetNumberCols() - 1 );
170 else // selmode == wxGridSelectColumns)
172 if (topRow
!= 0 || bottomRow
!= m_grid
->GetNumberRows() - 1 )
174 m_blockSelectionTopLeft
.RemoveAt(n
);
175 m_blockSelectionBottomRight
.RemoveAt(n
);
176 SelectBlock( 0, leftCol
,
177 m_grid
->GetNumberRows() - 1, rightCol
);
181 m_selectionMode
= selmode
;
185 void wxGridSelection::SelectRow( int row
, bool addToSelected
)
187 if ( m_selectionMode
== wxGrid::wxGridSelectColumns
)
191 // Remove single cells contained in newly selected block.
192 if ( m_selectionMode
== wxGrid::wxGridSelectCells
)
194 count
= m_cellSelection
.GetCount();
195 for ( n
= 0; n
< count
; n
++ )
197 wxGridCellCoords
& coords
= m_cellSelection
[n
];
198 if ( BlockContainsCell( row
, 0, row
, m_grid
->GetNumberCols() - 1,
199 coords
.GetRow(), coords
.GetCol() ) )
201 m_cellSelection
.RemoveAt(n
);
207 // Simplify list of selected blocks (if possible)
208 count
= m_blockSelectionTopLeft
.GetCount();
210 for ( n
= 0; n
< count
; n
++ )
212 wxGridCellCoords
& coords1
= m_blockSelectionTopLeft
[n
];
213 wxGridCellCoords
& coords2
= m_blockSelectionBottomRight
[n
];
215 // Remove block if it is a subset of the row
216 if ( coords1
.GetRow() == row
&& row
== coords2
.GetRow() )
218 m_blockSelectionTopLeft
.RemoveAt(n
);
219 m_blockSelectionBottomRight
.RemoveAt(n
);
222 else if ( coords1
.GetCol() == 0 &&
223 coords2
.GetCol() == m_grid
->GetNumberCols() - 1 )
225 // silently return, if row is contained in block
226 if ( coords1
.GetRow() <= row
&& row
<= coords2
.GetRow() )
228 // expand block, if it touched row
229 else if ( coords1
.GetRow() == row
+ 1)
234 else if ( coords2
.GetRow() == row
- 1)
242 // Unless we successfully handled the row,
243 // check whether row is already selected.
246 count
= m_rowSelection
.GetCount();
247 for ( n
= 0; n
< count
; n
++ )
249 if ( row
== m_rowSelection
[n
] )
253 // Add row to selection
254 m_rowSelection
.Add(row
);
258 wxRect r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( row
, 0 ),
259 wxGridCellCoords( row
, m_grid
->GetNumberCols() - 1 ) );
260 if ( !m_grid
->GetBatchCount() )
261 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
263 // Possibly send event here? This would imply that no event is sent,
264 // if the row already was part of the selection.
267 void wxGridSelection::SelectCol( int col
, bool addToSelected
)
269 if ( m_selectionMode
== wxGrid::wxGridSelectRows
)
273 // Remove single cells contained in newly selected block.
274 if ( m_selectionMode
== wxGrid::wxGridSelectCells
)
276 count
= m_cellSelection
.GetCount();
277 for ( n
= 0; n
< count
; n
++ )
279 wxGridCellCoords
& coords
= m_cellSelection
[n
];
280 if ( BlockContainsCell( 0, col
, m_grid
->GetNumberRows() - 1, col
,
281 coords
.GetRow(), coords
.GetCol() ) )
283 m_cellSelection
.RemoveAt(n
);
289 // Simplify list of selected blocks (if possible)
290 count
= m_blockSelectionTopLeft
.GetCount();
292 for ( n
= 0; n
< count
; n
++ )
294 wxGridCellCoords
& coords1
= m_blockSelectionTopLeft
[n
];
295 wxGridCellCoords
& coords2
= m_blockSelectionBottomRight
[n
];
297 // Remove block if it is a subset of the column
298 if ( coords1
.GetCol() == col
&& col
== coords2
.GetCol() )
300 m_blockSelectionTopLeft
.RemoveAt(n
);
301 m_blockSelectionBottomRight
.RemoveAt(n
);
304 else if ( coords1
.GetRow() == 0 &&
305 coords2
.GetRow() == m_grid
->GetNumberRows() - 1 )
307 // silently return, if row is contained in block
308 if ( coords1
.GetCol() <= col
&& col
<= coords2
.GetCol() )
310 // expand block, if it touched col
311 else if ( coords1
.GetCol() == col
+ 1)
316 else if ( coords2
.GetCol() == col
- 1)
324 // Unless we successfully handled the column,
325 // Check whether col is already selected.
328 count
= m_colSelection
.GetCount();
329 for ( n
= 0; n
< count
; n
++ )
331 if ( col
== m_colSelection
[n
] )
335 // Add col to selection
336 m_colSelection
.Add(col
);
340 wxRect r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( 0, col
),
341 wxGridCellCoords( m_grid
->GetNumberRows() - 1, col
) );
342 if ( !m_grid
->GetBatchCount() )
343 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
345 // Possibly send event here? This would imply that no event is sent,
346 // if the row already was part of the selection.
349 void wxGridSelection::SelectBlock( int topRow
, int leftCol
, int bottomRow
, int rightCol
)
351 // Fix the coordinates of the block if potentially needed
352 if ( m_selectionMode
== wxGrid::wxGridSelectRows
)
355 rightCol
= m_grid
->GetNumberCols() - 1;
357 else if ( m_selectionMode
== wxGrid::wxGridSelectColumns
)
360 bottomRow
= m_grid
->GetNumberRows() - 1;
363 // Handle single cell selection in SelectCell.
364 if ( topRow
== bottomRow
&& leftCol
== rightCol
)
365 SelectCell( topRow
, leftCol
);
368 // Remove single cells contained in newly selected block.
369 if ( m_selectionMode
== wxGrid::wxGridSelectCells
)
371 count
= m_cellSelection
.GetCount();
372 for ( n
= 0; n
< count
; n
++ )
374 wxGridCellCoords
& coords
= m_cellSelection
[n
];
375 if ( BlockContainsCell( topRow
, leftCol
, bottomRow
, rightCol
,
376 coords
.GetRow(), coords
.GetCol() ) )
378 m_cellSelection
.RemoveAt(n
);
384 // If a block containing the selection is already selected, return,
385 // if a block contained in the selection is found, remove it.
387 count
= m_blockSelectionTopLeft
.GetCount();
388 for ( n
= 0; n
< count
; n
++ )
390 wxGridCellCoords
& coords1
= m_blockSelectionTopLeft
[n
];
391 wxGridCellCoords
& coords2
= m_blockSelectionBottomRight
[n
];
392 switch ( BlockContain( coords1
.GetRow(), coords1
.GetCol(),
393 coords2
.GetRow(), coords2
.GetCol(),
394 topRow
, leftCol
, bottomRow
, rightCol
) )
399 m_blockSelectionTopLeft
.RemoveAt(n
);
400 m_blockSelectionBottomRight
.RemoveAt(n
);
407 // If a row containing the selection is already selected, return,
408 // if a row contained in newly selected block is found, remove it.
409 if ( m_selectionMode
!= wxGrid::wxGridSelectColumns
)
411 count
= m_rowSelection
.GetCount();
412 for ( n
= 0; n
< count
; n
++ )
414 switch ( BlockContain( m_rowSelection
[n
], 0,
415 m_rowSelection
[n
], m_grid
->GetNumberCols()-1,
416 topRow
, leftCol
, bottomRow
, rightCol
) )
421 m_rowSelection
.RemoveAt(n
);
428 if ( m_selectionMode
!= wxGrid::wxGridSelectRows
)
430 count
= m_colSelection
.GetCount();
431 for ( n
= 0; n
< count
; n
++ )
433 switch ( BlockContain( 0, m_colSelection
[n
],
434 m_grid
->GetNumberRows()-1, m_colSelection
[n
],
435 topRow
, leftCol
, bottomRow
, rightCol
) )
440 m_colSelection
.RemoveAt(n
);
447 m_blockSelectionTopLeft
.Add( wxGridCellCoords( topRow
, leftCol
) );
448 m_blockSelectionBottomRight
.Add( wxGridCellCoords( bottomRow
, rightCol
) );
451 wxRect r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( topRow
, leftCol
),
452 wxGridCellCoords( bottomRow
, rightCol
) );
453 if ( !m_grid
->GetBatchCount() )
454 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
456 // Possibly send event?
459 void wxGridSelection::SelectCell( int row
, int col
)
461 if ( m_selectionMode
== wxGrid::wxGridSelectRows
)
463 SelectBlock(row
, 0, row
, m_grid
->GetNumberCols() - 1 );
466 else if ( m_selectionMode
== wxGrid::wxGridSelectColumns
)
468 SelectBlock(0, col
, m_grid
->GetNumberRows() - 1, col
);
471 else if ( IsInSelection ( row
, col
) )
473 m_cellSelection
.Add( wxGridCellCoords( row
, col
) );
476 wxRect r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( row
, col
),
477 wxGridCellCoords( row
, col
) );
478 if ( !m_grid
->GetBatchCount() )
479 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
481 // Possibly send event?
484 void wxGridSelection::ToggleCellSelection( int row
, int col
)
486 // if the cell is not selected, select it
487 if ( !IsInSelection ( row
, col
) )
489 SelectCell( row
, col
);
493 // otherwise deselect it. This can be simple or more or
494 // less difficult, depending on how the cell is selected.
497 // The simplest case: The cell is contained in m_cellSelection
498 // Then it can't be contained in rows/cols/block (since those
499 // would remove the cell from m_cellSelection on creation), so
500 // we just have to remove it from m_cellSelection.
502 if ( m_selectionMode
== wxGrid::wxGridSelectCells
)
504 count
= m_cellSelection
.GetCount();
505 for ( n
= 0; n
< count
; n
++ )
507 wxGridCellCoords
& coords
= m_cellSelection
[n
];
508 if ( row
== coords
.GetRow() && col
== coords
.GetCol() )
511 r
= m_grid
->BlockToDeviceRect( m_cellSelection
[n
],
512 m_cellSelection
[n
] );
513 m_cellSelection
.RemoveAt(n
);
515 if ( !m_grid
->GetBatchCount() )
516 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
522 // The most difficult case: The cell is member of one or even several
523 // blocks. Split each such block in up to 4 new parts, that don't
524 // contain the cell to be selected, like this:
525 // |---------------------------|
529 // |---------------------------|
530 // | part 3 |x| part 4 |
531 // |---------------------------|
535 // |---------------------------|
536 // (The x marks the newly deselected cell).
537 // Note: in row selection mode, we only need part1 and part2;
538 // in column selection mode, we only need part 3 and part4,
539 // which are expanded to whole columns automatically!
541 count
= m_blockSelectionTopLeft
.GetCount();
542 for ( n
= 0; n
< count
; n
++ )
544 wxGridCellCoords
& coords1
= m_blockSelectionTopLeft
[n
];
545 wxGridCellCoords
& coords2
= m_blockSelectionBottomRight
[n
];
546 int topRow
= coords1
.GetRow();
547 int leftCol
= coords1
.GetCol();
548 int bottomRow
= coords2
.GetRow();
549 int rightCol
= coords2
.GetCol();
550 if ( BlockContainsCell( topRow
, leftCol
, bottomRow
, rightCol
,
554 m_blockSelectionTopLeft
.RemoveAt(n
);
555 m_blockSelectionBottomRight
.RemoveAt(n
);
557 // add up to 4 smaller blocks and set update region
558 if ( m_selectionMode
!= wxGrid::wxGridSelectColumns
)
561 SelectBlock( topRow
, leftCol
, row
- 1, rightCol
);
562 if ( bottomRow
> row
)
563 SelectBlock( row
+ 1, leftCol
, bottomRow
, rightCol
);
565 if ( m_selectionMode
!= wxGrid::wxGridSelectRows
)
568 SelectBlock( row
, leftCol
, row
, col
- 1 );
569 if ( rightCol
> col
)
570 SelectBlock( row
, col
+ 1, row
, rightCol
);
575 // remove a cell from a row, adding up to two new blocks
576 if ( m_selectionMode
!= wxGrid::wxGridSelectColumns
)
578 count
= m_rowSelection
.GetCount();
579 for ( n
= 0; n
< count
; n
++ )
581 if ( m_rowSelection
[n
] == row
)
583 m_rowSelection
.RemoveAt(n
);
585 if (m_selectionMode
== wxGrid::wxGridSelectCells
)
588 SelectBlock( row
, 0, row
, col
- 1 );
589 if ( col
< m_grid
->GetNumberCols() - 1 )
590 SelectBlock( row
, col
+ 1, row
, m_grid
->GetNumberCols() - 1 );
596 // remove a cell from a column, adding up to two new blocks
597 if ( m_selectionMode
!= wxGrid::wxGridSelectRows
)
599 count
= m_colSelection
.GetCount();
600 for ( n
= 0; n
< count
; n
++ )
602 if ( m_colSelection
[n
] == col
)
604 m_colSelection
.RemoveAt(n
);
606 if (m_selectionMode
== wxGrid::wxGridSelectCells
)
609 SelectBlock( 0, col
, row
- 1, col
);
610 if ( row
< m_grid
->GetNumberRows() - 1 )
611 SelectBlock( row
+ 1, col
, m_grid
->GetNumberRows() - 1, col
);
617 // Refresh the screen; according to m_selectionMode, we
618 // need to either update only the cell, or the whole row/column.
620 switch (m_selectionMode
)
622 case wxGrid::wxGridSelectCells
:
623 r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( row
, col
),
624 wxGridCellCoords( row
, col
) );
626 case wxGrid::wxGridSelectRows
:
627 r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( row
, 0 ),
628 wxGridCellCoords( row
, m_grid
->GetNumberCols() - 1 ) );
630 case wxGrid::wxGridSelectColumns
:
631 r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( 0, col
),
632 wxGridCellCoords( m_grid
->GetNumberRows() - 1, col
) );
635 if ( !m_grid
->GetBatchCount() )
636 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
639 void wxGridSelection::ClearSelection()
641 // Should this send deselection events?
644 // deselect all invidiual cells and update the screen
645 if ( m_selectionMode
== wxGrid::wxGridSelectCells
)
648 while( ( n
= m_cellSelection
.GetCount() ) > 0)
652 r
= m_grid
->BlockToDeviceRect( m_cellSelection
[n
],
653 m_cellSelection
[n
] );
654 m_cellSelection
.RemoveAt(n
);
655 if ( !m_grid
->GetBatchCount() )
656 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
660 // deselect all blocks and update the screen
661 while( ( n
= m_blockSelectionTopLeft
.GetCount() ) > 0)
665 r
= m_grid
->BlockToDeviceRect( m_blockSelectionTopLeft
[n
],
666 m_blockSelectionBottomRight
[n
] );
667 m_blockSelectionTopLeft
.RemoveAt(n
);
668 m_blockSelectionBottomRight
.RemoveAt(n
);
669 if ( !m_grid
->GetBatchCount() )
670 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
673 // deselect all rows and update the screen
674 if ( m_selectionMode
!= wxGrid::wxGridSelectColumns
)
676 while( ( n
= m_rowSelection
.GetCount() ) > 0)
679 int & row
= m_rowSelection
[n
];
681 r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( row
, 0 ),
682 wxGridCellCoords( row
, m_grid
->GetNumberCols() - 1 ) );
683 m_rowSelection
.RemoveAt(n
);
684 if ( !m_grid
->GetBatchCount() )
685 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
689 // deselect all columns and update the screen
690 if ( m_selectionMode
!= wxGrid::wxGridSelectRows
)
692 while( ( n
= m_colSelection
.GetCount() ) > 0)
695 int & col
= m_colSelection
[n
];
697 r
= m_grid
->BlockToDeviceRect( wxGridCellCoords( 0, col
),
698 wxGridCellCoords( m_grid
->GetNumberRows() - 1, col
) );
699 m_colSelection
.RemoveAt(n
);
700 if ( !m_grid
->GetBatchCount() )
701 ((wxWindow
*)m_grid
->m_gridWin
)->Refresh( FALSE
, &r
);
707 void wxGridSelection::UpdateRows( size_t pos
, int numRows
)
709 size_t count
= m_cellSelection
.GetCount();
711 for ( n
= 0; n
< count
; n
++ )
713 wxGridCellCoords
& coords
= m_cellSelection
[n
];
714 wxCoord row
= coords
.GetRow();
715 if ((size_t)row
>= pos
)
719 // If rows inserted, increase row counter where necessary
720 coords
.SetRow(row
+ numRows
);
722 else if (numRows
< 0)
724 // If rows deleted ...
725 if ((size_t)row
>= pos
- numRows
)
727 // ...either decrement row counter (if row still exists)...
728 coords
.SetRow(row
+ numRows
);
732 // ...or remove the attribute
733 m_cellSelection
.RemoveAt(n
);
740 count
= m_blockSelectionTopLeft
.GetCount();
741 for ( n
= 0; n
< count
; n
++ )
743 wxGridCellCoords
& coords1
= m_blockSelectionTopLeft
[n
];
744 wxGridCellCoords
& coords2
= m_blockSelectionBottomRight
[n
];
745 wxCoord row1
= coords1
.GetRow();
746 wxCoord row2
= coords2
.GetRow();
747 if ((size_t)row2
>= pos
)
751 // If rows inserted, increase row counter where necessary
752 coords2
.SetRow(row2
+ numRows
);
753 if ( (size_t)row1
>= pos
)
754 coords1
.SetRow(row1
+ numRows
);
756 else if (numRows
< 0)
758 // If rows deleted ...
759 if ((size_t)row2
>= pos
- numRows
)
761 // ...either decrement row counter (if row still exists)...
762 coords2
.SetRow(row2
+ numRows
);
763 if ( (size_t) row1
>= pos
)
764 coords1
.SetRow( wxMax(row1
+ numRows
, (int) pos
) );
769 if ( (size_t) row1
>= pos
)
771 // ...or remove the attribute
772 m_blockSelectionTopLeft
.RemoveAt(n
);
773 m_blockSelectionBottomRight
.RemoveAt(n
);
783 count
= m_rowSelection
.GetCount();
784 for ( n
= 0; n
< count
; n
++ )
786 int & rowOrCol
= m_rowSelection
[n
];
787 if ( (size_t)rowOrCol
>= pos
)
791 // If rows inserted, include row counter where necessary
794 else if ( numRows
< 0)
796 // If rows deleted, either decrement row counter (if row still exists)
797 if ((size_t)rowOrCol
>= pos
- numRows
)
801 m_rowSelection
.RemoveAt(n
);
809 void wxGridSelection::UpdateCols( size_t pos
, int numCols
)
811 size_t count
= m_cellSelection
.GetCount();
813 for ( n
= 0; n
< count
; n
++ )
815 wxGridCellCoords
& coords
= m_cellSelection
[n
];
816 wxCoord col
= coords
.GetCol();
817 if ((size_t)col
>= pos
)
821 // If rows inserted, increase row counter where necessary
822 coords
.SetCol(col
+ numCols
);
824 else if (numCols
< 0)
826 // If rows deleted ...
827 if ((size_t)col
>= pos
- numCols
)
829 // ...either decrement row counter (if row still exists)...
830 coords
.SetCol(col
+ numCols
);
834 // ...or remove the attribute
835 m_cellSelection
.RemoveAt(n
);
842 count
= m_blockSelectionTopLeft
.GetCount();
843 for ( n
= 0; n
< count
; n
++ )
845 wxGridCellCoords
& coords1
= m_blockSelectionTopLeft
[n
];
846 wxGridCellCoords
& coords2
= m_blockSelectionBottomRight
[n
];
847 wxCoord col1
= coords1
.GetCol();
848 wxCoord col2
= coords2
.GetCol();
849 if ((size_t)col2
>= pos
)
853 // If rows inserted, increase row counter where necessary
854 coords2
.SetCol(col2
+ numCols
);
855 if ( (size_t)col1
>= pos
)
856 coords1
.SetCol(col1
+ numCols
);
858 else if (numCols
< 0)
860 // If cols deleted ...
861 if ((size_t)col2
>= pos
- numCols
)
863 // ...either decrement col counter (if col still exists)...
864 coords2
.SetCol(col2
+ numCols
);
865 if ( (size_t) col1
>= pos
)
866 coords1
.SetCol( wxMax(col1
+ numCols
, (int) pos
) );
871 if ( (size_t) col1
>= pos
)
873 // ...or remove the attribute
874 m_blockSelectionTopLeft
.RemoveAt(n
);
875 m_blockSelectionBottomRight
.RemoveAt(n
);
885 count
= m_colSelection
.GetCount();
886 for ( n
= 0; n
< count
; n
++ )
888 int & rowOrCol
= m_colSelection
[n
];
889 if ( (size_t)rowOrCol
>= pos
)
893 // If cols inserted, include col counter where necessary
896 else if ( numCols
< 0)
898 // If cols deleted, either decrement col counter (if col still exists)
899 if ((size_t)rowOrCol
>= pos
- numCols
)
903 m_colSelection
.RemoveAt(n
);
911 int wxGridSelection::BlockContain( int topRow1
, int leftCol1
,
912 int bottomRow1
, int rightCol1
,
913 int topRow2
, int leftCol2
,
914 int bottomRow2
, int rightCol2
)
915 // returns 1, if Block1 contains Block2,
916 // -1, if Block2 contains Block1,
919 if ( topRow1
<= topRow2
&& bottomRow2
<= bottomRow1
&&
920 leftCol1
<= leftCol2
&& rightCol2
<= rightCol1
)
922 else if ( topRow2
<= topRow1
&& bottomRow1
<= bottomRow2
&&
923 leftCol2
<= leftCol1
&& rightCol1
<= rightCol2
)