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 #ifndef FORMS_FORM_NAVIGATION_HXX
29*cdf0e10cSrcweir #define FORMS_FORM_NAVIGATION_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/frame/XStatusListener.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
35*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
36*cdf0e10cSrcweir #include "featuredispatcher.hxx"
37*cdf0e10cSrcweir #include <vector>
38*cdf0e10cSrcweir #include <map>
39*cdf0e10cSrcweir #include <memory>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir //.........................................................................
43*cdf0e10cSrcweir namespace frm
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir //.........................................................................
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir     class UrlTransformer;
48*cdf0e10cSrcweir     class ControlFeatureInterception;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir     //==================================================================
51*cdf0e10cSrcweir     //= OFormNavigationHelper
52*cdf0e10cSrcweir     //==================================================================
53*cdf0e10cSrcweir     typedef ::cppu::ImplHelper2 <   ::com::sun::star::frame::XDispatchProviderInterception
54*cdf0e10cSrcweir                                 ,   ::com::sun::star::frame::XStatusListener
55*cdf0e10cSrcweir                                 >   OFormNavigationHelper_Base;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     class OFormNavigationHelper
58*cdf0e10cSrcweir                         :public OFormNavigationHelper_Base
59*cdf0e10cSrcweir                         ,public IFeatureDispatcher
60*cdf0e10cSrcweir     {
61*cdf0e10cSrcweir     private:
62*cdf0e10cSrcweir         struct FeatureInfo
63*cdf0e10cSrcweir         {
64*cdf0e10cSrcweir             ::com::sun::star::util::URL                                             aURL;
65*cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >  xDispatcher;
66*cdf0e10cSrcweir             sal_Bool                                                                bCachedState;
67*cdf0e10cSrcweir             ::com::sun::star::uno::Any                                              aCachedAdditionalState;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir             FeatureInfo() : bCachedState( sal_False ) { }
70*cdf0e10cSrcweir         };
71*cdf0e10cSrcweir         typedef ::std::map< sal_Int16, FeatureInfo >    FeatureMap;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir     private:
74*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
75*cdf0e10cSrcweir                             m_xORB;
76*cdf0e10cSrcweir         ::std::auto_ptr< ControlFeatureInterception >
77*cdf0e10cSrcweir                             m_pFeatureInterception;
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir         // all supported features
80*cdf0e10cSrcweir         FeatureMap          m_aSupportedFeatures;
81*cdf0e10cSrcweir         // all features which we have an external dispatcher for
82*cdf0e10cSrcweir         sal_Int32           m_nConnectedFeatures;
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir     protected:
85*cdf0e10cSrcweir         inline const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&
86*cdf0e10cSrcweir             getORB( ) const { return m_xORB; }
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     protected:
89*cdf0e10cSrcweir         OFormNavigationHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB );
90*cdf0e10cSrcweir         virtual ~OFormNavigationHelper();
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 	    // XComponent
93*cdf0e10cSrcweir         void SAL_CALL dispose(  ) throw( ::com::sun::star::uno::RuntimeException );
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir         // XDispatchProviderInterception
96*cdf0e10cSrcweir         virtual void SAL_CALL registerDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException);
97*cdf0e10cSrcweir         virtual void SAL_CALL releaseDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException);
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir         // XStatusListener
100*cdf0e10cSrcweir         virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& State ) throw (::com::sun::star::uno::RuntimeException);
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir         // XEventListener
103*cdf0e10cSrcweir         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir         // IFeatureDispatcher
106*cdf0e10cSrcweir         virtual void            dispatch( sal_Int16 _nFeatureId ) const;
107*cdf0e10cSrcweir         virtual void            dispatchWithArgument( sal_Int16 _nFeatureId, const sal_Char* _pParamName, const ::com::sun::star::uno::Any& _rParamValue ) const;
108*cdf0e10cSrcweir         virtual bool            isEnabled( sal_Int16 _nFeatureId ) const;
109*cdf0e10cSrcweir         virtual bool            getBooleanState( sal_Int16 _nFeatureId ) const;
110*cdf0e10cSrcweir         virtual ::rtl::OUString getStringState( sal_Int16 _nFeatureId ) const;
111*cdf0e10cSrcweir         virtual sal_Int32       getIntegerState( sal_Int16 _nFeatureId ) const;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir         // own overridables
114*cdf0e10cSrcweir         /** is called when the interceptors have.
115*cdf0e10cSrcweir             <p>The default implementations simply calls <member>updateDispatches</member>,
116*cdf0e10cSrcweir             derived classes can prevent this in certain cases, or do additional handling.</p>
117*cdf0e10cSrcweir         */
118*cdf0e10cSrcweir         virtual void    interceptorsChanged( );
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir         /** called when the status of a feature changed
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir             <p>The default implementation does nothing.</p>
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir             <p>If the feature in question does support more state information that just the
125*cdf0e10cSrcweir             enabled/disabled state, then this additional information is to be retrieved in
126*cdf0e10cSrcweir             a separate call.</p>
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir             @param _nFeatureId
129*cdf0e10cSrcweir                 the id of the feature
130*cdf0e10cSrcweir             @param _bEnabled
131*cdf0e10cSrcweir                 determines if the features is enabled or disabled
132*cdf0e10cSrcweir             @see getBooleanState
133*cdf0e10cSrcweir         */
134*cdf0e10cSrcweir         virtual void    featureStateChanged( sal_Int16 _nFeatureId, sal_Bool _bEnabled );
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir         /** notification for (potential) changes in the state of all features
137*cdf0e10cSrcweir             <p>The base class implementation does nothing. Derived classes could force
138*cdf0e10cSrcweir             their peer to update it's state, depending on the result of calls to
139*cdf0e10cSrcweir             <member>IFeatureDispatcher::isEnabled</member>.</p>
140*cdf0e10cSrcweir         */
141*cdf0e10cSrcweir         virtual void    allFeatureStatesChanged( );
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir         /** retrieves the list of supported features
144*cdf0e10cSrcweir             <p>To be overridden by derived classes</p>
145*cdf0e10cSrcweir             @param _rFeatureIds
146*cdf0e10cSrcweir                 the array of features to support. Out parameter to fill by the derivee's implementation
147*cdf0e10cSrcweir             @pure
148*cdf0e10cSrcweir         */
149*cdf0e10cSrcweir         virtual void    getSupportedFeatures( ::std::vector< sal_Int16 >& /* [out] */ _rFeatureIds ) = 0;
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir     protected:
152*cdf0e10cSrcweir         /** update all our dispatches which are controlled by our dispatch interceptors
153*cdf0e10cSrcweir         */
154*cdf0e10cSrcweir         void    updateDispatches();
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir         /** connect to the dispatch interceptors
157*cdf0e10cSrcweir         */
158*cdf0e10cSrcweir         void    connectDispatchers();
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir         /** disconnect from the dispatch interceptors
161*cdf0e10cSrcweir         */
162*cdf0e10cSrcweir         void    disconnectDispatchers();
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir         /** queries the interceptor chain for a dispatcher for the given URL
165*cdf0e10cSrcweir         */
166*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >
167*cdf0e10cSrcweir                 queryDispatch( const ::com::sun::star::util::URL& _rURL );
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir         /** invalidates the set of supported features
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir             <p>This will invalidate all structures which are tied to the set of supported
172*cdf0e10cSrcweir             features. All dispatches will be disconnected.<br/>
173*cdf0e10cSrcweir             No automatic re-connection to potential external dispatchers is done, instead,
174*cdf0e10cSrcweir             you have to call updateDispatches explicitly, if necessary.</p>
175*cdf0e10cSrcweir         */
176*cdf0e10cSrcweir         void    invalidateSupportedFeaturesSet();
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir     private:
179*cdf0e10cSrcweir         /** initialize m_aSupportedFeatures, if necessary
180*cdf0e10cSrcweir         */
181*cdf0e10cSrcweir         void    initializeSupportedFeatures();
182*cdf0e10cSrcweir     };
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir     //==================================================================
185*cdf0e10cSrcweir     //= OFormNavigationMapper
186*cdf0e10cSrcweir     //==================================================================
187*cdf0e10cSrcweir     /** helper class mapping between feature ids and feature URLs
188*cdf0e10cSrcweir     */
189*cdf0e10cSrcweir     class OFormNavigationMapper
190*cdf0e10cSrcweir     {
191*cdf0e10cSrcweir     private:
192*cdf0e10cSrcweir         ::std::auto_ptr< UrlTransformer >   m_pUrlTransformer;
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir     public:
195*cdf0e10cSrcweir         OFormNavigationMapper(
196*cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB
197*cdf0e10cSrcweir         );
198*cdf0e10cSrcweir         ~OFormNavigationMapper( );
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir         /** retrieves the ASCII representation of a feature URL belonging to an id
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir             @complexity O(log n)
203*cdf0e10cSrcweir             @return NULL if the given id is not a known feature id (which is a valid usage)
204*cdf0e10cSrcweir         */
205*cdf0e10cSrcweir         const char* getFeatureURLAscii( sal_Int16 _nFeatureId );
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir         /** retrieves the feature URL belonging to an feature id
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir             @complexity O(log n), with n being the number of all potentially known URLs
210*cdf0e10cSrcweir             @return
211*cdf0e10cSrcweir                 <TRUE/> if and only if the given id is a known feature id
212*cdf0e10cSrcweir                 (which is a valid usage)
213*cdf0e10cSrcweir         */
214*cdf0e10cSrcweir         bool        getFeatureURL( sal_Int16 _nFeatureId, ::com::sun::star::util::URL& /* [out] */ _rURL );
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir         /** retrieves the feature id belonging to an feature URL
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir             @complexity O(n), with n being the number of all potentially known URLs
219*cdf0e10cSrcweir             @return
220*cdf0e10cSrcweir                 the id of the feature URL, or -1 if the URl is not known
221*cdf0e10cSrcweir                 (which is a valid usage)
222*cdf0e10cSrcweir         */
223*cdf0e10cSrcweir         sal_Int16   getFeatureId( const ::rtl::OUString& _rCompleteURL );
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir     private:
226*cdf0e10cSrcweir         OFormNavigationMapper( );                                           // never implemented
227*cdf0e10cSrcweir         OFormNavigationMapper( const OFormNavigationMapper& );              // never implemented
228*cdf0e10cSrcweir         OFormNavigationMapper& operator=( const OFormNavigationMapper& );   // never implemented
229*cdf0e10cSrcweir     };
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir //.........................................................................
232*cdf0e10cSrcweir }   // namespace frm
233*cdf0e10cSrcweir //.........................................................................
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir #endif // FORMS_FORM_NAVIGATION_HXX
236