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
|
// ListViewDialog.cpp
#include "StdAfx.h"
#include "ListViewDialog.h"
#include "Common/Vector.h"
#ifdef LANG
#include "../../LangUtils.h"
static CIDLangPair kIDLangPairs[] =
{
{ IDOK, 0x02000702 },
{ IDCANCEL, 0x02000710 }
};
#endif
bool CListViewDialog::OnInit()
{
#ifdef LANG
LangSetDlgItemsText(HWND(*this), kIDLangPairs, sizeof(kIDLangPairs) / sizeof(kIDLangPairs[0]));
#endif
_listView.Attach(GetItem(IDC_LISTVIEW_LIST));
SetText(Title);
LVCOLUMN columnInfo;
columnInfo.mask = LVCF_FMT | LVCF_WIDTH | LVCF_SUBITEM;
columnInfo.fmt = LVCFMT_LEFT;
columnInfo.iSubItem = 0;
columnInfo.cx = 1000;
_listView.InsertColumn(0, &columnInfo);
for(int i = 0; i < Strings.Size(); i++)
{
LVITEMW item;
item.mask = LVIF_TEXT;
item.iItem = i;
item.pszText = (LPWSTR)(LPCWSTR)Strings[i];
item.iSubItem = 0;
_listView.InsertItem(&item);
}
if (Strings.Size() > 0)
_listView.SetItemState(0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
StringsWereChanged = false;
return CModalDialog::OnInit();
}
bool CListViewDialog::OnNotify(UINT /* controlID */, LPNMHDR header)
{
if (header->hwndFrom != _listView)
return false;
switch(header->code)
{
case LVN_KEYDOWN:
{
LPNMLVKEYDOWN keyDownInfo = LPNMLVKEYDOWN(header);
switch(keyDownInfo->wVKey)
{
case VK_DELETE:
{
if (!DeleteIsAllowed)
return false;
int focusedIndex = _listView.GetFocusedItem();
if (focusedIndex < 0)
focusedIndex = 0;
for (;;)
{
int index = _listView.GetNextSelectedItem(-1);
if (index < 0)
break;
StringsWereChanged = true;
_listView.DeleteItem(index);
Strings.Delete(index);
}
if (focusedIndex >= _listView.GetItemCount())
focusedIndex = _listView.GetItemCount() - 1;
if (focusedIndex >= 0)
_listView.SetItemState(focusedIndex, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
return true;
}
case 'A':
{
bool ctrl = (::GetKeyState(VK_CONTROL) & 0x8000) != 0;
if (ctrl)
{
int numItems = _listView.GetItemCount();
for (int i = 0; i < numItems; i++)
_listView.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
return true;
}
}
}
}
}
return false;
}
void CListViewDialog::OnOK()
{
FocusedItemIndex = _listView.GetFocusedItem();
CModalDialog::OnOK();
}
|