Audacity 3.2.0
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 or later. See License.txt.
6
7 MultiDialog.h
8
9 Monty
10 Vaughan Johnson
11
12*******************************************************************//*******************************************************************/
18
19
20#include "MultiDialog.h"
21#include "MemoryX.h"
22
23#include "../ShuttleGui.h"
24
25#include <wx/app.h>
26#include <wx/button.h>
27#include <wx/dialog.h>
28#include <wx/intl.h>
29#include <wx/icon.h>
30#include <wx/sizer.h>
31#include <wx/stattext.h>
32#include <wx/statbmp.h>
33#include <wx/artprov.h>
34#include <wx/radiobox.h>
35#include <wx/bmpbuttn.h>
36
37
38#include "wxPanelWrapper.h"
39#include "../LogWindow.h"
40#include "Theme.h"
41#include "AllThemeResources.h"
42#include "../widgets/HelpSystem.h"
43
44class MultiDialog final : public wxDialogWrapper
45{
46public:
47 MultiDialog(wxWindow * pParent,
48 const TranslatableString &message,
50 const TranslatableStrings &buttons,
51 const ManualPageID &helpPage,
52 const TranslatableString &boxMsg, bool log);
54
55private:
56 void OnOK( wxCommandEvent &event );
57 void OnShowLog(wxCommandEvent& event);
58 void OnHelp(wxCommandEvent& event);
59
60 wxRadioBox* mRadioBox;
62
63 DECLARE_EVENT_TABLE()
64};
65
66#define ID_SHOW_LOG_BUTTON 3333
67
68BEGIN_EVENT_TABLE(MultiDialog, wxDialogWrapper)
73
74MultiDialog::MultiDialog(wxWindow * pParent,
75 const TranslatableString &message,
77 const TranslatableStrings &buttons,
78 const ManualPageID &helpPage,
79 const TranslatableString &boxMsg,
80 bool log
81 )
82 : wxDialogWrapper(pParent, wxID_ANY, title,
83 wxDefaultPosition, wxDefaultSize,
84 wxCAPTION), // not wxDEFAULT_DIALOG_STYLE because we don't want wxCLOSE_BOX and wxSYSTEM_MENU
85 mHelpPage( helpPage)
86{
87 SetName();
88
89 ShuttleGui S{ this, eIsCreating };
90 {
91 S.SetBorder( 5 );
92 S.StartVerticalLay( 0 );
93 {
94 S.StartHorizontalLay(wxALIGN_LEFT | wxALL, 0);
95 {
96 S.SetBorder( 0 );
97 wxBitmap bitmap = wxArtProvider::GetIcon(wxART_WARNING,
98 wxART_MESSAGE_BOX);
99 auto icon = safenew wxStaticBitmap(S.GetParent(), -1, bitmap);
100 S
101 .Position( wxCENTER )
102 .AddWindow( icon );
103
104 S.SetBorder( 15 );
105 S.Prop(1).AddVariableText( message, false, wxCENTER | wxLEFT );
106 }
107 S.EndHorizontalLay();
108
109 const auto buttonLabels = transform_container<wxArrayStringEx>(
110 buttons, std::mem_fn( &TranslatableString::Translation ) );
111
112 const auto count = buttons.size();
113
114 const auto boxStr = boxMsg.Translation();
115
116 S.SetBorder( 5 );
117
118 mRadioBox = safenew wxRadioBox(S.GetParent(), -1,
119 boxStr,
120 wxDefaultPosition, wxDefaultSize,
121 count, count ? &buttonLabels[0] : nullptr,
122 1, wxRA_SPECIFY_COLS);
123 mRadioBox->SetSelection(0);
124 S.Prop( 1 )
125 .Name( boxMsg )
126 .Position(wxEXPAND | wxALL)
127 .AddWindow( mRadioBox );
128
129
130 S.StartHorizontalLay(wxALIGN_CENTER | wxALL, 0);
131 {
132 if (log)
133 {
134 S
136 .AddButton(
137 XXO("Show Log for Details"), wxALIGN_LEFT | wxALL,
138 // set default to encourage user to look at files.
139 true);
140
141 S.AddSpace(40, 0);
142 }
143
144 auto pButton = S.Id(wxID_OK)
145 .AddButton(XXO("OK"), wxALIGN_CENTER, !log);
146
147 if (!mHelpPage.empty()) {
148 auto pHelpBtn = S.Id(wxID_HELP)
149 .AddBitmapButton(theTheme.Bitmap(bmpHelpIcon), wxALIGN_CENTER, false);
150 pHelpBtn->SetToolTip(XO("Help").Translation());
151 pHelpBtn->SetLabel(XO("Help").Translation()); // for screen readers
152 }
153 }
154 S.EndHorizontalLay();
155 }
156 S.EndVerticalLay();
157 }
158
159 SetAutoLayout(true);
160 GetSizer()->Fit(this);
161 GetSizer()->SetSizeHints(this);
162}
163
164void MultiDialog::OnOK(wxCommandEvent & WXUNUSED(event))
165{
166 EndModal(mRadioBox->GetSelection());
167}
168
169void MultiDialog::OnShowLog(wxCommandEvent & WXUNUSED(event))
170{
172}
173
174void MultiDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
175{
176 HelpSystem::ShowHelp(FindWindow(wxID_HELP), mHelpPage, true);
177}
178
181 const TranslatableStrings &buttons,
182 const ManualPageID &helpPage,
183 const TranslatableString &boxMsg, bool log)
184{
185 wxWindow * pParent = wxTheApp->GetTopWindow();
186
187 // We want a parent we can display over, so don't make it a parent if top
188 // window is a STAY_ON_TOP.
189 if (pParent) {
190 if ((pParent->GetWindowStyle() & wxSTAY_ON_TOP) == wxSTAY_ON_TOP)
191 pParent = NULL;
192 }
193 MultiDialog dlog(pParent,
194 message, title, buttons, helpPage, boxMsg, log);
195 // If dialog does not have a parent, cannot be centred on it.
196 if (pParent != NULL)
197 dlog.CentreOnParent();
198 else {
199 dlog.CenterOnScreen();
200 // and after centring move the dialog left by the size of the dialog.
201 // Likely to help if we have the splash screen visible, or if
202 // we're spanning two equally sized monitors.
203 // Unlikely to make things worse.
204 wxSize Size = dlog.GetSize();
205 Size.SetHeight( 10 );
206 wxPoint Pos = dlog.GetPosition() -Size;
207 dlog.Move(Pos);
208 }
209 return dlog.ShowModal();
210}
END_EVENT_TABLE()
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
#define XXO(s)
Definition: Internat.h:44
#define XO(s)
Definition: Internat.h:31
#define safenew
Definition: MemoryX.h:10
#define ID_SHOW_LOG_BUTTON
Definition: MultiDialog.cpp:66
int ShowMultiDialog(const TranslatableString &message, const TranslatableString &title, const TranslatableStrings &buttons, const ManualPageID &helpPage, const TranslatableString &boxMsg, bool log)
static const auto title
@ eIsCreating
Definition: ShuttleGui.h:39
THEME_API Theme theTheme
Definition: Theme.cpp:82
#define S(N)
Definition: ToChars.cpp:64
std::vector< TranslatableString > TranslatableStrings
static void ShowHelp(wxWindow *parent, const FilePath &localFileName, const URLString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:237
static void Show(bool show=true)
Show or hide the unique logging window; create it on demand the first time it is shown.
Definition: LogWindow.cpp:61
A dialog presenting an exclusive, multiple choice, help button, and log info.
Definition: MultiDialog.cpp:45
void OnHelp(wxCommandEvent &event)
ManualPageID mHelpPage
Definition: MultiDialog.cpp:61
MultiDialog(wxWindow *pParent, const TranslatableString &message, const TranslatableString &title, const TranslatableStrings &buttons, const ManualPageID &helpPage, const TranslatableString &boxMsg, bool log)
Definition: MultiDialog.cpp:74
void OnShowLog(wxCommandEvent &event)
void OnOK(wxCommandEvent &event)
wxRadioBox * mRadioBox
Definition: MultiDialog.cpp:60
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:628
wxBitmap & Bitmap(int iIndex)
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const