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>
23 #include <basic/sberrors.hxx>
26 using namespace ::ooo::vba
;
27 using namespace ::com::sun::star
;
29 /// @throws css::script::BasicErrorException
30 static ScVbaFormatConditions
*
31 lcl_getScVbaFormatConditionsPtr( const uno::Reference
< excel::XFormatConditions
>& xFormatConditions
)
33 ScVbaFormatConditions
* pFormatConditions
= static_cast< ScVbaFormatConditions
* >( xFormatConditions
.get() );
34 if ( !pFormatConditions
)
35 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {} );
36 return pFormatConditions
;
39 ScVbaFormatCondition::ScVbaFormatCondition( const uno::Reference
< XHelperInterface
>& xParent
,
40 const uno::Reference
< uno::XComponentContext
> & xContext
,
41 const uno::Reference
< sheet::XSheetConditionalEntry
>& _xSheetConditionalEntry
,
42 uno::Reference
< excel::XStyle
> _xStyle
,
43 uno::Reference
< excel::XFormatConditions
> _xFormatConditions
,
44 uno::Reference
< css::beans::XPropertySet
> _xPropertySet
)
45 : ScVbaFormatCondition_BASE( xParent
, xContext
,
46 uno::Reference
< sheet::XSheetCondition
>( _xSheetConditionalEntry
, css::uno::UNO_QUERY_THROW
) ),
47 moFormatConditions(std::move( _xFormatConditions
)), mxStyle(std::move( _xStyle
)), mxParentRangePropertySet(std::move( _xPropertySet
))
49 mxSheetConditionalEntries
= lcl_getScVbaFormatConditionsPtr( moFormatConditions
)->getSheetConditionalEntries();
51 msStyleName
= mxStyle
->getName();
55 ScVbaFormatCondition::Delete( )
57 ScVbaFormatConditions
* pFormatConditions
= lcl_getScVbaFormatConditionsPtr( moFormatConditions
);
58 pFormatConditions
->removeFormatCondition(msStyleName
, true);
63 ScVbaFormatCondition::Modify( ::sal_Int32 _nType
, const uno::Any
& _aOperator
, const uno::Any
& _aFormula1
, const uno::Any
& _aFormula2
)
67 ScVbaFormatConditions
* pFormatConditions
= lcl_getScVbaFormatConditionsPtr( moFormatConditions
);
68 pFormatConditions
->removeFormatCondition(msStyleName
, false);
69 pFormatConditions
->Add(_nType
, _aOperator
, _aFormula1
, _aFormula2
, mxStyle
);
71 catch (const uno::Exception
&)
73 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {} );
77 uno::Reference
< excel::XInterior
> SAL_CALL
78 ScVbaFormatCondition::Interior( )
80 return mxStyle
->Interior();
83 uno::Reference
< excel::XFont
> SAL_CALL
84 ScVbaFormatCondition::Font( )
86 return mxStyle
->Font();
89 ScVbaFormatCondition::Borders( const uno::Any
& Index
)
90 { return mxStyle
->Borders( Index
);
93 sheet::ConditionOperator
94 ScVbaFormatCondition::retrieveAPIType(sal_Int32 _nVBAType
, const uno::Reference
< sheet::XSheetCondition
>& _xSheetCondition
)
96 sheet::ConditionOperator aAPIType
= sheet::ConditionOperator_NONE
;
99 case excel::XlFormatConditionType::xlExpression
:
100 aAPIType
= sheet::ConditionOperator_FORMULA
;
102 case excel::XlFormatConditionType::xlCellValue
:
103 if ( _xSheetCondition
.is() && (_xSheetCondition
->getOperator() == sheet::ConditionOperator_FORMULA
) )
104 aAPIType
= sheet::ConditionOperator_NONE
;
107 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {} );
113 ScVbaFormatCondition::Type( )
115 sal_Int32 nReturnType
= 0;
116 if ( mxSheetCondition
->getOperator() == sheet::ConditionOperator_FORMULA
)
117 nReturnType
= excel::XlFormatConditionType::xlExpression
;
119 nReturnType
= excel::XlFormatConditionType::xlCellValue
;
124 ScVbaFormatCondition::Operator( )
126 return ScVbaFormatCondition_BASE::Operator( true );
130 ScVbaFormatCondition::notifyRange()
134 mxParentRangePropertySet
->setPropertyValue(SC_UNONAME_CONDFMT
, uno::Any( mxSheetConditionalEntries
));
136 catch (uno::Exception
& )
138 DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILED
, {} );
143 ScVbaFormatCondition::getServiceImplName()
145 return u
"ScVbaFormatCondition"_ustr
;
148 uno::Sequence
< OUString
>
149 ScVbaFormatCondition::getServiceNames()
151 static uno::Sequence
< OUString
> const aServiceNames
153 u
"ooo.vba.excel.FormatCondition"_ustr
155 return aServiceNames
;
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */