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