Audacity  3.0.3
ProgressDialog.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ProgressDialog.h
6 
7  Copyright
8  Leland Lucius
9  Vaughan Johnson
10 
11  This program is free software; you can redistribute it and/or modify
12  it under the terms of the GNU General Public License as published by
13  the Free Software Foundation; either version 2 of the License, or
14  (at your option) any later version.
15 
16 *************************************************************************/
17 
18 #ifndef __AUDACITY_WIDGETS_PROGRESSDIALOG__
19 #define __AUDACITY_WIDGETS_PROGRESSDIALOG__
20 
21 
22 
23 #include <vector>
24 #include <wx/defs.h>
25 #include <wx/evtloop.h> // member variable
26 
27 #include "wxPanelWrapper.h" // to inherit
28 
29 class wxGauge;
30 class wxStaticText;
31 
32 enum class ProgressResult : unsigned
33 {
34  Cancelled = 0, //<! User says that whatever is happening is undesirable and shouldn't have happened at all
35  Success, //<! User says nothing, everything works fine, continue doing whatever we're doing
36  Failed, //<! Something has gone wrong, we should stop and cancel everything we did
37  Stopped //<! Nothing is wrong, but user says we should stop now and leave things as they are now
38 };
39 
41 {
42  pdlgEmptyFlags = 0x00000000,
43  pdlgHideStopButton = 0x00000001,
44  pdlgHideCancelButton = 0x00000002,
45  pdlgHideElapsedTime = 0x00000004,
46  pdlgConfirmStopCancel = 0x00000008,
47 
49 };
50 
54 
55 class AUDACITY_DLL_API ProgressDialog /* not final */ : public wxDialogWrapper
56 {
57 public:
59 
60  // Display a simple message.
61  ProgressDialog(const TranslatableString & title,
62  const TranslatableString & message = {},
63  int flags = pdlgDefaultFlags,
64  const TranslatableString & sRemainingLabelText = {});
65 
66  using MessageColumn = std::vector< TranslatableString >;
67  using MessageTable = std::vector< MessageColumn >;
68 
69 protected:
70  // Display a table of messages.
71  // Each member of the table is a column of messages.
72  // Each member of a column is a string that should have no newlines,
73  // and each column should have the same number of elements, to make
74  // proper correspondences, but this is not checked.
75  ProgressDialog(const TranslatableString & title,
76  const MessageTable & columns,
77  int flags = pdlgDefaultFlags,
78  const TranslatableString & sRemainingLabelText = {});
79 
80 public:
81  virtual ~ProgressDialog();
82 
83  bool Create(const TranslatableString & title,
84  const TranslatableString & message = {},
85  int flags = pdlgDefaultFlags,
86  const TranslatableString & sRemainingLabelText = {});
87 
88  void Reinit();
89 
90 protected:
91  bool Create(const TranslatableString & title,
92  const MessageTable & columns,
93  int flags = pdlgDefaultFlags,
94  const TranslatableString & sRemainingLabelText = {});
95 
96 public:
97  ProgressResult Update(int value, const TranslatableString & message = {});
98  ProgressResult Update(double current, const TranslatableString & message = {});
99  ProgressResult Update(double current, double total, const TranslatableString & message = {});
100  ProgressResult Update(wxULongLong_t current, wxULongLong_t total, const TranslatableString & message = {});
101  ProgressResult Update(wxLongLong current, wxLongLong total, const TranslatableString & message = {});
102  ProgressResult Update(wxLongLong_t current, wxLongLong_t total, const TranslatableString & message = {});
103  ProgressResult Update(int current, int total, const TranslatableString & message = {});
104 
105  void SetMessage(const TranslatableString & message);
106 
107 protected:
108  wxWindowRef mHadFocus;
109 
110  wxStaticText *mElapsed;
111  wxStaticText *mRemaining;
112  wxGauge *mGauge;
113 
114  wxLongLong_t mStartTime;
115  wxLongLong_t mLastUpdate;
116  wxLongLong_t mYieldTimer;
117  int mLastValue; // gauge value, range = [0,1000]
118 
119  bool mCancel;
120  bool mStop;
121 
123 
124  // MY: Booleans to hold the flag values
125  bool m_bShowElapsedTime = true;
126  bool m_bConfirmAction = false;
127 
128 private:
129  void Init();
130  bool SearchForWindow(const wxWindowList & list, const wxWindow *searchfor) const;
131  void OnCancel(wxCommandEvent & e);
132  void OnStop(wxCommandEvent & e);
133  void OnCloseWindow(wxCloseEvent & e);
134  void Beep() const;
135 
136  bool ConfirmAction(const TranslatableString & sPrompt,
137  const TranslatableString & sTitle,
138  int iButtonID = -1);
139 
140  void AddMessageAsColumn(wxBoxSizer * pSizer,
141  const MessageColumn &column, bool bFirstColumn);
142 
143 private:
144  // This guarantees we have an active event loop...possible during OnInit()
145  wxEventLoopGuarantor mLoop;
146 
147  std::unique_ptr<wxWindowDisabler> mDisable;
148 
149  wxStaticText *mMessage{} ;
150  int mLastW{ 0 };
151  int mLastH{ 0 };
152 
153  DECLARE_EVENT_TABLE()
154 };
155 
156 class AUDACITY_DLL_API TimerProgressDialog final : public ProgressDialog
157 {
158 public:
159  TimerProgressDialog(const wxLongLong_t duration,
160  const TranslatableString &title,
161  const MessageTable & columns,
162  int flags = pdlgDefaultFlags,
163  const TranslatableString & sRemainingLabelText = {});
164 
165  // Oh no, there is an inherited nullary "Update" in wxDialog!
166  // Choose another name then...
167  ProgressResult UpdateProgress();
168 
169 protected:
170  wxLongLong_t mDuration;
171 
172  // Disallow direct use of the inherited overloads of Update because it
173  // doesn't support changes of message
175 };
176 
177 #endif
TimerProgressDialog::mDuration
wxLongLong_t mDuration
Definition: ProgressDialog.h:170
TranslatableString
Definition: Types.h:290
ProgressDialog::MessageColumn
std::vector< TranslatableString > MessageColumn
Definition: ProgressDialog.h:66
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
ProgressDialog::mStartTime
wxLongLong_t mStartTime
Definition: ProgressDialog.h:114
pdlgHideStopButton
@ pdlgHideStopButton
Definition: ProgressDialog.h:43
ProgressDialog::mElapsed
wxStaticText * mElapsed
Definition: ProgressDialog.h:110
ProgressDialog::mRemaining
wxStaticText * mRemaining
Definition: ProgressDialog.h:111
ProgressResult::Cancelled
@ Cancelled
wxPanelWrapper.h
ProgressDialog::mLastValue
int mLastValue
Definition: ProgressDialog.h:117
ProgressDialog::mHadFocus
wxWindowRef mHadFocus
Definition: ProgressDialog.h:108
ProgressDialog::mCancel
bool mCancel
Definition: ProgressDialog.h:119
pdlgHideElapsedTime
@ pdlgHideElapsedTime
Definition: ProgressDialog.h:45
ProgressResult::Failed
@ Failed
ProgressDialog
ProgressDialog Class.
Definition: ProgressDialog.h:56
ProgressResult
ProgressResult
Definition: ProgressDialog.h:33
ProgressResult::Success
@ Success
ProgressDialog::mStop
bool mStop
Definition: ProgressDialog.h:120
TimerProgressDialog
Definition: ProgressDialog.h:157
pdlgDefaultFlags
@ pdlgDefaultFlags
Definition: ProgressDialog.h:48
ProgressDialog::MessageTable
std::vector< MessageColumn > MessageTable
Definition: ProgressDialog.h:67
pdlgConfirmStopCancel
@ pdlgConfirmStopCancel
Definition: ProgressDialog.h:46
ProgressResult::Stopped
@ Stopped
ProgressDialog::Update
ProgressResult Update(int value, const TranslatableString &message={})
Definition: ProgressDialog.cpp:1327
ProgressDialog::mYieldTimer
wxLongLong_t mYieldTimer
Definition: ProgressDialog.h:116
ProgressDialog::mLastUpdate
wxLongLong_t mLastUpdate
Definition: ProgressDialog.h:115
ProgressDialog::mIsTransparent
bool mIsTransparent
Definition: ProgressDialog.h:122
ProgressDialogFlags
ProgressDialogFlags
Definition: ProgressDialog.h:41
ProgressDialog::mDisable
std::unique_ptr< wxWindowDisabler > mDisable
Definition: ProgressDialog.h:147
wxDialogWrapper
Definition: wxPanelWrapper.h:81
ProgressDialog::mLoop
wxEventLoopGuarantor mLoop
Definition: ProgressDialog.h:145
ProgressDialog::mGauge
wxGauge * mGauge
Definition: ProgressDialog.h:112
pdlgEmptyFlags
@ pdlgEmptyFlags
Definition: ProgressDialog.h:42
pdlgHideCancelButton
@ pdlgHideCancelButton
Definition: ProgressDialog.h:44