shell32: Update for simplified Chinese translation.
[wine] / dlls / shdocvw / iexplore.c
1 /*
2  * SHDOCVW - Internet Explorer main frame window
3  *
4  * Copyright 2006 Mike McCormack (for CodeWeavers)
5  * Copyright 2006 Jacek Caban (for CodeWeavers)
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #define COBJMACROS
23
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"
33
34 #include "shdocvw.h"
35
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);
39
40 #define IDI_APPICON 1
41
42 static const WCHAR szIEWinFrame[] = { 'I','E','F','r','a','m','e',0 };
43
44 static LRESULT iewnd_OnCreate(HWND hwnd, LPCREATESTRUCTW lpcs)
45 {
46     SetWindowLongPtrW(hwnd, 0, (LONG_PTR) lpcs->lpCreateParams);
47     return 0;
48 }
49
50 static LRESULT iewnd_OnSize(InternetExplorer *This, INT width, INT height)
51 {
52     if(This->doc_host.hwnd)
53         SetWindowPos(This->doc_host.hwnd, NULL, 0, 0, width, height,
54                      SWP_NOZORDER | SWP_NOACTIVATE);
55
56     return 0;
57 }
58
59 static LRESULT iewnd_OnDestroy(InternetExplorer *This)
60 {
61     TRACE("%p\n", This);
62
63     This->frame_hwnd = NULL;
64     PostQuitMessage(0); /* FIXME */
65
66     return 0;
67 }
68
69 static LRESULT CALLBACK
70 ie_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
71 {
72     InternetExplorer *This = (InternetExplorer*) GetWindowLongPtrW(hwnd, 0);
73
74     switch (msg)
75     {
76     case WM_CREATE:
77         return iewnd_OnCreate(hwnd, (LPCREATESTRUCTW)lparam);
78     case WM_DESTROY:
79         return iewnd_OnDestroy(This);
80     case WM_SIZE:
81         return iewnd_OnSize(This, LOWORD(lparam), HIWORD(lparam));
82     case WM_DOCHOSTTASK:
83         return process_dochost_task(&This->doc_host, lparam);
84     }
85     return DefWindowProcW(hwnd, msg, wparam, lparam);
86 }
87
88 void register_iewindow_class(void)
89 {
90     WNDCLASSEXW wc;
91
92     memset(&wc, 0, sizeof wc);
93     wc.cbSize = sizeof(wc);
94     wc.style = 0;
95     wc.lpfnWndProc = ie_window_proc;
96     wc.cbClsExtra = 0;
97     wc.cbWndExtra = sizeof(InternetExplorer*);
98     wc.hInstance = shdocvw_hinstance;
99     wc.hIcon = LoadIconW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON));
100     wc.hIconSm = LoadImageW(GetModuleHandleW(0), MAKEINTRESOURCEW(IDI_APPICON), IMAGE_ICON,
101                             GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED);
102     wc.hCursor = LoadCursorW(0, MAKEINTRESOURCEW(IDC_ARROW));
103     wc.hbrBackground = 0;
104     wc.lpszClassName = szIEWinFrame;
105     wc.lpszMenuName = NULL;
106
107     RegisterClassExW(&wc);
108 }
109
110 void unregister_iewindow_class(void)
111 {
112     UnregisterClassW(szIEWinFrame, shdocvw_hinstance);
113 }
114
115 static void create_frame_hwnd(InternetExplorer *This)
116 {
117     /* Windows uses "Microsoft Internet Explorer" */
118     static const WCHAR wszWineInternetExplorer[] =
119         {'W','i','n','e',' ','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r',0};
120
121     This->frame_hwnd = CreateWindowExW(
122             WS_EX_WINDOWEDGE,
123             szIEWinFrame, wszWineInternetExplorer,
124             WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
125                 | WS_MINIMIZEBOX | WS_MAXIMIZEBOX,
126             CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
127             NULL, NULL /* FIXME */, shdocvw_hinstance, This);
128 }
129
130 static IWebBrowser2 *create_ie_window(LPCSTR cmdline)
131 {
132     IWebBrowser2 *wb = NULL;
133
134     InternetExplorer_Create(NULL, &IID_IWebBrowser2, (void**)&wb);
135     if(!wb)
136         return NULL;
137
138     IWebBrowser2_put_Visible(wb, VARIANT_TRUE);
139
140     if(!*cmdline) {
141         IWebBrowser2_GoHome(wb);
142     }else {
143         VARIANT var_url;
144         DWORD len;
145         int cmdlen;
146
147         if(!strncasecmp(cmdline, "-nohome", 7))
148             cmdline += 7;
149         while(*cmdline == ' ' || *cmdline == '\t')
150             cmdline++;
151         cmdlen = lstrlenA(cmdline);
152         if(cmdlen > 2 && cmdline[0] == '"' && cmdline[cmdlen-1] == '"') {
153             cmdline++;
154             cmdlen -= 2;
155         }
156
157         V_VT(&var_url) = VT_BSTR;
158
159         len = MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, NULL, 0);
160         V_BSTR(&var_url) = SysAllocStringLen(NULL, len);
161         MultiByteToWideChar(CP_ACP, 0, cmdline, cmdlen, V_BSTR(&var_url), len);
162
163         /* navigate to the first page */
164         IWebBrowser2_Navigate2(wb, &var_url, NULL, NULL, NULL, NULL);
165
166         SysFreeString(V_BSTR(&var_url));
167     }
168
169     return wb;
170 }
171
172 HRESULT InternetExplorer_Create(IUnknown *pOuter, REFIID riid, void **ppv)
173 {
174     InternetExplorer *ret;
175     HRESULT hres;
176
177     TRACE("(%p %s %p)\n", pOuter, debugstr_guid(riid), ppv);
178
179     ret = heap_alloc_zero(sizeof(InternetExplorer));
180     ret->ref = 0;
181
182     ret->doc_host.disp = (IDispatch*)WEBBROWSER2(ret);
183     DocHost_Init(&ret->doc_host, (IDispatch*)WEBBROWSER2(ret));
184
185     InternetExplorer_WebBrowser_Init(ret);
186
187     create_frame_hwnd(ret);
188     ret->doc_host.frame_hwnd = ret->frame_hwnd;
189
190     hres = IWebBrowser2_QueryInterface(WEBBROWSER2(ret), riid, ppv);
191     if(FAILED(hres)) {
192         heap_free(ret);
193         return hres;
194     }
195
196     return hres;
197 }
198
199 /******************************************************************
200  *              IEWinMain            (SHDOCVW.101)
201  *
202  * Only returns on error.
203  */
204 DWORD WINAPI IEWinMain(LPSTR szCommandLine, int nShowWindow)
205 {
206     IWebBrowser2 *wb = NULL;
207     MSG msg;
208     HRESULT hres;
209
210     TRACE("%s %d\n", debugstr_a(szCommandLine), nShowWindow);
211
212     if(*szCommandLine == '-' || *szCommandLine == '/') {
213         if(!strcasecmp(szCommandLine+1, "regserver"))
214             return register_iexplore(TRUE);
215         if(!strcasecmp(szCommandLine+1, "unregserver"))
216             return register_iexplore(FALSE);
217     }
218
219     CoInitialize(NULL);
220
221     hres = register_class_object(TRUE);
222     if(FAILED(hres)) {
223         CoUninitialize();
224         ExitProcess(1);
225     }
226
227     if(strcasecmp(szCommandLine, "-embedding"))
228         wb = create_ie_window(szCommandLine);
229
230     /* run the message loop for this thread */
231     while (GetMessageW(&msg, 0, 0, 0))
232     {
233         TranslateMessage(&msg);
234         DispatchMessageW(&msg);
235     }
236
237     if(wb)
238         IWebBrowser2_Release(wb);
239
240     register_class_object(FALSE);
241
242     CoUninitialize();
243
244     ExitProcess(0);
245     return 0;
246 }