From 461ba86312ed5409237652d19309a3b8f28ddeaa Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 30 Nov 2014 01:36:08 +0100 Subject: [PATCH] Don't count all MDI children, just check if there is more than one. Make the code in Skeleton::UponMenuOpen() marginally more efficient and slightly more clear and avoid pointer-to-integer coercion by just checking if more than one child exists instead of counting all of them. --- skeleton.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/skeleton.cpp b/skeleton.cpp index e5177466a..23dbda98b 100644 --- a/skeleton.cpp +++ b/skeleton.cpp @@ -848,22 +848,27 @@ void Skeleton::UponMenuOpen(wxMenuEvent& event) { event.Skip(); - int child_frame_count = 0; - wxWindowList const& wl = frame_->GetChildren(); - for(wxWindowList::const_iterator i = wl.begin(); i != wl.end(); ++i) - { - child_frame_count += !!dynamic_cast(*i); - } - wxMDIChildFrame* child_frame = frame_->GetActiveChild(); if(child_frame) { + bool has_another_child = false; + wxWindowList const& wl = frame_->GetChildren(); + for(wxWindowList::const_iterator i = wl.begin(); i != wl.end(); ++i) + { + wxMDIChildFrame* const child = dynamic_cast(*i); + if(child && child != child_frame) + { + has_another_child = true; + break; + } + } + wxMenuItem* window_next = child_frame->GetMenuBar()->FindItem (XRCID("window_next") ); if(window_next) { - window_next->Enable(1 < child_frame_count); + window_next->Enable(has_another_child); } wxMenuItem* window_previous = child_frame->GetMenuBar()->FindItem @@ -871,7 +876,7 @@ void Skeleton::UponMenuOpen(wxMenuEvent& event) ); if(window_previous) { - window_previous->Enable(1 < child_frame_count); + window_previous->Enable(has_another_child); } } // (else) Parent menu enablement could be handled here, but, for