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