LCOV - code coverage report
Current view: top level - sc/source/core/tool - chartpos.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 221 295 74.9 %
Date: 2014-04-11 Functions: 9 14 64.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include "chartpos.hxx"
      21             : #include "document.hxx"
      22             : #include "rechead.hxx"
      23             : #include <boost/scoped_array.hpp>
      24             : 
      25             : namespace
      26             : {
      27         276 :     bool lcl_hasValueDataButNoDates( ScDocument* pDocument, SCCOL nCol, SCROW nRow, SCTAB nTab )
      28             :     {
      29         276 :         bool bReturn = false;
      30         276 :         if (pDocument->HasValueData( nCol, nRow, nTab ))
      31             :         {
      32             :             //treat dates like text #i25706#
      33          13 :             sal_uInt32 nNumberFormat = pDocument->GetNumberFormat( ScAddress( nCol, nRow, nTab ) );
      34          13 :             short nType = pDocument->GetFormatTable()->GetType(nNumberFormat);
      35          13 :             bool bIsDate = (nType & NUMBERFORMAT_DATE);
      36          13 :             bReturn = !bIsDate;
      37             :         }
      38         276 :         return bReturn;
      39             :     }
      40             : }
      41             : 
      42           0 : ScChartPositioner::ScChartPositioner( ScDocument* pDoc, SCTAB nTab,
      43             :                     SCCOL nStartColP, SCROW nStartRowP, SCCOL nEndColP, SCROW nEndRowP) :
      44             :         pDocument( pDoc ),
      45             :         pPositionMap( NULL ),
      46             :         eGlue( SC_CHARTGLUE_NA ),
      47             :         nStartCol(0),
      48             :         nStartRow(0),
      49             :         bColHeaders( false ),
      50             :         bRowHeaders( false ),
      51           0 :         bDummyUpperLeft( false )
      52             : {
      53           0 :     SetRangeList( ScRange( nStartColP, nStartRowP, nTab, nEndColP, nEndRowP, nTab ) );
      54           0 :     CheckColRowHeaders();
      55           0 : }
      56             : 
      57          26 : ScChartPositioner::ScChartPositioner( ScDocument* pDoc, const ScRangeListRef& rRangeList ) :
      58             :         aRangeListRef( rRangeList ),
      59             :         pDocument( pDoc ),
      60             :         pPositionMap( NULL ),
      61             :         eGlue( SC_CHARTGLUE_NA ),
      62             :         nStartCol(0),
      63             :         nStartRow(0),
      64             :         bColHeaders( false ),
      65             :         bRowHeaders( false ),
      66          26 :         bDummyUpperLeft( false )
      67             : {
      68          26 :     if ( aRangeListRef.Is() )
      69          26 :         CheckColRowHeaders();
      70          26 : }
      71             : 
      72           0 : ScChartPositioner::ScChartPositioner( const ScChartPositioner& rPositioner ) :
      73             :         aRangeListRef( rPositioner.aRangeListRef ),
      74             :         pDocument(rPositioner.pDocument),
      75             :         pPositionMap( NULL ),
      76             :         eGlue(rPositioner.eGlue),
      77             :         nStartCol(rPositioner.nStartCol),
      78             :         nStartRow(rPositioner.nStartRow),
      79             :         bColHeaders(rPositioner.bColHeaders),
      80             :         bRowHeaders(rPositioner.bRowHeaders),
      81           0 :         bDummyUpperLeft( rPositioner.bDummyUpperLeft )
      82             : {
      83           0 : }
      84             : 
      85          52 : ScChartPositioner::~ScChartPositioner()
      86             : {
      87          26 :     delete pPositionMap;
      88          26 : }
      89             : 
      90           0 : bool ScChartPositioner::operator==(const ScChartPositioner& rCmp) const
      91             : {
      92           0 :     return bColHeaders == rCmp.bColHeaders
      93           0 :         && bRowHeaders == rCmp.bRowHeaders
      94           0 :         && *aRangeListRef == *rCmp.aRangeListRef;
      95             : }
      96             : 
      97           0 : void ScChartPositioner::SetRangeList( const ScRange& rRange )
      98             : {
      99           0 :     aRangeListRef = new ScRangeList;
     100           0 :     aRangeListRef->Append( rRange );
     101           0 :     InvalidateGlue();
     102           0 : }
     103             : 
     104          44 : void ScChartPositioner::GlueState()
     105             : {
     106          44 :     if ( eGlue != SC_CHARTGLUE_NA )
     107          47 :         return;
     108          26 :     bDummyUpperLeft = false;
     109             :     ScRange* pR;
     110          26 :     if ( aRangeListRef->size() <= 1 )
     111             :     {
     112          11 :         if (  !aRangeListRef->empty() )
     113             :         {
     114          11 :             pR = aRangeListRef->front();
     115          11 :             if ( pR->aStart.Tab() == pR->aEnd.Tab() )
     116          11 :                 eGlue = SC_CHARTGLUE_NONE;
     117             :             else
     118           0 :                 eGlue = SC_CHARTGLUE_COLS;  // several tables column by column
     119          11 :             nStartCol = pR->aStart.Col();
     120          11 :             nStartRow = pR->aStart.Row();
     121             :         }
     122             :         else
     123             :         {
     124           0 :             InvalidateGlue();
     125           0 :             nStartCol = 0;
     126           0 :             nStartRow = 0;
     127             :         }
     128          11 :         return;
     129             :     }
     130             : 
     131          15 :     pR = aRangeListRef->front();
     132          15 :     nStartCol = pR->aStart.Col();
     133          15 :     nStartRow = pR->aStart.Row();
     134             :     SCCOL nMaxCols, nEndCol;
     135             :     SCROW nMaxRows, nEndRow;
     136          15 :     nMaxCols = nEndCol = 0;
     137          15 :     nMaxRows = nEndRow = 0;
     138             : 
     139             :     // <= so 1 extra pass after last item
     140          75 :     for ( size_t i = 1, nRanges = aRangeListRef->size(); i <= nRanges; ++i )
     141             :     {   // detect spanning/surrounding area etc.
     142             :         SCCOLROW nTmp, n1, n2;
     143          60 :         if ( (n1 = pR->aStart.Col()) < nStartCol ) nStartCol = static_cast<SCCOL>(n1  );
     144          60 :         if ( (n2 = pR->aEnd.Col()  ) > nEndCol   ) nEndCol   = static_cast<SCCOL>(n2  );
     145          60 :         if ( (nTmp = n2 - n1 + 1   ) > nMaxCols  ) nMaxCols  = static_cast<SCCOL>(nTmp);
     146          60 :         if ( (n1 = pR->aStart.Row()) < nStartRow ) nStartRow = static_cast<SCROW>(n1  );
     147          60 :         if ( (n2 = pR->aEnd.Row()  ) > nEndRow   ) nEndRow   = static_cast<SCROW>(n2  );
     148          60 :         if ( (nTmp = n2 - n1 + 1   ) > nMaxRows  ) nMaxRows  = static_cast<SCROW>(nTmp);
     149             : 
     150             :         // in last pass; i = nRanges so don't use at()
     151          60 :         if ( i < nRanges )
     152          45 :             pR = (*aRangeListRef)[i];
     153             :     }
     154          15 :     SCCOL nC = nEndCol - nStartCol + 1;
     155          15 :     if ( nC == 1 )
     156             :     {
     157           0 :         eGlue = SC_CHARTGLUE_ROWS;
     158           0 :         return;
     159             :     }
     160          15 :     SCROW nR = nEndRow - nStartRow + 1;
     161          15 :     if ( nR == 1 )
     162             :     {
     163           0 :         eGlue = SC_CHARTGLUE_COLS;
     164           0 :         return;
     165             :     }
     166          15 :     sal_uLong nCR = (sal_uLong)nC * nR;
     167             : 
     168             :     /*
     169             :     TODO:
     170             :     First do it simple without bit masking. A maximum of 8MB could be allocated
     171             :     this way (256 Cols x 32000 Rows). That could be reduced to 2MB by
     172             :     using 2 Bits per entry, but it is faster this way.
     173             :     Another optimization would be to store only used rows/columns in the array, but
     174             :     would mean another iteration of the RangeList indirect access to the array. */
     175             : 
     176          15 :     const sal_uInt8 nHole = 0;
     177          15 :     const sal_uInt8 nOccu = 1;
     178          15 :     const sal_uInt8 nFree = 2;
     179          15 :     const sal_uInt8 nGlue = 3;
     180             :     sal_uInt8* p;
     181          15 :     boost::scoped_array<sal_uInt8> pA(new sal_uInt8[ nCR ]);
     182          15 :     memset( pA.get(), 0, nCR * sizeof(sal_uInt8) );
     183             : 
     184             :     SCCOL nCol, nCol1, nCol2;
     185             :     SCROW nRow, nRow1, nRow2;
     186          75 :     for ( size_t i = 0, nRanges = aRangeListRef->size(); i < nRanges; ++i )
     187             :     {   // mark selections as used in 2D
     188          60 :         pR = (*aRangeListRef)[i];
     189          60 :         nCol1 = pR->aStart.Col() - nStartCol;
     190          60 :         nCol2 = pR->aEnd.Col() - nStartCol;
     191          60 :         nRow1 = pR->aStart.Row() - nStartRow;
     192          60 :         nRow2 = pR->aEnd.Row() - nStartRow;
     193         180 :         for ( nCol = nCol1; nCol <= nCol2; nCol++ )
     194             :         {
     195         120 :             p = pA.get() + (sal_uLong)nCol * nR + nRow1;
     196         480 :             for ( nRow = nRow1; nRow <= nRow2; nRow++, p++ )
     197         360 :                 *p = nOccu;
     198             :         }
     199             :     }
     200          15 :     sal_Bool bGlue = sal_True;
     201             : 
     202          15 :     sal_Bool bGlueCols = false;
     203          60 :     for ( nCol = 0; bGlue && nCol < nC; nCol++ )
     204             :     {   // iterate columns and try to mark as unused
     205          45 :         p = pA.get() + (sal_uLong)nCol * nR;
     206         105 :         for ( nRow = 0; bGlue && nRow < nR; nRow++, p++ )
     207             :         {
     208          60 :             if ( *p == nOccu )
     209             :             {   // If there's one right in the middle, we can't combine.
     210             :                 // If it were at the edge, we could combine, if in this Column
     211             :                 // in every set line, one is set.
     212          45 :                 if ( nRow > 0 && nCol > 0 )
     213          15 :                     bGlue = false; // nCol==0 can be DummyUpperLeft
     214             :                 else
     215          30 :                     nRow = nR;
     216             :             }
     217             :             else
     218          15 :                 *p = nFree;
     219             :         }
     220          45 :         if ( bGlue && *(p = (pA.get() + ((((sal_uLong)nCol+1) * nR) - 1))) == nFree )
     221             :         {   // mark column as totally unused
     222           0 :             *p = nGlue;
     223           0 :             bGlueCols = sal_True; // one unused column at least
     224             :         }
     225             :     }
     226             : 
     227          15 :     sal_Bool bGlueRows = false;
     228          15 :     for ( nRow = 0; bGlue && nRow < nR; nRow++ )
     229             :     {   // iterate rows and try to mark as unused
     230           0 :         p = pA.get() + nRow;
     231           0 :         for ( nCol = 0; bGlue && nCol < nC; nCol++, p+=nR )
     232             :         {
     233           0 :             if ( *p == nOccu )
     234             :             {
     235           0 :                 if ( nCol > 0 && nRow > 0 )
     236           0 :                     bGlue = false; // nRow==0 can be DummyUpperLeft
     237             :                 else
     238           0 :                     nCol = nC;
     239             :             }
     240             :             else
     241           0 :                 *p = nFree;
     242             :         }
     243           0 :         if ( bGlue && *(p = (pA.get() + ((((sal_uLong)nC-1) * nR) + nRow))) == nFree )
     244             :         {   // mark row as totally unused
     245           0 :             *p = nGlue;
     246           0 :             bGlueRows = sal_True; // one unused row at least
     247             :         }
     248             :     }
     249             : 
     250             :     // If n=1: The upper left corner could be automagically pulled in for labeling
     251          15 :     p = pA.get() + 1;
     252          15 :     for ( sal_uLong n = 1; bGlue && n < nCR; n++, p++ )
     253             :     {   // An untouched field means we could neither reach it through rows nor columns,
     254             :         // thus we can't combine anything
     255           0 :         if ( *p == nHole )
     256           0 :             bGlue = false;
     257             :     }
     258          15 :     if ( bGlue )
     259             :     {
     260           0 :         if ( bGlueCols && bGlueRows )
     261           0 :             eGlue = SC_CHARTGLUE_BOTH;
     262           0 :         else if ( bGlueRows )
     263           0 :             eGlue = SC_CHARTGLUE_ROWS;
     264             :         else
     265           0 :             eGlue = SC_CHARTGLUE_COLS;
     266           0 :         if ( pA[0] != nOccu )
     267           0 :             bDummyUpperLeft = true;
     268             :     }
     269             :     else
     270             :     {
     271          15 :         eGlue = SC_CHARTGLUE_NONE;
     272          15 :     }
     273             : }
     274             : 
     275          26 : void ScChartPositioner::CheckColRowHeaders()
     276             : {
     277             :     SCCOL nCol1, nCol2, iCol;
     278             :     SCROW nRow1, nRow2, iRow;
     279             :     SCTAB nTab1, nTab2;
     280             : 
     281          26 :     sal_Bool bColStrings = sal_True;
     282          26 :     sal_Bool bRowStrings = sal_True;
     283          26 :     GlueState();
     284          26 :     if ( aRangeListRef->size() == 1 )
     285             :     {
     286          11 :         aRangeListRef->front()->GetVars( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
     287          11 :         if ( nCol1 > nCol2 || nRow1 > nRow2 )
     288           0 :             bColStrings = bRowStrings = false;
     289             :         else
     290             :         {
     291          55 :             for (iCol=nCol1; iCol<=nCol2 && bColStrings; iCol++)
     292             :             {
     293          44 :                 if (lcl_hasValueDataButNoDates( pDocument, iCol, nRow1, nTab1 ))
     294           0 :                         bColStrings = false;
     295             :             }
     296          66 :             for (iRow=nRow1; iRow<=nRow2 && bRowStrings; iRow++)
     297             :             {
     298          55 :                 if (lcl_hasValueDataButNoDates( pDocument, nCol1, iRow, nTab1 ))
     299           0 :                         bRowStrings = false;
     300             :             }
     301             :         }
     302             :     }
     303             :     else
     304             :     {
     305          15 :         sal_Bool bVert = (eGlue == SC_CHARTGLUE_NONE || eGlue == SC_CHARTGLUE_ROWS);
     306          69 :         for ( size_t i = 0, nRanges = aRangeListRef->size();
     307          56 :               (i < nRanges) && (bColStrings || bRowStrings);
     308             :               ++i
     309             :             )
     310             :         {
     311          54 :             ScRange* pR = (*aRangeListRef)[i];
     312          54 :             pR->GetVars( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
     313          54 :             sal_Bool bTopRow = (nRow1 == nStartRow);
     314          54 :             if ( bRowStrings && (bVert || nCol1 == nStartCol) )
     315             :             {   // NONE or ROWS: RowStrings in every selection possible
     316             :                 // COLS or BOTH: only from first column
     317          54 :                 if ( nCol1 <= nCol2 )
     318         203 :                     for (iRow=nRow1; iRow<=nRow2 && bRowStrings; iRow++)
     319             :                     {
     320         149 :                         if (lcl_hasValueDataButNoDates( pDocument, nCol1, iRow, nTab1 ))
     321          11 :                                 bRowStrings = false;
     322             :                     }
     323             :             }
     324          54 :             if ( bColStrings && bTopRow )
     325             :             {   // ColStrings only from first row
     326          15 :                 if ( nRow1 <= nRow2 )
     327          43 :                     for (iCol=nCol1; iCol<=nCol2 && bColStrings; iCol++)
     328             :                     {
     329          28 :                         if (lcl_hasValueDataButNoDates( pDocument, iCol, nRow1, nTab1 ))
     330           2 :                                 bColStrings = false;
     331             :                     }
     332             :             }
     333             :         }
     334             :     }
     335          26 :     bColHeaders = bColStrings;
     336          26 :     bRowHeaders = bRowStrings;
     337          26 : }
     338             : 
     339         288 : const ScChartPositionMap* ScChartPositioner::GetPositionMap()
     340             : {
     341         288 :     CreatePositionMap();
     342         288 :     return pPositionMap;
     343             : }
     344             : 
     345             : 
     346         288 : void ScChartPositioner::CreatePositionMap()
     347             : {
     348         288 :     if ( eGlue == SC_CHARTGLUE_NA && pPositionMap )
     349             :     {
     350           0 :         delete pPositionMap;
     351           0 :         pPositionMap = NULL;
     352             :     }
     353             : 
     354         288 :     if ( pPositionMap )
     355         558 :         return ;
     356             : 
     357          18 :     SCSIZE nColAdd = bRowHeaders ? 1 : 0;
     358          18 :     SCSIZE nRowAdd = bColHeaders ? 1 : 0;
     359             : 
     360             :     SCCOL nCol, nCol1, nCol2;
     361             :     SCROW nRow, nRow1, nRow2;
     362             :     SCTAB nTab, nTab1, nTab2;
     363             : 
     364             : 
     365             :     //  real size (without hidden rows/columns)
     366             : 
     367             : 
     368          18 :     SCSIZE nColCount = 0;
     369          18 :     SCSIZE nRowCount = 0;
     370             : 
     371          18 :     GlueState();
     372             : 
     373          18 :     const sal_Bool bNoGlue = (eGlue == SC_CHARTGLUE_NONE);
     374          18 :     ColumnMap* pCols = new ColumnMap;
     375          18 :     SCROW nNoGlueRow = 0;
     376          81 :     for ( size_t i = 0, nRanges = aRangeListRef->size(); i < nRanges; ++i )
     377             :     {
     378          63 :         ScRange* pR = (*aRangeListRef)[i];
     379          63 :         pR->GetVars( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
     380         126 :         for ( nTab = nTab1; nTab <= nTab2; nTab++ )
     381             :         {
     382             :             // nTab in ColKey to allow to have the same col/row in another tabe
     383          63 :             sal_uLong nInsCol = (static_cast<sal_uLong>(nTab) << 16) | (bNoGlue ? 0 :
     384          63 :                     static_cast<sal_uLong>(nCol1));
     385         195 :             for ( nCol = nCol1; nCol <= nCol2; ++nCol, ++nInsCol )
     386             :             {
     387         132 :                 RowMap* pCol = NULL;
     388         132 :                 ColumnMap::const_iterator it = pCols->find( nInsCol );
     389         132 :                 if ( it == pCols->end() )
     390             :                 {
     391          42 :                     pCol = new RowMap;
     392          42 :                     pCols->insert( ColumnMap::value_type( nInsCol, pCol ) );
     393             :                 }
     394             :                 else
     395          90 :                     pCol = it->second;
     396             : 
     397             :                 // in other table a new ColKey already was created,
     398             :                 // the rows must be equal to be filled with Dummy
     399         132 :                 sal_uLong nInsRow = (bNoGlue ? nNoGlueRow : nRow1);
     400         552 :                 for ( nRow = nRow1; nRow <= nRow2; nRow++, nInsRow++ )
     401             :                 {
     402         420 :                     if ( pCol->find( nInsRow ) == pCol->end() )
     403             :                     {
     404         420 :                         pCol->insert( RowMap::value_type( nInsRow, new ScAddress( nCol, nRow, nTab ) ) );
     405             :                     }
     406             :                 }
     407             :             }
     408             :         }
     409             :         // For NoGlue: associated tables will be rendered as ColGlue
     410          63 :         nNoGlueRow += nRow2 - nRow1 + 1;
     411             :     }
     412             : 
     413             :     // count of data
     414          18 :     nColCount = static_cast< SCSIZE >( pCols->size());
     415          18 :     if ( !pCols->empty() )
     416             :     {
     417          18 :         RowMap* pCol = pCols->begin()->second;
     418          18 :         if ( bDummyUpperLeft )
     419           0 :             (*pCol)[ 0 ] = NULL; // Dummy for labeling
     420          18 :         nRowCount = static_cast< SCSIZE >( pCol->size());
     421             :     }
     422             :     else
     423           0 :         nRowCount = 0;
     424          18 :     if ( nColCount > 0 )
     425          18 :         nColCount -= nColAdd;
     426          18 :     if ( nRowCount > 0 )
     427          18 :         nRowCount -= nRowAdd;
     428             : 
     429          18 :     if ( nColCount==0 || nRowCount==0 )
     430             :     {   // create an entry without data
     431             :         RowMap* pCol;
     432           0 :         if ( !pCols->empty() )
     433           0 :             pCol = pCols->begin()->second;
     434             :         else
     435             :         {
     436           0 :             pCol = new RowMap;
     437           0 :             (*pCols)[ 0 ] = pCol;
     438             :         }
     439           0 :         nColCount = 1;
     440           0 :         if ( !pCol->empty() )
     441             :         {   // cannot be if nColCount==0 || nRowCount==0
     442           0 :             ScAddress* pPos = pCol->begin()->second;
     443           0 :             if ( pPos )
     444             :             {
     445           0 :                 sal_uLong nCurrentKey = pCol->begin()->first;
     446           0 :                 delete pPos;
     447           0 :                 (*pCol)[ nCurrentKey ] = NULL;
     448             :             }
     449             :         }
     450             :         else
     451           0 :             (*pCol)[ 0 ] = NULL;
     452           0 :         nRowCount = 1;
     453           0 :         nColAdd = 0;
     454           0 :         nRowAdd = 0;
     455             :     }
     456             :     else
     457             :     {
     458          18 :         if ( bNoGlue )
     459             :         {   // fill gaps with Dummies, first column is master
     460          18 :             RowMap* pFirstCol = pCols->begin()->second;
     461          18 :             sal_uLong nCount = pFirstCol->size();
     462          18 :             RowMap::const_iterator it1 = pFirstCol->begin();
     463         213 :             for ( sal_uLong n = 0; n < nCount; n++, ++it1 )
     464             :             {
     465         195 :                 sal_uLong nKey = it1->first;
     466         420 :                 for (ColumnMap::const_iterator it2 = ++pCols->begin(); it2 != pCols->end(); ++it2 )
     467         225 :                     it2->second->insert( RowMap::value_type( nKey, (ScAddress *)NULL )); // no data
     468             :             }
     469             :         }
     470             :     }
     471             : 
     472             :     pPositionMap = new ScChartPositionMap( static_cast<SCCOL>(nColCount), static_cast<SCROW>(nRowCount),
     473          18 :         static_cast<SCCOL>(nColAdd), static_cast<SCROW>(nRowAdd), *pCols );
     474             : 
     475             :     //  cleanup
     476          60 :     for (ColumnMap::const_iterator it = pCols->begin(); it != pCols->end(); ++it )
     477             :     {   // Only delete tables, not the ScAddress*!
     478          42 :         delete it->second;
     479             :     }
     480          18 :     delete pCols;
     481             : }
     482             : 
     483             : 
     484          18 : ScChartPositionMap::ScChartPositionMap( SCCOL nChartCols, SCROW nChartRows,
     485             :             SCCOL nColAdd, SCROW nRowAdd, ColumnMap& rCols ) :
     486          18 :         ppData( new ScAddress* [ nChartCols * nChartRows ] ),
     487          18 :         ppColHeader( new ScAddress* [ nChartCols ] ),
     488          18 :         ppRowHeader( new ScAddress* [ nChartRows ] ),
     489          18 :         nCount( (sal_uLong) nChartCols * nChartRows ),
     490             :         nColCount( nChartCols ),
     491          72 :         nRowCount( nChartRows )
     492             : {
     493             :     OSL_ENSURE( nColCount && nRowCount, "ScChartPositionMap without dimension" );
     494             : 
     495          18 :     ColumnMap::const_iterator pColIter = rCols.begin();
     496          18 :     RowMap* pCol1 = pColIter->second;
     497          18 :     RowMap::const_iterator pPos1Iter;
     498             : 
     499             :     // row header
     500          18 :     pPos1Iter = pCol1->begin();
     501          18 :     if ( nRowAdd )
     502          14 :         ++pPos1Iter;
     503          18 :     if ( nColAdd )
     504             :     {   // independent
     505          14 :         SCROW nRow = 0;
     506         147 :         for ( ; nRow < nRowCount && pPos1Iter != pCol1->end(); nRow++ )
     507             :         {
     508         133 :             ppRowHeader[ nRow ] = pPos1Iter->second;
     509         133 :             ++pPos1Iter;
     510             :         }
     511          14 :         for ( ; nRow < nRowCount; nRow++ )
     512           0 :             ppRowHeader[ nRow ] = NULL;
     513             :     }
     514             :     else
     515             :     {   // copy
     516           4 :         SCROW nRow = 0;
     517          52 :         for ( ; nRow < nRowCount && pPos1Iter != pCol1->end(); nRow++ )
     518             :         {
     519          48 :             ppRowHeader[ nRow ] = pPos1Iter->second ?
     520          48 :                 new ScAddress( *pPos1Iter->second ) : NULL;
     521          48 :             ++pPos1Iter;
     522             :         }
     523           4 :         for ( ; nRow < nRowCount; nRow++ )
     524           0 :             ppRowHeader[ nRow ] = NULL;
     525             :     }
     526          18 :     if ( nColAdd )
     527             :     {
     528          14 :         ++pColIter;
     529             :     }
     530             : 
     531             :     // data column by column and column-header
     532          18 :     sal_uLong nIndex = 0;
     533          46 :     for ( SCCOL nCol = 0; nCol < nColCount; nCol++ )
     534             :     {
     535          28 :         if ( pColIter != rCols.end() )
     536             :         {
     537          28 :             RowMap* pCol2 = pColIter->second;
     538          28 :             RowMap::const_iterator pPosIter = pCol2->begin();
     539          28 :             if ( pPosIter != pCol2->end() )
     540             :             {
     541          28 :                 if ( nRowAdd )
     542             :                 {
     543          20 :                     ppColHeader[ nCol ] = pPosIter->second; // independent
     544          20 :                     ++pPosIter;
     545             :                 }
     546             :                 else
     547           8 :                     ppColHeader[ nCol ] = pPosIter->second ?
     548           8 :                         new ScAddress( *pPosIter->second ) : NULL;
     549             :             }
     550             : 
     551          28 :             SCROW nRow = 0;
     552         281 :             for ( ; nRow < nRowCount && pPosIter != pCol2->end(); nRow++, nIndex++ )
     553             :             {
     554         253 :                 ppData[ nIndex ] = pPosIter->second;
     555         253 :                 ++pPosIter;
     556             :             }
     557          28 :             for ( ; nRow < nRowCount; nRow++, nIndex++ )
     558           0 :                 ppData[ nIndex ] = NULL;
     559             : 
     560          28 :             ++pColIter;
     561             :         }
     562             :         else
     563             :         {
     564           0 :             ppColHeader[ nCol ] = NULL;
     565           0 :             for ( SCROW nRow = 0; nRow < nRowCount; nRow++, nIndex++ )
     566             :             {
     567           0 :                 ppData[ nIndex ] = NULL;
     568             :             }
     569             :         }
     570             :     }
     571          18 : }
     572             : 
     573             : 
     574          18 : ScChartPositionMap::~ScChartPositionMap()
     575             : {
     576         271 :     for ( sal_uLong nIndex=0; nIndex < nCount; nIndex++ )
     577             :     {
     578         253 :         delete ppData[nIndex];
     579             :     }
     580          18 :     delete [] ppData;
     581             : 
     582             :     SCCOL j;
     583          46 :     for ( j=0; j < nColCount; j++ )
     584             :     {
     585          28 :         delete ppColHeader[j];
     586             :     }
     587          18 :     delete [] ppColHeader;
     588             :     SCROW i;
     589         199 :     for ( i=0; i < nRowCount; i++ )
     590             :     {
     591         181 :         delete ppRowHeader[i];
     592             :     }
     593          18 :     delete [] ppRowHeader;
     594          18 : }
     595             : 
     596             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10