fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / uielement / addonstoolbarwrapper.cxx
blob35506a24e86ce3402822462915c6b6cd03bfbb9d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <uielement/addonstoolbarwrapper.hxx>
21 #include <framework/actiontriggerhelper.hxx>
22 #include <uielement/constitemcontainer.hxx>
23 #include <uielement/rootitemcontainer.hxx>
24 #include <uielement/addonstoolbarmanager.hxx>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/lang/DisposedException.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
30 #include <com/sun/star/awt/XMenuBar.hpp>
31 #include <com/sun/star/container/XIndexContainer.hpp>
32 #include <com/sun/star/container/XNameAccess.hpp>
33 #include <com/sun/star/ui/UIElementType.hpp>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <toolkit/awt/vclxwindow.hxx>
37 #include <comphelper/processfactory.hxx>
39 #include <svtools/miscopt.hxx>
40 #include <vcl/svapp.hxx>
41 #include <vcl/toolbox.hxx>
43 using namespace com::sun::star::uno;
44 using namespace com::sun::star::beans;
45 using namespace com::sun::star::frame;
46 using namespace com::sun::star::lang;
47 using namespace com::sun::star::container;
48 using namespace com::sun::star::awt;
49 using namespace ::com::sun::star::ui;
51 namespace framework
54 AddonsToolBarWrapper::AddonsToolBarWrapper( const Reference< XComponentContext >& xContext ) :
55 UIElementWrapperBase( UIElementType::TOOLBAR ),
56 m_xContext( xContext ),
57 m_bCreatedImages( false )
61 AddonsToolBarWrapper::~AddonsToolBarWrapper()
65 // XComponent
66 void SAL_CALL AddonsToolBarWrapper::dispose() throw ( RuntimeException, std::exception )
68 Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
70 com::sun::star::lang::EventObject aEvent( xThis );
71 m_aListenerContainer.disposeAndClear( aEvent );
73 SolarMutexGuard g;
75 if ( m_xToolBarManager.is() )
76 m_xToolBarManager->dispose();
77 m_xToolBarManager.clear();
79 m_bDisposed = true;
82 // XInitialization
83 void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException, std::exception )
85 SolarMutexGuard g;
87 if ( m_bDisposed )
88 throw DisposedException();
90 if ( !m_bInitialized )
92 UIElementWrapperBase::initialize( aArguments );
94 for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
96 PropertyValue aPropValue;
97 if ( aArguments[n] >>= aPropValue )
99 if ( aPropValue.Name == "ConfigurationData" )
100 aPropValue.Value >>= m_aConfigData;
104 Reference< XFrame > xFrame( m_xWeakFrame );
105 if ( xFrame.is() && m_aConfigData.getLength() > 0 )
107 // Create VCL based toolbar which will be filled with settings data
108 ToolBox* pToolBar = 0;
109 AddonsToolBarManager* pToolBarManager = 0;
111 SolarMutexGuard aSolarMutexGuard;
112 vcl::Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
113 if ( pWindow )
115 sal_uLong nStyles = WB_LINESPACING | WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
117 pToolBar = VclPtr<ToolBox>::Create( pWindow, nStyles );
118 pToolBarManager = new AddonsToolBarManager( m_xContext, xFrame, m_aResourceURL, pToolBar );
119 m_xToolBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
125 if (( m_aConfigData.getLength() > 0 ) && pToolBar && pToolBarManager )
127 // Fill toolbar with container contents
128 pToolBarManager->FillToolbar( m_aConfigData );
129 pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
130 pToolBar->EnableCustomize( true );
131 ::Size aActSize( pToolBar->GetSizePixel() );
132 ::Size aSize( pToolBar->CalcWindowSizePixel() );
133 aSize.Width() = aActSize.Width();
134 pToolBar->SetSizePixel( aSize );
137 catch ( const NoSuchElementException& )
144 // XUIElement interface
145 Reference< XInterface > SAL_CALL AddonsToolBarWrapper::getRealInterface() throw (::com::sun::star::uno::RuntimeException, std::exception)
147 SolarMutexGuard g;
149 if ( m_xToolBarManager.is() )
151 AddonsToolBarManager* pToolBarManager = static_cast< AddonsToolBarManager *>( m_xToolBarManager.get() );
152 if ( pToolBarManager )
154 vcl::Window* pWindow = (vcl::Window *)pToolBarManager->GetToolBar();
155 return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
159 return Reference< XInterface >();
162 // allow late population of images for add-on toolbars
163 void AddonsToolBarWrapper::populateImages()
165 SolarMutexGuard g;
167 if (m_bCreatedImages)
168 return;
170 if ( m_xToolBarManager.is() )
172 AddonsToolBarManager* pToolBarManager = static_cast< AddonsToolBarManager *>( m_xToolBarManager.get() );
173 if (pToolBarManager)
175 pToolBarManager->RefreshImages();
176 m_bCreatedImages = true;
181 } // namespace framework
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */