forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiDialog.cpp
More file actions
220 lines (183 loc) · 6.36 KB
/
Copy pathMultiDialog.cpp
File metadata and controls
220 lines (183 loc) · 6.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/**********************************************************************
Audacity: A Digital Audio Editor
Audacity(R) is copyright (c) 1999-2010 Audacity Team.
License: GPL v2. See License.txt.
MultiDialog.h
Monty
Vaughan Johnson
*******************************************************************//**
\class MultiDialog
\brief 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.
*//*******************************************************************/
#include "../Audacity.h"
#include "MultiDialog.h"
#include "../ShuttleGui.h"
#include <wx/app.h>
#include <wx/button.h>
#include <wx/dialog.h>
#include <wx/intl.h>
#include <wx/icon.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/statbmp.h>
#include <wx/artprov.h>
#include <wx/radiobox.h>
#include <wx/bmpbuttn.h>
#include "../AudacityLogger.h"
#include "wxPanelWrapper.h"
#include "../Theme.h"
#include "../AllThemeResources.h"
#include "../widgets/HelpSystem.h"
class MultiDialog final : public wxDialogWrapper
{
public:
MultiDialog(wxWindow * pParent,
const TranslatableString &message,
const TranslatableString &title,
const TranslatableStrings &buttons,
const wxString &helpPage,
const TranslatableString &boxMsg, bool log);
~MultiDialog() {};
private:
void OnOK( wxCommandEvent &event );
void OnShowLog(wxCommandEvent& event);
void OnHelp(wxCommandEvent& event);
wxRadioBox* mRadioBox;
wxString mHelpPage;
DECLARE_EVENT_TABLE()
};
#define ID_SHOW_LOG_BUTTON 3333
BEGIN_EVENT_TABLE(MultiDialog, wxDialogWrapper)
EVT_BUTTON( wxID_OK, MultiDialog::OnOK )
EVT_BUTTON(ID_SHOW_LOG_BUTTON, MultiDialog::OnShowLog)
EVT_BUTTON(wxID_HELP, MultiDialog::OnHelp)
END_EVENT_TABLE()
MultiDialog::MultiDialog(wxWindow * pParent,
const TranslatableString &message,
const TranslatableString &title,
const TranslatableStrings &buttons,
const wxString &helpPage,
const TranslatableString &boxMsg,
bool log
)
: wxDialogWrapper(pParent, wxID_ANY, title,
wxDefaultPosition, wxDefaultSize,
wxCAPTION), // not wxDEFAULT_DIALOG_STYLE because we don't want wxCLOSE_BOX and wxSYSTEM_MENU
mHelpPage( helpPage)
{
SetName();
ShuttleGui S{ this, eIsCreating };
{
S.SetBorder( 5 );
S.StartVerticalLay( 0 );
{
S.StartHorizontalLay(wxALIGN_LEFT | wxALL, 0);
{
S.SetBorder( 0 );
wxBitmap bitmap = wxArtProvider::GetIcon(wxART_WARNING,
wxART_MESSAGE_BOX);
auto icon = safenew wxStaticBitmap(S.GetParent(), -1, bitmap);
S
.Position( wxCENTER )
.AddWindow( icon );
S.SetBorder( 15 );
S.Prop(1).AddVariableText( message, false, wxCENTER | wxLEFT );
}
S.EndHorizontalLay();
const auto buttonLabels = transform_container<wxArrayStringEx>(
buttons, std::mem_fn( &TranslatableString::Translation ) );
const auto count = buttons.size();
const auto boxStr = boxMsg.Translation();
S.SetBorder( 5 );
mRadioBox = safenew wxRadioBox(S.GetParent(), -1,
boxStr,
wxDefaultPosition, wxDefaultSize,
count, count ? &buttonLabels[0] : nullptr,
1, wxRA_SPECIFY_COLS);
mRadioBox->SetSelection(0);
S.Prop( 1 )
.Name( boxMsg )
.Position(wxEXPAND | wxALL)
.AddWindow( mRadioBox );
S.StartHorizontalLay(wxALIGN_CENTER | wxALL, 0);
{
if (log)
{
S
.Id(ID_SHOW_LOG_BUTTON)
.AddButton(
XXO("Show Log for Details"), wxALIGN_LEFT | wxALL,
// set default to encourage user to look at files.
true);
S.AddSpace(40, 0);
}
auto pButton = S.Id(wxID_OK)
.AddButton(XXO("OK"), wxALIGN_CENTER, !log);
if (!mHelpPage.IsEmpty()) {
auto pHelpBtn = S.Id(wxID_HELP)
.AddBitmapButton(theTheme.Bitmap(bmpHelpIcon), wxALIGN_CENTER, false);
pHelpBtn->SetToolTip(XO("Help").Translation());
pHelpBtn->SetLabel(XO("Help").Translation()); // for screen readers
}
}
S.EndHorizontalLay();
}
S.EndVerticalLay();
}
SetAutoLayout(true);
GetSizer()->Fit(this);
GetSizer()->SetSizeHints(this);
}
void MultiDialog::OnOK(wxCommandEvent & WXUNUSED(event))
{
EndModal(mRadioBox->GetSelection());
}
void MultiDialog::OnShowLog(wxCommandEvent & WXUNUSED(event))
{
auto logger = AudacityLogger::Get();
if (logger) {
logger->Show();
}
}
void MultiDialog::OnHelp(wxCommandEvent & WXUNUSED(event))
{
HelpSystem::ShowHelp(FindWindow(wxID_HELP), mHelpPage, true);
}
int ShowMultiDialog(const TranslatableString &message,
const TranslatableString &title,
const TranslatableStrings &buttons,
const wxString &helpPage,
const TranslatableString &boxMsg, bool log)
{
wxWindow * pParent = wxTheApp->GetTopWindow();
// We want a parent we can display over, so don't make it a parent if top
// window is a STAY_ON_TOP.
if (pParent) {
if ((pParent->GetWindowStyle() & wxSTAY_ON_TOP) == wxSTAY_ON_TOP)
pParent = NULL;
}
MultiDialog dlog(pParent,
message, title, buttons, helpPage, boxMsg, log);
// If dialog does not have a parent, cannot be centred on it.
if (pParent != NULL)
dlog.CentreOnParent();
else {
dlog.CenterOnScreen();
// and after centring move the dialog left by the size of the dialog.
// Likely to help if we have the splash screen visible, or if
// we're spanning two equally sized monitors.
// Unlikely to make things worse.
wxSize Size = dlog.GetSize();
Size.SetHeight( 10 );
wxPoint Pos = dlog.GetPosition() -Size;
dlog.Move(Pos);
}
return dlog.ShowModal();
}
const TranslatableString &DefaultMultiDialogMessage()
{
static auto result = XO("Please select an action");
return result;
}