LCOV - code coverage report
Current view: top level - framework/source/uifactory - menubarfactory.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 70 75 93.3 %
Date: 2014-11-03 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <uifactory/menubarfactory.hxx>
      21             : 
      22             : #include <uielement/menubarwrapper.hxx>
      23             : 
      24             : #include <com/sun/star/frame/ModuleManager.hpp>
      25             : #include <com/sun/star/frame/XFrame.hpp>
      26             : #include <com/sun/star/frame/XModel.hpp>
      27             : #include <com/sun/star/lang/XInitialization.hpp>
      28             : #include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
      29             : #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
      30             : #include <com/sun/star/uno/XComponentContext.hpp>
      31             : 
      32             : #include <vcl/menu.hxx>
      33             : #include <vcl/svapp.hxx>
      34             : #include <rtl/ustrbuf.hxx>
      35             : 
      36             : using namespace com::sun::star::uno;
      37             : using namespace com::sun::star::lang;
      38             : using namespace com::sun::star::frame;
      39             : using namespace com::sun::star::beans;
      40             : using namespace com::sun::star::util;
      41             : using namespace ::com::sun::star::ui;
      42             : 
      43             : namespace framework
      44             : {
      45             : 
      46       22556 : MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext )
      47       22556 :     : m_xContext( xContext )
      48             : {
      49       22556 : }
      50             : 
      51       28036 : MenuBarFactory::~MenuBarFactory()
      52             : {
      53       28036 : }
      54             : 
      55             : // XUIElementFactory
      56        5478 : Reference< XUIElement > SAL_CALL MenuBarFactory::createUIElement(
      57             :     const OUString& ResourceURL,
      58             :     const Sequence< PropertyValue >& Args )
      59             : throw ( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception )
      60             : {
      61             :     Reference< ::com::sun::star::ui::XUIElement > xMenuBar(
      62        5478 :             static_cast<OWeakObject *>(new MenuBarWrapper(m_xContext)), UNO_QUERY);
      63        5478 :     CreateUIElement(ResourceURL, Args, "MenuOnly", "private:resource/menubar/", xMenuBar, m_xContext);
      64        5478 :     return xMenuBar;
      65             : }
      66             : 
      67       22554 : void MenuBarFactory::CreateUIElement(const OUString& ResourceURL
      68             :                                      ,const Sequence< PropertyValue >& Args
      69             :                                      ,const char* _pExtraMode
      70             :                                      ,const OUString& ResourceType
      71             :                                      ,const Reference< ::com::sun::star::ui::XUIElement >& _xMenuBar
      72             :                                      ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext)
      73             : {
      74       22554 :     Reference< XUIConfigurationManager > xCfgMgr;
      75       45108 :     Reference< XUIConfigurationManager > xConfigSource;
      76       45108 :     Reference< XFrame >                  xFrame;
      77       45108 :     OUString                        aResourceURL( ResourceURL );
      78       22554 :     bool                             bPersistent( true );
      79       22554 :     bool                             bExtraMode( false );
      80             : 
      81       67654 :     for ( sal_Int32 n = 0; n < Args.getLength(); n++ )
      82             :     {
      83       45100 :         if ( Args[n].Name == "ConfigurationSource" )
      84           0 :             Args[n].Value >>= xConfigSource;
      85       45100 :         else if ( Args[n].Name == "Frame" )
      86       22550 :             Args[n].Value >>= xFrame;
      87       22550 :         else if ( Args[n].Name == "ResourceURL" )
      88           0 :             Args[n].Value >>= aResourceURL;
      89       22550 :         else if ( Args[n].Name == "Persistent" )
      90       22550 :             Args[n].Value >>= bPersistent;
      91           0 :         else if ( _pExtraMode && Args[n].Name.equalsAscii( _pExtraMode ))
      92           0 :             Args[n].Value >>= bExtraMode;
      93             :     }
      94       22554 :     if (!aResourceURL.startsWith(ResourceType))
      95           0 :         throw IllegalArgumentException();
      96             : 
      97             :     // Identify frame and determine document based ui configuration manager/module ui configuration manager
      98       22554 :     if ( xFrame.is() && !xConfigSource.is() )
      99             :     {
     100       22550 :         bool bHasSettings( false );
     101       22550 :         Reference< XModel > xModel;
     102             : 
     103       45100 :         Reference< XController > xController = xFrame->getController();
     104       22550 :         if ( xController.is() )
     105       22550 :             xModel = xController->getModel();
     106             : 
     107       22550 :         if ( xModel.is() )
     108             :         {
     109       22546 :             Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY );
     110       22546 :             if ( xUIConfigurationManagerSupplier.is() )
     111             :             {
     112       22410 :                 xCfgMgr = xUIConfigurationManagerSupplier->getUIConfigurationManager();
     113       22410 :                 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
     114       22546 :             }
     115             :         }
     116             : 
     117       22550 :         if ( !bHasSettings )
     118             :         {
     119             :             Reference< ::com::sun::star::frame::XModuleManager2 > xModuleManager =
     120       22550 :                 ModuleManager::create( _rxContext );
     121       45100 :             OUString aModuleIdentifier = xModuleManager->identify( Reference<XInterface>( xFrame, UNO_QUERY ) );
     122       22550 :             if ( !aModuleIdentifier.isEmpty() )
     123             :             {
     124             :                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier =
     125       22550 :                     theModuleUIConfigurationManagerSupplier::get( _rxContext );
     126       22550 :                 xCfgMgr = xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier );
     127       22550 :                 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
     128       22550 :             }
     129       22550 :         }
     130             :     }
     131             : 
     132       45092 :     PropertyValue aPropValue;
     133       45092 :     Sequence< Any > aPropSeq( _pExtraMode ? 5 : 4);
     134       22546 :     aPropValue.Name = "Frame";
     135       22546 :     aPropValue.Value <<= xFrame;
     136       22546 :     aPropSeq[0] <<= aPropValue;
     137       22546 :     aPropValue.Name = "ConfigurationSource";
     138       22546 :     aPropValue.Value <<= xCfgMgr;
     139       22546 :     aPropSeq[1] <<= aPropValue;
     140       22546 :     aPropValue.Name = "ResourceURL";
     141       22546 :     aPropValue.Value <<= aResourceURL;
     142       22546 :     aPropSeq[2] <<= aPropValue;
     143       22546 :     aPropValue.Name = "Persistent";
     144       22546 :     aPropValue.Value <<= bPersistent;
     145       22546 :     aPropSeq[3] <<= aPropValue;
     146       22546 :     if ( _pExtraMode )
     147             :     {
     148       17040 :         aPropValue.Name = OUString::createFromAscii(_pExtraMode);
     149       17040 :         aPropValue.Value <<= bExtraMode;
     150       17040 :         aPropSeq[4] <<= aPropValue;
     151             :     }
     152             : 
     153       45092 :     SolarMutexGuard aGuard;
     154       45092 :     Reference< XInitialization > xInit( _xMenuBar, UNO_QUERY );
     155       45100 :     xInit->initialize( aPropSeq );
     156       22546 : }
     157             : 
     158             : } // namespace framework
     159             : 
     160             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     161        5480 : com_sun_star_comp_framework_MenuBarFactory_get_implementation(
     162             :     css::uno::XComponentContext *context,
     163             :     css::uno::Sequence<css::uno::Any> const &)
     164             : {
     165        5480 :     return cppu::acquire(new framework::MenuBarFactory(context));
     166         951 : }
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10