LibreOffice Module framework (master) 1
addonstoolbarwrapper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
22
23#include <com/sun/star/lang/DisposedException.hpp>
24#include <com/sun/star/ui/UIElementType.hpp>
25
27
28#include <vcl/svapp.hxx>
29#include <vcl/toolbox.hxx>
30
31using namespace com::sun::star::uno;
32using namespace com::sun::star::beans;
33using namespace com::sun::star::frame;
34using namespace com::sun::star::lang;
35using namespace com::sun::star::container;
36using namespace com::sun::star::awt;
37using namespace ::com::sun::star::ui;
38
39namespace framework
40{
41
43 UIElementWrapperBase( UIElementType::TOOLBAR ),
44 m_xContext( xContext ),
45 m_bCreatedImages( false )
46{
47}
48
50{
51}
52
53// XComponent
55{
56 Reference< XComponent > xThis(this);
57
58 css::lang::EventObject aEvent( xThis );
60
62
63 if ( m_xToolBarManager.is() )
64 m_xToolBarManager->dispose();
65 m_xToolBarManager.clear();
66
67 m_bDisposed = true;
68}
69
70// XInitialization
71void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArguments )
72{
74
75 if ( m_bDisposed )
76 throw DisposedException();
77
78 if ( m_bInitialized )
79 return;
80
82
83 for ( const Any& rArg : aArguments )
84 {
85 PropertyValue aPropValue;
86 if ( rArg >>= aPropValue )
87 {
88 if ( aPropValue.Name == "ConfigurationData" )
89 aPropValue.Value >>= m_aConfigData;
90 }
91 }
92
94 if ( !(xFrame.is() && m_aConfigData.hasElements()) )
95 return;
96
97 // Create VCL based toolbar which will be filled with settings data
98 VclPtr<ToolBox> pToolBar;
99 rtl::Reference<ToolBarManager> pToolBarManager;
100 {
101 SolarMutexGuard aSolarMutexGuard;
102 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
103 if ( pWindow )
104 {
106
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;
111 }
112 }
113
114 try
115 {
116 if ( m_aConfigData.hasElements() && pToolBar && pToolBarManager )
117 {
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 );
125 }
126 }
127 catch ( const NoSuchElementException& )
128 {
129 }
130}
131
132// XUIElement interface
134{
136
137 if ( m_xToolBarManager.is() )
138 {
139 ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
140 if ( pToolBarManager )
141 {
142 vcl::Window* pWindow = pToolBarManager->GetToolBar();
143 return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
144 }
145 }
146
148}
149
150// allow late population of images for add-on toolbars
152{
154
156 return;
157
158 if ( m_xToolBarManager.is() )
159 {
160 ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
161 if (pToolBarManager)
162 {
163 pToolBarManager->RequestImages();
164 m_bCreatedImages = true;
165 }
166 }
167}
168
169} // namespace framework
170
171/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
void setWidth(tools::Long nWidth)
constexpr tools::Long Width() const
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
static VclPtr< reference_type > Create(Arg &&... arg)
void disposeAndClear(const css::lang::EventObject &rEvt)
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
css::uno::Reference< css::lang::XComponent > m_xToolBarManager
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getRealInterface() override
virtual void SAL_CALL dispose() override
css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > m_aConfigData
AddonsToolBarWrapper(const css::uno::Reference< css::uno::XComponentContext > &xContext)
ToolBox * GetToolBar() const
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
comphelper::OMultiTypeInterfaceContainerHelper2 m_aListenerContainer
css::uno::WeakReference< css::frame::XFrame > m_xWeakFrame
OUString m_aResourceURL
container for ALL Listener
css::uno::Reference< css::uno::XComponentContext > m_xContext
Sequence< PropertyValue > aArguments
sal_uIntPtr sal_uLong
Reference< XFrame > xFrame
WinBits const WB_CLOSEABLE
WinBits const WB_MOVEABLE
WinBits const WB_DOCKABLE
WinBits const WB_SIZEABLE
WinBits const WB_3DLOOK
WinBits const WB_BORDER
WinBits const WB_SCROLL