1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6d739b60SAndrew Rist  * distributed with this work for additional information
6*6d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6d739b60SAndrew Rist  *
11*6d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6d739b60SAndrew Rist  *
13*6d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist  * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
17*6d739b60SAndrew Rist  * specific language governing permissions and limitations
18*6d739b60SAndrew Rist  * under the License.
19*6d739b60SAndrew Rist  *
20*6d739b60SAndrew Rist  *************************************************************/
21*6d739b60SAndrew Rist 
22*6d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir //_________________________________________________________________________________________________________________
27cdf0e10cSrcweir //	my own includes
28cdf0e10cSrcweir //_________________________________________________________________________________________________________________
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <uielement/toolbarwrapper.hxx>
32cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
33cdf0e10cSrcweir #include <framework/actiontriggerhelper.hxx>
34cdf0e10cSrcweir #include <uielement/constitemcontainer.hxx>
35cdf0e10cSrcweir #include <uielement/rootitemcontainer.hxx>
36cdf0e10cSrcweir #include <uielement/toolbarmanager.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_TOOLBARW_HXX_
39cdf0e10cSrcweir #include <uielement/toolbar.hxx>
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //_________________________________________________________________________________________________________________
43cdf0e10cSrcweir //	interface includes
44cdf0e10cSrcweir //_________________________________________________________________________________________________________________
45cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
46cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
47cdf0e10cSrcweir #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
48cdf0e10cSrcweir #include <com/sun/star/awt/XMenuBar.hpp>
49cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
50cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
51cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp>
52cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //_________________________________________________________________________________________________________________
55cdf0e10cSrcweir //	other includes
56cdf0e10cSrcweir //_________________________________________________________________________________________________________________
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
59cdf0e10cSrcweir #include <toolkit/unohlp.hxx>
60cdf0e10cSrcweir #endif
61cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
62cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
63cdf0e10cSrcweir 
64cdf0e10cSrcweir #include <svtools/miscopt.hxx>
65cdf0e10cSrcweir #include <vcl/svapp.hxx>
66cdf0e10cSrcweir #include <vcl/toolbox.hxx>
67cdf0e10cSrcweir #include <rtl/logfile.hxx>
68cdf0e10cSrcweir 
69cdf0e10cSrcweir using namespace com::sun::star;
70cdf0e10cSrcweir using namespace com::sun::star::uno;
71cdf0e10cSrcweir using namespace com::sun::star::beans;
72cdf0e10cSrcweir using namespace com::sun::star::frame;
73cdf0e10cSrcweir using namespace com::sun::star::lang;
74cdf0e10cSrcweir using namespace com::sun::star::container;
75cdf0e10cSrcweir using namespace com::sun::star::awt;
76cdf0e10cSrcweir using namespace ::com::sun::star::ui;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir namespace framework
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 
ToolBarWrapper(const Reference<XMultiServiceFactory> & xServiceManager)81cdf0e10cSrcweir ToolBarWrapper::ToolBarWrapper( const Reference< XMultiServiceFactory >& xServiceManager ) :
82cdf0e10cSrcweir     UIConfigElementWrapperBase( UIElementType::TOOLBAR,xServiceManager )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
~ToolBarWrapper()86cdf0e10cSrcweir ToolBarWrapper::~ToolBarWrapper()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir // XInterface
acquire()91cdf0e10cSrcweir void SAL_CALL ToolBarWrapper::acquire() throw()
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     UIConfigElementWrapperBase::acquire();
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
release()96cdf0e10cSrcweir void SAL_CALL ToolBarWrapper::release() throw()
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     UIConfigElementWrapperBase::release();
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
queryInterface(const uno::Type & rType)101cdf0e10cSrcweir uno::Any SAL_CALL ToolBarWrapper::queryInterface( const uno::Type & rType )
102cdf0e10cSrcweir throw( ::com::sun::star::uno::RuntimeException )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	Any a = ::cppu::queryInterface(
105cdf0e10cSrcweir 				rType ,
106cdf0e10cSrcweir 				SAL_STATIC_CAST( ::com::sun::star::ui::XUIFunctionListener*, this ) );
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	if( a.hasValue() )
109cdf0e10cSrcweir 		return a;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	return UIConfigElementWrapperBase::queryInterface( rType );
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir // XComponent
dispose()115cdf0e10cSrcweir void SAL_CALL ToolBarWrapper::dispose() throw ( RuntimeException )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	{
120cdf0e10cSrcweir 		ResetableGuard aLock( m_aLock );
121cdf0e10cSrcweir 		if ( m_bDisposed )
122cdf0e10cSrcweir 			return;
123cdf0e10cSrcweir 	}
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	com::sun::star::lang::EventObject aEvent( xThis );
126cdf0e10cSrcweir     m_aListenerContainer.disposeAndClear( aEvent );
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     if ( m_xToolBarManager.is() )
131cdf0e10cSrcweir         m_xToolBarManager->dispose();
132cdf0e10cSrcweir     m_xToolBarManager.clear();
133cdf0e10cSrcweir     m_xConfigSource.clear();
134cdf0e10cSrcweir     m_xConfigData.clear();
135cdf0e10cSrcweir     m_xToolBarWindow.clear();
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     m_bDisposed = sal_True;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir // XInitialization
initialize(const Sequence<Any> & aArguments)141cdf0e10cSrcweir void SAL_CALL ToolBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     if ( m_bDisposed )
146cdf0e10cSrcweir         throw DisposedException();
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     if ( !m_bInitialized )
149cdf0e10cSrcweir     {
150cdf0e10cSrcweir         UIConfigElementWrapperBase::initialize( aArguments );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         sal_Bool bPopupMode( sal_False );
153cdf0e10cSrcweir         for ( sal_Int32 i = 0; i < aArguments.getLength(); i++ )
154cdf0e10cSrcweir         {
155cdf0e10cSrcweir             PropertyValue aPropValue;
156cdf0e10cSrcweir             if ( aArguments[i] >>= aPropValue )
157cdf0e10cSrcweir             {
158cdf0e10cSrcweir                 if ( aPropValue.Name.equalsAsciiL( "PopupMode", 9 ))
159cdf0e10cSrcweir                 {
160cdf0e10cSrcweir                     aPropValue.Value >>= bPopupMode;
161cdf0e10cSrcweir                     break;
162cdf0e10cSrcweir                 }
163cdf0e10cSrcweir             }
164cdf0e10cSrcweir         }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir         Reference< XFrame > xFrame( m_xWeakFrame );
167cdf0e10cSrcweir         if ( xFrame.is() && m_xConfigSource.is() )
168cdf0e10cSrcweir         {
169cdf0e10cSrcweir             // Create VCL based toolbar which will be filled with settings data
170cdf0e10cSrcweir             ToolBar* pToolBar = 0;
171cdf0e10cSrcweir             ToolBarManager* pToolBarManager = 0;
172cdf0e10cSrcweir             {
173cdf0e10cSrcweir                 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
174cdf0e10cSrcweir                 Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
175cdf0e10cSrcweir                 if ( pWindow )
176cdf0e10cSrcweir                 {
177cdf0e10cSrcweir                     sal_uLong nStyles = WB_LINESPACING | WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
178cdf0e10cSrcweir 
179cdf0e10cSrcweir                     pToolBar = new ToolBar( pWindow, nStyles );
180cdf0e10cSrcweir                     m_xToolBarWindow = VCLUnoHelper::GetInterface( pToolBar );
181cdf0e10cSrcweir                     pToolBarManager = new ToolBarManager( m_xServiceFactory, xFrame, m_aResourceURL, pToolBar );
182cdf0e10cSrcweir                     pToolBar->SetToolBarManager( pToolBarManager );
183cdf0e10cSrcweir                     m_xToolBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
184cdf0e10cSrcweir                     pToolBar->WillUsePopupMode( bPopupMode );
185cdf0e10cSrcweir                 }
186cdf0e10cSrcweir             }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir             try
189cdf0e10cSrcweir             {
190cdf0e10cSrcweir                 m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
191cdf0e10cSrcweir                 if ( m_xConfigData.is() && pToolBar && pToolBarManager )
192cdf0e10cSrcweir                 {
193cdf0e10cSrcweir                     // Fill toolbar with container contents
194cdf0e10cSrcweir                     pToolBarManager->FillToolbar( m_xConfigData );
195cdf0e10cSrcweir                     pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
196cdf0e10cSrcweir                     pToolBar->EnableCustomize( sal_True );
197cdf0e10cSrcweir                     ::Size aActSize( pToolBar->GetSizePixel() );
198cdf0e10cSrcweir                     ::Size aSize( pToolBar->CalcWindowSizePixel() );
199cdf0e10cSrcweir                     aSize.Width() = aActSize.Width();
200cdf0e10cSrcweir                     pToolBar->SetOutputSizePixel( aSize );
201cdf0e10cSrcweir                 }
202cdf0e10cSrcweir             }
203cdf0e10cSrcweir             catch ( NoSuchElementException& )
204cdf0e10cSrcweir             {
205cdf0e10cSrcweir                 // No settings in our configuration manager. This means we are
206cdf0e10cSrcweir                 // a transient toolbar which has no persistent settings.
207cdf0e10cSrcweir                 m_bPersistent = sal_False;
208cdf0e10cSrcweir                 if ( pToolBar && pToolBarManager )
209cdf0e10cSrcweir                 {
210cdf0e10cSrcweir                     pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
211cdf0e10cSrcweir                     pToolBar->EnableCustomize( sal_True );
212cdf0e10cSrcweir                     ::Size aActSize( pToolBar->GetSizePixel() );
213cdf0e10cSrcweir                     ::Size aSize( pToolBar->CalcWindowSizePixel() );
214cdf0e10cSrcweir                     aSize.Width() = aActSize.Width();
215cdf0e10cSrcweir                     pToolBar->SetOutputSizePixel( aSize );
216cdf0e10cSrcweir                 }
217cdf0e10cSrcweir             }
218cdf0e10cSrcweir         }
219cdf0e10cSrcweir     }
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir // XEventListener
disposing(const::com::sun::star::lang::EventObject &)223cdf0e10cSrcweir void SAL_CALL ToolBarWrapper::disposing( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     // nothing todo
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir // XUpdatable
update()229cdf0e10cSrcweir void SAL_CALL ToolBarWrapper::update() throw (::com::sun::star::uno::RuntimeException)
230cdf0e10cSrcweir {
231cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
232cdf0e10cSrcweir 
233cdf0e10cSrcweir     if ( m_bDisposed )
234cdf0e10cSrcweir         throw DisposedException();
235cdf0e10cSrcweir 
236cdf0e10cSrcweir     ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
237cdf0e10cSrcweir     if ( pToolBarManager )
238cdf0e10cSrcweir         pToolBarManager->CheckAndUpdateImages();
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir // XUIElementSettings
updateSettings()242cdf0e10cSrcweir void SAL_CALL ToolBarWrapper::updateSettings() throw (::com::sun::star::uno::RuntimeException)
243cdf0e10cSrcweir {
244cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     if ( m_bDisposed )
247cdf0e10cSrcweir         throw DisposedException();
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     if ( m_xToolBarManager.is() )
250cdf0e10cSrcweir     {
251cdf0e10cSrcweir         if ( m_xConfigSource.is() && m_bPersistent )
252cdf0e10cSrcweir         {
253cdf0e10cSrcweir             try
254cdf0e10cSrcweir             {
255cdf0e10cSrcweir                 ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
256cdf0e10cSrcweir 
257cdf0e10cSrcweir                 m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
258cdf0e10cSrcweir                 if ( m_xConfigData.is() )
259cdf0e10cSrcweir                     pToolBarManager->FillToolbar( m_xConfigData );
260cdf0e10cSrcweir             }
261cdf0e10cSrcweir             catch ( NoSuchElementException& )
262cdf0e10cSrcweir             {
263cdf0e10cSrcweir             }
264cdf0e10cSrcweir         }
265cdf0e10cSrcweir         else if ( !m_bPersistent )
266cdf0e10cSrcweir         {
267cdf0e10cSrcweir             // Transient toolbar: do nothing
268cdf0e10cSrcweir         }
269cdf0e10cSrcweir     }
270cdf0e10cSrcweir }
271cdf0e10cSrcweir 
impl_fillNewData()272cdf0e10cSrcweir void ToolBarWrapper::impl_fillNewData()
273cdf0e10cSrcweir {
274cdf0e10cSrcweir     // Transient toolbar => Fill toolbar with new data
275cdf0e10cSrcweir     ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
276cdf0e10cSrcweir     if ( pToolBarManager )
277cdf0e10cSrcweir         pToolBarManager->FillToolbar( m_xConfigData );
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir // XUIElement interface
getRealInterface()281cdf0e10cSrcweir Reference< XInterface > SAL_CALL ToolBarWrapper::getRealInterface(  ) throw (::com::sun::star::uno::RuntimeException)
282cdf0e10cSrcweir {
283cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
284cdf0e10cSrcweir 
285cdf0e10cSrcweir     if ( m_xToolBarManager.is() )
286cdf0e10cSrcweir     {
287cdf0e10cSrcweir         ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
288cdf0e10cSrcweir         if ( pToolBarManager )
289cdf0e10cSrcweir         {
290cdf0e10cSrcweir             Window* pWindow = (Window *)pToolBarManager->GetToolBar();
291cdf0e10cSrcweir             return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
292cdf0e10cSrcweir         }
293cdf0e10cSrcweir     }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     return Reference< XInterface >();
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir //XUIFunctionExecute
functionExecute(const::rtl::OUString & aUIElementName,const::rtl::OUString & aCommand)299cdf0e10cSrcweir void SAL_CALL ToolBarWrapper::functionExecute(
300cdf0e10cSrcweir     const ::rtl::OUString& aUIElementName,
301cdf0e10cSrcweir     const ::rtl::OUString& aCommand )
302cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
303cdf0e10cSrcweir {
304cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
305cdf0e10cSrcweir 
306cdf0e10cSrcweir     if ( m_xToolBarManager.is() )
307cdf0e10cSrcweir     {
308cdf0e10cSrcweir         ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
309cdf0e10cSrcweir         if ( pToolBarManager )
310cdf0e10cSrcweir             pToolBarManager->notifyRegisteredControllers( aUIElementName, aCommand );
311cdf0e10cSrcweir     }
312cdf0e10cSrcweir }
313cdf0e10cSrcweir 
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const com::sun::star::uno::Any & aValue)314cdf0e10cSrcweir void SAL_CALL ToolBarWrapper::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const com::sun::star::uno::Any&  aValue ) throw( com::sun::star::uno::Exception )
315cdf0e10cSrcweir {
316cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
317cdf0e10cSrcweir     sal_Bool bNoClose( m_bNoClose );
318cdf0e10cSrcweir     aLock.unlock();
319cdf0e10cSrcweir 
320cdf0e10cSrcweir     UIConfigElementWrapperBase::setFastPropertyValue_NoBroadcast( nHandle, aValue );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir     aLock.lock();
323cdf0e10cSrcweir 
324cdf0e10cSrcweir     sal_Bool bNewNoClose( m_bNoClose );
325cdf0e10cSrcweir     if ( m_xToolBarManager.is() && !m_bDisposed && ( bNewNoClose != bNoClose ))
326cdf0e10cSrcweir     {
327cdf0e10cSrcweir         ToolBarManager* pToolBarManager = static_cast< ToolBarManager *>( m_xToolBarManager.get() );
328cdf0e10cSrcweir         if ( pToolBarManager )
329cdf0e10cSrcweir         {
330cdf0e10cSrcweir             ToolBox* pToolBox = pToolBarManager->GetToolBar();
331cdf0e10cSrcweir             if ( pToolBox )
332cdf0e10cSrcweir             {
333cdf0e10cSrcweir                 if ( bNewNoClose )
334cdf0e10cSrcweir                 {
335cdf0e10cSrcweir                     pToolBox->SetStyle( pToolBox->GetStyle() & ~WB_CLOSEABLE );
336cdf0e10cSrcweir                     pToolBox->SetFloatStyle( pToolBox->GetFloatStyle() & ~WB_CLOSEABLE );
337cdf0e10cSrcweir                 }
338cdf0e10cSrcweir                 else
339cdf0e10cSrcweir                 {
340cdf0e10cSrcweir                     pToolBox->SetStyle( pToolBox->GetStyle() | WB_CLOSEABLE );
341cdf0e10cSrcweir                     pToolBox->SetFloatStyle( pToolBox->GetFloatStyle() | WB_CLOSEABLE );
342cdf0e10cSrcweir                 }
343cdf0e10cSrcweir             }
344cdf0e10cSrcweir         }
345cdf0e10cSrcweir     }
346cdf0e10cSrcweir }
347cdf0e10cSrcweir 
348cdf0e10cSrcweir } // namespace framework
349cdf0e10cSrcweir 
350