LCOV - code coverage report
Current view: top level - sw/source/uibase/table - swtablerep.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 78 1.3 %
Date: 2014-11-03 Functions: 2 5 40.0 %
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 <hintids.hxx>
      21             : #include <vcl/msgbox.hxx>
      22             : #include <svl/stritem.hxx>
      23             : #include <svl/intitem.hxx>
      24             : #include <editeng/keepitem.hxx>
      25             : #include <editeng/formatbreakitem.hxx>
      26             : #include <editeng/ulspitem.hxx>
      27             : #include <editeng/frmdiritem.hxx>
      28             : #include <svl/ctloptions.hxx>
      29             : #include <swmodule.hxx>
      30             : #include <fmtornt.hxx>
      31             : #include <fmtpdsc.hxx>
      32             : #include <fmtlsplt.hxx>
      33             : 
      34             : #include <svtools/htmlcfg.hxx>
      35             : #include <fmtrowsplt.hxx>
      36             : #include <sfx2/htmlmode.hxx>
      37             : 
      38             : #include <docsh.hxx>
      39             : #include <wrtsh.hxx>
      40             : #include <view.hxx>
      41             : #include <viewopt.hxx>
      42             : #include <uitool.hxx>
      43             : #include <frmatr.hxx>
      44             : 
      45             : #include <tablepg.hxx>
      46             : #include <tablemgr.hxx>
      47             : #include <pagedesc.hxx>
      48             : #include <poolfmt.hxx>
      49             : #include <SwStyleNameMapper.hxx>
      50             : 
      51             : #include <cmdid.h>
      52             : #include <table.hrc>
      53             : #include "swtablerep.hxx"
      54             : #include <boost/scoped_array.hpp>
      55             : 
      56           0 : SwTableRep::SwTableRep( const SwTabCols& rTabCol )
      57             :     :
      58             :     nTblWidth(0),
      59             :     nSpace(0),
      60             :     nLeftSpace(0),
      61             :     nRightSpace(0),
      62             :     nAlign(0),
      63             :     nWidthPercent(0),
      64             :     bLineSelected(false),
      65             :     bWidthChanged(false),
      66           0 :     bColsChanged(false)
      67             : {
      68           0 :     nAllCols = nColCount = rTabCol.Count();
      69           0 :     pTColumns = new TColumn[ nColCount + 1 ];
      70           0 :     SwTwips nStart = 0,
      71             :             nEnd;
      72           0 :     for( sal_uInt16 i = 0; i < nAllCols; ++i )
      73             :     {
      74           0 :         nEnd  = rTabCol[ i ] - rTabCol.GetLeft();
      75           0 :         pTColumns[ i ].nWidth = nEnd - nStart;
      76           0 :         pTColumns[ i ].bVisible = !rTabCol.IsHidden(i);
      77           0 :         if(!pTColumns[ i ].bVisible)
      78           0 :             nColCount --;
      79           0 :         nStart = nEnd;
      80             :     }
      81           0 :     pTColumns[ nAllCols ].nWidth = rTabCol.GetRight() - rTabCol.GetLeft() - nStart;
      82           0 :     pTColumns[ nAllCols ].bVisible = true;
      83           0 :     nColCount++;
      84           0 :     nAllCols++;
      85           0 : }
      86             : 
      87           0 : SwTableRep::~SwTableRep()
      88             : {
      89           0 :     delete[] pTColumns;
      90           0 : }
      91             : 
      92           0 : bool SwTableRep::FillTabCols( SwTabCols& rTabCols ) const
      93             : {
      94           0 :     long nOldLeft = rTabCols.GetLeft(),
      95           0 :          nOldRight = rTabCols.GetRight();
      96             : 
      97           0 :     bool bSingleLine = false;
      98             : 
      99           0 :     for ( size_t i = 0; i < rTabCols.Count(); ++i )
     100           0 :         if(!pTColumns[i].bVisible)
     101             :         {
     102           0 :             bSingleLine = true;
     103           0 :             break;
     104             :         }
     105             : 
     106           0 :     SwTwips nPos = 0;
     107           0 :     const SwTwips nLeft = GetLeftSpace();
     108           0 :     rTabCols.SetLeft(nLeft);
     109           0 :     if(bSingleLine)
     110             :     {
     111             :         // The invisible separators are taken from the old TabCols,
     112             :         // the visible coming from pTColumns.
     113           0 :         boost::scoped_array<TColumn> pOldTColumns(new TColumn[nAllCols + 1]);
     114           0 :         SwTwips nStart = 0;
     115           0 :         for ( sal_uInt16 i = 0; i < nAllCols - 1; ++i )
     116             :         {
     117           0 :             const SwTwips nEnd = rTabCols[i] - rTabCols.GetLeft();
     118           0 :             pOldTColumns[i].nWidth = nEnd - nStart;
     119           0 :             pOldTColumns[i].bVisible = !rTabCols.IsHidden(i);
     120           0 :             nStart = nEnd;
     121             :         }
     122           0 :         pOldTColumns[nAllCols - 1].nWidth = rTabCols.GetRight() - rTabCols.GetLeft() - nStart;
     123           0 :         pOldTColumns[nAllCols - 1].bVisible = true;
     124             : 
     125           0 :         sal_uInt16 nOldPos = 0;
     126           0 :         sal_uInt16 nNewPos = 0;
     127           0 :         SwTwips nOld = 0;
     128           0 :         SwTwips nNew = 0;
     129           0 :         bool bOld = false;
     130           0 :         bool bFirst = true;
     131             : 
     132           0 :         for ( sal_uInt16 i = 0; i < nAllCols - 1; ++i )
     133             :         {
     134           0 :             while((bFirst || bOld ) && nOldPos < nAllCols )
     135             :             {
     136           0 :                 nOld += pOldTColumns[nOldPos].nWidth;
     137           0 :                 nOldPos++;
     138           0 :                 if(!pOldTColumns[nOldPos - 1].bVisible)
     139           0 :                     break;
     140             :             }
     141           0 :             while((bFirst || !bOld ) && nNewPos < nAllCols )
     142             :             {
     143           0 :                 nNew += pTColumns[nNewPos].nWidth;
     144           0 :                 nNewPos++;
     145           0 :                 if(pOldTColumns[nNewPos - 1].bVisible)
     146           0 :                     break;
     147             :             }
     148           0 :             bFirst = false;
     149             :             // They have to be inserted sorted.
     150           0 :             bOld = nOld < nNew;
     151           0 :             nPos = bOld ? nOld : nNew;
     152           0 :             rTabCols[i] = nPos + nLeft;
     153           0 :             rTabCols.SetHidden( i, bOld );
     154             :         }
     155           0 :         rTabCols.SetRight(nLeft + nTblWidth);
     156             :     }
     157             :     else
     158             :     {
     159           0 :         for ( sal_uInt16 i = 0; i < nAllCols - 1; ++i )
     160             :         {
     161           0 :             nPos += pTColumns[i].nWidth;
     162           0 :             rTabCols[i] = nPos + rTabCols.GetLeft();
     163           0 :             rTabCols.SetHidden( i, !pTColumns[i].bVisible );
     164           0 :             rTabCols.SetRight(nLeft + pTColumns[nAllCols - 1].nWidth + nPos);
     165             :         }
     166             :     }
     167             : 
     168             :     // intercept rounding errors
     169           0 :     if(std::abs(nOldLeft - rTabCols.GetLeft()) < 3)
     170           0 :         rTabCols.SetLeft(nOldLeft);
     171             : 
     172           0 :     if(std::abs(nOldRight - rTabCols.GetRight()) < 3)
     173           0 :         rTabCols.SetRight(nOldRight);
     174             : 
     175           0 :     if(GetRightSpace() >= 0 &&
     176           0 :             rTabCols.GetRight() > rTabCols.GetRightMax())
     177           0 :         rTabCols.SetRight(rTabCols.GetRightMax());
     178           0 :     return bSingleLine;
     179         270 : }
     180             : 
     181             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10