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 "mshtml_private.h"
21 #define NS_PROMPTSERVICE_CONTRACTID "@mozilla.org/embedcomp/prompt-service;1"
22 #define NS_TOOLTIPTEXTPROVIDER_CONTRACTID "@mozilla.org/embedcomp/tooltiptextprovider;1"
24 #define NS_TOOLTIPTEXTPROVIDER_CLASSNAME "nsTooltipTextProvider"
26 static const nsIID NS_PROMPTSERVICE_CID
=
27 {0xa2112d6a,0x0e28,0x421f,{0xb4,0x6a,0x25,0xc0,0xb3,0x8,0xcb,0xd0}};
28 static const nsIID NS_TOOLTIPTEXTPROVIDER_CID
=
29 {0x0b666e3e,0x569a,0x462c,{0xa7,0xf0,0xb1,0x6b,0xb1,0x5d,0x42,0xff}};
31 static nsresult NSAPI
nsPromptService_QueryInterface(nsIPromptService
*iface
,
32 nsIIDRef riid
, void **result
)
36 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
37 TRACE("(IID_nsISupports %p)\n", result
);
39 }else if(IsEqualGUID(&IID_nsIPromptService
, riid
)) {
40 TRACE("(IID_nsIPromptService %p)\n", result
);
47 TRACE("(%s %p)\n", debugstr_guid(riid
), result
);
48 return NS_NOINTERFACE
;
51 static nsrefcnt NSAPI
nsPromptService_AddRef(nsIPromptService
*iface
)
56 static nsrefcnt NSAPI
nsPromptService_Release(nsIPromptService
*iface
)
61 static nsresult NSAPI
nsPromptService_Alert(nsIPromptService
*iface
, nsIDOMWindow
*aParent
,
62 const PRUnichar
*aDialogTitle
, const PRUnichar
*aText
)
64 HTMLOuterWindow
*window
;
67 TRACE("(%p %s %s)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
));
69 window
= nswindow_to_window(aParent
);
71 WARN("Could not find HTMLWindow for nsIDOMWindow %p\n", aParent
);
72 return NS_ERROR_UNEXPECTED
;
75 text
= SysAllocString(aText
);
76 IHTMLWindow2_alert(&window
->base
.IHTMLWindow2_iface
, text
);
82 static nsresult NSAPI
nsPromptService_AlertCheck(nsIPromptService
*iface
,
83 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
84 const PRUnichar
*aText
, const PRUnichar
*aCheckMsg
, cpp_bool
*aCheckState
)
86 FIXME("(%p %s %s %s %p)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
),
87 debugstr_w(aCheckMsg
), aCheckState
);
88 return NS_ERROR_NOT_IMPLEMENTED
;
91 static nsresult NSAPI
nsPromptService_Confirm(nsIPromptService
*iface
,
92 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
, const PRUnichar
*aText
,
95 FIXME("(%p %s %s %p)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
), _retval
);
96 return NS_ERROR_NOT_IMPLEMENTED
;
99 static nsresult NSAPI
nsPromptService_ConfirmCheck(nsIPromptService
*iface
,
100 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
101 const PRUnichar
*aText
, const PRUnichar
*aCheckMsg
, cpp_bool
*aCheckState
,
104 FIXME("(%p %s %s %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
),
105 debugstr_w(aCheckMsg
), aCheckState
, _retval
);
106 return NS_ERROR_NOT_IMPLEMENTED
;
109 static nsresult NSAPI
nsPromptService_ConfirmEx(nsIPromptService
*iface
,
110 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
111 const PRUnichar
*aText
, UINT32 aButtonFlags
, const PRUnichar
*aButton0Title
,
112 const PRUnichar
*aButton1Title
, const PRUnichar
*aButton2Title
,
113 const PRUnichar
*aCheckMsg
, cpp_bool
*aCheckState
, LONG
*_retval
)
115 static const PRUnichar wszContinue
[] = {'C','o','n','t','i','n','u','e',0};
117 FIXME("(%p %s %s %08x %s %s %s %s %p %p) hack!\n", aParent
, debugstr_w(aDialogTitle
),
118 debugstr_w(aText
), aButtonFlags
, debugstr_w(aButton0Title
),
119 debugstr_w(aButton1Title
), debugstr_w(aButton2Title
), debugstr_w(aCheckMsg
),
120 aCheckState
, _retval
);
124 * This is really very very ugly hack!!!
127 if(aButton0Title
&& !memcmp(aButton0Title
, wszContinue
, sizeof(wszContinue
)))
129 else if(aButton1Title
&& !memcmp(aButton1Title
, wszContinue
, sizeof(wszContinue
)))
131 else if(aButton2Title
&& !memcmp(aButton2Title
, wszContinue
, sizeof(wszContinue
)))
134 * let's hope that _retval is set to the default value */
139 static nsresult NSAPI
nsPromptService_Prompt(nsIPromptService
*iface
,
140 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
141 const PRUnichar
*aText
, PRUnichar
**aValue
, const PRUnichar
*aCheckMsg
,
142 cpp_bool
*aCheckState
, cpp_bool
*_retval
)
144 FIXME("(%p %s %s %p %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
), debugstr_w(aText
),
145 aValue
, debugstr_w(aCheckMsg
), aCheckState
, _retval
);
146 return NS_ERROR_NOT_IMPLEMENTED
;
149 static nsresult NSAPI
nsPromptService_PromptUsernameAndPassword(nsIPromptService
*iface
,
150 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
151 const PRUnichar
*aText
, PRUnichar
**aUsername
, PRUnichar
**aPassword
,
152 const PRUnichar
*aCheckMsg
, cpp_bool
*aCheckState
, cpp_bool
*_retval
)
154 FIXME("(%p %s %s %p %p %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
),
155 debugstr_w(aText
), aUsername
, aPassword
, debugstr_w(aCheckMsg
), aCheckState
,
157 return NS_ERROR_NOT_IMPLEMENTED
;
160 static nsresult NSAPI
nsPromptService_PromptPassword(nsIPromptService
*iface
,
161 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
162 const PRUnichar
*aText
, PRUnichar
**aPassword
, const PRUnichar
*aCheckMsg
,
163 cpp_bool
*aCheckState
, cpp_bool
*_retval
)
165 FIXME("(%p %s %s %p %s %p %p)\n", aParent
, debugstr_w(aDialogTitle
),
166 debugstr_w(aText
), aPassword
, debugstr_w(aCheckMsg
), aCheckState
, _retval
);
167 return NS_ERROR_NOT_IMPLEMENTED
;
170 static nsresult NSAPI
nsPromptService_Select(nsIPromptService
*iface
,
171 nsIDOMWindow
*aParent
, const PRUnichar
*aDialogTitle
,
172 const PRUnichar
*aText
, UINT32 aCount
, const PRUnichar
**aSelectList
,
173 LONG
*aOutSelection
, cpp_bool
*_retval
)
175 FIXME("(%p %s %s %d %p %p %p)\n", aParent
, debugstr_w(aDialogTitle
),
176 debugstr_w(aText
), aCount
, aSelectList
, aOutSelection
, _retval
);
177 return NS_ERROR_NOT_IMPLEMENTED
;
180 static const nsIPromptServiceVtbl PromptServiceVtbl
= {
181 nsPromptService_QueryInterface
,
182 nsPromptService_AddRef
,
183 nsPromptService_Release
,
184 nsPromptService_Alert
,
185 nsPromptService_AlertCheck
,
186 nsPromptService_Confirm
,
187 nsPromptService_ConfirmCheck
,
188 nsPromptService_ConfirmEx
,
189 nsPromptService_Prompt
,
190 nsPromptService_PromptUsernameAndPassword
,
191 nsPromptService_PromptPassword
,
192 nsPromptService_Select
195 static nsIPromptService nsPromptService
= { &PromptServiceVtbl
};
197 static nsresult NSAPI
nsTooltipTextProvider_QueryInterface(nsITooltipTextProvider
*iface
,
198 nsIIDRef riid
, void **result
)
202 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
203 TRACE("(IID_nsISupports %p)\n", result
);
205 }else if(IsEqualGUID(&IID_nsITooltipTextProvider
, riid
)) {
206 TRACE("(IID_nsITooltipTextProvider %p)\n", result
);
211 nsITooltipTextProvider_AddRef(iface
);
215 WARN("(%s %p)\n", debugstr_guid(riid
), result
);
216 return NS_NOINTERFACE
;
219 static nsrefcnt NSAPI
nsTooltipTextProvider_AddRef(nsITooltipTextProvider
*iface
)
224 static nsrefcnt NSAPI
nsTooltipTextProvider_Release(nsITooltipTextProvider
*iface
)
229 static nsresult NSAPI
nsTooltipTextProvider_GetNodeText(nsITooltipTextProvider
*iface
,
230 nsIDOMNode
*aNode
, PRUnichar
**aText
, cpp_bool
*_retval
)
232 nsIDOMHTMLElement
*nselem
;
233 nsIDOMNode
*node
= aNode
, *parent
;
235 const PRUnichar
*title
= NULL
;
238 TRACE("(%p %p %p)\n", aNode
, aText
, _retval
);
242 nsAString_Init(&title_str
, NULL
);
245 nsres
= nsIDOMNode_QueryInterface(node
, &IID_nsIDOMHTMLElement
, (void**)&nselem
);
246 if(NS_SUCCEEDED(nsres
)) {
249 nsIDOMHTMLElement_GetTitle(nselem
, &title_str
);
250 nsIDOMHTMLElement_Release(nselem
);
252 nsAString_GetData(&title_str
, &title
);
253 if(title
&& *title
) {
255 nsIDOMNode_Release(node
);
260 nsres
= nsIDOMNode_GetParentNode(node
, &parent
);
265 nsIDOMNode_Release(node
);
269 if(title
&& *title
) {
270 int size
= (strlenW(title
)+1)*sizeof(PRUnichar
);
272 *aText
= nsalloc(size
);
273 memcpy(*aText
, title
, size
);
274 TRACE("aText = %s\n", debugstr_w(*aText
));
281 nsAString_Finish(&title_str
);
286 static const nsITooltipTextProviderVtbl nsTooltipTextProviderVtbl
= {
287 nsTooltipTextProvider_QueryInterface
,
288 nsTooltipTextProvider_AddRef
,
289 nsTooltipTextProvider_Release
,
290 nsTooltipTextProvider_GetNodeText
293 static nsITooltipTextProvider nsTooltipTextProvider
= { &nsTooltipTextProviderVtbl
};
296 nsIFactory nsIFactory_iface
;
297 nsISupports
*service
;
300 static inline nsServiceFactory
*impl_from_nsIFactory(nsIFactory
*iface
)
302 return CONTAINING_RECORD(iface
, nsServiceFactory
, nsIFactory_iface
);
305 static nsresult NSAPI
nsServiceFactory_QueryInterface(nsIFactory
*iface
, nsIIDRef riid
,
308 nsServiceFactory
*This
= impl_from_nsIFactory(iface
);
312 if(IsEqualGUID(&IID_nsISupports
, riid
)) {
313 TRACE("(%p)->(IID_nsISupports %p)\n", This
, result
);
314 *result
= &This
->nsIFactory_iface
;
315 }else if(IsEqualGUID(&IID_nsIFactory
, riid
)) {
316 TRACE("(%p)->(IID_nsIFactory %p)\n", This
, result
);
317 *result
= &This
->nsIFactory_iface
;
323 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), result
);
324 return NS_NOINTERFACE
;
327 static nsrefcnt NSAPI
nsServiceFactory_AddRef(nsIFactory
*iface
)
332 static nsrefcnt NSAPI
nsServiceFactory_Release(nsIFactory
*iface
)
337 static nsresult NSAPI
nsServiceFactory_CreateInstance(nsIFactory
*iface
,
338 nsISupports
*aOuter
, const nsIID
*iid
, void **result
)
340 nsServiceFactory
*This
= impl_from_nsIFactory(iface
);
342 TRACE("(%p)->(%p %s %p)\n", This
, aOuter
, debugstr_guid(iid
), result
);
344 return nsISupports_QueryInterface(This
->service
, iid
, result
);
347 static nsresult NSAPI
nsServiceFactory_LockFactory(nsIFactory
*iface
, cpp_bool lock
)
349 nsServiceFactory
*This
= impl_from_nsIFactory(iface
);
350 WARN("(%p)->(%x)\n", This
, lock
);
354 static const nsIFactoryVtbl nsServiceFactoryVtbl
= {
355 nsServiceFactory_QueryInterface
,
356 nsServiceFactory_AddRef
,
357 nsServiceFactory_Release
,
358 nsServiceFactory_CreateInstance
,
359 nsServiceFactory_LockFactory
362 static nsServiceFactory nsPromptServiceFactory
= {
363 { &nsServiceFactoryVtbl
},
364 (nsISupports
*)&nsPromptService
367 static nsServiceFactory nsTooltipTextFactory
= {
368 { &nsServiceFactoryVtbl
},
369 (nsISupports
*)&nsTooltipTextProvider
372 void register_nsservice(nsIComponentRegistrar
*registrar
, nsIServiceManager
*service_manager
)
376 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_PROMPTSERVICE_CID
,
377 "Prompt Service", NS_PROMPTSERVICE_CONTRACTID
, &nsPromptServiceFactory
.nsIFactory_iface
);
379 ERR("RegisterFactory failed: %08x\n", nsres
);
381 nsres
= nsIComponentRegistrar_RegisterFactory(registrar
, &NS_TOOLTIPTEXTPROVIDER_CID
,
382 NS_TOOLTIPTEXTPROVIDER_CLASSNAME
, NS_TOOLTIPTEXTPROVIDER_CONTRACTID
,
383 &nsTooltipTextFactory
.nsIFactory_iface
);
385 ERR("RegisterFactory failed: %08x\n", nsres
);