Audacity 3.2.0
ListNavigationEnabled.cpp
Go to the documentation of this file.
1/*!********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 @file ListNavigationEnabled.cpp
6
7 @author Vitaly Sverchinsky
8
9**********************************************************************/
10
12
13void ListNavigationEnabled_HandleCharHook(wxWindow* self, wxKeyEvent& evt)
14{
15 //We want to restore focus to list item once arrow navigation is used
16 //on the child item, for this we need a char hook since key/navigation
17 //events are sent directly to the focused item
18 const auto keyCode = evt.GetKeyCode();
19 if((keyCode == WXK_DOWN || keyCode == WXK_UP) &&
20 !self->HasFocus() &&
21 self->IsDescendant(wxWindow::FindFocus()))
22 {
23 self->SetFocusFromKbd();
24 }
25 else
26 evt.Skip();
29void ListNavigationEnabled_HandleKeyDown(wxWindow* self, wxKeyEvent& evt)
30{
31 const auto keyCode = evt.GetKeyCode();
32 if(keyCode == WXK_TAB)
33 self->NavigateIn(wxNavigationKeyEvent::FromTab | (evt.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward));
34 else if(keyCode == WXK_DOWN)
35 self->Navigate(wxNavigationKeyEvent::IsForward);
36 else if(keyCode == WXK_UP)
37 self->Navigate(wxNavigationKeyEvent::IsBackward);
38 else
39 evt.Skip();
40}
41
42void ListNavigationEnabled_HandleNavigationKeyEvent(wxWindow* self, wxNavigationKeyEvent& evt)
43{
44 if(evt.GetEventObject() == self->GetParent() && !evt.IsFromTab())
45 self->SetFocusFromKbd();
46 else if(evt.GetEventObject() == self && evt.GetCurrentFocus() == self && evt.IsFromTab())
47 {
48 //NavigateIn
49 wxPropagationDisabler disableProp(evt);
50 const auto isForward = evt.GetDirection();
51 const auto& children = self->GetChildren();
52 auto node = isForward ? children.GetFirst() : children.GetLast();
53 while(node)
54 {
55 auto child = node->GetData();
56 if(child->CanAcceptFocusFromKeyboard())
57 {
58 if(!child->GetEventHandler()->ProcessEvent(evt))
59 {
60 child->SetFocusFromKbd();
61 }
62 evt.Skip(false);
63 return;
64 }
65 node = isForward ? node->GetNext() : node->GetPrevious();
66 }
67 }
68 else
69 evt.Skip();
70}
71
73{
74 if(self->IsDescendant(wxWindow::FindFocus()))
75 {
76 auto next = self->GetNextSibling();
77 if(next != nullptr && next->AcceptsFocus())
78 next->SetFocus();
79 else
80 {
81 auto prev = self->GetPrevSibling();
82 if(prev != nullptr && prev->AcceptsFocus())
83 prev->SetFocus();
84 }
85 }
86}
void ListNavigationEnabled_HandleNavigationKeyEvent(wxWindow *self, wxNavigationKeyEvent &evt)
void ListNavigationEnabled_HandleDestroy(wxWindow *self)
void ListNavigationEnabled_HandleKeyDown(wxWindow *self, wxKeyEvent &evt)
void ListNavigationEnabled_HandleCharHook(wxWindow *self, wxKeyEvent &evt)
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:375