merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / vba / vbaformatcondition.cxx
blobd9130d85652a0bd35821028be8db639ac436a34a
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: vbaformatcondition.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 ************************************************************************/
30 #include "vbaformatcondition.hxx"
31 #include "vbaformatconditions.hxx"
32 #include <ooo/vba/excel/XlFormatConditionType.hpp>
34 using namespace ::ooo::vba;
35 using namespace ::com::sun::star;
37 ScVbaFormatConditions*
38 lcl_getScVbaFormatConditionsPtr( const uno::Reference< excel::XFormatConditions >& xFormatConditions ) throw ( script::BasicErrorException )
40 ScVbaFormatConditions* pFormatConditions = static_cast< ScVbaFormatConditions* >( xFormatConditions.get() );
41 if ( !pFormatConditions )
42 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
43 return pFormatConditions;
45 ScVbaFormatCondition::ScVbaFormatCondition( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< sheet::XSheetConditionalEntry >& _xSheetConditionalEntry, const uno::Reference< excel::XStyle >& _xStyle, const uno::Reference< excel::XFormatConditions >& _xFormatConditions, const uno::Reference< css::beans::XPropertySet >& _xPropertySet ) throw ( css::uno::RuntimeException ) : ScVbaFormatCondition_BASE( xParent, xContext, uno::Reference< sheet::XSheetCondition >( _xSheetConditionalEntry, css::uno::UNO_QUERY_THROW ) ), moFormatConditions( _xFormatConditions ), mxStyle( _xStyle ), mxParentRangePropertySet( _xPropertySet )
47 mxSheetConditionalEntries = lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getSheetConditionalEntries();
49 mxSheetConditionalEntry = _xSheetConditionalEntry;
50 msStyleName = mxStyle->getName();
54 void SAL_CALL
55 ScVbaFormatCondition::Delete( ) throw (script::BasicErrorException, uno::RuntimeException)
57 ScVbaFormatConditions* pFormatConditions = lcl_getScVbaFormatConditionsPtr( moFormatConditions );
58 pFormatConditions->removeFormatCondition(msStyleName, sal_True);
59 notifyRange();
62 void SAL_CALL
63 ScVbaFormatCondition::Modify( ::sal_Int32 _nType, const uno::Any& _aOperator, const uno::Any& _aFormula1, const uno::Any& _aFormula2 ) throw (script::BasicErrorException, uno::RuntimeException)
65 try
67 ScVbaFormatConditions* pFormatConditions = lcl_getScVbaFormatConditionsPtr( moFormatConditions );
68 pFormatConditions->removeFormatCondition(msStyleName, sal_False);
69 pFormatConditions->Add(_nType, _aOperator, _aFormula1, _aFormula2, mxStyle);
71 catch (uno::Exception& )
73 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
77 uno::Reference< excel::XInterior > SAL_CALL
78 ScVbaFormatCondition::Interior( ) throw (script::BasicErrorException, uno::RuntimeException)
80 return mxStyle->Interior();
83 uno::Reference< excel::XFont > SAL_CALL
84 ScVbaFormatCondition::Font( ) throw (script::BasicErrorException, uno::RuntimeException)
86 return mxStyle->Font();
88 uno::Any SAL_CALL
89 ScVbaFormatCondition::Borders( const uno::Any& Index ) throw (script::BasicErrorException, uno::RuntimeException)
90 { return mxStyle->Borders( Index );
93 sheet::ConditionOperator
94 ScVbaFormatCondition::retrieveAPIType(sal_Int32 _nVBAType, const uno::Reference< sheet::XSheetCondition >& _xSheetCondition ) throw ( script::BasicErrorException )
96 sheet::ConditionOperator aAPIType = sheet::ConditionOperator_NONE;
97 switch (_nVBAType)
99 case excel::XlFormatConditionType::xlExpression:
100 aAPIType = sheet::ConditionOperator_FORMULA;
101 break;
102 case excel::XlFormatConditionType::xlCellValue:
103 if ( _xSheetCondition.is() && (_xSheetCondition->getOperator() == sheet::ConditionOperator_FORMULA ) )
104 aAPIType = sheet::ConditionOperator_NONE;
105 break;
106 default:
107 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
109 return aAPIType;
112 void
113 ScVbaFormatCondition::setFormula1( const uno::Any& _aFormula1) throw ( script::BasicErrorException )
115 // getA1Formula *SHOULD* detect whether the formula is r1c1 or A1 syntax
116 // and if R1C1 convert to A1
117 ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getA1Formula(_aFormula1) ) );
120 void
121 ScVbaFormatCondition::setFormula2( const uno::Any& _aFormula2) throw ( script::BasicErrorException )
123 ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getA1Formula(_aFormula2)) );
126 ::sal_Int32 SAL_CALL
127 ScVbaFormatCondition::Type( ) throw ( script::BasicErrorException, uno::RuntimeException )
129 sal_Int32 nReturnType = 0;
130 if ( mxSheetCondition->getOperator() == sheet::ConditionOperator_FORMULA)
131 nReturnType = excel::XlFormatConditionType::xlExpression;
132 else
133 nReturnType = excel::XlFormatConditionType::xlCellValue;
134 return nReturnType;
138 ::sal_Int32
139 ScVbaFormatCondition::Operator( sal_Bool bVal ) throw (script::BasicErrorException )
141 return ScVbaFormatCondition_BASE::Operator( bVal );
143 ::sal_Int32 SAL_CALL
144 ScVbaFormatCondition::Operator( ) throw (script::BasicErrorException, uno::RuntimeException)
146 return ScVbaFormatCondition_BASE::Operator( sal_True );
149 void
150 ScVbaFormatCondition::notifyRange() throw ( script::BasicErrorException )
154 mxParentRangePropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ConditionalFormat") ), uno::makeAny( mxSheetConditionalEntries) );
156 catch (uno::Exception& )
158 DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
162 rtl::OUString&
163 ScVbaFormatCondition::getServiceImplName()
165 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFormatCondition") );
166 return sImplName;
169 uno::Sequence< rtl::OUString >
170 ScVbaFormatCondition::getServiceNames()
172 static uno::Sequence< rtl::OUString > aServiceNames;
173 if ( aServiceNames.getLength() == 0 )
175 aServiceNames.realloc( 1 );
176 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.FormatCondition" ) );
178 return aServiceNames;