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