update dev300-m58
[ooovba.git] / framework / source / uifactory / menubarfactory.cxx
blobf07700c20b22efa76ef4f8d5b289e97f1ce07ee3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: menubarfactory.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
33 #include <uifactory/menubarfactory.hxx>
35 //_________________________________________________________________________________________________________________
36 // my own includes
37 //_________________________________________________________________________________________________________________
38 #include <threadhelp/resetableguard.hxx>
39 #include "services.h"
40 #include <uielement/menubarwrapper.hxx>
42 //_________________________________________________________________________________________________________________
43 // interface includes
44 //_________________________________________________________________________________________________________________
45 #include <com/sun/star/util/XURLTransformer.hpp>
46 #include <com/sun/star/frame/XFrame.hpp>
47 #include <com/sun/star/frame/XModel.hpp>
48 #include <com/sun/star/lang/XInitialization.hpp>
49 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
51 #ifndef _COM_SUN_STAR_UI_XUICONFIGURATIONMANAGERSUPLLIER_HPP_
52 #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
53 #endif
55 //_________________________________________________________________________________________________________________
56 // includes of other projects
57 //_________________________________________________________________________________________________________________
59 #ifndef _VCL_MENU_HXX_
60 #include <vcl/menu.hxx>
61 #endif
62 #include <vcl/svapp.hxx>
63 #include <tools/urlobj.hxx>
64 #include <rtl/ustrbuf.hxx>
65 #include <rtl/logfile.hxx>
67 //_________________________________________________________________________________________________________________
68 // Defines
69 //_________________________________________________________________________________________________________________
70 //
72 using namespace com::sun::star::uno;
73 using namespace com::sun::star::lang;
74 using namespace com::sun::star::frame;
75 using namespace com::sun::star::beans;
76 using namespace com::sun::star::util;
77 using namespace ::com::sun::star::ui;
79 namespace framework
82 //*****************************************************************************************************************
83 // XInterface, XTypeProvider, XServiceInfo
84 //*****************************************************************************************************************
85 DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( MenuBarFactory ,
86 ::cppu::OWeakObject ,
87 SERVICENAME_MENUBARFACTORY ,
88 IMPLEMENTATIONNAME_MENUBARFACTORY
91 DEFINE_INIT_SERVICE ( MenuBarFactory, {} )
93 MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
94 ThreadHelpBase()
95 , m_xServiceManager( xServiceManager )
96 , m_xModuleManager( xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY )
99 MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager,bool ) :
100 ThreadHelpBase(&Application::GetSolarMutex())
101 , m_xServiceManager( xServiceManager )
102 , m_xModuleManager( xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY )
106 MenuBarFactory::~MenuBarFactory()
110 // XUIElementFactory
111 Reference< XUIElement > SAL_CALL MenuBarFactory::createUIElement(
112 const ::rtl::OUString& ResourceURL,
113 const Sequence< PropertyValue >& Args )
114 throw ( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException )
116 // SAFE
117 ResetableGuard aLock( m_aLock );
118 MenuBarWrapper* pMenuBarWrapper = new MenuBarWrapper( m_xServiceManager );
119 Reference< ::com::sun::star::ui::XUIElement > xMenuBar( (OWeakObject *)pMenuBarWrapper, UNO_QUERY );
120 Reference< ::com::sun::star::frame::XModuleManager > xModuleManager = m_xModuleManager;
121 aLock.unlock();
122 CreateUIElement(ResourceURL,Args,"MenuOnly","private:resource/menubar/",xMenuBar,xModuleManager,m_xServiceManager);
123 return xMenuBar;
125 void MenuBarFactory::CreateUIElement(const ::rtl::OUString& ResourceURL
126 , const Sequence< PropertyValue >& Args
127 ,const char* _pExtraMode
128 ,const char* _pAsciiName
129 ,const Reference< ::com::sun::star::ui::XUIElement >& _xMenuBar
130 ,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager >& _xModuleManager
131 ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xServiceManager)
133 Reference< XUIConfigurationManager > xCfgMgr;
134 Reference< XUIConfigurationManager > xConfigSource;
135 Reference< XFrame > xFrame;
136 rtl::OUString aResourceURL( ResourceURL );
137 sal_Bool bPersistent( sal_True );
138 sal_Bool bExtraMode( sal_False );
140 for ( sal_Int32 n = 0; n < Args.getLength(); n++ )
142 if ( Args[n].Name.equalsAscii( "ConfigurationSource" ))
143 Args[n].Value >>= xConfigSource;
144 else if ( Args[n].Name.equalsAscii( "Frame" ))
145 Args[n].Value >>= xFrame;
146 else if ( Args[n].Name.equalsAscii( "ResourceURL" ))
147 Args[n].Value >>= aResourceURL;
148 else if ( Args[n].Name.equalsAscii( "Persistent" ))
149 Args[n].Value >>= bPersistent;
150 else if ( _pExtraMode && Args[n].Name.equalsAscii( _pExtraMode ))
151 Args[n].Value >>= bExtraMode;
152 } // for ( sal_Int32 n = 0; n < Args.getLength(); n++ )
153 if ( aResourceURL.indexOf( rtl::OUString::createFromAscii(_pAsciiName)) != 0 )
154 throw IllegalArgumentException();
156 // Identify frame and determine document based ui configuration manager/module ui configuration manager
157 if ( xFrame.is() && !xConfigSource.is() )
159 bool bHasSettings( false );
160 Reference< XModel > xModel;
162 Reference< XController > xController = xFrame->getController();
163 if ( xController.is() )
164 xModel = xController->getModel();
166 if ( xModel.is() )
168 Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY );
169 if ( xUIConfigurationManagerSupplier.is() )
171 xCfgMgr = xUIConfigurationManagerSupplier->getUIConfigurationManager();
172 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
176 if ( !bHasSettings )
178 rtl::OUString aModuleIdentifier = _xModuleManager->identify( Reference< XInterface >( xFrame, UNO_QUERY ));
179 if ( aModuleIdentifier.getLength() )
181 Reference< ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier(
182 _xServiceManager->createInstance( SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ), UNO_QUERY );
183 xCfgMgr = xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier );
184 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
189 PropertyValue aPropValue;
190 Sequence< Any > aPropSeq( _pExtraMode ? 5 : 4);
191 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
192 aPropValue.Value <<= xFrame;
193 aPropSeq[0] <<= aPropValue;
194 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" ));
195 aPropValue.Value <<= xCfgMgr;
196 aPropSeq[1] <<= aPropValue;
197 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" ));
198 aPropValue.Value <<= aResourceURL;
199 aPropSeq[2] <<= aPropValue;
200 aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
201 aPropValue.Value <<= bPersistent;
202 aPropSeq[3] <<= aPropValue;
203 if ( _pExtraMode )
205 aPropValue.Name = rtl::OUString::createFromAscii(_pExtraMode);
206 aPropValue.Value <<= bExtraMode;
207 aPropSeq[4] <<= aPropValue;
210 vos::OGuard aGuard( Application::GetSolarMutex() );
211 Reference< XInitialization > xInit( _xMenuBar, UNO_QUERY );
212 xInit->initialize( aPropSeq );
215 } // namespace framework