Audacity  2.2.2
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 #include "../Audacity.h"
22 
23 #include "../MemoryX.h"
24 #include <vector>
25 #include <wx/defs.h>
26 #include <wx/evtloop.h>
27 #include <wx/gauge.h>
28 #include <wx/stattext.h>
29 #include <wx/utils.h>
30 
31 #include "wxPanelWrapper.h"
32 
33 enum class ProgressResult : unsigned
34 {
35  Cancelled = 0, //<! User says that whatever is happening is undesirable and shouldn't have happened at all
36  Success, //<! User says nothing, everything works fine, continue doing whatever we're doing
37  Failed, //<! Something has gone wrong, we should stop and cancel everything we did
38  Stopped //<! Nothing is wrong, but user says we should stop now and leave things as they are now
39 };
40 
42 {
43  pdlgEmptyFlags = 0x00000000,
44  pdlgHideStopButton = 0x00000001,
45  pdlgHideCancelButton = 0x00000002,
46  pdlgHideElapsedTime = 0x00000004,
47  pdlgConfirmStopCancel = 0x00000008,
48 
50 };
51 
55 
56 class AUDACITY_DLL_API ProgressDialog /* not final */ : public wxDialogWrapper
57 {
58 public:
60 
61  // Display a simple message.
62  ProgressDialog(const wxString & title,
63  const wxString & message = wxEmptyString,
64  int flags = pdlgDefaultFlags,
65  const wxString & sRemainingLabelText = wxEmptyString);
66 
67  using MessageColumn = std::vector< wxString >;
68  using MessageTable = std::vector< MessageColumn >;
69 
70 protected:
71  // Display a table of messages.
72  // Each member of the table is a column of messages.
73  // Each member of a column is a string that should have no newlines,
74  // and each column should have the same number of elements, to make
75  // proper correspondences, but this is not checked.
76  ProgressDialog(const wxString & title,
77  const MessageTable & columns,
78  int flags = pdlgDefaultFlags,
79  const wxString & sRemainingLabelText = wxEmptyString);
80 
81 public:
82  virtual ~ProgressDialog();
83 
84  bool Create(const wxString & title,
85  const wxString & message = wxEmptyString,
86  int flags = pdlgDefaultFlags,
87  const wxString & sRemainingLabelText = wxEmptyString);
88 
89  void Reinit();
90 
91 protected:
92  bool Create(const wxString & title,
93  const MessageTable & columns,
94  int flags = pdlgDefaultFlags,
95  const wxString & sRemainingLabelText = wxEmptyString);
96 
97 public:
98  ProgressResult Update(int value, const wxString & message = wxEmptyString);
99  ProgressResult Update(double current, const wxString & message = wxEmptyString);
100  ProgressResult Update(double current, double total, const wxString & message = wxEmptyString);
101  ProgressResult Update(wxULongLong_t current, wxULongLong_t total, const wxString & message = wxEmptyString);
102  ProgressResult Update(wxLongLong current, wxLongLong total, const wxString & message = wxEmptyString);
103  ProgressResult Update(wxLongLong_t current, wxLongLong_t total, const wxString & message = wxEmptyString);
104  ProgressResult Update(int current, int total, const wxString & message = wxEmptyString);
105  void SetMessage(const wxString & message);
106 
107 protected:
108  wxWeakRef<wxWindow> 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 wxString & sPrompt,
137  const wxString & 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 wxString &title,
161  const MessageTable & columns,
162  int flags = pdlgDefaultFlags,
163  const wxString & sRemainingLabelText = wxEmptyString);
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
ProgressResult
wxGauge * mGauge
ProgressDialog Class.
void OnStop(const CommandContext &context)
wxWeakRef< wxWindow > mHadFocus
wxLongLong_t mYieldTimer
std::vector< MessageColumn > MessageTable
wxLongLong_t mDuration
std::unique_ptr< wxWindowDisabler > mDisable
wxEventLoopGuarantor mLoop
wxLongLong_t mStartTime
wxStaticText * mRemaining
ProgressResult Update(int value, const wxString &message=wxEmptyString)
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
ProgressDialogFlags
wxLongLong_t mLastUpdate
std::vector< wxString > MessageColumn