LCOV - code coverage report
Current view: top level - libreoffice/framework/source/uielement - popupmenucontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 77 0.0 %
Date: 2012-12-27 Functions: 0 22 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             : 
      21             : #include <com/sun/star/awt/XPopupMenu.hpp>
      22             : #include <com/sun/star/frame/XPopupMenuController.hpp>
      23             : #include <com/sun/star/frame/PopupMenuControllerFactory.hpp>
      24             : 
      25             : #include <toolkit/helper/vclunohelper.hxx>
      26             : 
      27             : #include <rtl/ref.hxx>
      28             : 
      29             : #include <vcl/toolbox.hxx>
      30             : #include <vcl/menu.hxx>
      31             : #include <vcl/svapp.hxx>
      32             : #include <osl/mutex.hxx>
      33             : 
      34             : #include "uielement/popupmenucontroller.hxx"
      35             : #include "services.h"
      36             : 
      37             : using rtl::OUString;
      38             : using namespace ::com::sun::star;
      39             : using namespace ::com::sun::star::uno;
      40             : using namespace ::com::sun::star::lang;
      41             : using namespace ::com::sun::star::frame;
      42             : using namespace ::com::sun::star::beans;
      43             : 
      44             : // --------------------------------------------------------------------
      45             : 
      46             : 
      47             : namespace framework
      48             : {
      49             : 
      50           0 : DEFINE_XSERVICEINFO_MULTISERVICE        (   PopupMenuController                         ,
      51             :                                             OWeakObject                      ,
      52             :                                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ToolbarController" ) )            ,
      53             :                                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.framework.PopupMenuController" ) )
      54             :                                         )
      55             : 
      56           0 : DEFINE_INIT_SERVICE                     (   PopupMenuController, {} )
      57             : 
      58             : class PopupMenuControllerImpl
      59             : {
      60             : };
      61             : 
      62             : //========================================================================
      63             : // class PopupMenuController
      64             : //========================================================================
      65             : 
      66           0 : PopupMenuController::PopupMenuController( const Reference< lang::XMultiServiceFactory >& rServiceManager )
      67           0 : : svt::ToolboxController( rServiceManager, Reference< frame::XFrame >(), OUString() )
      68             : {
      69           0 : }
      70             : 
      71             : // --------------------------------------------------------------------
      72             : 
      73           0 : PopupMenuController::~PopupMenuController()
      74             : {
      75           0 : }
      76             : 
      77             : // --------------------------------------------------------------------
      78             : // XInterface
      79             : // --------------------------------------------------------------------
      80             : 
      81           0 : Any SAL_CALL PopupMenuController::queryInterface( const Type& aType )  throw (RuntimeException)
      82             : {
      83           0 :     Any a( ToolboxController::queryInterface( aType ) );
      84           0 :     if ( a.hasValue() )
      85           0 :         return a;
      86             : 
      87           0 :     return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ));
      88             : }
      89             : 
      90             : // --------------------------------------------------------------------
      91             : 
      92           0 : void SAL_CALL PopupMenuController::acquire() throw ()
      93             : {
      94           0 :     ToolboxController::acquire();
      95           0 : }
      96             : 
      97             : // --------------------------------------------------------------------
      98             : 
      99           0 : void SAL_CALL PopupMenuController::release() throw ()
     100             : {
     101           0 :     ToolboxController::release();
     102           0 : }
     103             : 
     104             : // --------------------------------------------------------------------
     105             : // XComponent
     106             : // --------------------------------------------------------------------
     107             : 
     108           0 : void SAL_CALL PopupMenuController::dispose() throw (RuntimeException)
     109             : {
     110           0 :     if( mxPopupMenuController.is() )
     111             :     {
     112           0 :         Reference< XComponent > xComponent( mxPopupMenuController, UNO_QUERY );
     113           0 :         if( xComponent.is() )
     114           0 :             xComponent->dispose();
     115           0 :         mxPopupMenuController.clear();
     116             :     }
     117             : 
     118           0 :     mxPopupMenu.clear();
     119             : 
     120           0 :     svt::ToolboxController::dispose();
     121           0 : }
     122             : 
     123             : // --------------------------------------------------------------------
     124             : // XStatusListener
     125             : // --------------------------------------------------------------------
     126             : 
     127           0 : void SAL_CALL PopupMenuController::statusChanged( const frame::FeatureStateEvent& rEvent ) throw ( RuntimeException )
     128             : {
     129           0 :     svt::ToolboxController::statusChanged(rEvent);
     130           0 :     enable( rEvent.IsEnabled );
     131           0 : }
     132             : 
     133             : // --------------------------------------------------------------------
     134             : // XToolbarController
     135             : // --------------------------------------------------------------------
     136             : 
     137           0 : void SAL_CALL PopupMenuController::execute( sal_Int16 KeyModifier ) throw (RuntimeException)
     138             : {
     139           0 :     svt::ToolboxController::execute( KeyModifier );
     140           0 : }
     141             : 
     142             : // --------------------------------------------------------------------
     143             : 
     144           0 : void SAL_CALL PopupMenuController::click() throw (RuntimeException)
     145             : {
     146           0 :     svt::ToolboxController::click();
     147           0 : }
     148             : 
     149             : // --------------------------------------------------------------------
     150             : 
     151           0 : void SAL_CALL PopupMenuController::doubleClick() throw (RuntimeException)
     152             : {
     153           0 :     svt::ToolboxController::doubleClick();
     154           0 : }
     155             : 
     156             : // --------------------------------------------------------------------
     157             : 
     158           0 : bool PopupMenuController::CreatePopupMenuController() throw (Exception)
     159             : {
     160             :     Reference< XComponentContext > xComponentContext(
     161           0 :         comphelper::getComponentContext( getServiceManager() ) );
     162             : 
     163           0 :     Reference< XToolbarControllerFactory > xPopupMenuControllerRegistration = PopupMenuControllerFactory::create( xComponentContext );
     164             : 
     165           0 :     Sequence< Any > aSeq( 2 );
     166           0 :     PropertyValue aPropValue;
     167             : 
     168           0 :     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" ));
     169           0 :     aPropValue.Value <<= getModuleName();
     170           0 :     aSeq[0] <<= aPropValue;
     171           0 :     aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
     172           0 :     aPropValue.Value <<= m_xFrame;
     173           0 :     aSeq[1] <<= aPropValue;
     174             : 
     175           0 :     Reference< XPopupMenuController > xPopupMenuController( xPopupMenuControllerRegistration->createInstanceWithArgumentsAndContext( getCommandURL(), aSeq, xComponentContext ), UNO_QUERY );
     176           0 :     if ( xPopupMenuController.is() )
     177             :     {
     178           0 :         mxPopupMenuController = xPopupMenuController;
     179           0 :         return true;
     180             :     }
     181           0 :     return false;
     182             : }
     183             : 
     184           0 : Reference< awt::XWindow > SAL_CALL PopupMenuController::createPopupWindow() throw (RuntimeException)
     185             : {
     186           0 :     SolarMutexGuard aSolarLock;
     187             : 
     188           0 :     Reference< awt::XWindow > xRet;
     189             : 
     190             :     try
     191             :     {
     192           0 :         ToolBox* pToolBox = dynamic_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
     193           0 :         if( !pToolBox )
     194             :             return xRet;
     195             : 
     196             :         // get selected button
     197           0 :         sal_uInt16 nItemId = pToolBox->GetDownItemId();
     198           0 :         if( !nItemId )
     199             :             return xRet;
     200             : 
     201           0 :         ::Rectangle aRect( pToolBox->GetItemRect( nItemId ) );
     202             : 
     203           0 :         if( !mxPopupMenuController.is() && !CreatePopupMenuController() )
     204             :             return xRet;
     205             : 
     206           0 :         if( !mxPopupMenu.is() )
     207             :         {
     208           0 :             mxPopupMenu = Reference< awt::XPopupMenu >( getServiceManager()->createInstance( DECLARE_ASCII( "stardiv.Toolkit.VCLXPopupMenu" ) ), UNO_QUERY_THROW );
     209           0 :             mxPopupMenuController->setPopupMenu( mxPopupMenu );
     210             :         }
     211             :         else
     212             :         {
     213           0 :             mxPopupMenuController->updatePopupMenu();
     214             : 
     215             :         }
     216           0 :         pToolBox->SetItemDown( nItemId, sal_True );
     217           0 :         Reference< awt::XWindowPeer > xPeer( getParent(), UNO_QUERY_THROW );
     218           0 :         mxPopupMenu->execute( xPeer, VCLUnoHelper::ConvertToAWTRect( aRect ), 0 );
     219           0 :         pToolBox->SetItemDown( nItemId, sal_False );
     220             :     }
     221           0 :     catch( const Exception& )
     222             :     {
     223             :     }
     224             : 
     225           0 :     return xRet;
     226             : }
     227             : 
     228             : // --------------------------------------------------------------------
     229             : 
     230           0 : Reference< awt::XWindow > SAL_CALL PopupMenuController::createItemWindow( const Reference< awt::XWindow >& /*Parent*/ )  throw (RuntimeException)
     231             : {
     232           0 :     return Reference< awt::XWindow >();
     233             : }
     234             : 
     235             : // --------------------------------------------------------------------
     236             : 
     237             : }
     238             : 
     239             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10