Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <sfx2/objsh.hxx>
30 : : #include <svl/smplhint.hxx>
31 : : #include <svl/zforlist.hxx>
32 : :
33 : : #include "cellform.hxx"
34 : : #include "cell.hxx"
35 : : #include "document.hxx"
36 : : #include "formula/errorcodes.hxx"
37 : : #include "sc.hrc"
38 : :
39 : : // STATIC DATA -----------------------------------------------------------
40 : :
41 : : // Err527 Workaround
42 : : const ScFormulaCell* pLastFormulaTreeTop = 0;
43 : :
44 : : // -----------------------------------------------------------------------
45 : :
46 : 71362 : void ScCellFormat::GetString( ScBaseCell* pCell, sal_uLong nFormat, rtl::OUString& rString,
47 : : Color** ppColor, SvNumberFormatter& rFormatter,
48 : : sal_Bool bNullVals,
49 : : sal_Bool bFormula,
50 : : ScForceTextFmt eForceTextFmt,
51 : : bool bUseStarFormat )
52 : : {
53 : 71362 : *ppColor = NULL;
54 [ - + ]: 71362 : if (&rFormatter==NULL)
55 : : {
56 : 0 : rString = rtl::OUString();
57 : 71362 : return;
58 : : }
59 : :
60 : 71362 : CellType eType = pCell->GetCellType();
61 [ + + + + : 71362 : switch(eType)
+ ]
62 : : {
63 : : case CELLTYPE_STRING:
64 : : {
65 : 17326 : rtl::OUString aCellString = ((ScStringCell*)pCell)->GetString();
66 [ + - ]: 17326 : rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor );
67 : : }
68 : 17326 : break;
69 : : case CELLTYPE_EDIT:
70 : : {
71 [ + - ]: 652 : rtl::OUString aCellString = ((ScEditCell*)pCell)->GetString();
72 [ + - ]: 652 : rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor );
73 : : }
74 : 652 : break;
75 : : case CELLTYPE_VALUE:
76 : : {
77 : 51418 : double nValue = ((ScValueCell*)pCell)->GetValue();
78 [ # # ][ - + ]: 51418 : if ( !bNullVals && nValue == 0.0 )
79 : 0 : rString = rtl::OUString();
80 : : else
81 : : {
82 [ + + ]: 51418 : if( eForceTextFmt == ftCheck )
83 : : {
84 [ + + ][ + - ]: 19834 : if( nFormat && rFormatter.IsTextFormat( nFormat ) )
[ - + ][ - + ]
85 : 0 : eForceTextFmt = ftForce;
86 : : }
87 [ - + ]: 51418 : if( eForceTextFmt == ftForce )
88 : : {
89 : 0 : rtl::OUString aTemp;
90 [ # # ]: 0 : rFormatter.GetOutputString( nValue, 0, aTemp, ppColor );
91 [ # # ]: 0 : rFormatter.GetOutputString( aTemp, nFormat, rString, ppColor );
92 : : }
93 : : else
94 [ + - ]: 51418 : rFormatter.GetOutputString( nValue, nFormat, rString, ppColor, bUseStarFormat );
95 : : }
96 : : }
97 : 51418 : break;
98 : : case CELLTYPE_FORMULA:
99 : : {
100 [ + - ]: 1962 : ScFormulaCell* pFCell = (ScFormulaCell*)pCell;
101 [ - + ]: 1962 : if ( bFormula )
102 : : {
103 : 0 : pFCell->GetFormula( rString );
104 : : }
105 : : else
106 : : {
107 : : // A macro started from the interpreter, which has
108 : : // access to Formular Cells, becomes a CellText, even if
109 : : // that triggers further interpretation, except if those
110 : : // cells are already being interpreted.
111 : : // IdleCalc generally doesn't trigger futher interpretation,
112 : : // as not to get Err522 (circular).
113 [ - + # # : 1962 : if ( pFCell->GetDocument()->IsInInterpreter() &&
# # ][ - + ]
114 : 0 : (!pFCell->GetDocument()->GetMacroInterpretLevel()
115 : 0 : || pFCell->IsRunning()) )
116 : : {
117 : 0 : rString = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("..."));
118 : : }
119 : : else
120 : : {
121 : 1962 : sal_uInt16 nErrCode = pFCell->GetErrCode();
122 : :
123 : : // get the number format only after interpretation (GetErrCode):
124 [ + + ]: 1962 : if ( (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
125 : : nFormat = pFCell->GetStandardFormat( rFormatter,
126 : 1566 : nFormat );
127 : :
128 [ + + ]: 1962 : if (nErrCode != 0)
129 [ + - ]: 190 : rString = ScGlobal::GetErrorString(nErrCode);
130 [ - + ]: 1772 : else if ( pFCell->IsEmptyDisplayedAsString() )
131 : 0 : rString = rtl::OUString();
132 [ + + ]: 1772 : else if ( pFCell->IsValue() )
133 : : {
134 [ + - ]: 1505 : double fValue = pFCell->GetValue();
135 [ - + ][ # # ]: 1505 : if ( !bNullVals && fValue == 0.0 )
136 : 0 : rString = rtl::OUString();
137 : : else
138 [ + - ]: 1505 : rFormatter.GetOutputString( fValue, nFormat, rString, ppColor );
139 : : }
140 : : else
141 : : {
142 [ + - ]: 267 : rtl::OUString aCellString = pFCell->GetString();
143 [ + - ]: 267 : rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor );
144 : : }
145 : : }
146 : : }
147 : : }
148 : 1962 : break;
149 : : default:
150 : 4 : rString = rtl::OUString();
151 : 4 : break;
152 : : }
153 : : }
154 : :
155 : 1011 : void ScCellFormat::GetInputString( ScBaseCell* pCell, sal_uLong nFormat, rtl::OUString& rString,
156 : : SvNumberFormatter& rFormatter )
157 : : {
158 [ - + ]: 1011 : if (&rFormatter==NULL)
159 : : {
160 : 0 : rString = rtl::OUString();
161 : 1011 : return;
162 : : }
163 : :
164 [ + - ]: 1011 : String aString = rString;
165 : 1011 : CellType eType = pCell->GetCellType();
166 [ + - + + : 1011 : switch(eType)
- ]
167 : : {
168 : : case CELLTYPE_STRING:
169 : : {
170 [ + - ]: 785 : aString = ((ScStringCell*)pCell)->GetString();
171 : : }
172 : 785 : break;
173 : : case CELLTYPE_EDIT:
174 : : {
175 [ # # ][ # # ]: 0 : aString = ((ScEditCell*)pCell)->GetString();
176 : : }
177 : 0 : break;
178 : : case CELLTYPE_VALUE:
179 : : {
180 : 190 : double nValue = ((ScValueCell*)pCell)->GetValue();
181 [ + - ]: 190 : rFormatter.GetInputLineString( nValue, nFormat, aString );
182 : : }
183 : 190 : break;
184 : : case CELLTYPE_FORMULA:
185 : : {
186 [ + - ][ + - ]: 36 : if (((ScFormulaCell*)pCell)->IsEmptyDisplayedAsString())
[ - + ]
187 : : {
188 [ # # ]: 0 : aString.Erase();
189 : : }
190 [ + - ][ + - ]: 36 : else if (((ScFormulaCell*)pCell)->IsValue())
[ + + ]
191 : : {
192 [ + - ][ + - ]: 15 : double nValue = ((ScFormulaCell*)pCell)->GetValue();
193 [ + - ]: 15 : rFormatter.GetInputLineString( nValue, nFormat, aString );
194 : : }
195 : : else
196 : : {
197 [ + - ][ + - ]: 21 : aString = ((ScFormulaCell*)pCell)->GetString();
[ + - ]
198 : : }
199 : :
200 [ + - ][ + - ]: 36 : sal_uInt16 nErrCode = ((ScFormulaCell*)pCell)->GetErrCode();
201 [ - + ]: 36 : if (nErrCode != 0)
202 : : {
203 [ # # ]: 0 : aString.Erase();
204 : : }
205 : : }
206 : 36 : break;
207 : : default:
208 [ # # ]: 0 : aString.Erase();
209 : 0 : break;
210 : : }
211 [ + - ][ + - ]: 1011 : rString = aString;
212 : : }
213 : :
214 : :
215 : :
216 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|