LCOV - code coverage report
Current view: top level - framework/source/uifactory - menubarfactory.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 69 74 93.2 %
Date: 2015-06-13 12:38:46 Functions: 6 6 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       13182 : MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext )
      47       13182 :     : m_xContext( xContext )
      48             : {
      49       13182 : }
      50             : 
      51       16383 : MenuBarFactory::~MenuBarFactory()
      52             : {
      53       16383 : }
      54             : 
      55             : // XUIElementFactory
      56        3199 : 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        3199 :             static_cast<OWeakObject *>(new MenuBarWrapper(m_xContext)), UNO_QUERY);
      63        3199 :     CreateUIElement(ResourceURL, Args, "MenuOnly", "private:resource/menubar/", xMenuBar, m_xContext);
      64        3199 :     return xMenuBar;
      65             : }
      66             : 
      67       13180 : 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       13180 :     Reference< XUIConfigurationManager > xCfgMgr;
      75       26360 :     Reference< XUIConfigurationManager > xConfigSource;
      76       26360 :     Reference< XFrame >                  xFrame;
      77       26360 :     OUString                        aResourceURL( ResourceURL );
      78       13180 :     bool                             bPersistent( true );
      79       13180 :     bool                             bExtraMode( false );
      80             : 
      81       39536 :     for ( sal_Int32 n = 0; n < Args.getLength(); n++ )
      82             :     {
      83       26356 :         if ( Args[n].Name == "ConfigurationSource" )
      84           0 :             Args[n].Value >>= xConfigSource;
      85       26356 :         else if ( Args[n].Name == "Frame" )
      86       13178 :             Args[n].Value >>= xFrame;
      87       13178 :         else if ( Args[n].Name == "ResourceURL" )
      88           0 :             Args[n].Value >>= aResourceURL;
      89       13178 :         else if ( Args[n].Name == "Persistent" )
      90       13178 :             Args[n].Value >>= bPersistent;
      91           0 :         else if ( _pExtraMode && Args[n].Name.equalsAscii( _pExtraMode ))
      92           0 :             Args[n].Value >>= bExtraMode;
      93             :     }
      94       13180 :     if (!aResourceURL.startsWith(ResourceType))
      95           0 :         throw IllegalArgumentException();
      96             : 
      97             :     // Identify frame and determine document based ui configuration manager/module ui configuration manager
      98       13180 :     if ( xFrame.is() && !xConfigSource.is() )
      99             :     {
     100       13178 :         bool bHasSettings( false );
     101       13178 :         Reference< XModel > xModel;
     102             : 
     103       26356 :         Reference< XController > xController = xFrame->getController();
     104       13178 :         if ( xController.is() )
     105       13178 :             xModel = xController->getModel();
     106             : 
     107       13178 :         if ( xModel.is() )
     108             :         {
     109       13176 :             Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY );
     110       13176 :             if ( xUIConfigurationManagerSupplier.is() )
     111             :             {
     112       13108 :                 xCfgMgr = xUIConfigurationManagerSupplier->getUIConfigurationManager();
     113       13108 :                 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
     114       13176 :             }
     115             :         }
     116             : 
     117       13178 :         if ( !bHasSettings )
     118             :         {
     119             :             Reference< ::com::sun::star::frame::XModuleManager2 > xModuleManager =
     120       13178 :                 ModuleManager::create( _rxContext );
     121       26356 :             OUString aModuleIdentifier = xModuleManager->identify( Reference<XInterface>( xFrame, UNO_QUERY ) );
     122       13178 :             if ( !aModuleIdentifier.isEmpty() )
     123             :             {
     124             :                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier =
     125       13178 :                     theModuleUIConfigurationManagerSupplier::get( _rxContext );
     126       13178 :                 xCfgMgr = xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier );
     127       13178 :                 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
     128       13178 :             }
     129       13178 :         }
     130             :     }
     131             : 
     132       26352 :     PropertyValue aPropValue;
     133       26352 :     Sequence< Any > aPropSeq( _pExtraMode ? 5 : 4);
     134       13176 :     aPropValue.Name = "Frame";
     135       13176 :     aPropValue.Value <<= xFrame;
     136       13176 :     aPropSeq[0] <<= aPropValue;
     137       13176 :     aPropValue.Name = "ConfigurationSource";
     138       13176 :     aPropValue.Value <<= xCfgMgr;
     139       13176 :     aPropSeq[1] <<= aPropValue;
     140       13176 :     aPropValue.Name = "ResourceURL";
     141       13176 :     aPropValue.Value <<= aResourceURL;
     142       13176 :     aPropSeq[2] <<= aPropValue;
     143       13176 :     aPropValue.Name = "Persistent";
     144       13176 :     aPropValue.Value <<= bPersistent;
     145       13176 :     aPropSeq[3] <<= aPropValue;
     146       13176 :     if ( _pExtraMode )
     147             :     {
     148        9963 :         aPropValue.Name = OUString::createFromAscii(_pExtraMode);
     149        9963 :         aPropValue.Value <<= bExtraMode;
     150        9963 :         aPropSeq[4] <<= aPropValue;
     151             :     }
     152             : 
     153       26352 :     SolarMutexGuard aGuard;
     154       26352 :     Reference< XInitialization > xInit( _xMenuBar, UNO_QUERY );
     155       26356 :     xInit->initialize( aPropSeq );
     156       13176 : }
     157             : 
     158             : } // namespace framework
     159             : 
     160             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     161        3201 : com_sun_star_comp_framework_MenuBarFactory_get_implementation(
     162             :     css::uno::XComponentContext *context,
     163             :     css::uno::Sequence<css::uno::Any> const &)
     164             : {
     165        3201 :     return cppu::acquire(new framework::MenuBarFactory(context));
     166             : }
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11