Rename wxDataViewMainWindow::OnArrowChar to OnVerticalNavigation.

The method handled much more than just arrow characters and it didn't
handle all arrow characters.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68994 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík 2011-09-03 13:14:25 +00:00
parent 2c336e249e
commit 1dc779fc6c

View File

@ -545,8 +545,8 @@ public:
wxBitmap CreateItemBitmap( unsigned int row, int &indent ); wxBitmap CreateItemBitmap( unsigned int row, int &indent );
#endif // wxUSE_DRAG_AND_DROP #endif // wxUSE_DRAG_AND_DROP
void OnPaint( wxPaintEvent &event ); void OnPaint( wxPaintEvent &event );
void OnArrowChar(unsigned int newCurrent, const wxKeyEvent& event);
void OnChar( wxKeyEvent &event ); void OnChar( wxKeyEvent &event );
void OnVerticalNavigation(unsigned int newCurrent, const wxKeyEvent& event);
void OnMouse( wxMouseEvent &event ); void OnMouse( wxMouseEvent &event );
void OnSetFocus( wxFocusEvent &event ); void OnSetFocus( wxFocusEvent &event );
void OnKillFocus( wxFocusEvent &event ); void OnKillFocus( wxFocusEvent &event );
@ -2552,58 +2552,6 @@ void wxDataViewMainWindow::RefreshRowsAfter( unsigned int firstRow )
Refresh( true, &rect ); Refresh( true, &rect );
} }
void wxDataViewMainWindow::OnArrowChar(unsigned int newCurrent, const wxKeyEvent& event)
{
wxCHECK_RET( newCurrent < GetRowCount(),
wxT("invalid item index in OnArrowChar()") );
// if there is no selection, we cannot move it anywhere
if (!HasCurrentRow())
return;
unsigned int oldCurrent = m_currentRow;
// in single selection we just ignore Shift as we can't select several
// items anyhow
if ( event.ShiftDown() && !IsSingleSel() )
{
RefreshRow( oldCurrent );
ChangeCurrentRow( newCurrent );
// select all the items between the old and the new one
if ( oldCurrent > newCurrent )
{
newCurrent = oldCurrent;
oldCurrent = m_currentRow;
}
SelectRows( oldCurrent, newCurrent, true );
if (oldCurrent!=newCurrent)
SendSelectionChangedEvent(GetItemByRow(m_selection[0]));
}
else // !shift
{
RefreshRow( oldCurrent );
// all previously selected items are unselected unless ctrl is held
if ( !event.ControlDown() )
SelectAllRows(false);
ChangeCurrentRow( newCurrent );
if ( !event.ControlDown() )
{
SelectRow( m_currentRow, true );
SendSelectionChangedEvent(GetItemByRow(m_currentRow));
}
else
RefreshRow( m_currentRow );
}
GetOwner()->EnsureVisible( m_currentRow, -1 );
}
wxRect wxDataViewMainWindow::GetLineRect( unsigned int row ) const wxRect wxDataViewMainWindow::GetLineRect( unsigned int row ) const
{ {
wxRect rect; wxRect rect;
@ -3377,12 +3325,12 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
case WXK_UP: case WXK_UP:
if ( m_currentRow > 0 ) if ( m_currentRow > 0 )
OnArrowChar( m_currentRow - 1, event ); OnVerticalNavigation( m_currentRow - 1, event );
break; break;
case WXK_DOWN: case WXK_DOWN:
if ( m_currentRow + 1 < GetRowCount() ) if ( m_currentRow + 1 < GetRowCount() )
OnArrowChar( m_currentRow + 1, event ); OnVerticalNavigation( m_currentRow + 1, event );
break; break;
// Add the process for tree expanding/collapsing // Add the process for tree expanding/collapsing
case WXK_LEFT: case WXK_LEFT:
@ -3436,12 +3384,12 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
case WXK_END: case WXK_END:
{ {
if (!IsEmpty()) if (!IsEmpty())
OnArrowChar( GetRowCount() - 1, event ); OnVerticalNavigation( GetRowCount() - 1, event );
break; break;
} }
case WXK_HOME: case WXK_HOME:
if (!IsEmpty()) if (!IsEmpty())
OnArrowChar( 0, event ); OnVerticalNavigation( 0, event );
break; break;
case WXK_PAGEUP: case WXK_PAGEUP:
@ -3451,7 +3399,7 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
if (index < 0) if (index < 0)
index = 0; index = 0;
OnArrowChar( index, event ); OnVerticalNavigation( index, event );
} }
break; break;
@ -3463,7 +3411,7 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
if ( index >= count ) if ( index >= count )
index = count - 1; index = count - 1;
OnArrowChar( index, event ); OnVerticalNavigation( index, event );
} }
break; break;
@ -3482,6 +3430,58 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event )
} }
} }
void wxDataViewMainWindow::OnVerticalNavigation(unsigned int newCurrent, const wxKeyEvent& event)
{
wxCHECK_RET( newCurrent < GetRowCount(),
wxT("invalid item index in OnVerticalNavigation()") );
// if there is no selection, we cannot move it anywhere
if (!HasCurrentRow())
return;
unsigned int oldCurrent = m_currentRow;
// in single selection we just ignore Shift as we can't select several
// items anyhow
if ( event.ShiftDown() && !IsSingleSel() )
{
RefreshRow( oldCurrent );
ChangeCurrentRow( newCurrent );
// select all the items between the old and the new one
if ( oldCurrent > newCurrent )
{
newCurrent = oldCurrent;
oldCurrent = m_currentRow;
}
SelectRows( oldCurrent, newCurrent, true );
if (oldCurrent!=newCurrent)
SendSelectionChangedEvent(GetItemByRow(m_selection[0]));
}
else // !shift
{
RefreshRow( oldCurrent );
// all previously selected items are unselected unless ctrl is held
if ( !event.ControlDown() )
SelectAllRows(false);
ChangeCurrentRow( newCurrent );
if ( !event.ControlDown() )
{
SelectRow( m_currentRow, true );
SendSelectionChangedEvent(GetItemByRow(m_currentRow));
}
else
RefreshRow( m_currentRow );
}
GetOwner()->EnsureVisible( m_currentRow, -1 );
}
void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
{ {
if (event.GetEventType() == wxEVT_MOUSEWHEEL) if (event.GetEventType() == wxEVT_MOUSEWHEEL)