calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / framework / source / uielement / buttontoolbarcontroller.cxx
blob4972b6da7667d45c08c0bab35f3e35f131685634
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 <uielement/buttontoolbarcontroller.hxx>
22 #include <com/sun/star/util/URLTransformer.hpp>
23 #include <com/sun/star/frame/XDispatchProvider.hpp>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/lang/DisposedException.hpp>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <cppuhelper/queryinterface.hxx>
29 #include <comphelper/processfactory.hxx>
30 #include <comphelper/propertyvalue.hxx>
31 #include <utility>
32 #include <vcl/svapp.hxx>
33 #include <vcl/toolbox.hxx>
35 using namespace ::com::sun::star;
36 using namespace css::awt;
37 using namespace css::uno;
38 using namespace css::beans;
39 using namespace css::lang;
40 using namespace css::frame;
41 using namespace css::util;
43 namespace framework
46 ButtonToolbarController::ButtonToolbarController(
47 uno::Reference< uno::XComponentContext > xContext,
48 ToolBox* pToolBar,
49 OUString aCommand ) :
50 m_bInitialized( false ),
51 m_bDisposed( false ),
52 m_aCommandURL(std::move( aCommand )),
53 m_xContext(std::move( xContext )),
54 m_pToolbar( pToolBar )
58 ButtonToolbarController::~ButtonToolbarController()
62 // XInterface
63 uno::Any SAL_CALL ButtonToolbarController::queryInterface( const uno::Type& rType )
65 Any a = ::cppu::queryInterface(
66 rType ,
67 static_cast< frame::XStatusListener* >( this ),
68 static_cast< frame::XToolbarController* >( this ),
69 static_cast< lang::XInitialization* >( this ),
70 static_cast< lang::XComponent* >( this ),
71 static_cast< util::XUpdatable* >( this ));
73 if ( a.hasValue() )
74 return a;
76 return cppu::OWeakObject::queryInterface( rType );
79 void SAL_CALL ButtonToolbarController::acquire() noexcept
81 cppu::OWeakObject::acquire();
84 void SAL_CALL ButtonToolbarController::release() noexcept
86 cppu::OWeakObject::release();
89 // XInitialization
90 void SAL_CALL ButtonToolbarController::initialize(
91 const css::uno::Sequence< css::uno::Any >& aArguments )
93 bool bInitialized( true );
96 SolarMutexGuard aSolarMutexGuard;
98 if ( m_bDisposed )
99 throw DisposedException();
101 bInitialized = m_bInitialized;
104 if ( bInitialized )
105 return;
107 SolarMutexGuard aSolarMutexGuard;
108 m_bInitialized = true;
110 PropertyValue aPropValue;
111 for ( const css::uno::Any& rArg : aArguments )
113 if ( rArg >>= aPropValue )
115 if ( aPropValue.Name == "Frame" )
116 m_xFrame.set(aPropValue.Value,UNO_QUERY);
117 else if ( aPropValue.Name == "CommandURL" )
118 aPropValue.Value >>= m_aCommandURL;
119 else if ( aPropValue.Name == "ServiceManager" )
121 Reference<XMultiServiceFactory> xServiceManager(aPropValue.Value,UNO_QUERY);
122 m_xContext = comphelper::getComponentContext(xServiceManager);
128 // XComponent
129 void SAL_CALL ButtonToolbarController::dispose()
131 Reference< XComponent > xThis = this;
134 SolarMutexGuard aSolarMutexGuard;
135 if ( m_bDisposed )
136 throw DisposedException();
138 m_xContext.clear();
139 m_xURLTransformer.clear();
140 m_xFrame.clear();
141 m_pToolbar.clear();
142 m_bDisposed = true;
146 void SAL_CALL ButtonToolbarController::addEventListener(
147 const css::uno::Reference< css::lang::XEventListener >& )
149 // do nothing
152 void SAL_CALL ButtonToolbarController::removeEventListener(
153 const css::uno::Reference< css::lang::XEventListener >& )
155 // do nothing
158 // XUpdatable
159 void SAL_CALL ButtonToolbarController::update()
161 SolarMutexGuard aSolarMutexGuard;
162 if ( m_bDisposed )
163 throw DisposedException();
166 // XEventListener
167 void SAL_CALL ButtonToolbarController::disposing(
168 const css::lang::EventObject& Source )
170 uno::Reference< uno::XInterface > xSource( Source.Source );
172 SolarMutexGuard aSolarMutexGuard;
174 if ( m_bDisposed )
175 return;
177 uno::Reference< uno::XInterface > xIfac( m_xFrame, uno::UNO_QUERY );
178 if ( xIfac == xSource )
179 m_xFrame.clear();
182 void SAL_CALL ButtonToolbarController::statusChanged( const css::frame::FeatureStateEvent& )
184 // do nothing
185 if ( m_bDisposed )
186 throw DisposedException();
189 // XToolbarController
190 void SAL_CALL ButtonToolbarController::execute( sal_Int16 KeyModifier )
192 uno::Reference< frame::XDispatch > xDispatch;
193 uno::Reference< frame::XFrame > xFrame;
194 uno::Reference< util::XURLTransformer > xURLTransformer;
195 OUString aCommandURL;
196 css::util::URL aTargetURL;
199 SolarMutexGuard aSolarMutexGuard;
201 if ( m_bDisposed )
202 throw DisposedException();
204 if ( m_bInitialized &&
205 m_xFrame.is() &&
206 m_xContext.is() &&
207 !m_aCommandURL.isEmpty() )
209 if ( !m_xURLTransformer.is() )
211 m_xURLTransformer = util::URLTransformer::create( m_xContext );
214 xFrame = m_xFrame;
215 aCommandURL = m_aCommandURL;
216 xURLTransformer = m_xURLTransformer;
220 uno::Reference< frame::XDispatchProvider > xDispatchProvider( xFrame, uno::UNO_QUERY );
221 if ( xDispatchProvider.is() )
223 aTargetURL.Complete = aCommandURL;
224 xURLTransformer->parseStrict( aTargetURL );
225 xDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 );
228 if ( !xDispatch.is() )
229 return;
233 // Provide key modifier information to dispatch function
234 Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue("KeyModifier", KeyModifier) };
236 xDispatch->dispatch( aTargetURL, aArgs );
238 catch ( const DisposedException& )
243 void SAL_CALL ButtonToolbarController::click()
245 SolarMutexGuard aSolarMutexGuard;
247 if ( m_bDisposed )
248 throw DisposedException();
250 sal_Int16 nKeyModifier( static_cast<sal_Int16>(m_pToolbar->GetModifier()) );
251 execute( nKeyModifier );
254 void SAL_CALL ButtonToolbarController::doubleClick()
256 // do nothing
257 if ( m_bDisposed )
258 throw DisposedException();
261 uno::Reference< awt::XWindow > SAL_CALL ButtonToolbarController::createPopupWindow()
263 if ( m_bDisposed )
264 throw DisposedException();
266 return uno::Reference< awt::XWindow >();
269 uno::Reference< awt::XWindow > SAL_CALL ButtonToolbarController::createItemWindow(
270 const css::uno::Reference< css::awt::XWindow >& )
272 if ( m_bDisposed )
273 throw DisposedException();
275 return uno::Reference< awt::XWindow >();
278 } // namespace
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */