[DINPUT]
[reactos.git] / reactos / 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 reg_ie_main[] = {'S','o','f','t','w','a','r','e','\\',
30 'M','i','c','r','o','s','o','f','t','\\',
31 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
32 'M','a','i','n',0};
33
34 /* list of unimplemented buttons */
35 static DWORD disabled_general_buttons[] = {IDC_HOME_CURRENT,
36 IDC_HOME_DEFAULT,
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
169 switch (wparam)
170 {
171 case MAKEWPARAM(IDC_HOME_EDIT, EN_CHANGE):
172 /* enable apply button */
173 SendMessageW(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
174 break;
175
176 case MAKEWPARAM(IDC_HOME_BLANK, BN_CLICKED):
177 SetDlgItemTextW(hwnd, IDC_HOME_EDIT, about_blank);
178 break;
179
180 case MAKEWPARAM(IDC_HISTORY_DELETE, BN_CLICKED):
181 DialogBoxW(hcpl, MAKEINTRESOURCEW(IDD_DELETE_HISTORY), hwnd,
182 delhist_dlgproc);
183 break;
184
185 default:
186 TRACE("not implemented for command: %d/%d\n", HIWORD(wparam), LOWORD(wparam));
187 return FALSE;
188 }
189 return TRUE;
190 }
191
192 /*********************************************************************
193 * general_on_initdialog [internal]
194 *
195 * handle WM_INITDIALOG
196 *
197 */
198 static VOID general_on_initdialog(HWND hwnd)
199 {
200 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
201 DWORD len;
202 DWORD type;
203 LONG res;
204 DWORD *ptr = disabled_general_buttons;
205
206 /* disable unimplemented buttons */
207 while (*ptr)
208 {
209 EnableWindow(GetDlgItem(hwnd, *ptr), FALSE);
210 ptr++;
211 }
212
213 /* read current homepage from the registry. Try HCU first, then HKLM */
214 *buffer = 0;
215 len = sizeof(buffer);
216 type = REG_SZ;
217 res = SHRegGetUSValueW(reg_ie_main, start_page, &type, buffer, &len, FALSE, (LPBYTE) about_blank, sizeof(about_blank));
218
219 if (!res && (type == REG_SZ))
220 {
221 SetDlgItemTextW(hwnd, IDC_HOME_EDIT, buffer);
222 }
223 }
224
225 /*********************************************************************
226 * general_on_notify [internal]
227 *
228 * handle WM_NOTIFY
229 *
230 */
231 static INT_PTR general_on_notify(HWND hwnd, WPARAM wparam, LPARAM lparam)
232 {
233 PSHNOTIFY *psn;
234 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
235 WCHAR parsed[INTERNET_MAX_URL_LENGTH];
236 LONG res;
237
238 psn = (PSHNOTIFY *) lparam;
239 TRACE("WM_NOTIFY (%p, 0x%lx, 0x%lx) from %p with code: %d\n", hwnd, wparam, lparam,
240 psn->hdr.hwndFrom, psn->hdr.code);
241
242 if (psn->hdr.code == PSN_APPLY)
243 {
244 *buffer = 0;
245 GetDlgItemTextW(hwnd, IDC_HOME_EDIT, buffer, sizeof(buffer)/sizeof(WCHAR));
246 TRACE("EDITTEXT has %s\n", debugstr_w(buffer));
247
248 res = parse_url_from_outside(buffer, parsed, sizeof(parsed)/sizeof(WCHAR));
249 TRACE("got %d with %s\n", res, debugstr_w(parsed));
250
251 if (res)
252 {
253 HKEY hkey;
254
255 /* update the dialog, when needed */
256 if (lstrcmpW(buffer, parsed))
257 SetDlgItemTextW(hwnd, IDC_HOME_EDIT, parsed);
258
259 /* update the registry */
260 res = RegOpenKeyW(HKEY_CURRENT_USER, reg_ie_main, &hkey);
261 if (!res)
262 {
263 res = RegSetValueExW(hkey, start_page, 0, REG_SZ, (const BYTE *)parsed,
264 (lstrlenW(parsed) + 1) * sizeof(WCHAR));
265 RegCloseKey(hkey);
266 return !res;
267 }
268 }
269 }
270 return FALSE;
271 }
272
273 /*********************************************************************
274 * general_dlgproc [internal]
275 *
276 */
277 INT_PTR CALLBACK general_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
278 {
279
280 switch (msg)
281 {
282 case WM_INITDIALOG:
283 general_on_initdialog(hwnd);
284 return TRUE;
285
286 case WM_COMMAND:
287 return general_on_command(hwnd, wparam);
288
289 case WM_NOTIFY:
290 return general_on_notify(hwnd, wparam, lparam);
291
292 default:
293 /* do not flood the log */
294 if ((msg == WM_SETCURSOR) || (msg == WM_NCHITTEST) || (msg == WM_MOUSEMOVE))
295 return FALSE;
296
297 TRACE("(%p, 0x%08x/%d, 0x%lx, 0x%lx)\n", hwnd, msg, msg, wparam, lparam);
298
299 }
300 return FALSE;
301 }