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

Generated by: LCOV version 1.10