msvcirt: Add implementation of streambuf::unbuffered.
[wine.git] / dlls / inetcpl.cpl / general.c
blob0691579229fa9755869033563a377431bf76bcc8
1 /*
2 * Internet control panel applet: general propsheet
4 * Copyright 2010 Detlef Riekenberg
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.
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.
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
22 #include <stdarg.h>
23 #include <windef.h>
24 #include <winbase.h>
25 #include <winuser.h>
26 #include <wininet.h>
27 #include <winreg.h>
28 #include <shlwapi.h>
29 #include <prsht.h>
30 #include <shlobj.h>
32 #include "inetcpl.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(inetcpl);
37 static const WCHAR about_blank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
38 static const WCHAR start_page[] = {'S','t','a','r','t',' ','P','a','g','e',0};
39 static const WCHAR reg_ie_main[] = {'S','o','f','t','w','a','r','e','\\',
40 'M','i','c','r','o','s','o','f','t','\\',
41 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
42 'M','a','i','n',0};
44 /* list of unimplemented buttons */
45 static DWORD disabled_general_buttons[] = {IDC_HOME_CURRENT,
46 IDC_HOME_DEFAULT,
47 IDC_HISTORY_SETTINGS,
48 0};
49 static DWORD disabled_delhist_buttons[] = {IDC_DELETE_FORM_DATA,
50 IDC_DELETE_PASSWORDS,
51 0};
53 /*********************************************************************
54 * delhist_on_command [internal]
56 * handle WM_COMMAND in Delete browsing history dialog
59 static INT_PTR delhist_on_command(HWND hdlg, WPARAM wparam)
61 switch (wparam)
63 case MAKEWPARAM(IDOK, BN_CLICKED):
64 if (IsDlgButtonChecked(hdlg, IDC_DELETE_TEMP_FILES))
65 FreeUrlCacheSpaceW(NULL, 100, 0);
67 if (IsDlgButtonChecked(hdlg, IDC_DELETE_COOKIES))
69 WCHAR pathW[MAX_PATH];
71 if(SHGetSpecialFolderPathW(NULL, pathW, CSIDL_COOKIES, TRUE))
72 FreeUrlCacheSpaceW(pathW, 100, 0);
75 if (IsDlgButtonChecked(hdlg, IDC_DELETE_HISTORY))
77 WCHAR pathW[MAX_PATH];
79 if(SHGetSpecialFolderPathW(NULL, pathW, CSIDL_HISTORY, TRUE))
80 FreeUrlCacheSpaceW(pathW, 100, 0);
83 EndDialog(hdlg, IDOK);
84 return TRUE;
86 case MAKEWPARAM(IDCANCEL, BN_CLICKED):
87 EndDialog(hdlg, IDCANCEL);
88 return TRUE;
90 case MAKEWPARAM(IDC_DELETE_TEMP_FILES, BN_CLICKED):
91 case MAKEWPARAM(IDC_DELETE_COOKIES, BN_CLICKED):
92 case MAKEWPARAM(IDC_DELETE_HISTORY, BN_CLICKED):
93 case MAKEWPARAM(IDC_DELETE_FORM_DATA, BN_CLICKED):
94 case MAKEWPARAM(IDC_DELETE_PASSWORDS, BN_CLICKED):
96 BOOL any = IsDlgButtonChecked(hdlg, IDC_DELETE_TEMP_FILES) ||
97 IsDlgButtonChecked(hdlg, IDC_DELETE_COOKIES) ||
98 IsDlgButtonChecked(hdlg, IDC_DELETE_HISTORY) ||
99 IsDlgButtonChecked(hdlg, IDC_DELETE_FORM_DATA) ||
100 IsDlgButtonChecked(hdlg, IDC_DELETE_PASSWORDS);
101 EnableWindow(GetDlgItem(hdlg, IDOK), any);
102 break;
105 default:
106 break;
108 return FALSE;
112 /*********************************************************************
113 * delhist_dlgproc [internal]
115 * Delete browsing history dialog procedure
118 static INT_PTR CALLBACK delhist_dlgproc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
120 switch (msg)
122 case WM_COMMAND:
123 return delhist_on_command(hdlg, wparam);
125 case WM_INITDIALOG:
127 DWORD *ptr = disabled_delhist_buttons;
128 while (*ptr)
130 EnableWindow(GetDlgItem(hdlg, *ptr), FALSE);
131 ptr++;
133 CheckDlgButton(hdlg, IDC_DELETE_TEMP_FILES, BST_CHECKED);
134 break;
137 default:
138 break;
140 return FALSE;
143 /*********************************************************************
144 * parse_url_from_outside [internal]
146 * Filter an URL, add a usable scheme, when needed
149 static DWORD parse_url_from_outside(LPCWSTR url, LPWSTR out, DWORD maxlen)
151 HMODULE hdll;
152 DWORD (WINAPI *pParseURLFromOutsideSourceW)(LPCWSTR, LPWSTR, LPDWORD, LPDWORD);
153 DWORD res;
155 hdll = LoadLibraryA("shdocvw.dll");
156 pParseURLFromOutsideSourceW = (void *) GetProcAddress(hdll, (LPSTR) 170);
158 if (pParseURLFromOutsideSourceW)
160 res = pParseURLFromOutsideSourceW(url, out, &maxlen, NULL);
161 FreeLibrary(hdll);
162 return res;
165 ERR("failed to get ordinal 170: %d\n", GetLastError());
166 FreeLibrary(hdll);
167 return 0;
170 /*********************************************************************
171 * general_on_command [internal]
173 * handle WM_COMMAND
176 static INT_PTR general_on_command(HWND hwnd, WPARAM wparam)
179 switch (wparam)
181 case MAKEWPARAM(IDC_HOME_EDIT, EN_CHANGE):
182 /* enable apply button */
183 SendMessageW(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
184 break;
186 case MAKEWPARAM(IDC_HOME_BLANK, BN_CLICKED):
187 SetDlgItemTextW(hwnd, IDC_HOME_EDIT, about_blank);
188 break;
190 case MAKEWPARAM(IDC_HISTORY_DELETE, BN_CLICKED):
191 DialogBoxW(hcpl, MAKEINTRESOURCEW(IDD_DELETE_HISTORY), hwnd,
192 delhist_dlgproc);
193 break;
195 default:
196 TRACE("not implemented for command: %d/%d\n", HIWORD(wparam), LOWORD(wparam));
197 return FALSE;
199 return TRUE;
202 /*********************************************************************
203 * general_on_initdialog [internal]
205 * handle WM_INITDIALOG
208 static VOID general_on_initdialog(HWND hwnd)
210 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
211 DWORD len;
212 DWORD type;
213 LONG res;
214 DWORD *ptr = disabled_general_buttons;
216 /* disable unimplemented buttons */
217 while (*ptr)
219 EnableWindow(GetDlgItem(hwnd, *ptr), FALSE);
220 ptr++;
223 /* read current homepage from the registry. Try HCU first, then HKLM */
224 *buffer = 0;
225 len = sizeof(buffer);
226 type = REG_SZ;
227 res = SHRegGetUSValueW(reg_ie_main, start_page, &type, buffer, &len, FALSE, (LPBYTE) about_blank, sizeof(about_blank));
229 if (!res && (type == REG_SZ))
231 SetDlgItemTextW(hwnd, IDC_HOME_EDIT, buffer);
235 /*********************************************************************
236 * general_on_notify [internal]
238 * handle WM_NOTIFY
241 static INT_PTR general_on_notify(HWND hwnd, WPARAM wparam, LPARAM lparam)
243 PSHNOTIFY *psn;
244 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
245 WCHAR parsed[INTERNET_MAX_URL_LENGTH];
246 LONG res;
248 psn = (PSHNOTIFY *) lparam;
249 TRACE("WM_NOTIFY (%p, 0x%lx, 0x%lx) from %p with code: %d\n", hwnd, wparam, lparam,
250 psn->hdr.hwndFrom, psn->hdr.code);
252 if (psn->hdr.code == PSN_APPLY)
254 *buffer = 0;
255 GetDlgItemTextW(hwnd, IDC_HOME_EDIT, buffer, sizeof(buffer)/sizeof(WCHAR));
256 TRACE("EDITTEXT has %s\n", debugstr_w(buffer));
258 res = parse_url_from_outside(buffer, parsed, sizeof(parsed)/sizeof(WCHAR));
259 TRACE("got %d with %s\n", res, debugstr_w(parsed));
261 if (res)
263 HKEY hkey;
265 /* update the dialog, when needed */
266 if (lstrcmpW(buffer, parsed))
267 SetDlgItemTextW(hwnd, IDC_HOME_EDIT, parsed);
269 /* update the registry */
270 res = RegOpenKeyW(HKEY_CURRENT_USER, reg_ie_main, &hkey);
271 if (!res)
273 res = RegSetValueExW(hkey, start_page, 0, REG_SZ, (const BYTE *)parsed,
274 (lstrlenW(parsed) + 1) * sizeof(WCHAR));
275 RegCloseKey(hkey);
276 return !res;
280 return FALSE;
283 /*********************************************************************
284 * general_dlgproc [internal]
287 INT_PTR CALLBACK general_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
290 switch (msg)
292 case WM_INITDIALOG:
293 general_on_initdialog(hwnd);
294 return TRUE;
296 case WM_COMMAND:
297 return general_on_command(hwnd, wparam);
299 case WM_NOTIFY:
300 return general_on_notify(hwnd, wparam, lparam);
302 default:
303 /* do not flood the log */
304 if ((msg == WM_SETCURSOR) || (msg == WM_NCHITTEST) || (msg == WM_MOUSEMOVE))
305 return FALSE;
307 TRACE("(%p, 0x%08x/%d, 0x%lx, 0x%lx)\n", hwnd, msg, msg, wparam, lparam);
310 return FALSE;