merge the formfield patch from ooo-build
[ooovba.git] / framework / source / uielement / addonstoolbarwrapper.cxx
blobda40a4ee01c63a129d512e37e61d01dbd877c5cf
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: addonstoolbarwrapper.cxx,v $
10 * $Revision: 1.8 $
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"
34 //_________________________________________________________________________________________________________________
35 // my own includes
36 //_________________________________________________________________________________________________________________
39 #include <uielement/addonstoolbarwrapper.hxx>
40 #include <threadhelp/resetableguard.hxx>
41 #include <helper/actiontriggerhelper.hxx>
42 #include <uielement/constitemcontainer.hxx>
43 #include <uielement/rootitemcontainer.hxx>
44 #include <uielement/addonstoolbarmanager.hxx>
46 #ifndef __FRAMEWORK_UIELEMENT_TOOLBARW_HXX_
47 #include <uielement/toolbar.hxx>
48 #endif
50 //_________________________________________________________________________________________________________________
51 // interface includes
52 //_________________________________________________________________________________________________________________
53 #include <com/sun/star/lang/XServiceInfo.hpp>
54 #include <com/sun/star/lang/DisposedException.hpp>
55 #include <com/sun/star/beans/XPropertySet.hpp>
56 #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
57 #include <com/sun/star/awt/XMenuBar.hpp>
58 #include <com/sun/star/container/XIndexContainer.hpp>
59 #include <com/sun/star/container/XNameAccess.hpp>
60 #include <com/sun/star/ui/UIElementType.hpp>
62 //_________________________________________________________________________________________________________________
63 // other includes
64 //_________________________________________________________________________________________________________________
66 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
67 #include <toolkit/unohlp.hxx>
68 #endif
69 #include <toolkit/awt/vclxwindow.hxx>
70 #include <comphelper/processfactory.hxx>
72 #include <svtools/miscopt.hxx>
73 #include <vcl/svapp.hxx>
74 #include <vcl/toolbox.hxx>
75 #include <rtl/logfile.hxx>
77 using namespace com::sun::star::uno;
78 using namespace com::sun::star::beans;
79 using namespace com::sun::star::frame;
80 using namespace com::sun::star::lang;
81 using namespace com::sun::star::container;
82 using namespace com::sun::star::awt;
83 using namespace ::com::sun::star::ui;
85 namespace framework
88 AddonsToolBarWrapper::AddonsToolBarWrapper( const Reference< XMultiServiceFactory >& xServiceManager ) :
89 UIElementWrapperBase( UIElementType::TOOLBAR ),
90 m_xServiceManager( xServiceManager )
94 AddonsToolBarWrapper::~AddonsToolBarWrapper()
98 // XComponent
99 void SAL_CALL AddonsToolBarWrapper::dispose() throw ( RuntimeException )
101 Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
103 com::sun::star::lang::EventObject aEvent( xThis );
104 m_aListenerContainer.disposeAndClear( aEvent );
106 ResetableGuard aLock( m_aLock );
108 if ( m_xToolBarManager.is() )
109 m_xToolBarManager->dispose();
110 m_xToolBarManager.clear();
111 m_xToolBarWindow.clear();
113 m_bDisposed = sal_True;
116 // XInitialization
117 void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
119 ResetableGuard aLock( m_aLock );
121 if ( m_bDisposed )
122 throw DisposedException();
124 if ( !m_bInitialized )
126 UIElementWrapperBase::initialize( aArguments );
128 for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
130 PropertyValue aPropValue;
131 if ( aArguments[n] >>= aPropValue )
133 if ( aPropValue.Name.equalsAscii( "ConfigurationData" ))
134 aPropValue.Value >>= m_aConfigData;
138 Reference< XFrame > xFrame( m_xWeakFrame );
139 if ( xFrame.is() && m_aConfigData.getLength() > 0 )
141 // Create VCL based toolbar which will be filled with settings data
142 ToolBar* pToolBar = 0;
143 AddonsToolBarManager* pToolBarManager = 0;
145 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
146 Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
147 if ( pWindow )
149 ULONG nStyles = WB_LINESPACING | WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
151 pToolBar = new ToolBar( pWindow, nStyles );
152 m_xToolBarWindow = VCLUnoHelper::GetInterface( pToolBar );
153 pToolBarManager = new AddonsToolBarManager( m_xServiceManager, xFrame, m_aResourceURL, pToolBar );
154 pToolBar->SetToolBarManager( pToolBarManager );
155 m_xToolBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
161 if (( m_aConfigData.getLength() > 0 ) && pToolBar && pToolBarManager )
163 // Fill toolbar with container contents
164 pToolBarManager->FillToolbar( m_aConfigData );
165 pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
166 pToolBar->EnableCustomize( TRUE );
167 ::Size aActSize( pToolBar->GetSizePixel() );
168 ::Size aSize( pToolBar->CalcWindowSizePixel() );
169 aSize.Width() = aActSize.Width();
170 pToolBar->SetSizePixel( aSize );
173 catch ( NoSuchElementException& )
180 // XUIElement interface
181 Reference< XInterface > SAL_CALL AddonsToolBarWrapper::getRealInterface() throw (::com::sun::star::uno::RuntimeException)
183 ResetableGuard aLock( m_aLock );
185 if ( m_xToolBarManager.is() )
187 AddonsToolBarManager* pToolBarManager = static_cast< AddonsToolBarManager *>( m_xToolBarManager.get() );
188 if ( pToolBarManager )
190 Window* pWindow = (Window *)pToolBarManager->GetToolBar();
191 return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
195 return Reference< XInterface >();
198 } // namespace framework