Audacity  2.2.2
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:
wxDialogWrapper wxTabTraversalWrapper< wxDialog > TimerProgressDialog

Public Types

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

Public Member Functions

 ProgressDialog ()
 Methods for ProgressDialog. More...
 
 ProgressDialog (const wxString &title, const wxString &message=wxEmptyString, int flags=pdlgDefaultFlags, const wxString &sRemainingLabelText=wxEmptyString)
 
virtual ~ProgressDialog ()
 
bool Create (const wxString &title, const wxString &message=wxEmptyString, int flags=pdlgDefaultFlags, const wxString &sRemainingLabelText=wxEmptyString)
 
void Reinit ()
 
ProgressResult Update (int value, const wxString &message=wxEmptyString)
 
ProgressResult Update (double current, const wxString &message=wxEmptyString)
 
ProgressResult Update (double current, double total, const wxString &message=wxEmptyString)
 
ProgressResult Update (wxULongLong_t current, wxULongLong_t total, const wxString &message=wxEmptyString)
 
ProgressResult Update (wxLongLong current, wxLongLong total, const wxString &message=wxEmptyString)
 
ProgressResult Update (wxLongLong_t current, wxLongLong_t total, const wxString &message=wxEmptyString)
 
ProgressResult Update (int current, int total, const wxString &message=wxEmptyString)
 
void SetMessage (const wxString &message)
 
- Public Member Functions inherited from wxDialogWrapper
 wxDialogWrapper ()
 
 wxDialogWrapper (wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const wxString &name=_("Dialog"))
 
bool Create (wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const wxString &name=_("Dialog"))
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxDialog >
 wxTabTraversalWrapper (Args &&...args)
 

Protected Member Functions

 ProgressDialog (const wxString &title, const MessageTable &columns, int flags=pdlgDefaultFlags, const wxString &sRemainingLabelText=wxEmptyString)
 
bool Create (const wxString &title, const MessageTable &columns, int flags=pdlgDefaultFlags, const wxString &sRemainingLabelText=wxEmptyString)
 

Protected Attributes

wxWeakRef< wxWindow > 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 wxString &sPrompt, const wxString &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 56 of file ProgressDialog.h.

Member Typedef Documentation

using ProgressDialog::MessageColumn = std::vector< wxString >

Definition at line 67 of file ProgressDialog.h.

Definition at line 68 of file ProgressDialog.h.

Constructor & Destructor Documentation

ProgressDialog::ProgressDialog ( )

Methods for ProgressDialog.

Definition at line 997 of file ProgressDialog.cpp.

998 : wxDialogWrapper()
999 {
1000 }
ProgressDialog::ProgressDialog ( const wxString &  title,
const wxString &  message = wxEmptyString,
int  flags = pdlgDefaultFlags,
const wxString &  sRemainingLabelText = wxEmptyString 
)

Definition at line 1002 of file ProgressDialog.cpp.

References Create().

1006 : wxDialogWrapper()
1007 {
1008  Create(title, message, flags, sRemainingLabelText);
1009 }
bool Create(const wxString &title, const wxString &message=wxEmptyString, int flags=pdlgDefaultFlags, const wxString &sRemainingLabelText=wxEmptyString)
ProgressDialog::ProgressDialog ( const wxString &  title,
const MessageTable columns,
int  flags = pdlgDefaultFlags,
const wxString &  sRemainingLabelText = wxEmptyString 
)
protected

Definition at line 1011 of file ProgressDialog.cpp.

References Create().

1015 : wxDialogWrapper()
1016 {
1017  Create(title, columns, flags, sRemainingLabelText);
1018 }
bool Create(const wxString &title, const wxString &message=wxEmptyString, int flags=pdlgDefaultFlags, const wxString &sRemainingLabelText=wxEmptyString)
ProgressDialog::~ProgressDialog ( )
virtual

Definition at line 1023 of file ProgressDialog.cpp.

References Beep(), mDisable, mHadFocus, and SearchForWindow().

1024 {
1025  // Delete the window disabler before hiding the dialog to allow
1026  // focus to return to the original window.
1027  mDisable.reset();
1028 
1029  if (IsShown())
1030  {
1031  Show(false);
1032 
1033  Beep();
1034  }
1035 
1036 #if defined(__WXGTK__)
1037  // Under GTK, when applying any effect that prompts the user, it's more than
1038  // like that FindFocus() will return NULL. So, make sure something has focus.
1039  if (GetParent()) {
1040  GetParent()->SetFocus();
1041  }
1042 #endif
1043 
1044  // Restore saved focus, but only if the window still exists.
1045  //
1046  // It is possible that it was a deferred deletion and it was deleted since
1047  // we captured the focused window. So, we need to verify that the window
1048  // still exists by searching all of the wxWidgets windows. It's the only
1049  // sure way.
1050  if (mHadFocus && SearchForWindow(wxTopLevelWindows, mHadFocus)) {
1051  mHadFocus->SetFocus();
1052  }
1053 }
void Beep() const
wxWeakRef< wxWindow > mHadFocus
std::unique_ptr< wxWindowDisabler > mDisable
bool SearchForWindow(const wxWindowList &list, const wxWindow *searchfor) const

Member Function Documentation

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

Definition at line 1105 of file ProgressDialog.cpp.

References mMessage, and safenew.

Referenced by Create().

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

Definition at line 1581 of file ProgressDialog.cpp.

References beep, gPrefs, mStartTime, and name.

Referenced by ~ProgressDialog().

1582 {
1583  int after;
1584  bool should;
1585  wxString name;
1586 
1587  gPrefs->Read(wxT("/GUI/BeepOnCompletion"), &should, false);
1588  gPrefs->Read(wxT("/GUI/BeepAfterDuration"), &after, 60);
1589  gPrefs->Read(wxT("/GUI/BeepFileName"), &name, wxEmptyString);
1590 
1591  if (should && wxGetLocalTimeMillis().GetValue() - mStartTime > after * 1000)
1592  {
1593  wxBusyCursor busy;
1594  wxSound s;
1595 
1596  if (name.IsEmpty())
1597  {
1598  s.Create(sizeof(beep), beep);
1599  }
1600  else
1601  {
1602  s.Create(name);
1603  }
1604 
1605  if (s.IsOk())
1606  {
1607  s.Play(wxSOUND_SYNC);
1608  }
1609  }
1610 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
wxLongLong_t mStartTime
const wxChar * name
Definition: Distortion.cpp:94
static const unsigned char beep[]
bool ProgressDialog::ConfirmAction ( const wxString &  sPrompt,
const wxString &  sTitle,
int  iButtonID = -1 
)
private

Definition at line 1614 of file ProgressDialog.cpp.

References m_bConfirmAction.

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

1616  {
1617 
1618  // Check if confirmations are enabled?
1619  // If not then return TRUE
1620  if (m_bConfirmAction == false) {
1621  return true;
1622  }
1623 
1624  AudacityMessageDialog dlgMessage(this,
1625  sPrompt,
1626  sTitle,
1627  wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT | wxSTAY_ON_TOP);
1628  int iAction = dlgMessage.ShowModal();
1629 
1630  bool bReturn = (iAction == wxID_YES);
1631  if ((bReturn == false) && (iButtonID > -1)) {
1632  // Set the focus back to the relevant button
1633  FindWindowById(iButtonID, this)->SetFocus();
1634  }
1635 
1636  return bReturn;
1637 }
Wrap wxMessageDialog so that caption IS translatable.
Definition: ErrorDialog.h:129
bool ProgressDialog::Create ( const wxString &  title,
const wxString &  message = wxEmptyString,
int  flags = pdlgDefaultFlags,
const wxString &  sRemainingLabelText = wxEmptyString 
)

Definition at line 1136 of file ProgressDialog.cpp.

References mLastH, and mLastW.

Referenced by ProgressDialog().

1140 {
1141  MessageTable columns(1);
1142  columns.back().push_back(message);
1143  auto result = Create(title, columns, flags, sRemainingLabelText);
1144 
1145  if (result) {
1146  // Record some values used in case of change of message
1147  // TODO: make the following work in case of message tables
1148  wxClientDC dc(this);
1149  dc.GetMultiLineTextExtent(message, &mLastW, &mLastH);
1150  }
1151 
1152  return result;
1153 }
bool Create(const wxString &title, const wxString &message=wxEmptyString, int flags=pdlgDefaultFlags, const wxString &sRemainingLabelText=wxEmptyString)
std::vector< MessageColumn > MessageTable
bool ProgressDialog::Create ( const wxString &  title,
const MessageTable columns,
int  flags = pdlgDefaultFlags,
const wxString &  sRemainingLabelText = wxEmptyString 
)
protected

Definition at line 1155 of file ProgressDialog.cpp.

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

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

Definition at line 1055 of file ProgressDialog.cpp.

References mHadFocus.

Referenced by Create().

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

Definition at line 1554 of file ProgressDialog.cpp.

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

1555 {
1556  if (!ConfirmAction(_("Are you sure you wish to cancel?"), _("Confirm Cancel"), wxID_CANCEL)) {
1557  return;
1558  }
1559  FindWindowById(wxID_CANCEL, this)->Disable();
1560  mCancel = true;
1561 }
bool ConfirmAction(const wxString &sPrompt, const wxString &sTitle, int iButtonID=-1)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void ProgressDialog::OnCloseWindow ( wxCloseEvent &  e)
private

Definition at line 1573 of file ProgressDialog.cpp.

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

1574 {
1575  if (!ConfirmAction(_("Are you sure you wish to close?"), _("Confirm Close"))) {
1576  return;
1577  }
1578  mCancel = true;
1579 }
bool ConfirmAction(const wxString &sPrompt, const wxString &sTitle, int iButtonID=-1)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void ProgressDialog::OnStop ( wxCommandEvent &  e)
private

Definition at line 1563 of file ProgressDialog.cpp.

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

1564 {
1565  if (!ConfirmAction(_("Are you sure you wish to stop?"), _("Confirm Stop"), wxID_OK)) {
1566  return;
1567  }
1568  FindWindowById(wxID_OK, this)->Disable();
1569  mCancel = false;
1570  mStop = true;
1571 }
bool ConfirmAction(const wxString &sPrompt, const wxString &sTitle, int iButtonID=-1)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void ProgressDialog::Reinit ( )

Definition at line 1076 of file ProgressDialog.cpp.

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

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

1077 {
1078  mLastValue = 0;
1079 
1080  mStartTime = wxGetLocalTimeMillis().GetValue();
1083  mCancel = false;
1084  mStop = false;
1085 
1086  // Because wxGTK is very sensitive about maintaining focus when
1087  // this window is not shown, we always show it. But, since we
1088  // want a 500ms delay before it's actually visible for those
1089  // quick tasks, we show it as transparent. If the initial
1090  // delay is exceeded, then we reset the dialog to full opacity.
1091  SetTransparent(0);
1092  mIsTransparent = true;
1093 
1094  auto button = FindWindowById(wxID_CANCEL, this);
1095  if (button)
1096  button->Enable();
1097  button = FindWindowById(wxID_OK, this);
1098  if (button)
1099  button->Enable();
1100 
1101  wxDialogWrapper::Show(true);
1102 }
wxLongLong_t mYieldTimer
wxLongLong_t mStartTime
wxLongLong_t mLastUpdate
bool ProgressDialog::SearchForWindow ( const wxWindowList &  list,
const wxWindow *  searchfor 
) const
private

Definition at line 1541 of file ProgressDialog.cpp.

Referenced by ~ProgressDialog().

1542 {
1543  for (auto win : list)
1544  {
1545  if (win == searchfor || SearchForWindow(win->GetChildren(), searchfor))
1546  {
1547  return true;
1548  }
1549  }
1550 
1551  return false;
1552 }
bool SearchForWindow(const wxWindowList &list, const wxWindow *searchfor) const
void ProgressDialog::SetMessage ( const wxString &  message)

Definition at line 1495 of file ProgressDialog.cpp.

References mLastH, mLastW, and mMessage.

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

1496 {
1497  if (!message.IsEmpty())
1498  {
1499  mMessage->SetLabel(message);
1500 
1501  int w, h;
1502  wxClientDC dc(mMessage);
1503  dc.GetMultiLineTextExtent(message, &w, &h);
1504 
1505  bool sizeUpdated = false;
1506  wxSize ds = GetClientSize();
1507 
1508  // TODO: make the following work in case of message tables
1509  if (w > mLastW)
1510  {
1511  ds.x += (w - mLastW);
1512  sizeUpdated = true;
1513  mLastW = w;
1514  }
1515 
1516  if (h > mLastH)
1517  {
1518  ds.y += (h - mLastH);
1519  sizeUpdated = true;
1520  mLastH = h;
1521  }
1522 
1523  if (sizeUpdated)
1524  {
1525 #if defined(__WXMAC__)
1526  wxSize sz = mMessage->GetSize();
1527  mMessage->SetMinSize(wxSize(wxMax(sz.x, mLastW), wxMax(sz.y, mLastH)));
1528 #endif
1529  // No need to adjust for the margin here since we only add
1530  // to the existing dimensions.
1531  ds.x = wxMax(wxMax(ds.x, mLastW), wxMax(ds.y, mLastH));
1532  SetClientSize(ds);
1533  wxDialogWrapper::Update();
1534  }
1535  }
1536 }
wxStaticText * mMessage
ProgressResult ProgressDialog::Update ( int  value,
const wxString &  message = wxEmptyString 
)

Definition at line 1319 of file ProgressDialog.cpp.

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

Referenced by EffectNormalize::AnalyseTrack(), DirManager::FillBlockfilesCache(), PCMImportFileHandle::Import(), ImportRaw(), MixAndRender(), PluginRegistrationDialog::OnOK(), Effect::Preview(), RemoveDependencies(), WaveClip::Resample(), DirManager::SetProject(), Effect::TotalProgress(), Effect::TrackGroupProgress(), Effect::TrackProgress(), Update(), GUIProgressTarget::Update(), and DirManager::WriteCacheToDisk().

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

Definition at line 1412 of file ProgressDialog.cpp.

References Update().

1413 {
1414  return Update((int)(current * 1000), message);
1415 }
ProgressResult Update(int value, const wxString &message=wxEmptyString)
ProgressResult ProgressDialog::Update ( double  current,
double  total,
const wxString &  message = wxEmptyString 
)

Definition at line 1480 of file ProgressDialog.cpp.

References Update().

1481 {
1482  if (total != 0)
1483  {
1484  return Update((int)(current * 1000.0 / total), message);
1485  }
1486  else
1487  {
1488  return Update(1000, message);
1489  }
1490 }
ProgressResult Update(int value, const wxString &message=wxEmptyString)
ProgressResult ProgressDialog::Update ( wxULongLong_t  current,
wxULongLong_t  total,
const wxString &  message = wxEmptyString 
)

Definition at line 1420 of file ProgressDialog.cpp.

References Update().

1421 {
1422  if (total != 0)
1423  {
1424  return Update((int)(current * 1000 / total), message);
1425  }
1426  else
1427  {
1428  return Update(1000, message);
1429  }
1430 }
ProgressResult Update(int value, const wxString &message=wxEmptyString)
ProgressResult ProgressDialog::Update ( wxLongLong  current,
wxLongLong  total,
const wxString &  message = wxEmptyString 
)

Definition at line 1435 of file ProgressDialog.cpp.

References Update().

1436 {
1437  if (total.GetValue() != 0)
1438  {
1439  return Update((int)(current.GetValue() * 1000ll / total.GetValue()), message);
1440  }
1441  else
1442  {
1443  return Update(1000, message);
1444  }
1445 }
ProgressResult Update(int value, const wxString &message=wxEmptyString)
ProgressResult ProgressDialog::Update ( wxLongLong_t  current,
wxLongLong_t  total,
const wxString &  message = wxEmptyString 
)

Definition at line 1450 of file ProgressDialog.cpp.

References Update().

1451 {
1452  if (total != 0)
1453  {
1454  return Update((int)(current * 1000ll / total), message);
1455  }
1456  else
1457  {
1458  return Update(1000, message);
1459  }
1460 }
ProgressResult Update(int value, const wxString &message=wxEmptyString)
ProgressResult ProgressDialog::Update ( int  current,
int  total,
const wxString &  message = wxEmptyString 
)

Definition at line 1465 of file ProgressDialog.cpp.

References Update().

1466 {
1467  if (total != 0)
1468  {
1469  return Update((int)(current * ((double)(1000.0 / total))), message);
1470  }
1471  else
1472  {
1473  return Update(1000, message);
1474  }
1475 }
ProgressResult Update(int value, const wxString &message=wxEmptyString)

Member Data Documentation

bool ProgressDialog::m_bConfirmAction = false
protected

Definition at line 126 of file ProgressDialog.h.

Referenced by ConfirmAction(), and Create().

bool ProgressDialog::m_bShowElapsedTime = true
protected

Definition at line 125 of file ProgressDialog.h.

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

bool ProgressDialog::mCancel
protected
std::unique_ptr<wxWindowDisabler> ProgressDialog::mDisable
private

Definition at line 147 of file ProgressDialog.h.

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

wxStaticText* ProgressDialog::mElapsed
protected

Definition at line 110 of file ProgressDialog.h.

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

wxGauge* ProgressDialog::mGauge
protected

Definition at line 112 of file ProgressDialog.h.

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

wxWeakRef<wxWindow> ProgressDialog::mHadFocus
protected

Definition at line 108 of file ProgressDialog.h.

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

bool ProgressDialog::mIsTransparent
protected

Definition at line 122 of file ProgressDialog.h.

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

int ProgressDialog::mLastH { 0 }
private

Definition at line 151 of file ProgressDialog.h.

Referenced by Create(), and SetMessage().

wxLongLong_t ProgressDialog::mLastUpdate
protected

Definition at line 115 of file ProgressDialog.h.

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

int ProgressDialog::mLastValue
protected

Definition at line 117 of file ProgressDialog.h.

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

int ProgressDialog::mLastW { 0 }
private

Definition at line 150 of file ProgressDialog.h.

Referenced by Create(), and SetMessage().

wxEventLoopGuarantor ProgressDialog::mLoop
private

Definition at line 145 of file ProgressDialog.h.

wxStaticText* ProgressDialog::mMessage {}
private

Definition at line 149 of file ProgressDialog.h.

Referenced by AddMessageAsColumn(), and SetMessage().

wxStaticText* ProgressDialog::mRemaining
protected

Definition at line 111 of file ProgressDialog.h.

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

wxLongLong_t ProgressDialog::mStartTime
protected

Definition at line 114 of file ProgressDialog.h.

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

bool ProgressDialog::mStop
protected

Definition at line 120 of file ProgressDialog.h.

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

wxLongLong_t ProgressDialog::mYieldTimer
protected

Definition at line 116 of file ProgressDialog.h.

Referenced by Reinit(), and Update().


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