[EXPLORER] -First commit of my Explorer work. -Remove unneeded property pages and...
[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 StartMenuPageProc(HWND hwndDlg,
193 UINT uMsg,
194 WPARAM wParam,
195 LPARAM lParam)
196 {
197 switch (uMsg)
198 {
199 case WM_INITDIALOG:
200 break;
201
202 case WM_DESTROY:
203 break;
204
205 case WM_NOTIFY:
206 {
207 LPNMHDR pnmh = (LPNMHDR)lParam;
208
209 switch (pnmh->code)
210 {
211 case PSN_SETACTIVE:
212 break;
213
214 case PSN_APPLY:
215 break;
216 }
217
218 break;
219 }
220 }
221
222 return FALSE;
223 }
224
225 static VOID
226 InitPropSheetPage(PROPSHEETPAGE *psp,
227 WORD idDlg,
228 DLGPROC DlgProc,
229 LPARAM lParam)
230 {
231 ZeroMemory(psp, sizeof(PROPSHEETPAGE));
232 psp->dwSize = sizeof(PROPSHEETPAGE);
233 psp->dwFlags = PSP_DEFAULT;
234 psp->hInstance = hExplorerInstance;
235 psp->pszTemplate = MAKEINTRESOURCE(idDlg);
236 psp->lParam = lParam;
237 psp->pfnDlgProc = DlgProc;
238 }
239
240
241 VOID
242 DisplayTrayProperties(IN HWND hwndOwner)
243 {
244 PROPSHEET_INFO propInfo;
245 PROPSHEETHEADER psh;
246 PROPSHEETPAGE psp[2];
247 WCHAR szCaption[256];
248
249 if (!LoadString(hExplorerInstance,
250 IDS_TASKBAR_STARTMENU_PROP_CAPTION,
251 szCaption,
252 sizeof(szCaption) / sizeof(szCaption[0])))
253 {
254 return;
255 }
256
257 ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
258 psh.dwSize = sizeof(PROPSHEETHEADER);
259 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE;
260 psh.hwndParent = hwndOwner;
261 psh.hInstance = hExplorerInstance;
262 psh.hIcon = NULL;
263 psh.pszCaption = szCaption;
264 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
265 psh.nStartPage = 0;
266 psh.ppsp = psp;
267
268 InitPropSheetPage(&psp[0], IDD_TASKBARPROP_TASKBAR, TaskbarPageProc, (LPARAM)&propInfo);
269 InitPropSheetPage(&psp[1], IDD_TASKBARPROP_STARTMENU, StartMenuPageProc, (LPARAM)&propInfo);
270
271 PropertySheet(&psh);
272 }