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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
#include "stdafx.h"
class CDlgOptionsDlg : public CDlgBase
{
HANDLE hItemAll, hItemNew;
void SetListGroupIcons(HANDLE hFirstItem, HANDLE hParentItem, int *groupChildCount = nullptr)
{
int iconOn = 1;
int childCount = 0;
int typeOfFirst = clist.GetItemType(hFirstItem);
// check groups
HANDLE hItem = (typeOfFirst == CLCIT_GROUP) ? hFirstItem : clist.GetNextItem(hFirstItem, CLGN_NEXTGROUP);
while (hItem) {
HANDLE hChildItem = clist.GetNextItem(hItem, CLGN_CHILD);
if (hChildItem)
SetListGroupIcons(hChildItem, hItem, &childCount);
if (iconOn && clist.GetExtraImage(hItem, 0) == 0)
iconOn = 0;
hItem = clist.GetNextItem(hItem, CLGN_NEXTGROUP);
}
// check contacts
hItem = (typeOfFirst == CLCIT_CONTACT) ? hFirstItem : clist.GetNextItem(hFirstItem, CLGN_NEXTCONTACT);
while (hItem) {
int iImage = clist.GetExtraImage(hItem, 0);
if (iconOn && iImage == 0)
iconOn = 0;
if (iImage != EMPTY_EXTRA_ICON)
childCount++;
hItem = clist.GetNextItem(hItem, CLGN_NEXTCONTACT);
}
// set icons
clist.SetExtraImage(hParentItem, 0, childCount ? (iconOn ? 1 : 0) : EMPTY_EXTRA_ICON);
if (groupChildCount)
*groupChildCount += childCount;
}
void SetAllChildIcons(HANDLE hFirstItem, int iColumn, int iImage)
{
int typeOfFirst = clist.GetItemType(hFirstItem);
// check groups
HANDLE hItem = (typeOfFirst == CLCIT_GROUP) ? hFirstItem : clist.GetNextItem(hFirstItem, CLGN_NEXTGROUP);
while (hItem) {
HANDLE hChildItem = clist.GetNextItem(hItem, CLGN_CHILD);
if (hChildItem)
SetAllChildIcons(hChildItem, iColumn, iImage);
hItem = clist.GetNextItem(hItem, CLGN_NEXTGROUP);
}
// check contacts
hItem = (typeOfFirst == CLCIT_CONTACT) ? hFirstItem : clist.GetNextItem(hFirstItem, CLGN_NEXTCONTACT);
while (hItem) {
int iOldIcon = clist.GetExtraImage(hItem, iColumn);
if (iOldIcon != EMPTY_EXTRA_ICON && iOldIcon != iImage)
clist.SetExtraImage(hItem, iColumn, iImage);
hItem = clist.GetNextItem(hItem, CLGN_NEXTCONTACT);
}
}
void SetAllContactIcons()
{
for (auto &hContact : Contacts()) {
if (!Contact::IsGroupChat(hContact)) {
HANDLE hItem = clist.FindContact(hContact);
if (hItem) {
bool disabled = (g_plugin.getByte(hContact, DBSETTING_REMOVE) == 1);
clist.SetExtraImage(hItem, 0, disabled ? 1 : 0);
}
}
}
}
CCtrlClc clist;
CCtrlCheck chkOnStartup;
public:
CDlgOptionsDlg() :
CDlgBase(g_plugin, IDD_OPT),
clist(this, IDC_LIST),
chkOnStartup(this, IDC_ONSTARTUP)
{
CreateLink(chkOnStartup, g_plugin.bWipeOnStartup);
clist.OnNewContact = clist.OnListRebuilt = Callback(this, &CDlgOptionsDlg::onListRebuilt);
clist.OnOptionsChanged = Callback(this, &CDlgOptionsDlg::onOptionsChanged);
clist.OnContactMoved = Callback(this, &CDlgOptionsDlg::onContactMoved);
clist.OnClick = Callback(this, &CDlgOptionsDlg::onClick);
}
bool OnInitDialog() override
{
HIMAGELIST hIml = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32 | ILC_MASK, 2, 2);
g_plugin.addImgListIcon(hIml, IDI_HKEEP);
g_plugin.addImgListIcon(hIml, IDI_HREMOVE);
clist.SetExtraImageList(hIml);
SendDlgItemMessage(m_hwnd, IDC_PIC_KEEP, STM_SETICON, (WPARAM)g_plugin.getIcon(IDI_HKEEP), 0);
SendDlgItemMessage(m_hwnd, IDC_PIC_REMOVE, STM_SETICON, (WPARAM)g_plugin.getIcon(IDI_HREMOVE), 0);
onOptionsChanged(0);
clist.SetExtraColumns(1);
CLCINFOITEM cii = { sizeof(cii) };
cii.flags = CLCIIF_GROUPFONT;
cii.pszText = TranslateT("** All contacts **");
hItemAll = clist.AddInfoItem(&cii);
cii.pszText = TranslateT("** New contacts **");
hItemNew = clist.AddInfoItem(&cii);
clist.SetExtraImage(hItemNew, 0, g_plugin.bEnabledForNew);
onListRebuilt(0);
SetFocus(clist.GetHwnd());
SendDlgItemMessage(m_hwnd, IDC_SPN_TIMEOUT, UDM_SETRANGE, 0, (LPARAM)MAKELONG(60 * 60, 1));
return true;
}
bool OnApply() override
{
g_plugin.bEnabledForNew = clist.GetExtraImage(hItemNew, 0);
for (auto &hContact : Contacts()) {
if (!Contact::IsGroupChat(hContact)) {
HANDLE hItem = clist.FindContact(hContact);
if (hItem) {
int iImage = clist.GetExtraImage(hItem, 0);
g_plugin.setByte(hContact, DBSETTING_REMOVE, iImage == 1);
}
}
}
return true;
}
void OnDestroy() override
{
ImageList_Destroy(clist.GetExtraImageList());
}
void onListRebuilt(CCtrlClc::TEventInfo *)
{
SetAllContactIcons();
SetListGroupIcons(clist.GetNextItem(CLGN_ROOT, 0), hItemAll);
}
void onOptionsChanged(CCtrlClc::TEventInfo *)
{
SetWindowLongPtr(clist.GetHwnd(), GWL_STYLE, GetWindowLongPtr(clist.GetHwnd(), GWL_STYLE) | CLS_SHOWHIDDEN | CLS_HIDEEMPTYGROUPS);
}
void onContactMoved(CCtrlClc::TEventInfo *)
{
SetListGroupIcons(clist.GetNextItem(CLGN_ROOT, 0), hItemAll);
}
void onClick(CCtrlClc::TEventInfo *ev)
{
// Make sure we have an extra column
NMCLISTCONTROL *nm = ev->info;
if (nm->iColumn == -1)
return;
// Find clicked item
uint32_t hitFlags;
HANDLE hItem = clist.HitTest(nm->pt.x, nm->pt.y, &hitFlags);
if (hItem == nullptr || !(hitFlags & CLCHT_ONITEMEXTRA))
return;
// Get image in clicked column
int iImage = clist.GetExtraImage(hItem, 0);
if (iImage == 0)
iImage = 0 + 1;
else if (iImage == 1)
iImage = 0;
// Update list, making sure that the options are mutually exclusive
switch (clist.GetItemType(hItem)) {
case CLCIT_CONTACT:
clist.SetExtraImage(hItem, 0, iImage);
break;
case CLCIT_INFO:
if (hItem == hItemAll)
SetAllChildIcons(hItem, 0, iImage);
else
clist.SetExtraImage(hItem, 0, iImage);
break;
case CLCIT_GROUP:
hItem = clist.GetNextItem(hItem, CLGN_CHILD);
if (hItem)
SetAllChildIcons(hItem, 0, iImage);
}
// Update the all/none icons
SetListGroupIcons(clist.GetNextItem(CLGN_ROOT, 0), hItemAll);
// Activate Apply button
NotifyChange();
}
};
int OptInit(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = {};
odp.flags = ODPF_BOLDGROUPS;
odp.position = -790000000;
odp.szGroup.a = LPGEN("History");
odp.szTitle.a = LPGEN("No History");
odp.szTab.a = LPGEN("Logging");
odp.pDialog = new CDlgOptionsDlg();
g_plugin.addOptions(wParam, &odp);
return 0;
}
|