makefiles: Don't use standard libs for programs that specify -nodefaultlibs.
[wine/zf.git] / dlls / mshtml / nsservice.c
blob2eb838b2f54353a2440236576bd432080845caa6
1 /*
2 * Copyright 2005 Jacek Caban
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 <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "winreg.h"
27 #include "ole2.h"
29 #include "wine/debug.h"
31 #include "mshtml_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
35 #define NS_PROMPTSERVICE_CONTRACTID "@mozilla.org/embedcomp/prompt-service;1"
36 #define NS_TOOLTIPTEXTPROVIDER_CONTRACTID "@mozilla.org/embedcomp/tooltiptextprovider;1"
38 #define NS_TOOLTIPTEXTPROVIDER_CLASSNAME "nsTooltipTextProvider"
40 static const nsIID NS_PROMPTSERVICE_CID =
41 {0xa2112d6a,0x0e28,0x421f,{0xb4,0x6a,0x25,0xc0,0xb3,0x8,0xcb,0xd0}};
42 static const nsIID NS_TOOLTIPTEXTPROVIDER_CID =
43 {0x0b666e3e,0x569a,0x462c,{0xa7,0xf0,0xb1,0x6b,0xb1,0x5d,0x42,0xff}};
45 static nsresult NSAPI nsPromptService_QueryInterface(nsIPromptService *iface,
46 nsIIDRef riid, void **result)
48 *result = NULL;
50 if(IsEqualGUID(&IID_nsISupports, riid)) {
51 TRACE("(IID_nsISupports %p)\n", result);
52 *result = iface;
53 }else if(IsEqualGUID(&IID_nsIPromptService, riid)) {
54 TRACE("(IID_nsIPromptService %p)\n", result);
55 *result = iface;
58 if(*result)
59 return NS_OK;
61 TRACE("(%s %p)\n", debugstr_guid(riid), result);
62 return NS_NOINTERFACE;
65 static nsrefcnt NSAPI nsPromptService_AddRef(nsIPromptService *iface)
67 return 2;
70 static nsrefcnt NSAPI nsPromptService_Release(nsIPromptService *iface)
72 return 1;
75 static nsresult NSAPI nsPromptService_Alert(nsIPromptService *iface, mozIDOMWindowProxy *aParent,
76 const PRUnichar *aDialogTitle, const PRUnichar *aText)
78 HTMLOuterWindow *window;
79 BSTR text;
81 TRACE("(%p %s %s)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText));
83 window = mozwindow_to_window(aParent);
84 if(!window) {
85 WARN("Could not find HTMLWindow for mozIDOMWindowProxy %p\n", aParent);
86 return NS_ERROR_UNEXPECTED;
89 text = SysAllocString(aText);
90 IHTMLWindow2_alert(&window->base.IHTMLWindow2_iface, text);
91 SysFreeString(text);
93 return NS_OK;
96 static nsresult NSAPI nsPromptService_AlertCheck(nsIPromptService *iface,
97 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle,
98 const PRUnichar *aText, const PRUnichar *aCheckMsg, cpp_bool *aCheckState)
100 FIXME("(%p %s %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
101 debugstr_w(aCheckMsg), aCheckState);
102 return NS_ERROR_NOT_IMPLEMENTED;
105 static nsresult NSAPI nsPromptService_Confirm(nsIPromptService *iface,
106 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle, const PRUnichar *aText,
107 cpp_bool *_retval)
109 FIXME("(%p %s %s %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText), _retval);
110 return NS_ERROR_NOT_IMPLEMENTED;
113 static nsresult NSAPI nsPromptService_ConfirmCheck(nsIPromptService *iface,
114 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle,
115 const PRUnichar *aText, const PRUnichar *aCheckMsg, cpp_bool *aCheckState,
116 cpp_bool *_retval)
118 FIXME("(%p %s %s %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
119 debugstr_w(aCheckMsg), aCheckState, _retval);
120 return NS_ERROR_NOT_IMPLEMENTED;
123 static nsresult NSAPI nsPromptService_ConfirmEx(nsIPromptService *iface,
124 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle,
125 const PRUnichar *aText, UINT32 aButtonFlags, const PRUnichar *aButton0Title,
126 const PRUnichar *aButton1Title, const PRUnichar *aButton2Title,
127 const PRUnichar *aCheckMsg, cpp_bool *aCheckState, LONG *_retval)
129 static const PRUnichar wszContinue[] = {'C','o','n','t','i','n','u','e',0};
131 FIXME("(%p %s %s %08x %s %s %s %s %p %p) hack!\n", aParent, debugstr_w(aDialogTitle),
132 debugstr_w(aText), aButtonFlags, debugstr_w(aButton0Title),
133 debugstr_w(aButton1Title), debugstr_w(aButton2Title), debugstr_w(aCheckMsg),
134 aCheckState, _retval);
137 * FIXME:
138 * This is really very very ugly hack!!!
141 if(aButton0Title && !memcmp(aButton0Title, wszContinue, sizeof(wszContinue)))
142 *_retval = 0;
143 else if(aButton1Title && !memcmp(aButton1Title, wszContinue, sizeof(wszContinue)))
144 *_retval = 1;
145 else if(aButton2Title && !memcmp(aButton2Title, wszContinue, sizeof(wszContinue)))
146 *_retval = 2;
147 /* else
148 * let's hope that _retval is set to the default value */
150 return NS_OK;
153 static nsresult NSAPI nsPromptService_Prompt(nsIPromptService *iface,
154 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle,
155 const PRUnichar *aText, PRUnichar **aValue, const PRUnichar *aCheckMsg,
156 cpp_bool *aCheckState, cpp_bool *_retval)
158 FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle), debugstr_w(aText),
159 aValue, debugstr_w(aCheckMsg), aCheckState, _retval);
160 return NS_ERROR_NOT_IMPLEMENTED;
163 static nsresult NSAPI nsPromptService_PromptUsernameAndPassword(nsIPromptService *iface,
164 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle,
165 const PRUnichar *aText, PRUnichar **aUsername, PRUnichar **aPassword,
166 const PRUnichar *aCheckMsg, cpp_bool *aCheckState, cpp_bool *_retval)
168 FIXME("(%p %s %s %p %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
169 debugstr_w(aText), aUsername, aPassword, debugstr_w(aCheckMsg), aCheckState,
170 _retval);
171 return NS_ERROR_NOT_IMPLEMENTED;
174 static nsresult NSAPI nsPromptService_PromptPassword(nsIPromptService *iface,
175 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle,
176 const PRUnichar *aText, PRUnichar **aPassword, const PRUnichar *aCheckMsg,
177 cpp_bool *aCheckState, cpp_bool *_retval)
179 FIXME("(%p %s %s %p %s %p %p)\n", aParent, debugstr_w(aDialogTitle),
180 debugstr_w(aText), aPassword, debugstr_w(aCheckMsg), aCheckState, _retval);
181 return NS_ERROR_NOT_IMPLEMENTED;
184 static nsresult NSAPI nsPromptService_Select(nsIPromptService *iface,
185 mozIDOMWindowProxy *aParent, const PRUnichar *aDialogTitle,
186 const PRUnichar *aText, UINT32 aCount, const PRUnichar **aSelectList,
187 LONG *aOutSelection, cpp_bool *_retval)
189 FIXME("(%p %s %s %d %p %p %p)\n", aParent, debugstr_w(aDialogTitle),
190 debugstr_w(aText), aCount, aSelectList, aOutSelection, _retval);
191 return NS_ERROR_NOT_IMPLEMENTED;
194 static const nsIPromptServiceVtbl PromptServiceVtbl = {
195 nsPromptService_QueryInterface,
196 nsPromptService_AddRef,
197 nsPromptService_Release,
198 nsPromptService_Alert,
199 nsPromptService_AlertCheck,
200 nsPromptService_Confirm,
201 nsPromptService_ConfirmCheck,
202 nsPromptService_ConfirmEx,
203 nsPromptService_Prompt,
204 nsPromptService_PromptUsernameAndPassword,
205 nsPromptService_PromptPassword,
206 nsPromptService_Select
209 static nsIPromptService nsPromptService = { &PromptServiceVtbl };
211 static nsresult NSAPI nsTooltipTextProvider_QueryInterface(nsITooltipTextProvider *iface,
212 nsIIDRef riid, void **result)
214 *result = NULL;
216 if(IsEqualGUID(&IID_nsISupports, riid)) {
217 TRACE("(IID_nsISupports %p)\n", result);
218 *result = iface;
219 }else if(IsEqualGUID(&IID_nsITooltipTextProvider, riid)) {
220 TRACE("(IID_nsITooltipTextProvider %p)\n", result);
221 *result = iface;
224 if(*result) {
225 nsITooltipTextProvider_AddRef(iface);
226 return NS_OK;
229 WARN("(%s %p)\n", debugstr_guid(riid), result);
230 return NS_NOINTERFACE;
233 static nsrefcnt NSAPI nsTooltipTextProvider_AddRef(nsITooltipTextProvider *iface)
235 return 2;
238 static nsrefcnt NSAPI nsTooltipTextProvider_Release(nsITooltipTextProvider *iface)
240 return 1;
243 static nsresult NSAPI nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider *iface,
244 nsIDOMNode *aNode, PRUnichar **aText, cpp_bool *_retval)
246 nsIDOMHTMLElement *nselem;
247 nsIDOMNode *node = aNode, *parent;
248 nsAString title_str;
249 const PRUnichar *title = NULL;
250 nsresult nsres;
252 TRACE("(%p %p %p)\n", aNode, aText, _retval);
254 *aText = NULL;
256 nsAString_Init(&title_str, NULL);
258 do {
259 nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMHTMLElement, (void**)&nselem);
260 if(NS_SUCCEEDED(nsres)) {
261 title = NULL;
263 nsIDOMHTMLElement_GetTitle(nselem, &title_str);
264 nsIDOMHTMLElement_Release(nselem);
266 nsAString_GetData(&title_str, &title);
267 if(title && *title) {
268 if(node != aNode)
269 nsIDOMNode_Release(node);
270 break;
274 nsres = nsIDOMNode_GetParentNode(node, &parent);
275 if(NS_FAILED(nsres))
276 parent = NULL;
278 if(node != aNode)
279 nsIDOMNode_Release(node);
280 node = parent;
281 } while(node);
283 if(title && *title) {
284 int size = (lstrlenW(title)+1)*sizeof(PRUnichar);
286 *aText = nsalloc(size);
287 memcpy(*aText, title, size);
288 TRACE("aText = %s\n", debugstr_w(*aText));
290 *_retval = TRUE;
291 }else {
292 *_retval = FALSE;
295 nsAString_Finish(&title_str);
297 return NS_OK;
300 static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl = {
301 nsTooltipTextProvider_QueryInterface,
302 nsTooltipTextProvider_AddRef,
303 nsTooltipTextProvider_Release,
304 nsTooltipTextProvider_GetNodeText
307 static nsITooltipTextProvider nsTooltipTextProvider = { &nsTooltipTextProviderVtbl };
309 typedef struct {
310 nsIFactory nsIFactory_iface;
311 nsISupports *service;
312 } nsServiceFactory;
314 static inline nsServiceFactory *impl_from_nsIFactory(nsIFactory *iface)
316 return CONTAINING_RECORD(iface, nsServiceFactory, nsIFactory_iface);
319 static nsresult NSAPI nsServiceFactory_QueryInterface(nsIFactory *iface, nsIIDRef riid,
320 void **result)
322 nsServiceFactory *This = impl_from_nsIFactory(iface);
324 *result = NULL;
326 if(IsEqualGUID(&IID_nsISupports, riid)) {
327 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
328 *result = &This->nsIFactory_iface;
329 }else if(IsEqualGUID(&IID_nsIFactory, riid)) {
330 TRACE("(%p)->(IID_nsIFactory %p)\n", This, result);
331 *result = &This->nsIFactory_iface;
334 if(*result)
335 return NS_OK;
337 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
338 return NS_NOINTERFACE;
341 static nsrefcnt NSAPI nsServiceFactory_AddRef(nsIFactory *iface)
343 return 2;
346 static nsrefcnt NSAPI nsServiceFactory_Release(nsIFactory *iface)
348 return 1;
351 static nsresult NSAPI nsServiceFactory_CreateInstance(nsIFactory *iface,
352 nsISupports *aOuter, const nsIID *iid, void **result)
354 nsServiceFactory *This = impl_from_nsIFactory(iface);
356 TRACE("(%p)->(%p %s %p)\n", This, aOuter, debugstr_guid(iid), result);
358 return nsISupports_QueryInterface(This->service, iid, result);
361 static nsresult NSAPI nsServiceFactory_LockFactory(nsIFactory *iface, cpp_bool lock)
363 nsServiceFactory *This = impl_from_nsIFactory(iface);
364 WARN("(%p)->(%x)\n", This, lock);
365 return NS_OK;
368 static const nsIFactoryVtbl nsServiceFactoryVtbl = {
369 nsServiceFactory_QueryInterface,
370 nsServiceFactory_AddRef,
371 nsServiceFactory_Release,
372 nsServiceFactory_CreateInstance,
373 nsServiceFactory_LockFactory
376 static nsServiceFactory nsPromptServiceFactory = {
377 { &nsServiceFactoryVtbl },
378 (nsISupports*)&nsPromptService
381 static nsServiceFactory nsTooltipTextFactory = {
382 { &nsServiceFactoryVtbl },
383 (nsISupports*)&nsTooltipTextProvider
386 void register_nsservice(nsIComponentRegistrar *registrar, nsIServiceManager *service_manager)
388 nsresult nsres;
390 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_PROMPTSERVICE_CID,
391 "Prompt Service", NS_PROMPTSERVICE_CONTRACTID, &nsPromptServiceFactory.nsIFactory_iface);
392 if(NS_FAILED(nsres))
393 ERR("RegisterFactory failed: %08x\n", nsres);
395 nsres = nsIComponentRegistrar_RegisterFactory(registrar, &NS_TOOLTIPTEXTPROVIDER_CID,
396 NS_TOOLTIPTEXTPROVIDER_CLASSNAME, NS_TOOLTIPTEXTPROVIDER_CONTRACTID,
397 &nsTooltipTextFactory.nsIFactory_iface);
398 if(NS_FAILED(nsres))
399 ERR("RegisterFactory failed: %08x\n", nsres);