michael@0: // ProgressDialog.h michael@0: michael@0: #ifndef __PROGRESSDIALOG_H michael@0: #define __PROGRESSDIALOG_H michael@0: michael@0: #include "resource.h" michael@0: michael@0: #include "Windows/Control/Dialog.h" michael@0: #include "Windows/Control/ProgressBar.h" michael@0: #include "Windows/Synchronization.h" michael@0: michael@0: class CProgressSynch michael@0: { michael@0: NWindows::NSynchronization::CCriticalSection _criticalSection; michael@0: bool _stopped; michael@0: bool _paused; michael@0: UINT64 _total; michael@0: UINT64 _completed; michael@0: public: michael@0: CProgressSynch(): _stopped(false), _paused(false), _total(1), _completed(0) {} michael@0: michael@0: bool GetStopped() michael@0: { michael@0: NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); michael@0: return _stopped; michael@0: } michael@0: void SetStopped(bool value) michael@0: { michael@0: NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); michael@0: _stopped = value; michael@0: } michael@0: bool GetPaused() michael@0: { michael@0: NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); michael@0: return _paused; michael@0: } michael@0: void SetPaused(bool value) michael@0: { michael@0: NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); michael@0: _paused = value; michael@0: } michael@0: void SetProgress(UINT64 total, UINT64 completed) michael@0: { michael@0: NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); michael@0: _total = total; michael@0: _completed = completed; michael@0: } michael@0: void SetPos(UINT64 completed) michael@0: { michael@0: NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); michael@0: _completed = completed; michael@0: } michael@0: void GetProgress(UINT64 &total, UINT64 &completed) michael@0: { michael@0: NWindows::NSynchronization::CCriticalSectionLock lock(_criticalSection); michael@0: total = _total; michael@0: completed = _completed; michael@0: } michael@0: }; michael@0: michael@0: class CU64ToI32Converter michael@0: { michael@0: UINT64 _numShiftBits; michael@0: public: michael@0: void Init(UINT64 _range); michael@0: int Count(UINT64 aValue); michael@0: }; michael@0: michael@0: // class CProgressDialog: public NWindows::NControl::CModelessDialog michael@0: michael@0: class CProgressDialog: public NWindows::NControl::CModalDialog michael@0: { michael@0: private: michael@0: UINT_PTR _timer; michael@0: michael@0: UString _title; michael@0: CU64ToI32Converter _converter; michael@0: UINT64 _peviousPos; michael@0: UINT64 _range; michael@0: NWindows::NControl::CProgressBar m_ProgressBar; michael@0: michael@0: int _prevPercentValue; michael@0: michael@0: bool OnTimer(WPARAM timerID, LPARAM callback); michael@0: void SetRange(UINT64 range); michael@0: void SetPos(UINT64 pos); michael@0: virtual bool OnInit(); michael@0: virtual void OnCancel(); michael@0: NWindows::NSynchronization::CManualResetEvent _dialogCreatedEvent; michael@0: #ifndef _SFX michael@0: void AddToTitle(LPCWSTR string); michael@0: #endif michael@0: bool OnButtonClicked(int buttonID, HWND buttonHWND); michael@0: public: michael@0: CProgressSynch ProgressSynch; michael@0: michael@0: #ifndef _SFX michael@0: HWND MainWindow; michael@0: UString MainTitle; michael@0: UString MainAddTitle; michael@0: ~CProgressDialog(); michael@0: #endif michael@0: michael@0: CProgressDialog(): _timer(0) michael@0: #ifndef _SFX michael@0: ,MainWindow(0) michael@0: #endif michael@0: {} michael@0: michael@0: void WaitCreating() { _dialogCreatedEvent.Lock(); } michael@0: michael@0: michael@0: INT_PTR Create(const UString &title, HWND wndParent = 0) michael@0: { michael@0: _title = title; michael@0: return CModalDialog::Create(IDD_DIALOG_PROGRESS, wndParent); michael@0: } michael@0: michael@0: static const UINT kCloseMessage; michael@0: michael@0: virtual bool OnMessage(UINT message, WPARAM wParam, LPARAM lParam); michael@0: michael@0: void MyClose() michael@0: { michael@0: PostMessage(kCloseMessage); michael@0: }; michael@0: }; michael@0: michael@0: #endif