This commit is contained in:
Igor Pavlov
2003-12-11 00:00:00 +00:00
committed by Kornel Lesiński
commit 8c1b5c7b7e
982 changed files with 118799 additions and 0 deletions

View File

@@ -0,0 +1,175 @@
// ProgressDialog.cpp
#include "StdAfx.h"
#include "resource.h"
#include "ProgressDialog.h"
#include "Common/IntToString.h"
#include "Common/IntToString.h"
using namespace NWindows;
static const UINT_PTR kTimerID = 3;
static const UINT kTimerElapse = 50;
#ifdef LANG
#include "../../LangUtils.h"
#endif
#ifdef LANG
static CIDLangPair kIDLangPairs[] =
{
{ IDCANCEL, 0x02000711 }
};
#endif
#ifndef _SFX
CProgressDialog::~CProgressDialog()
{
AddToTitle(TEXT(""));
}
void CProgressDialog::AddToTitle(LPCTSTR s)
{
if (MainWindow != 0)
::SetWindowText(MainWindow, s + UString(MainTitle));
}
#endif
bool CProgressDialog::OnInit()
{
_range = UINT64(-1);
_prevPercentValue = -1;
#ifdef LANG
// LangSetWindowText(HWND(*this), 0x02000C00);
LangSetDlgItemsText(HWND(*this), kIDLangPairs, sizeof(kIDLangPairs) / sizeof(kIDLangPairs[0]));
#endif
m_ProgressBar.Attach(GetItem(IDC_PROGRESS1));
_timer = SetTimer(kTimerID, kTimerElapse);
_dialogCreatedEvent.Set();
SetText(_title);
return CModalDialog::OnInit();
}
void CProgressDialog::OnCancel()
{
ProgressSynch.SetStopped(true);
}
void CProgressDialog::SetRange(UINT64 range)
{
_range = range;
_peviousPos = _UI64_MAX;
_converter.Init(range);
m_ProgressBar.SetRange32(0 , _converter.Count(range)); // Test it for 100%
}
void CProgressDialog::SetPos(UINT64 pos)
{
bool redraw = true;
if (pos < _range && pos > _peviousPos)
{
UINT64 posDelta = pos - _peviousPos;
if (posDelta < (_range >> 10))
redraw = false;
}
if(redraw)
{
m_ProgressBar.SetPos(_converter.Count(pos)); // Test it for 100%
_peviousPos = pos;
}
}
bool CProgressDialog::OnTimer(WPARAM timerID, LPARAM callback)
{
if (ProgressSynch.GetPaused())
return true;
UINT64 total, completed;
ProgressSynch.GetProgress(total, completed);
if (total != _range)
SetRange(total);
SetPos(completed);
if (total == 0)
total = 1;
int percentValue = (int)(completed * 100 / total);
if (percentValue != _prevPercentValue)
{
wchar_t s[64];
ConvertUINT64ToString(percentValue, s);
UString title = s;
title += L"% ";
SetText(title + _title);
#ifndef _SFX
AddToTitle(title + MainAddTitle);
#endif
_prevPercentValue = percentValue;
}
return true;
}
////////////////////
// CU64ToI32Converter
static const UINT64 kMaxIntValue = 0x7FFFFFFF;
void CU64ToI32Converter::Init(UINT64 range)
{
_numShiftBits = 0;
while(range > kMaxIntValue)
{
range >>= 1;
_numShiftBits++;
}
}
int CU64ToI32Converter::Count(UINT64 aValue)
{
return int(aValue >> _numShiftBits);
}
const UINT CProgressDialog::kCloseMessage = WM_USER + 1;
bool CProgressDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case kCloseMessage:
{
KillTimer(_timer);
_timer = 0;
End(0);
return true;
}
case WM_SETTEXT:
{
if (_timer == 0)
return true;
}
}
return CModalDialog::OnMessage(message, wParam, lParam);
}
bool CProgressDialog::OnButtonClicked(int buttonID, HWND buttonHWND)
{
switch(buttonID)
{
case IDCANCEL:
{
bool paused = ProgressSynch.GetPaused();;
ProgressSynch.SetPaused(true);
int res = ::MessageBoxW(HWND(*this),
L"Are you sure you want to cancel?",
_title, MB_YESNOCANCEL);
ProgressSynch.SetPaused(paused);
if (res == IDCANCEL || res == IDNO)
return true;
break;
}
}
return CModalDialog::OnButtonClicked(buttonID, buttonHWND);
}

View File

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

View File

@@ -0,0 +1,20 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by resource.rc
//
#define IDD_DIALOG_PROGRESS 500
#define IDC_PROGRESS1 1000
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 157
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1002
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@@ -0,0 +1,101 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Russian resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
#ifdef _WIN32
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
#pragma code_page(1251)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // Russian resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG_PROGRESS DIALOG DISCARDABLE 0, 0, 186, 55
STYLE DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION |
WS_SYSMENU
CAPTION "Progress"
FONT 8, "MS Shell Dlg"
BEGIN
PUSHBUTTON "Cancel",IDCANCEL,61,34,64,14
CONTROL "Progress1",IDC_PROGRESS1,"msctls_progress32",PBS_SMOOTH |
WS_BORDER,7,7,172,14
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_DIALOG_PROGRESS, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 179
TOPMARGIN, 7
BOTTOMMARGIN, 48
END
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////