Audacity  2.2.2
MultiDialog.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4  Audacity(R) is copyright (c) 1999-2010 Audacity Team.
5  License: GPL v2. See License.txt.
6 
7  MultiDialog.h
8 
9  Monty
10  Vaughan Johnson
11 
12 *******************************************************************//*******************************************************************/
20 
21 #include "../Audacity.h"
22 #include "../Project.h"
23 
24 #include "MultiDialog.h"
25 
26 #include <wx/app.h>
27 #include <wx/button.h>
28 #include <wx/dialog.h>
29 #include <wx/intl.h>
30 #include <wx/icon.h>
31 #include <wx/sizer.h>
32 #include <wx/stattext.h>
33 #include <wx/statbmp.h>
34 #include <wx/artprov.h>
35 #include <wx/radiobox.h>
36 
37 #include "../commands/CommandContext.h"
38 
39 class MultiDialog final : public wxDialogWrapper
40 {
41 public:
42  MultiDialog(wxWindow * pParent,
43  wxString message,
44  wxString title,
45  const wxChar **buttons, wxString boxMsg, bool log);
47 
48 private:
49  void OnOK( wxCommandEvent &event );
50  void OnShowLog(wxCommandEvent& event);
51 
52  wxRadioBox* mRadioBox;
53 
54  DECLARE_EVENT_TABLE()
55 };
56 
57 #define ID_SHOW_LOG_BUTTON 3333
58 
59 BEGIN_EVENT_TABLE(MultiDialog, wxDialogWrapper)
60  EVT_BUTTON( wxID_OK, MultiDialog::OnOK )
63 
64 MultiDialog::MultiDialog(wxWindow * pParent,
65  wxString message,
66  wxString title,
67  const wxChar **buttons, wxString boxMsg, bool log)
68  : wxDialogWrapper(pParent, wxID_ANY, title,
69  wxDefaultPosition, wxDefaultSize,
70  wxCAPTION) // not wxDEFAULT_DIALOG_STYLE because we don't want wxCLOSE_BOX and wxSYSTEM_MENU
71 {
72  SetName(GetTitle());
73 
74  wxBoxSizer *mainSizer;
75  {
76  auto uMainSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
77  mainSizer = uMainSizer.get();
78 
79  {
80  auto vSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
81  {
82  auto iconAndTextSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
83 
84  wxBitmap bitmap = wxArtProvider::GetIcon(wxART_WARNING,
85  wxART_MESSAGE_BOX);
86  wxStaticBitmap *icon = safenew wxStaticBitmap(this, -1, bitmap);
87  iconAndTextSizer->Add(icon, 0, wxCENTER);
88 
89  wxStaticText *statText = safenew wxStaticText(this, -1, message);
90  statText->SetName(message); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
91  iconAndTextSizer->Add(statText, 1, wxCENTER | wxLEFT, 15);
92 
93  vSizer->Add(iconAndTextSizer.release(), 0, wxALIGN_LEFT | wxALL, 5);
94  }
95 
96  size_t count = 0;
97  while (buttons[count])count++;
98  ArrayOf<wxString> buttonLabels{ count };
99 
100  count = 0;
101  while (buttons[count]){
102  buttonLabels[count] = buttons[count];
103  count++;
104  }
105 
106  mRadioBox = safenew wxRadioBox(this, -1,
107  boxMsg,
108  wxDefaultPosition, wxDefaultSize,
109  count, buttonLabels.get(),
110  1, wxRA_SPECIFY_COLS);
111  mRadioBox->SetName(boxMsg);
112  mRadioBox->SetSelection(0);
113  vSizer->Add(mRadioBox, 1, wxEXPAND | wxALIGN_CENTER | wxALL, 5);
114 
115 
116  {
117  auto buttonSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
118 
119  wxButton* pButton;
120  if (log)
121  {
122  pButton = safenew wxButton(this, ID_SHOW_LOG_BUTTON, _("Show Log for Details"));
123  buttonSizer->Add(pButton, 0, wxALIGN_LEFT | wxALL, 5);
124  pButton->SetDefault(); // Encourage user to look at files.
125 
126  buttonSizer->AddSpacer(40);
127  }
128 
129  pButton = safenew wxButton(this, wxID_OK, _("OK"));
130  if (!log)
131  pButton->SetDefault();
132  buttonSizer->Add(pButton, 0, wxALIGN_RIGHT | wxALL, 5);
133 
134  vSizer->Add(buttonSizer.release(), 0, wxALIGN_CENTER | wxALL, 5);
135  }
136 
137  mainSizer->Add(vSizer.release(), 0, wxALL, 5);
138  }
139 
140  SetAutoLayout(true);
141  SetSizer(uMainSizer.release());
142  }
143 
144  mainSizer->Fit(this);
145  mainSizer->SetSizeHints(this);
146 }
147 
148 void MultiDialog::OnOK(wxCommandEvent & WXUNUSED(event))
149 {
150  EndModal(mRadioBox->GetSelection());
151 }
152 
153 void MultiDialog::OnShowLog(wxCommandEvent & WXUNUSED(event))
154 {
155  auto project = GetActiveProject();
156  project->OnShowLog(*project);
157 }
158 
159 
160 int ShowMultiDialog(const wxString &message,
161  const wxString &title,
162  const wxChar **buttons, const wxString &boxMsg, bool log)
163 {
164  wxWindow * pParent = wxTheApp->GetTopWindow();
165 
166  // We want a parent we can display over, so don't make it a parent if top
167  // window is a STAY_ON_TOP.
168  if (pParent) {
169  if ((pParent->GetWindowStyle() & wxSTAY_ON_TOP) == wxSTAY_ON_TOP)
170  pParent = NULL;
171  }
172  MultiDialog dlog(pParent,
173  message, title, buttons, boxMsg, log);
174  // If dialog does not have a parent, cannot be centred on it.
175  if (pParent != NULL)
176  dlog.CentreOnParent();
177  else {
178  dlog.CenterOnScreen();
179  // and after centring move the dialog left by the size of the dialog.
180  // Likely to help if we have the splash screen visible, or if
181  // we're spanning two equally sized monitors.
182  // Unlikely to make things worse.
183  wxSize Size = dlog.GetSize();
184  Size.SetHeight( 10 );
185  wxPoint Pos = dlog.GetPosition() -Size;
186  dlog.Move(Pos);
187  }
188  return dlog.ShowModal();
189 }
190 
wxRadioBox * mRadioBox
Definition: MultiDialog.cpp:52
void OnOK(wxCommandEvent &event)
#define ID_SHOW_LOG_BUTTON
Definition: MultiDialog.cpp:57
#define safenew
Definition: Audacity.h:230
void OnShowLog(const CommandContext &context)
int ShowMultiDialog(const wxString &message, const wxString &title, const wxChar **buttons, const wxString &boxMsg, bool log)
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
void OnShowLog(wxCommandEvent &event)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
Memory.h template class for making an array of float, bool, etc.
Definition: MemoryX.h:86
END_EVENT_TABLE()
A multi purpose dialog, mainly used to show lists of orphaned or damaged block files. It is a good alternative to having a dialog pop up for each problem encountered, since there can be many orphans.
Definition: MultiDialog.cpp:39
MultiDialog(wxWindow *pParent, wxString message, wxString title, const wxChar **buttons, wxString boxMsg, bool log)
Definition: MultiDialog.cpp:64