added ChangeCursorMode() method, rewrote the col/row resizing code to capture/release mouse properly
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5963 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -949,14 +949,28 @@ protected:
|
|||||||
bool m_inOnKeyDown;
|
bool m_inOnKeyDown;
|
||||||
int m_batchCount;
|
int m_batchCount;
|
||||||
|
|
||||||
int m_cursorMode;
|
enum CursorMode
|
||||||
enum { WXGRID_CURSOR_SELECT_CELL,
|
{
|
||||||
|
WXGRID_CURSOR_SELECT_CELL,
|
||||||
WXGRID_CURSOR_RESIZE_ROW,
|
WXGRID_CURSOR_RESIZE_ROW,
|
||||||
WXGRID_CURSOR_RESIZE_COL,
|
WXGRID_CURSOR_RESIZE_COL,
|
||||||
WXGRID_CURSOR_SELECT_ROW,
|
WXGRID_CURSOR_SELECT_ROW,
|
||||||
WXGRID_CURSOR_SELECT_COL
|
WXGRID_CURSOR_SELECT_COL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// this method not only sets m_cursorMode but also sets the correct cursor
|
||||||
|
// for the given mode and, if captureMouse is not FALSE releases the mouse
|
||||||
|
// if it was captured and captures it if it must be captured
|
||||||
|
//
|
||||||
|
// for this to work, you should always use it and not set m_cursorMode
|
||||||
|
// directly!
|
||||||
|
void ChangeCursorMode(CursorMode mode,
|
||||||
|
wxWindow *win = (wxWindow *)NULL,
|
||||||
|
bool captureMouse = TRUE);
|
||||||
|
|
||||||
|
wxWindow *m_winCapture; // the window which captured the mouse
|
||||||
|
CursorMode m_cursorMode;
|
||||||
|
|
||||||
int m_dragLastPos;
|
int m_dragLastPos;
|
||||||
int m_dragRowOrCol;
|
int m_dragRowOrCol;
|
||||||
bool m_isDragging;
|
bool m_isDragging;
|
||||||
|
@@ -1323,6 +1323,7 @@ void wxGrid::Init()
|
|||||||
m_gridLinesEnabled = TRUE;
|
m_gridLinesEnabled = TRUE;
|
||||||
|
|
||||||
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
|
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
|
||||||
|
m_winCapture = (wxWindow *)NULL;
|
||||||
m_dragLastPos = -1;
|
m_dragLastPos = -1;
|
||||||
m_dragRowOrCol = -1;
|
m_dragRowOrCol = -1;
|
||||||
m_isDragging = FALSE;
|
m_isDragging = FALSE;
|
||||||
@@ -1773,13 +1774,15 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case WXGRID_CURSOR_SELECT_ROW:
|
case WXGRID_CURSOR_SELECT_ROW:
|
||||||
{
|
|
||||||
if ( (row = YToRow( y )) >= 0 &&
|
if ( (row = YToRow( y )) >= 0 &&
|
||||||
!IsInSelection( row, 0 ) )
|
!IsInSelection( row, 0 ) )
|
||||||
{
|
{
|
||||||
SelectRow( row, TRUE );
|
SelectRow( row, TRUE );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// default label to suppress warnings about "enumeration value
|
||||||
|
// 'xxx' not handled in switch
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1793,8 +1796,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
|
|||||||
//
|
//
|
||||||
if ( event.Entering() || event.Leaving() )
|
if ( event.Entering() || event.Leaving() )
|
||||||
{
|
{
|
||||||
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
|
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin);
|
||||||
m_rowLabelWin->SetCursor( *wxSTANDARD_CURSOR );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1813,14 +1815,14 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
|
|||||||
!SendEvent( EVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) )
|
!SendEvent( EVT_GRID_LABEL_LEFT_CLICK, row, -1, event ) )
|
||||||
{
|
{
|
||||||
SelectRow( row, event.ShiftDown() );
|
SelectRow( row, event.ShiftDown() );
|
||||||
m_cursorMode = WXGRID_CURSOR_SELECT_ROW;
|
ChangeCursorMode(WXGRID_CURSOR_SELECT_ROW, m_rowLabelWin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// starting to drag-resize a row
|
// starting to drag-resize a row
|
||||||
//
|
//
|
||||||
m_rowLabelWin->CaptureMouse();
|
ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, m_rowLabelWin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1843,7 +1845,6 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
|
|||||||
{
|
{
|
||||||
if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
|
if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
|
||||||
{
|
{
|
||||||
m_rowLabelWin->ReleaseMouse();
|
|
||||||
DoEndDragResizeRow();
|
DoEndDragResizeRow();
|
||||||
|
|
||||||
// Note: we are ending the event *after* doing
|
// Note: we are ending the event *after* doing
|
||||||
@@ -1852,7 +1853,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
|
|||||||
SendEvent( EVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event );
|
SendEvent( EVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, event );
|
||||||
}
|
}
|
||||||
|
|
||||||
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
|
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin);
|
||||||
m_dragLastPos = -1;
|
m_dragLastPos = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1890,14 +1891,13 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
|
|||||||
{
|
{
|
||||||
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
|
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
|
||||||
{
|
{
|
||||||
m_cursorMode = WXGRID_CURSOR_RESIZE_ROW;
|
// don't capture the mouse yet
|
||||||
m_rowLabelWin->SetCursor( m_rowResizeCursor );
|
ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW, m_rowLabelWin, FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
|
else if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
|
||||||
{
|
{
|
||||||
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
|
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin, FALSE);
|
||||||
m_rowLabelWin->SetCursor( *wxSTANDARD_CURSOR );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1936,13 +1936,15 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case WXGRID_CURSOR_SELECT_COL:
|
case WXGRID_CURSOR_SELECT_COL:
|
||||||
{
|
|
||||||
if ( (col = XToCol( x )) >= 0 &&
|
if ( (col = XToCol( x )) >= 0 &&
|
||||||
!IsInSelection( 0, col ) )
|
!IsInSelection( 0, col ) )
|
||||||
{
|
{
|
||||||
SelectCol( col, TRUE );
|
SelectCol( col, TRUE );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// default label to suppress warnings about "enumeration value
|
||||||
|
// 'xxx' not handled in switch
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1956,8 +1958,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
|
|||||||
//
|
//
|
||||||
if ( event.Entering() || event.Leaving() )
|
if ( event.Entering() || event.Leaving() )
|
||||||
{
|
{
|
||||||
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
|
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin);
|
||||||
m_colLabelWin->SetCursor( *wxSTANDARD_CURSOR );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1976,14 +1977,14 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
|
|||||||
!SendEvent( EVT_GRID_LABEL_LEFT_CLICK, -1, col, event ) )
|
!SendEvent( EVT_GRID_LABEL_LEFT_CLICK, -1, col, event ) )
|
||||||
{
|
{
|
||||||
SelectCol( col, event.ShiftDown() );
|
SelectCol( col, event.ShiftDown() );
|
||||||
m_cursorMode = WXGRID_CURSOR_SELECT_COL;
|
ChangeCursorMode(WXGRID_CURSOR_SELECT_COL, m_colLabelWin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// starting to drag-resize a col
|
// starting to drag-resize a col
|
||||||
//
|
//
|
||||||
m_colLabelWin->CaptureMouse();
|
ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL, m_colLabelWin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2006,7 +2007,6 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
|
|||||||
{
|
{
|
||||||
if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
|
if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
|
||||||
{
|
{
|
||||||
m_colLabelWin->ReleaseMouse();
|
|
||||||
DoEndDragResizeCol();
|
DoEndDragResizeCol();
|
||||||
|
|
||||||
// Note: we are ending the event *after* doing
|
// Note: we are ending the event *after* doing
|
||||||
@@ -2015,7 +2015,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
|
|||||||
SendEvent( EVT_GRID_COL_SIZE, -1, m_dragRowOrCol, event );
|
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;
|
m_dragLastPos = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2053,14 +2053,13 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
|
|||||||
{
|
{
|
||||||
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
|
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
|
||||||
{
|
{
|
||||||
m_cursorMode = WXGRID_CURSOR_RESIZE_COL;
|
// don't capture the cursor yet
|
||||||
m_colLabelWin->SetCursor( m_colResizeCursor );
|
ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL, m_colLabelWin, FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
|
else if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
|
||||||
{
|
{
|
||||||
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
|
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin, FALSE);
|
||||||
m_colLabelWin->SetCursor( *wxSTANDARD_CURSOR );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2101,6 +2100,68 @@ void wxGrid::ProcessCornerLabelMouseEvent( wxMouseEvent& event )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 )
|
void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
||||||
{
|
{
|
||||||
@@ -2172,15 +2233,21 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
|||||||
|
|
||||||
if ( coords != wxGridNoCellCoords )
|
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() )
|
if ( event.Entering() || event.Leaving() )
|
||||||
{
|
{
|
||||||
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
|
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
|
||||||
m_gridWin->SetCursor( *wxSTANDARD_CURSOR );
|
m_gridWin->SetCursor( *wxSTANDARD_CURSOR );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
#endif // 0
|
||||||
|
|
||||||
// ------------ Left button pressed
|
// ------------ Left button pressed
|
||||||
//
|
//
|
||||||
else if ( event.LeftDown() )
|
if ( event.LeftDown() )
|
||||||
{
|
{
|
||||||
if ( event.ShiftDown() )
|
if ( event.ShiftDown() )
|
||||||
{
|
{
|
||||||
@@ -2233,7 +2300,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
|||||||
}
|
}
|
||||||
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
|
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
|
||||||
{
|
{
|
||||||
m_gridWin->ReleaseMouse();
|
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
|
||||||
DoEndDragResizeRow();
|
DoEndDragResizeRow();
|
||||||
|
|
||||||
// Note: we are ending the event *after* doing
|
// Note: we are ending the event *after* doing
|
||||||
@@ -2243,7 +2310,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
|||||||
}
|
}
|
||||||
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
|
else if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
|
||||||
{
|
{
|
||||||
m_gridWin->ReleaseMouse();
|
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
|
||||||
DoEndDragResizeCol();
|
DoEndDragResizeCol();
|
||||||
|
|
||||||
// Note: we are ending the event *after* doing
|
// Note: we are ending the event *after* doing
|
||||||
@@ -2295,8 +2362,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
|||||||
//
|
//
|
||||||
if ( dragRow >= 0 && dragCol >= 0 )
|
if ( dragRow >= 0 && dragCol >= 0 )
|
||||||
{
|
{
|
||||||
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
|
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
|
||||||
m_gridWin->SetCursor( *wxSTANDARD_CURSOR );
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2306,8 +2372,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
|||||||
|
|
||||||
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
|
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
|
||||||
{
|
{
|
||||||
m_cursorMode = WXGRID_CURSOR_RESIZE_ROW;
|
ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW);
|
||||||
m_gridWin->SetCursor( m_rowResizeCursor );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -2319,8 +2384,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
|||||||
|
|
||||||
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
|
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
|
||||||
{
|
{
|
||||||
m_cursorMode = WXGRID_CURSOR_RESIZE_COL;
|
ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL);
|
||||||
m_gridWin->SetCursor( m_colResizeCursor );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -2330,8 +2394,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
|
|||||||
//
|
//
|
||||||
if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
|
if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
|
||||||
{
|
{
|
||||||
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
|
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
|
||||||
m_gridWin->SetCursor( *wxSTANDARD_CURSOR );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user