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
31 #include "wine/debug.h"
33 #include "mshtml_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
37 #define NS_PROMPTSERVICE_CONTRACTID "@mozilla.org/embedcomp/prompt-service;1"
38 #define NS_TOOLTIPTEXTPROVIDER_CONTRACTID "@mozilla.org/embedcomp/tooltiptextprovider;1"
40 #define NS_TOOLTIPTEXTPROVIDER_CLASSNAME "nsTooltipTextProvider"
42 static const nsIID NS_PROMPTSERVICE_CID
=
43 {0xa2112d6a,0x0e28,0x421f,{0xb4,0x6a,0x25,0xc0,0xb3,0x8,0xcb,0xd0}};
44 static const nsIID NS_TOOLTIPTEXTPROVIDER_CID
=
45 {0x0b666e3e,0x569a,0x462c,{0xa7,0xf0,0xb1,0x6b,0xb1,0x5d,0x42,0xff}};
47 static nsresult NSAPI
nsPromptService_QueryInterface(nsIPromptService
*iface
,
48 nsIIDRef riid
, void **result
)
52 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
53 TRACE("(IID_nsISupports %p)\n", result
);
55 }else if(IsEqualGUID(&IID_nsIPromptService
, riid
)) {
56 TRACE("(IID_nsIPromptService %p)\n", result
);
63 TRACE("(%s %p)\n", debugstr_guid(riid
), result
);
64 return NS_NOINTERFACE
;
67 static nsrefcnt NSAPI
nsPromptService_AddRef(nsIPromptService
*iface
)
72 static nsrefcnt NSAPI
nsPromptService_Release(nsIPromptService
*iface
)
77 static nsresult NSAPI
nsPromptService_Alert(nsIPromptService
*iface
, nsIDOMWindow
*aParent
,
78 const PRUnichar
*aDialogTitle
, const PRUnichar
*aText
)
80 HTMLOuterWindow
*window
;
83 TRACE("(%p %s %s)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
));
85 window
= nswindow_to_window(aParent
);
87 WARN("Could not find HTMLWindow for nsIDOMWindow %p\n", aParent
);
88 return NS_ERROR_UNEXPECTED
;
91 text
= SysAllocString(aText
);
92 IHTMLWindow2_alert(&window
->base
.IHTMLWindow2_iface
, text
);
98 static nsresult NSAPI
nsPromptService_AlertCheck(nsIPromptService
*iface
,
99 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
100 const PRUnichar
*aText
, const PRUnichar
*aCheckMsg
, cpp_bool
*aCheckState
)
102 FIXME("(%p %s %s %s %p)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
),
103 debugstr_w(aCheckMsg
), aCheckState
);
104 return NS_ERROR_NOT_IMPLEMENTED
;
107 static nsresult NSAPI
nsPromptService_Confirm(nsIPromptService
*iface
,
108 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
, const PRUnichar
*aText
,
111 FIXME("(%p %s %s %p)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
), _retval
);
112 return NS_ERROR_NOT_IMPLEMENTED
;
115 static nsresult NSAPI
nsPromptService_ConfirmCheck(nsIPromptService
*iface
,
116 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
117 const PRUnichar
*aText
, const PRUnichar
*aCheckMsg
, cpp_bool
*aCheckState
,
120 FIXME("(%p %s %s %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
),
121 debugstr_w(aCheckMsg
), aCheckState
, _retval
);
122 return NS_ERROR_NOT_IMPLEMENTED
;
125 static nsresult NSAPI
nsPromptService_ConfirmEx(nsIPromptService
*iface
,
126 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
127 const PRUnichar
*aText
, UINT32 aButtonFlags
, const PRUnichar
*aButton0Title
,
128 const PRUnichar
*aButton1Title
, const PRUnichar
*aButton2Title
,
129 const PRUnichar
*aCheckMsg
, cpp_bool
*aCheckState
, LONG
*_retval
)
131 static const PRUnichar wszContinue
[] = {'C','o','n','t','i','n','u','e',0};
133 FIXME("(%p %s %s %08x %s %s %s %s %p %p) hack!\n", aParent
, debugstr_w(aDialogTitle
),
134 debugstr_w(aText
), aButtonFlags
, debugstr_w(aButton0Title
),
135 debugstr_w(aButton1Title
), debugstr_w(aButton2Title
), debugstr_w(aCheckMsg
),
136 aCheckState
, _retval
);
140 * This is really very very ugly hack!!!
143 if(aButton0Title
&& !memcmp(aButton0Title
, wszContinue
, sizeof(wszContinue
)))
145 else if(aButton1Title
&& !memcmp(aButton1Title
, wszContinue
, sizeof(wszContinue
)))
147 else if(aButton2Title
&& !memcmp(aButton2Title
, wszContinue
, sizeof(wszContinue
)))
150 * let's hope that _retval is set to the default value */
155 static nsresult NSAPI
nsPromptService_Prompt(nsIPromptService
*iface
,
156 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
157 const PRUnichar
*aText
, PRUnichar
**aValue
, const PRUnichar
*aCheckMsg
,
158 cpp_bool
*aCheckState
, cpp_bool
*_retval
)
160 FIXME("(%p %s %s %p %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
),
161 aValue
, debugstr_w(aCheckMsg
), aCheckState
, _retval
);
162 return NS_ERROR_NOT_IMPLEMENTED
;
165 static nsresult NSAPI
nsPromptService_PromptUsernameAndPassword(nsIPromptService
*iface
,
166 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
167 const PRUnichar
*aText
, PRUnichar
**aUsername
, PRUnichar
**aPassword
,
168 const PRUnichar
*aCheckMsg
, cpp_bool
*aCheckState
, cpp_bool
*_retval
)
170 FIXME("(%p %s %s %p %p %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
),
171 debugstr_w(aText
), aUsername
, aPassword
, debugstr_w(aCheckMsg
), aCheckState
,
173 return NS_ERROR_NOT_IMPLEMENTED
;
176 static nsresult NSAPI
nsPromptService_PromptPassword(nsIPromptService
*iface
,
177 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
178 const PRUnichar
*aText
, PRUnichar
**aPassword
, const PRUnichar
*aCheckMsg
,
179 cpp_bool
*aCheckState
, cpp_bool
*_retval
)
181 FIXME("(%p %s %s %p %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
),
182 debugstr_w(aText
), aPassword
, debugstr_w(aCheckMsg
), aCheckState
, _retval
);
183 return NS_ERROR_NOT_IMPLEMENTED
;
186 static nsresult NSAPI
nsPromptService_Select(nsIPromptService
*iface
,
187 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
188 const PRUnichar
*aText
, UINT32 aCount
, const PRUnichar
**aSelectList
,
189 LONG
*aOutSelection
, cpp_bool
*_retval
)
191 FIXME("(%p %s %s %d %p %p %p)\n", aParent
, debugstr_w(aDialogTitle
),
192 debugstr_w(aText
), aCount
, aSelectList
, aOutSelection
, _retval
);
193 return NS_ERROR_NOT_IMPLEMENTED
;
196 static const nsIPromptServiceVtbl PromptServiceVtbl
= {
197 nsPromptService_QueryInterface
,
198 nsPromptService_AddRef
,
199 nsPromptService_Release
,
200 nsPromptService_Alert
,
201 nsPromptService_AlertCheck
,
202 nsPromptService_Confirm
,
203 nsPromptService_ConfirmCheck
,
204 nsPromptService_ConfirmEx
,
205 nsPromptService_Prompt
,
206 nsPromptService_PromptUsernameAndPassword
,
207 nsPromptService_PromptPassword
,
208 nsPromptService_Select
211 static nsIPromptService nsPromptService
= { &PromptServiceVtbl
};
213 static nsresult NSAPI
nsTooltipTextProvider_QueryInterface(nsITooltipTextProvider
*iface
,
214 nsIIDRef riid
, void **result
)
218 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
219 TRACE("(IID_nsISupports %p)\n", result
);
221 }else if(IsEqualGUID(&IID_nsITooltipTextProvider
, riid
)) {
222 TRACE("(IID_nsITooltipTextProvider %p)\n", result
);
227 nsITooltipTextProvider_AddRef(iface
);
231 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
232 return NS_NOINTERFACE
;
235 static nsrefcnt NSAPI
nsTooltipTextProvider_AddRef(nsITooltipTextProvider
*iface
)
240 static nsrefcnt NSAPI
nsTooltipTextProvider_Release(nsITooltipTextProvider
*iface
)
245 static nsresult NSAPI
nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider
*iface
,
246 nsIDOMNode
*aNode
, PRUnichar
**aText
, cpp_bool
*_retval
)
248 nsIDOMHTMLElement
*nselem
;
249 nsIDOMNode
*node
= aNode
, *parent
;
251 const PRUnichar
*title
= NULL
;
254 TRACE("(%p %p %p)\n", aNode
, aText
, _retval
);
258 nsAString_Init(&title_str
, NULL
);
261 nsres
= nsIDOMNode_QueryInterface(node
, &IID_nsIDOMHTMLElement
, (void**)&nselem
);
262 if(NS_SUCCEEDED(nsres
)) {
265 nsIDOMHTMLElement_GetTitle(nselem
, &title_str
);
266 nsIDOMHTMLElement_Release(nselem
);
268 nsAString_GetData(&title_str
, &title
);
269 if(title
&& *title
) {
271 nsIDOMNode_Release(node
);
276 nsres
= nsIDOMNode_GetParentNode(node
, &parent
);
281 nsIDOMNode_Release(node
);
285 if(title
&& *title
) {
286 int size
= (strlenW(title
)+1)*sizeof(PRUnichar
);
288 *aText
= nsalloc(size
);
289 memcpy(*aText
, title
, size
);
290 TRACE("aText = %s\n", debugstr_w(*aText
));
297 nsAString_Finish(&title_str
);
302 static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl
= {
303 nsTooltipTextProvider_QueryInterface
,
304 nsTooltipTextProvider_AddRef
,
305 nsTooltipTextProvider_Release
,
306 nsTooltipTextProvider_GetNodeText
309 static nsITooltipTextProvider nsTooltipTextProvider
= { &nsTooltipTextProviderVtbl
};
312 nsIFactory nsIFactory_iface
;
313 nsISupports
*service
;
316 static inline nsServiceFactory
*impl_from_nsIFactory(nsIFactory
*iface
)
318 return CONTAINING_RECORD(iface
, nsServiceFactory
, nsIFactory_iface
);
321 static nsresult NSAPI
nsServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
324 nsServiceFactory
*This
= impl_from_nsIFactory(iface
);
328 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
329 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
330 *result
= &This
->nsIFactory_iface
;
331 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
332 TRACE("(%p)->(IID_nsIFactory %p)\n", This
, result
);
333 *result
= &This
->nsIFactory_iface
;
339 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
340 return NS_NOINTERFACE
;
343 static nsrefcnt NSAPI
nsServiceFactory_AddRef(nsIFactory
*iface
)
348 static nsrefcnt NSAPI
nsServiceFactory_Release(nsIFactory
*iface
)
353 static nsresult NSAPI
nsServiceFactory_CreateInstance(nsIFactory
*iface
,
354 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
356 nsServiceFactory
*This
= impl_from_nsIFactory(iface
);
358 TRACE("(%p)->(%p %s %p)\n", This
, aOuter
, debugstr_guid(iid
), result
);
360 return nsISupports_QueryInterface(This
->service
, iid
, result
);
363 static nsresult NSAPI
nsServiceFactory_LockFactory(nsIFactory
*iface
, cpp_bool lock
)
365 nsServiceFactory
*This
= impl_from_nsIFactory(iface
);
366 WARN("(%p)->(%x)\n", This
, lock
);
370 static const nsIFactoryVtbl nsServiceFactoryVtbl
= {
371 nsServiceFactory_QueryInterface
,
372 nsServiceFactory_AddRef
,
373 nsServiceFactory_Release
,
374 nsServiceFactory_CreateInstance
,
375 nsServiceFactory_LockFactory
378 static nsServiceFactory nsPromptServiceFactory
= {
379 { &nsServiceFactoryVtbl
},
380 (nsISupports
*)&nsPromptService
383 static nsServiceFactory nsTooltipTextFactory
= {
384 { &nsServiceFactoryVtbl
},
385 (nsISupports
*)&nsTooltipTextProvider
388 void register_nsservice(nsIComponentRegistrar
*registrar
, nsIServiceManager
*service_manager
)
392 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_PROMPTSERVICE_CID
,
393 "Prompt Service", NS_PROMPTSERVICE_CONTRACTID
, &nsPromptServiceFactory
.nsIFactory_iface
);
395 ERR("RegisterFactory failed: %08x\n", nsres
);
397 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_TOOLTIPTEXTPROVIDER_CID
,
398 NS_TOOLTIPTEXTPROVIDER_CLASSNAME
, NS_TOOLTIPTEXTPROVIDER_CONTRACTID
,
399 &nsTooltipTextFactory
.nsIFactory_iface
);
401 ERR("RegisterFactory failed: %08x\n", nsres
);