1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
42 AddonsToolBarWrapper::AddonsToolBarWrapper( const Reference
< XComponentContext
>& xContext
) :
43 UIElementWrapperBase( UIElementType::TOOLBAR
),
44 m_xContext( xContext
),
45 m_bCreatedImages( false )
49 AddonsToolBarWrapper::~AddonsToolBarWrapper()
54 void SAL_CALL
AddonsToolBarWrapper::dispose()
56 Reference
< XComponent
> xThis(this);
58 css::lang::EventObject
aEvent( xThis
);
59 m_aListenerContainer
.disposeAndClear( aEvent
);
63 if ( m_xToolBarManager
.is() )
64 m_xToolBarManager
->dispose();
65 m_xToolBarManager
.clear();
71 void SAL_CALL
AddonsToolBarWrapper::initialize( const Sequence
< Any
>& aArguments
)
76 throw DisposedException();
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()) )
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() );
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()
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()
155 if (m_bCreatedImages
)
158 if ( m_xToolBarManager
.is() )
160 ToolBarManager
* pToolBarManager
= static_cast< ToolBarManager
*>( m_xToolBarManager
.get() );
163 pToolBarManager
->RequestImages();
164 m_bCreatedImages
= true;
169 } // namespace framework
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */