nss: upgrade to release 3.73
[LibreOffice.git] / forms / source / helper / controlfeatureinterception.cxx
blob1e0d0fbcd03da1d1df74740412e82367d7ee15c7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include <controlfeatureinterception.hxx>
21 #include <urltransformer.hxx>
22 #include <osl/diagnose.h>
25 namespace frm
29 using namespace ::com::sun::star::uno;
30 using namespace ::com::sun::star::frame;
31 using namespace ::com::sun::star::util;
32 using namespace ::com::sun::star::lang;
34 ControlFeatureInterception::ControlFeatureInterception( const Reference< XComponentContext >& _rxORB )
35 :m_pUrlTransformer( new UrlTransformer( _rxORB ) )
40 void ControlFeatureInterception::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor )
42 if ( !_rxInterceptor.is() )
44 OSL_FAIL( "ControlFeatureInterception::registerDispatchProviderInterceptor: invalid interceptor!" );
45 return;
48 if ( m_xFirstDispatchInterceptor.is() )
50 // there is already an interceptor; the new one will become its master
51 _rxInterceptor->setSlaveDispatchProvider( m_xFirstDispatchInterceptor );
52 m_xFirstDispatchInterceptor->setMasterDispatchProvider( m_xFirstDispatchInterceptor );
55 // we are the master of the chain's first interceptor
56 m_xFirstDispatchInterceptor = _rxInterceptor;
57 m_xFirstDispatchInterceptor->setMasterDispatchProvider( nullptr );
58 // it's the first of the interceptor chain
62 void ControlFeatureInterception::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor )
64 if ( !_rxInterceptor.is() )
66 OSL_FAIL( "ControlFeatureInterception::releaseDispatchProviderInterceptor: invalid interceptor!" );
67 return;
70 Reference< XDispatchProviderInterceptor > xChainWalk( m_xFirstDispatchInterceptor );
72 if ( m_xFirstDispatchInterceptor == _rxInterceptor )
73 { // our chain will have a new first element
74 Reference< XDispatchProviderInterceptor > xSlave( m_xFirstDispatchInterceptor->getSlaveDispatchProvider(), UNO_QUERY );
75 m_xFirstDispatchInterceptor = xSlave;
77 // do this before removing the interceptor from the chain as we won't know it's slave afterwards)
79 while ( xChainWalk.is() )
81 // walk along the chain of interceptors and look for the interceptor that has to be removed
82 Reference< XDispatchProviderInterceptor > xSlave( xChainWalk->getSlaveDispatchProvider(), UNO_QUERY );
84 if ( xChainWalk == _rxInterceptor )
86 // old master may be an interceptor too
87 Reference< XDispatchProviderInterceptor > xMaster( xChainWalk->getMasterDispatchProvider(), UNO_QUERY );
89 // unchain the interceptor that has to be removed
90 xChainWalk->setSlaveDispatchProvider( nullptr );
91 xChainWalk->setMasterDispatchProvider( nullptr );
93 // reconnect the chain
94 if ( xMaster.is() )
96 xMaster->setSlaveDispatchProvider( Reference< XDispatchProvider >::query( xSlave ) );
99 // if somebody has registered the same interceptor twice, then we will remove
100 // it once per call ...
101 break;
104 xChainWalk = xSlave;
109 void ControlFeatureInterception::dispose()
111 // release all interceptors
112 Reference< XDispatchProviderInterceptor > xInterceptor( m_xFirstDispatchInterceptor );
113 m_xFirstDispatchInterceptor.clear();
114 while ( xInterceptor.is() )
116 // tell the interceptor it has a new (means no) predecessor
117 xInterceptor->setMasterDispatchProvider( nullptr );
119 // ask for its successor
120 Reference< XDispatchProvider > xSlave = xInterceptor->getSlaveDispatchProvider();
121 // and give it the new (means no) successoert
122 xInterceptor->setSlaveDispatchProvider( nullptr );
124 // start over with the next chain element
125 xInterceptor.set(xSlave, css::uno::UNO_QUERY);
129 Reference< XDispatch > ControlFeatureInterception::queryDispatch( const URL& _rURL )
131 Reference< XDispatch > xDispatcher;
132 if ( m_xFirstDispatchInterceptor.is() )
133 xDispatcher = m_xFirstDispatchInterceptor->queryDispatch( _rURL, OUString(), 0 );
134 return xDispatcher;
138 Reference< XDispatch > ControlFeatureInterception::queryDispatch( const char* _pAsciiURL )
140 return queryDispatch( m_pUrlTransformer->getStrictURLFromAscii( _pAsciiURL ) );
144 } // namespace frm
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */