37#include <wx/settings.h>
39#include <wx/valtext.h>
40#include <wx/stattext.h>
42#include <wx/statline.h>
48#include "../KeyboardCapture.h"
59#include "../widgets/AButton.h"
60#include "../widgets/auStaticText.h"
61#include "../widgets/BasicMenu.h"
62#include "../widgets/NumericTextCtrl.h"
91std::pair<const TranslatableString&, const TranslatableString&>
ModeNames[] = {
98std::unordered_map<TranslatableString, wxWindowID>
WindowIDs {
126 return wxT(
"Selection");
132 mStart(0.0), mEnd(0.0), mLength(0.0), mCenter(0.0),
183 up.Rescale(23, 23, wxIMAGE_QUALITY_HIGH);
185 down.Rescale(23, 23, wxIMAGE_QUALITY_HIGH);
187 hiliteUp.Rescale(23, 23, wxIMAGE_QUALITY_HIGH);
189 hiliteDown.Rescale(23, 23, wxIMAGE_QUALITY_HIGH);
192 this, wxID_ANY, wxDefaultPosition, wxSize { 23, 23 }, up, hiliteUp, down,
193 hiliteDown, up,
false);
198 btn->SetName(
XO(
"Selection Toolbar Setup").Translation());
205 const auto translated = Title.Translation();
208 pTitle->SetForegroundColour(
theTheme.
Colour( clrTrackPanelText ) );
209 pSizer->Add( pTitle, 0, wxEXPAND | wxRIGHT, 5 );
216 auto formatName = formats.GetSelectionFormat();
224 pSizer->Add(pCtrl, 0, wxALIGN_TOP | wxRIGHT, 5);
229 [
this,
id](
const auto& msg)
232 if (altCtrl !=
nullptr)
233 altCtrl->UpdateFormatToFit(msg.value);
243 auto showMenu = [
this, setupBtn]()
245 static const wxString choices[4] = {
246 _(
"Start and End of Selection"),
247 _(
"Start and Length of Selection"),
248 _(
"Length and End of Selection"),
249 _(
"Length and Center of Selection"),
253 int selectionMode {};
254 for (
auto& choice : choices)
256 auto subMenu = menu.AppendRadioItem(wxID_ANY, choice);
263 [
this, selectionMode](
auto& evt)
273 menu.Bind(wxEVT_MENU_CLOSE, [setupBtn](
auto&) { setupBtn->PopUp(); });
278 setupBtn->Bind(wxEVT_BUTTON, [
this, showMenu](
auto&) { showMenu(); });
279 pSizer->Add(setupBtn, 0, wxALIGN_RIGHT | wxBOTTOM | wxRIGHT, 5);
294 wxFlexGridSizer *mainSizer =
safenew wxFlexGridSizer(2, 1, 1);
295 Add(mainSizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5);
383 wxFAIL_MSG(
"Unexpected selection mode");
385 else if (driver == 1)
396 wxFAIL_MSG(
"Unexpected selection mode");
400 wxFAIL_MSG(
"Illegal selection driver");
406 if (driver == 0 &&
end < start)
408 else if (driver == 1 && start >
end)
413 end = start + length;
416 start =
end - length;
428 start = center - length / 2.0;
434 center = length / 2.0;
437 length = center * 2.0;
442 end = center + length / 2.0;
463 const auto focusedCtrlIdx =
468 auto format = evt.GetString();
474 formats.SetSelectionFormat(
format);
501 SetTimes(selectedRegion.t0(), selectedRegion.t1());
520 auto& modeName =
ModeNames[
static_cast<size_t>(mode)];
539 const double valuePairs[4][2] = {
545 const auto value = valuePairs[
static_cast<size_t>(
mSelectionMode)];
551 ctrl->SetValue(value[i]);
583 e.SetString(
format.GET());
606 wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
608 int keyCode = kevent->GetKeyCode();
611 if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9)) {
612 keyCode -= WXK_NUMPAD0 -
'0';
615 if (keyCode >=
'0' && keyCode <=
'9') {
624 for (
size_t controlIndex = 0; controlIndex <
mTimeControls.size();
635 ctrl->SetTypeAndFormatName(
644 wxSize sz = GetMinSize();
@ Internal
Indicates internal failure from Audacity.
XXO("&Cut/Copy/Paste Toolbar")
EVT_COMMAND(wxID_ANY, EVT_FREQUENCYTEXTCTRL_UPDATED, LabelDialog::OnFreqUpdate) LabelDialog
const NumericConverterType & NumericConverterType_DURATION()
const NumericConverterType & NumericConverterType_TIME()
audacity::BasicSettings * gPrefs
an object holding per-project preferred sample rate
static const AttachedProjectObjects::RegisteredFactory manager
IMPLEMENT_CLASS(SelectionBar, ToolBar)
static RegisteredToolbarFactory factory
IntSetting SelectionToolbarMode
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.
static FormatterContext ProjectContext(const AudacityProject &project)
An explicitly nonlocalized string, not meant for the user to see.
Specialization of Setting for int.
static ProjectRate & Get(AudacityProject &project)
static ProjectSelectionManager & Get(AudacityProject &project)
(not quite a Toolbar) at foot of screen for setting and viewing the selection range.
void OnIdle(wxIdleEvent &evt)
void AddTitle(const TranslatableString &Title, wxSizer *pSizer)
void ModifySelection(int driver, bool done=false)
void AddSelectionSetupButton(wxSizer *pSizer)
void SetSelectionMode(SelectionMode mode)
void SetSelectionFormat(const NumericFormatID &format)
void SelectionModeUpdated()
void AddTime(int id, wxSizer *pSizer)
void RegenerateTooltips() override
void SetTimes(double start, double end)
Observer::Subscription mFormatChangedToFitValueSubscription[2]
void Create(wxWindow *parent) override
void OnFocus(wxFocusEvent &event)
void OnSize(wxSizeEvent &evt)
void OnUpdate(wxCommandEvent &evt)
void OnFormatsChanged(struct ProjectNumericFormatsEvent)
bool ShownByDefault() const override
Whether the toolbar should be shown by default. Default implementation returns true.
static SelectionBar & Get(AudacityProject &project)
void UpdateTimeControlsFormat(const NumericFormatID &format)
SelectionMode mLastSelectionMode
SelectionMode mSelectionMode
void OnCaptureKey(wxCommandEvent &event)
SelectionBar(AudacityProject &project)
DockID DefaultDockID() const override
Which dock the toolbar defaults into. Default implementation chooses the top dock.
void UpdatePrefs() override
std::array< NumericTextCtrl *, 2 > mTimeControls
AButton * MakeSetupButton()
bool Write(const T &value)
Write value to config and return true if successful.
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined */
wxColour & Colour(int iIndex)
wxImage & Image(int iIndex)
Holds a msgid for the translation catalog; may also bind format arguments.
NotifyingSelectedRegion selectedRegion
static ViewInfo & Get(AudacityProject &project)
is like wxStaticText, except it can be themed. wxStaticText can't be.
virtual bool Flush() noexcept=0
virtual bool Read(const wxString &key, bool *value) const =0
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.
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
void OnFocus(wxWindow &window, wxFocusEvent &event)
a function useful to implement a focus event handler The window releases the keyboard if the event is...
const TranslatableString CenterTimeText
SelectionBar::SelectionMode ReadSelectionMode()
const TranslatableString LengthTimeText
AttachedToolBarMenuItem sAttachment
std::pair< const TranslatableString &, const TranslatableString & > ModeNames[]
const NumericConverterType TimeConverterType[][2]
void UpdateSelectionMode(SelectionBar::SelectionMode selectionMode)
const TranslatableString EndTimeText
std::unordered_map< TranslatableString, wxWindowID > WindowIDs
const TranslatableString StartTimeText
const char * end(const char *str) noexcept