1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_framework.hxx"
26 
27 //_________________________________________________________________________________________________________________
28 //	my own includes
29 //_________________________________________________________________________________________________________________
30 
31 
32 #include <uielement/addonstoolbarwrapper.hxx>
33 #include <threadhelp/resetableguard.hxx>
34 #include <framework/actiontriggerhelper.hxx>
35 #include <uielement/constitemcontainer.hxx>
36 #include <uielement/rootitemcontainer.hxx>
37 #include <uielement/addonstoolbarmanager.hxx>
38 
39 #ifndef __FRAMEWORK_UIELEMENT_TOOLBARW_HXX_
40 #include <uielement/toolbar.hxx>
41 #endif
42 
43 //_________________________________________________________________________________________________________________
44 //	interface includes
45 //_________________________________________________________________________________________________________________
46 #include <com/sun/star/lang/XServiceInfo.hpp>
47 #include <com/sun/star/lang/DisposedException.hpp>
48 #include <com/sun/star/beans/XPropertySet.hpp>
49 #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
50 #include <com/sun/star/awt/XMenuBar.hpp>
51 #include <com/sun/star/container/XIndexContainer.hpp>
52 #include <com/sun/star/container/XNameAccess.hpp>
53 #include <com/sun/star/ui/UIElementType.hpp>
54 
55 //_________________________________________________________________________________________________________________
56 //	other includes
57 //_________________________________________________________________________________________________________________
58 
59 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
60 #include <toolkit/helper/vclunohelper.hxx>
61 #endif
62 #include <toolkit/awt/vclxwindow.hxx>
63 #include <comphelper/processfactory.hxx>
64 
65 #include <svtools/miscopt.hxx>
66 #include <vcl/svapp.hxx>
67 #include <vcl/toolbox.hxx>
68 #include <rtl/logfile.hxx>
69 
70 using namespace com::sun::star::uno;
71 using namespace com::sun::star::beans;
72 using namespace com::sun::star::frame;
73 using namespace com::sun::star::lang;
74 using namespace com::sun::star::container;
75 using namespace com::sun::star::awt;
76 using namespace ::com::sun::star::ui;
77 
78 namespace framework
79 {
80 
AddonsToolBarWrapper(const Reference<XMultiServiceFactory> & xServiceManager)81 AddonsToolBarWrapper::AddonsToolBarWrapper( const Reference< XMultiServiceFactory >& xServiceManager ) :
82     UIElementWrapperBase( UIElementType::TOOLBAR ),
83     m_xServiceManager( xServiceManager )
84 {
85 }
86 
~AddonsToolBarWrapper()87 AddonsToolBarWrapper::~AddonsToolBarWrapper()
88 {
89 }
90 
91 // XComponent
dispose()92 void SAL_CALL AddonsToolBarWrapper::dispose() throw ( RuntimeException )
93 {
94     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
95 
96     com::sun::star::lang::EventObject aEvent( xThis );
97     m_aListenerContainer.disposeAndClear( aEvent );
98 
99     ResetableGuard aLock( m_aLock );
100 
101     if ( m_xToolBarManager.is() )
102         m_xToolBarManager->dispose();
103     m_xToolBarManager.clear();
104     m_xToolBarWindow.clear();
105 
106     m_bDisposed = sal_True;
107 }
108 
109 // XInitialization
initialize(const Sequence<Any> & aArguments)110 void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
111 {
112     ResetableGuard aLock( m_aLock );
113 
114     if ( m_bDisposed )
115         throw DisposedException();
116 
117     if ( !m_bInitialized )
118     {
119         UIElementWrapperBase::initialize( aArguments );
120 
121         for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
122         {
123             PropertyValue aPropValue;
124             if ( aArguments[n] >>= aPropValue )
125             {
126                 if ( aPropValue.Name.equalsAscii( "ConfigurationData" ))
127                     aPropValue.Value >>= m_aConfigData;
128             }
129         }
130 
131         Reference< XFrame > xFrame( m_xWeakFrame );
132         if ( xFrame.is() && m_aConfigData.getLength() > 0 )
133         {
134             // Create VCL based toolbar which will be filled with settings data
135             ToolBar* pToolBar = 0;
136             AddonsToolBarManager* pToolBarManager = 0;
137             {
138                 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
139                 Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
140                 if ( pWindow )
141                 {
142                     sal_uLong nStyles = WB_LINESPACING | WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
143 
144                     pToolBar = new ToolBar( pWindow, nStyles );
145                     m_xToolBarWindow = VCLUnoHelper::GetInterface( pToolBar );
146                     pToolBarManager = new AddonsToolBarManager( m_xServiceManager, xFrame, m_aResourceURL, pToolBar );
147                     pToolBar->SetToolBarManager( pToolBarManager );
148                     m_xToolBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
149                 }
150             }
151 
152             try
153             {
154                 if (( m_aConfigData.getLength() > 0 ) && pToolBar && pToolBarManager )
155                 {
156                     // Fill toolbar with container contents
157                     pToolBarManager->FillToolbar( m_aConfigData );
158                     pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
159                     pToolBar->EnableCustomize( sal_True );
160                     ::Size aActSize( pToolBar->GetSizePixel() );
161                     ::Size aSize( pToolBar->CalcWindowSizePixel() );
162                     aSize.Width() = aActSize.Width();
163 			        pToolBar->SetSizePixel( aSize );
164                 }
165             }
166             catch ( NoSuchElementException& )
167             {
168             }
169         }
170     }
171 }
172 
173 // XUIElement interface
getRealInterface()174 Reference< XInterface > SAL_CALL AddonsToolBarWrapper::getRealInterface() throw (::com::sun::star::uno::RuntimeException)
175 {
176     ResetableGuard aLock( m_aLock );
177 
178     if ( m_xToolBarManager.is() )
179     {
180         AddonsToolBarManager* pToolBarManager = static_cast< AddonsToolBarManager *>( m_xToolBarManager.get() );
181         if ( pToolBarManager )
182         {
183             Window* pWindow = (Window *)pToolBarManager->GetToolBar();
184             return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
185         }
186     }
187 
188     return Reference< XInterface >();
189 }
190 
191 } // namespace framework
192 
193