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