Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / data / global2.cxx
blobae5bdf92e56033ff01bd1b31636ec01ab04b7e05
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 OUString(*r.pStrTargetVal)
238 : NULL )
242 //------------------------------------------------------------------------
244 ScSolveParam::ScSolveParam( const ScAddress& rFormulaCell,
245 const ScAddress& rVariableCell,
246 const OUString& rTargetValStr )
247 : aRefFormulaCell ( rFormulaCell ),
248 aRefVariableCell( rVariableCell ),
249 pStrTargetVal ( new OUString(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 OUString(*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() : meMode(Column) {}
299 ScTabOpParam::ScTabOpParam( const ScTabOpParam& r )
300 : aRefFormulaCell ( r.aRefFormulaCell ),
301 aRefFormulaEnd ( r.aRefFormulaEnd ),
302 aRefRowCell ( r.aRefRowCell ),
303 aRefColCell ( r.aRefColCell ),
304 meMode(r.meMode)
308 //------------------------------------------------------------------------
310 ScTabOpParam::ScTabOpParam( const ScRefAddress& rFormulaCell,
311 const ScRefAddress& rFormulaEnd,
312 const ScRefAddress& rRowCell,
313 const ScRefAddress& rColCell,
314 Mode eMode )
315 : aRefFormulaCell ( rFormulaCell ),
316 aRefFormulaEnd ( rFormulaEnd ),
317 aRefRowCell ( rRowCell ),
318 aRefColCell ( rColCell ),
319 meMode(eMode)
323 //------------------------------------------------------------------------
325 ScTabOpParam& ScTabOpParam::operator=( const ScTabOpParam& r )
327 aRefFormulaCell = r.aRefFormulaCell;
328 aRefFormulaEnd = r.aRefFormulaEnd;
329 aRefRowCell = r.aRefRowCell;
330 aRefColCell = r.aRefColCell;
331 meMode = r.meMode;
332 return *this;
335 //------------------------------------------------------------------------
337 bool ScTabOpParam::operator==( const ScTabOpParam& r ) const
339 return ( (aRefFormulaCell == r.aRefFormulaCell)
340 && (aRefFormulaEnd == r.aRefFormulaEnd)
341 && (aRefRowCell == r.aRefRowCell)
342 && (aRefColCell == r.aRefColCell)
343 && (meMode == r.meMode) );
346 OUString ScGlobal::GetAbsDocName( const OUString& rFileName,
347 SfxObjectShell* pShell )
349 OUString aAbsName;
350 if ( !pShell->HasName() )
351 { // maybe relative to document path working directory
352 INetURLObject aObj;
353 SvtPathOptions aPathOpt;
354 aObj.SetSmartURL( aPathOpt.GetWorkPath() );
355 aObj.setFinalSlash(); // it IS a path
356 bool bWasAbs = true;
357 aAbsName = aObj.smartRel2Abs( rFileName, bWasAbs ).GetMainURL(INetURLObject::NO_DECODE);
358 // returned string must be encoded because it's used directly to create SfxMedium
360 else
362 const SfxMedium* pMedium = pShell->GetMedium();
363 if ( pMedium )
365 bool bWasAbs = true;
366 aAbsName = pMedium->GetURLObject().smartRel2Abs( rFileName, bWasAbs ).GetMainURL(INetURLObject::NO_DECODE);
368 else
369 { // This can't happen, but ...
370 // just to be sure to have the same encoding
371 INetURLObject aObj;
372 aObj.SetSmartURL( aAbsName );
373 aAbsName = aObj.GetMainURL(INetURLObject::NO_DECODE);
376 return aAbsName;
379 OUString ScGlobal::GetDocTabName( const OUString& rFileName,
380 const OUString& rTabName )
382 OUString aDocTab('\'');
383 aDocTab += rFileName;
384 sal_Int32 nPos = 1;
385 while( (nPos = aDocTab.indexOf( '\'', nPos )) != -1 )
386 { // escape Quotes
387 aDocTab = aDocTab.replaceAt( nPos, 0, "\\" );
388 nPos += 2;
390 aDocTab += "'";
391 aDocTab += OUString(SC_COMPILER_FILE_TAB_SEP);
392 aDocTab += rTabName; // "'Doc'#Tab"
393 return aDocTab;
396 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */