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

Generated by: LCOV version 1.10