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