LCOV - code coverage report
Current view: top level - sw/source/core/docnode - ndtbl1.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 347 827 42.0 %
Date: 2014-04-11 Functions: 18 36 50.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 <editeng/lrspitem.hxx>
      22             : #include <editeng/boxitem.hxx>
      23             : #include <editeng/brushitem.hxx>
      24             : #include <editeng/frmdiritem.hxx>
      25             : #include <fmtornt.hxx>
      26             : #include <fmtfsize.hxx>
      27             : #include <fmtlsplt.hxx>
      28             : #include <fmtrowsplt.hxx>
      29             : #include <tabcol.hxx>
      30             : #include <frmatr.hxx>
      31             : #include <cellfrm.hxx>
      32             : #include <tabfrm.hxx>
      33             : #include <cntfrm.hxx>
      34             : #include <txtfrm.hxx>
      35             : #include <svx/svxids.hrc>
      36             : #include <doc.hxx>
      37             : #include <IDocumentUndoRedo.hxx>
      38             : #include "pam.hxx"
      39             : #include "swcrsr.hxx"
      40             : #include "viscrs.hxx"
      41             : #include "swtable.hxx"
      42             : #include "htmltbl.hxx"
      43             : #include "tblsel.hxx"
      44             : #include "swtblfmt.hxx"
      45             : #include "docary.hxx"
      46             : #include "ndindex.hxx"
      47             : #include "undobj.hxx"
      48             : #include "switerator.hxx"
      49             : #include <UndoTable.hxx>
      50             : #include <boost/foreach.hpp>
      51             : 
      52             : using ::editeng::SvxBorderLine;
      53             : using namespace ::com::sun::star;
      54             : 
      55             : extern void ClearFEShellTabCols();
      56             : 
      57             : // See swtable.cxx too
      58             : #define COLFUZZY 20L
      59             : 
      60           3 : inline bool IsSame( long nA, long nB ) { return  std::abs(nA-nB) <= COLFUZZY; }
      61             : 
      62             : class SwTblFmtCmp
      63             : {
      64             : public:
      65             :     SwFrmFmt *pOld,
      66             :              *pNew;
      67             :     sal_Int16     nType;
      68             : 
      69             :     SwTblFmtCmp( SwFrmFmt *pOld, SwFrmFmt *pNew, sal_Int16 nType );
      70             : 
      71             :     static SwFrmFmt *FindNewFmt( std::vector<SwTblFmtCmp*> &rArr, SwFrmFmt*pOld, sal_Int16 nType );
      72             :     static void Delete( std::vector<SwTblFmtCmp*> &rArr );
      73             : };
      74             : 
      75          36 : SwTblFmtCmp::SwTblFmtCmp( SwFrmFmt *pO, SwFrmFmt *pN, sal_Int16 nT )
      76          36 :     : pOld ( pO ), pNew ( pN ), nType( nT )
      77             : {
      78          36 : }
      79             : 
      80          36 : SwFrmFmt *SwTblFmtCmp::FindNewFmt( std::vector<SwTblFmtCmp*> &rArr, SwFrmFmt *pOld, sal_Int16 nType )
      81             : {
      82         180 :     for ( sal_uInt16 i = 0; i < rArr.size(); ++i )
      83             :     {
      84         144 :         SwTblFmtCmp *pCmp = rArr[i];
      85         144 :         if ( pCmp->pOld == pOld && pCmp->nType == nType )
      86           0 :             return pCmp->pNew;
      87             :     }
      88          36 :     return 0;
      89             : }
      90             : 
      91           4 : void SwTblFmtCmp::Delete( std::vector<SwTblFmtCmp*> &rArr )
      92             : {
      93          40 :     for ( sal_uInt16 i = 0; i < rArr.size(); ++i )
      94          36 :         delete rArr[i];
      95           4 : }
      96             : 
      97          31 : static void lcl_GetStartEndCell( const SwCursor& rCrsr,
      98             :                         SwLayoutFrm *&prStart, SwLayoutFrm *&prEnd )
      99             : {
     100             :     OSL_ENSURE( rCrsr.GetCntntNode() && rCrsr.GetCntntNode( false ),
     101             :             "Tab selection not at ContentNode" );
     102             : 
     103          31 :     Point aPtPos, aMkPos;
     104          31 :     const SwShellCrsr* pShCrsr = dynamic_cast<const SwShellCrsr*>(&rCrsr);
     105          31 :     if( pShCrsr )
     106             :     {
     107          12 :         aPtPos = pShCrsr->GetPtPos();
     108          12 :         aMkPos = pShCrsr->GetMkPos();
     109             :     }
     110             : 
     111             :     // Robust:
     112          31 :     SwCntntNode* pPointNd = rCrsr.GetCntntNode();
     113          31 :     SwCntntNode* pMarkNd  = rCrsr.GetCntntNode(false);
     114             : 
     115          31 :     SwFrm* pPointFrm = pPointNd ? pPointNd->getLayoutFrm( pPointNd->GetDoc()->GetCurrentLayout(), &aPtPos ) : 0;
     116          31 :     SwFrm* pMarkFrm  = pMarkNd  ? pMarkNd->getLayoutFrm( pMarkNd->GetDoc()->GetCurrentLayout(), &aMkPos )  : 0;
     117             : 
     118          31 :     prStart = pPointFrm ? pPointFrm->GetUpper() : 0;
     119          31 :     prEnd   = pMarkFrm  ? pMarkFrm->GetUpper() : 0;
     120          31 : }
     121             : 
     122          16 : static bool lcl_GetBoxSel( const SwCursor& rCursor, SwSelBoxes& rBoxes,
     123             :                     bool bAllCrsr = false )
     124             : {
     125             :     const SwTableCursor* pTblCrsr =
     126          16 :         dynamic_cast<const SwTableCursor*>(&rCursor);
     127          16 :     if( pTblCrsr )
     128          12 :         ::GetTblSelCrs( *pTblCrsr, rBoxes );
     129             :     else
     130             :     {
     131           4 :         const SwPaM *pCurPam = &rCursor, *pSttPam = pCurPam;
     132           4 :         do {
     133           4 :             const SwNode* pNd = pCurPam->GetNode()->FindTableBoxStartNode();
     134           4 :             if( pNd )
     135             :             {
     136           4 :                 SwTableBox* pBox = (SwTableBox*)pNd->FindTableNode()->GetTable().
     137           8 :                                             GetTblBox( pNd->GetIndex() );
     138           4 :                 rBoxes.insert( pBox );
     139             :             }
     140           4 :         } while( bAllCrsr &&
     141           0 :                 pSttPam != ( pCurPam = (SwPaM*)pCurPam->GetNext()) );
     142             :     }
     143          16 :     return !rBoxes.empty();
     144             : }
     145             : 
     146           1 : inline void InsertLine( std::vector<SwTableLine*>& rLineArr, SwTableLine* pLine )
     147             : {
     148           1 :     if( rLineArr.end() == std::find( rLineArr.begin(), rLineArr.end(), pLine ) )
     149           1 :         rLineArr.push_back( pLine );
     150           1 : }
     151             : 
     152           0 : static bool lcl_IsAnLower( const SwTableLine *pLine, const SwTableLine *pAssumed )
     153             : {
     154           0 :     const SwTableLine *pTmp = pAssumed->GetUpper() ?
     155           0 :                                     pAssumed->GetUpper()->GetUpper() : 0;
     156           0 :     while ( pTmp )
     157             :     {
     158           0 :         if ( pTmp == pLine )
     159           0 :             return true;
     160           0 :         pTmp = pTmp->GetUpper() ? pTmp->GetUpper()->GetUpper() : 0;
     161             :     }
     162           0 :     return false;
     163             : }
     164             : 
     165             : struct LinesAndTable
     166             : {
     167             :     std::vector<SwTableLine*> &rLines;
     168             :     const SwTable             &rTable;
     169             :     bool                      bInsertLines;
     170             : 
     171           1 :     LinesAndTable( std::vector<SwTableLine*> &rL, const SwTable &rTbl ) :
     172           1 :           rLines( rL ), rTable( rTbl ), bInsertLines( true ) {}
     173             : };
     174             : 
     175             : bool _FindLine( _FndLine & rLine, LinesAndTable* pPara );
     176             : 
     177           2 : bool _FindBox( _FndBox & rBox, LinesAndTable* pPara )
     178             : {
     179           2 :     if (!rBox.GetLines().empty())
     180             :     {
     181           1 :         pPara->bInsertLines = true;
     182           2 :         BOOST_FOREACH( _FndLine & rFndLine, rBox.GetLines() )
     183           1 :             _FindLine( rFndLine, pPara );
     184           1 :         if ( pPara->bInsertLines )
     185             :         {
     186           1 :             const SwTableLines &rLines = (rBox.GetBox())
     187           0 :                                     ? rBox.GetBox()->GetTabLines()
     188           1 :                                     : pPara->rTable.GetTabLines();
     189           1 :             if (rBox.GetLines().size() == rLines.size())
     190             :             {
     191           0 :                 for ( sal_uInt16 i = 0; i < rLines.size(); ++i )
     192             :                     ::InsertLine( pPara->rLines,
     193           0 :                                   (SwTableLine*)rLines[i] );
     194             :             }
     195             :             else
     196           1 :                 pPara->bInsertLines = false;
     197             :         }
     198             :     }
     199           1 :     else if (rBox.GetBox())
     200             :     {
     201             :         ::InsertLine( pPara->rLines,
     202           1 :                       static_cast<SwTableLine*>(rBox.GetBox()->GetUpper()));
     203             :     }
     204           2 :     return true;
     205             : }
     206             : 
     207           1 : bool _FindLine( _FndLine& rLine, LinesAndTable* pPara )
     208             : {
     209           6 :     for (_FndBoxes::iterator it = rLine.GetBoxes().begin();
     210           4 :          it != rLine.GetBoxes().end(); ++it)
     211             :     {
     212           1 :         _FindBox(*it, pPara);
     213             :     }
     214           1 :     return true;
     215             : }
     216             : 
     217           1 : static void lcl_CollectLines( std::vector<SwTableLine*> &rArr, const SwCursor& rCursor, bool bRemoveLines )
     218             : {
     219             :     // Collect the selected Boxes first
     220           1 :     SwSelBoxes aBoxes;
     221           1 :     if( !::lcl_GetBoxSel( rCursor, aBoxes ))
     222           1 :         return ;
     223             : 
     224             :     // Copy the selected structure
     225           1 :     const SwTable &rTable = aBoxes[0]->GetSttNd()->FindTableNode()->GetTable();
     226           1 :     LinesAndTable aPara( rArr, rTable );
     227           2 :     _FndBox aFndBox( 0, 0 );
     228             :     {
     229           1 :         _FndPara aTmpPara( aBoxes, &aFndBox );
     230           1 :         ForEach_FndLineCopyCol( (SwTableLines&)rTable.GetTabLines(), &aTmpPara );
     231             :     }
     232             : 
     233             :     // Collect the Lines which only contain selected Boxes
     234           1 :     ::_FindBox(aFndBox, &aPara);
     235             : 
     236             :     // Remove lines, that have a common superordinate row.
     237             :     // (Not for row split)
     238           1 :     if ( bRemoveLines )
     239             :     {
     240           2 :         for ( sal_uInt16 i = 0; i < rArr.size(); ++i )
     241             :         {
     242           1 :             SwTableLine *pUpLine = rArr[i];
     243           2 :             for ( sal_uInt16 k = 0; k < rArr.size(); ++k )
     244             :             {
     245           1 :                 if ( k != i && ::lcl_IsAnLower( pUpLine, rArr[k] ) )
     246             :                 {
     247           0 :                     rArr.erase( rArr.begin() + k );
     248           0 :                     if ( k <= i )
     249           0 :                         --i;
     250           0 :                     --k;
     251             :                 }
     252             :             }
     253             :         }
     254           1 :     }
     255             : }
     256             : 
     257           0 : static void lcl_ProcessRowAttr( std::vector<SwTblFmtCmp*>& rFmtCmp, SwTableLine* pLine, const SfxPoolItem& rNew )
     258             : {
     259             :     SwFrmFmt *pNewFmt;
     260           0 :     if ( 0 != (pNewFmt = SwTblFmtCmp::FindNewFmt( rFmtCmp, pLine->GetFrmFmt(), 0 )))
     261           0 :         pLine->ChgFrmFmt( (SwTableLineFmt*)pNewFmt );
     262             :     else
     263             :     {
     264           0 :         SwFrmFmt *pOld = pLine->GetFrmFmt();
     265           0 :         SwFrmFmt *pNew = pLine->ClaimFrmFmt();
     266           0 :         pNew->SetFmtAttr( rNew );
     267           0 :         rFmtCmp.push_back( new SwTblFmtCmp( pOld, pNew, 0 ) );
     268             :     }
     269           0 : }
     270             : 
     271             : static void lcl_ProcessBoxSize( std::vector<SwTblFmtCmp*> &rFmtCmp, SwTableBox *pBox, const SwFmtFrmSize &rNew );
     272             : 
     273           0 : static void lcl_ProcessRowSize( std::vector<SwTblFmtCmp*> &rFmtCmp, SwTableLine *pLine, const SwFmtFrmSize &rNew )
     274             : {
     275           0 :     lcl_ProcessRowAttr( rFmtCmp, pLine, rNew );
     276           0 :     SwTableBoxes &rBoxes = pLine->GetTabBoxes();
     277           0 :     for ( sal_uInt16 i = 0; i < rBoxes.size(); ++i )
     278           0 :         ::lcl_ProcessBoxSize( rFmtCmp, rBoxes[i], rNew );
     279           0 : }
     280             : 
     281           0 : static void lcl_ProcessBoxSize( std::vector<SwTblFmtCmp*> &rFmtCmp, SwTableBox *pBox, const SwFmtFrmSize &rNew )
     282             : {
     283           0 :     SwTableLines &rLines = pBox->GetTabLines();
     284           0 :     if ( !rLines.empty() )
     285             :     {
     286           0 :         SwFmtFrmSize aSz( rNew );
     287           0 :         aSz.SetHeight( rNew.GetHeight() ? rNew.GetHeight() / rLines.size() : 0 );
     288           0 :         for ( sal_uInt16 i = 0; i < rLines.size(); ++i )
     289           0 :             ::lcl_ProcessRowSize( rFmtCmp, rLines[i], aSz );
     290             :     }
     291           0 : }
     292             : 
     293           0 : void SwDoc::SetRowSplit( const SwCursor& rCursor, const SwFmtRowSplit &rNew )
     294             : {
     295           0 :     SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
     296           0 :     if( pTblNd )
     297             :     {
     298           0 :         std::vector<SwTableLine*> aRowArr; // For Lines collecting
     299           0 :         ::lcl_CollectLines( aRowArr, rCursor, false );
     300             : 
     301           0 :         if( !aRowArr.empty() )
     302             :         {
     303           0 :             if (GetIDocumentUndoRedo().DoesUndo())
     304             :             {
     305           0 :                 GetIDocumentUndoRedo().AppendUndo(new SwUndoAttrTbl(*pTblNd));
     306             :             }
     307             : 
     308           0 :             std::vector<SwTblFmtCmp*> aFmtCmp;
     309           0 :             aFmtCmp.reserve( std::max( 255, (int)aRowArr.size() ) );
     310             : 
     311           0 :             for( sal_uInt16 i = 0; i < aRowArr.size(); ++i )
     312           0 :                 ::lcl_ProcessRowAttr( aFmtCmp, aRowArr[i], rNew );
     313             : 
     314           0 :             SwTblFmtCmp::Delete( aFmtCmp );
     315           0 :             SetModified();
     316           0 :         }
     317             :     }
     318           0 : }
     319             : 
     320           0 : void SwDoc::GetRowSplit( const SwCursor& rCursor, SwFmtRowSplit *& rpSz ) const
     321             : {
     322           0 :     rpSz = 0;
     323             : 
     324           0 :     SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
     325           0 :     if( pTblNd )
     326             :     {
     327           0 :         std::vector<SwTableLine*> aRowArr; // For Lines collecting
     328           0 :         ::lcl_CollectLines( aRowArr, rCursor, false );
     329             : 
     330           0 :         if( !aRowArr.empty() )
     331             :         {
     332           0 :             rpSz = &(SwFmtRowSplit&)aRowArr[0]->GetFrmFmt()->GetRowSplit();
     333             : 
     334           0 :             for ( sal_uInt16 i = 1; i < aRowArr.size() && rpSz; ++i )
     335             :             {
     336           0 :                 if ( (*rpSz).GetValue() != aRowArr[i]->GetFrmFmt()->GetRowSplit().GetValue() )
     337           0 :                     rpSz = 0;
     338             :             }
     339           0 :             if ( rpSz )
     340           0 :                 rpSz = new SwFmtRowSplit( *rpSz );
     341           0 :         }
     342             :     }
     343           0 : }
     344             : 
     345             : /* Class:  SwDoc
     346             :  * Methods:  SetRowHeight(), GetRowHeight()
     347             :  *
     348             :  * The line height is calculated from the Selection.
     349             :  * Starting with every Cell within the Selection, all Cells are iterated
     350             :  * through in an upwards fashion.
     351             :  *
     352             :  * The topmost Line gets the requested value, all Lines below it get
     353             :  * a respective value that is calculated from the relation of the old and
     354             :  * new size of the topmost Line in the lower line's own size.
     355             :  *
     356             :  * All changed Lines may get an own FrmFmt.
     357             :  * Of course we can only touch every Line once.
     358             :  */
     359             : 
     360           0 : void SwDoc::SetRowHeight( const SwCursor& rCursor, const SwFmtFrmSize &rNew )
     361             : {
     362           0 :     SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
     363           0 :     if( pTblNd )
     364             :     {
     365           0 :         std::vector<SwTableLine*> aRowArr; // For Lines collecting
     366           0 :         ::lcl_CollectLines( aRowArr, rCursor, true );
     367             : 
     368           0 :         if( !aRowArr.empty() )
     369             :         {
     370           0 :             if (GetIDocumentUndoRedo().DoesUndo())
     371             :             {
     372           0 :                 GetIDocumentUndoRedo().AppendUndo(new SwUndoAttrTbl(*pTblNd));
     373             :             }
     374             : 
     375           0 :             std::vector<SwTblFmtCmp*> aFmtCmp;
     376           0 :             aFmtCmp.reserve( std::max( 255, (int)aRowArr.size() ) );
     377           0 :             for ( sal_uInt16 i = 0; i < aRowArr.size(); ++i )
     378           0 :                 ::lcl_ProcessRowSize( aFmtCmp, aRowArr[i], rNew );
     379           0 :             SwTblFmtCmp::Delete( aFmtCmp );
     380             : 
     381           0 :             SetModified();
     382           0 :         }
     383             :     }
     384           0 : }
     385             : 
     386           0 : void SwDoc::GetRowHeight( const SwCursor& rCursor, SwFmtFrmSize *& rpSz ) const
     387             : {
     388           0 :     rpSz = 0;
     389             : 
     390           0 :     SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
     391           0 :     if( pTblNd )
     392             :     {
     393           0 :         std::vector<SwTableLine*> aRowArr; // For Lines collecting
     394           0 :         ::lcl_CollectLines( aRowArr, rCursor, true );
     395             : 
     396           0 :         if( !aRowArr.empty() )
     397             :         {
     398           0 :             rpSz = &(SwFmtFrmSize&)aRowArr[0]->GetFrmFmt()->GetFrmSize();
     399             : 
     400           0 :             for ( sal_uInt16 i = 1; i < aRowArr.size() && rpSz; ++i )
     401             :             {
     402           0 :                 if ( *rpSz != aRowArr[i]->GetFrmFmt()->GetFrmSize() )
     403           0 :                     rpSz = 0;
     404             :             }
     405           0 :             if ( rpSz )
     406           0 :                 rpSz = new SwFmtFrmSize( *rpSz );
     407           0 :         }
     408             :     }
     409           0 : }
     410             : 
     411           1 : sal_Bool SwDoc::BalanceRowHeight( const SwCursor& rCursor, sal_Bool bTstOnly )
     412             : {
     413           1 :     sal_Bool bRet = sal_False;
     414           1 :     SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
     415           1 :     if( pTblNd )
     416             :     {
     417           1 :         std::vector<SwTableLine*> aRowArr; // For Lines collecting
     418           1 :         ::lcl_CollectLines( aRowArr, rCursor, true );
     419             : 
     420           1 :         if( 1 < aRowArr.size() )
     421             :         {
     422           0 :             if( !bTstOnly )
     423             :             {
     424           0 :                 long nHeight = 0;
     425             :                 sal_uInt16 i;
     426             : 
     427           0 :                 for ( i = 0; i < aRowArr.size(); ++i )
     428             :                 {
     429           0 :                     SwIterator<SwFrm,SwFmt> aIter( *aRowArr[i]->GetFrmFmt() );
     430           0 :                     SwFrm* pFrm = aIter.First();
     431           0 :                     while ( pFrm )
     432             :                     {
     433           0 :                         nHeight = std::max( nHeight, pFrm->Frm().Height() );
     434           0 :                         pFrm = aIter.Next();
     435             :                     }
     436           0 :                 }
     437           0 :                 SwFmtFrmSize aNew( ATT_MIN_SIZE, 0, nHeight );
     438             : 
     439           0 :                 if (GetIDocumentUndoRedo().DoesUndo())
     440             :                 {
     441           0 :                     GetIDocumentUndoRedo().AppendUndo(
     442           0 :                             new SwUndoAttrTbl(*pTblNd));
     443             :                 }
     444             : 
     445           0 :                 std::vector<SwTblFmtCmp*> aFmtCmp;
     446           0 :                 aFmtCmp.reserve( std::max( 255, (int)aRowArr.size() ) );
     447           0 :                 for( i = 0; i < aRowArr.size(); ++i )
     448           0 :                     ::lcl_ProcessRowSize( aFmtCmp, (SwTableLine*)aRowArr[i], aNew );
     449           0 :                 SwTblFmtCmp::Delete( aFmtCmp );
     450             : 
     451           0 :                 SetModified();
     452             :             }
     453           0 :             bRet = sal_True;
     454           1 :         }
     455             :     }
     456           1 :     return bRet;
     457             : }
     458             : 
     459           0 : void SwDoc::SetRowBackground( const SwCursor& rCursor, const SvxBrushItem &rNew )
     460             : {
     461           0 :     SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
     462           0 :     if( pTblNd )
     463             :     {
     464           0 :         std::vector<SwTableLine*> aRowArr; // For Lines collecting
     465           0 :         ::lcl_CollectLines( aRowArr, rCursor, true );
     466             : 
     467           0 :         if( !aRowArr.empty() )
     468             :         {
     469           0 :             if (GetIDocumentUndoRedo().DoesUndo())
     470             :             {
     471           0 :                 GetIDocumentUndoRedo().AppendUndo(new SwUndoAttrTbl(*pTblNd));
     472             :             }
     473             : 
     474           0 :             std::vector<SwTblFmtCmp*> aFmtCmp;
     475           0 :             aFmtCmp.reserve( std::max( 255, (int)aRowArr.size() ) );
     476             : 
     477           0 :             for( sal_uInt16 i = 0; i < aRowArr.size(); ++i )
     478           0 :                 ::lcl_ProcessRowAttr( aFmtCmp, aRowArr[i], rNew );
     479             : 
     480           0 :             SwTblFmtCmp::Delete( aFmtCmp );
     481           0 :             SetModified();
     482           0 :         }
     483             :     }
     484           0 : }
     485             : 
     486           0 : sal_Bool SwDoc::GetRowBackground( const SwCursor& rCursor, SvxBrushItem &rToFill ) const
     487             : {
     488           0 :     sal_Bool bRet = sal_False;
     489           0 :     SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
     490           0 :     if( pTblNd )
     491             :     {
     492           0 :         std::vector<SwTableLine*> aRowArr; // For Lines collecting
     493           0 :         ::lcl_CollectLines( aRowArr, rCursor, true );
     494             : 
     495           0 :         if( !aRowArr.empty() )
     496             :         {
     497           0 :             rToFill = aRowArr[0]->GetFrmFmt()->GetBackground();
     498             : 
     499           0 :             bRet = sal_True;
     500           0 :             for ( sal_uInt16 i = 1; i < aRowArr.size(); ++i )
     501           0 :                 if ( rToFill != aRowArr[i]->GetFrmFmt()->GetBackground() )
     502             :                 {
     503           0 :                     bRet = sal_False;
     504           0 :                     break;
     505             :                 }
     506           0 :         }
     507             :     }
     508           0 :     return bRet;
     509             : }
     510             : 
     511         170 : inline void InsertCell( std::vector<SwCellFrm*>& rCellArr, SwCellFrm* pCellFrm )
     512             : {
     513         170 :     if( rCellArr.end() == std::find( rCellArr.begin(), rCellArr.end(), pCellFrm ) )
     514         170 :         rCellArr.push_back( pCellFrm );
     515         170 : }
     516             : 
     517          28 : static void lcl_CollectCells( std::vector<SwCellFrm*> &rArr, const SwRect &rUnion,
     518             :                           SwTabFrm *pTab )
     519             : {
     520          28 :     SwLayoutFrm *pCell = pTab->FirstCell();
     521         179 :     do
     522             :     {
     523             :         // If the Cell contains a CellFrame, we need to use it
     524             :         // in order to get to the Cell
     525         358 :         while ( !pCell->IsCellFrm() )
     526           0 :             pCell = pCell->GetUpper();
     527             :         OSL_ENSURE( pCell, "Frame is not a Cell" );
     528         179 :         if ( rUnion.IsOver( pCell->Frm() ) )
     529         170 :             ::InsertCell( rArr, (SwCellFrm*)pCell );
     530             : 
     531             :         // Make sure the Cell is left (Areas)
     532         179 :         SwLayoutFrm *pTmp = pCell;
     533         179 :         do
     534         179 :         {   pTmp = pTmp->GetNextLayoutLeaf();
     535         179 :         } while ( pCell->IsAnLower( pTmp ) );
     536         179 :         pCell = pTmp;
     537         179 :     } while( pCell && pTab->IsAnLower( pCell ) );
     538          28 : }
     539             : 
     540           5 : void SwDoc::SetTabBorders( const SwCursor& rCursor, const SfxItemSet& rSet )
     541             : {
     542           5 :     SwCntntNode* pCntNd = rCursor.GetPoint()->nNode.GetNode().GetCntntNode();
     543           5 :     SwTableNode* pTblNd = pCntNd ? pCntNd->FindTableNode() : 0;
     544           5 :     if( !pTblNd )
     545           5 :         return ;
     546             : 
     547             :     SwLayoutFrm *pStart, *pEnd;
     548           5 :     ::lcl_GetStartEndCell( rCursor, pStart, pEnd );
     549             : 
     550           5 :     SwSelUnions aUnions;
     551           5 :     ::MakeSelUnions( aUnions, pStart, pEnd );
     552             : 
     553           5 :     if( !aUnions.empty() )
     554             :     {
     555           4 :         SwTable& rTable = pTblNd->GetTable();
     556           4 :         if (GetIDocumentUndoRedo().DoesUndo())
     557             :         {
     558           4 :             GetIDocumentUndoRedo().AppendUndo( new SwUndoAttrTbl(*pTblNd) );
     559             :         }
     560             : 
     561           4 :         std::vector<SwTblFmtCmp*> aFmtCmp;
     562           4 :         aFmtCmp.reserve( 255 );
     563             :         const SvxBoxItem* pSetBox;
     564             :         const SvxBoxInfoItem *pSetBoxInfo;
     565             : 
     566           4 :         const SvxBorderLine* pLeft = 0;
     567           4 :         const SvxBorderLine* pRight = 0;
     568           4 :         const SvxBorderLine* pTop = 0;
     569           4 :         const SvxBorderLine* pBottom = 0;
     570           4 :         const SvxBorderLine* pHori = 0;
     571           4 :         const SvxBorderLine* pVert = 0;
     572           4 :         sal_Bool bHoriValid = sal_True, bVertValid = sal_True,
     573           4 :              bTopValid = sal_True, bBottomValid = sal_True,
     574           4 :              bLeftValid = sal_True, bRightValid = sal_True;
     575             : 
     576             :         // The Flags in the BoxInfo Item decide whether a BorderLine is valid!
     577           4 :         if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_BORDER_INNER, false,
     578           4 :             (const SfxPoolItem**)&pSetBoxInfo) )
     579             :         {
     580           4 :             pHori = pSetBoxInfo->GetHori();
     581           4 :             pVert = pSetBoxInfo->GetVert();
     582             : 
     583           4 :             bHoriValid = pSetBoxInfo->IsValid(VALID_HORI);
     584           4 :             bVertValid = pSetBoxInfo->IsValid(VALID_VERT);
     585             : 
     586             :             // Do we want to evaluate these?
     587           4 :             bTopValid = pSetBoxInfo->IsValid(VALID_TOP);
     588           4 :             bBottomValid = pSetBoxInfo->IsValid(VALID_BOTTOM);
     589           4 :             bLeftValid = pSetBoxInfo->IsValid(VALID_LEFT);
     590           4 :             bRightValid = pSetBoxInfo->IsValid(VALID_RIGHT);
     591             :         }
     592             : 
     593           4 :         if( SFX_ITEM_SET == rSet.GetItemState( RES_BOX, false,
     594           4 :             (const SfxPoolItem**)&pSetBox) )
     595             :         {
     596           4 :             pLeft = pSetBox->GetLeft();
     597           4 :             pRight = pSetBox->GetRight();
     598           4 :             pTop = pSetBox->GetTop();
     599           4 :             pBottom = pSetBox->GetBottom();
     600             :         }
     601             :         else
     602             :         {
     603             :             // Not set, thus not valid values
     604           0 :             bTopValid = bBottomValid = bLeftValid = bRightValid = sal_False;
     605           0 :             pSetBox = 0;
     606             :         }
     607             : 
     608           4 :         bool bFirst = true;
     609           8 :         for ( sal_uInt16 i = 0; i < aUnions.size(); ++i )
     610             :         {
     611           4 :             SwSelUnion *pUnion = &aUnions[i];
     612           4 :             SwTabFrm *pTab = pUnion->GetTable();
     613           4 :             const SwRect &rUnion = pUnion->GetUnion();
     614           4 :             const bool bLast  = (i == aUnions.size() - 1);
     615             : 
     616           4 :             std::vector<SwCellFrm*> aCellArr;
     617           4 :             aCellArr.reserve( 255 );
     618           4 :             ::lcl_CollectCells( aCellArr, pUnion->GetUnion(), pTab );
     619             : 
     620             :             // All Cell Borders that match the UnionRect or extend it are
     621             :             // Outer Borders. All others are Inner Borders.
     622             : 
     623             :             // New: The Outer Borders can, depending on whether it's a
     624             :             // Start/Middle/Follow Table (for Selection via FollowTabs),
     625             :             // also not be Outer Borders.
     626             :             // Outer Borders are set on the left, right, at the top and at the bottom.
     627             :             // Inner Borders are only set at the top and on the left.
     628          40 :             for ( sal_uInt16 j = 0; j < aCellArr.size(); ++j )
     629             :             {
     630          36 :                 SwCellFrm *pCell = aCellArr[j];
     631          36 :                 const sal_Bool bVert = pTab->IsVertical();
     632          36 :                 const sal_Bool bRTL = pTab->IsRightToLeft();
     633             :                 sal_Bool bTopOver, bLeftOver, bRightOver, bBottomOver;
     634          36 :                 if ( bVert )
     635             :                 {
     636           0 :                     bTopOver = pCell->Frm().Right() >= rUnion.Right();
     637           0 :                     bLeftOver = pCell->Frm().Top() <= rUnion.Top();
     638           0 :                     bRightOver = pCell->Frm().Bottom() >= rUnion.Bottom();
     639           0 :                     bBottomOver = pCell->Frm().Left() <= rUnion.Left();
     640             :                 }
     641             :                 else
     642             :                 {
     643          36 :                     bTopOver = pCell->Frm().Top() <= rUnion.Top();
     644          36 :                     bLeftOver = pCell->Frm().Left() <= rUnion.Left();
     645          36 :                     bRightOver = pCell->Frm().Right() >= rUnion.Right();
     646          36 :                     bBottomOver = pCell->Frm().Bottom() >= rUnion.Bottom();
     647             :                 }
     648             : 
     649          36 :                 if ( bRTL )
     650             :                 {
     651           0 :                     sal_Bool bTmp = bRightOver;
     652           0 :                     bRightOver = bLeftOver;
     653           0 :                     bLeftOver = bTmp;
     654             :                 }
     655             : 
     656             :                 // Do not set anything by default in HeadlineRepeats
     657          36 :                 if ( pTab->IsFollow() &&
     658           0 :                      ( pTab->IsInHeadline( *pCell ) ||
     659             :                        // Same holds for follow flow rows
     660           0 :                        pCell->IsInFollowFlowRow() ) )
     661           0 :                     continue;
     662             : 
     663          36 :                 SvxBoxItem aBox( pCell->GetFmt()->GetBox() );
     664             : 
     665          36 :                 sal_Int16 nType = 0;
     666             : 
     667             :                 // Top Border
     668          36 :                 if( bTopValid )
     669             :                 {
     670          36 :                     if ( bFirst && bTopOver )
     671             :                     {
     672          12 :                         aBox.SetLine( pTop, BOX_LINE_TOP );
     673          12 :                         nType |= 0x0001;
     674             :                     }
     675          24 :                     else if ( bHoriValid )
     676             :                     {
     677          24 :                         aBox.SetLine( 0, BOX_LINE_TOP );
     678          24 :                         nType |= 0x0002;
     679             :                     }
     680             :                 }
     681             : 
     682             :                 // Fix fdo#62470 correct the input for RTL table
     683          36 :                 if (bRTL)
     684             :                 {
     685           0 :                         if( bLeftOver && bRightOver)
     686             :                         {
     687           0 :                             if ( bLeftValid )
     688             :                             {
     689           0 :                                 aBox.SetLine( pLeft, BOX_LINE_RIGHT );
     690           0 :                                 nType |= 0x0010;
     691             :                             }
     692           0 :                             if ( bRightValid )
     693             :                             {
     694           0 :                                 aBox.SetLine( pRight, BOX_LINE_LEFT );
     695           0 :                                 nType |= 0x0004;
     696             :                             }
     697             :                         }
     698             :                         else
     699             :                         {
     700           0 :                             if ( bLeftValid )
     701             :                             {
     702           0 :                                 aBox.SetLine( bRightOver ? pLeft : 0, BOX_LINE_RIGHT );
     703           0 :                                 bVertValid ? nType |= 0x0020 : nType |= 0x0010;
     704             :                             }
     705           0 :                             if ( bLeftOver )
     706             :                             {
     707           0 :                                 if ( bRightValid )
     708             :                                 {
     709           0 :                                     aBox.SetLine( pRight, BOX_LINE_LEFT );
     710           0 :                                     nType |= 0x0004;
     711             :                                 }
     712             :                             }
     713           0 :                             else if ( bVertValid )
     714             :                             {
     715           0 :                                 aBox.SetLine( pVert, BOX_LINE_LEFT );
     716           0 :                                 nType |= 0x0008;
     717             :                             }
     718             :                         }
     719             :                 }
     720             :                 else
     721             :                 {
     722             :                     // Left Border
     723          36 :                     if ( bLeftOver )
     724             :                     {
     725          12 :                         if( bLeftValid )
     726             :                         {
     727          12 :                             aBox.SetLine( pLeft, BOX_LINE_LEFT );
     728          12 :                             nType |= 0x0004;
     729             :                         }
     730             :                     }
     731          24 :                     else if( bVertValid )
     732             :                     {
     733          24 :                         aBox.SetLine( pVert, BOX_LINE_LEFT );
     734          24 :                         nType |= 0x0008;
     735             :                     }
     736             : 
     737             :                     // Right Border
     738          36 :                     if( bRightValid )
     739             :                     {
     740          36 :                         if ( bRightOver )
     741             :                         {
     742          12 :                             aBox.SetLine( pRight, BOX_LINE_RIGHT );
     743          12 :                             nType |= 0x0010;
     744             :                         }
     745          24 :                         else if ( bVertValid )
     746             :                         {
     747          24 :                             aBox.SetLine( 0, BOX_LINE_RIGHT );
     748          24 :                             nType |= 0x0020;
     749             :                         }
     750             :                     }
     751             :                 }
     752             : 
     753             :                 // Bottom Border
     754          36 :                 if ( bLast && bBottomOver )
     755             :                 {
     756          24 :                     if( bBottomValid )
     757             :                     {
     758          12 :                         aBox.SetLine( pBottom, BOX_LINE_BOTTOM );
     759          12 :                         nType |= 0x0040;
     760             :                     }
     761             :                 }
     762          24 :                 else if( bHoriValid )
     763             :                 {
     764          24 :                     aBox.SetLine( pHori, BOX_LINE_BOTTOM );
     765          24 :                     nType |= 0x0080;
     766             :                 }
     767             : 
     768          36 :                 if( pSetBox )
     769             :                 {
     770             :                     static sal_uInt16 const aBorders[] = {
     771             :                         BOX_LINE_BOTTOM, BOX_LINE_TOP,
     772             :                         BOX_LINE_RIGHT, BOX_LINE_LEFT };
     773          36 :                     const sal_uInt16* pBrd = aBorders;
     774         180 :                     for( int k = 0; k < 4; ++k, ++pBrd )
     775         144 :                         aBox.SetDistance( pSetBox->GetDistance( *pBrd ), *pBrd );
     776             :                 }
     777             : 
     778          36 :                 SwTableBox *pBox = (SwTableBox*)pCell->GetTabBox();
     779             :                 SwFrmFmt *pNewFmt;
     780          36 :                 if ( 0 != (pNewFmt = SwTblFmtCmp::FindNewFmt( aFmtCmp, pBox->GetFrmFmt(), nType )))
     781           0 :                     pBox->ChgFrmFmt( (SwTableBoxFmt*)pNewFmt );
     782             :                 else
     783             :                 {
     784          36 :                     SwFrmFmt *pOld = pBox->GetFrmFmt();
     785          36 :                     SwFrmFmt *pNew = pBox->ClaimFrmFmt();
     786          36 :                     pNew->SetFmtAttr( aBox );
     787          36 :                     aFmtCmp.push_back( new SwTblFmtCmp( pOld, pNew, nType ) );
     788             :                 }
     789          36 :             }
     790             : 
     791           4 :             bFirst = false;
     792           4 :         }
     793             : 
     794           4 :         SwHTMLTableLayout *pTableLayout = rTable.GetHTMLTableLayout();
     795           4 :         if( pTableLayout )
     796             :         {
     797           0 :             SwCntntFrm* pFrm = rCursor.GetCntntNode()->getLayoutFrm( rCursor.GetCntntNode()->GetDoc()->GetCurrentLayout() );
     798           0 :             SwTabFrm* pTabFrm = pFrm->ImplFindTabFrm();
     799             : 
     800             :             pTableLayout->BordersChanged(
     801           0 :                 pTableLayout->GetBrowseWidthByTabFrm( *pTabFrm ), sal_True );
     802             :         }
     803           4 :         SwTblFmtCmp::Delete( aFmtCmp );
     804           4 :         ::ClearFEShellTabCols();
     805           4 :         SetModified();
     806           5 :     }
     807             : }
     808             : 
     809           0 : static void lcl_SetLineStyle( SvxBorderLine *pToSet,
     810             :                           const Color *pColor, const SvxBorderLine *pBorderLine)
     811             : {
     812           0 :     if ( pBorderLine )
     813             :     {
     814           0 :         if ( !pColor )
     815             :         {
     816           0 :             Color aTmp( pToSet->GetColor() );
     817           0 :             *pToSet = *pBorderLine;
     818           0 :             pToSet->SetColor( aTmp );
     819             :         }
     820             :         else
     821           0 :             *pToSet = *pBorderLine;
     822             :     }
     823           0 :     if ( pColor )
     824           0 :         pToSet->SetColor( *pColor );
     825           0 : }
     826             : 
     827           0 : void SwDoc::SetTabLineStyle( const SwCursor& rCursor,
     828             :                              const Color* pColor, sal_Bool bSetLine,
     829             :                              const SvxBorderLine* pBorderLine )
     830             : {
     831           0 :     SwCntntNode* pCntNd = rCursor.GetPoint()->nNode.GetNode().GetCntntNode();
     832           0 :     SwTableNode* pTblNd = pCntNd ? pCntNd->FindTableNode() : 0;
     833           0 :     if( !pTblNd )
     834           0 :         return ;
     835             : 
     836             :     SwLayoutFrm *pStart, *pEnd;
     837           0 :     ::lcl_GetStartEndCell( rCursor, pStart, pEnd );
     838             : 
     839           0 :     SwSelUnions aUnions;
     840           0 :     ::MakeSelUnions( aUnions, pStart, pEnd );
     841             : 
     842           0 :     if( !aUnions.empty() )
     843             :     {
     844           0 :         SwTable& rTable = pTblNd->GetTable();
     845           0 :         if (GetIDocumentUndoRedo().DoesUndo())
     846             :         {
     847           0 :             GetIDocumentUndoRedo().AppendUndo(new SwUndoAttrTbl(*pTblNd));
     848             :         }
     849             : 
     850           0 :         for( sal_uInt16 i = 0; i < aUnions.size(); ++i )
     851             :         {
     852           0 :             SwSelUnion *pUnion = &aUnions[i];
     853           0 :             SwTabFrm *pTab = pUnion->GetTable();
     854           0 :             std::vector<SwCellFrm*> aCellArr;
     855           0 :             aCellArr.reserve( 255 );
     856           0 :             ::lcl_CollectCells( aCellArr, pUnion->GetUnion(), pTab );
     857             : 
     858           0 :             for ( sal_uInt16 j = 0; j < aCellArr.size(); ++j )
     859             :             {
     860           0 :                 SwCellFrm *pCell = aCellArr[j];
     861             : 
     862             :                 // Do not set anything by default in HeadlineRepeats
     863           0 :                 if ( pTab->IsFollow() && pTab->IsInHeadline( *pCell ) )
     864           0 :                     continue;
     865             : 
     866           0 :                 ((SwTableBox*)pCell->GetTabBox())->ClaimFrmFmt();
     867           0 :                 SwFrmFmt *pFmt = pCell->GetFmt();
     868           0 :                 SvxBoxItem aBox( pFmt->GetBox() );
     869             : 
     870           0 :                 if ( !pBorderLine && bSetLine )
     871           0 :                     aBox = *(SvxBoxItem*)::GetDfltAttr( RES_BOX );
     872             :                 else
     873             :                 {
     874           0 :                     if ( aBox.GetTop() )
     875           0 :                         ::lcl_SetLineStyle( (SvxBorderLine*)aBox.GetTop(),
     876           0 :                                         pColor, pBorderLine );
     877           0 :                     if ( aBox.GetBottom() )
     878           0 :                         ::lcl_SetLineStyle( (SvxBorderLine*)aBox.GetBottom(),
     879           0 :                                         pColor, pBorderLine );
     880           0 :                     if ( aBox.GetLeft() )
     881           0 :                         ::lcl_SetLineStyle( (SvxBorderLine*)aBox.GetLeft(),
     882           0 :                                         pColor, pBorderLine );
     883           0 :                     if ( aBox.GetRight() )
     884           0 :                         ::lcl_SetLineStyle( (SvxBorderLine*)aBox.GetRight(),
     885           0 :                                         pColor, pBorderLine );
     886             :                 }
     887           0 :                 pFmt->SetFmtAttr( aBox );
     888           0 :             }
     889           0 :         }
     890             : 
     891           0 :         SwHTMLTableLayout *pTableLayout = rTable.GetHTMLTableLayout();
     892           0 :         if( pTableLayout )
     893             :         {
     894           0 :             SwCntntFrm* pFrm = rCursor.GetCntntNode()->getLayoutFrm( rCursor.GetCntntNode()->GetDoc()->GetCurrentLayout() );
     895           0 :             SwTabFrm* pTabFrm = pFrm->ImplFindTabFrm();
     896             : 
     897             :             pTableLayout->BordersChanged(
     898           0 :                 pTableLayout->GetBrowseWidthByTabFrm( *pTabFrm ), sal_True );
     899             :         }
     900           0 :         ::ClearFEShellTabCols();
     901           0 :         SetModified();
     902           0 :     }
     903             : }
     904             : 
     905          26 : void SwDoc::GetTabBorders( const SwCursor& rCursor, SfxItemSet& rSet ) const
     906             : {
     907          26 :     SwCntntNode* pCntNd = rCursor.GetPoint()->nNode.GetNode().GetCntntNode();
     908          26 :     SwTableNode* pTblNd = pCntNd ? pCntNd->FindTableNode() : 0;
     909          26 :     if( !pTblNd )
     910          26 :         return ;
     911             : 
     912             :     SwLayoutFrm *pStart, *pEnd;
     913          26 :     ::lcl_GetStartEndCell( rCursor, pStart, pEnd );
     914             : 
     915          26 :     SwSelUnions aUnions;
     916          26 :     ::MakeSelUnions( aUnions, pStart, pEnd );
     917             : 
     918          26 :     if( !aUnions.empty() )
     919             :     {
     920          24 :         SvxBoxItem     aSetBox    ((const SvxBoxItem    &) rSet.Get(RES_BOX    ));
     921          48 :         SvxBoxInfoItem aSetBoxInfo((const SvxBoxInfoItem&) rSet.Get(SID_ATTR_BORDER_INNER));
     922             : 
     923          24 :         sal_Bool bTopSet      = sal_False,
     924          24 :              bBottomSet   = sal_False,
     925          24 :              bLeftSet     = sal_False,
     926          24 :              bRightSet    = sal_False,
     927          24 :              bHoriSet     = sal_False,
     928          24 :              bVertSet     = sal_False,
     929          24 :              bDistanceSet = sal_False,
     930          24 :              bRTLTab      = sal_False;
     931             : 
     932          24 :         aSetBoxInfo.ResetFlags();
     933             : 
     934          48 :         for ( sal_uInt16 i = 0; i < aUnions.size(); ++i )
     935             :         {
     936          24 :             SwSelUnion *pUnion = &aUnions[i];
     937          24 :             const SwTabFrm *pTab = pUnion->GetTable();
     938          24 :             const SwRect &rUnion = pUnion->GetUnion();
     939          24 :             const bool bFirst = i == 0;
     940          24 :             const bool bLast  = (i == aUnions.size() - 1);
     941             : 
     942          24 :             std::vector<SwCellFrm*> aCellArr;
     943          24 :             aCellArr.reserve(255);
     944          24 :             ::lcl_CollectCells( aCellArr, rUnion, (SwTabFrm*)pTab );
     945             : 
     946         158 :             for ( sal_uInt16 j = 0; j < aCellArr.size(); ++j )
     947             :             {
     948         134 :                 SwCellFrm *pCell = aCellArr[j];
     949         134 :                 const sal_Bool bVert = pTab->IsVertical();
     950         134 :                 const sal_Bool bRTL = bRTLTab = pTab->IsRightToLeft();
     951             :                 sal_Bool bTopOver, bLeftOver, bRightOver, bBottomOver;
     952         134 :                 if ( bVert )
     953             :                 {
     954           0 :                     bTopOver = pCell->Frm().Right() >= rUnion.Right();
     955           0 :                     bLeftOver = pCell->Frm().Top() <= rUnion.Top();
     956           0 :                     bRightOver = pCell->Frm().Bottom() >= rUnion.Bottom();
     957           0 :                     bBottomOver = pCell->Frm().Left() <= rUnion.Left();
     958             :                 }
     959             :                 else
     960             :                 {
     961         134 :                     bTopOver = pCell->Frm().Top() <= rUnion.Top();
     962         134 :                     bLeftOver = pCell->Frm().Left() <= rUnion.Left();
     963         134 :                     bRightOver = pCell->Frm().Right() >= rUnion.Right();
     964         134 :                     bBottomOver = pCell->Frm().Bottom() >= rUnion.Bottom();
     965             :                 }
     966             : 
     967         134 :                 if ( bRTL )
     968             :                 {
     969           0 :                     sal_Bool bTmp = bRightOver;
     970           0 :                     bRightOver = bLeftOver;
     971           0 :                     bLeftOver = bTmp;
     972             :                 }
     973             : 
     974         134 :                 const SwFrmFmt  *pFmt  = pCell->GetFmt();
     975         134 :                 const SvxBoxItem  &rBox  = pFmt->GetBox();
     976             : 
     977             :                 // Top Border
     978         134 :                 if ( bFirst && bTopOver )
     979             :                 {
     980          54 :                     if (aSetBoxInfo.IsValid(VALID_TOP))
     981             :                     {
     982          54 :                         if ( !bTopSet )
     983          24 :                         {   bTopSet = sal_True;
     984          24 :                             aSetBox.SetLine( rBox.GetTop(), BOX_LINE_TOP );
     985             :                         }
     986         120 :                         else if ((aSetBox.GetTop() && rBox.GetTop() &&
     987          90 :                                  !(*aSetBox.GetTop() == *rBox.GetTop())) ||
     988          30 :                                  ((!aSetBox.GetTop()) != (!rBox.GetTop()))) // XOR expression is sal_True, if one of the two pointers is 0
     989             :                         {
     990           0 :                             aSetBoxInfo.SetValid(VALID_TOP, false );
     991           0 :                             aSetBox.SetLine( 0, BOX_LINE_TOP );
     992             :                         }
     993             :                     }
     994             :                 }
     995             : 
     996             :                 // Left Border
     997         134 :                 if ( bLeftOver )
     998             :                 {
     999          54 :                     if (aSetBoxInfo.IsValid(VALID_LEFT))
    1000             :                     {
    1001          54 :                         if ( !bLeftSet )
    1002          24 :                         {   bLeftSet = sal_True;
    1003          24 :                             aSetBox.SetLine( rBox.GetLeft(), BOX_LINE_LEFT );
    1004             :                         }
    1005         120 :                         else if ((aSetBox.GetLeft() && rBox.GetLeft() &&
    1006          90 :                                  !(*aSetBox.GetLeft() == *rBox.GetLeft())) ||
    1007          30 :                                  ((!aSetBox.GetLeft()) != (!rBox.GetLeft())))
    1008             :                         {
    1009           0 :                             aSetBoxInfo.SetValid(VALID_LEFT, false );
    1010           0 :                             aSetBox.SetLine( 0, BOX_LINE_LEFT );
    1011             :                         }
    1012             :                     }
    1013             :                 }
    1014             :                 else
    1015             :                 {
    1016          80 :                     if (aSetBoxInfo.IsValid(VALID_VERT))
    1017             :                     {
    1018          74 :                         if ( !bVertSet )
    1019          20 :                         {   bVertSet = sal_True;
    1020          20 :                             aSetBoxInfo.SetLine( rBox.GetLeft(), BOXINFO_LINE_VERT );
    1021             :                         }
    1022         216 :                         else if ((aSetBoxInfo.GetVert() && rBox.GetLeft() &&
    1023         160 :                                  !(*aSetBoxInfo.GetVert() == *rBox.GetLeft())) ||
    1024          52 :                                  ((!aSetBoxInfo.GetVert()) != (!rBox.GetLeft())))
    1025           2 :                         {   aSetBoxInfo.SetValid( VALID_VERT, false );
    1026           2 :                             aSetBoxInfo.SetLine( 0, BOXINFO_LINE_VERT );
    1027             :                         }
    1028             :                     }
    1029             :                 }
    1030             : 
    1031             :                 // Right Border
    1032         134 :                 if ( aSetBoxInfo.IsValid(VALID_RIGHT) && bRightOver )
    1033             :                 {
    1034          54 :                     if ( !bRightSet )
    1035          24 :                     {   bRightSet = sal_True;
    1036          24 :                         aSetBox.SetLine( rBox.GetRight(), BOX_LINE_RIGHT );
    1037             :                     }
    1038         120 :                     else if ((aSetBox.GetRight() && rBox.GetRight() &&
    1039          90 :                              !(*aSetBox.GetRight() == *rBox.GetRight())) ||
    1040          30 :                              (!aSetBox.GetRight() != !rBox.GetRight()))
    1041           0 :                     {   aSetBoxInfo.SetValid( VALID_RIGHT, false );
    1042           0 :                         aSetBox.SetLine( 0, BOX_LINE_RIGHT );
    1043             :                     }
    1044             :                 }
    1045             : 
    1046             :                 // Bottom Border
    1047         134 :                 if ( bLast && bBottomOver )
    1048             :                 {
    1049         108 :                     if ( aSetBoxInfo.IsValid(VALID_BOTTOM) )
    1050             :                     {
    1051          54 :                         if ( !bBottomSet )
    1052          24 :                         {   bBottomSet = sal_True;
    1053          24 :                             aSetBox.SetLine( rBox.GetBottom(), BOX_LINE_BOTTOM );
    1054             :                         }
    1055         116 :                         else if ((aSetBox.GetBottom() && rBox.GetBottom() &&
    1056          88 :                                  !(*aSetBox.GetBottom() == *rBox.GetBottom())) ||
    1057          30 :                                  (!aSetBox.GetBottom() != !rBox.GetBottom()))
    1058           0 :                         {   aSetBoxInfo.SetValid( VALID_BOTTOM, false );
    1059           0 :                             aSetBox.SetLine( 0, BOX_LINE_BOTTOM );
    1060             :                         }
    1061             :                     }
    1062             :                 }
    1063             :                 // In all Lines, except for the last one, the horizontal Line
    1064             :                 // is taken from the Bottom Line.
    1065             :                 else
    1066             :                 {
    1067          80 :                     if (aSetBoxInfo.IsValid(VALID_HORI))
    1068             :                     {
    1069          72 :                         if ( !bHoriSet )
    1070          20 :                         {   bHoriSet = sal_True;
    1071          20 :                             aSetBoxInfo.SetLine( rBox.GetBottom(), BOXINFO_LINE_HORI );
    1072             :                         }
    1073         208 :                         else if ((aSetBoxInfo.GetHori() && rBox.GetBottom() &&
    1074         154 :                                  !(*aSetBoxInfo.GetHori() == *rBox.GetBottom())) ||
    1075          50 :                                  ((!aSetBoxInfo.GetHori()) != (!rBox.GetBottom())))
    1076             :                         {
    1077           2 :                             aSetBoxInfo.SetValid( VALID_HORI, false );
    1078           2 :                             aSetBoxInfo.SetLine( 0, BOXINFO_LINE_HORI );
    1079             :                         }
    1080             :                     }
    1081             :                 }
    1082             : 
    1083             :                 // Distance to text
    1084         134 :                 if (aSetBoxInfo.IsValid(VALID_DISTANCE))
    1085             :                 {
    1086             :                     static sal_uInt16 const aBorders[] = {
    1087             :                         BOX_LINE_BOTTOM, BOX_LINE_TOP,
    1088             :                         BOX_LINE_RIGHT, BOX_LINE_LEFT };
    1089         134 :                     const sal_uInt16* pBrd = aBorders;
    1090             : 
    1091         134 :                     if( !bDistanceSet ) // Set on first iteration
    1092             :                     {
    1093          24 :                         bDistanceSet = sal_True;
    1094         120 :                         for( int k = 0; k < 4; ++k, ++pBrd )
    1095          96 :                             aSetBox.SetDistance( rBox.GetDistance( *pBrd ), *pBrd );
    1096             :                     }
    1097             :                     else
    1098             :                     {
    1099         550 :                         for( int k = 0; k < 4; ++k, ++pBrd )
    1100         880 :                             if( aSetBox.GetDistance( *pBrd ) !=
    1101         440 :                                 rBox.GetDistance( *pBrd ) )
    1102             :                             {
    1103           0 :                                 aSetBoxInfo.SetValid( VALID_DISTANCE, false );
    1104           0 :                                 aSetBox.SetDistance( (sal_uInt16) 0 );
    1105           0 :                                 break;
    1106             :                             }
    1107             :                     }
    1108             :                 }
    1109             :             }
    1110          24 :         }
    1111             : 
    1112             :         // fdo#62470 fix the reading for table format.
    1113          24 :         if ( bRTLTab )
    1114             :         {
    1115           0 :             SvxBoxItem     aTempBox    ((const SvxBoxItem    &) rSet.Get(RES_BOX    ));
    1116           0 :             SvxBoxInfoItem aTempBoxInfo((const SvxBoxInfoItem&) rSet.Get(SID_ATTR_BORDER_INNER));
    1117             : 
    1118           0 :             aTempBox.SetLine( aSetBox.GetRight(), BOX_LINE_RIGHT);
    1119           0 :             aSetBox.SetLine( aSetBox.GetLeft(), BOX_LINE_RIGHT);
    1120           0 :             aSetBox.SetLine( aTempBox.GetRight(), BOX_LINE_LEFT);
    1121             : 
    1122           0 :             aTempBoxInfo.SetValid( VALID_LEFT, aSetBoxInfo.IsValid(VALID_LEFT) );
    1123           0 :             aSetBoxInfo.SetValid( VALID_LEFT, aSetBoxInfo.IsValid(VALID_RIGHT) );
    1124           0 :             aSetBoxInfo.SetValid( VALID_RIGHT, aTempBoxInfo.IsValid(VALID_LEFT) );
    1125             :         }
    1126             : 
    1127          24 :         rSet.Put( aSetBox );
    1128          48 :         rSet.Put( aSetBoxInfo );
    1129          26 :     }
    1130             : }
    1131             : 
    1132           0 : void SwDoc::SetBoxAttr( const SwCursor& rCursor, const SfxPoolItem &rNew )
    1133             : {
    1134           0 :     SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
    1135           0 :     SwSelBoxes aBoxes;
    1136           0 :     if( pTblNd && ::lcl_GetBoxSel( rCursor, aBoxes, true ) )
    1137             :     {
    1138           0 :         SwTable& rTable = pTblNd->GetTable();
    1139           0 :         if (GetIDocumentUndoRedo().DoesUndo())
    1140             :         {
    1141           0 :             GetIDocumentUndoRedo().AppendUndo( new SwUndoAttrTbl(*pTblNd) );
    1142             :         }
    1143             : 
    1144           0 :         std::vector<SwTblFmtCmp*> aFmtCmp;
    1145           0 :         aFmtCmp.reserve(std::max<size_t>(255, aBoxes.size()));
    1146           0 :         for (size_t i = 0; i < aBoxes.size(); ++i)
    1147             :         {
    1148           0 :             SwTableBox *pBox = aBoxes[i];
    1149             : 
    1150             :             SwFrmFmt *pNewFmt;
    1151           0 :             if ( 0 != (pNewFmt = SwTblFmtCmp::FindNewFmt( aFmtCmp, pBox->GetFrmFmt(), 0 )))
    1152           0 :                 pBox->ChgFrmFmt( (SwTableBoxFmt*)pNewFmt );
    1153             :             else
    1154             :             {
    1155           0 :                 SwFrmFmt *pOld = pBox->GetFrmFmt();
    1156           0 :                 SwFrmFmt *pNew = pBox->ClaimFrmFmt();
    1157           0 :                 pNew->SetFmtAttr( rNew );
    1158           0 :                 aFmtCmp.push_back( new SwTblFmtCmp( pOld, pNew, 0 ) );
    1159             :             }
    1160             :         }
    1161             : 
    1162           0 :         SwHTMLTableLayout *pTableLayout = rTable.GetHTMLTableLayout();
    1163           0 :         if( pTableLayout )
    1164             :         {
    1165           0 :             SwCntntFrm* pFrm = rCursor.GetCntntNode()->getLayoutFrm( rCursor.GetCntntNode()->GetDoc()->GetCurrentLayout() );
    1166           0 :             SwTabFrm* pTabFrm = pFrm->ImplFindTabFrm();
    1167             : 
    1168             :             pTableLayout->Resize(
    1169           0 :                 pTableLayout->GetBrowseWidthByTabFrm( *pTabFrm ), sal_True );
    1170             :         }
    1171           0 :         SwTblFmtCmp::Delete( aFmtCmp );
    1172           0 :         SetModified();
    1173           0 :     }
    1174           0 : }
    1175             : 
    1176           3 : sal_Bool SwDoc::GetBoxAttr( const SwCursor& rCursor, SfxPoolItem& rToFill ) const
    1177             : {
    1178           3 :     sal_Bool bRet = sal_False;
    1179           3 :     SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
    1180           3 :     SwSelBoxes aBoxes;
    1181           3 :     if( pTblNd && lcl_GetBoxSel( rCursor, aBoxes ))
    1182             :     {
    1183           3 :         bRet = sal_True;
    1184           3 :         bool bOneFound = false;
    1185           3 :         const sal_uInt16 nWhich = rToFill.Which();
    1186          15 :         for (size_t i = 0; i < aBoxes.size(); ++i)
    1187             :         {
    1188          12 :             switch ( nWhich )
    1189             :             {
    1190             :                 case RES_BACKGROUND:
    1191             :                 {
    1192             :                     const SvxBrushItem &rBack =
    1193          12 :                                     aBoxes[i]->GetFrmFmt()->GetBackground();
    1194          12 :                     if( !bOneFound )
    1195             :                     {
    1196           3 :                         (SvxBrushItem&)rToFill = rBack;
    1197           3 :                         bOneFound = true;
    1198             :                     }
    1199           9 :                     else if( rToFill != rBack )
    1200           0 :                         bRet = sal_False;
    1201             :                 }
    1202          12 :                 break;
    1203             : 
    1204             :                 case RES_FRAMEDIR:
    1205             :                 {
    1206             :                     const SvxFrameDirectionItem& rDir =
    1207           0 :                                     aBoxes[i]->GetFrmFmt()->GetFrmDir();
    1208           0 :                     if( !bOneFound )
    1209             :                     {
    1210           0 :                         (SvxFrameDirectionItem&)rToFill = rDir;
    1211           0 :                         bOneFound = true;
    1212             :                     }
    1213           0 :                     else if( rToFill != rDir )
    1214           0 :                         bRet = sal_False;
    1215             :                 }
    1216             :             }
    1217             : 
    1218          12 :             if ( sal_False == bRet )
    1219           0 :                 break;
    1220             :         }
    1221             :     }
    1222           3 :     return bRet;
    1223             : }
    1224             : 
    1225           0 : void SwDoc::SetBoxAlign( const SwCursor& rCursor, sal_uInt16 nAlign )
    1226             : {
    1227             :     OSL_ENSURE( nAlign == text::VertOrientation::NONE   ||
    1228             :             nAlign == text::VertOrientation::CENTER ||
    1229             :             nAlign == text::VertOrientation::BOTTOM, "Wrong alignment" );
    1230           0 :     SwFmtVertOrient aVertOri( 0, nAlign );
    1231           0 :     SetBoxAttr( rCursor, aVertOri );
    1232           0 : }
    1233             : 
    1234          12 : sal_uInt16 SwDoc::GetBoxAlign( const SwCursor& rCursor ) const
    1235             : {
    1236          12 :     sal_uInt16 nAlign = USHRT_MAX;
    1237          12 :     SwTableNode* pTblNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
    1238          12 :     SwSelBoxes aBoxes;
    1239          12 :     if( pTblNd && ::lcl_GetBoxSel( rCursor, aBoxes ))
    1240             :     {
    1241          51 :         for (size_t i = 0; i < aBoxes.size(); ++i)
    1242             :         {
    1243             :             const SwFmtVertOrient &rOri =
    1244          39 :                             aBoxes[i]->GetFrmFmt()->GetVertOrient();
    1245          39 :             if( USHRT_MAX == nAlign )
    1246          12 :                 nAlign = static_cast<sal_uInt16>(rOri.GetVertOrient());
    1247          27 :             else if( rOri.GetVertOrient() != nAlign )
    1248             :             {
    1249           0 :                 nAlign = USHRT_MAX;
    1250           0 :                 break;
    1251             :             }
    1252             :         }
    1253             :     }
    1254          12 :     return nAlign;
    1255             : }
    1256             : 
    1257           0 : static sal_uInt16 lcl_CalcCellFit( const SwLayoutFrm *pCell )
    1258             : {
    1259           0 :     SwTwips nRet = 0;
    1260           0 :     const SwFrm *pFrm = pCell->Lower(); // The whole Line
    1261           0 :     SWRECTFN( pCell )
    1262           0 :     while ( pFrm )
    1263             :     {
    1264           0 :         const SwTwips nAdd = (pFrm->Frm().*fnRect->fnGetWidth)() -
    1265           0 :                              (pFrm->Prt().*fnRect->fnGetWidth)();
    1266             : 
    1267             :         // pFrm does not necessarily have to be a SwTxtFrm!
    1268           0 :         const SwTwips nCalcFitToContent = pFrm->IsTxtFrm() ?
    1269             :                                           ((SwTxtFrm*)pFrm)->CalcFitToContent() :
    1270           0 :                                           (pFrm->Prt().*fnRect->fnGetWidth)();
    1271             : 
    1272           0 :         nRet = std::max( nRet, nCalcFitToContent + nAdd );
    1273           0 :         pFrm = pFrm->GetNext();
    1274             :     }
    1275             :     // Surrounding border as well as left and Right Border also need to be respected
    1276           0 :     nRet += (pCell->Frm().*fnRect->fnGetWidth)() -
    1277           0 :             (pCell->Prt().*fnRect->fnGetWidth)();
    1278             : 
    1279             :     // To compensate for the accuracy of calculation later on in SwTable::SetTabCols
    1280             :     // we keep adding up a little.
    1281           0 :     nRet += COLFUZZY;
    1282           0 :     return (sal_uInt16)std::max( long(MINLAY), nRet );
    1283             : }
    1284             : 
    1285             : /* The Line is within the Selection but not outlined by the TabCols.
    1286             :  *
    1287             :  * That means that the Line has been "split" by other Cells due to the
    1288             :  * two-dimensional representation used. Thus, we have to distribute the cell's
    1289             :  * default or minium value amongst the Cell it has been split by.
    1290             :  *
    1291             :  * First, we collect the Columns (not the Column separators) which overlap
    1292             :  * with the Cell. We then distribute the desired value according to the
    1293             :  * amount of overlapping amongst the Cells.
    1294             :  *
    1295             :  * A Cell's default value stays the same if it already has a larger value than
    1296             :  * the desired one. It's overwritten if it's smaller.
    1297             :  */
    1298           0 : static void lcl_CalcSubColValues( std::vector<sal_uInt16> &rToFill, const SwTabCols &rCols,
    1299             :                               const SwLayoutFrm *pCell, const SwLayoutFrm *pTab,
    1300             :                               sal_Bool bWishValues )
    1301             : {
    1302             :     const sal_uInt16 nWish = bWishValues ?
    1303             :                     ::lcl_CalcCellFit( pCell ) :
    1304           0 :                     MINLAY + sal_uInt16(pCell->Frm().Width() - pCell->Prt().Width());
    1305             : 
    1306           0 :     SWRECTFN( pTab )
    1307             : 
    1308           0 :     for ( size_t i = 0 ; i <= rCols.Count(); ++i )
    1309             :     {
    1310           0 :         long nColLeft  = i == 0             ? rCols.GetLeft()  : rCols[i-1];
    1311           0 :         long nColRight = i == rCols.Count() ? rCols.GetRight() : rCols[i];
    1312           0 :         nColLeft  += rCols.GetLeftMin();
    1313           0 :         nColRight += rCols.GetLeftMin();
    1314             : 
    1315             :         // Adapt values to the proportions of the Table (Follows)
    1316           0 :         if ( rCols.GetLeftMin() != (pTab->Frm().*fnRect->fnGetLeft)() )
    1317             :         {
    1318           0 :             const long nDiff = (pTab->Frm().*fnRect->fnGetLeft)() - rCols.GetLeftMin();
    1319           0 :             nColLeft  += nDiff;
    1320           0 :             nColRight += nDiff;
    1321             :         }
    1322           0 :         const long nCellLeft  = (pCell->Frm().*fnRect->fnGetLeft)();
    1323           0 :         const long nCellRight = (pCell->Frm().*fnRect->fnGetRight)();
    1324             : 
    1325             :         // Calculate overlapping value
    1326           0 :         long nWidth = 0;
    1327           0 :         if ( nColLeft <= nCellLeft && nColRight >= (nCellLeft+COLFUZZY) )
    1328           0 :             nWidth = nColRight - nCellLeft;
    1329           0 :         else if ( nColLeft <= (nCellRight-COLFUZZY) && nColRight >= nCellRight )
    1330           0 :             nWidth = nCellRight - nColLeft;
    1331           0 :         else if ( nColLeft >= nCellLeft && nColRight <= nCellRight )
    1332           0 :             nWidth = nColRight - nColLeft;
    1333           0 :         if ( nWidth && pCell->Frm().Width() )
    1334             :         {
    1335           0 :             long nTmp = nWidth * nWish / pCell->Frm().Width();
    1336           0 :             if ( sal_uInt16(nTmp) > rToFill[i] )
    1337           0 :                 rToFill[i] = sal_uInt16(nTmp);
    1338             :         }
    1339             :     }
    1340           0 : }
    1341             : 
    1342             : /**
    1343             :  * Retrievs new values to set the TabCols.
    1344             :  *
    1345             :  * We do not iterate over the TabCols' entries, but over the gaps that describe Cells.
    1346             :  *
    1347             :  * @param bWishValues == sal_True: We calculate the desired value of all affected
    1348             :  *                                 Cells for the current Selection/current Cell.
    1349             :  *                                 If more Cells are within a Column, the highest
    1350             :  *                                 desired value is returned.
    1351             :  *                                 We set TabCol entries for which we did not calculate
    1352             :  *                                 Cells to 0.
    1353             :  *
    1354             :  * @param bWishValues == sal_False: The Selection is expanded vertically.
    1355             :  *                                  We calculate the minimum value for every
    1356             :  *                                  Column in the TabCols that intersects with the
    1357             :  *                                  Selection.
    1358             :  */
    1359           0 : static void lcl_CalcColValues( std::vector<sal_uInt16> &rToFill, const SwTabCols &rCols,
    1360             :                            const SwLayoutFrm *pStart, const SwLayoutFrm *pEnd,
    1361             :                            sal_Bool bWishValues )
    1362             : {
    1363           0 :     SwSelUnions aUnions;
    1364             :     ::MakeSelUnions( aUnions, pStart, pEnd,
    1365           0 :                     bWishValues ? nsSwTblSearchType::TBLSEARCH_NONE : nsSwTblSearchType::TBLSEARCH_COL );
    1366             : 
    1367           0 :     for ( sal_uInt16 i2 = 0; i2 < aUnions.size(); ++i2 )
    1368             :     {
    1369           0 :         SwSelUnion *pSelUnion = &aUnions[i2];
    1370           0 :         const SwTabFrm *pTab = pSelUnion->GetTable();
    1371           0 :         const SwRect &rUnion = pSelUnion->GetUnion();
    1372             : 
    1373           0 :         SWRECTFN( pTab )
    1374           0 :         sal_Bool bRTL = pTab->IsRightToLeft();
    1375             : 
    1376           0 :         const SwLayoutFrm *pCell = pTab->FirstCell();
    1377           0 :         do
    1378             :         {
    1379           0 :             if ( pCell->IsCellFrm() && pCell->FindTabFrm() == pTab && ::IsFrmInTblSel( rUnion, pCell ) )
    1380             :             {
    1381           0 :                 const long nCLeft  = (pCell->Frm().*fnRect->fnGetLeft)();
    1382           0 :                 const long nCRight = (pCell->Frm().*fnRect->fnGetRight)();
    1383             : 
    1384           0 :                 bool bNotInCols = true;
    1385             : 
    1386           0 :                 for ( size_t i = 0; i <= rCols.Count(); ++i )
    1387             :                 {
    1388           0 :                     sal_uInt16 nFit = rToFill[i];
    1389           0 :                     long nColLeft  = i == 0             ? rCols.GetLeft()  : rCols[i-1];
    1390           0 :                     long nColRight = i == rCols.Count() ? rCols.GetRight() : rCols[i];
    1391             : 
    1392           0 :                     if ( bRTL )
    1393             :                     {
    1394           0 :                         long nTmpRight = nColRight;
    1395           0 :                         nColRight = rCols.GetRight() - nColLeft;
    1396           0 :                         nColLeft = rCols.GetRight() - nTmpRight;
    1397             :                     }
    1398             : 
    1399           0 :                     nColLeft  += rCols.GetLeftMin();
    1400           0 :                     nColRight += rCols.GetLeftMin();
    1401             : 
    1402             :                     // Adapt values to the proportions of the Table (Follows)
    1403           0 :                     long nLeftA  = nColLeft;
    1404           0 :                     long nRightA = nColRight;
    1405           0 :                     if ( rCols.GetLeftMin() !=  sal_uInt16((pTab->Frm().*fnRect->fnGetLeft)()) )
    1406             :                     {
    1407           0 :                         const long nDiff = (pTab->Frm().*fnRect->fnGetLeft)() - rCols.GetLeftMin();
    1408           0 :                         nLeftA  += nDiff;
    1409           0 :                         nRightA += nDiff;
    1410             :                     }
    1411             : 
    1412             :                     // We don't want to take a too close look
    1413           0 :                     if ( ::IsSame(nCLeft, nLeftA) && ::IsSame(nCRight, nRightA))
    1414             :                     {
    1415           0 :                         bNotInCols = false;
    1416           0 :                         if ( bWishValues )
    1417             :                         {
    1418           0 :                             const sal_uInt16 nWish = ::lcl_CalcCellFit( pCell );
    1419           0 :                             if ( nWish > nFit )
    1420           0 :                                 nFit = nWish;
    1421             :                         }
    1422             :                         else
    1423           0 :                         {   const sal_uInt16 nMin = MINLAY + sal_uInt16(pCell->Frm().Width() -
    1424           0 :                                                                 pCell->Prt().Width());
    1425           0 :                             if ( !nFit || nMin < nFit )
    1426           0 :                                 nFit = nMin;
    1427             :                         }
    1428           0 :                         if ( rToFill[i] < nFit )
    1429           0 :                             rToFill[i] = nFit;
    1430             :                     }
    1431             :                 }
    1432           0 :                 if ( bNotInCols )
    1433           0 :                     ::lcl_CalcSubColValues( rToFill, rCols, pCell, pTab, bWishValues );
    1434             :             }
    1435           0 :             do {
    1436           0 :                 pCell = pCell->GetNextLayoutLeaf();
    1437           0 :             } while( pCell && pCell->Frm().Width() == 0 );
    1438           0 :         } while ( pCell && pTab->IsAnLower( pCell ) );
    1439           0 :     }
    1440           0 : }
    1441             : 
    1442           0 : void SwDoc::AdjustCellWidth( const SwCursor& rCursor, sal_Bool bBalance )
    1443             : {
    1444             :     // Check whether the current Crsr has it's Point/Mark in a Table
    1445           0 :     SwCntntNode* pCntNd = rCursor.GetPoint()->nNode.GetNode().GetCntntNode();
    1446           0 :     SwTableNode* pTblNd = pCntNd ? pCntNd->FindTableNode() : 0;
    1447           0 :     if( !pTblNd )
    1448           0 :         return ;
    1449             : 
    1450             :     SwLayoutFrm *pStart, *pEnd;
    1451           0 :     ::lcl_GetStartEndCell( rCursor, pStart, pEnd );
    1452             : 
    1453             :     // Collect TabCols; we reset the Table with them
    1454           0 :     SwFrm* pBoxFrm = pStart;
    1455           0 :     while( pBoxFrm && !pBoxFrm->IsCellFrm() )
    1456           0 :         pBoxFrm = pBoxFrm->GetUpper();
    1457             : 
    1458           0 :     if ( !pBoxFrm )
    1459           0 :         return; // Robust
    1460             : 
    1461           0 :     SwTabCols aTabCols;
    1462           0 :     GetTabCols( aTabCols, 0, (SwCellFrm*)pBoxFrm );
    1463             : 
    1464           0 :     if ( ! aTabCols.Count() )
    1465           0 :         return;
    1466             : 
    1467           0 :     std::vector<sal_uInt16> aWish(aTabCols.Count() + 1);
    1468           0 :     std::vector<sal_uInt16> aMins(aTabCols.Count() + 1);
    1469             : 
    1470           0 :     ::lcl_CalcColValues( aWish, aTabCols, pStart, pEnd, sal_True  );
    1471             : 
    1472             :     // It's more robust if we calculate the minimum values for the whole Table
    1473           0 :     const SwTabFrm *pTab = pStart->ImplFindTabFrm();
    1474           0 :     pStart = (SwLayoutFrm*)pTab->FirstCell();
    1475           0 :     pEnd   = (SwLayoutFrm*)pTab->FindLastCntnt()->GetUpper();
    1476           0 :     while( !pEnd->IsCellFrm() )
    1477           0 :         pEnd = pEnd->GetUpper();
    1478           0 :     ::lcl_CalcColValues( aMins, aTabCols, pStart, pEnd, sal_False );
    1479             : 
    1480           0 :     if( bBalance )
    1481             :     {
    1482             :         // All Columns, which are now selected, have a desired value.
    1483             :         // We add up the current values, divide the result by their
    1484             :         // count and get a desired value for balancing.
    1485           0 :         sal_uInt16 nWish = 0, nCnt = 0;
    1486           0 :         for ( size_t i = 0; i <= aTabCols.Count(); ++i )
    1487             :         {
    1488           0 :             int nDiff = aWish[i];
    1489           0 :             if ( nDiff )
    1490             :             {
    1491           0 :                 if ( i == 0 )
    1492           0 :                     nWish += aTabCols[i] - aTabCols.GetLeft();
    1493           0 :                 else if ( i == aTabCols.Count() )
    1494           0 :                     nWish += aTabCols.GetRight() - aTabCols[i-1];
    1495             :                 else
    1496           0 :                     nWish += aTabCols[i] - aTabCols[i-1];
    1497           0 :                 ++nCnt;
    1498             :             }
    1499             :         }
    1500           0 :         nWish /= nCnt;
    1501           0 :         for ( size_t i = 0; i < aWish.size(); ++i )
    1502           0 :             if ( aWish[i] )
    1503           0 :                 aWish[i] = nWish;
    1504             :     }
    1505             : 
    1506           0 :     const long nOldRight = aTabCols.GetRight();
    1507             : 
    1508             :     // In order to make the implementation easier, but still use the available
    1509             :     // space properly, we do this twice.
    1510             : 
    1511             :     // The problem: The first column is getting wider, the others get slimmer
    1512             :     // only afterwards.
    1513             :     // The first column's desired width would be discarded as it would cause
    1514             :     // the Table's width to exceed the maximum width.
    1515           0 :     for ( sal_uInt16 k = 0; k < 2; ++k )
    1516             :     {
    1517           0 :         for ( size_t i = 0; i <= aTabCols.Count(); ++i )
    1518             :         {
    1519           0 :             int nDiff = aWish[i];
    1520           0 :             if ( nDiff )
    1521             :             {
    1522           0 :                 int nMin = aMins[i];
    1523           0 :                 if ( nMin > nDiff )
    1524           0 :                     nDiff = nMin;
    1525             : 
    1526           0 :                 if ( i == 0 )
    1527             :                 {
    1528           0 :                     if( aTabCols.Count() )
    1529           0 :                         nDiff -= aTabCols[0] - aTabCols.GetLeft();
    1530             :                     else
    1531           0 :                         nDiff -= aTabCols.GetRight() - aTabCols.GetLeft();
    1532             :                 }
    1533           0 :                 else if ( i == aTabCols.Count() )
    1534           0 :                     nDiff -= aTabCols.GetRight() - aTabCols[i-1];
    1535             :                 else
    1536           0 :                     nDiff -= aTabCols[i] - aTabCols[i-1];
    1537             : 
    1538           0 :                 long nTabRight = aTabCols.GetRight() + nDiff;
    1539             : 
    1540             :                 // If the Table would become too wide, we restrict the
    1541             :                 // adjusted amount to the allowed maximum.
    1542           0 :                 if ( !bBalance && nTabRight > aTabCols.GetRightMax() )
    1543             :                 {
    1544           0 :                     const long nTmpD = nTabRight - aTabCols.GetRightMax();
    1545           0 :                     nDiff     -= nTmpD;
    1546           0 :                     nTabRight -= nTmpD;
    1547             :                 }
    1548           0 :                 for ( size_t i2 = i; i2 < aTabCols.Count(); ++i2 )
    1549           0 :                     aTabCols[i2] += nDiff;
    1550           0 :                 aTabCols.SetRight( nTabRight );
    1551             :             }
    1552             :         }
    1553             :     }
    1554             : 
    1555           0 :     const long nNewRight = aTabCols.GetRight();
    1556             : 
    1557           0 :     SwFrmFmt *pFmt = pTblNd->GetTable().GetFrmFmt();
    1558           0 :     const sal_Int16 nOriHori = pFmt->GetHoriOrient().GetHoriOrient();
    1559             : 
    1560             :     // We can leave the "real" work to the SwTable now
    1561           0 :     SetTabCols( aTabCols, sal_False, 0, (SwCellFrm*)pBoxFrm );
    1562             : 
    1563             :     // Alignment might have been changed in SetTabCols; restore old value
    1564           0 :     const SwFmtHoriOrient &rHori = pFmt->GetHoriOrient();
    1565           0 :     SwFmtHoriOrient aHori( rHori );
    1566           0 :     if ( aHori.GetHoriOrient() != nOriHori )
    1567             :     {
    1568           0 :         aHori.SetHoriOrient( nOriHori );
    1569           0 :         pFmt->SetFmtAttr( aHori );
    1570             :     }
    1571             : 
    1572             :     // We switch to left-adjusted for automatic width
    1573             :     // We adjust the right border for Border attributes
    1574           0 :     if( !bBalance && nNewRight < nOldRight )
    1575             :     {
    1576           0 :         if( aHori.GetHoriOrient() == text::HoriOrientation::FULL )
    1577             :         {
    1578           0 :             aHori.SetHoriOrient( text::HoriOrientation::LEFT );
    1579           0 :             pFmt->SetFmtAttr( aHori );
    1580             :         }
    1581             :     }
    1582             : 
    1583           0 :     SetModified();
    1584             : }
    1585             : 
    1586             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10