1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include "vbaformatcondition.hxx"
20 #include "vbaformatconditions.hxx"
21 #include <ooo/vba/excel/XlFormatConditionType.hpp>
23 using namespace ::ooo::vba
;
24 using namespace ::com::sun::star
;
26 static ScVbaFormatConditions
*
27 lcl_getScVbaFormatConditionsPtr( const uno::Reference
< excel::XFormatConditions
>& xFormatConditions
) throw ( script::BasicErrorException
)
29 ScVbaFormatConditions
* pFormatConditions
= static_cast< ScVbaFormatConditions
* >( xFormatConditions
.get() );
30 if ( !pFormatConditions
)
31 DebugHelper::exception(SbERR_METHOD_FAILED
, OUString() );
32 return pFormatConditions
;
34 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
)
36 mxSheetConditionalEntries
= lcl_getScVbaFormatConditionsPtr( moFormatConditions
)->getSheetConditionalEntries();
38 mxSheetConditionalEntry
= _xSheetConditionalEntry
;
39 msStyleName
= mxStyle
->getName();
44 ScVbaFormatCondition::Delete( ) throw (script::BasicErrorException
, uno::RuntimeException
)
46 ScVbaFormatConditions
* pFormatConditions
= lcl_getScVbaFormatConditionsPtr( moFormatConditions
);
47 pFormatConditions
->removeFormatCondition(msStyleName
, sal_True
);
52 ScVbaFormatCondition::Modify( ::sal_Int32 _nType
, const uno::Any
& _aOperator
, const uno::Any
& _aFormula1
, const uno::Any
& _aFormula2
) throw (script::BasicErrorException
, uno::RuntimeException
)
56 ScVbaFormatConditions
* pFormatConditions
= lcl_getScVbaFormatConditionsPtr( moFormatConditions
);
57 pFormatConditions
->removeFormatCondition(msStyleName
, false);
58 pFormatConditions
->Add(_nType
, _aOperator
, _aFormula1
, _aFormula2
, mxStyle
);
60 catch (uno::Exception
& )
62 DebugHelper::exception(SbERR_METHOD_FAILED
, OUString() );
66 uno::Reference
< excel::XInterior
> SAL_CALL
67 ScVbaFormatCondition::Interior( ) throw (script::BasicErrorException
, uno::RuntimeException
)
69 return mxStyle
->Interior();
72 uno::Reference
< excel::XFont
> SAL_CALL
73 ScVbaFormatCondition::Font( ) throw (script::BasicErrorException
, uno::RuntimeException
)
75 return mxStyle
->Font();
78 ScVbaFormatCondition::Borders( const uno::Any
& Index
) throw (script::BasicErrorException
, uno::RuntimeException
)
79 { return mxStyle
->Borders( Index
);
82 sheet::ConditionOperator
83 ScVbaFormatCondition::retrieveAPIType(sal_Int32 _nVBAType
, const uno::Reference
< sheet::XSheetCondition
>& _xSheetCondition
) throw ( script::BasicErrorException
)
85 sheet::ConditionOperator aAPIType
= sheet::ConditionOperator_NONE
;
88 case excel::XlFormatConditionType::xlExpression
:
89 aAPIType
= sheet::ConditionOperator_FORMULA
;
91 case excel::XlFormatConditionType::xlCellValue
:
92 if ( _xSheetCondition
.is() && (_xSheetCondition
->getOperator() == sheet::ConditionOperator_FORMULA
) )
93 aAPIType
= sheet::ConditionOperator_NONE
;
96 DebugHelper::exception(SbERR_METHOD_FAILED
, OUString() );
102 ScVbaFormatCondition::setFormula1( const uno::Any
& _aFormula1
) throw ( script::BasicErrorException
)
104 // getA1Formula *SHOULD* detect whether the formula is r1c1 or A1 syntax
105 // and if R1C1 convert to A1
106 ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( lcl_getScVbaFormatConditionsPtr( moFormatConditions
)->getA1Formula(_aFormula1
) ) );
110 ScVbaFormatCondition::setFormula2( const uno::Any
& _aFormula2
) throw ( script::BasicErrorException
)
112 ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( lcl_getScVbaFormatConditionsPtr( moFormatConditions
)->getA1Formula(_aFormula2
)) );
116 ScVbaFormatCondition::Type( ) throw ( script::BasicErrorException
, uno::RuntimeException
)
118 sal_Int32 nReturnType
= 0;
119 if ( mxSheetCondition
->getOperator() == sheet::ConditionOperator_FORMULA
)
120 nReturnType
= excel::XlFormatConditionType::xlExpression
;
122 nReturnType
= excel::XlFormatConditionType::xlCellValue
;
128 ScVbaFormatCondition::Operator( sal_Bool bVal
) throw (script::BasicErrorException
)
130 return ScVbaFormatCondition_BASE::Operator( bVal
);
133 ScVbaFormatCondition::Operator( ) throw (script::BasicErrorException
, uno::RuntimeException
)
135 return ScVbaFormatCondition_BASE::Operator( sal_True
);
139 ScVbaFormatCondition::notifyRange() throw ( script::BasicErrorException
)
143 mxParentRangePropertySet
->setPropertyValue("ConditionalFormat", uno::makeAny( mxSheetConditionalEntries
) );
145 catch (uno::Exception
& )
147 DebugHelper::exception(SbERR_METHOD_FAILED
, OUString() );
152 ScVbaFormatCondition::getServiceImplName()
154 return OUString("ScVbaFormatCondition");
157 uno::Sequence
< OUString
>
158 ScVbaFormatCondition::getServiceNames()
160 static uno::Sequence
< OUString
> aServiceNames
;
161 if ( aServiceNames
.getLength() == 0 )
163 aServiceNames
.realloc( 1 );
164 aServiceNames
[ 0 ] = "ooo.vba.excel.FormatCondition";
166 return aServiceNames
;
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */