Audacity  3.0.3
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 ()
 
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={})
 
void SetMessage (const TranslatableString &message)
 
- 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
 

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
 
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 }
 

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 61 of file ProgressDialog.h.

◆ MessageTable

Definition at line 62 of file ProgressDialog.h.

Constructor & Destructor Documentation

◆ ProgressDialog() [1/3]

ProgressDialog::ProgressDialog ( )

Methods for ProgressDialog.

Definition at line 996 of file ProgressDialog.cpp.

997 : wxDialogWrapper()
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.

1005 : wxDialogWrapper()
1006 {
1007  Create(title, message, flags, sRemainingLabelText);
1008 }

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.

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

References Create(), and title.

Here is the call graph for this function:

◆ ~ProgressDialog()

ProgressDialog::~ProgressDialog ( )
virtual

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 }

References Beep(), anonymous_namespace{wxWidgetsBasicUI.cpp}::GetParent(), mDisable, mHadFocus, 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 1102 of file ProgressDialog.cpp.

1104  {
1105 
1106  // Assuming that we don't want empty columns, bail out if there is no text.
1107  if (column.empty())
1108  return;
1109 
1110  // Join strings
1111  auto sText = column[0];
1112  std::for_each( column.begin() + 1, column.end(),
1113  [&](const TranslatableString &text)
1114  { sText.Join( text, wxT("\n") ); });
1115 
1116  // Create a statictext object and add to the sizer
1117  wxStaticText* oText = safenew wxStaticText(this,
1118  wxID_ANY,
1119  sText.Translation(),
1120  wxDefaultPosition,
1121  wxDefaultSize,
1122  wxALIGN_LEFT);
1123  oText->SetName(sText.Translation()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1124 
1125  // If this is the first column then set the mMessage pointer so non-TimerRecord usages
1126  // will still work correctly in SetMessage()
1127  if (bFirstColumn) {
1128  mMessage = oText;
1129  }
1130 
1131  pSizer->Add(oText, 1, wxEXPAND | wxALL, 5);
1132 }

References mMessage, and safenew.

Referenced by Create().

Here is the caller graph for this function:

◆ Beep()

void ProgressDialog::Beep ( ) const
private

Definition at line 1601 of file ProgressDialog.cpp.

1602 {
1603  int after;
1604  bool should;
1605  wxString name;
1606 
1607  gPrefs->Read(wxT("/GUI/BeepOnCompletion"), &should, false);
1608  gPrefs->Read(wxT("/GUI/BeepAfterDuration"), &after, 60);
1609  gPrefs->Read(wxT("/GUI/BeepFileName"), &name, wxEmptyString);
1610 
1611  if (should && wxGetUTCTimeMillis().GetValue() - mStartTime > after * 1000)
1612  {
1613  wxBusyCursor busy;
1614  wxSound s;
1615 
1616  if (name.empty())
1617  {
1618  s.Create(sizeof(beep), beep);
1619  }
1620  else
1621  {
1622  s.Create(name);
1623  }
1624 
1625  if (s.IsOk())
1626  {
1627  s.Play(wxSOUND_SYNC);
1628  }
1629  }
1630 }

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

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 1634 of file ProgressDialog.cpp.

1636  {
1637 
1638  // Check if confirmations are enabled?
1639  // If not then return TRUE
1640  if (m_bConfirmAction == false) {
1641  return true;
1642  }
1643 
1644  AudacityMessageDialog dlgMessage(
1645  this,
1646  sPrompt,
1647  sTitle,
1648  wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT | wxSTAY_ON_TOP );
1649  int iAction = dlgMessage.ShowModal();
1650 
1651  bool bReturn = (iAction == wxID_YES);
1652  if ((bReturn == false) && (iButtonID > -1)) {
1653  // Set the focus back to the relevant button
1654  FindWindowById(iButtonID, this)->SetFocus();
1655  }
1656 
1657  return bReturn;
1658 }

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 1153 of file ProgressDialog.cpp.

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

References _, AddMessageAsColumn(), wxDialogWrapper::Create(), anonymous_namespace{wxWidgetsBasicUI.cpp}::GetParent(), Init(), m_bConfirmAction, m_bShowElapsedTime, mDisable, mElapsed, mGauge, mHadFocus, mRemaining, pdlgConfirmStopCancel, pdlgHideCancelButton, pdlgHideElapsedTime, pdlgHideStopButton, Reinit(), safenew, wxDialogWrapper::SetName(), title, 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 1134 of file ProgressDialog.cpp.

1138 {
1139  MessageTable columns(1);
1140  columns.back().push_back(message);
1141  auto result = Create(title, columns, flags, sRemainingLabelText);
1142 
1143  if (result) {
1144  // Record some values used in case of change of message
1145  // TODO: make the following work in case of message tables
1146  wxClientDC dc(this);
1147  dc.GetMultiLineTextExtent(message.Translation(), &mLastW, &mLastH);
1148  }
1149 
1150  return result;
1151 }

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

Referenced by 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 1052 of file ProgressDialog.cpp.

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

References anonymous_namespace{wxWidgetsBasicUI.cpp}::GetParent(), and mHadFocus.

Referenced by Create().

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

◆ OnCancel()

void ProgressDialog::OnCancel ( wxCommandEvent &  e)
private

Definition at line 1569 of file ProgressDialog.cpp.

1570 {
1571  if (!ConfirmAction(
1572  XO("Are you sure you wish to cancel?"),
1573  XO("Confirm Cancel"), wxID_CANCEL)) {
1574  return;
1575  }
1576  FindWindowById(wxID_CANCEL, this)->Disable();
1577  mCancel = true;
1578 }

References ConfirmAction(), mCancel, and XO.

Here is the call graph for this function:

◆ OnCloseWindow()

void ProgressDialog::OnCloseWindow ( wxCloseEvent &  e)
private

Definition at line 1592 of file ProgressDialog.cpp.

1593 {
1594  if (!ConfirmAction(
1595  XO("Are you sure you wish to close?"), XO("Confirm Close"))) {
1596  return;
1597  }
1598  mCancel = true;
1599 }

References ConfirmAction(), mCancel, and XO.

Here is the call graph for this function:

◆ OnStop()

void ProgressDialog::OnStop ( wxCommandEvent &  e)
private

Definition at line 1580 of file ProgressDialog.cpp.

1581 {
1582  if (!ConfirmAction(
1583  XO("Are you sure you wish to stop?"),
1584  XO("Confirm Stop"), wxID_OK)) {
1585  return;
1586  }
1587  FindWindowById(wxID_OK, this)->Disable();
1588  mCancel = false;
1589  mStop = true;
1590 }

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

Here is the call graph for this function:

◆ Reinit()

void ProgressDialog::Reinit ( )

Definition at line 1073 of file ProgressDialog.cpp.

1074 {
1075  mLastValue = 0;
1076 
1077  mStartTime = wxGetUTCTimeMillis().GetValue();
1080  mCancel = false;
1081  mStop = false;
1082 
1083  // Because wxGTK is very sensitive about maintaining focus when
1084  // this window is not shown, we always show it. But, since we
1085  // want a 500ms delay before it's actually visible for those
1086  // quick tasks, we show it as transparent. If the initial
1087  // delay is exceeded, then we reset the dialog to full opacity.
1088  SetTransparent(0);
1089  mIsTransparent = true;
1090 
1091  auto button = FindWindowById(wxID_CANCEL, this);
1092  if (button)
1093  button->Enable();
1094  button = FindWindowById(wxID_OK, this);
1095  if (button)
1096  button->Enable();
1097 
1098  wxDialogWrapper::Show(true);
1099 }

References mCancel, mIsTransparent, mLastUpdate, mLastValue, mStartTime, mStop, and mYieldTimer.

Referenced by Create(), and ExportPlugin::InitProgress().

Here is the caller graph for this function:

◆ SearchForWindow()

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

Definition at line 1556 of file ProgressDialog.cpp.

1557 {
1558  for (auto win : list)
1559  {
1560  if (win == searchfor || SearchForWindow(win->GetChildren(), searchfor))
1561  {
1562  return true;
1563  }
1564  }
1565 
1566  return false;
1567 }

Referenced by ~ProgressDialog().

Here is the caller graph for this function:

◆ SetMessage()

void ProgressDialog::SetMessage ( const TranslatableString message)

Definition at line 1510 of file ProgressDialog.cpp.

1511 {
1512  if (!message.empty())
1513  {
1514  mMessage->SetLabel(message.Translation());
1515 
1516  int w, h;
1517  wxClientDC dc(mMessage);
1518  dc.GetMultiLineTextExtent(message.Translation(), &w, &h);
1519 
1520  bool sizeUpdated = false;
1521  wxSize ds = GetClientSize();
1522 
1523  // TODO: make the following work in case of message tables
1524  if (w > mLastW)
1525  {
1526  ds.x += (w - mLastW);
1527  sizeUpdated = true;
1528  mLastW = w;
1529  }
1530 
1531  if (h > mLastH)
1532  {
1533  ds.y += (h - mLastH);
1534  sizeUpdated = true;
1535  mLastH = h;
1536  }
1537 
1538  if (sizeUpdated)
1539  {
1540 #if defined(__WXMAC__)
1541  wxSize sz = mMessage->GetSize();
1542  mMessage->SetMinSize(wxSize(wxMax(sz.x, mLastW), wxMax(sz.y, mLastH)));
1543 #endif
1544  // No need to adjust for the margin here since we only add
1545  // to the existing dimensions.
1546  ds.x = wxMax(wxMax(ds.x, mLastW), wxMax(ds.y, mLastH));
1547  SetClientSize(ds);
1548  wxDialogWrapper::Update();
1549  }
1550  }
1551 }

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

Referenced by ExportPlugin::InitProgress(), EffectStereoToMono::Process(), and 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 1421 of file ProgressDialog.cpp.

1423 {
1424  return Update((int)(current * 1000), message);
1425 }

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 1494 of file ProgressDialog.cpp.

1496 {
1497  if (total != 0)
1498  {
1499  return Update((int)(current * 1000.0 / total), message);
1500  }
1501  else
1502  {
1503  return Update(1000, message);
1504  }
1505 }

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 1478 of file ProgressDialog.cpp.

1480 {
1481  if (total != 0)
1482  {
1483  return Update((int)(current * ((double)(1000.0 / total))), message);
1484  }
1485  else
1486  {
1487  return Update(1000, message);
1488  }
1489 }

References Update().

Here is the call graph for this function:

◆ Update() [4/7]

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

Definition at line 1327 of file ProgressDialog.cpp.

1329 {
1330  if (mCancel)
1331  {
1332  // for compatibility with old Update, that returned false on cancel
1334  }
1335  else if (mStop)
1336  {
1337  return ProgressResult::Stopped;
1338  }
1339 
1340  wxLongLong_t now = wxGetUTCTimeMillis().GetValue();
1341  wxLongLong_t elapsed = now - mStartTime;
1342 
1343  if (elapsed < 500)
1344  {
1345  return ProgressResult::Success;
1346  }
1347 
1348  if (mIsTransparent)
1349  {
1350  SetTransparent(255);
1351  mIsTransparent = false;
1352  }
1353 
1354  if (value <= 0)
1355  {
1356  value = 1;
1357  }
1358 
1359  if (value > 1000)
1360  {
1361  value = 1000;
1362  }
1363 
1364  wxLongLong_t estimate = elapsed * 1000ll / value;
1365  wxLongLong_t remains = (estimate + mStartTime) - now;
1366 
1367  SetMessage(message);
1368 
1369  if (value != mLastValue)
1370  {
1371  mGauge->SetValue(value);
1372  mGauge->Update();
1373  mLastValue = value;
1374  }
1375 
1376  // Only update if a full second has passed or track progress is complete
1377  if ((now - mLastUpdate > 1000) || (value == 1000))
1378  {
1379  if (m_bShowElapsedTime) {
1380  wxTimeSpan tsElapsed(0, 0, 0, elapsed);
1381  mElapsed->SetLabel(tsElapsed.Format(wxT("%H:%M:%S")));
1382  mElapsed->SetName(mElapsed->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1383  mElapsed->Update();
1384  }
1385 
1386  wxTimeSpan tsRemains(0, 0, 0, remains);
1387  mRemaining->SetLabel(tsRemains.Format(wxT("%H:%M:%S")));
1388  mRemaining->SetName(mRemaining->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1389  mRemaining->Update();
1390 
1391  mLastUpdate = now;
1392  }
1393 
1394  wxDialogWrapper::Update();
1395 
1396  // Copied from wx 3.0.2 generic progress dialog
1397  //
1398  // we have to yield because not only we want to update the display but
1399  // also to process the clicks on the cancel and skip buttons
1400  // NOTE: using YieldFor() this call shouldn't give re-entrancy problems
1401  // for event handlers not interested to UI/user-input events.
1402  //
1403  // LL: Added timer category to prevent extreme delays when processing effects
1404  // (and probably other things). I do not yet know why this happens and
1405  // I'm not too keen on having timer events processed here, but you do
1406  // what you have to do.
1407 
1408  // Nyquist effects call Update on every callback, but YieldFor is
1409  // quite slow on Linux / Mac, so don't call too frequently. (bug 1575)
1410  if ((now - mYieldTimer > 50) || (value == 1000)) {
1411  wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI | wxEVT_CATEGORY_USER_INPUT | wxEVT_CATEGORY_TIMER);
1412  mYieldTimer = now;
1413  }
1414 
1415  return ProgressResult::Success;
1416 }

References RefreshCode::Cancelled, m_bShowElapsedTime, mCancel, mElapsed, mGauge, mIsTransparent, mLastUpdate, mLastValue, mRemaining, mStartTime, mStop, mYieldTimer, SetMessage(), and BasicUI::Success.

Referenced by ProjectFileIO::CopyTo(), ImportRaw(), MixAndRender(), anonymous_namespace{TransportMenus.cpp}::PlayCurrentRegionAndWait(), anonymous_namespace{TransportMenus.cpp}::PlayPlayRegionAndWait(), Effect::Preview(), anonymous_namespace{TransportMenus.cpp}::RecordAndWait(), RemoveDependencies(), WaveClip::Resample(), Effect::TotalProgress(), Effect::TrackGroupProgress(), Effect::TrackProgress(), 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 1446 of file ProgressDialog.cpp.

1448 {
1449  if (total.GetValue() != 0)
1450  {
1451  return Update((int)(current.GetValue() * 1000ll / total.GetValue()), message);
1452  }
1453  else
1454  {
1455  return Update(1000, message);
1456  }
1457 }

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 1462 of file ProgressDialog.cpp.

1464 {
1465  if (total != 0)
1466  {
1467  return Update((int)(current * 1000ll / total), message);
1468  }
1469  else
1470  {
1471  return Update(1000, message);
1472  }
1473 }

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 1430 of file ProgressDialog.cpp.

1432 {
1433  if (total != 0)
1434  {
1435  return Update((int)(current * 1000 / total), message);
1436  }
1437  else
1438  {
1439  return Update(1000, message);
1440  }
1441 }

References Update().

Here is the call graph for this function:

Member Data Documentation

◆ m_bConfirmAction

bool ProgressDialog::m_bConfirmAction = false
protected

Definition at line 121 of file ProgressDialog.h.

Referenced by ConfirmAction(), and Create().

◆ m_bShowElapsedTime

bool ProgressDialog::m_bShowElapsedTime = true
protected

Definition at line 120 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 142 of file ProgressDialog.h.

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

◆ mElapsed

wxStaticText* ProgressDialog::mElapsed
protected

Definition at line 105 of file ProgressDialog.h.

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

◆ mGauge

wxGauge* ProgressDialog::mGauge
protected

Definition at line 107 of file ProgressDialog.h.

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

◆ mHadFocus

wxWindowRef ProgressDialog::mHadFocus
protected

Definition at line 103 of file ProgressDialog.h.

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

◆ mIsTransparent

bool ProgressDialog::mIsTransparent
protected

Definition at line 117 of file ProgressDialog.h.

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

◆ mLastH

int ProgressDialog::mLastH { 0 }
private

Definition at line 146 of file ProgressDialog.h.

Referenced by Create(), and SetMessage().

◆ mLastUpdate

wxLongLong_t ProgressDialog::mLastUpdate
protected

Definition at line 110 of file ProgressDialog.h.

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

◆ mLastValue

int ProgressDialog::mLastValue
protected

Definition at line 112 of file ProgressDialog.h.

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

◆ mLastW

int ProgressDialog::mLastW { 0 }
private

Definition at line 145 of file ProgressDialog.h.

Referenced by Create(), and SetMessage().

◆ mLoop

wxEventLoopGuarantor ProgressDialog::mLoop
private

Definition at line 140 of file ProgressDialog.h.

◆ mMessage

wxStaticText* ProgressDialog::mMessage {}
private

Definition at line 144 of file ProgressDialog.h.

Referenced by AddMessageAsColumn(), and SetMessage().

◆ mRemaining

wxStaticText* ProgressDialog::mRemaining
protected

Definition at line 106 of file ProgressDialog.h.

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

◆ mStartTime

wxLongLong_t ProgressDialog::mStartTime
protected

Definition at line 109 of file ProgressDialog.h.

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

◆ mStop

bool ProgressDialog::mStop
protected

Definition at line 115 of file ProgressDialog.h.

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

◆ mYieldTimer

wxLongLong_t ProgressDialog::mYieldTimer
protected

Definition at line 111 of file ProgressDialog.h.

Referenced by Reinit(), and Update().


The documentation for this class was generated from the following files:
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
TranslatableString::empty
bool empty() const
Definition: TranslatableString.h:72
wxDialogWrapper::Create
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"))
Definition: wxPanelWrapper.h:100
BasicUI::ProgressResult::Success
@ Success
gPrefs
FileConfig * gPrefs
Definition: Prefs.cpp:70
ProgressDialog::mStartTime
wxLongLong_t mStartTime
Definition: ProgressDialog.h:109
pdlgHideStopButton
@ pdlgHideStopButton
Definition: ProgressDialog.h:38
ProgressDialog::mElapsed
wxStaticText * mElapsed
Definition: ProgressDialog.h:105
ProgressDialog::mRemaining
wxStaticText * mRemaining
Definition: ProgressDialog.h:106
ProgressDialog::Init
void Init()
Definition: ProgressDialog.cpp:1052
RefreshCode::Cancelled
@ Cancelled
Definition: RefreshCode.h:23
XO
#define XO(s)
Definition: Internat.h:31
ProgressDialog::m_bShowElapsedTime
bool m_bShowElapsedTime
Definition: ProgressDialog.h:120
ProgressDialog::SearchForWindow
bool SearchForWindow(const wxWindowList &list, const wxWindow *searchfor) const
Definition: ProgressDialog.cpp:1556
ProgressDialog::mLastValue
int mLastValue
Definition: ProgressDialog.h:112
AudacityMessageDialog
Wrap wxMessageDialog so that caption IS translatable.
Definition: wxPanelWrapper.h:215
ProgressDialog::mHadFocus
wxWindowRef mHadFocus
Definition: ProgressDialog.h:103
ProgressDialog::SetMessage
void SetMessage(const TranslatableString &message)
Definition: ProgressDialog.cpp:1510
ProgressDialog::mCancel
bool mCancel
Definition: ProgressDialog.h:114
pdlgHideElapsedTime
@ pdlgHideElapsedTime
Definition: ProgressDialog.h:40
ProgressDialog::mMessage
wxStaticText * mMessage
Definition: ProgressDialog.h:144
ProgressDialog::mStop
bool mStop
Definition: ProgressDialog.h:115
ProgressDialog::m_bConfirmAction
bool m_bConfirmAction
Definition: ProgressDialog.h:121
ProgressDialog::MessageTable
std::vector< MessageColumn > MessageTable
Definition: ProgressDialog.h:62
name
const TranslatableString name
Definition: Distortion.cpp:98
pdlgConfirmStopCancel
@ pdlgConfirmStopCancel
Definition: ProgressDialog.h:41
ProgressDialog::Update
ProgressResult Update(int value, const TranslatableString &message={})
Definition: ProgressDialog.cpp:1327
ProgressDialog::mYieldTimer
wxLongLong_t mYieldTimer
Definition: ProgressDialog.h:111
beep
static const unsigned char beep[]
Definition: ProgressDialog.cpp:56
ProgressDialog::mLastUpdate
wxLongLong_t mLastUpdate
Definition: ProgressDialog.h:110
title
static const auto title
Definition: UpdateNoticeDialog.cpp:23
ProgressDialog::ConfirmAction
bool ConfirmAction(const TranslatableString &sPrompt, const TranslatableString &sTitle, int iButtonID=-1)
Definition: ProgressDialog.cpp:1634
ProgressDialog::mIsTransparent
bool mIsTransparent
Definition: ProgressDialog.h:117
ProgressDialog::mLastW
int mLastW
Definition: ProgressDialog.h:145
ProgressDialog::mDisable
std::unique_ptr< wxWindowDisabler > mDisable
Definition: ProgressDialog.h:142
_
#define _(s)
Definition: Internat.h:75
ProgressDialog::mGauge
wxGauge * mGauge
Definition: ProgressDialog.h:107
ProgressDialog::Create
bool Create(const TranslatableString &title, const TranslatableString &message={}, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
Definition: ProgressDialog.cpp:1134
wxDialogWrapper::wxDialogWrapper
wxDialogWrapper()
Definition: wxPanelWrapper.h:84
ProgressDialog::mLastH
int mLastH
Definition: ProgressDialog.h:146
ProgressDialog::Beep
void Beep() const
Definition: ProgressDialog.cpp:1601
TranslatableString::Translation
wxString Translation() const
Definition: TranslatableString.h:79
wxDialogWrapper::SetName
void SetName()
Definition: wxPanelWrapper.cpp:81
ProgressDialog::Reinit
void Reinit()
Definition: ProgressDialog.cpp:1073
anonymous_namespace{wxWidgetsBasicUI.cpp}::GetParent
wxWindow * GetParent(const BasicUI::WindowPlacement &placement)
Definition: wxWidgetsBasicUI.cpp:39
safenew
#define safenew
Definition: MemoryX.h:10
pdlgHideCancelButton
@ pdlgHideCancelButton
Definition: ProgressDialog.h:39
ProgressDialog::AddMessageAsColumn
void AddMessageAsColumn(wxBoxSizer *pSizer, const MessageColumn &column, bool bFirstColumn)
Definition: ProgressDialog.cpp:1102