Audacity 3.2.0
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#include "BasicUI.h" // For ProgressResult
31
32class wxGauge;
33class wxStaticText;
34
36{
37 pdlgEmptyFlags = 0x00000000,
38 pdlgHideStopButton = 0x00000001,
40 pdlgHideElapsedTime = 0x00000004,
42
44};
45
49
50class AUDACITY_DLL_API ProgressDialog /* not final */ :
51 public wxDialogWrapper,
53{
54public:
56
57 // Display a simple message.
59 const TranslatableString & message = {},
60 int flags = pdlgDefaultFlags,
61 const TranslatableString & sRemainingLabelText = {});
62
63 using MessageColumn = std::vector< TranslatableString >;
64 using MessageTable = std::vector< MessageColumn >;
65
66protected:
67 // Display a table of messages.
68 // Each member of the table is a column of messages.
69 // Each member of a column is a string that should have no newlines,
70 // and each column should have the same number of elements, to make
71 // proper correspondences, but this is not checked.
73 const MessageTable & columns,
74 int flags = pdlgDefaultFlags,
75 const TranslatableString & sRemainingLabelText = {});
76
77public:
78 virtual ~ProgressDialog();
79
80 bool Create(const TranslatableString & title,
81 const TranslatableString & message = {},
82 int flags = pdlgDefaultFlags,
83 const TranslatableString & sRemainingLabelText = {});
84
85 void Reinit() override;
86
87 void SetDialogTitle(const TranslatableString& title) override;
88
89protected:
90 bool Create(const TranslatableString & title,
91 const MessageTable & columns,
92 int flags = pdlgDefaultFlags,
93 const TranslatableString & sRemainingLabelText = {});
94
95public:
96 ProgressResult Update(int value, const TranslatableString & message = {});
97 ProgressResult Update(double current, const TranslatableString & message = {});
98 ProgressResult Update(double current, double total, const TranslatableString & message = {});
99 ProgressResult Update(wxULongLong_t current, wxULongLong_t total, const TranslatableString & message = {});
100 ProgressResult Update(wxLongLong current, wxLongLong total, const TranslatableString & message = {});
101 ProgressResult Update(wxLongLong_t current, wxLongLong_t total, const TranslatableString & message = {});
102 ProgressResult Update(int current, int total, const TranslatableString & message = {});
103
105 unsigned long long numerator, unsigned long long denominator,
106 const TranslatableString& message = {}) override;
107
108 void SetMessage(const TranslatableString & message) override;
109
110protected:
111 wxWindowRef mHadFocus;
112
113 wxStaticText *mElapsed;
114 wxStaticText *mRemaining;
115 wxGauge *mGauge;
116
117 wxLongLong_t mStartTime;
118 wxLongLong_t mLastUpdate;
119 wxLongLong_t mYieldTimer;
120 int mLastValue; // gauge value, range = [0,1000]
121
123 bool mStop;
124
126
127 // MY: Booleans to hold the flag values
128 bool m_bShowElapsedTime = true;
129 bool m_bConfirmAction = false;
130
131private:
132 void Init();
133 bool SearchForWindow(const wxWindowList & list, const wxWindow *searchfor) const;
134 void OnCancel(wxCommandEvent & e);
135 void OnStop(wxCommandEvent & e);
136 void OnCloseWindow(wxCloseEvent & e);
137 void Beep() const;
138
139 bool ConfirmAction(const TranslatableString & sPrompt,
140 const TranslatableString & sTitle,
141 int iButtonID = -1);
142
143 void AddMessageAsColumn(wxBoxSizer * pSizer,
144 const MessageColumn &column, bool bFirstColumn);
145
146private:
147 // This guarantees we have an active event loop...possible during OnInit()
148 wxEventLoopGuarantor mLoop;
149
150 std::unique_ptr<wxWindowDisabler> mDisable;
151
152 wxStaticText *mMessage{} ;
153 int mLastW{ 0 };
154 int mLastH{ 0 };
155
156 DECLARE_EVENT_TABLE()
157};
158
159class AUDACITY_DLL_API TimerProgressDialog final : public ProgressDialog
160{
161public:
162 TimerProgressDialog(const wxLongLong_t duration,
164 const MessageTable & columns,
165 int flags = pdlgDefaultFlags,
166 const TranslatableString & sRemainingLabelText = {});
167
168 // Oh no, there is an inherited nullary "Update" in wxDialog!
169 // Choose another name then...
170 ProgressResult UpdateProgress();
171
172protected:
173 wxLongLong_t mDuration;
174
175 // Disallow direct use of the inherited overloads of Update because it
176 // doesn't support changes of message
178};
179
180#endif
Toolkit-neutral facade for basic user interface services.
static const auto title
ProgressDialogFlags
@ pdlgConfirmStopCancel
@ pdlgHideStopButton
@ pdlgHideElapsedTime
@ pdlgEmptyFlags
@ pdlgHideCancelButton
@ pdlgDefaultFlags
Abstraction of a progress dialog with well defined time-to-completion estimate.
Definition: BasicUI.h:154
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.
virtual void SetMessage(const TranslatableString &message)=0
Change an existing dialog's message.
virtual void SetDialogTitle(const TranslatableString &title)=0
Change the dialog's title.
virtual void Reinit()=0
Reset the dialog state.
ProgressDialog Class.
std::unique_ptr< wxWindowDisabler > mDisable
wxStaticText * mElapsed
wxGauge * mGauge
wxStaticText * mRemaining
wxLongLong_t mStartTime
wxLongLong_t mLastUpdate
std::vector< MessageColumn > MessageTable
wxLongLong_t mYieldTimer
std::vector< TranslatableString > MessageColumn
wxEventLoopGuarantor mLoop
ProgressResult Update(int value, const TranslatableString &message={})
wxWindowRef mHadFocus
wxLongLong_t mDuration
Holds a msgid for the translation catalog; may also bind format arguments.
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"))
ProgressResult
Definition: BasicUI.h:145
void OnCloseWindow(wxCloseEvent &e)