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 #include <uifactory/menubarfactory.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir //_________________________________________________________________________________________________________________
29cdf0e10cSrcweir //	my own includes
30cdf0e10cSrcweir //_________________________________________________________________________________________________________________
31cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
32cdf0e10cSrcweir #include "services.h"
33cdf0e10cSrcweir #include <uielement/menubarwrapper.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //_________________________________________________________________________________________________________________
36cdf0e10cSrcweir //	interface includes
37cdf0e10cSrcweir //_________________________________________________________________________________________________________________
38cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
39cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
40cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
41cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
42cdf0e10cSrcweir #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UI_XUICONFIGURATIONMANAGERSUPLLIER_HPP_
45cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //_________________________________________________________________________________________________________________
49cdf0e10cSrcweir //	includes of other projects
50cdf0e10cSrcweir //_________________________________________________________________________________________________________________
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #ifndef _VCL_MENU_HXX_
53cdf0e10cSrcweir #include <vcl/menu.hxx>
54cdf0e10cSrcweir #endif
55cdf0e10cSrcweir #include <vcl/svapp.hxx>
56cdf0e10cSrcweir #include <tools/urlobj.hxx>
57cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
58cdf0e10cSrcweir #include <rtl/logfile.hxx>
59cdf0e10cSrcweir 
60cdf0e10cSrcweir //_________________________________________________________________________________________________________________
61cdf0e10cSrcweir //	Defines
62cdf0e10cSrcweir //_________________________________________________________________________________________________________________
63cdf0e10cSrcweir //
64cdf0e10cSrcweir 
65cdf0e10cSrcweir using namespace com::sun::star::uno;
66cdf0e10cSrcweir using namespace com::sun::star::lang;
67cdf0e10cSrcweir using namespace com::sun::star::frame;
68cdf0e10cSrcweir using namespace com::sun::star::beans;
69cdf0e10cSrcweir using namespace com::sun::star::util;
70cdf0e10cSrcweir using namespace ::com::sun::star::ui;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir namespace framework
73cdf0e10cSrcweir {
74cdf0e10cSrcweir 
75cdf0e10cSrcweir //*****************************************************************************************************************
76cdf0e10cSrcweir //	XInterface, XTypeProvider, XServiceInfo
77cdf0e10cSrcweir //*****************************************************************************************************************
DEFINE_XSERVICEINFO_ONEINSTANCESERVICE(MenuBarFactory,::cppu::OWeakObject,SERVICENAME_MENUBARFACTORY,IMPLEMENTATIONNAME_MENUBARFACTORY)78cdf0e10cSrcweir DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   MenuBarFactory				                    ,
79cdf0e10cSrcweir                                             ::cppu::OWeakObject							    ,
80cdf0e10cSrcweir                                             SERVICENAME_MENUBARFACTORY	                    ,
81cdf0e10cSrcweir 											IMPLEMENTATIONNAME_MENUBARFACTORY
82cdf0e10cSrcweir 										)
83cdf0e10cSrcweir 
84cdf0e10cSrcweir DEFINE_INIT_SERVICE                     (   MenuBarFactory, {} )
85cdf0e10cSrcweir 
86cdf0e10cSrcweir MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
87cdf0e10cSrcweir     ThreadHelpBase()
88cdf0e10cSrcweir     , m_xServiceManager( xServiceManager )
89cdf0e10cSrcweir     , m_xModuleManager( xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir }
MenuBarFactory(const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & xServiceManager,bool)92cdf0e10cSrcweir MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager,bool ) :
93cdf0e10cSrcweir     ThreadHelpBase(&Application::GetSolarMutex())
94cdf0e10cSrcweir     , m_xServiceManager( xServiceManager )
95cdf0e10cSrcweir     , m_xModuleManager( xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
~MenuBarFactory()99cdf0e10cSrcweir MenuBarFactory::~MenuBarFactory()
100cdf0e10cSrcweir {
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir // XUIElementFactory
createUIElement(const::rtl::OUString & ResourceURL,const Sequence<PropertyValue> & Args)104cdf0e10cSrcweir Reference< XUIElement > SAL_CALL MenuBarFactory::createUIElement(
105cdf0e10cSrcweir     const ::rtl::OUString& ResourceURL,
106cdf0e10cSrcweir     const Sequence< PropertyValue >& Args )
107cdf0e10cSrcweir throw ( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     // SAFE
110cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
111cdf0e10cSrcweir     MenuBarWrapper* pMenuBarWrapper = new MenuBarWrapper( m_xServiceManager );
112cdf0e10cSrcweir     Reference< ::com::sun::star::ui::XUIElement > xMenuBar( (OWeakObject *)pMenuBarWrapper, UNO_QUERY );
113cdf0e10cSrcweir     Reference< ::com::sun::star::frame::XModuleManager > xModuleManager = m_xModuleManager;
114cdf0e10cSrcweir     aLock.unlock();
115cdf0e10cSrcweir     CreateUIElement(ResourceURL,Args,"MenuOnly","private:resource/menubar/",xMenuBar,xModuleManager,m_xServiceManager);
116cdf0e10cSrcweir     return xMenuBar;
117cdf0e10cSrcweir }
CreateUIElement(const::rtl::OUString & ResourceURL,const Sequence<PropertyValue> & Args,const char * _pExtraMode,const char * _pAsciiName,const Reference<::com::sun::star::ui::XUIElement> & _xMenuBar,const::com::sun::star::uno::Reference<::com::sun::star::frame::XModuleManager> & _xModuleManager,const::com::sun::star::uno::Reference<::com::sun::star::lang::XMultiServiceFactory> & _xServiceManager)118cdf0e10cSrcweir void MenuBarFactory::CreateUIElement(const ::rtl::OUString& ResourceURL
119cdf0e10cSrcweir                                      , const Sequence< PropertyValue >& Args
120cdf0e10cSrcweir                                      ,const char* _pExtraMode
121cdf0e10cSrcweir                                      ,const char* _pAsciiName
122cdf0e10cSrcweir                                      ,const Reference< ::com::sun::star::ui::XUIElement >& _xMenuBar
123cdf0e10cSrcweir                                      ,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager >& _xModuleManager
124cdf0e10cSrcweir                                      ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xServiceManager)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     Reference< XUIConfigurationManager > xCfgMgr;
127cdf0e10cSrcweir     Reference< XUIConfigurationManager > xConfigSource;
128cdf0e10cSrcweir     Reference< XFrame >                  xFrame;
129cdf0e10cSrcweir     rtl::OUString                        aResourceURL( ResourceURL );
130cdf0e10cSrcweir     sal_Bool                             bPersistent( sal_True );
131cdf0e10cSrcweir     sal_Bool                             bExtraMode( sal_False );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     for ( sal_Int32 n = 0; n < Args.getLength(); n++ )
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         if ( Args[n].Name.equalsAscii( "ConfigurationSource" ))
136cdf0e10cSrcweir             Args[n].Value >>= xConfigSource;
137cdf0e10cSrcweir         else if ( Args[n].Name.equalsAscii( "Frame" ))
138cdf0e10cSrcweir             Args[n].Value >>= xFrame;
139cdf0e10cSrcweir         else if ( Args[n].Name.equalsAscii( "ResourceURL" ))
140cdf0e10cSrcweir             Args[n].Value >>= aResourceURL;
141cdf0e10cSrcweir         else if ( Args[n].Name.equalsAscii( "Persistent" ))
142cdf0e10cSrcweir             Args[n].Value >>= bPersistent;
143cdf0e10cSrcweir         else if ( _pExtraMode && Args[n].Name.equalsAscii( _pExtraMode ))
144cdf0e10cSrcweir             Args[n].Value >>= bExtraMode;
145cdf0e10cSrcweir     } // for ( sal_Int32 n = 0; n < Args.getLength(); n++ )
146cdf0e10cSrcweir     if ( aResourceURL.indexOf( rtl::OUString::createFromAscii(_pAsciiName)) != 0 )
147cdf0e10cSrcweir         throw IllegalArgumentException();
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     // Identify frame and determine document based ui configuration manager/module ui configuration manager
150cdf0e10cSrcweir     if ( xFrame.is() && !xConfigSource.is() )
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir         bool bHasSettings( false );
153cdf0e10cSrcweir         Reference< XModel > xModel;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         Reference< XController > xController = xFrame->getController();
156cdf0e10cSrcweir         if ( xController.is() )
157cdf0e10cSrcweir             xModel = xController->getModel();
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         if ( xModel.is() )
160cdf0e10cSrcweir         {
161cdf0e10cSrcweir             Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY );
162cdf0e10cSrcweir             if ( xUIConfigurationManagerSupplier.is() )
163cdf0e10cSrcweir             {
164cdf0e10cSrcweir                 xCfgMgr = xUIConfigurationManagerSupplier->getUIConfigurationManager();
165cdf0e10cSrcweir                 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
166cdf0e10cSrcweir             }
167cdf0e10cSrcweir         }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         if ( !bHasSettings )
170cdf0e10cSrcweir         {
171cdf0e10cSrcweir             rtl::OUString aModuleIdentifier = _xModuleManager->identify( Reference< XInterface >( xFrame, UNO_QUERY ));
172cdf0e10cSrcweir             if ( aModuleIdentifier.getLength() )
173cdf0e10cSrcweir             {
174cdf0e10cSrcweir                 Reference< ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier(
175cdf0e10cSrcweir                     _xServiceManager->createInstance( SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ), UNO_QUERY );
176cdf0e10cSrcweir                 xCfgMgr = xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier );
177cdf0e10cSrcweir                 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
178cdf0e10cSrcweir             }
179cdf0e10cSrcweir         }
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     PropertyValue aPropValue;
183cdf0e10cSrcweir     Sequence< Any > aPropSeq( _pExtraMode ? 5 : 4);
184cdf0e10cSrcweir     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
185cdf0e10cSrcweir     aPropValue.Value <<= xFrame;
186cdf0e10cSrcweir     aPropSeq[0] <<= aPropValue;
187cdf0e10cSrcweir     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" ));
188cdf0e10cSrcweir     aPropValue.Value <<= xCfgMgr;
189cdf0e10cSrcweir     aPropSeq[1] <<= aPropValue;
190cdf0e10cSrcweir     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" ));
191cdf0e10cSrcweir     aPropValue.Value <<= aResourceURL;
192cdf0e10cSrcweir     aPropSeq[2] <<= aPropValue;
193cdf0e10cSrcweir     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
194cdf0e10cSrcweir     aPropValue.Value <<= bPersistent;
195cdf0e10cSrcweir     aPropSeq[3] <<= aPropValue;
196cdf0e10cSrcweir     if ( _pExtraMode )
197cdf0e10cSrcweir     {
198cdf0e10cSrcweir         aPropValue.Name = rtl::OUString::createFromAscii(_pExtraMode);
199cdf0e10cSrcweir         aPropValue.Value <<= bExtraMode;
200cdf0e10cSrcweir         aPropSeq[4] <<= aPropValue;
201cdf0e10cSrcweir     }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     vos::OGuard	aGuard( Application::GetSolarMutex() );
204cdf0e10cSrcweir     Reference< XInitialization > xInit( _xMenuBar, UNO_QUERY );
205cdf0e10cSrcweir     xInit->initialize( aPropSeq );
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir } // namespace framework
209