Audacity  2.2.2
ShuttleGui.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ShuttleGui.h
6 
7  James Crook
8 
9  Audacity is free software.
10  This file is licensed under the wxWidgets license, see License.txt
11 
12 **********************************************************************/
13 
14 #ifndef SHUTTLE_GUI
15 #define SHUTTLE_GUI
16 
17 #include "Audacity.h"
18 
19 #include "MemoryX.h"
20 #include <wx/grid.h>
21 #include <wx/sizer.h>
22 #include <wx/string.h>
23 
24 #include "WrappedType.h"
25 
26 const int nMaxNestedSizers = 20;
27 
29 {
35 
36  // Next two are only ever seen in constructor.
37  // After that they revert to one of the modes above.
38  // They are used to achieve 'two step' operation,
39  // where we transfer between two shuttles in one go.
42 };
43 
44 class wxArrayInt;
45 class wxListCtrl;
46 class wxCheckBox;
47 class wxChoice;
48 class wxComboBox;
49 class wxScrolledWindow;
50 class wxStaticText;
51 class wxTreeCtrl;
52 class wxTextCtrl;
53 class wxSlider;
54 class wxTreeListCtrl;
55 class wxNotebook;
56 typedef wxWindow wxNotebookPage; // so far, any window can be a page
57 class wxButton;
58 class wxBitmapButton;
59 class wxRadioButton;
60 class wxBitmap;
61 class wxPanel;
62 class wxSizer;
63 class wxStaticBox;
64 class wxMenuBar;
65 class wxMenu;
66 class wxSpinCtrl;
67 class wxListBox;
68 class wxGrid;
69 class Shuttle;
70 
71 class WrappedType;
72 
73 class AUDACITY_DLL_API ShuttleGuiBase /* not final */
74 {
75 public:
76  ShuttleGuiBase(wxWindow * pParent,teShuttleMode ShuttleMode);
77  ~ShuttleGuiBase(void);
78  void Init();
79 
80 //-- Add functions. These only add a widget or 2.
81  void AddPrompt(const wxString &Prompt);
82  void AddUnits(const wxString &Prompt);
83  void AddTitle(const wxString &Prompt);
84  wxWindow * AddWindow(wxWindow * pWindow, int Flags = wxALIGN_CENTRE | wxALL );
85  wxSlider * AddSlider(const wxString &Prompt, int pos, int Max, int Min = 0);
86  wxSlider * AddVSlider(const wxString &Prompt, int pos, int Max);
87  wxSpinCtrl * AddSpinCtrl(const wxString &Prompt, int Value, int Max, int Min);
88  wxTreeCtrl * AddTree();
89  wxRadioButton * AddRadioButton( const wxString & Prompt );
90  wxRadioButton * AddRadioButtonToGroup( const wxString & Prompt);
91  wxButton * AddButton( const wxString & Text, int PositionFlags = wxALIGN_CENTRE );
92  wxBitmapButton * AddBitmapButton(const wxBitmap &Bitmap, int PositionFlags = wxALIGN_CENTRE);
93  wxStaticText * AddVariableText(const wxString &Str, bool bCenter = false, int PositionFlags = 0);
94  wxTextCtrl * AddTextBox(const wxString &Caption, const wxString &Value, const int nChars);
95  wxTextCtrl * AddNumericTextBox(const wxString &Caption, const wxString &Value, const int nChars);
96  wxTextCtrl * AddTextWindow(const wxString &Value);
97  wxListBox * AddListBox(const wxArrayString * pChoices, long style = 0);
98  wxListCtrl * AddListControl();
99  wxListCtrl * AddListControlReportMode();
100  wxGrid * AddGrid();
101  wxCheckBox * AddCheckBox( const wxString &Prompt, const wxString &Selected);
102  wxCheckBox * AddCheckBoxOnRight( const wxString &Prompt, const wxString &Selected);
103  wxComboBox * AddCombo( const wxString &Prompt, const wxString &Selected,const wxArrayString * pChoices, long style = 0 );
104  wxChoice * AddChoice( const wxString &Prompt, const wxString &Selected, const wxArrayString * pChoices );
105  wxMenuBar * AddMenuBar( );
106  wxMenu * AddMenu( const wxString & Title );
107  void AddIcon( wxBitmap * pBmp);
108  void AddIconButton( const wxString & Command, const wxString & Params,wxBitmap * pBmp );
109  void AddFixedText( const wxString & Str, bool bCenter = false );
110  void AddConstTextBox( const wxString &Caption, const wxString & Value );
111 
112 //-- Start and end functions. These are used for sizer, or other window containers
113 // and create the appropriate widget.
114  void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1);
115  void EndHorizontalLay();
116  void StartVerticalLay(int iProp=1);
117  void EndVerticalLay();
118  wxScrolledWindow * StartScroller(int iStyle=0);
119  void EndScroller();
120  wxPanel * StartPanel(int iStyle=0);
121  void EndPanel();
122  void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT);
123  void EndMultiColumn();
124 
125  void StartTwoColumn() {StartMultiColumn(2);};
126  void EndTwoColumn() {EndMultiColumn();};
127  void StartThreeColumn(){StartMultiColumn(3);};
128  void EndThreeColumn(){EndMultiColumn();};
129 
130  wxStaticBox * StartStatic( const wxString & Str, int iProp=0 );
131  void EndStatic();
132 
133  wxNotebook * StartNotebook();
134  void EndNotebook();
135  wxNotebookPage * StartNotebookPage( const wxString & Name );
136  void StartNotebookPage( const wxString & Name, wxNotebookPage * pPage );
137  void EndNotebookPage();
138  wxPanel * StartInvisiblePanel();
139  void EndInvisiblePanel();
140 
141  void StartRadioButtonGroup( const wxString & SettingName );
142  void EndRadioButtonGroup();
143 
144  void StartRadioButtonGroup( const wxString & SettingName, const int iDefaultValue );
145  void StartRadioButtonGroup( const wxString & SettingName, const wxString &DefaultValue );
146 
147  void DoDataShuttle( const wxString &Name, WrappedType & WrappedRef );
148 
149  bool DoStep( int iStep );
150  int TranslateToIndex( const wxString &Value, const wxArrayString &Choices );
151  wxString TranslateFromIndex( const int nIn, const wxArrayString &Choices );
152  int TranslateToIndex( const int Value, const wxArrayInt &Choices );
153  int TranslateFromIndex( const int nIn, const wxArrayInt &Choices );
154 
155 //-- Tie functions both add controls and also read/write to them.
156 // The ones taking a 'WrappedType' are type-generic and are used by the type specific ones.
157 
158  wxTextCtrl * TieTextBox( const wxString &Prompt, WrappedType & WrappedRef, const int nChars);
159  wxTextCtrl * TieTextBox( const wxString &Caption, wxString & Value, const int nChars=0);
160  wxTextCtrl * TieTextBox( const wxString &Prompt, int &Selected, const int nChars=0);
161  wxTextCtrl * TieTextBox( const wxString &Prompt, double &Value, const int nChars=0);
162 
163  wxTextCtrl * TieNumericTextBox( const wxString &Prompt, WrappedType & WrappedRef, const int nChars);
164  wxTextCtrl * TieNumericTextBox( const wxString &Caption, wxString & Value, const int nChars=0);
165  wxTextCtrl * TieNumericTextBox( const wxString &Prompt, int &Selected, const int nChars=0);
166  wxTextCtrl * TieNumericTextBox( const wxString &Prompt, double &Value, const int nChars=0);
167 
168  wxCheckBox * TieCheckBox( const wxString &Prompt, WrappedType & WrappedRef );
169  wxCheckBox * TieCheckBox( const wxString &Prompt, const wxString &Selected );
170  wxCheckBox * TieCheckBox( const wxString &Prompt, bool & Var );
171  wxCheckBox * TieCheckBoxOnRight( const wxString & Prompt, WrappedType & WrappedRef );
172  wxCheckBox * TieCheckBoxOnRight( const wxString & Prompt, bool & Var );
173 
174  wxChoice * TieChoice( const wxString &Prompt, WrappedType & WrappedRef, const wxArrayString * pChoices );
175  wxChoice * TieChoice( const wxString &Prompt, wxString &Selected, const wxArrayString * pChoices );
176  wxChoice * TieChoice( const wxString &Prompt, int &Selected, const wxArrayString * pChoices );
177 
178  wxSlider * TieSlider( const wxString &Prompt, WrappedType & WrappedRef, const int max, const int min = 0 );
179  wxSlider * TieSlider( const wxString &Prompt, int &pos, const int max, const int min = 0);
180  wxSlider * TieSlider( const wxString &Prompt, double &pos, const double max, const double min = 0.0);
181  wxSlider * TieSlider( const wxString &Prompt, float &pos, const float fMin, const float fMax);
182  wxSlider * TieVSlider( const wxString &Prompt, float &pos, const float fMin, const float fMax);
183 
184  wxRadioButton * TieRadioButton( const wxString & Prompt, WrappedType &WrappedRef);
185  wxRadioButton * TieRadioButton( const wxString &Prompt, const int iValue);
186  wxRadioButton * TieRadioButton( const wxString &Prompt, const wxString &Value);
187 
188  wxSpinCtrl * TieSpinCtrl( const wxString &Prompt, WrappedType & WrappedRef, const int max, const int min = 0 );
189  wxSpinCtrl * TieSpinCtrl( const wxString &Prompt, int &Value, const int max, const int min = 0 );
190 
191 
192 //-- Variants of the standard Tie functions which do two step exchange in one go
193 // Note that unlike the other Tie functions, ALL the arguments are const.
194 // That's because the data is being exchanged between the dialog and mpShuttle
195 // so it doesn't need an argument that is writeable.
196  wxCheckBox * TieCheckBox(
197  const wxString &Prompt,
198  const wxString &SettingName,
199  const bool bDefault);
200  wxCheckBox * TieCheckBoxOnRight(
201  const wxString &Prompt,
202  const wxString &SettingName,
203  const bool bDefault);
204  wxChoice * TieChoice(
205  const wxString &Prompt,
206  const wxString &SettingName,
207  const wxString &Default,
208  const wxArrayString &Choices,
209  const wxArrayString & TranslatedChoices );
210  wxChoice * TieChoice(
211  const wxString &Prompt,
212  const wxString &SettingName,
213  const int Default,
214  const wxArrayString & Choices,
215  const wxArrayInt & TranslatedChoices);
216  wxTextCtrl * TieTextBox(
217  const wxString &Prompt,
218  const wxString &SettingName,
219  const wxString &Default,
220  const int nChars);
221  wxTextCtrl * TieTextBox(
222  const wxString & Prompt,
223  const wxString & SettingName,
224  const double & Default,
225  const int nChars);
226  wxTextCtrl * TieNumericTextBox(
227  const wxString &Prompt,
228  const wxString &SettingName,
229  const wxString &Default,
230  const int nChars);
231  wxTextCtrl * TieNumericTextBox(
232  const wxString & Prompt,
233  const wxString & SettingName,
234  const double & Default,
235  const int nChars);
236  wxSlider * TieSlider(
237  const wxString & Prompt,
238  const wxString & SettingName,
239  const int iDefault,
240  const int max,
241  const int min = 0);
242  wxSpinCtrl * TieSpinCtrl(
243  const wxString &Prompt,
244  const wxString &SettingName,
245  const int Value,
246  const int max,
247  const int min);
248 //-- End of variants.
249  void EnableCtrl( bool bEnable );
250  void SetSizeHints( int minX, int minY );
251  void SetBorder( int Border ) {miBorder = Border;};
252  void SetStyle( int Style ) {miStyle = Style;};
253  void SetNoMatchSelector( int iSelector ) {miNoMatchSelector = iSelector;};
254  void SetSizerProportion( int iProp ) {miSizerProp = iProp;};
255  void SetStretchyCol( int i );
256  void SetStretchyRow( int i );
257 
258 //--Some Additions since June 2007 that don't fit in elsewhere...
259  wxWindow * GetParent()
260  {
261  // This assertion justifies the use of safenew in many places where GetParent()
262  // is used to construct a window
263  wxASSERT(mpParent != NULL);
264  return mpParent;
265  }
266  ShuttleGuiBase & Prop( int iProp );
267  void UseUpId();
268 
269  wxSizer * GetSizer() {return mpSizer;}
270 
271 protected:
272  void SetProportions( int Default );
273  void PushSizer();
274  void PopSizer();
275 
276  void UpdateSizersCore( bool bPrepend, int Flags );
277  void UpdateSizers();
278  void UpdateSizersC();
279  void UpdateSizersAtStart();
280 
281  long Style( long Style );
282 
283  wxWindow * mpLastWind;
284  wxWindow * mpDlg;
285  wxSizer * pSizerStack[ nMaxNestedSizers ];
286 
287  std::unique_ptr<Shuttle> mpShuttle;
290 
292 
293  // These five are needed to handle radio button groups.
294  wxString mSettingName;
296 
298  wxString mRadioValueString;
300 
303  int miBorder;
304  long miStyle;
305  int miProp;
306 
307  // See UseUpId() for explanation of these three.
308  int miId;
309  int miIdNext;
311  // Proportion set by user rather than default.
313 
314  std::unique_ptr<wxSizer> mpSubSizer;
315  wxSizer * mpSizer;
316  wxWindow * mpParent;
317  wxWindow * mpWind;
318  wxMenuBar * mpMenuBar;
319  wxMenu * mpMenu;
320 };
321 
322 // A rarely used helper function that sets a pointer
323 // ONLY if the value it is to be set to is non NULL.
324 extern void SetIfCreated( wxChoice *&Var, wxChoice * Val );
325 extern void SetIfCreated( wxTextCtrl *&Var, wxTextCtrl * Val );
326 extern void SetIfCreated( wxStaticText *&Var, wxStaticText * Val );
327 
328 class GuiWaveTrack;
329 class AttachableScrollBar;
330 class ViewInfo;
331 #include <wx/scrolbar.h> // to get wxSB_HORIZONTAL
332 
333 // CreateStdButtonSizer defs...should probably move to widgets subdir
334 enum
335 {
336  eOkButton = 0x0001,
337  eCancelButton = 0x0002,
338  eYesButton = 0x0004,
339  eNoButton = 0x0008,
340  eHelpButton = 0x0010,
341  ePreviewButton = 0x0020,
342  eDebugButton = 0x0040,
345  eApplyButton = 0x0200,
346  eCloseButton = 0x0400,
347 };
348 
349 enum
350 {
351  // ePreviewID = wxID_LOWEST - 1,
352  // But there is a wxID_PREVIEW
353  ePreviewID = wxID_PREVIEW,
354 
355  eDebugID = wxID_LOWEST - 2,
356  eSettingsID = wxID_LOWEST - 3,
357  ePreviewDryID = wxID_LOWEST - 4,
358  eCloseID = wxID_CANCEL
359 };
360 
361 AUDACITY_DLL_API std::unique_ptr<wxSizer> CreateStdButtonSizer( wxWindow *parent,
362  long buttons = eOkButton | eCancelButton,
363  wxWindow *extra = NULL );
364 
365 // ShuttleGui extends ShuttleGuiBase with Audacity specific extensions.
366 class AUDACITY_DLL_API ShuttleGui /* not final */ : public ShuttleGuiBase
367 {
368 public:
369  ShuttleGui(wxWindow * pParent,teShuttleMode ShuttleMode);
370  ~ShuttleGui(void);
371 public:
372  ShuttleGui & Id(int id );
373  // Prop() sets the proportion value, defined as in wxSizer::Add().
374  ShuttleGui & Prop( int iProp ){ ShuttleGuiBase::Prop(iProp); return *this;}; // Has to be here too, to return a ShuttleGui and not a ShuttleGuiBase.
375  GuiWaveTrack * AddGuiWaveTrack( const wxString & Name);
376  AttachableScrollBar * AddAttachableScrollBar( long style = wxSB_HORIZONTAL );
377  void AddStandardButtons( long buttons = eOkButton | eCancelButton, wxButton *extra = NULL );
378  wxSizerItem * AddSpace( int width, int height );
379  wxSizerItem * AddSpace( int size ) { return AddSpace( size, size ); };
380 
381  void SetSizeHints( int minX = -1, int minY = -1 );
382  void SetSizeHints( const wxArrayString & items );
383  void SetSizeHints( const wxArrayInt & items );
384  static void SetSizeHints( wxWindow *window, const wxArrayString & items );
385  static void SetSizeHints( wxWindow *window, const wxArrayInt & items );
386 
388 };
389 #endif
void SetSizeHints(int minX, int minY)
Used to modify an already placed Window.
Definition: ShuttleGui.cpp:183
void EndThreeColumn()
Definition: ShuttleGui.h:128
WrappedType mRadioValue
The index of this radio item. -1 for none.
Definition: ShuttleGui.h:297
void SetNoMatchSelector(int iSelector)
Definition: ShuttleGui.h:253
An AttachableScrollBar is a scroll bar that can be attached to multiple items and so control their sc...
ViewInfo is used mainly to hold the zooming, selection and scroll information. It also has some statu...
Definition: ViewInfo.h:141
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:366
wxSizerItem * AddSpace(int size)
Definition: ShuttleGui.h:379
std::unique_ptr< Shuttle > mpShuttle
Definition: ShuttleGui.h:287
Moves data from one place to another, converting it as required.
Definition: Shuttle.h:27
wxString mRadioValueString
The wrapped value associated with the active radio button.
Definition: ShuttleGui.h:298
wxWindow * mpDlg
Definition: ShuttleGui.h:284
int miSizerProp
Unwrapped integer value.
Definition: ShuttleGui.h:301
int mRadioValueInt
Unwrapped string value.
Definition: ShuttleGui.h:299
Abstract base class for command interface. It implements Command::SetParameter() and defers all other...
Definition: Command.h:70
const int nMaxNestedSizers
Definition: ShuttleGui.h:26
void SetSizerProportion(int iProp)
Definition: ShuttleGui.h:254
wxMenu * mpMenu
Definition: ShuttleGui.h:319
ShuttleGuiBase & Prop(int iProp)
Definition: ShuttleGui.cpp:669
wxSizer * mpSizer
Definition: ShuttleGui.h:315
void StartTwoColumn()
Definition: ShuttleGui.h:125
wxWindow * GetParent()
Definition: ShuttleGui.h:259
void SetStyle(int Style)
Definition: ShuttleGui.h:252
wxWindow * mpParent
Definition: ShuttleGui.h:316
teShuttleMode
Definition: ShuttleGui.h:28
int min(int a, int b)
Base class for shuttling data to and from a GUI.
Definition: ShuttleGui.h:73
void StartThreeColumn()
Definition: ShuttleGui.h:127
teShuttleMode mShuttleMode
Used in choices to determine which item to use on no match.
Definition: ShuttleGui.h:291
wxSizer * GetSizer()
Definition: ShuttleGui.h:269
wxWindow * mpWind
Definition: ShuttleGui.h:317
teShuttleMode GetMode()
Definition: ShuttleGui.h:387
AUDACITY_DLL_API std::unique_ptr< wxSizer > CreateStdButtonSizer(wxWindow *parent, long buttons=eOkButton|eCancelButton, wxWindow *extra=NULL)
void SetIfCreated(wxChoice *&Var, wxChoice *Val)
int mRadioCount
The setting controlled by a group.
Definition: ShuttleGui.h:295
int miNoMatchSelector
Definition: ShuttleGui.h:289
wxMenuBar * mpMenuBar
Definition: ShuttleGui.h:318
wxWindow wxNotebookPage
Definition: ShuttleGui.h:55
wxString mSettingName
Definition: ShuttleGui.h:294
wxWindow * mpLastWind
Definition: ShuttleGui.h:283
ShuttleGui & Prop(int iProp)
Definition: ShuttleGui.h:374
std::unique_ptr< wxSizer > mpSubSizer
Definition: ShuttleGui.h:314
void SetBorder(int Border)
Definition: ShuttleGui.h:251
void EndTwoColumn()
Definition: ShuttleGui.h:126
Used in type conversions, this wrapper for ints, strings, doubles and enums provides conversions betw...
Definition: WrappedType.h:31