re-enabled user-defined numeric fields for dBase export
[LibreOffice.git] / sc / source / core / data / global2.cxx
blob64c362236b94e374b78d0872c6f3e21a37ee4ebd
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/.
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 .
20 #include <sfx2/docfile.hxx>
21 #include <sfx2/objsh.hxx>
22 #include <unotools/pathoptions.hxx>
23 #include <unotools/useroptions.hxx>
24 #include <tools/urlobj.hxx>
25 #include <unotools/charclass.hxx>
26 #include <stdlib.h>
27 #include <ctype.h>
28 #include <unotools/syslocale.hxx>
30 #include "global.hxx"
31 #include "rangeutl.hxx"
32 #include "rechead.hxx"
33 #include "compiler.hxx"
34 #include "paramisc.hxx"
36 #include "sc.hrc"
37 #include "globstr.hrc"
39 using ::std::vector;
41 // -----------------------------------------------------------------------
43 //------------------------------------------------------------------------
44 // struct ScImportParam:
46 ScImportParam::ScImportParam() :
47 nCol1(0),
48 nRow1(0),
49 nCol2(0),
50 nRow2(0),
51 bImport(false),
52 bNative(false),
53 bSql(true),
54 nType(ScDbTable)
58 ScImportParam::ScImportParam( const ScImportParam& r ) :
59 nCol1 (r.nCol1),
60 nRow1 (r.nRow1),
61 nCol2 (r.nCol2),
62 nRow2 (r.nRow2),
63 bImport (r.bImport),
64 aDBName (r.aDBName),
65 aStatement (r.aStatement),
66 bNative (r.bNative),
67 bSql (r.bSql),
68 nType (r.nType)
72 ScImportParam::~ScImportParam()
76 ScImportParam& ScImportParam::operator=( const ScImportParam& r )
78 nCol1 = r.nCol1;
79 nRow1 = r.nRow1;
80 nCol2 = r.nCol2;
81 nRow2 = r.nRow2;
82 bImport = r.bImport;
83 aDBName = r.aDBName;
84 aStatement = r.aStatement;
85 bNative = r.bNative;
86 bSql = r.bSql;
87 nType = r.nType;
89 return *this;
92 bool ScImportParam::operator==( const ScImportParam& rOther ) const
94 return( nCol1 == rOther.nCol1 &&
95 nRow1 == rOther.nRow1 &&
96 nCol2 == rOther.nCol2 &&
97 nRow2 == rOther.nRow2 &&
98 bImport == rOther.bImport &&
99 aDBName == rOther.aDBName &&
100 aStatement == rOther.aStatement &&
101 bNative == rOther.bNative &&
102 bSql == rOther.bSql &&
103 nType == rOther.nType );
105 //! nQuerySh und pConnection sind gleich ?
108 //------------------------------------------------------------------------
109 // struct ScConsolidateParam:
111 ScConsolidateParam::ScConsolidateParam() :
112 ppDataAreas( NULL )
114 Clear();
117 //------------------------------------------------------------------------
119 ScConsolidateParam::ScConsolidateParam( const ScConsolidateParam& r ) :
120 nCol(r.nCol),nRow(r.nRow),nTab(r.nTab),
121 eFunction(r.eFunction),nDataAreaCount(0),
122 ppDataAreas( NULL ),
123 bByCol(r.bByCol),bByRow(r.bByRow),bReferenceData(r.bReferenceData)
125 if ( r.nDataAreaCount > 0 )
127 nDataAreaCount = r.nDataAreaCount;
128 ppDataAreas = new ScArea*[nDataAreaCount];
129 for ( sal_uInt16 i=0; i<nDataAreaCount; i++ )
130 ppDataAreas[i] = new ScArea( *(r.ppDataAreas[i]) );
134 //------------------------------------------------------------------------
136 ScConsolidateParam::~ScConsolidateParam()
138 ClearDataAreas();
141 //------------------------------------------------------------------------
143 void ScConsolidateParam::ClearDataAreas()
145 if ( ppDataAreas )
147 for ( sal_uInt16 i=0; i<nDataAreaCount; i++ )
148 delete ppDataAreas[i];
149 delete [] ppDataAreas;
150 ppDataAreas = NULL;
152 nDataAreaCount = 0;
155 //------------------------------------------------------------------------
157 void ScConsolidateParam::Clear()
159 ClearDataAreas();
161 nCol = 0;
162 nRow = 0;
163 nTab = 0;
164 bByCol = bByRow = bReferenceData = false;
165 eFunction = SUBTOTAL_FUNC_SUM;
168 //------------------------------------------------------------------------
170 ScConsolidateParam& ScConsolidateParam::operator=( const ScConsolidateParam& r )
172 nCol = r.nCol;
173 nRow = r.nRow;
174 nTab = r.nTab;
175 bByCol = r.bByCol;
176 bByRow = r.bByRow;
177 bReferenceData = r.bReferenceData;
178 eFunction = r.eFunction;
179 SetAreas( r.ppDataAreas, r.nDataAreaCount );
181 return *this;
184 //------------------------------------------------------------------------
186 sal_Bool ScConsolidateParam::operator==( const ScConsolidateParam& r ) const
188 sal_Bool bEqual = (nCol == r.nCol)
189 && (nRow == r.nRow)
190 && (nTab == r.nTab)
191 && (bByCol == r.bByCol)
192 && (bByRow == r.bByRow)
193 && (bReferenceData == r.bReferenceData)
194 && (nDataAreaCount == r.nDataAreaCount)
195 && (eFunction == r.eFunction);
197 if ( nDataAreaCount == 0 )
198 bEqual = bEqual && (ppDataAreas == NULL) && (r.ppDataAreas == NULL);
199 else
200 bEqual = bEqual && (ppDataAreas != NULL) && (r.ppDataAreas != NULL);
202 if ( bEqual && (nDataAreaCount > 0) )
203 for ( sal_uInt16 i=0; i<nDataAreaCount && bEqual; i++ )
204 bEqual = *(ppDataAreas[i]) == *(r.ppDataAreas[i]);
206 return bEqual;
209 //------------------------------------------------------------------------
211 void ScConsolidateParam::SetAreas( ScArea* const* ppAreas, sal_uInt16 nCount )
213 ClearDataAreas();
214 if ( ppAreas && nCount > 0 )
216 ppDataAreas = new ScArea*[nCount];
217 for ( sal_uInt16 i=0; i<nCount; i++ )
218 ppDataAreas[i] = new ScArea( *(ppAreas[i]) );
219 nDataAreaCount = nCount;
223 //------------------------------------------------------------------------
224 // struct ScSolveParam
226 ScSolveParam::ScSolveParam()
227 : pStrTargetVal( NULL )
231 //------------------------------------------------------------------------
233 ScSolveParam::ScSolveParam( const ScSolveParam& r )
234 : aRefFormulaCell ( r.aRefFormulaCell ),
235 aRefVariableCell( r.aRefVariableCell ),
236 pStrTargetVal ( r.pStrTargetVal
237 ? new String(*r.pStrTargetVal)
238 : NULL )
242 //------------------------------------------------------------------------
244 ScSolveParam::ScSolveParam( const ScAddress& rFormulaCell,
245 const ScAddress& rVariableCell,
246 const String& rTargetValStr )
247 : aRefFormulaCell ( rFormulaCell ),
248 aRefVariableCell( rVariableCell ),
249 pStrTargetVal ( new String(rTargetValStr) )
253 //------------------------------------------------------------------------
255 ScSolveParam::~ScSolveParam()
257 delete pStrTargetVal;
260 //------------------------------------------------------------------------
262 ScSolveParam& ScSolveParam::operator=( const ScSolveParam& r )
264 delete pStrTargetVal;
266 aRefFormulaCell = r.aRefFormulaCell;
267 aRefVariableCell = r.aRefVariableCell;
268 pStrTargetVal = r.pStrTargetVal
269 ? new String(*r.pStrTargetVal)
270 : NULL;
271 return *this;
274 //------------------------------------------------------------------------
276 sal_Bool ScSolveParam::operator==( const ScSolveParam& r ) const
278 sal_Bool bEqual = (aRefFormulaCell == r.aRefFormulaCell)
279 && (aRefVariableCell == r.aRefVariableCell);
281 if ( bEqual )
283 if ( !pStrTargetVal && !r.pStrTargetVal )
284 bEqual = sal_True;
285 else if ( !pStrTargetVal || !r.pStrTargetVal )
286 bEqual = false;
287 else if ( pStrTargetVal && r.pStrTargetVal )
288 bEqual = ( *pStrTargetVal == *(r.pStrTargetVal) );
291 return bEqual;
294 //------------------------------------------------------------------------
295 // struct ScTabOpParam
297 ScTabOpParam::ScTabOpParam( const ScTabOpParam& r )
298 : aRefFormulaCell ( r.aRefFormulaCell ),
299 aRefFormulaEnd ( r.aRefFormulaEnd ),
300 aRefRowCell ( r.aRefRowCell ),
301 aRefColCell ( r.aRefColCell ),
302 nMode ( r.nMode )
306 //------------------------------------------------------------------------
308 ScTabOpParam::ScTabOpParam( const ScRefAddress& rFormulaCell,
309 const ScRefAddress& rFormulaEnd,
310 const ScRefAddress& rRowCell,
311 const ScRefAddress& rColCell,
312 sal_uInt8 nMd)
313 : aRefFormulaCell ( rFormulaCell ),
314 aRefFormulaEnd ( rFormulaEnd ),
315 aRefRowCell ( rRowCell ),
316 aRefColCell ( rColCell ),
317 nMode ( nMd )
321 //------------------------------------------------------------------------
323 ScTabOpParam& ScTabOpParam::operator=( const ScTabOpParam& r )
325 aRefFormulaCell = r.aRefFormulaCell;
326 aRefFormulaEnd = r.aRefFormulaEnd;
327 aRefRowCell = r.aRefRowCell;
328 aRefColCell = r.aRefColCell;
329 nMode = r.nMode;
330 return *this;
333 //------------------------------------------------------------------------
335 sal_Bool ScTabOpParam::operator==( const ScTabOpParam& r ) const
337 return ( (aRefFormulaCell == r.aRefFormulaCell)
338 && (aRefFormulaEnd == r.aRefFormulaEnd)
339 && (aRefRowCell == r.aRefRowCell)
340 && (aRefColCell == r.aRefColCell)
341 && (nMode == r.nMode) );
344 String ScGlobal::GetAbsDocName( const String& rFileName,
345 SfxObjectShell* pShell )
347 String aAbsName;
348 if ( !pShell->HasName() )
349 { // maybe relative to document path working directory
350 INetURLObject aObj;
351 SvtPathOptions aPathOpt;
352 aObj.SetSmartURL( aPathOpt.GetWorkPath() );
353 aObj.setFinalSlash(); // it IS a path
354 bool bWasAbs = true;
355 aAbsName = aObj.smartRel2Abs( rFileName, bWasAbs ).GetMainURL(INetURLObject::NO_DECODE);
356 // returned string must be encoded because it's used directly to create SfxMedium
358 else
360 const SfxMedium* pMedium = pShell->GetMedium();
361 if ( pMedium )
363 bool bWasAbs = true;
364 aAbsName = pMedium->GetURLObject().smartRel2Abs( rFileName, bWasAbs ).GetMainURL(INetURLObject::NO_DECODE);
366 else
367 { // This can't happen, but ...
368 // just to be sure to have the same encoding
369 INetURLObject aObj;
370 aObj.SetSmartURL( aAbsName );
371 aAbsName = aObj.GetMainURL(INetURLObject::NO_DECODE);
374 return aAbsName;
377 String ScGlobal::GetDocTabName( const String& rFileName,
378 const String& rTabName )
380 String aDocTab(OUString('\''));
381 aDocTab += rFileName;
382 xub_StrLen nPos = 1;
383 while( (nPos = aDocTab.Search( '\'', nPos ))
384 != STRING_NOTFOUND )
385 { // escape Quotes
386 aDocTab.Insert( '\\', nPos );
387 nPos += 2;
389 aDocTab += '\'';
390 aDocTab += SC_COMPILER_FILE_TAB_SEP;
391 aDocTab += rTabName; // "'Doc'#Tab"
392 return aDocTab;
395 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */