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