-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathListCtrlEx.cpp
139 lines (123 loc) · 3.21 KB
/
ListCtrlEx.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// This file is part of Par-N-Rar
// http://www.milow.net/site/projects/parnrar.html
//
// Copyright (c) Gil Milow
//
// Par-N-Rar is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Par-N-Rar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// This code may not be used to develop a RAR (WinRAR) compatible archiver.
//
#include "stdafx.h"
#include "ListCtrlEx.h"
IMPLEMENT_DYNAMIC(CListCtrlEx, CListCtrl)
CListCtrlEx::CListCtrlEx() : m_ProgressColumn(0)
{
}
CListCtrlEx::~CListCtrlEx()
{
int Count = m_ProgressList.GetSize();
for (int i = 0; i < Count; i++)
{
CProgressCtrl* pCtrl = m_ProgressList.GetAt(0);
pCtrl->DestroyWindow();
delete pCtrl;
m_ProgressList.RemoveAt(0);
}
}
BEGIN_MESSAGE_MAP(CListCtrlEx, CListCtrl)
ON_WM_PAINT()
END_MESSAGE_MAP()
void CListCtrlEx::OnPaint()
{
int i;
int Top = GetTopIndex();
int Total = GetItemCount();
int PerPage = GetCountPerPage();
int Last = ((Top+PerPage) > Total)? Total : Top+PerPage;
CProgressCtrl* pCtrl;
CHeaderCtrl* pHeader = GetHeaderCtrl();
for (i = Top; i < Last; i++)
{
CRect ColRt;
pHeader->GetItemRect(m_ProgressColumn, &ColRt);
CRect rt;
GetItemRect(i, &rt, LVIR_LABEL);
rt.top += 1;
rt.bottom -= 1;
rt.left += ColRt.left;
rt.right = rt.left + ColRt.Width() - 4;
ValidateRect( rt );
pCtrl = m_ProgressList.GetAt(i-Top);
CString strPercent = GetItemText(i, m_ProgressColumn);
int nPercent = atoi(strPercent);
pCtrl->SetPos(nPercent);
pCtrl->MoveWindow(&rt);
pCtrl->Invalidate();
}
CListCtrl::OnPaint();
}
int CListCtrlEx::InsertItem(int nItem, LPCSTR lpszItem, int nImage)
{
try
{
CreateProgressCtrl();
return CListCtrl::InsertItem(nItem, lpszItem, nImage);
}catch(...)
{
MessageBox("Error inserting item.", "Error");
}
}
int CListCtrlEx::InsertItem(const LVITEM* pItem)
{
try
{
CreateProgressCtrl();
return CListCtrl::InsertItem(pItem);
}catch(...)
{
MessageBox("Error inserting item.", "Error");
}
}
int CListCtrlEx::InsertItem(int nItem, LPCTSTR lpszItem)
{
try
{
CreateProgressCtrl();
return CListCtrl::InsertItem(nItem, lpszItem);
}catch(...)
{
MessageBox("Error inserting item.", "Error");
}
}
void CListCtrlEx::CreateProgressCtrl()
{
CProgressCtrl* pCtrl = new CProgressCtrl();
CRect rt(1,1,1,1);
pCtrl->Create(NULL, rt, this, IDC_PROGRESS_LIST + GetItemCount() + 1);
m_ProgressList.Add(pCtrl);
pCtrl->ShowWindow(SW_SHOWNORMAL);
}
void CListCtrlEx::InitProgressColumn(int ColNum)
{
m_ProgressColumn = ColNum;
}
BOOL CListCtrlEx::DeleteItem(int nItem)
{
delete m_ProgressList.GetAt(nItem);
m_ProgressList.RemoveAt(nItem);
BOOL bRet = CListCtrl::DeleteItem(nItem);
CListCtrl::Invalidate();
return bRet;
}