-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
notifyiconscust.cpp
266 lines (227 loc) · 8.58 KB
/
notifyiconscust.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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
* ReactOS Explorer
*
* Copyright 2015 Jared Smudde <computerwhiz02@hotmail.com>
* Copyright 2018 Denis Malikov <filedem@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "precomp.h"
VOID ShowBehaviorCombo(HWND hwnd, LPNMITEMACTIVATE itemdata)
{
HWND hListView = GetDlgItem(hwnd, IDC_NOTIFICATION_LIST);
HWND hCombo = GetDlgItem(hwnd, IDC_NOTIFICATION_BEHAVIOUR);
if (ComboBox_GetCount(hCombo) == 0)
{
WCHAR sShow[100];
WCHAR sHide[100];
WCHAR sInactive[100];
LoadStringW(NULL, IDS_NOTIF_BEH_SHOW, sShow, _countof(sShow));
LoadStringW(NULL, IDS_NOTIF_BEH_HIDE, sHide, _countof(sHide));
LoadStringW(NULL, IDS_NOTIF_BEH_HIDE_INACTIVE, sInactive, _countof(sInactive));
ComboBox_AddString(hCombo, sShow);
ComboBox_AddString(hCombo, sHide);
ComboBox_AddString(hCombo, sInactive);
ComboBox_SetCurSel(hCombo, 0);
}
int iItem = itemdata->iItem;
if (iItem > -1)
{
POINT pt;
RECT rc;
ListView_GetItemPosition(hListView, iItem, &pt);
GetWindowRect(hListView, &rc);
POINT lv = { rc.left, rc.top };
ScreenToClient(hwnd, &lv);
LVITEM lvItem;
lvItem.iItem = iItem;
lvItem.iSubItem = 0;
lvItem.mask = LVIF_PARAM;
ListView_GetItem(hListView, &lvItem);
ComboBox_SetCurSel(hCombo, lvItem.lParam);
int iNameWidth = ListView_GetColumnWidth(hListView, 0);
int iBehaviorWidth = ListView_GetColumnWidth(hListView, 1);
ComboBox_SetItemData(hCombo, 0, iItem);
SetWindowPos(hCombo, HWND_TOP, iNameWidth + lv.x, pt.y + lv.y, iBehaviorWidth, 20, SWP_SHOWWINDOW);
}
else
{
ShowWindow(hCombo, SW_HIDE);
}
}
VOID SetItemBehavior(HWND hwnd, HWND hCombo)
{
int iState = ComboBox_GetCurSel(hCombo);
int iItem = (int)ComboBox_GetItemData(hCombo, 0);
HWND hListView = GetDlgItem(hwnd, IDC_NOTIFICATION_LIST);
WCHAR szBehavior[100];
int resId = iState == 0 ? IDS_NOTIF_BEH_SHOW : (iState == 1 ? IDS_NOTIF_BEH_HIDE : IDS_NOTIF_BEH_HIDE_INACTIVE);
LoadStringW(NULL, resId, szBehavior, _countof(szBehavior));
LVITEM lvItem;
ZeroMemory(&lvItem, sizeof(lvItem));
lvItem.mask = LVIF_TEXT;
lvItem.iItem = iItem;
lvItem.iSubItem = 1;
lvItem.cchTextMax = 100;
lvItem.pszText = szBehavior;
ListView_SetItem(hListView, &lvItem);
ZeroMemory(&lvItem, sizeof(lvItem));
lvItem.mask = LVIF_PARAM;
lvItem.iSubItem = 0;
lvItem.lParam = iState;
lvItem.iItem = iItem;
ListView_SetItem(hListView, &lvItem);
ShowWindow(hCombo, SW_HIDE);
}
VOID ResetBehaviors(HWND hwnd)
{
HWND hListView = GetDlgItem(hwnd, IDC_NOTIFICATION_LIST);
int count = ListView_GetItemCount(hListView);
WCHAR szBehavior[100];
LoadStringW(NULL, IDS_NOTIF_BEH_HIDE_INACTIVE, szBehavior, _countof(szBehavior));
LVITEM lviBehavior;
ZeroMemory(&lviBehavior, sizeof(lviBehavior));
lviBehavior.mask = LVIF_TEXT;
lviBehavior.iSubItem = 1;
lviBehavior.cchTextMax = 100;
lviBehavior.pszText = szBehavior;
LVITEM lviName;
ZeroMemory(&lviName, sizeof(lviName));
lviName.mask = LVIF_PARAM;
lviName.iSubItem = 0;
lviName.lParam = 2;
for (int i = 0; i < count; i++)
{
lviName.iItem = i;
ListView_SetItem(hListView, &lviName);
lviBehavior.iItem = i;
ListView_SetItem(hListView, &lviBehavior);
}
}
VOID InitializeListView(HWND hwnd)
{
HWND hListView = GetDlgItem(hwnd, IDC_NOTIFICATION_LIST);
LVCOLUMN lvColumn;
WCHAR sName[256];
SendMessage(hListView, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
ZeroMemory(&lvColumn, sizeof(lvColumn));
lvColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
LoadStringW(NULL, IDS_NOTIF_BEH_NAME, sName, _countof(sName));
lvColumn.pszText = sName;
lvColumn.cx = 190;
ListView_InsertColumn(hListView, 0, &lvColumn);
LoadStringW(NULL, IDS_NOTIF_BEH_BEHAVIOR, sName, _countof(sName));
lvColumn.pszText = sName;
lvColumn.cx = 130;
ListView_InsertColumn(hListView, 1, &lvColumn);
ListView_EnableGroupView(hListView, TRUE);
LVGROUP lvGroup;
lvGroup.cbSize = sizeof(LVGROUP);
lvGroup.mask = LVGF_HEADER | LVGF_ALIGN | LVGF_GROUPID | LVGF_STATE;
lvGroup.uAlign = LVGA_FOOTER_LEFT;
lvGroup.state = LVGS_NORMAL;
LoadStringW(NULL, IDS_NOTIF_BEH_CURRENT, sName, _countof(sName));
lvGroup.pszHeader = sName;
lvGroup.iGroupId = 0;
ListView_InsertGroup(hListView, -1, &lvGroup);
LoadStringW(NULL, IDS_NOTIF_BEH_PAST, sName, _countof(sName));
lvGroup.pszHeader = sName;
lvGroup.iGroupId = 1;
ListView_InsertGroup(hListView, -1, &lvGroup);
}
INT_PTR CALLBACK CustomizeNotifyIconsProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
InitializeListView(hwnd);
break;
case WM_NOTIFY:
if (LOWORD(wParam) == IDC_NOTIFICATION_LIST && ((LPNMHDR)lParam)->code == NM_CLICK)
{
ShowBehaviorCombo(hwnd, (LPNMITEMACTIVATE)lParam);
}
else return FALSE;
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hwnd, IDOK);
break;
case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
break;
case IDC_NOTIFICATION_BEHAVIOUR:
if (HIWORD(wParam) == CBN_SELCHANGE)
{
SetItemBehavior(hwnd, (HWND)lParam);
}
break;
case IDC_TASKBARPROP_NOTIREST:
ResetBehaviors(hwnd);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
VOID SetNotifyIcons(HWND hDialog, HWND hTrayNotify)
{
HWND hListView = GetDlgItem(hDialog, IDC_NOTIFICATION_LIST);
HWND hSysPager = FindWindowEx(hTrayNotify, NULL, L"SysPager", NULL);
HWND hToolbar = FindWindowEx(hSysPager, NULL, L"ToolbarWindow32", NULL);
HIMAGELIST tbImageList = (HIMAGELIST)SendMessage(hToolbar, TB_GETIMAGELIST, 0, 0);
HIMAGELIST lvImageList = ImageList_Duplicate(tbImageList);
ListView_SetImageList(hListView, lvImageList, LVSIL_SMALL);
WCHAR sShow[100];
WCHAR sHide[100];
WCHAR sInactive[100];
LoadStringW(NULL, IDS_NOTIF_BEH_SHOW, sShow, _countof(sShow));
LoadStringW(NULL, IDS_NOTIF_BEH_HIDE, sHide, _countof(sHide));
LoadStringW(NULL, IDS_NOTIF_BEH_HIDE_INACTIVE, sInactive, _countof(sInactive));
LVITEM lvItem;
TBBUTTON tbtn;
DWORD nButtons = (DWORD)SendMessage(hToolbar, TB_BUTTONCOUNT, 0, 0);
for (UINT i = 0; i != nButtons; i++)
{
if (SendMessage(hToolbar, TB_GETBUTTON, (WPARAM)i, (LPARAM)&tbtn))
{
ZeroMemory(&lvItem, sizeof(lvItem));
lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_GROUPID | LVIF_PARAM;
lvItem.cchTextMax = 256;
lvItem.iImage = tbtn.iBitmap;
lvItem.iItem = i;
lvItem.pszText = ((NOTIFYICONDATA*)tbtn.dwData)->szTip;
lvItem.lParam = i % 3;
ListView_InsertItem(hListView, &lvItem);
ZeroMemory(&lvItem, sizeof(lvItem));
lvItem.mask = LVIF_TEXT;
lvItem.iItem = i;
lvItem.iSubItem = 1;
lvItem.cchTextMax = 100;
lvItem.pszText = (i % 3) == 0 ? sShow : ((i % 3) == 1 ? sHide : sInactive);
ListView_SetItem(hListView, &lvItem);
}
}
}
VOID ShowCustomizeNotifyIcons(HINSTANCE hInst, HWND hExplorer, HWND hTrayNotify)
{
HWND hDlg = CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_NOTIFICATIONS_CUSTOMIZE), hExplorer, CustomizeNotifyIconsProc);
SetNotifyIcons(hDlg, hTrayNotify);
ShowWindow(hDlg, SW_SHOW);
}