Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
DoubleProgDlg.h
1 //
2 // DoubleProgressDialog class
3 //
4 // Copyright (c) 2007 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 
8 #include "wx/defs.h"
9 #include "wx/progdlg.h"
10 #include "wx/dialog.h"
11 
12 class DoubleProgressDialog : public wxDialog
13 {
14  DECLARE_DYNAMIC_CLASS(DoubleProgressDialog)
15 public:
16  /* Creates and displays dialog, disables event handling for other
17  frames or parent frame to avoid recursion problems.
18  @param title title for window
19  @param message message to display in window
20  @param maximum value for status bar, if <= 0, no bar is shown
21  @param parent window or NULL
22  @param style is the bit mask of wxPD_XXX constants from wx/defs.h
23  */
24  DoubleProgressDialog(const wxString &title, wxString const &message,
25  wxWindow *parent = NULL,
26  int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE);
27  /* Destructor.
28  Re-enables event handling for other windows.
29  */
30  virtual ~DoubleProgressDialog();
31 
32  /* Update the status bar to the new value.
33  @param value new value
34  @param newmsg if used, new message to display
35  @returns true if ABORT button has not been pressed
36  */
37  virtual bool Update(int value1, int value2, const wxString& newmsg = wxEmptyString);
38 
39  // Must provide overload to avoid hiding it (and warnings about it)
40  virtual void Update() { wxDialog::Update(); }
41 
42  /* Can be called to continue after the cancel button has been pressed, but
43  the program decided to continue the operation (e.g., user didn't
44  confirm it) */
45  void Resume();
46 
47  virtual bool Show( bool show = true );
48 
49 protected:
50  // callback for optional abort button
51  void OnCancel(wxCommandEvent& event);
52 
53  // callback to disable "hard" window closing
54  void OnClose(wxCloseEvent& event);
55 
56  // must be called to reenable the other windows temporarily disabled while
57  // the dialog was shown
58  void ReenableOtherWindows();
59 
60 private:
61  // create the label with given text and another one to show the time nearby
62  // as the next windows in the sizer, returns the created control
63  wxStaticText *CreateLabel(const wxString& text, wxSizer *sizer);
64 
65  // updates the label message
66  void UpdateMessage(const wxString &newmsg);
67 
68  // part of Update() returns true if not cancelled
69  bool DoAfterUpdate();
70 
71  // shortcuts for enabling buttons
72  void EnableClose();
73  void EnableAbort(bool enable=true);
74  inline void DisableAbort() { EnableAbort(false); }
75 
76  // Yield to other parts of the GUI
77  void DoYield();
78 
79  // the status bars
80  wxGauge *m_gauge1;
81  wxGauge *m_gauge2;
82  // the message displayed
83  wxStaticText *m_msg;
84 
85  // parent top level window (may be NULL)
86  wxWindow *m_parentTop;
87 
88  // continue processing or not (return value for Update())
89  enum
90  {
91  Uncancelable = -1, // dialog can't be canceled
92  Canceled, // can be cancelled and, in fact, was
93  Continue, // can be cancelled but wasn't
94  Finished // finished, waiting to be removed from screen
95  } m_state;
96 
97  // the abort buttons (or NULL if none)
98  wxButton *m_btnAbort;
99 
100  // the maximum value
101  int m_maximum;
102 
103  // tells how often a change of the estimated time has to be confirmed
104  // before it is actually displayed - this reduces the frequence of updates
105  // of estimated and remaining time
106  const int m_delay;
107  // counts the confirmations
108  int m_ctdelay;
109  unsigned long m_display_estimated;
110 
111  bool m_hasAbortButton;
112 
113 #if defined(__WXMSW__ ) || defined(__WXPM__)
114  // the factor we use to always keep the value in 16 bit range as the native
115  // control only supports ranges from 0 to 65,535
116  size_t m_factor;
117 #endif // __WXMSW__
118 
119  // for wxPD_APP_MODAL case
120  class WXDLLEXPORT wxWindowDisabler *m_winDisabler;
121 
122  DECLARE_EVENT_TABLE()
123  // DECLARE_NO_COPY_CLASS(DoubleProgressDialog)
124 };
125