LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/reportdesign/source/ui/inspection - GeometryHandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 1236 0.0 %
Date: 2013-07-09 Functions: 0 64 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             : #include "GeometryHandler.hxx"
      20             : 
      21             : #include <comphelper/sequence.hxx>
      22             : #include <comphelper/types.hxx>
      23             : #include <comphelper/property.hxx>
      24             : #include <comphelper/mimeconfighelper.hxx>
      25             : 
      26             : #include "uistrings.hrc"
      27             : #include "reportformula.hxx"
      28             : 
      29             : #include <unotools/textsearch.hxx>
      30             : #include <unotools/configmgr.hxx>
      31             : 
      32             : #include <toolkit/helper/vclunohelper.hxx>
      33             : #include <unotools/syslocale.hxx>
      34             : #include <tools/diagnose_ex.h>
      35             : #include <tools/StringListResource.hxx>
      36             : #include <com/sun/star/lang/XInitialization.hpp>
      37             : #include "com/sun/star/form/inspection/FormComponentPropertyHandler.hpp"
      38             : #include "com/sun/star/inspection/StringRepresentation.hpp"
      39             : #include <com/sun/star/inspection/PropertyLineElement.hpp>
      40             : #include <com/sun/star/inspection/PropertyControlType.hpp>
      41             : #include <com/sun/star/inspection/XStringListControl.hpp>
      42             : #include <com/sun/star/report/Function.hpp>
      43             : #include <com/sun/star/report/XReportDefinition.hpp>
      44             : #include <com/sun/star/report/XShape.hpp>
      45             : #include <com/sun/star/report/XSection.hpp>
      46             : #include <com/sun/star/report/XFormattedField.hpp>
      47             : #include <com/sun/star/report/XFixedLine.hpp>
      48             : #include <com/sun/star/script/Converter.hpp>
      49             : #include <com/sun/star/sdb/XSingleSelectQueryComposer.hpp>
      50             : #include <com/sun/star/sdb/CommandType.hpp>
      51             : #include <com/sun/star/sdb/FilterDialog.hpp>
      52             : #include <com/sun/star/sdb/SQLContext.hpp>
      53             : #include <com/sun/star/sdbc/XConnection.hpp>
      54             : #include <com/sun/star/util/SearchOptions.hpp>
      55             : #include <com/sun/star/util/MeasureUnit.hpp>
      56             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      57             : #include <com/sun/star/container/XNameContainer.hpp>
      58             : #include <com/sun/star/inspection/XNumericControl.hpp>
      59             : #include <com/sun/star/style/ParagraphAdjust.hpp>
      60             : 
      61             : #include <vcl/msgbox.hxx>
      62             : #include <vcl/waitobj.hxx>
      63             : #include <tools/fldunit.hxx>
      64             : #include <vcl/stdtext.hxx>
      65             : 
      66             : #include "ModuleHelper.hxx"
      67             : #include "RptResId.hrc"
      68             : #include "RptDef.hxx"
      69             : #include "UITools.hxx"
      70             : 
      71             : #include <connectivity/dbexception.hxx>
      72             : #include <connectivity/dbconversion.hxx>
      73             : #include <connectivity/dbtools.hxx>
      74             : 
      75             : #include <boost/bind.hpp>
      76             : #include <tools/string.hxx>
      77             : #include "metadata.hxx"
      78             : #include <svl/itempool.hxx>
      79             : #include <svl/itemset.hxx>
      80             : #include <svx/xdef.hxx>
      81             : #include <svx/xpool.hxx>
      82             : #include <svx/xtable.hxx>
      83             : #include <svx/xlnwtit.hxx>
      84             : #include <svx/xlntrit.hxx>
      85             : #include <svx/xlnclit.hxx>
      86             : #include <svx/xlnstit.hxx>
      87             : #include <svx/xlnedit.hxx>
      88             : #include <svx/xlnstwit.hxx>
      89             : #include <svx/xlnedwit.hxx>
      90             : #include <svx/xlnstcit.hxx>
      91             : #include <svx/xlnedcit.hxx>
      92             : #include <svx/xlndsit.hxx>
      93             : #include <svx/xlineit0.hxx>
      94             : #include <svx/svxids.hrc>
      95             : #include <svx/drawitem.hxx>
      96             : #include <editeng/brushitem.hxx>
      97             : #include <sfx2/docfilt.hxx>
      98             : 
      99             : #include "dlgpage.hxx"
     100             : #include "helpids.hrc"
     101             : #include <toolkit/helper/convert.hxx>
     102             : 
     103             : #include <o3tl/compat_functional.hxx>
     104             : 
     105             : #define DATA_OR_FORMULA     0
     106             : #define FUNCTION            1
     107             : #define COUNTER             2
     108             : #define USER_DEF_FUNCTION   3
     109             : #define UNDEF_DATA          4
     110             : 
     111             : //........................................................................
     112             : namespace rptui
     113             : {
     114             : //........................................................................
     115             : using namespace ::com::sun::star;
     116             : 
     117             : namespace{
     118             : // comparing two property instances
     119             : struct PropertyCompare : public ::std::binary_function< beans::Property, OUString , bool >
     120             : {
     121           0 :     bool operator() (const beans::Property& x, const OUString& y) const
     122             :     {
     123           0 :         return x.Name.equals(y);
     124             :     }
     125             :     bool operator() (const OUString& x,const beans::Property& y) const
     126             :     {
     127             :         return x.equals(y.Name);
     128             :     }
     129             : };
     130             : 
     131             : // -----------------------------------------------------------------------------
     132           0 : OUString lcl_getQuotedFunctionName(const OUString& _sFunction)
     133             : {
     134           0 :     OUString sQuotedFunctionName("[");
     135           0 :     sQuotedFunctionName += _sFunction + OUString("]");
     136           0 :     return sQuotedFunctionName;
     137             : }
     138             : // -----------------------------------------------------------------------------
     139           0 : OUString lcl_getQuotedFunctionName(const uno::Reference< report::XFunction>& _xFunction)
     140             : {
     141           0 :     return lcl_getQuotedFunctionName(_xFunction->getName());
     142             : }
     143             : // -----------------------------------------------------------------------------
     144           0 : void lcl_collectFunctionNames(const uno::Reference< report::XFunctions>& _xFunctions,TFunctions& _rFunctionNames)
     145             : {
     146           0 :     uno::Reference< report::XFunctionsSupplier> xParent(_xFunctions->getParent(),uno::UNO_QUERY_THROW);
     147           0 :     const sal_Int32 nCount = _xFunctions->getCount();
     148           0 :     for (sal_Int32 i = 0; i < nCount ; ++i)
     149             :     {
     150           0 :         uno::Reference< report::XFunction > xFunction(_xFunctions->getByIndex(i),uno::UNO_QUERY_THROW);
     151           0 :         _rFunctionNames.insert(TFunctions::value_type(lcl_getQuotedFunctionName(xFunction),TFunctionPair(xFunction,xParent)));
     152           0 :     }
     153           0 : }
     154             : // -----------------------------------------------------------------------------
     155           0 : void lcl_collectFunctionNames(const uno::Reference< report::XSection>& _xSection,TFunctions& _rFunctionNames)
     156             : {
     157           0 :     const uno::Reference< report::XReportDefinition> xReportDefinition = _xSection->getReportDefinition();
     158           0 :     const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
     159           0 :     sal_Int32 nPos = -1;
     160           0 :     uno::Reference< report::XGroup> xGroup = _xSection->getGroup();
     161           0 :     if ( xGroup.is() )
     162           0 :         nPos = getPositionInIndexAccess(xGroups.get(),xGroup);
     163           0 :     else if ( _xSection == xReportDefinition->getDetail() )
     164           0 :         nPos = xGroups->getCount()-1;
     165             : 
     166           0 :     for (sal_Int32 i = 0 ; i <= nPos ; ++i)
     167             :     {
     168           0 :         xGroup.set(xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
     169           0 :         lcl_collectFunctionNames(xGroup->getFunctions(),_rFunctionNames);
     170             :     }
     171           0 :     lcl_collectFunctionNames(xReportDefinition->getFunctions(),_rFunctionNames);
     172           0 : }
     173             : // -----------------------------------------------------------------------------
     174           0 : void lcl_convertFormulaTo(const uno::Any& _aPropertyValue,uno::Any& _rControlValue)
     175             : {
     176           0 :     OUString sName;
     177           0 :     _aPropertyValue >>= sName;
     178           0 :     const sal_Int32 nLen = sName.getLength();
     179           0 :     if ( nLen )
     180             :     {
     181           0 :         ReportFormula aFormula( sName );
     182           0 :         _rControlValue <<= aFormula.getUndecoratedContent();
     183           0 :     }
     184           0 : }
     185             : 
     186             : // return value rounded to the nearest multiple of base
     187             : // if equidistant of two multiples, round up (for positive numbers)
     188             : // T is assumed to be an integer type
     189           0 : template <typename T, T base> T lcl_round(T value)
     190             : {
     191             :     OSL_ENSURE(value >= 0, "lcl_round: positive numbers only please");
     192           0 :     const T threshold = (base % 2 == 0) ? (base/2) : (base/2 + 1);
     193           0 :     const T rest = value % base;
     194           0 :     if ( rest >= threshold )
     195           0 :         return value + (base - rest);
     196             :     else
     197           0 :         return value - rest;
     198             : }
     199             : 
     200             : } // anonymous namespace
     201             : // -----------------------------------------------------------------------------
     202           0 : bool GeometryHandler::impl_isDataField(const OUString& _sName) const
     203             : {
     204           0 :     const OUString* pEnd = m_aFieldNames.getConstArray() + m_aFieldNames.getLength();
     205           0 :     bool bIsField = ( ::std::find( m_aFieldNames.getConstArray(), pEnd, _sName ) != pEnd );
     206             : 
     207           0 :     if ( !bIsField )
     208             :     {
     209           0 :         pEnd = m_aParamNames.getConstArray() + m_aParamNames.getLength();
     210           0 :         bIsField = ( ::std::find( m_aParamNames.getConstArray(), pEnd, _sName ) != pEnd );
     211             :     }
     212           0 :     return bIsField;
     213             : }
     214             : // -----------------------------------------------------------------------------
     215           0 : OUString GeometryHandler::impl_convertToFormula( const uno::Any& _rControlValue )
     216             : {
     217           0 :     OUString sName;
     218           0 :     _rControlValue >>= sName;
     219             : 
     220           0 :     if ( sName.isEmpty() )
     221           0 :         return sName;
     222             : 
     223           0 :     ReportFormula aParser( sName );
     224           0 :     if ( aParser.isValid() )
     225           0 :         return sName;
     226             : 
     227           0 :     aParser = ReportFormula( impl_isDataField(sName) ? ReportFormula::Field : ReportFormula::Expression, sName );
     228           0 :     return aParser.getCompleteFormula();
     229             : }
     230             : DBG_NAME(rpt_GeometryHandler)
     231           0 : GeometryHandler::GeometryHandler(uno::Reference< uno::XComponentContext > const & context) :
     232             :     GeometryHandler_Base(m_aMutex)
     233             :     ,m_aPropertyListeners( m_aMutex )
     234             :     ,m_xContext(context)
     235           0 :     ,m_pInfoService(new OPropertyInfoService())
     236             :     ,m_nDataFieldType(0)
     237           0 :     ,m_bIn(false)
     238             : {
     239             :     DBG_CTOR(rpt_GeometryHandler,NULL);
     240             :     try
     241             :     {
     242           0 :         m_xFormComponentHandler = form::inspection::FormComponentPropertyHandler::create(m_xContext);
     243           0 :         m_xTypeConverter = script::Converter::create(context);
     244           0 :         loadDefaultFunctions();
     245             :     }
     246           0 :     catch(const uno::Exception&)
     247             :     {
     248             :     }
     249           0 : }
     250             : // -----------------------------------------------------------------------------
     251           0 : GeometryHandler::~GeometryHandler()
     252             : {
     253             :     DBG_DTOR(rpt_GeometryHandler,NULL);
     254           0 : }
     255             : //------------------------------------------------------------------------
     256           0 : OUString SAL_CALL GeometryHandler::getImplementationName(  ) throw(uno::RuntimeException)
     257             : {
     258           0 :     return getImplementationName_Static();
     259             : }
     260             : 
     261             : //------------------------------------------------------------------------
     262           0 : sal_Bool SAL_CALL GeometryHandler::supportsService( const OUString& ServiceName ) throw(uno::RuntimeException)
     263             : {
     264           0 :     return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_static());
     265             : }
     266             : 
     267             : //------------------------------------------------------------------------
     268           0 : uno::Sequence< OUString > SAL_CALL GeometryHandler::getSupportedServiceNames(  ) throw(uno::RuntimeException)
     269             : {
     270           0 :     return getSupportedServiceNames_static();
     271             : }
     272             : 
     273             : //------------------------------------------------------------------------
     274           0 : OUString GeometryHandler::getImplementationName_Static(  ) throw(uno::RuntimeException)
     275             : {
     276           0 :     return OUString("com.sun.star.comp.report.GeometryHandler");
     277             : }
     278             : 
     279             : //------------------------------------------------------------------------
     280           0 : uno::Sequence< OUString > GeometryHandler::getSupportedServiceNames_static(  ) throw(uno::RuntimeException)
     281             : {
     282           0 :     uno::Sequence< OUString > aSupported(1);
     283           0 :     aSupported[0] = OUString("com.sun.star.report.inspection.GeometryHandler");
     284           0 :     return aSupported;
     285             : }
     286             : 
     287             : //------------------------------------------------------------------------
     288           0 : uno::Reference< uno::XInterface > SAL_CALL GeometryHandler::create( const uno::Reference< uno::XComponentContext >& _rxContext )
     289             : {
     290           0 :     return *(new GeometryHandler( _rxContext ));
     291             : }
     292             : // overload WeakComponentImplHelperBase::disposing()
     293             : // This function is called upon disposing the component,
     294             : // if your component needs special work when it becomes
     295             : // disposed, do it here.
     296           0 : void SAL_CALL GeometryHandler::disposing()
     297             : {
     298             :     try
     299             :     {
     300           0 :         ::comphelper::disposeComponent(m_xFormComponentHandler);
     301           0 :         ::comphelper::disposeComponent(m_xTypeConverter);
     302           0 :         if ( m_xReportComponent.is() && m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) )
     303           0 :             m_xReportComponent->removePropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this ));
     304             : 
     305           0 :         m_xReportComponent.clear();
     306           0 :         m_xRowSet.clear();
     307           0 :         m_aPropertyListeners.clear();
     308             :     }
     309           0 :     catch(uno::Exception&)
     310             :     {}
     311           0 : }
     312           0 : void SAL_CALL GeometryHandler::addEventListener(const uno::Reference< lang::XEventListener > & xListener) throw (uno::RuntimeException)
     313             : {
     314           0 :     m_xFormComponentHandler->addEventListener(xListener);
     315           0 : }
     316             : 
     317           0 : void SAL_CALL GeometryHandler::removeEventListener(const uno::Reference< lang::XEventListener > & aListener) throw (uno::RuntimeException)
     318             : {
     319           0 :     m_xFormComponentHandler->removeEventListener(aListener);
     320           0 : }
     321             : 
     322             : // inspection::XPropertyHandler:
     323             : 
     324             : /********************************************************************************/
     325           0 : void SAL_CALL GeometryHandler::inspect( const uno::Reference< uno::XInterface > & _rxInspectee ) throw (uno::RuntimeException, lang::NullPointerException)
     326             : {
     327           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     328           0 :     m_sScope = m_sDefaultFunction = OUString();
     329           0 :     m_bNewFunction = false;
     330           0 :     m_nDataFieldType = 0;
     331           0 :     m_xFunction.clear();
     332           0 :     m_aFunctionNames.clear();
     333             :     try
     334             :     {
     335           0 :         if ( m_xReportComponent.is() && m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) )
     336           0 :             m_xReportComponent->removePropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this ));
     337             : 
     338           0 :         const uno::Reference< container::XNameContainer > xObjectAsContainer( _rxInspectee, uno::UNO_QUERY );
     339           0 :         m_xReportComponent.set( xObjectAsContainer->getByName("ReportComponent"), uno::UNO_QUERY );
     340             : 
     341           0 :         const OUString sRowSet("RowSet");
     342           0 :         if ( xObjectAsContainer->hasByName( sRowSet ) )
     343             :         {
     344           0 :             const uno::Any aRowSet( xObjectAsContainer->getByName(sRowSet) );
     345           0 :             aRowSet >>= m_xRowSet;
     346             :             // forward the rowset to our delegator handler
     347           0 :             uno::Reference< beans::XPropertySet > xProp( m_xFormComponentHandler,uno::UNO_QUERY );
     348           0 :             xProp->setPropertyValue( sRowSet, aRowSet );
     349             : 
     350           0 :             m_aParamNames = getParameterNames( m_xRowSet );
     351           0 :             impl_initFieldList_nothrow(m_aFieldNames);
     352           0 :             if ( m_xReportComponent->getPropertySetInfo()->hasPropertyByName(PROPERTY_DATAFIELD) )
     353           0 :                 m_xReportComponent->addPropertyChangeListener(PROPERTY_DATAFIELD,static_cast< beans::XPropertyChangeListener* >( this ));
     354             :         }
     355             : 
     356           0 :         const uno::Reference< report::XReportComponent> xReportComponent( m_xReportComponent, uno::UNO_QUERY);
     357           0 :         uno::Reference< report::XSection> xSection( m_xReportComponent, uno::UNO_QUERY );
     358           0 :         if ( !xSection.is() && xReportComponent.is() )
     359           0 :             xSection = xReportComponent->getSection();
     360           0 :         if ( xSection.is() )
     361           0 :             lcl_collectFunctionNames( xSection, m_aFunctionNames );
     362             :     }
     363           0 :     catch(const uno::Exception &)
     364             :     {
     365           0 :         throw lang::NullPointerException();
     366             :     }
     367           0 :     m_xFormComponentHandler->inspect(m_xReportComponent);
     368           0 : }
     369             : 
     370           0 : uno::Any SAL_CALL GeometryHandler::getPropertyValue(const OUString & PropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException)
     371             : {
     372           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     373           0 :     uno::Any aPropertyValue;
     374           0 :     const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
     375           0 :     switch(nId)
     376             :     {
     377             :         case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
     378             :         case PROPERTY_ID_INITIALFORMULA:
     379             :         case PROPERTY_ID_FORMULA:
     380             :         case PROPERTY_ID_DATAFIELD:
     381           0 :             aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName );
     382           0 :             lcl_convertFormulaTo(aPropertyValue,aPropertyValue);
     383           0 :             if ( PROPERTY_ID_DATAFIELD == nId )
     384             :             {
     385           0 :                 OUString sDataField;
     386           0 :                 aPropertyValue >>= sDataField;
     387           0 :                 switch(m_nDataFieldType)
     388             :                 {
     389             :                     case DATA_OR_FORMULA:
     390           0 :                         break;
     391             :                     case FUNCTION:
     392           0 :                         if ( isDefaultFunction(sDataField,sDataField) )
     393           0 :                             aPropertyValue <<= sDataField;
     394           0 :                         else if ( sDataField.isEmpty() )
     395           0 :                             aPropertyValue = uno::Any();
     396           0 :                         break;
     397             :                     case COUNTER:
     398             :                     case USER_DEF_FUNCTION:
     399           0 :                         aPropertyValue = uno::Any();
     400           0 :                         break;
     401           0 :                 }
     402             : 
     403             :             }
     404           0 :             break;
     405             :         case PROPERTY_ID_TYPE:
     406             :             {
     407           0 :                 const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
     408           0 :                 m_nDataFieldType = impl_getDataFieldType_throw();
     409           0 :                 if ( UNDEF_DATA == m_nDataFieldType )
     410           0 :                     m_nDataFieldType = nOldDataFieldType;
     411           0 :                 aPropertyValue <<= m_nDataFieldType;
     412             :             }
     413           0 :             break;
     414             :         case PROPERTY_ID_FORMULALIST:
     415             :         case PROPERTY_ID_SCOPE:
     416             :             {
     417           0 :                 uno::Any aDataField = m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD );
     418           0 :                 lcl_convertFormulaTo(aDataField,aDataField);
     419           0 :                 OUString sDataField;
     420           0 :                 aDataField >>= sDataField;
     421           0 :                 switch(m_nDataFieldType)
     422             :                 {
     423             :                     case DATA_OR_FORMULA:
     424           0 :                         break;
     425             :                     case FUNCTION:
     426           0 :                         if ( isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true) )
     427           0 :                             aPropertyValue <<= (PROPERTY_ID_FORMULALIST == nId ? m_sDefaultFunction : m_sScope);
     428           0 :                         break;
     429             :                     case USER_DEF_FUNCTION:
     430           0 :                         if ( !sDataField.isEmpty() && PROPERTY_ID_FORMULALIST == nId )
     431           0 :                             aPropertyValue = aDataField;
     432           0 :                         break;
     433             :                     case COUNTER:
     434           0 :                         if ( PROPERTY_ID_SCOPE == nId && impl_isCounterFunction_throw(sDataField,m_sScope) )
     435           0 :                             aPropertyValue <<= m_sScope;
     436           0 :                         break;
     437           0 :                 }
     438             : 
     439             :             }
     440           0 :             break;
     441             :         case PROPERTY_ID_BACKCOLOR:
     442             :         case PROPERTY_ID_CONTROLBACKGROUND:
     443             :             {
     444           0 :                 aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName );
     445           0 :                 sal_Int32 nColor = COL_TRANSPARENT;
     446           0 :                 if ( (aPropertyValue >>= nColor) && static_cast<sal_Int32>(COL_TRANSPARENT) == nColor )
     447           0 :                     aPropertyValue.clear();
     448             :             }
     449           0 :             break;
     450             :         case PROPERTY_ID_MIMETYPE:
     451             :             {
     452           0 :                 OUString sValue;
     453           0 :                 m_xReportComponent->getPropertyValue( PropertyName ) >>= sValue;
     454           0 :                 aPropertyValue <<= impl_ConvertMimeTypeToUI_nothrow(sValue);
     455             :             }
     456           0 :             break;
     457             :         default:
     458           0 :             aPropertyValue = m_xReportComponent->getPropertyValue( PropertyName );
     459           0 :             break;
     460             :     }
     461           0 :     return aPropertyValue;
     462             : }
     463             : 
     464           0 : void SAL_CALL GeometryHandler::setPropertyValue(const OUString & PropertyName, const uno::Any & Value) throw (uno::RuntimeException, beans::UnknownPropertyException, beans::PropertyVetoException)
     465             : {
     466           0 :     ::osl::ResettableMutexGuard aGuard( m_aMutex );
     467           0 :     uno::Any aNewValue = Value;
     468           0 :     const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
     469           0 :     bool bHandled = false;
     470           0 :     switch(nId)
     471             :     {
     472             :         case PROPERTY_ID_INITIALFORMULA:
     473             :         case PROPERTY_ID_FORMULA:
     474           0 :             break;
     475             :         case PROPERTY_ID_DATAFIELD:
     476             :             {
     477           0 :                 OBlocker aBlocker(m_bIn);
     478           0 :                 m_xReportComponent->setPropertyValue(PropertyName, aNewValue);
     479           0 :                 bHandled = true;
     480           0 :                 const OUString sOldFunctionName = m_sDefaultFunction;
     481           0 :                 const OUString sOldScope = m_sScope;
     482             : 
     483           0 :                 uno::Any aPropertyValue;
     484           0 :                 lcl_convertFormulaTo(Value,aPropertyValue);
     485           0 :                 OUString sDataField;
     486           0 :                 aPropertyValue >>= sDataField;
     487             : 
     488           0 :                 m_sScope = m_sDefaultFunction = OUString();
     489           0 :                 m_xFunction.clear();
     490           0 :                 const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
     491           0 :                 if ( !sDataField.isEmpty() )
     492             :                 {
     493           0 :                     if ( isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true) )
     494           0 :                         m_nDataFieldType = FUNCTION;
     495           0 :                     else if ( m_aFunctionNames.find(sDataField) != m_aFunctionNames.end() )
     496           0 :                         m_nDataFieldType = USER_DEF_FUNCTION;
     497             :                 }
     498             : 
     499           0 :                 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType);
     500             :             }
     501           0 :             break;
     502             :         case PROPERTY_ID_TYPE:
     503             :             {
     504           0 :                 bHandled = true;
     505           0 :                 Value >>= m_nDataFieldType;
     506             : 
     507           0 :                 const OUString sOldFunctionName = m_sDefaultFunction;
     508           0 :                 const OUString sOldScope = m_sScope;
     509           0 :                 m_sDefaultFunction = m_sScope = OUString();
     510             : 
     511           0 :                 if ( m_nDataFieldType == COUNTER )
     512             :                 {
     513           0 :                     impl_setCounterFunction_throw();
     514             :                 }
     515             :                 else
     516             :                 {
     517           0 :                     if ( m_bNewFunction )
     518           0 :                         removeFunction();
     519           0 :                     m_xFunction.clear();
     520           0 :                     OBlocker aBlocker(m_bIn);
     521           0 :                     m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(OUString()));
     522             :                 }
     523           0 :                 resetOwnProperties(aGuard,sOldFunctionName,sOldScope,m_nDataFieldType);
     524             :             }
     525           0 :             break;
     526             :         case PROPERTY_ID_FORMULALIST:
     527             :             {
     528           0 :                 bHandled = true;
     529           0 :                 OUString sFunction;
     530           0 :                 if ( !(Value >>= sFunction) || sFunction.isEmpty() )
     531             :                 {
     532           0 :                     if ( m_nDataFieldType == FUNCTION )
     533             :                     {
     534           0 :                         m_sDefaultFunction = OUString();
     535           0 :                         if ( m_bNewFunction )
     536           0 :                             removeFunction();
     537           0 :                         m_xFunction.clear();
     538             : 
     539           0 :                         beans::PropertyChangeEvent aEvent;
     540           0 :                         aEvent.PropertyName = PROPERTY_SCOPE;
     541           0 :                         aEvent.OldValue <<= m_sScope;
     542           0 :                         m_sScope = OUString();
     543           0 :                         aEvent.NewValue <<= m_sScope;
     544           0 :                         aGuard.clear();
     545           0 :                         m_aPropertyListeners.notify( aEvent, &beans::XPropertyChangeListener::propertyChange );
     546             :                     }
     547           0 :                     else if ( m_nDataFieldType == USER_DEF_FUNCTION )
     548             :                     {
     549           0 :                         OBlocker aBlocker(m_bIn);
     550           0 :                         m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(OUString()));
     551             :                     }
     552             :                 }
     553           0 :                 else if ( m_nDataFieldType == USER_DEF_FUNCTION )
     554             :                 {
     555           0 :                     OUString sDataField;
     556           0 :                     OBlocker aBlocker(m_bIn);
     557           0 :                     const sal_uInt32 nNewDataType = impl_getDataFieldType_throw(sFunction);
     558           0 :                     if ( nNewDataType != UNDEF_DATA && nNewDataType != m_nDataFieldType )
     559             :                     {
     560           0 :                         const OUString sOldFunctionName = m_sDefaultFunction;
     561           0 :                         const OUString sOldScope = m_sScope;
     562           0 :                         m_sScope = m_sDefaultFunction = OUString();
     563           0 :                         m_xFunction.clear();
     564           0 :                         if ( nNewDataType == COUNTER )
     565           0 :                             impl_isCounterFunction_throw(sFunction,m_sScope);
     566             :                         else
     567             :                         {
     568           0 :                             OUString sNamePostFix;
     569           0 :                             const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix);
     570           0 :                             isDefaultFunction(sFunction,sDataField,xFunctionsSupplier,true);
     571             :                         }
     572           0 :                         const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
     573           0 :                         m_nDataFieldType = nNewDataType;
     574           0 :                         m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sFunction))));
     575           0 :                         resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType);
     576             :                     }
     577             :                     else
     578           0 :                         m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sFunction))));
     579             :                 }
     580           0 :                 else if ( m_nDataFieldType == FUNCTION )
     581             :                 {
     582           0 :                     uno::Any aPropertyValue = m_xReportComponent->getPropertyValue(PROPERTY_DATAFIELD);
     583           0 :                     lcl_convertFormulaTo(aPropertyValue,aPropertyValue);
     584           0 :                     OUString sDataField;
     585           0 :                     aPropertyValue >>= sDataField;
     586           0 :                     if ( m_nDataFieldType == FUNCTION && (!isDefaultFunction(sDataField,sDataField) || m_sDefaultFunction != sFunction) )
     587             :                     {
     588           0 :                         if ( m_bNewFunction )
     589           0 :                             removeFunction();
     590             :                         // function currently does not exist
     591           0 :                         createDefaultFunction(aGuard,sFunction,sDataField);
     592           0 :                         m_sDefaultFunction = sFunction;
     593           0 :                     }
     594           0 :                 }
     595             :             }
     596             : 
     597           0 :             break;
     598             :         case PROPERTY_ID_SCOPE:
     599           0 :             if ( !(Value >>= m_sScope) )
     600           0 :                 m_sScope = OUString();
     601             :             else
     602             :             {
     603           0 :                 if ( m_bNewFunction )
     604           0 :                     removeFunction();
     605           0 :                 if ( m_nDataFieldType == COUNTER )
     606           0 :                     impl_setCounterFunction_throw();
     607             :                 else
     608             :                 {
     609             :                     OSL_ENSURE(m_xFunction.is(),"Where is my function gone!");
     610             : 
     611           0 :                     OUString sNamePostFix;
     612           0 :                     const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix);
     613             : 
     614           0 :                     OUString sQuotedFunctionName(lcl_getQuotedFunctionName(m_xFunction));
     615           0 :                     if ( isDefaultFunction(sQuotedFunctionName,sQuotedFunctionName,xFunctionsSupplier,true) )
     616           0 :                         m_bNewFunction = false;
     617             :                     else
     618             :                     {
     619           0 :                         OUString sDefaultFunctionName;
     620           0 :                         OUString sDataField;
     621           0 :                         OSL_VERIFY( impl_isDefaultFunction_nothrow(m_xFunction,sDataField,sDefaultFunctionName) );
     622           0 :                         m_sDefaultFunction = sDefaultFunctionName;
     623           0 :                         createDefaultFunction(aGuard,m_sDefaultFunction,sDataField);
     624           0 :                     }
     625             :                 }
     626             :             }
     627           0 :             bHandled = true;
     628           0 :             break;
     629             :         case PROPERTY_ID_POSITIONX:
     630             :         case PROPERTY_ID_POSITIONY:
     631             :         case PROPERTY_ID_HEIGHT:
     632             :         case PROPERTY_ID_WIDTH:
     633             :             {
     634           0 :                 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
     635           0 :                 if ( xSourceReportComponent.is() ) // check only report components
     636             :                 {
     637           0 :                     sal_Int32 nNewValue = 0;
     638           0 :                     Value >>= nNewValue;
     639             :                     OSL_ENSURE(nNewValue >= 0, "A position/dimension should not be negative!");
     640           0 :                     nNewValue = lcl_round<sal_Int32, 10>(nNewValue);
     641           0 :                     awt::Point aAwtPoint = xSourceReportComponent->getPosition();
     642           0 :                     awt::Size aAwtSize = xSourceReportComponent->getSize();
     643           0 :                     if ( nId == PROPERTY_ID_POSITIONX )
     644           0 :                         aAwtPoint.X = nNewValue;
     645           0 :                     else if ( nId == PROPERTY_ID_POSITIONY )
     646           0 :                         aAwtPoint.Y = nNewValue;
     647           0 :                     else if ( nId == PROPERTY_ID_HEIGHT )
     648           0 :                         aAwtSize.Height = nNewValue;
     649           0 :                     else if ( nId == PROPERTY_ID_WIDTH )
     650           0 :                         aAwtSize.Width = nNewValue;
     651             : 
     652           0 :                     checkPosAndSize(aAwtPoint,aAwtSize);
     653           0 :                 }
     654             :             }
     655           0 :             break;
     656             :         case PROPERTY_ID_FONT:
     657             :             {
     658           0 :                 const uno::Reference< report::XReportControlFormat > xReportControlFormat( m_xReportComponent,uno::UNO_QUERY_THROW );
     659           0 :                 uno::Sequence< beans::NamedValue > aFontSettings;
     660           0 :                 OSL_VERIFY( Value >>= aFontSettings );
     661           0 :                 applyCharacterSettings( xReportControlFormat, aFontSettings );
     662           0 :                 bHandled = true;
     663             :             }
     664           0 :             break;
     665             :         case PROPERTY_ID_MIMETYPE:
     666             :             {
     667           0 :                 OUString sValue;
     668           0 :                 Value >>= sValue;
     669           0 :                 aNewValue <<= impl_ConvertUIToMimeType_nothrow(sValue);
     670             :             }
     671             :         default:
     672           0 :             break;
     673             :     }
     674             : 
     675           0 :     if ( !bHandled )
     676           0 :         m_xReportComponent->setPropertyValue(PropertyName, aNewValue);
     677           0 : }
     678             : 
     679             : // -----------------------------------------------------------------------------
     680           0 : beans::PropertyState SAL_CALL GeometryHandler::getPropertyState(const OUString & PropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException)
     681             : {
     682           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     683           0 :     return m_xFormComponentHandler->getPropertyState(PropertyName);
     684             : }
     685             : // -----------------------------------------------------------------------------
     686           0 : void GeometryHandler::implCreateListLikeControl(
     687             :         const uno::Reference< inspection::XPropertyControlFactory >& _rxControlFactory
     688             :         ,inspection::LineDescriptor & out_Descriptor
     689             :         ,sal_uInt16 _nResId
     690             :         ,sal_Bool _bReadOnlyControl
     691             :         ,sal_Bool _bTrueIfListBoxFalseIfComboBox
     692             :     )
     693             : {
     694           0 :     ::std::vector< OUString > aList;
     695           0 :     tools::StringListResource aRes(ModuleRes(_nResId),aList);
     696             : 
     697           0 :     implCreateListLikeControl(_rxControlFactory,out_Descriptor,aList,_bReadOnlyControl,_bTrueIfListBoxFalseIfComboBox);
     698           0 : }
     699             : // -----------------------------------------------------------------------------
     700           0 : void GeometryHandler::implCreateListLikeControl(
     701             :         const uno::Reference< inspection::XPropertyControlFactory >& _rxControlFactory
     702             :         ,inspection::LineDescriptor & out_Descriptor
     703             :         ,const ::std::vector< OUString>& _aEntries
     704             :         ,sal_Bool _bReadOnlyControl
     705             :         ,sal_Bool _bTrueIfListBoxFalseIfComboBox
     706             :     )
     707             : {
     708             :     const uno::Reference< inspection::XStringListControl > xListControl(
     709           0 :         _rxControlFactory->createPropertyControl(
     710             :             _bTrueIfListBoxFalseIfComboBox ? inspection::PropertyControlType::ListBox : inspection::PropertyControlType::ComboBox, _bReadOnlyControl
     711           0 :         ),
     712             :         uno::UNO_QUERY_THROW
     713           0 :     );
     714             : 
     715           0 :     out_Descriptor.Control = xListControl.get();
     716           0 :     ::std::for_each( _aEntries.begin(), _aEntries.end(),::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl,_1 ));
     717           0 : }
     718             : // -----------------------------------------------------------------------------
     719             : 
     720           0 : inspection::LineDescriptor SAL_CALL GeometryHandler::describePropertyLine(const OUString & PropertyName, const uno::Reference< inspection::XPropertyControlFactory > & _xControlFactory) throw (beans::UnknownPropertyException, lang::NullPointerException,uno::RuntimeException)
     721             : {
     722           0 :     inspection::LineDescriptor aOut;
     723           0 :     const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
     724           0 :     switch(nId)
     725             :     {
     726             :         case PROPERTY_ID_FORCENEWPAGE:
     727             :         case PROPERTY_ID_NEWROWORCOL:
     728           0 :             implCreateListLikeControl(_xControlFactory,aOut,RID_STR_FORCENEWPAGE_CONST,sal_False,sal_True);
     729           0 :             break;
     730             :         case PROPERTY_ID_GROUPKEEPTOGETHER:
     731           0 :             implCreateListLikeControl(_xControlFactory,aOut,RID_STR_GROUPKEEPTOGETHER_CONST,sal_False,sal_True);
     732           0 :             break;
     733             :         case PROPERTY_ID_PAGEHEADEROPTION:
     734             :         case PROPERTY_ID_PAGEFOOTEROPTION:
     735           0 :             implCreateListLikeControl(_xControlFactory,aOut,RID_STR_REPORTPRINTOPTION_CONST,sal_False,sal_True);
     736           0 :             break;
     737             :         case PROPERTY_ID_FORMULALIST:
     738             :             {
     739           0 :                 ::std::vector< OUString > aList;
     740           0 :                 impl_fillFormulaList_nothrow(aList);
     741           0 :                 implCreateListLikeControl(_xControlFactory,aOut,aList,sal_False,sal_True);
     742             :             }
     743           0 :             break;
     744             :         case PROPERTY_ID_SCOPE:
     745             :             {
     746           0 :                 ::std::vector< OUString > aList;
     747           0 :                 impl_fillScopeList_nothrow(aList);
     748           0 :                 implCreateListLikeControl(_xControlFactory,aOut,aList,sal_False,sal_True);
     749             :             }
     750           0 :             break;
     751             :         case PROPERTY_ID_MIMETYPE:
     752             :             {
     753           0 :                 ::std::vector< OUString > aList;
     754           0 :                 impl_fillMimeTypes_nothrow(aList);
     755           0 :                 implCreateListLikeControl(_xControlFactory,aOut,aList,sal_False,sal_True);
     756             :             }
     757           0 :             break;
     758             :         case PROPERTY_ID_TYPE:
     759           0 :             implCreateListLikeControl(_xControlFactory,aOut,RID_STR_TYPE_CONST,sal_False,sal_True);
     760           0 :             break;
     761             :         case PROPERTY_ID_VISIBLE:
     762             :         case PROPERTY_ID_CANGROW:
     763             :         case PROPERTY_ID_CANSHRINK:
     764             :         case PROPERTY_ID_REPEATSECTION:
     765             :         case PROPERTY_ID_PRINTREPEATEDVALUES:
     766             :         case PROPERTY_ID_STARTNEWCOLUMN:
     767             :         case PROPERTY_ID_RESETPAGENUMBER:
     768             :         case PROPERTY_ID_PRINTWHENGROUPCHANGE:
     769             :         case PROPERTY_ID_KEEPTOGETHER:
     770             :         case PROPERTY_ID_DEEPTRAVERSING:
     771             :         case PROPERTY_ID_PREEVALUATED:
     772             :         case PROPERTY_ID_PRESERVEIRI:
     773             :         case PROPERTY_ID_BACKTRANSPARENT:
     774             :         case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
     775             :             {
     776           0 :                 sal_uInt16 nResId = RID_STR_BOOL;
     777           0 :                 if ( PROPERTY_ID_KEEPTOGETHER == nId && uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is())
     778           0 :                     nResId = RID_STR_KEEPTOGETHER_CONST;
     779           0 :                 implCreateListLikeControl(_xControlFactory,aOut,nResId,sal_False,sal_True);
     780             :             }
     781           0 :             break;
     782             :         case PROPERTY_ID_INITIALFORMULA:
     783             :         case PROPERTY_ID_FORMULA:
     784           0 :             aOut.PrimaryButtonId = OUString::createFromAscii(UID_RPT_PROP_FORMULA);
     785           0 :             aOut.HasPrimaryButton = sal_True;
     786           0 :             aOut.Control = _xControlFactory->createPropertyControl(inspection::PropertyControlType::MultiLineTextField , sal_False);
     787           0 :             break;
     788             :         case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
     789           0 :             aOut.PrimaryButtonId = OUString::createFromAscii(UID_RPT_PROP_FORMULA);
     790           0 :             aOut.HasPrimaryButton = sal_True;
     791           0 :             aOut.Control = _xControlFactory->createPropertyControl(inspection::PropertyControlType::MultiLineTextField , sal_False);
     792           0 :             break;
     793             :         case PROPERTY_ID_DATAFIELD:
     794             :             {
     795             :                 uno::Reference< inspection::XStringListControl > xListControl(
     796           0 :                     _xControlFactory->createPropertyControl(
     797           0 :                         m_nDataFieldType == DATA_OR_FORMULA ? inspection::PropertyControlType::ComboBox : inspection::PropertyControlType::ListBox, sal_False
     798           0 :                     ),
     799             :                     uno::UNO_QUERY_THROW
     800           0 :                 );
     801             : 
     802           0 :                 if ( m_nDataFieldType == DATA_OR_FORMULA )
     803             :                 {
     804           0 :                     aOut.PrimaryButtonId = OUString::createFromAscii(UID_RPT_PROP_FORMULA);
     805           0 :                     aOut.HasPrimaryButton = sal_True;
     806             :                 }
     807             : 
     808           0 :                 aOut.Control = xListControl.get();
     809           0 :                 if ( m_nDataFieldType == USER_DEF_FUNCTION )
     810             :                 {
     811             :                     // add function names
     812             :                     ::std::for_each( m_aFunctionNames.begin(), m_aFunctionNames.end(),
     813             :                         ::o3tl::compose1(
     814             :                             ::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl,_1 ),
     815           0 :                             ::o3tl::select1st<TFunctions::value_type>()));
     816             :                 }
     817             :                 else
     818             :                 {
     819           0 :                     ::std::for_each( m_aFieldNames.getConstArray(), m_aFieldNames.getConstArray() + m_aFieldNames.getLength(),
     820           0 :                         ::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl, _1 ) );
     821           0 :                     ::std::for_each( m_aParamNames.getConstArray(), m_aParamNames.getConstArray() + m_aParamNames.getLength(),
     822           0 :                         ::boost::bind( &inspection::XStringListControl::appendListEntry, xListControl, _1 ) );
     823           0 :                 }
     824             :             }
     825           0 :             break;
     826             :         case PROPERTY_ID_BACKCOLOR:
     827             :         case PROPERTY_ID_CONTROLBACKGROUND:
     828           0 :             aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::ColorListBox, sal_False );
     829           0 :             break;
     830             :         case PROPERTY_ID_FONT:
     831           0 :             aOut.PrimaryButtonId = OUString::createFromAscii(UID_RPT_RPT_PROP_DLG_FONT_TYPE);
     832           0 :             aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::TextField, sal_True );
     833           0 :             aOut.HasPrimaryButton = sal_True;
     834           0 :             break;
     835             :         case PROPERTY_ID_AREA:
     836           0 :             aOut.PrimaryButtonId = OUString::createFromAscii(UID_RPT_RPT_PROP_DLG_AREA);
     837           0 :             aOut.Control = _xControlFactory->createPropertyControl( inspection::PropertyControlType::TextField, sal_True );
     838           0 :             aOut.HasPrimaryButton = sal_True;
     839           0 :             break;
     840             :         case PROPERTY_ID_VERTICALALIGN:
     841           0 :             implCreateListLikeControl(_xControlFactory,aOut,RID_STR_VERTICAL_ALIGN_CONST,sal_False,sal_True);
     842           0 :             break;
     843             :         case PROPERTY_ID_PARAADJUST:
     844           0 :             implCreateListLikeControl(_xControlFactory,aOut,RID_STR_PARAADJUST_CONST,sal_False,sal_True);
     845           0 :             break;
     846             :         default:
     847             :             {
     848           0 :             aOut = m_xFormComponentHandler->describePropertyLine(PropertyName, _xControlFactory);
     849             :             }
     850             :     }
     851             : 
     852           0 :     if ( nId != -1 )
     853             :     {
     854           0 :         aOut.Category = ((m_pInfoService->getPropertyUIFlags(nId ) & PROP_FLAG_DATA_PROPERTY) != 0) ?
     855             :                                     OUString("Data")
     856             :                                                         :
     857           0 :                                     OUString("General");
     858           0 :         aOut.HelpURL = HelpIdUrl::getHelpURL( m_pInfoService->getPropertyHelpId( nId ) );
     859           0 :         aOut.DisplayName = m_pInfoService->getPropertyTranslation(nId);
     860             :     }
     861             : 
     862           0 :     if  (  ( nId == PROPERTY_ID_POSITIONX )
     863           0 :         || ( nId == PROPERTY_ID_POSITIONY )
     864           0 :         || ( nId == PROPERTY_ID_WIDTH )
     865           0 :         || ( nId == PROPERTY_ID_HEIGHT )
     866             :         )
     867             :     {
     868           0 :         const MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
     869           0 :         const sal_Int16 nDisplayUnit = VCLUnoHelper::ConvertToMeasurementUnit( MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_INCH, 1 );
     870           0 :         uno::Reference< inspection::XNumericControl > xNumericControl(aOut.Control,uno::UNO_QUERY);
     871           0 :         xNumericControl->setDecimalDigits( 2 );
     872           0 :         xNumericControl->setValueUnit( util::MeasureUnit::MM_100TH );
     873           0 :         uno::Reference< drawing::XShapeDescriptor> xShapeDesc(m_xReportComponent,uno::UNO_QUERY);
     874           0 :         bool bSetMin = !xShapeDesc.is() || xShapeDesc->getShapeType() != OUString("com.sun.star.drawing.CustomShape");
     875           0 :         if ( bSetMin )
     876           0 :             xNumericControl->setMinValue(beans::Optional<double>(sal_True,0.0));
     877           0 :         if ( nDisplayUnit != -1 )
     878           0 :             xNumericControl->setDisplayUnit( nDisplayUnit );
     879           0 :         uno::Reference< report::XReportComponent> xComp(m_xReportComponent,uno::UNO_QUERY);
     880           0 :         if ( xComp.is() && xComp->getSection().is() )
     881             :         {
     882           0 :             uno::Reference< report::XReportDefinition > xReport = xComp->getSection()->getReportDefinition();
     883             :             OSL_ENSURE(xReport.is(),"Why is the report definition NULL!");
     884           0 :             if ( xReport.is() )
     885             :             {
     886           0 :                 const awt::Size aSize = getStyleProperty<awt::Size>(xReport,PROPERTY_PAPERSIZE);
     887           0 :                 const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReport,PROPERTY_LEFTMARGIN);
     888           0 :                 const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReport,PROPERTY_RIGHTMARGIN);
     889           0 :                 switch(nId)
     890             :                 {
     891             :                     case PROPERTY_ID_POSITIONX:
     892             :                     case PROPERTY_ID_POSITIONY:
     893             :                     case PROPERTY_ID_WIDTH:
     894           0 :                         if ( bSetMin )
     895           0 :                             xNumericControl->setMinValue(beans::Optional<double>(sal_True,0.0));
     896           0 :                         xNumericControl->setMaxValue(beans::Optional<double>(sal_True,double(aSize.Width - nLeftMargin - nRightMargin)));
     897           0 :                         if ( PROPERTY_ID_WIDTH == nId )
     898             :                         {
     899           0 :                             uno::Reference<report::XFixedLine> xFixedLine(m_xReportComponent,uno::UNO_QUERY);
     900           0 :                             if ( xFixedLine.is() && xFixedLine->getOrientation() == 1 ) // vertical
     901           0 :                                 xNumericControl->setMinValue(beans::Optional<double>(sal_True,0.08 ));
     902             :                         }
     903           0 :                         break;
     904             :                     default:
     905           0 :                         break;
     906             :                 }
     907           0 :             }
     908             :         }
     909           0 :         else if ( PROPERTY_ID_HEIGHT == nId )
     910             :         {
     911           0 :             const uno::Reference< report::XSection> xSection(m_xReportComponent,uno::UNO_QUERY);
     912           0 :             if ( xSection.is() )
     913             :             {
     914           0 :                 sal_Int32 nHeight = 0;
     915           0 :                 const sal_Int32 nCount = xSection->getCount();
     916           0 :                 for (sal_Int32 i = 0; i < nCount; ++i)
     917             :                 {
     918           0 :                     uno::Reference<drawing::XShape> xShape(xSection->getByIndex(i),uno::UNO_QUERY);
     919           0 :                     nHeight = ::std::max<sal_Int32>(nHeight,xShape->getPosition().Y + xShape->getSize().Height);
     920           0 :                 }
     921           0 :                 xNumericControl->setMinValue(beans::Optional<double>(sal_True,nHeight ));
     922           0 :             }
     923           0 :         }
     924             :     }
     925           0 :     return aOut;
     926             : }
     927             : // -----------------------------------------------------------------------------
     928           0 : beans::Property GeometryHandler::getProperty(const OUString & PropertyName)
     929             : {
     930           0 :     uno::Sequence< beans::Property > aProps = getSupportedProperties();
     931           0 :     const beans::Property* pIter = aProps.getConstArray();
     932           0 :     const beans::Property* pEnd  = pIter + aProps.getLength();
     933           0 :     const beans::Property* pFind = ::std::find_if(pIter,pEnd,::std::bind2nd(PropertyCompare(),boost::cref(PropertyName)));
     934           0 :     if ( pFind == pEnd )
     935           0 :         return beans::Property();
     936           0 :     return *pFind;
     937             : }
     938           0 : uno::Any GeometryHandler::getConstantValue(sal_Bool _bToControlValue,sal_uInt16 _nResId,const uno::Any& _aValue,const OUString& _sConstantName,const OUString & PropertyName )
     939             : {
     940           0 :     ::std::vector< OUString > aList;
     941           0 :     tools::StringListResource aRes(ModuleRes(_nResId),aList);
     942           0 :     uno::Sequence< OUString > aSeq(aList.size());
     943           0 :     ::std::copy( aList.begin(), aList.end(), aSeq.getArray() );
     944             : 
     945           0 :     uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::createConstant( m_xContext,m_xTypeConverter,_sConstantName,aSeq);
     946           0 :     if ( _bToControlValue )
     947             :     {
     948           0 :         return uno::makeAny( xConversionHelper->convertToControlValue( _aValue ) );
     949             :     }
     950             :     else
     951             :     {
     952           0 :         OUString sControlValue;
     953           0 :         _aValue >>= sControlValue;
     954           0 :         const beans::Property aProp = getProperty(PropertyName);
     955           0 :         return xConversionHelper->convertToPropertyValue( sControlValue, aProp.Type );
     956           0 :     }
     957             : }
     958             : 
     959           0 : uno::Any SAL_CALL GeometryHandler::convertToPropertyValue(const OUString & PropertyName, const uno::Any & _rControlValue) throw (uno::RuntimeException, beans::UnknownPropertyException)
     960             : {
     961           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     962           0 :     uno::Any aPropertyValue( _rControlValue );
     963           0 :     const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
     964           0 :     switch(nId)
     965             :     {
     966             :         case PROPERTY_ID_FORCENEWPAGE:
     967             :         case PROPERTY_ID_NEWROWORCOL:
     968           0 :             aPropertyValue = getConstantValue(sal_False,RID_STR_FORCENEWPAGE_CONST,_rControlValue,OUString("com.sun.star.report.ForceNewPage"),PropertyName);
     969           0 :             break;
     970             :         case PROPERTY_ID_GROUPKEEPTOGETHER:
     971           0 :             aPropertyValue = getConstantValue(sal_False,RID_STR_GROUPKEEPTOGETHER_CONST,_rControlValue,OUString("com.sun.star.report.GroupKeepTogether"),PropertyName);
     972           0 :             break;
     973             :         case PROPERTY_ID_PAGEHEADEROPTION:
     974             :         case PROPERTY_ID_PAGEFOOTEROPTION:
     975           0 :             aPropertyValue = getConstantValue(sal_False,RID_STR_REPORTPRINTOPTION_CONST,_rControlValue,OUString("com.sun.star.report.ReportPrintOption"),PropertyName);
     976           0 :             break;
     977             :         case PROPERTY_ID_BACKCOLOR:
     978             :         case PROPERTY_ID_CONTROLBACKGROUND:
     979           0 :             if ( !_rControlValue.hasValue() )
     980             :             {
     981           0 :                 aPropertyValue <<= static_cast<sal_Int32>(COL_TRANSPARENT);
     982           0 :                 break;
     983             :             }
     984             :             // run through
     985             : 
     986             :         case PROPERTY_ID_KEEPTOGETHER:
     987           0 :             if ( uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is())
     988             :             {
     989           0 :                 aPropertyValue = getConstantValue(sal_False,RID_STR_KEEPTOGETHER_CONST,_rControlValue,OUString("com.sun.star.report.KeepTogether"),PropertyName);
     990           0 :                 break;
     991             :             }
     992             :             // run through
     993             : 
     994             :         case PROPERTY_ID_VISIBLE:
     995             :         case PROPERTY_ID_CANGROW:
     996             :         case PROPERTY_ID_CANSHRINK:
     997             :         case PROPERTY_ID_REPEATSECTION:
     998             :         case PROPERTY_ID_PRINTREPEATEDVALUES:
     999             :         case PROPERTY_ID_STARTNEWCOLUMN:
    1000             :         case PROPERTY_ID_RESETPAGENUMBER:
    1001             :         case PROPERTY_ID_PRINTWHENGROUPCHANGE:
    1002             :         case PROPERTY_ID_DEEPTRAVERSING:
    1003             :         case PROPERTY_ID_PREEVALUATED:
    1004             :         case PROPERTY_ID_PRESERVEIRI:
    1005             :         case PROPERTY_ID_BACKTRANSPARENT:
    1006             :         case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
    1007             :         {
    1008           0 :             if ( aPropertyValue.hasValue() )
    1009             :             {
    1010           0 :                 const beans::Property aProp = getProperty(PropertyName);
    1011           0 :                 if ( aPropertyValue.getValueType().equals( aProp.Type ) )
    1012             :                     // nothing to do, type is already as desired
    1013           0 :                     return aPropertyValue;
    1014             : 
    1015           0 :                 if ( _rControlValue.getValueType().getTypeClass() == uno::TypeClass_STRING )
    1016             :                 {
    1017           0 :                     OUString sControlValue;
    1018           0 :                     _rControlValue >>= sControlValue;
    1019             : 
    1020           0 :                     const uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::create( m_xContext,m_xTypeConverter );
    1021           0 :                     aPropertyValue = xConversionHelper->convertToPropertyValue( sControlValue, aProp.Type );
    1022             :                 }
    1023             :                 else
    1024             :                 {
    1025             :                     try
    1026             :                     {
    1027           0 :                         aPropertyValue = m_xTypeConverter->convertTo( _rControlValue, aProp.Type );
    1028             :                     }
    1029           0 :                     catch( const uno::Exception& )
    1030             :                     {
    1031             :                         OSL_FAIL( "GeometryHandler::convertToPropertyValue: caught an exception while converting via TypeConverter!" );
    1032             :                     }
    1033           0 :                 }
    1034             :             }
    1035             : 
    1036           0 :             break;
    1037             :         }
    1038             :         case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
    1039             :         case PROPERTY_ID_INITIALFORMULA:
    1040             :         case PROPERTY_ID_FORMULA:
    1041           0 :             return uno::makeAny( impl_convertToFormula( _rControlValue ) );
    1042             :         case PROPERTY_ID_DATAFIELD:
    1043             :             {
    1044           0 :                 OUString sDataField;
    1045           0 :                 _rControlValue >>= sDataField;
    1046           0 :                 if ( isDefaultFunction(sDataField,sDataField) )
    1047             :                 {
    1048             :                     OSL_ENSURE(m_xFunction.is(),"No function set!");
    1049           0 :                     aPropertyValue <<= impl_convertToFormula( uno::makeAny(lcl_getQuotedFunctionName(m_xFunction)) );
    1050             :                 }
    1051             :                 else
    1052           0 :                     aPropertyValue <<= impl_convertToFormula( _rControlValue );
    1053             :             }
    1054           0 :             break;
    1055             :         case PROPERTY_ID_POSITIONX:
    1056             :             {
    1057           0 :                 aPropertyValue = m_xFormComponentHandler->convertToPropertyValue(PropertyName, _rControlValue);
    1058           0 :                 sal_Int32 nPosX = 0;
    1059           0 :                 aPropertyValue >>= nPosX;
    1060           0 :                 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
    1061           0 :                 if ( xSourceReportComponent->getSection().is() )
    1062           0 :                     nPosX += getStyleProperty<sal_Int32>(xSourceReportComponent->getSection()->getReportDefinition(),PROPERTY_LEFTMARGIN);
    1063           0 :                 aPropertyValue <<= nPosX;
    1064             :             }
    1065           0 :             break;
    1066             :         case PROPERTY_ID_FONT:
    1067           0 :             aPropertyValue = m_xFormComponentHandler->convertToPropertyValue(PROPERTY_FONT, _rControlValue);
    1068           0 :             break;
    1069             :         case PROPERTY_ID_SCOPE:
    1070             :         case PROPERTY_ID_FORMULALIST:
    1071             :         case PROPERTY_ID_AREA:
    1072           0 :             aPropertyValue = _rControlValue;
    1073           0 :             break;
    1074             :         case PROPERTY_ID_TYPE:
    1075             :             {
    1076           0 :                 OUString sValue;
    1077           0 :                 _rControlValue >>= sValue;
    1078           0 :                 ::std::vector< OUString > aList;
    1079           0 :                 tools::StringListResource aRes(ModuleRes(RID_STR_TYPE_CONST),aList);
    1080           0 :                 ::std::vector< OUString >::iterator aFind = ::std::find(aList.begin(),aList.end(),sValue);
    1081           0 :                 if ( aFind != aList.end() )
    1082           0 :                     aPropertyValue <<= static_cast<sal_uInt32>(aFind - aList.begin());
    1083             :             }
    1084           0 :             break;
    1085             :         case PROPERTY_ID_MIMETYPE:
    1086           0 :             aPropertyValue = _rControlValue;
    1087           0 :             break;
    1088             :         case PROPERTY_ID_VERTICALALIGN:
    1089             :             {
    1090           0 :                 OUString sValue;
    1091           0 :                 _rControlValue >>= sValue;
    1092           0 :                 ::std::vector< OUString > aList;
    1093           0 :                 tools::StringListResource aRes(ModuleRes(RID_STR_VERTICAL_ALIGN_CONST),aList);
    1094           0 :                 ::std::vector< OUString >::iterator aFind = ::std::find(aList.begin(),aList.end(),sValue);
    1095           0 :                 if ( aFind != aList.end() )
    1096           0 :                     aPropertyValue <<= static_cast<style::VerticalAlignment>(aFind - aList.begin());
    1097             :             }
    1098           0 :             break;
    1099             :         case PROPERTY_ID_PARAADJUST:
    1100             :             {
    1101           0 :                 OUString sValue;
    1102           0 :                 _rControlValue >>= sValue;
    1103           0 :                 ::std::vector< OUString > aList;
    1104           0 :                 tools::StringListResource aRes(ModuleRes(RID_STR_PARAADJUST_CONST),aList);
    1105           0 :                 ::std::vector< OUString >::iterator aFind = ::std::find(aList.begin(),aList.end(),sValue);
    1106           0 :                 if ( aFind != aList.end() )
    1107           0 :                     aPropertyValue <<= static_cast<sal_Int16>(aFind - aList.begin());
    1108             :             }
    1109           0 :             break;
    1110             :         default:
    1111           0 :             return m_xFormComponentHandler->convertToPropertyValue(PropertyName, _rControlValue);
    1112             :     }
    1113           0 :     return aPropertyValue;
    1114             : }
    1115             : 
    1116           0 : uno::Any SAL_CALL GeometryHandler::convertToControlValue(const OUString & PropertyName, const uno::Any & _rPropertyValue, const uno::Type & _rControlValueType) throw (uno::RuntimeException, beans::UnknownPropertyException)
    1117             : {
    1118           0 :     uno::Any aControlValue( _rPropertyValue );
    1119           0 :     if ( !aControlValue.hasValue() )
    1120             :         // NULL is converted to NULL
    1121           0 :         return aControlValue;
    1122             : 
    1123           0 :     uno::Any aPropertyValue(_rPropertyValue);
    1124             : 
    1125           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1126           0 :     const sal_Int32 nId = m_pInfoService->getPropertyId(PropertyName);
    1127           0 :     switch(nId)
    1128             :     {
    1129             :         case PROPERTY_ID_AREA:
    1130           0 :             break;
    1131             :         case PROPERTY_ID_FORCENEWPAGE:
    1132             :         case PROPERTY_ID_NEWROWORCOL:
    1133           0 :             aControlValue = getConstantValue(sal_True,RID_STR_FORCENEWPAGE_CONST,aPropertyValue,OUString("com.sun.star.report.ForceNewPage"),PropertyName);
    1134           0 :             break;
    1135             :         case PROPERTY_ID_GROUPKEEPTOGETHER:
    1136           0 :             aControlValue = getConstantValue(sal_True,RID_STR_GROUPKEEPTOGETHER_CONST,aPropertyValue,OUString("com.sun.star.report.GroupKeepTogether"),PropertyName);
    1137           0 :             break;
    1138             :         case PROPERTY_ID_PAGEHEADEROPTION:
    1139             :         case PROPERTY_ID_PAGEFOOTEROPTION:
    1140           0 :             aControlValue = getConstantValue(sal_True,RID_STR_REPORTPRINTOPTION_CONST,aPropertyValue,OUString("com.sun.star.report.ReportPrintOption"),PropertyName);
    1141           0 :             break;
    1142             :         case PROPERTY_ID_KEEPTOGETHER:
    1143           0 :             if ( uno::Reference< report::XGroup>(m_xReportComponent,uno::UNO_QUERY).is())
    1144             :             {
    1145           0 :                 aControlValue = getConstantValue(sal_True,RID_STR_KEEPTOGETHER_CONST,aPropertyValue,OUString("com.sun.star.report.KeepTogether"),PropertyName);
    1146           0 :                 break;
    1147             :             }
    1148             :             // run through
    1149             :         case PROPERTY_ID_VISIBLE:
    1150             :         case PROPERTY_ID_CANGROW:
    1151             :         case PROPERTY_ID_CANSHRINK:
    1152             :         case PROPERTY_ID_REPEATSECTION:
    1153             :         case PROPERTY_ID_PRINTREPEATEDVALUES:
    1154             :         case PROPERTY_ID_STARTNEWCOLUMN:
    1155             :         case PROPERTY_ID_RESETPAGENUMBER:
    1156             :         case PROPERTY_ID_PRINTWHENGROUPCHANGE:
    1157             :         case PROPERTY_ID_DEEPTRAVERSING:
    1158             :         case PROPERTY_ID_PREEVALUATED:
    1159             :         case PROPERTY_ID_PRESERVEIRI:
    1160             :         case PROPERTY_ID_BACKTRANSPARENT:
    1161             :         case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
    1162             :         {
    1163           0 :             if ( _rControlValueType.getTypeClass() == uno::TypeClass_STRING )
    1164             :             {
    1165           0 :                 const uno::Reference< inspection::XStringRepresentation > xConversionHelper = inspection::StringRepresentation::create( m_xContext,m_xTypeConverter );
    1166           0 :                 aControlValue <<= xConversionHelper->convertToControlValue( aPropertyValue );
    1167             :             }
    1168             :             else
    1169             :             {
    1170             :                 try
    1171             :                 {
    1172           0 :                     aControlValue = m_xTypeConverter->convertTo( aPropertyValue, _rControlValueType );
    1173             :                 }
    1174           0 :                 catch( const uno::Exception& )
    1175             :                 {
    1176             :                     OSL_FAIL( "GeometryHandler::convertToControlValue: caught an exception while converting via TypeConverter!" );
    1177             :                 }
    1178             :             }
    1179           0 :             break;
    1180             :         }
    1181             :         case PROPERTY_ID_CONDITIONALPRINTEXPRESSION:
    1182             :         case PROPERTY_ID_INITIALFORMULA:
    1183             :         case PROPERTY_ID_FORMULA:
    1184           0 :             lcl_convertFormulaTo(aPropertyValue,aControlValue);
    1185           0 :             break;
    1186             :         case PROPERTY_ID_DATAFIELD:
    1187             :             {
    1188           0 :                 OUString sValue;
    1189           0 :                 aControlValue >>= sValue;
    1190           0 :                 if ( isDefaultFunction(sValue,sValue) )
    1191           0 :                     aControlValue <<= sValue;
    1192             :                 else
    1193           0 :                     lcl_convertFormulaTo(aPropertyValue,aControlValue);
    1194             :             }
    1195           0 :             break;
    1196             :         case PROPERTY_ID_FONT:
    1197           0 :             aControlValue = m_xFormComponentHandler->convertToControlValue(PROPERTY_FONT, aPropertyValue, _rControlValueType);
    1198           0 :             break;
    1199             :         case PROPERTY_ID_POSITIONX:
    1200             :             {
    1201           0 :                 sal_Int32 nPosX = 0;
    1202           0 :                 aPropertyValue >>= nPosX;
    1203           0 :                 const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
    1204           0 :                 if ( xSourceReportComponent->getSection().is() )
    1205           0 :                     nPosX -= getStyleProperty<sal_Int32>(xSourceReportComponent->getSection()->getReportDefinition(),PROPERTY_LEFTMARGIN);
    1206           0 :                 aPropertyValue <<= nPosX;
    1207           0 :                 aControlValue = m_xFormComponentHandler->convertToControlValue(PropertyName, aPropertyValue, _rControlValueType);
    1208             :             }
    1209           0 :             break;
    1210             :         case PROPERTY_ID_FORMULALIST:
    1211           0 :             aControlValue <<= m_sDefaultFunction;
    1212           0 :             break;
    1213             :         case PROPERTY_ID_SCOPE:
    1214           0 :             aControlValue <<= m_sScope;
    1215           0 :             break;
    1216             :         case PROPERTY_ID_MIMETYPE:
    1217           0 :             aControlValue = aPropertyValue;
    1218           0 :             break;
    1219             :         case PROPERTY_ID_TYPE:
    1220             :             {
    1221           0 :                 ::std::vector< OUString > aList;
    1222           0 :                 tools::StringListResource aRes(ModuleRes(RID_STR_TYPE_CONST),aList);
    1223           0 :                 if ( m_nDataFieldType < aList.size() )
    1224           0 :                     aControlValue <<= aList[m_nDataFieldType];
    1225             :             }
    1226           0 :             break;
    1227             :         case PROPERTY_ID_VERTICALALIGN:
    1228             :             {
    1229           0 :                 style::VerticalAlignment nParagraphVertAlign = style::VerticalAlignment_TOP;
    1230           0 :                 aPropertyValue >>= nParagraphVertAlign;
    1231           0 :                 ::std::vector< OUString > aList;
    1232           0 :                 tools::StringListResource aRes(ModuleRes(RID_STR_VERTICAL_ALIGN_CONST),aList);
    1233           0 :                 if ( static_cast<sal_Int16>(nParagraphVertAlign) < static_cast<sal_Int16>(aList.size()) )
    1234           0 :                     aControlValue <<= aList[nParagraphVertAlign];
    1235             :             }
    1236           0 :             break;
    1237             :         case PROPERTY_ID_PARAADJUST:
    1238             :             {
    1239           0 :                 sal_Int16 nParagraphAdjust = style::ParagraphAdjust_LEFT;
    1240           0 :                 aPropertyValue >>= nParagraphAdjust;
    1241           0 :                 ::std::vector< OUString > aList;
    1242           0 :                 tools::StringListResource aRes(ModuleRes(RID_STR_PARAADJUST_CONST),aList);
    1243           0 :                 if ( nParagraphAdjust < static_cast<sal_Int16>(aList.size()) )
    1244           0 :                     aControlValue <<= aList[nParagraphAdjust];
    1245             :             }
    1246           0 :             break;
    1247             :         case PROPERTY_ID_BACKCOLOR:
    1248             :         case PROPERTY_ID_CONTROLBACKGROUND:
    1249             :             {
    1250           0 :                 sal_Int32 nColor = COL_TRANSPARENT;
    1251           0 :                 if ( (aPropertyValue >>= nColor) && static_cast<sal_Int32>(COL_TRANSPARENT) == nColor )
    1252           0 :                     aPropertyValue.clear();
    1253             :             }
    1254             :             // run through
    1255             :         default:
    1256           0 :             aControlValue = m_xFormComponentHandler->convertToControlValue(PropertyName, aPropertyValue, _rControlValueType);
    1257             :     }
    1258           0 :     return aControlValue;
    1259             : }
    1260           0 : void SAL_CALL GeometryHandler::addPropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & _rxListener) throw (uno::RuntimeException, lang::NullPointerException)
    1261             : {
    1262           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1263           0 :     m_aPropertyListeners.addListener( _rxListener );
    1264           0 :     m_xFormComponentHandler->addPropertyChangeListener(_rxListener);
    1265           0 : }
    1266             : 
    1267           0 : void SAL_CALL GeometryHandler::removePropertyChangeListener(const uno::Reference< beans::XPropertyChangeListener > & _rxListener) throw (uno::RuntimeException)
    1268             : {
    1269           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1270           0 :     m_aPropertyListeners.removeListener( _rxListener );
    1271           0 :     m_xFormComponentHandler->removePropertyChangeListener(_rxListener);
    1272           0 : }
    1273             : // -----------------------------------------------------------------------------
    1274             : //--------------------------------------------------------------------------
    1275           0 : uno::Sequence< beans::Property > SAL_CALL GeometryHandler::getSupportedProperties() throw (uno::RuntimeException)
    1276             : {
    1277           0 :     ::std::vector< beans::Property > aNewProps;
    1278           0 :     aNewProps.reserve(20); // only a guess
    1279           0 :     m_pInfoService->getExcludeProperties( aNewProps, m_xFormComponentHandler );
    1280             : 
    1281             :     const OUString pIncludeProperties[] =
    1282             :     {
    1283             :          OUString(PROPERTY_FORCENEWPAGE)
    1284             :         ,OUString(PROPERTY_KEEPTOGETHER)
    1285             :         ,OUString(PROPERTY_CANGROW)
    1286             :         ,OUString(PROPERTY_CANSHRINK)
    1287             :         ,OUString(PROPERTY_REPEATSECTION)
    1288             :         ,OUString(PROPERTY_PRINTREPEATEDVALUES)
    1289             :         ,OUString(PROPERTY_CONDITIONALPRINTEXPRESSION)
    1290             :         ,OUString(PROPERTY_STARTNEWCOLUMN)
    1291             :         ,OUString(PROPERTY_RESETPAGENUMBER)
    1292             :         ,OUString(PROPERTY_PRINTWHENGROUPCHANGE)
    1293             :         ,OUString(PROPERTY_VISIBLE)
    1294             :         ,OUString(PROPERTY_PAGEHEADEROPTION)
    1295             :         ,OUString(PROPERTY_PAGEFOOTEROPTION)
    1296             :         ,OUString("ControlLabel")
    1297             :         ,OUString(PROPERTY_POSITIONX)
    1298             :         ,OUString(PROPERTY_POSITIONY)
    1299             :         ,OUString(PROPERTY_WIDTH)
    1300             :         ,OUString(PROPERTY_HEIGHT)
    1301             :         ,OUString(PROPERTY_PREEVALUATED)
    1302             :         ,OUString(PROPERTY_DEEPTRAVERSING)
    1303             :         ,OUString(PROPERTY_FORMULA)
    1304             :         ,OUString(PROPERTY_INITIALFORMULA)
    1305             :         ,OUString(PROPERTY_PRESERVEIRI)
    1306             :         ,OUString(PROPERTY_DATAFIELD)
    1307             :         ,OUString(PROPERTY_FONT)
    1308             :         ,OUString(PROPERTY_BACKCOLOR)
    1309             :         ,OUString(PROPERTY_BACKTRANSPARENT)
    1310             :         ,OUString(PROPERTY_CONTROLBACKGROUND)
    1311             :         ,OUString(PROPERTY_CONTROLBACKGROUNDTRANSPARENT)
    1312             :         ,OUString(PROPERTY_LABEL)
    1313             :         ,OUString(PROPERTY_MIMETYPE)
    1314             :         ,OUString(PROPERTY_VERTICALALIGN)
    1315             :         ,OUString(PROPERTY_PARAADJUST)
    1316           0 :     };
    1317           0 :     const uno::Reference < beans::XPropertySetInfo > xInfo = m_xReportComponent->getPropertySetInfo();
    1318           0 :     const uno::Sequence< beans::Property> aSeq = xInfo->getProperties();
    1319           0 :     for (size_t i = 0; i < sizeof(pIncludeProperties)/sizeof(pIncludeProperties[0]) ;++i )
    1320             :     {
    1321           0 :         const beans::Property* pIter = aSeq.getConstArray();
    1322           0 :         const beans::Property* pEnd  = pIter + aSeq.getLength();
    1323           0 :         const beans::Property* pFind = ::std::find_if(pIter,pEnd,::std::bind2nd(PropertyCompare(),boost::cref(pIncludeProperties[i])));
    1324           0 :         if ( pFind != pEnd )
    1325             :         {
    1326             :             // special case for controls which contain a data field
    1327           0 :             if ( PROPERTY_DATAFIELD == pIncludeProperties[i] )
    1328             :             {
    1329           0 :                 beans::Property aValue;
    1330           0 :                 aValue.Name = PROPERTY_FORMULALIST;
    1331           0 :                 aNewProps.push_back(aValue);
    1332           0 :                 aValue.Name = PROPERTY_SCOPE;
    1333           0 :                 aNewProps.push_back(aValue);
    1334           0 :                 aValue.Name = PROPERTY_TYPE;
    1335           0 :                 aNewProps.push_back(aValue);
    1336             :             }
    1337           0 :             aNewProps.push_back(*pFind);
    1338             :         }
    1339             :     }
    1340             : 
    1341             :     // special property for shapes
    1342             : //    if ( uno::Reference< report::XShape>(m_xReportComponent,uno::UNO_QUERY).is() )
    1343             : //    {
    1344             : //        beans::Property aValue;
    1345             : //        aValue.Name = PROPERTY_AREA;
    1346             : //        aNewProps.push_back(aValue);
    1347             : //    }
    1348             :     // re-enable when the remaining issues of #i88727# are fixed
    1349             : 
    1350           0 :     return uno::Sequence< beans::Property > (&(*aNewProps.begin()),aNewProps.size());
    1351             : }
    1352             : 
    1353           0 : uno::Sequence< OUString > SAL_CALL GeometryHandler::getSupersededProperties() throw (uno::RuntimeException)
    1354             : {
    1355           0 :     uno::Sequence< OUString > aRet;
    1356           0 :     const uno::Reference<report::XReportDefinition> xReport(m_xReportComponent,uno::UNO_QUERY);
    1357           0 :     if ( xReport.is() && !uno::Reference< report::XSection>(xReport->getParent(),uno::UNO_QUERY).is() )
    1358             :     {
    1359           0 :         aRet.realloc(5);
    1360           0 :         OUString* pIter = aRet.getArray();
    1361           0 :         *pIter++ = PROPERTY_POSITIONX;
    1362           0 :         *pIter++ = PROPERTY_POSITIONY;
    1363           0 :         *pIter++ = PROPERTY_WIDTH;
    1364           0 :         *pIter++ = PROPERTY_HEIGHT;
    1365           0 :         *pIter++ = PROPERTY_DATAFIELD;
    1366             :     }
    1367           0 :     return aRet;
    1368             : }
    1369             : 
    1370           0 : uno::Sequence< OUString > SAL_CALL GeometryHandler::getActuatingProperties() throw (uno::RuntimeException)
    1371             : {
    1372           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1373             : 
    1374           0 :     uno::Sequence< OUString > aSeq(5);
    1375           0 :     aSeq[0] = PROPERTY_BACKTRANSPARENT;
    1376           0 :     aSeq[1] = PROPERTY_CONTROLBACKGROUNDTRANSPARENT;
    1377           0 :     aSeq[2] = PROPERTY_FORMULALIST;
    1378           0 :     aSeq[3] = PROPERTY_TYPE;
    1379           0 :     aSeq[4] = PROPERTY_DATAFIELD;
    1380             : 
    1381           0 :     return ::comphelper::concatSequences(m_xFormComponentHandler->getActuatingProperties(),aSeq);
    1382             : }
    1383             : 
    1384           0 : ::sal_Bool SAL_CALL GeometryHandler::isComposable(const OUString & _rPropertyName) throw (uno::RuntimeException, beans::UnknownPropertyException)
    1385             : {
    1386           0 :     return m_pInfoService->isComposable( _rPropertyName, m_xFormComponentHandler );
    1387             : }
    1388             : 
    1389           0 : inspection::InteractiveSelectionResult SAL_CALL GeometryHandler::onInteractivePropertySelection(const OUString & PropertyName, ::sal_Bool Primary, uno::Any & _rData, const uno::Reference< inspection::XObjectInspectorUI > & _rxInspectorUI) throw (uno::RuntimeException, beans::UnknownPropertyException, lang::NullPointerException)
    1390             : {
    1391           0 :     if ( !_rxInspectorUI.is() )
    1392           0 :         throw lang::NullPointerException();
    1393           0 :     if (PropertyName == PROPERTY_FILTER)
    1394             :     {
    1395           0 :         ::osl::ClearableMutexGuard aGuard( m_aMutex );
    1396             : 
    1397           0 :         inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
    1398           0 :         OUString sClause;
    1399           0 :         if ( impl_dialogFilter_nothrow( sClause, aGuard ) )
    1400             :         {
    1401           0 :             _rData <<= sClause;
    1402           0 :             eResult = inspection::InteractiveSelectionResult_ObtainedValue;
    1403             :         }
    1404           0 :         return eResult;
    1405             :     }
    1406           0 :     else if (PropertyName == PROPERTY_FONT)
    1407             :     {
    1408           0 :         ::osl::ClearableMutexGuard aGuard( m_aMutex );
    1409             : 
    1410           0 :         inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
    1411           0 :         const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
    1412           0 :         const uno::Reference< report::XReportControlFormat> xReportControlFormat(m_xReportComponent,uno::UNO_QUERY);
    1413           0 :         aGuard.clear();
    1414             : 
    1415           0 :         uno::Sequence< beans::NamedValue > aFontSettings;
    1416           0 :         if ( rptui::openCharDialog( xReportControlFormat, xInspectorWindow, aFontSettings ) )
    1417             :         {
    1418           0 :             _rData <<= aFontSettings;
    1419           0 :             eResult = inspection::InteractiveSelectionResult_ObtainedValue;
    1420             :         }
    1421           0 :         return eResult;
    1422             :     }
    1423           0 :     else if (      PropertyName == PROPERTY_FORMULA
    1424           0 :                 || PropertyName == PROPERTY_INITIALFORMULA
    1425           0 :                 || PropertyName == PROPERTY_DATAFIELD
    1426           0 :                 || PropertyName == PROPERTY_CONDITIONALPRINTEXPRESSION)
    1427             :     {
    1428           0 :         ::osl::ClearableMutexGuard aGuard( m_aMutex );
    1429             : 
    1430             : 
    1431           0 :         OUString sFormula;
    1432           0 :         m_xReportComponent->getPropertyValue(PropertyName) >>= sFormula;
    1433           0 :         const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
    1434           0 :         uno::Reference< uno::XComponentContext > xContext = m_xContext;
    1435           0 :         uno::Reference< beans::XPropertySet > xRowSet( m_xRowSet,uno::UNO_QUERY);
    1436           0 :         aGuard.clear();
    1437             : 
    1438           0 :         inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
    1439           0 :         if ( rptui::openDialogFormula_nothrow( sFormula, xContext,xInspectorWindow,xRowSet ) )
    1440             :         {
    1441           0 :             _rData <<= sFormula;
    1442           0 :             eResult = inspection::InteractiveSelectionResult_ObtainedValue;
    1443             :         }
    1444           0 :         return eResult;
    1445             :     }
    1446           0 :     else if (PropertyName == PROPERTY_AREA)
    1447             :     {
    1448           0 :         ::osl::ClearableMutexGuard aGuard( m_aMutex );
    1449             : 
    1450           0 :         inspection::InteractiveSelectionResult eResult = inspection::InteractiveSelectionResult_Cancelled;
    1451           0 :         const uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
    1452           0 :         const uno::Reference< report::XShape> xShape(m_xReportComponent,uno::UNO_QUERY);
    1453           0 :         aGuard.clear();
    1454             : 
    1455           0 :         if ( rptui::openAreaDialog( xShape, xInspectorWindow) )
    1456             :         {
    1457           0 :             eResult = inspection::InteractiveSelectionResult_ObtainedValue;
    1458           0 :             beans::PropertyChangeEvent aScopeEvent;
    1459           0 :             aScopeEvent.PropertyName = PROPERTY_FILLCOLOR;
    1460           0 :             aScopeEvent.NewValue <<= xShape->getPropertyValue(PROPERTY_FILLCOLOR);
    1461           0 :             m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange );
    1462             :         }
    1463           0 :         return eResult;
    1464             :     }
    1465             : 
    1466             : 
    1467           0 :     return m_xFormComponentHandler->onInteractivePropertySelection(PropertyName, Primary, _rData, _rxInspectorUI);
    1468             : }
    1469             : 
    1470           0 : void SAL_CALL GeometryHandler::actuatingPropertyChanged(const OUString & ActuatingPropertyName, const uno::Any & NewValue, const uno::Any & OldValue, const uno::Reference< inspection::XObjectInspectorUI > & _rxInspectorUI, ::sal_Bool _bFirstTimeInit) throw (uno::RuntimeException, lang::NullPointerException)
    1471             : {
    1472           0 :     if ( !_rxInspectorUI.is() )
    1473           0 :         throw lang::NullPointerException();
    1474             : 
    1475           0 :     ::osl::MutexGuard aGuard( m_aMutex );
    1476           0 :     const sal_Int32 nId = m_pInfoService->getPropertyId(ActuatingPropertyName);
    1477           0 :     switch(nId)
    1478             :     {
    1479             :         case PROPERTY_ID_TYPE:
    1480             :             {
    1481           0 :                 sal_uInt32 nNewVal = 0;
    1482           0 :                 NewValue >>= nNewVal;
    1483           0 :                 switch(nNewVal)
    1484             :                 {
    1485             :                     case DATA_OR_FORMULA:
    1486           0 :                         _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
    1487           0 :                         _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_True);
    1488           0 :                         _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,sal_False);
    1489           0 :                         _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,sal_False);
    1490             :                         OSL_ENSURE(m_sDefaultFunction.isEmpty(),"Why is the m_sDefaultFunction set?");
    1491             :                         OSL_ENSURE(m_sScope.isEmpty(),"Why is the m_sScope set?");
    1492           0 :                         break;
    1493             :                     case FUNCTION:
    1494           0 :                         _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
    1495           0 :                         _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
    1496           0 :                         _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_True);
    1497           0 :                         _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,!m_sDefaultFunction.isEmpty());
    1498           0 :                         _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,!m_sScope.isEmpty());
    1499           0 :                         break;
    1500             :                     case USER_DEF_FUNCTION:
    1501           0 :                         _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_False);
    1502           0 :                         _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,sal_True);
    1503           0 :                         _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
    1504           0 :                         _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,sal_False);
    1505           0 :                         break;
    1506             :                     case COUNTER:
    1507           0 :                         _rxInspectorUI->enablePropertyUI(PROPERTY_DATAFIELD,sal_False);
    1508           0 :                         _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,sal_False);
    1509           0 :                         _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,sal_True);
    1510           0 :                         break;
    1511             :                 }
    1512             :             }
    1513           0 :             break;
    1514             :         case PROPERTY_ID_DATAFIELD:
    1515             :             {
    1516           0 :                 sal_Bool bEnable = (m_nDataFieldType != DATA_OR_FORMULA && m_nDataFieldType != COUNTER );
    1517           0 :                 if ( bEnable )
    1518             :                 {
    1519           0 :                     OUString sValue;
    1520           0 :                     m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD ) >>= sValue;
    1521           0 :                     bEnable = !sValue.isEmpty();
    1522             :                 }
    1523           0 :                 _rxInspectorUI->enablePropertyUI(PROPERTY_FORMULALIST,bEnable);
    1524           0 :                 if ( bEnable )
    1525             :                 {
    1526           0 :                     _rxInspectorUI->rebuildPropertyUI(PROPERTY_DATAFIELD);
    1527           0 :                     _rxInspectorUI->rebuildPropertyUI(PROPERTY_FORMULALIST);
    1528             :                 }
    1529           0 :                 m_xFormComponentHandler->actuatingPropertyChanged(ActuatingPropertyName, NewValue, OldValue, _rxInspectorUI, _bFirstTimeInit);
    1530             :             }
    1531           0 :             break;
    1532             :         case PROPERTY_ID_FORMULALIST:
    1533             :             {
    1534           0 :                 _rxInspectorUI->enablePropertyUI(PROPERTY_SCOPE,m_nDataFieldType == FUNCTION || m_nDataFieldType == COUNTER);
    1535             :             }
    1536           0 :             break;
    1537             :         case PROPERTY_ID_BACKTRANSPARENT:
    1538             :         case PROPERTY_ID_CONTROLBACKGROUNDTRANSPARENT:
    1539             :             {
    1540           0 :                 sal_Bool bValue = sal_False;
    1541           0 :                 NewValue >>= bValue;
    1542           0 :                 bValue = !bValue;
    1543           0 :                 _rxInspectorUI->enablePropertyUI(PROPERTY_BACKCOLOR,bValue);
    1544           0 :                 _rxInspectorUI->enablePropertyUI(PROPERTY_CONTROLBACKGROUND,bValue);
    1545             :             }
    1546           0 :             break;
    1547             :         default:
    1548           0 :             m_xFormComponentHandler->actuatingPropertyChanged(ActuatingPropertyName, NewValue, OldValue, _rxInspectorUI, _bFirstTimeInit);
    1549           0 :             break;
    1550           0 :     }
    1551           0 : }
    1552             : 
    1553           0 : ::sal_Bool SAL_CALL GeometryHandler::suspend(::sal_Bool Suspend) throw (uno::RuntimeException)
    1554             : {
    1555           0 :     return m_xFormComponentHandler->suspend(Suspend);
    1556             : }
    1557             : // -----------------------------------------------------------------------------
    1558           0 : bool GeometryHandler::impl_dialogFilter_nothrow( OUString& _out_rSelectedClause, ::osl::ClearableMutexGuard& _rClearBeforeDialog ) const
    1559             : {
    1560           0 :     _out_rSelectedClause = OUString();
    1561           0 :     bool bSuccess = false;
    1562           0 :     ::dbtools::SQLExceptionInfo aErrorInfo;
    1563           0 :     uno::Reference< awt::XWindow > xInspectorWindow;
    1564           0 :     uno::Reference< lang::XMultiComponentFactory > xFactory;
    1565             :     try
    1566             :     {
    1567           0 :         xFactory = m_xContext->getServiceManager();
    1568           0 :         xInspectorWindow.set(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
    1569           0 :         uno::Reference<sdbc::XConnection> xCon(m_xContext->getValueByName("ActiveConnection") ,uno::UNO_QUERY);
    1570           0 :         if ( !xCon.is() )
    1571           0 :             return false;
    1572             : 
    1573           0 :         uno::Reference< beans::XPropertySet> xRowSetProp(m_xRowSet,uno::UNO_QUERY);
    1574           0 :         if ( !m_xRowSet.is() )
    1575             :         {
    1576           0 :             m_xRowSet.set(xFactory->createInstanceWithContext("com.sun.star.sdb.RowSet",m_xContext),uno::UNO_QUERY);
    1577           0 :             xRowSetProp.set(m_xRowSet,uno::UNO_QUERY);
    1578           0 :             xRowSetProp->setPropertyValue(PROPERTY_ACTIVECONNECTION,uno::makeAny(xCon));
    1579           0 :             ::comphelper::copyProperties(m_xReportComponent,xRowSetProp);
    1580             :         }
    1581             : 
    1582             :         // get a composer for the statement which the form is currently based on
    1583           0 :         uno::Reference< sdb::XSingleSelectQueryComposer > xComposer( ::dbtools::getCurrentSettingsComposer( xRowSetProp, m_xContext ) );
    1584             :         OSL_ENSURE( xComposer.is(), "GeometryHandler::impl_dialogFilter_nothrow: could not obtain a composer!" );
    1585           0 :         if ( !xComposer.is() )
    1586           0 :             return false;
    1587             : 
    1588             :         // create the dialog
    1589           0 :         uno::Reference< ui::dialogs::XExecutableDialog > xDialog = sdb::FilterDialog::createWithQuery(m_xContext, xComposer, m_xRowSet, xInspectorWindow);
    1590             : 
    1591           0 :         const String aGcc3WorkaroundTemporary( ModuleRes(RID_STR_FILTER));
    1592           0 :         const OUString sPropertyUIName( aGcc3WorkaroundTemporary );
    1593             :         // initialize the dialog
    1594           0 :         xDialog->setTitle( sPropertyUIName );
    1595             : 
    1596           0 :         _rClearBeforeDialog.clear();
    1597           0 :         bSuccess = ( xDialog->execute() != 0 );
    1598           0 :         if ( bSuccess )
    1599           0 :             _out_rSelectedClause = xComposer->getFilter();
    1600             :     }
    1601           0 :     catch (const sdb::SQLContext& e) { aErrorInfo = e; }
    1602           0 :     catch (const sdbc::SQLWarning& e) { aErrorInfo = e; }
    1603           0 :     catch (const sdbc::SQLException& e) { aErrorInfo = e; }
    1604           0 :     catch( const uno::Exception& )
    1605             :     {
    1606             :         OSL_FAIL( "GeometryHandler::impl_dialogFilter_nothrow: caught an exception!" );
    1607             :     }
    1608             : 
    1609           0 :     if ( aErrorInfo.isValid() )
    1610           0 :         ::dbtools::showError( aErrorInfo, xInspectorWindow, m_xContext );
    1611             : 
    1612           0 :     return bSuccess;
    1613             : }
    1614             : // -----------------------------------------------------------------------------
    1615           0 : void GeometryHandler::checkPosAndSize(  const awt::Point& _aNewPos,
    1616             :                                     const awt::Size& _aSize)
    1617             : {
    1618           0 :     const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY);
    1619           0 :     const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY);
    1620           0 :     if ( !xSection.is() || uno::Reference< report::XShape>(xSourceReportComponent,uno::UNO_QUERY).is() ) // shapes can overlap.
    1621           0 :         return;
    1622             : 
    1623           0 :     ::Point aPos(VCLPoint(_aNewPos));
    1624           0 :     if ( aPos.X() < 0 || aPos.Y() < 0 ) // TODO: have to check size with pos aka || (aPos.X() + aAwtSize.Width) > m_xSection->getReportDefinition()->
    1625           0 :         throw beans::PropertyVetoException(String(ModuleRes(RID_STR_ILLEGAL_POSITION)),xSourceReportComponent);
    1626             : 
    1627           0 :     ::Rectangle aSourceRect(aPos,VCLSize(_aSize));
    1628             : 
    1629           0 :     const sal_Int32 nCount = xSection->getCount();
    1630           0 :     for (sal_Int32 i = 0; i < nCount ; ++i)
    1631             :     {
    1632           0 :         const uno::Reference< report::XReportComponent> xReportComponent(xSection->getByIndex(i),uno::UNO_QUERY);
    1633           0 :         if ( xReportComponent.is() && xReportComponent != xSourceReportComponent )
    1634             :         {
    1635           0 :             const ::Rectangle aBoundRect(VCLPoint(xReportComponent->getPosition()),VCLSize(xReportComponent->getSize()));
    1636           0 :             const ::Rectangle aRect = aSourceRect.GetIntersection(aBoundRect);
    1637           0 :             if ( !aRect.IsEmpty() && (aRect.Left() != aRect.Right() && aRect.Top() != aRect.Bottom() ) )
    1638           0 :                 throw beans::PropertyVetoException(String(ModuleRes( RID_STR_OVERLAP_OTHER_CONTROL)),xSourceReportComponent);
    1639             :         }
    1640           0 :     }
    1641             : }
    1642             : // -----------------------------------------------------------------------------
    1643           0 : void GeometryHandler::impl_fillFormulaList_nothrow(::std::vector< OUString >& _out_rList) const
    1644             : {
    1645           0 :     if ( m_nDataFieldType == FUNCTION )
    1646           0 :         ::std::transform(m_aDefaultFunctions.begin(),m_aDefaultFunctions.end(),::std::back_inserter(_out_rList),::boost::bind( &DefaultFunction::getName, _1 ));
    1647           0 :     else if ( m_nDataFieldType == USER_DEF_FUNCTION )
    1648           0 :         ::std::transform(m_aFunctionNames.begin(),m_aFunctionNames.end(),::std::back_inserter(_out_rList),::o3tl::select1st<TFunctions::value_type>());
    1649           0 : }
    1650             : // -----------------------------------------------------------------------------
    1651           0 : OUString GeometryHandler::impl_ConvertUIToMimeType_nothrow(const OUString& _sUIName) const
    1652             : {
    1653           0 :     ::std::vector< OUString > aList;
    1654           0 :     impl_fillMimeTypes_nothrow(aList);
    1655           0 :     OUString sRet;
    1656           0 :     ::std::vector< OUString >::const_iterator aFind = ::std::find(aList.begin(),aList.end(),_sUIName);
    1657           0 :     if ( aFind != aList.end() )
    1658             :     {
    1659           0 :         const sal_Size nPos = aFind - aList.begin();
    1660           0 :         const uno::Reference< report::XReportDefinition> xReportDefinition(m_xReportComponent,uno::UNO_QUERY);
    1661           0 :         if ( xReportDefinition.is() )
    1662             :         {
    1663           0 :             const uno::Sequence< OUString > aMimeTypes( xReportDefinition->getAvailableMimeTypes() );
    1664           0 :             sRet = aMimeTypes[nPos];
    1665           0 :         }
    1666             :     }
    1667           0 :     return sRet;
    1668             : }
    1669             : // -----------------------------------------------------------------------------
    1670           0 : OUString GeometryHandler::impl_ConvertMimeTypeToUI_nothrow(const OUString& _sMimetype) const
    1671             : {
    1672           0 :     ::comphelper::MimeConfigurationHelper aMimeHelper(m_xContext);
    1673           0 :     OUString sRet;
    1674           0 :     const SfxFilter* pFilter = SfxFilter::GetDefaultFilter( aMimeHelper.GetDocServiceNameFromMediaType(_sMimetype) );
    1675           0 :     if ( pFilter )
    1676           0 :         sRet = pFilter->GetUIName();
    1677           0 :     if ( sRet.isEmpty() )
    1678           0 :         sRet = _sMimetype;
    1679           0 :     return sRet;
    1680             : }
    1681             : // -----------------------------------------------------------------------------
    1682           0 : void GeometryHandler::impl_fillMimeTypes_nothrow(::std::vector< OUString >& _out_rList) const
    1683             : {
    1684             :     try
    1685             :     {
    1686           0 :         const uno::Reference< report::XReportDefinition> xReportDefinition(m_xReportComponent,uno::UNO_QUERY);
    1687           0 :         if ( xReportDefinition.is() )
    1688             :         {
    1689           0 :             uno::Sequence< OUString > aMimeTypes( xReportDefinition->getAvailableMimeTypes() );
    1690           0 :             const OUString* pIter = aMimeTypes.getConstArray();
    1691           0 :             const OUString* pEnd  = pIter + aMimeTypes.getLength();
    1692           0 :             for(;pIter != pEnd; ++pIter)
    1693             :             {
    1694           0 :                 const OUString sDocName( impl_ConvertMimeTypeToUI_nothrow(*pIter) );
    1695           0 :                 if ( !sDocName.isEmpty() )
    1696           0 :                     _out_rList.push_back(sDocName);
    1697           0 :             }
    1698           0 :         }
    1699             :     }
    1700           0 :     catch(uno::Exception&)
    1701             :     {
    1702             :         OSL_FAIL("Exception caught!");
    1703             :     }
    1704           0 : }
    1705             : // -----------------------------------------------------------------------------
    1706           0 : void GeometryHandler::impl_fillScopeList_nothrow(::std::vector< OUString >& _out_rList) const
    1707             : {
    1708             :     try
    1709             :     {
    1710           0 :         const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
    1711           0 :         const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
    1712             : 
    1713           0 :         const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
    1714           0 :         const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
    1715           0 :         sal_Int32 nPos = -1;
    1716           0 :         uno::Reference< report::XGroup> xGroup = xSection->getGroup();
    1717           0 :         if ( xGroup.is() )
    1718           0 :             nPos = getPositionInIndexAccess(xGroups.get(),xGroup);
    1719           0 :         else if ( xSection == xReportDefinition->getDetail() )
    1720           0 :             nPos = xGroups->getCount()-1;
    1721             : 
    1722           0 :         const String sGroup = String(ModuleRes(RID_STR_SCOPE_GROUP));
    1723           0 :         for (sal_Int32 i = 0 ; i <= nPos ; ++i)
    1724             :         {
    1725           0 :             xGroup.set(xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
    1726           0 :             String sGroupName = sGroup;
    1727           0 :             sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression());
    1728           0 :             _out_rList.push_back(sGroupName);
    1729           0 :         }
    1730           0 :         _out_rList.push_back(xReportDefinition->getName());
    1731             :     }
    1732           0 :     catch(uno::Exception&)
    1733             :     {
    1734             :         OSL_FAIL("Exception caught!");
    1735             :     }
    1736           0 : }
    1737             : // -----------------------------------------------------------------------------
    1738           0 : uno::Reference< report::XFunctionsSupplier> GeometryHandler::fillScope_throw(OUString& _rsNamePostFix)
    1739             : {
    1740           0 :     uno::Reference< report::XFunctionsSupplier> xReturn;
    1741             : 
    1742           0 :     const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
    1743           0 :     const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
    1744           0 :     const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
    1745           0 :     if ( m_sScope.isEmpty() )
    1746             :     {
    1747           0 :         const uno::Reference< report::XGroup> xGroup(xSection->getGroup(),uno::UNO_QUERY);
    1748           0 :         if ( xGroup.is() )
    1749             :         {
    1750           0 :             String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
    1751           0 :             _rsNamePostFix = xGroup->getExpression();
    1752           0 :             sGroupName.SearchAndReplaceAscii("%1",_rsNamePostFix);
    1753           0 :             m_sScope = sGroupName;
    1754           0 :             xReturn = xGroup.get();
    1755             :         }
    1756           0 :         else if ( xSection == xReportDefinition->getDetail() )
    1757             :         {
    1758           0 :             const uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
    1759           0 :             const sal_Int32 nCount = xGroups->getCount();
    1760           0 :             if ( nCount )
    1761             :             {
    1762           0 :                 const uno::Reference< report::XGroup> xGroup2(xGroups->getByIndex(nCount - 1),uno::UNO_QUERY_THROW);
    1763           0 :                 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
    1764           0 :                 _rsNamePostFix = xGroup2->getExpression();
    1765           0 :                 sGroupName.SearchAndReplaceAscii("%1",_rsNamePostFix);
    1766           0 :                 m_sScope = sGroupName;
    1767           0 :                 xReturn = xGroup2.get();
    1768           0 :             }
    1769             :         }
    1770           0 :         if ( m_sScope.isEmpty() )
    1771             :         {
    1772           0 :             xReturn = xReportDefinition.get();
    1773           0 :             _rsNamePostFix = m_sScope = xReportDefinition->getName();
    1774           0 :         }
    1775             :     }
    1776           0 :     else if ( m_sScope == xReportDefinition->getName() )
    1777             :     {
    1778           0 :         xReturn = xReportDefinition.get();
    1779           0 :         _rsNamePostFix = m_sScope;
    1780             :     }
    1781             :     else
    1782             :     {
    1783           0 :         uno::Reference< report::XGroups> xGroups = xReportDefinition->getGroups();
    1784           0 :         const sal_Int32 nCount = xGroups->getCount();
    1785             : 
    1786           0 :         for (sal_Int32 i = 0 ; i < nCount; ++i)
    1787             :         {
    1788           0 :             const uno::Reference< report::XGroup> xGroup(xGroups->getByIndex(i),uno::UNO_QUERY_THROW);
    1789           0 :             String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
    1790           0 :             sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression());
    1791           0 :             if ( m_sScope == OUString(sGroupName) )
    1792             :             {
    1793           0 :                 _rsNamePostFix = xGroup->getExpression();
    1794           0 :                 xReturn = xGroup.get();
    1795           0 :                 break;
    1796             :             }
    1797           0 :         }
    1798             : 
    1799             :     }
    1800             :     OSL_ENSURE(xReturn.is(),"Why don't we have a functionssupplier here!");
    1801             : 
    1802           0 :     return xReturn;
    1803             : }
    1804             : // -----------------------------------------------------------------------------
    1805           0 : sal_Bool GeometryHandler::isDefaultFunction( const OUString& _sQuotedFunction
    1806             :                                             ,OUString& _rDataField
    1807             :                                             ,const uno::Reference< report::XFunctionsSupplier>& _xFunctionsSupplier
    1808             :                                             ,bool _bSet) const
    1809             : {
    1810           0 :     sal_Bool bDefaultFunction = sal_False;
    1811             :     try
    1812             :     {
    1813           0 :         const uno::Reference< report::XReportComponent> xSourceReportComponent(m_xReportComponent,uno::UNO_QUERY_THROW);
    1814           0 :         const uno::Reference< report::XSection> xSection(xSourceReportComponent->getParent(),uno::UNO_QUERY_THROW);
    1815           0 :         const uno::Reference< report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
    1816             : 
    1817           0 :         ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(_sQuotedFunction);
    1818           0 :         while ( aFind.first != aFind.second )
    1819             :         {
    1820           0 :             if ( !_xFunctionsSupplier.is() || _xFunctionsSupplier == aFind.first->second.second )
    1821             :             {
    1822           0 :                 const beans::Optional< OUString> aInitalFormula = aFind.first->second.first->getInitialFormula();
    1823           0 :                 if ( aInitalFormula.IsPresent )
    1824             :                 {
    1825           0 :                     OUString sDefaultFunctionName;
    1826           0 :                     bDefaultFunction = impl_isDefaultFunction_nothrow(aFind.first->second.first,_rDataField,sDefaultFunctionName);
    1827           0 :                     if ( bDefaultFunction )
    1828             :                     {
    1829           0 :                         m_xFunction = aFind.first->second.first;
    1830           0 :                         if ( _bSet )
    1831             :                         {
    1832           0 :                             m_sDefaultFunction = sDefaultFunctionName;
    1833           0 :                             uno::Reference< report::XGroup> xGroup(aFind.first->second.second,uno::UNO_QUERY);
    1834           0 :                             if ( xGroup.is() )
    1835             :                             {
    1836           0 :                                 String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
    1837           0 :                                 sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression());
    1838           0 :                                 m_sScope = sGroupName;
    1839             :                             }
    1840             :                             else
    1841           0 :                                 m_sScope = xReportDefinition->getName();
    1842             :                         }
    1843             :                     }
    1844           0 :                     break;
    1845           0 :                 }
    1846             :             }
    1847           0 :             ++(aFind.first);
    1848           0 :         }
    1849             :     }
    1850           0 :     catch(uno::Exception&)
    1851             :     {
    1852             :         OSL_FAIL("Exception caught!");
    1853             :     }
    1854           0 :     return bDefaultFunction;
    1855             : }
    1856             : // -----------------------------------------------------------------------------
    1857           0 : sal_Bool GeometryHandler::impl_isDefaultFunction_nothrow( const uno::Reference< report::XFunction>& _xFunction
    1858             :                                             ,OUString& _rDataField
    1859             :                                             ,OUString& _rsDefaultFunctionName) const
    1860             : {
    1861           0 :     sal_Bool bDefaultFunction = sal_False;
    1862             :     try
    1863             :     {
    1864           0 :         const String sFormula( _xFunction->getFormula() );
    1865           0 :         util::SearchOptions aSearchOptions;
    1866           0 :         aSearchOptions.algorithmType = util::SearchAlgorithms_REGEXP;
    1867           0 :         aSearchOptions.searchFlag = 0x00000100;
    1868           0 :         ::std::vector< DefaultFunction >::const_iterator aIter = m_aDefaultFunctions.begin();
    1869           0 :         ::std::vector< DefaultFunction >::const_iterator aDeEnd = m_aDefaultFunctions.end();
    1870           0 :         for (; aIter != aDeEnd; ++aIter)
    1871             :         {
    1872           0 :             aSearchOptions.searchString = aIter->m_sSearchString;
    1873           0 :             utl::TextSearch aTextSearch(aSearchOptions);
    1874           0 :             sal_Int32 start = 0;
    1875           0 :             sal_Int32 end = sFormula.Len();
    1876           0 :             if ( aTextSearch.SearchForward(sFormula,&start,&end) && start == 0 && end == sFormula.Len()) // default function found
    1877             :             {
    1878           0 :                 aSearchOptions.searchString = OUString("\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]");
    1879           0 :                 utl::TextSearch aDataSearch(aSearchOptions);
    1880           0 :                 aDataSearch.SearchForward(sFormula,&start,&end );
    1881           0 :                 ++start;
    1882           0 :                 _rDataField = sFormula.Copy(start,end-start-1);
    1883           0 :                 _rsDefaultFunctionName = aIter->m_sName;
    1884           0 :                 break;
    1885             :             }
    1886           0 :         }
    1887             : 
    1888           0 :         bDefaultFunction = aIter != aDeEnd;
    1889             :     }
    1890           0 :     catch(uno::Exception&)
    1891             :     {
    1892             :         OSL_FAIL("Exception caught!");
    1893             :     }
    1894           0 :     return bDefaultFunction;
    1895             : }
    1896             : // -----------------------------------------------------------------------------
    1897           0 : void GeometryHandler::loadDefaultFunctions()
    1898             : {
    1899           0 :     if ( m_aDefaultFunctions.empty() )
    1900             :     {
    1901           0 :         m_aCounterFunction.m_bPreEvaluated = sal_False;
    1902           0 :         m_aCounterFunction.m_bDeepTraversing = sal_False;
    1903           0 :         m_aCounterFunction.m_sName = String(ModuleRes(RID_STR_F_COUNTER));
    1904           0 :         m_aCounterFunction.m_sFormula = OUString("rpt:[%FunctionName] + 1");
    1905           0 :         m_aCounterFunction.m_sSearchString = OUString("rpt:\\[[:alpha:]+([:space:]*[:alnum:]*)*\\][:space:]*\\+[:space:]*[:digit:]*");
    1906           0 :         m_aCounterFunction.m_sInitialFormula.IsPresent = sal_True;
    1907           0 :         m_aCounterFunction.m_sInitialFormula.Value = OUString("rpt:1");
    1908             : 
    1909           0 :         DefaultFunction aDefault;
    1910           0 :         aDefault.m_bDeepTraversing = sal_False;
    1911             : 
    1912           0 :         aDefault.m_bPreEvaluated = sal_True;
    1913             : 
    1914           0 :         aDefault.m_sName = String(ModuleRes(RID_STR_F_ACCUMULATION));
    1915           0 :         aDefault.m_sFormula = OUString("rpt:[%Column] + [%FunctionName]");
    1916           0 :         aDefault.m_sSearchString = OUString("rpt:\\[[:alpha:]+([:space:]*[:alnum:]*)*\\][:space:]*\\+[:space:]*\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]");
    1917           0 :         aDefault.m_sInitialFormula.IsPresent = sal_True;
    1918           0 :         aDefault.m_sInitialFormula.Value = OUString("rpt:[%Column]");
    1919           0 :         m_aDefaultFunctions.push_back(aDefault);
    1920             : 
    1921           0 :         aDefault.m_sName = String(ModuleRes(RID_STR_F_MINIMUM));
    1922           0 :         aDefault.m_sFormula = OUString("rpt:IF([%Column] < [%FunctionName];[%Column];[%FunctionName])");
    1923           0 :         aDefault.m_sSearchString = OUString("rpt:IF\\((\\[[:alpha:]+([:space:]*[:alnum:]*)*\\])[:space:]*<[:space:]*(\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]);[:space:]*\\1[:space:]*;[:space:]*\\3[:space:]*\\)");
    1924           0 :         aDefault.m_sInitialFormula.IsPresent = sal_True;
    1925           0 :         aDefault.m_sInitialFormula.Value = OUString("rpt:[%Column]");
    1926           0 :         m_aDefaultFunctions.push_back(aDefault);
    1927             : 
    1928           0 :         aDefault.m_sName = String(ModuleRes(RID_STR_F_MAXIMUM));
    1929           0 :         aDefault.m_sFormula = OUString("rpt:IF([%Column] > [%FunctionName];[%Column];[%FunctionName])");
    1930           0 :         aDefault.m_sSearchString = OUString("rpt:IF\\((\\[[:alpha:]+([:space:]*[:alnum:]*)*\\])[:space:]*>[:space:]*(\\[[:alpha:]+([:space:]*[:alnum:]*)*\\]);[:space:]*\\1[:space:]*;[:space:]*\\3[:space:]*\\)");
    1931           0 :         aDefault.m_sInitialFormula.IsPresent = sal_True;
    1932           0 :         aDefault.m_sInitialFormula.Value = OUString("rpt:[%Column]");
    1933           0 :         m_aDefaultFunctions.push_back(aDefault);
    1934             :     }
    1935           0 : }
    1936             : // -----------------------------------------------------------------------------
    1937           0 : void GeometryHandler::createDefaultFunction(::osl::ResettableMutexGuard& _aGuard ,const OUString& _sFunction,const OUString& _sDataField)
    1938             : {
    1939             :     try
    1940             :     {
    1941           0 :         OUString sNamePostFix;
    1942           0 :         const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix);
    1943             : 
    1944           0 :         ::std::vector< DefaultFunction >::const_iterator aIter = m_aDefaultFunctions.begin();
    1945           0 :         ::std::vector< DefaultFunction >::const_iterator aDeEnd = m_aDefaultFunctions.end();
    1946           0 :         for (; aIter != aDeEnd; ++aIter)
    1947             :         {
    1948           0 :             if ( aIter->m_sName == _sFunction )
    1949             :             {
    1950           0 :                 const OUString sFunctionName( _sFunction + _sDataField + sNamePostFix);
    1951           0 :                 const OUString sQuotedFunctionName(lcl_getQuotedFunctionName(sFunctionName));
    1952             : 
    1953           0 :                 beans::PropertyChangeEvent aEvent;
    1954           0 :                 aEvent.PropertyName = PROPERTY_SCOPE;
    1955           0 :                 aEvent.OldValue <<= m_sScope;
    1956             : 
    1957           0 :                 ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(sQuotedFunctionName);
    1958           0 :                 while ( aFind.first != aFind.second )
    1959             :                 {
    1960           0 :                     if ( xFunctionsSupplier == aFind.first->second.second )
    1961             :                     {
    1962           0 :                         m_xFunction = aFind.first->second.first;
    1963           0 :                         OUString sTemp;
    1964           0 :                         isDefaultFunction(sQuotedFunctionName,sTemp,uno::Reference< report::XFunctionsSupplier>(),true); // implicitly sets the m_sScope
    1965           0 :                         break;
    1966             :                     }
    1967           0 :                     ++(aFind.first);
    1968             :                 }
    1969           0 :                 if ( aFind.first == aFind.second )
    1970           0 :                     impl_createFunction(sFunctionName,_sDataField,*aIter);
    1971             : 
    1972           0 :                 OBlocker aBlocker(m_bIn);
    1973           0 :                 m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny( impl_convertToFormula( uno::makeAny(sQuotedFunctionName) )));
    1974           0 :                 aEvent.NewValue <<= m_sScope;
    1975           0 :                 _aGuard.clear();
    1976           0 :                 m_aPropertyListeners.notify( aEvent, &beans::XPropertyChangeListener::propertyChange );
    1977           0 :                 break;
    1978             :             }
    1979           0 :         }
    1980             :     }
    1981           0 :     catch(uno::Exception&)
    1982             :     {
    1983             :         OSL_FAIL("Exception caught!");
    1984             :     }
    1985           0 : }
    1986             : // -----------------------------------------------------------------------------
    1987           0 : void GeometryHandler::removeFunction()
    1988             : {
    1989           0 :     if ( m_xFunction.is() )
    1990             :     {
    1991           0 :         const OUString sQuotedFunctionName(lcl_getQuotedFunctionName(m_xFunction));
    1992           0 :         ::std::pair<TFunctions::iterator,TFunctions::iterator> aFind = m_aFunctionNames.equal_range(sQuotedFunctionName);
    1993           0 :         while ( aFind.first != aFind.second )
    1994             :         {
    1995           0 :             if ( aFind.first->second.first == m_xFunction )
    1996             :             {
    1997           0 :                 uno::Reference< report::XFunctions> xFunctions = aFind.first->second.second->getFunctions();
    1998           0 :                 xFunctions->removeByIndex(xFunctions->getCount() - 1 ); /// TODO: insert new method in XFunctions: removeFunction(xfunction)
    1999           0 :                 m_aFunctionNames.erase(aFind.first);
    2000           0 :                 m_bNewFunction = false;
    2001           0 :                 break;
    2002             :             }
    2003           0 :             ++(aFind.first);
    2004           0 :         }
    2005             :     }
    2006           0 : }
    2007             : // -----------------------------------------------------------------------------
    2008           0 : void GeometryHandler::resetOwnProperties(::osl::ResettableMutexGuard& _aGuard,const OUString& _sOldFunctionName,const OUString& _sOldScope,const sal_uInt32 _nOldDataFieldType)
    2009             : {
    2010           0 :     const OUString sNewFunction = m_sDefaultFunction;
    2011           0 :     const OUString sNewScope = m_sScope;
    2012           0 :     const sal_uInt32 nNewDataFieldType = m_nDataFieldType;
    2013           0 :     _aGuard.clear();
    2014           0 :     if ( _nOldDataFieldType != nNewDataFieldType )
    2015             :     {
    2016           0 :         beans::PropertyChangeEvent aScopeEvent;
    2017           0 :         aScopeEvent.PropertyName = PROPERTY_TYPE;
    2018           0 :         aScopeEvent.OldValue <<= _nOldDataFieldType;
    2019           0 :         aScopeEvent.NewValue <<= nNewDataFieldType;
    2020           0 :         m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange );
    2021             :     }
    2022           0 :     if ( _sOldFunctionName != sNewFunction )
    2023             :     {
    2024           0 :         beans::PropertyChangeEvent aFormulaEvent;
    2025           0 :         aFormulaEvent.PropertyName = PROPERTY_FORMULALIST;
    2026           0 :         aFormulaEvent.OldValue <<= _sOldFunctionName;
    2027           0 :         aFormulaEvent.NewValue <<= sNewFunction;
    2028             : 
    2029           0 :         m_aPropertyListeners.notify( aFormulaEvent, &beans::XPropertyChangeListener::propertyChange );
    2030             :     }
    2031           0 :     if ( _sOldScope != sNewScope )
    2032             :     {
    2033           0 :         beans::PropertyChangeEvent aScopeEvent;
    2034           0 :         aScopeEvent.PropertyName = PROPERTY_SCOPE;
    2035           0 :         aScopeEvent.OldValue <<= _sOldScope;
    2036           0 :         aScopeEvent.NewValue <<= sNewScope;
    2037           0 :         m_aPropertyListeners.notify( aScopeEvent, &beans::XPropertyChangeListener::propertyChange );
    2038             :     }
    2039             : 
    2040           0 :     _aGuard.reset();
    2041           0 : }
    2042             : //------------------------------------------------------------------------
    2043           0 : void GeometryHandler::impl_initFieldList_nothrow( uno::Sequence< OUString >& _rFieldNames ) const
    2044             : {
    2045           0 :     _rFieldNames.realloc(0);
    2046             :     try
    2047             :     {
    2048           0 :         uno::Reference< awt::XWindow> xInspectorWindow(m_xContext->getValueByName("DialogParentWindow") ,uno::UNO_QUERY);
    2049           0 :         Window* pInspectorWindow = VCLUnoHelper::GetWindow( xInspectorWindow );
    2050           0 :         WaitObject aWaitCursor( pInspectorWindow );
    2051             : 
    2052           0 :         uno::Reference< sdbc::XPreparedStatement >  xStatement;
    2053             : 
    2054             :         // get the form of the control we're inspecting
    2055           0 :         uno::Reference< beans::XPropertySet > xFormSet( m_xRowSet, uno::UNO_QUERY );
    2056           0 :         if ( !xFormSet.is() )
    2057           0 :             return;
    2058             : 
    2059           0 :         OUString sObjectName;
    2060           0 :         OSL_VERIFY( xFormSet->getPropertyValue( PROPERTY_COMMAND ) >>= sObjectName );
    2061             :         // when there is no command we don't need to ask for columns
    2062           0 :         uno::Reference<sdbc::XConnection> xCon(m_xContext->getValueByName("ActiveConnection") ,uno::UNO_QUERY);
    2063           0 :         if ( !sObjectName.isEmpty() && xCon.is() )
    2064             :         {
    2065           0 :             sal_Int32 nObjectType = sdb::CommandType::COMMAND;
    2066           0 :             OSL_VERIFY( xFormSet->getPropertyValue( PROPERTY_COMMANDTYPE ) >>= nObjectType );
    2067             : 
    2068           0 :             _rFieldNames = ::dbtools::getFieldNamesByCommandDescriptor( xCon, nObjectType, sObjectName );
    2069           0 :         }
    2070             :     }
    2071           0 :     catch (uno::Exception&)
    2072             :     {
    2073             :         OSL_FAIL( "GeometryHandler::impl_initFieldList_nothrow: caught an exception!" );
    2074             :     }
    2075             : }
    2076             : // -----------------------------------------------------------------------------
    2077           0 : bool GeometryHandler::impl_isCounterFunction_throw(const OUString& _sQuotedFunctionName,OUString& _Out_sScope) const
    2078             : {
    2079           0 :     ::std::pair<TFunctions::const_iterator,TFunctions::const_iterator> aFind = m_aFunctionNames.equal_range(_sQuotedFunctionName);
    2080           0 :     while ( aFind.first != aFind.second )
    2081             :     {
    2082           0 :         const beans::Optional< OUString> aInitalFormula = aFind.first->second.first->getInitialFormula();
    2083           0 :         if ( aInitalFormula.IsPresent )
    2084             :         {
    2085           0 :             const String sFormula( aFind.first->second.first->getFormula() );
    2086           0 :             util::SearchOptions aSearchOptions;
    2087           0 :             aSearchOptions.algorithmType = util::SearchAlgorithms_REGEXP;
    2088           0 :             aSearchOptions.searchFlag = 0x00000100;
    2089           0 :             aSearchOptions.searchString = m_aCounterFunction.m_sSearchString;
    2090           0 :             utl::TextSearch aTextSearch(aSearchOptions);
    2091           0 :             sal_Int32 start = 0;
    2092           0 :             sal_Int32 end = sFormula.Len();
    2093           0 :             if ( aTextSearch.SearchForward(sFormula,&start,&end) && start == 0 && end == sFormula.Len()) // counter function found
    2094             :             {
    2095           0 :                 const uno::Reference< report::XGroup > xGroup(aFind.first->second.second,uno::UNO_QUERY);
    2096           0 :                 if ( xGroup.is() )
    2097             :                 {
    2098           0 :                     String sGroupName = String(ModuleRes(RID_STR_SCOPE_GROUP));
    2099           0 :                     sGroupName.SearchAndReplaceAscii("%1",xGroup->getExpression());
    2100           0 :                     _Out_sScope = sGroupName;
    2101             :                 }
    2102             :                 else
    2103           0 :                     _Out_sScope = uno::Reference< report::XReportDefinition >(aFind.first->second.second,uno::UNO_QUERY_THROW)->getName();
    2104           0 :                 break;
    2105           0 :             }
    2106             :         }
    2107           0 :         ++(aFind.first);
    2108           0 :     }
    2109           0 :     return aFind.first != aFind.second;
    2110             : }
    2111             : // -----------------------------------------------------------------------------
    2112           0 : void GeometryHandler::impl_createFunction(const OUString& _sFunctionName,const OUString& _sDataField,const DefaultFunction& _aFunction)
    2113             : {
    2114           0 :     if ( m_bNewFunction )
    2115           0 :         removeFunction();
    2116             : 
    2117           0 :     const OUString sQuotedFunctionName(lcl_getQuotedFunctionName(_sFunctionName));
    2118           0 :     m_xFunction.set(report::Function::create(m_xContext));
    2119           0 :     m_xFunction->setName( _sFunctionName );
    2120             : 
    2121           0 :     const String sPlaceHolder1(RTL_CONSTASCII_USTRINGPARAM("%Column"));
    2122           0 :     const String sPlaceHolder2(RTL_CONSTASCII_USTRINGPARAM("%FunctionName"));
    2123           0 :     String sFormula(_aFunction.m_sFormula);
    2124           0 :     sFormula.SearchAndReplaceAll(sPlaceHolder1,_sDataField);
    2125           0 :     sFormula.SearchAndReplaceAll(sPlaceHolder2,_sFunctionName);
    2126             : 
    2127           0 :     m_xFunction->setFormula(sFormula);
    2128           0 :     m_xFunction->setPreEvaluated(_aFunction.m_bPreEvaluated);
    2129           0 :     m_xFunction->setDeepTraversing(_aFunction.m_bDeepTraversing);
    2130           0 :     if ( _aFunction.m_sInitialFormula.IsPresent )
    2131             :     {
    2132           0 :         beans::Optional< OUString> aInitialFormula = _aFunction.m_sInitialFormula;
    2133           0 :         String sInitialFormula = aInitialFormula.Value;
    2134           0 :         sInitialFormula.SearchAndReplaceAll(sPlaceHolder1,_sDataField);
    2135           0 :         sInitialFormula.SearchAndReplaceAll(sPlaceHolder2,_sFunctionName);
    2136           0 :         aInitialFormula.Value = sInitialFormula;
    2137           0 :         m_xFunction->setInitialFormula( aInitialFormula );
    2138             :     }
    2139           0 :     OUString sNamePostFix;
    2140           0 :     const uno::Reference< report::XFunctionsSupplier> xFunctionsSupplier = fillScope_throw(sNamePostFix);
    2141           0 :     const uno::Reference< container::XIndexContainer> xFunctions(xFunctionsSupplier->getFunctions(),uno::UNO_QUERY_THROW);
    2142           0 :     xFunctions->insertByIndex(xFunctions->getCount(),uno::makeAny(m_xFunction));
    2143           0 :     m_aFunctionNames.insert(TFunctions::value_type(sQuotedFunctionName,TFunctionPair(m_xFunction,xFunctionsSupplier)));
    2144           0 :     m_bNewFunction = true;
    2145           0 : }
    2146             : // -----------------------------------------------------------------------------
    2147           0 : void GeometryHandler::impl_setCounterFunction_throw()
    2148             : {
    2149           0 :     OUString sNamePostFix;
    2150           0 :     fillScope_throw(sNamePostFix);
    2151           0 :     OUString sFunctionName = m_aCounterFunction.m_sName;
    2152           0 :     sFunctionName += sNamePostFix;
    2153           0 :     const OUString sQuotedFunctionName = lcl_getQuotedFunctionName(sFunctionName);
    2154           0 :     OUString sScope;
    2155           0 :     if ( !(!sFunctionName.isEmpty() && m_aFunctionNames.find(sQuotedFunctionName) != m_aFunctionNames.end() && impl_isCounterFunction_throw(sQuotedFunctionName,sScope)) )
    2156           0 :         impl_createFunction(sFunctionName,OUString(),m_aCounterFunction);
    2157             : 
    2158           0 :     OBlocker aBlocker(m_bIn);
    2159           0 :     m_xReportComponent->setPropertyValue(PROPERTY_DATAFIELD,uno::makeAny(impl_convertToFormula( uno::makeAny(sQuotedFunctionName))));
    2160           0 : }
    2161             : // -----------------------------------------------------------------------------
    2162           0 : sal_uInt32 GeometryHandler::impl_getDataFieldType_throw(const OUString& _sDataField) const
    2163             : {
    2164           0 :     sal_uInt32 nDataFieldType = UNDEF_DATA;
    2165           0 :     OUString sDataField;
    2166           0 :     if ( !_sDataField.isEmpty() )
    2167           0 :         sDataField = _sDataField;
    2168             :     else
    2169             :     {
    2170           0 :         uno::Any aDataField( m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD ) );
    2171           0 :         lcl_convertFormulaTo(aDataField,aDataField);
    2172           0 :         aDataField >>= sDataField;
    2173             :     }
    2174             : 
    2175           0 :     if ( !sDataField.isEmpty() )
    2176             :     {
    2177           0 :         if ( impl_isDataField(sDataField) )
    2178           0 :             nDataFieldType = DATA_OR_FORMULA;
    2179           0 :         else if ( isDefaultFunction(sDataField,sDataField) )
    2180           0 :             nDataFieldType = FUNCTION;
    2181           0 :         else if ( m_aFunctionNames.find(sDataField) != m_aFunctionNames.end() )
    2182             :         {
    2183           0 :             nDataFieldType = USER_DEF_FUNCTION;
    2184           0 :             OUString sScope;
    2185           0 :             if ( impl_isCounterFunction_throw(sDataField,sScope) )
    2186           0 :                 nDataFieldType = COUNTER;
    2187             :         }
    2188             :         else
    2189           0 :             nDataFieldType = DATA_OR_FORMULA;
    2190             :     }
    2191           0 :     return nDataFieldType;
    2192             : }
    2193             : // -----------------------------------------------------------------------------
    2194             : // XEventListener
    2195           0 : void SAL_CALL GeometryHandler::disposing(const lang::EventObject& ) throw( uno::RuntimeException )
    2196             : {
    2197           0 : }
    2198             : // XPropertyChangeListener
    2199           0 : void SAL_CALL GeometryHandler::propertyChange(const beans::PropertyChangeEvent& /*evt*/) throw(uno::RuntimeException)
    2200             : {
    2201           0 :     ::osl::ResettableMutexGuard aGuard( m_aMutex );
    2202           0 :     if ( !m_bIn )
    2203             :     {
    2204           0 :         const sal_uInt32 nOldDataFieldType = m_nDataFieldType;
    2205           0 :         const OUString sOldFunctionName = m_sDefaultFunction;
    2206           0 :         const OUString sOldScope = m_sScope;
    2207           0 :         m_sDefaultFunction = m_sScope = OUString();
    2208           0 :         m_nDataFieldType = impl_getDataFieldType_throw();
    2209           0 :         if ( UNDEF_DATA == m_nDataFieldType )
    2210           0 :             m_nDataFieldType = nOldDataFieldType;
    2211           0 :         uno::Any aDataField = m_xReportComponent->getPropertyValue( PROPERTY_DATAFIELD );
    2212           0 :         lcl_convertFormulaTo(aDataField,aDataField);
    2213           0 :         OUString sDataField;
    2214           0 :         aDataField >>= sDataField;
    2215           0 :         switch(m_nDataFieldType)
    2216             :         {
    2217             :             case FUNCTION:
    2218           0 :                 isDefaultFunction(sDataField,sDataField,uno::Reference< report::XFunctionsSupplier>(),true);
    2219           0 :                 break;
    2220             :             case COUNTER:
    2221           0 :                 impl_isCounterFunction_throw(sDataField,m_sScope);
    2222           0 :                 break;
    2223             :             default:
    2224             :                 ;
    2225             :         }
    2226             : 
    2227           0 :         resetOwnProperties(aGuard,sOldFunctionName,sOldScope,nOldDataFieldType);
    2228           0 :     }
    2229           0 : }
    2230             : //........................................................................
    2231           0 : } // namespace rptui
    2232             : //........................................................................
    2233             : 
    2234             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10