xref: /aoo41x/main/sfx2/source/appl/sfxhelp.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir  /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "sfx2/sfxhelp.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <set>
34*cdf0e10cSrcweir #include <algorithm>
35*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
36*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
39*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
40*cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
50*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
51*cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp>
52*cdf0e10cSrcweir #include <unotools/configmgr.hxx>
53*cdf0e10cSrcweir #include <unotools/configitem.hxx>
54*cdf0e10cSrcweir #include <svtools/helpopt.hxx>
55*cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
56*cdf0e10cSrcweir #include <tools/urlobj.hxx>
57*cdf0e10cSrcweir #include <unotools/configmgr.hxx>
58*cdf0e10cSrcweir #include <ucbhelper/content.hxx>
59*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
60*cdf0e10cSrcweir #include <rtl/ustring.hxx>
61*cdf0e10cSrcweir #include <osl/process.h>
62*cdf0e10cSrcweir #include <osl/file.hxx>
63*cdf0e10cSrcweir #include <unotools/bootstrap.hxx>
64*cdf0e10cSrcweir #include <rtl/uri.hxx>
65*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
66*cdf0e10cSrcweir #include <svtools/ehdl.hxx>
67*cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR
70*cdf0e10cSrcweir #define _SVSTDARR_ULONGSSORT
71*cdf0e10cSrcweir #include <svl/svstdarr.hxx>
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir #include "newhelp.hxx"
74*cdf0e10cSrcweir #include <sfx2/objsh.hxx>
75*cdf0e10cSrcweir #include <sfx2/docfac.hxx>
76*cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
77*cdf0e10cSrcweir #include "helper.hxx"
78*cdf0e10cSrcweir #include "app.hrc"
79*cdf0e10cSrcweir #include <sfx2/sfxuno.hxx>
80*cdf0e10cSrcweir #include <vcl/svapp.hxx>
81*cdf0e10cSrcweir #include <sfx2/frame.hxx>
82*cdf0e10cSrcweir #include <rtl/string.hxx>
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
85*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
86*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
87*cdf0e10cSrcweir using namespace ::com::sun::star::util;
88*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
89*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir #define ERROR_TAG	String( DEFINE_CONST_UNICODE("Error: ") )
92*cdf0e10cSrcweir #define PATH_TAG	String( DEFINE_CONST_UNICODE("\nPath: ") )
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir // class NoHelpErrorBox --------------------------------------------------
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir class NoHelpErrorBox : public ErrorBox
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir public:
99*cdf0e10cSrcweir     NoHelpErrorBox( Window* _pParent );
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir     virtual void    RequestHelp( const HelpEvent& rHEvt );
102*cdf0e10cSrcweir };
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir NoHelpErrorBox::NoHelpErrorBox( Window* _pParent ) :
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     ErrorBox( _pParent, WB_OK, String( SfxResId( RID_STR_HLPFILENOTEXIST ) ) )
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir     // Error message: "No help available"
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir void NoHelpErrorBox::RequestHelp( const HelpEvent& )
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir     // do nothing, because no help available
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir // -----------------------------------------------------------------------
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir #define STARTERLIST 0
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir rtl::OUString HelpLocaleString()
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir 	static rtl::OUString aLocaleStr;
123*cdf0e10cSrcweir 	if (!aLocaleStr.getLength())
124*cdf0e10cSrcweir 	{
125*cdf0e10cSrcweir 		// detect installed locale
126*cdf0e10cSrcweir 		Any aLocale =
127*cdf0e10cSrcweir 			::utl::ConfigManager::GetConfigManager()->GetDirectConfigProperty(
128*cdf0e10cSrcweir 			   ::utl::ConfigManager::LOCALE );
129*cdf0e10cSrcweir         aLocale >>= aLocaleStr;
130*cdf0e10cSrcweir         bool bOk = aLocaleStr.getLength() != 0;
131*cdf0e10cSrcweir 		if ( bOk )
132*cdf0e10cSrcweir 		{
133*cdf0e10cSrcweir 			rtl::OUString aBaseInstallPath;
134*cdf0e10cSrcweir 			// utl::Bootstrap::PathStatus aBaseLocateResult =
135*cdf0e10cSrcweir 			utl::Bootstrap::locateBaseInstallation(aBaseInstallPath);
136*cdf0e10cSrcweir 			static const char *szHelpPath = "/help/";
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 			rtl::OUString sHelpPath = aBaseInstallPath +
139*cdf0e10cSrcweir 				rtl::OUString::createFromAscii(szHelpPath) + aLocaleStr;
140*cdf0e10cSrcweir 			osl::DirectoryItem aDirItem;
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 			if (!osl::DirectoryItem::get(sHelpPath, aDirItem) == osl::FileBase::E_None)
143*cdf0e10cSrcweir 			{
144*cdf0e10cSrcweir 				bOk = false;
145*cdf0e10cSrcweir 				String sLang(aLocaleStr);
146*cdf0e10cSrcweir 				xub_StrLen nSepPos = sLang.Search( '-' );
147*cdf0e10cSrcweir 				if (nSepPos != STRING_NOTFOUND)
148*cdf0e10cSrcweir 				{
149*cdf0e10cSrcweir 					bOk = true;
150*cdf0e10cSrcweir         			sLang = sLang.Copy( 0, nSepPos );
151*cdf0e10cSrcweir 					sHelpPath = aBaseInstallPath +
152*cdf0e10cSrcweir 						rtl::OUString::createFromAscii(szHelpPath) + sLang;
153*cdf0e10cSrcweir 					if (!osl::DirectoryItem::get(sHelpPath, aDirItem) == osl::FileBase::E_None)
154*cdf0e10cSrcweir 						bOk = false;
155*cdf0e10cSrcweir 				}
156*cdf0e10cSrcweir 			}
157*cdf0e10cSrcweir 		}
158*cdf0e10cSrcweir 		if (!bOk)
159*cdf0e10cSrcweir 			aLocaleStr = rtl::OUString( DEFINE_CONST_UNICODE("en") );
160*cdf0e10cSrcweir 	}
161*cdf0e10cSrcweir 	return aLocaleStr;
162*cdf0e10cSrcweir }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir void AppendConfigToken_Impl( String& rURL, sal_Bool bQuestionMark )
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir 	::rtl::OUString aLocaleStr(HelpLocaleString());
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 	// query part exists?
169*cdf0e10cSrcweir 	if ( bQuestionMark )
170*cdf0e10cSrcweir 		// no, so start with '?'
171*cdf0e10cSrcweir 		rURL += '?';
172*cdf0e10cSrcweir 	else
173*cdf0e10cSrcweir 		// yes, so only append with '&'
174*cdf0e10cSrcweir 		rURL += '&';
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	// set parameters
177*cdf0e10cSrcweir 	rURL += DEFINE_CONST_UNICODE("Language=");
178*cdf0e10cSrcweir 	rURL += String( aLocaleStr );
179*cdf0e10cSrcweir 	rURL += DEFINE_CONST_UNICODE("&System=");
180*cdf0e10cSrcweir 	rURL += SvtHelpOptions().GetSystem();
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir }
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir // -----------------------------------------------------------------------
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir sal_Bool GetHelpAnchor_Impl( const String& _rURL, String& _rAnchor )
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
189*cdf0e10cSrcweir 	::rtl::OUString sAnchor;
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     // --> OD 2009-07-01 #159496#
192*cdf0e10cSrcweir     // do not release solar mutex due to crash regarding accessibility
193*cdf0e10cSrcweir //    sal_uIntPtr nSolarCount = Application::ReleaseSolarMutex();
194*cdf0e10cSrcweir     // <--
195*cdf0e10cSrcweir 	try
196*cdf0e10cSrcweir 	{
197*cdf0e10cSrcweir 		::ucbhelper::Content aCnt( INetURLObject( _rURL ).GetMainURL( INetURLObject::NO_DECODE ),
198*cdf0e10cSrcweir 							 Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
199*cdf0e10cSrcweir 		if ( ( aCnt.getPropertyValue( ::rtl::OUString::createFromAscii( "AnchorName" ) ) >>= sAnchor ) )
200*cdf0e10cSrcweir 		{
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 			if ( sAnchor.getLength() > 0 )
203*cdf0e10cSrcweir 			{
204*cdf0e10cSrcweir 				_rAnchor = String( sAnchor );
205*cdf0e10cSrcweir 				bRet = sal_True;
206*cdf0e10cSrcweir 			}
207*cdf0e10cSrcweir 		}
208*cdf0e10cSrcweir 		else
209*cdf0e10cSrcweir 		{
210*cdf0e10cSrcweir 			DBG_ERRORFILE( "Property 'AnchorName' is missing" );
211*cdf0e10cSrcweir 		}
212*cdf0e10cSrcweir 	}
213*cdf0e10cSrcweir 	catch( ::com::sun::star::uno::Exception& )
214*cdf0e10cSrcweir 	{
215*cdf0e10cSrcweir 	}
216*cdf0e10cSrcweir     // --> OD 2009-07-01 #159496#
217*cdf0e10cSrcweir //    Application::AcquireSolarMutex( nSolarCount );
218*cdf0e10cSrcweir     // <--
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 	return bRet;
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir // -----------------------------------------------------------------------
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir class SfxHelpOptions_Impl : public utl::ConfigItem
226*cdf0e10cSrcweir {
227*cdf0e10cSrcweir private:
228*cdf0e10cSrcweir     std::set < rtl::OString > m_aIds;
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir public:
231*cdf0e10cSrcweir                     SfxHelpOptions_Impl();
232*cdf0e10cSrcweir                     ~SfxHelpOptions_Impl();
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir     bool            HasId( const rtl::OString& rId ) { return m_aIds.size() ? m_aIds.find( rId ) != m_aIds.end() : false; }
235*cdf0e10cSrcweir     virtual void            Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
236*cdf0e10cSrcweir     virtual void            Commit();
237*cdf0e10cSrcweir };
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir static Sequence< ::rtl::OUString > GetPropertyNames()
240*cdf0e10cSrcweir {
241*cdf0e10cSrcweir 	static const char* aPropNames[] =
242*cdf0e10cSrcweir 	{
243*cdf0e10cSrcweir         "HelpAgentStarterList",
244*cdf0e10cSrcweir 	};
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir     const int nCount = sizeof( aPropNames ) / sizeof( const char* );
247*cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aNames( nCount );
248*cdf0e10cSrcweir 	::rtl::OUString* pNames = aNames.getArray();
249*cdf0e10cSrcweir 	::rtl::OUString* pEnd	= pNames + aNames.getLength();
250*cdf0e10cSrcweir 	int i = 0;
251*cdf0e10cSrcweir 	for ( ; pNames != pEnd; ++pNames )
252*cdf0e10cSrcweir 		*pNames = ::rtl::OUString::createFromAscii( aPropNames[i++] );
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 	return aNames;
255*cdf0e10cSrcweir }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir // -----------------------------------------------------------------------
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir SfxHelpOptions_Impl::SfxHelpOptions_Impl()
260*cdf0e10cSrcweir     : ConfigItem( ::rtl::OUString::createFromAscii("Office.SFX/Help") )
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aNames = GetPropertyNames();
263*cdf0e10cSrcweir 	Sequence< Any > aValues = GetProperties( aNames );
264*cdf0e10cSrcweir 	EnableNotification( aNames );
265*cdf0e10cSrcweir 	const Any* pValues = aValues.getConstArray();
266*cdf0e10cSrcweir 	DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
267*cdf0e10cSrcweir 	if ( aValues.getLength() == aNames.getLength() )
268*cdf0e10cSrcweir 	{
269*cdf0e10cSrcweir 		for ( int nProp = 0; nProp < aNames.getLength(); nProp++ )
270*cdf0e10cSrcweir 		{
271*cdf0e10cSrcweir 			DBG_ASSERT( pValues[nProp].hasValue(), "property value missing" );
272*cdf0e10cSrcweir 			if ( pValues[nProp].hasValue() )
273*cdf0e10cSrcweir 			{
274*cdf0e10cSrcweir 				switch ( nProp )
275*cdf0e10cSrcweir 				{
276*cdf0e10cSrcweir                     case STARTERLIST :
277*cdf0e10cSrcweir                     {
278*cdf0e10cSrcweir                         ::rtl::OUString aCodedList;
279*cdf0e10cSrcweir                         if ( pValues[nProp] >>= aCodedList )
280*cdf0e10cSrcweir                         {
281*cdf0e10cSrcweir                             rtl::OString aTmp( aCodedList, aCodedList.getLength(), RTL_TEXTENCODING_UTF8 );
282*cdf0e10cSrcweir                             sal_Int32 nIndex = 0;
283*cdf0e10cSrcweir                             do
284*cdf0e10cSrcweir                             {
285*cdf0e10cSrcweir                                 rtl::OString aToken = aTmp.getToken( 0, ',', nIndex );
286*cdf0e10cSrcweir                                 if ( aToken.getLength() )
287*cdf0e10cSrcweir                                     m_aIds.insert( aToken );
288*cdf0e10cSrcweir                             }
289*cdf0e10cSrcweir                             while ( nIndex >= 0 );
290*cdf0e10cSrcweir                         }
291*cdf0e10cSrcweir                         else {
292*cdf0e10cSrcweir                             DBG_ERRORFILE( "Wrong property type!" );
293*cdf0e10cSrcweir                         }
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir                         break;
296*cdf0e10cSrcweir                     }
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 					default:
299*cdf0e10cSrcweir                         DBG_ERRORFILE( "Wrong property!" );
300*cdf0e10cSrcweir                         break;
301*cdf0e10cSrcweir 				}
302*cdf0e10cSrcweir 			}
303*cdf0e10cSrcweir 		}
304*cdf0e10cSrcweir 	}
305*cdf0e10cSrcweir }
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir SfxHelpOptions_Impl::~SfxHelpOptions_Impl()
308*cdf0e10cSrcweir {
309*cdf0e10cSrcweir }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir void SfxHelpOptions_Impl::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
313*cdf0e10cSrcweir {
314*cdf0e10cSrcweir }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir void SfxHelpOptions_Impl::Commit()
317*cdf0e10cSrcweir {
318*cdf0e10cSrcweir }
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir // class SfxHelp_Impl ----------------------------------------------------
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir class SfxHelp_Impl
323*cdf0e10cSrcweir {
324*cdf0e10cSrcweir private:
325*cdf0e10cSrcweir 	sal_Bool							m_bIsDebug;		// environment variable "help_debug=1"
326*cdf0e10cSrcweir     SfxHelpOptions_Impl*				m_pOpt;			// the options
327*cdf0e10cSrcweir 	::std::vector< ::rtl::OUString >	m_aModulesList;	// list of all installed modules
328*cdf0e10cSrcweir 	void					Load();
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir public:
331*cdf0e10cSrcweir     SfxHelp_Impl( sal_Bool bDebug );
332*cdf0e10cSrcweir     ~SfxHelp_Impl();
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir     SfxHelpOptions_Impl*	GetOptions();
335*cdf0e10cSrcweir     static String           GetHelpText( const rtl::OUString& aCommandURL, const String& rModule );
336*cdf0e10cSrcweir 	sal_Bool				HasModule( const ::rtl::OUString& rModule );			// module installed
337*cdf0e10cSrcweir 	sal_Bool				IsHelpInstalled();										// module list not empty
338*cdf0e10cSrcweir };
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir SfxHelp_Impl::SfxHelp_Impl( sal_Bool bDebug ) :
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 	m_bIsDebug		( bDebug ),
343*cdf0e10cSrcweir     m_pOpt      	( NULL )
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir {
346*cdf0e10cSrcweir }
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir SfxHelp_Impl::~SfxHelp_Impl()
349*cdf0e10cSrcweir {
350*cdf0e10cSrcweir     delete m_pOpt;
351*cdf0e10cSrcweir }
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir void SfxHelp_Impl::Load()
354*cdf0e10cSrcweir {
355*cdf0e10cSrcweir 	// fill modules list
356*cdf0e10cSrcweir 	// create the help url (empty, without module and helpid)
357*cdf0e10cSrcweir 	String sHelpURL( DEFINE_CONST_UNICODE("vnd.sun.star.help://") );
358*cdf0e10cSrcweir 	AppendConfigToken_Impl( sHelpURL, sal_True );
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 	// open ucb content and get the list of the help modules
361*cdf0e10cSrcweir 	// the list contains strings with three tokens "ui title \t type \t url"
362*cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aAllModulesList = SfxContentHelper::GetResultSet( sHelpURL );
363*cdf0e10cSrcweir 	sal_Int32 nLen = aAllModulesList.getLength();
364*cdf0e10cSrcweir 	m_aModulesList.reserve( nLen + 1 );
365*cdf0e10cSrcweir 	const ::rtl::OUString* pBegin = aAllModulesList.getConstArray();
366*cdf0e10cSrcweir 	const ::rtl::OUString* pEnd	= pBegin + nLen;
367*cdf0e10cSrcweir 	for ( ; pBegin != pEnd; ++pBegin )
368*cdf0e10cSrcweir 	{
369*cdf0e10cSrcweir 		// get one module string
370*cdf0e10cSrcweir 		String sModule( *pBegin );
371*cdf0e10cSrcweir 		// extract the url
372*cdf0e10cSrcweir 		String sURL = sModule.GetToken( 2, '\t' );
373*cdf0e10cSrcweir 		// insert the module (the host part of the "vnd.sun.star.help" url)
374*cdf0e10cSrcweir 		m_aModulesList.push_back( ::rtl::OUString( INetURLObject( sURL ).GetHost() ) );
375*cdf0e10cSrcweir 	}
376*cdf0e10cSrcweir }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir String SfxHelp_Impl::GetHelpText( const rtl::OUString& aCommandURL, const String& rModule )
379*cdf0e10cSrcweir {
380*cdf0e10cSrcweir 	// create help url
381*cdf0e10cSrcweir     String aHelpURL = SfxHelp::CreateHelpURL( aCommandURL, rModule );
382*cdf0e10cSrcweir 	// added 'active' parameter
383*cdf0e10cSrcweir 	aHelpURL.Insert( String( DEFINE_CONST_UNICODE("&Active=true") ), aHelpURL.SearchBackward( '#' ) );
384*cdf0e10cSrcweir 	// load help string
385*cdf0e10cSrcweir 	return SfxContentHelper::GetActiveHelpString( aHelpURL );
386*cdf0e10cSrcweir }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir SfxHelpOptions_Impl* SfxHelp_Impl::GetOptions()
389*cdf0e10cSrcweir {
390*cdf0e10cSrcweir 	// create if not exists
391*cdf0e10cSrcweir     if ( !m_pOpt )
392*cdf0e10cSrcweir         m_pOpt = new SfxHelpOptions_Impl;
393*cdf0e10cSrcweir     return m_pOpt;
394*cdf0e10cSrcweir }
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir sal_Bool SfxHelp_Impl::HasModule( const ::rtl::OUString& rModule )
397*cdf0e10cSrcweir {
398*cdf0e10cSrcweir 	if ( !m_aModulesList.size() )
399*cdf0e10cSrcweir 		Load();
400*cdf0e10cSrcweir 	return ( ::std::find( m_aModulesList.begin(), m_aModulesList.end(), rModule ) != m_aModulesList.end() );
401*cdf0e10cSrcweir }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir sal_Bool SfxHelp_Impl::IsHelpInstalled()
404*cdf0e10cSrcweir {
405*cdf0e10cSrcweir 	if ( !m_aModulesList.size() )
406*cdf0e10cSrcweir 		Load();
407*cdf0e10cSrcweir 	return ( m_aModulesList.begin() != m_aModulesList.end() );
408*cdf0e10cSrcweir }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir // class SfxHelp ---------------------------------------------------------
411*cdf0e10cSrcweir /* some test code for HID conversion - please don't remove
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir #include <tools/stream.hxx>
414*cdf0e10cSrcweir void TestHids()
415*cdf0e10cSrcweir {
416*cdf0e10cSrcweir     static const char* aModules[] =
417*cdf0e10cSrcweir     {
418*cdf0e10cSrcweir         "swriter",
419*cdf0e10cSrcweir         "scalc",
420*cdf0e10cSrcweir         "simpress",
421*cdf0e10cSrcweir         "sdraw",
422*cdf0e10cSrcweir         "sdatabase",
423*cdf0e10cSrcweir         "smath",
424*cdf0e10cSrcweir         "schart",
425*cdf0e10cSrcweir         "sbasic"
426*cdf0e10cSrcweir     };
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir     SvFileStream* pOut[] =
429*cdf0e10cSrcweir     {
430*cdf0e10cSrcweir         0,0,0,0,0,0,0,0,0
431*cdf0e10cSrcweir     };
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir     String aIn = String::CreateFromAscii("/data/OOo/replacer/hidsin.lst");
434*cdf0e10cSrcweir     String aOut = String::CreateFromAscii("/data/OOo/replacer/");
435*cdf0e10cSrcweir     SvFileStream aInStrm( aIn, STREAM_READ );
436*cdf0e10cSrcweir     ByteString aBuffer;
437*cdf0e10cSrcweir     while ( aInStrm.ReadLine( aBuffer ) )
438*cdf0e10cSrcweir     {
439*cdf0e10cSrcweir         ByteString aHid = aBuffer.GetToken(0, ' ');
440*cdf0e10cSrcweir         ByteString aNr  = aBuffer.GetToken(1, ' ');
441*cdf0e10cSrcweir         bool bFound=false;
442*cdf0e10cSrcweir         for (sal_Int32 n= 0; n<8; n++)
443*cdf0e10cSrcweir         {
444*cdf0e10cSrcweir             bFound = false;
445*cdf0e10cSrcweir 	        String aHelpURL = SfxHelp::CreateHelpURL( String( aNr, RTL_TEXTENCODING_UTF8 ), String( aModules[n], RTL_TEXTENCODING_UTF8 ) );
446*cdf0e10cSrcweir             if ( !SfxContentHelper::IsHelpErrorDocument( aHelpURL ) )
447*cdf0e10cSrcweir             {
448*cdf0e10cSrcweir                 if (!pOut[n])
449*cdf0e10cSrcweir                 {
450*cdf0e10cSrcweir                     String aTmp( aOut );
451*cdf0e10cSrcweir                     aTmp += String( aModules[n], RTL_TEXTENCODING_UTF8 );
452*cdf0e10cSrcweir                     aTmp += String::CreateFromAscii(".lst");
453*cdf0e10cSrcweir                     pOut[n] = new SvFileStream( aTmp, STREAM_WRITE | STREAM_TRUNC );
454*cdf0e10cSrcweir                 }
455*cdf0e10cSrcweir                 pOut[n]->WriteLine( aHid );
456*cdf0e10cSrcweir                 bFound = true;
457*cdf0e10cSrcweir                 break;
458*cdf0e10cSrcweir             }
459*cdf0e10cSrcweir         }
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir         if (!bFound)
462*cdf0e10cSrcweir         {
463*cdf0e10cSrcweir             if (!pOut[8])
464*cdf0e10cSrcweir             {
465*cdf0e10cSrcweir                 String aTmp( aOut );
466*cdf0e10cSrcweir                 aTmp += String( "notfound", RTL_TEXTENCODING_UTF8 );
467*cdf0e10cSrcweir                 aTmp += String::CreateFromAscii(".lst");
468*cdf0e10cSrcweir                 pOut[8] = new SvFileStream( aTmp, STREAM_WRITE | STREAM_TRUNC );
469*cdf0e10cSrcweir             }
470*cdf0e10cSrcweir             pOut[8]->WriteLine( aHid );
471*cdf0e10cSrcweir         }
472*cdf0e10cSrcweir     }
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir     for (sal_Int32 n= 0; n<9; n++)
475*cdf0e10cSrcweir         DELETEZ( pOut[n] );
476*cdf0e10cSrcweir }
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir void TestHids2()
479*cdf0e10cSrcweir {
480*cdf0e10cSrcweir     static const char* aModules[] =
481*cdf0e10cSrcweir     {
482*cdf0e10cSrcweir         "swriter",
483*cdf0e10cSrcweir         "scalc",
484*cdf0e10cSrcweir         "simpress",
485*cdf0e10cSrcweir         "smath",
486*cdf0e10cSrcweir         "sbasic"
487*cdf0e10cSrcweir     };
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir     String aOut = String::CreateFromAscii("/data/OOo/replacer/");
490*cdf0e10cSrcweir     aOut += String::CreateFromAscii("lost.lst");
491*cdf0e10cSrcweir     SvFileStream aOutStrm( aOut, STREAM_WRITE | STREAM_TRUNC );
492*cdf0e10cSrcweir     for (sal_Int32 n= 0; n<5; n++)
493*cdf0e10cSrcweir     {
494*cdf0e10cSrcweir         String aIn = String::CreateFromAscii("/data/OOo/replacer/help/");
495*cdf0e10cSrcweir         aIn += String::CreateFromAscii( aModules[n] );
496*cdf0e10cSrcweir         aIn += String::CreateFromAscii(".lst");
497*cdf0e10cSrcweir         SvFileStream aInStrm( aIn, STREAM_READ );
498*cdf0e10cSrcweir         ByteString aBuffer;
499*cdf0e10cSrcweir         while ( aInStrm.ReadLine( aBuffer ) )
500*cdf0e10cSrcweir         {
501*cdf0e10cSrcweir             String aHelpURL = SfxHelp::CreateHelpURL( String( aBuffer, RTL_TEXTENCODING_UTF8 ), String( aModules[n], RTL_TEXTENCODING_UTF8 ) );
502*cdf0e10cSrcweir             if ( SfxContentHelper::IsHelpErrorDocument( aHelpURL ) )
503*cdf0e10cSrcweir                 aOutStrm.WriteLine( aBuffer );
504*cdf0e10cSrcweir         }
505*cdf0e10cSrcweir     }
506*cdf0e10cSrcweir }
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir #include <tools/stream.hxx>
509*cdf0e10cSrcweir void TestHids3()
510*cdf0e10cSrcweir {
511*cdf0e10cSrcweir     static const char* aModules[] =
512*cdf0e10cSrcweir     {
513*cdf0e10cSrcweir         "swriter",
514*cdf0e10cSrcweir         "scalc",
515*cdf0e10cSrcweir         "simpress",
516*cdf0e10cSrcweir         "sdraw",
517*cdf0e10cSrcweir         "sdatabase",
518*cdf0e10cSrcweir         "smath",
519*cdf0e10cSrcweir         "schart",
520*cdf0e10cSrcweir         "sbasic"
521*cdf0e10cSrcweir     };
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir     SvFileStream* pOut[] =
524*cdf0e10cSrcweir     {
525*cdf0e10cSrcweir         0,0,0,0,0,0,0,0,0
526*cdf0e10cSrcweir     };
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir     String aIn = String::CreateFromAscii("/data/OOo/replacer/hidsin.lst");
529*cdf0e10cSrcweir     String aOut = String::CreateFromAscii("/data/OOo/replacer/quickhelp/");
530*cdf0e10cSrcweir     SvFileStream aInStrm( aIn, STREAM_READ );
531*cdf0e10cSrcweir     ByteString aBuffer;
532*cdf0e10cSrcweir     while ( aInStrm.ReadLine( aBuffer ) )
533*cdf0e10cSrcweir     {
534*cdf0e10cSrcweir         ByteString aHid = aBuffer.GetToken(0, ' ');
535*cdf0e10cSrcweir         ByteString aNr  = aBuffer.GetToken(1, ' ');
536*cdf0e10cSrcweir         bool bFound=false;
537*cdf0e10cSrcweir         for (sal_Int32 n= 0; n<8; n++)
538*cdf0e10cSrcweir         {
539*cdf0e10cSrcweir             bFound = false;
540*cdf0e10cSrcweir             String aHelpURL = SfxHelp::CreateHelpURL( String( aNr, RTL_TEXTENCODING_UTF8 ), String( aModules[n], RTL_TEXTENCODING_UTF8 ) );
541*cdf0e10cSrcweir 	        if ( SfxContentHelper::GetActiveHelpString( aHelpURL ).Len() )
542*cdf0e10cSrcweir //            if ( SfxHelp_Impl::GetHelpText( String( aNr, RTL_TEXTENCODING_UTF8 ), String( aModules[n], RTL_TEXTENCODING_UTF8 ) ).Len() )
543*cdf0e10cSrcweir             {
544*cdf0e10cSrcweir                 if (!pOut[n])
545*cdf0e10cSrcweir                 {
546*cdf0e10cSrcweir                     String aTmp( aOut );
547*cdf0e10cSrcweir                     aTmp += String( aModules[n], RTL_TEXTENCODING_UTF8 );
548*cdf0e10cSrcweir                     aTmp += String::CreateFromAscii(".lst");
549*cdf0e10cSrcweir                     pOut[n] = new SvFileStream( aTmp, STREAM_WRITE | STREAM_TRUNC );
550*cdf0e10cSrcweir                 }
551*cdf0e10cSrcweir                 pOut[n]->WriteLine( aHid );
552*cdf0e10cSrcweir                 bFound = true;
553*cdf0e10cSrcweir                 break;
554*cdf0e10cSrcweir             }
555*cdf0e10cSrcweir         }
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir         if (!bFound)
558*cdf0e10cSrcweir         {
559*cdf0e10cSrcweir             if (!pOut[8])
560*cdf0e10cSrcweir             {
561*cdf0e10cSrcweir                 String aTmp( aOut );
562*cdf0e10cSrcweir                 aTmp += String( "notfound", RTL_TEXTENCODING_UTF8 );
563*cdf0e10cSrcweir                 aTmp += String::CreateFromAscii(".lst");
564*cdf0e10cSrcweir                 pOut[8] = new SvFileStream( aTmp, STREAM_WRITE | STREAM_TRUNC );
565*cdf0e10cSrcweir             }
566*cdf0e10cSrcweir             pOut[8]->WriteLine( aHid );
567*cdf0e10cSrcweir         }
568*cdf0e10cSrcweir     }
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir     for (sal_Int32 n= 0; n<9; n++)
571*cdf0e10cSrcweir         DELETEZ( pOut[n] );
572*cdf0e10cSrcweir }
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir void TestHids4()
575*cdf0e10cSrcweir {
576*cdf0e10cSrcweir     static const char* aModules[] =
577*cdf0e10cSrcweir     {
578*cdf0e10cSrcweir         "swriter",
579*cdf0e10cSrcweir         "scalc",
580*cdf0e10cSrcweir         "simpress",
581*cdf0e10cSrcweir         "smath",
582*cdf0e10cSrcweir         "sbasic"
583*cdf0e10cSrcweir     };
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir     String aOut = String::CreateFromAscii("/data/OOo/replacer/quickhelp/");
586*cdf0e10cSrcweir     aOut += String::CreateFromAscii("lost.lst");
587*cdf0e10cSrcweir     SvFileStream aOutStrm( aOut, STREAM_WRITE | STREAM_TRUNC );
588*cdf0e10cSrcweir     for (sal_Int32 n= 0; n<5; n++)
589*cdf0e10cSrcweir     {
590*cdf0e10cSrcweir         String aIn = String::CreateFromAscii("/data/OOo/replacer/quickhelp/");
591*cdf0e10cSrcweir         aIn += String::CreateFromAscii( aModules[n] );
592*cdf0e10cSrcweir         aIn += String::CreateFromAscii(".lst");
593*cdf0e10cSrcweir         SvFileStream aInStrm( aIn, STREAM_READ );
594*cdf0e10cSrcweir         ByteString aBuffer;
595*cdf0e10cSrcweir         while ( aInStrm.ReadLine( aBuffer ) )
596*cdf0e10cSrcweir         {
597*cdf0e10cSrcweir             String aHelpURL = SfxHelp::CreateHelpURL( String( aBuffer, RTL_TEXTENCODING_UTF8 ), String( aModules[n], RTL_TEXTENCODING_UTF8 ) );
598*cdf0e10cSrcweir 	        if ( !SfxContentHelper::GetActiveHelpString( aHelpURL ).Len() )
599*cdf0e10cSrcweir                 aOutStrm.WriteLine( aBuffer );
600*cdf0e10cSrcweir         }
601*cdf0e10cSrcweir     }
602*cdf0e10cSrcweir }
603*cdf0e10cSrcweir */
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir SfxHelp::SfxHelp() :
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir 	bIsDebug( sal_False ),
608*cdf0e10cSrcweir     pImp	( NULL )
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir {
611*cdf0e10cSrcweir 	// read the environment variable "HELP_DEBUG"
612*cdf0e10cSrcweir 	// if it's set, you will see debug output on active help
613*cdf0e10cSrcweir 	{
614*cdf0e10cSrcweir 		::rtl::OUString sHelpDebug;
615*cdf0e10cSrcweir 		::rtl::OUString sEnvVarName( RTL_CONSTASCII_USTRINGPARAM( "HELP_DEBUG" ) );
616*cdf0e10cSrcweir 		osl_getEnvironment( sEnvVarName.pData, &sHelpDebug.pData );
617*cdf0e10cSrcweir 		bIsDebug = ( 0 != sHelpDebug.getLength() );
618*cdf0e10cSrcweir 	}
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir 	pImp = new SfxHelp_Impl( bIsDebug );
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir     ::rtl::OUString aLocaleStr = HelpLocaleString();
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir     sal_Int32 nSepPos = aLocaleStr.indexOf( '_' );
625*cdf0e10cSrcweir     if ( nSepPos != -1 )
626*cdf0e10cSrcweir     {
627*cdf0e10cSrcweir         aLanguageStr = aLocaleStr.copy( 0, nSepPos );
628*cdf0e10cSrcweir         aCountryStr = aLocaleStr.copy( nSepPos+1 );
629*cdf0e10cSrcweir     }
630*cdf0e10cSrcweir     else
631*cdf0e10cSrcweir     {
632*cdf0e10cSrcweir         nSepPos = aLocaleStr.indexOf( '-' );
633*cdf0e10cSrcweir         if ( nSepPos != -1 )
634*cdf0e10cSrcweir         {
635*cdf0e10cSrcweir             aLanguageStr = aLocaleStr.copy( 0, nSepPos );
636*cdf0e10cSrcweir             aCountryStr = aLocaleStr.copy( nSepPos+1 );
637*cdf0e10cSrcweir         }
638*cdf0e10cSrcweir         else
639*cdf0e10cSrcweir         {
640*cdf0e10cSrcweir             aLanguageStr = aLocaleStr;
641*cdf0e10cSrcweir         }
642*cdf0e10cSrcweir     }
643*cdf0e10cSrcweir }
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir SfxHelp::~SfxHelp()
646*cdf0e10cSrcweir {
647*cdf0e10cSrcweir     delete pImp;
648*cdf0e10cSrcweir }
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir ::rtl::OUString getDefaultModule_Impl()
651*cdf0e10cSrcweir {
652*cdf0e10cSrcweir     rtl::OUString sDefaultModule;
653*cdf0e10cSrcweir     SvtModuleOptions aModOpt;
654*cdf0e10cSrcweir     if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
655*cdf0e10cSrcweir         sDefaultModule = DEFINE_CONST_UNICODE("swriter");
656*cdf0e10cSrcweir     else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
657*cdf0e10cSrcweir         sDefaultModule = DEFINE_CONST_UNICODE("scalc");
658*cdf0e10cSrcweir     else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
659*cdf0e10cSrcweir         sDefaultModule = DEFINE_CONST_UNICODE("simpress");
660*cdf0e10cSrcweir     else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
661*cdf0e10cSrcweir         sDefaultModule = DEFINE_CONST_UNICODE("sdraw");
662*cdf0e10cSrcweir     else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
663*cdf0e10cSrcweir         sDefaultModule = DEFINE_CONST_UNICODE("smath");
664*cdf0e10cSrcweir     else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SCHART ) )
665*cdf0e10cSrcweir         sDefaultModule = DEFINE_CONST_UNICODE("schart");
666*cdf0e10cSrcweir     else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SBASIC ) )
667*cdf0e10cSrcweir         sDefaultModule = DEFINE_CONST_UNICODE("sbasic");
668*cdf0e10cSrcweir     else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
669*cdf0e10cSrcweir         sDefaultModule = DEFINE_CONST_UNICODE("sdatabase");
670*cdf0e10cSrcweir     else
671*cdf0e10cSrcweir     {
672*cdf0e10cSrcweir         DBG_ERRORFILE( "getDefaultModule_Impl(): no module installed" );
673*cdf0e10cSrcweir     }
674*cdf0e10cSrcweir     return sDefaultModule;
675*cdf0e10cSrcweir }
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir ::rtl::OUString getCurrentModuleIdentifier_Impl()
678*cdf0e10cSrcweir {
679*cdf0e10cSrcweir     ::rtl::OUString sIdentifier;
680*cdf0e10cSrcweir     Reference < XFrame > xCurrentFrame;
681*cdf0e10cSrcweir     Reference < XModuleManager > xModuleManager( ::comphelper::getProcessServiceFactory()->createInstance(
682*cdf0e10cSrcweir         DEFINE_CONST_UNICODE("com.sun.star.frame.ModuleManager") ), UNO_QUERY );
683*cdf0e10cSrcweir     Reference < XDesktop > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
684*cdf0e10cSrcweir         DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
685*cdf0e10cSrcweir     if ( xDesktop.is() )
686*cdf0e10cSrcweir         xCurrentFrame = xDesktop->getCurrentFrame();
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir     if ( xCurrentFrame.is() && xModuleManager.is() )
689*cdf0e10cSrcweir     {
690*cdf0e10cSrcweir         try
691*cdf0e10cSrcweir         {
692*cdf0e10cSrcweir             sIdentifier = xModuleManager->identify( xCurrentFrame );
693*cdf0e10cSrcweir         }
694*cdf0e10cSrcweir         catch ( ::com::sun::star::frame::UnknownModuleException& )
695*cdf0e10cSrcweir         {
696*cdf0e10cSrcweir             DBG_WARNING( "SfxHelp::getCurrentModuleIdentifier_Impl(): unknown module (help in help?)" );
697*cdf0e10cSrcweir         }
698*cdf0e10cSrcweir         catch ( Exception& )
699*cdf0e10cSrcweir         {
700*cdf0e10cSrcweir             DBG_ERRORFILE( "SfxHelp::getCurrentModuleIdentifier_Impl(): exception of XModuleManager::identify()" );
701*cdf0e10cSrcweir         }
702*cdf0e10cSrcweir     }
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir     return sIdentifier;
705*cdf0e10cSrcweir }
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir String SfxHelp::GetHelpModuleName_Impl()
708*cdf0e10cSrcweir {
709*cdf0e10cSrcweir     String sModuleName;
710*cdf0e10cSrcweir     rtl::OUString aFactoryShortName;
711*cdf0e10cSrcweir     rtl::OUString aModuleIdentifier = getCurrentModuleIdentifier_Impl();
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir     if ( aModuleIdentifier.getLength() > 0 )
714*cdf0e10cSrcweir     {
715*cdf0e10cSrcweir         try
716*cdf0e10cSrcweir         {
717*cdf0e10cSrcweir             Reference < XModuleManager > xModuleManager(
718*cdf0e10cSrcweir                 ::comphelper::getProcessServiceFactory()->createInstance(
719*cdf0e10cSrcweir                     DEFINE_CONST_UNICODE("com.sun.star.frame.ModuleManager") ), UNO_QUERY );
720*cdf0e10cSrcweir             Sequence< PropertyValue > lProps;
721*cdf0e10cSrcweir             Reference< ::com::sun::star::container::XNameAccess > xCont( xModuleManager, UNO_QUERY);
722*cdf0e10cSrcweir             if ( xCont.is() )
723*cdf0e10cSrcweir                 xCont->getByName( aModuleIdentifier ) >>= lProps;
724*cdf0e10cSrcweir             for ( sal_Int32 i = 0; i < lProps.getLength(); ++i )
725*cdf0e10cSrcweir             {
726*cdf0e10cSrcweir                 if ( lProps[i].Name.equalsAscii("ooSetupFactoryShortName") )
727*cdf0e10cSrcweir                 {
728*cdf0e10cSrcweir                     lProps[i].Value >>= aFactoryShortName;
729*cdf0e10cSrcweir                     break;
730*cdf0e10cSrcweir                 }
731*cdf0e10cSrcweir             }
732*cdf0e10cSrcweir         }
733*cdf0e10cSrcweir         catch ( Exception& )
734*cdf0e10cSrcweir         {
735*cdf0e10cSrcweir             DBG_ERRORFILE( "SfxHelp::GetHelpModuleName_Impl(): exception of XNameAccess::getByName()" );
736*cdf0e10cSrcweir         }
737*cdf0e10cSrcweir     }
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir     rtl::OUString sDefaultModule = getDefaultModule_Impl();
740*cdf0e10cSrcweir     if ( aFactoryShortName.getLength() > 0 )
741*cdf0e10cSrcweir     {
742*cdf0e10cSrcweir         // Map some module identifiers to their "real" help module string.
743*cdf0e10cSrcweir         if ( aFactoryShortName.equalsAscii( "chart2" ) )
744*cdf0e10cSrcweir             aFactoryShortName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "schart" ) );
745*cdf0e10cSrcweir         else if ( aFactoryShortName.equalsAscii( "BasicIDE" ) )
746*cdf0e10cSrcweir             aFactoryShortName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "sbasic" ) );
747*cdf0e10cSrcweir         else if ( aFactoryShortName.equalsAscii( "sweb" )
748*cdf0e10cSrcweir                 || aFactoryShortName.equalsAscii( "sglobal" )
749*cdf0e10cSrcweir                 || aFactoryShortName.equalsAscii( "swxform" ) )
750*cdf0e10cSrcweir             aFactoryShortName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "swriter" ) );
751*cdf0e10cSrcweir         else if ( aFactoryShortName.equalsAscii( "dbquery" )
752*cdf0e10cSrcweir                 || aFactoryShortName.equalsAscii( "dbbrowser" )
753*cdf0e10cSrcweir                 || aFactoryShortName.equalsAscii( "dbrelation" )
754*cdf0e10cSrcweir                 || aFactoryShortName.equalsAscii( "dbtable" )
755*cdf0e10cSrcweir                 || aFactoryShortName.equalsAscii( "dbapp" )
756*cdf0e10cSrcweir                 || aFactoryShortName.equalsAscii( "dbreport" )
757*cdf0e10cSrcweir                 || aFactoryShortName.equalsAscii( "swreport" )
758*cdf0e10cSrcweir                 || aFactoryShortName.equalsAscii( "dbbrowser" )
759*cdf0e10cSrcweir                 || aFactoryShortName.equalsAscii( "swform" ) )
760*cdf0e10cSrcweir             aFactoryShortName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "sdatabase" ) );
761*cdf0e10cSrcweir         else if ( aFactoryShortName.equalsAscii( "sbibliography" )
762*cdf0e10cSrcweir                 || aFactoryShortName.equalsAscii( "StartModule" ) )
763*cdf0e10cSrcweir             aFactoryShortName = sDefaultModule;
764*cdf0e10cSrcweir     }
765*cdf0e10cSrcweir     else
766*cdf0e10cSrcweir         aFactoryShortName = sDefaultModule;
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir     sModuleName = String( aFactoryShortName );
769*cdf0e10cSrcweir     return sModuleName;
770*cdf0e10cSrcweir }
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir String	SfxHelp::CreateHelpURL_Impl( const String& aCommandURL, const String& rModuleName )
773*cdf0e10cSrcweir {
774*cdf0e10cSrcweir 	// build up the help URL
775*cdf0e10cSrcweir     String aHelpURL;
776*cdf0e10cSrcweir 	sal_Bool bHasAnchor = sal_False;
777*cdf0e10cSrcweir 	String aAnchor;
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir 	String aModuleName( rModuleName );
780*cdf0e10cSrcweir 	if ( aModuleName.Len() == 0 )
781*cdf0e10cSrcweir         aModuleName = getDefaultModule_Impl();
782*cdf0e10cSrcweir 
783*cdf0e10cSrcweir     aHelpURL = String::CreateFromAscii("vnd.sun.star.help://");
784*cdf0e10cSrcweir     aHelpURL += aModuleName;
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir     if ( !aCommandURL.Len() )
787*cdf0e10cSrcweir         aHelpURL += String::CreateFromAscii("/start");
788*cdf0e10cSrcweir     else
789*cdf0e10cSrcweir     {
790*cdf0e10cSrcweir         aHelpURL += '/';
791*cdf0e10cSrcweir         aHelpURL += String( rtl::Uri::encode( aCommandURL,
792*cdf0e10cSrcweir                                               rtl_UriCharClassRelSegment,
793*cdf0e10cSrcweir                                               rtl_UriEncodeKeepEscapes,
794*cdf0e10cSrcweir                                               RTL_TEXTENCODING_UTF8 ));
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir 		String aTempURL = aHelpURL;
797*cdf0e10cSrcweir 	    AppendConfigToken_Impl( aTempURL, sal_True );
798*cdf0e10cSrcweir 		bHasAnchor = GetHelpAnchor_Impl( aTempURL, aAnchor );
799*cdf0e10cSrcweir 	}
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir     AppendConfigToken_Impl( aHelpURL, sal_True );
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir 	if ( bHasAnchor )
804*cdf0e10cSrcweir 	{
805*cdf0e10cSrcweir 		aHelpURL += '#';
806*cdf0e10cSrcweir 		aHelpURL += aAnchor;
807*cdf0e10cSrcweir 	}
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir     return aHelpURL;
810*cdf0e10cSrcweir }
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir SfxHelpWindow_Impl* impl_createHelp(Reference< XFrame >& rHelpTask   ,
813*cdf0e10cSrcweir                                     Reference< XFrame >& rHelpContent)
814*cdf0e10cSrcweir {
815*cdf0e10cSrcweir     Reference < XFrame > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
816*cdf0e10cSrcweir 		DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir     // otherwhise - create new help task
819*cdf0e10cSrcweir     Reference< XFrame > xHelpTask = xDesktop->findFrame(
820*cdf0e10cSrcweir         ::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP_TASK")),
821*cdf0e10cSrcweir         FrameSearchFlag::TASKS | FrameSearchFlag::CREATE);
822*cdf0e10cSrcweir     if (!xHelpTask.is())
823*cdf0e10cSrcweir         return 0;
824*cdf0e10cSrcweir 
825*cdf0e10cSrcweir     // create all internal windows and sub frames ...
826*cdf0e10cSrcweir     Reference< ::com::sun::star::awt::XWindow > xParentWindow = xHelpTask->getContainerWindow();
827*cdf0e10cSrcweir     Window*                                     pParentWindow = VCLUnoHelper::GetWindow( xParentWindow );
828*cdf0e10cSrcweir     SfxHelpWindow_Impl*                         pHelpWindow   = new SfxHelpWindow_Impl( xHelpTask, pParentWindow, WB_DOCKBORDER );
829*cdf0e10cSrcweir     Reference< ::com::sun::star::awt::XWindow > xHelpWindow   = VCLUnoHelper::GetInterface( pHelpWindow );
830*cdf0e10cSrcweir 
831*cdf0e10cSrcweir     Reference< XFrame > xHelpContent;
832*cdf0e10cSrcweir     if (xHelpTask->setComponent( xHelpWindow, Reference< XController >() ))
833*cdf0e10cSrcweir     {
834*cdf0e10cSrcweir         // Customize UI ...
835*cdf0e10cSrcweir         xHelpTask->setName( ::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP_TASK")) );
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir         Reference< XPropertySet > xProps(xHelpTask, UNO_QUERY);
838*cdf0e10cSrcweir         if (xProps.is())
839*cdf0e10cSrcweir             xProps->setPropertyValue(
840*cdf0e10cSrcweir                 DEFINE_CONST_UNICODE("Title"),
841*cdf0e10cSrcweir                 makeAny(::rtl::OUString(String(SfxResId(STR_HELP_WINDOW_TITLE)))));
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir         pHelpWindow->setContainerWindow( xParentWindow );
844*cdf0e10cSrcweir         xParentWindow->setVisible(sal_True);
845*cdf0e10cSrcweir         xHelpWindow->setVisible(sal_True);
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir         // This sub frame is created internaly (if we called new SfxHelpWindow_Impl() ...)
848*cdf0e10cSrcweir         // It should exist :-)
849*cdf0e10cSrcweir         xHelpContent = xHelpTask->findFrame(::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP")), FrameSearchFlag::CHILDREN);
850*cdf0e10cSrcweir     }
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir     if (!xHelpContent.is())
853*cdf0e10cSrcweir         delete pHelpWindow;
854*cdf0e10cSrcweir 
855*cdf0e10cSrcweir     xHelpContent->setName(::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP")));
856*cdf0e10cSrcweir 
857*cdf0e10cSrcweir     rHelpTask    = xHelpTask;
858*cdf0e10cSrcweir     rHelpContent = xHelpContent;
859*cdf0e10cSrcweir     return pHelpWindow;
860*cdf0e10cSrcweir }
861*cdf0e10cSrcweir 
862*cdf0e10cSrcweir XubString SfxHelp::GetHelpText( const String& aCommandURL, const Window* pWindow )
863*cdf0e10cSrcweir {
864*cdf0e10cSrcweir     String sModuleName = GetHelpModuleName_Impl();
865*cdf0e10cSrcweir     String sHelpText = pImp->GetHelpText( aCommandURL, sModuleName );
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir 	ByteString aNewHelpId;
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir 	if ( pWindow && !sHelpText.Len() )
870*cdf0e10cSrcweir 	{
871*cdf0e10cSrcweir 		// no help text found -> try with parent help id.
872*cdf0e10cSrcweir 		Window* pParent = pWindow->GetParent();
873*cdf0e10cSrcweir 		while ( pParent )
874*cdf0e10cSrcweir 		{
875*cdf0e10cSrcweir 			aNewHelpId = pParent->GetHelpId();
876*cdf0e10cSrcweir 			sHelpText = pImp->GetHelpText( String( aNewHelpId, RTL_TEXTENCODING_UTF8 ), sModuleName );
877*cdf0e10cSrcweir 			if ( sHelpText.Len() > 0 )
878*cdf0e10cSrcweir 				pParent = NULL;
879*cdf0e10cSrcweir 			else
880*cdf0e10cSrcweir 				pParent = pParent->GetParent();
881*cdf0e10cSrcweir 		}
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir 		if ( bIsDebug && !sHelpText.Len() )
884*cdf0e10cSrcweir 			aNewHelpId.Erase();
885*cdf0e10cSrcweir 	}
886*cdf0e10cSrcweir 
887*cdf0e10cSrcweir     // add some debug information?
888*cdf0e10cSrcweir     if ( bIsDebug )
889*cdf0e10cSrcweir     {
890*cdf0e10cSrcweir         sHelpText += DEFINE_CONST_UNICODE("\n-------------\n");
891*cdf0e10cSrcweir         sHelpText += String( sModuleName );
892*cdf0e10cSrcweir         sHelpText += DEFINE_CONST_UNICODE(": ");
893*cdf0e10cSrcweir         sHelpText += aCommandURL;
894*cdf0e10cSrcweir 		if ( aNewHelpId.Len() )
895*cdf0e10cSrcweir 		{
896*cdf0e10cSrcweir 			sHelpText += DEFINE_CONST_UNICODE(" - ");
897*cdf0e10cSrcweir 			sHelpText += String( aNewHelpId, RTL_TEXTENCODING_UTF8 );
898*cdf0e10cSrcweir 		}
899*cdf0e10cSrcweir     }
900*cdf0e10cSrcweir 
901*cdf0e10cSrcweir     return sHelpText;
902*cdf0e10cSrcweir }
903*cdf0e10cSrcweir 
904*cdf0e10cSrcweir sal_Bool SfxHelp::SearchKeyword( const XubString& rKeyword )
905*cdf0e10cSrcweir {
906*cdf0e10cSrcweir 	return Start_Impl( String(), NULL, rKeyword );
907*cdf0e10cSrcweir }
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir sal_Bool SfxHelp::Start( const String& rURL, const Window* pWindow )
910*cdf0e10cSrcweir {
911*cdf0e10cSrcweir     return Start_Impl( rURL, pWindow, String() );
912*cdf0e10cSrcweir }
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir sal_Bool SfxHelp::Start_Impl( const String& rURL, const Window* pWindow, const String& rKeyword )
915*cdf0e10cSrcweir {
916*cdf0e10cSrcweir     // check if help is available
917*cdf0e10cSrcweir     String aHelpRootURL( DEFINE_CONST_OUSTRING("vnd.sun.star.help://") );
918*cdf0e10cSrcweir     AppendConfigToken_Impl( aHelpRootURL, sal_True );
919*cdf0e10cSrcweir     Sequence< ::rtl::OUString > aFactories = SfxContentHelper::GetResultSet( aHelpRootURL );
920*cdf0e10cSrcweir     if ( 0 == aFactories.getLength() )
921*cdf0e10cSrcweir     {
922*cdf0e10cSrcweir         // no factories -> no help -> error message and return
923*cdf0e10cSrcweir         NoHelpErrorBox aErrBox( const_cast< Window* >( pWindow ) );
924*cdf0e10cSrcweir         aErrBox.Execute();
925*cdf0e10cSrcweir         return sal_False;
926*cdf0e10cSrcweir     }
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir 	/* rURL may be
929*cdf0e10cSrcweir 		- a "real" URL
930*cdf0e10cSrcweir 		- a HelpID (formerly a long, now a string)
931*cdf0e10cSrcweir 	   If rURL is a URL, CreateHelpURL should be called for this URL
932*cdf0e10cSrcweir 	   If rURL is an arbitrary string, the same should happen, but the URL should be tried out
933*cdf0e10cSrcweir 	   if it delivers real help content. In case only the Help Error Document is returned, the
934*cdf0e10cSrcweir 	   parent of the window for that help was called, is asked for its HelpID.
935*cdf0e10cSrcweir 	   For compatibility reasons this upward search is not implemented for "real" URLs.
936*cdf0e10cSrcweir 	   Help keyword search now is implemented as own method; in former versions it
937*cdf0e10cSrcweir 	   was done via Help::Start, but this implementation conflicted with the upward search.
938*cdf0e10cSrcweir 	*/
939*cdf0e10cSrcweir 	String aHelpURL;
940*cdf0e10cSrcweir 	INetURLObject aParser( rURL );
941*cdf0e10cSrcweir     INetProtocol nProtocol = aParser.GetProtocol();
942*cdf0e10cSrcweir 	String aHelpModuleName( GetHelpModuleName_Impl() );
943*cdf0e10cSrcweir 	switch ( nProtocol )
944*cdf0e10cSrcweir 	{
945*cdf0e10cSrcweir 		case INET_PROT_VND_SUN_STAR_HELP:
946*cdf0e10cSrcweir 			// already a vnd.sun.star.help URL -> nothing to do
947*cdf0e10cSrcweir 			aHelpURL = rURL;
948*cdf0e10cSrcweir 			break;
949*cdf0e10cSrcweir 		default:
950*cdf0e10cSrcweir 		{
951*cdf0e10cSrcweir 			// no URL, just a HelpID (maybe empty in case of keyword search)
952*cdf0e10cSrcweir 			aHelpURL  = CreateHelpURL_Impl( rURL, aHelpModuleName );
953*cdf0e10cSrcweir 			if ( pWindow && SfxContentHelper::IsHelpErrorDocument( aHelpURL ) )
954*cdf0e10cSrcweir 			{
955*cdf0e10cSrcweir 				// no help found -> try with parent help id.
956*cdf0e10cSrcweir 				Window* pParent = pWindow->GetParent();
957*cdf0e10cSrcweir 				while ( pParent )
958*cdf0e10cSrcweir 				{
959*cdf0e10cSrcweir 					ByteString aHelpId = pParent->GetHelpId();
960*cdf0e10cSrcweir 					aHelpURL = CreateHelpURL( String( aHelpId, RTL_TEXTENCODING_UTF8 ), aHelpModuleName );
961*cdf0e10cSrcweir 					if ( !SfxContentHelper::IsHelpErrorDocument( aHelpURL ) )
962*cdf0e10cSrcweir 						break;
963*cdf0e10cSrcweir 					else
964*cdf0e10cSrcweir 					{
965*cdf0e10cSrcweir 						pParent = pParent->GetParent();
966*cdf0e10cSrcweir 						if ( !pParent )
967*cdf0e10cSrcweir 							// create help url of start page ( helpid == 0 -> start page)
968*cdf0e10cSrcweir 							aHelpURL = CreateHelpURL( String(), aHelpModuleName );
969*cdf0e10cSrcweir 					}
970*cdf0e10cSrcweir 				}
971*cdf0e10cSrcweir 			}
972*cdf0e10cSrcweir 			break;
973*cdf0e10cSrcweir 		}
974*cdf0e10cSrcweir 	}
975*cdf0e10cSrcweir 
976*cdf0e10cSrcweir     Reference < XFrame > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
977*cdf0e10cSrcweir 		DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
978*cdf0e10cSrcweir 
979*cdf0e10cSrcweir     // check if help window is still open
980*cdf0e10cSrcweir     // If not, create a new one and return access directly to the internal sub frame showing the help content
981*cdf0e10cSrcweir 	// search must be done here; search one desktop level could return an arbitraty frame
982*cdf0e10cSrcweir     Reference< XFrame > xHelp = xDesktop->findFrame(
983*cdf0e10cSrcweir         ::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP_TASK")),
984*cdf0e10cSrcweir         FrameSearchFlag::CHILDREN);
985*cdf0e10cSrcweir     Reference< XFrame > xHelpContent = xDesktop->findFrame(
986*cdf0e10cSrcweir         ::rtl::OUString(DEFINE_CONST_UNICODE("OFFICE_HELP")),
987*cdf0e10cSrcweir         FrameSearchFlag::CHILDREN);
988*cdf0e10cSrcweir 
989*cdf0e10cSrcweir     SfxHelpWindow_Impl* pHelpWindow = 0;
990*cdf0e10cSrcweir     if (!xHelp.is())
991*cdf0e10cSrcweir         pHelpWindow = impl_createHelp(xHelp, xHelpContent);
992*cdf0e10cSrcweir     else
993*cdf0e10cSrcweir         pHelpWindow = (SfxHelpWindow_Impl*)VCLUnoHelper::GetWindow(xHelp->getComponentWindow());
994*cdf0e10cSrcweir     if (!xHelp.is() || !xHelpContent.is() || !pHelpWindow)
995*cdf0e10cSrcweir         return sal_False;
996*cdf0e10cSrcweir 
997*cdf0e10cSrcweir #ifdef DBG_UTIL
998*cdf0e10cSrcweir     ByteString aTmp("SfxHelp: HelpId = ");
999*cdf0e10cSrcweir     aTmp += ByteString( aHelpURL, RTL_TEXTENCODING_UTF8 );
1000*cdf0e10cSrcweir     DBG_TRACE( aTmp.GetBuffer() );
1001*cdf0e10cSrcweir #endif
1002*cdf0e10cSrcweir 
1003*cdf0e10cSrcweir     pHelpWindow->SetHelpURL( aHelpURL );
1004*cdf0e10cSrcweir     pHelpWindow->loadHelpContent(aHelpURL);
1005*cdf0e10cSrcweir     if ( rKeyword.Len() )
1006*cdf0e10cSrcweir 		pHelpWindow->OpenKeyword( rKeyword );
1007*cdf0e10cSrcweir 
1008*cdf0e10cSrcweir 	Reference < ::com::sun::star::awt::XTopWindow > xTopWindow( xHelp->getContainerWindow(), UNO_QUERY );
1009*cdf0e10cSrcweir     if ( xTopWindow.is() )
1010*cdf0e10cSrcweir         xTopWindow->toFront();
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir     return sal_True;
1013*cdf0e10cSrcweir }
1014*cdf0e10cSrcweir 
1015*cdf0e10cSrcweir String SfxHelp::CreateHelpURL( const String& aCommandURL, const String& rModuleName )
1016*cdf0e10cSrcweir {
1017*cdf0e10cSrcweir 	String aURL;
1018*cdf0e10cSrcweir 	SfxHelp* pHelp = SAL_STATIC_CAST( SfxHelp*, Application::GetHelp() );
1019*cdf0e10cSrcweir 	if ( pHelp )
1020*cdf0e10cSrcweir 		aURL = pHelp->CreateHelpURL_Impl( aCommandURL, rModuleName );
1021*cdf0e10cSrcweir 	return aURL;
1022*cdf0e10cSrcweir }
1023*cdf0e10cSrcweir 
1024*cdf0e10cSrcweir void SfxHelp::OpenHelpAgent( SfxFrame*, const rtl::OString& sHelpId )
1025*cdf0e10cSrcweir {
1026*cdf0e10cSrcweir 	SfxHelp* pHelp = SAL_STATIC_CAST( SfxHelp*, Application::GetHelp() );
1027*cdf0e10cSrcweir 	if ( pHelp )
1028*cdf0e10cSrcweir 		pHelp->OpenHelpAgent( sHelpId );
1029*cdf0e10cSrcweir }
1030*cdf0e10cSrcweir 
1031*cdf0e10cSrcweir void SfxHelp::OpenHelpAgent( const rtl::OString& sHelpId )
1032*cdf0e10cSrcweir {
1033*cdf0e10cSrcweir 	if ( SvtHelpOptions().IsHelpAgentAutoStartMode() )
1034*cdf0e10cSrcweir 	{
1035*cdf0e10cSrcweir 			SfxHelpOptions_Impl *pOpt = pImp->GetOptions();
1036*cdf0e10cSrcweir     		if ( !pOpt->HasId( sHelpId ) )
1037*cdf0e10cSrcweir         		return;
1038*cdf0e10cSrcweir 
1039*cdf0e10cSrcweir 			try
1040*cdf0e10cSrcweir 			{
1041*cdf0e10cSrcweir 				URL aURL;
1042*cdf0e10cSrcweir                 aURL.Complete = CreateHelpURL_Impl( String( ByteString(sHelpId), RTL_TEXTENCODING_UTF8 ), GetHelpModuleName_Impl() );
1043*cdf0e10cSrcweir         		Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
1044*cdf0e10cSrcweir 					::rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" ) ), UNO_QUERY );
1045*cdf0e10cSrcweir         		xTrans->parseStrict(aURL);
1046*cdf0e10cSrcweir 
1047*cdf0e10cSrcweir 				Reference < XFrame > xCurrentFrame;
1048*cdf0e10cSrcweir 				Reference < XDesktop > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
1049*cdf0e10cSrcweir 					DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
1050*cdf0e10cSrcweir 				if ( xDesktop.is() )
1051*cdf0e10cSrcweir 					xCurrentFrame = xDesktop->getCurrentFrame();
1052*cdf0e10cSrcweir 
1053*cdf0e10cSrcweir         		Reference< XDispatchProvider > xDispProv( xCurrentFrame, UNO_QUERY );
1054*cdf0e10cSrcweir 				Reference< XDispatch > xHelpDispatch;
1055*cdf0e10cSrcweir 				if ( xDispProv.is() )
1056*cdf0e10cSrcweir 					xHelpDispatch = xDispProv->queryDispatch(
1057*cdf0e10cSrcweir 						aURL, ::rtl::OUString::createFromAscii("_helpagent"),
1058*cdf0e10cSrcweir 						FrameSearchFlag::PARENT | FrameSearchFlag::SELF );
1059*cdf0e10cSrcweir 
1060*cdf0e10cSrcweir         		DBG_ASSERT( xHelpDispatch.is(), "OpenHelpAgent: could not get a dispatcher!" );
1061*cdf0e10cSrcweir 				if ( xHelpDispatch.is() )
1062*cdf0e10cSrcweir 					xHelpDispatch->dispatch( aURL, Sequence< PropertyValue >() );
1063*cdf0e10cSrcweir 			}
1064*cdf0e10cSrcweir 			catch( const Exception& )
1065*cdf0e10cSrcweir 			{
1066*cdf0e10cSrcweir         		DBG_ERRORFILE( "OpenHelpAgent: caught an exception while executing the dispatch!" );
1067*cdf0e10cSrcweir 			}
1068*cdf0e10cSrcweir 	}
1069*cdf0e10cSrcweir }
1070*cdf0e10cSrcweir 
1071*cdf0e10cSrcweir String SfxHelp::GetDefaultHelpModule()
1072*cdf0e10cSrcweir {
1073*cdf0e10cSrcweir     return getDefaultModule_Impl();
1074*cdf0e10cSrcweir }
1075*cdf0e10cSrcweir 
1076*cdf0e10cSrcweir ::rtl::OUString SfxHelp::GetCurrentModuleIdentifier()
1077*cdf0e10cSrcweir {
1078*cdf0e10cSrcweir     return getCurrentModuleIdentifier_Impl();
1079*cdf0e10cSrcweir }
1080*cdf0e10cSrcweir 
1081