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