| 21 | namespace { |
| 22 | |
| 23 | void NextOrPrevFrame(AudacityProject &project, bool forward) |
| 24 | { |
| 25 | // Focus won't take in a dock unless at least one descendant window |
| 26 | // accepts focus. Tell controls to take focus for the duration of this |
| 27 | // function, only. Outside of this, they won't steal the focus when |
| 28 | // clicked. |
| 29 | auto temp1 = AButton::TemporarilyAllowFocus(); |
| 30 | auto temp2 = ASlider::TemporarilyAllowFocus(); |
| 31 | auto temp3 = MeterPanel::TemporarilyAllowFocus(); |
| 32 | |
| 33 | std::vector<wxWindow*> seq; |
| 34 | // Skip docks that are empty (Bug 1564). |
| 35 | if(!ToolManager::Get(project).GetTopDock()->GetChildren().IsEmpty()) |
| 36 | seq.push_back(ProjectWindow::Get( project ).GetTopPanel()); |
| 37 | seq.push_back(&TrackPanel::Get( project )); |
| 38 | seq.push_back(&RealtimeEffectPanel::Get(project)); |
| 39 | if(!ToolManager::Get( project ).GetBotDock()->GetChildren().IsEmpty()) |
| 40 | seq.push_back(ToolManager::Get( project ).GetBotDock()); |
| 41 | |
| 42 | auto FindAncestor = [&]() { |
| 43 | wxWindow *pWindow = wxWindow::FindFocus(); |
| 44 | while (pWindow) |
| 45 | { |
| 46 | auto it = std::find(seq.cbegin(), seq.cend(), pWindow); |
| 47 | if(it != seq.cend()) |
| 48 | return static_cast<size_t>(std::distance(seq.cbegin(), it)); |
| 49 | pWindow = pWindow->GetParent(); |
| 50 | } |
| 51 | return seq.size(); |
| 52 | }; |
| 53 | |
| 54 | const auto idx = FindAncestor(); |
| 55 | if (idx == seq.size()) |
| 56 | return; |
| 57 | |
| 58 | auto idx2 = idx; |
| 59 | const auto increment = (forward ? 1 : static_cast<int>(seq.size()) - 1); |
| 60 | |
| 61 | while( idx != (idx2 = (idx2 + increment) % seq.size()) ) { |
| 62 | wxWindow *toFocus = seq[idx2]; |
| 63 | if(!toFocus->IsShown()) |
| 64 | continue; |
| 65 | |
| 66 | toFocus->SetFocus(); |
| 67 | if ( FindAncestor() == idx2 ) |
| 68 | // The focus took! |
| 69 | break; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /// \todo Merge related methods, OnPrevTrack and OnNextTrack. |
| 74 | void DoPrevTrack( |
no test coverage detected