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