1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
23 #include <com/sun/star/frame/XStatusListener.hpp>
24 #include <com/sun/star/uno/XComponentContext.hpp>
25 #include <cppuhelper/implbase2.hxx>
26 #include "featuredispatcher.hxx"
27 #include "controlfeatureinterception.hxx"
40 //= OFormNavigationHelper
42 typedef ::cppu::ImplHelper2
< css::frame::XDispatchProviderInterception
43 , css::frame::XStatusListener
44 > OFormNavigationHelper_Base
;
46 class OFormNavigationHelper
47 :public OFormNavigationHelper_Base
48 ,public IFeatureDispatcher
54 css::uno::Reference
< css::frame::XDispatch
> xDispatcher
;
56 css::uno::Any aCachedAdditionalState
;
58 FeatureInfo() : bCachedState( false ) { }
60 typedef ::std::map
< sal_Int16
, FeatureInfo
> FeatureMap
;
63 css::uno::Reference
< css::uno::XComponentContext
>
65 ControlFeatureInterception
66 m_aFeatureInterception
;
68 // all supported features
69 FeatureMap m_aSupportedFeatures
;
70 // all features which we have an external dispatcher for
71 sal_Int32 m_nConnectedFeatures
;
74 OFormNavigationHelper( const css::uno::Reference
< css::uno::XComponentContext
>& _rxORB
);
75 virtual ~OFormNavigationHelper();
78 /// @throws css::uno::RuntimeException
81 // XDispatchProviderInterception
82 virtual void SAL_CALL
registerDispatchProviderInterceptor( const css::uno::Reference
< css::frame::XDispatchProviderInterceptor
>& Interceptor
) override
;
83 virtual void SAL_CALL
releaseDispatchProviderInterceptor( const css::uno::Reference
< css::frame::XDispatchProviderInterceptor
>& Interceptor
) override
;
86 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& State
) override
;
89 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
92 virtual void dispatch( sal_Int16 _nFeatureId
) const override
;
93 virtual void dispatchWithArgument( sal_Int16 _nFeatureId
, const OUString
& _pParamName
, const css::uno::Any
& _rParamValue
) const override
;
94 virtual bool isEnabled( sal_Int16 _nFeatureId
) const override
;
95 virtual bool getBooleanState( sal_Int16 _nFeatureId
) const override
;
96 virtual OUString
getStringState( sal_Int16 _nFeatureId
) const override
;
97 virtual sal_Int32
getIntegerState( sal_Int16 _nFeatureId
) const override
;
100 /** is called when the interceptors have.
101 <p>The default implementations simply calls <member>updateDispatches</member>,
102 derived classes can prevent this in certain cases, or do additional handling.</p>
104 virtual void interceptorsChanged( );
106 /** called when the status of a feature changed
108 <p>The default implementation does nothing.</p>
110 <p>If the feature in question does support more state information that just the
111 enabled/disabled state, then this additional information is to be retrieved in
115 the id of the feature
117 determines if the features is enabled or disabled
120 virtual void featureStateChanged( sal_Int16 _nFeatureId
, bool _bEnabled
);
122 /** notification for (potential) changes in the state of all features
123 <p>The base class implementation does nothing. Derived classes could force
124 their peer to update it's state, depending on the result of calls to
125 <member>IFeatureDispatcher::isEnabled</member>.</p>
127 virtual void allFeatureStatesChanged( );
129 /** retrieves the list of supported features
130 <p>To be overridden by derived classes</p>
132 the array of features to support. Out parameter to fill by the derivee's implementation
135 virtual void getSupportedFeatures( ::std::vector
< sal_Int16
>& /* [out] */ _rFeatureIds
) = 0;
138 /** update all our dispatches which are controlled by our dispatch interceptors
140 void updateDispatches();
142 /** connect to the dispatch interceptors
144 void connectDispatchers();
146 /** disconnect from the dispatch interceptors
148 void disconnectDispatchers();
150 /** queries the interceptor chain for a dispatcher for the given URL
152 css::uno::Reference
< css::frame::XDispatch
>
153 queryDispatch( const css::util::URL
& _rURL
);
155 /** invalidates the set of supported features
157 <p>This will invalidate all structures which are tied to the set of supported
158 features. All dispatches will be disconnected.<br/>
159 No automatic re-connection to potential external dispatchers is done, instead,
160 you have to call updateDispatches explicitly, if necessary.</p>
162 void invalidateSupportedFeaturesSet();
165 /** initialize m_aSupportedFeatures, if necessary
167 void initializeSupportedFeatures();
170 /** helper class mapping between feature ids and feature URLs
172 class OFormNavigationMapper
175 ::std::unique_ptr
< UrlTransformer
> m_pUrlTransformer
;
178 OFormNavigationMapper(
179 const css::uno::Reference
< css::uno::XComponentContext
>& _rxORB
181 ~OFormNavigationMapper( );
183 /** retrieves the ASCII representation of a feature URL belonging to an id
186 @return NULL if the given id is not a known feature id (which is a valid usage)
188 static std::optional
<OUString
> getFeatureURL( sal_Int16 _nFeatureId
);
190 /** retrieves the feature URL belonging to a feature id
192 @complexity O(log n), with n being the number of all potentially known URLs
194 <TRUE/> if and only if the given id is a known feature id
195 (which is a valid usage)
197 bool getFeatureURL( sal_Int16 _nFeatureId
, css::util::URL
& /* [out] */ _rURL
);
199 /** retrieves the feature id belonging to a feature URL
201 @complexity O(n), with n being the number of all potentially known URLs
203 the id of the feature URL, or -1 if the URl is not known
204 (which is a valid usage)
206 static sal_Int16
getFeatureId( std::u16string_view _rCompleteURL
);
209 OFormNavigationMapper( const OFormNavigationMapper
& ) = delete;
210 OFormNavigationMapper
& operator=( const OFormNavigationMapper
& ) = delete;
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */