- //wxLogDebug("pos(%d, %d) coords(%d, %d)", pos.x, pos.y, coords.GetRow(), coords.GetCol());
-
- // Don't start doing anything until the mouse has been drug at
- // least 3 pixels in any direction...
- if (! m_isDragging)
- {
- if (m_startDragPos == wxDefaultPosition)
- {
- m_startDragPos = pos;
- return;
- }
- if (abs(m_startDragPos.x - pos.x) < 4 && abs(m_startDragPos.y - pos.y) < 4)
- return;
- }
-
- m_isDragging = TRUE;
- if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
- {
- // Hide the edit control, so it
- // won't interfer with drag-shrinking.
- if ( IsCellEditControlEnabled() )
- HideCellEditControl();
-
- // Have we captured the mouse yet?
- if (! m_winCapture)
- {
- m_winCapture = m_gridWin;
- m_winCapture->CaptureMouse();
- }
-
- if ( coords != wxGridNoCellCoords )
- {
- if ( !IsSelection() )
- {
- SelectBlock( coords, coords );
- }
- else
- {
- SelectBlock( m_currentCellCoords, coords );
- }
-
- if (! IsVisible(coords))
- {
- MakeCellVisible(coords);
- // TODO: need to introduce a delay or something here. The
- // scrolling is way to fast, at least on MSW.
- }
- }
- }
- else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
- {
- int cw, ch, left, dummy;
- m_gridWin->GetClientSize( &cw, &ch );
- CalcUnscrolledPosition( 0, 0, &left, &dummy );
-
- wxClientDC dc( m_gridWin );
- PrepareDC( dc );
- y = wxMax( y, GetRowTop(m_dragRowOrCol) + WXGRID_MIN_ROW_HEIGHT );
- dc.SetLogicalFunction(wxINVERT);
- if ( m_dragLastPos >= 0 )
- {
- dc.DrawLine( left, m_dragLastPos, left+cw, m_dragLastPos );
- }
- dc.DrawLine( left, y, left+cw, y );
- m_dragLastPos = y;
- }
- else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
- {
- int cw, ch, dummy, top;
- m_gridWin->GetClientSize( &cw, &ch );
- CalcUnscrolledPosition( 0, 0, &dummy, &top );
-
- wxClientDC dc( m_gridWin );
- PrepareDC( dc );
- x = wxMax( x, GetColLeft(m_dragRowOrCol) +
- GetColMinimalWidth(m_dragRowOrCol) );
- dc.SetLogicalFunction(wxINVERT);
- if ( m_dragLastPos >= 0 )
- {
- dc.DrawLine( m_dragLastPos, top, m_dragLastPos, top+ch );
- }
- dc.DrawLine( x, top, x, top+ch );
- m_dragLastPos = x;
- }
-
- return;
- }
-
- m_isDragging = FALSE;
- m_startDragPos = wxDefaultPosition;
-
-// if ( coords == wxGridNoCellCoords && m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
-// {
-// ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
-// }
-
-// if ( coords != wxGridNoCellCoords )
-// {
- // VZ: if we do this, the mode is reset to WXGRID_CURSOR_SELECT_CELL
- // immediately after it becomes WXGRID_CURSOR_RESIZE_ROW/COL under
- // wxGTK
-#if 0
- if ( event.Entering() || event.Leaving() )
- {
- ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
- m_gridWin->SetCursor( *wxSTANDARD_CURSOR );
- }
- else
-#endif // 0
-
- // ------------ Left button pressed
- //
- if ( event.LeftDown() && coords != wxGridNoCellCoords )
- {
- DisableCellEditControl();
- if ( event.ShiftDown() )
- {
- SelectBlock( m_currentCellCoords, coords );
- }
- else if ( XToEdgeOfCol(x) < 0 &&
- YToEdgeOfRow(y) < 0 )
- {
- if ( !SendEvent( wxEVT_GRID_CELL_LEFT_CLICK,
- coords.GetRow(),
- coords.GetCol(),
- event ) )
- {
- MakeCellVisible( coords );
-
- // if this is the second click on this cell then start
- // the edit control
- if ( m_waitForSlowClick &&
- (coords == m_currentCellCoords) &&
- CanEnableCellControl())
- {
- EnableCellEditControl();
-
- wxGridCellAttr* attr = GetCellAttr(m_currentCellCoords);
- attr->GetEditor(this, coords.GetRow(), coords.GetCol())->StartingClick();
- attr->DecRef();
-
- m_waitForSlowClick = FALSE;
- }
- else
- {
- SetCurrentCell( coords );
- m_waitForSlowClick = TRUE;
- }
- }
- }
- }
-
-
- // ------------ Left double click
- //
- else if ( event.LeftDClick() && coords != wxGridNoCellCoords )
- {
- DisableCellEditControl();
- if ( XToEdgeOfCol(x) < 0 && YToEdgeOfRow(y) < 0 )
- {
- SendEvent( wxEVT_GRID_CELL_LEFT_DCLICK,
- coords.GetRow(),
- coords.GetCol(),
- event );
- }
- }
-
-
- // ------------ Left button released
- //
- else if ( event.LeftUp() )
- {
- if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
- {
- if ( IsSelection() )
- {
- if (m_winCapture)
- {
- m_winCapture->ReleaseMouse();
- m_winCapture = NULL;
- }
- SendEvent( wxEVT_GRID_RANGE_SELECT, -1, -1, event );
- }
-
- // Show the edit control, if it has been hidden for
- // drag-shrinking.
- ShowCellEditControl();
- }
- else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
- {
- ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
- DoEndDragResizeRow();
-
- // Note: we are ending the event *after* doing
- // default processing in this case
- //
- SendEvent( wxEVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event );
- }
- else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
- {
- ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
- DoEndDragResizeCol();
-
- // Note: we are ending the event *after* doing
- // default processing in this case
- //
- SendEvent( wxEVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event );
- }
-
- m_dragLastPos = -1;
- }
-
-
- // ------------ Right button down
- //
- else if ( event.RightDown() && coords != wxGridNoCellCoords )
- {
- DisableCellEditControl();
- if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_CLICK,
- coords.GetRow(),
- coords.GetCol(),
- event ) )
- {
- // no default action at the moment
- }
- }
-
-
- // ------------ Right double click
- //
- else if ( event.RightDClick() && coords != wxGridNoCellCoords )
- {
- DisableCellEditControl();
- if ( !SendEvent( wxEVT_GRID_CELL_RIGHT_DCLICK,
- coords.GetRow(),
- coords.GetCol(),
- event ) )
- {
- // no default action at the moment
- }
- }
-
- // ------------ Moving and no button action
- //
- else if ( event.Moving() && !event.IsButton() )
- {
- int dragRow = YToEdgeOfRow( y );
- int dragCol = XToEdgeOfCol( x );
-
- // Dragging on the corner of a cell to resize in both
- // directions is not implemented yet...
- //
- if ( dragRow >= 0 && dragCol >= 0 )
- {
- ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
- return;
- }
-
- if ( dragRow >= 0 )
- {
- m_dragRowOrCol = dragRow;
-
- if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
- {
- if ( CanDragRowSize() && CanDragGridSize() )
- ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW);
- }
-
- return;
- }
-
- if ( dragCol >= 0 )
- {
- m_dragRowOrCol = dragCol;
-
- if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
- {
- if ( CanDragColSize() && CanDragGridSize() )
- ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL);
- }
-
- return;
- }
-
- // Neither on a row or col edge
- //
- if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
- {
- ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
- }
- }
-}
-