progdlg.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: progdlg.h
  3. // Purpose: interface of wxProgressDialog
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. #define wxPD_CAN_ABORT 0x0001
  8. #define wxPD_APP_MODAL 0x0002
  9. #define wxPD_AUTO_HIDE 0x0004
  10. #define wxPD_ELAPSED_TIME 0x0008
  11. #define wxPD_ESTIMATED_TIME 0x0010
  12. #define wxPD_SMOOTH 0x0020
  13. #define wxPD_REMAINING_TIME 0x0040
  14. #define wxPD_CAN_SKIP 0x0080
  15. /**
  16. @class wxGenericProgressDialog
  17. This class represents a dialog that shows a short message and a
  18. progress bar. Optionally, it can display ABORT and SKIP buttons, and
  19. the elapsed, remaining and estimated time for the end of the progress.
  20. This class provides a generic implementation of the progress dialog. If
  21. the platform has a native progress dialog available then it will be
  22. accessible using the @a wxProgressDialog class, otherwise it will
  23. essentially be the same as this class.
  24. Note that you must be aware that wxProgressDialog internally calls
  25. wxEventLoopBase::YieldFor with @c wxEVT_CATEGORY_UI and @c wxEVT_CATEGORY_USER_INPUT
  26. and this may cause unwanted re-entrancies or the out-of-order processing
  27. of pending events (to help preventing the last problem if you're using
  28. wxProgressDialog in a multi-threaded application you should be sure to use
  29. wxThreadEvent for your inter-threads communications).
  30. @beginStyleTable
  31. @style{wxPD_APP_MODAL}
  32. Make the progress dialog modal. If this flag is not given, it is
  33. only "locally" modal - that is the input to the parent window is
  34. disabled, but not to the other ones.
  35. @style{wxPD_AUTO_HIDE}
  36. Causes the progress dialog to disappear from screen as soon as the
  37. maximum value of the progress meter has been reached.
  38. If this style is not present, the dialog will become a modal dialog
  39. (see wxDialog::ShowModal) once the maximum value has been reached
  40. and wait for the user to dismiss it.
  41. @style{wxPD_SMOOTH}
  42. Causes smooth progress of the gauge control (uses a wxGauge with the
  43. @c wxGA_SMOOTH style).
  44. @style{wxPD_CAN_ABORT}
  45. This flag tells the dialog that it should have a "Cancel" button
  46. which the user may press. If this happens, the next call to
  47. Update() will return @false.
  48. @style{wxPD_CAN_SKIP}
  49. This flag tells the dialog that it should have a "Skip" button
  50. which the user may press. If this happens, the next call to
  51. Update() will return @true in its skip parameter.
  52. @style{wxPD_ELAPSED_TIME}
  53. This flag tells the dialog that it should show elapsed time (since
  54. creating the dialog).
  55. @style{wxPD_ESTIMATED_TIME}
  56. This flag tells the dialog that it should show estimated time.
  57. @style{wxPD_REMAINING_TIME}
  58. This flag tells the dialog that it should show remaining time.
  59. @endStyleTable
  60. @library{wxcore}
  61. @category{cmndlg}
  62. */
  63. class wxGenericProgressDialog : public wxDialog
  64. {
  65. public:
  66. /**
  67. Constructor. Creates the dialog, displays it and disables user input
  68. for other windows, or, if @c wxPD_APP_MODAL flag is not given, for its
  69. parent window only.
  70. @param title
  71. Dialog title to show in titlebar.
  72. @param message
  73. Message displayed above the progress bar.
  74. @param maximum
  75. Maximum value for the progress bar.
  76. In the generic implementation the progress bar is constructed
  77. only if this value is greater than zero.
  78. @param parent
  79. Parent window.
  80. @param style
  81. The dialog style. See wxProgressDialog.
  82. */
  83. wxGenericProgressDialog(const wxString& title, const wxString& message,
  84. int maximum = 100,
  85. wxWindow* parent = NULL,
  86. int style = wxPD_AUTO_HIDE | wxPD_APP_MODAL);
  87. /**
  88. Destructor. Deletes the dialog and enables all top level windows.
  89. */
  90. virtual ~wxGenericProgressDialog();
  91. /**
  92. Returns the last value passed to the Update() function or
  93. @c wxNOT_FOUND if the dialog has no progress bar.
  94. @since 2.9.0
  95. */
  96. int GetValue() const;
  97. /**
  98. Returns the maximum value of the progress meter, as passed to
  99. the constructor or @c wxNOT_FOUND if the dialog has no progress bar.
  100. @since 2.9.0
  101. */
  102. int GetRange() const;
  103. /**
  104. Returns the last message passed to the Update() function;
  105. if you always passed wxEmptyString to Update() then the message
  106. set through the constructor is returned.
  107. @since 2.9.0
  108. */
  109. wxString GetMessage() const;
  110. /**
  111. Like Update() but makes the gauge control run in indeterminate mode.
  112. In indeterminate mode the remaining and the estimated time labels (if
  113. present) are set to "Unknown" or to @a newmsg (if it's non-empty).
  114. Each call to this function moves the progress bar a bit to indicate
  115. that some progress was done.
  116. @see wxGauge::Pulse(), Update()
  117. */
  118. virtual bool Pulse(const wxString& newmsg = wxEmptyString, bool* skip = NULL);
  119. /**
  120. Can be used to continue with the dialog, after the user had clicked the "Abort" button.
  121. */
  122. void Resume();
  123. /**
  124. Changes the maximum value of the progress meter given in the constructor.
  125. This function can only be called (with a positive value) if the value passed
  126. in the constructor was positive.
  127. @since 2.9.1
  128. */
  129. void SetRange(int maximum);
  130. /**
  131. Returns true if the "Cancel" button was pressed.
  132. Normally a Cancel button press is indicated by Update() returning
  133. @false but sometimes it may be more convenient to check if the dialog
  134. was cancelled from elsewhere in the code and this function allows to
  135. do it.
  136. It always returns @false if the Cancel button is not shown at all.
  137. @since 2.9.1
  138. */
  139. bool WasCancelled() const;
  140. /**
  141. Returns true if the "Skip" button was pressed.
  142. This is similar to WasCancelled() but returns @true if the "Skip"
  143. button was pressed, not the "Cancel" one.
  144. @since 2.9.1
  145. */
  146. bool WasSkipped() const;
  147. /**
  148. Updates the dialog, setting the progress bar to the new value and
  149. updating the message if new one is specified.
  150. Returns @true unless the "Cancel" button has been pressed.
  151. If @false is returned, the application can either immediately destroy the
  152. dialog or ask the user for the confirmation and if the abort is not confirmed
  153. the dialog may be resumed with Resume() function.
  154. If @a value is the maximum value for the dialog, the behaviour of the
  155. function depends on whether @c wxPD_AUTO_HIDE was used when the dialog
  156. was created. If it was, the dialog is hidden and the function returns
  157. immediately. If it was not, the dialog becomes a modal dialog and waits
  158. for the user to dismiss it, meaning that this function does not return
  159. until this happens.
  160. Notice that you may want to call Fit() to change the dialog size to
  161. conform to the length of the new message if desired. The dialog does
  162. not do this automatically.
  163. @param value
  164. The new value of the progress meter. It should be less than or equal to
  165. the maximum value given to the constructor.
  166. @param newmsg
  167. The new messages for the progress dialog text, if it is
  168. empty (which is the default) the message is not changed.
  169. @param skip
  170. If "Skip" button was pressed since last Update() call,
  171. this is set to @true.
  172. */
  173. virtual bool Update(int value, const wxString& newmsg = wxEmptyString,
  174. bool* skip = NULL);
  175. };
  176. /**
  177. @class wxProgressDialog
  178. If supported by the platform this class will provide the platform's native
  179. progress dialog, else it will simply be the @a wxGenericProgressDialog.
  180. */
  181. class wxProgressDialog : public wxGenericProgressDialog
  182. {
  183. public:
  184. wxProgressDialog( const wxString& title, const wxString& message,
  185. int maximum = 100,
  186. wxWindow *parent = NULL,
  187. int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE );
  188. };