LCOV - code coverage report
Current view: top level - framework/source/uifactory - menubarfactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 76 81 93.8 %
Date: 2012-08-25 Functions: 11 14 78.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 100 198 50.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <uifactory/menubarfactory.hxx>
      30                 :            : 
      31                 :            : #include <threadhelp/resetableguard.hxx>
      32                 :            : #include "services.h"
      33                 :            : #include <uielement/menubarwrapper.hxx>
      34                 :            : 
      35                 :            : #include <com/sun/star/util/XURLTransformer.hpp>
      36                 :            : #include <com/sun/star/frame/XFrame.hpp>
      37                 :            : #include <com/sun/star/frame/XModel.hpp>
      38                 :            : #include <com/sun/star/lang/XInitialization.hpp>
      39                 :            : #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
      40                 :            : 
      41                 :            : #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
      42                 :            : 
      43                 :            : #include <vcl/menu.hxx>
      44                 :            : #include <vcl/svapp.hxx>
      45                 :            : #include <rtl/ustrbuf.hxx>
      46                 :            : #include <rtl/logfile.hxx>
      47                 :            : 
      48                 :            : //_________________________________________________________________________________________________________________
      49                 :            : //  Defines
      50                 :            : //_________________________________________________________________________________________________________________
      51                 :            : 
      52                 :            : using namespace com::sun::star::uno;
      53                 :            : using namespace com::sun::star::lang;
      54                 :            : using namespace com::sun::star::frame;
      55                 :            : using namespace com::sun::star::beans;
      56                 :            : using namespace com::sun::star::util;
      57                 :            : using namespace ::com::sun::star::ui;
      58                 :            : 
      59                 :            : namespace framework
      60                 :            : {
      61                 :            : 
      62                 :            : //*****************************************************************************************************************
      63                 :            : //  XInterface, XTypeProvider, XServiceInfo
      64                 :            : //*****************************************************************************************************************
      65 [ +  - ][ +  - ]:       2120 : DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   MenuBarFactory                                  ,
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
                 [ #  # ]
      66                 :            :                                             ::cppu::OWeakObject                             ,
      67                 :            :                                             SERVICENAME_MENUBARFACTORY                      ,
      68                 :            :                                             IMPLEMENTATIONNAME_MENUBARFACTORY
      69                 :            :                                         )
      70                 :            : 
      71                 :        111 : DEFINE_INIT_SERVICE                     (   MenuBarFactory, {} )
      72                 :            : 
      73                 :        111 : MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
      74                 :            :     ThreadHelpBase()
      75                 :            :     , m_xServiceManager( xServiceManager )
      76 [ +  - ][ +  - ]:        111 :     , m_xModuleManager( xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY )
         [ +  - ][ +  - ]
                 [ +  - ]
      77                 :            : {
      78                 :        111 : }
      79                 :        222 : MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager,bool ) :
      80                 :        222 :     ThreadHelpBase(&Application::GetSolarMutex())
      81                 :            :     , m_xServiceManager( xServiceManager )
      82 [ +  - ][ +  - ]:        222 :     , m_xModuleManager( xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY )
         [ +  - ][ +  - ]
                 [ +  - ]
      83                 :            : {
      84                 :        222 : }
      85                 :            : 
      86         [ +  - ]:        333 : MenuBarFactory::~MenuBarFactory()
      87                 :            : {
      88         [ -  + ]:        444 : }
      89                 :            : 
      90                 :            : // XUIElementFactory
      91                 :       1713 : Reference< XUIElement > SAL_CALL MenuBarFactory::createUIElement(
      92                 :            :     const ::rtl::OUString& ResourceURL,
      93                 :            :     const Sequence< PropertyValue >& Args )
      94                 :            : throw ( ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException )
      95                 :            : {
      96                 :            :     // SAFE
      97         [ +  - ]:       1713 :     ResetableGuard aLock( m_aLock );
      98         [ +  - ]:       1713 :     MenuBarWrapper* pMenuBarWrapper = new MenuBarWrapper( m_xServiceManager );
      99 [ +  - ][ +  - ]:       1713 :     Reference< ::com::sun::star::ui::XUIElement > xMenuBar( (OWeakObject *)pMenuBarWrapper, UNO_QUERY );
     100                 :       1713 :     Reference< ::com::sun::star::frame::XModuleManager > xModuleManager = m_xModuleManager;
     101         [ +  - ]:       1713 :     aLock.unlock();
     102         [ +  - ]:       1713 :     CreateUIElement(ResourceURL,Args,"MenuOnly","private:resource/menubar/",xMenuBar,xModuleManager,m_xServiceManager);
     103         [ +  - ]:       1713 :     return xMenuBar;
     104                 :            : }
     105                 :       7163 : void MenuBarFactory::CreateUIElement(const ::rtl::OUString& ResourceURL
     106                 :            :                                      , const Sequence< PropertyValue >& Args
     107                 :            :                                      ,const char* _pExtraMode
     108                 :            :                                      ,const char* _pAsciiName
     109                 :            :                                      ,const Reference< ::com::sun::star::ui::XUIElement >& _xMenuBar
     110                 :            :                                      ,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager >& _xModuleManager
     111                 :            :                                      ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xServiceManager)
     112                 :            : {
     113                 :       7163 :     Reference< XUIConfigurationManager > xCfgMgr;
     114                 :       7163 :     Reference< XUIConfigurationManager > xConfigSource;
     115                 :       7163 :     Reference< XFrame >                  xFrame;
     116                 :       7163 :     rtl::OUString                        aResourceURL( ResourceURL );
     117                 :       7163 :     sal_Bool                             bPersistent( sal_True );
     118                 :       7163 :     sal_Bool                             bExtraMode( sal_False );
     119                 :            : 
     120         [ +  + ]:      21481 :     for ( sal_Int32 n = 0; n < Args.getLength(); n++ )
     121                 :            :     {
     122         [ -  + ]:      14318 :         if ( Args[n].Name == "ConfigurationSource" )
     123         [ #  # ]:          0 :             Args[n].Value >>= xConfigSource;
     124         [ +  + ]:      14318 :         else if ( Args[n].Name == "Frame" )
     125         [ +  - ]:       7159 :             Args[n].Value >>= xFrame;
     126         [ -  + ]:       7159 :         else if ( Args[n].Name == "ResourceURL" )
     127                 :          0 :             Args[n].Value >>= aResourceURL;
     128         [ +  - ]:       7159 :         else if ( Args[n].Name == "Persistent" )
     129                 :       7159 :             Args[n].Value >>= bPersistent;
     130 [ #  # ][ #  # ]:          0 :         else if ( _pExtraMode && Args[n].Name.equalsAscii( _pExtraMode ))
                 [ #  # ]
     131                 :          0 :             Args[n].Value >>= bExtraMode;
     132                 :            :     }
     133         [ -  + ]:       7163 :     if ( aResourceURL.indexOf( rtl::OUString::createFromAscii(_pAsciiName)) != 0 )
     134         [ #  # ]:          0 :         throw IllegalArgumentException();
     135                 :            : 
     136                 :            :     // Identify frame and determine document based ui configuration manager/module ui configuration manager
     137 [ +  + ][ +  - ]:       7163 :     if ( xFrame.is() && !xConfigSource.is() )
                 [ +  + ]
     138                 :            :     {
     139                 :       7159 :         bool bHasSettings( false );
     140                 :       7159 :         Reference< XModel > xModel;
     141                 :            : 
     142 [ +  - ][ +  - ]:       7159 :         Reference< XController > xController = xFrame->getController();
     143         [ +  - ]:       7159 :         if ( xController.is() )
     144 [ +  - ][ +  - ]:       7159 :             xModel = xController->getModel();
                 [ +  - ]
     145                 :            : 
     146         [ +  + ]:       7159 :         if ( xModel.is() )
     147                 :            :         {
     148         [ +  - ]:       7155 :             Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY );
     149         [ +  + ]:       7155 :             if ( xUIConfigurationManagerSupplier.is() )
     150                 :            :             {
     151 [ +  - ][ +  - ]:       7019 :                 xCfgMgr = xUIConfigurationManagerSupplier->getUIConfigurationManager();
                 [ +  - ]
     152 [ +  - ][ +  - ]:       7019 :                 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
     153                 :       7155 :             }
     154                 :            :         }
     155                 :            : 
     156         [ +  - ]:       7159 :         if ( !bHasSettings )
     157                 :            :         {
     158 [ +  - ][ +  - ]:       7159 :             rtl::OUString aModuleIdentifier = _xModuleManager->identify( Reference< XInterface >( xFrame, UNO_QUERY ));
                 [ +  - ]
     159         [ +  - ]:       7159 :             if ( !aModuleIdentifier.isEmpty() )
     160                 :            :             {
     161                 :            :                 Reference< ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier(
     162 [ +  - ][ +  - ]:       7159 :                     _xServiceManager->createInstance( SERVICENAME_MODULEUICONFIGURATIONMANAGERSUPPLIER ), UNO_QUERY );
         [ +  - ][ +  - ]
     163 [ +  - ][ +  - ]:       7159 :                 xCfgMgr = xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier );
                 [ +  - ]
     164 [ +  - ][ +  - ]:       7159 :                 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
     165                 :       7159 :             }
     166                 :       7159 :         }
     167                 :            :     }
     168                 :            : 
     169                 :       7163 :     PropertyValue aPropValue;
     170 [ +  - ][ +  + ]:       7163 :     Sequence< Any > aPropSeq( _pExtraMode ? 5 : 4);
     171         [ +  - ]:       7163 :     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
     172         [ +  - ]:       7163 :     aPropValue.Value <<= xFrame;
     173 [ +  - ][ +  - ]:       7163 :     aPropSeq[0] <<= aPropValue;
     174         [ +  - ]:       7163 :     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" ));
     175         [ +  - ]:       7163 :     aPropValue.Value <<= xCfgMgr;
     176 [ +  - ][ +  - ]:       7163 :     aPropSeq[1] <<= aPropValue;
     177         [ +  - ]:       7163 :     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" ));
     178         [ +  - ]:       7163 :     aPropValue.Value <<= aResourceURL;
     179 [ +  - ][ +  - ]:       7163 :     aPropSeq[2] <<= aPropValue;
     180         [ +  - ]:       7163 :     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
     181         [ +  - ]:       7163 :     aPropValue.Value <<= bPersistent;
     182 [ +  - ][ +  - ]:       7163 :     aPropSeq[3] <<= aPropValue;
     183         [ +  + ]:       7163 :     if ( _pExtraMode )
     184                 :            :     {
     185                 :       5422 :         aPropValue.Name = rtl::OUString::createFromAscii(_pExtraMode);
     186         [ +  - ]:       5422 :         aPropValue.Value <<= bExtraMode;
     187 [ +  - ][ +  - ]:       5422 :         aPropSeq[4] <<= aPropValue;
     188                 :            :     }
     189                 :            : 
     190         [ +  - ]:       7163 :     SolarMutexGuard aGuard;
     191         [ +  - ]:       7163 :     Reference< XInitialization > xInit( _xMenuBar, UNO_QUERY );
     192 [ +  - ][ +  - ]:       7163 :     xInit->initialize( aPropSeq );
         [ +  - ][ +  - ]
     193                 :       7163 : }
     194                 :            : 
     195                 :            : } // namespace framework
     196                 :            : 
     197                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10