1 // ProgressDialog.h
2 
3 #ifndef __PROGRESSDIALOG_H
4 #define __PROGRESSDIALOG_H
5 
6 #include "resource.h"
7 
8 #include "Windows/Control/Dialog.h"
9 #include "Windows/Control/ProgressBar.h"
10 #include "Windows/Synchronization.h"
11 
12 class CProgressSynch
13 {
14   NWindows::NSynchronization::CCriticalSection _criticalSection;
15   bool _stopped;
16   bool _paused;
17   UINT64 _total;
18   UINT64 _completed;
19 public:
CProgressSynch()20   CProgressSynch(): _stopped(false), _paused(false), _total(1), _completed(0) {}
21 
GetStopped()22   bool GetStopped()
23   {
24     NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
25     return _stopped;
26   }
SetStopped(bool value)27   void SetStopped(bool value)
28   {
29     NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
30     _stopped = value;
31   }
GetPaused()32   bool GetPaused()
33   {
34     NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
35     return _paused;
36   }
SetPaused(bool value)37   void SetPaused(bool value)
38   {
39     NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
40     _paused = value;
41   }
SetProgress(UINT64 total,UINT64 completed)42   void SetProgress(UINT64 total, UINT64 completed)
43   {
44     NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
45     _total = total;
46     _completed = completed;
47   }
SetPos(UINT64 completed)48   void SetPos(UINT64 completed)
49   {
50     NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
51     _completed = completed;
52   }
GetProgress(UINT64 & total,UINT64 & completed)53   void GetProgress(UINT64 &total, UINT64 &completed)
54   {
55     NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection);
56     total = _total;
57     completed = _completed;
58   }
59 };
60 
61 class CU64ToI32Converter
62 {
63   UINT64 _numShiftBits;
64 public:
65   void Init(UINT64 _range);
66   int Count(UINT64 aValue);
67 };
68 
69 // class CProgressDialog: public NWindows::NControl::CModelessDialog
70 
71 class CProgressDialog: public NWindows::NControl::CModalDialog
72 {
73 private:
74   UINT_PTR _timer;
75 
76   UString _title;
77   CU64ToI32Converter _converter;
78   UINT64 _peviousPos;
79   UINT64 _range;
80 	NWindows::NControl::CProgressBar m_ProgressBar;
81 
82   int _prevPercentValue;
83 
84   bool OnTimer(WPARAM timerID, LPARAM callback);
85   void SetRange(UINT64 range);
86   void SetPos(UINT64 pos);
87 	virtual bool OnInit();
88 	virtual void OnCancel();
89   NWindows::NSynchronization::CManualResetEvent _dialogCreatedEvent;
90   #ifndef _SFX
91   void AddToTitle(LPCWSTR string);
92   #endif
93   bool OnButtonClicked(int buttonID, HWND buttonHWND);
94 public:
95   CProgressSynch ProgressSynch;
96 
97   #ifndef _SFX
98   HWND MainWindow;
99   UString MainTitle;
100   UString MainAddTitle;
101   ~CProgressDialog();
102   #endif
103 
CProgressDialog()104   CProgressDialog(): _timer(0)
105     #ifndef _SFX
106     ,MainWindow(0)
107     #endif
108   {}
109 
WaitCreating()110   void WaitCreating() { _dialogCreatedEvent.Lock(); }
111 
112 
113   INT_PTR Create(const UString &title, HWND wndParent = 0)
114   {
115     _title = title;
116     return CModalDialog::Create(IDD_DIALOG_PROGRESS, wndParent);
117   }
118 
119   static const UINT kCloseMessage;
120 
121   virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
122 
MyClose()123   void MyClose()
124   {
125     PostMessage(kCloseMessage);
126   };
127 };
128 
129 #endif
130