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 "unonames.hxx"
22 #include <ooo/vba/excel/XlFormatConditionType.hpp>
24 using namespace ::ooo::vba
;
25 using namespace ::com::sun::star
;
27 static ScVbaFormatConditions
*
28 lcl_getScVbaFormatConditionsPtr( const uno::Reference
< excel::XFormatConditions
>& xFormatConditions
) throw ( script::BasicErrorException
)
30 ScVbaFormatConditions
* pFormatConditions
= static_cast< ScVbaFormatConditions
* >( xFormatConditions
.get() );
31 if ( !pFormatConditions
)
32 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
33 return pFormatConditions
;
36 ScVbaFormatCondition::ScVbaFormatCondition( const uno::Reference
< XHelperInterface
>& xParent
,
37 const uno::Reference
< uno::XComponentContext
> & xContext
,
38 const uno::Reference
< sheet::XSheetConditionalEntry
>& _xSheetConditionalEntry
,
39 const uno::Reference
< excel::XStyle
>& _xStyle
,
40 const uno::Reference
< excel::XFormatConditions
>& _xFormatConditions
,
41 const uno::Reference
< css::beans::XPropertySet
>& _xPropertySet
) throw ( css::uno::RuntimeException
, css::script::BasicErrorException
)
42 : ScVbaFormatCondition_BASE( xParent
, xContext
,
43 uno::Reference
< sheet::XSheetCondition
>( _xSheetConditionalEntry
, css::uno::UNO_QUERY_THROW
) ),
44 moFormatConditions( _xFormatConditions
), mxStyle( _xStyle
), mxParentRangePropertySet( _xPropertySet
)
46 mxSheetConditionalEntries
= lcl_getScVbaFormatConditionsPtr( moFormatConditions
)->getSheetConditionalEntries();
48 mxSheetConditionalEntry
= _xSheetConditionalEntry
;
49 msStyleName
= mxStyle
->getName();
53 ScVbaFormatCondition::Delete( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
55 ScVbaFormatConditions
* pFormatConditions
= lcl_getScVbaFormatConditionsPtr( moFormatConditions
);
56 pFormatConditions
->removeFormatCondition(msStyleName
, true);
61 ScVbaFormatCondition::Modify( ::sal_Int32 _nType
, const uno::Any
& _aOperator
, const uno::Any
& _aFormula1
, const uno::Any
& _aFormula2
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
65 ScVbaFormatConditions
* pFormatConditions
= lcl_getScVbaFormatConditionsPtr( moFormatConditions
);
66 pFormatConditions
->removeFormatCondition(msStyleName
, false);
67 pFormatConditions
->Add(_nType
, _aOperator
, _aFormula1
, _aFormula2
, mxStyle
);
69 catch (const uno::Exception
&)
71 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
75 uno::Reference
< excel::XInterior
> SAL_CALL
76 ScVbaFormatCondition::Interior( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
78 return mxStyle
->Interior();
81 uno::Reference
< excel::XFont
> SAL_CALL
82 ScVbaFormatCondition::Font( ) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
84 return mxStyle
->Font();
87 ScVbaFormatCondition::Borders( const uno::Any
& Index
) throw (script::BasicErrorException
, uno::RuntimeException
, std::exception
)
88 { return mxStyle
->Borders( Index
);
91 sheet::ConditionOperator
92 ScVbaFormatCondition::retrieveAPIType(sal_Int32 _nVBAType
, const uno::Reference
< sheet::XSheetCondition
>& _xSheetCondition
) throw ( script::BasicErrorException
)
94 sheet::ConditionOperator aAPIType
= sheet::ConditionOperator_NONE
;
97 case excel::XlFormatConditionType::xlExpression
:
98 aAPIType
= sheet::ConditionOperator_FORMULA
;
100 case excel::XlFormatConditionType::xlCellValue
:
101 if ( _xSheetCondition
.is() && (_xSheetCondition
->getOperator() == sheet::ConditionOperator_FORMULA
) )
102 aAPIType
= sheet::ConditionOperator_NONE
;
105 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
111 ScVbaFormatCondition::setFormula1( const uno::Any
& _aFormula1
) throw ( script::BasicErrorException
)
113 // getA1Formula *SHOULD* detect whether the formula is r1c1 or A1 syntax
114 // and if R1C1 convert to A1
115 ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( ScVbaFormatConditions::getA1Formula(_aFormula1
) ) );
119 ScVbaFormatCondition::setFormula2( const uno::Any
& _aFormula2
) throw ( script::BasicErrorException
)
121 ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( ScVbaFormatConditions::getA1Formula(_aFormula2
)) );
125 ScVbaFormatCondition::Type( ) throw ( script::BasicErrorException
, uno::RuntimeException
, std::exception
)
127 sal_Int32 nReturnType
= 0;
128 if ( mxSheetCondition
->getOperator() == sheet::ConditionOperator_FORMULA
)
129 nReturnType
= excel::XlFormatConditionType::xlExpression
;
131 nReturnType
= excel::XlFormatConditionType::xlCellValue
;
136 ScVbaFormatCondition::Operator( bool bVal
) throw (script::BasicErrorException
)
138 return ScVbaFormatCondition_BASE::Operator( bVal
);
141 ScVbaFormatCondition::Operator( ) throw (script::BasicErrorException
, uno::RuntimeException
)
143 return ScVbaFormatCondition_BASE::Operator( true );
147 ScVbaFormatCondition::notifyRange() throw ( script::BasicErrorException
)
151 mxParentRangePropertySet
->setPropertyValue(SC_UNONAME_CONDFMT
, uno::makeAny( mxSheetConditionalEntries
));
153 catch (uno::Exception
& )
155 DebugHelper::basicexception(SbERR_METHOD_FAILED
, OUString() );
160 ScVbaFormatCondition::getServiceImplName()
162 return OUString("ScVbaFormatCondition");
165 uno::Sequence
< OUString
>
166 ScVbaFormatCondition::getServiceNames()
168 static uno::Sequence
< OUString
> aServiceNames
;
169 if ( aServiceNames
.getLength() == 0 )
171 aServiceNames
.realloc( 1 );
172 aServiceNames
[ 0 ] = "ooo.vba.excel.FormatCondition";
174 return aServiceNames
;
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */