LCOV - code coverage report
Current view: top level - framework/source/uielement - objectmenucontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 23 51 45.1 %
Date: 2012-08-25 Functions: 11 15 73.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 19 84 22.6 %

           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 <uielement/objectmenucontroller.hxx>
      30                 :            : 
      31                 :            : #include <threadhelp/resetableguard.hxx>
      32                 :            : #include "services.h"
      33                 :            : 
      34                 :            : #include <com/sun/star/awt/XDevice.hpp>
      35                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      36                 :            : #include <com/sun/star/awt/MenuItemStyle.hpp>
      37                 :            : #include <com/sun/star/frame/XDispatchProvider.hpp>
      38                 :            : 
      39                 :            : #include <com/sun/star/embed/VerbAttributes.hpp>
      40                 :            : 
      41                 :            : #include <vcl/menu.hxx>
      42                 :            : #include <vcl/svapp.hxx>
      43                 :            : #include <vcl/i18nhelp.hxx>
      44                 :            : #include <rtl/ustrbuf.hxx>
      45                 :            : #include <osl/mutex.hxx>
      46                 :            : 
      47                 :            : //_________________________________________________________________________________________________________________
      48                 :            : //  Defines
      49                 :            : //_________________________________________________________________________________________________________________
      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                 :            : 
      57                 :            : namespace framework
      58                 :            : {
      59                 :            : 
      60 [ +  - ][ +  - ]:       2339 : DEFINE_XSERVICEINFO_MULTISERVICE        (   ObjectMenuController                    ,
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
                 [ #  # ]
      61                 :            :                                             OWeakObject                             ,
      62                 :            :                                             SERVICENAME_POPUPMENUCONTROLLER         ,
      63                 :            :                                             IMPLEMENTATIONNAME_OBJECTMENUCONTROLLER
      64                 :            :                                         )
      65                 :            : 
      66                 :          8 : DEFINE_INIT_SERVICE                     (   ObjectMenuController, {} )
      67                 :            : 
      68                 :          8 : ObjectMenuController::ObjectMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
      69                 :          8 :     svt::PopupMenuControllerBase( xServiceManager )
      70                 :            : {
      71                 :          8 : }
      72                 :            : 
      73                 :          8 : ObjectMenuController::~ObjectMenuController()
      74                 :            : {
      75         [ -  + ]:         16 : }
      76                 :            : 
      77                 :            : // private function
      78                 :          0 : void ObjectMenuController::fillPopupMenu( const Sequence< com::sun::star::embed::VerbDescriptor >& rVerbCommandSeq, Reference< css::awt::XPopupMenu >& rPopupMenu )
      79                 :            : {
      80                 :          0 :     const com::sun::star::embed::VerbDescriptor* pVerbCommandArray = rVerbCommandSeq.getConstArray();
      81                 :          0 :     VCLXPopupMenu*                                     pPopupMenu        = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu );
      82                 :          0 :     PopupMenu*                                         pVCLPopupMenu     = 0;
      83                 :            : 
      84         [ #  # ]:          0 :     SolarMutexGuard aSolarMutexGuard;
      85                 :            : 
      86         [ #  # ]:          0 :     resetPopupMenu( rPopupMenu );
      87         [ #  # ]:          0 :     if ( pPopupMenu )
      88                 :          0 :         pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
      89                 :            : 
      90         [ #  # ]:          0 :     if ( pVCLPopupMenu )
      91                 :            :     {
      92                 :          0 :         const rtl::OUString aVerbCommand( ".uno:ObjectMenue?VerbID:short=" );
      93         [ #  # ]:          0 :         for ( sal_uInt16 i = 0; i < rVerbCommandSeq.getLength(); i++ )
      94                 :            :         {
      95                 :          0 :             const com::sun::star::embed::VerbDescriptor& rVerb = pVerbCommandArray[i];
      96         [ #  # ]:          0 :             if ( rVerb.VerbAttributes & com::sun::star::embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU )
      97                 :            :             {
      98 [ #  # ][ #  # ]:          0 :                 m_xPopupMenu->insertItem( i+1, rVerb.VerbName, 0, i );
      99                 :            :                 // use VCL popup menu pointer to set vital information that are not part of the awt implementation
     100                 :            : 
     101                 :          0 :                 rtl::OUString aCommand( aVerbCommand );
     102                 :          0 :                 aCommand += rtl::OUString::valueOf( rVerb.VerbID );
     103 [ #  # ][ #  # ]:          0 :                 pVCLPopupMenu->SetItemCommand( i+1, aCommand ); // Store verb command
                 [ #  # ]
     104                 :            :             }
     105                 :          0 :         }
     106         [ #  # ]:          0 :     }
     107                 :          0 : }
     108                 :            : 
     109                 :            : // XEventListener
     110                 :          4 : void SAL_CALL ObjectMenuController::disposing( const EventObject& ) throw ( RuntimeException )
     111                 :            : {
     112         [ +  - ]:          4 :     Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
     113                 :            : 
     114         [ +  - ]:          4 :     osl::MutexGuard aLock( m_aMutex );
     115                 :          4 :     m_xFrame.clear();
     116                 :          4 :     m_xDispatch.clear();
     117                 :          4 :     m_xObjectUpdateDispatch.clear();
     118                 :          4 :     m_xServiceManager.clear();
     119                 :            : 
     120         [ +  - ]:          4 :     if ( m_xPopupMenu.is() )
     121 [ +  - ][ +  - ]:          4 :         m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
                 [ +  - ]
     122         [ +  - ]:          4 :     m_xPopupMenu.clear();
     123                 :          4 : }
     124                 :            : 
     125                 :            : // XStatusListener
     126                 :         12 : void SAL_CALL ObjectMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException )
     127                 :            : {
     128         [ +  - ]:         12 :     Sequence < com::sun::star::embed::VerbDescriptor > aVerbCommandSeq;
     129 [ +  - ][ -  + ]:         12 :     if ( Event.State >>= aVerbCommandSeq )
     130                 :            :     {
     131         [ #  # ]:          0 :         osl::MutexGuard aLock( m_aMutex );
     132         [ #  # ]:          0 :         if ( m_xPopupMenu.is() )
     133 [ #  # ][ #  # ]:          0 :             fillPopupMenu( aVerbCommandSeq, m_xPopupMenu );
     134         [ +  - ]:         12 :     }
     135                 :         12 : }
     136                 :            : 
     137                 :            : // XMenuListener
     138                 :          0 : void ObjectMenuController::impl_select(const Reference< XDispatch >& _xDispatch,const ::com::sun::star::util::URL& aTargetURL)
     139                 :            : {
     140         [ #  # ]:          0 :     Sequence<PropertyValue>      aArgs;
     141                 :            :     OSL_ENSURE(_xDispatch.is(),"ObjectMenuController::impl_select: No dispatch");
     142         [ #  # ]:          0 :     if ( _xDispatch.is() )
     143 [ #  # ][ #  # ]:          0 :         _xDispatch->dispatch( aTargetURL, aArgs );
                 [ #  # ]
     144                 :          0 : }
     145                 :            : 
     146                 :            : }
     147                 :            : 
     148                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10