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 .
20 #ifndef INCLUDED_FORMS_SOURCE_INC_FORMNAVIGATION_HXX
21 #define INCLUDED_FORMS_SOURCE_INC_FORMNAVIGATION_HXX
23 #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
24 #include <com/sun/star/frame/XStatusListener.hpp>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <cppuhelper/implbase2.hxx>
27 #include "featuredispatcher.hxx"
38 class ControlFeatureInterception
;
41 //= OFormNavigationHelper
43 typedef ::cppu::ImplHelper2
< css::frame::XDispatchProviderInterception
44 , css::frame::XStatusListener
45 > OFormNavigationHelper_Base
;
47 class OFormNavigationHelper
48 :public OFormNavigationHelper_Base
49 ,public IFeatureDispatcher
55 css::uno::Reference
< css::frame::XDispatch
> xDispatcher
;
57 css::uno::Any aCachedAdditionalState
;
59 FeatureInfo() : bCachedState( false ) { }
61 typedef ::std::map
< sal_Int16
, FeatureInfo
> FeatureMap
;
64 css::uno::Reference
< css::uno::XComponentContext
>
66 ::std::unique_ptr
< ControlFeatureInterception
>
67 m_pFeatureInterception
;
69 // all supported features
70 FeatureMap m_aSupportedFeatures
;
71 // all features which we have an external dispatcher for
72 sal_Int32 m_nConnectedFeatures
;
75 OFormNavigationHelper( const css::uno::Reference
< css::uno::XComponentContext
>& _rxORB
);
76 virtual ~OFormNavigationHelper();
79 /// @throws css::uno::RuntimeException
82 // XDispatchProviderInterception
83 virtual void SAL_CALL
registerDispatchProviderInterceptor( const css::uno::Reference
< css::frame::XDispatchProviderInterceptor
>& Interceptor
) override
;
84 virtual void SAL_CALL
releaseDispatchProviderInterceptor( const css::uno::Reference
< css::frame::XDispatchProviderInterceptor
>& Interceptor
) override
;
87 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& State
) override
;
90 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
93 virtual void dispatch( sal_Int16 _nFeatureId
) const override
;
94 virtual void dispatchWithArgument( sal_Int16 _nFeatureId
, const char* _pParamName
, const css::uno::Any
& _rParamValue
) const override
;
95 virtual bool isEnabled( sal_Int16 _nFeatureId
) const override
;
96 virtual bool getBooleanState( sal_Int16 _nFeatureId
) const override
;
97 virtual OUString
getStringState( sal_Int16 _nFeatureId
) const override
;
98 virtual sal_Int32
getIntegerState( sal_Int16 _nFeatureId
) const override
;
101 /** is called when the interceptors have.
102 <p>The default implementations simply calls <member>updateDispatches</member>,
103 derived classes can prevent this in certain cases, or do additional handling.</p>
105 virtual void interceptorsChanged( );
107 /** called when the status of a feature changed
109 <p>The default implementation does nothing.</p>
111 <p>If the feature in question does support more state information that just the
112 enabled/disabled state, then this additional information is to be retrieved in
116 the id of the feature
118 determines if the features is enabled or disabled
121 virtual void featureStateChanged( sal_Int16 _nFeatureId
, bool _bEnabled
);
123 /** notification for (potential) changes in the state of all features
124 <p>The base class implementation does nothing. Derived classes could force
125 their peer to update it's state, depending on the result of calls to
126 <member>IFeatureDispatcher::isEnabled</member>.</p>
128 virtual void allFeatureStatesChanged( );
130 /** retrieves the list of supported features
131 <p>To be overridden by derived classes</p>
133 the array of features to support. Out parameter to fill by the derivee's implementation
136 virtual void getSupportedFeatures( ::std::vector
< sal_Int16
>& /* [out] */ _rFeatureIds
) = 0;
139 /** update all our dispatches which are controlled by our dispatch interceptors
141 void updateDispatches();
143 /** connect to the dispatch interceptors
145 void connectDispatchers();
147 /** disconnect from the dispatch interceptors
149 void disconnectDispatchers();
151 /** queries the interceptor chain for a dispatcher for the given URL
153 css::uno::Reference
< css::frame::XDispatch
>
154 queryDispatch( const css::util::URL
& _rURL
);
156 /** invalidates the set of supported features
158 <p>This will invalidate all structures which are tied to the set of supported
159 features. All dispatches will be disconnected.<br/>
160 No automatic re-connection to potential external dispatchers is done, instead,
161 you have to call updateDispatches explicitly, if necessary.</p>
163 void invalidateSupportedFeaturesSet();
166 /** initialize m_aSupportedFeatures, if necessary
168 void initializeSupportedFeatures();
171 /** helper class mapping between feature ids and feature URLs
173 class OFormNavigationMapper
176 ::std::unique_ptr
< UrlTransformer
> m_pUrlTransformer
;
179 OFormNavigationMapper(
180 const css::uno::Reference
< css::uno::XComponentContext
>& _rxORB
182 ~OFormNavigationMapper( );
184 /** retrieves the ASCII representation of a feature URL belonging to an id
187 @return NULL if the given id is not a known feature id (which is a valid usage)
189 static const char* getFeatureURLAscii( sal_Int16 _nFeatureId
);
191 /** retrieves the feature URL belonging to a feature id
193 @complexity O(log n), with n being the number of all potentially known URLs
195 <TRUE/> if and only if the given id is a known feature id
196 (which is a valid usage)
198 bool getFeatureURL( sal_Int16 _nFeatureId
, css::util::URL
& /* [out] */ _rURL
);
200 /** retrieves the feature id belonging to a feature URL
202 @complexity O(n), with n being the number of all potentially known URLs
204 the id of the feature URL, or -1 if the URl is not known
205 (which is a valid usage)
207 static sal_Int16
getFeatureId( const OUString
& _rCompleteURL
);
210 OFormNavigationMapper( const OFormNavigationMapper
& ) = delete;
211 OFormNavigationMapper
& operator=( const OFormNavigationMapper
& ) = delete;
218 #endif // INCLUDED_FORMS_SOURCE_INC_FORMNAVIGATION_HXX
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */