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-27 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         145 : DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   MenuBarFactory                                  ,
      58             :                                             ::cppu::OWeakObject                             ,
      59             :                                             SERVICENAME_MENUBARFACTORY                      ,
      60             :                                             IMPLEMENTATIONNAME_MENUBARFACTORY
      61             :                                         )
      62             : 
      63           8 : DEFINE_INIT_SERVICE                     (   MenuBarFactory, {} )
      64             : 
      65           8 : MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
      66             :     ThreadHelpBase()
      67             :     , m_xServiceManager( xServiceManager )
      68           8 :     , m_xModuleManager( ModuleManager::create( comphelper::getComponentContext(xServiceManager) ) )
      69             : {
      70           8 : }
      71          16 : MenuBarFactory::MenuBarFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager,bool ) :
      72          16 :     ThreadHelpBase(&Application::GetSolarMutex())
      73             :     , m_xServiceManager( xServiceManager )
      74          16 :     , m_xModuleManager( ModuleManager::create( comphelper::getComponentContext(xServiceManager) ) )
      75             : {
      76          16 : }
      77             : 
      78          32 : MenuBarFactory::~MenuBarFactory()
      79             : {
      80          32 : }
      81             : 
      82             : // XUIElementFactory
      83         236 : 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         236 :     ResetableGuard aLock( m_aLock );
      90         236 :     MenuBarWrapper* pMenuBarWrapper = new MenuBarWrapper( m_xServiceManager );
      91         236 :     Reference< ::com::sun::star::ui::XUIElement > xMenuBar( (OWeakObject *)pMenuBarWrapper, UNO_QUERY );
      92         236 :     Reference< ::com::sun::star::frame::XModuleManager2 > xModuleManager = m_xModuleManager;
      93         236 :     aLock.unlock();
      94         236 :     CreateUIElement(ResourceURL,Args,"MenuOnly","private:resource/menubar/",xMenuBar,xModuleManager, comphelper::getComponentContext(m_xServiceManager));
      95         236 :     return xMenuBar;
      96             : }
      97         967 : 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         967 :     Reference< XUIConfigurationManager > xCfgMgr;
     106         967 :     Reference< XUIConfigurationManager > xConfigSource;
     107         967 :     Reference< XFrame >                  xFrame;
     108         967 :     rtl::OUString                        aResourceURL( ResourceURL );
     109         967 :     sal_Bool                             bPersistent( sal_True );
     110         967 :     sal_Bool                             bExtraMode( sal_False );
     111             : 
     112        2901 :     for ( sal_Int32 n = 0; n < Args.getLength(); n++ )
     113             :     {
     114        1934 :         if ( Args[n].Name == "ConfigurationSource" )
     115           0 :             Args[n].Value >>= xConfigSource;
     116        1934 :         else if ( Args[n].Name == "Frame" )
     117         967 :             Args[n].Value >>= xFrame;
     118         967 :         else if ( Args[n].Name == "ResourceURL" )
     119           0 :             Args[n].Value >>= aResourceURL;
     120         967 :         else if ( Args[n].Name == "Persistent" )
     121         967 :             Args[n].Value >>= bPersistent;
     122           0 :         else if ( _pExtraMode && Args[n].Name.equalsAscii( _pExtraMode ))
     123           0 :             Args[n].Value >>= bExtraMode;
     124             :     }
     125         967 :     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         967 :     if ( xFrame.is() && !xConfigSource.is() )
     130             :     {
     131         967 :         bool bHasSettings( false );
     132         967 :         Reference< XModel > xModel;
     133             : 
     134         967 :         Reference< XController > xController = xFrame->getController();
     135         967 :         if ( xController.is() )
     136         967 :             xModel = xController->getModel();
     137             : 
     138         967 :         if ( xModel.is() )
     139             :         {
     140         967 :             Reference< XUIConfigurationManagerSupplier > xUIConfigurationManagerSupplier( xModel, UNO_QUERY );
     141         967 :             if ( xUIConfigurationManagerSupplier.is() )
     142             :             {
     143         967 :                 xCfgMgr = xUIConfigurationManagerSupplier->getUIConfigurationManager();
     144         967 :                 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
     145         967 :             }
     146             :         }
     147             : 
     148         967 :         if ( !bHasSettings )
     149             :         {
     150         967 :             rtl::OUString aModuleIdentifier = _xModuleManager->identify( Reference< XInterface >( xFrame, UNO_QUERY ));
     151         967 :             if ( !aModuleIdentifier.isEmpty() )
     152             :             {
     153             :                 Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgSupplier =
     154         967 :                     ModuleUIConfigurationManagerSupplier::create( _rxContext );
     155         967 :                 xCfgMgr = xModuleCfgSupplier->getUIConfigurationManager( aModuleIdentifier );
     156         967 :                 bHasSettings = xCfgMgr->hasSettings( aResourceURL );
     157         967 :             }
     158         967 :         }
     159             :     }
     160             : 
     161         967 :     PropertyValue aPropValue;
     162         967 :     Sequence< Any > aPropSeq( _pExtraMode ? 5 : 4);
     163         967 :     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
     164         967 :     aPropValue.Value <<= xFrame;
     165         967 :     aPropSeq[0] <<= aPropValue;
     166         967 :     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" ));
     167         967 :     aPropValue.Value <<= xCfgMgr;
     168         967 :     aPropSeq[1] <<= aPropValue;
     169         967 :     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" ));
     170         967 :     aPropValue.Value <<= aResourceURL;
     171         967 :     aPropSeq[2] <<= aPropValue;
     172         967 :     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
     173         967 :     aPropValue.Value <<= bPersistent;
     174         967 :     aPropSeq[3] <<= aPropValue;
     175         967 :     if ( _pExtraMode )
     176             :     {
     177         731 :         aPropValue.Name = rtl::OUString::createFromAscii(_pExtraMode);
     178         731 :         aPropValue.Value <<= bExtraMode;
     179         731 :         aPropSeq[4] <<= aPropValue;
     180             :     }
     181             : 
     182         967 :     SolarMutexGuard aGuard;
     183         967 :     Reference< XInitialization > xInit( _xMenuBar, UNO_QUERY );
     184         967 :     xInit->initialize( aPropSeq );
     185         967 : }
     186             : 
     187             : } // namespace framework
     188             : 
     189             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10