Audacity  3.0.3
wxPanelWrapper.h
Go to the documentation of this file.
1 //
2 // wxPanelWrapper.h
3 // Audacity
4 //
5 // Created by Paul Licameli on 6/25/16.
6 //
7 //
8 
9 #ifndef __AUDACITY_WXPANEL_WRAPPER__
10 #define __AUDACITY_WXPANEL_WRAPPER__
11 
12 #include <memory>
13 #include <wx/panel.h> // to inherit
14 #include <wx/dialog.h> // to inherit
15 
16 #include "Internat.h"
17 
18 #include "Identifier.h"
19 
20 AUDACITY_DLL_API void wxTabTraversalWrapperCharHook(wxKeyEvent &event);
21 
22 template <typename Base>
23 class AUDACITY_DLL_API wxTabTraversalWrapper : public Base
24 {
25 public:
26  template <typename... Args>
27  wxTabTraversalWrapper(Args&&... args)
28  : Base( std::forward<Args>(args)... )
29  {
30  this->Bind(wxEVT_CHAR_HOOK, wxTabTraversalWrapperCharHook);
31  }
32 
37 
38 };
39 
40 class AUDACITY_DLL_API wxPanelWrapper : public wxTabTraversalWrapper<wxPanel>
41 {
42 public:
43  // Constructors
45 
47  wxWindow *parent,
48  wxWindowID winid = wxID_ANY,
49  const wxPoint& pos = wxDefaultPosition,
50  const wxSize& size = wxDefaultSize,
51  long style = wxTAB_TRAVERSAL | wxNO_BORDER,
52  // Important: default window name localizes!
53  const TranslatableString& name = XO("Panel"))
54  : wxTabTraversalWrapper<wxPanel> (
55  parent, winid, pos, size, style, name.Translation() )
56  {}
57 
58  // Pseudo ctor
59  bool Create(
60  wxWindow *parent,
61  wxWindowID winid = wxID_ANY,
62  const wxPoint& pos = wxDefaultPosition,
63  const wxSize& size = wxDefaultSize,
64  long style = wxTAB_TRAVERSAL | wxNO_BORDER,
65  // Important: default window name localizes!
66  const TranslatableString& name = XO("Panel"))
67  {
69  parent, winid, pos, size, style, name.Translation()
70  );
71  }
72  // overload and hide the inherited functions that take naked wxString:
73  void SetLabel(const TranslatableString & label);
74  void SetName(const TranslatableString & name);
75  void SetToolTip(const TranslatableString &toolTip);
76  // Set the name to equal the label:
77  void SetName();
78 };
79 
80 class AUDACITY_DLL_API wxDialogWrapper : public wxTabTraversalWrapper<wxDialog>
81 {
82 public:
83  // Constructors
85 
86  // Constructor with no modal flag - the new convention.
88  wxWindow *parent, wxWindowID id,
89  const TranslatableString& title,
90  const wxPoint& pos = wxDefaultPosition,
91  const wxSize& size = wxDefaultSize,
92  long style = wxDEFAULT_DIALOG_STYLE,
93  // Important: default window name localizes!
94  const TranslatableString& name = XO("Dialog"))
95  : wxTabTraversalWrapper<wxDialog>(
96  parent, id, title.Translation(), pos, size, style, name.Translation() )
97  {}
98 
99  // Pseudo ctor
100  bool Create(
101  wxWindow *parent, wxWindowID id,
102  const TranslatableString& title,
103  const wxPoint& pos = wxDefaultPosition,
104  const wxSize& size = wxDefaultSize,
105  long style = wxDEFAULT_DIALOG_STYLE,
106  // Important: default window name localizes!
107  const TranslatableString& name = XO("Dialog"))
108  {
110  parent, id, title.Translation(), pos, size, style, name.Translation()
111  );
112  }
113 
114  // overload and hide the inherited functions that take naked wxString:
115  void SetTitle(const TranslatableString & title);
116  void SetLabel(const TranslatableString & title);
117  void SetName(const TranslatableString & title);
118  // Set the name to equal the title:
119  void SetName();
120 };
121 
122 #include <wx/dirdlg.h> // to inherit
123 
124 class AUDACITY_DLL_API wxDirDialogWrapper
125  : public wxTabTraversalWrapper<wxDirDialog>
126 {
127 public:
128  // Constructor with no modal flag - the new convention.
130  wxWindow *parent,
131  const TranslatableString& message = XO("Select a directory"),
132  const wxString& defaultPath = {},
133  long style = wxDD_DEFAULT_STYLE,
134  const wxPoint& pos = wxDefaultPosition,
135  const wxSize& size = wxDefaultSize,
136  // Important: default window name localizes!
137  const TranslatableString& name = XO("Directory Dialog"))
139  parent, message.Translation(), defaultPath, style, pos, size,
140  name.Translation() )
141  {}
142 
143  // Pseudo ctor
144  void Create(
145  wxWindow *parent,
146  const TranslatableString& message = XO("Select a directory"),
147  const wxString& defaultPath = {},
148  long style = wxDD_DEFAULT_STYLE,
149  const wxPoint& pos = wxDefaultPosition,
150  const wxSize& size = wxDefaultSize,
151  // Important: default window name localizes!
152  const TranslatableString& name = XO("Directory Dialog"))
153  {
155  parent, message.Translation(), defaultPath, style, pos, size,
156  name.Translation() );
157  }
158 };
159 
160 #include "FileDialog/FileDialog.h"
161 #include "../FileNames.h" // for FileTypes
162 
163 class AUDACITY_DLL_API FileDialogWrapper
164  : public wxTabTraversalWrapper<FileDialog>
165 {
166 public:
168 
169  // Constructor with no modal flag - the new convention.
171  wxWindow *parent,
172  const TranslatableString& message,
173  const FilePath& defaultDir,
174  const FilePath& defaultFile,
175  const FileNames::FileTypes& fileTypes,
176  long style = wxFD_DEFAULT_STYLE,
177  const wxPoint& pos = wxDefaultPosition,
178  const wxSize& sz = wxDefaultSize,
179  // Important: default window name localizes!
180  const TranslatableString& name = XO("File Dialog"))
182  parent, message.Translation(), defaultDir, defaultFile,
183  FileNames::FormatWildcard( fileTypes ),
184  style, pos, sz, name.Translation() )
185  {}
186 
187  // Pseudo ctor
188  void Create(
189  wxWindow *parent,
190  const TranslatableString& message,
191  const FilePath& defaultDir,
192  const FilePath& defaultFile,
193  const FileNames::FileTypes& fileTypes,
194  long style = wxFD_DEFAULT_STYLE,
195  const wxPoint& pos = wxDefaultPosition,
196  const wxSize& sz = wxDefaultSize,
197  // Important: default window name localizes!
198  const TranslatableString& name = XO("File Dialog"))
199  {
201  parent, message.Translation(), defaultDir, defaultFile,
202  FileNames::FormatWildcard( fileTypes ),
203  style, pos, sz, name.Translation()
204  );
205  }
206 };
207 
208 #include <wx/msgdlg.h>
209 
210 /**************************************************************************/
214 class AudacityMessageDialog : public wxTabTraversalWrapper< wxMessageDialog >
215 {
216 public:
218  wxWindow *parent,
219  const TranslatableString &message,
220  const TranslatableString &caption, // don't use = wxMessageBoxCaptionStr,
221  long style = wxOK|wxCENTRE,
222  const wxPoint& pos = wxDefaultPosition)
223  : wxTabTraversalWrapper< wxMessageDialog>
224  ( parent, message.Translation(), caption.Translation(), style, pos )
225  {}
226 };
227 
228 #endif
FileDialogWrapper::FileDialogWrapper
FileDialogWrapper()
Definition: wxPanelWrapper.h:167
FilePath
wxString FilePath
Definition: Identifier.h:227
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
wxTabTraversalWrapper::operator=
wxTabTraversalWrapper & operator=(wxTabTraversalWrapper &&)=delete
wxDialogWrapper::Create
bool Create(wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
Definition: wxPanelWrapper.h:100
wxDirDialogWrapper::wxDirDialogWrapper
wxDirDialogWrapper(wxWindow *parent, const TranslatableString &message=XO("Select a directory"), const wxString &defaultPath={}, long style=wxDD_DEFAULT_STYLE, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, const TranslatableString &name=XO("Directory Dialog"))
Definition: wxPanelWrapper.h:129
wxDialogWrapper::wxDialogWrapper
wxDialogWrapper(wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
Definition: wxPanelWrapper.h:87
wxTabTraversalWrapperCharHook
AUDACITY_DLL_API void wxTabTraversalWrapperCharHook(wxKeyEvent &event)
Definition: wxPanelWrapper.cpp:14
wxPanelWrapper
Definition: wxPanelWrapper.h:41
FileDialogWrapper::Create
void Create(wxWindow *parent, const TranslatableString &message, const FilePath &defaultDir, const FilePath &defaultFile, const FileNames::FileTypes &fileTypes, long style=wxFD_DEFAULT_STYLE, const wxPoint &pos=wxDefaultPosition, const wxSize &sz=wxDefaultSize, const TranslatableString &name=XO("File Dialog"))
Definition: wxPanelWrapper.h:188
wxDirDialogWrapper
Definition: wxPanelWrapper.h:126
XO
#define XO(s)
Definition: Internat.h:31
wxTabTraversalWrapper
Definition: wxPanelWrapper.h:24
AudacityMessageDialog
Wrap wxMessageDialog so that caption IS translatable.
Definition: wxPanelWrapper.h:215
FileDialog
Dialog used to present platform specific "Save As" dialog with custom controls.
Definition: gtk/FileDialogPrivate.h:23
wxTabTraversalWrapper::wxTabTraversalWrapper
wxTabTraversalWrapper(wxTabTraversalWrapper &&)=delete
AudacityMessageDialog::AudacityMessageDialog
AudacityMessageDialog(wxWindow *parent, const TranslatableString &message, const TranslatableString &caption, long style=wxOK|wxCENTRE, const wxPoint &pos=wxDefaultPosition)
Definition: wxPanelWrapper.h:217
label
TranslatableString label
Definition: Tags.cpp:755
FileNames
Definition: FileNames.h:53
FileDialog.h
name
const TranslatableString name
Definition: Distortion.cpp:98
Identifier.h
wxTabTraversalWrapper::wxTabTraversalWrapper
wxTabTraversalWrapper(const wxTabTraversalWrapper &)=delete
wxTabTraversalWrapper::operator=
wxTabTraversalWrapper & operator=(const wxTabTraversalWrapper &)=delete
Internat.h
id
int id
Definition: WaveTrackControls.cpp:589
wxDialogWrapper
Definition: wxPanelWrapper.h:81
FileDialogWrapper
Definition: wxPanelWrapper.h:165
wxDirDialogWrapper::Create
void Create(wxWindow *parent, const TranslatableString &message=XO("Select a directory"), const wxString &defaultPath={}, long style=wxDD_DEFAULT_STYLE, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, const TranslatableString &name=XO("Directory Dialog"))
Definition: wxPanelWrapper.h:144
wxPanelWrapper::Create
bool Create(wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
Definition: wxPanelWrapper.h:59
wxDialogWrapper::wxDialogWrapper
wxDialogWrapper()
Definition: wxPanelWrapper.h:84
FileNames::FileTypes
std::vector< FileType > FileTypes
Definition: FileNames.h:79
TranslatableString::Translation
wxString Translation() const
Definition: TranslatableString.h:79
wxTabTraversalWrapper::wxTabTraversalWrapper
wxTabTraversalWrapper(Args &&... args)
Definition: wxPanelWrapper.h:27
FileNames::FormatWildcard
AUDACITY_DLL_API wxString FormatWildcard(const FileTypes &fileTypes)
FileDialogWrapper::FileDialogWrapper
FileDialogWrapper(wxWindow *parent, const TranslatableString &message, const FilePath &defaultDir, const FilePath &defaultFile, const FileNames::FileTypes &fileTypes, long style=wxFD_DEFAULT_STYLE, const wxPoint &pos=wxDefaultPosition, const wxSize &sz=wxDefaultSize, const TranslatableString &name=XO("File Dialog"))
Definition: wxPanelWrapper.h:170