progdlgg.h 7.7 KB

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