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/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"
40 class ControlFeatureInterception
;
43 //= OFormNavigationHelper
45 typedef ::cppu::ImplHelper2
< css::frame::XDispatchProviderInterception
46 , css::frame::XStatusListener
47 > OFormNavigationHelper_Base
;
49 class OFormNavigationHelper
50 :public OFormNavigationHelper_Base
51 ,public IFeatureDispatcher
57 css::uno::Reference
< css::frame::XDispatch
> xDispatcher
;
59 css::uno::Any aCachedAdditionalState
;
61 FeatureInfo() : bCachedState( false ) { }
63 typedef ::std::map
< sal_Int16
, FeatureInfo
> FeatureMap
;
66 css::uno::Reference
< css::uno::XComponentContext
>
68 ::std::unique_ptr
< ControlFeatureInterception
>
69 m_pFeatureInterception
;
71 // all supported features
72 FeatureMap m_aSupportedFeatures
;
73 // all features which we have an external dispatcher for
74 sal_Int32 m_nConnectedFeatures
;
77 OFormNavigationHelper( const css::uno::Reference
< css::uno::XComponentContext
>& _rxORB
);
78 virtual ~OFormNavigationHelper();
81 void SAL_CALL
dispose( ) throw( css::uno::RuntimeException
);
83 // XDispatchProviderInterception
84 virtual void SAL_CALL
registerDispatchProviderInterceptor( const css::uno::Reference
< css::frame::XDispatchProviderInterceptor
>& Interceptor
) throw (css::uno::RuntimeException
, std::exception
) override
;
85 virtual void SAL_CALL
releaseDispatchProviderInterceptor( const css::uno::Reference
< css::frame::XDispatchProviderInterceptor
>& Interceptor
) throw (css::uno::RuntimeException
, std::exception
) override
;
88 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& State
) throw (css::uno::RuntimeException
, std::exception
) override
;
91 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) throw (css::uno::RuntimeException
, std::exception
) override
;
94 virtual void dispatch( sal_Int16 _nFeatureId
) const override
;
95 virtual void dispatchWithArgument( sal_Int16 _nFeatureId
, const sal_Char
* _pParamName
, const css::uno::Any
& _rParamValue
) const override
;
96 virtual bool isEnabled( sal_Int16 _nFeatureId
) const override
;
97 virtual bool getBooleanState( sal_Int16 _nFeatureId
) const override
;
98 virtual OUString
getStringState( sal_Int16 _nFeatureId
) const override
;
99 virtual sal_Int32
getIntegerState( sal_Int16 _nFeatureId
) const override
;
102 /** is called when the interceptors have.
103 <p>The default implementations simply calls <member>updateDispatches</member>,
104 derived classes can prevent this in certain cases, or do additional handling.</p>
106 virtual void interceptorsChanged( );
108 /** called when the status of a feature changed
110 <p>The default implementation does nothing.</p>
112 <p>If the feature in question does support more state information that just the
113 enabled/disabled state, then this additional information is to be retrieved in
117 the id of the feature
119 determines if the features is enabled or disabled
122 virtual void featureStateChanged( sal_Int16 _nFeatureId
, bool _bEnabled
);
124 /** notification for (potential) changes in the state of all features
125 <p>The base class implementation does nothing. Derived classes could force
126 their peer to update it's state, depending on the result of calls to
127 <member>IFeatureDispatcher::isEnabled</member>.</p>
129 virtual void allFeatureStatesChanged( );
131 /** retrieves the list of supported features
132 <p>To be overridden by derived classes</p>
134 the array of features to support. Out parameter to fill by the derivee's implementation
137 virtual void getSupportedFeatures( ::std::vector
< sal_Int16
>& /* [out] */ _rFeatureIds
) = 0;
140 /** update all our dispatches which are controlled by our dispatch interceptors
142 void updateDispatches();
144 /** connect to the dispatch interceptors
146 void connectDispatchers();
148 /** disconnect from the dispatch interceptors
150 void disconnectDispatchers();
152 /** queries the interceptor chain for a dispatcher for the given URL
154 css::uno::Reference
< css::frame::XDispatch
>
155 queryDispatch( const css::util::URL
& _rURL
);
157 /** invalidates the set of supported features
159 <p>This will invalidate all structures which are tied to the set of supported
160 features. All dispatches will be disconnected.<br/>
161 No automatic re-connection to potential external dispatchers is done, instead,
162 you have to call updateDispatches explicitly, if necessary.</p>
164 void invalidateSupportedFeaturesSet();
167 /** initialize m_aSupportedFeatures, if necessary
169 void initializeSupportedFeatures();
172 /** helper class mapping between feature ids and feature URLs
174 class OFormNavigationMapper
177 ::std::unique_ptr
< UrlTransformer
> m_pUrlTransformer
;
180 OFormNavigationMapper(
181 const css::uno::Reference
< css::uno::XComponentContext
>& _rxORB
183 ~OFormNavigationMapper( );
185 /** retrieves the ASCII representation of a feature URL belonging to an id
188 @return NULL if the given id is not a known feature id (which is a valid usage)
190 static const char* getFeatureURLAscii( sal_Int16 _nFeatureId
);
192 /** retrieves the feature URL belonging to an feature id
194 @complexity O(log n), with n being the number of all potentially known URLs
196 <TRUE/> if and only if the given id is a known feature id
197 (which is a valid usage)
199 bool getFeatureURL( sal_Int16 _nFeatureId
, css::util::URL
& /* [out] */ _rURL
);
201 /** retrieves the feature id belonging to an feature URL
203 @complexity O(n), with n being the number of all potentially known URLs
205 the id of the feature URL, or -1 if the URl is not known
206 (which is a valid usage)
208 static sal_Int16
getFeatureId( const OUString
& _rCompleteURL
);
211 OFormNavigationMapper( const OFormNavigationMapper
& ) = delete;
212 OFormNavigationMapper
& operator=( const OFormNavigationMapper
& ) = delete;
219 #endif // INCLUDED_FORMS_SOURCE_INC_FORMNAVIGATION_HXX
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */