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

Generated by: LCOV version 1.10