LCOV - code coverage report
Current view: top level - chart2/source/controller/dialogs - RangeSelectionHelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 73 1.4 %
Date: 2014-11-03 Functions: 2 11 18.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 "RangeSelectionHelper.hxx"
      21             : #include "RangeSelectionListener.hxx"
      22             : #include "macros.hxx"
      23             : #include "ControllerLockGuard.hxx"
      24             : #include <com/sun/star/frame/XModel.hpp>
      25             : #include <com/sun/star/awt/XTopWindow.hpp>
      26             : #include <com/sun/star/text/XText.hpp>
      27             : #include <com/sun/star/embed/XEmbeddedObject.hpp>
      28             : #include <com/sun/star/embed/EmbedStates.hpp>
      29             : #include <com/sun/star/embed/XComponentSupplier.hpp>
      30             : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
      31             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      32             : #include <com/sun/star/sheet/XCellRangesAccess.hpp>
      33             : #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
      34             : #include <rtl/ustrbuf.hxx>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : 
      38             : using ::com::sun::star::uno::Reference;
      39             : using ::com::sun::star::uno::Sequence;
      40             : 
      41             : namespace chart
      42             : {
      43             : 
      44           0 : RangeSelectionHelper::RangeSelectionHelper(
      45             :     const Reference< chart2::XChartDocument > & xChartDocument ) :
      46           0 :         m_xChartDocument( xChartDocument )
      47           0 : {}
      48             : 
      49           0 : RangeSelectionHelper::~RangeSelectionHelper()
      50           0 : {}
      51             : 
      52           0 : bool RangeSelectionHelper::hasRangeSelection()
      53             : {
      54           0 :     return getRangeSelection().is();
      55             : }
      56             : 
      57           0 : Reference< sheet::XRangeSelection > RangeSelectionHelper::getRangeSelection()
      58             : {
      59           0 :     if( !m_xRangeSelection.is() &&
      60           0 :         m_xChartDocument.is() )
      61             :     {
      62             :         try
      63             :         {
      64           0 :             Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider());
      65           0 :             if( xDataProvider.is())
      66           0 :                 m_xRangeSelection.set( xDataProvider->getRangeSelection());
      67             :         }
      68           0 :         catch( const uno::Exception & ex )
      69             :         {
      70             :             ASSERT_EXCEPTION( ex );
      71             : 
      72           0 :             m_xRangeSelection.clear();
      73             :         }
      74             :     }
      75             : 
      76           0 :     return m_xRangeSelection;
      77             : }
      78             : 
      79           0 : void RangeSelectionHelper::raiseRangeSelectionDocument()
      80             : {
      81           0 :     Reference< sheet::XRangeSelection > xRangeSel( getRangeSelection());
      82           0 :     if( xRangeSel.is())
      83             :     {
      84             :         try
      85             :         {
      86             :             // bring document to front
      87           0 :             Reference< frame::XController > xCtrl( xRangeSel, uno::UNO_QUERY );
      88           0 :             if( xCtrl.is())
      89             :             {
      90           0 :                 Reference< frame::XFrame > xFrame( xCtrl->getFrame());
      91           0 :                 if( xFrame.is())
      92             :                 {
      93           0 :                     Reference< awt::XTopWindow > xWin( xFrame->getContainerWindow(),
      94           0 :                                                        uno::UNO_QUERY_THROW );
      95           0 :                     xWin->toFront();
      96           0 :                 }
      97           0 :             }
      98             :         }
      99           0 :         catch( const uno::Exception & ex )
     100             :         {
     101             :             ASSERT_EXCEPTION( ex );
     102             :         }
     103           0 :     }
     104           0 : }
     105             : 
     106           0 : bool RangeSelectionHelper::chooseRange(
     107             :     const OUString & aCurrentRange,
     108             :     const OUString & aUIString,
     109             :     RangeSelectionListenerParent & rListenerParent )
     110             : {
     111           0 :     ControllerLockGuardUNO aGuard( Reference< frame::XModel >(m_xChartDocument, uno::UNO_QUERY ) );
     112             : 
     113           0 :     bool bResult = true;
     114           0 :     raiseRangeSelectionDocument();
     115             : 
     116             :     try
     117             :     {
     118           0 :         Reference< sheet::XRangeSelection > xRangeSel( getRangeSelection());
     119           0 :         if( xRangeSel.is())
     120             :         {
     121           0 :             Sequence< beans::PropertyValue > aArgs( 4 );
     122           0 :             aArgs[0] = beans::PropertyValue(
     123             :                 "InitialValue", -1, uno::makeAny( aCurrentRange ),
     124           0 :                 beans::PropertyState_DIRECT_VALUE );
     125           0 :             aArgs[1] = beans::PropertyValue(
     126             :                 "Title", -1,
     127             :                 uno::makeAny( aUIString ),
     128           0 :                 beans::PropertyState_DIRECT_VALUE );
     129           0 :             aArgs[2] = beans::PropertyValue(
     130             :                 "CloseOnMouseRelease", -1, uno::makeAny( true ),
     131           0 :                 beans::PropertyState_DIRECT_VALUE );
     132           0 :             aArgs[3] = beans::PropertyValue(
     133             :                 "MultiSelectionMode", -1, uno::makeAny( true ),
     134           0 :                 beans::PropertyState_DIRECT_VALUE );
     135             : 
     136           0 :             if( m_xRangeSelectionListener.is() )
     137           0 :                 stopRangeListening();
     138             :             m_xRangeSelectionListener.set( Reference< sheet::XRangeSelectionListener >(
     139           0 :                 new RangeSelectionListener( rListenerParent, aCurrentRange, Reference< frame::XModel >(m_xChartDocument, uno::UNO_QUERY ) )));
     140             : 
     141           0 :             xRangeSel->addRangeSelectionListener( m_xRangeSelectionListener );
     142           0 :             xRangeSel->startRangeSelection( aArgs );
     143           0 :         }
     144             :     }
     145           0 :     catch( const uno::Exception & ex )
     146             :     {
     147           0 :         bResult = false;
     148             :         ASSERT_EXCEPTION( ex );
     149             :     }
     150             : 
     151           0 :     return bResult;
     152             : }
     153             : 
     154           0 : void RangeSelectionHelper::stopRangeListening( bool bRemoveListener /* = true */ )
     155             : {
     156           0 :     if( bRemoveListener &&
     157           0 :         m_xRangeSelectionListener.is() &&
     158           0 :         m_xRangeSelection.is() )
     159             :     {
     160           0 :         m_xRangeSelection->removeRangeSelectionListener( m_xRangeSelectionListener );
     161             :     }
     162             : 
     163           0 :     m_xRangeSelectionListener = 0;
     164           0 : }
     165             : 
     166           0 : bool RangeSelectionHelper::verifyCellRange( const OUString & rRangeStr )
     167             : {
     168           0 :     Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider());
     169           0 :     if( ! xDataProvider.is())
     170           0 :         return false;
     171             : 
     172           0 :     return xDataProvider->createDataSequenceByRangeRepresentationPossible( rRangeStr );
     173             : }
     174             : 
     175           0 : bool RangeSelectionHelper::verifyArguments( const Sequence< beans::PropertyValue > & rArguments )
     176             : {
     177           0 :     Reference< chart2::data::XDataProvider > xDataProvider( m_xChartDocument->getDataProvider());
     178           0 :     if( ! xDataProvider.is())
     179           0 :         return false;
     180             : 
     181           0 :     return xDataProvider->createDataSourcePossible( rArguments );
     182             : }
     183             : 
     184         102 : } //  namespace chart
     185             : 
     186             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10