LCOV - code coverage report
Current view: top level - framework/source/uielement - menubarwrapper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 129 0.0 %
Date: 2014-04-14 Functions: 0 19 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 <uielement/menubarwrapper.hxx>
      21             : #include <framework/actiontriggerhelper.hxx>
      22             : #include <services.h>
      23             : 
      24             : #include <com/sun/star/lang/XServiceInfo.hpp>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
      27             : #include <com/sun/star/awt/XMenuBar.hpp>
      28             : #include <com/sun/star/container/XIndexContainer.hpp>
      29             : #include <com/sun/star/container/XNameAccess.hpp>
      30             : #include <com/sun/star/ui/UIElementType.hpp>
      31             : #include <com/sun/star/frame/ModuleManager.hpp>
      32             : #include <com/sun/star/util/URLTransformer.hpp>
      33             : 
      34             : #include <comphelper/processfactory.hxx>
      35             : #include <vcl/svapp.hxx>
      36             : 
      37             : using namespace com::sun::star;
      38             : using namespace com::sun::star::uno;
      39             : using namespace com::sun::star::beans;
      40             : using namespace com::sun::star::frame;
      41             : using namespace com::sun::star::lang;
      42             : using namespace com::sun::star::container;
      43             : using namespace com::sun::star::awt;
      44             : using namespace com::sun::star::util;
      45             : using namespace ::com::sun::star::ui;
      46             : 
      47             : namespace framework
      48             : {
      49             : 
      50             : //  XInterface, XTypeProvider
      51           0 : DEFINE_XINTERFACE_11    (   MenuBarWrapper                                                    ,
      52             :                             UIConfigElementWrapperBase                                        ,
      53             :                             DIRECT_INTERFACE( ::com::sun::star::lang::XTypeProvider          ),
      54             :                             DIRECT_INTERFACE( ::com::sun::star::ui::XUIElement               ),
      55             :                             DIRECT_INTERFACE( ::com::sun::star::ui::XUIElementSettings       ),
      56             :                             DIRECT_INTERFACE( ::com::sun::star::beans::XMultiPropertySet     ),
      57             :                             DIRECT_INTERFACE( ::com::sun::star::beans::XFastPropertySet      ),
      58             :                             DIRECT_INTERFACE( ::com::sun::star::beans::XPropertySet          ),
      59             :                             DIRECT_INTERFACE( ::com::sun::star::lang::XInitialization        ),
      60             :                             DIRECT_INTERFACE( ::com::sun::star::lang::XComponent             ),
      61             :                             DIRECT_INTERFACE( ::com::sun::star::util::XUpdatable             ),
      62             :                             DIRECT_INTERFACE( ::com::sun::star::ui::XUIConfigurationListener ),
      63             :                             DERIVED_INTERFACE( ::com::sun::star::container::XNameAccess, ::com::sun::star::container::XElementAccess )
      64             :                         )
      65             : 
      66           0 : DEFINE_XTYPEPROVIDER_11 (   MenuBarWrapper                                  ,
      67             :                             ::com::sun::star::lang::XTypeProvider           ,
      68             :                             ::com::sun::star::ui::XUIElement                ,
      69             :                             ::com::sun::star::ui::XUIElementSettings        ,
      70             :                             ::com::sun::star::beans::XMultiPropertySet      ,
      71             :                             ::com::sun::star::beans::XFastPropertySet       ,
      72             :                             ::com::sun::star::beans::XPropertySet           ,
      73             :                             ::com::sun::star::lang::XInitialization         ,
      74             :                             ::com::sun::star::lang::XComponent              ,
      75             :                             ::com::sun::star::util::XUpdatable              ,
      76             :                             ::com::sun::star::ui::XUIConfigurationListener  ,
      77             :                             ::com::sun::star::container::XNameAccess
      78             :                         )
      79             : 
      80           0 : MenuBarWrapper::MenuBarWrapper(
      81             :     const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext
      82             :     )
      83             : :    UIConfigElementWrapperBase( UIElementType::MENUBAR ),
      84             :      m_bRefreshPopupControllerCache( true ),
      85           0 :      m_xContext( rxContext )
      86             : {
      87           0 : }
      88             : 
      89           0 : MenuBarWrapper::~MenuBarWrapper()
      90             : {
      91           0 : }
      92             : 
      93           0 : void SAL_CALL MenuBarWrapper::dispose() throw (::com::sun::star::uno::RuntimeException, std::exception)
      94             : {
      95           0 :     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
      96             : 
      97           0 :     com::sun::star::lang::EventObject aEvent( xThis );
      98           0 :     m_aListenerContainer.disposeAndClear( aEvent );
      99             : 
     100           0 :     SolarMutexGuard g;
     101             : 
     102           0 :     m_xMenuBarManager->dispose();
     103           0 :     m_xMenuBarManager.clear();
     104           0 :     m_xConfigSource.clear();
     105           0 :     m_xConfigData.clear();
     106             : 
     107           0 :     m_xMenuBar.clear();
     108           0 :     m_bDisposed = true;
     109           0 : }
     110             : 
     111             : // XInitialization
     112           0 : void SAL_CALL MenuBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException, std::exception )
     113             : {
     114           0 :     SolarMutexGuard g;
     115             : 
     116           0 :     if ( m_bDisposed )
     117           0 :         throw DisposedException();
     118             : 
     119           0 :     if ( !m_bInitialized )
     120             :     {
     121           0 :         OUString aModuleIdentifier;
     122           0 :         UIConfigElementWrapperBase::initialize( aArguments );
     123             : 
     124           0 :         Reference< XFrame > xFrame( m_xWeakFrame );
     125           0 :         if ( xFrame.is() && m_xConfigSource.is() )
     126             :         {
     127             :             // Create VCL menubar which will be filled with settings data
     128           0 :             MenuBar*        pVCLMenuBar = 0;
     129           0 :             VCLXMenuBar*    pAwtMenuBar = 0;
     130             :             {
     131           0 :                 SolarMutexGuard aSolarMutexGuard;
     132           0 :                 pVCLMenuBar = new MenuBar();
     133             :             }
     134             : 
     135           0 :             Reference< XModuleManager2 > xModuleManager = ModuleManager::create( m_xContext );
     136             : 
     137             :             try
     138             :             {
     139           0 :                 aModuleIdentifier = xModuleManager->identify( xFrame );
     140             :             }
     141           0 :             catch( const Exception& )
     142             :             {
     143             :             }
     144             : 
     145           0 :             Reference< XURLTransformer > xTrans;
     146             :             try
     147             :             {
     148           0 :                 xTrans.set( URLTransformer::create(m_xContext) );
     149           0 :                 m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
     150           0 :                 if ( m_xConfigData.is() )
     151             :                 {
     152             :                     // Fill menubar with container contents
     153           0 :                     sal_uInt16 nId = 1;
     154           0 :                     MenuBarManager::FillMenuWithConfiguration( nId, pVCLMenuBar, aModuleIdentifier, m_xConfigData, xTrans );
     155             :                 }
     156             :             }
     157           0 :             catch ( const NoSuchElementException& )
     158             :             {
     159             :             }
     160             : 
     161           0 :             bool bMenuOnly( false );
     162           0 :             for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
     163             :             {
     164           0 :                 PropertyValue aPropValue;
     165           0 :                 if ( aArguments[n] >>= aPropValue )
     166             :                 {
     167           0 :                     if ( aPropValue.Name == "MenuOnly" )
     168           0 :                         aPropValue.Value >>= bMenuOnly;
     169             :                 }
     170           0 :             }
     171             : 
     172           0 :             if ( !bMenuOnly )
     173             :             {
     174             :                 // Initialize menubar manager with our vcl menu bar. There are some situations where we only want to get the menu without any
     175             :                 // interaction which is done by the menu bar manager. This must be requested by a special property called "MenuOnly". Be careful
     176             :                 // a menu bar created with this property is not fully supported. It must be attached to a real menu bar manager to have full
     177             :                 // support. This feature is currently used for "Inplace editing"!
     178           0 :                 Reference< XDispatchProvider > xDispatchProvider;
     179             : 
     180             :                 MenuBarManager* pMenuBarManager = new MenuBarManager( m_xContext,
     181             :                                                                       xFrame,
     182             :                                                                       xTrans,
     183             :                                                                       xDispatchProvider,
     184             :                                                                       aModuleIdentifier,
     185             :                                                                       pVCLMenuBar,
     186             :                                                                       false,
     187           0 :                                                                       true );
     188             : 
     189           0 :                 m_xMenuBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pMenuBarManager ), UNO_QUERY );
     190             :             }
     191             : 
     192             :             // Initialize toolkit menu bar implementation to have awt::XMenuBar for data exchange.
     193             :             // Don't use this toolkit menu bar or one of its functions. It is only used as a data container!
     194           0 :             pAwtMenuBar = new VCLXMenuBar( pVCLMenuBar );
     195           0 :             m_xMenuBar = Reference< XMenuBar >( static_cast< OWeakObject *>( pAwtMenuBar ), UNO_QUERY );
     196           0 :         }
     197           0 :     }
     198           0 : }
     199             : 
     200             : // XUIElementSettings
     201           0 : void SAL_CALL MenuBarWrapper::updateSettings() throw ( RuntimeException, std::exception )
     202             : {
     203           0 :     SolarMutexGuard g;
     204             : 
     205           0 :     if ( m_bDisposed )
     206           0 :         throw DisposedException();
     207             : 
     208           0 :     if ( m_xMenuBarManager.is() )
     209             :     {
     210           0 :         if ( m_xConfigSource.is() && m_bPersistent )
     211             :         {
     212             :             try
     213             :             {
     214           0 :                 MenuBarManager* pMenuBarManager = static_cast< MenuBarManager *>( m_xMenuBarManager.get() );
     215             : 
     216           0 :                 m_xConfigData = m_xConfigSource->getSettings( m_aResourceURL, sal_False );
     217           0 :                 if ( m_xConfigData.is() )
     218           0 :                     pMenuBarManager->SetItemContainer( m_xConfigData );
     219             :             }
     220           0 :             catch ( const NoSuchElementException& )
     221             :             {
     222             :             }
     223             :         }
     224           0 :         else if ( !m_bPersistent )
     225             :         {
     226             :             // Transient menubar: do nothing
     227             :         }
     228           0 :     }
     229           0 : }
     230           0 : void MenuBarWrapper::impl_fillNewData()
     231             : {
     232             :     // Transient menubar => Fill menubar with new data
     233           0 :     MenuBarManager* pMenuBarManager = static_cast< MenuBarManager *>( m_xMenuBarManager.get() );
     234             : 
     235           0 :     if ( pMenuBarManager )
     236           0 :         pMenuBarManager->SetItemContainer( m_xConfigData );
     237           0 : }
     238             : 
     239           0 : void MenuBarWrapper::fillPopupControllerCache()
     240             : {
     241           0 :     if ( m_bRefreshPopupControllerCache )
     242             :     {
     243           0 :         MenuBarManager* pMenuBarManager = static_cast< MenuBarManager *>( m_xMenuBarManager.get() );
     244           0 :         if ( pMenuBarManager )
     245           0 :             pMenuBarManager->GetPopupController( m_aPopupControllerCache );
     246           0 :         if ( !m_aPopupControllerCache.empty() )
     247           0 :             m_bRefreshPopupControllerCache = false;
     248             :     }
     249           0 : }
     250             : 
     251             : // XElementAccess
     252           0 : Type SAL_CALL MenuBarWrapper::getElementType()
     253             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     254             : {
     255           0 :     return ::getCppuType(( Reference< XDispatchProvider >*)0);
     256             : }
     257             : 
     258           0 : sal_Bool SAL_CALL MenuBarWrapper::hasElements()
     259             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     260             : {
     261           0 :     SolarMutexGuard g;
     262             : 
     263           0 :     if ( m_bDisposed )
     264           0 :         throw DisposedException();
     265             : 
     266           0 :     fillPopupControllerCache();
     267           0 :     return ( !m_aPopupControllerCache.empty() );
     268             : }
     269             : 
     270             : // XNameAccess
     271           0 : Any SAL_CALL MenuBarWrapper::getByName(
     272             :     const OUString& aName )
     273             : throw ( container::NoSuchElementException,
     274             :         lang::WrappedTargetException,
     275             :         uno::RuntimeException, std::exception)
     276             : {
     277           0 :     SolarMutexGuard g;
     278             : 
     279           0 :     if ( m_bDisposed )
     280           0 :         throw DisposedException();
     281             : 
     282           0 :     fillPopupControllerCache();
     283             : 
     284           0 :     PopupControllerCache::const_iterator pIter = m_aPopupControllerCache.find( aName );
     285           0 :     if ( pIter != m_aPopupControllerCache.end() )
     286             :     {
     287           0 :         uno::Reference< frame::XDispatchProvider > xDispatchProvider;
     288           0 :         xDispatchProvider = pIter->second.m_xDispatchProvider;
     289           0 :         return uno::makeAny( xDispatchProvider );
     290             :     }
     291             :     else
     292           0 :         throw container::NoSuchElementException();
     293             : }
     294             : 
     295           0 : Sequence< OUString > SAL_CALL MenuBarWrapper::getElementNames()
     296             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     297             : {
     298           0 :     SolarMutexGuard g;
     299             : 
     300           0 :     if ( m_bDisposed )
     301           0 :         throw DisposedException();
     302             : 
     303           0 :     fillPopupControllerCache();
     304             : 
     305           0 :     Sequence< OUString > aSeq( m_aPopupControllerCache.size() );
     306             : 
     307           0 :     sal_Int32 i( 0 );
     308           0 :     PopupControllerCache::const_iterator pIter = m_aPopupControllerCache.begin();
     309           0 :     while ( pIter != m_aPopupControllerCache.end() )
     310             :     {
     311           0 :         aSeq[i++] = pIter->first;
     312           0 :         ++pIter;
     313             :     }
     314             : 
     315           0 :     return aSeq;
     316             : }
     317             : 
     318           0 : sal_Bool SAL_CALL MenuBarWrapper::hasByName(
     319             :     const OUString& aName )
     320             : throw (::com::sun::star::uno::RuntimeException, std::exception)
     321             : {
     322           0 :     SolarMutexGuard g;
     323             : 
     324           0 :     if ( m_bDisposed )
     325           0 :         throw DisposedException();
     326             : 
     327           0 :     fillPopupControllerCache();
     328             : 
     329           0 :     PopupControllerCache::const_iterator pIter = m_aPopupControllerCache.find( aName );
     330           0 :     if ( pIter != m_aPopupControllerCache.end() )
     331           0 :         return sal_True;
     332             :     else
     333           0 :         return sal_False;
     334             : }
     335             : 
     336             : // XUIElement
     337           0 : Reference< XInterface > SAL_CALL MenuBarWrapper::getRealInterface() throw ( RuntimeException, std::exception )
     338             : {
     339           0 :     if ( m_bDisposed )
     340           0 :         throw DisposedException();
     341             : 
     342           0 :     return Reference< XInterface >( m_xMenuBarManager, UNO_QUERY );
     343             : }
     344             : 
     345             : } // namespace framework
     346             : 
     347             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10