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
|
#include "StdAfx.h"
#include "ListCtrlSetter.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
ListCtrlSetter::ListCtrlSetter( CListCtrl &list ) :
m_List( list ),
m_nLineNo( -1 )
{
}
ListCtrlSetter::~ListCtrlSetter()
{
}
void
ListCtrlSetter::modifyLine( int nLineNo )
{
editLine( nLineNo, nLineNo >= m_List.GetItemCount() );
}
void
ListCtrlSetter::addLine()
{
editLine( m_List.GetItemCount(), true );
}
void
ListCtrlSetter::insertLine( int nLineNo )
{
editLine( nLineNo, true );
}
void
ListCtrlSetter::editLine( int nLineNo,
bool bInsertLine )
{
m_nLineNo = nLineNo;
m_bInsertLine = bInsertLine;
m_nNextSubItem = 0;
}
void
ListCtrlSetter::addSubItem( const CString &strText )
{
doAddSubItem( LVIF_TEXT, strText, 0 );
}
void
ListCtrlSetter::addSubItem( const CString &strText,
void *lParam )
{
doAddSubItem( LVIF_TEXT | LVIF_PARAM, strText, 0, lParam );
}
void
ListCtrlSetter::addSubItem( const CString &strText,
int nImage )
{
doAddSubItem( LVIF_TEXT | LVIF_IMAGE, strText, nImage );
}
void
ListCtrlSetter::addSubItem( const CString &strText,
void *lParam,
int nImage )
{
doAddSubItem( LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM, strText, 0, lParam );
}
void
ListCtrlSetter::doAddSubItem( UINT nMask,
CString strText,
int nImage,
void *lParam )
{
int textLength = strText.GetLength();
LVITEM item;
item.mask = nMask;
item.pszText = strText.GetBuffer( textLength );
item.cchTextMax = textLength;
item.iImage = nImage;
item.lParam = (LPARAM)lParam;
item.iItem = m_nLineNo;
item.iSubItem = m_nNextSubItem++;
if ( m_nNextSubItem == 1 &&
m_bInsertLine ) // First item & new line
{
m_nLineNo = m_List.InsertItem( &item );
VERIFY( m_nLineNo >= 0 );
}
else
{
VERIFY( m_List.SetItem( &item ) );
}
strText.ReleaseBuffer();
}
int
ListCtrlSetter::getLineNo() const
{
return m_nLineNo;
}
|