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: toolbarwrapper.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_framework.hxx"
33 //_________________________________________________________________________________________________________________
35 //_________________________________________________________________________________________________________________
38 #include <uielement/toolbarwrapper.hxx>
39 #include <threadhelp/resetableguard.hxx>
40 #include <helper/actiontriggerhelper.hxx>
41 #include <uielement/constitemcontainer.hxx>
42 #include <uielement/rootitemcontainer.hxx>
43 #include <uielement/toolbarmanager.hxx>
45 #ifndef __FRAMEWORK_UIELEMENT_TOOLBARW_HXX_
46 #include <uielement/toolbar.hxx>
49 //_________________________________________________________________________________________________________________
51 //_________________________________________________________________________________________________________________
52 #include <com/sun/star/lang/XServiceInfo.hpp>
53 #include <com/sun/star/beans/XPropertySet.hpp>
54 #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
55 #include <com/sun/star/awt/XMenuBar.hpp>
56 #include <com/sun/star/container/XIndexContainer.hpp>
57 #include <com/sun/star/container/XNameAccess.hpp>
58 #include <com/sun/star/ui/UIElementType.hpp>
60 //_________________________________________________________________________________________________________________
62 //_________________________________________________________________________________________________________________
64 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
65 #include <toolkit/unohlp.hxx>
67 #include <toolkit/awt/vclxwindow.hxx>
68 #include <comphelper/processfactory.hxx>
70 #include <svtools/miscopt.hxx>
71 #include <vcl/svapp.hxx>
72 #include <vcl/toolbox.hxx>
73 #include <rtl/logfile.hxx>
75 using namespace com::sun::star
;
76 using namespace com::sun::star::uno
;
77 using namespace com::sun::star::beans
;
78 using namespace com::sun::star::frame
;
79 using namespace com::sun::star::lang
;
80 using namespace com::sun::star::container
;
81 using namespace com::sun::star::awt
;
82 using namespace ::com::sun::star::ui
;
87 ToolBarWrapper::ToolBarWrapper( const Reference
< XMultiServiceFactory
>& xServiceManager
) :
88 UIConfigElementWrapperBase( UIElementType::TOOLBAR
,xServiceManager
)
92 ToolBarWrapper::~ToolBarWrapper()
97 void SAL_CALL
ToolBarWrapper::acquire() throw()
99 UIConfigElementWrapperBase::acquire();
102 void SAL_CALL
ToolBarWrapper::release() throw()
104 UIConfigElementWrapperBase::release();
107 uno::Any SAL_CALL
ToolBarWrapper::queryInterface( const uno::Type
& rType
)
108 throw( ::com::sun::star::uno::RuntimeException
)
110 Any a
= ::cppu::queryInterface(
112 SAL_STATIC_CAST( ::com::sun::star::ui::XUIFunctionListener
*, this ) );
117 return UIConfigElementWrapperBase::queryInterface( rType
);
121 void SAL_CALL
ToolBarWrapper::dispose() throw ( RuntimeException
)
123 Reference
< XComponent
> xThis( static_cast< OWeakObject
* >(this), UNO_QUERY
);
126 ResetableGuard
aLock( m_aLock
);
131 com::sun::star::lang::EventObject
aEvent( xThis
);
132 m_aListenerContainer
.disposeAndClear( aEvent
);
134 ResetableGuard
aLock( m_aLock
);
136 if ( m_xToolBarManager
.is() )
137 m_xToolBarManager
->dispose();
138 m_xToolBarManager
.clear();
139 m_xConfigSource
.clear();
140 m_xConfigData
.clear();
141 m_xToolBarWindow
.clear();
143 m_bDisposed
= sal_True
;
147 void SAL_CALL
ToolBarWrapper::initialize( const Sequence
< Any
>& aArguments
) throw ( Exception
, RuntimeException
)
149 ResetableGuard
aLock( m_aLock
);
152 throw DisposedException();
154 if ( !m_bInitialized
)
156 UIConfigElementWrapperBase::initialize( aArguments
);
158 sal_Bool
bPopupMode( sal_False
);
159 for ( sal_Int32 i
= 0; i
< aArguments
.getLength(); i
++ )
161 PropertyValue aPropValue
;
162 if ( aArguments
[i
] >>= aPropValue
)
164 if ( aPropValue
.Name
.equalsAsciiL( "PopupMode", 9 ))
166 aPropValue
.Value
>>= bPopupMode
;
172 Reference
< XFrame
> xFrame( m_xWeakFrame
);
173 if ( xFrame
.is() && m_xConfigSource
.is() )
175 // Create VCL based toolbar which will be filled with settings data
176 ToolBar
* pToolBar
= 0;
177 ToolBarManager
* pToolBarManager
= 0;
179 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
180 Window
* pWindow
= VCLUnoHelper::GetWindow( xFrame
->getContainerWindow() );
183 ULONG nStyles
= WB_LINESPACING
| WB_BORDER
| WB_SCROLL
| WB_MOVEABLE
| WB_3DLOOK
| WB_DOCKABLE
| WB_SIZEABLE
| WB_CLOSEABLE
;
185 pToolBar
= new ToolBar( pWindow
, nStyles
);
186 m_xToolBarWindow
= VCLUnoHelper::GetInterface( pToolBar
);
187 pToolBarManager
= new ToolBarManager( m_xServiceFactory
, xFrame
, m_aResourceURL
, pToolBar
);
188 pToolBar
->SetToolBarManager( pToolBarManager
);
189 m_xToolBarManager
= Reference
< XComponent
>( static_cast< OWeakObject
*>( pToolBarManager
), UNO_QUERY
);
190 pToolBar
->WillUsePopupMode( bPopupMode
);
196 m_xConfigData
= m_xConfigSource
->getSettings( m_aResourceURL
, sal_False
);
197 if ( m_xConfigData
.is() && pToolBar
&& pToolBarManager
)
199 // Fill toolbar with container contents
200 pToolBarManager
->FillToolbar( m_xConfigData
);
201 pToolBar
->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
202 pToolBar
->EnableCustomize( TRUE
);
203 ::Size
aActSize( pToolBar
->GetSizePixel() );
204 ::Size
aSize( pToolBar
->CalcWindowSizePixel() );
205 aSize
.Width() = aActSize
.Width();
206 pToolBar
->SetOutputSizePixel( aSize
);
209 catch ( NoSuchElementException
& )
211 // No settings in our configuration manager. This means we are
212 // a transient toolbar which has no persistent settings.
213 m_bPersistent
= sal_False
;
214 if ( pToolBar
&& pToolBarManager
)
216 pToolBar
->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
217 pToolBar
->EnableCustomize( TRUE
);
218 ::Size
aActSize( pToolBar
->GetSizePixel() );
219 ::Size
aSize( pToolBar
->CalcWindowSizePixel() );
220 aSize
.Width() = aActSize
.Width();
221 pToolBar
->SetOutputSizePixel( aSize
);
229 void SAL_CALL
ToolBarWrapper::disposing( const ::com::sun::star::lang::EventObject
& ) throw (::com::sun::star::uno::RuntimeException
)
235 void SAL_CALL
ToolBarWrapper::update() throw (::com::sun::star::uno::RuntimeException
)
237 ResetableGuard
aLock( m_aLock
);
240 throw DisposedException();
242 ToolBarManager
* pToolBarManager
= static_cast< ToolBarManager
*>( m_xToolBarManager
.get() );
243 if ( pToolBarManager
)
244 pToolBarManager
->CheckAndUpdateImages();
247 // XUIElementSettings
248 void SAL_CALL
ToolBarWrapper::updateSettings() throw (::com::sun::star::uno::RuntimeException
)
250 ResetableGuard
aLock( m_aLock
);
253 throw DisposedException();
255 if ( m_xToolBarManager
.is() )
257 if ( m_xConfigSource
.is() && m_bPersistent
)
261 ToolBarManager
* pToolBarManager
= static_cast< ToolBarManager
*>( m_xToolBarManager
.get() );
263 m_xConfigData
= m_xConfigSource
->getSettings( m_aResourceURL
, sal_False
);
264 if ( m_xConfigData
.is() )
265 pToolBarManager
->FillToolbar( m_xConfigData
);
267 catch ( NoSuchElementException
& )
271 else if ( !m_bPersistent
)
273 // Transient toolbar: do nothing
278 void ToolBarWrapper::impl_fillNewData()
280 // Transient toolbar => Fill toolbar with new data
281 ToolBarManager
* pToolBarManager
= static_cast< ToolBarManager
*>( m_xToolBarManager
.get() );
282 if ( pToolBarManager
)
283 pToolBarManager
->FillToolbar( m_xConfigData
);
286 // XUIElement interface
287 Reference
< XInterface
> SAL_CALL
ToolBarWrapper::getRealInterface( ) throw (::com::sun::star::uno::RuntimeException
)
289 ResetableGuard
aLock( m_aLock
);
291 if ( m_xToolBarManager
.is() )
293 ToolBarManager
* pToolBarManager
= static_cast< ToolBarManager
*>( m_xToolBarManager
.get() );
294 if ( pToolBarManager
)
296 Window
* pWindow
= (Window
*)pToolBarManager
->GetToolBar();
297 return Reference
< XInterface
>( VCLUnoHelper::GetInterface( pWindow
), UNO_QUERY
);
301 return Reference
< XInterface
>();
305 void SAL_CALL
ToolBarWrapper::functionExecute(
306 const ::rtl::OUString
& aUIElementName
,
307 const ::rtl::OUString
& aCommand
)
308 throw (::com::sun::star::uno::RuntimeException
)
310 ResetableGuard
aLock( m_aLock
);
312 if ( m_xToolBarManager
.is() )
314 ToolBarManager
* pToolBarManager
= static_cast< ToolBarManager
*>( m_xToolBarManager
.get() );
315 if ( pToolBarManager
)
316 pToolBarManager
->notifyRegisteredControllers( aUIElementName
, aCommand
);
320 void SAL_CALL
ToolBarWrapper::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const com::sun::star::uno::Any
& aValue
) throw( com::sun::star::uno::Exception
)
322 ResetableGuard
aLock( m_aLock
);
323 sal_Bool
bNoClose( m_bNoClose
);
326 UIConfigElementWrapperBase::setFastPropertyValue_NoBroadcast( nHandle
, aValue
);
330 sal_Bool
bNewNoClose( m_bNoClose
);
331 if ( m_xToolBarManager
.is() && !m_bDisposed
&& ( bNewNoClose
!= bNoClose
))
333 ToolBarManager
* pToolBarManager
= static_cast< ToolBarManager
*>( m_xToolBarManager
.get() );
334 if ( pToolBarManager
)
336 ToolBox
* pToolBox
= pToolBarManager
->GetToolBar();
341 pToolBox
->SetStyle( pToolBox
->GetStyle() & ~WB_CLOSEABLE
);
342 pToolBox
->SetFloatStyle( pToolBox
->GetFloatStyle() & ~WB_CLOSEABLE
);
346 pToolBox
->SetStyle( pToolBox
->GetStyle() | WB_CLOSEABLE
);
347 pToolBox
->SetFloatStyle( pToolBox
->GetFloatStyle() | WB_CLOSEABLE
);
354 } // namespace framework