1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
30 
31 //_________________________________________________________________________________________________________________
32 //	my own includes
33 //_________________________________________________________________________________________________________________
34 
35 
36 #include <uielement/addonstoolbarwrapper.hxx>
37 #include <threadhelp/resetableguard.hxx>
38 #include <framework/actiontriggerhelper.hxx>
39 #include <uielement/constitemcontainer.hxx>
40 #include <uielement/rootitemcontainer.hxx>
41 #include <uielement/addonstoolbarmanager.hxx>
42 
43 #ifndef __FRAMEWORK_UIELEMENT_TOOLBARW_HXX_
44 #include <uielement/toolbar.hxx>
45 #endif
46 
47 //_________________________________________________________________________________________________________________
48 //	interface includes
49 //_________________________________________________________________________________________________________________
50 #include <com/sun/star/lang/XServiceInfo.hpp>
51 #include <com/sun/star/lang/DisposedException.hpp>
52 #include <com/sun/star/beans/XPropertySet.hpp>
53 #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
54 #include <com/sun/star/awt/XMenuBar.hpp>
55 #include <com/sun/star/container/XIndexContainer.hpp>
56 #include <com/sun/star/container/XNameAccess.hpp>
57 #include <com/sun/star/ui/UIElementType.hpp>
58 
59 //_________________________________________________________________________________________________________________
60 //	other includes
61 //_________________________________________________________________________________________________________________
62 
63 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
64 #include <toolkit/unohlp.hxx>
65 #endif
66 #include <toolkit/awt/vclxwindow.hxx>
67 #include <comphelper/processfactory.hxx>
68 
69 #include <svtools/miscopt.hxx>
70 #include <vcl/svapp.hxx>
71 #include <vcl/toolbox.hxx>
72 #include <rtl/logfile.hxx>
73 
74 using namespace com::sun::star::uno;
75 using namespace com::sun::star::beans;
76 using namespace com::sun::star::frame;
77 using namespace com::sun::star::lang;
78 using namespace com::sun::star::container;
79 using namespace com::sun::star::awt;
80 using namespace ::com::sun::star::ui;
81 
82 namespace framework
83 {
84 
85 AddonsToolBarWrapper::AddonsToolBarWrapper( const Reference< XMultiServiceFactory >& xServiceManager ) :
86     UIElementWrapperBase( UIElementType::TOOLBAR ),
87     m_xServiceManager( xServiceManager )
88 {
89 }
90 
91 AddonsToolBarWrapper::~AddonsToolBarWrapper()
92 {
93 }
94 
95 // XComponent
96 void SAL_CALL AddonsToolBarWrapper::dispose() throw ( RuntimeException )
97 {
98     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
99 
100     com::sun::star::lang::EventObject aEvent( xThis );
101     m_aListenerContainer.disposeAndClear( aEvent );
102 
103     ResetableGuard aLock( m_aLock );
104 
105     if ( m_xToolBarManager.is() )
106         m_xToolBarManager->dispose();
107     m_xToolBarManager.clear();
108     m_xToolBarWindow.clear();
109 
110     m_bDisposed = sal_True;
111 }
112 
113 // XInitialization
114 void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
115 {
116     ResetableGuard aLock( m_aLock );
117 
118     if ( m_bDisposed )
119         throw DisposedException();
120 
121     if ( !m_bInitialized )
122     {
123         UIElementWrapperBase::initialize( aArguments );
124 
125         for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
126         {
127             PropertyValue aPropValue;
128             if ( aArguments[n] >>= aPropValue )
129             {
130                 if ( aPropValue.Name.equalsAscii( "ConfigurationData" ))
131                     aPropValue.Value >>= m_aConfigData;
132             }
133         }
134 
135         Reference< XFrame > xFrame( m_xWeakFrame );
136         if ( xFrame.is() && m_aConfigData.getLength() > 0 )
137         {
138             // Create VCL based toolbar which will be filled with settings data
139             ToolBar* pToolBar = 0;
140             AddonsToolBarManager* pToolBarManager = 0;
141             {
142                 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
143                 Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
144                 if ( pWindow )
145                 {
146                     sal_uLong nStyles = WB_LINESPACING | WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
147 
148                     pToolBar = new ToolBar( pWindow, nStyles );
149                     m_xToolBarWindow = VCLUnoHelper::GetInterface( pToolBar );
150                     pToolBarManager = new AddonsToolBarManager( m_xServiceManager, xFrame, m_aResourceURL, pToolBar );
151                     pToolBar->SetToolBarManager( pToolBarManager );
152                     m_xToolBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
153                 }
154             }
155 
156             try
157             {
158                 if (( m_aConfigData.getLength() > 0 ) && pToolBar && pToolBarManager )
159                 {
160                     // Fill toolbar with container contents
161                     pToolBarManager->FillToolbar( m_aConfigData );
162                     pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
163                     pToolBar->EnableCustomize( sal_True );
164                     ::Size aActSize( pToolBar->GetSizePixel() );
165                     ::Size aSize( pToolBar->CalcWindowSizePixel() );
166                     aSize.Width() = aActSize.Width();
167 			        pToolBar->SetSizePixel( aSize );
168                 }
169             }
170             catch ( NoSuchElementException& )
171             {
172             }
173         }
174     }
175 }
176 
177 // XUIElement interface
178 Reference< XInterface > SAL_CALL AddonsToolBarWrapper::getRealInterface() throw (::com::sun::star::uno::RuntimeException)
179 {
180     ResetableGuard aLock( m_aLock );
181 
182     if ( m_xToolBarManager.is() )
183     {
184         AddonsToolBarManager* pToolBarManager = static_cast< AddonsToolBarManager *>( m_xToolBarManager.get() );
185         if ( pToolBarManager )
186         {
187             Window* pWindow = (Window *)pToolBarManager->GetToolBar();
188             return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
189         }
190     }
191 
192     return Reference< XInterface >();
193 }
194 
195 } // namespace framework
196 
197