X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/779e28da630ef9fba6441fb0bab01cd538a7e7bb..d48f13a168143e97c271bbeb2f544a63983ee435:/samples/grid/griddemo.cpp diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index c331a34845..ad85aa1117 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -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...") ); @@ -436,6 +444,9 @@ GridFrame::GridFrame() grid->SetCellValue( 0, 5, wxT("Press\nCtrl+arrow\nto skip over\ncells") ); grid->SetRowSize( 99, 60 ); + grid->SetCellValue(98, 98, "Test background colour setting"); + grid->SetCellBackgroundColour(98, 99, wxColour(255, 127, 127)); + grid->SetCellBackgroundColour(99, 98, wxColour(255, 127, 127)); grid->SetCellValue( 99, 99, wxT("Ctrl+End\nwill go to\nthis cell") ); grid->SetCellValue( 1, 0, wxT("This default cell will overflow into neighboring cells, but not if you turn overflow off.")); @@ -457,6 +468,7 @@ GridFrame::GridFrame() grid->SetCellRenderer(3, 0, new wxGridCellBoolRenderer); grid->SetCellEditor(3, 0, new wxGridCellBoolEditor); + grid->SetCellBackgroundColour(3, 0, wxColour(255, 127, 127)); wxGridCellAttr *attr; attr = new wxGridCellAttr; @@ -661,6 +673,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(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( @@ -2220,7 +2268,6 @@ void GridFrame::OnGridRender( wxCommandEvent& event ) if ( useLometric ) { memDc.SetMapMode( wxMM_LOMETRIC ); - wxSize sizePPI = memDc.GetPPI(); sizeRender.x = memDc.DeviceToLogicalXRel( sizeRender.x ); sizeRender.y = memDc.DeviceToLogicalYRel( sizeRender.y ); } @@ -2237,7 +2284,10 @@ void GridFrame::OnGridRender( wxCommandEvent& event ) m_gridBitmap = bmp; - canvas->Bind( wxEVT_PAINT, &GridFrame::OnRenderPaint, this ); + canvas->Connect( wxEVT_PAINT, + wxPaintEventHandler(GridFrame::OnRenderPaint), + NULL, + this ); frame->Show(); }