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
10cdf0e10cSrcweir *
11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
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.
19cdf0e10cSrcweir *
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 //_________________________________________________________________________________________________________________
28cdf0e10cSrcweir // my own includes
29cdf0e10cSrcweir //_________________________________________________________________________________________________________________
30cdf0e10cSrcweir
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <uielement/addonstoolbarwrapper.hxx>
33cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
34cdf0e10cSrcweir #include <framework/actiontriggerhelper.hxx>
35cdf0e10cSrcweir #include <uielement/constitemcontainer.hxx>
36cdf0e10cSrcweir #include <uielement/rootitemcontainer.hxx>
37cdf0e10cSrcweir #include <uielement/addonstoolbarmanager.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_TOOLBARW_HXX_
40cdf0e10cSrcweir #include <uielement/toolbar.hxx>
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir
43cdf0e10cSrcweir //_________________________________________________________________________________________________________________
44cdf0e10cSrcweir // interface includes
45cdf0e10cSrcweir //_________________________________________________________________________________________________________________
46cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
47cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
48cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
49cdf0e10cSrcweir #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
50cdf0e10cSrcweir #include <com/sun/star/awt/XMenuBar.hpp>
51cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
52cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
53cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp>
54cdf0e10cSrcweir
55cdf0e10cSrcweir //_________________________________________________________________________________________________________________
56cdf0e10cSrcweir // other includes
57cdf0e10cSrcweir //_________________________________________________________________________________________________________________
58cdf0e10cSrcweir
59cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
60cdf0e10cSrcweir #include <toolkit/unohlp.hxx>
61cdf0e10cSrcweir #endif
62cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
63cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
64cdf0e10cSrcweir
65cdf0e10cSrcweir #include <svtools/miscopt.hxx>
66cdf0e10cSrcweir #include <vcl/svapp.hxx>
67cdf0e10cSrcweir #include <vcl/toolbox.hxx>
68cdf0e10cSrcweir #include <rtl/logfile.hxx>
69cdf0e10cSrcweir
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
AddonsToolBarWrapper(const Reference<XMultiServiceFactory> & xServiceManager)81cdf0e10cSrcweir AddonsToolBarWrapper::AddonsToolBarWrapper( const Reference< XMultiServiceFactory >& xServiceManager ) :
82cdf0e10cSrcweir UIElementWrapperBase( UIElementType::TOOLBAR ),
83cdf0e10cSrcweir m_xServiceManager( xServiceManager )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
~AddonsToolBarWrapper()87cdf0e10cSrcweir AddonsToolBarWrapper::~AddonsToolBarWrapper()
88cdf0e10cSrcweir {
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
91cdf0e10cSrcweir // XComponent
dispose()92cdf0e10cSrcweir void SAL_CALL AddonsToolBarWrapper::dispose() throw ( RuntimeException )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
95cdf0e10cSrcweir
96cdf0e10cSrcweir com::sun::star::lang::EventObject aEvent( xThis );
97cdf0e10cSrcweir m_aListenerContainer.disposeAndClear( aEvent );
98cdf0e10cSrcweir
99cdf0e10cSrcweir ResetableGuard aLock( m_aLock );
100cdf0e10cSrcweir
101cdf0e10cSrcweir if ( m_xToolBarManager.is() )
102cdf0e10cSrcweir m_xToolBarManager->dispose();
103cdf0e10cSrcweir m_xToolBarManager.clear();
104cdf0e10cSrcweir m_xToolBarWindow.clear();
105cdf0e10cSrcweir
106cdf0e10cSrcweir m_bDisposed = sal_True;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
109cdf0e10cSrcweir // XInitialization
initialize(const Sequence<Any> & aArguments)110cdf0e10cSrcweir void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir ResetableGuard aLock( m_aLock );
113cdf0e10cSrcweir
114cdf0e10cSrcweir if ( m_bDisposed )
115cdf0e10cSrcweir throw DisposedException();
116cdf0e10cSrcweir
117cdf0e10cSrcweir if ( !m_bInitialized )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir UIElementWrapperBase::initialize( aArguments );
120cdf0e10cSrcweir
121cdf0e10cSrcweir for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir PropertyValue aPropValue;
124cdf0e10cSrcweir if ( aArguments[n] >>= aPropValue )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir if ( aPropValue.Name.equalsAscii( "ConfigurationData" ))
127cdf0e10cSrcweir aPropValue.Value >>= m_aConfigData;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir Reference< XFrame > xFrame( m_xWeakFrame );
132cdf0e10cSrcweir if ( xFrame.is() && m_aConfigData.getLength() > 0 )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir // Create VCL based toolbar which will be filled with settings data
135cdf0e10cSrcweir ToolBar* pToolBar = 0;
136cdf0e10cSrcweir AddonsToolBarManager* pToolBarManager = 0;
137cdf0e10cSrcweir {
138cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
139cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
140cdf0e10cSrcweir if ( pWindow )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir sal_uLong nStyles = WB_LINESPACING | WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
143cdf0e10cSrcweir
144cdf0e10cSrcweir pToolBar = new ToolBar( pWindow, nStyles );
145cdf0e10cSrcweir m_xToolBarWindow = VCLUnoHelper::GetInterface( pToolBar );
146cdf0e10cSrcweir pToolBarManager = new AddonsToolBarManager( m_xServiceManager, xFrame, m_aResourceURL, pToolBar );
147cdf0e10cSrcweir pToolBar->SetToolBarManager( pToolBarManager );
148cdf0e10cSrcweir m_xToolBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
149cdf0e10cSrcweir }
150cdf0e10cSrcweir }
151cdf0e10cSrcweir
152cdf0e10cSrcweir try
153cdf0e10cSrcweir {
154cdf0e10cSrcweir if (( m_aConfigData.getLength() > 0 ) && pToolBar && pToolBarManager )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir // Fill toolbar with container contents
157cdf0e10cSrcweir pToolBarManager->FillToolbar( m_aConfigData );
158cdf0e10cSrcweir pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
159cdf0e10cSrcweir pToolBar->EnableCustomize( sal_True );
160cdf0e10cSrcweir ::Size aActSize( pToolBar->GetSizePixel() );
161cdf0e10cSrcweir ::Size aSize( pToolBar->CalcWindowSizePixel() );
162cdf0e10cSrcweir aSize.Width() = aActSize.Width();
163cdf0e10cSrcweir pToolBar->SetSizePixel( aSize );
164cdf0e10cSrcweir }
165cdf0e10cSrcweir }
166cdf0e10cSrcweir catch ( NoSuchElementException& )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir }
169cdf0e10cSrcweir }
170cdf0e10cSrcweir }
171cdf0e10cSrcweir }
172cdf0e10cSrcweir
173cdf0e10cSrcweir // XUIElement interface
getRealInterface()174cdf0e10cSrcweir Reference< XInterface > SAL_CALL AddonsToolBarWrapper::getRealInterface() throw (::com::sun::star::uno::RuntimeException)
175cdf0e10cSrcweir {
176cdf0e10cSrcweir ResetableGuard aLock( m_aLock );
177cdf0e10cSrcweir
178cdf0e10cSrcweir if ( m_xToolBarManager.is() )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir AddonsToolBarManager* pToolBarManager = static_cast< AddonsToolBarManager *>( m_xToolBarManager.get() );
181cdf0e10cSrcweir if ( pToolBarManager )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir Window* pWindow = (Window *)pToolBarManager->GetToolBar();
184cdf0e10cSrcweir return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
185cdf0e10cSrcweir }
186cdf0e10cSrcweir }
187cdf0e10cSrcweir
188cdf0e10cSrcweir return Reference< XInterface >();
189cdf0e10cSrcweir }
190cdf0e10cSrcweir
191cdf0e10cSrcweir } // namespace framework
192cdf0e10cSrcweir
193