Audacity  2.2.2
ToolsToolBar.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ToolsToolBar.cpp
6 
7  Dominic Mazzoni
8  Shane T. Mueller
9  Leland Lucius
10 
11  See ToolsToolBar.h for details
12 
13 *******************************************************************//*******************************************************************/
33 
34 
35 #include "../Audacity.h"
36 #include "ToolsToolBar.h"
37 
38 // For compilers that support precompilation, includes "wx/wx.h".
39 #include <wx/wxprec.h>
40 
41 #ifndef WX_PRECOMP
42 #include <wx/defs.h>
43 #include <wx/event.h>
44 #include <wx/intl.h>
45 #include <wx/sizer.h>
46 #endif
47 #include <wx/tooltip.h>
48 
49 #include "MeterToolBar.h"
50 
51 #include "../Prefs.h"
52 #include "../AllThemeResources.h"
53 #include "../ImageManipulation.h"
54 #include "../Project.h"
55 #include "../tracks/ui/Scrubbing.h"
56 #include "../Theme.h"
57 
58 #include "../Experimental.h"
59 
60 #include "../widgets/AButton.h"
61 
62 
64 
68 
69 BEGIN_EVENT_TABLE(ToolsToolBar, ToolBar)
71  lastTool,
72  wxEVT_COMMAND_BUTTON_CLICKED,
73  ToolsToolBar::OnTool)
75 
76 //Standard constructor
78 : ToolBar(ToolsBarID, _("Tools"), wxT("Tools"))
79 {
80  //Read the following wxASSERTs as documentating a design decision
81  wxASSERT( selectTool == selectTool - firstTool );
82  wxASSERT( envelopeTool == envelopeTool - firstTool );
83  wxASSERT( slideTool == slideTool - firstTool );
84  wxASSERT( zoomTool == zoomTool - firstTool );
85  wxASSERT( drawTool == drawTool - firstTool );
86  wxASSERT( multiTool == multiTool - firstTool );
87 
88  bool multiToolActive = false;
89  gPrefs->Read(wxT("/GUI/ToolBars/Tools/MultiToolActive"), &multiToolActive);
90 
91  if (multiToolActive)
92  mCurrentTool = multiTool;
93  else
94  mCurrentTool = selectTool;
95 }
96 
98 {
99 }
100 
102 {
103 
104 // JKC:
105 // Under Win98 Tooltips appear to be buggy, when you have a lot of
106 // tooltip messages flying around. I found that just creating a
107 // twelfth tooltip caused Audacity to crash when it tried to show
108 // any tooltip.
109 //
110 // Win98 does NOT recover from this crash - for any application which is
111 // using tooltips will also crash thereafter... so you must reboot.
112 // Rather weird.
113 //
114 // Getting windows to process more of its stacked up messages seems
115 // to workaround the problem. The problem is not fully understood though
116 // (as of April 2003).
117 
118  // Vaughan, October 2003: Now we're crashing on Win2K if
119  // "Quit when closing last window" is unchecked, when we come back
120  // through here, on either of the wxSafeYield calls.
121  // James confirms that commenting them out does not cause his original problem
122  // to reappear, so they're commented out now.
123  // wxSafeYield(); //Deal with some queued up messages...
124 
125  #if wxUSE_TOOLTIPS
126 
127  static const struct Entry {
128  int tool;
129  wxString commandName;
130  wxString untranslatedLabel;
131  } table[] = {
132  { selectTool, wxT("SelectTool"), XO("Selection Tool") },
133  { envelopeTool, wxT("EnvelopeTool"), XO("Envelope Tool") },
134  { slideTool, wxT("TimeShiftTool"), XO("Time Shift Tool") },
135  { zoomTool, wxT("ZoomTool"), XO("Zoom Tool") },
136  { drawTool, wxT("DrawTool"), XO("Draw Tool") },
137  { multiTool, wxT("MultiTool"), XO("Multi Tool") },
138  };
139 
140  for (const auto &entry : table) {
141  LocalizedCommandNameVector commands( 1u,
142  { wxGetTranslation(entry.untranslatedLabel), entry.commandName } );
143  ToolBar::SetButtonToolTip(*mTool[entry.tool], commands);
144  }
145 
146  #endif
147 
148  // wxSafeYield();
149  return;
150 }
151 
153 {
156 }
157 
159  ToolsToolBar *pBar, teBmps eTool,
160  int id, const wxChar *label)
161 {
162  AButton *button = ToolBar::MakeButton(pBar,
163  bmpRecoloredUpSmall,
164  bmpRecoloredDownSmall,
165  bmpRecoloredUpHiliteSmall,
166  bmpRecoloredDownSmall, // Not bmpRecoloredHiliteSmall as down is inactive.
167  eTool, eTool, eTool,
168  wxWindowID(id),
169  wxDefaultPosition, true,
170  theTheme.ImageSize( bmpRecoloredUpSmall ));
171  button->SetLabel( label );
172  pBar->mToolSizer->Add( button );
173  return button;
174 }
175 
176 
178 {
179  SetBackgroundColour( theTheme.Colour( clrMedium ) );
181  Add(mToolSizer = safenew wxGridSizer(2, 3, 1, 1));
182 
183  /* Tools */
184  mTool[ selectTool ] = MakeTool( this, bmpIBeam, selectTool, _("Selection Tool") );
185  mTool[ envelopeTool ] = MakeTool( this, bmpEnvelope, envelopeTool, _("Envelope Tool") );
186  mTool[ drawTool ] = MakeTool( this, bmpDraw, drawTool, _("Draw Tool") );
187  mTool[ zoomTool ] = MakeTool( this, bmpZoom, zoomTool, _("Zoom Tool") );
188  mTool[ slideTool ] = MakeTool( this, bmpTimeShift, slideTool, _("Slide Tool") );
189  mTool[ multiTool ] = MakeTool( this, bmpMulti, multiTool, _("Multi Tool") );
190 
192 
194 }
195 
200 {
201  return mCurrentTool;
202 }
203 
207 {
208  //In multi-mode the current tool is shown by the
209  //cursor icon. The buttons are not updated.
210 
211  bool leavingMulticlipMode =
212  IsDown(multiTool) && tool != multiTool;
213 
214  if (leavingMulticlipMode)
215  mTool[multiTool]->PopUp();
216 
217  if (tool != mCurrentTool || leavingMulticlipMode) {
219  mCurrentTool=tool;
221  }
222  //JKC: ANSWER-ME: Why is this RedrawAllProjects() line required?
223  //msmeyer: I think it isn't, we leave it out for 1.3.1 (beta), and
224  // we'll see if anyone complains.
225  // RedrawAllProjects();
226 
227  //msmeyer: But we instruct the projects to handle the cursor shape again
229 
230  gPrefs->Write(wxT("/GUI/ToolBars/Tools/MultiToolActive"),
231  IsDown(multiTool));
232  gPrefs->Flush();
233 }
234 
235 bool ToolsToolBar::IsDown(int tool) const
236 {
237  return mTool[tool]->IsDown();
238 }
239 
241 {
242  int tool;
243 
244  for (tool = firstTool; tool <= lastTool; tool++)
245  if (IsDown(tool))
246  return tool;
247 
248  return firstTool; // Should never happen
249 }
250 
251 void ToolsToolBar::OnTool(wxCommandEvent & evt)
252 {
253  mCurrentTool = evt.GetId() - firstTool;
254  for (int i = 0; i < numTools; i++)
255  if (i == mCurrentTool)
256  mTool[i]->PushDown();
257  else
258  mTool[i]->PopUp();
259 
261 
262  gPrefs->Write(wxT("/GUI/ToolBars/Tools/MultiToolActive"),
263  IsDown(multiTool));
264  gPrefs->Flush();
265 }
void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:732
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
virtual void UpdatePrefs()
Definition: ToolBar.cpp:540
void PopUp()
Definition: AButton.cpp:525
bool IsDown()
Definition: AButton.h:122
AButton * mTool[numTools]
Definition: ToolsToolBar.h:76
static void SetButtonToolTip(AButton &button, const LocalizedCommandNameVector &commands)
Definition: ToolBar.cpp:828
wxString label
Definition: Tags.cpp:727
#define XO(s)
Definition: Internat.h:30
int teBmps
Definition: Theme.h:28
wxSize ImageSize(int iIndex)
Definition: Theme.cpp:1240
static AButton * MakeButton(wxWindow *parent, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxWindowID id, wxPoint placement, bool processdownevents, wxSize size)
Definition: ToolBar.cpp:770
#define safenew
Definition: Audacity.h:223
void RedrawAllProjects()
Definition: Project.cpp:588
wxGridSizer * mToolSizer
Definition: ToolsToolBar.h:77
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
IMPLEMENT_CLASS(ToolsToolBar, ToolBar)
int GetCurrentTool() const
std::vector< LocalizedCommandName > LocalizedCommandNameVector
Definition: ToolBar.h:160
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:616
void SetCurrentTool(int tool)
_("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 &)
void RefreshCursorForAllProjects()
Definition: Project.cpp:595
static AButton * MakeTool(ToolsToolBar *pBar, teBmps eTool, int id, const wxChar *label)
bool IsDown(int tool) const
virtual ~ToolsToolBar()
A kind of ToolBar with Tools on it.
Definition: ToolsToolBar.h:47
void RegenerateTooltips() override
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1208
void PushDown()
Definition: AButton.cpp:517
END_EVENT_TABLE()
void UpdatePrefs() override
void Populate() override
EVT_COMMAND_RANGE(firstTool, lastTool, wxEVT_COMMAND_BUTTON_CLICKED, ToolsToolBar::OnTool) ToolsToolBar
Methods for ToolsToolBar.
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed...
Definition: ToolBar.h:87
void OnTool(wxCommandEvent &evt)
A wxButton with mouse-over behaviour.
Definition: AButton.h:27