Release 1.3.7.
[wine/gsoc-2012-control.git] / dlls / inetcpl.cpl / general.c
blob082589751e9564f8dbfe716af47b502639432b88
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 #define NONAMELESSUNION
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>
33 #include "inetcpl.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(inetcpl);
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};
45 /* list of unimplemented buttons */
46 static DWORD disable_me[] = {IDC_HOME_CURRENT,
47 IDC_HOME_DEFAULT, 0};
49 /*********************************************************************
50 * parse_url_from_outside [internal]
52 * Filter an URL, add a usable scheme, when needed
55 static DWORD parse_url_from_outside(LPCWSTR url, LPWSTR out, DWORD maxlen)
57 HMODULE hdll;
58 DWORD (WINAPI *pParseURLFromOutsideSourceW)(LPCWSTR, LPWSTR, LPDWORD, LPDWORD);
59 DWORD res;
61 hdll = LoadLibraryA("shdocvw.dll");
62 pParseURLFromOutsideSourceW = (void *) GetProcAddress(hdll, (LPSTR) 170);
64 if (pParseURLFromOutsideSourceW)
66 res = pParseURLFromOutsideSourceW(url, out, &maxlen, NULL);
67 FreeLibrary(hdll);
68 return res;
71 ERR("failed to get ordinal 170: %d\n", GetLastError());
72 FreeLibrary(hdll);
73 return 0;
76 /*********************************************************************
77 * general_on_command [internal]
79 * handle WM_COMMAND
82 static INT_PTR general_on_command(HWND hwnd, WPARAM wparam)
85 switch (wparam)
87 case MAKEWPARAM(IDC_HOME_EDIT, EN_CHANGE):
88 /* enable apply button */
89 SendMessageW(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
90 break;
92 case MAKEWPARAM(IDC_HOME_BLANK, BN_CLICKED):
93 SetDlgItemTextW(hwnd, IDC_HOME_EDIT, about_blank);
94 break;
96 default:
97 TRACE("not implemented for command: %d/%d\n", HIWORD(wparam), LOWORD(wparam));
98 return FALSE;
100 return TRUE;
103 /*********************************************************************
104 * general_on_initdialog [internal]
106 * handle WM_INITDIALOG
109 static VOID general_on_initdialog(HWND hwnd)
111 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
112 DWORD len;
113 DWORD type;
114 LONG res;
115 DWORD *ptr = disable_me;
117 /* disable unimplemented buttons */
118 while (*ptr)
120 EnableWindow(GetDlgItem(hwnd, *ptr), FALSE);
121 ptr++;
124 /* read current homepage from the registry. Try HCU first, then HKLM */
125 *buffer = 0;
126 len = sizeof(buffer);
127 type = REG_SZ;
128 res = SHRegGetUSValueW(reg_ie_main, start_page, &type, buffer, &len, FALSE, (LPBYTE) about_blank, sizeof(about_blank));
130 if (!res && (type == REG_SZ))
132 SetDlgItemTextW(hwnd, IDC_HOME_EDIT, buffer);
136 /*********************************************************************
137 * general_on_notify [internal]
139 * handle WM_NOTIFY
142 static INT_PTR general_on_notify(HWND hwnd, WPARAM wparam, LPARAM lparam)
144 PSHNOTIFY *psn;
145 WCHAR buffer[INTERNET_MAX_URL_LENGTH];
146 WCHAR parsed[INTERNET_MAX_URL_LENGTH];
147 LONG res;
149 psn = (PSHNOTIFY *) lparam;
150 TRACE("WM_NOTIFY (%p, 0x%lx, 0x%lx) from %p with code: %d\n", hwnd, wparam, lparam,
151 psn->hdr.hwndFrom, psn->hdr.code);
153 if (psn->hdr.code == PSN_APPLY)
155 *buffer = 0;
156 GetDlgItemTextW(hwnd, IDC_HOME_EDIT, buffer, sizeof(buffer)/sizeof(WCHAR));
157 TRACE("EDITTEXT has %s\n", debugstr_w(buffer));
159 res = parse_url_from_outside(buffer, parsed, sizeof(parsed)/sizeof(WCHAR));
160 TRACE("got %d with %s\n", res, debugstr_w(parsed));
162 if (res)
164 HKEY hkey;
166 /* update the dialog, when needed */
167 if (lstrcmpW(buffer, parsed))
168 SetDlgItemTextW(hwnd, IDC_HOME_EDIT, parsed);
170 /* update the registry */
171 res = RegOpenKeyW(HKEY_CURRENT_USER, reg_ie_main, &hkey);
172 if (!res)
174 res = RegSetValueExW(hkey, start_page, 0, REG_SZ, (const BYTE *)parsed,
175 (lstrlenW(parsed) + 1) * sizeof(WCHAR));
176 RegCloseKey(hkey);
177 return !res;
181 return FALSE;
184 /*********************************************************************
185 * general_dlgproc [internal]
188 INT_PTR CALLBACK general_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
191 switch (msg)
193 case WM_INITDIALOG:
194 general_on_initdialog(hwnd);
195 return TRUE;
197 case WM_COMMAND:
198 return general_on_command(hwnd, wparam);
200 case WM_NOTIFY:
201 return general_on_notify(hwnd, wparam, lparam);
203 default:
204 /* do not flood the log */
205 if ((msg == WM_SETCURSOR) || (msg == WM_NCHITTEST) || (msg == WM_MOUSEMOVE))
206 return FALSE;
208 TRACE("(%p, 0x%08x/%d, 0x%lx, 0x%lx)\n", hwnd, msg, msg, wparam, lparam);
211 return FALSE;