usp10: Correct matra type for Oriya 0x0B57.
[wine/multimedia.git] / dlls / shdocvw / iexplore.c
blob0ad1e894353c6d7c5af1868239e871f909633cac
1 /*
2 * SHDOCVW - Internet Explorer main frame window
4 * Copyright 2006 Mike McCormack (for CodeWeavers)
5 * Copyright 2006 Jacek Caban (for CodeWeavers)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define COBJMACROS
24 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wingdi.h"
29 #include "winnls.h"
30 #include "ole2.h"
31 #include "exdisp.h"
32 #include "oleidl.h"
34 #include "shdocvw.h"
35 #include "mshtmcid.h"
36 #include "shellapi.h"
37 #include "winreg.h"
38 #include "shlwapi.h"
39 #include "intshcut.h"
40 #include "ddeml.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
46 #define IDI_APPICON 1
48 static const WCHAR szIEWinFrame[] = { 'I','E','F','r','a','m','e',0 };
50 /* Windows uses "Microsoft Internet Explorer" */
51 static const WCHAR wszWineInternetExplorer[] =
52 {'W','i','n','e',' ','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',0};
54 static LONG obj_cnt;
55 static DWORD dde_inst;
56 static HSZ ddestr_iexplore, ddestr_openurl;
57 static struct list ie_list;
59 HRESULT update_ie_statustext(InternetExplorer* This, LPCWSTR text)
61 if(!SendMessageW(This->status_hwnd, SB_SETTEXTW, MAKEWORD(SB_SIMPLEID, 0), (LPARAM)text))
62 return E_FAIL;
64 return S_OK;
67 static void adjust_ie_docobj_rect(HWND frame, RECT* rc)
69 HWND hwndRebar = GetDlgItem(frame, IDC_BROWSE_REBAR);
70 HWND hwndStatus = GetDlgItem(frame, IDC_BROWSE_STATUSBAR);
71 INT barHeight = SendMessageW(hwndRebar, RB_GETBARHEIGHT, 0, 0);
73 rc->top += barHeight;
74 rc->bottom -= barHeight;
76 if(IsWindowVisible(hwndStatus))
78 RECT statusrc;
80 GetClientRect(hwndStatus, &statusrc);
81 rc->bottom -= statusrc.bottom - statusrc.top;
85 static HMENU get_tb_menu(HMENU menu)
87 HMENU menu_view = GetSubMenu(menu, 1);
89 return GetSubMenu(menu_view, 0);
92 static HMENU get_fav_menu(HMENU menu)
94 return GetSubMenu(menu, 2);
97 static LPWSTR get_fav_url_from_id(HMENU menu, UINT id)
99 MENUITEMINFOW item;
101 item.cbSize = sizeof(item);
102 item.fMask = MIIM_DATA;
104 if(!GetMenuItemInfoW(menu, id, FALSE, &item))
105 return NULL;
107 return (LPWSTR)item.dwItemData;
110 static void free_fav_menu_data(HMENU menu)
112 LPWSTR url;
113 int i;
115 for(i = 0; (url = get_fav_url_from_id(menu, ID_BROWSE_GOTOFAV_FIRST + i)); i++)
116 heap_free( url );
119 static int get_menu_item_count(HMENU menu)
121 MENUITEMINFOW item;
122 int count = 0;
123 int i;
125 item.cbSize = sizeof(item);
126 item.fMask = MIIM_DATA | MIIM_SUBMENU;
128 for(i = 0; GetMenuItemInfoW(menu, i, TRUE, &item); i++)
130 if(item.hSubMenu)
131 count += get_menu_item_count(item.hSubMenu);
132 else
133 count++;
136 return count;
139 static void add_fav_to_menu(HMENU favmenu, HMENU menu, LPWSTR title, LPCWSTR url)
141 MENUITEMINFOW item;
142 /* Subtract the number of standard elements in the Favorites menu */
143 int favcount = get_menu_item_count(favmenu) - 2;
144 LPWSTR urlbuf;
146 if(favcount > (ID_BROWSE_GOTOFAV_MAX - ID_BROWSE_GOTOFAV_FIRST))
148 FIXME("Add support for more than %d Favorites\n", favcount);
149 return;
152 urlbuf = heap_alloc((lstrlenW(url) + 1) * sizeof(WCHAR));
154 if(!urlbuf)
155 return;
157 lstrcpyW(urlbuf, url);
159 item.cbSize = sizeof(item);
160 item.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_DATA | MIIM_ID;
161 item.fType = MFT_STRING;
162 item.dwTypeData = title;
163 item.wID = ID_BROWSE_GOTOFAV_FIRST + favcount;
164 item.dwItemData = (ULONG_PTR)urlbuf;
165 InsertMenuItemW(menu, -1, TRUE, &item);
168 static void add_favs_to_menu(HMENU favmenu, HMENU menu, LPCWSTR dir)
170 WCHAR path[MAX_PATH*2];
171 const WCHAR search[] = {'*',0};
172 WCHAR* filename;
173 HANDLE findhandle;
174 WIN32_FIND_DATAW finddata;
175 IUniformResourceLocatorW* urlobj;
176 IPersistFile* urlfile = NULL;
177 HRESULT res;
179 lstrcpyW(path, dir);
180 PathAppendW(path, search);
182 findhandle = FindFirstFileW(path, &finddata);
184 if(findhandle == INVALID_HANDLE_VALUE)
185 return;
187 res = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_INPROC_SERVER, &IID_IUniformResourceLocatorW, (PVOID*)&urlobj);
189 if(SUCCEEDED(res))
190 res = IUnknown_QueryInterface(urlobj, &IID_IPersistFile, (PVOID*)&urlfile);
192 if(SUCCEEDED(res))
194 filename = path + lstrlenW(path) - lstrlenW(search);
198 lstrcpyW(filename, finddata.cFileName);
200 if(finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
202 MENUITEMINFOW item;
203 const WCHAR ignore1[] = {'.','.',0};
204 const WCHAR ignore2[] = {'.',0};
206 if(!lstrcmpW(filename, ignore1) || !lstrcmpW(filename, ignore2))
207 continue;
209 item.cbSize = sizeof(item);
210 item.fMask = MIIM_STRING | MIIM_SUBMENU;
211 item.dwTypeData = filename;
212 item.hSubMenu = CreatePopupMenu();
213 InsertMenuItemW(menu, -1, TRUE, &item);
214 add_favs_to_menu(favmenu, item.hSubMenu, path);
215 } else
217 WCHAR* fileext;
218 WCHAR* url = NULL;
219 const WCHAR urlext[] = {'.','u','r','l',0};
221 if(lstrcmpiW(PathFindExtensionW(filename), urlext))
222 continue;
224 if(FAILED(IPersistFile_Load(urlfile, path, 0)))
225 continue;
227 urlobj->lpVtbl->GetURL(urlobj, &url);
229 if(!url)
230 continue;
232 fileext = filename + lstrlenW(filename) - lstrlenW(urlext);
233 *fileext = 0;
234 add_fav_to_menu(favmenu, menu, filename, url);
236 } while(FindNextFileW(findhandle, &finddata));
239 if(urlfile)
240 IPersistFile_Release(urlfile);
242 if(urlobj)
243 IUnknown_Release(urlobj);
245 FindClose(findhandle);
248 static void add_tbs_to_menu(HMENU menu)
250 HUSKEY toolbar_handle;
251 WCHAR toolbar_key[] = {'S','o','f','t','w','a','r','e','\\',
252 'M','i','c','r','o','s','o','f','t','\\',
253 'I','n','t','e','r','n','e','t',' ',
254 'E','x','p','l','o','r','e','r','\\',
255 'T','o','o','l','b','a','r',0};
257 if(SHRegOpenUSKeyW(toolbar_key, KEY_READ, NULL, &toolbar_handle, TRUE) == ERROR_SUCCESS)
259 HUSKEY classes_handle;
260 WCHAR classes_key[] = {'S','o','f','t','w','a','r','e','\\',
261 'C','l','a','s','s','e','s','\\','C','L','S','I','D',0};
262 WCHAR guid[39];
263 DWORD value_len = sizeof(guid)/sizeof(guid[0]);
264 int i;
266 if(SHRegOpenUSKeyW(classes_key, KEY_READ, NULL, &classes_handle, TRUE) != ERROR_SUCCESS)
268 SHRegCloseUSKey(toolbar_handle);
269 ERR("Failed to open key %s\n", debugstr_w(classes_key));
270 return;
273 for(i = 0; SHRegEnumUSValueW(toolbar_handle, i, guid, &value_len, NULL, NULL, NULL, SHREGENUM_HKLM) == ERROR_SUCCESS; i++)
275 WCHAR tb_name[100];
276 DWORD tb_name_len = sizeof(tb_name)/sizeof(tb_name[0]);
277 HUSKEY tb_class_handle;
278 MENUITEMINFOW item;
279 LSTATUS ret;
280 value_len = sizeof(guid)/sizeof(guid[0]);
282 if(lstrlenW(guid) != 38)
284 TRACE("Found invalid IE toolbar entry: %s\n", debugstr_w(guid));
285 continue;
288 if(SHRegOpenUSKeyW(guid, KEY_READ, classes_handle, &tb_class_handle, TRUE) != ERROR_SUCCESS)
290 ERR("Failed to get class info for %s\n", debugstr_w(guid));
291 continue;
294 ret = SHRegQueryUSValueW(tb_class_handle, NULL, NULL, tb_name, &tb_name_len, TRUE, NULL, 0);
296 SHRegCloseUSKey(tb_class_handle);
298 if(ret != ERROR_SUCCESS)
300 ERR("Failed to get toolbar name for %s\n", debugstr_w(guid));
301 continue;
304 item.cbSize = sizeof(item);
305 item.fMask = MIIM_STRING;
306 item.dwTypeData = tb_name;
307 InsertMenuItemW(menu, GetMenuItemCount(menu), TRUE, &item);
310 SHRegCloseUSKey(classes_handle);
311 SHRegCloseUSKey(toolbar_handle);
315 static HMENU create_ie_menu(void)
317 HMENU menu = LoadMenuW(shdocvw_hinstance, MAKEINTRESOURCEW(IDR_BROWSE_MAIN_MENU));
318 HMENU favmenu = get_fav_menu(menu);
319 WCHAR path[MAX_PATH];
321 add_tbs_to_menu(get_tb_menu(menu));
323 if(SHGetFolderPathW(NULL, CSIDL_COMMON_FAVORITES, NULL, SHGFP_TYPE_CURRENT, path) == S_OK)
324 add_favs_to_menu(favmenu, favmenu, path);
326 if(SHGetFolderPathW(NULL, CSIDL_FAVORITES, NULL, SHGFP_TYPE_CURRENT, path) == S_OK)
327 add_favs_to_menu(favmenu, favmenu, path);
329 return menu;
332 static void ie_navigate(InternetExplorer* This, LPCWSTR url)
334 VARIANT variant;
336 V_VT(&variant) = VT_BSTR;
337 V_BSTR(&variant) = SysAllocString(url);
339 IWebBrowser2_Navigate2(&This->IWebBrowser2_iface, &variant, NULL, NULL, NULL, NULL);
341 SysFreeString(V_BSTR(&variant));
344 static INT_PTR CALLBACK ie_dialog_open_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
346 static InternetExplorer* This;
348 switch(msg)
350 case WM_INITDIALOG:
351 This = (InternetExplorer*)lparam;
352 EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
353 return TRUE;
355 case WM_COMMAND:
356 switch(LOWORD(wparam))
358 case IDC_BROWSE_OPEN_URL:
360 HWND hwndurl = GetDlgItem(hwnd, IDC_BROWSE_OPEN_URL);
361 int len = GetWindowTextLengthW(hwndurl);
363 EnableWindow(GetDlgItem(hwnd, IDOK), len ? TRUE : FALSE);
364 break;
366 case IDOK:
368 HWND hwndurl = GetDlgItem(hwnd, IDC_BROWSE_OPEN_URL);
369 int len = GetWindowTextLengthW(hwndurl);
371 if(len)
373 VARIANT url;
375 V_VT(&url) = VT_BSTR;
376 V_BSTR(&url) = SysAllocStringLen(NULL, len);
378 GetWindowTextW(hwndurl, V_BSTR(&url), len + 1);
379 IWebBrowser2_Navigate2(&This->IWebBrowser2_iface, &url, NULL, NULL, NULL, NULL);
381 SysFreeString(V_BSTR(&url));
384 /* fall through */
385 case IDCANCEL:
386 EndDialog(hwnd, wparam);
387 return TRUE;
390 return FALSE;
393 static void ie_dialog_about(HWND hwnd)
395 HICON icon = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON, 48, 48, LR_SHARED);
397 ShellAboutW(hwnd, wszWineInternetExplorer, NULL, icon);
399 DestroyIcon(icon);
402 static void add_tb_separator(HWND hwnd)
404 TBBUTTON btn;
406 ZeroMemory(&btn, sizeof(btn));
408 btn.iBitmap = 3;
409 btn.fsStyle = BTNS_SEP;
410 SendMessageW(hwnd, TB_ADDBUTTONSW, 1, (LPARAM)&btn);
413 static void add_tb_button(HWND hwnd, int bmp, int cmd, int strId)
415 TBBUTTON btn;
416 WCHAR buf[30];
418 LoadStringW(shdocvw_hinstance, strId, buf, sizeof(buf)/sizeof(buf[0]));
420 btn.iBitmap = bmp;
421 btn.idCommand = cmd;
422 btn.fsState = TBSTATE_ENABLED;
423 btn.fsStyle = BTNS_SHOWTEXT;
424 btn.dwData = 0;
425 btn.iString = (INT_PTR)buf;
427 SendMessageW(hwnd, TB_ADDBUTTONSW, 1, (LPARAM)&btn);
430 static void create_rebar(HWND hwnd)
432 HWND hwndRebar;
433 HWND hwndAddress;
434 HWND hwndToolbar;
435 REBARINFO rebarinf;
436 REBARBANDINFOW bandinf;
437 WCHAR addr[40];
438 HIMAGELIST imagelist;
439 WCHAR idb_ietoolbar[] = {'I','D','B','_','I','E','T','O','O','L','B','A','R',0};
441 LoadStringW(shdocvw_hinstance, IDS_ADDRESS, addr, sizeof(addr)/sizeof(addr[0]));
443 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);
445 rebarinf.cbSize = sizeof(rebarinf);
446 rebarinf.fMask = 0;
447 rebarinf.himl = NULL;
448 rebarinf.cbSize = sizeof(rebarinf);
450 SendMessageW(hwndRebar, RB_SETBARINFO, 0, (LPARAM)&rebarinf);
452 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);
454 imagelist = ImageList_LoadImageW(shdocvw_hinstance, idb_ietoolbar, 32, 0, CLR_NONE, IMAGE_BITMAP, LR_CREATEDIBSECTION);
456 SendMessageW(hwndToolbar, TB_SETIMAGELIST, 0, (LPARAM)imagelist);
457 SendMessageW(hwndToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
458 add_tb_button(hwndToolbar, 0, 0, IDS_TB_BACK);
459 add_tb_button(hwndToolbar, 1, 0, IDS_TB_FORWARD);
460 add_tb_button(hwndToolbar, 2, 0, IDS_TB_STOP);
461 add_tb_button(hwndToolbar, 3, 0, IDS_TB_REFRESH);
462 add_tb_button(hwndToolbar, 4, ID_BROWSE_HOME, IDS_TB_HOME);
463 add_tb_separator(hwndToolbar);
464 add_tb_button(hwndToolbar, 5, ID_BROWSE_PRINT, IDS_TB_PRINT);
465 SendMessageW(hwndToolbar, TB_SETBUTTONSIZE, 0, MAKELPARAM(55,50));
466 SendMessageW(hwndToolbar, TB_AUTOSIZE, 0, 0);
468 bandinf.cbSize = sizeof(bandinf);
469 bandinf.fMask = RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE;
470 bandinf.fStyle = RBBS_CHILDEDGE;
471 bandinf.cx = 100;
472 bandinf.cyMinChild = 52;
473 bandinf.hwndChild = hwndToolbar;
475 SendMessageW(hwndRebar, RB_INSERTBANDW, -1, (LPARAM)&bandinf);
477 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);
479 bandinf.fMask |= RBBIM_TEXT;
480 bandinf.fStyle = RBBS_CHILDEDGE | RBBS_BREAK;
481 bandinf.lpText = addr;
482 bandinf.cyMinChild = 20;
483 bandinf.hwndChild = hwndAddress;
485 SendMessageW(hwndRebar, RB_INSERTBANDW, -1, (LPARAM)&bandinf);
488 static LRESULT iewnd_OnCreate(HWND hwnd, LPCREATESTRUCTW lpcs)
490 InternetExplorer* This = (InternetExplorer*)lpcs->lpCreateParams;
491 SetWindowLongPtrW(hwnd, 0, (LONG_PTR) lpcs->lpCreateParams);
493 This->menu = create_ie_menu();
495 This->status_hwnd = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|SBT_NOBORDERS|CCS_NODIVIDER,
496 NULL, hwnd, IDC_BROWSE_STATUSBAR);
497 SendMessageW(This->status_hwnd, SB_SIMPLE, TRUE, 0);
499 create_rebar(hwnd);
501 return 0;
504 static LRESULT iewnd_OnSize(InternetExplorer *This, INT width, INT height)
506 HWND hwndRebar = GetDlgItem(This->frame_hwnd, IDC_BROWSE_REBAR);
507 INT barHeight = SendMessageW(hwndRebar, RB_GETBARHEIGHT, 0, 0);
508 RECT docarea = {0, 0, width, height};
510 SendMessageW(This->status_hwnd, WM_SIZE, 0, 0);
512 adjust_ie_docobj_rect(This->frame_hwnd, &docarea);
514 if(This->doc_host->doc_host.hwnd)
515 SetWindowPos(This->doc_host->doc_host.hwnd, NULL, docarea.left, docarea.top, docarea.right, docarea.bottom,
516 SWP_NOZORDER | SWP_NOACTIVATE);
518 SetWindowPos(hwndRebar, NULL, 0, 0, width, barHeight, SWP_NOZORDER | SWP_NOACTIVATE);
520 return 0;
523 static LRESULT iewnd_OnNotify(InternetExplorer *This, WPARAM wparam, LPARAM lparam)
525 NMHDR* hdr = (NMHDR*)lparam;
527 if(hdr->idFrom == IDC_BROWSE_ADDRESSBAR && hdr->code == CBEN_ENDEDITW)
529 NMCBEENDEDITW* info = (NMCBEENDEDITW*)lparam;
531 if(info->fChanged && info->iWhy == CBENF_RETURN)
533 VARIANT vt;
535 V_VT(&vt) = VT_BSTR;
536 V_BSTR(&vt) = SysAllocString(info->szText);
538 IWebBrowser2_Navigate2(&This->IWebBrowser2_iface, &vt, NULL, NULL, NULL, NULL);
540 SysFreeString(V_BSTR(&vt));
542 return 0;
546 return 0;
549 static LRESULT iewnd_OnDestroy(InternetExplorer *This)
551 HWND hwndRebar = GetDlgItem(This->frame_hwnd, IDC_BROWSE_REBAR);
552 HWND hwndToolbar = GetDlgItem(hwndRebar, IDC_BROWSE_TOOLBAR);
553 HIMAGELIST list = (HIMAGELIST)SendMessageW(hwndToolbar, TB_GETIMAGELIST, 0, 0);
555 TRACE("%p\n", This);
557 free_fav_menu_data(get_fav_menu(This->menu));
558 ImageList_Destroy(list);
559 This->frame_hwnd = NULL;
561 return 0;
564 static LRESULT iewnd_OnCommand(InternetExplorer *This, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
566 switch(LOWORD(wparam))
568 case ID_BROWSE_OPEN:
569 DialogBoxParamW(shdocvw_hinstance, MAKEINTRESOURCEW(IDD_BROWSE_OPEN), hwnd, ie_dialog_open_proc, (LPARAM)This);
570 break;
572 case ID_BROWSE_PRINT:
573 if(This->doc_host->doc_host.document)
575 IOleCommandTarget* target;
577 if(FAILED(IUnknown_QueryInterface(This->doc_host->doc_host.document, &IID_IOleCommandTarget, (LPVOID*)&target)))
578 break;
580 IOleCommandTarget_Exec(target, &CGID_MSHTML, IDM_PRINT, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
582 IOleCommandTarget_Release(target);
584 break;
586 case ID_BROWSE_HOME:
587 IWebBrowser2_GoHome(&This->IWebBrowser2_iface);
588 break;
590 case ID_BROWSE_ABOUT:
591 ie_dialog_about(hwnd);
592 break;
594 case ID_BROWSE_QUIT:
595 ShowWindow(hwnd, SW_HIDE);
596 break;
598 default:
599 if(LOWORD(wparam) >= ID_BROWSE_GOTOFAV_FIRST && LOWORD(wparam) <= ID_BROWSE_GOTOFAV_MAX)
601 LPCWSTR url = get_fav_url_from_id(get_fav_menu(This->menu), LOWORD(wparam));
603 if(url)
604 ie_navigate(This, url);
606 return DefWindowProcW(hwnd, msg, wparam, lparam);
608 return 0;
611 static LRESULT update_addrbar(InternetExplorer *This, LPARAM lparam)
613 HWND hwndRebar = GetDlgItem(This->frame_hwnd, IDC_BROWSE_REBAR);
614 HWND hwndAddress = GetDlgItem(hwndRebar, IDC_BROWSE_ADDRESSBAR);
615 HWND hwndEdit = (HWND)SendMessageW(hwndAddress, CBEM_GETEDITCONTROL, 0, 0);
616 LPCWSTR url = (LPCWSTR)lparam;
618 SendMessageW(hwndEdit, WM_SETTEXT, 0, (LPARAM)url);
620 return 0;
623 static LRESULT CALLBACK
624 ie_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
626 InternetExplorer *This = (InternetExplorer*) GetWindowLongPtrW(hwnd, 0);
628 switch (msg)
630 case WM_CREATE:
631 return iewnd_OnCreate(hwnd, (LPCREATESTRUCTW)lparam);
632 case WM_CLOSE:
633 TRACE("WM_CLOSE\n");
634 ShowWindow(hwnd, SW_HIDE);
635 return 0;
636 case WM_SHOWWINDOW:
637 TRACE("WM_SHOWWINDOW %lx\n", wparam);
638 if(wparam)
639 IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
640 else
641 IWebBrowser2_Release(&This->IWebBrowser2_iface);
642 break;
643 case WM_DESTROY:
644 return iewnd_OnDestroy(This);
645 case WM_SIZE:
646 return iewnd_OnSize(This, LOWORD(lparam), HIWORD(lparam));
647 case WM_COMMAND:
648 return iewnd_OnCommand(This, hwnd, msg, wparam, lparam);
649 case WM_NOTIFY:
650 return iewnd_OnNotify(This, wparam, lparam);
651 case WM_DOCHOSTTASK:
652 return process_dochost_tasks(&This->doc_host->doc_host);
653 case WM_UPDATEADDRBAR:
654 return update_addrbar(This, lparam);
656 return DefWindowProcW(hwnd, msg, wparam, lparam);
659 void register_iewindow_class(void)
661 WNDCLASSEXW wc;
663 memset(&wc, 0, sizeof wc);
664 wc.cbSize = sizeof(wc);
665 wc.style = 0;
666 wc.lpfnWndProc = ie_window_proc;
667 wc.cbClsExtra = 0;
668 wc.cbWndExtra = sizeof(InternetExplorer*);
669 wc.hInstance = shdocvw_hinstance;
670 wc.hIcon = LoadIconW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON));
671 wc.hIconSm = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON,
672 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
673 wc.hCursor = LoadCursorW(0, MAKEINTRESOURCEW(IDC_ARROW));
674 wc.hbrBackground = 0;
675 wc.lpszClassName = szIEWinFrame;
676 wc.lpszMenuName = NULL;
678 RegisterClassExW(&wc);
681 void unregister_iewindow_class(void)
683 UnregisterClassW(szIEWinFrame, shdocvw_hinstance);
686 static void create_frame_hwnd(InternetExplorer *This)
688 This->frame_hwnd = CreateWindowExW(
689 WS_EX_WINDOWEDGE,
690 szIEWinFrame, wszWineInternetExplorer,
691 WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
692 | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
693 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
694 NULL, NULL /* FIXME */, shdocvw_hinstance, This);
697 static inline IEDocHost *impl_from_DocHost(DocHost *iface)
699 return CONTAINING_RECORD(iface, IEDocHost, doc_host);
702 static ULONG IEDocHost_addref(DocHost *iface)
704 IEDocHost *This = impl_from_DocHost(iface);
705 LONG ref = InterlockedIncrement(&This->ref);
707 TRACE("(%p) ref=%d\n", This, ref);
709 return ref;
712 static ULONG IEDocHost_release(DocHost *iface)
714 IEDocHost *This = impl_from_DocHost(iface);
715 LONG ref = InterlockedDecrement(&This->ref);
717 TRACE("(%p) ref=%d\n", This, ref);
719 if(!ref) {
720 if(This->ie)
721 ERR("This->ie is not NULL\n");
722 heap_free(This);
725 return ref;
728 static void WINAPI DocHostContainer_GetDocObjRect(DocHost* This, RECT* rc)
730 GetClientRect(This->frame_hwnd, rc);
731 adjust_ie_docobj_rect(This->frame_hwnd, rc);
734 static HRESULT WINAPI DocHostContainer_SetStatusText(DocHost *iface, LPCWSTR text)
736 IEDocHost *This = impl_from_DocHost(iface);
737 return update_ie_statustext(This->ie, text);
740 static void WINAPI DocHostContainer_SetURL(DocHost* iface, LPCWSTR url)
742 IEDocHost *This = impl_from_DocHost(iface);
744 if(!This->ie)
745 return;
747 This->ie->nohome = FALSE;
748 SendMessageW(This->ie->frame_hwnd, WM_UPDATEADDRBAR, 0, (LPARAM)url);
751 static HRESULT DocHostContainer_exec(DocHost* This, const GUID *cmd_group, DWORD cmdid, DWORD execopt, VARIANT *in,
752 VARIANT *out)
754 return S_OK;
756 static const IDocHostContainerVtbl DocHostContainerVtbl = {
757 IEDocHost_addref,
758 IEDocHost_release,
759 DocHostContainer_GetDocObjRect,
760 DocHostContainer_SetStatusText,
761 DocHostContainer_SetURL,
762 DocHostContainer_exec
765 static HRESULT create_ie(InternetExplorer **ret_obj)
767 InternetExplorer *ret;
769 ret = heap_alloc_zero(sizeof(InternetExplorer));
770 if(!ret)
771 return E_OUTOFMEMORY;
773 ret->doc_host = heap_alloc_zero(sizeof(IEDocHost));
774 if(!ret->doc_host) {
775 heap_free(ret);
776 return E_OUTOFMEMORY;
779 ret->ref = 1;
780 ret->doc_host->ref = 1;
781 ret->doc_host->ie = ret;
783 DocHost_Init(&ret->doc_host->doc_host, (IDispatch*)&ret->IWebBrowser2_iface, &DocHostContainerVtbl);
785 InternetExplorer_WebBrowser_Init(ret);
787 HlinkFrame_Init(&ret->hlink_frame, (IUnknown*)&ret->IWebBrowser2_iface, &ret->doc_host->doc_host);
789 create_frame_hwnd(ret);
790 ret->doc_host->doc_host.frame_hwnd = ret->frame_hwnd;
792 InterlockedIncrement(&obj_cnt);
793 list_add_tail(&ie_list, &ret->entry);
794 *ret_obj = ret;
795 return S_OK;
798 HRESULT InternetExplorer_Create(IUnknown *pOuter, REFIID riid, void **ppv)
800 InternetExplorer *ret;
801 HRESULT hres;
803 TRACE("(%p %s %p)\n", pOuter, debugstr_guid(riid), ppv);
805 hres = create_ie(&ret);
806 if(FAILED(hres))
807 return hres;
809 hres = IWebBrowser2_QueryInterface(&ret->IWebBrowser2_iface, riid, ppv);
810 IWebBrowser2_Release(&ret->IWebBrowser2_iface);
811 if(FAILED(hres))
812 return hres;
814 return S_OK;
817 void released_obj(void)
819 if(!InterlockedDecrement(&obj_cnt))
820 PostQuitMessage(0);
823 static BOOL create_ie_window(LPCSTR cmdline)
825 InternetExplorer *ie;
826 HRESULT hres;
828 hres = create_ie(&ie);
829 if(FAILED(hres))
830 return FALSE;
832 IWebBrowser2_put_Visible(&ie->IWebBrowser2_iface, VARIANT_TRUE);
833 IWebBrowser2_put_MenuBar(&ie->IWebBrowser2_iface, VARIANT_TRUE);
835 if(!*cmdline) {
836 IWebBrowser2_GoHome(&ie->IWebBrowser2_iface);
837 }else {
838 VARIANT var_url;
839 DWORD len;
840 int cmdlen;
842 while(*cmdline == ' ' || *cmdline == '\t')
843 cmdline++;
844 cmdlen = lstrlenA(cmdline);
845 if(cmdlen > 2 && cmdline[0] == '"' && cmdline[cmdlen-1] == '"') {
846 cmdline++;
847 cmdlen -= 2;
850 if(cmdlen == 7 && !memcmp(cmdline, "-nohome", 7)) {
851 ie->nohome = TRUE;
852 }else {
853 V_VT(&var_url) = VT_BSTR;
855 len = MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, NULL, 0);
856 V_BSTR(&var_url) = SysAllocStringLen(NULL, len);
857 MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, V_BSTR(&var_url), len);
859 /* navigate to the first page */
860 IWebBrowser2_Navigate2(&ie->IWebBrowser2_iface, &var_url, NULL, NULL, NULL, NULL);
862 SysFreeString(V_BSTR(&var_url));
866 IWebBrowser2_Release(&ie->IWebBrowser2_iface);
867 return TRUE;
870 static ULONG open_dde_url(WCHAR *dde_url)
872 InternetExplorer *ie = NULL, *iter;
873 WCHAR *url, *url_end;
874 VARIANT urlv;
875 HRESULT hres;
877 TRACE("%s\n", debugstr_w(dde_url));
879 url = dde_url;
880 if(*url == '"') {
881 url++;
882 url_end = strchrW(url, '"');
883 if(!url_end) {
884 FIXME("missing string terminator\n");
885 return 0;
887 *url_end = 0;
888 }else {
889 url_end = strchrW(url, ',');
890 if(url_end)
891 *url_end = 0;
892 else
893 url_end = url + strlenW(url);
896 LIST_FOR_EACH_ENTRY(iter, &ie_list, InternetExplorer, entry) {
897 if(iter->nohome) {
898 IWebBrowser2_AddRef(&iter->IWebBrowser2_iface);
899 ie = iter;
900 break;
904 if(!ie) {
905 hres = create_ie(&ie);
906 if(FAILED(hres))
907 return 0;
910 IWebBrowser2_put_Visible(&ie->IWebBrowser2_iface, VARIANT_TRUE);
911 IWebBrowser2_put_MenuBar(&ie->IWebBrowser2_iface, VARIANT_TRUE);
913 V_VT(&urlv) = VT_BSTR;
914 V_BSTR(&urlv) = SysAllocStringLen(url, url_end-url);
915 if(!V_BSTR(&urlv)) {
916 IWebBrowser2_Release(&ie->IWebBrowser2_iface);
917 return 0;
920 hres = IWebBrowser2_Navigate2(&ie->IWebBrowser2_iface, &urlv, NULL, NULL, NULL, NULL);
921 if(FAILED(hres))
922 return 0;
924 IWebBrowser2_Release(&ie->IWebBrowser2_iface);
925 return DDE_FACK;
928 static HDDEDATA WINAPI dde_proc(UINT type, UINT uFmt, HCONV hConv, HSZ hsz1, HSZ hsz2, HDDEDATA data,
929 ULONG_PTR dwData1, ULONG_PTR dwData2)
931 switch(type) {
932 case XTYP_CONNECT:
933 TRACE("XTYP_CONNECT %p\n", hsz1);
934 return (HDDEDATA)!DdeCmpStringHandles(hsz1, ddestr_openurl);
936 case XTYP_EXECUTE: {
937 WCHAR *url;
938 DWORD size;
939 HDDEDATA ret;
941 TRACE("XTYP_EXECUTE %p\n", data);
943 size = DdeGetData(data, NULL, 0, 0);
944 if(!size) {
945 WARN("size = 0\n");
946 break;
949 url = heap_alloc(size);
950 if(!url)
951 break;
953 if(DdeGetData(data, (BYTE*)url, size, 0) != size) {
954 ERR("error during read\n");
955 break;
958 ret = (HDDEDATA)open_dde_url(url);
960 heap_free(url);
961 return ret;
964 case XTYP_REQUEST:
965 FIXME("XTYP_REQUEST\n");
966 break;
968 default:
969 TRACE("type %d\n", type);
972 return NULL;
975 static void init_dde(void)
977 UINT res;
979 static const WCHAR iexploreW[] = {'I','E','x','p','l','o','r','e',0};
980 static const WCHAR openurlW[] = {'W','W','W','_','O','p','e','n','U','R','L',0};
982 res = DdeInitializeW(&dde_inst, dde_proc, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES | CBF_FAIL_POKES, 0);
983 if(res != DMLERR_NO_ERROR) {
984 WARN("DdeInitialize failed: %u\n", res);
985 return;
988 ddestr_iexplore = DdeCreateStringHandleW(dde_inst, iexploreW, CP_WINUNICODE);
989 if(!ddestr_iexplore)
990 WARN("Failed to create string handle: %u\n", DdeGetLastError(dde_inst));
992 ddestr_openurl = DdeCreateStringHandleW(dde_inst, openurlW, CP_WINUNICODE);
993 if(!ddestr_openurl)
994 WARN("Failed to create string handle: %u\n", DdeGetLastError(dde_inst));
996 res = (ULONG)DdeNameService(dde_inst, ddestr_iexplore, 0, DNS_REGISTER);
997 if(res != DMLERR_NO_ERROR)
998 WARN("DdeNameService failed: %u\n", res);
1001 static void release_dde(void)
1003 if(ddestr_iexplore)
1004 DdeNameService(dde_inst, ddestr_iexplore, 0, DNS_UNREGISTER);
1005 if(ddestr_openurl)
1006 DdeFreeStringHandle(dde_inst, ddestr_openurl);
1007 if(ddestr_iexplore)
1008 DdeFreeStringHandle(dde_inst, ddestr_iexplore);
1009 DdeUninitialize(dde_inst);
1012 /******************************************************************
1013 * IEWinMain (SHDOCVW.101)
1015 * Only returns on error.
1017 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
1019 MSG msg;
1020 HRESULT hres;
1022 TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
1024 list_init(&ie_list);
1026 if(*szCommandLine == '-' || *szCommandLine == '/') {
1027 if(!strcasecmp(szCommandLine+1, "regserver"))
1028 return register_iexplore(TRUE);
1029 if(!strcasecmp(szCommandLine+1, "unregserver"))
1030 return register_iexplore(FALSE);
1033 CoInitialize(NULL);
1035 hres = register_class_object(TRUE);
1036 if(FAILED(hres)) {
1037 CoUninitialize();
1038 ExitProcess(1);
1041 init_dde();
1043 if(strcasecmp(szCommandLine, "-embedding")) {
1044 if(!create_ie_window(szCommandLine)) {
1045 CoUninitialize();
1046 ExitProcess(1);
1050 /* run the message loop for this thread */
1051 while (GetMessageW(&msg, 0, 0, 0))
1053 TranslateMessage(&msg);
1054 DispatchMessageW(&msg);
1057 register_class_object(FALSE);
1058 release_dde();
1060 CoUninitialize();
1062 ExitProcess(0);
1063 return 0;