18#include <wx/checkbox.h>
21#include <wx/textctrl.h>
39#if wxUSE_ACCESSIBILITY
49 return item !=
nullptr ? item->label :
XO(
"Unknown");
63 UpdateCurrentIndex(msg.newSnapTo);
65 auto comboCtrl = GetComboCtrl();
70 comboCtrl->SetName(GetComboCtrl()->GetValue());
79 mSnapToList.push_back(item.
name);
85 bool Create(wxWindow* parent)
override
87 mControl =
safenew wxWindow(parent, wxID_ANY);
93 GetComboCtrl()->SetValue(GetStringValue());
112 std::vector<wxMenu*> menuStack{ &menu };
114 const auto visitor = std::tuple{
122 menuStack.push_back(menu);
125 auto menuItem = menuStack.back()->AppendCheckItem(wxID_ANY, item.
label.
Translation());
130 menuStack.back()->Bind(
132 [
this,
id = item.name](wxCommandEvent&) {
139 assert(!menuStack.empty());
143 menuStack.back()->AppendSeparator();
147 menuStack.pop_back();
154 { 0, GetComboCtrl()->GetSize().y });
162 wxComboPopup::SetStringValue(value);
165 bool FindItem(
const wxString& item, wxString* trueItem = NULL)
override
167 return wxComboPopup::FindItem(item, trueItem);
172 const auto keyCode =
event.GetKeyCode();
174 if (keyCode == WXK_RETURN || keyCode == WXK_NUMPAD_ENTER)
176 GetComboCtrl()->ShowPopup();
183 keyCode == WXK_UP || keyCode == WXK_NUMPAD_UP || keyCode == WXK_LEFT ||
184 keyCode == WXK_NUMPAD_LEFT)
187 keyCode == WXK_DOWN || keyCode == WXK_NUMPAD_DOWN ||
188 keyCode == WXK_RIGHT || keyCode == WXK_NUMPAD_RIGHT)
194 const auto newIndex = std::clamp<ptrdiff_t>(
195 mCurrentIndex + direction, 0, mSnapToList.size() - 1);
197 if (newIndex == mCurrentIndex)
200 mCurrentIndex = newIndex;
213 mCurrentIndex < mSnapToList.size() &&
214 mSnapToList[mCurrentIndex] == identifier)
217 mCurrentIndex =
static_cast<size_t>(std::distance(
219 std::find(mSnapToList.begin(), mSnapToList.end(), identifier)));
227 std::ptrdiff_t mCurrentIndex { -1 };
241 return wxT(
"Snapping");
246 , mSnappingModeChangedSubscription(
ProjectSnap::
Get(mProject).Subscribe(
259 SetMinSize({ -1, height });
260 SetMaxSize({ -1, height });
299 auto sizer =
safenew wxFlexGridSizer(1, 1, 1);
300 Add(sizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5);
302 auto boxSizer =
safenew wxBoxSizer(wxHORIZONTAL);
307#if wxUSE_ACCESSIBILITY
316 boxSizer->Add(snapLabelCtrl, 0, wxEXPAND, 0);
318 sizer->Add(boxSizer, 0, wxBOTTOM | wxRIGHT | wxEXPAND, 5);
320 const bool snapEnabled =
327 this, wxID_ANY, {}, wxDefaultPosition, wxDefaultSize );
328#if wxUSE_ACCESSIBILITY
337 mSnapToCombo->GetTextCtrl()->SetName(
XO(
"Snap to combo box").Translation());
353 const auto keyCode = evt.GetKeyCode();
355 if (keyCode != WXK_NUMPAD_ENTER && keyCode != WXK_RETURN)
368 [snapLabelCtrl](
auto&) { snapLabelCtrl->SetSelected(
true); });
372 [snapLabelCtrl](
auto&) { snapLabelCtrl->SetSelected(
false); });
377 wxEVT_KILL_FOCUS, [
this](
auto&) {
mSnapToCombo->SelectNone(); });
XXO("&Cut/Copy/Paste Toolbar")
static Settings & settings()
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
void Popup(const BasicUI::WindowPlacement &window, const Point &pos={})
Display the menu at pos, invoke at most one action, then hide it.
An explicitly nonlocalized string, not meant for the user to see.
A move-only handle representing a connection to a Publisher.
Project snapping settings.
void SetSnapMode(SnapMode mode)
void SetSnapTo(Identifier snap)
static ProjectSnap & Get(AudacityProject &project)
SnapMode GetSnapMode() const
wxColour & Colour(int iIndex)
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const
TranslatableString Stripped(unsigned options=MenuCodes) const
non-mutating, constructs another TranslatableString object
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
is like wxStaticText, except it can be themed. wxStaticText can't be.
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
static const SnapRegistryItem * Find(const Identifier &id)
static void Visit(const SnapRegistryVisitor &visitor)
const TranslatableString label
const TranslatableString & Label() const