From 4b918966f600411a750744d293ae1217678fc8a6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 18 Aug 2020 01:27:39 +0200 Subject: [PATCH] Refactor logging of wxGridRangeSelectEvent in the grid sample Avoid duplicating the complicated logging code twice, when it's exactly the same for both the SELECTED and SELECTING events. Just use a common helper function instead. --- samples/grid/griddemo.cpp | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/samples/grid/griddemo.cpp b/samples/grid/griddemo.cpp index 45beb7770d..46ed8d5e42 100644 --- a/samples/grid/griddemo.cpp +++ b/samples/grid/griddemo.cpp @@ -1638,14 +1638,19 @@ void GridFrame::OnSelectCell( wxGridEvent& ev ) ev.Skip(); } -void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev ) +namespace +{ + +void +LogRangeSelectEvent(wxGridRangeSelectEvent& ev, const char* suffix) { wxString logBuf; if ( ev.Selecting() ) - logBuf << "Selected "; + logBuf << "Select"; else - logBuf << "Deselected "; - logBuf << "cells from row " << ev.GetTopRow() + logBuf << "Deselect"; + logBuf << suffix + << " cells from row " << ev.GetTopRow() << " col " << ev.GetLeftCol() << " to row " << ev.GetBottomRow() << " col " << ev.GetRightCol() @@ -1657,24 +1662,17 @@ void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev ) ev.Skip(); } + +} // anonymous namespace + +void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev ) +{ + LogRangeSelectEvent(ev, "ed"); +} + void GridFrame::OnRangeSelecting( wxGridRangeSelectEvent& ev ) { - wxString logBuf; - if ( ev.Selecting() ) - logBuf << "Selecting "; - else - logBuf << "Deselecting "; - logBuf << "cells from row " << ev.GetTopRow() - << " col " << ev.GetLeftCol() - << " to row " << ev.GetBottomRow() - << " col " << ev.GetRightCol() - << " ( ControlDown: "<< (ev.ControlDown() ? 'T':'F') - << ", ShiftDown: "<< (ev.ShiftDown() ? 'T':'F') - << ", AltDown: "<< (ev.AltDown() ? 'T':'F') - << ", MetaDown: "<< (ev.MetaDown() ? 'T':'F') << " )"; - wxLogMessage( "%s", logBuf ); - - ev.Skip(); + LogRangeSelectEvent(ev, "ing"); } void GridFrame::OnCellValueChanging( wxGridEvent& ev )