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:
Vadim Zeitlin 2000-02-11 17:43:42 +00:00
parent c3b177ae63
commit e2b42eebeb
2 changed files with 137 additions and 60 deletions

View File

@ -949,14 +949,28 @@ protected:
bool m_inOnKeyDown;
int m_batchCount;
int m_cursorMode;
enum { WXGRID_CURSOR_SELECT_CELL,
enum CursorMode
{
WXGRID_CURSOR_SELECT_CELL,
WXGRID_CURSOR_RESIZE_ROW,
WXGRID_CURSOR_RESIZE_COL,
WXGRID_CURSOR_SELECT_ROW,
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_dragRowOrCol;
bool m_isDragging;

View File

@ -1323,6 +1323,7 @@ void wxGrid::Init()
m_gridLinesEnabled = TRUE;
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
m_winCapture = (wxWindow *)NULL;
m_dragLastPos = -1;
m_dragRowOrCol = -1;
m_isDragging = FALSE;
@ -1773,13 +1774,15 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
break;
case WXGRID_CURSOR_SELECT_ROW:
{
if ( (row = YToRow( y )) >= 0 &&
!IsInSelection( row, 0 ) )
{
SelectRow( row, TRUE );
}
}
// default label to suppress warnings about "enumeration value
// 'xxx' not handled in switch
default:
break;
}
}
@ -1793,8 +1796,7 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
//
if ( event.Entering() || event.Leaving() )
{
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
m_rowLabelWin->SetCursor( *wxSTANDARD_CURSOR );
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin);
}
@ -1813,14 +1815,14 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
!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);
}
}
@ -1843,7 +1845,6 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
{
if ( m_cursorMode == WXGRID_CURSOR_RESIZE_ROW )
{
m_rowLabelWin->ReleaseMouse();
DoEndDragResizeRow();
// 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 );
}
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_rowLabelWin);
m_dragLastPos = -1;
}
@ -1890,14 +1891,13 @@ void wxGrid::ProcessRowLabelMouseEvent( wxMouseEvent& event )
{
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);
}
}
}
@ -1936,13 +1936,15 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
break;
case WXGRID_CURSOR_SELECT_COL:
{
if ( (col = XToCol( x )) >= 0 &&
!IsInSelection( 0, col ) )
{
SelectCol( col, TRUE );
}
}
// default label to suppress warnings about "enumeration value
// 'xxx' not handled in switch
default:
break;
}
}
@ -1956,8 +1958,7 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
//
if ( event.Entering() || event.Leaving() )
{
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
m_colLabelWin->SetCursor( *wxSTANDARD_CURSOR );
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin);
}
@ -1976,14 +1977,14 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
!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);
}
}
@ -2006,7 +2007,6 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
{
if ( m_cursorMode == WXGRID_CURSOR_RESIZE_COL )
{
m_colLabelWin->ReleaseMouse();
DoEndDragResizeCol();
// 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 );
}
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL, m_colLabelWin);
m_dragLastPos = -1;
}
@ -2053,14 +2053,13 @@ void wxGrid::ProcessColLabelMouseEvent( wxMouseEvent& event )
{
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);
}
}
}
@ -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 )
{
@ -2172,15 +2233,21 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
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() )
{
@ -2233,7 +2300,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
}
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
@ -2243,7 +2310,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
}
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
@ -2295,8 +2362,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
//
if ( dragRow >= 0 && dragCol >= 0 )
{
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
m_gridWin->SetCursor( *wxSTANDARD_CURSOR );
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
return;
}
@ -2306,8 +2372,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
m_cursorMode = WXGRID_CURSOR_RESIZE_ROW;
m_gridWin->SetCursor( m_rowResizeCursor );
ChangeCursorMode(WXGRID_CURSOR_RESIZE_ROW);
}
return;
@ -2319,8 +2384,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
if ( m_cursorMode == WXGRID_CURSOR_SELECT_CELL )
{
m_cursorMode = WXGRID_CURSOR_RESIZE_COL;
m_gridWin->SetCursor( m_colResizeCursor );
ChangeCursorMode(WXGRID_CURSOR_RESIZE_COL);
}
return;
@ -2330,8 +2394,7 @@ void wxGrid::ProcessGridCellMouseEvent( wxMouseEvent& event )
//
if ( m_cursorMode != WXGRID_CURSOR_SELECT_CELL )
{
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
m_gridWin->SetCursor( *wxSTANDARD_CURSOR );
ChangeCursorMode(WXGRID_CURSOR_SELECT_CELL);
}
}
}