[ACPPAGE] Make use of the PCH.
[reactos.git] / dll / cpl / inetcpl / general.c
1 /*
2 * Internet control panel applet: general propsheet
3 *
4 * Copyright 2010 Detlef Riekenberg
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 St, Fifth Floor, Boston, MA 02110-1301, USA
19 *
20 */
21
22 #include "inetcpl.h"
23
24 #include <wininet.h>
25 #include <shlobj.h>
26
27 static const WCHAR about_blank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
28 static const WCHAR start_page[] = {'S','t','a','r','t',' ','P','a','g','e',0};
29 static const WCHAR default_page[] = {'D','e','f','a','u','l','t','_','P','a','g','e','_','U','R','L',0};
30 static const WCHAR reg_ie_main[] = {'S','o','f','t','w','a','r','e','\\',
31 'M','i','c','r','o','s','o','f','t','\\',
32 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
33 'M','a','i','n',0};
34
35 /* list of unimplemented buttons */
36 static DWORD disabled_general_buttons[] = {IDC_HOME_CURRENT,
37 IDC_HISTORY_SETTINGS,
38 0};
39 static DWORD disabled_delhist_buttons[] = {IDC_DELETE_FORM_DATA,
40 IDC_DELETE_PASSWORDS,
41 0};
42
43 /*********************************************************************
44 * delhist_on_command [internal]
45 *
46 * handle WM_COMMAND in Delete browsing history dialog
47 *
48 */
49 static INT_PTR delhist_on_command(HWND hdlg, WPARAM wparam)
50 {
51 switch (wparam)
52 {
53 case MAKEWPARAM(IDOK, BN_CLICKED):
54 if (IsDlgButtonChecked(hdlg, IDC_DELETE_TEMP_FILES))
55 FreeUrlCacheSpaceW(NULL, 100, 0);
56
57 if (IsDlgButtonChecked(hdlg, IDC_DELETE_COOKIES))
58 {
59 WCHAR pathW[MAX_PATH];
60
61 if(SHGetSpecialFolderPathW(NULL, pathW, CSIDL_COOKIES, TRUE))
62 FreeUrlCacheSpaceW(pathW, 100, 0);
63 }
64
65 if (IsDlgButtonChecked(hdlg, IDC_DELETE_HISTORY))
66 {
67 WCHAR pathW[MAX_PATH];
68
69 if(SHGetSpecialFolderPathW(NULL, pathW, CSIDL_HISTORY, TRUE))
70 FreeUrlCacheSpaceW(pathW, 100, 0);
71 }
72
73 EndDialog(hdlg, IDOK);
74 return TRUE;
75
76 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
77 EndDialog(hdlg, IDCANCEL);
78 return TRUE;
79
80 case MAKEWPARAM(IDC_DELETE_TEMP_FILES, BN_CLICKED):
81 case MAKEWPARAM(IDC_DELETE_COOKIES, BN_CLICKED):
82 case MAKEWPARAM(IDC_DELETE_HISTORY, BN_CLICKED):
83 case MAKEWPARAM(IDC_DELETE_FORM_DATA, BN_CLICKED):
84 case MAKEWPARAM(IDC_DELETE_PASSWORDS, BN_CLICKED):
85 {
86 BOOL any = IsDlgButtonChecked(hdlg, IDC_DELETE_TEMP_FILES) ||
87 IsDlgButtonChecked(hdlg, IDC_DELETE_COOKIES) ||
88 IsDlgButtonChecked(hdlg, IDC_DELETE_HISTORY) ||
89 IsDlgButtonChecked(hdlg, IDC_DELETE_FORM_DATA) ||
90 IsDlgButtonChecked(hdlg, IDC_DELETE_PASSWORDS);
91 EnableWindow(GetDlgItem(hdlg, IDOK), any);
92 break;
93 }
94
95 default:
96 break;
97 }
98 return FALSE;
99 }
100
101
102 /*********************************************************************
103 * delhist_dlgproc [internal]
104 *
105 * Delete browsing history dialog procedure
106 *
107 */
108 static INT_PTR CALLBACK delhist_dlgproc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
109 {
110 switch (msg)
111 {
112 case WM_COMMAND:
113 return delhist_on_command(hdlg, wparam);
114
115 case WM_INITDIALOG:
116 {
117 DWORD *ptr = disabled_delhist_buttons;
118 while (*ptr)
119 {
120 EnableWindow(GetDlgItem(hdlg, *ptr), FALSE);
121 ptr++;
122 }
123 CheckDlgButton(hdlg, IDC_DELETE_TEMP_FILES, BST_CHECKED);
124 break;
125 }
126
127 default:
128 break;
129 }
130 return FALSE;
131 }
132
133 /*********************************************************************
134 * parse_url_from_outside [internal]
135 *
136 * Filter an URL, add a usable scheme, when needed
137 *
138 */
139 static DWORD parse_url_from_outside(LPCWSTR url, LPWSTR out, DWORD maxlen)
140 {
141 HMODULE hdll;
142 DWORD (WINAPI *pParseURLFromOutsideSourceW)(LPCWSTR, LPWSTR, LPDWORD, LPDWORD);
143 DWORD res;
144
145 hdll = LoadLibraryA("shdocvw.dll");
146 pParseURLFromOutsideSourceW = (void *) GetProcAddress(hdll, (LPSTR) 170);
147
148 if (pParseURLFromOutsideSourceW)
149 {
150 res = pParseURLFromOutsideSourceW(url, out, &maxlen, NULL);
151 FreeLibrary(hdll);
152 return res;
153 }
154
155 ERR("failed to get ordinal 170: %d\n", GetLastError());
156 FreeLibrary(hdll);
157 return 0;
158 }
159
160 /*********************************************************************
161 * general_on_command [internal]
162 *
163 * handle WM_COMMAND
164 *
165 */
166 static INT_PTR general_on_command(HWND hwnd, WPARAM wparam)
167 {
168 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
169 DWORD len;
170 DWORD type;
171 LONG res;
172
173 switch (wparam)
174 {
175 case MAKEWPARAM(IDC_HOME_EDIT, EN_CHANGE):
176 /* enable apply button */
177 SendMessageW(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
178 break;
179
180 case MAKEWPARAM(IDC_HOME_BLANK, BN_CLICKED):
181 SetDlgItemTextW(hwnd, IDC_HOME_EDIT, about_blank);
182 break;
183
184 case MAKEWPARAM(IDC_HOME_DEFAULT, BN_CLICKED):
185 len = sizeof(buffer);
186 type = REG_SZ;
187 res = SHRegGetUSValueW(reg_ie_main, default_page, &type, buffer, &len, FALSE, (LPBYTE) about_blank, sizeof(about_blank));
188 if (!res && (type == REG_SZ)) SetDlgItemTextW(hwnd, IDC_HOME_EDIT, buffer);
189 break;
190
191 case MAKEWPARAM(IDC_HISTORY_DELETE, BN_CLICKED):
192 DialogBoxW(hcpl, MAKEINTRESOURCEW(IDD_DELETE_HISTORY), hwnd,
193 delhist_dlgproc);
194 break;
195
196 default:
197 TRACE("not implemented for command: %d/%d\n", HIWORD(wparam), LOWORD(wparam));
198 return FALSE;
199 }
200 return TRUE;
201 }
202
203 /*********************************************************************
204 * general_on_initdialog [internal]
205 *
206 * handle WM_INITDIALOG
207 *
208 */
209 static VOID general_on_initdialog(HWND hwnd)
210 {
211 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
212 DWORD len;
213 DWORD type;
214 LONG res;
215 DWORD *ptr = disabled_general_buttons;
216
217 /* disable unimplemented buttons */
218 while (*ptr)
219 {
220 EnableWindow(GetDlgItem(hwnd, *ptr), FALSE);
221 ptr++;
222 }
223
224 /* read current homepage from the registry. Try HCU first, then HKLM */
225 *buffer = 0;
226 len = sizeof(buffer);
227 type = REG_SZ;
228 res = SHRegGetUSValueW(reg_ie_main, start_page, &type, buffer, &len, FALSE, (LPBYTE) about_blank, sizeof(about_blank));
229
230 if (!res && (type == REG_SZ))
231 {
232 SetDlgItemTextW(hwnd, IDC_HOME_EDIT, buffer);
233 }
234 }
235
236 /*********************************************************************
237 * general_on_notify [internal]
238 *
239 * handle WM_NOTIFY
240 *
241 */
242 static INT_PTR general_on_notify(HWND hwnd, WPARAM wparam, LPARAM lparam)
243 {
244 PSHNOTIFY *psn;
245 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
246 WCHAR parsed[INTERNET_MAX_URL_LENGTH];
247 LONG res;
248
249 psn = (PSHNOTIFY *) lparam;
250 TRACE("WM_NOTIFY (%p, 0x%lx, 0x%lx) from %p with code: %d\n", hwnd, wparam, lparam,
251 psn->hdr.hwndFrom, psn->hdr.code);
252
253 if (psn->hdr.code == PSN_APPLY)
254 {
255 *buffer = 0;
256 GetDlgItemTextW(hwnd, IDC_HOME_EDIT, buffer, sizeof(buffer)/sizeof(WCHAR));
257 TRACE("EDITTEXT has %s\n", debugstr_w(buffer));
258
259 res = parse_url_from_outside(buffer, parsed, sizeof(parsed)/sizeof(WCHAR));
260 TRACE("got %d with %s\n", res, debugstr_w(parsed));
261
262 if (res)
263 {
264 HKEY hkey;
265
266 /* update the dialog, when needed */
267 if (lstrcmpW(buffer, parsed))
268 SetDlgItemTextW(hwnd, IDC_HOME_EDIT, parsed);
269
270 /* update the registry */
271 res = RegOpenKeyW(HKEY_CURRENT_USER, reg_ie_main, &hkey);
272 if (!res)
273 {
274 res = RegSetValueExW(hkey, start_page, 0, REG_SZ, (const BYTE *)parsed,
275 (lstrlenW(parsed) + 1) * sizeof(WCHAR));
276 RegCloseKey(hkey);
277 return !res;
278 }
279 }
280 }
281 return FALSE;
282 }
283
284 /*********************************************************************
285 * general_dlgproc [internal]
286 *
287 */
288 INT_PTR CALLBACK general_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
289 {
290
291 switch (msg)
292 {
293 case WM_INITDIALOG:
294 general_on_initdialog(hwnd);
295 return TRUE;
296
297 case WM_COMMAND:
298 return general_on_command(hwnd, wparam);
299
300 case WM_NOTIFY:
301 return general_on_notify(hwnd, wparam, lparam);
302
303 default:
304 /* do not flood the log */
305 if ((msg == WM_SETCURSOR) || (msg == WM_NCHITTEST) || (msg == WM_MOUSEMOVE))
306 return FALSE;
307
308 TRACE("(%p, 0x%08x/%d, 0x%lx, 0x%lx)\n", hwnd, msg, msg, wparam, lparam);
309
310 }
311 return FALSE;
312 }