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 #include <controlfeatureinterception.hxx>
21 #include <urltransformer.hxx>
22 #include <osl/diagnose.h>
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::frame
;
31 using namespace ::com::sun::star::util
;
33 ControlFeatureInterception::ControlFeatureInterception( const Reference
< XComponentContext
>& _rxORB
)
34 :m_pUrlTransformer( new UrlTransformer( _rxORB
) )
39 void ControlFeatureInterception::registerDispatchProviderInterceptor( const Reference
< XDispatchProviderInterceptor
>& _rxInterceptor
)
41 if ( !_rxInterceptor
.is() )
43 OSL_FAIL( "ControlFeatureInterception::registerDispatchProviderInterceptor: invalid interceptor!" );
47 if ( m_xFirstDispatchInterceptor
.is() )
49 // there is already an interceptor; the new one will become its master
50 _rxInterceptor
->setSlaveDispatchProvider( m_xFirstDispatchInterceptor
);
51 m_xFirstDispatchInterceptor
->setMasterDispatchProvider( m_xFirstDispatchInterceptor
);
54 // we are the master of the chain's first interceptor
55 m_xFirstDispatchInterceptor
= _rxInterceptor
;
56 m_xFirstDispatchInterceptor
->setMasterDispatchProvider( nullptr );
57 // it's the first of the interceptor chain
61 void ControlFeatureInterception::releaseDispatchProviderInterceptor( const Reference
< XDispatchProviderInterceptor
>& _rxInterceptor
)
63 if ( !_rxInterceptor
.is() )
65 OSL_FAIL( "ControlFeatureInterception::releaseDispatchProviderInterceptor: invalid interceptor!" );
69 Reference
< XDispatchProviderInterceptor
> xChainWalk( m_xFirstDispatchInterceptor
);
71 if ( m_xFirstDispatchInterceptor
== _rxInterceptor
)
72 { // our chain will have a new first element
73 m_xFirstDispatchInterceptor
.set(m_xFirstDispatchInterceptor
->getSlaveDispatchProvider(), UNO_QUERY
);
75 // do this before removing the interceptor from the chain as we won't know it's slave afterwards)
77 while ( xChainWalk
.is() )
79 // walk along the chain of interceptors and look for the interceptor that has to be removed
80 Reference
< XDispatchProviderInterceptor
> xSlave( xChainWalk
->getSlaveDispatchProvider(), UNO_QUERY
);
82 if ( xChainWalk
== _rxInterceptor
)
84 // old master may be an interceptor too
85 Reference
< XDispatchProviderInterceptor
> xMaster( xChainWalk
->getMasterDispatchProvider(), UNO_QUERY
);
87 // unchain the interceptor that has to be removed
88 xChainWalk
->setSlaveDispatchProvider( nullptr );
89 xChainWalk
->setMasterDispatchProvider( nullptr );
91 // reconnect the chain
94 xMaster
->setSlaveDispatchProvider( xSlave
);
97 // if somebody has registered the same interceptor twice, then we will remove
98 // it once per call ...
102 xChainWalk
= std::move(xSlave
);
107 void ControlFeatureInterception::dispose()
109 // release all interceptors
110 Reference
< XDispatchProviderInterceptor
> xInterceptor( m_xFirstDispatchInterceptor
);
111 m_xFirstDispatchInterceptor
.clear();
112 while ( xInterceptor
.is() )
114 // tell the interceptor it has a new (means no) predecessor
115 xInterceptor
->setMasterDispatchProvider( nullptr );
117 // ask for its successor
118 Reference
< XDispatchProvider
> xSlave
= xInterceptor
->getSlaveDispatchProvider();
119 // and give it the new (means no) successoert
120 xInterceptor
->setSlaveDispatchProvider( nullptr );
122 // start over with the next chain element
123 xInterceptor
.set(xSlave
, css::uno::UNO_QUERY
);
127 Reference
< XDispatch
> ControlFeatureInterception::queryDispatch( const URL
& _rURL
)
129 Reference
< XDispatch
> xDispatcher
;
130 if ( m_xFirstDispatchInterceptor
.is() )
131 xDispatcher
= m_xFirstDispatchInterceptor
->queryDispatch( _rURL
, OUString(), 0 );
136 Reference
< XDispatch
> ControlFeatureInterception::queryDispatch( const OUString
& _rURL
)
138 return queryDispatch( m_pUrlTransformer
->getStrictURL( _rURL
) );
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */