[AT]
[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 // FIXME: check buttons
244 CheckDlgButton(hwnd, IDC_TASKBARPROP_SECONDS, AdvancedSettings.bShowSeconds ? BST_CHECKED : BST_UNCHECKED);
245
246 UpdateBitmaps(pPropInfo);
247 }
248
249 static VOID
250 OnCreateStartPage(HWND hwnd,
251 PPROPSHEET_INFO pPropInfo)
252 {
253 pPropInfo->hStartWnd = hwnd;
254
255 CheckDlgButton(hwnd, IDC_TASKBARPROP_STARTMENUCLASSIC, 1); // HACK: This has to be read from registry!
256
257 UpdateBitmaps(pPropInfo);
258 }
259
260 INT_PTR CALLBACK
261 TaskbarPageProc(HWND hwndDlg,
262 UINT uMsg,
263 WPARAM wParam,
264 LPARAM lParam)
265 {
266 PPROPSHEET_INFO pPropInfo;
267
268 /* Get the window context */
269 pPropInfo = (PPROPSHEET_INFO)GetWindowLongPtrW(hwndDlg,
270 GWLP_USERDATA);
271 if (pPropInfo == NULL && uMsg != WM_INITDIALOG)
272 {
273 goto HandleDefaultMessage;
274 }
275
276 switch (uMsg)
277 {
278 case WM_INITDIALOG:
279 OnCreateTaskbarPage(hwndDlg, (PPROPSHEET_INFO)((LPPROPSHEETPAGE)lParam)->lParam);
280 break;
281
282 case WM_COMMAND:
283 switch (LOWORD(wParam))
284 {
285 case IDC_TASKBARPROP_LOCK:
286 case IDC_TASKBARPROP_HIDE:
287 case IDC_TASKBARPROP_GROUP:
288 case IDC_TASKBARPROP_SHOWQL:
289 case IDC_TASKBARPROP_HIDEICONS:
290 case IDC_TASKBARPROP_CLOCK:
291 case IDC_TASKBARPROP_SECONDS:
292 if (HIWORD(wParam) == BN_CLICKED)
293 {
294 UpdateBitmaps(pPropInfo);
295
296 /* Enable the 'Apply' button */
297 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
298 }
299 break;
300 case IDC_TASKBARPROP_ICONCUST:
301 ShowCustomizeNotifyIcons(hExplorerInstance, hwndDlg);
302 break;
303 }
304 break;
305
306 case WM_NOTIFY:
307 {
308 LPNMHDR pnmh = (LPNMHDR)lParam;
309
310 switch (pnmh->code)
311 {
312 case PSN_SETACTIVE:
313 break;
314
315 case PSN_APPLY:
316 AdvancedSettings.bShowSeconds = IsDlgButtonChecked(hwndDlg, IDC_TASKBARPROP_SECONDS);
317 SaveSettingDword(szAdvancedSettingsKey, TEXT("ShowSeconds"), AdvancedSettings.bShowSeconds);
318 break;
319 }
320
321 break;
322 }
323
324 case WM_DESTROY:
325 if (pPropInfo->hTaskbarBitmap)
326 {
327 DeleteObject(pPropInfo->hTaskbarBitmap);
328 }
329 if (pPropInfo->hTrayBitmap)
330 {
331 DeleteObject(pPropInfo->hTrayBitmap);
332 }
333 break;
334
335 HandleDefaultMessage:
336 default:
337 return FALSE;
338 }
339
340 return FALSE;
341 }
342
343 static INT_PTR CALLBACK
344 StartMenuPageProc(HWND hwndDlg,
345 UINT uMsg,
346 WPARAM wParam,
347 LPARAM lParam)
348 {
349 switch (uMsg)
350 {
351 case WM_INITDIALOG:
352 OnCreateStartPage(hwndDlg, (PPROPSHEET_INFO)((LPPROPSHEETPAGE)lParam)->lParam);
353 break;
354
355 case WM_COMMAND:
356 {
357 switch (LOWORD(wParam))
358 {
359 case IDC_TASKBARPROP_STARTMENUCLASSICCUST:
360 ShowCustomizeClassic(hExplorerInstance, hwndDlg);
361 break;
362 }
363 break;
364 }
365
366 case WM_DESTROY:
367 break;
368
369 case WM_NOTIFY:
370 {
371 LPNMHDR pnmh = (LPNMHDR)lParam;
372
373 switch (pnmh->code)
374 {
375 case PSN_SETACTIVE:
376 break;
377
378 case PSN_APPLY:
379 break;
380 }
381
382 break;
383 }
384 }
385
386 return FALSE;
387 }
388
389 static VOID
390 InitPropSheetPage(PROPSHEETPAGE *psp,
391 WORD idDlg,
392 DLGPROC DlgProc,
393 LPARAM lParam)
394 {
395 ZeroMemory(psp, sizeof(*psp));
396 psp->dwSize = sizeof(*psp);
397 psp->dwFlags = PSP_DEFAULT;
398 psp->hInstance = hExplorerInstance;
399 psp->pszTemplate = MAKEINTRESOURCEW(idDlg);
400 psp->lParam = lParam;
401 psp->pfnDlgProc = DlgProc;
402 }
403
404
405 VOID
406 DisplayTrayProperties(IN HWND hwndOwner)
407 {
408 PROPSHEET_INFO propInfo = {0};
409 PROPSHEETHEADER psh;
410 PROPSHEETPAGE psp[2];
411 WCHAR szCaption[256];
412
413 if (!LoadStringW(hExplorerInstance,
414 IDS_TASKBAR_STARTMENU_PROP_CAPTION,
415 szCaption,
416 _countof(szCaption)))
417 {
418 return;
419 }
420
421 ZeroMemory(&psh, sizeof(psh));
422 psh.dwSize = sizeof(psh);
423 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE;
424 psh.hwndParent = hwndOwner;
425 psh.hInstance = hExplorerInstance;
426 psh.hIcon = NULL;
427 psh.pszCaption = szCaption;
428 psh.nPages = _countof(psp);
429 psh.nStartPage = 0;
430 psh.ppsp = psp;
431
432 InitPropSheetPage(&psp[0], IDD_TASKBARPROP_TASKBAR, TaskbarPageProc, (LPARAM)&propInfo);
433 InitPropSheetPage(&psp[1], IDD_TASKBARPROP_STARTMENU, StartMenuPageProc, (LPARAM)&propInfo);
434
435 PropertySheet(&psh);
436 }