dmime: Implement band track IDirectMusicTrack_Play.
[wine.git] / dlls / ieframe / iexplore.c
blob43ecf5ee3f14163983d112022e70d79636852b04
1 /*
2 * ieframe - 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>
26 #include "ieframe.h"
27 #include "resource.h"
29 #include "winuser.h"
30 #include "wingdi.h"
31 #include "winnls.h"
32 #include "ole2.h"
33 #include "exdisp.h"
34 #include "oleidl.h"
36 #include "mshtmcid.h"
37 #include "shellapi.h"
38 #include "winreg.h"
39 #include "shlwapi.h"
40 #include "intshcut.h"
41 #include "ddeml.h"
42 #include "ieautomation.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(ieframe);
48 #define IDI_APPICON 1
50 #define WM_UPDATEADDRBAR (WM_APP+1)
52 static const WCHAR szIEWinFrame[] = { 'I','E','F','r','a','m','e',0 };
54 /* Windows uses "Microsoft Internet Explorer" */
55 static const WCHAR wszWineInternetExplorer[] =
56 {'W','i','n','e',' ','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',0};
58 static LONG obj_cnt;
59 static DWORD dde_inst;
60 static HSZ ddestr_iexplore, ddestr_openurl;
61 static struct list ie_list = LIST_INIT(ie_list);
63 HRESULT update_ie_statustext(InternetExplorer* This, LPCWSTR text)
65 if(!SendMessageW(This->status_hwnd, SB_SETTEXTW, MAKEWORD(SB_SIMPLEID, 0), (LPARAM)text))
66 return E_FAIL;
68 return S_OK;
71 static void adjust_ie_docobj_rect(HWND frame, RECT* rc)
73 HWND hwndRebar = GetDlgItem(frame, IDC_BROWSE_REBAR);
74 HWND hwndStatus = GetDlgItem(frame, IDC_BROWSE_STATUSBAR);
75 INT barHeight = SendMessageW(hwndRebar, RB_GETBARHEIGHT, 0, 0);
77 InflateRect(rc, 0, -barHeight);
79 if(IsWindowVisible(hwndStatus))
81 RECT statusrc;
83 GetClientRect(hwndStatus, &statusrc);
84 rc->bottom -= statusrc.bottom - statusrc.top;
88 static HMENU get_tb_menu(HMENU menu)
90 HMENU menu_view = GetSubMenu(menu, 1);
92 return GetSubMenu(menu_view, 0);
95 static HMENU get_fav_menu(HMENU menu)
97 return GetSubMenu(menu, 2);
100 static LPWSTR get_fav_url_from_id(HMENU menu, UINT id)
102 MENUITEMINFOW item;
104 item.cbSize = sizeof(item);
105 item.fMask = MIIM_DATA;
107 if(!GetMenuItemInfoW(menu, id, FALSE, &item))
108 return NULL;
110 return (LPWSTR)item.dwItemData;
113 static void free_fav_menu_data(HMENU menu)
115 LPWSTR url;
116 int i;
118 for(i = 0; (url = get_fav_url_from_id(menu, ID_BROWSE_GOTOFAV_FIRST + i)); i++)
119 free( url );
122 static int get_menu_item_count(HMENU menu)
124 MENUITEMINFOW item;
125 int count = 0;
126 int i;
128 item.cbSize = sizeof(item);
129 item.fMask = MIIM_DATA | MIIM_SUBMENU;
131 for(i = 0; GetMenuItemInfoW(menu, i, TRUE, &item); i++)
133 if(item.hSubMenu)
134 count += get_menu_item_count(item.hSubMenu);
135 else
136 count++;
139 return count;
142 static void add_fav_to_menu(HMENU favmenu, HMENU menu, LPWSTR title, LPCWSTR url)
144 MENUITEMINFOW item;
145 /* Subtract the number of standard elements in the Favorites menu */
146 int favcount = get_menu_item_count(favmenu) - 2;
147 LPWSTR urlbuf;
149 if(favcount > (ID_BROWSE_GOTOFAV_MAX - ID_BROWSE_GOTOFAV_FIRST))
151 FIXME("Add support for more than %d Favorites\n", favcount);
152 return;
155 urlbuf = malloc((wcslen(url) + 1) * sizeof(WCHAR));
157 if(!urlbuf)
158 return;
160 lstrcpyW(urlbuf, url);
162 item.cbSize = sizeof(item);
163 item.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_DATA | MIIM_ID;
164 item.fType = MFT_STRING;
165 item.dwTypeData = title;
166 item.wID = ID_BROWSE_GOTOFAV_FIRST + favcount;
167 item.dwItemData = (ULONG_PTR)urlbuf;
168 InsertMenuItemW(menu, -1, TRUE, &item);
171 static void add_favs_to_menu(HMENU favmenu, HMENU menu, LPCWSTR dir)
173 static const WCHAR search[] = {'*',0};
174 WCHAR path[MAX_PATH*2];
175 WCHAR* filename;
176 HANDLE findhandle;
177 WIN32_FIND_DATAW finddata;
178 IUniformResourceLocatorW* urlobj;
179 IPersistFile* urlfile = NULL;
180 HRESULT res;
182 lstrcpyW(path, dir);
183 PathAppendW(path, search);
185 findhandle = FindFirstFileW(path, &finddata);
187 if(findhandle == INVALID_HANDLE_VALUE)
188 return;
190 res = CoCreateInstance(&CLSID_InternetShortcut, NULL, CLSCTX_INPROC_SERVER, &IID_IUniformResourceLocatorW, (PVOID*)&urlobj);
192 if(SUCCEEDED(res))
193 res = IUnknown_QueryInterface((IUnknown*)urlobj, &IID_IPersistFile, (PVOID*)&urlfile);
195 if(SUCCEEDED(res))
197 filename = path + lstrlenW(path) - lstrlenW(search);
201 lstrcpyW(filename, finddata.cFileName);
203 if(finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
205 static const WCHAR ignore1[] = {'.','.',0};
206 static const WCHAR ignore2[] = {'.',0};
207 MENUITEMINFOW item;
209 if(!lstrcmpW(filename, ignore1) || !lstrcmpW(filename, ignore2))
210 continue;
212 item.cbSize = sizeof(item);
213 item.fMask = MIIM_STRING | MIIM_SUBMENU;
214 item.dwTypeData = filename;
215 item.hSubMenu = CreatePopupMenu();
216 InsertMenuItemW(menu, -1, TRUE, &item);
217 add_favs_to_menu(favmenu, item.hSubMenu, path);
218 } else
220 static const WCHAR urlext[] = {'.','u','r','l',0};
221 WCHAR* fileext;
222 WCHAR* url = NULL;
224 if(lstrcmpiW(PathFindExtensionW(filename), urlext))
225 continue;
227 if(FAILED(IPersistFile_Load(urlfile, path, 0)))
228 continue;
230 urlobj->lpVtbl->GetURL(urlobj, &url);
232 if(!url)
233 continue;
235 fileext = filename + lstrlenW(filename) - lstrlenW(urlext);
236 *fileext = 0;
237 add_fav_to_menu(favmenu, menu, filename, url);
239 } while(FindNextFileW(findhandle, &finddata));
242 if(urlfile)
243 IPersistFile_Release(urlfile);
245 if(urlobj)
246 IUnknown_Release((IUnknown*)urlobj);
248 FindClose(findhandle);
251 static void add_tbs_to_menu(HMENU menu)
253 static const WCHAR toolbar_key[] = {'S','o','f','t','w','a','r','e','\\',
254 'M','i','c','r','o','s','o','f','t','\\',
255 'I','n','t','e','r','n','e','t',' ',
256 'E','x','p','l','o','r','e','r','\\',
257 'T','o','o','l','b','a','r',0};
258 HUSKEY toolbar_handle;
260 if(SHRegOpenUSKeyW(toolbar_key, KEY_READ, NULL, &toolbar_handle, TRUE) == ERROR_SUCCESS)
262 static const WCHAR classes_key[] = {'S','o','f','t','w','a','r','e','\\',
263 'C','l','a','s','s','e','s','\\','C','L','S','I','D',0};
264 HUSKEY classes_handle;
265 WCHAR guid[39];
266 DWORD value_len = ARRAY_SIZE(guid);
267 int i;
269 if(SHRegOpenUSKeyW(classes_key, KEY_READ, NULL, &classes_handle, TRUE) != ERROR_SUCCESS)
271 SHRegCloseUSKey(toolbar_handle);
272 ERR("Failed to open key %s\n", debugstr_w(classes_key));
273 return;
276 for(i = 0; SHRegEnumUSValueW(toolbar_handle, i, guid, &value_len, NULL, NULL, NULL, SHREGENUM_HKLM) == ERROR_SUCCESS; i++)
278 WCHAR tb_name[100];
279 DWORD tb_name_len = ARRAY_SIZE(tb_name);
280 HUSKEY tb_class_handle;
281 MENUITEMINFOW item;
282 LSTATUS ret;
283 value_len = ARRAY_SIZE(guid);
285 if(lstrlenW(guid) != 38)
287 TRACE("Found invalid IE toolbar entry: %s\n", debugstr_w(guid));
288 continue;
291 if(SHRegOpenUSKeyW(guid, KEY_READ, classes_handle, &tb_class_handle, TRUE) != ERROR_SUCCESS)
293 ERR("Failed to get class info for %s\n", debugstr_w(guid));
294 continue;
297 ret = SHRegQueryUSValueW(tb_class_handle, NULL, NULL, tb_name, &tb_name_len, TRUE, NULL, 0);
299 SHRegCloseUSKey(tb_class_handle);
301 if(ret != ERROR_SUCCESS)
303 ERR("Failed to get toolbar name for %s\n", debugstr_w(guid));
304 continue;
307 item.cbSize = sizeof(item);
308 item.fMask = MIIM_STRING;
309 item.dwTypeData = tb_name;
310 InsertMenuItemW(menu, GetMenuItemCount(menu), TRUE, &item);
313 SHRegCloseUSKey(classes_handle);
314 SHRegCloseUSKey(toolbar_handle);
318 static HMENU create_ie_menu(void)
320 HMENU menu = LoadMenuW(ieframe_instance, MAKEINTRESOURCEW(IDR_BROWSE_MAIN_MENU));
321 HMENU favmenu = get_fav_menu(menu);
322 WCHAR path[MAX_PATH];
324 add_tbs_to_menu(get_tb_menu(menu));
326 if(SHGetFolderPathW(NULL, CSIDL_COMMON_FAVORITES, NULL, SHGFP_TYPE_CURRENT, path) == S_OK)
327 add_favs_to_menu(favmenu, favmenu, path);
329 if(SHGetFolderPathW(NULL, CSIDL_FAVORITES, NULL, SHGFP_TYPE_CURRENT, path) == S_OK)
330 add_favs_to_menu(favmenu, favmenu, path);
332 return menu;
335 static void ie_navigate(InternetExplorer* This, LPCWSTR url)
337 VARIANT variant;
339 V_VT(&variant) = VT_BSTR;
340 V_BSTR(&variant) = SysAllocString(url);
342 IWebBrowser2_Navigate2(&This->IWebBrowser2_iface, &variant, NULL, NULL, NULL, NULL);
344 SysFreeString(V_BSTR(&variant));
347 static INT_PTR CALLBACK ie_dialog_open_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
349 static InternetExplorer* This;
351 switch(msg)
353 case WM_INITDIALOG:
354 This = (InternetExplorer*)lparam;
355 EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
356 return TRUE;
358 case WM_COMMAND:
359 switch(LOWORD(wparam))
361 case IDC_BROWSE_OPEN_URL:
363 HWND hwndurl = GetDlgItem(hwnd, IDC_BROWSE_OPEN_URL);
364 int len = GetWindowTextLengthW(hwndurl);
366 EnableWindow(GetDlgItem(hwnd, IDOK), len != 0);
367 break;
369 case IDOK:
371 HWND hwndurl = GetDlgItem(hwnd, IDC_BROWSE_OPEN_URL);
372 int len = GetWindowTextLengthW(hwndurl);
374 if(len)
376 VARIANT url;
378 V_VT(&url) = VT_BSTR;
379 V_BSTR(&url) = SysAllocStringLen(NULL, len);
381 GetWindowTextW(hwndurl, V_BSTR(&url), len + 1);
382 IWebBrowser2_Navigate2(&This->IWebBrowser2_iface, &url, NULL, NULL, NULL, NULL);
384 SysFreeString(V_BSTR(&url));
387 /* fall through */
388 case IDCANCEL:
389 EndDialog(hwnd, wparam);
390 return TRUE;
393 return FALSE;
396 static void ie_dialog_about(HWND hwnd)
398 HICON icon = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON, 48, 48, LR_SHARED);
400 ShellAboutW(hwnd, wszWineInternetExplorer, NULL, icon);
402 DestroyIcon(icon);
405 static void add_tb_separator(InternetExplorer *ie)
407 TBBUTTON btn;
409 ZeroMemory(&btn, sizeof(btn));
411 btn.iBitmap = 3;
412 btn.fsStyle = BTNS_SEP;
413 SendMessageW(ie->toolbar_hwnd, TB_ADDBUTTONSW, 1, (LPARAM)&btn);
416 static void add_tb_button(InternetExplorer *ie, int bmp, int cmd, int strId)
418 TBBUTTON btn;
419 WCHAR buf[30];
421 LoadStringW(ieframe_instance, strId, buf, ARRAY_SIZE(buf));
423 btn.iBitmap = bmp;
424 btn.idCommand = cmd;
425 btn.fsState = TBSTATE_ENABLED;
426 btn.fsStyle = BTNS_SHOWTEXT;
427 btn.dwData = 0;
428 btn.iString = (INT_PTR)buf;
430 SendMessageW(ie->toolbar_hwnd, TB_ADDBUTTONSW, 1, (LPARAM)&btn);
433 static void enable_toolbar_button(InternetExplorer *ie, int command, BOOL enable)
435 SendMessageW(ie->toolbar_hwnd, TB_ENABLEBUTTON, command, enable);
438 static void create_rebar(InternetExplorer *ie)
440 HWND hwndRebar;
441 HWND hwndAddress;
442 REBARINFO rebarinf;
443 REBARBANDINFOW bandinf;
444 WCHAR addr[40];
445 HIMAGELIST imagelist;
446 SIZE toolbar_size;
448 LoadStringW(ieframe_instance, IDS_ADDRESS, addr, ARRAY_SIZE(addr));
450 hwndRebar = CreateWindowExW(WS_EX_TOOLWINDOW, REBARCLASSNAMEW, NULL,
451 WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|RBS_VARHEIGHT|CCS_TOP|CCS_NODIVIDER, 0, 0, 0, 0,
452 ie->frame_hwnd, (HMENU)IDC_BROWSE_REBAR, ieframe_instance, NULL);
454 rebarinf.cbSize = sizeof(rebarinf);
455 rebarinf.fMask = 0;
456 rebarinf.himl = NULL;
458 SendMessageW(hwndRebar, RB_SETBARINFO, 0, (LPARAM)&rebarinf);
460 ie->toolbar_hwnd = CreateWindowExW(TBSTYLE_EX_MIXEDBUTTONS, TOOLBARCLASSNAMEW, NULL, TBSTYLE_FLAT | WS_CHILD | WS_VISIBLE | CCS_NORESIZE,
461 0, 0, 0, 0, hwndRebar, (HMENU)IDC_BROWSE_TOOLBAR, ieframe_instance, NULL);
463 imagelist = ImageList_LoadImageW(ieframe_instance, MAKEINTRESOURCEW(IDB_IETOOLBAR), 32, 0, CLR_NONE, IMAGE_BITMAP, LR_CREATEDIBSECTION);
465 SendMessageW(ie->toolbar_hwnd, TB_SETIMAGELIST, 0, (LPARAM)imagelist);
466 SendMessageW(ie->toolbar_hwnd, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
467 add_tb_button(ie, 0, ID_BROWSE_BACK, IDS_TB_BACK);
468 add_tb_button(ie, 1, ID_BROWSE_FORWARD, IDS_TB_FORWARD);
469 add_tb_button(ie, 2, ID_BROWSE_STOP, IDS_TB_STOP);
470 add_tb_button(ie, 3, ID_BROWSE_REFRESH, IDS_TB_REFRESH);
471 add_tb_button(ie, 4, ID_BROWSE_HOME, IDS_TB_HOME);
472 add_tb_separator(ie);
473 add_tb_button(ie, 5, ID_BROWSE_PRINT, IDS_TB_PRINT);
474 SendMessageW(ie->toolbar_hwnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(65,50));
475 SendMessageW(ie->toolbar_hwnd, TB_GETMAXSIZE, 0, (LPARAM)&toolbar_size);
477 bandinf.cbSize = sizeof(bandinf);
478 bandinf.fMask = RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE;
479 bandinf.fStyle = RBBS_CHILDEDGE;
480 bandinf.cxMinChild = toolbar_size.cx;
481 bandinf.cyMinChild = toolbar_size.cy+2;
482 bandinf.hwndChild = ie->toolbar_hwnd;
484 SendMessageW(hwndRebar, RB_INSERTBANDW, -1, (LPARAM)&bandinf);
486 hwndAddress = CreateWindowExW(0, WC_COMBOBOXEXW, NULL, WS_BORDER|WS_CHILD|WS_VISIBLE|CBS_DROPDOWN,
487 0, 0, 100,20,hwndRebar, (HMENU)IDC_BROWSE_ADDRESSBAR, ieframe_instance, NULL);
489 bandinf.fMask |= RBBIM_TEXT;
490 bandinf.fStyle = RBBS_CHILDEDGE | RBBS_BREAK;
491 bandinf.lpText = addr;
492 bandinf.cxMinChild = 100;
493 bandinf.cyMinChild = 20;
494 bandinf.hwndChild = hwndAddress;
496 SendMessageW(hwndRebar, RB_INSERTBANDW, -1, (LPARAM)&bandinf);
499 static LRESULT iewnd_OnCreate(HWND hwnd, LPCREATESTRUCTW lpcs)
501 InternetExplorer* This = (InternetExplorer*)lpcs->lpCreateParams;
502 SetWindowLongPtrW(hwnd, 0, (LONG_PTR) lpcs->lpCreateParams);
504 This->doc_host.frame_hwnd = This->frame_hwnd = hwnd;
506 This->menu = create_ie_menu();
508 This->status_hwnd = CreateStatusWindowW(WS_VISIBLE|WS_CHILD|SBT_NOBORDERS|CCS_NODIVIDER,
509 NULL, hwnd, IDC_BROWSE_STATUSBAR);
510 SendMessageW(This->status_hwnd, SB_SIMPLE, TRUE, 0);
512 create_rebar(This);
514 return 0;
517 static LRESULT iewnd_OnSize(InternetExplorer *This, INT width, INT height)
519 HWND hwndRebar = GetDlgItem(This->frame_hwnd, IDC_BROWSE_REBAR);
520 INT barHeight = SendMessageW(hwndRebar, RB_GETBARHEIGHT, 0, 0);
521 RECT docarea = {0, 0, width, height};
523 SendMessageW(This->status_hwnd, WM_SIZE, 0, 0);
525 adjust_ie_docobj_rect(This->frame_hwnd, &docarea);
527 if(This->doc_host.hwnd)
528 SetWindowPos(This->doc_host.hwnd, NULL, docarea.left, docarea.top, docarea.right, docarea.bottom,
529 SWP_NOZORDER | SWP_NOACTIVATE);
531 SetWindowPos(hwndRebar, NULL, 0, 0, width, barHeight, SWP_NOZORDER | SWP_NOACTIVATE);
533 return 0;
536 static LRESULT iewnd_OnNotify(InternetExplorer *This, WPARAM wparam, LPARAM lparam)
538 NMHDR* hdr = (NMHDR*)lparam;
540 if(hdr->idFrom == IDC_BROWSE_ADDRESSBAR && hdr->code == CBEN_ENDEDITW)
542 NMCBEENDEDITW* info = (NMCBEENDEDITW*)lparam;
544 if(info->fChanged && info->iWhy == CBENF_RETURN)
546 VARIANT vt;
548 V_VT(&vt) = VT_BSTR;
549 V_BSTR(&vt) = SysAllocString(info->szText);
551 IWebBrowser2_Navigate2(&This->IWebBrowser2_iface, &vt, NULL, NULL, NULL, NULL);
553 SysFreeString(V_BSTR(&vt));
555 return 0;
559 if(hdr->idFrom == IDC_BROWSE_REBAR && hdr->code == RBN_HEIGHTCHANGE)
561 RECT docarea;
563 GetClientRect(This->frame_hwnd, &docarea);
564 adjust_ie_docobj_rect(This->frame_hwnd, &docarea);
566 if(This->doc_host.hwnd)
567 SetWindowPos(This->doc_host.hwnd, NULL, docarea.left, docarea.top, docarea.right, docarea.bottom,
568 SWP_NOZORDER | SWP_NOACTIVATE);
571 return 0;
574 static LRESULT iewnd_OnDestroy(InternetExplorer *This)
576 HIMAGELIST list = (HIMAGELIST)SendMessageW(This->toolbar_hwnd, TB_GETIMAGELIST, 0, 0);
578 TRACE("%p\n", This);
580 free_fav_menu_data(get_fav_menu(This->menu));
581 ImageList_Destroy(list);
582 This->frame_hwnd = NULL;
584 return 0;
587 static LRESULT iewnd_OnCommand(InternetExplorer *This, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
589 switch(LOWORD(wparam))
591 case ID_BROWSE_OPEN:
592 DialogBoxParamW(ieframe_instance, MAKEINTRESOURCEW(IDD_BROWSE_OPEN), hwnd, ie_dialog_open_proc, (LPARAM)This);
593 break;
595 case ID_BROWSE_PRINT:
596 if(This->doc_host.document)
598 IOleCommandTarget* target;
600 if(FAILED(IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (LPVOID*)&target)))
601 break;
603 IOleCommandTarget_Exec(target, &CGID_MSHTML, IDM_PRINT, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
605 IOleCommandTarget_Release(target);
607 break;
609 case ID_BROWSE_HOME:
610 IWebBrowser2_GoHome(&This->IWebBrowser2_iface);
611 break;
613 case ID_BROWSE_BACK:
614 IWebBrowser2_GoBack(&This->IWebBrowser2_iface);
615 break;
617 case ID_BROWSE_FORWARD:
618 IWebBrowser2_GoForward(&This->IWebBrowser2_iface);
619 break;
621 case ID_BROWSE_STOP:
622 IWebBrowser2_Stop(&This->IWebBrowser2_iface);
623 break;
625 case ID_BROWSE_REFRESH:
626 IWebBrowser2_Refresh(&This->IWebBrowser2_iface);
627 break;
629 case ID_BROWSE_ABOUT:
630 ie_dialog_about(hwnd);
631 break;
633 case ID_BROWSE_QUIT:
634 ShowWindow(hwnd, SW_HIDE);
635 break;
637 default:
638 if(LOWORD(wparam) >= ID_BROWSE_GOTOFAV_FIRST && LOWORD(wparam) <= ID_BROWSE_GOTOFAV_MAX)
640 LPCWSTR url = get_fav_url_from_id(get_fav_menu(This->menu), LOWORD(wparam));
642 if(url)
643 ie_navigate(This, url);
645 return DefWindowProcW(hwnd, msg, wparam, lparam);
647 return 0;
650 static LRESULT update_addrbar(InternetExplorer *This, LPARAM lparam)
652 HWND hwndRebar = GetDlgItem(This->frame_hwnd, IDC_BROWSE_REBAR);
653 HWND hwndAddress = GetDlgItem(hwndRebar, IDC_BROWSE_ADDRESSBAR);
654 HWND hwndEdit = (HWND)SendMessageW(hwndAddress, CBEM_GETEDITCONTROL, 0, 0);
655 LPCWSTR url = (LPCWSTR)lparam;
657 SendMessageW(hwndEdit, WM_SETTEXT, 0, (LPARAM)url);
659 return 0;
662 static LRESULT WINAPI ie_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
664 InternetExplorer *This = (InternetExplorer*) GetWindowLongPtrW(hwnd, 0);
666 switch (msg)
668 case WM_CREATE:
669 return iewnd_OnCreate(hwnd, (LPCREATESTRUCTW)lparam);
670 case WM_CLOSE:
671 TRACE("WM_CLOSE\n");
672 ShowWindow(hwnd, SW_HIDE);
673 return 0;
674 case WM_SHOWWINDOW:
675 TRACE("WM_SHOWWINDOW %Ix\n", wparam);
676 if(wparam) {
677 IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
678 InterlockedIncrement(&This->extern_ref);
679 }else {
680 release_extern_ref(This, TRUE);
681 IWebBrowser2_Release(&This->IWebBrowser2_iface);
683 break;
684 case WM_DESTROY:
685 return iewnd_OnDestroy(This);
686 case WM_SIZE:
687 return iewnd_OnSize(This, LOWORD(lparam), HIWORD(lparam));
688 case WM_COMMAND:
689 return iewnd_OnCommand(This, hwnd, msg, wparam, lparam);
690 case WM_NOTIFY:
691 return iewnd_OnNotify(This, wparam, lparam);
692 case WM_DOCHOSTTASK:
693 return process_dochost_tasks(&This->doc_host);
694 case WM_UPDATEADDRBAR:
695 return update_addrbar(This, lparam);
697 return DefWindowProcW(hwnd, msg, wparam, lparam);
700 void register_iewindow_class(void)
702 WNDCLASSEXW wc;
704 memset(&wc, 0, sizeof wc);
705 wc.cbSize = sizeof(wc);
706 wc.style = 0;
707 wc.lpfnWndProc = ie_window_proc;
708 wc.cbClsExtra = 0;
709 wc.cbWndExtra = sizeof(InternetExplorer*);
710 wc.hInstance = ieframe_instance;
711 wc.hIcon = LoadIconW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON));
712 wc.hIconSm = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON,
713 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
714 wc.hCursor = LoadCursorW(0, (LPWSTR)IDC_ARROW);
715 wc.hbrBackground = 0;
716 wc.lpszClassName = szIEWinFrame;
717 wc.lpszMenuName = NULL;
719 RegisterClassExW(&wc);
722 void unregister_iewindow_class(void)
724 UnregisterClassW(szIEWinFrame, ieframe_instance);
727 static void create_frame_hwnd(InternetExplorer *This)
729 CreateWindowExW(
730 WS_EX_WINDOWEDGE,
731 szIEWinFrame, wszWineInternetExplorer,
732 WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
733 | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
734 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
735 NULL, NULL /* FIXME */, ieframe_instance, This);
737 create_doc_view_hwnd(&This->doc_host);
740 static inline InternetExplorer *impl_from_DocHost(DocHost *iface)
742 return CONTAINING_RECORD(iface, InternetExplorer, doc_host);
745 static ULONG IEDocHost_addref(DocHost *iface)
747 InternetExplorer *This = impl_from_DocHost(iface);
748 return IWebBrowser2_AddRef(&This->IWebBrowser2_iface);
751 static ULONG IEDocHost_release(DocHost *iface)
753 InternetExplorer *This = impl_from_DocHost(iface);
754 return IWebBrowser2_Release(&This->IWebBrowser2_iface);
757 static void DocHostContainer_get_docobj_rect(DocHost *This, RECT *rc)
759 GetClientRect(This->frame_hwnd, rc);
760 adjust_ie_docobj_rect(This->frame_hwnd, rc);
763 static HRESULT DocHostContainer_set_status_text(DocHost *iface, const WCHAR *text)
765 InternetExplorer *This = impl_from_DocHost(iface);
766 return update_ie_statustext(This, text);
769 static void DocHostContainer_on_command_state_change(DocHost *iface, LONG command, BOOL enable)
771 InternetExplorer *This = impl_from_DocHost(iface);
773 switch(command) {
774 case CSC_NAVIGATEBACK:
775 enable_toolbar_button(This, ID_BROWSE_BACK, enable);
776 break;
777 case CSC_NAVIGATEFORWARD:
778 enable_toolbar_button(This, ID_BROWSE_FORWARD, enable);
779 break;
783 static void DocHostContainer_set_url(DocHost* iface, const WCHAR *url)
785 InternetExplorer *This = impl_from_DocHost(iface);
786 const WCHAR *orig_url = error_url_frag(url);
788 if(orig_url)
789 url = orig_url;
791 This->nohome = FALSE;
792 SendMessageW(This->frame_hwnd, WM_UPDATEADDRBAR, 0, (LPARAM)url);
795 static const IDocHostContainerVtbl DocHostContainerVtbl = {
796 IEDocHost_addref,
797 IEDocHost_release,
798 DocHostContainer_get_docobj_rect,
799 DocHostContainer_set_status_text,
800 DocHostContainer_on_command_state_change,
801 DocHostContainer_set_url
804 static HRESULT create_ie(InternetExplorer **ret_obj)
806 InternetExplorer *ret;
808 ret = calloc(1, sizeof(InternetExplorer));
809 if(!ret)
810 return E_OUTOFMEMORY;
812 ret->ref = 1;
814 DocHost_Init(&ret->doc_host, &ret->IWebBrowser2_iface, &DocHostContainerVtbl);
816 InternetExplorer_WebBrowser_Init(ret);
818 HlinkFrame_Init(&ret->hlink_frame, (IUnknown*)&ret->IWebBrowser2_iface, &ret->doc_host);
820 create_frame_hwnd(ret);
822 InterlockedIncrement(&obj_cnt);
823 list_add_tail(&ie_list, &ret->entry);
824 *ret_obj = ret;
825 return S_OK;
828 HRESULT WINAPI InternetExplorer_Create(IClassFactory *iface, IUnknown *pOuter, REFIID riid, void **ppv)
830 InternetExplorer *ret;
831 HRESULT hres;
833 TRACE("(%p %s %p)\n", pOuter, debugstr_guid(riid), ppv);
835 hres = create_ie(&ret);
836 if(FAILED(hres))
837 return hres;
839 hres = IWebBrowser2_QueryInterface(&ret->IWebBrowser2_iface, riid, ppv);
840 IWebBrowser2_Release(&ret->IWebBrowser2_iface);
841 if(FAILED(hres))
842 return hres;
844 return S_OK;
847 /******************************************************************
848 * IInternetExplorerManager implementation
850 struct InternetExplorerManager {
851 IInternetExplorerManager IInternetExplorerManager_iface;
852 LONG ref;
855 static inline InternetExplorerManager *impl_from_IInternetExplorerManager(IInternetExplorerManager *iface)
857 return CONTAINING_RECORD(iface, InternetExplorerManager, IInternetExplorerManager_iface);
860 static HRESULT WINAPI InternetExplorerManager_QueryInterface(IInternetExplorerManager *iface, REFIID riid, void **out)
862 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), out);
864 if (IsEqualGUID(riid, &IID_IInternetExplorerManager) || IsEqualGUID(riid, &IID_IUnknown))
866 IInternetExplorerManager_AddRef(iface);
867 *out = iface;
868 return S_OK;
871 FIXME("interface %s not implemented\n", debugstr_guid(riid));
872 *out = NULL;
873 return E_NOINTERFACE;
876 static ULONG WINAPI InternetExplorerManager_AddRef(IInternetExplorerManager *iface)
878 InternetExplorerManager *This = impl_from_IInternetExplorerManager(iface);
879 ULONG ref = InterlockedIncrement(&This->ref);
881 TRACE("(%p) increasing refcount to %lu\n", iface, ref);
883 return ref;
886 static ULONG WINAPI InternetExplorerManager_Release(IInternetExplorerManager *iface)
888 InternetExplorerManager *This = impl_from_IInternetExplorerManager(iface);
889 ULONG ref = InterlockedDecrement(&This->ref);
891 TRACE("(%p) decreasing refcount to %lu\n", iface, ref);
893 if (ref == 0)
895 free(This);
896 released_obj();
899 return ref;
902 static HRESULT WINAPI InternetExplorerManager_CreateObject(IInternetExplorerManager *iface, DWORD config, LPCWSTR url, REFIID riid, void **ppv)
904 FIXME("(%p)->(0x%lx, %s, %s, %p) stub!\n", iface, config, debugstr_w(url), debugstr_guid(riid), ppv);
906 return E_NOTIMPL;
909 static const IInternetExplorerManagerVtbl InternetExplorerManager_vtbl =
911 InternetExplorerManager_QueryInterface,
912 InternetExplorerManager_AddRef,
913 InternetExplorerManager_Release,
914 InternetExplorerManager_CreateObject,
917 HRESULT WINAPI InternetExplorerManager_Create(IClassFactory *iface, IUnknown *pOuter, REFIID riid, void **ppv)
919 InternetExplorerManager *ret;
920 HRESULT hr;
922 TRACE("(%p %s %p)\n", pOuter, debugstr_guid(riid), ppv);
924 if (!(ret = calloc(1, sizeof(*ret))))
925 return E_OUTOFMEMORY;
927 ret->IInternetExplorerManager_iface.lpVtbl = &InternetExplorerManager_vtbl;
928 ret->ref = 1;
930 hr = IInternetExplorerManager_QueryInterface(&ret->IInternetExplorerManager_iface, riid, ppv);
931 IInternetExplorerManager_Release(&ret->IInternetExplorerManager_iface);
933 InterlockedIncrement(&obj_cnt);
934 return hr;
937 void released_obj(void)
939 if(!InterlockedDecrement(&obj_cnt))
940 PostQuitMessage(0);
943 static BOOL create_ie_window(BOOL nohome, const WCHAR *cmdline)
945 InternetExplorer *ie;
946 HRESULT hres;
948 hres = create_ie(&ie);
949 if(FAILED(hres))
950 return FALSE;
952 IWebBrowser2_put_Visible(&ie->IWebBrowser2_iface, VARIANT_TRUE);
953 IWebBrowser2_put_MenuBar(&ie->IWebBrowser2_iface, VARIANT_TRUE);
955 if(!*cmdline) {
956 if (nohome)
957 ie->nohome = TRUE;
958 else
959 IWebBrowser2_GoHome(&ie->IWebBrowser2_iface);
960 }else {
961 VARIANT var_url;
962 int cmdlen;
964 cmdlen = lstrlenW(cmdline);
965 if(cmdlen > 2 && cmdline[0] == '"' && cmdline[cmdlen-1] == '"') {
966 cmdline++;
967 cmdlen -= 2;
970 V_VT(&var_url) = VT_BSTR;
971 V_BSTR(&var_url) = SysAllocStringLen(cmdline, cmdlen);
973 /* navigate to the first page */
974 IWebBrowser2_Navigate2(&ie->IWebBrowser2_iface, &var_url, NULL, NULL, NULL, NULL);
976 SysFreeString(V_BSTR(&var_url));
979 IWebBrowser2_Release(&ie->IWebBrowser2_iface);
980 return TRUE;
983 static HDDEDATA open_dde_url(WCHAR *dde_url)
985 InternetExplorer *ie = NULL, *iter;
986 WCHAR *url, *url_end;
987 VARIANT urlv;
988 HRESULT hres;
990 TRACE("%s\n", debugstr_w(dde_url));
992 url = dde_url;
993 if(*url == '"') {
994 url++;
995 url_end = wcschr(url, '"');
996 if(!url_end) {
997 FIXME("missing string terminator\n");
998 return 0;
1000 *url_end = 0;
1001 }else {
1002 url_end = wcschr(url, ',');
1003 if(url_end)
1004 *url_end = 0;
1005 else
1006 url_end = url + lstrlenW(url);
1009 LIST_FOR_EACH_ENTRY(iter, &ie_list, InternetExplorer, entry) {
1010 if(iter->nohome) {
1011 IWebBrowser2_AddRef(&iter->IWebBrowser2_iface);
1012 ie = iter;
1013 break;
1017 if(!ie) {
1018 hres = create_ie(&ie);
1019 if(FAILED(hres))
1020 return 0;
1023 IWebBrowser2_put_Visible(&ie->IWebBrowser2_iface, VARIANT_TRUE);
1024 IWebBrowser2_put_MenuBar(&ie->IWebBrowser2_iface, VARIANT_TRUE);
1026 V_VT(&urlv) = VT_BSTR;
1027 V_BSTR(&urlv) = SysAllocStringLen(url, url_end-url);
1028 if(!V_BSTR(&urlv)) {
1029 IWebBrowser2_Release(&ie->IWebBrowser2_iface);
1030 return 0;
1033 hres = IWebBrowser2_Navigate2(&ie->IWebBrowser2_iface, &urlv, NULL, NULL, NULL, NULL);
1035 SysFreeString(V_BSTR(&urlv));
1036 IWebBrowser2_Release(&ie->IWebBrowser2_iface);
1038 if(FAILED(hres))
1039 return 0;
1040 return ULongToHandle(DDE_FACK);
1043 static HDDEDATA WINAPI dde_proc(UINT type, UINT uFmt, HCONV hConv, HSZ hsz1, HSZ hsz2, HDDEDATA data,
1044 ULONG_PTR dwData1, ULONG_PTR dwData2)
1046 switch(type) {
1047 case XTYP_CONNECT:
1048 TRACE("XTYP_CONNECT %p\n", hsz1);
1049 return ULongToHandle(!DdeCmpStringHandles(hsz1, ddestr_openurl));
1051 case XTYP_EXECUTE: {
1052 WCHAR *url;
1053 DWORD size;
1054 HDDEDATA ret;
1056 TRACE("XTYP_EXECUTE %p\n", data);
1058 size = DdeGetData(data, NULL, 0, 0);
1059 if(!size) {
1060 WARN("size = 0\n");
1061 break;
1064 url = malloc(size);
1065 if(!url)
1066 break;
1068 if(DdeGetData(data, (BYTE*)url, size, 0) != size) {
1069 ERR("error during read\n");
1070 free(url);
1071 break;
1074 ret = open_dde_url(url);
1076 free(url);
1077 return ret;
1080 case XTYP_REQUEST:
1081 FIXME("XTYP_REQUEST\n");
1082 break;
1084 default:
1085 TRACE("type %d\n", type);
1088 return NULL;
1091 static void init_dde(void)
1093 UINT res;
1095 static const WCHAR iexploreW[] = {'I','E','x','p','l','o','r','e',0};
1096 static const WCHAR openurlW[] = {'W','W','W','_','O','p','e','n','U','R','L',0};
1098 res = DdeInitializeW(&dde_inst, dde_proc, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES | CBF_FAIL_POKES, 0);
1099 if(res != DMLERR_NO_ERROR) {
1100 WARN("DdeInitialize failed: %u\n", res);
1101 return;
1104 ddestr_iexplore = DdeCreateStringHandleW(dde_inst, iexploreW, CP_WINUNICODE);
1105 if(!ddestr_iexplore)
1106 WARN("Failed to create string handle: %u\n", DdeGetLastError(dde_inst));
1108 ddestr_openurl = DdeCreateStringHandleW(dde_inst, openurlW, CP_WINUNICODE);
1109 if(!ddestr_openurl)
1110 WARN("Failed to create string handle: %u\n", DdeGetLastError(dde_inst));
1112 if(!DdeNameService(dde_inst, ddestr_iexplore, 0, DNS_REGISTER))
1113 WARN("DdeNameService failed\n");
1116 static void release_dde(void)
1118 if(ddestr_iexplore)
1119 DdeNameService(dde_inst, ddestr_iexplore, 0, DNS_UNREGISTER);
1120 if(ddestr_openurl)
1121 DdeFreeStringHandle(dde_inst, ddestr_openurl);
1122 if(ddestr_iexplore)
1123 DdeFreeStringHandle(dde_inst, ddestr_iexplore);
1124 DdeUninitialize(dde_inst);
1127 /******************************************************************
1128 * IEWinMain (ieframe.101)
1130 * Only returns on error.
1132 DWORD WINAPI IEWinMain(const WCHAR *cmdline, int nShowWindow)
1134 BOOL embedding = FALSE, nohome = FALSE, manager = FALSE, activated = FALSE;
1135 MSG msg;
1136 HRESULT hres;
1137 HANDLE context = INVALID_HANDLE_VALUE;
1138 DWORD reg_cookie, ret = 1;
1139 ULONG_PTR context_cookie;
1140 ACTCTXW actctx;
1142 static const WCHAR embeddingW[] = {'-','e','m','b','e','d','d','i','n','g',0};
1143 static const WCHAR nohomeW[] = {'-','n','o','h','o','m','e',0};
1144 static const WCHAR startmanagerW[] = {'-','s','t','a','r','t','m','a','n','a','g','e','r',0};
1146 TRACE("%s %d\n", debugstr_w(cmdline), nShowWindow);
1148 CoInitialize(NULL);
1150 memset(&actctx, 0, sizeof(actctx));
1151 actctx.cbSize = sizeof(actctx);
1152 actctx.hModule = ieframe_instance;
1153 actctx.lpResourceName = MAKEINTRESOURCEW(123);
1154 actctx.dwFlags = ACTCTX_FLAG_HMODULE_VALID | ACTCTX_FLAG_RESOURCE_NAME_VALID;
1155 context = CreateActCtxW(&actctx);
1156 if (context != INVALID_HANDLE_VALUE)
1157 activated = ActivateActCtx(context, &context_cookie);
1159 init_dde();
1161 while (*cmdline)
1163 int length = 0;
1165 while (*cmdline == ' ' || *cmdline == '\t') cmdline++;
1166 if (!*cmdline) break;
1168 while (cmdline[length] && cmdline[length] != ' ' && cmdline[length] != '\t') length++;
1170 if (!wcsnicmp(cmdline, embeddingW, length))
1171 embedding = TRUE;
1172 else if (!wcsnicmp(cmdline, nohomeW, length))
1173 nohome = TRUE;
1174 else if (!wcsnicmp(cmdline, startmanagerW, length))
1175 manager = TRUE;
1176 else
1177 break;
1179 cmdline += length;
1182 if (manager)
1183 hres = CoRegisterClassObject(&CLSID_InternetExplorerManager,
1184 (IUnknown*)&InternetExplorerManagerFactory, CLSCTX_SERVER,
1185 REGCLS_SINGLEUSE, &reg_cookie);
1186 else
1187 hres = CoRegisterClassObject(&CLSID_InternetExplorer,
1188 (IUnknown*)&InternetExplorerFactory, CLSCTX_SERVER,
1189 REGCLS_MULTIPLEUSE, &reg_cookie);
1191 if (FAILED(hres))
1193 ERR("failed to register CLSID_InternetExplorer%s: %08lx\n", manager ? "Manager" : "", hres);
1194 goto done;
1197 if (!embedding)
1199 if(!create_ie_window(nohome, cmdline))
1200 goto done;
1203 /* run the message loop for this thread */
1204 while (GetMessageW(&msg, 0, 0, 0))
1206 TranslateMessage(&msg);
1207 DispatchMessageW(&msg);
1210 CoRevokeClassObject(reg_cookie);
1211 release_dde();
1213 ret = 0;
1214 done:
1215 CoUninitialize();
1216 if (activated)
1217 DeactivateActCtx(0, context_cookie);
1218 ReleaseActCtx(context);
1219 ExitProcess(ret);