1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-06 07:29:07 +02:00

Simplify some iterations over lists

This commit is contained in:
Paul Licameli 2016-09-08 12:03:40 -04:00
parent 2263a0f477
commit b973698fdf
5 changed files with 25 additions and 51 deletions

View File

@ -2882,13 +2882,12 @@ void AudacityProject::PrevFrame()
void AudacityProject::NextWindow() void AudacityProject::NextWindow()
{ {
wxWindow *w = wxGetTopLevelParent(wxWindow::FindFocus()); wxWindow *w = wxGetTopLevelParent(wxWindow::FindFocus());
const wxWindowList & list = GetChildren(); const auto & list = GetChildren();
wxWindowList::compatibility_iterator iter; auto iter = list.begin(), end = list.end();
// If the project window has the current focus, start the search with the first child // If the project window has the current focus, start the search with the first child
if (w == this) if (w == this)
{ {
iter = list.GetFirst();
} }
// Otherwise start the search with the current window's next sibling // Otherwise start the search with the current window's next sibling
else else
@ -2896,31 +2895,27 @@ void AudacityProject::NextWindow()
// Find the window in this projects children. If the window with the // Find the window in this projects children. If the window with the
// focus isn't a child of this project (like when a dialog is created // focus isn't a child of this project (like when a dialog is created
// without specifying a parent), then we'll get back NULL here. // without specifying a parent), then we'll get back NULL here.
iter = list.Find(w); while (iter != end && *iter != w)
if (iter) ++iter;
{ if (iter != end)
iter = iter->GetNext(); ++iter;
}
} }
// Search for the next toplevel window // Search for the next toplevel window
while (iter) for (; iter != end; ++iter)
{ {
// If it's a toplevel, visible (we have hidden windows) and is enabled, // If it's a toplevel, visible (we have hidden windows) and is enabled,
// then we're done. The IsEnabled() prevents us from moving away from // then we're done. The IsEnabled() prevents us from moving away from
// a modal dialog because all other toplevel windows will be disabled. // a modal dialog because all other toplevel windows will be disabled.
w = iter->GetData(); w = *iter;
if (w->IsTopLevel() && w->IsShown() && w->IsEnabled()) if (w->IsTopLevel() && w->IsShown() && w->IsEnabled())
{ {
break; break;
} }
// Get the next sibling
iter = iter->GetNext();
} }
// Ran out of siblings, so make the current project active // Ran out of siblings, so make the current project active
if (!iter && IsEnabled()) if ((iter == end) && IsEnabled())
{ {
w = this; w = this;
} }
@ -2943,43 +2938,35 @@ void AudacityProject::NextWindow()
void AudacityProject::PrevWindow() void AudacityProject::PrevWindow()
{ {
wxWindow *w = wxGetTopLevelParent(wxWindow::FindFocus()); wxWindow *w = wxGetTopLevelParent(wxWindow::FindFocus());
const wxWindowList & list = GetChildren(); const auto & list = GetChildren();
wxWindowList::compatibility_iterator iter; auto iter = list.rbegin(), end = list.rend();
// If the project window has the current focus, start the search with the last child // If the project window has the current focus, start the search with the last child
if (w == this) if (w == this)
{ {
iter = list.GetLast();
} }
// Otherwise start the search with the current window's previous sibling // Otherwise start the search with the current window's previous sibling
else else
{ {
if (list.Find(w)) while (iter != end && *iter != w)
iter = list.Find(w)->GetPrevious(); ++iter;
if (iter != end)
++iter;
} }
// Search for the previous toplevel window // Search for the previous toplevel window
while (iter) for (; iter != end; ++iter)
{ {
// If it's a toplevel and is visible (we have come hidden windows), then we're done // If it's a toplevel and is visible (we have come hidden windows), then we're done
w = iter->GetData(); w = *iter;
if (w->IsTopLevel() && w->IsShown() && IsEnabled()) if (w->IsTopLevel() && w->IsShown() && IsEnabled())
{ {
break; break;
} }
// Find the window in this projects children. If the window with the
// focus isn't a child of this project (like when a dialog is created
// without specifying a parent), then we'll get back NULL here.
iter = list.Find(w);
if (iter)
{
iter = iter->GetPrevious();
}
} }
// Ran out of siblings, so make the current project active // Ran out of siblings, so make the current project active
if (!iter && IsEnabled()) if ((iter == end) && IsEnabled())
{ {
w = this; w = this;
} }

View File

@ -8272,14 +8272,11 @@ int TrackPanel::IdOfFormat( int format )
/// Puts a check mark at a given position in a menu. /// Puts a check mark at a given position in a menu.
void TrackPanel::SetMenuCheck( wxMenu & menu, int newId ) void TrackPanel::SetMenuCheck( wxMenu & menu, int newId )
{ {
wxMenuItemList & list = menu.GetMenuItems(); auto & list = menu.GetMenuItems();
wxMenuItem * item;
int id;
for ( wxMenuItemList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext() ) for ( auto item : list )
{ {
item = node->GetData(); auto id = item->GetId();
id = item->GetId();
// We only need to set check marks. Clearing checks causes problems on Linux (bug 851) // We only need to set check marks. Clearing checks causes problems on Linux (bug 851)
if (id==newId) if (id==newId)
menu.Check( id, true ); menu.Check( id, true );

View File

@ -321,12 +321,8 @@ void ExpandingToolBar::RecursivelyPushEventHandlers(wxWindow *win)
} }
wxWindowList children = win->GetChildren(); wxWindowList children = win->GetChildren();
for(auto child : children)
typedef wxWindowList::compatibility_iterator Node;
for(Node node = children.GetFirst(); node; node = node->GetNext()) {
wxWindow *child = node->GetData();
RecursivelyPushEventHandlers(child); RecursivelyPushEventHandlers(child);
}
} }
bool ExpandingToolBar::Layout() bool ExpandingToolBar::Layout()

View File

@ -166,11 +166,8 @@ void FileHistory::AddFilesToMenu()
void FileHistory::AddFilesToMenu(wxMenu *menu) void FileHistory::AddFilesToMenu(wxMenu *menu)
{ {
wxMenuItemList items = menu->GetMenuItems(); wxMenuItemList items = menu->GetMenuItems();
wxMenuItemList::compatibility_iterator node = items.GetFirst(); for (auto end = items.end(), iter = items.begin(); iter != end;)
while (node) { menu->Destroy(*iter++);
menu->Destroy((wxMenuItem *) node->GetData());
node = node->GetNext();
}
for (size_t i = 0; i < mHistory.GetCount(); i++) { for (size_t i = 0; i < mHistory.GetCount(); i++) {
menu->Append(mIDBase + 1 + i, mHistory[i]); menu->Append(mIDBase + 1 + i, mHistory[i]);

View File

@ -1482,15 +1482,12 @@ void ProgressDialog::SetMessage(const wxString & message)
// //
bool ProgressDialog::SearchForWindow(const wxWindowList & list, const wxWindow *searchfor) const bool ProgressDialog::SearchForWindow(const wxWindowList & list, const wxWindow *searchfor) const
{ {
wxWindowList::compatibility_iterator node = list.GetFirst(); for (auto win : list)
while (node)
{ {
wxWindow *win = node->GetData();
if (win == searchfor || SearchForWindow(win->GetChildren(), searchfor)) if (win == searchfor || SearchForWindow(win->GetChildren(), searchfor))
{ {
return true; return true;
} }
node = node->GetNext();
} }
return false; return false;