Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygeniexplore.c
Go to the documentation of this file.
00001 /* 00002 * SHDOCVW - Internet Explorer main frame window 00003 * 00004 * Copyright 2006 Mike McCormack (for CodeWeavers) 00005 * Copyright 2006 Jacek Caban (for CodeWeavers) 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 00022 #define COBJMACROS 00023 00024 #include <stdarg.h> 00025 #include "windef.h" 00026 #include "winbase.h" 00027 #include "winuser.h" 00028 #include "wingdi.h" 00029 #include "winnls.h" 00030 #include "ole2.h" 00031 #include "exdisp.h" 00032 #include "oleidl.h" 00033 00034 #include "shdocvw.h" 00035 #include "mshtmcid.h" 00036 #include "shellapi.h" 00037 #include "winreg.h" 00038 #include "shlwapi.h" 00039 #include "intshcut.h" 00040 00041 #include "wine/debug.h" 00042 00043 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw); 00044 00045 #define IDI_APPICON 1 00046 00047 #define DOCHOST_THIS(iface) DEFINE_THIS2(InternetExplorer,doc_host,iface) 00048 00049 static const WCHAR szIEWinFrame[] = { 'I','E','F','r','a','m','e',0 }; 00050 00051 /* Windows uses "Microsoft Internet Explorer" */ 00052 static const WCHAR wszWineInternetExplorer[] = 00053 {'W','i','n','e',' ','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',0}; 00054 00055 HRESULT update_ie_statustext(InternetExplorer* This, LPCWSTR text) 00056 { 00057 if(!SendMessageW(This->status_hwnd, SB_SETTEXTW, MAKEWORD(SB_SIMPLEID, 0), (LPARAM)text)) 00058 return E_FAIL; 00059 00060 return S_OK; 00061 } 00062 00063 static void adjust_ie_docobj_rect(HWND frame, RECT* rc) 00064 { 00065 HWND hwndRebar = GetDlgItem(frame, IDC_BROWSE_REBAR); 00066 HWND hwndStatus = GetDlgItem(frame, IDC_BROWSE_STATUSBAR); 00067 INT barHeight = SendMessageW(hwndRebar, RB_GETBARHEIGHT, 0, 0); 00068 00069 rc->top += barHeight; 00070 rc->bottom -= barHeight; 00071 00072 if(IsWindowVisible(hwndStatus)) 00073 { 00074 RECT statusrc; 00075 00076 GetClientRect(hwndStatus, &statusrc); 00077 rc->bottom -= statusrc.bottom - statusrc.top; 00078 } 00079 } 00080 00081 static HMENU get_tb_menu(HMENU menu) 00082 { 00083 HMENU menu_view = GetSubMenu(menu, 1); 00084 00085 return GetSubMenu(menu_view, 0); 00086 } 00087 00088 static HMENU get_fav_menu(HMENU menu) 00089 { 00090 return GetSubMenu(menu, 2); 00091 } 00092 00093 static LPWSTR get_fav_url_from_id(HMENU menu, UINT id) 00094 { 00095 MENUITEMINFOW item; 00096 00097 item.cbSize = sizeof(item); 00098 item.fMask = MIIM_DATA; 00099 00100 if(!GetMenuItemInfoW(menu, id, FALSE, &item)) 00101 return NULL; 00102 00103 return (LPWSTR)item.dwItemData; 00104 } 00105 00106 static void free_fav_menu_data(HMENU menu) 00107 { 00108 LPWSTR url; 00109 int i; 00110 00111 for(i = 0; (url = get_fav_url_from_id(menu, ID_BROWSE_GOTOFAV_FIRST + i)); i++) 00112 heap_free( url ); 00113 } 00114 00115 static int get_menu_item_count(HMENU menu) 00116 { 00117 MENUITEMINFOW item; 00118 int count = 0; 00119 int i; 00120 00121 item.cbSize = sizeof(item); 00122 item.fMask = MIIM_DATA | MIIM_SUBMENU; 00123 00124 for(i = 0; GetMenuItemInfoW(menu, i, TRUE, &item); i++) 00125 { 00126 if(item.hSubMenu) 00127 count += get_menu_item_count(item.hSubMenu); 00128 else 00129 count++; 00130 } 00131 00132 return count; 00133 } 00134 00135 static void add_fav_to_menu(HMENU favmenu, HMENU menu, LPWSTR title, LPCWSTR url) 00136 { 00137 MENUITEMINFOW item; 00138 /* Subtract the number of standard elements in the Favorites menu */ 00139 int favcount = get_menu_item_count(favmenu) - 2; 00140 LPWSTR urlbuf; 00141 00142 if(favcount > (ID_BROWSE_GOTOFAV_MAX - ID_BROWSE_GOTOFAV_FIRST)) 00143 { 00144 FIXME("Add support for more than %d Favorites\n", favcount); 00145 return; 00146 } 00147 00148 urlbuf = heap_alloc((lstrlenW(url) + 1) * sizeof(WCHAR)); 00149 00150 if(!urlbuf) 00151 return; 00152 00153 lstrcpyW(urlbuf, url); 00154 00155 item.cbSize = sizeof(item); 00156 item.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_DATA | MIIM_ID; 00157 item.fType = MFT_STRING; 00158 item.dwTypeData = title; 00159 item.wID = ID_BROWSE_GOTOFAV_FIRST + favcount; 00160 item.dwItemData = (ULONG_PTR)urlbuf; 00161 InsertMenuItemW(menu, -1, TRUE, &item); 00162 } 00163 00164 static void add_favs_to_menu(HMENU favmenu, HMENU menu, LPCWSTR dir) 00165 { 00166 WCHAR path[MAX_PATH*2]; 00167 const WCHAR search[] = {'*',0}; 00168 WCHAR* filename; 00169 HANDLE findhandle; 00170 WIN32_FIND_DATAW finddata; 00171 IUniformResourceLocatorW* urlobj; 00172 IPersistFile* urlfile; 00173 HRESULT res; 00174 00175 lstrcpyW(path, dir); 00176 PathAppendW(path, search); 00177 00178 findhandle = FindFirstFileW(path, &finddata); 00179 00180 if(findhandle == INVALID_HANDLE_VALUE) 00181 return; 00182 00183 res = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_INPROC_SERVER, &IID_IUniformResourceLocatorW, (PVOID*)&urlobj); 00184 00185 if(SUCCEEDED(res)) 00186 res = IUnknown_QueryInterface(urlobj, &IID_IPersistFile, (PVOID*)&urlfile); 00187 00188 if(SUCCEEDED(res)) 00189 { 00190 filename = path + lstrlenW(path) - lstrlenW(search); 00191 00192 do 00193 { 00194 lstrcpyW(filename, finddata.cFileName); 00195 00196 if(finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) 00197 { 00198 MENUITEMINFOW item; 00199 const WCHAR ignore1[] = {'.','.',0}; 00200 const WCHAR ignore2[] = {'.',0}; 00201 00202 if(!lstrcmpW(filename, ignore1) || !lstrcmpW(filename, ignore2)) 00203 continue; 00204 00205 item.cbSize = sizeof(item); 00206 item.fMask = MIIM_STRING | MIIM_SUBMENU; 00207 item.dwTypeData = filename; 00208 item.hSubMenu = CreatePopupMenu(); 00209 InsertMenuItemW(menu, -1, TRUE, &item); 00210 add_favs_to_menu(favmenu, item.hSubMenu, path); 00211 } else 00212 { 00213 WCHAR* fileext; 00214 WCHAR* url = NULL; 00215 const WCHAR urlext[] = {'.','u','r','l',0}; 00216 00217 if(lstrcmpiW(PathFindExtensionW(filename), urlext)) 00218 continue; 00219 00220 if(FAILED(IPersistFile_Load(urlfile, path, 0))) 00221 continue; 00222 00223 urlobj->lpVtbl->GetURL(urlobj, &url); 00224 00225 if(!url) 00226 continue; 00227 00228 fileext = filename + lstrlenW(filename) - lstrlenW(urlext); 00229 *fileext = 0; 00230 add_fav_to_menu(favmenu, menu, filename, url); 00231 } 00232 } while(FindNextFileW(findhandle, &finddata)); 00233 } 00234 00235 if(urlfile) 00236 IPersistFile_Release(urlfile); 00237 00238 if(urlobj) 00239 IUnknown_Release(urlobj); 00240 00241 FindClose(findhandle); 00242 } 00243 00244 static void add_tbs_to_menu(HMENU menu) 00245 { 00246 HUSKEY toolbar_handle; 00247 WCHAR toolbar_key[] = {'S','o','f','t','w','a','r','e','\\', 00248 'M','i','c','r','o','s','o','f','t','\\', 00249 'I','n','t','e','r','n','e','t',' ', 00250 'E','x','p','l','o','r','e','r','\\', 00251 'T','o','o','l','b','a','r',0}; 00252 00253 if(SHRegOpenUSKeyW(toolbar_key, KEY_READ, NULL, &toolbar_handle, TRUE) == ERROR_SUCCESS) 00254 { 00255 HUSKEY classes_handle; 00256 WCHAR classes_key[] = {'S','o','f','t','w','a','r','e','\\', 00257 'C','l','a','s','s','e','s','\\','C','L','S','I','D',0}; 00258 WCHAR guid[39]; 00259 DWORD value_len = sizeof(guid)/sizeof(guid[0]); 00260 int i; 00261 00262 if(SHRegOpenUSKeyW(classes_key, KEY_READ, NULL, &classes_handle, TRUE) != ERROR_SUCCESS) 00263 { 00264 SHRegCloseUSKey(toolbar_handle); 00265 ERR("Failed to open key %s\n", debugstr_w(classes_key)); 00266 return; 00267 } 00268 00269 for(i = 0; SHRegEnumUSValueW(toolbar_handle, i, guid, &value_len, NULL, NULL, NULL, SHREGENUM_HKLM) == ERROR_SUCCESS; i++) 00270 { 00271 WCHAR tb_name[100]; 00272 DWORD tb_name_len = sizeof(tb_name)/sizeof(tb_name[0]); 00273 HUSKEY tb_class_handle; 00274 MENUITEMINFOW item; 00275 LSTATUS ret; 00276 value_len = sizeof(guid)/sizeof(guid[0]); 00277 00278 if(lstrlenW(guid) != 38) 00279 { 00280 TRACE("Found invalid IE toolbar entry: %s\n", debugstr_w(guid)); 00281 continue; 00282 } 00283 00284 if(SHRegOpenUSKeyW(guid, KEY_READ, classes_handle, &tb_class_handle, TRUE) != ERROR_SUCCESS) 00285 { 00286 ERR("Failed to get class info for %s\n", debugstr_w(guid)); 00287 continue; 00288 } 00289 00290 ret = SHRegQueryUSValueW(tb_class_handle, NULL, NULL, tb_name, &tb_name_len, TRUE, NULL, 0); 00291 00292 SHRegCloseUSKey(tb_class_handle); 00293 00294 if(ret != ERROR_SUCCESS) 00295 { 00296 ERR("Failed to get toolbar name for %s\n", debugstr_w(guid)); 00297 continue; 00298 } 00299 00300 item.cbSize = sizeof(item); 00301 item.fMask = MIIM_STRING; 00302 item.dwTypeData = tb_name; 00303 InsertMenuItemW(menu, GetMenuItemCount(menu), TRUE, &item); 00304 } 00305 00306 SHRegCloseUSKey(classes_handle); 00307 SHRegCloseUSKey(toolbar_handle); 00308 } 00309 } 00310 00311 static HMENU create_ie_menu(void) 00312 { 00313 HMENU menu = LoadMenuW(shdocvw_hinstance, MAKEINTRESOURCEW(IDR_BROWSE_MAIN_MENU)); 00314 HMENU favmenu = get_fav_menu(menu); 00315 WCHAR path[MAX_PATH]; 00316 00317 add_tbs_to_menu(get_tb_menu(menu)); 00318 00319 if(SHGetFolderPathW(NULL, CSIDL_COMMON_FAVORITES, NULL, SHGFP_TYPE_CURRENT, path) == S_OK) 00320 add_favs_to_menu(favmenu, favmenu, path); 00321 00322 if(SHGetFolderPathW(NULL, CSIDL_FAVORITES, NULL, SHGFP_TYPE_CURRENT, path) == S_OK) 00323 add_favs_to_menu(favmenu, favmenu, path); 00324 00325 return menu; 00326 } 00327 00328 static void ie_navigate(InternetExplorer* This, LPCWSTR url) 00329 { 00330 VARIANT variant; 00331 00332 V_VT(&variant) = VT_BSTR; 00333 V_BSTR(&variant) = SysAllocString(url); 00334 00335 IWebBrowser2_Navigate2(WEBBROWSER2(This), &variant, NULL, NULL, NULL, NULL); 00336 00337 SysFreeString(V_BSTR(&variant)); 00338 } 00339 00340 static INT_PTR CALLBACK ie_dialog_open_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) 00341 { 00342 static InternetExplorer* This; 00343 00344 switch(msg) 00345 { 00346 case WM_INITDIALOG: 00347 This = (InternetExplorer*)lparam; 00348 EnableWindow(GetDlgItem(hwnd, IDOK), FALSE); 00349 return TRUE; 00350 00351 case WM_COMMAND: 00352 switch(LOWORD(wparam)) 00353 { 00354 case IDC_BROWSE_OPEN_URL: 00355 { 00356 HWND hwndurl = GetDlgItem(hwnd, IDC_BROWSE_OPEN_URL); 00357 int len = GetWindowTextLengthW(hwndurl); 00358 00359 EnableWindow(GetDlgItem(hwnd, IDOK), len ? TRUE : FALSE); 00360 break; 00361 } 00362 case IDOK: 00363 { 00364 HWND hwndurl = GetDlgItem(hwnd, IDC_BROWSE_OPEN_URL); 00365 int len = GetWindowTextLengthW(hwndurl); 00366 00367 if(len) 00368 { 00369 VARIANT url; 00370 00371 V_VT(&url) = VT_BSTR; 00372 V_BSTR(&url) = SysAllocStringLen(NULL, len); 00373 00374 GetWindowTextW(hwndurl, V_BSTR(&url), len + 1); 00375 IWebBrowser2_Navigate2(WEBBROWSER2(This), &url, NULL, NULL, NULL, NULL); 00376 00377 SysFreeString(V_BSTR(&url)); 00378 } 00379 } 00380 /* fall through */ 00381 case IDCANCEL: 00382 EndDialog(hwnd, wparam); 00383 return TRUE; 00384 } 00385 } 00386 return FALSE; 00387 } 00388 00389 static void ie_dialog_about(HWND hwnd) 00390 { 00391 HICON icon = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON, 48, 48, LR_SHARED); 00392 00393 ShellAboutW(hwnd, wszWineInternetExplorer, NULL, icon); 00394 00395 DestroyIcon(icon); 00396 } 00397 00398 static void add_tb_separator(HWND hwnd) 00399 { 00400 TBBUTTON btn; 00401 00402 ZeroMemory(&btn, sizeof(btn)); 00403 00404 btn.iBitmap = 3; 00405 btn.fsStyle = BTNS_SEP; 00406 SendMessageW(hwnd, TB_ADDBUTTONSW, 1, (LPARAM)&btn); 00407 } 00408 00409 static void add_tb_button(HWND hwnd, int bmp, int cmd, int strId) 00410 { 00411 TBBUTTON btn; 00412 WCHAR buf[30]; 00413 00414 LoadStringW(shdocvw_hinstance, strId, buf, sizeof(buf)/sizeof(buf[0])); 00415 00416 btn.iBitmap = bmp; 00417 btn.idCommand = cmd; 00418 btn.fsState = TBSTATE_ENABLED; 00419 btn.fsStyle = BTNS_SHOWTEXT; 00420 btn.dwData = 0; 00421 btn.iString = (INT_PTR)buf; 00422 00423 SendMessageW(hwnd, TB_ADDBUTTONSW, 1, (LPARAM)&btn); 00424 } 00425 00426 static void create_rebar(HWND hwnd) 00427 { 00428 HWND hwndRebar; 00429 HWND hwndAddress; 00430 HWND hwndToolbar; 00431 REBARINFO rebarinf; 00432 REBARBANDINFOW bandinf; 00433 WCHAR addr[40]; 00434 HIMAGELIST imagelist; 00435 WCHAR idb_ietoolbar[] = {'I','D','B','_','I','E','T','O','O','L','B','A','R',0}; 00436 00437 LoadStringW(shdocvw_hinstance, IDS_ADDRESS, addr, sizeof(addr)/sizeof(addr[0])); 00438 00439 hwndRebar = CreateWindowExW(WS_EX_TOOLWINDOW, REBARCLASSNAMEW, NULL, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|RBS_VARHEIGHT|CCS_TOP|CCS_NODIVIDER, 0, 0, 0, 0, hwnd, (HMENU)IDC_BROWSE_REBAR, shdocvw_hinstance, NULL); 00440 00441 rebarinf.cbSize = sizeof(rebarinf); 00442 rebarinf.fMask = 0; 00443 rebarinf.himl = NULL; 00444 rebarinf.cbSize = sizeof(rebarinf); 00445 00446 SendMessageW(hwndRebar, RB_SETBARINFO, 0, (LPARAM)&rebarinf); 00447 00448 hwndToolbar = CreateWindowExW(TBSTYLE_EX_MIXEDBUTTONS, TOOLBARCLASSNAMEW, NULL, TBSTYLE_FLAT | WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwndRebar, (HMENU)IDC_BROWSE_TOOLBAR, shdocvw_hinstance, NULL); 00449 00450 imagelist = ImageList_LoadImageW(shdocvw_hinstance, idb_ietoolbar, 32, 0, CLR_NONE, IMAGE_BITMAP, LR_CREATEDIBSECTION); 00451 00452 SendMessageW(hwndToolbar, TB_SETIMAGELIST, 0, (LPARAM)imagelist); 00453 SendMessageW(hwndToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); 00454 add_tb_button(hwndToolbar, 0, 0, IDS_TB_BACK); 00455 add_tb_button(hwndToolbar, 1, 0, IDS_TB_FORWARD); 00456 add_tb_button(hwndToolbar, 2, 0, IDS_TB_STOP); 00457 add_tb_button(hwndToolbar, 3, 0, IDS_TB_REFRESH); 00458 add_tb_button(hwndToolbar, 4, ID_BROWSE_HOME, IDS_TB_HOME); 00459 add_tb_separator(hwndToolbar); 00460 add_tb_button(hwndToolbar, 5, ID_BROWSE_PRINT, IDS_TB_PRINT); 00461 SendMessageW(hwndToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(55,50)); 00462 SendMessageW(hwndToolbar, TB_AUTOSIZE, 0, 0); 00463 00464 bandinf.cbSize = sizeof(bandinf); 00465 bandinf.fMask = RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE; 00466 bandinf.fStyle = RBBS_CHILDEDGE; 00467 bandinf.cx = 100; 00468 bandinf.cyMinChild = 52; 00469 bandinf.hwndChild = hwndToolbar; 00470 00471 SendMessageW(hwndRebar, RB_INSERTBANDW, -1, (LPARAM)&bandinf); 00472 00473 hwndAddress = CreateWindowExW(0, WC_COMBOBOXEXW, NULL, WS_BORDER|WS_CHILD|WS_VISIBLE|CBS_DROPDOWN, 0, 0, 100,20,hwndRebar, (HMENU)IDC_BROWSE_ADDRESSBAR, shdocvw_hinstance, NULL); 00474 00475 bandinf.fMask |= RBBIM_TEXT; 00476 bandinf.fStyle = RBBS_CHILDEDGE | RBBS_BREAK; 00477 bandinf.lpText = addr; 00478 bandinf.cyMinChild = 20; 00479 bandinf.hwndChild = hwndAddress; 00480 00481 SendMessageW(hwndRebar, RB_INSERTBANDW, -1, (LPARAM)&bandinf); 00482 } 00483 00484 static LRESULT iewnd_OnCreate(HWND hwnd, LPCREATESTRUCTW lpcs) 00485 { 00486 InternetExplorer* This = (InternetExplorer*)lpcs->lpCreateParams; 00487 SetWindowLongPtrW(hwnd, 0, (LONG_PTR) lpcs->lpCreateParams); 00488 00489 This->menu = create_ie_menu(); 00490 00491 This->status_hwnd = CreateStatusWindowW(CCS_NODIVIDER|WS_CHILD|WS_VISIBLE, NULL, hwnd, IDC_BROWSE_STATUSBAR); 00492 SendMessageW(This->status_hwnd, SB_SIMPLE, TRUE, 0); 00493 00494 create_rebar(hwnd); 00495 00496 return 0; 00497 } 00498 00499 static LRESULT iewnd_OnSize(InternetExplorer *This, INT width, INT height) 00500 { 00501 HWND hwndRebar = GetDlgItem(This->frame_hwnd, IDC_BROWSE_REBAR); 00502 INT barHeight = SendMessageW(hwndRebar, RB_GETBARHEIGHT, 0, 0); 00503 RECT docarea = {0, 0, width, height}; 00504 00505 SendMessageW(This->status_hwnd, WM_SIZE, 0, 0); 00506 00507 adjust_ie_docobj_rect(This->frame_hwnd, &docarea); 00508 00509 if(This->doc_host.hwnd) 00510 SetWindowPos(This->doc_host.hwnd, NULL, docarea.left, docarea.top, docarea.right, docarea.bottom, 00511 SWP_NOZORDER | SWP_NOACTIVATE); 00512 00513 SetWindowPos(hwndRebar, NULL, 0, 0, width, barHeight, SWP_NOZORDER | SWP_NOACTIVATE); 00514 00515 return 0; 00516 } 00517 00518 static LRESULT iewnd_OnNotify(InternetExplorer *This, WPARAM wparam, LPARAM lparam) 00519 { 00520 NMHDR* hdr = (NMHDR*)lparam; 00521 00522 if(hdr->idFrom == IDC_BROWSE_ADDRESSBAR && hdr->code == CBEN_ENDEDITW) 00523 { 00524 NMCBEENDEDITW* info = (NMCBEENDEDITW*)lparam; 00525 00526 if(info->fChanged && info->iWhy == CBENF_RETURN && info->szText) 00527 { 00528 VARIANT vt; 00529 00530 V_VT(&vt) = VT_BSTR; 00531 V_BSTR(&vt) = SysAllocString(info->szText); 00532 00533 IWebBrowser2_Navigate2(WEBBROWSER2(This), &vt, NULL, NULL, NULL, NULL); 00534 00535 SysFreeString(V_BSTR(&vt)); 00536 00537 return 0; 00538 } 00539 } 00540 00541 return 0; 00542 } 00543 00544 static LRESULT iewnd_OnDestroy(InternetExplorer *This) 00545 { 00546 HWND hwndRebar = GetDlgItem(This->frame_hwnd, IDC_BROWSE_REBAR); 00547 HWND hwndToolbar = GetDlgItem(hwndRebar, IDC_BROWSE_TOOLBAR); 00548 HIMAGELIST list = (HIMAGELIST)SendMessageW(hwndToolbar, TB_GETIMAGELIST, 0, 0); 00549 00550 TRACE("%p\n", This); 00551 00552 free_fav_menu_data(get_fav_menu(This->menu)); 00553 ImageList_Destroy(list); 00554 This->frame_hwnd = NULL; 00555 PostQuitMessage(0); /* FIXME */ 00556 00557 return 0; 00558 } 00559 00560 static LRESULT iewnd_OnCommand(InternetExplorer *This, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) 00561 { 00562 switch(LOWORD(wparam)) 00563 { 00564 case ID_BROWSE_OPEN: 00565 DialogBoxParamW(shdocvw_hinstance, MAKEINTRESOURCEW(IDD_BROWSE_OPEN), hwnd, ie_dialog_open_proc, (LPARAM)This); 00566 break; 00567 00568 case ID_BROWSE_PRINT: 00569 if(This->doc_host.document) 00570 { 00571 IOleCommandTarget* target; 00572 00573 if(FAILED(IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (LPVOID*)&target))) 00574 break; 00575 00576 IOleCommandTarget_Exec(target, &CGID_MSHTML, IDM_PRINT, OLECMDEXECOPT_DODEFAULT, NULL, NULL); 00577 00578 IOleCommandTarget_Release(target); 00579 } 00580 break; 00581 00582 case ID_BROWSE_HOME: 00583 IWebBrowser2_GoHome(WEBBROWSER2(This)); 00584 break; 00585 00586 case ID_BROWSE_ABOUT: 00587 ie_dialog_about(hwnd); 00588 break; 00589 00590 case ID_BROWSE_QUIT: 00591 iewnd_OnDestroy(This); 00592 break; 00593 00594 default: 00595 if(LOWORD(wparam) >= ID_BROWSE_GOTOFAV_FIRST && LOWORD(wparam) <= ID_BROWSE_GOTOFAV_MAX) 00596 { 00597 LPCWSTR url = get_fav_url_from_id(get_fav_menu(This->menu), LOWORD(wparam)); 00598 00599 if(url) 00600 ie_navigate(This, url); 00601 } 00602 return DefWindowProcW(hwnd, msg, wparam, lparam); 00603 } 00604 return 0; 00605 } 00606 00607 static LRESULT update_addrbar(InternetExplorer *This, LPARAM lparam) 00608 { 00609 HWND hwndRebar = GetDlgItem(This->frame_hwnd, IDC_BROWSE_REBAR); 00610 HWND hwndAddress = GetDlgItem(hwndRebar, IDC_BROWSE_ADDRESSBAR); 00611 HWND hwndEdit = (HWND)SendMessageW(hwndAddress, CBEM_GETEDITCONTROL, 0, 0); 00612 LPCWSTR url = (LPCWSTR)lparam; 00613 00614 SendMessageW(hwndEdit, WM_SETTEXT, 0, (LPARAM)url); 00615 00616 return 0; 00617 } 00618 00619 static LRESULT CALLBACK 00620 ie_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) 00621 { 00622 InternetExplorer *This = (InternetExplorer*) GetWindowLongPtrW(hwnd, 0); 00623 00624 switch (msg) 00625 { 00626 case WM_CREATE: 00627 return iewnd_OnCreate(hwnd, (LPCREATESTRUCTW)lparam); 00628 case WM_DESTROY: 00629 return iewnd_OnDestroy(This); 00630 case WM_SIZE: 00631 return iewnd_OnSize(This, LOWORD(lparam), HIWORD(lparam)); 00632 case WM_COMMAND: 00633 return iewnd_OnCommand(This, hwnd, msg, wparam, lparam); 00634 case WM_NOTIFY: 00635 return iewnd_OnNotify(This, wparam, lparam); 00636 case WM_DOCHOSTTASK: 00637 return process_dochost_task(&This->doc_host, lparam); 00638 case WM_UPDATEADDRBAR: 00639 return update_addrbar(This, lparam); 00640 } 00641 return DefWindowProcW(hwnd, msg, wparam, lparam); 00642 } 00643 00644 void register_iewindow_class(void) 00645 { 00646 WNDCLASSEXW wc; 00647 00648 memset(&wc, 0, sizeof wc); 00649 wc.cbSize = sizeof(wc); 00650 wc.style = 0; 00651 wc.lpfnWndProc = ie_window_proc; 00652 wc.cbClsExtra = 0; 00653 wc.cbWndExtra = sizeof(InternetExplorer*); 00654 wc.hInstance = shdocvw_hinstance; 00655 wc.hIcon = LoadIconW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON)); 00656 wc.hIconSm = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON, 00657 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED); 00658 wc.hCursor = LoadCursorW(0, MAKEINTRESOURCEW(IDC_ARROW)); 00659 wc.hbrBackground = 0; 00660 wc.lpszClassName = szIEWinFrame; 00661 wc.lpszMenuName = NULL; 00662 00663 RegisterClassExW(&wc); 00664 } 00665 00666 void unregister_iewindow_class(void) 00667 { 00668 UnregisterClassW(szIEWinFrame, shdocvw_hinstance); 00669 } 00670 00671 static void create_frame_hwnd(InternetExplorer *This) 00672 { 00673 This->frame_hwnd = CreateWindowExW( 00674 WS_EX_WINDOWEDGE, 00675 szIEWinFrame, wszWineInternetExplorer, 00676 WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME 00677 | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, 00678 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 00679 NULL, NULL /* FIXME */, shdocvw_hinstance, This); 00680 } 00681 00682 static IWebBrowser2 *create_ie_window(LPCSTR cmdline) 00683 { 00684 IWebBrowser2 *wb = NULL; 00685 00686 InternetExplorer_Create(NULL, &IID_IWebBrowser2, (void**)&wb); 00687 if(!wb) 00688 return NULL; 00689 00690 IWebBrowser2_put_Visible(wb, VARIANT_TRUE); 00691 IWebBrowser2_put_MenuBar(wb, VARIANT_TRUE); 00692 00693 if(!*cmdline) { 00694 IWebBrowser2_GoHome(wb); 00695 }else { 00696 VARIANT var_url; 00697 DWORD len; 00698 int cmdlen; 00699 00700 if(!strncasecmp(cmdline, "-nohome", 7)) 00701 cmdline += 7; 00702 while(*cmdline == ' ' || *cmdline == '\t') 00703 cmdline++; 00704 cmdlen = lstrlenA(cmdline); 00705 if(cmdlen > 2 && cmdline[0] == '"' && cmdline[cmdlen-1] == '"') { 00706 cmdline++; 00707 cmdlen -= 2; 00708 } 00709 00710 V_VT(&var_url) = VT_BSTR; 00711 00712 len = MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, NULL, 0); 00713 V_BSTR(&var_url) = SysAllocStringLen(NULL, len); 00714 MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, V_BSTR(&var_url), len); 00715 00716 /* navigate to the first page */ 00717 IWebBrowser2_Navigate2(wb, &var_url, NULL, NULL, NULL, NULL); 00718 00719 SysFreeString(V_BSTR(&var_url)); 00720 } 00721 00722 return wb; 00723 } 00724 00725 static void WINAPI DocHostContainer_GetDocObjRect(DocHost* This, RECT* rc) 00726 { 00727 GetClientRect(This->frame_hwnd, rc); 00728 adjust_ie_docobj_rect(This->frame_hwnd, rc); 00729 } 00730 00731 static HRESULT WINAPI DocHostContainer_SetStatusText(DocHost* This, LPCWSTR text) 00732 { 00733 InternetExplorer* ie = DOCHOST_THIS(This); 00734 return update_ie_statustext(ie, text); 00735 } 00736 00737 static void WINAPI DocHostContainer_SetURL(DocHost* This, LPCWSTR url) 00738 { 00739 SendMessageW(This->frame_hwnd, WM_UPDATEADDRBAR, 0, (LPARAM)url); 00740 } 00741 00742 static HRESULT DocHostContainer_exec(DocHost* This, const GUID *cmd_group, DWORD cmdid, DWORD execopt, VARIANT *in, 00743 VARIANT *out) 00744 { 00745 return S_OK; 00746 } 00747 static const IDocHostContainerVtbl DocHostContainerVtbl = { 00748 DocHostContainer_GetDocObjRect, 00749 DocHostContainer_SetStatusText, 00750 DocHostContainer_SetURL, 00751 DocHostContainer_exec 00752 }; 00753 00754 HRESULT InternetExplorer_Create(IUnknown *pOuter, REFIID riid, void **ppv) 00755 { 00756 InternetExplorer *ret; 00757 HRESULT hres; 00758 00759 TRACE("(%p %s %p)\n", pOuter, debugstr_guid(riid), ppv); 00760 00761 ret = heap_alloc_zero(sizeof(InternetExplorer)); 00762 ret->ref = 0; 00763 00764 ret->doc_host.disp = (IDispatch*)WEBBROWSER2(ret); 00765 DocHost_Init(&ret->doc_host, (IDispatch*)WEBBROWSER2(ret), &DocHostContainerVtbl); 00766 00767 InternetExplorer_WebBrowser_Init(ret); 00768 00769 HlinkFrame_Init(&ret->hlink_frame, (IUnknown*)WEBBROWSER2(ret), &ret->doc_host); 00770 00771 create_frame_hwnd(ret); 00772 ret->doc_host.frame_hwnd = ret->frame_hwnd; 00773 00774 hres = IWebBrowser2_QueryInterface(WEBBROWSER2(ret), riid, ppv); 00775 if(FAILED(hres)) { 00776 heap_free(ret); 00777 return hres; 00778 } 00779 00780 return hres; 00781 } 00782 00783 /****************************************************************** 00784 * IEWinMain (SHDOCVW.101) 00785 * 00786 * Only returns on error. 00787 */ 00788 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow) 00789 { 00790 IWebBrowser2 *wb = NULL; 00791 MSG msg; 00792 HRESULT hres; 00793 00794 TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow); 00795 00796 if(*szCommandLine == '-' || *szCommandLine == '/') { 00797 if(!strcasecmp(szCommandLine+1, "regserver")) 00798 return register_iexplore(TRUE); 00799 if(!strcasecmp(szCommandLine+1, "unregserver")) 00800 return register_iexplore(FALSE); 00801 } 00802 00803 CoInitialize(NULL); 00804 00805 hres = register_class_object(TRUE); 00806 if(FAILED(hres)) { 00807 CoUninitialize(); 00808 ExitProcess(1); 00809 } 00810 00811 if(strcasecmp(szCommandLine, "-embedding")) 00812 wb = create_ie_window(szCommandLine); 00813 00814 /* run the message loop for this thread */ 00815 while (GetMessageW(&msg, 0, 0, 0)) 00816 { 00817 TranslateMessage(&msg); 00818 DispatchMessageW(&msg); 00819 } 00820 00821 if(wb) 00822 IWebBrowser2_Release(wb); 00823 00824 register_class_object(FALSE); 00825 00826 CoUninitialize(); 00827 00828 ExitProcess(0); 00829 return 0; 00830 } Generated on Sat May 26 2012 04:24:51 for ReactOS by
1.7.6.1
|