00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "Wnd_DownloadProgress.h"
00009 #include "fsDownloadsMgr.h"
00010 #include "list.h"
00011
00012 #ifdef _DEBUG
00013 #define new DEBUG_NEW
00014 #undef THIS_FILE
00015 static char THIS_FILE[] = __FILE__;
00016 #endif
00017
00018 CWnd_DownloadProgress::CWnd_DownloadProgress()
00019 {
00020 m_hevShutdown = CreateEvent (NULL, TRUE, FALSE, NULL);
00021 m_hevDraw = CreateEvent (NULL, TRUE, FALSE, NULL);
00022
00023 DWORD dw;
00024 m_hthDraw = CreateThread (NULL, 0, _threadDraw, this, 0, &dw);
00025 }
00026
00027 CWnd_DownloadProgress::~CWnd_DownloadProgress()
00028 {
00029 SetEvent (m_hevShutdown);
00030 WaitForSingleObject (m_hthDraw, INFINITE);
00031 CloseHandle (m_hthDraw);
00032 CloseHandle (m_hevDraw);
00033 CloseHandle (m_hevShutdown);
00034 }
00035
00036 BEGIN_MESSAGE_MAP(CWnd_DownloadProgress, CWnd)
00037
00038 ON_WM_PAINT()
00039
00040 END_MESSAGE_MAP()
00041
00042 void CWnd_DownloadProgress::Create(CWnd *pwndParent)
00043 {
00044 CWnd::CreateEx (_theme.IsThemeActive () ? 0 : WS_EX_STATICEDGE,
00045 AfxRegisterWndClass (0, NULL, NULL, NULL),
00046 "", WS_CHILD|WS_VISIBLE,
00047 CRect (0, 0, 0, 0), pwndParent, 0);
00048 }
00049
00050 void CWnd_DownloadProgress::OnPaint()
00051 {
00052 CPaintDC dc(this);
00053 SetEvent (m_hevDraw);
00054 }
00055
00056 DWORD WINAPI CWnd_DownloadProgress::_threadDraw(LPVOID lp)
00057 {
00058 CWnd_DownloadProgress *pthis = (CWnd_DownloadProgress*) lp;
00059
00060 SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_IDLE);
00061
00062 HANDLE phEvs [] = {pthis->m_hevDraw, pthis->m_hevShutdown};
00063
00064 while (WAIT_OBJECT_0 == WaitForMultipleObjects (2, phEvs, FALSE, INFINITE))
00065 {
00066 CDC *dc = pthis->GetDC ();
00067
00068 CRect rc;
00069 pthis->GetClientRect (&rc);
00070
00071 CDC* pdc = pthis->m_renderer.Start (dc, &rc);
00072
00073 UINT64 uSize = pthis->m_dld->pMgr->GetLDFileSize ();
00074 COLORREF clr = GetSysColor (COLOR_HIGHLIGHT);
00075
00076 HTHEME hTheme = NULL;
00077 int nSepW = 0;
00078 if (_theme.IsThemeActive ())
00079 {
00080 hTheme = _theme.OpenThemeData (pthis->m_hWnd, L"PROGRESS");
00081 if (hTheme)
00082 nSepW = 3;
00083 }
00084
00085 if (hTheme)
00086 _theme.DrawThemeBackground (hTheme, pdc->GetSafeHdc (), 1 , 0, &rc, NULL);
00087 else
00088 pdc->FillSolidRect (&rc, GetSysColor (COLOR_3DFACE));
00089
00090 fs::list <CSize> vParts;
00091
00092 rc.top += nSepW;
00093 rc.bottom -= nSepW;
00094 rc.left += nSepW + (nSepW ? 1 : 0);
00095 rc.right -= nSepW;
00096
00097
00098 std::vector <vmsSectionInfo> v;
00099 pthis->m_dld->pMgr->GetSplittedSectionsList (v);
00100
00101 for (size_t i = 0; i < v.size (); i++)
00102 {
00103 vmsSectionInfo § = v [i];
00104
00105 CSize part;
00106 part.cy = rc.left + (int)((double)(INT64)sect.uDCurrent / (INT64)uSize * rc.Width ());
00107 part.cx = rc.left + (int)((double)(INT64)sect.uDStart / (INT64)uSize * rc.Width ());
00108
00109 if (part.cy == part.cx)
00110 {
00111 if (pthis->m_dld->pMgr->IsBittorrent ())
00112 continue;
00113 part.cy++;
00114 }
00115
00116 vParts.add (part);
00117 }
00118
00119
00120 for (i = 0; i < (size_t)vParts.size (); i++)
00121 {
00122 CSize& part = vParts [i];
00123
00124 for (size_t j = i + 1; j < (size_t)vParts.size (); j++)
00125 {
00126 if (part.cy == vParts [j].cx)
00127 {
00128 part.cy = vParts [j].cy;
00129 vParts.del (j);
00130 i--;
00131 break;
00132 }
00133
00134 if (part.cx == vParts [j].cy)
00135 {
00136 part.cx = vParts [j].cx;
00137 vParts.del (j);
00138 i--;
00139 break;
00140 }
00141 }
00142 }
00143
00144 for (i = 0; i < (size_t)vParts.size (); i++)
00145 {
00146 CRect rc2 = rc;
00147
00148 rc2.left = vParts [i].cx;
00149 rc2.right = vParts [i].cy;
00150
00151 if (hTheme)
00152 _theme.DrawThemeBackground (hTheme, pdc->GetSafeHdc (), 3 , 0, &rc2, NULL);
00153 else
00154 pdc->FillSolidRect (&rc2, clr);
00155 }
00156
00157 if (hTheme)
00158 _theme.CloseThemeData (hTheme);
00159
00160 pthis->m_renderer.End ();
00161
00162 pthis->ReleaseDC (dc);
00163 ResetEvent (pthis->m_hevDraw);
00164 }
00165
00166 return 0;
00167 }