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/.
10 #include <sal/config.h>
12 #include <o3tl/safeint.hxx>
13 #include <rtl/ustrbuf.hxx>
14 #include <condformathelper.hxx>
15 #include <globstr.hrc>
16 #include <scresid.hxx>
17 #include <conditio.hxx>
21 OUString
getTextForType(ScCondFormatEntryType eType
)
26 return ScResId(STR_COND_CONDITION
);
28 return ScResId(STR_COND_COLORSCALE
);
30 return ScResId(STR_COND_DATABAR
);
32 return ScResId(STR_COND_FORMULA
);
34 return ScResId(STR_COND_ICONSET
);
36 return ScResId(STR_COND_DATE
);
44 OUString
getExpression(sal_Int32 nIndex
)
61 return ScResId(STR_COND_BETWEEN
);
63 return ScResId(STR_COND_NOTBETWEEN
);
65 return ScResId(STR_COND_DUPLICATE
);
67 return ScResId(STR_COND_UNIQUE
);
70 return ScResId(STR_COND_TOP10
);
72 return ScResId(STR_COND_BOTTOM10
);
74 return ScResId(STR_COND_TOP_PERCENT
);
76 return ScResId(STR_COND_BOTTOM_PERCENT
);
78 return ScResId(STR_COND_ABOVE_AVERAGE
);
80 return ScResId(STR_COND_BELOW_AVERAGE
);
82 return ScResId(STR_COND_ABOVE_EQUAL_AVERAGE
);
84 return ScResId(STR_COND_BELOW_EQUAL_AVERAGE
);
86 return ScResId(STR_COND_ERROR
);
88 return ScResId(STR_COND_NOERROR
);
90 return ScResId(STR_COND_BEGINS_WITH
);
92 return ScResId(STR_COND_ENDS_WITH
);
94 return ScResId(STR_COND_CONTAINS
);
96 return ScResId(STR_COND_NOT_CONTAINS
);
104 OUString
getDateString(sal_Int32 nIndex
)
106 const char* aCondStrs
[] =
123 if (nIndex
>= 0 && o3tl::make_unsigned(nIndex
) < SAL_N_ELEMENTS(aCondStrs
))
124 return ScResId(aCondStrs
[nIndex
]);
131 OUString
ScCondFormatHelper::GetExpression(const ScConditionalFormat
& rFormat
, const ScAddress
& rPos
)
133 OUStringBuffer aBuffer
;
134 if(!rFormat
.IsEmpty())
136 switch(rFormat
.GetEntry(0)->GetType())
138 case ScFormatEntry::Type::Condition
:
139 case ScFormatEntry::Type::ExtCondition
:
141 const ScConditionEntry
* pEntry
= static_cast<const ScConditionEntry
*>(rFormat
.GetEntry(0));
142 ScConditionMode eMode
= pEntry
->GetOperation();
143 if(eMode
== ScConditionMode::Direct
)
145 aBuffer
.append(getTextForType(FORMULA
));
147 aBuffer
.append(pEntry
->GetExpression(rPos
, 0));
151 aBuffer
.append(getTextForType(CONDITION
));
153 aBuffer
.append(getExpression(static_cast<sal_Int32
>(eMode
)));
155 if(eMode
== ScConditionMode::Between
|| eMode
== ScConditionMode::NotBetween
)
157 aBuffer
.append(pEntry
->GetExpression(rPos
, 0));
159 aBuffer
.append(ScResId(STR_COND_AND
));
161 aBuffer
.append(pEntry
->GetExpression(rPos
, 1));
163 else if(eMode
<= ScConditionMode::NotEqual
|| eMode
>= ScConditionMode::BeginsWith
)
165 aBuffer
.append(pEntry
->GetExpression(rPos
, 0));
171 case ScFormatEntry::Type::Databar
:
172 aBuffer
.append(getTextForType(DATABAR
));
174 case ScFormatEntry::Type::Colorscale
:
175 aBuffer
.append(getTextForType(COLORSCALE
));
177 case ScFormatEntry::Type::Iconset
:
178 aBuffer
.append(getTextForType(ICONSET
));
180 case ScFormatEntry::Type::Date
:
182 aBuffer
.append(getTextForType(DATE
));
184 sal_Int32 nDateEntry
= static_cast<sal_Int32
>(static_cast<const ScCondDateFormatEntry
*>(rFormat
.GetEntry(0))->GetDateType());
185 aBuffer
.append(getDateString(nDateEntry
));
190 return aBuffer
.makeStringAndClear();
193 OUString
ScCondFormatHelper::GetExpression( ScCondFormatEntryType eType
, sal_Int32 nIndex
,
194 const OUString
& aStr1
, const OUString
& aStr2
)
196 OUStringBuffer
aBuffer(getTextForType(eType
));
198 if(eType
== CONDITION
)
200 // workaround missing FORMULA option in the conditions case
201 // FORMULA is handled later
204 aBuffer
.append(getExpression(nIndex
));
205 if(nIndex
<= 7 || nIndex
>= 19)
207 aBuffer
.append(" ").append(aStr1
);
208 if(nIndex
== 6 || nIndex
== 7)
211 aBuffer
.append(ScResId(STR_COND_AND
));
213 aBuffer
.append(aStr2
);
217 else if(eType
== FORMULA
)
219 aBuffer
.append(" ").append(aStr1
);
221 else if(eType
== DATE
)
223 aBuffer
.append(getDateString(nIndex
));
226 return aBuffer
.makeStringAndClear();
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */