LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/misc - bindablecontrolhelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 53 0.0 %
Date: 2012-12-27 Functions: 0 2 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             : #include "bindablecontrolhelper.hxx"
      21             : #include <com/sun/star/form/binding/XBindableValue.hpp>
      22             : #include <com/sun/star/form/binding/XValueBinding.hpp>
      23             : #include <com/sun/star/form/binding/XListEntrySink.hpp>
      24             : #include <com/sun/star/form/binding/XListEntrySource.hpp>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : #include <com/sun/star/container/XNameAccess.hpp>
      27             : #include <com/sun/star/table/CellRangeAddress.hpp>
      28             : #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
      29             : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
      30             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      31             : #include <com/sun/star/table/CellAddress.hpp>
      32             : #include <com/sun/star/beans/NamedValue.hpp>
      33             : 
      34             : //........................................................................
      35             : namespace svt
      36             : {
      37             : //........................................................................
      38             : 
      39             : #ifndef C2U
      40             : #define C2U(cChar)  rtl::OUString::createFromAscii(cChar)
      41             : #endif
      42             : 
      43             :     using namespace ::com::sun::star;
      44             : 
      45           0 : bool lcl_isNamedRange( const rtl::OUString& sAddress, const uno::Reference< frame::XModel >& xModel, table::CellRangeAddress& aAddress )
      46             : {
      47           0 :     bool bRes = false;
      48           0 :     const static rtl::OUString sNamedRanges( RTL_CONSTASCII_USTRINGPARAM("NamedRanges"));
      49           0 :     uno::Reference< sheet::XCellRangeReferrer > xReferrer;
      50             :     try
      51             :     {
      52           0 :         uno::Reference< beans::XPropertySet > xPropSet( xModel, uno::UNO_QUERY_THROW );
      53           0 :         uno::Reference< container::XNameAccess > xNamed( xPropSet->getPropertyValue( sNamedRanges ), uno::UNO_QUERY_THROW );
      54           0 :         xReferrer.set ( xNamed->getByName( sAddress ), uno::UNO_QUERY );
      55             :     }
      56           0 :     catch( uno::Exception& /*e*/ )
      57             :     {
      58             :         // do nothing
      59             :     }
      60           0 :     if ( xReferrer.is() )
      61             :     {
      62           0 :         uno::Reference< sheet::XCellRangeAddressable > xRangeAddressable( xReferrer->getReferredCells(), uno::UNO_QUERY );
      63           0 :         if ( xRangeAddressable.is() )
      64             :         {
      65           0 :             aAddress = xRangeAddressable->getRangeAddress();
      66           0 :             bRes = true;
      67           0 :         }
      68             :     }
      69           0 :     return bRes;
      70             : }
      71             : 
      72             : 
      73             : void
      74           0 : BindableControlHelper::ApplyListSourceAndBindableData( const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& xModel, const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& rObj, const rtl::OUString& rsCtrlSource, const rtl::OUString& rsRowSource )
      75             : {
      76             : // XBindable etc.
      77           0 :     uno::Reference< lang::XMultiServiceFactory > xFac;
      78           0 :     if ( xModel.is() )
      79           0 :         xFac.set( xModel, uno::UNO_QUERY );
      80           0 :     uno::Reference< form::binding::XBindableValue > xBindable( rObj, uno::UNO_QUERY );
      81           0 :     if (  xFac.is() && rsCtrlSource.getLength() && xBindable.is() )
      82             :     {
      83             : 
      84             :          // OOo address structures
      85             :          // RefCell - convert from XL
      86             :          // pretend we converted the imported string address into the
      87             :          // appropriate address structure
      88           0 :          uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( C2U( "com.sun.star.table.CellAddressConversion" )), uno::UNO_QUERY );
      89           0 :          table::CellAddress aAddress;
      90           0 :          if ( xConvertor.is() )
      91             :          {
      92             :              // we need this service to properly convert XL notation also
      93             :              // Should be easy to extend
      94           0 :              xConvertor->setPropertyValue( C2U( "XL_A1_Representation" ), uno::makeAny( rsCtrlSource ) );
      95           0 :              xConvertor->getPropertyValue( C2U( "Address" ) ) >>= aAddress;
      96             :          }
      97             : 
      98           0 :          beans::NamedValue aArg1;
      99           0 :          aArg1.Name = C2U("BoundCell");
     100           0 :          aArg1.Value <<= aAddress;
     101             : 
     102           0 :          uno::Sequence< uno::Any > aArgs(1);
     103           0 :          aArgs[ 0 ]  <<= aArg1;
     104             : 
     105           0 :          uno::Reference< form::binding::XValueBinding > xBinding( xFac->createInstanceWithArguments( C2U("com.sun.star.table.CellValueBinding" ), aArgs ), uno::UNO_QUERY );
     106           0 :          xBindable->setValueBinding( xBinding );
     107             :     }
     108           0 :     else if ( xBindable.is() ) // reset it
     109           0 :         xBindable->setValueBinding( uno::Reference< form::binding::XValueBinding >() );
     110           0 :     uno::Reference< form::binding::XListEntrySink > xListEntrySink( rObj, uno::UNO_QUERY );
     111           0 :     if (  xFac.is() && rsRowSource.getLength() && xListEntrySink.is() )
     112             :     {
     113             : 
     114             :          // OOo address structures
     115             :          // RefCell - convert from XL
     116             :          // pretend we converted the imported string address into the
     117             :          // appropriate address structure
     118           0 :          uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( C2U( "com.sun.star.table.CellRangeAddressConversion" )), uno::UNO_QUERY );
     119           0 :          table::CellRangeAddress aAddress;
     120           0 :          if ( xConvertor.is() )
     121             :          {
     122           0 :              if ( !lcl_isNamedRange( rsRowSource, xModel, aAddress ) )
     123             :              {
     124             :                  // we need this service to properly convert XL notation also
     125             :                  // Should be easy to extend
     126           0 :                  xConvertor->setPropertyValue( C2U( "XL_A1_Representation" ), uno::makeAny( rsRowSource ) );
     127           0 :                  xConvertor->getPropertyValue( C2U( "Address" ) ) >>= aAddress;
     128             :              }
     129             :          }
     130             : 
     131           0 :          beans::NamedValue aArg1;
     132           0 :          aArg1.Name = C2U("CellRange");
     133           0 :          aArg1.Value <<= aAddress;
     134             : 
     135           0 :          uno::Sequence< uno::Any > aArgs(1);
     136           0 :          aArgs[ 0 ]  <<= aArg1;
     137             : 
     138           0 :          uno::Reference< form::binding::XListEntrySource > xSource( xFac->createInstanceWithArguments( C2U("com.sun.star.table.CellRangeListSource" ), aArgs ), uno::UNO_QUERY );
     139           0 :          xListEntrySink->setListEntrySource( xSource );
     140             :     }
     141           0 :     else if (  xListEntrySink.is() ) // reset
     142           0 :          xListEntrySink->setListEntrySource( uno::Reference< form::binding::XListEntrySource >()  );
     143             : 
     144           0 : }
     145             : 
     146             : //........................................................................
     147             : } // namespace svt
     148             : //........................................................................
     149             : 
     150             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10