Renamed existing wxGrid::SelectBlock to HighlightBlock.
Added new wxGrid::SelectBlock that does what the name suggests (consistent with the other SelectXXX functions). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@7890 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1300,12 +1300,15 @@ public:
|
|||||||
void SelectRow( int row, bool addToSelected = FALSE );
|
void SelectRow( int row, bool addToSelected = FALSE );
|
||||||
void SelectCol( int col, bool addToSelected = FALSE );
|
void SelectCol( int col, bool addToSelected = FALSE );
|
||||||
|
|
||||||
void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol );
|
void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
|
||||||
|
bool addToSelected = FALSE );
|
||||||
|
|
||||||
void SelectBlock( const wxGridCellCoords& topLeft,
|
void SelectBlock( const wxGridCellCoords& topLeft,
|
||||||
const wxGridCellCoords& bottomRight )
|
const wxGridCellCoords& bottomRight,
|
||||||
|
bool addToSelected = FALSE )
|
||||||
{ SelectBlock( topLeft.GetRow(), topLeft.GetCol(),
|
{ SelectBlock( topLeft.GetRow(), topLeft.GetCol(),
|
||||||
bottomRight.GetRow(), bottomRight.GetCol() ); }
|
bottomRight.GetRow(), bottomRight.GetCol(),
|
||||||
|
addToSelected ); }
|
||||||
|
|
||||||
void SelectAll();
|
void SelectAll();
|
||||||
|
|
||||||
@@ -1734,6 +1737,12 @@ protected:
|
|||||||
void SetCurrentCell( int row, int col )
|
void SetCurrentCell( int row, int col )
|
||||||
{ SetCurrentCell( wxGridCellCoords(row, col) ); }
|
{ SetCurrentCell( wxGridCellCoords(row, col) ); }
|
||||||
|
|
||||||
|
void HighlightBlock( int topRow, int leftCol, int bottomRow, int rightCol );
|
||||||
|
|
||||||
|
void HighlightBlock( const wxGridCellCoords& topLeft,
|
||||||
|
const wxGridCellCoords& bottomRight )
|
||||||
|
{ HighlightBlock( topLeft.GetRow(), topLeft.GetCol(),
|
||||||
|
bottomRight.GetRow(), bottomRight.GetCol() ); }
|
||||||
|
|
||||||
// ------ functions to get/send data (see also public functions)
|
// ------ functions to get/send data (see also public functions)
|
||||||
//
|
//
|
||||||
|
@@ -4674,17 +4674,17 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
|||||||
{
|
{
|
||||||
if ( m_selectingKeyboard == wxGridNoCellCoords)
|
if ( m_selectingKeyboard == wxGridNoCellCoords)
|
||||||
m_selectingKeyboard = coords;
|
m_selectingKeyboard = coords;
|
||||||
SelectBlock ( m_selectingKeyboard, coords );
|
HighlightBlock ( m_selectingKeyboard, coords );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( !IsSelection() )
|
if ( !IsSelection() )
|
||||||
{
|
{
|
||||||
SelectBlock( coords, coords );
|
HighlightBlock( coords, coords );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SelectBlock( m_currentCellCoords, coords );
|
HighlightBlock( m_currentCellCoords, coords );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4816,7 +4816,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
|||||||
SetCurrentCell( coords );
|
SetCurrentCell( coords );
|
||||||
if ( m_selection->GetSelectionMode()
|
if ( m_selection->GetSelectionMode()
|
||||||
!= wxGrid::wxGridSelectCells)
|
!= wxGrid::wxGridSelectCells)
|
||||||
SelectBlock( coords, coords );
|
HighlightBlock( coords, coords );
|
||||||
}
|
}
|
||||||
m_waitForSlowClick = TRUE;
|
m_waitForSlowClick = TRUE;
|
||||||
}
|
}
|
||||||
@@ -5625,6 +5625,141 @@ void wxGrid::SetCurrentCell( const wxGridCellCoords& coords )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void wxGrid::HighlightBlock( int topRow, int leftCol, int bottomRow, int rightCol )
|
||||||
|
{
|
||||||
|
int temp;
|
||||||
|
wxGridCellCoords updateTopLeft, updateBottomRight;
|
||||||
|
|
||||||
|
if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectRows )
|
||||||
|
{
|
||||||
|
leftCol = 0;
|
||||||
|
rightCol = GetNumberCols() - 1;
|
||||||
|
}
|
||||||
|
else if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectColumns )
|
||||||
|
{
|
||||||
|
topRow = 0;
|
||||||
|
bottomRow = GetNumberRows() - 1;
|
||||||
|
}
|
||||||
|
if ( topRow > bottomRow )
|
||||||
|
{
|
||||||
|
temp = topRow;
|
||||||
|
topRow = bottomRow;
|
||||||
|
bottomRow = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( leftCol > rightCol )
|
||||||
|
{
|
||||||
|
temp = leftCol;
|
||||||
|
leftCol = rightCol;
|
||||||
|
rightCol = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTopLeft = wxGridCellCoords( topRow, leftCol );
|
||||||
|
updateBottomRight = wxGridCellCoords( bottomRow, rightCol );
|
||||||
|
|
||||||
|
if ( m_selectingTopLeft != updateTopLeft ||
|
||||||
|
m_selectingBottomRight != updateBottomRight )
|
||||||
|
{
|
||||||
|
// Compute two optimal update rectangles:
|
||||||
|
// Either one rectangle is a real subset of the
|
||||||
|
// other, or they are (almost) disjoint!
|
||||||
|
wxRect rect[4];
|
||||||
|
bool need_refresh[4];
|
||||||
|
need_refresh[0] =
|
||||||
|
need_refresh[1] =
|
||||||
|
need_refresh[2] =
|
||||||
|
need_refresh[3] = FALSE;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
// Store intermediate values
|
||||||
|
wxCoord oldLeft = m_selectingTopLeft.GetCol();
|
||||||
|
wxCoord oldTop = m_selectingTopLeft.GetRow();
|
||||||
|
wxCoord oldRight = m_selectingBottomRight.GetCol();
|
||||||
|
wxCoord oldBottom = m_selectingBottomRight.GetRow();
|
||||||
|
|
||||||
|
// Determine the outer/inner coordinates.
|
||||||
|
if (oldLeft > leftCol)
|
||||||
|
{
|
||||||
|
temp = oldLeft;
|
||||||
|
oldLeft = leftCol;
|
||||||
|
leftCol = temp;
|
||||||
|
}
|
||||||
|
if (oldTop > topRow )
|
||||||
|
{
|
||||||
|
temp = oldTop;
|
||||||
|
oldTop = topRow;
|
||||||
|
topRow = temp;
|
||||||
|
}
|
||||||
|
if (oldRight < rightCol )
|
||||||
|
{
|
||||||
|
temp = oldRight;
|
||||||
|
oldRight = rightCol;
|
||||||
|
rightCol = temp;
|
||||||
|
}
|
||||||
|
if (oldBottom < bottomRow)
|
||||||
|
{
|
||||||
|
temp = oldBottom;
|
||||||
|
oldBottom = bottomRow;
|
||||||
|
bottomRow = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now, either the stuff marked old is the outer
|
||||||
|
// rectangle or we don't have a situation where one
|
||||||
|
// is contained in the other.
|
||||||
|
|
||||||
|
if ( oldLeft < leftCol )
|
||||||
|
{
|
||||||
|
need_refresh[0] = TRUE;
|
||||||
|
rect[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
|
||||||
|
oldLeft ),
|
||||||
|
wxGridCellCoords ( oldBottom,
|
||||||
|
leftCol - 1 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( oldTop < topRow )
|
||||||
|
{
|
||||||
|
need_refresh[1] = TRUE;
|
||||||
|
rect[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
|
||||||
|
leftCol ),
|
||||||
|
wxGridCellCoords ( topRow - 1,
|
||||||
|
rightCol ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( oldRight > rightCol )
|
||||||
|
{
|
||||||
|
need_refresh[2] = TRUE;
|
||||||
|
rect[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
|
||||||
|
rightCol + 1 ),
|
||||||
|
wxGridCellCoords ( oldBottom,
|
||||||
|
oldRight ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( oldBottom > bottomRow )
|
||||||
|
{
|
||||||
|
need_refresh[3] = TRUE;
|
||||||
|
rect[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow + 1,
|
||||||
|
leftCol ),
|
||||||
|
wxGridCellCoords ( oldBottom,
|
||||||
|
rightCol ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Change Selection
|
||||||
|
m_selectingTopLeft = updateTopLeft;
|
||||||
|
m_selectingBottomRight = updateBottomRight;
|
||||||
|
|
||||||
|
// various Refresh() calls
|
||||||
|
for (i = 0; i < 4; i++ )
|
||||||
|
if ( need_refresh[i] && rect[i] != wxGridNoCellRect )
|
||||||
|
m_gridWin->Refresh( FALSE, &(rect[i]) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// never generate an event as it will be generated from
|
||||||
|
// wxGridSelection::SelectBlock!
|
||||||
|
// (old comment from when this was the body of SelectBlock)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// ------ functions to get/send data (see also public functions)
|
// ------ functions to get/send data (see also public functions)
|
||||||
//
|
//
|
||||||
@@ -6622,7 +6757,7 @@ bool wxGrid::MoveCursorUp( bool expandSelection )
|
|||||||
m_selectingKeyboard.SetRow( m_selectingKeyboard.GetRow() - 1 );
|
m_selectingKeyboard.SetRow( m_selectingKeyboard.GetRow() - 1 );
|
||||||
MakeCellVisible( m_selectingKeyboard.GetRow(),
|
MakeCellVisible( m_selectingKeyboard.GetRow(),
|
||||||
m_selectingKeyboard.GetCol() );
|
m_selectingKeyboard.GetCol() );
|
||||||
SelectBlock( m_currentCellCoords, m_selectingKeyboard );
|
HighlightBlock( m_currentCellCoords, m_selectingKeyboard );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( m_currentCellCoords.GetRow() > 0 )
|
else if ( m_currentCellCoords.GetRow() > 0 )
|
||||||
@@ -6656,7 +6791,7 @@ bool wxGrid::MoveCursorDown( bool expandSelection )
|
|||||||
m_selectingKeyboard.SetRow( m_selectingKeyboard.GetRow() + 1 );
|
m_selectingKeyboard.SetRow( m_selectingKeyboard.GetRow() + 1 );
|
||||||
MakeCellVisible( m_selectingKeyboard.GetRow(),
|
MakeCellVisible( m_selectingKeyboard.GetRow(),
|
||||||
m_selectingKeyboard.GetCol() );
|
m_selectingKeyboard.GetCol() );
|
||||||
SelectBlock( m_currentCellCoords, m_selectingKeyboard );
|
HighlightBlock( m_currentCellCoords, m_selectingKeyboard );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( m_currentCellCoords.GetRow() < m_numRows - 1 )
|
else if ( m_currentCellCoords.GetRow() < m_numRows - 1 )
|
||||||
@@ -6690,7 +6825,7 @@ bool wxGrid::MoveCursorLeft( bool expandSelection )
|
|||||||
m_selectingKeyboard.SetCol( m_selectingKeyboard.GetCol() - 1 );
|
m_selectingKeyboard.SetCol( m_selectingKeyboard.GetCol() - 1 );
|
||||||
MakeCellVisible( m_selectingKeyboard.GetRow(),
|
MakeCellVisible( m_selectingKeyboard.GetRow(),
|
||||||
m_selectingKeyboard.GetCol() );
|
m_selectingKeyboard.GetCol() );
|
||||||
SelectBlock( m_currentCellCoords, m_selectingKeyboard );
|
HighlightBlock( m_currentCellCoords, m_selectingKeyboard );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( m_currentCellCoords.GetCol() > 0 )
|
else if ( m_currentCellCoords.GetCol() > 0 )
|
||||||
@@ -6724,7 +6859,7 @@ bool wxGrid::MoveCursorRight( bool expandSelection )
|
|||||||
m_selectingKeyboard.SetCol( m_selectingKeyboard.GetCol() + 1 );
|
m_selectingKeyboard.SetCol( m_selectingKeyboard.GetCol() + 1 );
|
||||||
MakeCellVisible( m_selectingKeyboard.GetRow(),
|
MakeCellVisible( m_selectingKeyboard.GetRow(),
|
||||||
m_selectingKeyboard.GetCol() );
|
m_selectingKeyboard.GetCol() );
|
||||||
SelectBlock( m_currentCellCoords, m_selectingKeyboard );
|
HighlightBlock( m_currentCellCoords, m_selectingKeyboard );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( m_currentCellCoords.GetCol() < m_numCols - 1 )
|
else if ( m_currentCellCoords.GetCol() < m_numCols - 1 )
|
||||||
@@ -6854,7 +6989,7 @@ bool wxGrid::MoveCursorUpBlock( bool expandSelection )
|
|||||||
if ( expandSelection )
|
if ( expandSelection )
|
||||||
{
|
{
|
||||||
m_selectingKeyboard = wxGridCellCoords( row, col );
|
m_selectingKeyboard = wxGridCellCoords( row, col );
|
||||||
SelectBlock( m_currentCellCoords, m_selectingKeyboard );
|
HighlightBlock( m_currentCellCoords, m_selectingKeyboard );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -6917,7 +7052,7 @@ bool wxGrid::MoveCursorDownBlock( bool expandSelection )
|
|||||||
if ( expandSelection )
|
if ( expandSelection )
|
||||||
{
|
{
|
||||||
m_selectingKeyboard = wxGridCellCoords( row, col );
|
m_selectingKeyboard = wxGridCellCoords( row, col );
|
||||||
SelectBlock( m_currentCellCoords, m_selectingKeyboard );
|
HighlightBlock( m_currentCellCoords, m_selectingKeyboard );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -6981,7 +7116,7 @@ bool wxGrid::MoveCursorLeftBlock( bool expandSelection )
|
|||||||
if ( expandSelection )
|
if ( expandSelection )
|
||||||
{
|
{
|
||||||
m_selectingKeyboard = wxGridCellCoords( row, col );
|
m_selectingKeyboard = wxGridCellCoords( row, col );
|
||||||
SelectBlock( m_currentCellCoords, m_selectingKeyboard );
|
HighlightBlock( m_currentCellCoords, m_selectingKeyboard );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -7045,7 +7180,7 @@ bool wxGrid::MoveCursorRightBlock( bool expandSelection )
|
|||||||
if ( expandSelection )
|
if ( expandSelection )
|
||||||
{
|
{
|
||||||
m_selectingKeyboard = wxGridCellCoords( row, col );
|
m_selectingKeyboard = wxGridCellCoords( row, col );
|
||||||
SelectBlock( m_currentCellCoords, m_selectingKeyboard );
|
HighlightBlock( m_currentCellCoords, m_selectingKeyboard );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -8111,139 +8246,17 @@ void wxGrid::SelectCol( int col, bool addToSelected )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol )
|
void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
|
||||||
|
bool addToSelected )
|
||||||
{
|
{
|
||||||
int temp;
|
if ( IsSelection() && !addToSelected )
|
||||||
wxGridCellCoords updateTopLeft, updateBottomRight;
|
ClearSelection();
|
||||||
|
|
||||||
if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectRows )
|
m_selection->SelectBlock( topRow, leftCol, bottomRow, rightCol,
|
||||||
{
|
FALSE, addToSelected );
|
||||||
leftCol = 0;
|
|
||||||
rightCol = GetNumberCols() - 1;
|
|
||||||
}
|
|
||||||
else if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectColumns )
|
|
||||||
{
|
|
||||||
topRow = 0;
|
|
||||||
bottomRow = GetNumberRows() - 1;
|
|
||||||
}
|
|
||||||
if ( topRow > bottomRow )
|
|
||||||
{
|
|
||||||
temp = topRow;
|
|
||||||
topRow = bottomRow;
|
|
||||||
bottomRow = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( leftCol > rightCol )
|
|
||||||
{
|
|
||||||
temp = leftCol;
|
|
||||||
leftCol = rightCol;
|
|
||||||
rightCol = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateTopLeft = wxGridCellCoords( topRow, leftCol );
|
|
||||||
updateBottomRight = wxGridCellCoords( bottomRow, rightCol );
|
|
||||||
|
|
||||||
if ( m_selectingTopLeft != updateTopLeft ||
|
|
||||||
m_selectingBottomRight != updateBottomRight )
|
|
||||||
{
|
|
||||||
// Compute two optimal update rectangles:
|
|
||||||
// Either one rectangle is a real subset of the
|
|
||||||
// other, or they are (almost) disjoint!
|
|
||||||
wxRect rect[4];
|
|
||||||
bool need_refresh[4];
|
|
||||||
need_refresh[0] =
|
|
||||||
need_refresh[1] =
|
|
||||||
need_refresh[2] =
|
|
||||||
need_refresh[3] = FALSE;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
// Store intermediate values
|
|
||||||
wxCoord oldLeft = m_selectingTopLeft.GetCol();
|
|
||||||
wxCoord oldTop = m_selectingTopLeft.GetRow();
|
|
||||||
wxCoord oldRight = m_selectingBottomRight.GetCol();
|
|
||||||
wxCoord oldBottom = m_selectingBottomRight.GetRow();
|
|
||||||
|
|
||||||
// Determine the outer/inner coordinates.
|
|
||||||
if (oldLeft > leftCol)
|
|
||||||
{
|
|
||||||
temp = oldLeft;
|
|
||||||
oldLeft = leftCol;
|
|
||||||
leftCol = temp;
|
|
||||||
}
|
|
||||||
if (oldTop > topRow )
|
|
||||||
{
|
|
||||||
temp = oldTop;
|
|
||||||
oldTop = topRow;
|
|
||||||
topRow = temp;
|
|
||||||
}
|
|
||||||
if (oldRight < rightCol )
|
|
||||||
{
|
|
||||||
temp = oldRight;
|
|
||||||
oldRight = rightCol;
|
|
||||||
rightCol = temp;
|
|
||||||
}
|
|
||||||
if (oldBottom < bottomRow)
|
|
||||||
{
|
|
||||||
temp = oldBottom;
|
|
||||||
oldBottom = bottomRow;
|
|
||||||
bottomRow = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now, either the stuff marked old is the outer
|
|
||||||
// rectangle or we don't have a situation where one
|
|
||||||
// is contained in the other.
|
|
||||||
|
|
||||||
if ( oldLeft < leftCol )
|
|
||||||
{
|
|
||||||
need_refresh[0] = TRUE;
|
|
||||||
rect[0] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
|
|
||||||
oldLeft ),
|
|
||||||
wxGridCellCoords ( oldBottom,
|
|
||||||
leftCol - 1 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( oldTop < topRow )
|
|
||||||
{
|
|
||||||
need_refresh[1] = TRUE;
|
|
||||||
rect[1] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
|
|
||||||
leftCol ),
|
|
||||||
wxGridCellCoords ( topRow - 1,
|
|
||||||
rightCol ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( oldRight > rightCol )
|
|
||||||
{
|
|
||||||
need_refresh[2] = TRUE;
|
|
||||||
rect[2] = BlockToDeviceRect( wxGridCellCoords ( oldTop,
|
|
||||||
rightCol + 1 ),
|
|
||||||
wxGridCellCoords ( oldBottom,
|
|
||||||
oldRight ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( oldBottom > bottomRow )
|
|
||||||
{
|
|
||||||
need_refresh[3] = TRUE;
|
|
||||||
rect[3] = BlockToDeviceRect( wxGridCellCoords ( bottomRow + 1,
|
|
||||||
leftCol ),
|
|
||||||
wxGridCellCoords ( oldBottom,
|
|
||||||
rightCol ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Change Selection
|
|
||||||
m_selectingTopLeft = updateTopLeft;
|
|
||||||
m_selectingBottomRight = updateBottomRight;
|
|
||||||
|
|
||||||
// various Refresh() calls
|
|
||||||
for (i = 0; i < 4; i++ )
|
|
||||||
if ( need_refresh[i] && rect[i] != wxGridNoCellRect )
|
|
||||||
m_gridWin->Refresh( FALSE, &(rect[i]) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// never generate an event as it will be generated from
|
|
||||||
// wxGridSelection::SelectBlock!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wxGrid::SelectAll()
|
void wxGrid::SelectAll()
|
||||||
{
|
{
|
||||||
m_selection->SelectBlock( 0, 0, m_numRows-1, m_numCols-1 );
|
m_selection->SelectBlock( 0, 0, m_numRows-1, m_numCols-1 );
|
||||||
|
Reference in New Issue
Block a user