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/.
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>
28 #include <unotools/syslocale.hxx>
31 #include "rangeutl.hxx"
32 #include "rechead.hxx"
33 #include "compiler.hxx"
34 #include "paramisc.hxx"
37 #include "globstr.hrc"
41 // -----------------------------------------------------------------------
43 //------------------------------------------------------------------------
44 // struct ScImportParam:
46 ScImportParam::ScImportParam() :
58 ScImportParam::ScImportParam( const ScImportParam
& r
) :
65 aStatement (r
.aStatement
),
72 ScImportParam::~ScImportParam()
76 ScImportParam
& ScImportParam::operator=( const ScImportParam
& r
)
84 aStatement
= r
.aStatement
;
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() :
117 //------------------------------------------------------------------------
119 ScConsolidateParam::ScConsolidateParam( const ScConsolidateParam
& r
) :
120 nCol(r
.nCol
),nRow(r
.nRow
),nTab(r
.nTab
),
121 eFunction(r
.eFunction
),nDataAreaCount(0),
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()
141 //------------------------------------------------------------------------
143 void ScConsolidateParam::ClearDataAreas()
147 for ( sal_uInt16 i
=0; i
<nDataAreaCount
; i
++ )
148 delete ppDataAreas
[i
];
149 delete [] ppDataAreas
;
155 //------------------------------------------------------------------------
157 void ScConsolidateParam::Clear()
164 bByCol
= bByRow
= bReferenceData
= false;
165 eFunction
= SUBTOTAL_FUNC_SUM
;
168 //------------------------------------------------------------------------
170 ScConsolidateParam
& ScConsolidateParam::operator=( const ScConsolidateParam
& r
)
177 bReferenceData
= r
.bReferenceData
;
178 eFunction
= r
.eFunction
;
179 SetAreas( r
.ppDataAreas
, r
.nDataAreaCount
);
184 //------------------------------------------------------------------------
186 sal_Bool
ScConsolidateParam::operator==( const ScConsolidateParam
& r
) const
188 sal_Bool bEqual
= (nCol
== r
.nCol
)
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
);
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
]);
209 //------------------------------------------------------------------------
211 void ScConsolidateParam::SetAreas( ScArea
* const* ppAreas
, sal_uInt16 nCount
)
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
)
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
)
274 //------------------------------------------------------------------------
276 sal_Bool
ScSolveParam::operator==( const ScSolveParam
& r
) const
278 sal_Bool bEqual
= (aRefFormulaCell
== r
.aRefFormulaCell
)
279 && (aRefVariableCell
== r
.aRefVariableCell
);
283 if ( !pStrTargetVal
&& !r
.pStrTargetVal
)
285 else if ( !pStrTargetVal
|| !r
.pStrTargetVal
)
287 else if ( pStrTargetVal
&& r
.pStrTargetVal
)
288 bEqual
= ( *pStrTargetVal
== *(r
.pStrTargetVal
) );
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
),
308 //------------------------------------------------------------------------
310 ScTabOpParam::ScTabOpParam( const ScRefAddress
& rFormulaCell
,
311 const ScRefAddress
& rFormulaEnd
,
312 const ScRefAddress
& rRowCell
,
313 const ScRefAddress
& rColCell
,
315 : aRefFormulaCell ( rFormulaCell
),
316 aRefFormulaEnd ( rFormulaEnd
),
317 aRefRowCell ( rRowCell
),
318 aRefColCell ( rColCell
),
323 //------------------------------------------------------------------------
325 ScTabOpParam
& ScTabOpParam::operator=( const ScTabOpParam
& r
)
327 aRefFormulaCell
= r
.aRefFormulaCell
;
328 aRefFormulaEnd
= r
.aRefFormulaEnd
;
329 aRefRowCell
= r
.aRefRowCell
;
330 aRefColCell
= r
.aRefColCell
;
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
)
350 if ( !pShell
->HasName() )
351 { // maybe relative to document path working directory
353 SvtPathOptions aPathOpt
;
354 aObj
.SetSmartURL( aPathOpt
.GetWorkPath() );
355 aObj
.setFinalSlash(); // it IS a path
357 aAbsName
= aObj
.smartRel2Abs( rFileName
, bWasAbs
).GetMainURL(INetURLObject::NO_DECODE
);
358 // returned string must be encoded because it's used directly to create SfxMedium
362 const SfxMedium
* pMedium
= pShell
->GetMedium();
366 aAbsName
= pMedium
->GetURLObject().smartRel2Abs( rFileName
, bWasAbs
).GetMainURL(INetURLObject::NO_DECODE
);
369 { // This can't happen, but ...
370 // just to be sure to have the same encoding
372 aObj
.SetSmartURL( aAbsName
);
373 aAbsName
= aObj
.GetMainURL(INetURLObject::NO_DECODE
);
379 OUString
ScGlobal::GetDocTabName( const OUString
& rFileName
,
380 const OUString
& rTabName
)
382 OUString
aDocTab('\'');
383 aDocTab
+= rFileName
;
385 while( (nPos
= aDocTab
.indexOf( '\'', nPos
)) != -1 )
387 aDocTab
= aDocTab
.replaceAt( nPos
, 0, "\\" );
391 aDocTab
+= OUString(SC_COMPILER_FILE_TAB_SEP
);
392 aDocTab
+= rTabName
; // "'Doc'#Tab"
396 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */