1*24acc546SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*24acc546SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*24acc546SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*24acc546SAndrew Rist  * distributed with this work for additional information
6*24acc546SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*24acc546SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*24acc546SAndrew Rist  * "License"); you may not use this file except in compliance
9*24acc546SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*24acc546SAndrew Rist  *
11*24acc546SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*24acc546SAndrew Rist  *
13*24acc546SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*24acc546SAndrew Rist  * software distributed under the License is distributed on an
15*24acc546SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*24acc546SAndrew Rist  * KIND, either express or implied.  See the License for the
17*24acc546SAndrew Rist  * specific language governing permissions and limitations
18*24acc546SAndrew Rist  * under the License.
19*24acc546SAndrew Rist  *
20*24acc546SAndrew Rist  *************************************************************/
21*24acc546SAndrew Rist 
22*24acc546SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_forms.hxx"
26cdf0e10cSrcweir #include "formnavigation.hxx"
27cdf0e10cSrcweir #include "urltransformer.hxx"
28cdf0e10cSrcweir #include "controlfeatureinterception.hxx"
29cdf0e10cSrcweir #include "frm_strings.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <com/sun/star/form/runtime/FormFeature.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <tools/debug.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //.........................................................................
37cdf0e10cSrcweir namespace frm
38cdf0e10cSrcweir {
39cdf0e10cSrcweir //.........................................................................
40cdf0e10cSrcweir 
41cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
42cdf0e10cSrcweir     using namespace ::com::sun::star::beans;
43cdf0e10cSrcweir     using namespace ::com::sun::star::lang;
44cdf0e10cSrcweir     using namespace ::com::sun::star::util;
45cdf0e10cSrcweir     using namespace ::com::sun::star::frame;
46cdf0e10cSrcweir     namespace FormFeature = ::com::sun::star::form::runtime::FormFeature;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     //==================================================================
49cdf0e10cSrcweir     //= OFormNavigationHelper
50cdf0e10cSrcweir     //==================================================================
DBG_NAME(OFormNavigationHelper)51cdf0e10cSrcweir     DBG_NAME( OFormNavigationHelper )
52cdf0e10cSrcweir     //------------------------------------------------------------------
53cdf0e10cSrcweir     OFormNavigationHelper::OFormNavigationHelper( const Reference< XMultiServiceFactory >& _rxORB )
54cdf0e10cSrcweir         :m_xORB( _rxORB )
55cdf0e10cSrcweir         ,m_nConnectedFeatures( 0 )
56cdf0e10cSrcweir     {
57cdf0e10cSrcweir         DBG_CTOR( OFormNavigationHelper, NULL );
58cdf0e10cSrcweir         m_pFeatureInterception.reset( new ControlFeatureInterception( m_xORB ) );
59cdf0e10cSrcweir     }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     //------------------------------------------------------------------
~OFormNavigationHelper()62cdf0e10cSrcweir     OFormNavigationHelper::~OFormNavigationHelper()
63cdf0e10cSrcweir     {
64cdf0e10cSrcweir         DBG_DTOR( OFormNavigationHelper, NULL );
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     //------------------------------------------------------------------
dispose()68cdf0e10cSrcweir     void SAL_CALL OFormNavigationHelper::dispose( ) throw( RuntimeException )
69cdf0e10cSrcweir     {
70cdf0e10cSrcweir         m_pFeatureInterception->dispose();
71cdf0e10cSrcweir         disconnectDispatchers();
72cdf0e10cSrcweir     }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     //------------------------------------------------------------------
interceptorsChanged()75cdf0e10cSrcweir     void OFormNavigationHelper::interceptorsChanged( )
76cdf0e10cSrcweir     {
77cdf0e10cSrcweir         updateDispatches();
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     //------------------------------------------------------------------
featureStateChanged(sal_Int16,sal_Bool)81cdf0e10cSrcweir     void OFormNavigationHelper::featureStateChanged( sal_Int16 /*_nFeatureId*/, sal_Bool /*_bEnabled*/ )
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         // not interested in
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     //------------------------------------------------------------------
allFeatureStatesChanged()87cdf0e10cSrcweir     void OFormNavigationHelper::allFeatureStatesChanged( )
88cdf0e10cSrcweir     {
89cdf0e10cSrcweir         // not interested in
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     //------------------------------------------------------------------
registerDispatchProviderInterceptor(const Reference<XDispatchProviderInterceptor> & _rxInterceptor)93cdf0e10cSrcweir     void SAL_CALL OFormNavigationHelper::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException)
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         m_pFeatureInterception->registerDispatchProviderInterceptor( _rxInterceptor );
96cdf0e10cSrcweir         interceptorsChanged();
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     //------------------------------------------------------------------
releaseDispatchProviderInterceptor(const Reference<XDispatchProviderInterceptor> & _rxInterceptor)100cdf0e10cSrcweir     void SAL_CALL OFormNavigationHelper::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException)
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir         m_pFeatureInterception->releaseDispatchProviderInterceptor( _rxInterceptor );
103cdf0e10cSrcweir         interceptorsChanged();
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     //------------------------------------------------------------------
statusChanged(const FeatureStateEvent & _rState)107cdf0e10cSrcweir     void SAL_CALL OFormNavigationHelper::statusChanged( const FeatureStateEvent& _rState ) throw (RuntimeException)
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir         for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
110cdf0e10cSrcweir                 aFeature != m_aSupportedFeatures.end();
111cdf0e10cSrcweir                 ++aFeature
112cdf0e10cSrcweir             )
113cdf0e10cSrcweir         {
114cdf0e10cSrcweir             if ( aFeature->second.aURL.Main == _rState.FeatureURL.Main )
115cdf0e10cSrcweir             {
116cdf0e10cSrcweir                 if  (  ( aFeature->second.bCachedState != _rState.IsEnabled )
117cdf0e10cSrcweir                     || ( aFeature->second.aCachedAdditionalState != _rState.State )
118cdf0e10cSrcweir                     )
119cdf0e10cSrcweir                 {
120cdf0e10cSrcweir                     // change the cached state
121cdf0e10cSrcweir                     aFeature->second.bCachedState           = _rState.IsEnabled;
122cdf0e10cSrcweir                     aFeature->second.aCachedAdditionalState = _rState.State;
123cdf0e10cSrcweir                     // tell derivees what happened
124cdf0e10cSrcweir                     featureStateChanged( aFeature->first, _rState.IsEnabled );
125cdf0e10cSrcweir                 }
126cdf0e10cSrcweir                 return;
127cdf0e10cSrcweir             }
128cdf0e10cSrcweir         }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         // unreachable
131cdf0e10cSrcweir         DBG_ERROR( "OFormNavigationHelper::statusChanged: huh? An invalid/unknown URL?" );
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     //------------------------------------------------------------------
disposing(const EventObject & _rSource)135cdf0e10cSrcweir     void SAL_CALL OFormNavigationHelper::disposing( const EventObject& _rSource ) throw (RuntimeException)
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir         // was it one of our external dispatchers?
138cdf0e10cSrcweir 	    if ( m_nConnectedFeatures )
139cdf0e10cSrcweir 	    {
140cdf0e10cSrcweir             for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
141cdf0e10cSrcweir                     aFeature != m_aSupportedFeatures.end();
142cdf0e10cSrcweir                     ++aFeature
143cdf0e10cSrcweir                 )
144cdf0e10cSrcweir 		    {
145cdf0e10cSrcweir 			    if ( aFeature->second.xDispatcher == _rSource.Source )
146cdf0e10cSrcweir 			    {
147cdf0e10cSrcweir 				    aFeature->second.xDispatcher->removeStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
148cdf0e10cSrcweir 				    aFeature->second.xDispatcher = NULL;
149cdf0e10cSrcweir                     aFeature->second.bCachedState = sal_False;
150cdf0e10cSrcweir                     aFeature->second.aCachedAdditionalState.clear();
151cdf0e10cSrcweir                     --m_nConnectedFeatures;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir                     featureStateChanged( aFeature->first, sal_False );
154cdf0e10cSrcweir                     break;
155cdf0e10cSrcweir 			    }
156cdf0e10cSrcweir 		    }
157cdf0e10cSrcweir 	    }
158cdf0e10cSrcweir     }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     //------------------------------------------------------------------
updateDispatches()161cdf0e10cSrcweir     void OFormNavigationHelper::updateDispatches()
162cdf0e10cSrcweir     {
163cdf0e10cSrcweir 	    if ( !m_nConnectedFeatures )
164cdf0e10cSrcweir 	    {	// we don't have any dispatchers yet -> do the initial connect
165cdf0e10cSrcweir 		    connectDispatchers();
166cdf0e10cSrcweir 		    return;
167cdf0e10cSrcweir 	    }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         initializeSupportedFeatures();
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 	    m_nConnectedFeatures = 0;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         Reference< XDispatch >  xNewDispatcher;
174cdf0e10cSrcweir         Reference< XDispatch >  xCurrentDispatcher;
175cdf0e10cSrcweir 
176cdf0e10cSrcweir         for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
177cdf0e10cSrcweir                 aFeature != m_aSupportedFeatures.end();
178cdf0e10cSrcweir                 ++aFeature
179cdf0e10cSrcweir             )
180cdf0e10cSrcweir 	    {
181cdf0e10cSrcweir             xNewDispatcher = queryDispatch( aFeature->second.aURL );
182cdf0e10cSrcweir             xCurrentDispatcher = aFeature->second.xDispatcher;
183cdf0e10cSrcweir 		    if ( xNewDispatcher != xCurrentDispatcher )
184cdf0e10cSrcweir 		    {
185cdf0e10cSrcweir                 // the dispatcher for this particular URL changed
186cdf0e10cSrcweir 			    if ( xCurrentDispatcher.is() )
187cdf0e10cSrcweir 				    xCurrentDispatcher->removeStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
188cdf0e10cSrcweir 
189cdf0e10cSrcweir                 xCurrentDispatcher = aFeature->second.xDispatcher = xNewDispatcher;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir                 if ( xCurrentDispatcher.is() )
192cdf0e10cSrcweir 				    xCurrentDispatcher->addStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
193cdf0e10cSrcweir 		    }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir             if ( xCurrentDispatcher.is() )
196cdf0e10cSrcweir 			    ++m_nConnectedFeatures;
197cdf0e10cSrcweir             else
198cdf0e10cSrcweir                 aFeature->second.bCachedState = sal_False;
199cdf0e10cSrcweir 	    }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir         // notify derivee that (potentially) all features changed their state
202cdf0e10cSrcweir         allFeatureStatesChanged( );
203cdf0e10cSrcweir     }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     //------------------------------------------------------------------
connectDispatchers()206cdf0e10cSrcweir     void OFormNavigationHelper::connectDispatchers()
207cdf0e10cSrcweir     {
208cdf0e10cSrcweir         if ( m_nConnectedFeatures )
209cdf0e10cSrcweir 	    {	// already connected -> just do an update
210cdf0e10cSrcweir 		    updateDispatches();
211cdf0e10cSrcweir 		    return;
212cdf0e10cSrcweir 	    }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir         initializeSupportedFeatures();
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 	    m_nConnectedFeatures = 0;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir         for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
219cdf0e10cSrcweir                 aFeature != m_aSupportedFeatures.end();
220cdf0e10cSrcweir                 ++aFeature
221cdf0e10cSrcweir             )
222cdf0e10cSrcweir 	    {
223cdf0e10cSrcweir             aFeature->second.bCachedState = sal_False;
224cdf0e10cSrcweir             aFeature->second.aCachedAdditionalState.clear();
225cdf0e10cSrcweir             aFeature->second.xDispatcher = queryDispatch( aFeature->second.aURL );
226cdf0e10cSrcweir 		    if ( aFeature->second.xDispatcher.is() )
227cdf0e10cSrcweir 		    {
228cdf0e10cSrcweir 			    ++m_nConnectedFeatures;
229cdf0e10cSrcweir 			    aFeature->second.xDispatcher->addStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
230cdf0e10cSrcweir 		    }
231cdf0e10cSrcweir 	    }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir         // notify derivee that (potentially) all features changed their state
234cdf0e10cSrcweir         allFeatureStatesChanged( );
235cdf0e10cSrcweir     }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     //------------------------------------------------------------------
disconnectDispatchers()238cdf0e10cSrcweir     void OFormNavigationHelper::disconnectDispatchers()
239cdf0e10cSrcweir     {
240cdf0e10cSrcweir 	    if ( m_nConnectedFeatures )
241cdf0e10cSrcweir         {
242cdf0e10cSrcweir             for (   FeatureMap::iterator aFeature = m_aSupportedFeatures.begin();
243cdf0e10cSrcweir                     aFeature != m_aSupportedFeatures.end();
244cdf0e10cSrcweir                     ++aFeature
245cdf0e10cSrcweir                 )
246cdf0e10cSrcweir 	        {
247cdf0e10cSrcweir 		        if ( aFeature->second.xDispatcher.is() )
248cdf0e10cSrcweir 			        aFeature->second.xDispatcher->removeStatusListener( static_cast< XStatusListener* >( this ), aFeature->second.aURL );
249cdf0e10cSrcweir 
250cdf0e10cSrcweir                 aFeature->second.xDispatcher = NULL;
251cdf0e10cSrcweir                 aFeature->second.bCachedState = sal_False;
252cdf0e10cSrcweir                 aFeature->second.aCachedAdditionalState.clear();
253cdf0e10cSrcweir 	        }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir             m_nConnectedFeatures = 0;
256cdf0e10cSrcweir         }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir         // notify derivee that (potentially) all features changed their state
259cdf0e10cSrcweir         allFeatureStatesChanged( );
260cdf0e10cSrcweir     }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     //------------------------------------------------------------------
initializeSupportedFeatures()263cdf0e10cSrcweir     void OFormNavigationHelper::initializeSupportedFeatures( )
264cdf0e10cSrcweir     {
265cdf0e10cSrcweir         if ( m_aSupportedFeatures.empty() )
266cdf0e10cSrcweir         {
267cdf0e10cSrcweir             // ask the derivee which feature ids it wants us to support
268cdf0e10cSrcweir             ::std::vector< sal_Int16 > aFeatureIds;
269cdf0e10cSrcweir             getSupportedFeatures( aFeatureIds );
270cdf0e10cSrcweir 
271cdf0e10cSrcweir             OFormNavigationMapper aUrlMapper( m_xORB );
272cdf0e10cSrcweir 
273cdf0e10cSrcweir             for (   ::std::vector< sal_Int16 >::const_iterator aLoop = aFeatureIds.begin();
274cdf0e10cSrcweir                     aLoop != aFeatureIds.end();
275cdf0e10cSrcweir                     ++aLoop
276cdf0e10cSrcweir                 )
277cdf0e10cSrcweir             {
278cdf0e10cSrcweir                 FeatureInfo aFeatureInfo;
279cdf0e10cSrcweir 
280cdf0e10cSrcweir                 bool bKnownId =
281cdf0e10cSrcweir                     aUrlMapper.getFeatureURL( *aLoop, aFeatureInfo.aURL );
282cdf0e10cSrcweir                 DBG_ASSERT( bKnownId, "OFormNavigationHelper::initializeSupportedFeatures: unknown feature id!" );
283cdf0e10cSrcweir 
284cdf0e10cSrcweir                 if ( bKnownId )
285cdf0e10cSrcweir                     // add to our map
286cdf0e10cSrcweir                     m_aSupportedFeatures.insert( FeatureMap::value_type( *aLoop, aFeatureInfo ) );
287cdf0e10cSrcweir             }
288cdf0e10cSrcweir         }
289cdf0e10cSrcweir     }
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     //------------------------------------------------------------------
queryDispatch(const URL & _rURL)292cdf0e10cSrcweir     Reference< XDispatch > OFormNavigationHelper::queryDispatch( const URL& _rURL )
293cdf0e10cSrcweir     {
294cdf0e10cSrcweir         return m_pFeatureInterception->queryDispatch( _rURL );
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     //------------------------------------------------------------------
dispatchWithArgument(sal_Int16 _nFeatureId,const sal_Char * _pParamAsciiName,const Any & _rParamValue) const298cdf0e10cSrcweir     void OFormNavigationHelper::dispatchWithArgument( sal_Int16 _nFeatureId, const sal_Char* _pParamAsciiName,
299cdf0e10cSrcweir         const Any& _rParamValue ) const
300cdf0e10cSrcweir     {
301cdf0e10cSrcweir         FeatureMap::const_iterator aInfo = m_aSupportedFeatures.find( _nFeatureId );
302cdf0e10cSrcweir         if ( m_aSupportedFeatures.end() != aInfo )
303cdf0e10cSrcweir         {
304cdf0e10cSrcweir             if ( aInfo->second.xDispatcher.is() )
305cdf0e10cSrcweir             {
306cdf0e10cSrcweir                 Sequence< PropertyValue > aArgs( 1 );
307cdf0e10cSrcweir                 aArgs[0].Name = ::rtl::OUString::createFromAscii( _pParamAsciiName );
308cdf0e10cSrcweir                 aArgs[0].Value = _rParamValue;
309cdf0e10cSrcweir 
310cdf0e10cSrcweir                 aInfo->second.xDispatcher->dispatch( aInfo->second.aURL, aArgs );
311cdf0e10cSrcweir             }
312cdf0e10cSrcweir         }
313cdf0e10cSrcweir     }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir     //------------------------------------------------------------------
dispatch(sal_Int16 _nFeatureId) const316cdf0e10cSrcweir     void OFormNavigationHelper::dispatch( sal_Int16 _nFeatureId ) const
317cdf0e10cSrcweir     {
318cdf0e10cSrcweir         FeatureMap::const_iterator aInfo = m_aSupportedFeatures.find( _nFeatureId );
319cdf0e10cSrcweir         if ( m_aSupportedFeatures.end() != aInfo )
320cdf0e10cSrcweir         {
321cdf0e10cSrcweir             if ( aInfo->second.xDispatcher.is() )
322cdf0e10cSrcweir             {
323cdf0e10cSrcweir                 Sequence< PropertyValue > aEmptyArgs;
324cdf0e10cSrcweir                 aInfo->second.xDispatcher->dispatch( aInfo->second.aURL, aEmptyArgs );
325cdf0e10cSrcweir             }
326cdf0e10cSrcweir         }
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     //------------------------------------------------------------------
isEnabled(sal_Int16 _nFeatureId) const330cdf0e10cSrcweir     bool OFormNavigationHelper::isEnabled( sal_Int16 _nFeatureId ) const
331cdf0e10cSrcweir     {
332cdf0e10cSrcweir         FeatureMap::const_iterator aInfo = m_aSupportedFeatures.find( _nFeatureId );
333cdf0e10cSrcweir         if ( m_aSupportedFeatures.end() != aInfo )
334cdf0e10cSrcweir             return aInfo->second.bCachedState;
335cdf0e10cSrcweir 
336cdf0e10cSrcweir         return false;
337cdf0e10cSrcweir     }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir     //------------------------------------------------------------------
getBooleanState(sal_Int16 _nFeatureId) const340cdf0e10cSrcweir     bool OFormNavigationHelper::getBooleanState( sal_Int16 _nFeatureId ) const
341cdf0e10cSrcweir     {
342cdf0e10cSrcweir         sal_Bool bState = sal_False;
343cdf0e10cSrcweir 
344cdf0e10cSrcweir         FeatureMap::const_iterator aInfo = m_aSupportedFeatures.find( _nFeatureId );
345cdf0e10cSrcweir         if ( m_aSupportedFeatures.end() != aInfo )
346cdf0e10cSrcweir             aInfo->second.aCachedAdditionalState >>= bState;
347cdf0e10cSrcweir 
348cdf0e10cSrcweir         return (bool)bState;
349cdf0e10cSrcweir     }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir     //------------------------------------------------------------------
getStringState(sal_Int16 _nFeatureId) const352cdf0e10cSrcweir     ::rtl::OUString OFormNavigationHelper::getStringState( sal_Int16 _nFeatureId ) const
353cdf0e10cSrcweir     {
354cdf0e10cSrcweir         ::rtl::OUString sState;
355cdf0e10cSrcweir 
356cdf0e10cSrcweir         FeatureMap::const_iterator aInfo = m_aSupportedFeatures.find( _nFeatureId );
357cdf0e10cSrcweir         if ( m_aSupportedFeatures.end() != aInfo )
358cdf0e10cSrcweir             aInfo->second.aCachedAdditionalState >>= sState;
359cdf0e10cSrcweir 
360cdf0e10cSrcweir         return sState;
361cdf0e10cSrcweir     }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir     //------------------------------------------------------------------
getIntegerState(sal_Int16 _nFeatureId) const364cdf0e10cSrcweir     sal_Int32 OFormNavigationHelper::getIntegerState( sal_Int16 _nFeatureId ) const
365cdf0e10cSrcweir     {
366cdf0e10cSrcweir         sal_Int32 nState = 0;
367cdf0e10cSrcweir 
368cdf0e10cSrcweir         FeatureMap::const_iterator aInfo = m_aSupportedFeatures.find( _nFeatureId );
369cdf0e10cSrcweir         if ( m_aSupportedFeatures.end() != aInfo )
370cdf0e10cSrcweir             aInfo->second.aCachedAdditionalState >>= nState;
371cdf0e10cSrcweir 
372cdf0e10cSrcweir         return nState;
373cdf0e10cSrcweir     }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir     //------------------------------------------------------------------
invalidateSupportedFeaturesSet()376cdf0e10cSrcweir     void OFormNavigationHelper::invalidateSupportedFeaturesSet()
377cdf0e10cSrcweir     {
378cdf0e10cSrcweir         disconnectDispatchers( );
379cdf0e10cSrcweir         // no supported features anymore:
380cdf0e10cSrcweir         FeatureMap aEmpty;
381cdf0e10cSrcweir         m_aSupportedFeatures.swap( aEmpty );
382cdf0e10cSrcweir     }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir     //==================================================================
385cdf0e10cSrcweir     //= OFormNavigationMapper
386cdf0e10cSrcweir     //==================================================================
387cdf0e10cSrcweir     //------------------------------------------------------------------
OFormNavigationMapper(const Reference<XMultiServiceFactory> & _rxORB)388cdf0e10cSrcweir     OFormNavigationMapper::OFormNavigationMapper( const Reference< XMultiServiceFactory >& _rxORB )
389cdf0e10cSrcweir     {
390cdf0e10cSrcweir         m_pUrlTransformer.reset( new UrlTransformer( _rxORB ) );
391cdf0e10cSrcweir     }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir     //------------------------------------------------------------------
~OFormNavigationMapper()394cdf0e10cSrcweir     OFormNavigationMapper::~OFormNavigationMapper( )
395cdf0e10cSrcweir     {
396cdf0e10cSrcweir     }
397cdf0e10cSrcweir 
398cdf0e10cSrcweir     //------------------------------------------------------------------
getFeatureURL(sal_Int16 _nFeatureId,URL & _rURL)399cdf0e10cSrcweir     bool OFormNavigationMapper::getFeatureURL( sal_Int16 _nFeatureId, URL& /* [out] */ _rURL )
400cdf0e10cSrcweir     {
401cdf0e10cSrcweir         // get the ascii version of the URL
402cdf0e10cSrcweir         const char* pAsciiURL = getFeatureURLAscii( _nFeatureId );
403cdf0e10cSrcweir         if ( pAsciiURL )
404cdf0e10cSrcweir             _rURL = m_pUrlTransformer->getStrictURLFromAscii( pAsciiURL );
405cdf0e10cSrcweir 
406cdf0e10cSrcweir         return ( pAsciiURL != NULL );
407cdf0e10cSrcweir     }
408cdf0e10cSrcweir 
409cdf0e10cSrcweir     //------------------------------------------------------------------
410cdf0e10cSrcweir     namespace
411cdf0e10cSrcweir     {
412cdf0e10cSrcweir         struct FeatureURL
413cdf0e10cSrcweir         {
414cdf0e10cSrcweir             const sal_Int16 nFormFeature;
415cdf0e10cSrcweir             const sal_Char* pAsciiURL;
416cdf0e10cSrcweir 
FeatureURLfrm::__anon6a44a3a00111::FeatureURL417cdf0e10cSrcweir             FeatureURL( const sal_Int16 _nFormFeature, const sal_Char* _pAsciiURL )
418cdf0e10cSrcweir                 :nFormFeature( _nFormFeature )
419cdf0e10cSrcweir                 ,pAsciiURL( _pAsciiURL )
420cdf0e10cSrcweir             {
421cdf0e10cSrcweir             }
422cdf0e10cSrcweir         };
lcl_getFeatureTable()423cdf0e10cSrcweir         const FeatureURL* lcl_getFeatureTable()
424cdf0e10cSrcweir         {
425cdf0e10cSrcweir             static const FeatureURL s_aFeatureURLs[] =
426cdf0e10cSrcweir             {
427cdf0e10cSrcweir                 FeatureURL( FormFeature::MoveAbsolute,            URL_FORM_POSITION ),
428cdf0e10cSrcweir                 FeatureURL( FormFeature::TotalRecords,            URL_FORM_RECORDCOUNT ),
429cdf0e10cSrcweir                 FeatureURL( FormFeature::MoveToFirst,             URL_RECORD_FIRST ),
430cdf0e10cSrcweir                 FeatureURL( FormFeature::MoveToPrevious,          URL_RECORD_PREV ),
431cdf0e10cSrcweir                 FeatureURL( FormFeature::MoveToNext,              URL_RECORD_NEXT ),
432cdf0e10cSrcweir                 FeatureURL( FormFeature::MoveToLast,              URL_RECORD_LAST ),
433cdf0e10cSrcweir                 FeatureURL( FormFeature::SaveRecordChanges,       URL_RECORD_SAVE ),
434cdf0e10cSrcweir                 FeatureURL( FormFeature::UndoRecordChanges,       URL_RECORD_UNDO ),
435cdf0e10cSrcweir                 FeatureURL( FormFeature::MoveToInsertRow,         URL_RECORD_NEW ),
436cdf0e10cSrcweir                 FeatureURL( FormFeature::DeleteRecord,            URL_RECORD_DELETE ),
437cdf0e10cSrcweir                 FeatureURL( FormFeature::ReloadForm,              URL_FORM_REFRESH ),
438cdf0e10cSrcweir                 FeatureURL( FormFeature::RefreshCurrentControl,   URL_FORM_REFRESH_CURRENT_CONTROL ),
439cdf0e10cSrcweir                 FeatureURL( FormFeature::SortAscending,           URL_FORM_SORT_UP ),
440cdf0e10cSrcweir                 FeatureURL( FormFeature::SortDescending,          URL_FORM_SORT_DOWN ),
441cdf0e10cSrcweir                 FeatureURL( FormFeature::InteractiveSort,         URL_FORM_SORT ),
442cdf0e10cSrcweir                 FeatureURL( FormFeature::AutoFilter,              URL_FORM_AUTO_FILTER ),
443cdf0e10cSrcweir                 FeatureURL( FormFeature::InteractiveFilter,       URL_FORM_FILTER ),
444cdf0e10cSrcweir                 FeatureURL( FormFeature::ToggleApplyFilter,       URL_FORM_APPLY_FILTER ),
445cdf0e10cSrcweir                 FeatureURL( FormFeature::RemoveFilterAndSort,     URL_FORM_REMOVE_FILTER ),
446cdf0e10cSrcweir                 FeatureURL( 0, NULL )
447cdf0e10cSrcweir             };
448cdf0e10cSrcweir             return s_aFeatureURLs;
449cdf0e10cSrcweir         }
450cdf0e10cSrcweir     }
451cdf0e10cSrcweir 
452cdf0e10cSrcweir     //------------------------------------------------------------------
getFeatureURLAscii(sal_Int16 _nFeatureId)453cdf0e10cSrcweir     const char* OFormNavigationMapper::getFeatureURLAscii( sal_Int16 _nFeatureId )
454cdf0e10cSrcweir     {
455cdf0e10cSrcweir         const FeatureURL* pFeatures = lcl_getFeatureTable();
456cdf0e10cSrcweir         while ( pFeatures->pAsciiURL )
457cdf0e10cSrcweir         {
458cdf0e10cSrcweir             if ( pFeatures->nFormFeature == _nFeatureId )
459cdf0e10cSrcweir                 return pFeatures->pAsciiURL;
460cdf0e10cSrcweir             ++pFeatures;
461cdf0e10cSrcweir         }
462cdf0e10cSrcweir         return NULL;
463cdf0e10cSrcweir     }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir     //------------------------------------------------------------------
getFeatureId(const::rtl::OUString & _rCompleteURL)466cdf0e10cSrcweir     sal_Int16 OFormNavigationMapper::getFeatureId( const ::rtl::OUString& _rCompleteURL )
467cdf0e10cSrcweir     {
468cdf0e10cSrcweir         const FeatureURL* pFeatures = lcl_getFeatureTable();
469cdf0e10cSrcweir         while ( pFeatures->pAsciiURL )
470cdf0e10cSrcweir         {
471cdf0e10cSrcweir             if ( _rCompleteURL.compareToAscii( pFeatures->pAsciiURL ) == 0 )
472cdf0e10cSrcweir                 return pFeatures->nFormFeature;
473cdf0e10cSrcweir             ++pFeatures;
474cdf0e10cSrcweir         }
475cdf0e10cSrcweir         return -1;
476cdf0e10cSrcweir     }
477cdf0e10cSrcweir 
478cdf0e10cSrcweir //.........................................................................
479cdf0e10cSrcweir }   // namespace frm
480cdf0e10cSrcweir //.........................................................................
481