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