summaryrefslogtreecommitdiff
path: root/binfilter/bf_sc/source/core/data/sc_pivot2.cxx
blob: d0382f6335fc75ed165b0621e4fff7f40542fc41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifdef _MSC_VER
#pragma hdrstop
#endif

#ifdef _MSC_VER
#pragma optimize("",off)
#endif
#ifdef _MSC_VER
#pragma optimize("q",off) // p-code off
#endif


#include "scitems.hxx"
#include <unotools/transliterationwrapper.hxx>

#include "globstr.hrc"
#include "rangeutl.hxx"
#include "pivot.hxx"
#include "rechead.hxx"
#include "refupdat.hxx"
#include "stlsheet.hxx"
namespace binfilter {


// STATIC DATA -----------------------------------------------------------

//--------------------------------------------------------------------------------------------------
// Hilfsmethoden von ScPivot
//--------------------------------------------------------------------------------------------------










//--------------------------------------------------------------------------------------------------

/*N*/ void ScPivot::GetParam( ScPivotParam& rParam, ScQueryParam& rQuery, ScArea& rSrcArea ) const
/*N*/ {
/*N*/   short nCount;
/*N*/   USHORT nDummy;
/*N*/   GetDestArea( rParam.nCol,rParam.nRow, nDummy,nDummy, rParam.nTab );
/*N*/
/*N*/   // Row und Col in der Bedeutung vertauscht:
/*N*/   GetRowFields( rParam.aColArr, nCount );
/*N*/   rParam.nColCount = (USHORT) nCount;
/*N*/   GetColFields( rParam.aRowArr, nCount );
/*N*/   rParam.nRowCount = (USHORT) nCount;
/*N*/   GetDataFields( rParam.aDataArr, nCount );
/*N*/   rParam.nDataCount = (USHORT) nCount;
/*N*/
/*N*/   rParam.bIgnoreEmptyRows  = GetIgnoreEmpty();
/*N*/   rParam.bDetectCategories = GetDetectCat();
/*N*/   rParam.bMakeTotalCol     = GetMakeTotalCol();
/*N*/   rParam.bMakeTotalRow     = GetMakeTotalRow();
/*N*/
/*N*/   GetQuery(rQuery);
/*N*/   GetSrcArea( rSrcArea.nColStart, rSrcArea.nRowStart,
/*N*/                       rSrcArea.nColEnd, rSrcArea.nRowEnd, rSrcArea.nTab );
/*N*/ }

/*N*/ void ScPivot::SetParam( const ScPivotParam& rParam, const ScQueryParam& rQuery,
/*N*/                           const ScArea& rSrcArea )
/*N*/ {
/*N*/   SetQuery( rQuery );
/*N*/   SetHeader( TRUE );
/*N*/   SetSrcArea( rSrcArea.nColStart, rSrcArea.nRowStart,
/*N*/                         rSrcArea.nColEnd, rSrcArea.nRowEnd, rSrcArea.nTab );
/*N*/   SetDestPos( rParam.nCol, rParam.nRow, rParam.nTab );
/*N*/   SetIgnoreEmpty( rParam.bIgnoreEmptyRows );
/*N*/   SetDetectCat( rParam.bDetectCategories );
/*N*/   SetMakeTotalCol( rParam.bMakeTotalCol );
/*N*/   SetMakeTotalRow( rParam.bMakeTotalRow );
/*N*/
/*N*/   // Row und Col in der Bedeutung vertauscht:
/*N*/   SetRowFields( rParam.aColArr, rParam.nColCount );
/*N*/   SetColFields( rParam.aRowArr, rParam.nRowCount );
/*N*/   SetDataFields( rParam.aDataArr, rParam.nDataCount );
/*N*/ }

/*N*/ DataObject*   ScPivot::Clone() const
/*N*/ {
/*N*/   return new ScPivot(*this);
/*N*/ }

//--------------------------------------------------------------------------------------------------
// PivotStrCollection
//--------------------------------------------------------------------------------------------------


/*N*/ short PivotStrCollection::Compare(DataObject* pKey1, DataObject* pKey2) const
/*N*/ {
/*N*/   DBG_ASSERT(pKey1&&pKey2,"0-Zeiger bei PivotStrCollection::Compare");
/*N*/
/*N*/   short nResult = 0;
/*N*/
/*N*/   TypedStrData& rData1 = (TypedStrData&)*pKey1;
/*N*/   TypedStrData& rData2 = (TypedStrData&)*pKey2;
/*N*/
/*N*/   if ( rData1.nStrType > rData2.nStrType )
/*N*/       nResult = 1;
/*N*/   else if ( rData1.nStrType < rData2.nStrType )
/*N*/       nResult = -1;
/*N*/   else if ( !rData1.nStrType /* && !rData2.nStrType */ )
/*N*/   {
/*?*/       // Zahlen vergleichen:
/*?*/
/*?*/       if ( rData1.nValue == rData2.nValue )
/*?*/           nResult = 0;
/*?*/       else if ( rData1.nValue < rData2.nValue )
/*?*/           nResult = -1;
/*?*/       else
/*?*/           nResult = 1;
/*N*/   }
/*N*/   else /* if ( rData1.nStrType && rData2.nStrType ) */
/*N*/   {
/*N*/       // Strings vergleichen:
/*N*/
/*N*/       if ( !pUserData )
/*N*/       {
/*N*/           nResult = (short) ScGlobal::pTransliteration->compareString(
/*N*/               rData1.aStrValue, rData2.aStrValue );
/*N*/       }
/*N*/   }
/*N*/
/*N*/   return nResult;
/*N*/ }

/*N*/ short PivotStrCollection::GetIndex(TypedStrData* pData) const
/*N*/ {
/*N*/   USHORT nIndex = 0;
/*N*/   if (!Search(pData, nIndex))
/*N*/       nIndex = 0;
/*N*/   return (short)nIndex;
/*N*/ }

//--------------------------------------------------------------------------------------------------
// PivotCollection
//--------------------------------------------------------------------------------------------------

/*N*/ String ScPivotCollection::CreateNewName( USHORT nMin ) const
/*N*/ {
/*N*/     String aBase( RTL_CONSTASCII_USTRINGPARAM("DataPilot") );
/*N*/   //! from Resource?
/*N*/
/*N*/   for (USHORT nAdd=0; nAdd<=nCount; nAdd++)   //  nCount+1 Versuche
/*N*/   {
/*N*/       String aNewName = aBase;
/*N*/       aNewName += String::CreateFromInt32( nMin + nAdd );
/*N*/       BOOL bFound = FALSE;
/*N*/       for (USHORT i=0; i<nCount && !bFound; i++)
/*N*/           if (((ScPivot*)pItems[i])->GetName() == aNewName)
/*N*/               bFound = TRUE;
/*N*/       if (!bFound)
/*N*/           return aNewName;            // freien Namen gefunden
/*N*/   }
/*N*/   return String();                    // sollte nicht vorkommen
/*N*/ }


/*N*/ BOOL ScPivotCollection::Load(SvStream& rStream)
/*N*/ {
/*N*/   BOOL bSuccess = TRUE;
/*N*/   USHORT nNewCount, i;
/*N*/   FreeAll();
/*N*/
/*N*/   ScMultipleReadHeader aHdr( rStream );
/*N*/
/*N*/   rStream >> nNewCount;
/*N*/   for (i=0; i<nNewCount && bSuccess; i++)
/*N*/   {
/*N*/       ScPivot* pPivot = new ScPivot( pDoc );
/*N*/       if (pPivot)
/*N*/       {
/*N*/           bSuccess = pPivot->Load(rStream, aHdr);
/*N*/           Insert( pPivot );
/*N*/       }
/*N*/       else
/*N*/           bSuccess = FALSE;
/*N*/   }
/*N*/
/*N*/   //  fuer alte Dateien: eindeutige Namen vergeben
/*N*/
/*N*/   if (bSuccess)
/*N*/       for (i=0; i<nCount; i++)
/*N*/           if (!((const ScPivot*)At(i))->GetName().Len())
/*N*/               ((ScPivot*)At(i))->SetName( CreateNewName() );
/*N*/
/*N*/   return bSuccess;
/*N*/ }

/*N*/ void ScPivotCollection::UpdateReference(UpdateRefMode eUpdateRefMode,
/*N*/                               USHORT nCol1, USHORT nRow1, USHORT nTab1,
/*N*/                               USHORT nCol2, USHORT nRow2, USHORT nTab2,
/*N*/                               short nDx, short nDy, short nDz )
/*N*/ {
/*N*/   for (USHORT i=0; i<nCount; i++)
/*N*/   {
/*?*/       USHORT theCol1;
/*?*/       USHORT theRow1;
/*?*/       USHORT theTab1;
/*?*/       USHORT theCol2;
/*?*/       USHORT theRow2;
/*?*/       USHORT theTab2;
/*?*/       ScRefUpdateRes eRes;
/*?*/       ScPivot* pPivot = (ScPivot*)pItems[i];
/*?*/
/*?*/       //  Source
/*?*/
/*?*/       pPivot->GetSrcArea( theCol1, theRow1, theCol2, theRow2, theTab1 );
/*?*/       theTab2 = theTab1;
/*?*/
/*?*/       eRes = ScRefUpdate::Update( pDoc, eUpdateRefMode,
/*?*/                                               nCol1,nRow1,nTab1, nCol2,nRow2,nTab2, nDx,nDy,nDz,
/*?*/                                               theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 );
/*?*/
/*?*/       if (eRes != UR_NOTHING)
/*?*/           pPivot->MoveSrcArea( theCol1, theRow1, theTab1 );
/*?*/
/*?*/       //  Dest
/*?*/
/*?*/       pPivot->GetDestArea( theCol1, theRow1, theCol2, theRow2, theTab1 );
/*?*/       theTab2 = theTab1;
/*?*/
/*?*/       eRes = ScRefUpdate::Update( pDoc, eUpdateRefMode,
/*?*/                                               nCol1,nRow1,nTab1, nCol2,nRow2,nTab2, nDx,nDy,nDz,
/*?*/                                               theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 );
/*?*/
/*?*/       if (eRes != UR_NOTHING)
/*?*/           pPivot->MoveDestArea( theCol1, theRow1, theTab1 );
/*N*/   }
/*N*/ }







}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */