3 #ifndef __PROGRESS_DIALOG_H
\r
4 #define __PROGRESS_DIALOG_H
\r
6 #include "Windows/Synchronization.h"
\r
7 #include "Windows/Thread.h"
\r
9 #include "Windows/Control/Dialog.h"
\r
10 #include "Windows/Control/ProgressBar.h"
\r
12 #include "ProgressDialogRes.h"
\r
16 NWindows::NSynchronization::CCriticalSection _cs;
\r
22 CProgressSync(): _stopped(false), _paused(false), _total(1), _completed(0) {}
\r
24 HRESULT ProcessStopAndPause();
\r
27 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
30 void SetStopped(bool value)
\r
32 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
37 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
40 void SetPaused(bool value)
\r
42 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
45 void SetProgress(UInt64 total, UInt64 completed)
\r
47 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
49 _completed = completed;
\r
51 void SetPos(UInt64 completed)
\r
53 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
54 _completed = completed;
\r
56 void GetProgress(UInt64 &total, UInt64 &completed)
\r
58 NWindows::NSynchronization::CCriticalSectionLock lock(_cs);
\r
60 completed = _completed;
\r
64 class CU64ToI32Converter
\r
66 UInt64 _numShiftBits;
\r
68 void Init(UInt64 range)
\r
70 // Windows CE doesn't like big number here.
\r
71 for (_numShiftBits = 0; range > (1 << 15); _numShiftBits++)
\r
74 int Count(UInt64 value) { return int(value >> _numShiftBits); }
\r
77 class CProgressDialog: public NWindows::NControl::CModalDialog
\r
83 CU64ToI32Converter _converter;
\r
86 NWindows::NControl::CProgressBar m_ProgressBar;
\r
88 int _prevPercentValue;
\r
92 bool _inCancelMessageBox;
\r
93 bool _externalCloseMessageWasReceived;
\r
95 bool OnTimer(WPARAM timerID, LPARAM callback);
\r
96 void SetRange(UInt64 range);
\r
97 void SetPos(UInt64 pos);
\r
98 virtual bool OnInit();
\r
99 virtual void OnCancel();
\r
100 virtual void OnOK();
\r
101 NWindows::NSynchronization::CManualResetEvent _dialogCreatedEvent;
\r
103 void AddToTitle(LPCWSTR string);
\r
105 bool OnButtonClicked(int buttonID, HWND buttonHWND);
\r
107 void WaitCreating() { _dialogCreatedEvent.Lock(); }
\r
108 void CheckNeedClose();
\r
109 bool OnExternalCloseMessage();
\r
111 CProgressSync Sync;
\r
117 UString MainAddTitle;
\r
118 ~CProgressDialog();
\r
121 CProgressDialog(): _timer(0)
\r
127 _wasCreated = false;
\r
128 _needClose = false;
\r
129 _inCancelMessageBox = false;
\r
130 _externalCloseMessageWasReceived = false;
\r
132 if (_dialogCreatedEvent.Create() != S_OK)
\r
136 INT_PTR Create(const UString &title, NWindows::CThread &thread, HWND wndParent = 0)
\r
139 INT_PTR res = CModalDialog::Create(IDD_DIALOG_PROGRESS, wndParent);
\r
146 kCloseMessage = WM_USER + 1
\r
149 virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
\r
151 void ProcessWasFinished()
\r
155 PostMessage(kCloseMessage);
\r
162 class CProgressCloser
\r
164 CProgressDialog *_p;
\r
166 CProgressCloser(CProgressDialog &p) : _p(&p) {}
\r
167 ~CProgressCloser() { _p->ProcessWasFinished(); }
\r