1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6d739b60SAndrew Rist  * distributed with this work for additional information
6*6d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6d739b60SAndrew Rist  *
11*6d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6d739b60SAndrew Rist  *
13*6d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist  * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
17*6d739b60SAndrew Rist  * specific language governing permissions and limitations
18*6d739b60SAndrew Rist  * under the License.
19*6d739b60SAndrew Rist  *
20*6d739b60SAndrew Rist  *************************************************************/
21*6d739b60SAndrew Rist 
22*6d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_BUTTONTOOLBARCONTROLLER_HXX
28cdf0e10cSrcweir #include "uielement/buttontoolbarcontroller.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir 
31cdf0e10cSrcweir //_________________________________________________________________________________________________________________
32cdf0e10cSrcweir //  my own includes
33cdf0e10cSrcweir //_________________________________________________________________________________________________________________
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #ifndef __FRAMEWORK_TOOLBAR_HXX_
36cdf0e10cSrcweir #include "uielement/toolbar.hxx"
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //_________________________________________________________________________________________________________________
40cdf0e10cSrcweir //  interface includes
41cdf0e10cSrcweir //_________________________________________________________________________________________________________________
42cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
43cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
44cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
45cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
46cdf0e10cSrcweir #include "com/sun/star/util/XMacroExpander.hpp"
47cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
48cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp"
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //_________________________________________________________________________________________________________________
51cdf0e10cSrcweir //  other includes
52cdf0e10cSrcweir //_________________________________________________________________________________________________________________
53cdf0e10cSrcweir 
54cdf0e10cSrcweir #include <rtl/uri.hxx>
55cdf0e10cSrcweir #include <vos/mutex.hxx>
56cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
57cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
58cdf0e10cSrcweir #include <tools/urlobj.hxx>
59cdf0e10cSrcweir #include <vcl/svapp.hxx>
60cdf0e10cSrcweir #include <vcl/mnemonic.hxx>
61cdf0e10cSrcweir #include <vcl/window.hxx>
62cdf0e10cSrcweir #include <vcl/graph.hxx>
63cdf0e10cSrcweir #include <vcl/bitmap.hxx>
64cdf0e10cSrcweir #include <svtools/filter.hxx>
65cdf0e10cSrcweir #include <svtools/miscopt.hxx>
66cdf0e10cSrcweir #include <dispatch/uieventloghelper.hxx>
67cdf0e10cSrcweir 
68cdf0e10cSrcweir using namespace ::com::sun::star;
69cdf0e10cSrcweir using namespace ::com::sun::star::awt;
70cdf0e10cSrcweir using namespace ::com::sun::star::uno;
71cdf0e10cSrcweir using namespace ::com::sun::star::beans;
72cdf0e10cSrcweir using namespace ::com::sun::star::lang;
73cdf0e10cSrcweir using namespace ::com::sun::star::frame;
74cdf0e10cSrcweir using namespace ::com::sun::star::util;
75cdf0e10cSrcweir 
76cdf0e10cSrcweir namespace framework
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 
ButtonToolbarController(const uno::Reference<lang::XMultiServiceFactory> & rServiceManager,ToolBox * pToolBar,const rtl::OUString & aCommand)79cdf0e10cSrcweir ButtonToolbarController::ButtonToolbarController(
80cdf0e10cSrcweir     const uno::Reference< lang::XMultiServiceFactory >& rServiceManager,
81cdf0e10cSrcweir     ToolBox*                                            pToolBar,
82cdf0e10cSrcweir     const rtl::OUString&                                aCommand ) :
83cdf0e10cSrcweir     cppu::OWeakObject(),
84cdf0e10cSrcweir     m_bInitialized( sal_False ),
85cdf0e10cSrcweir     m_bDisposed( sal_False ),
86cdf0e10cSrcweir     m_aCommandURL( aCommand ),
87cdf0e10cSrcweir     m_xServiceManager( rServiceManager ),
88cdf0e10cSrcweir     m_pToolbar( pToolBar )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
~ButtonToolbarController()92cdf0e10cSrcweir ButtonToolbarController::~ButtonToolbarController()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         // XInterface
queryInterface(const uno::Type & rType)97cdf0e10cSrcweir uno::Any SAL_CALL ButtonToolbarController::queryInterface( const uno::Type& rType )
98cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir     Any a = ::cppu::queryInterface(
101cdf0e10cSrcweir                 rType ,
102cdf0e10cSrcweir                 static_cast< frame::XStatusListener* >( this ),
103cdf0e10cSrcweir                 static_cast< frame::XToolbarController* >( this ),
104cdf0e10cSrcweir                 static_cast< lang::XInitialization* >( this ),
105cdf0e10cSrcweir                 static_cast< lang::XComponent* >( this ),
106cdf0e10cSrcweir                 static_cast< util::XUpdatable* >( this ));
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     if ( a.hasValue() )
109cdf0e10cSrcweir         return a;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     return cppu::OWeakObject::queryInterface( rType );
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
acquire()114cdf0e10cSrcweir void SAL_CALL ButtonToolbarController::acquire() throw ()
115cdf0e10cSrcweir {
116cdf0e10cSrcweir     cppu::OWeakObject::acquire();
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
release()119cdf0e10cSrcweir void SAL_CALL ButtonToolbarController::release() throw ()
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     cppu::OWeakObject::release();
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir // XInitialization
initialize(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> & aArguments)125cdf0e10cSrcweir void SAL_CALL ButtonToolbarController::initialize(
126cdf0e10cSrcweir     const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
127cdf0e10cSrcweir throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     const rtl::OUString aFrameName( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
130cdf0e10cSrcweir     const rtl::OUString aCommandURLName( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" ));
131cdf0e10cSrcweir     const rtl::OUString aServiceManagerName( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" ));
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     bool bInitialized( true );
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         if ( m_bDisposed )
139cdf0e10cSrcweir             throw DisposedException();
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         bInitialized = m_bInitialized;
142cdf0e10cSrcweir     }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     if ( !bInitialized )
145cdf0e10cSrcweir     {
146cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
147cdf0e10cSrcweir         m_bInitialized = sal_True;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         PropertyValue aPropValue;
150cdf0e10cSrcweir         for ( int i = 0; i < aArguments.getLength(); i++ )
151cdf0e10cSrcweir         {
152cdf0e10cSrcweir             if ( aArguments[i] >>= aPropValue )
153cdf0e10cSrcweir             {
154cdf0e10cSrcweir                 if ( aPropValue.Name.equalsAscii( "Frame" ))
155cdf0e10cSrcweir                     m_xFrame.set(aPropValue.Value,UNO_QUERY);
156cdf0e10cSrcweir                 else if ( aPropValue.Name.equalsAscii( "CommandURL" ))
157cdf0e10cSrcweir                     aPropValue.Value >>= m_aCommandURL;
158cdf0e10cSrcweir                 else if ( aPropValue.Name.equalsAscii( "ServiceManager" ))
159cdf0e10cSrcweir                     m_xServiceManager.set(aPropValue.Value,UNO_QUERY);
160cdf0e10cSrcweir             }
161cdf0e10cSrcweir         }
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir // XComponent
dispose()166cdf0e10cSrcweir void SAL_CALL ButtonToolbarController::dispose() throw (::com::sun::star::uno::RuntimeException)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     {
171cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
172cdf0e10cSrcweir         if ( m_bDisposed )
173cdf0e10cSrcweir             throw DisposedException();
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         m_xServiceManager.clear();
176cdf0e10cSrcweir         m_xURLTransformer.clear();
177cdf0e10cSrcweir         m_xFrame.clear();
178cdf0e10cSrcweir         m_pToolbar = 0;
179cdf0e10cSrcweir         m_bDisposed = sal_True;
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
addEventListener(const::com::sun::star::uno::Reference<::com::sun::star::lang::XEventListener> &)183cdf0e10cSrcweir void SAL_CALL ButtonToolbarController::addEventListener(
184cdf0e10cSrcweir     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& )
185cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir     // do nothing
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
removeEventListener(const::com::sun::star::uno::Reference<::com::sun::star::lang::XEventListener> &)190cdf0e10cSrcweir void SAL_CALL ButtonToolbarController::removeEventListener(
191cdf0e10cSrcweir     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& )
192cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir     // do nothing
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir // XUpdatable
update()198cdf0e10cSrcweir void SAL_CALL ButtonToolbarController::update()
199cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
202cdf0e10cSrcweir     if ( m_bDisposed )
203cdf0e10cSrcweir         throw DisposedException();
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir // XEventListener
disposing(const com::sun::star::lang::EventObject & Source)207cdf0e10cSrcweir void SAL_CALL ButtonToolbarController::disposing(
208cdf0e10cSrcweir     const com::sun::star::lang::EventObject& Source )
209cdf0e10cSrcweir throw ( ::com::sun::star::uno::RuntimeException )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir     uno::Reference< uno::XInterface > xSource( Source.Source );
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     if ( m_bDisposed )
216cdf0e10cSrcweir         return;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     uno::Reference< uno::XInterface > xIfac( m_xFrame, uno::UNO_QUERY );
219cdf0e10cSrcweir     if ( xIfac == xSource )
220cdf0e10cSrcweir         m_xFrame.clear();
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
statusChanged(const::com::sun::star::frame::FeatureStateEvent &)223cdf0e10cSrcweir void SAL_CALL ButtonToolbarController::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& )
224cdf0e10cSrcweir throw ( ::com::sun::star::uno::RuntimeException )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir     // do nothing
227cdf0e10cSrcweir     if ( m_bDisposed )
228cdf0e10cSrcweir         throw DisposedException();
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir // XToolbarController
execute(sal_Int16 KeyModifier)232cdf0e10cSrcweir void SAL_CALL ButtonToolbarController::execute( sal_Int16 KeyModifier )
233cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir     uno::Reference< frame::XDispatch >      xDispatch;
236cdf0e10cSrcweir     uno::Reference< frame::XFrame >         xFrame;
237cdf0e10cSrcweir     uno::Reference< util::XURLTransformer > xURLTransformer;
238cdf0e10cSrcweir     rtl::OUString                           aCommandURL;
239cdf0e10cSrcweir     ::com::sun::star::util::URL             aTargetURL;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     {
242cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
243cdf0e10cSrcweir 
244cdf0e10cSrcweir         if ( m_bDisposed )
245cdf0e10cSrcweir             throw DisposedException();
246cdf0e10cSrcweir 
247cdf0e10cSrcweir         if ( m_bInitialized &&
248cdf0e10cSrcweir              m_xFrame.is() &&
249cdf0e10cSrcweir              m_xServiceManager.is() &&
250cdf0e10cSrcweir              m_aCommandURL.getLength() )
251cdf0e10cSrcweir         {
252cdf0e10cSrcweir             if ( !m_xURLTransformer.is() )
253cdf0e10cSrcweir             {
254cdf0e10cSrcweir                 m_xURLTransformer = uno::Reference< util::XURLTransformer >(
255cdf0e10cSrcweir                     m_xServiceManager->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ))),
256cdf0e10cSrcweir                     uno::UNO_QUERY_THROW );
257cdf0e10cSrcweir             }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir             xFrame          = m_xFrame;
260cdf0e10cSrcweir             aCommandURL     = m_aCommandURL;
261cdf0e10cSrcweir             xURLTransformer = m_xURLTransformer;
262cdf0e10cSrcweir         }
263cdf0e10cSrcweir     }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     uno::Reference< frame::XDispatchProvider > xDispatchProvider( xFrame, uno::UNO_QUERY );
266cdf0e10cSrcweir     if ( xDispatchProvider.is() )
267cdf0e10cSrcweir     {
268cdf0e10cSrcweir         aTargetURL.Complete = aCommandURL;
269cdf0e10cSrcweir         xURLTransformer->parseStrict( aTargetURL );
270cdf0e10cSrcweir         xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
271cdf0e10cSrcweir     }
272cdf0e10cSrcweir 
273cdf0e10cSrcweir     if ( xDispatch.is() )
274cdf0e10cSrcweir     {
275cdf0e10cSrcweir         try
276cdf0e10cSrcweir         {
277cdf0e10cSrcweir             Sequence<PropertyValue>   aArgs( 1 );
278cdf0e10cSrcweir 
279cdf0e10cSrcweir             // Provide key modifier information to dispatch function
280cdf0e10cSrcweir             aArgs[0].Name   = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
281cdf0e10cSrcweir             aArgs[0].Value  <<= KeyModifier;
282cdf0e10cSrcweir 
283cdf0e10cSrcweir             if(::comphelper::UiEventsLogger::isEnabled()) //#i88653#
284cdf0e10cSrcweir                 UiEventLogHelper(::rtl::OUString::createFromAscii("ButtonToolbarController")).log(m_xServiceManager, m_xFrame, aTargetURL, aArgs);
285cdf0e10cSrcweir             xDispatch->dispatch( aTargetURL, aArgs );
286cdf0e10cSrcweir         }
287cdf0e10cSrcweir         catch ( DisposedException& )
288cdf0e10cSrcweir         {
289cdf0e10cSrcweir         }
290cdf0e10cSrcweir     }
291cdf0e10cSrcweir }
292cdf0e10cSrcweir 
click()293cdf0e10cSrcweir void SAL_CALL ButtonToolbarController::click()
294cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
295cdf0e10cSrcweir {
296cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     if ( m_bDisposed )
299cdf0e10cSrcweir         throw DisposedException();
300cdf0e10cSrcweir 
301cdf0e10cSrcweir     sal_Int16   nKeyModifier( (sal_Int16)m_pToolbar->GetModifier() );
302cdf0e10cSrcweir     execute( nKeyModifier );
303cdf0e10cSrcweir }
304cdf0e10cSrcweir 
doubleClick()305cdf0e10cSrcweir void SAL_CALL ButtonToolbarController::doubleClick()
306cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
307cdf0e10cSrcweir {
308cdf0e10cSrcweir     // do nothing
309cdf0e10cSrcweir     if ( m_bDisposed )
310cdf0e10cSrcweir         throw DisposedException();
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
createPopupWindow()313cdf0e10cSrcweir uno::Reference< awt::XWindow > SAL_CALL ButtonToolbarController::createPopupWindow()
314cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
315cdf0e10cSrcweir {
316cdf0e10cSrcweir     if ( m_bDisposed )
317cdf0e10cSrcweir         throw DisposedException();
318cdf0e10cSrcweir 
319cdf0e10cSrcweir     return uno::Reference< awt::XWindow >();
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
createItemWindow(const::com::sun::star::uno::Reference<::com::sun::star::awt::XWindow> &)322cdf0e10cSrcweir uno::Reference< awt::XWindow > SAL_CALL ButtonToolbarController::createItemWindow(
323cdf0e10cSrcweir     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& )
324cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
325cdf0e10cSrcweir {
326cdf0e10cSrcweir     if ( m_bDisposed )
327cdf0e10cSrcweir         throw DisposedException();
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     return uno::Reference< awt::XWindow >();
330cdf0e10cSrcweir }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir } // namespace
333cdf0e10cSrcweir 
334