Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup Class Referencefinal
Inheritance diagram for anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup:
[legend]
Collaboration diagram for anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup:
[legend]

Public Member Functions

 SnapModePopup (AudacityProject &project)
 
void Init () override
 
bool Create (wxWindow *parent) override
 
wxWindow * GetControl () override
 
wxString GetStringValue () const override
 
void OnPopup () override
 
void SetStringValue (const wxString &value) override
 
bool FindItem (const wxString &item, wxString *trueItem=NULL) override
 
void OnComboKeyEvent (wxKeyEvent &event) override
 
void OnComboCharEvent (wxKeyEvent &event) override
 
void UpdateCurrentIndex (const Identifier &identifier)
 

Private Attributes

AudacityProjectmProject
 
wxWeakRef< wxWindow > mControl
 
std::vector< IdentifiermSnapToList
 
std::ptrdiff_t mCurrentIndex { -1 }
 
Observer::Subscription mSnappingModeChangedSubscription
 

Detailed Description

Definition at line 56 of file SnappingToolBar.cpp.

Constructor & Destructor Documentation

◆ SnapModePopup()

anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::SnapModePopup ( AudacityProject project)
inlineexplicit

Definition at line 59 of file SnappingToolBar.cpp.

60 : mProject { project }
62 [this](auto& msg) {
63 UpdateCurrentIndex(msg.newSnapTo);
64
65 auto comboCtrl = GetComboCtrl();
66
67 comboCtrl->SetValue(
68 GetSnapToLabel(msg.newSnapTo).Translation());
69
70 comboCtrl->SetName(GetComboCtrl()->GetValue());
71 }))
72 {
73 }
const auto project
static ProjectSnap & Get(AudacityProject &project)
Definition: ProjectSnap.cpp:27
wxString Translation() const
TranslatableString GetSnapToLabel(Identifier snapTo)

References anonymous_namespace{SnappingToolBar.cpp}::GetSnapToLabel(), and TranslatableString::Translation().

Here is the call graph for this function:

Member Function Documentation

◆ Create()

bool anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::Create ( wxWindow *  parent)
inlineoverride

Definition at line 85 of file SnappingToolBar.cpp.

86 {
87 mControl = safenew wxWindow(parent, wxID_ANY);
88
89 // This call cannot happen in Init(), because the combobox is not yet in a valid
90 // state. Doing a deferred call from Init() is unsafe,
91 // as in some cases Audacity recreates the combobox multiple times before the next
92 // event loop iteration.
93 GetComboCtrl()->SetValue(GetStringValue());
94
95 return mControl;
96 }
#define safenew
Definition: MemoryX.h:10

References safenew.

◆ FindItem()

bool anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::FindItem ( const wxString &  item,
wxString *  trueItem = NULL 
)
inlineoverride

Definition at line 165 of file SnappingToolBar.cpp.

166 {
167 return wxComboPopup::FindItem(item, trueItem);
168 }

◆ GetControl()

wxWindow * anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::GetControl ( )
inlineoverride

Definition at line 98 of file SnappingToolBar.cpp.

99 {
100 return mControl;
101 }

◆ GetStringValue()

wxString anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::GetStringValue ( ) const
inlineoverride

Definition at line 103 of file SnappingToolBar.cpp.

104 {
106 }
Identifier ReadSnapTo()
Definition: SnapUtils.cpp:90

References anonymous_namespace{SnappingToolBar.cpp}::GetSnapToLabel(), ReadSnapTo(), and TranslatableString::Translation().

Here is the call graph for this function:

◆ Init()

void anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::Init ( )
inlineoverride

Definition at line 75 of file SnappingToolBar.cpp.

76 {
77 // Build a linear list from all the items in the snap functions registry
78 SnapFunctionsRegistry::Visit([this](const SnapRegistryItem& item, auto&) {
79 mSnapToList.push_back(item.name);
80 });
81
83 }
const Identifier name
Definition: Registry.h:86
static void Visit(const SnapRegistryVisitor &visitor)
Definition: SnapUtils.cpp:110

References Registry::detail::BaseItem::name, ReadSnapTo(), and SnapFunctionsRegistry::Visit().

Here is the call graph for this function:

◆ OnComboCharEvent()

void anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::OnComboCharEvent ( wxKeyEvent &  event)
inlineoverride

Definition at line 205 of file SnappingToolBar.cpp.

206 {
207 // Consume the event to prevent editing
208 }

◆ OnComboKeyEvent()

void anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::OnComboKeyEvent ( wxKeyEvent &  event)
inlineoverride

Definition at line 170 of file SnappingToolBar.cpp.

171 {
172 const auto keyCode = event.GetKeyCode();
173
174 if (keyCode == WXK_RETURN || keyCode == WXK_NUMPAD_ENTER)
175 {
176 GetComboCtrl()->ShowPopup();
177 return;
178 }
179
180 int direction = 0;
181
182 if (
183 keyCode == WXK_UP || keyCode == WXK_NUMPAD_UP || keyCode == WXK_LEFT ||
184 keyCode == WXK_NUMPAD_LEFT)
185 direction = -1;
186 else if (
187 keyCode == WXK_DOWN || keyCode == WXK_NUMPAD_DOWN ||
188 keyCode == WXK_RIGHT || keyCode == WXK_NUMPAD_RIGHT)
189 direction = 1;
190
191 if (direction == 0)
192 return;
193
194 const auto newIndex = std::clamp<ptrdiff_t>(
195 mCurrentIndex + direction, 0, mSnapToList.size() - 1);
196
197 if (newIndex == mCurrentIndex)
198 return;
199
200 mCurrentIndex = newIndex;
201
203 }
void SetSnapTo(Identifier snap)
Definition: ProjectSnap.cpp:59

References ProjectSnap::Get(), and ProjectSnap::SetSnapTo().

Here is the call graph for this function:

◆ OnPopup()

void anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::OnPopup ( )
inlineoverride

Definition at line 108 of file SnappingToolBar.cpp.

109 {
110 // Build a popup menu based on snap functions registry
111 wxMenu menu;
112 std::vector<wxMenu*> menuStack{ &menu };
113
114 const auto visitor = std::tuple{
115 [&](const SnapRegistryGroup& item, auto &) {
116 if (item.Inlined())
117 return;
118
119 auto menu = safenew wxMenu;
120
121 menuStack.back()->AppendSubMenu(menu, item.Label().Translation());
122 menuStack.push_back(menu);
123 },
124 [&, this](const SnapRegistryItem& item, auto &) {
125 auto menuItem = menuStack.back()->AppendCheckItem(wxID_ANY, item.label.Translation());
126
127 if (ReadSnapTo() == item.name)
128 menuItem->Check();
129
130 menuStack.back()->Bind(
131 wxEVT_MENU,
132 [this, id = item.name](wxCommandEvent&) {
134 },
135 menuItem->GetId()
136 );
137 },
138 [&](const SnapRegistryGroup& item, auto &) {
139 assert(!menuStack.empty());
140
141 if (item.Inlined())
142 {
143 menuStack.back()->AppendSeparator();
144 return;
145 }
146
147 menuStack.pop_back();
148 }
149 };
151
152 BasicMenu::Handle { &menu }.Popup(
153 wxWidgetsWindowPlacement { GetComboCtrl() },
154 { 0, GetComboCtrl()->GetSize().y });
155
156 // Hide the combobox list after the menu was closed
157 BasicUI::CallAfter([this] { Dismiss(); });
158 }
void Popup(const BasicUI::WindowPlacement &window, const Point &pos={})
Display the menu at pos, invoke at most one action, then hide it.
Definition: BasicMenu.cpp:209
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:214
const TranslatableString & Label() const
Definition: SnapUtils.h:73
bool Inlined() const
Definition: SnapUtils.h:72
const TranslatableString label
Definition: SnapUtils.h:82
Window placement information for wxWidgetsBasicUI can be constructed from a wxWindow pointer.

References BasicUI::CallAfter(), ProjectSnap::Get(), SnapRegistryGroup::Inlined(), SnapRegistryGroupData::label, SnapRegistryGroup::Label(), BasicMenu::Handle::Popup(), ReadSnapTo(), safenew, ProjectSnap::SetSnapTo(), TranslatableString::Translation(), and SnapFunctionsRegistry::Visit().

Here is the call graph for this function:

◆ SetStringValue()

void anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::SetStringValue ( const wxString &  value)
inlineoverride

Definition at line 160 of file SnappingToolBar.cpp.

161 {
162 wxComboPopup::SetStringValue(value);
163 }

◆ UpdateCurrentIndex()

void anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::UpdateCurrentIndex ( const Identifier identifier)
inline

Definition at line 210 of file SnappingToolBar.cpp.

211 {
212 if (
213 mCurrentIndex < mSnapToList.size() &&
214 mSnapToList[mCurrentIndex] == identifier)
215 return;
216
217 mCurrentIndex = static_cast<size_t>(std::distance(
218 mSnapToList.begin(),
219 std::find(mSnapToList.begin(), mSnapToList.end(), identifier)));
220 }

Member Data Documentation

◆ mControl

wxWeakRef<wxWindow> anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::mControl
private

Definition at line 224 of file SnappingToolBar.cpp.

◆ mCurrentIndex

std::ptrdiff_t anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::mCurrentIndex { -1 }
private

Definition at line 227 of file SnappingToolBar.cpp.

◆ mProject

AudacityProject& anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::mProject
private

Definition at line 223 of file SnappingToolBar.cpp.

◆ mSnappingModeChangedSubscription

Observer::Subscription anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::mSnappingModeChangedSubscription
private

Definition at line 229 of file SnappingToolBar.cpp.

◆ mSnapToList

std::vector<Identifier> anonymous_namespace{SnappingToolBar.cpp}::SnapModePopup::mSnapToList
private

Definition at line 226 of file SnappingToolBar.cpp.


The documentation for this class was generated from the following file: