Add support for freezing columns and/or rows of wxGrid
Add wxGrid::FreezeTo() method which allows to freeze the given number of columns and/or rows at the beginning of the grid, i.e. keep them pinned in place while the rest of the grid is scrolled. The main wxGridWindow (m_gridWin) now corresponds to the non-frozen part of the grid, with up to 3 new similar windows for the frozen rows/columns and the frozen corner cells (which only exist if both rows and columns are frozen) being additionally used. Doing this involved adding "wxGridWindow*" parameter to many functions that previously only worked with m_gridWin itself and addressing additional complications, such as mouse events that can now cross different windows. See https://github.com/wxWidgets/wxWidgets/pull/952 for the original version of the changes.
This commit is contained in:
committed by
Vadim Zeitlin
parent
f61b58bba3
commit
04f7f1fd32
@@ -189,6 +189,8 @@ wxBEGIN_EVENT_TABLE( GridFrame, wxFrame )
|
||||
EVT_MENU( ID_SELCOLS, GridFrame::SelectCols )
|
||||
EVT_MENU( ID_SELROWSORCOLS, GridFrame::SelectRowsOrCols )
|
||||
|
||||
EVT_MENU( ID_FREEZE_OR_THAW, GridFrame::FreezeOrThaw )
|
||||
|
||||
EVT_MENU( ID_SET_CELL_FG_COLOUR, GridFrame::SetCellFgColour )
|
||||
EVT_MENU( ID_SET_CELL_BG_COLOUR, GridFrame::SetCellBgColour )
|
||||
|
||||
@@ -370,6 +372,8 @@ GridFrame::GridFrame()
|
||||
editMenu->Append( ID_CLEARGRID, "Cl&ear grid cell contents" );
|
||||
editMenu->Append( ID_SETCORNERLABEL, "&Set corner label..." );
|
||||
|
||||
editMenu->AppendCheckItem( ID_FREEZE_OR_THAW, "Freeze up to cursor\tCtrl-F" );
|
||||
|
||||
wxMenu *selectMenu = new wxMenu;
|
||||
selectMenu->Append( ID_SELECT_UNSELECT, "Add new cells to the selection",
|
||||
"When off, old selection is deselected before "
|
||||
@@ -573,10 +577,10 @@ GridFrame::GridFrame()
|
||||
"This takes two cells",
|
||||
"Another choice",
|
||||
};
|
||||
grid->SetCellEditor(4, 0, new wxGridCellChoiceEditor(WXSIZEOF(choices), choices));
|
||||
grid->SetCellSize(4, 0, 1, 2);
|
||||
grid->SetCellValue(4, 0, choices[0]);
|
||||
grid->SetCellOverflow(4, 0, false);
|
||||
grid->SetCellEditor(4, 2, new wxGridCellChoiceEditor(WXSIZEOF(choices), choices));
|
||||
grid->SetCellSize(4, 2, 1, 2);
|
||||
grid->SetCellValue(4, 2, choices[0]);
|
||||
grid->SetCellOverflow(4, 2, false);
|
||||
|
||||
grid->SetCellSize(7, 1, 3, 4);
|
||||
grid->SetCellAlignment(7, 1, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||
@@ -1209,6 +1213,30 @@ void GridFrame::SelectRowsOrCols( wxCommandEvent& WXUNUSED(ev) )
|
||||
grid->SetSelectionMode( wxGrid::wxGridSelectRowsOrColumns );
|
||||
}
|
||||
|
||||
void GridFrame::FreezeOrThaw(wxCommandEvent& ev)
|
||||
{
|
||||
if ( ev.IsChecked() )
|
||||
{
|
||||
if ( !grid->FreezeTo(grid->GetGridCursorCoords()) )
|
||||
{
|
||||
wxLogMessage("Failed to freeze the grid.");
|
||||
GetMenuBar()->Check(ID_FREEZE_OR_THAW, false);
|
||||
return;
|
||||
}
|
||||
|
||||
wxLogMessage("Grid is now frozen");
|
||||
}
|
||||
else
|
||||
{
|
||||
// This never fails.
|
||||
grid->FreezeTo(0, 0);
|
||||
|
||||
wxLogMessage("Grid is now thawed");
|
||||
}
|
||||
|
||||
GetMenuBar()->Enable( ID_TOGGLECOLMOVING, !grid->IsFrozen() );
|
||||
}
|
||||
|
||||
void GridFrame::SetCellFgColour( wxCommandEvent& WXUNUSED(ev) )
|
||||
{
|
||||
wxColour col = wxGetColourFromUser(this);
|
||||
|
Reference in New Issue
Block a user