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