LCOV - code coverage report
Current view: top level - framework/source/uielement - objectmenucontroller.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 25 59 42.4 %
Date: 2014-11-03 Functions: 9 13 69.2 %
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 <stdtypes.h>
      21             : 
      22             : #include <com/sun/star/awt/XDevice.hpp>
      23             : #include <com/sun/star/beans/PropertyValue.hpp>
      24             : #include <com/sun/star/awt/MenuItemStyle.hpp>
      25             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      26             : 
      27             : #include <com/sun/star/embed/VerbAttributes.hpp>
      28             : #include <com/sun/star/embed/VerbDescriptor.hpp>
      29             : #include <com/sun/star/frame/XDispatch.hpp>
      30             : #include <com/sun/star/frame/XStatusListener.hpp>
      31             : #include <com/sun/star/frame/XPopupMenuController.hpp>
      32             : #include <com/sun/star/lang/XServiceInfo.hpp>
      33             : 
      34             : #include <svtools/popupmenucontrollerbase.hxx>
      35             : #include <toolkit/awt/vclxmenu.hxx>
      36             : #include <cppuhelper/supportsservice.hxx>
      37             : #include <cppuhelper/weak.hxx>
      38             : #include <vcl/menu.hxx>
      39             : #include <vcl/svapp.hxx>
      40             : #include <vcl/i18nhelp.hxx>
      41             : #include <rtl/ref.hxx>
      42             : #include <rtl/ustrbuf.hxx>
      43             : #include <osl/mutex.hxx>
      44             : 
      45             : using namespace com::sun::star::uno;
      46             : using namespace com::sun::star::lang;
      47             : using namespace com::sun::star::frame;
      48             : using namespace com::sun::star::beans;
      49             : using namespace com::sun::star::util;
      50             : using namespace framework;
      51             : 
      52             : namespace {
      53             : 
      54             : class ObjectMenuController :  public svt::PopupMenuControllerBase
      55             : {
      56             :     using svt::PopupMenuControllerBase::disposing;
      57             : 
      58             : public:
      59             :     ObjectMenuController( const css::uno::Reference< css::uno::XComponentContext >& xContext );
      60             :     virtual ~ObjectMenuController();
      61             : 
      62             :     // XServiceInfo
      63           4 :     virtual OUString SAL_CALL getImplementationName()
      64             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      65             :     {
      66           4 :         return OUString("com.sun.star.comp.framework.ObjectMenuController");
      67             :     }
      68             : 
      69           0 :     virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
      70             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      71             :     {
      72           0 :         return cppu::supportsService(this, ServiceName);
      73             :     }
      74             : 
      75           0 :     virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
      76             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      77             :     {
      78           0 :         css::uno::Sequence< OUString > aSeq(1);
      79           0 :         aSeq[0] = OUString("com.sun.star.frame.PopupMenuController");
      80           0 :         return aSeq;
      81             :     }
      82             : 
      83             :     // XStatusListener
      84             :     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) throw ( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      85             : 
      86             :     // XEventListener
      87             :     virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) throw ( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      88             : 
      89             : private:
      90             :     void fillPopupMenu( const css::uno::Sequence< css::embed::VerbDescriptor >& rVerbCommandSeq, css::uno::Reference< css::awt::XPopupMenu >& rPopupMenu );
      91             :     virtual void impl_select(const css::uno::Reference< css::frame::XDispatch >& _xDispatch,const css::util::URL& aURL) SAL_OVERRIDE;
      92             : 
      93             :     css::uno::Reference< css::frame::XDispatch >  m_xObjectUpdateDispatch;
      94             : };
      95             : 
      96           8 : ObjectMenuController::ObjectMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext ) :
      97           8 :     svt::PopupMenuControllerBase( xContext )
      98             : {
      99           8 : }
     100             : 
     101          16 : ObjectMenuController::~ObjectMenuController()
     102             : {
     103          16 : }
     104             : 
     105             : // private function
     106           0 : void ObjectMenuController::fillPopupMenu( const Sequence< com::sun::star::embed::VerbDescriptor >& rVerbCommandSeq, Reference< css::awt::XPopupMenu >& rPopupMenu )
     107             : {
     108           0 :     const css::embed::VerbDescriptor* pVerbCommandArray = rVerbCommandSeq.getConstArray();
     109           0 :     VCLXPopupMenu*                    pPopupMenu        = static_cast<VCLXPopupMenu *>(VCLXMenu::GetImplementation( rPopupMenu ));
     110           0 :     PopupMenu*                        pVCLPopupMenu     = 0;
     111             : 
     112           0 :     SolarMutexGuard aSolarMutexGuard;
     113             : 
     114           0 :     resetPopupMenu( rPopupMenu );
     115           0 :     if ( pPopupMenu )
     116           0 :         pVCLPopupMenu = static_cast<PopupMenu *>(pPopupMenu->GetMenu());
     117             : 
     118           0 :     if ( pVCLPopupMenu )
     119             :     {
     120           0 :         const OUString aVerbCommand( ".uno:ObjectMenue?VerbID:short=" );
     121           0 :         for ( sal_uInt16 i = 0; i < rVerbCommandSeq.getLength(); i++ )
     122             :         {
     123           0 :             const com::sun::star::embed::VerbDescriptor& rVerb = pVerbCommandArray[i];
     124           0 :             if ( rVerb.VerbAttributes & com::sun::star::embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU )
     125             :             {
     126           0 :                 m_xPopupMenu->insertItem( i+1, rVerb.VerbName, 0, i );
     127             :                 // use VCL popup menu pointer to set vital information that are not part of the awt implementation
     128             : 
     129           0 :                 OUString aCommand( aVerbCommand );
     130           0 :                 aCommand += OUString::number( rVerb.VerbID );
     131           0 :                 pVCLPopupMenu->SetItemCommand( i+1, aCommand ); // Store verb command
     132             :             }
     133           0 :         }
     134           0 :     }
     135           0 : }
     136             : 
     137             : // XEventListener
     138           4 : void SAL_CALL ObjectMenuController::disposing( const EventObject& ) throw ( RuntimeException, std::exception )
     139             : {
     140           4 :     Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
     141             : 
     142           8 :     osl::MutexGuard aLock( m_aMutex );
     143           4 :     m_xFrame.clear();
     144           4 :     m_xDispatch.clear();
     145           4 :     m_xObjectUpdateDispatch.clear();
     146             : 
     147           4 :     if ( m_xPopupMenu.is() )
     148           4 :         m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
     149           8 :     m_xPopupMenu.clear();
     150           4 : }
     151             : 
     152             : // XStatusListener
     153          12 : void SAL_CALL ObjectMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException, std::exception )
     154             : {
     155          12 :     Sequence < com::sun::star::embed::VerbDescriptor > aVerbCommandSeq;
     156          12 :     if ( Event.State >>= aVerbCommandSeq )
     157             :     {
     158           0 :         osl::MutexGuard aLock( m_aMutex );
     159           0 :         if ( m_xPopupMenu.is() )
     160           0 :             fillPopupMenu( aVerbCommandSeq, m_xPopupMenu );
     161          12 :     }
     162          12 : }
     163             : 
     164             : // XMenuListener
     165           0 : void ObjectMenuController::impl_select(const Reference< XDispatch >& _xDispatch,const ::com::sun::star::util::URL& aTargetURL)
     166             : {
     167           0 :     Sequence<PropertyValue>      aArgs;
     168             :     OSL_ENSURE(_xDispatch.is(),"ObjectMenuController::impl_select: No dispatch");
     169           0 :     if ( _xDispatch.is() )
     170           0 :         _xDispatch->dispatch( aTargetURL, aArgs );
     171           0 : }
     172             : 
     173             : }
     174             : 
     175             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     176           8 : com_sun_star_comp_framework_ObjectMenuController_get_implementation(
     177             :     css::uno::XComponentContext *context,
     178             :     css::uno::Sequence<css::uno::Any> const &)
     179             : {
     180           8 :     return cppu::acquire(new ObjectMenuController(context));
     181         951 : }
     182             : 
     183             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10