125896f2aeb1a1d1ce9ca21b8098a7007c8dbd0e
[reactos.git] / reactos / base / shell / explorer / trayprop.cpp
1 /*
2 * ReactOS Explorer
3 *
4 * Copyright 2006 - 2007 Thomas Weidenmueller <w3seek@reactos.org>
5 * 2015 Robert Naumann <gonzomdx@gmail.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "precomp.h"
23
24 typedef struct _PROPSHEET_INFO
25 {
26 HWND hTaskbarWnd;
27 HWND hStartWnd;
28
29 HBITMAP hTaskbarBitmap;
30 HBITMAP hTrayBitmap;
31 } PROPSHEET_INFO, *PPROPSHEET_INFO;
32
33
34 static BOOL
35 UpdateTaskbarBitmap(PPROPSHEET_INFO pPropInfo)
36 {
37 HWND hwndLock, hwndHide, hwndGroup, hwndShowQL, hwndClock, hwndSeconds, hwndHideInactive;
38 HWND hwndTaskbarBitmap, hwndTrayBitmap;
39 HWND hwndAdvancedButton;
40 BOOL bLock, bHide, bGroup, bShowQL, bShowClock, bShowSeconds, bHideInactive;
41 LPTSTR lpTaskBarImageName = NULL, lpTrayImageName = NULL;
42 BOOL bRet = FALSE;
43
44 hwndLock = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_LOCK);
45 hwndHide = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_HIDE);
46 hwndGroup = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_GROUP);
47 hwndShowQL = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_SHOWQL);
48
49 hwndClock = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_CLOCK);
50 hwndSeconds = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_SECONDS);
51 hwndHideInactive = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_HIDEICONS);
52
53 hwndAdvancedButton = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_ICONCUST);
54
55 if (hwndLock && hwndHide && hwndGroup && hwndShowQL && hwndClock && hwndSeconds && hwndHideInactive)
56 {
57 bLock = (SendMessage(hwndLock, BM_GETCHECK, 0, 0) == BST_CHECKED);
58 bHide = (SendMessage(hwndHide, BM_GETCHECK, 0, 0) == BST_CHECKED);
59 bGroup = (SendMessage(hwndGroup, BM_GETCHECK, 0, 0) == BST_CHECKED);
60 bShowQL = (SendMessage(hwndShowQL, BM_GETCHECK, 0, 0) == BST_CHECKED);
61
62 bShowClock = (SendMessage(hwndClock, BM_GETCHECK, 0, 0) == BST_CHECKED);
63 bShowSeconds = (SendMessage(hwndSeconds, BM_GETCHECK, 0, 0) == BST_CHECKED);
64 bHideInactive = (SendMessage(hwndHideInactive, BM_GETCHECK, 0, 0) == BST_CHECKED);
65
66 if (bHide)
67 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_AUTOHIDE);
68 else if (bLock && bGroup && bShowQL)
69 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_LOCK_GROUP_QL);
70 else if (bLock && !bGroup && !bShowQL)
71 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_LOCK_NOGROUP_NOQL);
72 else if (bLock && bGroup && !bShowQL)
73 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_LOCK_GROUP_NOQL);
74 else if (bLock && !bGroup && bShowQL)
75 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_LOCK_NOGROUP_QL);
76 else if (!bLock && !bGroup && !bShowQL)
77 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_NOLOCK_NOGROUP_NOQL);
78 else if (!bLock && bGroup && !bShowQL)
79 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_NOLOCK_GROUP_NOQL);
80 else if (!bLock && !bGroup && bShowQL)
81 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_NOLOCK_NOGROUP_QL);
82 else if (!bLock && bGroup && bShowQL)
83 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_NOLOCK_GROUP_QL);
84
85
86 if (lpTaskBarImageName)
87 {
88 if (pPropInfo->hTaskbarBitmap)
89 {
90 DeleteObject(pPropInfo->hTaskbarBitmap);
91 }
92
93 pPropInfo->hTaskbarBitmap = (HBITMAP)LoadImageW(hExplorerInstance,
94 lpTaskBarImageName,
95 IMAGE_BITMAP,
96 0,
97 0,
98 LR_DEFAULTCOLOR);
99 if (pPropInfo->hTaskbarBitmap)
100 {
101 hwndTaskbarBitmap = GetDlgItem(pPropInfo->hTaskbarWnd,
102 IDC_TASKBARPROP_TASKBARBITMAP);
103 if (hwndTaskbarBitmap)
104 {
105 SendMessage(hwndTaskbarBitmap,
106 STM_SETIMAGE,
107 IMAGE_BITMAP,
108 (LPARAM)pPropInfo->hTaskbarBitmap);
109 }
110 }
111 }
112
113 if (bHideInactive)
114 {
115 EnableWindow(hwndAdvancedButton, TRUE);
116 if (bShowClock)
117 {
118 EnableWindow(hwndSeconds, TRUE);
119 if (bShowSeconds)
120 lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_HIDE_SECONDS);
121 else
122 lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_HIDE_CLOCK);
123 }
124 else
125 {
126 SendMessage(hwndSeconds, BM_SETCHECK, BST_UNCHECKED, 0);
127 EnableWindow(hwndSeconds, FALSE);
128 lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_HIDE_NOCLOCK);
129 }
130 }
131 else
132 {
133 EnableWindow(hwndAdvancedButton, FALSE);
134 if (bShowClock)
135 {
136 EnableWindow(hwndSeconds, TRUE);
137 if (bShowSeconds)
138 lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_SHOW_SECONDS);
139 else
140 lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_SHOW_CLOCK);
141 }
142 else
143 {
144 SendMessage(hwndSeconds, BM_SETCHECK, BST_UNCHECKED, 0);
145 EnableWindow(hwndSeconds, FALSE);
146 lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_SHOW_NOCLOCK);
147 }
148 }
149
150 if (lpTrayImageName)
151 {
152 if (pPropInfo->hTrayBitmap)
153 {
154 DeleteObject(pPropInfo->hTrayBitmap);
155 }
156
157 pPropInfo->hTrayBitmap = (HBITMAP)LoadImageW(hExplorerInstance,
158 lpTrayImageName,
159 IMAGE_BITMAP,
160 0,
161 0,
162 LR_DEFAULTCOLOR);
163 if (pPropInfo->hTrayBitmap)
164 {
165 hwndTrayBitmap = GetDlgItem(pPropInfo->hTaskbarWnd,
166 IDC_TASKBARPROP_NOTIFICATIONBITMAP);
167 if (hwndTrayBitmap)
168 {
169 SendMessage(hwndTrayBitmap,
170 STM_SETIMAGE,
171 IMAGE_BITMAP,
172 (LPARAM)pPropInfo->hTrayBitmap);
173 }
174 }
175 }
176 }
177
178 return bRet;
179 }
180
181 static VOID
182 OnCreateTaskbarPage(HWND hwnd,
183 PPROPSHEET_INFO pPropInfo)
184 {
185 SetWindowLongPtr(hwnd,
186 GWLP_USERDATA,
187 (LONG_PTR)pPropInfo);
188
189 pPropInfo->hTaskbarWnd = hwnd;
190
191 // FIXME: check buttons
192 CheckDlgButton(hwnd, IDC_TASKBARPROP_SECONDS, AdvancedSettings.bShowSeconds ? BST_CHECKED : BST_UNCHECKED);
193
194 UpdateTaskbarBitmap(pPropInfo);
195 }
196
197 INT_PTR CALLBACK
198 TaskbarPageProc(HWND hwndDlg,
199 UINT uMsg,
200 WPARAM wParam,
201 LPARAM lParam)
202 {
203 PPROPSHEET_INFO pPropInfo;
204
205 /* Get the window context */
206 pPropInfo = (PPROPSHEET_INFO)GetWindowLongPtrW(hwndDlg,
207 GWLP_USERDATA);
208 if (pPropInfo == NULL && uMsg != WM_INITDIALOG)
209 {
210 goto HandleDefaultMessage;
211 }
212
213 switch (uMsg)
214 {
215 case WM_INITDIALOG:
216 OnCreateTaskbarPage(hwndDlg, (PPROPSHEET_INFO)((LPPROPSHEETPAGE)lParam)->lParam);
217 break;
218
219 case WM_COMMAND:
220 switch (LOWORD(wParam))
221 {
222 case IDC_TASKBARPROP_LOCK:
223 case IDC_TASKBARPROP_HIDE:
224 case IDC_TASKBARPROP_GROUP:
225 case IDC_TASKBARPROP_SHOWQL:
226 case IDC_TASKBARPROP_HIDEICONS:
227 case IDC_TASKBARPROP_CLOCK:
228 case IDC_TASKBARPROP_SECONDS:
229 if (HIWORD(wParam) == BN_CLICKED)
230 {
231 UpdateTaskbarBitmap(pPropInfo);
232
233 /* Enable the 'Apply' button */
234 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
235 }
236 break;
237 case IDC_TASKBARPROP_ICONCUST:
238 ShowCustomizeNotifyIcons(hExplorerInstance, hwndDlg);
239 break;
240 }
241 break;
242
243 case WM_NOTIFY:
244 {
245 LPNMHDR pnmh = (LPNMHDR)lParam;
246
247 switch (pnmh->code)
248 {
249 case PSN_SETACTIVE:
250 break;
251
252 case PSN_APPLY:
253 AdvancedSettings.bShowSeconds = IsDlgButtonChecked(hwndDlg, IDC_TASKBARPROP_SECONDS);
254 SaveSettingDword(szAdvancedSettingsKey, TEXT("ShowSeconds"), AdvancedSettings.bShowSeconds);
255 break;
256 }
257
258 break;
259 }
260
261 case WM_DESTROY:
262 if (pPropInfo->hTaskbarBitmap)
263 {
264 DeleteObject(pPropInfo->hTaskbarBitmap);
265 }
266 if (pPropInfo->hTrayBitmap)
267 {
268 DeleteObject(pPropInfo->hTrayBitmap);
269 }
270 break;
271
272 HandleDefaultMessage:
273 default:
274 return FALSE;
275 }
276
277 return FALSE;
278 }
279
280 static INT_PTR CALLBACK
281 StartMenuPageProc(HWND hwndDlg,
282 UINT uMsg,
283 WPARAM wParam,
284 LPARAM lParam)
285 {
286 switch (uMsg)
287 {
288 case WM_INITDIALOG:
289 break;
290
291 case WM_COMMAND:
292 {
293 switch (LOWORD(wParam))
294 {
295 case IDC_TASKBARPROP_STARTMENUCLASSICCUST:
296 ShowCustomizeClassic(hExplorerInstance, hwndDlg);
297 break;
298 }
299 break;
300 }
301
302 case WM_DESTROY:
303 break;
304
305 case WM_NOTIFY:
306 {
307 LPNMHDR pnmh = (LPNMHDR)lParam;
308
309 switch (pnmh->code)
310 {
311 case PSN_SETACTIVE:
312 break;
313
314 case PSN_APPLY:
315 break;
316 }
317
318 break;
319 }
320 }
321
322 return FALSE;
323 }
324
325 static VOID
326 InitPropSheetPage(PROPSHEETPAGE *psp,
327 WORD idDlg,
328 DLGPROC DlgProc,
329 LPARAM lParam)
330 {
331 ZeroMemory(psp, sizeof(*psp));
332 psp->dwSize = sizeof(*psp);
333 psp->dwFlags = PSP_DEFAULT;
334 psp->hInstance = hExplorerInstance;
335 psp->pszTemplate = MAKEINTRESOURCEW(idDlg);
336 psp->lParam = lParam;
337 psp->pfnDlgProc = DlgProc;
338 }
339
340
341 VOID
342 DisplayTrayProperties(IN HWND hwndOwner)
343 {
344 PROPSHEET_INFO propInfo = {0};
345 PROPSHEETHEADER psh;
346 PROPSHEETPAGE psp[2];
347 WCHAR szCaption[256];
348
349 if (!LoadStringW(hExplorerInstance,
350 IDS_TASKBAR_STARTMENU_PROP_CAPTION,
351 szCaption,
352 _countof(szCaption)))
353 {
354 return;
355 }
356
357 ZeroMemory(&psh, sizeof(psh));
358 psh.dwSize = sizeof(psh);
359 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE;
360 psh.hwndParent = hwndOwner;
361 psh.hInstance = hExplorerInstance;
362 psh.hIcon = NULL;
363 psh.pszCaption = szCaption;
364 psh.nPages = _countof(psp);
365 psh.nStartPage = 0;
366 psh.ppsp = psp;
367
368 InitPropSheetPage(&psp[0], IDD_TASKBARPROP_TASKBAR, TaskbarPageProc, (LPARAM)&propInfo);
369 InitPropSheetPage(&psp[1], IDD_TASKBARPROP_STARTMENU, StartMenuPageProc, (LPARAM)&propInfo);
370
371 PropertySheet(&psh);
372 }