Audacity  2.2.2
AutomationCommands.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity - A Digital Audio Editor
4  Copyright 1999-2009 Audacity Team
5  License: wxWidgets
6 
7  Dan Horgan
8 
9 ******************************************************************//*******************************************************************/
19 
20 #include "AutomationCommands.h"
21 #include "../Project.h"
22 #include "CommandManager.h"
23 #include "../widgets/Overlay.h"
24 #include "../widgets/OverlayPanel.h"
25 #include "../TrackPanel.h"
26 
28 {
29  return mCustomName;
30 }
31 
33 {
34  auto infoTypeValidator = make_movable<OptionValidator>();
35  infoTypeValidator->AddOption(wxT("Menus"));
36  infoTypeValidator->AddOption(wxT("Menus+"));
37  infoTypeValidator->AddOption(wxT("Keycodes"));
38  infoTypeValidator->AddOption(wxT("Boxes"));
39 
40  signature.AddParameter(wxT("Type"), "Menus", std::move(infoTypeValidator));
41 }
42 
43 CommandHolder AutomationCommandsType::Create(std::unique_ptr<CommandOutputTarget> &&target)
44 {
45  return std::make_shared<AutomationCommands>(*this, std::move(target));
46 }
47 
48 
49 
50 void AutomationCommands::ExploreMenu( wxMenu * pMenu, int Id, int depth ){
51  Id;//compiler food.
52  if( !pMenu )
53  return;
54 
55  wxMenuItemList list = pMenu->GetMenuItems();
56  size_t lcnt = list.GetCount();
57  wxMenuItem * item;
58  wxString Label;
59  wxString Accel;
60 
61  for (size_t lndx = 0; lndx < lcnt; lndx++) {
62  item = list.Item(lndx)->GetData();
63  Label = item->GetItemLabelText();
64  Accel = item->GetItemLabel();
65  if( Accel.Contains("\t") )
66  Accel = Accel.AfterLast('\t');
67  else
68  Accel = "";
69  if( item->IsSeparator() )
70  Label = "----";
71  int flags = 0;
72  if (item->IsSubMenu())
73  flags +=1;
74  if (item->IsCheck() && item->IsChecked())
75  flags +=2;
76 
77  Status( wxString::Format(" [ %2i, %2i, \"%s\", \"%s\" ],", depth, flags, Label,Accel ));
78  if (item->IsSubMenu()) {
79  pMenu = item->GetSubMenu();
80  ExploreMenu( pMenu, item->GetId(), depth+1 );
81  }
82  }
83 }
84 
86 {
87  wxMenuBar * pBar = context.GetProject()->GetMenuBar();
88  if(!pBar ){
89  wxLogDebug("No menus");
90  return false;
91  }
92 
93  size_t cnt = pBar->GetMenuCount();
94  size_t i;
95  wxString Label;
96  Status( "AudacityMenus[" );
97  for(i=0;i<cnt;i++)
98  {
99  Label = pBar->GetMenuLabelText( i );
100  Status( wxString::Format(" [ %2i, %2i, \"%s\", \"%s\" ],", 0, 0, Label, "" ));
101  ExploreMenu( pBar->GetMenu( i ), pBar->GetId(), 1 );
102  }
103  Status( "];" );
104  return true;
105 }
106 
107 
108 
110 {
111  bool bShowStatus = true;
112  wxArrayString names;
113  CommandManager *cmdManager = context.GetProject()->GetCommandManager();
114  cmdManager->GetAllCommandNames(names, false);
115  wxArrayString::iterator iter;
116  for (iter = names.begin(); iter != names.end(); ++iter)
117  {
118  wxString name = *iter;
119  wxString out = name;
120  if (bShowStatus)
121  {
122  out += wxT("\t");
123  out += cmdManager->GetEnabled(name) ? wxT("Enabled") : wxT("Disabled");
124  }
125  Status(out);
126  }
127  return true;
128 }
129 
131 {
132  bool bShowStatus = true;
133  wxArrayString names;
134  CommandManager *cmdManager = context.GetProject()->GetCommandManager();
135  cmdManager->GetAllCommandNames(names, false);
136  wxArrayString::iterator iter;
137  for (iter = names.begin(); iter != names.end(); ++iter)
138  {
139  wxString name = *iter;
140  wxString out = name;
141  if (bShowStatus)
142  {
143  out += wxT("\t");
144  out += cmdManager->GetEnabled(name) ? wxT("Enabled") : wxT("Disabled");
145  }
146  Status(out);
147  }
148  return true;
149 }
150 
152 {
153  Status("Keycodes");
154  return true;
155 }
156 
158  wxPoint WXUNUSED(P), wxWindow * pWin, int WXUNUSED(Id), int depth )
159 {
160  // Dang! wxMenuBar returns bogus screen rect.
161  // We're going to have to fake it instead.
162  //wxMenuBar * pBar = context.GetProject()->GetMenuBar();
163  //wxRect R = pBar->GetScreenRect();
164  //R.SetPosition( R.GetPosition() - P );
165 
166  wxRect R1 = pWin->GetScreenRect();
167  wxSize s = pWin->GetWindowBorderSize();
168  wxRect R( 2,32, R1.GetWidth() - s.GetWidth() * 2 -16, 22 );
169 
170  Status( wxString::Format(" [ %2i, %3i, %3i, %3i, %3i, \"%s\" ],",
171  depth, R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom(), "MenuBar" ));
172 }
173 
175  wxPoint P, wxWindow * pWin, int WXUNUSED(Id), int depth )
176 {
177  AudacityProject * pProj = context.GetProject();
178  TrackPanel * pTP = pProj->GetTrackPanel();
179 
180  wxRect trackRect = pWin->GetRect();
181 
182  VisibleTrackIterator iter(pProj);
183  for (Track *t = iter.First(); t; t = iter.Next()) {
184  trackRect.y = t->GetY() - pTP->mViewInfo->vpos;
185  trackRect.height = t->GetHeight();
186 
187 #if 0
188  // Work in progress on getting the TCP button positions and sizes.
189  wxRect rect = trackRect;
190  Track *l = t->GetLink();
191 
192  if (t->GetLinked()) {
193  rect.height += l->GetHeight();
194  }
195 
196  switch (t->GetKind()) {
197  case Track::Wave:
198  {
199  break;
200  }
201 #ifdef USE_MIDI
202  case Track::Note:
203  {
204  break;
205  }
206 #endif // USE_MIDI
207  case Track::Label:
208  break;
209  case Track::Time:
210  break;
211  }
212  {
213  // Start with whole track rect
214  wxRect R = trackRect;
215 
216  // Now exclude left, right, and top insets
217  R.x += kLeftInset;
218  R.y += kTopInset;
219  R.width -= kLeftInset * 2;
220  R.height -= kTopInset;
221 
222  int labelw = pTP->GetLabelWidth();
223  int vrul = pTP->GetVRulerOffset();
224  bool bIsWave = true;
225  //mTrackInfo.DrawBackground(dc, R, t->GetSelected(), bIsWave, labelw, vrul);
226 
227 
228  for (Overlay * pOverlay : pTP->mOverlays) {
229  auto R2(pOverlay->GetRectangle(trackRect.GetSize()).first);
230  Status( wxString::Format(" [ %2i, %3i, %3i, %3i, %3i, \"%s\" ],",
231  depth, R2.GetLeft(), R2.GetTop(), R2.GetRight(), R2.GetBottom(), "Overthing" ));
232  }
233  }
234 #endif
235 
236  // The VRuler.
237  {
238  wxRect R = trackRect;
239  R.x += pTP->GetVRulerOffset();
240  R.y += kTopMargin;
241  R.width = pTP->GetVRulerWidth();
242  R.height -= (kTopMargin + kBottomMargin);
243  R.SetPosition( R.GetPosition() + P );
244 
245  Status( wxString::Format(" [ %2i, %3i, %3i, %3i, %3i, \"%s\" ],",
246  depth, R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom(), "VRuler" ));
247  }
248  }
249 }
250 
251 
253  wxPoint P, wxWindow * pWin, int Id, int depth )
254 {
255  Id;//Compiler food.
256 
257  if( pWin->GetName() == "Track Panel" )
258  {
259  wxRect R = pWin->GetScreenRect();
260  ExploreTrackPanel( context, R.GetPosition()-P, pWin, Id, depth );
261  return;
262  }
263  wxWindowList list = pWin->GetChildren();
264  size_t lcnt = list.GetCount();
265 
266  for (size_t lndx = 0; lndx < lcnt; lndx++) {
267  wxWindow * item = list[lndx];
268  if( !item->IsShown() )
269  continue;
270  wxRect R = item->GetScreenRect();
271  R.SetPosition( R.GetPosition() - P );
272  wxString Name = item->GetName();
273  // Ignore staticLine and StaticBitmap.
274  if( Name.StartsWith( "static" ) )
275  continue;
276  // Ignore anonymous panels.
277  if( Name == "panel" )
278  continue;
279  if( Name.IsEmpty() )
280  Name = wxString("*") + item->GetToolTipText();
281  Status( wxString::Format(" [ %2i, %3i, %3i, %3i, %3i, \"%s\" ],",
282  depth, R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom(), Name ));
283  ExploreWindows( context, P, item, item->GetId(), depth+1 );
284  }
285 }
286 
287 
289 {
290  Status("Boxes");
291  wxWindow * pWin = context.GetProject();
292 
293  Status( "AudacityBoxes[" );
294  wxRect R = pWin->GetScreenRect();
295 
296  //R.SetPosition( wxPoint(0,0) );
297 
298  //wxString Name = pWin->GetName();
299  Status( wxString::Format(" [ %2i, %3i, %3i, %3i, %3i, \"%s\" ],",
300  0, R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom(), "Audacity Window" ));
301  ExploreAdornments( context, pWin->GetPosition()+wxSize( 6,-1), pWin, pWin->GetId(), 1 );
302  ExploreWindows( context, pWin->GetPosition()+wxSize( 6,-1), pWin, pWin->GetId(), 1 );
303  Status( "];" );
304  return true;
305 }
306 
307 
308 
310 {
311  wxString mode = mMode;
312 
313  bool bOK = false;
314  if (mode.IsSameAs(wxT("GetMenus")))
315  {
316  bOK = SendMenus( context );
317  }
318  if (mode.IsSameAs(wxT("GetMenusPlus")))
319  {
320  bOK = SendMenusPlus( context );
321  }
322  else if (mode.IsSameAs(wxT("GetClips")))
323  {
324  bOK = SendClips( context );
325  }
326  else if (mode.IsSameAs(wxT("GetKeycodes")))
327  {
328  bOK = SendKeycodes( context );
329  }
330  else if (mode.IsSameAs(wxT("GetBoxes")))
331  {
332  bOK = SendBoxes( context );
333  }
334 
335  return bOK;
336 }
bool GetEnabled(const wxString &name)
int GetLabelWidth() const
Definition: TrackPanel.h:383
static wxArrayString names()
Definition: Tags.cpp:697
void BuildSignature(CommandSignature &signature) override
Postcondition: signature is a 'signature' map containing parameter.
bool SendMenusPlus(CommandExecutionContext context)
std::shared_ptr< Command > CommandHolder
bool SendClips(CommandExecutionContext context)
void AddParameter(const wxString &name, const wxVariant &dft, movable_ptr< Validator > &&valid)
int GetVRulerWidth() const
void ExploreWindows(CommandExecutionContext context, wxPoint P, wxWindow *pWin, int Id, int depth)
wxString BuildName() override
CommandManager * GetCommandManager()
Definition: Project.h:328
bool SendBoxes(CommandExecutionContext context)
std::pair< wxRect, bool > GetRectangle(wxSize size)
Definition: Overlay.cpp:17
Track * Next(bool skiplinked=false) override
Definition: Track.cpp:565
void ExploreMenu(wxMenu *pMenu, int Id, int depth)
ViewInfo * mViewInfo
Definition: TrackPanel.h:451
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
void ExploreTrackPanel(CommandExecutionContext context, wxPoint P, wxWindow *pWin, int Id, int depth)
The TrackPanel class coordinates updates and operations on the main part of the screen which contains...
Definition: TrackPanel.h:245
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:95
CommandManager implements a system for organizing all user-callable commands.
void Status(const wxString &status) override
Definition: Command.cpp:179
void ExploreAdornments(CommandExecutionContext context, wxPoint P, wxWindow *pWin, int Id, int depth)
int vpos
Definition: ViewInfo.h:45
const wxChar * name
Definition: Distortion.cpp:94
bool SendKeycodes(CommandExecutionContext context)
Track * GetLink() const
Definition: Track.cpp:267
Represents a context to which a command may be applied.
Definition: Command.h:50
Track * First(TrackList *val=NULL) override
Definition: Track.cpp:554
bool SendMenus(CommandExecutionContext context)
TrackPanel * GetTrackPanel()
Definition: Project.h:289
CommandHolder Create(std::unique_ptr< CommandOutputTarget > &&target) override
AudacityProject * GetProject() const
Definition: Command.h:60
void GetAllCommandNames(wxArrayString &names, bool includeMultis)
Class that maps parameter names to default values and validators.
Contains declaration of AutomationCommands class.
bool Apply(CommandExecutionContext context) override
int GetHeight() const
Definition: Track.cpp:178
int GetVRulerOffset() const
Definition: TrackPanel.h:381