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 static const WCHAR szIEWinFrame[] = { 'I','E','F','r','a','m','e',0 };
46 /* Windows uses "Microsoft Internet Explorer" */
47 static const WCHAR wszWineInternetExplorer[] =
48 {'W','i','n','e',' ','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',0};
50 void adjust_ie_docobj_rect(HWND frame, RECT* rc)
52 HWND hwndRebar = GetDlgItem(frame, IDC_BROWSE_REBAR);
53 INT barHeight = SendMessageW(hwndRebar, RB_GETBARHEIGHT, 0, 0);
56 rc->bottom -= barHeight;
59 static INT_PTR CALLBACK ie_dialog_open_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
61 static InternetExplorer* This;
66 This = (InternetExplorer*)lparam;
67 EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
71 switch(LOWORD(wparam))
73 case IDC_BROWSE_OPEN_URL:
75 HWND hwndurl = GetDlgItem(hwnd, IDC_BROWSE_OPEN_URL);
76 int len = GetWindowTextLengthW(hwndurl);
78 EnableWindow(GetDlgItem(hwnd, IDOK), len ? TRUE : FALSE);
83 HWND hwndurl = GetDlgItem(hwnd, IDC_BROWSE_OPEN_URL);
84 int len = GetWindowTextLengthW(hwndurl);
91 V_BSTR(&url) = SysAllocStringLen(NULL, len);
93 GetWindowTextW(hwndurl, V_BSTR(&url), len);
94 IWebBrowser2_Navigate2(WEBBROWSER2(This), &url, NULL, NULL, NULL, NULL);
96 SysFreeString(V_BSTR(&url));
101 EndDialog(hwnd, wparam);
108 static void ie_dialog_about(HWND hwnd)
110 HICON icon = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON, 48, 48, LR_SHARED);
112 ShellAboutW(hwnd, wszWineInternetExplorer, NULL, icon);
117 static void create_rebar(HWND hwnd)
122 REBARBANDINFOW bandinf;
123 WCHAR addr[] = {'A','d','d','r','e','s','s',0};
125 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);
127 rebarinf.cbSize = sizeof(rebarinf);
129 rebarinf.himl = NULL;
130 rebarinf.cbSize = sizeof(rebarinf);
132 SendMessageW(hwndRebar, RB_SETBARINFO, 0, (LPARAM)&rebarinf);
134 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);
136 bandinf.fMask = RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE | RBBIM_TEXT;
137 bandinf.fStyle = RBBS_CHILDEDGE | RBBS_GRIPPERALWAYS;
138 bandinf.lpText = addr;
140 bandinf.cyMinChild = 20;
141 bandinf.hwndChild = hwndAddress;
143 SendMessageW(hwndRebar, RB_INSERTBANDW, 0, (LPARAM)&bandinf);
146 static LRESULT iewnd_OnCreate(HWND hwnd, LPCREATESTRUCTW lpcs)
148 SetWindowLongPtrW(hwnd, 0, (LONG_PTR) lpcs->lpCreateParams);
154 static LRESULT iewnd_OnSize(InternetExplorer *This, INT width, INT height)
156 HWND hwndRebar = GetDlgItem(This->frame_hwnd, IDC_BROWSE_REBAR);
157 INT barHeight = SendMessageW(hwndRebar, RB_GETBARHEIGHT, 0, 0);
158 RECT docarea = {0, 0, width, height};
160 adjust_ie_docobj_rect(This->frame_hwnd, &docarea);
162 if(This->doc_host.hwnd)
163 SetWindowPos(This->doc_host.hwnd, NULL, docarea.left, docarea.top, docarea.right, docarea.bottom,
164 SWP_NOZORDER | SWP_NOACTIVATE);
166 SetWindowPos(hwndRebar, NULL, 0, 0, width, barHeight, SWP_NOZORDER | SWP_NOACTIVATE);
171 static LRESULT iewnd_OnNotify(InternetExplorer *This, WPARAM wparam, LPARAM lparam)
173 NMHDR* hdr = (NMHDR*)lparam;
175 if(hdr->idFrom == IDC_BROWSE_ADDRESSBAR && hdr->code == CBEN_ENDEDITW)
177 NMCBEENDEDITW* info = (NMCBEENDEDITW*)lparam;
179 if(info->fChanged && info->iWhy == CBENF_RETURN && info->szText)
182 HWND hwndEdit = (HWND)SendMessageW(hdr->hwndFrom, CBEM_GETEDITCONTROL, 0, 0);
185 V_BSTR(&vt) = SysAllocString(info->szText);
187 IWebBrowser2_Navigate2(WEBBROWSER2(This), &vt, NULL, NULL, NULL, NULL);
189 SysFreeString(V_BSTR(&vt));
191 /* Clear the address bar, as we don't change it when
192 the user navigates to a new page */
193 SendMessageW(hwndEdit, WM_SETTEXT, 0, 0);
201 static LRESULT iewnd_OnDestroy(InternetExplorer *This)
205 This->frame_hwnd = NULL;
206 PostQuitMessage(0); /* FIXME */
211 static LRESULT CALLBACK iewnd_OnCommand(InternetExplorer *This, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
213 switch(LOWORD(wparam))
216 DialogBoxParamW(shdocvw_hinstance, MAKEINTRESOURCEW(IDD_BROWSE_OPEN), hwnd, ie_dialog_open_proc, (LPARAM)This);
219 case ID_BROWSE_PRINT:
220 if(This->doc_host.document)
222 IOleCommandTarget* target;
224 if(FAILED(IUnknown_QueryInterface(This->doc_host.document, &IID_IOleCommandTarget, (LPVOID*)&target)))
227 IOleCommandTarget_Exec(target, &CGID_MSHTML, IDM_PRINT, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
229 IOleCommandTarget_Release(target);
233 case ID_BROWSE_ABOUT:
234 ie_dialog_about(hwnd);
238 return DefWindowProcW(hwnd, msg, wparam, lparam);
243 static LRESULT CALLBACK
244 ie_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
246 InternetExplorer *This = (InternetExplorer*) GetWindowLongPtrW(hwnd, 0);
251 return iewnd_OnCreate(hwnd, (LPCREATESTRUCTW)lparam);
253 return iewnd_OnDestroy(This);
255 return iewnd_OnSize(This, LOWORD(lparam), HIWORD(lparam));
257 return iewnd_OnCommand(This, hwnd, msg, wparam, lparam);
259 return iewnd_OnNotify(This, wparam, lparam);
261 return process_dochost_task(&This->doc_host, lparam);
263 return DefWindowProcW(hwnd, msg, wparam, lparam);
266 void register_iewindow_class(void)
270 memset(&wc, 0, sizeof wc);
271 wc.cbSize = sizeof(wc);
273 wc.lpfnWndProc = ie_window_proc;
275 wc.cbWndExtra = sizeof(InternetExplorer*);
276 wc.hInstance = shdocvw_hinstance;
277 wc.hIcon = LoadIconW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON));
278 wc.hIconSm = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON,
279 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
280 wc.hCursor = LoadCursorW(0, MAKEINTRESOURCEW(IDC_ARROW));
281 wc.hbrBackground = 0;
282 wc.lpszClassName = szIEWinFrame;
283 wc.lpszMenuName = NULL;
285 RegisterClassExW(&wc);
288 void unregister_iewindow_class(void)
290 UnregisterClassW(szIEWinFrame, shdocvw_hinstance);
293 static void create_frame_hwnd(InternetExplorer *This)
295 This->frame_hwnd = CreateWindowExW(
297 szIEWinFrame, wszWineInternetExplorer,
298 WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
299 | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
300 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
301 NULL, NULL /* FIXME */, shdocvw_hinstance, This);
304 static IWebBrowser2 *create_ie_window(LPCSTR cmdline)
306 IWebBrowser2 *wb = NULL;
308 InternetExplorer_Create(NULL, &IID_IWebBrowser2, (void**)&wb);
312 IWebBrowser2_put_Visible(wb, VARIANT_TRUE);
313 IWebBrowser2_put_MenuBar(wb, VARIANT_TRUE);
316 IWebBrowser2_GoHome(wb);
322 if(!strncasecmp(cmdline, "-nohome", 7))
324 while(*cmdline == ' ' || *cmdline == '\t')
326 cmdlen = lstrlenA(cmdline);
327 if(cmdlen > 2 && cmdline[0] == '"' && cmdline[cmdlen-1] == '"') {
332 V_VT(&var_url) = VT_BSTR;
334 len = MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, NULL, 0);
335 V_BSTR(&var_url) = SysAllocStringLen(NULL, len);
336 MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, V_BSTR(&var_url), len);
338 /* navigate to the first page */
339 IWebBrowser2_Navigate2(wb, &var_url, NULL, NULL, NULL, NULL);
341 SysFreeString(V_BSTR(&var_url));
347 HRESULT InternetExplorer_Create(IUnknown *pOuter, REFIID riid, void **ppv)
349 InternetExplorer *ret;
352 TRACE("(%p %s %p)\n", pOuter, debugstr_guid(riid), ppv);
354 ret = heap_alloc_zero(sizeof(InternetExplorer));
357 ret->doc_host.disp = (IDispatch*)WEBBROWSER2(ret);
358 DocHost_Init(&ret->doc_host, (IDispatch*)WEBBROWSER2(ret));
360 InternetExplorer_WebBrowser_Init(ret);
362 HlinkFrame_Init(&ret->hlink_frame, (IUnknown*)WEBBROWSER2(ret), &ret->doc_host);
364 create_frame_hwnd(ret);
365 ret->doc_host.frame_hwnd = ret->frame_hwnd;
367 hres = IWebBrowser2_QueryInterface(WEBBROWSER2(ret), riid, ppv);
376 /******************************************************************
377 * IEWinMain (SHDOCVW.101)
379 * Only returns on error.
381 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
383 IWebBrowser2 *wb = NULL;
387 TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
389 if(*szCommandLine == '-' || *szCommandLine == '/') {
390 if(!strcasecmp(szCommandLine+1, "regserver"))
391 return register_iexplore(TRUE);
392 if(!strcasecmp(szCommandLine+1, "unregserver"))
393 return register_iexplore(FALSE);
398 hres = register_class_object(TRUE);
404 if(strcasecmp(szCommandLine, "-embedding"))
405 wb = create_ie_window(szCommandLine);
407 /* run the message loop for this thread */
408 while (GetMessageW(&msg, 0, 0, 0))
410 TranslateMessage(&msg);
411 DispatchMessageW(&msg);
415 IWebBrowser2_Release(wb);
417 register_class_object(FALSE);