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
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
44 #define DOCHOST_THIS(iface) DEFINE_THIS2(InternetExplorer,doc_host,iface)
46 static const WCHAR szIEWinFrame[] = { 'I','E','F','r','a','m','e',0 };
48 /* Windows uses "Microsoft Internet Explorer" */
49 static const WCHAR wszWineInternetExplorer[] =
50 {'W','i','n','e',' ','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',0};
52 HRESULT update_ie_statustext(InternetExplorer* This, LPCWSTR text)
54 if(!SendMessageW(This->status_hwnd, SB_SETTEXTW, MAKEWORD(SB_SIMPLEID, 0), (LPARAM)text))
60 void adjust_ie_docobj_rect(HWND frame, RECT* rc)
62 HWND hwndRebar = GetDlgItem(frame, IDC_BROWSE_REBAR);
63 HWND hwndStatus = GetDlgItem(frame, IDC_BROWSE_STATUSBAR);
64 INT barHeight = SendMessageW(hwndRebar, RB_GETBARHEIGHT, 0, 0);
67 rc->bottom -= barHeight;
69 if(IsWindowVisible(hwndStatus))
73 GetClientRect(hwndStatus, &statusrc);
74 rc->bottom -= statusrc.bottom - statusrc.top;
78 static INT_PTR CALLBACK ie_dialog_open_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
80 static InternetExplorer* This;
85 This = (InternetExplorer*)lparam;
86 EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
90 switch(LOWORD(wparam))
92 case IDC_BROWSE_OPEN_URL:
94 HWND hwndurl = GetDlgItem(hwnd, IDC_BROWSE_OPEN_URL);
95 int len = GetWindowTextLengthW(hwndurl);
97 EnableWindow(GetDlgItem(hwnd, IDOK), len ? TRUE : FALSE);
102 HWND hwndurl = GetDlgItem(hwnd, IDC_BROWSE_OPEN_URL);
103 int len = GetWindowTextLengthW(hwndurl);
109 V_VT(&url) = VT_BSTR;
110 V_BSTR(&url) = SysAllocStringLen(NULL, len);
112 GetWindowTextW(hwndurl, V_BSTR(&url), len);
113 IWebBrowser2_Navigate2(WEBBROWSER2(This), &url, NULL, NULL, NULL, NULL);
115 SysFreeString(V_BSTR(&url));
120 EndDialog(hwnd, wparam);
127 static void ie_dialog_about(HWND hwnd)
129 HICON icon = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON, 48, 48, LR_SHARED);
131 ShellAboutW(hwnd, wszWineInternetExplorer, NULL, icon);
136 static void create_rebar(HWND hwnd)
141 REBARBANDINFOW bandinf;
142 WCHAR addr[] = {'A','d','d','r','e','s','s',0};
144 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);
146 rebarinf.cbSize = sizeof(rebarinf);
148 rebarinf.himl = NULL;
149 rebarinf.cbSize = sizeof(rebarinf);
151 SendMessageW(hwndRebar, RB_SETBARINFO, 0, (LPARAM)&rebarinf);
153 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);
155 bandinf.fMask = RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_TEXT;
156 bandinf.fStyle = RBBS_CHILDEDGE | RBBS_GRIPPERALWAYS;
157 bandinf.lpText = addr;
159 bandinf.cyMinChild = 20;
160 bandinf.hwndChild = hwndAddress;
162 SendMessageW(hwndRebar, RB_INSERTBANDW, 0, (LPARAM)&bandinf);
165 static LRESULT iewnd_OnCreate(HWND hwnd, LPCREATESTRUCTW lpcs)
167 InternetExplorer* This = (InternetExplorer*)lpcs->lpCreateParams;
168 SetWindowLongPtrW(hwnd, 0, (LONG_PTR) lpcs->lpCreateParams);
170 This->status_hwnd = CreateStatusWindowW(CCS_NODIVIDER|WS_CHILD|WS_VISIBLE, NULL, hwnd, IDC_BROWSE_STATUSBAR);
171 SendMessageW(This->status_hwnd, SB_SIMPLE, TRUE, 0);
178 static LRESULT iewnd_OnSize(InternetExplorer *This, INT width, INT height)
180 HWND hwndRebar = GetDlgItem(This->frame_hwnd, IDC_BROWSE_REBAR);
181 INT barHeight = SendMessageW(hwndRebar, RB_GETBARHEIGHT, 0, 0);
182 RECT docarea = {0, 0, width, height};
184 SendMessageW(This->status_hwnd, WM_SIZE, 0, 0);
186 adjust_ie_docobj_rect(This->frame_hwnd, &docarea);
188 if(This->doc_host.hwnd)
189 SetWindowPos(This->doc_host.hwnd, NULL, docarea.left, docarea.top, docarea.right, docarea.bottom,
190 SWP_NOZORDER | SWP_NOACTIVATE);
192 SetWindowPos(hwndRebar, NULL, 0, 0, width, barHeight, SWP_NOZORDER | SWP_NOACTIVATE);
197 static LRESULT iewnd_OnNotify(InternetExplorer *This, WPARAM wparam, LPARAM lparam)
199 NMHDR* hdr = (NMHDR*)lparam;
201 if(hdr->idFrom == IDC_BROWSE_ADDRESSBAR && hdr->code == CBEN_ENDEDITW)
203 NMCBEENDEDITW* info = (NMCBEENDEDITW*)lparam;
205 if(info->fChanged && info->iWhy == CBENF_RETURN && info->szText)
210 V_BSTR(&vt) = SysAllocString(info->szText);
212 IWebBrowser2_Navigate2(WEBBROWSER2(This), &vt, NULL, NULL, NULL, NULL);
214 SysFreeString(V_BSTR(&vt));
223 static LRESULT iewnd_OnDestroy(InternetExplorer *This)
227 This->frame_hwnd = NULL;
228 PostQuitMessage(0); /* FIXME */
233 static LRESULT CALLBACK iewnd_OnCommand(InternetExplorer *This, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
235 switch(LOWORD(wparam))
238 DialogBoxParamW(shdocvw_hinstance, MAKEINTRESOURCEW(IDD_BROWSE_OPEN), hwnd, ie_dialog_open_proc, (LPARAM)This);
241 case ID_BROWSE_PRINT:
242 if(This->doc_host.document)
244 IOleCommandTarget* target;
246 if(FAILED(IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (LPVOID*)&target)))
249 IOleCommandTarget_Exec(target, &CGID_MSHTML, IDM_PRINT, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
251 IOleCommandTarget_Release(target);
255 case ID_BROWSE_ABOUT:
256 ie_dialog_about(hwnd);
260 return DefWindowProcW(hwnd, msg, wparam, lparam);
265 static LRESULT CALLBACK update_addrbar(InternetExplorer *This, LPARAM lparam)
267 HWND hwndRebar = GetDlgItem(This->frame_hwnd, IDC_BROWSE_REBAR);
268 HWND hwndAddress = GetDlgItem(hwndRebar, IDC_BROWSE_ADDRESSBAR);
269 HWND hwndEdit = (HWND)SendMessageW(hwndAddress, CBEM_GETEDITCONTROL, 0, 0);
270 LPCWSTR url = (LPCWSTR)lparam;
272 SendMessageW(hwndEdit, WM_SETTEXT, 0, (LPARAM)url);
277 static LRESULT CALLBACK
278 ie_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
280 InternetExplorer *This = (InternetExplorer*) GetWindowLongPtrW(hwnd, 0);
285 return iewnd_OnCreate(hwnd, (LPCREATESTRUCTW)lparam);
287 return iewnd_OnDestroy(This);
289 return iewnd_OnSize(This, LOWORD(lparam), HIWORD(lparam));
291 return iewnd_OnCommand(This, hwnd, msg, wparam, lparam);
293 return iewnd_OnNotify(This, wparam, lparam);
295 return process_dochost_task(&This->doc_host, lparam);
296 case WM_UPDATEADDRBAR:
297 return update_addrbar(This, lparam);
299 return DefWindowProcW(hwnd, msg, wparam, lparam);
302 void register_iewindow_class(void)
306 memset(&wc, 0, sizeof wc);
307 wc.cbSize = sizeof(wc);
309 wc.lpfnWndProc = ie_window_proc;
311 wc.cbWndExtra = sizeof(InternetExplorer*);
312 wc.hInstance = shdocvw_hinstance;
313 wc.hIcon = LoadIconW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON));
314 wc.hIconSm = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON,
315 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
316 wc.hCursor = LoadCursorW(0, MAKEINTRESOURCEW(IDC_ARROW));
317 wc.hbrBackground = 0;
318 wc.lpszClassName = szIEWinFrame;
319 wc.lpszMenuName = NULL;
321 RegisterClassExW(&wc);
324 void unregister_iewindow_class(void)
326 UnregisterClassW(szIEWinFrame, shdocvw_hinstance);
329 static void create_frame_hwnd(InternetExplorer *This)
331 This->frame_hwnd = CreateWindowExW(
333 szIEWinFrame, wszWineInternetExplorer,
334 WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
335 | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
336 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
337 NULL, NULL /* FIXME */, shdocvw_hinstance, This);
340 static IWebBrowser2 *create_ie_window(LPCSTR cmdline)
342 IWebBrowser2 *wb = NULL;
344 InternetExplorer_Create(NULL, &IID_IWebBrowser2, (void**)&wb);
348 IWebBrowser2_put_Visible(wb, VARIANT_TRUE);
349 IWebBrowser2_put_MenuBar(wb, VARIANT_TRUE);
352 IWebBrowser2_GoHome(wb);
358 if(!strncasecmp(cmdline, "-nohome", 7))
360 while(*cmdline == ' ' || *cmdline == '\t')
362 cmdlen = lstrlenA(cmdline);
363 if(cmdlen > 2 && cmdline[0] == '"' && cmdline[cmdlen-1] == '"') {
368 V_VT(&var_url) = VT_BSTR;
370 len = MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, NULL, 0);
371 V_BSTR(&var_url) = SysAllocStringLen(NULL, len);
372 MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, V_BSTR(&var_url), len);
374 /* navigate to the first page */
375 IWebBrowser2_Navigate2(wb, &var_url, NULL, NULL, NULL, NULL);
377 SysFreeString(V_BSTR(&var_url));
383 static void WINAPI DocHostContainer_GetDocObjRect(DocHost* This, RECT* rc)
385 GetClientRect(This->frame_hwnd, rc);
386 adjust_ie_docobj_rect(This->frame_hwnd, rc);
389 static HRESULT WINAPI DocHostContainer_SetStatusText(DocHost* This, LPCWSTR text)
391 InternetExplorer* ie = DOCHOST_THIS(This);
392 return update_ie_statustext(ie, text);
395 static void WINAPI DocHostContainer_SetURL(DocHost* This, LPCWSTR url)
397 SendMessageW(This->frame_hwnd, WM_UPDATEADDRBAR, 0, (LPARAM)url);
400 static const IDocHostContainerVtbl DocHostContainerVtbl = {
401 DocHostContainer_GetDocObjRect,
402 DocHostContainer_SetStatusText,
403 DocHostContainer_SetURL
406 HRESULT InternetExplorer_Create(IUnknown *pOuter, REFIID riid, void **ppv)
408 InternetExplorer *ret;
411 TRACE("(%p %s %p)\n", pOuter, debugstr_guid(riid), ppv);
413 ret = heap_alloc_zero(sizeof(InternetExplorer));
416 ret->doc_host.disp = (IDispatch*)WEBBROWSER2(ret);
417 DocHost_Init(&ret->doc_host, (IDispatch*)WEBBROWSER2(ret), &DocHostContainerVtbl);
419 InternetExplorer_WebBrowser_Init(ret);
421 HlinkFrame_Init(&ret->hlink_frame, (IUnknown*)WEBBROWSER2(ret), &ret->doc_host);
423 create_frame_hwnd(ret);
424 ret->doc_host.frame_hwnd = ret->frame_hwnd;
426 hres = IWebBrowser2_QueryInterface(WEBBROWSER2(ret), riid, ppv);
435 /******************************************************************
436 * IEWinMain (SHDOCVW.101)
438 * Only returns on error.
440 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
442 IWebBrowser2 *wb = NULL;
446 TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
448 if(*szCommandLine == '-' || *szCommandLine == '/') {
449 if(!strcasecmp(szCommandLine+1, "regserver"))
450 return register_iexplore(TRUE);
451 if(!strcasecmp(szCommandLine+1, "unregserver"))
452 return register_iexplore(FALSE);
457 hres = register_class_object(TRUE);
463 if(strcasecmp(szCommandLine, "-embedding"))
464 wb = create_ie_window(szCommandLine);
466 /* run the message loop for this thread */
467 while (GetMessageW(&msg, 0, 0, 0))
469 TranslateMessage(&msg);
470 DispatchMessageW(&msg);
474 IWebBrowser2_Release(wb);
476 register_class_object(FALSE);