[EXPLORER] -Fix a parameter of OnCreateTaskbarPage(). Fix by Mark Jansen
[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 BOOL bLock, bHide, bGroup, bShowQL, bShowClock, bShowSeconds, bHideInactive;
40 LPTSTR lpTaskBarImageName = NULL, lpTrayImageName = NULL;
41 BOOL bRet = FALSE;
42
43 hwndLock = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_LOCK);
44 hwndHide = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_HIDE);
45 hwndGroup = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_GROUP);
46 hwndShowQL = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_SHOWQL);
47
48 hwndClock = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_CLOCK);
49 hwndSeconds = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_SECONDS);
50 hwndHideInactive = GetDlgItem(pPropInfo->hTaskbarWnd, IDC_TASKBARPROP_HIDEICONS);
51
52 if (hwndLock && hwndHide && hwndGroup && hwndShowQL && hwndClock && hwndSeconds && hwndHideInactive)
53 {
54 bLock = (SendMessage(hwndLock, BM_GETCHECK, 0, 0) == BST_CHECKED);
55 bHide = (SendMessage(hwndHide, BM_GETCHECK, 0, 0) == BST_CHECKED);
56 bGroup = (SendMessage(hwndGroup, BM_GETCHECK, 0, 0) == BST_CHECKED);
57 bShowQL = (SendMessage(hwndShowQL, BM_GETCHECK, 0, 0) == BST_CHECKED);
58
59 bShowClock = (SendMessage(hwndClock, BM_GETCHECK, 0, 0) == BST_CHECKED);
60 bShowSeconds = (SendMessage(hwndSeconds, BM_GETCHECK, 0, 0) == BST_CHECKED);
61 bHideInactive = (SendMessage(hwndHideInactive, BM_GETCHECK, 0, 0) == BST_CHECKED);
62
63 if (bHide)
64 lpTaskBarImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_AUTOHIDE);
65 else if (bLock && bGroup && bShowQL)
66 lpTaskBarImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_LOCK_GROUP_QL);
67 else if (bLock && !bGroup && !bShowQL)
68 lpTaskBarImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_LOCK_NOGROUP_NOQL);
69 else if (bLock && bGroup && !bShowQL)
70 lpTaskBarImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_LOCK_GROUP_NOQL);
71 else if (bLock && !bGroup && bShowQL)
72 lpTaskBarImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_LOCK_NOGROUP_QL);
73 else if (!bLock && !bGroup && !bShowQL)
74 lpTaskBarImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_NOLOCK_NOGROUP_NOQL);
75 else if (!bLock && bGroup && !bShowQL)
76 lpTaskBarImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_NOLOCK_GROUP_NOQL);
77 else if (!bLock && !bGroup && bShowQL)
78 lpTaskBarImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_NOLOCK_NOGROUP_QL);
79 else if (!bLock && bGroup && bShowQL)
80 lpTaskBarImageName = MAKEINTRESOURCE(IDB_TASKBARPROP_NOLOCK_GROUP_QL);
81
82
83 if (lpTaskBarImageName)
84 {
85 if (pPropInfo->hTaskbarBitmap)
86 {
87 DeleteObject(pPropInfo->hTaskbarBitmap);
88 }
89
90 pPropInfo->hTaskbarBitmap = (HBITMAP)LoadImage(hExplorerInstance,
91 lpTaskBarImageName,
92 IMAGE_BITMAP,
93 0,
94 0,
95 LR_DEFAULTCOLOR);
96 if (pPropInfo->hTaskbarBitmap)
97 {
98 hwndTaskbarBitmap = GetDlgItem(pPropInfo->hTaskbarWnd,
99 IDC_TASKBARPROP_TASKBARBITMAP);
100 if (hwndTaskbarBitmap)
101 {
102 SendMessage(hwndTaskbarBitmap,
103 STM_SETIMAGE,
104 IMAGE_BITMAP,
105 (LPARAM)pPropInfo->hTaskbarBitmap);
106 }
107 }
108 }
109
110 if (bHideInactive)
111 {
112 /* FIXME: when the customize button is disabled, enable it. */
113 if(bShowClock)
114 {
115 /* FIXME: when the seconds checkbox is disabled, enable it. */
116 if(bShowSeconds)
117 lpTrayImageName = MAKEINTRESOURCE(IDB_SYSTRAYPROP_HIDE_SECONDS);
118 else
119 lpTrayImageName = MAKEINTRESOURCE(IDB_SYSTRAYPROP_HIDE_CLOCK);
120 }
121 else
122 {
123 /* FIXME: when the seconds checkbox is enabled, disable it it. */
124 lpTrayImageName = MAKEINTRESOURCE(IDB_SYSTRAYPROP_HIDE_NOCLOCK);
125 }
126 }
127 else
128 {
129 /* FIXME: when the customize button is enabled, disable it. */
130 if(bShowClock)
131 {
132 /* FIXME: when the seconds checkbox is disabled, enable it. */
133 if(bShowSeconds)
134 lpTrayImageName = MAKEINTRESOURCE(IDB_SYSTRAYPROP_SHOW_SECONDS);
135 else
136 lpTrayImageName = MAKEINTRESOURCE(IDB_SYSTRAYPROP_SHOW_CLOCK);
137 }
138 else
139 {
140 /* FIXME: when the seconds checkbox is enabled, disable it it. */
141 lpTrayImageName = MAKEINTRESOURCE(IDB_SYSTRAYPROP_SHOW_NOCLOCK);
142 }
143 }
144
145 if(lpTrayImageName)
146 {
147 if (pPropInfo->hTrayBitmap)
148 {
149 DeleteObject(pPropInfo->hTrayBitmap);
150 }
151
152 pPropInfo->hTrayBitmap = (HBITMAP)LoadImage(hExplorerInstance,
153 lpTrayImageName,
154 IMAGE_BITMAP,
155 0,
156 0,
157 LR_DEFAULTCOLOR);
158 if (pPropInfo->hTrayBitmap)
159 {
160 hwndTrayBitmap = GetDlgItem(pPropInfo->hTaskbarWnd,
161 IDC_TASKBARPROP_NOTIFICATIONBITMAP);
162 if (hwndTrayBitmap)
163 {
164 SendMessage(hwndTrayBitmap,
165 STM_SETIMAGE,
166 IMAGE_BITMAP,
167 (LPARAM)pPropInfo->hTrayBitmap);
168 }
169 }
170 }
171 }
172
173 return bRet;
174 }
175
176 static VOID
177 OnCreateTaskbarPage(HWND hwnd,
178 PPROPSHEET_INFO pPropInfo)
179 {
180 SetWindowLongPtr(hwnd,
181 GWLP_USERDATA,
182 (LONG_PTR)pPropInfo);
183
184 pPropInfo->hTaskbarWnd = hwnd;
185
186 // FIXME: check buttons
187
188 UpdateTaskbarBitmap(pPropInfo);
189 }
190
191 INT_PTR CALLBACK
192 TaskbarPageProc(HWND hwndDlg,
193 UINT uMsg,
194 WPARAM wParam,
195 LPARAM lParam)
196 {
197 PPROPSHEET_INFO pPropInfo;
198
199 /* Get the window context */
200 pPropInfo = (PPROPSHEET_INFO)GetWindowLongPtrW(hwndDlg,
201 GWLP_USERDATA);
202 if (pPropInfo == NULL && uMsg != WM_INITDIALOG)
203 {
204 goto HandleDefaultMessage;
205 }
206
207 switch (uMsg)
208 {
209 case WM_INITDIALOG:
210 OnCreateTaskbarPage(hwndDlg, (PPROPSHEET_INFO)((LPPROPSHEETPAGE)lParam)->lParam);
211 break;
212
213 case WM_COMMAND:
214 switch (LOWORD(wParam))
215 {
216 case IDC_TASKBARPROP_LOCK:
217 case IDC_TASKBARPROP_HIDE:
218 case IDC_TASKBARPROP_GROUP:
219 case IDC_TASKBARPROP_SHOWQL:
220 case IDC_TASKBARPROP_HIDEICONS:
221 case IDC_TASKBARPROP_CLOCK:
222 case IDC_TASKBARPROP_SECONDS:
223 if (HIWORD(wParam) == BN_CLICKED)
224 {
225 UpdateTaskbarBitmap(pPropInfo);
226
227 /* Enable the 'Apply' button */
228 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
229 }
230 break;
231 }
232 break;
233
234 case WM_NOTIFY:
235 {
236 LPNMHDR pnmh = (LPNMHDR)lParam;
237
238 switch (pnmh->code)
239 {
240 case PSN_SETACTIVE:
241 break;
242
243 case PSN_APPLY:
244 break;
245 }
246
247 break;
248 }
249
250 case WM_DESTROY:
251 if (pPropInfo->hTaskbarBitmap)
252 {
253 DeleteObject(pPropInfo->hTaskbarBitmap);
254 }
255 if (pPropInfo->hTrayBitmap)
256 {
257 DeleteObject(pPropInfo->hTrayBitmap);
258 }
259 break;
260
261 HandleDefaultMessage:
262 default:
263 return FALSE;
264 }
265
266 return FALSE;
267 }
268
269 static INT_PTR CALLBACK
270 StartMenuPageProc(HWND hwndDlg,
271 UINT uMsg,
272 WPARAM wParam,
273 LPARAM lParam)
274 {
275 switch (uMsg)
276 {
277 case WM_INITDIALOG:
278 break;
279
280 case WM_COMMAND:
281 {
282 switch (LOWORD(wParam))
283 {
284 case IDC_TASKBARPROP_STARTMENUCLASSICCUST:
285 ShowCustomizeClassic(hExplorerInstance, hwndDlg);
286 break;
287 }
288 break;
289 }
290
291 case WM_DESTROY:
292 break;
293
294 case WM_NOTIFY:
295 {
296 LPNMHDR pnmh = (LPNMHDR)lParam;
297
298 switch (pnmh->code)
299 {
300 case PSN_SETACTIVE:
301 break;
302
303 case PSN_APPLY:
304 break;
305 }
306
307 break;
308 }
309 }
310
311 return FALSE;
312 }
313
314 static VOID
315 InitPropSheetPage(PROPSHEETPAGE *psp,
316 WORD idDlg,
317 DLGPROC DlgProc,
318 LPARAM lParam)
319 {
320 ZeroMemory(psp, sizeof(PROPSHEETPAGE));
321 psp->dwSize = sizeof(PROPSHEETPAGE);
322 psp->dwFlags = PSP_DEFAULT;
323 psp->hInstance = hExplorerInstance;
324 psp->pszTemplate = MAKEINTRESOURCE(idDlg);
325 psp->lParam = lParam;
326 psp->pfnDlgProc = DlgProc;
327 }
328
329
330 VOID
331 DisplayTrayProperties(IN HWND hwndOwner)
332 {
333 PROPSHEET_INFO propInfo;
334 PROPSHEETHEADER psh;
335 PROPSHEETPAGE psp[2];
336 WCHAR szCaption[256];
337
338 if (!LoadString(hExplorerInstance,
339 IDS_TASKBAR_STARTMENU_PROP_CAPTION,
340 szCaption,
341 sizeof(szCaption) / sizeof(szCaption[0])))
342 {
343 return;
344 }
345
346 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
347 psh.dwSize = sizeof(PROPSHEETHEADER);
348 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE;
349 psh.hwndParent = hwndOwner;
350 psh.hInstance = hExplorerInstance;
351 psh.hIcon = NULL;
352 psh.pszCaption = szCaption;
353 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
354 psh.nStartPage = 0;
355 psh.ppsp = psp;
356
357 InitPropSheetPage(&psp[0], IDD_TASKBARPROP_TASKBAR, TaskbarPageProc, (LPARAM)&propInfo);
358 InitPropSheetPage(&psp[1], IDD_TASKBARPROP_STARTMENU, StartMenuPageProc, (LPARAM)&propInfo);
359
360 PropertySheet(&psh);
361 }