Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / framework / source / uielement / addonstoolbarwrapper.cxx
blob6547d1c6bcdeeac92c1211be1f9e896b526b594a
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 <uielement/toolbarmanager.hxx>
23 #include <com/sun/star/lang/DisposedException.hpp>
24 #include <com/sun/star/ui/UIElementType.hpp>
26 #include <toolkit/helper/vclunohelper.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/toolbox.hxx>
31 using namespace com::sun::star::uno;
32 using namespace com::sun::star::beans;
33 using namespace com::sun::star::frame;
34 using namespace com::sun::star::lang;
35 using namespace com::sun::star::container;
36 using namespace com::sun::star::awt;
37 using namespace ::com::sun::star::ui;
39 namespace framework
42 AddonsToolBarWrapper::AddonsToolBarWrapper( const Reference< XComponentContext >& xContext ) :
43 UIElementWrapperBase( UIElementType::TOOLBAR ),
44 m_xContext( xContext ),
45 m_bCreatedImages( false )
49 AddonsToolBarWrapper::~AddonsToolBarWrapper()
53 // XComponent
54 void SAL_CALL AddonsToolBarWrapper::dispose()
56 Reference< XComponent > xThis(this);
58 css::lang::EventObject aEvent( xThis );
59 m_aListenerContainer.disposeAndClear( aEvent );
61 SolarMutexGuard g;
63 if ( m_xToolBarManager.is() )
64 m_xToolBarManager->dispose();
65 m_xToolBarManager.clear();
67 m_bDisposed = true;
70 // XInitialization
71 void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArguments )
73 SolarMutexGuard g;
75 if ( m_bDisposed )
76 throw DisposedException();
78 if ( m_bInitialized )
79 return;
81 UIElementWrapperBase::initialize( aArguments );
83 for ( const Any& rArg : aArguments )
85 PropertyValue aPropValue;
86 if ( rArg >>= aPropValue )
88 if ( aPropValue.Name == "ConfigurationData" )
89 aPropValue.Value >>= m_aConfigData;
93 Reference< XFrame > xFrame( m_xWeakFrame );
94 if ( !(xFrame.is() && m_aConfigData.hasElements()) )
95 return;
97 // Create VCL based toolbar which will be filled with settings data
98 VclPtr<ToolBox> pToolBar;
99 rtl::Reference<ToolBarManager> pToolBarManager;
101 SolarMutexGuard aSolarMutexGuard;
102 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
103 if ( pWindow )
105 sal_uLong nStyles = WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
107 pToolBar = VclPtr<ToolBox>::Create( pWindow, nStyles );
108 pToolBar->SetLineSpacing(true);
109 pToolBarManager = new ToolBarManager( m_xContext, xFrame, m_aResourceURL, pToolBar );
110 m_xToolBarManager = pToolBarManager;
116 if ( m_aConfigData.hasElements() && pToolBar && pToolBarManager )
118 // Fill toolbar with container contents
119 pToolBarManager->FillAddonToolbar( m_aConfigData );
120 pToolBar->EnableCustomize();
121 ::Size aActSize( pToolBar->GetSizePixel() );
122 ::Size aSize( pToolBar->CalcWindowSizePixel() );
123 aSize.setWidth( aActSize.Width() );
124 pToolBar->SetSizePixel( aSize );
127 catch ( const NoSuchElementException& )
132 // XUIElement interface
133 Reference< XInterface > SAL_CALL AddonsToolBarWrapper::getRealInterface()
135 SolarMutexGuard g;
137 if ( m_xToolBarManager.is() )
139 ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
140 if ( pToolBarManager )
142 vcl::Window* pWindow = pToolBarManager->GetToolBar();
143 return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
147 return Reference< XInterface >();
150 // allow late population of images for add-on toolbars
151 void AddonsToolBarWrapper::populateImages()
153 SolarMutexGuard g;
155 if (m_bCreatedImages)
156 return;
158 if ( m_xToolBarManager.is() )
160 ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
161 if (pToolBarManager)
163 pToolBarManager->RequestImages();
164 m_bCreatedImages = true;
169 } // namespace framework
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */