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
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>
25
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>
34
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <toolkit/awt/vclxwindow.hxx>
37
38 #include <svtools/miscopt.hxx>
39 #include <vcl/svapp.hxx>
40 #include <vcl/toolbox.hxx>
41
42 using namespace com::sun::star::uno;
43 using namespace com::sun::star::beans;
44 using namespace com::sun::star::frame;
45 using namespace com::sun::star::lang;
46 using namespace com::sun::star::container;
47 using namespace com::sun::star::awt;
48 using namespace ::com::sun::star::ui;
49
50 namespace framework
51 {
52
AddonsToolBarWrapper(const Reference<XComponentContext> & xContext)53 AddonsToolBarWrapper::AddonsToolBarWrapper( const Reference< XComponentContext >& xContext ) :
54 UIElementWrapperBase( UIElementType::TOOLBAR ),
55 m_xContext( xContext ),
56 m_bCreatedImages( false )
57 {
58 }
59
~AddonsToolBarWrapper()60 AddonsToolBarWrapper::~AddonsToolBarWrapper()
61 {
62 }
63
64 // XComponent
dispose()65 void SAL_CALL AddonsToolBarWrapper::dispose()
66 {
67 Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
68
69 css::lang::EventObject aEvent( xThis );
70 m_aListenerContainer.disposeAndClear( aEvent );
71
72 SolarMutexGuard g;
73
74 if ( m_xToolBarManager.is() )
75 m_xToolBarManager->dispose();
76 m_xToolBarManager.clear();
77
78 m_bDisposed = true;
79 }
80
81 // XInitialization
initialize(const Sequence<Any> & aArguments)82 void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArguments )
83 {
84 SolarMutexGuard g;
85
86 if ( m_bDisposed )
87 throw DisposedException();
88
89 if ( !m_bInitialized )
90 {
91 UIElementWrapperBase::initialize( aArguments );
92
93 for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
94 {
95 PropertyValue aPropValue;
96 if ( aArguments[n] >>= aPropValue )
97 {
98 if ( aPropValue.Name == "ConfigurationData" )
99 aPropValue.Value >>= m_aConfigData;
100 }
101 }
102
103 Reference< XFrame > xFrame( m_xWeakFrame );
104 if ( xFrame.is() && m_aConfigData.hasElements() )
105 {
106 // Create VCL based toolbar which will be filled with settings data
107 VclPtr<ToolBox> pToolBar;
108 AddonsToolBarManager* pToolBarManager = nullptr;
109 {
110 SolarMutexGuard aSolarMutexGuard;
111 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
112 if ( pWindow )
113 {
114 sal_uLong nStyles = WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
115
116 pToolBar = VclPtr<ToolBox>::Create( pWindow, nStyles );
117 pToolBar->SetLineSpacing(true);
118 pToolBarManager = new AddonsToolBarManager( m_xContext, xFrame, m_aResourceURL, pToolBar );
119 m_xToolBarManager.set( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
120 }
121 }
122
123 try
124 {
125 if ( m_aConfigData.hasElements() && pToolBar && pToolBarManager )
126 {
127 // Fill toolbar with container contents
128 pToolBarManager->FillToolbar( m_aConfigData );
129 pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
130 pToolBar->EnableCustomize();
131 ::Size aActSize( pToolBar->GetSizePixel() );
132 ::Size aSize( pToolBar->CalcWindowSizePixel() );
133 aSize.setWidth( aActSize.Width() );
134 pToolBar->SetSizePixel( aSize );
135 }
136 }
137 catch ( const NoSuchElementException& )
138 {
139 }
140 }
141 }
142 }
143
144 // XUIElement interface
getRealInterface()145 Reference< XInterface > SAL_CALL AddonsToolBarWrapper::getRealInterface()
146 {
147 SolarMutexGuard g;
148
149 if ( m_xToolBarManager.is() )
150 {
151 AddonsToolBarManager* pToolBarManager = static_cast< AddonsToolBarManager *>( m_xToolBarManager.get() );
152 if ( pToolBarManager )
153 {
154 vcl::Window* pWindow = pToolBarManager->GetToolBar();
155 return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
156 }
157 }
158
159 return Reference< XInterface >();
160 }
161
162 // allow late population of images for add-on toolbars
populateImages()163 void AddonsToolBarWrapper::populateImages()
164 {
165 SolarMutexGuard g;
166
167 if (m_bCreatedImages)
168 return;
169
170 if ( m_xToolBarManager.is() )
171 {
172 AddonsToolBarManager* pToolBarManager = static_cast< AddonsToolBarManager *>( m_xToolBarManager.get() );
173 if (pToolBarManager)
174 {
175 pToolBarManager->RefreshImages();
176 m_bCreatedImages = true;
177 }
178 }
179 }
180
181 } // namespace framework
182
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
184