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>
30 #include <vcl/wintypes.hxx>
32 using namespace com::sun::star::uno
;
33 using namespace com::sun::star::beans
;
34 using namespace com::sun::star::frame
;
35 using namespace com::sun::star::lang
;
36 using namespace com::sun::star::container
;
37 using namespace com::sun::star::awt
;
38 using namespace ::com::sun::star::ui
;
43 AddonsToolBarWrapper::AddonsToolBarWrapper( const Reference
< XComponentContext
>& xContext
) :
44 UIElementWrapperBase( UIElementType::TOOLBAR
),
45 m_xContext( xContext
),
46 m_bCreatedImages( false )
50 AddonsToolBarWrapper::~AddonsToolBarWrapper()
55 void SAL_CALL
AddonsToolBarWrapper::dispose()
57 Reference
< XComponent
> xThis(this);
59 css::lang::EventObject
aEvent( xThis
);
60 m_aListenerContainer
.disposeAndClear( aEvent
);
64 if ( m_xToolBarManager
.is() )
65 m_xToolBarManager
->dispose();
66 m_xToolBarManager
.clear();
72 void SAL_CALL
AddonsToolBarWrapper::initialize( const Sequence
< Any
>& aArguments
)
77 throw DisposedException();
82 UIElementWrapperBase::initialize( aArguments
);
84 for ( const Any
& rArg
: aArguments
)
86 PropertyValue aPropValue
;
87 if ( rArg
>>= aPropValue
)
89 if ( aPropValue
.Name
== "ConfigurationData" )
90 aPropValue
.Value
>>= m_aConfigData
;
94 Reference
< XFrame
> xFrame( m_xWeakFrame
);
95 if ( !(xFrame
.is() && m_aConfigData
.hasElements()) )
98 // Create VCL based toolbar which will be filled with settings data
99 VclPtr
<ToolBox
> pToolBar
;
100 rtl::Reference
<ToolBarManager
> pToolBarManager
;
102 SolarMutexGuard aSolarMutexGuard
;
103 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( xFrame
->getContainerWindow() );
106 WinBits nStyles
= WB_BORDER
| WB_SCROLL
| WB_MOVEABLE
| WB_3DLOOK
| WB_DOCKABLE
| WB_SIZEABLE
| WB_CLOSEABLE
;
108 pToolBar
= VclPtr
<ToolBox
>::Create( pWindow
, nStyles
);
109 pToolBar
->SetLineSpacing(true);
110 pToolBarManager
= new ToolBarManager( m_xContext
, xFrame
, m_aResourceURL
, pToolBar
);
111 m_xToolBarManager
= pToolBarManager
;
117 if ( m_aConfigData
.hasElements() && pToolBar
&& pToolBarManager
)
119 // Fill toolbar with container contents
120 pToolBarManager
->FillAddonToolbar( m_aConfigData
);
121 pToolBar
->EnableCustomize();
122 ::Size
aActSize( pToolBar
->GetSizePixel() );
123 ::Size
aSize( pToolBar
->CalcWindowSizePixel() );
124 aSize
.setWidth( aActSize
.Width() );
125 pToolBar
->SetSizePixel( aSize
);
128 catch ( const NoSuchElementException
& )
133 // XUIElement interface
134 Reference
< XInterface
> SAL_CALL
AddonsToolBarWrapper::getRealInterface()
138 if ( m_xToolBarManager
)
140 vcl::Window
* pWindow
= m_xToolBarManager
->GetToolBar();
141 return Reference
< XInterface
>( VCLUnoHelper::GetInterface( pWindow
), UNO_QUERY
);
144 return Reference
< XInterface
>();
147 // allow late population of images for add-on toolbars
148 void AddonsToolBarWrapper::populateImages()
152 if (m_bCreatedImages
)
155 if (m_xToolBarManager
)
157 m_xToolBarManager
->RequestImages();
158 m_bCreatedImages
= true;
162 } // namespace framework
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */