ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

general.c
Go to the documentation of this file.
00001 /*
00002  * Internet control panel applet: general propsheet
00003  *
00004  * Copyright 2010 Detlef Riekenberg
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  *
00020  */
00021 
00022 #define NONAMELESSUNION
00023 
00024 #include <stdarg.h>
00025 #include <windef.h>
00026 #include <winbase.h>
00027 #include <winuser.h>
00028 #include <wininet.h>
00029 #include <winreg.h>
00030 #include <shlwapi.h>
00031 #include <prsht.h>
00032 
00033 #include "inetcpl.h"
00034 #include "wine/debug.h"
00035 
00036 WINE_DEFAULT_DEBUG_CHANNEL(inetcpl);
00037 
00038 static const WCHAR about_blank[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
00039 static const WCHAR start_page[] = {'S','t','a','r','t',' ','P','a','g','e',0};
00040 static const WCHAR reg_ie_main[] = {'S','o','f','t','w','a','r','e','\\',
00041                                     'M','i','c','r','o','s','o','f','t','\\',
00042                                     'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\',
00043                                     'M','a','i','n',0};
00044 
00045 /* list of unimplemented buttons */
00046 static DWORD disabled_general_buttons[] = {IDC_HOME_CURRENT,
00047                                            IDC_HOME_DEFAULT,
00048                                            IDC_HISTORY_SETTINGS,
00049                                            0};
00050 static DWORD disabled_delhist_buttons[] = {IDC_DELETE_COOKIES,
00051                                            IDC_DELETE_HISTORY,
00052                                            IDC_DELETE_FORM_DATA,
00053                                            IDC_DELETE_PASSWORDS,
00054                                            0};
00055 
00056 /*********************************************************************
00057  * delhist_on_command [internal]
00058  *
00059  * handle WM_COMMAND in Delete browsing history dialog
00060  *
00061  */
00062 static INT_PTR delhist_on_command(HWND hdlg, WPARAM wparam)
00063 {
00064     switch (wparam)
00065     {
00066         case MAKEWPARAM(IDOK, BN_CLICKED):
00067             if (!FreeUrlCacheSpaceW(NULL, 100, FCS_PERCENT_CACHE_SPACE))
00068                 break;   /* Don't close the dialog. */
00069             EndDialog(hdlg, IDOK);
00070             return TRUE;
00071 
00072         case MAKEWPARAM(IDCANCEL, BN_CLICKED):
00073             EndDialog(hdlg, IDCANCEL);
00074             return TRUE;
00075 
00076         case MAKEWPARAM(IDC_DELETE_TEMP_FILES, BN_CLICKED):
00077         case MAKEWPARAM(IDC_DELETE_COOKIES, BN_CLICKED):
00078         case MAKEWPARAM(IDC_DELETE_HISTORY, BN_CLICKED):
00079         case MAKEWPARAM(IDC_DELETE_FORM_DATA, BN_CLICKED):
00080         case MAKEWPARAM(IDC_DELETE_PASSWORDS, BN_CLICKED):
00081         {
00082             BOOL any = IsDlgButtonChecked(hdlg, IDC_DELETE_TEMP_FILES) ||
00083                        IsDlgButtonChecked(hdlg, IDC_DELETE_COOKIES) ||
00084                        IsDlgButtonChecked(hdlg, IDC_DELETE_HISTORY) ||
00085                        IsDlgButtonChecked(hdlg, IDC_DELETE_FORM_DATA) ||
00086                        IsDlgButtonChecked(hdlg, IDC_DELETE_PASSWORDS);
00087             EnableWindow(GetDlgItem(hdlg, IDOK), any);
00088             break;
00089         }
00090 
00091         default:
00092             break;
00093     }
00094     return FALSE;
00095 }
00096 
00097 
00098 /*********************************************************************
00099  * delhist_dlgproc [internal]
00100  *
00101  * Delete browsing history dialog procedure
00102  *
00103  */
00104 static INT_PTR CALLBACK delhist_dlgproc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam)
00105 {
00106     switch (msg)
00107     {
00108         case WM_COMMAND:
00109             return delhist_on_command(hdlg, wparam);
00110 
00111         case WM_INITDIALOG:
00112         {
00113             DWORD *ptr = disabled_delhist_buttons;
00114             while (*ptr)
00115             {
00116                 EnableWindow(GetDlgItem(hdlg, *ptr), FALSE);
00117                 ptr++;
00118             }
00119             CheckDlgButton(hdlg, IDC_DELETE_TEMP_FILES, BST_CHECKED);
00120             break;
00121         }
00122 
00123         default:
00124             break;
00125     }
00126     return FALSE;
00127 }
00128 
00129 /*********************************************************************
00130  * parse_url_from_outside [internal]
00131  *
00132  * Filter an URL, add a usable scheme, when needed
00133  *
00134  */
00135 static DWORD parse_url_from_outside(LPCWSTR url, LPWSTR out, DWORD maxlen)
00136 {
00137     HMODULE hdll;
00138     DWORD (WINAPI *pParseURLFromOutsideSourceW)(LPCWSTR, LPWSTR, LPDWORD, LPDWORD);
00139     DWORD res;
00140 
00141     hdll = LoadLibraryA("shdocvw.dll");
00142     pParseURLFromOutsideSourceW = (void *) GetProcAddress(hdll, (LPSTR) 170);
00143 
00144     if (pParseURLFromOutsideSourceW)
00145     {
00146         res = pParseURLFromOutsideSourceW(url, out, &maxlen, NULL);
00147         FreeLibrary(hdll);
00148         return res;
00149     }
00150 
00151     ERR("failed to get ordinal 170: %d\n", GetLastError());
00152     FreeLibrary(hdll);
00153     return 0;
00154 }
00155 
00156 /*********************************************************************
00157  * general_on_command [internal]
00158  *
00159  * handle WM_COMMAND
00160  *
00161  */
00162 static INT_PTR general_on_command(HWND hwnd, WPARAM wparam)
00163 {
00164 
00165     switch (wparam)
00166     {
00167         case MAKEWPARAM(IDC_HOME_EDIT, EN_CHANGE):
00168             /* enable apply button */
00169             SendMessageW(GetParent(hwnd), PSM_CHANGED, (WPARAM)hwnd, 0);
00170             break;
00171 
00172         case MAKEWPARAM(IDC_HOME_BLANK, BN_CLICKED):
00173             SetDlgItemTextW(hwnd, IDC_HOME_EDIT, about_blank);
00174             break;
00175 
00176         case MAKEWPARAM(IDC_HISTORY_DELETE, BN_CLICKED):
00177             DialogBoxW(hcpl, MAKEINTRESOURCEW(IDD_DELETE_HISTORY), hwnd,
00178                        delhist_dlgproc);
00179             break;
00180 
00181         default:
00182             TRACE("not implemented for command: %d/%d\n", HIWORD(wparam),  LOWORD(wparam));
00183             return FALSE;
00184     }
00185     return TRUE;
00186 }
00187 
00188 /*********************************************************************
00189  * general_on_initdialog [internal]
00190  *
00191  * handle WM_INITDIALOG
00192  *
00193  */
00194 static VOID general_on_initdialog(HWND hwnd)
00195 {
00196     WCHAR buffer[INTERNET_MAX_URL_LENGTH];
00197     DWORD len;
00198     DWORD type;
00199     LONG res;
00200     DWORD *ptr = disabled_general_buttons;
00201 
00202     /* disable unimplemented buttons */
00203     while (*ptr)
00204     {
00205         EnableWindow(GetDlgItem(hwnd, *ptr), FALSE);
00206         ptr++;
00207     }
00208 
00209     /* read current homepage from the registry. Try HCU first, then HKLM */
00210     *buffer = 0;
00211     len = sizeof(buffer);
00212     type = REG_SZ;
00213     res = SHRegGetUSValueW(reg_ie_main, start_page, &type, buffer, &len, FALSE, (LPBYTE) about_blank, sizeof(about_blank));
00214 
00215     if (!res && (type == REG_SZ))
00216     {
00217         SetDlgItemTextW(hwnd, IDC_HOME_EDIT, buffer);
00218     }
00219 }
00220 
00221 /*********************************************************************
00222  * general_on_notify [internal]
00223  *
00224  * handle WM_NOTIFY
00225  *
00226  */
00227 static INT_PTR general_on_notify(HWND hwnd, WPARAM wparam, LPARAM lparam)
00228 {
00229     PSHNOTIFY *psn;
00230     WCHAR buffer[INTERNET_MAX_URL_LENGTH];
00231     WCHAR parsed[INTERNET_MAX_URL_LENGTH];
00232     LONG res;
00233 
00234     psn = (PSHNOTIFY *) lparam;
00235     TRACE("WM_NOTIFY (%p, 0x%lx, 0x%lx) from %p with code: %d\n", hwnd, wparam, lparam,
00236             psn->hdr.hwndFrom, psn->hdr.code);
00237 
00238     if (psn->hdr.code == PSN_APPLY)
00239     {
00240         *buffer = 0;
00241         GetDlgItemTextW(hwnd, IDC_HOME_EDIT, buffer, sizeof(buffer)/sizeof(WCHAR));
00242         TRACE("EDITTEXT has %s\n", debugstr_w(buffer));
00243 
00244         res = parse_url_from_outside(buffer, parsed, sizeof(parsed)/sizeof(WCHAR));
00245         TRACE("got %d with %s\n", res, debugstr_w(parsed));
00246 
00247         if (res)
00248         {
00249             HKEY hkey;
00250 
00251             /* update the dialog, when needed */
00252             if (lstrcmpW(buffer, parsed))
00253                 SetDlgItemTextW(hwnd, IDC_HOME_EDIT, parsed);
00254 
00255             /* update the registry */
00256             res = RegOpenKeyW(HKEY_CURRENT_USER, reg_ie_main, &hkey);
00257             if (!res)
00258             {
00259                 res = RegSetValueExW(hkey, start_page, 0, REG_SZ, (const BYTE *)parsed,
00260                                     (lstrlenW(parsed) + 1) * sizeof(WCHAR));
00261                 RegCloseKey(hkey);
00262                 return !res;
00263             }
00264         }
00265     }
00266     return FALSE;
00267 }
00268 
00269 /*********************************************************************
00270  * general_dlgproc [internal]
00271  *
00272  */
00273 INT_PTR CALLBACK general_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
00274 {
00275 
00276     switch (msg)
00277     {
00278         case WM_INITDIALOG:
00279             general_on_initdialog(hwnd);
00280             return TRUE;
00281 
00282         case WM_COMMAND:
00283             return general_on_command(hwnd, wparam);
00284 
00285         case WM_NOTIFY:
00286             return general_on_notify(hwnd, wparam, lparam);
00287 
00288         default:
00289             /* do not flood the log */
00290             if ((msg == WM_SETCURSOR) || (msg == WM_NCHITTEST) || (msg == WM_MOUSEMOVE))
00291                 return FALSE;
00292 
00293             TRACE("(%p, 0x%08x/%d, 0x%lx, 0x%lx)\n", hwnd, msg, msg, wparam, lparam);
00294 
00295     }
00296     return FALSE;
00297 }

Generated on Sat May 26 2012 04:19:40 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.