xref: /reactos/dll/cpl/inetcpl/general.c (revision d02c7225)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * Internet control panel applet: general propsheet
3c2c66affSColin Finck  *
4c2c66affSColin Finck  * Copyright 2010 Detlef Riekenberg
5c2c66affSColin Finck  *
6c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
7c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
8c2c66affSColin Finck  * License as published by the Free Software Foundation; either
9c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
10c2c66affSColin Finck  *
11c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
12c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14c2c66affSColin Finck  * Lesser General Public License for more details.
15c2c66affSColin Finck  *
16c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
17c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
18c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19c2c66affSColin Finck  *
20c2c66affSColin Finck  */
21c2c66affSColin Finck 
2288d36209SAmine Khaldi #include <stdarg.h>
2388d36209SAmine Khaldi #include <windef.h>
2488d36209SAmine Khaldi #include <winbase.h>
2588d36209SAmine Khaldi #include <winuser.h>
26c2c66affSColin Finck #include <wininet.h>
2788d36209SAmine Khaldi #include <winreg.h>
2888d36209SAmine Khaldi #include <shlwapi.h>
2988d36209SAmine Khaldi #include <prsht.h>
30c2c66affSColin Finck #include <shlobj.h>
31c2c66affSColin Finck 
3288d36209SAmine Khaldi #include "inetcpl.h"
3388d36209SAmine Khaldi #include "wine/debug.h"
3488d36209SAmine Khaldi 
3588d36209SAmine Khaldi WINE_DEFAULT_DEBUG_CHANNEL(inetcpl);
3688d36209SAmine Khaldi 
37c2c66affSColin Finck static const WCHAR about_blank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
38c2c66affSColin Finck static const WCHAR start_page[] = {'S','t','a','r','t',' ','P','a','g','e',0};
39c2c66affSColin Finck static const WCHAR default_page[] = {'D','e','f','a','u','l','t','_','P','a','g','e','_','U','R','L',0};
40c2c66affSColin Finck static const WCHAR reg_ie_main[] = {'S','o','f','t','w','a','r','e','\\',
41c2c66affSColin Finck                                     'M','i','c','r','o','s','o','f','t','\\',
42c2c66affSColin Finck                                     'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
43c2c66affSColin Finck                                     'M','a','i','n',0};
44c2c66affSColin Finck 
45c2c66affSColin Finck /* list of unimplemented buttons */
46c2c66affSColin Finck static DWORD disabled_general_buttons[] = {IDC_HOME_CURRENT,
47c2c66affSColin Finck                                            IDC_HISTORY_SETTINGS,
48c2c66affSColin Finck                                            0};
49c2c66affSColin Finck static DWORD disabled_delhist_buttons[] = {IDC_DELETE_FORM_DATA,
50c2c66affSColin Finck                                            IDC_DELETE_PASSWORDS,
51c2c66affSColin Finck                                            0};
52c2c66affSColin Finck 
53c2c66affSColin Finck /*********************************************************************
54c2c66affSColin Finck  * delhist_on_command [internal]
55c2c66affSColin Finck  *
56c2c66affSColin Finck  * handle WM_COMMAND in Delete browsing history dialog
57c2c66affSColin Finck  *
58c2c66affSColin Finck  */
delhist_on_command(HWND hdlg,WPARAM wparam)59c2c66affSColin Finck static INT_PTR delhist_on_command(HWND hdlg, WPARAM wparam)
60c2c66affSColin Finck {
61c2c66affSColin Finck     switch (wparam)
62c2c66affSColin Finck     {
63c2c66affSColin Finck         case MAKEWPARAM(IDOK, BN_CLICKED):
64c2c66affSColin Finck             if (IsDlgButtonChecked(hdlg, IDC_DELETE_TEMP_FILES))
65c2c66affSColin Finck                 FreeUrlCacheSpaceW(NULL, 100, 0);
66c2c66affSColin Finck 
67c2c66affSColin Finck             if (IsDlgButtonChecked(hdlg, IDC_DELETE_COOKIES))
68c2c66affSColin Finck             {
69c2c66affSColin Finck                 WCHAR pathW[MAX_PATH];
70c2c66affSColin Finck 
71c2c66affSColin Finck                 if(SHGetSpecialFolderPathW(NULL, pathW, CSIDL_COOKIES, TRUE))
72c2c66affSColin Finck                     FreeUrlCacheSpaceW(pathW, 100, 0);
73c2c66affSColin Finck             }
74c2c66affSColin Finck 
75c2c66affSColin Finck             if (IsDlgButtonChecked(hdlg, IDC_DELETE_HISTORY))
76c2c66affSColin Finck             {
77c2c66affSColin Finck                 WCHAR pathW[MAX_PATH];
78c2c66affSColin Finck 
79c2c66affSColin Finck                 if(SHGetSpecialFolderPathW(NULL, pathW, CSIDL_HISTORY, TRUE))
80c2c66affSColin Finck                     FreeUrlCacheSpaceW(pathW, 100, 0);
81c2c66affSColin Finck             }
82c2c66affSColin Finck 
83c2c66affSColin Finck             EndDialog(hdlg, IDOK);
84c2c66affSColin Finck             return TRUE;
85c2c66affSColin Finck 
86c2c66affSColin Finck         case MAKEWPARAM(IDCANCEL, BN_CLICKED):
87c2c66affSColin Finck             EndDialog(hdlg, IDCANCEL);
88c2c66affSColin Finck             return TRUE;
89c2c66affSColin Finck 
90c2c66affSColin Finck         case MAKEWPARAM(IDC_DELETE_TEMP_FILES, BN_CLICKED):
91c2c66affSColin Finck         case MAKEWPARAM(IDC_DELETE_COOKIES, BN_CLICKED):
92c2c66affSColin Finck         case MAKEWPARAM(IDC_DELETE_HISTORY, BN_CLICKED):
93c2c66affSColin Finck         case MAKEWPARAM(IDC_DELETE_FORM_DATA, BN_CLICKED):
94c2c66affSColin Finck         case MAKEWPARAM(IDC_DELETE_PASSWORDS, BN_CLICKED):
95c2c66affSColin Finck         {
96c2c66affSColin Finck             BOOL any = IsDlgButtonChecked(hdlg, IDC_DELETE_TEMP_FILES) ||
97c2c66affSColin Finck                        IsDlgButtonChecked(hdlg, IDC_DELETE_COOKIES) ||
98c2c66affSColin Finck                        IsDlgButtonChecked(hdlg, IDC_DELETE_HISTORY) ||
99c2c66affSColin Finck                        IsDlgButtonChecked(hdlg, IDC_DELETE_FORM_DATA) ||
100c2c66affSColin Finck                        IsDlgButtonChecked(hdlg, IDC_DELETE_PASSWORDS);
101c2c66affSColin Finck             EnableWindow(GetDlgItem(hdlg, IDOK), any);
102c2c66affSColin Finck             break;
103c2c66affSColin Finck         }
104c2c66affSColin Finck 
105c2c66affSColin Finck         default:
106c2c66affSColin Finck             break;
107c2c66affSColin Finck     }
108c2c66affSColin Finck     return FALSE;
109c2c66affSColin Finck }
110c2c66affSColin Finck 
111c2c66affSColin Finck 
112c2c66affSColin Finck /*********************************************************************
113c2c66affSColin Finck  * delhist_dlgproc [internal]
114c2c66affSColin Finck  *
115c2c66affSColin Finck  * Delete browsing history dialog procedure
116c2c66affSColin Finck  *
117c2c66affSColin Finck  */
delhist_dlgproc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam)118c2c66affSColin Finck static INT_PTR CALLBACK delhist_dlgproc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
119c2c66affSColin Finck {
120c2c66affSColin Finck     switch (msg)
121c2c66affSColin Finck     {
122c2c66affSColin Finck         case WM_COMMAND:
123c2c66affSColin Finck             return delhist_on_command(hdlg, wparam);
124c2c66affSColin Finck 
125c2c66affSColin Finck         case WM_INITDIALOG:
126c2c66affSColin Finck         {
127c2c66affSColin Finck             DWORD *ptr = disabled_delhist_buttons;
128c2c66affSColin Finck             while (*ptr)
129c2c66affSColin Finck             {
130c2c66affSColin Finck                 EnableWindow(GetDlgItem(hdlg, *ptr), FALSE);
131c2c66affSColin Finck                 ptr++;
132c2c66affSColin Finck             }
133c2c66affSColin Finck             CheckDlgButton(hdlg, IDC_DELETE_TEMP_FILES, BST_CHECKED);
134c2c66affSColin Finck             break;
135c2c66affSColin Finck         }
136c2c66affSColin Finck 
137c2c66affSColin Finck         default:
138c2c66affSColin Finck             break;
139c2c66affSColin Finck     }
140c2c66affSColin Finck     return FALSE;
141c2c66affSColin Finck }
142c2c66affSColin Finck 
143c2c66affSColin Finck /*********************************************************************
144c2c66affSColin Finck  * parse_url_from_outside [internal]
145c2c66affSColin Finck  *
146c2c66affSColin Finck  * Filter an URL, add a usable scheme, when needed
147c2c66affSColin Finck  *
148c2c66affSColin Finck  */
parse_url_from_outside(LPCWSTR url,LPWSTR out,DWORD maxlen)149c2c66affSColin Finck static DWORD parse_url_from_outside(LPCWSTR url, LPWSTR out, DWORD maxlen)
150c2c66affSColin Finck {
151c2c66affSColin Finck     HMODULE hdll;
152c2c66affSColin Finck     DWORD (WINAPI *pParseURLFromOutsideSourceW)(LPCWSTR, LPWSTR, LPDWORD, LPDWORD);
153c2c66affSColin Finck     DWORD res;
154c2c66affSColin Finck 
155c2c66affSColin Finck     hdll = LoadLibraryA("shdocvw.dll");
156c2c66affSColin Finck     pParseURLFromOutsideSourceW = (void *) GetProcAddress(hdll, (LPSTR) 170);
157c2c66affSColin Finck 
158c2c66affSColin Finck     if (pParseURLFromOutsideSourceW)
159c2c66affSColin Finck     {
160c2c66affSColin Finck         res = pParseURLFromOutsideSourceW(url, out, &maxlen, NULL);
161c2c66affSColin Finck         FreeLibrary(hdll);
162c2c66affSColin Finck         return res;
163c2c66affSColin Finck     }
164c2c66affSColin Finck 
165c2c66affSColin Finck     ERR("failed to get ordinal 170: %d\n", GetLastError());
166c2c66affSColin Finck     FreeLibrary(hdll);
167c2c66affSColin Finck     return 0;
168c2c66affSColin Finck }
169c2c66affSColin Finck 
170c2c66affSColin Finck /*********************************************************************
171c2c66affSColin Finck  * general_on_command [internal]
172c2c66affSColin Finck  *
173c2c66affSColin Finck  * handle WM_COMMAND
174c2c66affSColin Finck  *
175c2c66affSColin Finck  */
general_on_command(HWND hwnd,WPARAM wparam)176c2c66affSColin Finck static INT_PTR general_on_command(HWND hwnd, WPARAM wparam)
177c2c66affSColin Finck {
178c2c66affSColin Finck     WCHAR buffer[INTERNET_MAX_URL_LENGTH];
179c2c66affSColin Finck     DWORD len;
180c2c66affSColin Finck     DWORD type;
181c2c66affSColin Finck     LONG res;
182c2c66affSColin Finck 
183c2c66affSColin Finck     switch (wparam)
184c2c66affSColin Finck     {
185c2c66affSColin Finck         case MAKEWPARAM(IDC_HOME_EDIT, EN_CHANGE):
186c2c66affSColin Finck             /* enable apply button */
187c2c66affSColin Finck             SendMessageW(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
188c2c66affSColin Finck             break;
189c2c66affSColin Finck 
190c2c66affSColin Finck         case MAKEWPARAM(IDC_HOME_BLANK, BN_CLICKED):
191c2c66affSColin Finck             SetDlgItemTextW(hwnd, IDC_HOME_EDIT, about_blank);
192c2c66affSColin Finck             break;
193c2c66affSColin Finck 
194c2c66affSColin Finck         case MAKEWPARAM(IDC_HOME_DEFAULT, BN_CLICKED):
195c2c66affSColin Finck             len = sizeof(buffer);
196c2c66affSColin Finck             type = REG_SZ;
197c2c66affSColin Finck             res = SHRegGetUSValueW(reg_ie_main, default_page, &type, buffer, &len, FALSE, (LPBYTE) about_blank, sizeof(about_blank));
198c2c66affSColin Finck             if (!res && (type == REG_SZ)) SetDlgItemTextW(hwnd, IDC_HOME_EDIT, buffer);
199c2c66affSColin Finck             break;
200c2c66affSColin Finck 
201c2c66affSColin Finck         case MAKEWPARAM(IDC_HISTORY_DELETE, BN_CLICKED):
202c2c66affSColin Finck             DialogBoxW(hcpl, MAKEINTRESOURCEW(IDD_DELETE_HISTORY), hwnd,
203c2c66affSColin Finck                        delhist_dlgproc);
204c2c66affSColin Finck             break;
205c2c66affSColin Finck 
206c2c66affSColin Finck         default:
207c2c66affSColin Finck             TRACE("not implemented for command: %d/%d\n", HIWORD(wparam),  LOWORD(wparam));
208c2c66affSColin Finck             return FALSE;
209c2c66affSColin Finck     }
210c2c66affSColin Finck     return TRUE;
211c2c66affSColin Finck }
212c2c66affSColin Finck 
213c2c66affSColin Finck /*********************************************************************
214c2c66affSColin Finck  * general_on_initdialog [internal]
215c2c66affSColin Finck  *
216c2c66affSColin Finck  * handle WM_INITDIALOG
217c2c66affSColin Finck  *
218c2c66affSColin Finck  */
general_on_initdialog(HWND hwnd)219c2c66affSColin Finck static VOID general_on_initdialog(HWND hwnd)
220c2c66affSColin Finck {
221c2c66affSColin Finck     WCHAR buffer[INTERNET_MAX_URL_LENGTH];
222c2c66affSColin Finck     DWORD len;
223c2c66affSColin Finck     DWORD type;
224c2c66affSColin Finck     LONG res;
225c2c66affSColin Finck     DWORD *ptr = disabled_general_buttons;
226c2c66affSColin Finck 
227c2c66affSColin Finck     /* disable unimplemented buttons */
228c2c66affSColin Finck     while (*ptr)
229c2c66affSColin Finck     {
230c2c66affSColin Finck         EnableWindow(GetDlgItem(hwnd, *ptr), FALSE);
231c2c66affSColin Finck         ptr++;
232c2c66affSColin Finck     }
233c2c66affSColin Finck 
234c2c66affSColin Finck     /* read current homepage from the registry. Try HCU first, then HKLM */
235c2c66affSColin Finck     *buffer = 0;
236c2c66affSColin Finck     len = sizeof(buffer);
237c2c66affSColin Finck     type = REG_SZ;
238c2c66affSColin Finck     res = SHRegGetUSValueW(reg_ie_main, start_page, &type, buffer, &len, FALSE, (LPBYTE) about_blank, sizeof(about_blank));
239c2c66affSColin Finck 
240c2c66affSColin Finck     if (!res && (type == REG_SZ))
241c2c66affSColin Finck     {
242c2c66affSColin Finck         SetDlgItemTextW(hwnd, IDC_HOME_EDIT, buffer);
243c2c66affSColin Finck     }
244c2c66affSColin Finck }
245c2c66affSColin Finck 
246c2c66affSColin Finck /*********************************************************************
247c2c66affSColin Finck  * general_on_notify [internal]
248c2c66affSColin Finck  *
249c2c66affSColin Finck  * handle WM_NOTIFY
250c2c66affSColin Finck  *
251c2c66affSColin Finck  */
general_on_notify(HWND hwnd,WPARAM wparam,LPARAM lparam)252c2c66affSColin Finck static INT_PTR general_on_notify(HWND hwnd, WPARAM wparam, LPARAM lparam)
253c2c66affSColin Finck {
254c2c66affSColin Finck     PSHNOTIFY *psn;
255c2c66affSColin Finck     WCHAR buffer[INTERNET_MAX_URL_LENGTH];
256c2c66affSColin Finck     WCHAR parsed[INTERNET_MAX_URL_LENGTH];
257c2c66affSColin Finck     LONG res;
258c2c66affSColin Finck 
259c2c66affSColin Finck     psn = (PSHNOTIFY *) lparam;
260c2c66affSColin Finck     TRACE("WM_NOTIFY (%p, 0x%lx, 0x%lx) from %p with code: %d\n", hwnd, wparam, lparam,
261c2c66affSColin Finck             psn->hdr.hwndFrom, psn->hdr.code);
262c2c66affSColin Finck 
263c2c66affSColin Finck     if (psn->hdr.code == PSN_APPLY)
264c2c66affSColin Finck     {
265c2c66affSColin Finck         *buffer = 0;
266*d02c7225SAmine Khaldi         GetDlgItemTextW(hwnd, IDC_HOME_EDIT, buffer, ARRAY_SIZE(buffer));
267c2c66affSColin Finck         TRACE("EDITTEXT has %s\n", debugstr_w(buffer));
268c2c66affSColin Finck 
269*d02c7225SAmine Khaldi         res = parse_url_from_outside(buffer, parsed, ARRAY_SIZE(parsed));
270c2c66affSColin Finck         TRACE("got %d with %s\n", res, debugstr_w(parsed));
271c2c66affSColin Finck 
272c2c66affSColin Finck         if (res)
273c2c66affSColin Finck         {
274c2c66affSColin Finck             HKEY hkey;
275c2c66affSColin Finck 
276c2c66affSColin Finck             /* update the dialog, when needed */
277c2c66affSColin Finck             if (lstrcmpW(buffer, parsed))
278c2c66affSColin Finck                 SetDlgItemTextW(hwnd, IDC_HOME_EDIT, parsed);
279c2c66affSColin Finck 
280c2c66affSColin Finck             /* update the registry */
281c2c66affSColin Finck             res = RegOpenKeyW(HKEY_CURRENT_USER, reg_ie_main, &hkey);
282c2c66affSColin Finck             if (!res)
283c2c66affSColin Finck             {
284c2c66affSColin Finck                 res = RegSetValueExW(hkey, start_page, 0, REG_SZ, (const BYTE *)parsed,
285c2c66affSColin Finck                                     (lstrlenW(parsed) + 1) * sizeof(WCHAR));
286c2c66affSColin Finck                 RegCloseKey(hkey);
287c2c66affSColin Finck                 return !res;
288c2c66affSColin Finck             }
289c2c66affSColin Finck         }
290c2c66affSColin Finck     }
291c2c66affSColin Finck     return FALSE;
292c2c66affSColin Finck }
293c2c66affSColin Finck 
294c2c66affSColin Finck /*********************************************************************
295c2c66affSColin Finck  * general_dlgproc [internal]
296c2c66affSColin Finck  *
297c2c66affSColin Finck  */
general_dlgproc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)298c2c66affSColin Finck INT_PTR CALLBACK general_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
299c2c66affSColin Finck {
300c2c66affSColin Finck 
301c2c66affSColin Finck     switch (msg)
302c2c66affSColin Finck     {
303c2c66affSColin Finck         case WM_INITDIALOG:
304c2c66affSColin Finck             general_on_initdialog(hwnd);
305c2c66affSColin Finck             return TRUE;
306c2c66affSColin Finck 
307c2c66affSColin Finck         case WM_COMMAND:
308c2c66affSColin Finck             return general_on_command(hwnd, wparam);
309c2c66affSColin Finck 
310c2c66affSColin Finck         case WM_NOTIFY:
311c2c66affSColin Finck             return general_on_notify(hwnd, wparam, lparam);
312c2c66affSColin Finck 
313c2c66affSColin Finck         default:
314c2c66affSColin Finck             /* do not flood the log */
315c2c66affSColin Finck             if ((msg == WM_SETCURSOR) || (msg == WM_NCHITTEST) || (msg == WM_MOUSEMOVE))
316c2c66affSColin Finck                 return FALSE;
317c2c66affSColin Finck 
318c2c66affSColin Finck             TRACE("(%p, 0x%08x/%d, 0x%lx, 0x%lx)\n", hwnd, msg, msg, wparam, lparam);
319c2c66affSColin Finck 
320c2c66affSColin Finck     }
321c2c66affSColin Finck     return FALSE;
322c2c66affSColin Finck }
323