]>
Commit | Line | Data |
---|---|---|
ed1288ee | 1 | /////////////////////////////////////////////////////////////////////////////// |
8fa2e6a2 | 2 | // Name: progdlgg.h |
c31d9c7f | 3 | // Purpose: wxGenericProgressDialog class |
9d55bfef | 4 | // Author: Karsten Ballueder |
ed1288ee | 5 | // Modified by: Francesco Montorsi |
8fa2e6a2 KB |
6 | // Created: 09.05.1999 |
7 | // RCS-ID: $Id$ | |
9d55bfef | 8 | // Copyright: (c) Karsten Ballueder |
65571936 | 9 | // Licence: wxWindows licence |
ed1288ee | 10 | /////////////////////////////////////////////////////////////////////////////// |
8fa2e6a2 KB |
11 | |
12 | #ifndef __PROGDLGH_G__ | |
13 | #define __PROGDLGH_G__ | |
14 | ||
0655ad29 | 15 | #include "wx/dialog.h" |
8fa2e6a2 | 16 | |
b5dbe15d VS |
17 | class WXDLLIMPEXP_FWD_CORE wxButton; |
18 | class WXDLLIMPEXP_FWD_CORE wxGauge; | |
19 | class WXDLLIMPEXP_FWD_CORE wxStaticText; | |
0655ad29 | 20 | |
ed1288ee FM |
21 | /* |
22 | Progress dialog which shows a moving progress bar. | |
23 | Taken from the Mahogany project. | |
24 | */ | |
c31d9c7f | 25 | class WXDLLIMPEXP_CORE wxGenericProgressDialog : public wxDialog |
8fa2e6a2 | 26 | { |
8fa2e6a2 | 27 | public: |
c31d9c7f VZ |
28 | wxGenericProgressDialog(const wxString& title, const wxString& message, |
29 | int maximum = 100, | |
30 | wxWindow *parent = NULL, | |
31 | int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE); | |
ed1288ee | 32 | |
c31d9c7f | 33 | virtual ~wxGenericProgressDialog(); |
695f550b | 34 | |
695f550b | 35 | virtual bool Update(int value, const wxString& newmsg = wxEmptyString, bool *skip = NULL); |
f4aa7ec3 | 36 | virtual bool Pulse(const wxString& newmsg = wxEmptyString, bool *skip = NULL); |
fe8635a7 | 37 | |
695f550b | 38 | void Resume(); |
8fa2e6a2 | 39 | |
af237ae4 FM |
40 | int GetValue() const; |
41 | int GetRange() const; | |
42 | wxString GetMessage() const; | |
7d1dcec2 | 43 | |
ed1288ee FM |
44 | void SetRange(int maximum); |
45 | ||
f994a8ac VZ |
46 | // Return whether "Cancel" or "Skip" button was pressed, always return |
47 | // false if the corresponding button is not shown. | |
48 | bool WasCancelled() const; | |
49 | bool WasSkipped() const; | |
50 | ||
ed1288ee FM |
51 | // Must provide overload to avoid hiding it (and warnings about it) |
52 | virtual void Update() { wxDialog::Update(); } | |
53 | ||
54 | virtual bool Show( bool show = true ); | |
55 | ||
c31d9c7f VZ |
56 | // This enum is an implementation detail and should not be used |
57 | // by user code. | |
58 | enum ProgressDialogState | |
59 | { | |
60 | Uncancelable = -1, // dialog can't be canceled | |
61 | Canceled, // can be cancelled and, in fact, was | |
62 | Continue, // can be cancelled but wasn't | |
63 | Finished // finished, waiting to be removed from screen | |
64 | }; | |
65 | ||
ef8698d6 | 66 | protected: |
c31d9c7f VZ |
67 | // This ctor is used by the native MSW implementation only. |
68 | wxGenericProgressDialog(wxWindow *parent, int maximum, int style); | |
69 | ||
70 | void Create(const wxString& title, | |
71 | const wxString& message, | |
72 | int maximum, | |
73 | wxWindow *parent, | |
74 | int style); | |
75 | ||
76 | // Return the labels to use for showing the elapsed/estimated/remaining | |
77 | // times respectively. | |
78 | static wxString GetElapsedLabel() { return _("Elapsed time:"); } | |
79 | static wxString GetEstimatedLabel() { return _("Estimated time:"); } | |
80 | static wxString GetRemainingLabel() { return _("Remaining time:"); } | |
81 | ||
82 | ||
83 | // Updates estimated times from a given progress bar value and stores the | |
84 | // results in provided arguments. | |
85 | void UpdateTimeEstimates(int value, | |
86 | unsigned long &elapsedTime, | |
87 | unsigned long &estimatedTime, | |
88 | unsigned long &remainingTime); | |
89 | ||
90 | // Converts seconds to HH:mm:ss format. | |
91 | static wxString GetFormattedTime(unsigned long timeInSec); | |
92 | ||
695f550b VZ |
93 | // callback for optional abort button |
94 | void OnCancel(wxCommandEvent&); | |
ef8698d6 | 95 | |
695f550b VZ |
96 | // callback for optional skip button |
97 | void OnSkip(wxCommandEvent&); | |
ecda9475 | 98 | |
695f550b VZ |
99 | // callback to disable "hard" window closing |
100 | void OnClose(wxCloseEvent&); | |
8fa2e6a2 | 101 | |
c31d9c7f VZ |
102 | // called to disable the other windows while this dialog is shown |
103 | void DisableOtherWindows(); | |
104 | ||
695f550b VZ |
105 | // must be called to reenable the other windows temporarily disabled while |
106 | // the dialog was shown | |
107 | void ReenableOtherWindows(); | |
ef8698d6 | 108 | |
c31d9c7f VZ |
109 | // return the top level parent window of this dialog (may be NULL) |
110 | wxWindow *GetTopParent() const { return m_parentTop; } | |
111 | ||
112 | ||
113 | // continue processing or not (return value for Update()) | |
114 | ProgressDialogState m_state; | |
115 | ||
116 | // the maximum value | |
117 | int m_maximum; | |
118 | ||
119 | #if defined(__WXMSW__ ) || defined(__WXPM__) | |
120 | // the factor we use to always keep the value in 16 bit range as the native | |
121 | // control only supports ranges from 0 to 65,535 | |
122 | size_t m_factor; | |
123 | #endif // __WXMSW__ | |
124 | ||
125 | // time when the dialog was created | |
126 | unsigned long m_timeStart; | |
127 | // time when the dialog was closed or cancelled | |
128 | unsigned long m_timeStop; | |
129 | // time between the moment the dialog was closed/cancelled and resume | |
130 | unsigned long m_break; | |
131 | ||
8fa2e6a2 | 132 | private: |
c31d9c7f VZ |
133 | // update the label to show the given time (in seconds) |
134 | static void SetTimeLabel(unsigned long val, wxStaticText *label); | |
135 | ||
136 | // common part of all ctors | |
137 | void Init(wxWindow *parent, int maximum, int style); | |
138 | ||
695f550b VZ |
139 | // create the label with given text and another one to show the time nearby |
140 | // as the next windows in the sizer, returns the created control | |
141 | wxStaticText *CreateLabel(const wxString& text, wxSizer *sizer); | |
0655ad29 | 142 | |
fe8635a7 | 143 | // updates the label message |
695f550b VZ |
144 | void UpdateMessage(const wxString &newmsg); |
145 | ||
146 | // common part of Update() and Pulse(), returns true if not cancelled | |
86417abf VZ |
147 | bool DoBeforeUpdate(bool *skip); |
148 | ||
149 | // common part of Update() and Pulse() | |
150 | void DoAfterUpdate(); | |
695f550b VZ |
151 | |
152 | // shortcuts for enabling buttons | |
153 | void EnableClose(); | |
154 | void EnableSkip(bool enable = true); | |
155 | void EnableAbort(bool enable = true); | |
156 | void DisableSkip() { EnableSkip(false); } | |
157 | void DisableAbort() { EnableAbort(false); } | |
158 | ||
af237ae4 | 159 | // the widget displaying current status (may be NULL) |
695f550b VZ |
160 | wxGauge *m_gauge; |
161 | // the message displayed | |
162 | wxStaticText *m_msg; | |
163 | // displayed elapsed, estimated, remaining time | |
164 | wxStaticText *m_elapsed, | |
165 | *m_estimated, | |
166 | *m_remaining; | |
695f550b VZ |
167 | |
168 | // parent top level window (may be NULL) | |
169 | wxWindow *m_parentTop; | |
abceee76 | 170 | |
69c69546 WS |
171 | // skip some portion |
172 | bool m_skip; | |
ecda9475 WS |
173 | |
174 | #if !defined(__SMARTPHONE__) | |
69c69546 WS |
175 | // the abort and skip buttons (or NULL if none) |
176 | wxButton *m_btnAbort; | |
177 | wxButton *m_btnSkip; | |
ecda9475 | 178 | #endif |
cbc66a27 | 179 | |
69c69546 WS |
180 | // saves the time when elapsed time was updated so there is only one |
181 | // update per second | |
182 | unsigned long m_last_timeupdate; | |
c31d9c7f | 183 | |
69c69546 | 184 | // tells how often a change of the estimated time has to be confirmed |
c31d9c7f | 185 | // before it is actually displayed - this reduces the frequency of updates |
69c69546 | 186 | // of estimated and remaining time |
c31d9c7f VZ |
187 | int m_delay; |
188 | ||
69c69546 WS |
189 | // counts the confirmations |
190 | int m_ctdelay; | |
191 | unsigned long m_display_estimated; | |
8fa2e6a2 | 192 | |
69c69546 WS |
193 | bool m_hasAbortButton, |
194 | m_hasSkipButton; | |
2c5ef4e2 | 195 | |
69c69546 | 196 | // for wxPD_APP_MODAL case |
b5dbe15d | 197 | class WXDLLIMPEXP_FWD_CORE wxWindowDisabler *m_winDisabler; |
cbc66a27 | 198 | |
69c69546 | 199 | DECLARE_EVENT_TABLE() |
c31d9c7f | 200 | wxDECLARE_NO_COPY_CLASS(wxGenericProgressDialog); |
8fa2e6a2 | 201 | }; |
ce4169a4 | 202 | |
555f645a | 203 | #endif // __PROGDLGH_G__ |