LCOV - code coverage report
Current view: top level - reportdesign/source/core/api - FormattedField.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 34 167 20.4 %
Date: 2015-06-13 12:38:46 Functions: 13 193 6.7 %
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             : #include "FormattedField.hxx"
      20             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      21             : #include <com/sun/star/beans/XPropertyState.hpp>
      22             : #include "corestrings.hrc"
      23             : #include "core_resource.hrc"
      24             : #include "core_resource.hxx"
      25             : #include <tools/color.hxx>
      26             : #include <tools/debug.hxx>
      27             : #include <connectivity/dbtools.hxx>
      28             : #include <comphelper/property.hxx>
      29             : #include <cppuhelper/supportsservice.hxx>
      30             : #include "Tools.hxx"
      31             : #include "FormatCondition.hxx"
      32             : #include <com/sun/star/text/ParagraphVertAlign.hpp>
      33             : #include "ReportHelperImpl.hxx"
      34             : 
      35             : namespace reportdesign
      36             : {
      37             : 
      38             :     using namespace com::sun::star;
      39             :     using namespace comphelper;
      40             : 
      41           1 : uno::Reference< uno::XInterface > OFormattedField::create(uno::Reference< uno::XComponentContext > const & xContext)
      42             : {
      43           1 :     return *(new OFormattedField(xContext));
      44             : }
      45             : 
      46           1 : uno::Sequence< OUString > lcl_getFormattedFieldOptionals()
      47             : {
      48           3 :     OUString pProps[] = { OUString(PROPERTY_MASTERFIELDS),OUString(PROPERTY_DETAILFIELDS) };
      49           3 :     return uno::Sequence< OUString >(pProps,sizeof(pProps)/sizeof(pProps[0]));
      50             : }
      51             : 
      52           1 : OFormattedField::OFormattedField(uno::Reference< uno::XComponentContext > const & _xContext)
      53             : :FormattedFieldBase(m_aMutex)
      54             : ,FormattedFieldPropertySet(_xContext,static_cast< Implements >(IMPLEMENTS_PROPERTY_SET),lcl_getFormattedFieldOptionals())
      55             : ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
      56           1 : ,m_nFormatKey(0)
      57             : {
      58           1 :     m_aProps.aComponent.m_sName  = RPT_RESSTRING(RID_STR_FORMATTEDFIELD,m_aProps.aComponent.m_xContext->getServiceManager());
      59           1 : }
      60             : 
      61           0 : OFormattedField::OFormattedField(uno::Reference< uno::XComponentContext > const & _xContext
      62             :                                  ,const uno::Reference< lang::XMultiServiceFactory>& _xFactory
      63             :                                  ,uno::Reference< drawing::XShape >& _xShape)
      64             : :FormattedFieldBase(m_aMutex)
      65             : ,FormattedFieldPropertySet(_xContext,static_cast< Implements >(IMPLEMENTS_PROPERTY_SET),lcl_getFormattedFieldOptionals())
      66             : ,m_aProps(m_aMutex,static_cast< container::XContainer*>( this ),_xContext)
      67           0 : ,m_nFormatKey(0)
      68             : {
      69           0 :     m_aProps.aComponent.m_sName  = RPT_RESSTRING(RID_STR_FORMATTEDFIELD,m_aProps.aComponent.m_xContext->getServiceManager());
      70           0 :     m_aProps.aComponent.m_xFactory = _xFactory;
      71           0 :     osl_atomic_increment( &m_refCount );
      72             :     {
      73           0 :         m_aProps.aComponent.setShape(_xShape,this,m_refCount);
      74             :     }
      75           0 :     osl_atomic_decrement( &m_refCount );
      76           0 : }
      77             : 
      78           2 : OFormattedField::~OFormattedField()
      79             : {
      80           2 : }
      81             : 
      82          28 : IMPLEMENT_FORWARD_REFCOUNT( OFormattedField, FormattedFieldBase )
      83             : 
      84           2 : uno::Any SAL_CALL OFormattedField::queryInterface( const uno::Type& _rType ) throw (uno::RuntimeException, std::exception)
      85             : {
      86           2 :     uno::Any aReturn = FormattedFieldBase::queryInterface(_rType);
      87           2 :     if ( !aReturn.hasValue() )
      88           0 :         aReturn = FormattedFieldPropertySet::queryInterface(_rType);
      89           2 :     if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
      90           0 :         return aReturn;
      91             : 
      92           2 :     return aReturn.hasValue() ? aReturn : (m_aProps.aComponent.m_xProxy.is() ? m_aProps.aComponent.m_xProxy->queryAggregation(_rType) : aReturn);
      93             : }
      94             : 
      95             : 
      96           1 : void SAL_CALL OFormattedField::dispose() throw(uno::RuntimeException, std::exception)
      97             : {
      98           1 :     FormattedFieldPropertySet::dispose();
      99           1 :     cppu::WeakComponentImplHelperBase::dispose();
     100           1 :     m_xFormatsSupplier.clear();
     101           1 :     m_xFunction.clear();
     102           1 : }
     103             : 
     104           9 : OUString OFormattedField::getImplementationName_Static(  ) throw(uno::RuntimeException, std::exception)
     105             : {
     106           9 :     return OUString("com.sun.star.comp.report.OFormattedField");
     107             : }
     108             : 
     109             : 
     110           1 : OUString SAL_CALL OFormattedField::getImplementationName(  ) throw(uno::RuntimeException, std::exception)
     111             : {
     112           1 :     return getImplementationName_Static();
     113             : }
     114             : 
     115           2 : uno::Sequence< OUString > OFormattedField::getSupportedServiceNames_Static(  ) throw(uno::RuntimeException, std::exception)
     116             : {
     117           2 :     uno::Sequence< OUString > aServices(2);
     118           2 :     aServices[0] = SERVICE_FORMATTEDFIELD;
     119           2 :     aServices[1] = "com.sun.star.awt.UnoControlFormattedFieldModel";
     120             : 
     121           2 :     return aServices;
     122             : }
     123             : 
     124           1 : uno::Sequence< OUString > SAL_CALL OFormattedField::getSupportedServiceNames(  ) throw(uno::RuntimeException, std::exception)
     125             : {
     126           1 :     return getSupportedServiceNames_Static();
     127             : }
     128             : 
     129           0 : sal_Bool SAL_CALL OFormattedField::supportsService(const OUString& ServiceName) throw( uno::RuntimeException, std::exception )
     130             : {
     131           0 :     return cppu::supportsService(this, ServiceName);
     132             : }
     133             : 
     134             : // XReportComponent
     135           0 : REPORTCOMPONENT_IMPL(OFormattedField,m_aProps.aComponent)
     136           0 : REPORTCOMPONENT_IMPL2(OFormattedField,m_aProps.aComponent)
     137           0 : REPORTCOMPONENT_NOMASTERDETAIL(OFormattedField)
     138           0 : REPORTCONTROLFORMAT_IMPL(OFormattedField,m_aProps.aFormatProperties)
     139             : 
     140             : 
     141           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL OFormattedField::getPropertySetInfo(  ) throw(uno::RuntimeException, std::exception)
     142             : {
     143           0 :     return FormattedFieldPropertySet::getPropertySetInfo();
     144             : }
     145             : 
     146           0 : void SAL_CALL OFormattedField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     147             : {
     148             :     // special case here /// TODO check
     149           0 :     if ( !aValue.hasValue() && aPropertyName == PROPERTY_FORMATKEY )
     150           0 :         m_nFormatKey = 0;
     151             :     else
     152           0 :         FormattedFieldPropertySet::setPropertyValue( aPropertyName, aValue );
     153           0 : }
     154             : 
     155           0 : uno::Any SAL_CALL OFormattedField::getPropertyValue( const OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     156             : {
     157           0 :     return FormattedFieldPropertySet::getPropertyValue( PropertyName);
     158             : }
     159             : 
     160           0 : void SAL_CALL OFormattedField::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     161             : {
     162           0 :     FormattedFieldPropertySet::addPropertyChangeListener( aPropertyName, xListener );
     163           0 : }
     164             : 
     165           0 : void SAL_CALL OFormattedField::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     166             : {
     167           0 :     FormattedFieldPropertySet::removePropertyChangeListener( aPropertyName, aListener );
     168           0 : }
     169             : 
     170           0 : void SAL_CALL OFormattedField::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     171             : {
     172           0 :     FormattedFieldPropertySet::addVetoableChangeListener( PropertyName, aListener );
     173           0 : }
     174             : 
     175           0 : void SAL_CALL OFormattedField::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     176             : {
     177           0 :     FormattedFieldPropertySet::removeVetoableChangeListener( PropertyName, aListener );
     178           0 : }
     179             : 
     180             : // XReportControlModel
     181           0 : OUString SAL_CALL OFormattedField::getDataField() throw ( beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     182             : {
     183           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     184           0 :     return m_aProps.aDataField;
     185             : }
     186             : 
     187           0 : void SAL_CALL OFormattedField::setDataField( const OUString& _datafield ) throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     188             : {
     189           0 :     set(PROPERTY_DATAFIELD,_datafield,m_aProps.aDataField);
     190           0 : }
     191             : 
     192           0 : sal_Bool SAL_CALL OFormattedField::getPrintWhenGroupChange() throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     193             : {
     194           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     195           0 :     return m_aProps.bPrintWhenGroupChange;
     196             : }
     197             : 
     198           0 : void SAL_CALL OFormattedField::setPrintWhenGroupChange( sal_Bool _printwhengroupchange ) throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     199             : {
     200           0 :     set(PROPERTY_PRINTWHENGROUPCHANGE,_printwhengroupchange,m_aProps.bPrintWhenGroupChange);
     201           0 : }
     202             : 
     203           0 : OUString SAL_CALL OFormattedField::getConditionalPrintExpression() throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     204             : {
     205           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     206           0 :     return m_aProps.aConditionalPrintExpression;
     207             : }
     208             : 
     209           0 : void SAL_CALL OFormattedField::setConditionalPrintExpression( const OUString& _conditionalprintexpression ) throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     210             : {
     211           0 :     set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_aProps.aConditionalPrintExpression);
     212           0 : }
     213             : 
     214             : 
     215             : 
     216             : // XCloneable
     217           0 : uno::Reference< util::XCloneable > SAL_CALL OFormattedField::createClone(  ) throw (uno::RuntimeException, std::exception)
     218             : {
     219           0 :     uno::Reference< report::XReportComponent> xSource = this;
     220           0 :     uno::Reference< report::XFormattedField> xSet(cloneObject(xSource,m_aProps.aComponent.m_xFactory,SERVICE_FORMATTEDFIELD),uno::UNO_QUERY_THROW);
     221             : 
     222           0 :     if ( xSet.is() )
     223             :     {
     224           0 :         ::std::vector< uno::Reference< report::XFormatCondition> >::iterator aIter = m_aProps.m_aFormatConditions.begin();
     225           0 :         ::std::vector< uno::Reference< report::XFormatCondition> >::iterator aEnd  = m_aProps.m_aFormatConditions.end();
     226           0 :         for (sal_Int32 i = 0; aIter != aEnd; ++aIter,++i)
     227             :         {
     228           0 :             uno::Reference< report::XFormatCondition > xCond = xSet->createFormatCondition();
     229           0 :             ::comphelper::copyProperties(aIter->get(),xCond.get());
     230           0 :             xSet->insertByIndex(i,uno::makeAny(xCond));
     231           0 :         }
     232             :     }
     233           0 :     return xSet.get();
     234             : }
     235             : 
     236             : // XFormattedField
     237             : 
     238           0 : ::sal_Int32 SAL_CALL OFormattedField::getFormatKey() throw (uno::RuntimeException, std::exception)
     239             : {
     240           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     241           0 :     return m_nFormatKey;
     242             : }
     243             : 
     244           0 : void SAL_CALL OFormattedField::setFormatKey(::sal_Int32 _formatkey) throw (uno::RuntimeException, std::exception)
     245             : {
     246           0 :     set(PROPERTY_FORMATKEY,_formatkey,m_nFormatKey);
     247           0 : }
     248             : 
     249           0 : uno::Reference< util::XNumberFormatsSupplier > SAL_CALL OFormattedField::getFormatsSupplier() throw (uno::RuntimeException, std::exception)
     250             : {
     251           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     252           0 :     if ( !m_xFormatsSupplier.is() )
     253             :     {
     254           0 :         uno::Reference< report::XSection> xSection = getSection();
     255           0 :         if ( xSection.is() )
     256           0 :             m_xFormatsSupplier.set(xSection->getReportDefinition(),uno::UNO_QUERY);
     257           0 :         if ( !m_xFormatsSupplier.is() )
     258             :         {
     259           0 :             uno::Reference< beans::XPropertySet> xProp(::dbtools::findDataSource(getParent()),uno::UNO_QUERY);
     260           0 :             if ( xProp.is() )
     261           0 :                 m_xFormatsSupplier.set(xProp->getPropertyValue("NumberFormatsSupplier"),uno::UNO_QUERY);
     262           0 :         }
     263             :     }
     264           0 :     return m_xFormatsSupplier;
     265             : }
     266             : 
     267           0 : void SAL_CALL OFormattedField::setFormatsSupplier( const uno::Reference< util::XNumberFormatsSupplier >& _formatssupplier ) throw (uno::RuntimeException, std::exception)
     268             : {
     269           0 :     set(PROPERTY_FORMATSSUPPLIER,_formatssupplier,m_xFormatsSupplier);
     270           0 : }
     271             : 
     272             : // XChild
     273           0 : uno::Reference< uno::XInterface > SAL_CALL OFormattedField::getParent(  ) throw (uno::RuntimeException, std::exception)
     274             : {
     275           0 :     return OShapeHelper::getParent(this);
     276             : }
     277             : 
     278           0 : void SAL_CALL OFormattedField::setParent( const uno::Reference< uno::XInterface >& Parent ) throw (lang::NoSupportException, uno::RuntimeException, std::exception)
     279             : {
     280           0 :     OShapeHelper::setParent(Parent,this);
     281           0 : }
     282             : 
     283           0 : uno::Reference< report::XFormatCondition > SAL_CALL OFormattedField::createFormatCondition(  ) throw (uno::Exception, uno::RuntimeException, std::exception)
     284             : {
     285           0 :     return new OFormatCondition(m_aProps.aComponent.m_xContext);
     286             : }
     287             : 
     288             : // XContainer
     289           0 : void SAL_CALL OFormattedField::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException, std::exception)
     290             : {
     291           0 :     m_aProps.addContainerListener(xListener);
     292           0 : }
     293             : 
     294           0 : void SAL_CALL OFormattedField::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException, std::exception)
     295             : {
     296           0 :     m_aProps.removeContainerListener(xListener);
     297           0 : }
     298             : 
     299             : // XElementAccess
     300           0 : uno::Type SAL_CALL OFormattedField::getElementType(  ) throw (uno::RuntimeException, std::exception)
     301             : {
     302           0 :     return cppu::UnoType<report::XFormatCondition>::get();
     303             : }
     304             : 
     305           0 : sal_Bool SAL_CALL OFormattedField::hasElements(  ) throw (uno::RuntimeException, std::exception)
     306             : {
     307           0 :     return m_aProps.hasElements();
     308             : }
     309             : 
     310             : // XIndexContainer
     311           0 : void SAL_CALL OFormattedField::insertByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     312             : {
     313           0 :     m_aProps.insertByIndex(Index,Element);
     314           0 : }
     315             : 
     316           0 : void SAL_CALL OFormattedField::removeByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     317             : {
     318           0 :     m_aProps.removeByIndex(Index);
     319           0 : }
     320             : 
     321             : // XIndexReplace
     322           0 : void SAL_CALL OFormattedField::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     323             : {
     324           0 :     m_aProps.replaceByIndex(Index,Element);
     325           0 : }
     326             : 
     327             : // XIndexAccess
     328           0 : ::sal_Int32 SAL_CALL OFormattedField::getCount(  ) throw (uno::RuntimeException, std::exception)
     329             : {
     330           0 :     return m_aProps.getCount();
     331             : }
     332             : 
     333           0 : uno::Any SAL_CALL OFormattedField::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     334             : {
     335           0 :     return m_aProps.getByIndex( Index );
     336             : }
     337             : 
     338             : // XShape
     339           0 : awt::Point SAL_CALL OFormattedField::getPosition(  ) throw (uno::RuntimeException, std::exception)
     340             : {
     341           0 :     return OShapeHelper::getPosition(this);
     342             : }
     343             : 
     344           0 : void SAL_CALL OFormattedField::setPosition( const awt::Point& aPosition ) throw (uno::RuntimeException, std::exception)
     345             : {
     346           0 :     OShapeHelper::setPosition(aPosition,this);
     347           0 : }
     348             : 
     349           0 : awt::Size SAL_CALL OFormattedField::getSize(  ) throw (uno::RuntimeException, std::exception)
     350             : {
     351           0 :     return OShapeHelper::getSize(this);
     352             : }
     353             : 
     354           0 : void SAL_CALL OFormattedField::setSize( const awt::Size& aSize ) throw (beans::PropertyVetoException, uno::RuntimeException, std::exception)
     355             : {
     356           0 :     OShapeHelper::setSize(aSize,this);
     357           0 : }
     358             : 
     359             : 
     360             : // XShapeDescriptor
     361           0 : OUString SAL_CALL OFormattedField::getShapeType(  ) throw (uno::RuntimeException, std::exception)
     362             : {
     363           0 :     ::osl::MutexGuard aGuard(m_aMutex);
     364           0 :     if ( m_aProps.aComponent.m_xShape.is() )
     365           0 :         return m_aProps.aComponent.m_xShape->getShapeType();
     366           0 :    return OUString("com.sun.star.drawing.ControlShape");
     367             : }
     368             : 
     369             : 
     370             : } // namespace reportdesign
     371             : 
     372             : 
     373             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11