From ed204211810ac347082cb0ad0704acdbb18ee7b3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 4 Nov 2018 17:16:31 +0100 Subject: [PATCH] Clarify RowToTreeNodeJob in generic wxDataViewCtrl code Get rid of hardcoded, without any explanation, "-2" value passed to this class ctor and instead initialize its m_current member to -1 and explain why do we do it and increment it after processing the current item, not before, in operator(). No changes in behaviour. --- src/generic/datavgen.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index d5a2fffd75..f2db03c189 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -3468,14 +3468,16 @@ int wxDataViewMainWindow::GetLineHeight( unsigned int row ) const class RowToTreeNodeJob: public DoJob { public: - RowToTreeNodeJob(int row, int current) - : m_row(row), m_current(current), m_ret(NULL) + // Note that we initialize m_current to -1 because the first node passed to + // our operator() will be the root node, which doesn't appear in the window + // and so doesn't count as a real row. + explicit RowToTreeNodeJob(int row) + : m_row(row), m_current(-1), m_ret(NULL) { } virtual int operator() ( wxDataViewTreeNode * node ) wxOVERRIDE { - m_current ++; if( m_current == m_row) { m_ret = node; @@ -3484,7 +3486,7 @@ public: if( node->GetSubTreeCount() + m_current < m_row ) { - m_current += node->GetSubTreeCount(); + m_current += node->GetSubTreeCount() + 1; return DoJob::SKIP_SUBTREE; } else @@ -3500,6 +3502,8 @@ public: return DoJob::DONE; } + m_current++; + return DoJob::CONTINUE; } } @@ -3520,7 +3524,7 @@ wxDataViewTreeNode * wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row) co if ( row == (unsigned)-1 ) return NULL; - RowToTreeNodeJob job( static_cast(row) , -2 ); + RowToTreeNodeJob job(static_cast(row)); Walker( m_root , job ); return job.GetResult(); }