// Internal Helper function for computing row or column from some
// (unscrolled) coordinate value, using either
-// m_defaultRowHeight/m_defaultColWidth or binary search on array
+// m_defaultRowHeight/m_defaultColWidth or binary search on array
// of m_rowBottoms/m_ColRights to speed up the search!
// Internal helper macros for simpler use of that function
// create the type registry
m_typeRegistry = new wxGridTypeRegistry;
- m_selection = 0;
+ m_selection = NULL;
+
// subwindow components that make up the wxGrid
m_cornerLabelWin = new wxGridCornerLabelWindow( this,
-1,
if ( m_created )
{
// RD: Actually, this should probably be allowed. I think it would be
- // nice to be able to switch multiple Tables in and out of a single
- // View at runtime. Is there anything in the implmentation that would
- // prevent this?
+ // nice to be able to switch multiple Tables in and out of a single
+ // View at runtime. Is there anything in the implementation that
+ // would prevent this?
// At least, you now have to cope with m_selection
wxFAIL_MSG( wxT("wxGrid::CreateGrid or wxGrid::SetTable called more than once") );
//
SetCurrentCell( 0, 0 );
}
- m_selection->UpdateRows( pos, numRows );
+
+ if ( m_selection )
+ m_selection->UpdateRows( pos, numRows );
wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider();
if (attrProvider)
attrProvider->UpdateAttrRows( pos, numRows );
if ( m_currentCellCoords.GetRow() >= m_numRows )
m_currentCellCoords.Set( 0, 0 );
}
- m_selection->UpdateRows( pos, -((int)numRows) );
+
+ if ( m_selection )
+ m_selection->UpdateRows( pos, -((int)numRows) );
wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider();
if (attrProvider) {
attrProvider->UpdateAttrRows( pos, -((int)numRows) );
//
SetCurrentCell( 0, 0 );
}
- m_selection->UpdateCols( pos, numCols );
+
+ if ( m_selection )
+ m_selection->UpdateCols( pos, numCols );
wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider();
if (attrProvider)
attrProvider->UpdateAttrCols( pos, numCols );
if ( m_currentCellCoords.GetCol() >= m_numCols )
m_currentCellCoords.Set( 0, 0 );
}
- m_selection->UpdateCols( pos, -((int)numCols) );
+
+ if ( m_selection )
+ m_selection->UpdateCols( pos, -((int)numCols) );
wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider();
if (attrProvider) {
attrProvider->UpdateAttrCols( pos, -((int)numCols) );
if ( event.Dragging() )
{
- m_isDragging = TRUE;
+ if (!m_isDragging)
+ {
+ m_isDragging = TRUE;
+ m_rowLabelWin->CaptureMouse();
+ }
if ( event.LeftIsDown() )
{
case WXGRID_CURSOR_SELECT_ROW:
if ( (row = YToRow( y )) >= 0 )
{
- m_selection->SelectRow( row,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ if ( m_selection )
+ {
+ m_selection->SelectRow( row,
+ event.ControlDown(),
+ event.ShiftDown(),
+ event.AltDown(),
+ event.MetaDown() );
+ }
}
// default label to suppress warnings about "enumeration value
return;
}
- m_isDragging = FALSE;
+ if ( m_isDragging && (event.Entering() || event.Leaving()) )
+ return;
+ if (m_isDragging)
+ {
+ if (m_rowLabelWin->HasCapture()) m_rowLabelWin->ReleaseMouse();
+ m_isDragging = FALSE;
+ }
// ------------ Entering or leaving the window
//
{
if ( !event.ShiftDown() && !event.ControlDown() )
ClearSelection();
- if ( event.ShiftDown() )
- m_selection->SelectBlock( m_currentCellCoords.GetRow(),
- 0,
- row,
- GetNumberCols() - 1,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
- else
- m_selection->SelectRow( row,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ else if ( m_selection )
+ {
+ if ( event.ShiftDown() )
+ {
+ m_selection->SelectBlock( m_currentCellCoords.GetRow(),
+ 0,
+ row,
+ GetNumberCols() - 1,
+ event.ControlDown(),
+ event.ShiftDown(),
+ event.AltDown(),
+ event.MetaDown() );
+ }
+ else
+ {
+ m_selection->SelectRow( row,
+ event.ControlDown(),
+ event.ShiftDown(),
+ event.AltDown(),
+ event.MetaDown() );
+ }
+ }
+
ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW, m_rowLabelWin);
}
}
if ( event.Dragging() )
{
- m_isDragging = TRUE;
+ if (!m_isDragging)
+ {
+ m_isDragging = TRUE;
+ m_colLabelWin->CaptureMouse();
+ }
if ( event.LeftIsDown() )
{
case WXGRID_CURSOR_SELECT_COL:
if ( (col = XToCol( x )) >= 0 )
{
- m_selection->SelectCol( col,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ if ( m_selection )
+ {
+ m_selection->SelectCol( col,
+ event.ControlDown(),
+ event.ShiftDown(),
+ event.AltDown(),
+ event.MetaDown() );
+ }
}
// default label to suppress warnings about "enumeration value
return;
}
- m_isDragging = FALSE;
+ if ( m_isDragging && (event.Entering() || event.Leaving()) )
+ return;
+ if (m_isDragging)
+ {
+ if (m_colLabelWin->HasCapture()) m_colLabelWin->ReleaseMouse();
+ m_isDragging = FALSE;
+ }
// ------------ Entering or leaving the window
//
{
if ( !event.ShiftDown() && !event.ControlDown() )
ClearSelection();
- if ( event.ShiftDown() )
- m_selection->SelectBlock( 0,
- m_currentCellCoords.GetCol(),
- GetNumberRows() - 1, col,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
- else
- m_selection->SelectCol( col,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ if ( m_selection )
+ {
+ if ( event.ShiftDown() )
+ {
+ m_selection->SelectBlock( 0,
+ m_currentCellCoords.GetCol(),
+ GetNumberRows() - 1, col,
+ event.ControlDown(),
+ event.ShiftDown(),
+ event.AltDown(),
+ event.MetaDown() );
+ }
+ else
+ {
+ m_selection->SelectCol( col,
+ event.ControlDown(),
+ event.ShiftDown(),
+ event.AltDown(),
+ event.MetaDown() );
+ }
+ }
+
ChangeCursorMode(WXGRID_CURSOR_SELECT_COL, m_colLabelWin);
}
}
if ( m_winCapture )
{
- m_winCapture->ReleaseMouse();
+ if (m_winCapture->HasCapture()) m_winCapture->ReleaseMouse();
m_winCapture = (wxWindow *)NULL;
}
ClearSelection();
if ( event.ShiftDown() )
{
- m_selection->SelectBlock( m_currentCellCoords.GetRow(),
- m_currentCellCoords.GetCol(),
- coords.GetRow(),
- coords.GetCol(),
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ if ( m_selection )
+ {
+ m_selection->SelectBlock( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol(),
+ coords.GetRow(),
+ coords.GetCol(),
+ event.ControlDown(),
+ event.ShiftDown(),
+ event.AltDown(),
+ event.MetaDown() );
+ }
}
else if ( XToEdgeOfCol(x) < 0 &&
YToEdgeOfRow(y) < 0 )
{
if ( event.ControlDown() )
{
- m_selection->ToggleCellSelection( coords.GetRow(),
- coords.GetCol(),
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ if ( m_selection )
+ {
+ m_selection->ToggleCellSelection( coords.GetRow(),
+ coords.GetCol(),
+ event.ControlDown(),
+ event.ShiftDown(),
+ event.AltDown(),
+ event.MetaDown() );
+ }
m_selectingTopLeft = wxGridNoCellCoords;
m_selectingBottomRight = wxGridNoCellCoords;
m_selectingKeyboard = coords;
else
{
SetCurrentCell( coords );
- if ( m_selection->GetSelectionMode()
- != wxGrid::wxGridSelectCells)
- HighlightBlock( coords, coords );
+ if ( m_selection )
+ {
+ if ( m_selection->GetSelectionMode() !=
+ wxGrid::wxGridSelectCells )
+ {
+ HighlightBlock( coords, coords );
+ }
+ }
}
m_waitForSlowClick = TRUE;
}
{
if (m_winCapture)
{
- m_winCapture->ReleaseMouse();
+ if (m_winCapture->HasCapture()) m_winCapture->ReleaseMouse();
m_winCapture = NULL;
}
- m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
- m_selectingTopLeft.GetCol(),
- m_selectingBottomRight.GetRow(),
- m_selectingBottomRight.GetCol(),
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+
+ if ( m_selection )
+ {
+ m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
+ m_selectingTopLeft.GetCol(),
+ m_selectingBottomRight.GetRow(),
+ m_selectingBottomRight.GetCol(),
+ event.ControlDown(),
+ event.ShiftDown(),
+ event.AltDown(),
+ event.MetaDown() );
+ }
+
m_selectingTopLeft = wxGridNoCellCoords;
m_selectingBottomRight = wxGridNoCellCoords;
}
case WXK_SPACE:
if ( event.ControlDown() )
{
- m_selection->ToggleCellSelection( m_currentCellCoords.GetRow(),
- m_currentCellCoords.GetCol(),
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ if ( m_selection )
+ {
+ m_selection->ToggleCellSelection( m_currentCellCoords.GetRow(),
+ m_currentCellCoords.GetCol(),
+ event.ControlDown(),
+ event.ShiftDown(),
+ event.AltDown(),
+ event.MetaDown() );
+ }
break;
}
if ( !IsEditable() )
{
if ( m_selectingTopLeft != wxGridNoCellCoords &&
m_selectingBottomRight != wxGridNoCellCoords )
- m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
- m_selectingTopLeft.GetCol(),
- m_selectingBottomRight.GetRow(),
- m_selectingBottomRight.GetCol(),
- event.ControlDown(),
- TRUE,
- event.AltDown(),
- event.MetaDown() );
+ {
+ if ( m_selection )
+ {
+ m_selection->SelectBlock( m_selectingTopLeft.GetRow(),
+ m_selectingTopLeft.GetCol(),
+ m_selectingBottomRight.GetRow(),
+ m_selectingBottomRight.GetCol(),
+ event.ControlDown(),
+ TRUE,
+ event.AltDown(),
+ event.MetaDown() );
+ }
+ }
+
m_selectingTopLeft = wxGridNoCellCoords;
m_selectingBottomRight = wxGridNoCellCoords;
m_selectingKeyboard = wxGridNoCellCoords;
int temp;
wxGridCellCoords updateTopLeft, updateBottomRight;
- if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectRows )
- {
- leftCol = 0;
- rightCol = GetNumberCols() - 1;
- }
- else if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectColumns )
+ if ( m_selection )
{
- topRow = 0;
- bottomRow = GetNumberRows() - 1;
+ 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;
// cell is shifted by one pixel
// However, don't allow x or y to become negative
- // since the SetSize() method interprets that as
+ // since the SetSize() method interprets that as
// "don't change."
if (rect.x > 0)
rect.x--;
// Internal Helper function for computing row or column from some
// (unscrolled) coordinate value, using either
-// m_defaultRowHeight/m_defaultColWidth or binary search on array
+// m_defaultRowHeight/m_defaultColWidth or binary search on array
// of m_rowBottoms/m_ColRights to speed up the search!
static int CoordToRowOrCol(int coord, int defaultDist, int minDist,
if ( i_max >= BorderArray.GetCount())
i_max = BorderArray.GetCount() - 1;
- else
+ else
{
if ( coord >= BorderArray[i_max])
{
if ( IsSelection() && !addToSelected )
ClearSelection();
- m_selection->SelectRow( row, FALSE, addToSelected );
+ if ( m_selection )
+ m_selection->SelectRow( row, FALSE, addToSelected );
}
if ( IsSelection() && !addToSelected )
ClearSelection();
- m_selection->SelectCol( col, FALSE, addToSelected );
+ if ( m_selection )
+ m_selection->SelectCol( col, FALSE, addToSelected );
}
if ( IsSelection() && !addToSelected )
ClearSelection();
- m_selection->SelectBlock( topRow, leftCol, bottomRow, rightCol,
- FALSE, addToSelected );
+ if ( m_selection )
+ m_selection->SelectBlock( topRow, leftCol, bottomRow, rightCol,
+ FALSE, addToSelected );
}
void wxGrid::SelectAll()
{
if ( m_numRows > 0 && m_numCols > 0 )
- m_selection->SelectBlock( 0, 0, m_numRows-1, m_numCols-1 );
+ {
+ if ( m_selection )
+ m_selection->SelectBlock( 0, 0, m_numRows-1, m_numCols-1 );
+ }
}
//
void wxGrid::DeselectRow( int row )
{
+ if ( !m_selection )
+ return;
+
if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectRows )
{
if ( m_selection->IsInSelection(row, 0 ) )
void wxGrid::DeselectCol( int col )
{
+ if ( !m_selection )
+ return;
+
if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectColumns )
{
if ( m_selection->IsInSelection(0, col ) )
void wxGrid::DeselectCell( int row, int col )
{
- if ( m_selection->IsInSelection(row, col) )
+ if ( m_selection && m_selection->IsInSelection(row, col) )
m_selection->ToggleCellSelection(row, col);
}
bool wxGrid::IsSelection()
{
- return ( m_selection->IsSelection() ||
+ return ( m_selection && (m_selection->IsSelection() ||
( m_selectingTopLeft != wxGridNoCellCoords &&
- m_selectingBottomRight != wxGridNoCellCoords ) );
+ m_selectingBottomRight != wxGridNoCellCoords) ) );
}
bool wxGrid::IsInSelection( int row, int col )
{
- return ( m_selection->IsInSelection( row, col ) ||
+ return ( m_selection && (m_selection->IsInSelection( row, col ) ||
( row >= m_selectingTopLeft.GetRow() &&
col >= m_selectingTopLeft.GetCol() &&
row <= m_selectingBottomRight.GetRow() &&
- col <= m_selectingBottomRight.GetCol() ) );
+ col <= m_selectingBottomRight.GetCol() )) );
}
void wxGrid::ClearSelection()
{
m_selectingTopLeft = wxGridNoCellCoords;
m_selectingBottomRight = wxGridNoCellCoords;
- m_selection->ClearSelection();
+ if ( m_selection )
+ m_selection->ClearSelection();
}