LCOV - code coverage report
Current view: top level - framework/source/uielement - macrosmenucontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 12 82 14.6 %
Date: 2012-08-25 Functions: 10 18 55.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 11 204 5.4 %

           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                 :            : 
      30                 :            : #include <uielement/macrosmenucontroller.hxx>
      31                 :            : #include <uielement/menubarmanager.hxx>
      32                 :            : #include <threadhelp/resetableguard.hxx>
      33                 :            : #include "services.h"
      34                 :            : #include <classes/resource.hrc>
      35                 :            : #include <classes/fwkresid.hxx>
      36                 :            : #include <framework/imageproducer.hxx>
      37                 :            : #include <com/sun/star/awt/MenuItemStyle.hpp>
      38                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      39                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      40                 :            : #include <com/sun/star/container/XContentEnumerationAccess.hpp>
      41                 :            : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      42                 :            : #include <com/sun/star/frame/XModuleManager.hpp>
      43                 :            : #include <comphelper/processfactory.hxx>
      44                 :            : #include <vcl/svapp.hxx>
      45                 :            : #include <vcl/i18nhelp.hxx>
      46                 :            : #include <rtl/ustrbuf.hxx>
      47                 :            : #include "helper/mischelper.hxx"
      48                 :            : #include "helpid.hrc"
      49                 :            : #include <osl/mutex.hxx>
      50                 :            : 
      51                 :            : using namespace com::sun::star::uno;
      52                 :            : using namespace com::sun::star::lang;
      53                 :            : using namespace com::sun::star::frame;
      54                 :            : using namespace com::sun::star::beans;
      55                 :            : using namespace com::sun::star::util;
      56                 :            : using namespace com::sun::star::style;
      57                 :            : using namespace com::sun::star::container;
      58                 :            : using namespace ::com::sun::star::frame;
      59                 :            : 
      60                 :            : namespace framework
      61                 :            : {
      62                 :            : class
      63 [ +  - ][ +  - ]:         34 : DEFINE_XSERVICEINFO_MULTISERVICE        (   MacrosMenuController                    ,
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
                 [ #  # ]
      64                 :            :                                             OWeakObject                             ,
      65                 :            :                                             SERVICENAME_POPUPMENUCONTROLLER         ,
      66                 :            :                                             IMPLEMENTATIONNAME_MACROSMENUCONTROLLER
      67                 :            :                                         )
      68                 :            : 
      69                 :          4 : DEFINE_INIT_SERVICE                     (   MacrosMenuController, {} )
      70                 :            : 
      71                 :          4 : MacrosMenuController::MacrosMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
      72                 :            :     svt::PopupMenuControllerBase( xServiceManager ),
      73                 :          4 :     m_xServiceManager( xServiceManager)
      74                 :            : {
      75                 :          4 : }
      76                 :            : 
      77                 :          4 : MacrosMenuController::~MacrosMenuController()
      78                 :            : {
      79                 :            :     OSL_TRACE("calling dtor");
      80         [ -  + ]:          8 : }
      81                 :            : 
      82                 :            : // private function
      83                 :          0 : void MacrosMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu )
      84                 :            : {
      85                 :          0 :     VCLXPopupMenu* pVCLPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu );
      86                 :          0 :     PopupMenu*     pPopupMenu    = 0;
      87                 :            : 
      88         [ #  # ]:          0 :     SolarMutexGuard aSolarMutexGuard;
      89                 :            : 
      90         [ #  # ]:          0 :     resetPopupMenu( rPopupMenu );
      91         [ #  # ]:          0 :     if ( pVCLPopupMenu )
      92                 :          0 :         pPopupMenu = (PopupMenu *)pVCLPopupMenu->GetMenu();
      93                 :            : 
      94         [ #  # ]:          0 :     if (!pPopupMenu)
      95                 :          0 :         return;
      96                 :            : 
      97                 :            :     // insert basic
      98                 :          0 :     rtl::OUString aCommand(".uno:MacroDialog");
      99 [ #  # ][ #  # ]:          0 :     String aDisplayName = RetrieveLabelFromCommand( aCommand );
                 [ #  # ]
     100         [ #  # ]:          0 :     pPopupMenu->InsertItem( 2, aDisplayName );
     101 [ #  # ][ #  # ]:          0 :     pPopupMenu->SetItemCommand( 2, aCommand );
                 [ #  # ]
     102                 :            : 
     103                 :            :     // insert providers but not basic or java
     104 [ #  # ][ #  # ]:          0 :     addScriptItems( pPopupMenu, 4);
         [ #  # ][ #  # ]
     105                 :            : }
     106                 :            : 
     107                 :            : // XEventListener
     108                 :          0 : void SAL_CALL MacrosMenuController::disposing( const EventObject& ) throw ( RuntimeException )
     109                 :            : {
     110         [ #  # ]:          0 :     Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
     111                 :            : 
     112         [ #  # ]:          0 :     osl::MutexGuard aLock( m_aMutex );
     113                 :            :     OSL_TRACE("disposing");
     114                 :          0 :     m_xFrame.clear();
     115                 :          0 :     m_xDispatch.clear();
     116                 :          0 :     m_xServiceManager.clear();
     117                 :            : 
     118         [ #  # ]:          0 :     if ( m_xPopupMenu.is() )
     119                 :            :     {
     120 [ #  # ][ #  # ]:          0 :         m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
                 [ #  # ]
     121                 :            :         OSL_TRACE("removed listener");
     122                 :            :     }
     123         [ #  # ]:          0 :     m_xPopupMenu.clear();
     124                 :          0 : }
     125                 :            : 
     126                 :            : // XStatusListener
     127                 :          2 : void SAL_CALL MacrosMenuController::statusChanged( const FeatureStateEvent& ) throw ( RuntimeException )
     128                 :            : {
     129         [ +  - ]:          2 :     osl::MutexGuard aLock( m_aMutex );
     130         [ -  + ]:          2 :     if ( m_xPopupMenu.is() )
     131                 :            :     {
     132         [ #  # ]:          0 :         fillPopupMenu( m_xPopupMenu );
     133         [ +  - ]:          2 :     }
     134                 :          2 : }
     135                 :            : 
     136                 :            : // XMenuListener
     137                 :          0 : void MacrosMenuController::impl_select(const Reference< XDispatch >& /*_xDispatch*/,const ::com::sun::star::util::URL& aTargetURL)
     138                 :            : {
     139                 :            :     // need to requery, since we handle more than one type of Command
     140                 :            :     // if we don't do this only .uno:ScriptOrganizer commands are executed
     141         [ #  # ]:          0 :     Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
     142 [ #  # ][ #  # ]:          0 :     Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
     143         [ #  # ]:          0 :     if( xDispatch.is() )
     144                 :            :     {
     145 [ #  # ][ #  # ]:          0 :         ExecuteInfo* pExecuteInfo = new ExecuteInfo;
     146         [ #  # ]:          0 :         pExecuteInfo->xDispatch     = xDispatch;
     147                 :          0 :         pExecuteInfo->aTargetURL    = aTargetURL;
     148 [ #  # ][ #  # ]:          0 :         Application::PostUserEvent( STATIC_LINK(0, MacrosMenuController , ExecuteHdl_Impl), pExecuteInfo );
     149                 :          0 :     }
     150                 :          0 : }
     151                 :            : 
     152                 :            : 
     153                 :          0 : IMPL_STATIC_LINK_NOINSTANCE( MacrosMenuController, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
     154                 :            : {
     155                 :            :    try
     156                 :            :    {
     157                 :            :        // Asynchronous execution as this can lead to our own destruction!
     158                 :            :        // Framework can recycle our current frame and the layout manager disposes all user interface
     159                 :            :        // elements if a component gets detached from its frame!
     160 [ #  # ][ #  # ]:          0 :        pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
     161                 :            :    }
     162                 :          0 :    catch ( const Exception& )
     163                 :            :    {
     164                 :            :    }
     165         [ #  # ]:          0 :    delete pExecuteInfo;
     166         [ #  # ]:          0 :    return 0;
     167                 :            : }
     168                 :            : 
     169                 :          0 : String MacrosMenuController::RetrieveLabelFromCommand( const String& aCmdURL )
     170                 :            : {
     171                 :          0 :     sal_Bool bModuleIdentified = !m_aModuleIdentifier.isEmpty();
     172 [ #  # ][ #  # ]:          0 :     return framework::RetrieveLabelFromCommand(aCmdURL,m_xServiceManager,m_xUICommandLabels,m_xFrame,m_aModuleIdentifier,bModuleIdentified,"Label");
                 [ #  # ]
     173                 :            : }
     174                 :            : 
     175                 :          0 : void MacrosMenuController::addScriptItems( PopupMenu* pPopupMenu, sal_uInt16 startItemId )
     176                 :            : {
     177                 :          0 :     const rtl::OUString aCmdBase(".uno:ScriptOrganizer?ScriptOrganizer.Language:string=");
     178                 :          0 :     const rtl::OUString ellipsis( "..." );
     179                 :          0 :     const rtl::OUString providerKey("com.sun.star.script.provider.ScriptProviderFor");
     180                 :          0 :     const rtl::OUString languageProviderName("com.sun.star.script.provider.LanguageScriptProvider");
     181                 :          0 :     sal_uInt16 itemId = startItemId;
     182         [ #  # ]:          0 :     Reference< XContentEnumerationAccess > xEnumAccess = Reference< XContentEnumerationAccess >( m_xServiceManager, UNO_QUERY_THROW );
     183 [ #  # ][ #  # ]:          0 :     Reference< XEnumeration > xEnum = xEnumAccess->createContentEnumeration ( languageProviderName );
     184                 :            : 
     185 [ #  # ][ #  # ]:          0 :     while ( xEnum->hasMoreElements() )
                 [ #  # ]
     186                 :            :     {
     187                 :          0 :         Reference< XServiceInfo > xServiceInfo;
     188 [ #  # ][ #  # ]:          0 :         if ( sal_False == ( xEnum->nextElement() >>= xServiceInfo ) )
         [ #  # ][ #  # ]
     189                 :            :         {
     190                 :            :             break;
     191                 :            :         }
     192 [ #  # ][ #  # ]:          0 :         Sequence< ::rtl::OUString > serviceNames = xServiceInfo->getSupportedServiceNames();
     193                 :            : 
     194         [ #  # ]:          0 :         if ( serviceNames.getLength() > 0 )
     195                 :            :         {
     196         [ #  # ]:          0 :             for ( sal_Int32 index = 0; index < serviceNames.getLength(); index++ )
     197                 :            :             {
     198 [ #  # ][ #  # ]:          0 :                 if ( serviceNames[ index ].indexOf( providerKey ) == 0 )
     199                 :            :                 {
     200         [ #  # ]:          0 :                     ::rtl::OUString serviceName = serviceNames[ index ];
     201         [ #  # ]:          0 :                     String aCommand =  aCmdBase;
     202         [ #  # ]:          0 :                     String aDisplayName = String( serviceName.copy( providerKey.getLength() ) );
     203 [ #  # ][ #  # ]:          0 :                     if( aDisplayName.Equals( rtl::OUString("Java") ) || aDisplayName.Equals( rtl::OUString("Basic") ) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
          #  #  #  #  #  
          #  #  #  #  #  
           #  # ][ #  # ]
     204                 :            :                     {
     205                 :            :                         // no entries for Java & Basic added elsewhere
     206                 :            :                         break;
     207                 :            :                     }
     208         [ #  # ]:          0 :                     aCommand.Append( aDisplayName );
     209 [ #  # ][ #  # ]:          0 :                     aDisplayName.Append( ellipsis );
                 [ #  # ]
     210         [ #  # ]:          0 :                     pPopupMenu->InsertItem( itemId, aDisplayName );
     211         [ #  # ]:          0 :                     pPopupMenu->SetItemCommand( itemId, aCommand );
     212                 :          0 :                     itemId++;
     213 [ #  # ][ #  # ]:          0 :                     break;
     214                 :            :                 }
     215                 :            :             }
     216                 :            :         }
     217 [ #  # ][ #  # ]:          0 :     }
     218                 :          0 : }
     219                 :            : 
     220                 :            : }
     221                 :            : 
     222                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10