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/toolbarwrapper.hxx>
21 #include <framework/actiontriggerhelper.hxx>
22 #include <uielement/constitemcontainer.hxx>
23 #include <uielement/rootitemcontainer.hxx>
24 #include <uielement/toolbarmanager.hxx>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
29 #include <com/sun/star/awt/XMenuBar.hpp>
30 #include <com/sun/star/container/XIndexContainer.hpp>
31 #include <com/sun/star/container/XNameAccess.hpp>
32 #include <com/sun/star/ui/UIElementType.hpp>
33 #include <com/sun/star/lang/DisposedException.hpp>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <toolkit/awt/vclxwindow.hxx>
37 #include <comphelper/processfactory.hxx>
39 #include <svtools/miscopt.hxx>
40 #include <vcl/svapp.hxx>
41 #include <vcl/toolbox.hxx>
43 using namespace com::sun::star
;
44 using namespace com::sun::star::uno
;
45 using namespace com::sun::star::beans
;
46 using namespace com::sun::star::frame
;
47 using namespace com::sun::star::lang
;
48 using namespace com::sun::star::container
;
49 using namespace com::sun::star::awt
;
50 using namespace ::com::sun::star::ui
;
55 ToolBarWrapper::ToolBarWrapper( const Reference
< XComponentContext
>& rxContext
) :
56 UIConfigElementWrapperBase( UIElementType::TOOLBAR
),
57 m_xContext( rxContext
)
61 ToolBarWrapper::~ToolBarWrapper()
66 void SAL_CALL
ToolBarWrapper::acquire() throw()
68 UIConfigElementWrapperBase::acquire();
71 void SAL_CALL
ToolBarWrapper::release() throw()
73 UIConfigElementWrapperBase::release();
76 uno::Any SAL_CALL
ToolBarWrapper::queryInterface( const uno::Type
& rType
)
77 throw( ::com::sun::star::uno::RuntimeException
, std::exception
)
79 Any a
= ::cppu::queryInterface(
81 (static_cast< ::com::sun::star::ui::XUIFunctionListener
* >(this)) );
86 return UIConfigElementWrapperBase::queryInterface( rType
);
90 void SAL_CALL
ToolBarWrapper::dispose() throw ( RuntimeException
, std::exception
)
92 Reference
< XComponent
> xThis( static_cast< OWeakObject
* >(this), UNO_QUERY
);
100 com::sun::star::lang::EventObject
aEvent( xThis
);
101 m_aListenerContainer
.disposeAndClear( aEvent
);
105 if ( m_xToolBarManager
.is() )
106 m_xToolBarManager
->dispose();
107 m_xToolBarManager
.clear();
108 m_xConfigSource
.clear();
109 m_xConfigData
.clear();
115 void SAL_CALL
ToolBarWrapper::initialize( const Sequence
< Any
>& aArguments
) throw ( Exception
, RuntimeException
, std::exception
)
120 throw DisposedException();
122 if ( !m_bInitialized
)
124 UIConfigElementWrapperBase::initialize( aArguments
);
126 bool bPopupMode( false );
127 for ( sal_Int32 i
= 0; i
< aArguments
.getLength(); i
++ )
129 PropertyValue aPropValue
;
130 if ( aArguments
[i
] >>= aPropValue
)
132 if ( aPropValue
.Name
== "PopupMode" )
134 aPropValue
.Value
>>= bPopupMode
;
140 Reference
< XFrame
> xFrame( m_xWeakFrame
);
141 if ( xFrame
.is() && m_xConfigSource
.is() )
143 // Create VCL based toolbar which will be filled with settings data
144 ToolBox
* pToolBar
= 0;
145 ToolBarManager
* pToolBarManager
= 0;
147 SolarMutexGuard aSolarMutexGuard
;
148 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow( xFrame
->getContainerWindow() );
151 sal_uLong nStyles
= WB_LINESPACING
| WB_BORDER
| WB_SCROLL
| WB_MOVEABLE
| WB_3DLOOK
| WB_DOCKABLE
| WB_SIZEABLE
| WB_CLOSEABLE
;
153 pToolBar
= VclPtr
<ToolBox
>::Create( pWindow
, nStyles
);
154 pToolBarManager
= new ToolBarManager( m_xContext
, xFrame
, m_aResourceURL
, pToolBar
);
155 m_xToolBarManager
= Reference
< XComponent
>( static_cast< OWeakObject
*>( pToolBarManager
), UNO_QUERY
);
156 pToolBar
->WillUsePopupMode( bPopupMode
);
162 m_xConfigData
= m_xConfigSource
->getSettings( m_aResourceURL
, sal_False
);
163 if ( m_xConfigData
.is() && pToolBar
&& pToolBarManager
)
165 // Fill toolbar with container contents
166 pToolBarManager
->FillToolbar( m_xConfigData
);
167 pToolBar
->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
168 pToolBar
->EnableCustomize( true );
169 ::Size
aActSize( pToolBar
->GetSizePixel() );
170 ::Size
aSize( pToolBar
->CalcWindowSizePixel() );
171 aSize
.Width() = aActSize
.Width();
172 pToolBar
->SetOutputSizePixel( aSize
);
175 catch ( const NoSuchElementException
& )
177 // No settings in our configuration manager. This means we are
178 // a transient toolbar which has no persistent settings.
179 m_bPersistent
= false;
180 if ( pToolBar
&& pToolBarManager
)
182 pToolBar
->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
183 pToolBar
->EnableCustomize( true );
184 ::Size
aActSize( pToolBar
->GetSizePixel() );
185 ::Size
aSize( pToolBar
->CalcWindowSizePixel() );
186 aSize
.Width() = aActSize
.Width();
187 pToolBar
->SetOutputSizePixel( aSize
);
195 void SAL_CALL
ToolBarWrapper::disposing( const ::com::sun::star::lang::EventObject
& ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
201 void SAL_CALL
ToolBarWrapper::update() throw (::com::sun::star::uno::RuntimeException
, std::exception
)
206 throw DisposedException();
208 ToolBarManager
* pToolBarManager
= static_cast< ToolBarManager
*>( m_xToolBarManager
.get() );
209 if ( pToolBarManager
)
210 pToolBarManager
->CheckAndUpdateImages();
213 // XUIElementSettings
214 void SAL_CALL
ToolBarWrapper::updateSettings() throw (::com::sun::star::uno::RuntimeException
, std::exception
)
219 throw DisposedException();
221 if ( m_xToolBarManager
.is() )
223 if ( m_xConfigSource
.is() && m_bPersistent
)
227 ToolBarManager
* pToolBarManager
= static_cast< ToolBarManager
*>( m_xToolBarManager
.get() );
229 m_xConfigData
= m_xConfigSource
->getSettings( m_aResourceURL
, sal_False
);
230 if ( m_xConfigData
.is() )
231 pToolBarManager
->FillToolbar( m_xConfigData
);
233 catch ( const NoSuchElementException
& )
237 else if ( !m_bPersistent
)
239 // Transient toolbar: do nothing
244 void ToolBarWrapper::impl_fillNewData()
246 // Transient toolbar => Fill toolbar with new data
247 ToolBarManager
* pToolBarManager
= static_cast< ToolBarManager
*>( m_xToolBarManager
.get() );
248 if ( pToolBarManager
)
249 pToolBarManager
->FillToolbar( m_xConfigData
);
252 // XUIElement interface
253 Reference
< XInterface
> SAL_CALL
ToolBarWrapper::getRealInterface( ) throw (::com::sun::star::uno::RuntimeException
, std::exception
)
257 if ( m_xToolBarManager
.is() )
259 ToolBarManager
* pToolBarManager
= static_cast< ToolBarManager
*>( m_xToolBarManager
.get() );
260 if ( pToolBarManager
)
262 vcl::Window
* pWindow
= (vcl::Window
*)pToolBarManager
->GetToolBar();
263 return Reference
< XInterface
>( VCLUnoHelper::GetInterface( pWindow
), UNO_QUERY
);
267 return Reference
< XInterface
>();
271 void SAL_CALL
ToolBarWrapper::functionExecute(
272 const OUString
& aUIElementName
,
273 const OUString
& aCommand
)
274 throw (::com::sun::star::uno::RuntimeException
, std::exception
)
278 if ( m_xToolBarManager
.is() )
280 ToolBarManager
* pToolBarManager
= static_cast< ToolBarManager
*>( m_xToolBarManager
.get() );
281 if ( pToolBarManager
)
282 pToolBarManager
->notifyRegisteredControllers( aUIElementName
, aCommand
);
286 void SAL_CALL
ToolBarWrapper::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const com::sun::star::uno::Any
& aValue
) throw( com::sun::star::uno::Exception
, std::exception
)
288 SolarMutexResettableGuard aLock
;
289 bool bNoClose( m_bNoClose
);
292 UIConfigElementWrapperBase::setFastPropertyValue_NoBroadcast( nHandle
, aValue
);
296 bool bNewNoClose( m_bNoClose
);
297 if ( m_xToolBarManager
.is() && !m_bDisposed
&& ( bNewNoClose
!= bNoClose
))
299 ToolBarManager
* pToolBarManager
= static_cast< ToolBarManager
*>( m_xToolBarManager
.get() );
300 if ( pToolBarManager
)
302 ToolBox
* pToolBox
= pToolBarManager
->GetToolBar();
307 pToolBox
->SetStyle( pToolBox
->GetStyle() & ~WB_CLOSEABLE
);
308 pToolBox
->SetFloatStyle( pToolBox
->GetFloatStyle() & ~WB_CLOSEABLE
);
312 pToolBox
->SetStyle( pToolBox
->GetStyle() | WB_CLOSEABLE
);
313 pToolBox
->SetFloatStyle( pToolBox
->GetFloatStyle() | WB_CLOSEABLE
);
320 } // namespace framework
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */