m_gridLinesEnabled = TRUE;
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
+ m_winCapture = (wxWindow *)NULL;
m_dragLastPos = -1;
m_dragRowOrCol = -1;
m_isDragging = FALSE;
break;
case WXGRID_CURSOR_SELECT_ROW:
- {
if ( (row = YToRow( y )) >= 0 &&
!IsInSelection( row, 0 ) )
{
SelectRow( row, TRUE );
}
- }
- break;
+
+ // default label to suppress warnings about "enumeration value
+ // 'xxx' not handled in switch
+ default:
+ break;
}
}
return;
//
if ( event.Entering() || event.Leaving() )
{
- m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
- m_rowLabelWin->SetCursor( *wxSTANDARD_CURSOR );
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin);
}
-
+
// ------------ Left button pressed
//
else if ( event.LeftDown() )
!SendEvent( EVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) )
{
SelectRow( row, event.ShiftDown() );
- m_cursorMode = WXGRID_CURSOR_SELECT_ROW;
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW, m_rowLabelWin);
}
}
else
{
// starting to drag-resize a row
//
- m_rowLabelWin->CaptureMouse();
+ ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, m_rowLabelWin);
}
}
{
if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
{
- m_rowLabelWin->ReleaseMouse();
DoEndDragResizeRow();
// Note: we are ending the event *after* doing
SendEvent( EVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event );
}
- m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
- m_dragLastPos = -1;
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin);
+ m_dragLastPos = -1;
}
{
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
- m_cursorMode = WXGRID_CURSOR_RESIZE_ROW;
- m_rowLabelWin->SetCursor( m_rowResizeCursor );
+ // don't capture the mouse yet
+ ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, m_rowLabelWin, FALSE);
}
}
else if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
{
- m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
- m_rowLabelWin->SetCursor( *wxSTANDARD_CURSOR );
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin, FALSE);
}
}
}
break;
case WXGRID_CURSOR_SELECT_COL:
- {
if ( (col = XToCol( x )) >= 0 &&
!IsInSelection( 0, col ) )
{
SelectCol( col, TRUE );
}
- }
- break;
+
+ // default label to suppress warnings about "enumeration value
+ // 'xxx' not handled in switch
+ default:
+ break;
}
}
return;
//
if ( event.Entering() || event.Leaving() )
{
- m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
- m_colLabelWin->SetCursor( *wxSTANDARD_CURSOR );
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin);
}
-
+
// ------------ Left button pressed
//
else if ( event.LeftDown() )
!SendEvent( EVT_GRID_LABEL_LEFT_CLICK, -1, col, event ) )
{
SelectCol( col, event.ShiftDown() );
- m_cursorMode = WXGRID_CURSOR_SELECT_COL;
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_COL, m_colLabelWin);
}
}
else
{
// starting to drag-resize a col
//
- m_colLabelWin->CaptureMouse();
+ ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL, m_colLabelWin);
}
}
{
if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
{
- m_colLabelWin->ReleaseMouse();
DoEndDragResizeCol();
-
+
// Note: we are ending the event *after* doing
// default processing in this case
//
SendEvent( EVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event );
}
- m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin);
m_dragLastPos = -1;
}
{
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
- m_cursorMode = WXGRID_CURSOR_RESIZE_COL;
- m_colLabelWin->SetCursor( m_colResizeCursor );
+ // don't capture the cursor yet
+ ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL, m_colLabelWin, FALSE);
}
}
else if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
{
- m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
- m_colLabelWin->SetCursor( *wxSTANDARD_CURSOR );
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin, FALSE);
}
}
}
}
}
+void wxGrid::ChangeCursorMode(CursorMode mode,
+ wxWindow *win,
+ bool captureMouse)
+{
+#ifdef __WXDEBUG__
+ static const wxChar *cursorModes[] =
+ {
+ _T("SELECT_CELL"),
+ _T("RESIZE_ROW"),
+ _T("RESIZE_COL"),
+ _T("SELECT_ROW"),
+ _T("SELECT_COL")
+ };
+
+ wxLogDebug(_T("wxGrid cursor mode (mouse capture for %s): %s -> %s"),
+ win == m_colLabelWin ? _T("colLabelWin")
+ : win ? _T("rowLabelWin")
+ : _T("gridWin"),
+ cursorModes[m_cursorMode], cursorModes[mode]);
+#endif // __WXDEBUG__
+
+ if ( mode == m_cursorMode )
+ return;
+
+ if ( !win )
+ {
+ // by default use the grid itself
+ win = m_gridWin;
+ }
+
+ if ( m_winCapture )
+ {
+ m_winCapture->ReleaseMouse();
+ m_winCapture = (wxWindow *)NULL;
+ }
+
+ m_cursorMode = mode;
+
+ switch ( m_cursorMode )
+ {
+ case WXGRID_CURSOR_RESIZE_ROW:
+ win->SetCursor( m_rowResizeCursor );
+ break;
+
+ case WXGRID_CURSOR_RESIZE_COL:
+ win->SetCursor( m_colResizeCursor );
+ break;
+
+ default:
+ win->SetCursor( *wxSTANDARD_CURSOR );
+ }
+
+ // we need to capture mouse when resizing
+ bool resize = m_cursorMode == WXGRID_CURSOR_RESIZE_ROW ||
+ m_cursorMode == WXGRID_CURSOR_RESIZE_COL;
+
+ if ( captureMouse && resize )
+ {
+ win->CaptureMouse();
+ m_winCapture = win;
+ }
+}
void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
{
int cw, ch, dummy, top;
m_gridWin->GetClientSize( &cw, &ch );
CalcUnscrolledPosition( 0, 0, &dummy, &top );
-
+
wxClientDC dc( m_gridWin );
PrepareDC( dc );
dc.SetLogicalFunction(wxINVERT);
dc.DrawLine( x, top, x, top+ch );
m_dragLastPos = x;
}
-
+
return;
}
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() )
{
- m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
m_gridWin->SetCursor( *wxSTANDARD_CURSOR );
}
-
+ else
+#endif // 0
+
// ------------ Left button pressed
//
- else if ( event.LeftDown() )
+ if ( event.LeftDown() )
{
if ( event.ShiftDown() )
{
}
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
{
- m_gridWin->ReleaseMouse();
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
DoEndDragResizeRow();
// Note: we are ending the event *after* doing
}
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
{
- m_gridWin->ReleaseMouse();
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
DoEndDragResizeCol();
-
+
// Note: we are ending the event *after* doing
// default processing in this case
//
SendEvent( EVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event );
}
-
+
m_dragLastPos = -1;
}
//
if ( dragRow >= 0 && dragCol >= 0 )
{
- m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
- m_gridWin->SetCursor( *wxSTANDARD_CURSOR );
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
return;
}
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
- m_cursorMode = WXGRID_CURSOR_RESIZE_ROW;
- m_gridWin->SetCursor( m_rowResizeCursor );
+ ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW);
}
return;
}
-
+
if ( dragCol >= 0 )
{
m_dragRowOrCol = dragCol;
-
+
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
- m_cursorMode = WXGRID_CURSOR_RESIZE_COL;
- m_gridWin->SetCursor( m_colResizeCursor );
+ ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL);
}
-
+
return;
}
-
+
// Neither on a row or col edge
//
if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
{
- m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
- m_gridWin->SetCursor( *wxSTANDARD_CURSOR );
+ ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
}
}
}
int rowTop = m_rowBottoms[m_dragRowOrCol] - m_rowHeights[m_dragRowOrCol];
SetRowSize( m_dragRowOrCol,
wxMax( m_dragLastPos - rowTop, WXGRID_MIN_ROW_HEIGHT ) );
-
+
if ( !GetBatchCount() )
{
// Only needed to get the correct rect.y:
rect.height = ch;
m_gridWin->Refresh( FALSE, &rect );
}
-
+
ShowCellEditControl();
}
}
int pos;
wxString eol = wxTextFile::GetEOL( wxTextFileType_Unix );
wxString tVal = wxTextFile::Translate( value, wxTextFileType_Unix );
-
+
while ( startPos < (int)tVal.Length() )
{
pos = tVal.Mid(startPos).Find( eol );