Audacity 3.2.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
ProgressDialog Class Reference

ProgressDialog Class. More...

#include <ProgressDialog.h>

Inheritance diagram for ProgressDialog:
[legend]
Collaboration diagram for ProgressDialog:
[legend]

Public Types

using MessageColumn = std::vector< TranslatableString >
 
using MessageTable = std::vector< MessageColumn >
 

Public Member Functions

 ProgressDialog ()
 Methods for ProgressDialog. More...
 
 ProgressDialog (const TranslatableString &title, const TranslatableString &message={}, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
 
virtual ~ProgressDialog ()
 
bool Create (const TranslatableString &title, const TranslatableString &message={}, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
 
void Reinit () override
 Reset the dialog state. More...
 
void SetDialogTitle (const TranslatableString &title) override
 Change the dialog's title. More...
 
ProgressResult Update (int value, const TranslatableString &message={})
 
ProgressResult Update (double current, const TranslatableString &message={})
 
ProgressResult Update (double current, double total, const TranslatableString &message={})
 
ProgressResult Update (wxULongLong_t current, wxULongLong_t total, const TranslatableString &message={})
 
ProgressResult Update (wxLongLong current, wxLongLong total, const TranslatableString &message={})
 
ProgressResult Update (wxLongLong_t current, wxLongLong_t total, const TranslatableString &message={})
 
ProgressResult Update (int current, int total, const TranslatableString &message={})
 
ProgressResult Poll (unsigned long long numerator, unsigned long long denominator, const TranslatableString &message={}) override
 Update the bar and poll for clicks. Call only on the main thread. More...
 
void SetMessage (const TranslatableString &message) override
 Change an existing dialog's message. More...
 
- Public Member Functions inherited from wxDialogWrapper
 wxDialogWrapper ()
 
 wxDialogWrapper (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
bool Create (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
void SetTitle (const TranslatableString &title)
 
void SetLabel (const TranslatableString &title)
 
void SetName (const TranslatableString &title)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxDialog >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 
virtual ~ProgressDialog ()
 
virtual ProgressResult Poll (unsigned long long numerator, unsigned long long denominator, const TranslatableString &message={})=0
 Update the bar and poll for clicks. Call only on the main thread. More...
 
virtual void SetMessage (const TranslatableString &message)=0
 Change an existing dialog's message. More...
 
virtual void SetDialogTitle (const TranslatableString &title)=0
 Change the dialog's title. More...
 
virtual void Reinit ()=0
 Reset the dialog state. More...
 

Protected Member Functions

 ProgressDialog (const TranslatableString &title, const MessageTable &columns, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
 
bool Create (const TranslatableString &title, const MessageTable &columns, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
 

Protected Attributes

wxWindowRef mHadFocus
 
wxStaticText * mElapsed
 
wxStaticText * mRemaining
 
wxGauge * mGauge
 
wxLongLong_t mStartTime
 
wxLongLong_t mLastUpdate
 
wxLongLong_t mYieldTimer
 
wxLongLong_t mElapsedTime {}
 
int mLastValue
 
bool mCancel
 
bool mStop
 
bool mIsTransparent
 
bool m_bShowElapsedTime = true
 
bool m_bConfirmAction = false
 

Private Member Functions

void Init ()
 
bool SearchForWindow (const wxWindowList &list, const wxWindow *searchfor) const
 
void OnCancel (wxCommandEvent &e)
 
void OnStop (wxCommandEvent &e)
 
void OnCloseWindow (wxCloseEvent &e)
 
void Beep () const
 
bool ConfirmAction (const TranslatableString &sPrompt, const TranslatableString &sTitle, int iButtonID=-1)
 
void AddMessageAsColumn (wxBoxSizer *pSizer, const MessageColumn &column, bool bFirstColumn)
 

Private Attributes

wxEventLoopGuarantor mLoop
 
std::unique_ptr< wxWindowDisabler > mDisable
 
wxStaticText * mMessage {}
 
int mLastW { 0 }
 
int mLastH { 0 }
 
std::chrono::nanoseconds mTotalPollTime {}
 
unsigned mPollsCount { 0 }
 
std::chrono::nanoseconds mTotalYieldTime {}
 
unsigned mYieldsCount { 0 }
 

Detailed Description

ProgressDialog Class.

Custom progress dialog with Audacity specific semantics.

Definition at line 50 of file ProgressDialog.h.

Member Typedef Documentation

◆ MessageColumn

Definition at line 63 of file ProgressDialog.h.

◆ MessageTable

Definition at line 64 of file ProgressDialog.h.

Constructor & Destructor Documentation

◆ ProgressDialog() [1/3]

ProgressDialog::ProgressDialog ( )

Methods for ProgressDialog.

Definition at line 996 of file ProgressDialog.cpp.

998{
999}

◆ ProgressDialog() [2/3]

ProgressDialog::ProgressDialog ( const TranslatableString title,
const TranslatableString message = {},
int  flags = pdlgDefaultFlags,
const TranslatableString sRemainingLabelText = {} 
)

Definition at line 1001 of file ProgressDialog.cpp.

1006{
1007 Create(title, message, flags, sRemainingLabelText);
1008}
static const auto title
bool Create(const TranslatableString &title, const TranslatableString &message={}, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})

References Create(), and title.

Here is the call graph for this function:

◆ ProgressDialog() [3/3]

ProgressDialog::ProgressDialog ( const TranslatableString title,
const MessageTable columns,
int  flags = pdlgDefaultFlags,
const TranslatableString sRemainingLabelText = {} 
)
protected

Definition at line 1010 of file ProgressDialog.cpp.

1015{
1016 Create(title, columns, flags, sRemainingLabelText);
1017}

References Create(), and title.

Here is the call graph for this function:

◆ ~ProgressDialog()

ProgressDialog::~ProgressDialog ( )
virtual

Reimplemented from BasicUI::ProgressDialog.

Definition at line 1022 of file ProgressDialog.cpp.

1023{
1024 // Delete the window disabler before hiding the dialog to allow
1025 // focus to return to the original window.
1026 mDisable.reset();
1027
1028 if (IsShown())
1029 {
1030 Show(false);
1031
1032 Beep();
1033 }
1034
1035#if defined(__WXGTK__)
1036 // Under GTK, when applying any effect that prompts the user, it's more than
1037 // like that FindFocus() will return NULL. So, make sure something has focus.
1038 if (GetParent()) {
1039 GetParent()->SetFocus();
1040 }
1041#endif
1042
1043 // Restore saved focus, but only if the window still exists.
1044 //
1045 // PRL: I'm conservatively preserving the old existence test, but I think
1046 // it's redundant now that we use wxWindowRef to avoid a dangling pointer
1047 if (mHadFocus && SearchForWindow(wxTopLevelWindows, mHadFocus)) {
1048 mHadFocus->SetFocus();
1049 }
1050
1051 using namespace std::chrono;
1052 wxLogInfo(
1053 "Operation '%s' took %f seconds. Poll was called %d times and took %f seconds. Yield was called %d times and took %f seconds.",
1054 GetTitle(), mElapsedTime / 1000.0,
1055 mPollsCount, duration_cast<duration<double>>(mTotalPollTime).count(),
1056 mYieldsCount, duration_cast<duration<double>>(mTotalYieldTime).count());
1057}
std::unique_ptr< wxWindowDisabler > mDisable
std::chrono::nanoseconds mTotalPollTime
void Beep() const
bool SearchForWindow(const wxWindowList &list, const wxWindow *searchfor) const
wxLongLong_t mElapsedTime
std::chrono::nanoseconds mTotalYieldTime
unsigned mPollsCount
unsigned mYieldsCount
wxWindowRef mHadFocus

References Beep(), mDisable, mElapsedTime, mHadFocus, mPollsCount, mTotalPollTime, mTotalYieldTime, mYieldsCount, and SearchForWindow().

Here is the call graph for this function:

Member Function Documentation

◆ AddMessageAsColumn()

void ProgressDialog::AddMessageAsColumn ( wxBoxSizer *  pSizer,
const MessageColumn column,
bool  bFirstColumn 
)
private

Definition at line 1120 of file ProgressDialog.cpp.

1122 {
1123
1124 // Assuming that we don't want empty columns, bail out if there is no text.
1125 if (column.empty())
1126 return;
1127
1128 // Join strings
1129 auto sText = column[0];
1130 std::for_each( column.begin() + 1, column.end(),
1131 [&](const TranslatableString &text)
1132 { sText.Join( text, wxT("\n") ); });
1133
1134 // Create a statictext object and add to the sizer
1135 wxStaticText* oText = safenew wxStaticText(this,
1136 wxID_ANY,
1137 sText.Translation(),
1138 wxDefaultPosition,
1139 wxDefaultSize,
1140 wxALIGN_LEFT);
1141 oText->SetName(sText.Translation()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1142
1143 // If this is the first column then set the mMessage pointer so non-TimerRecord usages
1144 // will still work correctly in SetMessage()
1145 if (bFirstColumn) {
1146 mMessage = oText;
1147 }
1148
1149 pSizer->Add(oText, 1, wxEXPAND | wxALL, 5);
1150}
#define safenew
Definition: MemoryX.h:10
wxStaticText * mMessage
Holds a msgid for the translation catalog; may also bind format arguments.
wxWeakRef< wxTextCtrl > sText
Definition: LogWindow.cpp:44

References mMessage, safenew, and anonymous_namespace{LogWindow.cpp}::sText.

Referenced by Create().

Here is the caller graph for this function:

◆ Beep()

void ProgressDialog::Beep ( ) const
private

Definition at line 1638 of file ProgressDialog.cpp.

1639{
1640 int after;
1641 bool should;
1642 wxString name;
1643
1644 gPrefs->Read(wxT("/GUI/BeepOnCompletion"), &should, false);
1645 gPrefs->Read(wxT("/GUI/BeepAfterDuration"), &after, 60);
1646 gPrefs->Read(wxT("/GUI/BeepFileName"), &name, wxEmptyString);
1647
1648 if (should && wxGetUTCTimeMillis().GetValue() - mStartTime > after * 1000)
1649 {
1650 wxBusyCursor busy;
1651 wxSound s;
1652
1653 if (name.empty())
1654 {
1655 s.Create(sizeof(beep), beep);
1656 }
1657 else
1658 {
1659 s.Create(name);
1660 }
1661
1662 if (s.IsOk())
1663 {
1664 s.Play(wxSOUND_SYNC);
1665 }
1666 }
1667}
wxT("CloseDown"))
const TranslatableString name
Definition: Distortion.cpp:74
FileConfig * gPrefs
Definition: Prefs.cpp:70
static const unsigned char beep[]
wxLongLong_t mStartTime

References beep, TranslatableString::empty(), gPrefs, mStartTime, name, and wxT().

Referenced by ~ProgressDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ConfirmAction()

bool ProgressDialog::ConfirmAction ( const TranslatableString sPrompt,
const TranslatableString sTitle,
int  iButtonID = -1 
)
private

Definition at line 1671 of file ProgressDialog.cpp.

1673 {
1674
1675 // Check if confirmations are enabled?
1676 // If not then return TRUE
1677 if (m_bConfirmAction == false) {
1678 return true;
1679 }
1680
1681 AudacityMessageDialog dlgMessage(
1682 this,
1683 sPrompt,
1684 sTitle,
1685 wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT | wxSTAY_ON_TOP );
1686 int iAction = dlgMessage.ShowModal();
1687
1688 bool bReturn = (iAction == wxID_YES);
1689 if ((bReturn == false) && (iButtonID > -1)) {
1690 // Set the focus back to the relevant button
1691 FindWindowById(iButtonID, this)->SetFocus();
1692 }
1693
1694 return bReturn;
1695}
Wrap wxMessageDialog so that caption IS translatable.

References m_bConfirmAction.

Referenced by OnCancel(), OnCloseWindow(), and OnStop().

Here is the caller graph for this function:

◆ Create() [1/2]

bool ProgressDialog::Create ( const TranslatableString title,
const MessageTable columns,
int  flags = pdlgDefaultFlags,
const TranslatableString sRemainingLabelText = {} 
)
protected

Definition at line 1171 of file ProgressDialog.cpp.

1175{
1176 Init();
1177
1178 wxWindow *parent =
1179#if defined(__WXMAC__)
1180 // Bug 2703: In release builds, the progress dialog will fall behind
1181 // the top level dialog (like effects dialogs). This does not happen
1182 // in debug builds and I was not able to track down the reason. So,
1183 // this is a workaround and should be reviewed as some point, like
1184 // when upgrading to the next WX version.
1185 GetParentForModalDialog(mHadFocus, 0);
1186#else
1187 GetParentForModalDialog(nullptr, 0);
1188#endif
1189
1190 // Set this boolean to indicate if we are using the "Elapsed" labels
1192 // Set this boolean to indicate if we confirm the Cancel/Stop actions
1194
1195 bool success = wxDialogWrapper::Create(parent,
1196 wxID_ANY,
1197 title,
1198 wxDefaultPosition,
1199 wxDefaultSize,
1200 wxDEFAULT_DIALOG_STYLE |
1201 wxFRAME_FLOAT_ON_PARENT);
1202 if (!success)
1203 {
1204 return false;
1205 }
1206
1207 SetName(); // This was added for NVDA screen reader and may now be redundant.
1208 SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT); // Ancient code. Is it still required?
1209
1210 {
1211 wxWindow *window;
1212
1213 // There may be more than one column, so create a BoxSizer container
1214 auto uColSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
1215 auto colSizer = uColSizer.get();
1216
1217 // TODO: this setting-up of a grid of text in a sizer might be worth
1218 // extracting as a utility for building other dialogs.
1219 {
1220 bool bFirstCol = true;
1221 for (const auto &column : columns) {
1222 AddMessageAsColumn(colSizer, column, bFirstCol);
1223 bFirstCol = false;
1224 }
1225 }
1226
1227 // and put message column(s) into a main vertical sizer.
1228 auto vertSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
1229 vertSizer->Add(uColSizer.release(), 1, wxEXPAND | wxALL, 10);
1230
1231 mGauge = safenew wxGauge(this,
1232 wxID_ANY,
1233 1000,
1234 wxDefaultPosition,
1235 wxDefaultSize,
1236 wxGA_HORIZONTAL);
1237 vertSizer->Add(mGauge, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
1238
1239 {
1240 auto uGridSizer = std::make_unique<wxFlexGridSizer>(2, 2, 10, 10);
1241 // Only one row if we are not going to show the elapsed time
1242 if (m_bShowElapsedTime == false) {
1243 uGridSizer = std::make_unique<wxFlexGridSizer>(1, 2, 10, 10);
1244 }
1245 auto gridSizer = uGridSizer.get();
1246
1247 if (m_bShowElapsedTime) {
1248 window = safenew wxStaticText(this,
1249 wxID_ANY,
1250 _("Elapsed Time:"),
1251 wxDefaultPosition,
1252 wxDefaultSize,
1253 wxALIGN_RIGHT);
1254
1255 window->SetName(window->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1256 gridSizer->Add(window, 0, wxALIGN_RIGHT);
1257
1258 mElapsed = safenew wxStaticText(this,
1259 wxID_ANY,
1260 wxT("00:00:00"),
1261 wxDefaultPosition,
1262 wxDefaultSize,
1263 wxALIGN_LEFT);
1264
1265 mElapsed->SetName(mElapsed->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1266 gridSizer->Add(mElapsed, 0, wxALIGN_LEFT);
1267 }
1268
1269 // Customised "Remaining" label text
1270 auto sRemainingText = sRemainingLabelText;
1271 if (sRemainingText.empty()) {
1272 sRemainingText = XO("Remaining Time:");
1273 }
1274
1275 window = safenew wxStaticText(this,
1276 wxID_ANY,
1277 sRemainingText.Translation(),
1278 wxDefaultPosition,
1279 wxDefaultSize,
1280 wxALIGN_RIGHT);
1281 window->SetName(window->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1282 gridSizer->Add(window, 0, wxALIGN_RIGHT);
1283
1284 mRemaining = safenew wxStaticText(this,
1285 wxID_ANY,
1286 wxT("00:00:00"),
1287 wxDefaultPosition,
1288 wxDefaultSize,
1289 wxALIGN_LEFT);
1290 mRemaining->SetName(mRemaining->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1291 gridSizer->Add(mRemaining, 0, wxALIGN_LEFT);
1292
1293 vertSizer->Add(uGridSizer.release(), 0, wxALIGN_CENTER | wxLEFT | wxRIGHT | wxBOTTOM, 10);
1294 }
1295
1296 {
1297 auto uButtonBar = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
1298 auto buttonBarSizer = uButtonBar.get();
1299
1300 if (!(flags & pdlgHideStopButton)) {
1301 window = safenew wxButton(this, wxID_OK, _("Stop"));
1302 buttonBarSizer->Add(window, 0, wxRIGHT, 10);
1303 }
1304 if (!(flags & pdlgHideCancelButton)) {
1305 window = safenew wxButton(this, wxID_CANCEL, _("Cancel"));
1306 buttonBarSizer->Add(window, 0, wxRIGHT, 10);
1307 }
1308 vertSizer->Add(uButtonBar.release(), 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 10);
1309 }
1310
1311 SetSizerAndFit(vertSizer.release());
1312 }
1313 Layout();
1314
1315 // Center progress bar on Parent if it is nice and wide, otherwise Center on screen.
1316 int parentWidth = -1, parentHeight=-1;
1317 if( GetParent() ) GetParent()->GetSize( &parentWidth, &parentHeight );
1318 if (parentWidth > 400)
1319 CenterOnParent();
1320 else
1321 CenterOnScreen();
1322
1323 Reinit();
1324
1325 // Even though we won't necessarily show the dialog due to the 500ms
1326 // delay, we MUST disable other windows/menus anyway since we run the risk
1327 // of allowing other tasks to run before this one is complete.
1328 //
1329 // Reviewed this code per Proposed Features #1, at
1330 // http://wiki.audacityteam.org/wiki/Proposal_Timer_Record_Improvements.
1331 // Note that this causes a problem for Timer Record wait dialog
1332 // (see TimerRecordDialog::RunWaitDialog()), because it makes it
1333 // impossible to do any editing, even in other open projects,
1334 // while waiting for Timer Record to start -- and then also
1335 // while it's recording, it has a ProgressDialog, so really,
1336 // no editing in any project until Timer Record finishes.
1337 mDisable = std::make_unique<wxWindowDisabler>(this);
1338
1339 return true;
1340}
XO("Cut/Copy/Paste")
#define _(s)
Definition: Internat.h:75
@ pdlgConfirmStopCancel
@ pdlgHideStopButton
@ pdlgHideElapsedTime
@ pdlgHideCancelButton
wxStaticText * mElapsed
wxGauge * mGauge
void AddMessageAsColumn(wxBoxSizer *pSizer, const MessageColumn &column, bool bFirstColumn)
void Reinit() override
Reset the dialog state.
wxStaticText * mRemaining
bool Create(wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))

References _, AddMessageAsColumn(), wxDialogWrapper::Create(), Init(), m_bConfirmAction, m_bShowElapsedTime, mDisable, mElapsed, mGauge, mHadFocus, mRemaining, pdlgConfirmStopCancel, pdlgHideCancelButton, pdlgHideElapsedTime, pdlgHideStopButton, Reinit(), safenew, wxDialogWrapper::SetName(), title, wxT(), and XO().

Here is the call graph for this function:

◆ Create() [2/2]

bool ProgressDialog::Create ( const TranslatableString title,
const TranslatableString message = {},
int  flags = pdlgDefaultFlags,
const TranslatableString sRemainingLabelText = {} 
)

Definition at line 1152 of file ProgressDialog.cpp.

1156{
1157 MessageTable columns(1);
1158 columns.back().push_back(message);
1159 auto result = Create(title, columns, flags, sRemainingLabelText);
1160
1161 if (result) {
1162 // Record some values used in case of change of message
1163 // TODO: make the following work in case of message tables
1164 wxClientDC dc(this);
1165 dc.GetMultiLineTextExtent(message.Translation(), &mLastW, &mLastH);
1166 }
1167
1168 return result;
1169}
std::vector< MessageColumn > MessageTable
wxString Translation() const

References Create(), mLastH, mLastW, title, and TranslatableString::Translation().

Referenced by Create(), and ProgressDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Init()

void ProgressDialog::Init ( )
private

Definition at line 1059 of file ProgressDialog.cpp.

1060{
1061 // There's a problem where the focus is not returned to the window that had
1062 // it before creating this object. The reason is because the focus events
1063 // that are sent to the parent window after the wxWindowDisabler are created
1064 // are tossed and focus will not get restored to the parent once the disabler
1065 // is deleted. (See bug #1173 for more info)
1066 //
1067 // So, we capture and restore the focus ourselves.
1068 mHadFocus = wxWindow::FindFocus();
1069
1070#if defined(__WXGTK__)
1071 // Under GTK, when applying any effect that prompts the user, it's more than
1072 // likely that FindFocus() will return NULL. So, make sure something has focus.
1073 if (GetParent())
1074 {
1075 GetParent()->SetFocus();
1076 }
1077#endif
1078}

References mHadFocus.

Referenced by Create().

Here is the caller graph for this function:

◆ OnCancel()

void ProgressDialog::OnCancel ( wxCommandEvent &  e)
private

Definition at line 1606 of file ProgressDialog.cpp.

1607{
1608 if (!ConfirmAction(
1609 XO("Are you sure you wish to cancel?"),
1610 XO("Confirm Cancel"), wxID_CANCEL)) {
1611 return;
1612 }
1613 FindWindowById(wxID_CANCEL, this)->Disable();
1614 mCancel = true;
1615}
bool ConfirmAction(const TranslatableString &sPrompt, const TranslatableString &sTitle, int iButtonID=-1)

References ConfirmAction(), mCancel, and XO().

Here is the call graph for this function:

◆ OnCloseWindow()

void ProgressDialog::OnCloseWindow ( wxCloseEvent &  e)
private

Definition at line 1629 of file ProgressDialog.cpp.

1630{
1631 if (!ConfirmAction(
1632 XO("Are you sure you wish to close?"), XO("Confirm Close"))) {
1633 return;
1634 }
1635 mCancel = true;
1636}

References ConfirmAction(), mCancel, and XO().

Here is the call graph for this function:

◆ OnStop()

void ProgressDialog::OnStop ( wxCommandEvent &  e)
private

Definition at line 1617 of file ProgressDialog.cpp.

1618{
1619 if (!ConfirmAction(
1620 XO("Are you sure you wish to stop?"),
1621 XO("Confirm Stop"), wxID_OK)) {
1622 return;
1623 }
1624 FindWindowById(wxID_OK, this)->Disable();
1625 mCancel = false;
1626 mStop = true;
1627}

References ConfirmAction(), mCancel, mStop, and XO().

Here is the call graph for this function:

◆ Poll()

ProgressResult ProgressDialog::Poll ( unsigned long long  numerator,
unsigned long long  denominator,
const TranslatableString message = {} 
)
overridevirtual

Update the bar and poll for clicks. Call only on the main thread.

Implements BasicUI::ProgressDialog.

Definition at line 1519 of file ProgressDialog.cpp.

1522{
1523 return Update(numerator, denominator, message);
1524}
ProgressResult Update(int value, const TranslatableString &message={})

References Update().

Here is the call graph for this function:

◆ Reinit()

void ProgressDialog::Reinit ( )
overridevirtual

Reset the dialog state.

Implements BasicUI::ProgressDialog.

Definition at line 1080 of file ProgressDialog.cpp.

1081{
1082 mLastValue = 0;
1083
1084 mStartTime = wxGetUTCTimeMillis().GetValue();
1087 mElapsedTime = 0;
1088 mCancel = false;
1089 mStop = false;
1090
1091 // Because wxGTK is very sensitive about maintaining focus when
1092 // this window is not shown, we always show it. But, since we
1093 // want a 500ms delay before it's actually visible for those
1094 // quick tasks, we show it as transparent. If the initial
1095 // delay is exceeded, then we reset the dialog to full opacity.
1096 SetTransparent(0);
1097 mIsTransparent = true;
1098
1099 auto button = FindWindowById(wxID_CANCEL, this);
1100 if (button)
1101 button->Enable();
1102 button = FindWindowById(wxID_OK, this);
1103 if (button)
1104 button->Enable();
1105
1106 wxDialogWrapper::Show(true);
1107
1108 mTotalPollTime = {};
1109 mPollsCount = {};
1110 mTotalYieldTime = {};
1111 mYieldsCount = {};
1112}
wxLongLong_t mLastUpdate
wxLongLong_t mYieldTimer

References mCancel, mElapsedTime, mIsTransparent, mLastUpdate, mLastValue, mPollsCount, mStartTime, mStop, mTotalPollTime, mTotalYieldTime, mYieldsCount, and mYieldTimer.

Referenced by Create().

Here is the caller graph for this function:

◆ SearchForWindow()

bool ProgressDialog::SearchForWindow ( const wxWindowList &  list,
const wxWindow *  searchfor 
) const
private

Definition at line 1593 of file ProgressDialog.cpp.

1594{
1595 for (auto win : list)
1596 {
1597 if (win == searchfor || SearchForWindow(win->GetChildren(), searchfor))
1598 {
1599 return true;
1600 }
1601 }
1602
1603 return false;
1604}

References SearchForWindow().

Referenced by SearchForWindow(), and ~ProgressDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetDialogTitle()

void ProgressDialog::SetDialogTitle ( const TranslatableString title)
overridevirtual

Change the dialog's title.

Implements BasicUI::ProgressDialog.

Definition at line 1114 of file ProgressDialog.cpp.

1115{
1116 SetTitle(title);
1117}
void SetTitle(const TranslatableString &title)

References wxDialogWrapper::SetTitle(), and title.

Here is the call graph for this function:

◆ SetMessage()

void ProgressDialog::SetMessage ( const TranslatableString message)
overridevirtual

Change an existing dialog's message.

Implements BasicUI::ProgressDialog.

Definition at line 1545 of file ProgressDialog.cpp.

1546{
1547 if (!message.empty())
1548 {
1549 mMessage->SetLabel(message.Translation());
1550
1551 int w, h;
1552 wxClientDC dc(mMessage);
1553 dc.GetMultiLineTextExtent(message.Translation(), &w, &h);
1554
1555 auto sizeUpdated = false;
1556 const auto currentSize = GetClientSize();
1557 auto ds = currentSize;
1558
1559 // TODO: make the following work in case of message tables
1560 if (w > mLastW)
1561 {
1562 ds.x += (w - mLastW);
1563 sizeUpdated = true;
1564 mLastW = w;
1565 }
1566
1567 if (h > mLastH)
1568 {
1569 ds.y += (h - mLastH);
1570 sizeUpdated = true;
1571 mLastH = h;
1572 }
1573
1574 if (sizeUpdated)
1575 {
1576#if defined(__WXMAC__)
1577 wxSize sz = mMessage->GetSize();
1578 mMessage->SetMinSize(wxSize(wxMax(sz.x, mLastW), wxMax(sz.y, mLastH)));
1579#endif
1580 // No need to adjust for the margin here since we only add
1581 // to the existing dimensions.
1582 ds.x = wxMax(wxMax(ds.x, mLastW), wxMax(ds.y, mLastH));
1583 SetClientSize(ds);
1584 SetPosition(GetPosition() - (ds - currentSize) / 2);
1585 wxDialogWrapper::Update();
1586 }
1587 }
1588}

References TranslatableString::empty(), mLastH, mLastW, mMessage, and TranslatableString::Translation().

Referenced by Update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Update() [1/7]

ProgressResult ProgressDialog::Update ( double  current,
const TranslatableString message = {} 
)

Definition at line 1449 of file ProgressDialog.cpp.

1451{
1452 return Update((int)(current * 1000), message);
1453}

References Update().

Here is the call graph for this function:

◆ Update() [2/7]

ProgressResult ProgressDialog::Update ( double  current,
double  total,
const TranslatableString message = {} 
)

Definition at line 1529 of file ProgressDialog.cpp.

1531{
1532 if (total != 0)
1533 {
1534 return Update((int)(current * 1000.0 / total), message);
1535 }
1536 else
1537 {
1538 return Update(1000, message);
1539 }
1540}

References Update().

Here is the call graph for this function:

◆ Update() [3/7]

ProgressResult ProgressDialog::Update ( int  current,
int  total,
const TranslatableString message = {} 
)

Definition at line 1506 of file ProgressDialog.cpp.

1508{
1509 if (total != 0)
1510 {
1511 return Update((int)(current * ((double)(1000.0 / total))), message);
1512 }
1513 else
1514 {
1515 return Update(1000, message);
1516 }
1517}

References Update().

Here is the call graph for this function:

◆ Update() [4/7]

ProgressResult ProgressDialog::Update ( int  value,
const TranslatableString message = {} 
)

Definition at line 1345 of file ProgressDialog.cpp.

1347{
1348 using namespace std::chrono;
1349 auto updatePollTime = finally([this, pollStart = high_resolution_clock::now()] {
1350 mTotalPollTime += high_resolution_clock::now() - pollStart;
1351 });
1352
1353 mPollsCount++;
1354
1355 if (mCancel)
1356 {
1357 // for compatibility with old Update, that returned false on cancel
1359 }
1360 else if (mStop)
1361 {
1362 return ProgressResult::Stopped;
1363 }
1364
1365 wxLongLong_t now = wxGetUTCTimeMillis().GetValue();
1366 mElapsedTime = now - mStartTime;
1367
1368 if (mElapsedTime < 500)
1369 {
1371 }
1372
1373 if (mIsTransparent)
1374 {
1375 SetTransparent(255);
1376 mIsTransparent = false;
1377 }
1378
1379 if (value <= 0)
1380 {
1381 value = 1;
1382 }
1383
1384 if (value > 1000)
1385 {
1386 value = 1000;
1387 }
1388
1389 wxLongLong_t estimate = mElapsedTime * 1000ll / value;
1390 wxLongLong_t remains = (estimate + mStartTime) - now;
1391
1392 SetMessage(message);
1393
1394 if (value != mLastValue)
1395 {
1396 mGauge->SetValue(value);
1397 mGauge->Update();
1398 mLastValue = value;
1399 }
1400
1401 // Only update if a full second has passed or track progress is complete
1402 if ((now - mLastUpdate > 1000) || (value == 1000))
1403 {
1404 if (m_bShowElapsedTime) {
1405 wxTimeSpan tsElapsed(0, 0, 0, mElapsedTime);
1406 mElapsed->SetLabel(tsElapsed.Format(wxT("%H:%M:%S")));
1407 mElapsed->SetName(mElapsed->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1408 mElapsed->Update();
1409 }
1410
1411 wxTimeSpan tsRemains(0, 0, 0, remains);
1412 mRemaining->SetLabel(tsRemains.Format(wxT("%H:%M:%S")));
1413 mRemaining->SetName(mRemaining->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1414 mRemaining->Update();
1415
1416 mLastUpdate = now;
1417 }
1418
1419 wxDialogWrapper::Update();
1420
1421 // Copied from wx 3.0.2 generic progress dialog
1422 //
1423 // we have to yield because not only we want to update the display but
1424 // also to process the clicks on the cancel and skip buttons
1425 // NOTE: using YieldFor() this call shouldn't give re-entrancy problems
1426 // for event handlers not interested to UI/user-input events.
1427 //
1428 // LL: Added timer category to prevent extreme delays when processing effects
1429 // (and probably other things). I do not yet know why this happens and
1430 // I'm not too keen on having timer events processed here, but you do
1431 // what you have to do.
1432
1433 // Nyquist effects call Update on every callback, but YieldFor is
1434 // quite slow on Linux / Mac, so don't call too frequently. (bug 1575)
1435 if ((now - mYieldTimer > 50) || (value == 1000)) {
1436 const auto yieldStart = high_resolution_clock::now();
1437 mYieldsCount++;
1438 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI | wxEVT_CATEGORY_USER_INPUT | wxEVT_CATEGORY_TIMER);
1439 mTotalYieldTime += high_resolution_clock::now() - yieldStart;
1440 mYieldTimer = now;
1441 }
1442
1444}
void SetMessage(const TranslatableString &message) override
Change an existing dialog's message.

References RefreshCode::Cancelled, m_bShowElapsedTime, mCancel, mElapsed, mElapsedTime, mGauge, mIsTransparent, mLastUpdate, mLastValue, mPollsCount, mRemaining, mStartTime, mStop, mTotalPollTime, mTotalYieldTime, mYieldsCount, mYieldTimer, SetMessage(), BasicUI::Success, and wxT().

Referenced by ProjectFileIO::CopyTo(), ImportRaw(), TransportUtilities::PlayCurrentRegionAndWait(), TransportUtilities::PlayPlayRegionAndWait(), Poll(), TransportUtilities::RecordAndWait(), RemoveDependencies(), and Update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Update() [5/7]

ProgressResult ProgressDialog::Update ( wxLongLong  current,
wxLongLong  total,
const TranslatableString message = {} 
)

Definition at line 1474 of file ProgressDialog.cpp.

1476{
1477 if (total.GetValue() != 0)
1478 {
1479 return Update((int)(current.GetValue() * 1000ll / total.GetValue()), message);
1480 }
1481 else
1482 {
1483 return Update(1000, message);
1484 }
1485}

References Update().

Here is the call graph for this function:

◆ Update() [6/7]

ProgressResult ProgressDialog::Update ( wxLongLong_t  current,
wxLongLong_t  total,
const TranslatableString message = {} 
)

Definition at line 1490 of file ProgressDialog.cpp.

1492{
1493 if (total != 0)
1494 {
1495 return Update((int)(current * 1000ll / total), message);
1496 }
1497 else
1498 {
1499 return Update(1000, message);
1500 }
1501}

References Update().

Here is the call graph for this function:

◆ Update() [7/7]

ProgressResult ProgressDialog::Update ( wxULongLong_t  current,
wxULongLong_t  total,
const TranslatableString message = {} 
)

Definition at line 1458 of file ProgressDialog.cpp.

1460{
1461 if (total != 0)
1462 {
1463 return Update((int)(current * 1000 / total), message);
1464 }
1465 else
1466 {
1467 return Update(1000, message);
1468 }
1469}

References Update().

Here is the call graph for this function:

Member Data Documentation

◆ m_bConfirmAction

bool ProgressDialog::m_bConfirmAction = false
protected

Definition at line 130 of file ProgressDialog.h.

Referenced by ConfirmAction(), and Create().

◆ m_bShowElapsedTime

bool ProgressDialog::m_bShowElapsedTime = true
protected

Definition at line 129 of file ProgressDialog.h.

Referenced by Create(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mCancel

bool ProgressDialog::mCancel
protected

◆ mDisable

std::unique_ptr<wxWindowDisabler> ProgressDialog::mDisable
private

Definition at line 151 of file ProgressDialog.h.

Referenced by Create(), and ~ProgressDialog().

◆ mElapsed

wxStaticText* ProgressDialog::mElapsed
protected

Definition at line 113 of file ProgressDialog.h.

Referenced by Create(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mElapsedTime

wxLongLong_t ProgressDialog::mElapsedTime {}
protected

Definition at line 120 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and ~ProgressDialog().

◆ mGauge

wxGauge* ProgressDialog::mGauge
protected

Definition at line 115 of file ProgressDialog.h.

Referenced by Create(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mHadFocus

wxWindowRef ProgressDialog::mHadFocus
protected

Definition at line 111 of file ProgressDialog.h.

Referenced by Create(), Init(), and ~ProgressDialog().

◆ mIsTransparent

bool ProgressDialog::mIsTransparent
protected

Definition at line 126 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mLastH

int ProgressDialog::mLastH { 0 }
private

Definition at line 155 of file ProgressDialog.h.

Referenced by Create(), and SetMessage().

◆ mLastUpdate

wxLongLong_t ProgressDialog::mLastUpdate
protected

Definition at line 118 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mLastValue

int ProgressDialog::mLastValue
protected

Definition at line 121 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mLastW

int ProgressDialog::mLastW { 0 }
private

Definition at line 154 of file ProgressDialog.h.

Referenced by Create(), and SetMessage().

◆ mLoop

wxEventLoopGuarantor ProgressDialog::mLoop
private

Definition at line 149 of file ProgressDialog.h.

◆ mMessage

wxStaticText* ProgressDialog::mMessage {}
private

Definition at line 153 of file ProgressDialog.h.

Referenced by AddMessageAsColumn(), and SetMessage().

◆ mPollsCount

unsigned ProgressDialog::mPollsCount { 0 }
private

Definition at line 158 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and ~ProgressDialog().

◆ mRemaining

wxStaticText* ProgressDialog::mRemaining
protected

Definition at line 114 of file ProgressDialog.h.

Referenced by Create(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mStartTime

wxLongLong_t ProgressDialog::mStartTime
protected

Definition at line 117 of file ProgressDialog.h.

Referenced by Beep(), Reinit(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mStop

bool ProgressDialog::mStop
protected

Definition at line 124 of file ProgressDialog.h.

Referenced by OnStop(), Reinit(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mTotalPollTime

std::chrono::nanoseconds ProgressDialog::mTotalPollTime {}
private

Definition at line 157 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and ~ProgressDialog().

◆ mTotalYieldTime

std::chrono::nanoseconds ProgressDialog::mTotalYieldTime {}
private

Definition at line 159 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and ~ProgressDialog().

◆ mYieldsCount

unsigned ProgressDialog::mYieldsCount { 0 }
private

Definition at line 160 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and ~ProgressDialog().

◆ mYieldTimer

wxLongLong_t ProgressDialog::mYieldTimer
protected

Definition at line 119 of file ProgressDialog.h.

Referenced by Reinit(), and Update().


The documentation for this class was generated from the following files: