Audacity  2.2.2
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 #include "../../../Audacity.h"
12 #include "LabelTrackControls.h"
13 #include "../../../HitTestResult.h"
14 #include "../../../LabelTrack.h"
15 #include "../../../widgets/PopupMenuTable.h"
16 #include "../../../Prefs.h"
17 #include "../../../RefreshCode.h"
18 #include "../../../ShuttleGui.h"
19 #include "../../../widgets/wxPanelWrapper.h"
20 #include <wx/dialog.h>
21 #include <wx/fontenum.h>
22 #include <wx/listbox.h>
23 #include <wx/spinctrl.h>
24 #include "../../../Internat.h"
25 
27 {
28 }
29 
30 std::vector<UIHandlePtr> LabelTrackControls::HitTest
31 (const TrackPanelMouseState & state,
32  const AudacityProject *pProject)
33 {
34  return TrackControls::HitTest(state, pProject);
35 }
36 
38 {
41 
42 public:
43  static LabelTrackMenuTable &Instance();
44 
45  void InitMenu(Menu*, void *pUserData) override
46  {
47  mpData = static_cast<TrackControls::InitMenuData*>(pUserData);
48  }
49 
50  void DestroyMenu() override
51  {
52  mpData = nullptr;
53  }
54 
56 
57  void OnSetFont(wxCommandEvent &);
58 };
59 
61 {
62  static LabelTrackMenuTable instance;
63  return instance;
64 }
65 
66 enum
67 {
68  OnSetFontID = 30000,
69 };
70 
73  POPUP_MENU_ITEM(OnSetFontID, _("&Font..."), OnSetFont)
75 
76 void LabelTrackMenuTable::OnSetFont(wxCommandEvent &)
77 {
78  // Small helper class to enumerate all fonts in the system
79  // We use this because the default implementation of
80  // wxFontEnumerator::GetFacenames() has changed between wx2.6 and 2.8
81  class FontEnumerator : public wxFontEnumerator
82  {
83  public:
84  explicit FontEnumerator(wxArrayString* fontNames) :
85  mFontNames(fontNames) {}
86 
87  bool OnFacename(const wxString& font) override
88  {
89  mFontNames->Add(font);
90  return true;
91  }
92 
93  private:
94  wxArrayString* mFontNames;
95  };
96 
97  wxArrayString facenames;
98  FontEnumerator fontEnumerator(&facenames);
99  fontEnumerator.EnumerateFacenames(wxFONTENCODING_SYSTEM, false);
100 
101  wxString facename = gPrefs->Read(wxT("/GUI/LabelFontFacename"), wxT(""));
102 
103  // Correct for empty facename, or bad preference file:
104  // get the name of a really existing font, to highlight by default
105  // in the list box
106  facename = LabelTrack::GetFont(facename).GetFaceName();
107 
108  long fontsize = gPrefs->Read(wxT("/GUI/LabelFontSize"),
110 
111  /* i18n-hint: (noun) This is the font for the label track.*/
112  wxDialogWrapper dlg(mpData->pParent, wxID_ANY, wxString(_("Label Track Font")));
113  dlg.SetName(dlg.GetTitle());
114  ShuttleGui S(&dlg, eIsCreating);
115  wxListBox *lb;
116  wxSpinCtrl *sc;
117 
118  S.StartVerticalLay(true);
119  {
120  S.StartMultiColumn(2, wxEXPAND);
121  {
122  S.SetStretchyRow(0);
123  S.SetStretchyCol(1);
124 
125  /* i18n-hint: (noun) The name of the typeface*/
126  S.AddPrompt(_("Face name"));
127  lb = safenew wxListBox(&dlg, wxID_ANY,
128  wxDefaultPosition,
129  wxDefaultSize,
130  facenames,
131  wxLB_SINGLE);
132 
133  lb->SetName(_("Face name"));
134  lb->SetSelection(facenames.Index(facename));
135  S.AddWindow(lb, wxALIGN_LEFT | wxEXPAND | wxALL);
136 
137  /* i18n-hint: (noun) The size of the typeface*/
138  S.AddPrompt(_("Face size"));
139  sc = safenew wxSpinCtrl(&dlg, wxID_ANY,
140  wxString::Format(wxT("%ld"), fontsize),
141  wxDefaultPosition,
142  wxDefaultSize,
143  wxSP_ARROW_KEYS,
144  8, 48, fontsize);
145  sc->SetName(_("Face size"));
146  S.AddWindow(sc, wxALIGN_LEFT | wxALL);
147  }
148  S.EndMultiColumn();
149  S.AddStandardButtons();
150  }
151  S.EndVerticalLay();
152 
153  dlg.Layout();
154  dlg.Fit();
155  dlg.CenterOnParent();
156  if (dlg.ShowModal() == wxID_CANCEL)
157  return;
158 
159  gPrefs->Write(wxT("/GUI/LabelFontFacename"), lb->GetStringSelection());
160  gPrefs->Write(wxT("/GUI/LabelFontSize"), sc->GetValue());
161  gPrefs->Flush();
162 
164 
165  mpData->result = RefreshCode::RefreshAll;
166 }
167 
169 {
171 }
#define POPUP_MENU_SEPARATOR()
void InitMenu(Menu *, void *pUserData) override
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
wxWindow * AddWindow(wxWindow *pWindow, int Flags=wxALIGN_CENTRE|wxALL)
Definition: ShuttleGui.cpp:257
virtual std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *) override=0
void EndMultiColumn()
#define END_POPUP_MENU()
static LabelTrackMenuTable & Instance()
void OnSetFont(wxCommandEvent &)
static void ResetFont()
Definition: LabelTrack.cpp:296
#define safenew
Definition: Audacity.h:223
void DestroyMenu() override
void AddPrompt(const wxString &Prompt)
Right aligned text string.
Definition: ShuttleGui.cpp:215
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
void EndVerticalLay()
Definition: ShuttleGui.cpp:991
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
static wxFont GetFont(const wxString &faceName, int size=DefaultFontSize)
Definition: LabelTrack.cpp:285
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
Definition: ShuttleGui.cpp:998
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:94
PopupMenuTable * GetMenuExtension(Track *pTrack) override
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
POPUP_MENU_ITEM(OnMoveUpID, _("Move Track &Up")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveUp"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveDownID
void AddStandardButtons(long buttons=eOkButton|eCancelButton, wxButton *extra=NULL)
TrackControls::InitMenuData * mpData
DECLARE_POPUP_MENU(LabelTrackMenuTable)
void SetStretchyCol(int i)
Used to modify an already placed FlexGridSizer to make a column stretchy.
Definition: ShuttleGui.cpp:192
static const int DefaultFontSize
Definition: LabelTrack.h:145
void SetStretchyRow(int i)
Used to modify an already placed FlexGridSizer to make a row stretchy.
Definition: ShuttleGui.cpp:202
BEGIN_POPUP_MENU(SpectrumVRulerMenuTable)
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:982