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 wxEventLoop
;
19 class WXDLLIMPEXP_FWD_CORE wxGauge
;
20 class WXDLLIMPEXP_FWD_CORE wxStaticText
;
21 class WXDLLIMPEXP_FWD_CORE wxWindowDisabler
;
24 Progress dialog which shows a moving progress bar.
25 Taken from the Mahogany project.
27 class WXDLLIMPEXP_CORE wxGenericProgressDialog
: public wxDialog
30 wxGenericProgressDialog(const wxString
& title
, const wxString
& message
,
32 wxWindow
*parent
= NULL
,
33 int style
= wxPD_APP_MODAL
| wxPD_AUTO_HIDE
);
35 virtual ~wxGenericProgressDialog();
37 virtual bool Update(int value
, const wxString
& newmsg
= wxEmptyString
, bool *skip
= NULL
);
38 virtual bool Pulse(const wxString
& newmsg
= wxEmptyString
, bool *skip
= NULL
);
44 wxString
GetMessage() const;
46 void SetRange(int maximum
);
48 // Return whether "Cancel" or "Skip" button was pressed, always return
49 // false if the corresponding button is not shown.
50 bool WasCancelled() const;
51 bool WasSkipped() const;
53 // Must provide overload to avoid hiding it (and warnings about it)
54 virtual void Update() { wxDialog::Update(); }
56 virtual bool Show( bool show
= true );
58 // This enum is an implementation detail and should not be used
60 enum ProgressDialogState
62 Uncancelable
= -1, // dialog can't be canceled
63 Canceled
, // can be cancelled and, in fact, was
64 Continue
, // can be cancelled but wasn't
65 Finished
// finished, waiting to be removed from screen
69 // This ctor is used by the native MSW implementation only.
70 wxGenericProgressDialog(wxWindow
*parent
, int maximum
, int style
);
72 void Create(const wxString
& title
,
73 const wxString
& message
,
78 // Return the labels to use for showing the elapsed/estimated/remaining
79 // times respectively.
80 static wxString
GetElapsedLabel() { return _("Elapsed time:"); }
81 static wxString
GetEstimatedLabel() { return _("Estimated time:"); }
82 static wxString
GetRemainingLabel() { return _("Remaining time:"); }
85 // Updates estimated times from a given progress bar value and stores the
86 // results in provided arguments.
87 void UpdateTimeEstimates(int value
,
88 unsigned long &elapsedTime
,
89 unsigned long &estimatedTime
,
90 unsigned long &remainingTime
);
92 // Converts seconds to HH:mm:ss format.
93 static wxString
GetFormattedTime(unsigned long timeInSec
);
95 // callback for optional abort button
96 void OnCancel(wxCommandEvent
&);
98 // callback for optional skip button
99 void OnSkip(wxCommandEvent
&);
101 // callback to disable "hard" window closing
102 void OnClose(wxCloseEvent
&);
104 // called to disable the other windows while this dialog is shown
105 void DisableOtherWindows();
107 // must be called to reenable the other windows temporarily disabled while
108 // the dialog was shown
109 void ReenableOtherWindows();
111 // return the top level parent window of this dialog (may be NULL)
112 wxWindow
*GetTopParent() const { return m_parentTop
; }
115 // continue processing or not (return value for Update())
116 ProgressDialogState m_state
;
121 #if defined(__WXMSW__ ) || defined(__WXPM__)
122 // the factor we use to always keep the value in 16 bit range as the native
123 // control only supports ranges from 0 to 65,535
127 // time when the dialog was created
128 unsigned long m_timeStart
;
129 // time when the dialog was closed or cancelled
130 unsigned long m_timeStop
;
131 // time between the moment the dialog was closed/cancelled and resume
132 unsigned long m_break
;
135 // update the label to show the given time (in seconds)
136 static void SetTimeLabel(unsigned long val
, wxStaticText
*label
);
138 // common part of all ctors
139 void Init(wxWindow
*parent
, int maximum
, int style
);
141 // create the label with given text and another one to show the time nearby
142 // as the next windows in the sizer, returns the created control
143 wxStaticText
*CreateLabel(const wxString
& text
, wxSizer
*sizer
);
145 // updates the label message
146 void UpdateMessage(const wxString
&newmsg
);
148 // common part of Update() and Pulse(), returns true if not cancelled
149 bool DoBeforeUpdate(bool *skip
);
151 // common part of Update() and Pulse()
152 void DoAfterUpdate();
154 // shortcuts for enabling buttons
156 void EnableSkip(bool enable
= true);
157 void EnableAbort(bool enable
= true);
158 void DisableSkip() { EnableSkip(false); }
159 void DisableAbort() { EnableAbort(false); }
161 // the widget displaying current status (may be NULL)
163 // the message displayed
165 // displayed elapsed, estimated, remaining time
166 wxStaticText
*m_elapsed
,
170 // parent top level window (may be NULL)
171 wxWindow
*m_parentTop
;
176 #if !defined(__SMARTPHONE__)
177 // the abort and skip buttons (or NULL if none)
178 wxButton
*m_btnAbort
;
182 // saves the time when elapsed time was updated so there is only one
184 unsigned long m_last_timeupdate
;
186 // tells how often a change of the estimated time has to be confirmed
187 // before it is actually displayed - this reduces the frequency of updates
188 // of estimated and remaining time
191 // counts the confirmations
193 unsigned long m_display_estimated
;
195 bool m_hasAbortButton
,
198 // for wxPD_APP_MODAL case
199 wxWindowDisabler
*m_winDisabler
;
201 // Temporary event loop created by the dialog itself if there is no
202 // currently active loop when it is created.
203 wxEventLoop
*m_tempEventLoop
;
206 DECLARE_EVENT_TABLE()
207 wxDECLARE_NO_COPY_CLASS(wxGenericProgressDialog
);
210 #endif // __PROGDLGH_G__