tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / framework / source / uielement / buttontoolbarcontroller.cxx
blob47b31bf99e8ad55a251ab34d1509ca9e0d296c3c
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 SolarMutexGuard aSolarMutexGuard;
95 if ( m_bDisposed )
96 throw DisposedException();
98 if ( m_bInitialized )
99 return;
101 m_bInitialized = true;
103 PropertyValue aPropValue;
104 for ( const css::uno::Any& rArg : aArguments )
106 if ( rArg >>= aPropValue )
108 if ( aPropValue.Name == "Frame" )
109 m_xFrame.set(aPropValue.Value,UNO_QUERY);
110 else if ( aPropValue.Name == "CommandURL" )
111 aPropValue.Value >>= m_aCommandURL;
112 else if ( aPropValue.Name == "ServiceManager" )
114 Reference<XMultiServiceFactory> xServiceManager(aPropValue.Value,UNO_QUERY);
115 m_xContext = comphelper::getComponentContext(xServiceManager);
121 // XComponent
122 void SAL_CALL ButtonToolbarController::dispose()
124 Reference< XComponent > xThis = this;
127 SolarMutexGuard aSolarMutexGuard;
128 if ( m_bDisposed )
129 return;
131 m_xContext.clear();
132 m_xURLTransformer.clear();
133 m_xFrame.clear();
134 m_pToolbar.clear();
135 m_bDisposed = true;
139 void SAL_CALL ButtonToolbarController::addEventListener(
140 const css::uno::Reference< css::lang::XEventListener >& )
142 // do nothing
145 void SAL_CALL ButtonToolbarController::removeEventListener(
146 const css::uno::Reference< css::lang::XEventListener >& )
148 // do nothing
151 // XUpdatable
152 void SAL_CALL ButtonToolbarController::update()
154 SolarMutexGuard aSolarMutexGuard;
155 if ( m_bDisposed )
156 throw DisposedException();
159 // XEventListener
160 void SAL_CALL ButtonToolbarController::disposing(
161 const css::lang::EventObject& Source )
163 uno::Reference< uno::XInterface > xSource( Source.Source );
165 SolarMutexGuard aSolarMutexGuard;
167 if ( m_bDisposed )
168 return;
170 uno::Reference< uno::XInterface > xIfac( m_xFrame, uno::UNO_QUERY );
171 if ( xIfac == xSource )
172 m_xFrame.clear();
175 void SAL_CALL ButtonToolbarController::statusChanged( const css::frame::FeatureStateEvent& )
177 // do nothing
178 if ( m_bDisposed )
179 throw DisposedException();
182 // XToolbarController
183 void SAL_CALL ButtonToolbarController::execute( sal_Int16 KeyModifier )
185 uno::Reference< frame::XDispatch > xDispatch;
186 uno::Reference< frame::XFrame > xFrame;
187 uno::Reference< util::XURLTransformer > xURLTransformer;
188 OUString aCommandURL;
189 css::util::URL aTargetURL;
192 SolarMutexGuard aSolarMutexGuard;
194 if ( m_bDisposed )
195 throw DisposedException();
197 if ( m_bInitialized &&
198 m_xFrame.is() &&
199 m_xContext.is() &&
200 !m_aCommandURL.isEmpty() )
202 if ( !m_xURLTransformer.is() )
204 m_xURLTransformer = util::URLTransformer::create( m_xContext );
207 xFrame = m_xFrame;
208 aCommandURL = m_aCommandURL;
209 xURLTransformer = m_xURLTransformer;
213 uno::Reference< frame::XDispatchProvider > xDispatchProvider( xFrame, uno::UNO_QUERY );
214 if ( xDispatchProvider.is() )
216 aTargetURL.Complete = aCommandURL;
217 xURLTransformer->parseStrict( aTargetURL );
218 xDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 );
221 if ( !xDispatch.is() )
222 return;
226 // Provide key modifier information to dispatch function
227 Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue(u"KeyModifier"_ustr, KeyModifier) };
229 xDispatch->dispatch( aTargetURL, aArgs );
231 catch ( const DisposedException& )
236 void SAL_CALL ButtonToolbarController::click()
238 SolarMutexGuard aSolarMutexGuard;
240 if ( m_bDisposed )
241 throw DisposedException();
243 sal_Int16 nKeyModifier( static_cast<sal_Int16>(m_pToolbar->GetModifier()) );
244 execute( nKeyModifier );
247 void SAL_CALL ButtonToolbarController::doubleClick()
249 // do nothing
250 if ( m_bDisposed )
251 throw DisposedException();
254 uno::Reference< awt::XWindow > SAL_CALL ButtonToolbarController::createPopupWindow()
256 if ( m_bDisposed )
257 throw DisposedException();
259 return uno::Reference< awt::XWindow >();
262 uno::Reference< awt::XWindow > SAL_CALL ButtonToolbarController::createItemWindow(
263 const css::uno::Reference< css::awt::XWindow >& )
265 if ( m_bDisposed )
266 throw DisposedException();
268 return uno::Reference< awt::XWindow >();
271 } // namespace
273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */