1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: generictoolboxcontroller.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <svtools/generictoolboxcontroller.hxx>
35 //_________________________________________________________________________________________________________________
37 //_________________________________________________________________________________________________________________
39 //_________________________________________________________________________________________________________________
41 //_________________________________________________________________________________________________________________
42 #include <com/sun/star/util/XURLTransformer.hpp>
43 #include <com/sun/star/frame/XDispatchProvider.hpp>
44 #include <com/sun/star/beans/PropertyValue.hpp>
45 #include <com/sun/star/lang/DisposedException.hpp>
46 #include <com/sun/star/frame/status/ItemStatus.hpp>
47 #include <com/sun/star/frame/status/ItemState.hpp>
49 //_________________________________________________________________________________________________________________
51 //_________________________________________________________________________________________________________________
52 #include <vos/mutex.hxx>
53 #include <vcl/svapp.hxx>
55 using namespace ::com::sun::star::awt
;
56 using namespace ::com::sun::star::uno
;
57 using namespace ::com::sun::star::beans
;
58 using namespace ::com::sun::star::lang
;
59 using namespace ::com::sun::star::frame
;
60 using namespace ::com::sun::star::frame::status
;
61 using namespace ::com::sun::star::util
;
68 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XDispatch
> xDispatch
;
69 ::com::sun::star::util::URL aTargetURL
;
70 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aArgs
;
73 GenericToolboxController::GenericToolboxController( const Reference
< XMultiServiceFactory
>& rServiceManager
,
74 const Reference
< XFrame
>& rFrame
,
77 const ::rtl::OUString
& aCommand
) :
78 svt::ToolboxController( rServiceManager
, rFrame
, aCommand
)
79 , m_pToolbox( pToolbox
)
82 // Initialization is done through ctor
83 m_bInitialized
= sal_True
;
85 // insert main command to our listener map
86 if ( m_aCommandURL
.getLength() )
87 m_aListenerMap
.insert( URLToDispatchMap::value_type( aCommand
, Reference
< XDispatch
>() ));
90 GenericToolboxController::~GenericToolboxController()
94 void SAL_CALL
GenericToolboxController::dispose()
95 throw ( RuntimeException
)
97 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
99 svt::ToolboxController::dispose();
105 void SAL_CALL
GenericToolboxController::execute( sal_Int16
/*KeyModifier*/ )
106 throw ( RuntimeException
)
108 Reference
< XDispatch
> xDispatch
;
109 Reference
< XURLTransformer
> xURLTransformer
;
110 ::rtl::OUString aCommandURL
;
113 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
116 throw DisposedException();
118 if ( m_bInitialized
&&
120 m_xServiceManager
.is() &&
121 m_aCommandURL
.getLength() )
123 xURLTransformer
= Reference
< XURLTransformer
>( m_xServiceManager
->createInstance(
124 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ))),
127 aCommandURL
= m_aCommandURL
;
128 URLToDispatchMap::iterator pIter
= m_aListenerMap
.find( m_aCommandURL
);
129 if ( pIter
!= m_aListenerMap
.end() )
130 xDispatch
= pIter
->second
;
134 if ( xDispatch
.is() && xURLTransformer
.is() )
136 com::sun::star::util::URL aTargetURL
;
137 Sequence
<PropertyValue
> aArgs
;
139 aTargetURL
.Complete
= aCommandURL
;
140 xURLTransformer
->parseStrict( aTargetURL
);
142 // Execute dispatch asynchronously
143 ExecuteInfo
* pExecuteInfo
= new ExecuteInfo
;
144 pExecuteInfo
->xDispatch
= xDispatch
;
145 pExecuteInfo
->aTargetURL
= aTargetURL
;
146 pExecuteInfo
->aArgs
= aArgs
;
147 Application::PostUserEvent( STATIC_LINK(0, GenericToolboxController
, ExecuteHdl_Impl
), pExecuteInfo
);
151 void GenericToolboxController::statusChanged( const FeatureStateEvent
& Event
)
152 throw ( RuntimeException
)
154 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
161 m_pToolbox
->EnableItem( m_nID
, Event
.IsEnabled
);
163 USHORT nItemBits
= m_pToolbox
->GetItemBits( m_nID
);
164 nItemBits
&= ~TIB_CHECKABLE
;
165 TriState eTri
= STATE_NOCHECK
;
167 sal_Bool bValue
= sal_Bool();
168 rtl::OUString aStrValue
;
169 ItemStatus aItemState
;
171 if ( Event
.State
>>= bValue
)
173 // Boolean, treat it as checked/unchecked
174 m_pToolbox
->SetItemBits( m_nID
, nItemBits
);
175 m_pToolbox
->CheckItem( m_nID
, bValue
);
178 nItemBits
|= TIB_CHECKABLE
;
180 else if ( Event
.State
>>= aStrValue
)
182 m_pToolbox
->SetItemText( m_nID
, aStrValue
);
184 else if ( Event
.State
>>= aItemState
)
186 eTri
= STATE_DONTKNOW
;
187 nItemBits
|= TIB_CHECKABLE
;
190 m_pToolbox
->SetItemState( m_nID
, eTri
);
191 m_pToolbox
->SetItemBits( m_nID
, nItemBits
);
195 IMPL_STATIC_LINK_NOINSTANCE( GenericToolboxController
, ExecuteHdl_Impl
, ExecuteInfo
*, pExecuteInfo
)
199 // Asynchronous execution as this can lead to our own destruction!
200 // Framework can recycle our current frame and the layout manager disposes all user interface
201 // elements if a component gets detached from its frame!
202 pExecuteInfo
->xDispatch
->dispatch( pExecuteInfo
->aTargetURL
, pExecuteInfo
->aArgs
);