msi: Fix a typo.
[wine.git] / dlls / mshtml / task.c
blob3bb99cc490ca7d44f80f2394e9e361e8896954e2
1 /*
2 * Copyright 2006 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "ole2.h"
30 #include "mshtmcid.h"
32 #include "wine/debug.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 #define WM_PROCESSTASK 0x8008
40 void push_task(task_t *task)
42 thread_data_t *thread_data = get_thread_data(TRUE);
44 if(thread_data->task_queue_tail)
45 thread_data->task_queue_tail->next = task;
46 else
47 thread_data->task_queue_head = task;
49 thread_data->task_queue_tail = task;
51 PostMessageW(thread_data->thread_hwnd, WM_PROCESSTASK, 0, 0);
54 static task_t *pop_task(void)
56 thread_data_t *thread_data = get_thread_data(TRUE);
57 task_t *task = thread_data->task_queue_head;
59 if(!task)
60 return NULL;
62 thread_data->task_queue_head = task->next;
63 if(!thread_data->task_queue_head)
64 thread_data->task_queue_tail = NULL;
66 return task;
69 void remove_doc_tasks(const HTMLDocument *doc)
71 thread_data_t *thread_data = get_thread_data(FALSE);
72 task_t *iter, *tmp;
74 if(!thread_data)
75 return;
77 while(thread_data->task_queue_head
78 && thread_data->task_queue_head->doc == doc)
79 pop_task();
81 for(iter = thread_data->task_queue_head; iter; iter = iter->next) {
82 while(iter->next && iter->next->doc == doc) {
83 tmp = iter->next;
84 iter->next = tmp->next;
85 heap_free(tmp);
88 if(!iter->next)
89 thread_data->task_queue_tail = iter;
93 static void set_downloading(HTMLDocument *doc)
95 IOleCommandTarget *olecmd;
96 HRESULT hres;
98 TRACE("(%p)\n", doc);
100 if(doc->frame)
101 IOleInPlaceFrame_SetStatusText(doc->frame, NULL /* FIXME */);
103 if(!doc->client)
104 return;
106 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
107 if(SUCCEEDED(hres)) {
108 VARIANT var;
110 V_VT(&var) = VT_I4;
111 V_I4(&var) = 1;
113 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETDOWNLOADSTATE, OLECMDEXECOPT_DONTPROMPTUSER,
114 &var, NULL);
115 IOleCommandTarget_Release(olecmd);
118 if(doc->hostui) {
119 IDropTarget *drop_target = NULL;
121 hres = IDocHostUIHandler_GetDropTarget(doc->hostui, NULL /* FIXME */, &drop_target);
122 if(drop_target) {
123 FIXME("Use IDropTarget\n");
124 IDropTarget_Release(drop_target);
129 static void set_parsecomplete(HTMLDocument *doc)
131 IOleCommandTarget *olecmd = NULL;
133 TRACE("(%p)\n", doc);
135 if(doc->usermode == EDITMODE)
136 init_editor(doc);
138 call_property_onchanged(&doc->cp_propnotif, 1005);
140 doc->readystate = READYSTATE_INTERACTIVE;
141 call_property_onchanged(&doc->cp_propnotif, DISPID_READYSTATE);
143 if(doc->client)
144 IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
146 if(olecmd) {
147 VARIANT state, progress;
149 V_VT(&progress) = VT_I4;
150 V_I4(&progress) = 0;
151 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSPOS, OLECMDEXECOPT_DONTPROMPTUSER,
152 &progress, NULL);
154 V_VT(&state) = VT_I4;
155 V_I4(&state) = 0;
156 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETDOWNLOADSTATE, OLECMDEXECOPT_DONTPROMPTUSER,
157 &state, NULL);
159 IOleCommandTarget_Exec(olecmd, &CGID_MSHTML, IDM_PARSECOMPLETE, 0, NULL, NULL);
160 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_HTTPEQUIV_DONE, 0, NULL, NULL);
162 IOleCommandTarget_Release(olecmd);
165 doc->readystate = READYSTATE_COMPLETE;
166 call_property_onchanged(&doc->cp_propnotif, DISPID_READYSTATE);
168 if(doc->frame) {
169 static const WCHAR wszDone[] = {'D','o','n','e',0};
170 IOleInPlaceFrame_SetStatusText(doc->frame, wszDone);
173 update_title(doc);
176 static void set_progress(HTMLDocument *doc)
178 IOleCommandTarget *olecmd = NULL;
179 HRESULT hres;
181 TRACE("(%p)\n", doc);
183 if(doc->client)
184 IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
186 if(olecmd) {
187 VARIANT progress_max, progress;
189 V_VT(&progress_max) = VT_I4;
190 V_I4(&progress_max) = 0; /* FIXME */
191 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSMAX, OLECMDEXECOPT_DONTPROMPTUSER,
192 &progress_max, NULL);
194 V_VT(&progress) = VT_I4;
195 V_I4(&progress) = 0; /* FIXME */
196 IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSPOS, OLECMDEXECOPT_DONTPROMPTUSER,
197 &progress, NULL);
200 if(doc->usermode == EDITMODE && doc->hostui) {
201 DOCHOSTUIINFO hostinfo;
203 memset(&hostinfo, 0, sizeof(DOCHOSTUIINFO));
204 hostinfo.cbSize = sizeof(DOCHOSTUIINFO);
205 hres = IDocHostUIHandler_GetHostInfo(doc->hostui, &hostinfo);
206 if(SUCCEEDED(hres))
207 /* FIXME: use hostinfo */
208 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
209 hostinfo.cbSize, hostinfo.dwFlags, hostinfo.dwDoubleClick,
210 debugstr_w(hostinfo.pchHostCss), debugstr_w(hostinfo.pchHostNS));
214 static void task_start_binding(HTMLDocument *doc, BSCallback *bscallback)
216 if(doc)
217 start_binding(doc, bscallback, NULL);
218 IUnknown_Release((IUnknown*)bscallback);
221 static void process_task(task_t *task)
223 switch(task->task_id) {
224 case TASK_SETDOWNLOADSTATE:
225 set_downloading(task->doc);
226 break;
227 case TASK_PARSECOMPLETE:
228 set_parsecomplete(task->doc);
229 break;
230 case TASK_SETPROGRESS:
231 set_progress(task->doc);
232 break;
233 case TASK_START_BINDING:
234 task_start_binding(task->doc, (BSCallback*)task->bscallback);
235 break;
236 default:
237 ERR("Wrong task_id %d\n", task->task_id);
241 static LRESULT WINAPI hidden_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
243 switch(msg) {
244 case WM_PROCESSTASK:
245 while(1) {
246 task_t *task = pop_task();
247 if(!task)
248 break;
250 process_task(task);
251 heap_free(task);
254 return 0;
257 if(msg > WM_USER)
258 FIXME("(%p %d %lx %lx)\n", hwnd, msg, wParam, lParam);
260 return DefWindowProcW(hwnd, msg, wParam, lParam);
263 static HWND create_thread_hwnd(void)
265 static ATOM hidden_wnd_class = 0;
266 static const WCHAR wszInternetExplorer_Hidden[] = {'I','n','t','e','r','n','e','t',
267 ' ','E','x','p','l','o','r','e','r','_','H','i','d','d','e','n',0};
269 if(!hidden_wnd_class) {
270 WNDCLASSEXW wndclass = {
271 sizeof(WNDCLASSEXW), 0,
272 hidden_proc,
273 0, 0, hInst, NULL, NULL, NULL, NULL,
274 wszInternetExplorer_Hidden,
275 NULL
278 hidden_wnd_class = RegisterClassExW(&wndclass);
281 return CreateWindowExW(0, wszInternetExplorer_Hidden, NULL, WS_POPUP,
282 0, 0, 0, 0, NULL, NULL, hInst, NULL);
285 HWND get_thread_hwnd(void)
287 thread_data_t *thread_data = get_thread_data(TRUE);
289 if(!thread_data->thread_hwnd)
290 thread_data->thread_hwnd = create_thread_hwnd();
292 return thread_data->thread_hwnd;
295 thread_data_t *get_thread_data(BOOL create)
297 thread_data_t *thread_data;
299 if(!mshtml_tls) {
300 if(create)
301 mshtml_tls = TlsAlloc();
302 else
303 return NULL;
306 thread_data = TlsGetValue(mshtml_tls);
307 if(!thread_data && create) {
308 thread_data = heap_alloc_zero(sizeof(thread_data_t));
309 TlsSetValue(mshtml_tls, thread_data);
312 return thread_data;