LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/framework/source/uifactory - menubarfactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 77 82 93.9 %
Date: 2013-07-09 Functions: 13 16 81.2 %
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 <threadhelp/resetableguard.hxx>
      23             : #include "services.h"
      24             : #include <uielement/menubarwrapper.hxx>
      25             : 
      26             : #include <com/sun/star/util/XURLTransformer.hpp>
      27             : #include <com/sun/star/frame/ModuleManager.hpp>
      28             : #include <com/sun/star/frame/XFrame.hpp>
      29             : #include <com/sun/star/frame/XModel.hpp>
      30             : #include <com/sun/star/lang/XInitialization.hpp>
      31             : #include <com/sun/star/ui/ModuleUIConfigurationManagerSupplier.hpp>
      32             : 
      33             : #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
      34             : 
      35             : #include <vcl/menu.hxx>
      36             : #include <vcl/svapp.hxx>
      37             : #include <rtl/ustrbuf.hxx>
      38             : #include <rtl/logfile.hxx>
      39             : 
      40             : //_________________________________________________________________________________________________________________
      41             : //  Defines
      42             : //_________________________________________________________________________________________________________________
      43             : 
      44             : using namespace com::sun::star::uno;
      45             : using namespace com::sun::star::lang;
      46             : using namespace com::sun::star::frame;
      47             : using namespace com::sun::star::beans;
      48             : using namespace com::sun::star::util;
      49             : using namespace ::com::sun::star::ui;
      50             : 
      51             : namespace framework
      52             : {
      53             : 
      54             : //*****************************************************************************************************************
      55             : //  XInterface, XTypeProvider, XServiceInfo
      56             : //*****************************************************************************************************************
      57        1279 : DEFINE_XSERVICEINFO_ONEINSTANCESERVICE_2(   MenuBarFactory                                  ,
      58             :                                             ::cppu::OWeakObject                             ,
      59             :                                             SERVICENAME_MENUBARFACTORY                      ,
      60             :                                             IMPLEMENTATIONNAME_MENUBARFACTORY
      61             :                                         )
      62             : 
      63          57 : DEFINE_INIT_SERVICE                     (   MenuBarFactory, {} )
      64             : 
      65          57 : MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext ) :
      66             :     ThreadHelpBase()
      67             :     , m_xContext( xContext )
      68          57 :     , m_xModuleManager( ModuleManager::create( xContext ) )
      69             : {
      70          57 : }
      71         114 : MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext,bool ) :
      72         114 :     ThreadHelpBase(&Application::GetSolarMutex())
      73             :     , m_xContext( xContext )
      74         114 :     , m_xModuleManager( ModuleManager::create( xContext ) )
      75             : {
      76         114 : }
      77             : 
      78         228 : MenuBarFactory::~MenuBarFactory()
      79             : {
      80         228 : }
      81             : 
      82             : // XUIElementFactory
      83        1073 : Reference< XUIElement > SAL_CALL MenuBarFactory::createUIElement(
      84             :     const OUString& ResourceURL,
      85             :     const Sequence< PropertyValue >& Args )
      86             : throw ( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException )
      87             : {
      88             :     // SAFE
      89        1073 :     ResetableGuard aLock( m_aLock );
      90        1073 :     MenuBarWrapper* pMenuBarWrapper = new MenuBarWrapper( m_xContext );
      91        1073 :     Reference< ::com::sun::star::ui::XUIElement > xMenuBar( (OWeakObject *)pMenuBarWrapper, UNO_QUERY );
      92        2146 :     Reference< ::com::sun::star::frame::XModuleManager2 > xModuleManager = m_xModuleManager;
      93        1073 :     aLock.unlock();
      94        1073 :     CreateUIElement(ResourceURL, Args, "MenuOnly", "private:resource/menubar/", xMenuBar, xModuleManager, m_xContext);
      95        2146 :     return xMenuBar;
      96             : }
      97        4482 : void MenuBarFactory::CreateUIElement(const OUString& ResourceURL
      98             :                                      , const Sequence< PropertyValue >& Args
      99             :                                      ,const char* _pExtraMode
     100             :                                      ,const char* _pAsciiName
     101             :                                      ,const Reference< ::com::sun::star::ui::XUIElement >& _xMenuBar
     102             :                                      ,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager2 >& _xModuleManager
     103             :                                      ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext)
     104             : {
     105        4482 :     Reference< XUIConfigurationManager > xCfgMgr;
     106        8964 :     Reference< XUIConfigurationManager > xConfigSource;
     107        8964 :     Reference< XFrame >                  xFrame;
     108        8964 :     OUString                        aResourceURL( ResourceURL );
     109        4482 :     sal_Bool                             bPersistent( sal_True );
     110        4482 :     sal_Bool                             bExtraMode( sal_False );
     111             : 
     112       13442 :     for ( sal_Int32 n = 0; n < Args.getLength(); n++ )
     113             :     {
     114        8960 :         if ( Args[n].Name == "ConfigurationSource" )
     115           0 :             Args[n].Value >>= xConfigSource;
     116        8960 :         else if ( Args[n].Name == "Frame" )
     117        4480 :             Args[n].Value >>= xFrame;
     118        4480 :         else if ( Args[n].Name == "ResourceURL" )
     119           0 :             Args[n].Value >>= aResourceURL;
     120        4480 :         else if ( Args[n].Name == "Persistent" )
     121        4480 :             Args[n].Value >>= bPersistent;
     122           0 :         else if ( _pExtraMode && Args[n].Name.equalsAscii( _pExtraMode ))
     123           0 :             Args[n].Value >>= bExtraMode;
     124             :     }
     125        4482 :     if ( aResourceURL.indexOf( OUString::createFromAscii(_pAsciiName)) != 0 )
     126           0 :         throw IllegalArgumentException();
     127             : 
     128             :     // Identify frame and determine document based ui configuration manager/module ui configuration manager
     129        4482 :     if ( xFrame.is() && !xConfigSource.is() )
     130             :     {
     131        4480 :         bool bHasSettings( false );
     132        4480 :         Reference< XModel > xModel;
     133             : 
     134        8960 :         Reference< XController > xController = xFrame->getController();
     135        4480 :         if ( xController.is() )
     136        4480 :             xModel = xController->getModel();
     137             : 
     138        4480 :         if ( xModel.is() )
     139             :         {
     140        4478 :             Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY );
     141        4478 :             if ( xUIConfigurationManagerSupplier.is() )
     142             :             {
     143        4410 :                 xCfgMgr = xUIConfigurationManagerSupplier->getUIConfigurationManager();
     144        4410 :                 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
     145        4478 :             }
     146             :         }
     147             : 
     148        4480 :         if ( !bHasSettings )
     149             :         {
     150        4480 :             OUString aModuleIdentifier = _xModuleManager->identify( xFrame );
     151        4480 :             if ( !aModuleIdentifier.isEmpty() )
     152             :             {
     153             :                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier =
     154        4480 :                     ModuleUIConfigurationManagerSupplier::create( _rxContext );
     155        4480 :                 xCfgMgr = xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier );
     156        4480 :                 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
     157        4480 :             }
     158        4480 :         }
     159             :     }
     160             : 
     161        8964 :     PropertyValue aPropValue;
     162        8964 :     Sequence< Any > aPropSeq( _pExtraMode ? 5 : 4);
     163        4482 :     aPropValue.Name = OUString( "Frame" );
     164        4482 :     aPropValue.Value <<= xFrame;
     165        4482 :     aPropSeq[0] <<= aPropValue;
     166        4482 :     aPropValue.Name = OUString( "ConfigurationSource" );
     167        4482 :     aPropValue.Value <<= xCfgMgr;
     168        4482 :     aPropSeq[1] <<= aPropValue;
     169        4482 :     aPropValue.Name = OUString( "ResourceURL" );
     170        4482 :     aPropValue.Value <<= aResourceURL;
     171        4482 :     aPropSeq[2] <<= aPropValue;
     172        4482 :     aPropValue.Name = OUString( "Persistent" );
     173        4482 :     aPropValue.Value <<= bPersistent;
     174        4482 :     aPropSeq[3] <<= aPropValue;
     175        4482 :     if ( _pExtraMode )
     176             :     {
     177        3395 :         aPropValue.Name = OUString::createFromAscii(_pExtraMode);
     178        3395 :         aPropValue.Value <<= bExtraMode;
     179        3395 :         aPropSeq[4] <<= aPropValue;
     180             :     }
     181             : 
     182        8964 :     SolarMutexGuard aGuard;
     183        8964 :     Reference< XInitialization > xInit( _xMenuBar, UNO_QUERY );
     184        8964 :     xInit->initialize( aPropSeq );
     185        4482 : }
     186             : 
     187         402 : } // namespace framework
     188             : 
     189             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10