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 bool bInitialized( true );
96 SolarMutexGuard aSolarMutexGuard
;
99 throw DisposedException();
101 bInitialized
= m_bInitialized
;
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
);
129 void SAL_CALL
ButtonToolbarController::dispose()
131 Reference
< XComponent
> xThis
= this;
134 SolarMutexGuard aSolarMutexGuard
;
136 throw DisposedException();
139 m_xURLTransformer
.clear();
146 void SAL_CALL
ButtonToolbarController::addEventListener(
147 const css::uno::Reference
< css::lang::XEventListener
>& )
152 void SAL_CALL
ButtonToolbarController::removeEventListener(
153 const css::uno::Reference
< css::lang::XEventListener
>& )
159 void SAL_CALL
ButtonToolbarController::update()
161 SolarMutexGuard aSolarMutexGuard
;
163 throw DisposedException();
167 void SAL_CALL
ButtonToolbarController::disposing(
168 const css::lang::EventObject
& Source
)
170 uno::Reference
< uno::XInterface
> xSource( Source
.Source
);
172 SolarMutexGuard aSolarMutexGuard
;
177 uno::Reference
< uno::XInterface
> xIfac( m_xFrame
, uno::UNO_QUERY
);
178 if ( xIfac
== xSource
)
182 void SAL_CALL
ButtonToolbarController::statusChanged( const css::frame::FeatureStateEvent
& )
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
;
202 throw DisposedException();
204 if ( m_bInitialized
&&
207 !m_aCommandURL
.isEmpty() )
209 if ( !m_xURLTransformer
.is() )
211 m_xURLTransformer
= util::URLTransformer::create( m_xContext
);
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() )
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
;
248 throw DisposedException();
250 sal_Int16
nKeyModifier( static_cast<sal_Int16
>(m_pToolbar
->GetModifier()) );
251 execute( nKeyModifier
);
254 void SAL_CALL
ButtonToolbarController::doubleClick()
258 throw DisposedException();
261 uno::Reference
< awt::XWindow
> SAL_CALL
ButtonToolbarController::createPopupWindow()
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
>& )
273 throw DisposedException();
275 return uno::Reference
< awt::XWindow
>();
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */