Audacity  3.0.3
LabelTrackControls.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 LabelTrackControls.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 
12 #include "LabelTrackControls.h"
13 
14 #include "LabelTrackView.h"
15 #include "../../../HitTestResult.h"
16 #include "../../../LabelTrack.h"
17 #include "../../../widgets/PopupMenuTable.h"
18 #include "Prefs.h"
19 #include "../../../RefreshCode.h"
20 #include "../../../ShuttleGui.h"
21 #include "../../../widgets/wxPanelWrapper.h"
22 #include <wx/dialog.h>
23 #include <wx/fontenum.h>
24 #include <wx/listbox.h>
25 #include <wx/spinctrl.h>
26 
28 {
29 }
30 
31 std::vector<UIHandlePtr> LabelTrackControls::HitTest
32 (const TrackPanelMouseState & state,
33  const AudacityProject *pProject)
34 {
35  return CommonTrackControls::HitTest(state, pProject);
36 }
37 
39 {
41  : PopupMenuTable{ "LabelTrack" }
42  {}
44 
45 public:
46  static LabelTrackMenuTable &Instance();
47 
48  void InitUserData(void *pUserData) override
49  {
50  mpData = static_cast<CommonTrackControls::InitMenuData*>(pUserData);
51  }
52 
53  void DestroyMenu() override
54  {
55  mpData = nullptr;
56  }
57 
59 
60  void OnSetFont(wxCommandEvent &);
61 };
62 
64 {
65  static LabelTrackMenuTable instance;
66  return instance;
67 }
68 
69 enum
70 {
71  OnSetFontID = 30000,
72 };
73 
75  BeginSection( "Basic" );
76  AppendItem( "Font", OnSetFontID, XXO("&Font..."), POPUP_MENU_FN( OnSetFont ) );
79 
80 void LabelTrackMenuTable::OnSetFont(wxCommandEvent &)
81 {
82  // Small helper class to enumerate all fonts in the system
83  // We use this because the default implementation of
84  // wxFontEnumerator::GetFacenames() has changed between wx2.6 and 2.8
85  class FontEnumerator : public wxFontEnumerator
86  {
87  public:
88  explicit FontEnumerator(wxArrayString* fontNames) :
89  mFontNames(fontNames) {}
90 
91  bool OnFacename(const wxString& font) override
92  {
93  mFontNames->push_back(font);
94  return true;
95  }
96 
97  private:
98  wxArrayString* mFontNames;
99  };
100 
101  wxArrayString facenames;
102  FontEnumerator fontEnumerator(&facenames);
103  fontEnumerator.EnumerateFacenames(wxFONTENCODING_SYSTEM, false);
104 
105  wxString facename = gPrefs->Read(wxT("/GUI/LabelFontFacename"), wxT(""));
106 
107  // Correct for empty facename, or bad preference file:
108  // get the name of a really existing font, to highlight by default
109  // in the list box
110  facename = LabelTrackView::GetFont(facename).GetFaceName();
111 
112  long fontsize = gPrefs->Read(wxT("/GUI/LabelFontSize"),
114 
115  /* i18n-hint: (noun) This is the font for the label track.*/
116  wxDialogWrapper dlg(mpData->pParent, wxID_ANY, XO("Label Track Font"));
117  dlg.SetName();
118  ShuttleGui S(&dlg, eIsCreating);
119  wxListBox *lb;
120  wxSpinCtrl *sc;
121 
122  S.StartVerticalLay(true);
123  {
124  S.StartMultiColumn(2, wxEXPAND);
125  {
126  S.SetStretchyRow(0);
127  S.SetStretchyCol(1);
128 
129  /* i18n-hint: (noun) The name of the typeface*/
130  S.AddPrompt(XXO("Face name"));
131  lb = safenew wxListBox(S.GetParent(), wxID_ANY,
132  wxDefaultPosition,
133  wxDefaultSize,
134  facenames,
135  wxLB_SINGLE);
136 
137  lb->SetSelection( make_iterator_range( facenames ).index( facename ));
138  S
139  .Name(XO("Face name"))
140  .Position( wxALIGN_LEFT | wxEXPAND | wxALL )
141  .AddWindow(lb);
142 
143  /* i18n-hint: (noun) The size of the typeface*/
144  S.AddPrompt(XXO("Face size"));
145  sc = safenew wxSpinCtrl(S.GetParent(), wxID_ANY,
146  wxString::Format(wxT("%ld"), fontsize),
147  wxDefaultPosition,
148  wxDefaultSize,
149  wxSP_ARROW_KEYS,
150  8, 48, fontsize);
151  S
152  .Name(XO("Face size"))
153  .Position( wxALIGN_LEFT | wxALL )
154  .AddWindow(sc);
155  }
156  S.EndMultiColumn();
157  S.AddStandardButtons();
158  }
159  S.EndVerticalLay();
160 
161  dlg.Layout();
162  dlg.Fit();
163  dlg.CenterOnParent();
164  if (dlg.ShowModal() == wxID_CANCEL)
165  return;
166 
167  gPrefs->Write(wxT("/GUI/LabelFontFacename"), lb->GetStringSelection());
168  gPrefs->Write(wxT("/GUI/LabelFontSize"), sc->GetValue());
169  gPrefs->Flush();
170 
172 
173  mpData->result = RefreshCode::RefreshAll;
174 }
175 
177 {
179 }
180 
182 template<> template<> auto DoGetLabelTrackControls::Implementation() -> Function {
183  return [](LabelTrack &track) {
184  return std::make_shared<LabelTrackControls>( track.SharedPointer() );
185  };
186 }
188 
190 template<> template<>
192  return [](LabelTrack &) {
193  // Label tracks are narrow
194  // Default is to allow two rows so that NEW users get the
195  // idea that labels can 'stack' when they would overlap.
196  return 73;
197  };
198 }
LabelTrackControls::~LabelTrackControls
~LabelTrackControls()
Definition: LabelTrackControls.cpp:27
eIsCreating
@ eIsCreating
Definition: ShuttleGui.h:38
ShuttleGuiBase::StartVerticalLay
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:1184
make_iterator_range
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:549
LabelTrackMenuTable::LabelTrackMenuTable
LabelTrackMenuTable()
Definition: LabelTrackControls.cpp:40
RefreshCode::RefreshAll
@ RefreshAll
Definition: RefreshCode.h:26
registerDoGetLabelTrackControls
static DoGetLabelTrackControls registerDoGetLabelTrackControls
Definition: LabelTrackControls.cpp:187
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
PopupMenuTable
Definition: PopupMenuTable.h:104
LabelTrackMenuTable::DestroyMenu
void DestroyMenu() override
Definition: LabelTrackControls.cpp:53
LabelTrackMenuTable::DECLARE_POPUP_MENU
DECLARE_POPUP_MENU(LabelTrackMenuTable)
XO
#define XO(s)
Definition: Internat.h:31
LabelTrackView::GetFont
static wxFont GetFont(const wxString &faceName, int size=DefaultFontSize)
Definition: LabelTrackView.cpp:241
LabelTrackMenuTable::mpData
CommonTrackControls::InitMenuData * mpData
Definition: LabelTrackControls.cpp:58
LabelTrackControls.h
LabelTrack
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:88
ShuttleGuiBase::EndMultiColumn
void EndMultiColumn()
Definition: ShuttleGui.cpp:1238
OnSetFontID
@ OnSetFontID
Definition: LabelTrackControls.cpp:71
AttachedVirtualFunction::Override::Implementation
static Function Implementation()
A function returning a std::function that must be defined so that the program links.
Definition: LabelTrackControls.cpp:182
XXO
#define XXO(s)
Definition: Internat.h:44
LabelTrackControls::HitTest
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
Definition: LabelTrackControls.cpp:32
CommonTrackControls::HitTest
virtual std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *) override=0
Definition: CommonTrackControls.cpp:35
ShuttleGuiBase::StartMultiColumn
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:1229
ShuttleGuiBase::EndVerticalLay
void EndVerticalLay()
Definition: ShuttleGui.cpp:1203
LabelTrackView::DefaultFontSize
@ DefaultFontSize
Definition: LabelTrackView.h:47
LabelTrackMenuTable::OnSetFont
void OnSetFont(wxCommandEvent &)
Definition: LabelTrackControls.cpp:80
LabelTrackMenuTable::InitUserData
void InitUserData(void *pUserData) override
Definition: LabelTrackControls.cpp:48
LabelTrackView.h
ShuttleGuiBase::GetParent
wxWindow * GetParent()
Definition: ShuttleGui.h:496
ShuttleGuiBase::AddWindow
wxWindow * AddWindow(wxWindow *pWindow, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:299
CommonTrackControls::InitMenuData
Definition: CommonTrackControls.h:34
wxDialogWrapper::SetName
void SetName(const TranslatableString &title)
Definition: wxPanelWrapper.cpp:76
POPUP_MENU_FN
#define POPUP_MENU_FN(memFn)
Definition: PopupMenuTable.h:313
LabelTrackMenuTable::Instance
static LabelTrackMenuTable & Instance()
Definition: LabelTrackControls.cpp:63
BEGIN_POPUP_MENU
#define BEGIN_POPUP_MENU(HandlerClass)
Definition: PopupMenuTable.h:305
ShuttleGui::Name
ShuttleGui & Name(const TranslatableString &name)
Definition: ShuttleGui.h:663
EndSection
EndSection()
wxDialogWrapper
Definition: wxPanelWrapper.h:81
LabelTrackControls::GetMenuExtension
PopupMenuTable * GetMenuExtension(Track *pTrack) override
Definition: LabelTrackControls.cpp:176
FileConfig::Flush
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
LabelTrackView::ResetFont
static void ResetFont()
Definition: LabelTrackView.cpp:257
ShuttleGui::Position
ShuttleGui & Position(int flags)
Definition: ShuttleGui.h:712
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
LabelTrackMenuTable
Definition: LabelTrackControls.cpp:39
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:113
registerGetDefaultLabelTrackHeight
static GetDefaultLabelTrackHeight registerGetDefaultLabelTrackHeight
Definition: LabelTrackControls.cpp:199
TrackPanelMouseState
Definition: TrackPanelMouseEvent.h:28
AttachedVirtualFunction::Override
For defining overrides of the method.
Definition: AttachedVirtualFunction.h:190
ShuttleGui::AddStandardButtons
void AddStandardButtons(long buttons=eOkButton|eCancelButton, wxWindow *extra=NULL)
Definition: ShuttleGui.cpp:2432
Prefs.h
AppendItem
AppendItem("Font", OnSetFontID, XXO("&Font..."), POPUP_MENU_FN(OnSetFont))
ShuttleGuiBase::AddPrompt
void AddPrompt(const TranslatableString &Prompt, int wrapWidth=0)
Right aligned text string.
Definition: ShuttleGui.cpp:238
safenew
#define safenew
Definition: MemoryX.h:10
ShuttleGuiBase::SetStretchyCol
void SetStretchyCol(int i)
Used to modify an already placed FlexGridSizer to make a column stretchy.
Definition: ShuttleGui.cpp:202
BeginSection
BeginSection("Basic")
ShuttleGuiBase::SetStretchyRow
void SetStretchyRow(int i)
Used to modify an already placed FlexGridSizer to make a row stretchy.
Definition: ShuttleGui.cpp:212
AttachedVirtualFunction::Function
std::function< Return(Object &, Arguments...) > Function
This member name is declared in this class template and redeclared in each override.
Definition: AttachedVirtualFunction.h:167
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
END_POPUP_MENU
#define END_POPUP_MENU()
Definition: PopupMenuTable.h:320