LibreOffice Module forms (master) 1
controlfeatureinterception.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include <urltransformer.hxx>
22#include <osl/diagnose.h>
23
24
25namespace frm
26{
27
28
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;
33
34 ControlFeatureInterception::ControlFeatureInterception( const Reference< XComponentContext >& _rxORB )
35 :m_pUrlTransformer( new UrlTransformer( _rxORB ) )
36 {
37 }
38
39
40 void ControlFeatureInterception::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor )
41 {
42 if ( !_rxInterceptor.is() )
43 {
44 OSL_FAIL( "ControlFeatureInterception::registerDispatchProviderInterceptor: invalid interceptor!" );
45 return;
46 }
47
49 {
50 // there is already an interceptor; the new one will become its master
51 _rxInterceptor->setSlaveDispatchProvider( m_xFirstDispatchInterceptor );
52 m_xFirstDispatchInterceptor->setMasterDispatchProvider( m_xFirstDispatchInterceptor );
53 }
54
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
59 }
60
61
62 void ControlFeatureInterception::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor )
63 {
64 if ( !_rxInterceptor.is() )
65 {
66 OSL_FAIL( "ControlFeatureInterception::releaseDispatchProviderInterceptor: invalid interceptor!" );
67 return;
68 }
69
70 Reference< XDispatchProviderInterceptor > xChainWalk( m_xFirstDispatchInterceptor );
71
72 if ( m_xFirstDispatchInterceptor == _rxInterceptor )
73 { // our chain will have a new first element
74 Reference< XDispatchProviderInterceptor > xSlave( m_xFirstDispatchInterceptor->getSlaveDispatchProvider(), UNO_QUERY );
76 }
77 // do this before removing the interceptor from the chain as we won't know it's slave afterwards)
78
79 while ( xChainWalk.is() )
80 {
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 );
83
84 if ( xChainWalk == _rxInterceptor )
85 {
86 // old master may be an interceptor too
87 Reference< XDispatchProviderInterceptor > xMaster( xChainWalk->getMasterDispatchProvider(), UNO_QUERY );
88
89 // unchain the interceptor that has to be removed
90 xChainWalk->setSlaveDispatchProvider( nullptr );
91 xChainWalk->setMasterDispatchProvider( nullptr );
92
93 // reconnect the chain
94 if ( xMaster.is() )
95 {
96 xMaster->setSlaveDispatchProvider( xSlave );
97 }
98
99 // if somebody has registered the same interceptor twice, then we will remove
100 // it once per call ...
101 break;
102 }
103
104 xChainWalk = xSlave;
105 }
106 }
107
108
110 {
111 // release all interceptors
112 Reference< XDispatchProviderInterceptor > xInterceptor( m_xFirstDispatchInterceptor );
114 while ( xInterceptor.is() )
115 {
116 // tell the interceptor it has a new (means no) predecessor
117 xInterceptor->setMasterDispatchProvider( nullptr );
118
119 // ask for its successor
120 Reference< XDispatchProvider > xSlave = xInterceptor->getSlaveDispatchProvider();
121 // and give it the new (means no) successoert
122 xInterceptor->setSlaveDispatchProvider( nullptr );
123
124 // start over with the next chain element
125 xInterceptor.set(xSlave, css::uno::UNO_QUERY);
126 }
127 }
128
129 Reference< XDispatch > ControlFeatureInterception::queryDispatch( const URL& _rURL )
130 {
131 Reference< XDispatch > xDispatcher;
133 xDispatcher = m_xFirstDispatchInterceptor->queryDispatch( _rURL, OUString(), 0 );
134 return xDispatcher;
135 }
136
137
138 Reference< XDispatch > ControlFeatureInterception::queryDispatch( const char* _pAsciiURL )
139 {
140 return queryDispatch( m_pUrlTransformer->getStrictURLFromAscii( _pAsciiURL ) );
141 }
142
143
144} // namespace frm
145
146
147/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void releaseDispatchProviderInterceptor(const css::uno::Reference< css::frame::XDispatchProviderInterceptor > &Interceptor)
css::uno::Reference< css::frame::XDispatchProviderInterceptor > m_xFirstDispatchInterceptor
void registerDispatchProviderInterceptor(const css::uno::Reference< css::frame::XDispatchProviderInterceptor > &Interceptor)
css::uno::Reference< css::frame::XDispatch > queryDispatch(const css::util::URL &_rURL)
queries the interceptor chain for the given dispatch, with a blank target frame and no frame search f...
ControlFeatureInterception(const css::uno::Reference< css::uno::XComponentContext > &_rxORB)
::std::unique_ptr< UrlTransformer > m_pUrlTransformer
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25