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