1*9e0e4191SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9e0e4191SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9e0e4191SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9e0e4191SAndrew Rist * distributed with this work for additional information 6*9e0e4191SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9e0e4191SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9e0e4191SAndrew Rist * "License"); you may not use this file except in compliance 9*9e0e4191SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9e0e4191SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9e0e4191SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9e0e4191SAndrew Rist * software distributed under the License is distributed on an 15*9e0e4191SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9e0e4191SAndrew Rist * KIND, either express or implied. See the License for the 17*9e0e4191SAndrew Rist * specific language governing permissions and limitations 18*9e0e4191SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9e0e4191SAndrew Rist *************************************************************/ 21*9e0e4191SAndrew Rist 22*9e0e4191SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "conditionupdater.hxx" 25cdf0e10cSrcweir #include "reportformula.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir /** === begin UNO includes === **/ 28cdf0e10cSrcweir #include <com/sun/star/report/XFormatCondition.hpp> 29cdf0e10cSrcweir /** === end UNO includes === **/ 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <tools/diagnose_ex.h> 32cdf0e10cSrcweir 33cdf0e10cSrcweir //........................................................................ 34cdf0e10cSrcweir namespace rptui 35cdf0e10cSrcweir { 36cdf0e10cSrcweir //........................................................................ 37cdf0e10cSrcweir 38cdf0e10cSrcweir /** === begin UNO using === **/ 39cdf0e10cSrcweir using ::com::sun::star::beans::PropertyChangeEvent; 40cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 41cdf0e10cSrcweir using ::com::sun::star::report::XReportControlModel; 42cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 43cdf0e10cSrcweir using ::com::sun::star::report::XFormatCondition; 44cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 45cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 46cdf0e10cSrcweir /** === end UNO using === **/ 47cdf0e10cSrcweir 48cdf0e10cSrcweir //==================================================================== 49cdf0e10cSrcweir //= ConditionUpdater 50cdf0e10cSrcweir //==================================================================== 51cdf0e10cSrcweir //-------------------------------------------------------------------- ConditionUpdater()52cdf0e10cSrcweir ConditionUpdater::ConditionUpdater() 53cdf0e10cSrcweir { 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir //-------------------------------------------------------------------- ~ConditionUpdater()57cdf0e10cSrcweir ConditionUpdater::~ConditionUpdater() 58cdf0e10cSrcweir { 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir //-------------------------------------------------------------------- notifyPropertyChange(const PropertyChangeEvent & _rEvent)62cdf0e10cSrcweir void ConditionUpdater::notifyPropertyChange( const PropertyChangeEvent& _rEvent ) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir if ( !impl_lateInit_nothrow() ) 65cdf0e10cSrcweir return; 66cdf0e10cSrcweir 67cdf0e10cSrcweir Reference< XReportControlModel > xRptControlModel( _rEvent.Source, UNO_QUERY ); 68cdf0e10cSrcweir if ( xRptControlModel.is() && _rEvent.PropertyName.equalsAscii( "DataField" ) ) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir ::rtl::OUString sOldDataSource, sNewDataSource; 71cdf0e10cSrcweir OSL_VERIFY( _rEvent.OldValue >>= sOldDataSource ); 72cdf0e10cSrcweir OSL_VERIFY( _rEvent.NewValue >>= sNewDataSource ); 73cdf0e10cSrcweir impl_adjustFormatConditions_nothrow( xRptControlModel, sOldDataSource, sNewDataSource ); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir //-------------------------------------------------------------------- impl_lateInit_nothrow()78cdf0e10cSrcweir bool ConditionUpdater::impl_lateInit_nothrow() 79cdf0e10cSrcweir { 80cdf0e10cSrcweir if ( !m_aConditionalExpressions.empty() ) 81cdf0e10cSrcweir return true; 82cdf0e10cSrcweir 83cdf0e10cSrcweir ConditionalExpressionFactory::getKnownConditionalExpressions( m_aConditionalExpressions ); 84cdf0e10cSrcweir return true; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir //-------------------------------------------------------------------- impl_adjustFormatConditions_nothrow(const Reference<XReportControlModel> & _rxRptControlModel,const::rtl::OUString & _rOldDataSource,const::rtl::OUString & _rNewDataSource)88cdf0e10cSrcweir void ConditionUpdater::impl_adjustFormatConditions_nothrow( const Reference< XReportControlModel >& _rxRptControlModel, 89cdf0e10cSrcweir const ::rtl::OUString& _rOldDataSource, const ::rtl::OUString& _rNewDataSource ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir try 92cdf0e10cSrcweir { 93cdf0e10cSrcweir ReportFormula aOldContentFormula( _rOldDataSource ); 94cdf0e10cSrcweir ::rtl::OUString sOldUnprefixed( aOldContentFormula.getBracketedFieldOrExpression() ); 95cdf0e10cSrcweir ReportFormula aNewContentFormula( _rNewDataSource ); 96cdf0e10cSrcweir ::rtl::OUString sNewUnprefixed( aNewContentFormula.getBracketedFieldOrExpression() ); 97cdf0e10cSrcweir 98cdf0e10cSrcweir sal_Int32 nCount( _rxRptControlModel->getCount() ); 99cdf0e10cSrcweir Reference< XFormatCondition > xFormatCondition; 100cdf0e10cSrcweir ::rtl::OUString sFormulaExpression, sLHS, sRHS; 101cdf0e10cSrcweir for ( sal_Int32 i=0; i<nCount; ++i ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir xFormatCondition.set( _rxRptControlModel->getByIndex( i ), UNO_QUERY_THROW ); 104cdf0e10cSrcweir ReportFormula aFormula( xFormatCondition->getFormula() ); 105cdf0e10cSrcweir sFormulaExpression = aFormula.getExpression(); 106cdf0e10cSrcweir 107cdf0e10cSrcweir for ( ConditionalExpressions::const_iterator loop = m_aConditionalExpressions.begin(); 108cdf0e10cSrcweir loop != m_aConditionalExpressions.end(); 109cdf0e10cSrcweir ++loop 110cdf0e10cSrcweir ) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir if ( !loop->second->matchExpression( sFormulaExpression, sOldUnprefixed, sLHS, sRHS ) ) 113cdf0e10cSrcweir continue; 114cdf0e10cSrcweir 115cdf0e10cSrcweir // the expression matches -> translate it to the new data source of the report control model 116cdf0e10cSrcweir sFormulaExpression = loop->second->assembleExpression( sNewUnprefixed, sLHS, sRHS ); 117cdf0e10cSrcweir aFormula = ReportFormula( ReportFormula::Expression, sFormulaExpression ); 118cdf0e10cSrcweir xFormatCondition->setFormula( aFormula.getCompleteFormula() ); 119cdf0e10cSrcweir break; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir } 122cdf0e10cSrcweir } 123cdf0e10cSrcweir catch( const Exception& ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir //........................................................................ 130cdf0e10cSrcweir } // namespace rptui 131cdf0e10cSrcweir //........................................................................ 132