fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / condformat / condformathelper.cxx
blob8d44ec43f721cedc69e0ab87d34fba715ae8541f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <rtl/ustrbuf.hxx>
11 #include "condformathelper.hxx"
12 #include "globstr.hrc"
14 namespace {
16 OUString getTextForType(ScCondFormatEntryType eType)
18 switch(eType)
20 case CONDITION:
21 return ScGlobal::GetRscString(STR_COND_CONDITION);
22 case COLORSCALE:
23 return ScGlobal::GetRscString(STR_COND_COLORSCALE);
24 case DATABAR:
25 return ScGlobal::GetRscString(STR_COND_DATABAR);
26 case FORMULA:
27 return ScGlobal::GetRscString(STR_COND_FORMULA);
28 case ICONSET:
29 return ScGlobal::GetRscString(STR_COND_ICONSET);
30 case DATE:
31 return ScGlobal::GetRscString(STR_COND_DATE);
32 default:
33 break;
36 return OUString("");
39 OUString getExpression(sal_Int32 nIndex)
41 switch(nIndex)
43 case 0:
44 return OUString("=");
45 case 1:
46 return OUString("<");
47 case 2:
48 return OUString(">");
49 case 3:
50 return OUString("<=");
51 case 4:
52 return OUString(">=");
53 case 5:
54 return OUString("!=");
55 case 6:
56 return ScGlobal::GetRscString(STR_COND_BETWEEN);
57 case 7:
58 return ScGlobal::GetRscString(STR_COND_NOTBETWEEN);
59 case 8:
60 return ScGlobal::GetRscString(STR_COND_DUPLICATE);
61 case 9:
62 return ScGlobal::GetRscString(STR_COND_UNIQUE);
63 case 10:
64 assert(false);
65 case 11:
66 return ScGlobal::GetRscString(STR_COND_TOP10);
67 case 12:
68 return ScGlobal::GetRscString(STR_COND_BOTTOM10);
69 case 13:
70 return ScGlobal::GetRscString(STR_COND_TOP_PERCENT);
71 case 14:
72 return ScGlobal::GetRscString(STR_COND_BOTTOM_PERCENT);
73 case 15:
74 return ScGlobal::GetRscString(STR_COND_ABOVE_AVERAGE);
75 case 16:
76 return ScGlobal::GetRscString(STR_COND_BELOW_AVERAGE);
77 case 17:
78 return ScGlobal::GetRscString(STR_COND_ABOVE_EQUAL_AVERAGE);
79 case 18:
80 return ScGlobal::GetRscString(STR_COND_BELOW_EQUAL_AVERAGE);
81 case 19:
82 return ScGlobal::GetRscString(STR_COND_ERROR);
83 case 20:
84 return ScGlobal::GetRscString(STR_COND_NOERROR);
85 case 21:
86 return ScGlobal::GetRscString(STR_COND_BEGINS_WITH);
87 case 22:
88 return ScGlobal::GetRscString(STR_COND_ENDS_WITH);
89 case 23:
90 return ScGlobal::GetRscString(STR_COND_CONTAINS);
91 case 24:
92 return ScGlobal::GetRscString(STR_COND_NOT_CONTAINS);
94 return OUString();
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);
103 assert(false);
104 return OUString();
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));
123 aBuffer.append(" ");
124 aBuffer.append(pEntry->GetExpression(rPos, 0));
126 else
128 aBuffer.append(getTextForType(CONDITION));
129 aBuffer.append(" ");
130 aBuffer.append(getExpression(static_cast<sal_Int32>(eMode)));
131 aBuffer.append(" ");
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));
145 break;
146 case condformat::DATABAR:
147 aBuffer.append(getTextForType(DATABAR));
148 break;
149 case condformat::COLORSCALE:
150 aBuffer.append(getTextForType(COLORSCALE));
151 break;
152 case condformat::ICONSET:
153 aBuffer.append(getTextForType(ICONSET));
154 break;
155 case condformat::DATE:
157 aBuffer.append(getTextForType(DATE));
158 aBuffer.append(" ");
159 sal_Int32 nDateEntry = static_cast<sal_Int32>(static_cast<const ScCondDateFormatEntry*>(rFormat.GetEntry(0))->GetDateType());
160 aBuffer.append(getDateString(nDateEntry));
162 break;
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));
172 aBuffer.append(" ");
173 if(eType == CONDITION)
175 // workaround missing FORMULA option in the conditions case
176 // FORMULA is handled later
177 if(nIndex > 9)
178 ++nIndex;
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: */