33167628c4263c546762ab40cfb69f5d1c3253e3
[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 HBITMAP hStartBitmap;
32 } PROPSHEET_INFO, *PPROPSHEET_INFO;
33
34
35 static BOOL
36 UpdateBitmaps(PPROPSHEET_INFO pPropInfo)
37 {
38 HWND hwndLock, hwndHide, hwndGroup, hwndShowQL, hwndClock, hwndSeconds, hwndHideInactive, hwndModernStart, hwndClassicStart;
39 HWND hwndTaskbarBitmap, hwndTrayBitmap, hwndStartBitmap;
40 HWND hwndCustomizeNotifyButton, hwndCustomizeClassicStartButton, hwndCustomizeModernStartButton;
41 BOOL bLock, bHide, bGroup, bShowQL, bShowClock, bShowSeconds, bHideInactive;
42 LPTSTR lpTaskBarImageName = NULL, lpTrayImageName = NULL, lpStartImageName = NULL;
43 BOOL bRet = FALSE;
44
45 hwndLock = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_LOCK);
46 hwndHide = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_HIDE);
47 hwndGroup = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_GROUP);
48 hwndShowQL = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_SHOWQL);
49
50 hwndClock = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_CLOCK);
51 hwndSeconds = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_SECONDS);
52 hwndHideInactive = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_HIDEICONS);
53
54 hwndCustomizeNotifyButton = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_ICONCUST);
55
56 hwndModernStart = GetDlgItem(pPropInfo->hStartWnd, IDC_TASKBARPROP_STARTMENU);
57 hwndClassicStart = GetDlgItem(pPropInfo->hStartWnd, IDC_TASKBARPROP_STARTMENUCLASSIC);
58
59 hwndCustomizeClassicStartButton = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_STARTMENUCLASSICCUST);
60 hwndCustomizeModernStartButton = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_STARTMENUCUST);
61
62
63
64 if (hwndLock && hwndHide && hwndGroup && hwndShowQL && hwndClock && hwndSeconds && hwndHideInactive)
65 {
66 bLock = (SendMessage(hwndLock, BM_GETCHECK, 0, 0) == BST_CHECKED);
67 bHide = (SendMessage(hwndHide, BM_GETCHECK, 0, 0) == BST_CHECKED);
68 bGroup = (SendMessage(hwndGroup, BM_GETCHECK, 0, 0) == BST_CHECKED);
69 bShowQL = (SendMessage(hwndShowQL, BM_GETCHECK, 0, 0) == BST_CHECKED);
70
71 bShowClock = (SendMessage(hwndClock, BM_GETCHECK, 0, 0) == BST_CHECKED);
72 bShowSeconds = (SendMessage(hwndSeconds, BM_GETCHECK, 0, 0) == BST_CHECKED);
73 bHideInactive = (SendMessage(hwndHideInactive, BM_GETCHECK, 0, 0) == BST_CHECKED);
74
75 if (bHide)
76 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_AUTOHIDE);
77 else if (bLock && bGroup && bShowQL)
78 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_LOCK_GROUP_QL);
79 else if (bLock && !bGroup && !bShowQL)
80 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_LOCK_NOGROUP_NOQL);
81 else if (bLock && bGroup && !bShowQL)
82 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_LOCK_GROUP_NOQL);
83 else if (bLock && !bGroup && bShowQL)
84 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_LOCK_NOGROUP_QL);
85 else if (!bLock && !bGroup && !bShowQL)
86 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_NOLOCK_NOGROUP_NOQL);
87 else if (!bLock && bGroup && !bShowQL)
88 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_NOLOCK_GROUP_NOQL);
89 else if (!bLock && !bGroup && bShowQL)
90 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_NOLOCK_NOGROUP_QL);
91 else if (!bLock && bGroup && bShowQL)
92 lpTaskBarImageName = MAKEINTRESOURCEW(IDB_TASKBARPROP_NOLOCK_GROUP_QL);
93
94
95 if (lpTaskBarImageName)
96 {
97 if (pPropInfo->hTaskbarBitmap)
98 {
99 DeleteObject(pPropInfo->hTaskbarBitmap);
100 }
101
102 pPropInfo->hTaskbarBitmap = (HBITMAP)LoadImageW(hExplorerInstance,
103 lpTaskBarImageName,
104 IMAGE_BITMAP,
105 0,
106 0,
107 LR_DEFAULTCOLOR);
108 if (pPropInfo->hTaskbarBitmap)
109 {
110 hwndTaskbarBitmap = GetDlgItem(pPropInfo->hTaskbarWnd,
111 IDC_TASKBARPROP_TASKBARBITMAP);
112 if (hwndTaskbarBitmap)
113 {
114 SendMessage(hwndTaskbarBitmap,
115 STM_SETIMAGE,
116 IMAGE_BITMAP,
117 (LPARAM)pPropInfo->hTaskbarBitmap);
118 }
119 }
120 }
121
122 if (bHideInactive)
123 {
124 EnableWindow(hwndCustomizeNotifyButton, TRUE);
125 if (bShowClock)
126 {
127 EnableWindow(hwndSeconds, TRUE);
128 if (bShowSeconds)
129 lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_HIDE_SECONDS);
130 else
131 lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_HIDE_CLOCK);
132 }
133 else
134 {
135 SendMessage(hwndSeconds, BM_SETCHECK, BST_UNCHECKED, 0);
136 EnableWindow(hwndSeconds, FALSE);
137 lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_HIDE_NOCLOCK);
138 }
139 }
140 else
141 {
142 EnableWindow(hwndCustomizeNotifyButton, FALSE);
143 if (bShowClock)
144 {
145 EnableWindow(hwndSeconds, TRUE);
146 if (bShowSeconds)
147 lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_SHOW_SECONDS);
148 else
149 lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_SHOW_CLOCK);
150 }
151 else
152 {
153 SendMessage(hwndSeconds, BM_SETCHECK, BST_UNCHECKED, 0);
154 EnableWindow(hwndSeconds, FALSE);
155 lpTrayImageName = MAKEINTRESOURCEW(IDB_SYSTRAYPROP_SHOW_NOCLOCK);
156 }
157 }
158
159 if (lpTrayImageName)
160 {
161 if (pPropInfo->hTrayBitmap)
162 {
163 DeleteObject(pPropInfo->hTrayBitmap);
164 }
165
166 pPropInfo->hTrayBitmap = (HBITMAP)LoadImageW(hExplorerInstance,
167 lpTrayImageName,
168 IMAGE_BITMAP,
169 0,
170 0,
171 LR_DEFAULTCOLOR);
172 if (pPropInfo->hTrayBitmap)
173 {
174 hwndTrayBitmap = GetDlgItem(pPropInfo->hTaskbarWnd,
175 IDC_TASKBARPROP_NOTIFICATIONBITMAP);
176 if (hwndTrayBitmap)
177 {
178 SendMessage(hwndTrayBitmap,
179 STM_SETIMAGE,
180 IMAGE_BITMAP,
181 (LPARAM)pPropInfo->hTrayBitmap);
182 }
183 }
184 }
185 }
186
187 if(hwndClassicStart && hwndModernStart)
188 {
189 if(SendMessage(hwndModernStart, BM_GETCHECK, 0, 0) == BST_CHECKED)
190 {
191 EnableWindow(hwndCustomizeModernStartButton, TRUE);
192 EnableWindow(hwndCustomizeClassicStartButton, FALSE);
193 lpStartImageName = MAKEINTRESOURCEW(IDB_STARTPREVIEW);
194 }
195 else
196 {
197 EnableWindow(hwndCustomizeModernStartButton, FALSE);
198 EnableWindow(hwndCustomizeClassicStartButton, TRUE);
199 lpStartImageName = MAKEINTRESOURCEW(IDB_STARTPREVIEW_CLASSIC);
200 }
201
202 if (lpStartImageName)
203 {
204 if (pPropInfo->hStartBitmap)
205 {
206 DeleteObject(pPropInfo->hStartBitmap);
207 }
208
209 pPropInfo->hStartBitmap = (HBITMAP)LoadImageW(hExplorerInstance,
210 lpStartImageName,
211 IMAGE_BITMAP,
212 0,
213 0,
214 LR_DEFAULTCOLOR);
215 if (pPropInfo->hStartBitmap)
216 {
217 hwndStartBitmap = GetDlgItem(pPropInfo->hStartWnd,
218 IDC_TASKBARPROP_STARTMENU_BITMAP);
219 if (hwndStartBitmap)
220 {
221 SendMessage(hwndStartBitmap,
222 STM_SETIMAGE,
223 IMAGE_BITMAP,
224 (LPARAM)pPropInfo->hStartBitmap);
225 }
226 }
227 }
228 }
229
230 return bRet;
231 }
232
233 static VOID
234 OnCreateTaskbarPage(HWND hwnd,
235 PPROPSHEET_INFO pPropInfo)
236 {
237 SetWindowLongPtr(hwnd,
238 GWLP_USERDATA,
239 (LONG_PTR)pPropInfo);
240
241 pPropInfo->hTaskbarWnd = hwnd;
242
243 CheckDlgButton(hwnd, IDC_TASKBARPROP_SECONDS, TaskBarSettings.bLock ? BST_CHECKED : BST_UNCHECKED);
244 CheckDlgButton(hwnd, IDC_TASKBARPROP_SECONDS, TaskBarSettings.bAutoHide ? BST_CHECKED : BST_UNCHECKED);
245 CheckDlgButton(hwnd, IDC_TASKBARPROP_SECONDS, TaskBarSettings.bAlwaysOnTop ? BST_CHECKED : BST_UNCHECKED);
246 CheckDlgButton(hwnd, IDC_TASKBARPROP_SECONDS, TaskBarSettings.bGroupButtons ? BST_CHECKED : BST_UNCHECKED);
247 CheckDlgButton(hwnd, IDC_TASKBARPROP_SECONDS, TaskBarSettings.bShowQuickLaunch ? BST_CHECKED : BST_UNCHECKED);
248 CheckDlgButton(hwnd, IDC_TASKBARPROP_SECONDS, TaskBarSettings.bShowClock ? BST_CHECKED : BST_UNCHECKED);
249 CheckDlgButton(hwnd, IDC_TASKBARPROP_SECONDS, TaskBarSettings.bShowSeconds ? BST_CHECKED : BST_UNCHECKED);
250 CheckDlgButton(hwnd, IDC_TASKBARPROP_SECONDS, TaskBarSettings.bHideInactiveIcons ? BST_CHECKED : BST_UNCHECKED);
251
252 UpdateBitmaps(pPropInfo);
253 }
254
255 static VOID
256 OnCreateStartPage(HWND hwnd,
257 PPROPSHEET_INFO pPropInfo)
258 {
259 pPropInfo->hStartWnd = hwnd;
260
261 CheckDlgButton(hwnd, IDC_TASKBARPROP_STARTMENUCLASSIC, 1); // HACK: This has to be read from registry!
262
263 UpdateBitmaps(pPropInfo);
264 }
265
266 INT_PTR CALLBACK
267 TaskbarPageProc(HWND hwndDlg,
268 UINT uMsg,
269 WPARAM wParam,
270 LPARAM lParam)
271 {
272 PPROPSHEET_INFO pPropInfo;
273
274 /* Get the window context */
275 pPropInfo = (PPROPSHEET_INFO)GetWindowLongPtrW(hwndDlg,
276 GWLP_USERDATA);
277 if (pPropInfo == NULL && uMsg != WM_INITDIALOG)
278 {
279 goto HandleDefaultMessage;
280 }
281
282 switch (uMsg)
283 {
284 case WM_INITDIALOG:
285 OnCreateTaskbarPage(hwndDlg, (PPROPSHEET_INFO)((LPPROPSHEETPAGE)lParam)->lParam);
286 break;
287
288 case WM_COMMAND:
289 switch (LOWORD(wParam))
290 {
291 case IDC_TASKBARPROP_LOCK:
292 case IDC_TASKBARPROP_HIDE:
293 case IDC_TASKBARPROP_GROUP:
294 case IDC_TASKBARPROP_SHOWQL:
295 case IDC_TASKBARPROP_HIDEICONS:
296 case IDC_TASKBARPROP_CLOCK:
297 case IDC_TASKBARPROP_SECONDS:
298 if (HIWORD(wParam) == BN_CLICKED)
299 {
300 UpdateBitmaps(pPropInfo);
301
302 /* Enable the 'Apply' button */
303 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
304 }
305 break;
306 case IDC_TASKBARPROP_ICONCUST:
307 ShowCustomizeNotifyIcons(hExplorerInstance, hwndDlg);
308 break;
309 }
310 break;
311
312 case WM_NOTIFY:
313 {
314 LPNMHDR pnmh = (LPNMHDR)lParam;
315
316 switch (pnmh->code)
317 {
318 case PSN_SETACTIVE:
319 break;
320
321 case PSN_APPLY:
322 TaskBarSettings.bShowSeconds = IsDlgButtonChecked(hwndDlg, IDC_TASKBARPROP_SECONDS);
323 SaveTaskBarSettings();
324 break;
325 }
326
327 break;
328 }
329
330 case WM_DESTROY:
331 if (pPropInfo->hTaskbarBitmap)
332 {
333 DeleteObject(pPropInfo->hTaskbarBitmap);
334 }
335 if (pPropInfo->hTrayBitmap)
336 {
337 DeleteObject(pPropInfo->hTrayBitmap);
338 }
339 break;
340
341 HandleDefaultMessage:
342 default:
343 return FALSE;
344 }
345
346 return FALSE;
347 }
348
349 static INT_PTR CALLBACK
350 StartMenuPageProc(HWND hwndDlg,
351 UINT uMsg,
352 WPARAM wParam,
353 LPARAM lParam)
354 {
355 switch (uMsg)
356 {
357 case WM_INITDIALOG:
358 OnCreateStartPage(hwndDlg, (PPROPSHEET_INFO)((LPPROPSHEETPAGE)lParam)->lParam);
359 break;
360
361 case WM_COMMAND:
362 {
363 switch (LOWORD(wParam))
364 {
365 case IDC_TASKBARPROP_STARTMENUCLASSICCUST:
366 ShowCustomizeClassic(hExplorerInstance, hwndDlg);
367 break;
368 }
369 break;
370 }
371
372 case WM_DESTROY:
373 break;
374
375 case WM_NOTIFY:
376 {
377 LPNMHDR pnmh = (LPNMHDR)lParam;
378
379 switch (pnmh->code)
380 {
381 case PSN_SETACTIVE:
382 break;
383
384 case PSN_APPLY:
385 break;
386 }
387
388 break;
389 }
390 }
391
392 return FALSE;
393 }
394
395 static VOID
396 InitPropSheetPage(PROPSHEETPAGE *psp,
397 WORD idDlg,
398 DLGPROC DlgProc,
399 LPARAM lParam)
400 {
401 ZeroMemory(psp, sizeof(*psp));
402 psp->dwSize = sizeof(*psp);
403 psp->dwFlags = PSP_DEFAULT;
404 psp->hInstance = hExplorerInstance;
405 psp->pszTemplate = MAKEINTRESOURCEW(idDlg);
406 psp->lParam = lParam;
407 psp->pfnDlgProc = DlgProc;
408 }
409
410
411 VOID
412 DisplayTrayProperties(IN HWND hwndOwner)
413 {
414 PROPSHEET_INFO propInfo = {0};
415 PROPSHEETHEADER psh;
416 PROPSHEETPAGE psp[2];
417 WCHAR szCaption[256];
418
419 if (!LoadStringW(hExplorerInstance,
420 IDS_TASKBAR_STARTMENU_PROP_CAPTION,
421 szCaption,
422 _countof(szCaption)))
423 {
424 return;
425 }
426
427 ZeroMemory(&psh, sizeof(psh));
428 psh.dwSize = sizeof(psh);
429 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE;
430 psh.hwndParent = hwndOwner;
431 psh.hInstance = hExplorerInstance;
432 psh.hIcon = NULL;
433 psh.pszCaption = szCaption;
434 psh.nPages = _countof(psp);
435 psh.nStartPage = 0;
436 psh.ppsp = psp;
437
438 InitPropSheetPage(&psp[0], IDD_TASKBARPROP_TASKBAR, TaskbarPageProc, (LPARAM)&propInfo);
439 InitPropSheetPage(&psp[1], IDD_TASKBARPROP_STARTMENU, StartMenuPageProc, (LPARAM)&propInfo);
440
441 PropertySheet(&psh);
442 }