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 <rtl/ustrbuf.hxx>
11 #include "condformathelper.hxx"
12 #include "globstr.hrc"
16 OUString
getTextForType(ScCondFormatEntryType eType
)
21 return ScGlobal::GetRscString(STR_COND_CONDITION
);
23 return ScGlobal::GetRscString(STR_COND_COLORSCALE
);
25 return ScGlobal::GetRscString(STR_COND_DATABAR
);
27 return ScGlobal::GetRscString(STR_COND_FORMULA
);
29 return ScGlobal::GetRscString(STR_COND_ICONSET
);
31 return ScGlobal::GetRscString(STR_COND_DATE
);
39 OUString
getExpression(sal_Int32 nIndex
)
50 return OUString("<=");
52 return OUString(">=");
54 return OUString("!=");
56 return ScGlobal::GetRscString(STR_COND_BETWEEN
);
58 return ScGlobal::GetRscString(STR_COND_NOTBETWEEN
);
60 return ScGlobal::GetRscString(STR_COND_DUPLICATE
);
62 return ScGlobal::GetRscString(STR_COND_UNIQUE
);
66 return ScGlobal::GetRscString(STR_COND_TOP10
);
68 return ScGlobal::GetRscString(STR_COND_BOTTOM10
);
70 return ScGlobal::GetRscString(STR_COND_TOP_PERCENT
);
72 return ScGlobal::GetRscString(STR_COND_BOTTOM_PERCENT
);
74 return ScGlobal::GetRscString(STR_COND_ABOVE_AVERAGE
);
76 return ScGlobal::GetRscString(STR_COND_BELOW_AVERAGE
);
78 return ScGlobal::GetRscString(STR_COND_ABOVE_EQUAL_AVERAGE
);
80 return ScGlobal::GetRscString(STR_COND_BELOW_EQUAL_AVERAGE
);
82 return ScGlobal::GetRscString(STR_COND_ERROR
);
84 return ScGlobal::GetRscString(STR_COND_NOERROR
);
86 return ScGlobal::GetRscString(STR_COND_BEGINS_WITH
);
88 return ScGlobal::GetRscString(STR_COND_ENDS_WITH
);
90 return ScGlobal::GetRscString(STR_COND_CONTAINS
);
92 return ScGlobal::GetRscString(STR_COND_NOT_CONTAINS
);
97 OUString
getDateString(sal_Int32 nIndex
)
99 sal_Int32 nStringIndex
= STR_COND_TODAY
+ nIndex
;
100 if(nStringIndex
<= STR_COND_NEXTYEAR
)
101 return ScGlobal::GetRscString(nStringIndex
);
109 OUString
ScCondFormatHelper::GetExpression(const ScConditionalFormat
& rFormat
, const ScAddress
& rPos
)
111 OUStringBuffer aBuffer
;
112 if(!rFormat
.IsEmpty())
114 switch(rFormat
.GetEntry(0)->GetType())
116 case condformat::CONDITION
:
118 const ScConditionEntry
* pEntry
= static_cast<const ScConditionEntry
*>(rFormat
.GetEntry(0));
119 ScConditionMode eMode
= pEntry
->GetOperation();
120 if(eMode
== SC_COND_DIRECT
)
122 aBuffer
.append(getTextForType(FORMULA
));
124 aBuffer
.append(pEntry
->GetExpression(rPos
, 0));
128 aBuffer
.append(getTextForType(CONDITION
));
130 aBuffer
.append(getExpression(static_cast<sal_Int32
>(eMode
)));
132 if(eMode
== SC_COND_BETWEEN
|| eMode
== SC_COND_NOTBETWEEN
)
134 aBuffer
.append(pEntry
->GetExpression(rPos
, 0));
135 aBuffer
.append(" and ");
136 aBuffer
.append(pEntry
->GetExpression(rPos
, 1));
138 else if(eMode
<= SC_COND_NOTEQUAL
|| eMode
>= SC_COND_BEGINS_WITH
)
140 aBuffer
.append(pEntry
->GetExpression(rPos
, 0));
146 case condformat::DATABAR
:
147 aBuffer
.append(getTextForType(DATABAR
));
149 case condformat::COLORSCALE
:
150 aBuffer
.append(getTextForType(COLORSCALE
));
152 case condformat::ICONSET
:
153 aBuffer
.append(getTextForType(ICONSET
));
155 case condformat::DATE
:
157 aBuffer
.append(getTextForType(DATE
));
159 sal_Int32 nDateEntry
= static_cast<sal_Int32
>(static_cast<const ScCondDateFormatEntry
*>(rFormat
.GetEntry(0))->GetDateType());
160 aBuffer
.append(getDateString(nDateEntry
));
165 return aBuffer
.makeStringAndClear();
168 OUString
ScCondFormatHelper::GetExpression( ScCondFormatEntryType eType
, sal_Int32 nIndex
,
169 const OUString
& aStr1
, const OUString
& aStr2
)
171 OUStringBuffer
aBuffer(getTextForType(eType
));
173 if(eType
== CONDITION
)
175 // workaround missing FORMULA option in the conditions case
176 // FORMULA is handled later
179 aBuffer
.append(getExpression(nIndex
));
180 if(nIndex
<= 7 || nIndex
>= 19)
182 aBuffer
.append(" ").append(aStr1
);
183 if(nIndex
== 6 || nIndex
== 7)
185 aBuffer
.append(" and ").append(aStr2
);
189 else if(eType
== FORMULA
)
191 aBuffer
.append(" ").append(aStr1
);
193 else if(eType
== DATE
)
195 aBuffer
.append(getDateString(nIndex
));
198 return aBuffer
.makeStringAndClear();
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */