LCOV - code coverage report
Current view: top level - uui/source - interactionhandler.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 25 43 58.1 %
Date: 2015-06-13 12:38:46 Functions: 7 10 70.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             : #include <sal/config.h>
      21             : 
      22             : #include <boost/noncopyable.hpp>
      23             : #include <com/sun/star/awt/XWindow.hpp>
      24             : #include <com/sun/star/lang/XInitialization.hpp>
      25             : #include <com/sun/star/lang/XServiceInfo.hpp>
      26             : #include <com/sun/star/task/XInteractionHandler2.hpp>
      27             : 
      28             : #include "iahndl.hxx"
      29             : #include <comphelper/namedvaluecollection.hxx>
      30             : #include <cppuhelper/implbase3.hxx>
      31             : #include <cppuhelper/supportsservice.hxx>
      32             : 
      33             : using namespace com::sun::star;
      34             : 
      35             : namespace {
      36             : 
      37             : class UUIInteractionHandler:
      38             :     public cppu::WeakImplHelper3< com::sun::star::lang::XServiceInfo,
      39             :                                   com::sun::star::lang::XInitialization,
      40             :                                   com::sun::star::task::XInteractionHandler2 >,
      41             :     private boost::noncopyable
      42             : {
      43             : private:
      44             :     UUIInteractionHelper * m_pImpl;
      45             : 
      46             : public:
      47             :     explicit UUIInteractionHandler(com::sun::star::uno::Reference<
      48             :                   com::sun::star::uno::XComponentContext >
      49             :                   const & rxContext);
      50             : 
      51             :     virtual ~UUIInteractionHandler();
      52             : 
      53             :     virtual OUString SAL_CALL getImplementationName()
      54             :         throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      55             : 
      56             :     virtual sal_Bool SAL_CALL supportsService(OUString const &
      57             :                           rServiceName)
      58             :         throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      59             : 
      60             :     virtual com::sun::star::uno::Sequence< OUString > SAL_CALL
      61             :     getSupportedServiceNames()
      62             :         throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      63             : 
      64             :     virtual void SAL_CALL
      65             :     initialize(
      66             :         com::sun::star::uno::Sequence< com::sun::star::uno::Any > const &
      67             :             rArguments)
      68             :         throw (com::sun::star::uno::Exception, std::exception) SAL_OVERRIDE;
      69             : 
      70             :     virtual void SAL_CALL
      71             :     handle(com::sun::star::uno::Reference<
      72             :            com::sun::star::task::XInteractionRequest > const &
      73             :        rRequest)
      74             :         throw (com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      75             : 
      76             :     virtual sal_Bool SAL_CALL
      77             :         handleInteractionRequest(
      78             :             const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& _Request
      79             :         )   throw ( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      80             : };
      81             : 
      82        1615 : UUIInteractionHandler::UUIInteractionHandler(
      83             :     uno::Reference< uno::XComponentContext > const &
      84             :         rxContext)
      85        1615 :         : m_pImpl(new UUIInteractionHelper(rxContext))
      86             : {
      87        1615 : }
      88             : 
      89        4833 : UUIInteractionHandler::~UUIInteractionHandler()
      90             : {
      91        1611 :     delete m_pImpl;
      92        3222 : }
      93             : 
      94           1 : OUString SAL_CALL UUIInteractionHandler::getImplementationName()
      95             :     throw (uno::RuntimeException, std::exception)
      96             : {
      97           1 :     return OUString("com.sun.star.comp.uui.UUIInteractionHandler");
      98             : }
      99             : 
     100             : sal_Bool SAL_CALL
     101           0 : UUIInteractionHandler::supportsService(OUString const & rServiceName)
     102             :     throw (uno::RuntimeException, std::exception)
     103             : {
     104           0 :     return cppu::supportsService(this, rServiceName);
     105             : }
     106             : 
     107             : uno::Sequence< OUString > SAL_CALL
     108           1 : UUIInteractionHandler::getSupportedServiceNames()
     109             :     throw (uno::RuntimeException, std::exception)
     110             : {
     111           1 :     uno::Sequence< OUString > aNames(3);
     112           1 :     aNames[0] = "com.sun.star.task.InteractionHandler";
     113             :     // added to indicate support for configuration.backend.MergeRecoveryRequest
     114           1 :     aNames[1] = "com.sun.star.configuration.backend.InteractionHandler";
     115           1 :     aNames[2] = "com.sun.star.uui.InteractionHandler";
     116             :     // for backwards compatibility
     117           1 :     return aNames;
     118             : }
     119             : 
     120             : void SAL_CALL
     121        1611 : UUIInteractionHandler::initialize(
     122             :     uno::Sequence< uno::Any > const & rArguments)
     123             :     throw (uno::Exception, std::exception)
     124             : {
     125        1611 :     uno::Reference<uno::XComponentContext> xContext = m_pImpl->getORB();
     126        1611 :     delete m_pImpl;
     127             : 
     128             :     // The old-style InteractionHandler service supported a sequence of
     129             :     // PropertyValue, while the new-style service now uses constructors to pass
     130             :     // in Parent and Context values; for backwards compatibility, keep support
     131             :     // for a PropertyValue sequence, too:
     132        3222 :     uno::Reference< awt::XWindow > xWindow;
     133        3222 :     OUString aContext;
     134        4833 :     if (!((rArguments.getLength() == 1 && (rArguments[0] >>= xWindow)) ||
     135           0 :           (rArguments.getLength() == 2 && (rArguments[0] >>= xWindow) &&
     136        1611 :            (rArguments[1] >>= aContext))))
     137             :     {
     138           0 :         ::comphelper::NamedValueCollection aProperties( rArguments );
     139           0 :         if ( aProperties.has( "Parent" ) )
     140             :         {
     141           0 :             OSL_VERIFY( aProperties.get( "Parent" ) >>= xWindow );
     142             :         }
     143           0 :         if ( aProperties.has( "Context" ) )
     144             :         {
     145           0 :             OSL_VERIFY( aProperties.get( "Context" ) >>= aContext );
     146           0 :         }
     147             :     }
     148             : 
     149        3222 :     m_pImpl = new UUIInteractionHelper(xContext, xWindow, aContext);
     150        1611 : }
     151             : 
     152             : void SAL_CALL
     153           0 : UUIInteractionHandler::handle(
     154             :     uno::Reference< task::XInteractionRequest > const & rRequest)
     155             :     throw (uno::RuntimeException, std::exception)
     156             : {
     157             :     try
     158             :     {
     159           0 :         m_pImpl->handleRequest(rRequest);
     160             :     }
     161           0 :     catch (uno::RuntimeException const & ex)
     162             :     {
     163           0 :         throw uno::RuntimeException(ex.Message, *this);
     164             :     }
     165           0 : }
     166             : 
     167           0 : sal_Bool SAL_CALL UUIInteractionHandler::handleInteractionRequest(
     168             :     const uno::Reference< task::XInteractionRequest >& _Request ) throw ( uno::RuntimeException, std::exception )
     169             : {
     170             :     try
     171             :     {
     172           0 :         return m_pImpl->handleRequest( _Request );
     173             :     }
     174           0 :     catch (uno::RuntimeException const & ex)
     175             :     {
     176           0 :         throw uno::RuntimeException( ex.Message, *this );
     177             :     }
     178             : }
     179             : 
     180             : }
     181             : 
     182             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     183        1615 : com_sun_star_comp_uui_UUIInteractionHandler_get_implementation(
     184             :     css::uno::XComponentContext *context,
     185             :     css::uno::Sequence<css::uno::Any> const &)
     186             : {
     187        1615 :     return cppu::acquire(new UUIInteractionHandler(context));
     188             : }
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11