LCOV - code coverage report
Current view: top level - libreoffice/framework/source/uifactory - menubarfactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 76 81 93.8 %
Date: 2012-12-17 Functions: 11 14 78.6 %
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         738 : DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   MenuBarFactory                                  ,
      58             :                                             ::cppu::OWeakObject                             ,
      59             :                                             SERVICENAME_MENUBARFACTORY                      ,
      60             :                                             IMPLEMENTATIONNAME_MENUBARFACTORY
      61             :                                         )
      62             : 
      63          44 : DEFINE_INIT_SERVICE                     (   MenuBarFactory, {} )
      64             : 
      65          44 : MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
      66             :     ThreadHelpBase()
      67             :     , m_xServiceManager( xServiceManager )
      68          44 :     , m_xModuleManager( ModuleManager::create( comphelper::getComponentContext(xServiceManager) ) )
      69             : {
      70          44 : }
      71          88 : MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager,bool ) :
      72          88 :     ThreadHelpBase(&Application::GetSolarMutex())
      73             :     , m_xServiceManager( xServiceManager )
      74          88 :     , m_xModuleManager( ModuleManager::create( comphelper::getComponentContext(xServiceManager) ) )
      75             : {
      76          88 : }
      77             : 
      78         176 : MenuBarFactory::~MenuBarFactory()
      79             : {
      80         176 : }
      81             : 
      82             : // XUIElementFactory
      83         508 : Reference< XUIElement > SAL_CALL MenuBarFactory::createUIElement(
      84             :     const ::rtl::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         508 :     ResetableGuard aLock( m_aLock );
      90         508 :     MenuBarWrapper* pMenuBarWrapper = new MenuBarWrapper( m_xServiceManager );
      91         508 :     Reference< ::com::sun::star::ui::XUIElement > xMenuBar( (OWeakObject *)pMenuBarWrapper, UNO_QUERY );
      92         508 :     Reference< ::com::sun::star::frame::XModuleManager2 > xModuleManager = m_xModuleManager;
      93         508 :     aLock.unlock();
      94         508 :     CreateUIElement(ResourceURL,Args,"MenuOnly","private:resource/menubar/",xMenuBar,xModuleManager, comphelper::getComponentContext(m_xServiceManager));
      95         508 :     return xMenuBar;
      96             : }
      97        2078 : void MenuBarFactory::CreateUIElement(const ::rtl::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        2078 :     Reference< XUIConfigurationManager > xCfgMgr;
     106        2078 :     Reference< XUIConfigurationManager > xConfigSource;
     107        2078 :     Reference< XFrame >                  xFrame;
     108        2078 :     rtl::OUString                        aResourceURL( ResourceURL );
     109        2078 :     sal_Bool                             bPersistent( sal_True );
     110        2078 :     sal_Bool                             bExtraMode( sal_False );
     111             : 
     112        6234 :     for ( sal_Int32 n = 0; n < Args.getLength(); n++ )
     113             :     {
     114        4156 :         if ( Args[n].Name == "ConfigurationSource" )
     115           0 :             Args[n].Value >>= xConfigSource;
     116        4156 :         else if ( Args[n].Name == "Frame" )
     117        2078 :             Args[n].Value >>= xFrame;
     118        2078 :         else if ( Args[n].Name == "ResourceURL" )
     119           0 :             Args[n].Value >>= aResourceURL;
     120        2078 :         else if ( Args[n].Name == "Persistent" )
     121        2078 :             Args[n].Value >>= bPersistent;
     122           0 :         else if ( _pExtraMode && Args[n].Name.equalsAscii( _pExtraMode ))
     123           0 :             Args[n].Value >>= bExtraMode;
     124             :     }
     125        2078 :     if ( aResourceURL.indexOf( rtl::OUString::createFromAscii(_pAsciiName)) != 0 )
     126           0 :         throw IllegalArgumentException();
     127             : 
     128             :     // Identify frame and determine document based ui configuration manager/module ui configuration manager
     129        2078 :     if ( xFrame.is() && !xConfigSource.is() )
     130             :     {
     131        2078 :         bool bHasSettings( false );
     132        2078 :         Reference< XModel > xModel;
     133             : 
     134        2078 :         Reference< XController > xController = xFrame->getController();
     135        2078 :         if ( xController.is() )
     136        2078 :             xModel = xController->getModel();
     137             : 
     138        2078 :         if ( xModel.is() )
     139             :         {
     140        2078 :             Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY );
     141        2078 :             if ( xUIConfigurationManagerSupplier.is() )
     142             :             {
     143        2078 :                 xCfgMgr = xUIConfigurationManagerSupplier->getUIConfigurationManager();
     144        2078 :                 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
     145        2078 :             }
     146             :         }
     147             : 
     148        2078 :         if ( !bHasSettings )
     149             :         {
     150        2078 :             rtl::OUString aModuleIdentifier = _xModuleManager->identify( Reference< XInterface >( xFrame, UNO_QUERY ));
     151        2078 :             if ( !aModuleIdentifier.isEmpty() )
     152             :             {
     153             :                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier =
     154        2078 :                     ModuleUIConfigurationManagerSupplier::create( _rxContext );
     155        2078 :                 xCfgMgr = xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier );
     156        2078 :                 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
     157        2078 :             }
     158        2078 :         }
     159             :     }
     160             : 
     161        2078 :     PropertyValue aPropValue;
     162        2078 :     Sequence< Any > aPropSeq( _pExtraMode ? 5 : 4);
     163        2078 :     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
     164        2078 :     aPropValue.Value <<= xFrame;
     165        2078 :     aPropSeq[0] <<= aPropValue;
     166        2078 :     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" ));
     167        2078 :     aPropValue.Value <<= xCfgMgr;
     168        2078 :     aPropSeq[1] <<= aPropValue;
     169        2078 :     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" ));
     170        2078 :     aPropValue.Value <<= aResourceURL;
     171        2078 :     aPropSeq[2] <<= aPropValue;
     172        2078 :     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
     173        2078 :     aPropValue.Value <<= bPersistent;
     174        2078 :     aPropSeq[3] <<= aPropValue;
     175        2078 :     if ( _pExtraMode )
     176             :     {
     177        1570 :         aPropValue.Name = rtl::OUString::createFromAscii(_pExtraMode);
     178        1570 :         aPropValue.Value <<= bExtraMode;
     179        1570 :         aPropSeq[4] <<= aPropValue;
     180             :     }
     181             : 
     182        2078 :     SolarMutexGuard aGuard;
     183        2078 :     Reference< XInitialization > xInit( _xMenuBar, UNO_QUERY );
     184        2078 :     xInit->initialize( aPropSeq );
     185        2078 : }
     186             : 
     187             : } // namespace framework
     188             : 
     189             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10