1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGenericProgressDialog class
4 // Author: Karsten Ballueder
5 // Modified by: Francesco Montorsi
8 // Copyright: (c) Karsten Ballueder
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef __PROGDLGH_G__
13 #define __PROGDLGH_G__
15 #include "wx/dialog.h"
17 class WXDLLIMPEXP_FWD_CORE wxButton
;
18 class WXDLLIMPEXP_FWD_CORE wxGauge
;
19 class WXDLLIMPEXP_FWD_CORE wxStaticText
;
20 class WXDLLIMPEXP_FWD_CORE wxWindowDisabler
;
23 Progress dialog which shows a moving progress bar.
24 Taken from the Mahogany project.
26 class WXDLLIMPEXP_CORE wxGenericProgressDialog
: public wxDialog
29 wxGenericProgressDialog(const wxString
& title
, const wxString
& message
,
31 wxWindow
*parent
= NULL
,
32 int style
= wxPD_APP_MODAL
| wxPD_AUTO_HIDE
);
34 virtual ~wxGenericProgressDialog();
36 virtual bool Update(int value
, const wxString
& newmsg
= wxEmptyString
, bool *skip
= NULL
);
37 virtual bool Pulse(const wxString
& newmsg
= wxEmptyString
, bool *skip
= NULL
);
43 wxString
GetMessage() const;
45 void SetRange(int maximum
);
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;
52 // Must provide overload to avoid hiding it (and warnings about it)
53 virtual void Update() { wxDialog::Update(); }
55 virtual bool Show( bool show
= true );
57 // This enum is an implementation detail and should not be used
59 enum ProgressDialogState
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
68 // This ctor is used by the native MSW implementation only.
69 wxGenericProgressDialog(wxWindow
*parent
, int maximum
, int style
);
71 void Create(const wxString
& title
,
72 const wxString
& message
,
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:"); }
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
);
91 // Converts seconds to HH:mm:ss format.
92 static wxString
GetFormattedTime(unsigned long timeInSec
);
94 // callback for optional abort button
95 void OnCancel(wxCommandEvent
&);
97 // callback for optional skip button
98 void OnSkip(wxCommandEvent
&);
100 // callback to disable "hard" window closing
101 void OnClose(wxCloseEvent
&);
103 // called to disable the other windows while this dialog is shown
104 void DisableOtherWindows();
106 // must be called to reenable the other windows temporarily disabled while
107 // the dialog was shown
108 void ReenableOtherWindows();
110 // return the top level parent window of this dialog (may be NULL)
111 wxWindow
*GetTopParent() const { return m_parentTop
; }
114 // continue processing or not (return value for Update())
115 ProgressDialogState m_state
;
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
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
;
134 // update the label to show the given time (in seconds)
135 static void SetTimeLabel(unsigned long val
, wxStaticText
*label
);
137 // common part of all ctors
138 void Init(wxWindow
*parent
, int maximum
, int style
);
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
);
144 // updates the label message
145 void UpdateMessage(const wxString
&newmsg
);
147 // common part of Update() and Pulse(), returns true if not cancelled
148 bool DoBeforeUpdate(bool *skip
);
150 // common part of Update() and Pulse()
151 void DoAfterUpdate();
153 // shortcuts for enabling buttons
155 void EnableSkip(bool enable
= true);
156 void EnableAbort(bool enable
= true);
157 void DisableSkip() { EnableSkip(false); }
158 void DisableAbort() { EnableAbort(false); }
160 // the widget displaying current status (may be NULL)
162 // the message displayed
164 // displayed elapsed, estimated, remaining time
165 wxStaticText
*m_elapsed
,
169 // parent top level window (may be NULL)
170 wxWindow
*m_parentTop
;
175 #if !defined(__SMARTPHONE__)
176 // the abort and skip buttons (or NULL if none)
177 wxButton
*m_btnAbort
;
181 // saves the time when elapsed time was updated so there is only one
183 unsigned long m_last_timeupdate
;
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
190 // counts the confirmations
192 unsigned long m_display_estimated
;
194 bool m_hasAbortButton
,
197 // for wxPD_APP_MODAL case
198 wxWindowDisabler
*m_winDisabler
;
200 DECLARE_EVENT_TABLE()
201 wxDECLARE_NO_COPY_CLASS(wxGenericProgressDialog
);
204 #endif // __PROGDLGH_G__