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 <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>
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
;
46 ButtonToolbarController::ButtonToolbarController(
47 uno::Reference
< uno::XComponentContext
> xContext
,
50 m_bInitialized( false ),
52 m_aCommandURL(std::move( aCommand
)),
53 m_xContext(std::move( xContext
)),
54 m_pToolbar( pToolBar
)
58 ButtonToolbarController::~ButtonToolbarController()
63 uno::Any SAL_CALL
ButtonToolbarController::queryInterface( const uno::Type
& rType
)
65 Any a
= ::cppu::queryInterface(
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 ));
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();
90 void SAL_CALL
ButtonToolbarController::initialize(
91 const css::uno::Sequence
< css::uno::Any
>& aArguments
)
93 SolarMutexGuard aSolarMutexGuard
;
96 throw DisposedException();
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
);
122 void SAL_CALL
ButtonToolbarController::dispose()
124 Reference
< XComponent
> xThis
= this;
127 SolarMutexGuard aSolarMutexGuard
;
132 m_xURLTransformer
.clear();
139 void SAL_CALL
ButtonToolbarController::addEventListener(
140 const css::uno::Reference
< css::lang::XEventListener
>& )
145 void SAL_CALL
ButtonToolbarController::removeEventListener(
146 const css::uno::Reference
< css::lang::XEventListener
>& )
152 void SAL_CALL
ButtonToolbarController::update()
154 SolarMutexGuard aSolarMutexGuard
;
156 throw DisposedException();
160 void SAL_CALL
ButtonToolbarController::disposing(
161 const css::lang::EventObject
& Source
)
163 uno::Reference
< uno::XInterface
> xSource( Source
.Source
);
165 SolarMutexGuard aSolarMutexGuard
;
170 uno::Reference
< uno::XInterface
> xIfac( m_xFrame
, uno::UNO_QUERY
);
171 if ( xIfac
== xSource
)
175 void SAL_CALL
ButtonToolbarController::statusChanged( const css::frame::FeatureStateEvent
& )
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
;
195 throw DisposedException();
197 if ( m_bInitialized
&&
200 !m_aCommandURL
.isEmpty() )
202 if ( !m_xURLTransformer
.is() )
204 m_xURLTransformer
= util::URLTransformer::create( m_xContext
);
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() )
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
;
241 throw DisposedException();
243 sal_Int16
nKeyModifier( static_cast<sal_Int16
>(m_pToolbar
->GetModifier()) );
244 execute( nKeyModifier
);
247 void SAL_CALL
ButtonToolbarController::doubleClick()
251 throw DisposedException();
254 uno::Reference
< awt::XWindow
> SAL_CALL
ButtonToolbarController::createPopupWindow()
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
>& )
266 throw DisposedException();
268 return uno::Reference
< awt::XWindow
>();
273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */