+// Change the selection mode
+void wxGridSelection::SetSelectionMode(wxGrid::wxGridSelectionModes selmode)
+{
+ // if selection mode is unchanged return immediately
+ if (selmode == m_selectionMode)
+ return;
+
+ if ( m_selectionMode != wxGrid::wxGridSelectCells )
+ {
+ // if changing form row to column selection
+ // or vice versa, clear the selection.
+ if ( selmode != wxGrid::wxGridSelectCells )
+ ClearSelection();
+
+ m_selectionMode = selmode;
+ }
+ else
+ {
+ // if changing from cell selection to something else,
+ // promote selected cells/blocks to whole rows/columns.
+ size_t n;
+ while ( ( n = m_cellSelection.GetCount() ) > 0 )
+ {
+ n--;
+ wxGridCellCoords& coords = m_cellSelection[n];
+ int row = coords.GetRow();
+ int col = coords.GetCol();
+ m_cellSelection.RemoveAt(n);
+ if (selmode == wxGrid::wxGridSelectRows)
+ SelectRow( row );
+ else // selmode == wxGridSelectColumns)
+ SelectCol( col );
+ }
+
+ for (n = 0; n < m_blockSelectionTopLeft.GetCount(); n++)
+ // Note that m_blockSelectionTopLeft's size may be changing!
+ {
+ wxGridCellCoords& coords = m_blockSelectionTopLeft[n];
+ int topRow = coords.GetRow();
+ int leftCol = coords.GetCol();
+ coords = m_blockSelectionBottomRight[n];
+ int bottomRow = coords.GetRow();
+ int rightCol = coords.GetCol();
+ if (selmode == wxGrid::wxGridSelectRows)
+ {
+ if (leftCol != 0 || rightCol != m_grid->GetNumberCols() - 1 )
+ {
+ m_blockSelectionTopLeft.RemoveAt(n);
+ m_blockSelectionBottomRight.RemoveAt(n);
+ SelectBlock( topRow, 0,
+ bottomRow, m_grid->GetNumberCols() - 1,
+ FALSE, FALSE, FALSE, FALSE, FALSE );
+ }
+ }
+ else // selmode == wxGridSelectColumns)
+ {
+ if (topRow != 0 || bottomRow != m_grid->GetNumberRows() - 1 )
+ {
+ m_blockSelectionTopLeft.RemoveAt(n);
+ m_blockSelectionBottomRight.RemoveAt(n);
+ SelectBlock( 0, leftCol,
+ m_grid->GetNumberRows() - 1, rightCol,
+ FALSE, FALSE, FALSE, FALSE, FALSE );
+ }
+ }
+ }
+ m_selectionMode = selmode;
+ }
+}
+
+void wxGridSelection::SelectRow( int row,
+ bool ControlDown, bool ShiftDown,
+ bool AltDown, bool MetaDown )