Update ooo320-m1
[ooovba.git] / reportdesign / source / core / misc / conditionupdater.cxx
blobc5b72bc3de3893f19c57d360aa3dcb2a2d8c41f6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: conditionupdater.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "conditionupdater.hxx"
32 #include "reportformula.hxx"
34 /** === begin UNO includes === **/
35 #include <com/sun/star/report/XFormatCondition.hpp>
36 /** === end UNO includes === **/
38 #include <tools/diagnose_ex.h>
40 //........................................................................
41 namespace rptui
43 //........................................................................
45 /** === begin UNO using === **/
46 using ::com::sun::star::beans::PropertyChangeEvent;
47 using ::com::sun::star::uno::Reference;
48 using ::com::sun::star::report::XReportControlModel;
49 using ::com::sun::star::uno::UNO_QUERY;
50 using ::com::sun::star::report::XFormatCondition;
51 using ::com::sun::star::uno::UNO_QUERY_THROW;
52 using ::com::sun::star::uno::Exception;
53 /** === end UNO using === **/
55 //====================================================================
56 //= ConditionUpdater
57 //====================================================================
58 //--------------------------------------------------------------------
59 ConditionUpdater::ConditionUpdater()
63 //--------------------------------------------------------------------
64 ConditionUpdater::~ConditionUpdater()
68 //--------------------------------------------------------------------
69 void ConditionUpdater::notifyPropertyChange( const PropertyChangeEvent& _rEvent )
71 if ( !impl_lateInit_nothrow() )
72 return;
74 Reference< XReportControlModel > xRptControlModel( _rEvent.Source, UNO_QUERY );
75 if ( xRptControlModel.is() && _rEvent.PropertyName.equalsAscii( "DataField" ) )
77 ::rtl::OUString sOldDataSource, sNewDataSource;
78 OSL_VERIFY( _rEvent.OldValue >>= sOldDataSource );
79 OSL_VERIFY( _rEvent.NewValue >>= sNewDataSource );
80 impl_adjustFormatConditions_nothrow( xRptControlModel, sOldDataSource, sNewDataSource );
84 //--------------------------------------------------------------------
85 bool ConditionUpdater::impl_lateInit_nothrow()
87 if ( !m_aConditionalExpressions.empty() )
88 return true;
90 ConditionalExpressionFactory::getKnownConditionalExpressions( m_aConditionalExpressions );
91 return true;
94 //--------------------------------------------------------------------
95 void ConditionUpdater::impl_adjustFormatConditions_nothrow( const Reference< XReportControlModel >& _rxRptControlModel,
96 const ::rtl::OUString& _rOldDataSource, const ::rtl::OUString& _rNewDataSource )
98 try
100 ReportFormula aOldContentFormula( _rOldDataSource );
101 ::rtl::OUString sOldUnprefixed( aOldContentFormula.getBracketedFieldOrExpression() );
102 ReportFormula aNewContentFormula( _rNewDataSource );
103 ::rtl::OUString sNewUnprefixed( aNewContentFormula.getBracketedFieldOrExpression() );
105 sal_Int32 nCount( _rxRptControlModel->getCount() );
106 Reference< XFormatCondition > xFormatCondition;
107 ::rtl::OUString sFormulaExpression, sLHS, sRHS;
108 for ( sal_Int32 i=0; i<nCount; ++i )
110 xFormatCondition.set( _rxRptControlModel->getByIndex( i ), UNO_QUERY_THROW );
111 ReportFormula aFormula( xFormatCondition->getFormula() );
112 sFormulaExpression = aFormula.getExpression();
114 for ( ConditionalExpressions::const_iterator loop = m_aConditionalExpressions.begin();
115 loop != m_aConditionalExpressions.end();
116 ++loop
119 if ( !loop->second->matchExpression( sFormulaExpression, sOldUnprefixed, sLHS, sRHS ) )
120 continue;
122 // the expression matches -> translate it to the new data source of the report control model
123 sFormulaExpression = loop->second->assembleExpression( sNewUnprefixed, sLHS, sRHS );
124 aFormula = ReportFormula( ReportFormula::Expression, sFormulaExpression );
125 xFormatCondition->setFormula( aFormula.getCompleteFormula() );
126 break;
130 catch( const Exception& )
132 DBG_UNHANDLED_EXCEPTION();
136 //........................................................................
137 } // namespace rptui
138 //........................................................................