Make TAB behaviour in wxGrid more configurable.

Allow making TAB/Shift-TAB wrap to the next/previous row or going to the
next/previous control when the cursor is at the end/beginning of the current
row easily.

Also add wxEVT_GRID_TABBING event to allow customizing TAB behaviour even
further.

Update the sample to show the different possible standard behaviours and a
stupid example of a custom one (it would be probably more useful to implement
something a tad more realistic, e.g. tabbing to the next non-empty cell).

Closes #14711.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72672 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-10-13 22:55:18 +00:00
parent ac6a837eed
commit 1dc17bcafb
6 changed files with 193 additions and 20 deletions

View File

@@ -160,6 +160,8 @@ BEGIN_EVENT_TABLE( GridFrame, wxFrame )
EVT_MENU( ID_COLNATIVEHEADER, GridFrame::SetNativeColHeader )
EVT_MENU( ID_COLDEFAULTHEADER, GridFrame::SetDefaultColHeader )
EVT_MENU( ID_COLCUSTOMHEADER, GridFrame::SetCustomColHeader )
EVT_MENU_RANGE( ID_TAB_STOP, ID_TAB_LEAVE, GridFrame::SetTabBehaviour )
EVT_MENU( ID_TAB_CUSTOM, GridFrame::SetTabCustomHandler )
EVT_MENU( ID_TOGGLEGRIDLINES, GridFrame::ToggleGridLines )
EVT_MENU( ID_AUTOSIZECOLS, GridFrame::AutoSizeCols )
EVT_MENU( ID_CELLOVERFLOW, GridFrame::CellOverflow )
@@ -320,6 +322,12 @@ GridFrame::GridFrame()
colHeaderMenu->AppendRadioItem( ID_COLNATIVEHEADER, wxT("&Native") );
colHeaderMenu->AppendRadioItem( ID_COLCUSTOMHEADER, wxT("&Custom") );
wxMenu *tabBehaviourMenu = new wxMenu;
tabBehaviourMenu->AppendRadioItem(ID_TAB_STOP, "&Stop at the boundary");
tabBehaviourMenu->AppendRadioItem(ID_TAB_WRAP, "&Wrap at the boundary");
tabBehaviourMenu->AppendRadioItem(ID_TAB_LEAVE, "&Leave the grid");
tabBehaviourMenu->AppendRadioItem(ID_TAB_CUSTOM, "&Custom tab handler");
viewMenu->AppendSubMenu(tabBehaviourMenu, "&Tab behaviour");
wxMenu *colMenu = new wxMenu;
colMenu->Append( ID_SETLABELCOLOUR, wxT("Set &label colour...") );
@@ -661,6 +669,42 @@ void GridFrame::SetDefaultColHeader( wxCommandEvent& WXUNUSED(ev) )
}
void GridFrame::OnGridCustomTab(wxGridEvent& event)
{
// just for testing, make the cursor move up and down instead of the usual
// left and right
if ( event.ShiftDown() )
{
if ( grid->GetGridCursorRow() > 0 )
grid->MoveCursorUp( false );
}
else
{
if ( grid->GetGridCursorRow() < grid->GetNumberRows() - 1 )
grid->MoveCursorDown( false );
}
}
void GridFrame::SetTabBehaviour(wxCommandEvent& event)
{
// To make any built-in behaviour work, we need to disable the custom TAB
// handler, otherwise it would be overriding them.
grid->Disconnect(wxEVT_GRID_TABBING,
wxGridEventHandler(GridFrame::OnGridCustomTab));
grid->SetTabBehaviour(
static_cast<wxGrid::TabBehaviour>(event.GetId() - ID_TAB_STOP)
);
}
void GridFrame::SetTabCustomHandler(wxCommandEvent&)
{
grid->Connect(wxEVT_GRID_TABBING,
wxGridEventHandler(GridFrame::OnGridCustomTab),
NULL, this);
}
void GridFrame::ToggleGridLines( wxCommandEvent& WXUNUSED(ev) )
{
grid->EnableGridLines(