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 class MultiDialog final : public wxDialogWrapper
38 {
39 public:
40  MultiDialog(wxWindow * pParent,
41  wxString message,
42  wxString title,
43  const wxChar **buttons, wxString boxMsg, bool log);
45 
46 private:
47  void OnOK( wxCommandEvent &event );
48  void OnShowLog(wxCommandEvent& event);
49 
50  wxRadioBox* mRadioBox;
51 
52  DECLARE_EVENT_TABLE()
53 };
54 
55 #define ID_SHOW_LOG_BUTTON 3333
56 
57 BEGIN_EVENT_TABLE(MultiDialog, wxDialogWrapper)
58  EVT_BUTTON( wxID_OK, MultiDialog::OnOK )
61 
62 MultiDialog::MultiDialog(wxWindow * pParent,
63  wxString message,
64  wxString title,
65  const wxChar **buttons, wxString boxMsg, bool log)
66  : wxDialogWrapper(pParent, wxID_ANY, title,
67  wxDefaultPosition, wxDefaultSize,
68  wxCAPTION) // not wxDEFAULT_DIALOG_STYLE because we don't want wxCLOSE_BOX and wxSYSTEM_MENU
69 {
70  SetName(GetTitle());
71 
72  wxBoxSizer *mainSizer;
73  {
74  auto uMainSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
75  mainSizer = uMainSizer.get();
76 
77  {
78  auto vSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
79  {
80  auto iconAndTextSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
81 
82  wxBitmap bitmap = wxArtProvider::GetIcon(wxART_WARNING,
83  wxART_MESSAGE_BOX);
84  wxStaticBitmap *icon = safenew wxStaticBitmap(this, -1, bitmap);
85  iconAndTextSizer->Add(icon, 0, wxCENTER);
86 
87  wxStaticText *statText = safenew wxStaticText(this, -1, message);
88  statText->SetName(message); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
89  iconAndTextSizer->Add(statText, 1, wxCENTER | wxLEFT, 15);
90 
91  vSizer->Add(iconAndTextSizer.release(), 0, wxALIGN_LEFT | wxALL, 5);
92  }
93 
94  size_t count = 0;
95  while (buttons[count])count++;
96  ArrayOf<wxString> buttonLabels{ count };
97 
98  count = 0;
99  while (buttons[count]){
100  buttonLabels[count] = buttons[count];
101  count++;
102  }
103 
104  mRadioBox = safenew wxRadioBox(this, -1,
105  boxMsg,
106  wxDefaultPosition, wxDefaultSize,
107  count, buttonLabels.get(),
108  1, wxRA_SPECIFY_COLS);
109  mRadioBox->SetName(boxMsg);
110  mRadioBox->SetSelection(0);
111  vSizer->Add(mRadioBox, 1, wxEXPAND | wxALIGN_CENTER | wxALL, 5);
112 
113 
114  {
115  auto buttonSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
116 
117  wxButton* pButton;
118  if (log)
119  {
120  pButton = safenew wxButton(this, ID_SHOW_LOG_BUTTON, _("Show Log for Details"));
121  buttonSizer->Add(pButton, 0, wxALIGN_LEFT | wxALL, 5);
122  pButton->SetDefault(); // Encourage user to look at files.
123 
124  buttonSizer->AddSpacer(40);
125  }
126 
127  pButton = safenew wxButton(this, wxID_OK, _("OK"));
128  if (!log)
129  pButton->SetDefault();
130  buttonSizer->Add(pButton, 0, wxALIGN_RIGHT | wxALL, 5);
131 
132  vSizer->Add(buttonSizer.release(), 0, wxALIGN_CENTER | wxALL, 5);
133  }
134 
135  mainSizer->Add(vSizer.release(), 0, wxALL, 5);
136  }
137 
138  SetAutoLayout(true);
139  SetSizer(uMainSizer.release());
140  }
141 
142  mainSizer->Fit(this);
143  mainSizer->SetSizeHints(this);
144 }
145 
146 void MultiDialog::OnOK(wxCommandEvent & WXUNUSED(event))
147 {
148  EndModal(mRadioBox->GetSelection());
149 }
150 
151 void MultiDialog::OnShowLog(wxCommandEvent & WXUNUSED(event))
152 {
153  auto project = GetActiveProject();
154  project->OnShowLog(*project);
155 }
156 
157 
158 int ShowMultiDialog(const wxString &message,
159  const wxString &title,
160  const wxChar **buttons, const wxString &boxMsg, bool log)
161 {
162  wxWindow * pParent = wxTheApp->GetTopWindow();
163 
164  // We want a parent we can display over, so don't make it a parent if top
165  // window is a STAY_ON_TOP.
166  if (pParent) {
167  if ((pParent->GetWindowStyle() & wxSTAY_ON_TOP) == wxSTAY_ON_TOP)
168  pParent = NULL;
169  }
170  MultiDialog dlog(pParent,
171  message, title, buttons, boxMsg, log);
172  // If dialog does not have a parent, cannot be centred on it.
173  if (pParent != NULL)
174  dlog.CentreOnParent();
175  else {
176  dlog.CenterOnScreen();
177  // and after centring move the dialog left by the size of the dialog.
178  // Likely to help if we have the splash screen visible, or if
179  // we're spanning two equally sized monitors.
180  // Unlikely to make things worse.
181  wxSize Size = dlog.GetSize();
182  Size.SetHeight( 10 );
183  wxPoint Pos = dlog.GetPosition() -Size;
184  dlog.Move(Pos);
185  }
186  return dlog.ShowModal();
187 }
188 
wxRadioBox * mRadioBox
Definition: MultiDialog.cpp:50
void OnOK(wxCommandEvent &event)
#define ID_SHOW_LOG_BUTTON
Definition: MultiDialog.cpp:55
#define safenew
Definition: Audacity.h:223
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"))), 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 &)
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
Memory.h template class for making an array of float, bool, etc.
Definition: MemoryX.h:469
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:37
MultiDialog(wxWindow *pParent, wxString message, wxString title, const wxChar **buttons, wxString boxMsg, bool log)
Definition: MultiDialog.cpp:62