xref: /trunk/main/sfx2/source/appl/helpdispatch.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sfx2.hxx"
30 
31 #include "helpdispatch.hxx"
32 #include <sfx2/sfxuno.hxx>
33 #include "newhelp.hxx"
34 #include <tools/debug.hxx>
35 #include <tools/urlobj.hxx>
36 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
37 
38 using namespace ::com::sun::star::beans;
39 using namespace ::com::sun::star::frame;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::util;
42 
43 // class HelpInterceptor_Impl --------------------------------------------
44 
45 HelpDispatch_Impl::HelpDispatch_Impl( HelpInterceptor_Impl& _rInterceptor,
46                                       const ::com::sun::star::uno::Reference<
47                                         ::com::sun::star::frame::XDispatch >& _xDisp ) :
48 
49     m_rInterceptor  ( _rInterceptor ),
50     m_xRealDispatch ( _xDisp )
51 
52 {
53 }
54 
55 // -----------------------------------------------------------------------
56 
57 HelpDispatch_Impl::~HelpDispatch_Impl()
58 {
59 }
60 
61 // -----------------------------------------------------------------------
62 // XDispatch
63 
64 void SAL_CALL HelpDispatch_Impl::dispatch(
65 
66     const URL& aURL, const Sequence< PropertyValue >& aArgs ) throw( RuntimeException )
67 
68 {
69     DBG_ASSERT( m_xRealDispatch.is(), "invalid dispatch" );
70 
71     // search for a keyword (dispatch from the basic ide)
72     sal_Bool bHasKeyword = sal_False;
73     String sKeyword;
74     const PropertyValue* pBegin = aArgs.getConstArray();
75     const PropertyValue* pEnd   = pBegin + aArgs.getLength();
76     for ( ; pBegin != pEnd; ++pBegin )
77     {
78         if ( 0 == ( *pBegin ).Name.compareToAscii( "HelpKeyword" ) )
79         {
80             rtl::OUString sHelpKeyword;
81             if ( ( ( *pBegin ).Value >>= sHelpKeyword ) && sHelpKeyword.getLength() > 0 )
82             {
83                 sKeyword = String( sHelpKeyword );
84                 bHasKeyword = ( sKeyword.Len() > 0 );
85                 break;
86             }
87         }
88     }
89 
90     // if a keyword was found, then open it
91     SfxHelpWindow_Impl* pHelpWin = m_rInterceptor.GetHelpWindow();
92     DBG_ASSERT( pHelpWin, "invalid HelpWindow" );
93     if ( bHasKeyword )
94     {
95         pHelpWin->OpenKeyword( sKeyword );
96         return;
97     }
98 
99     pHelpWin->loadHelpContent(aURL.Complete);
100 }
101 
102 // -----------------------------------------------------------------------
103 
104 void SAL_CALL HelpDispatch_Impl::addStatusListener(
105 
106     const Reference< XStatusListener >& xControl, const URL& aURL ) throw( RuntimeException )
107 
108 {
109     DBG_ASSERT( m_xRealDispatch.is(), "invalid dispatch" );
110     m_xRealDispatch->addStatusListener( xControl, aURL );
111 }
112 
113 // -----------------------------------------------------------------------
114 
115 void SAL_CALL HelpDispatch_Impl::removeStatusListener(
116 
117     const Reference< XStatusListener >& xControl, const URL& aURL ) throw( RuntimeException )
118 
119 {
120     DBG_ASSERT( m_xRealDispatch.is(), "invalid dispatch" );
121     m_xRealDispatch->removeStatusListener( xControl, aURL );
122 }
123 
124