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