LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/inc - tblsel.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 24 30 80.0 %
Date: 2013-07-09 Functions: 21 28 75.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             : #ifndef _TBLSEL_HXX
      20             : #define _TBLSEL_HXX
      21             : 
      22             : #include <swtable.hxx>
      23             : #include <swrect.hxx>
      24             : #include "swdllapi.h"
      25             : 
      26             : #include <deque>
      27             : #include <boost/ptr_container/ptr_vector.hpp>
      28             : #include <o3tl/sorted_vector.hxx>
      29             : 
      30             : class SwCrsrShell;
      31             : class SwCursor;
      32             : class SwTableCursor;
      33             : class SwFrm;
      34             : class SwTabFrm;
      35             : class SwTableBox;
      36             : class SwTableLine;
      37             : class SwLayoutFrm;
      38             : class SwPaM;
      39             : class SwNode;
      40             : class SwTable;
      41             : class SwUndoTblMerge;
      42             : class SwCellFrm;
      43             : 
      44             : typedef ::std::deque< SwCellFrm* > SwCellFrms;
      45             : 
      46             : struct CompareSwSelBoxes
      47             : {
      48        8898 :     bool operator()(SwTableBox* const& lhs, SwTableBox* const& rhs) const
      49             :     {
      50        8898 :         return lhs->GetSttIdx() < rhs->GetSttIdx();
      51             :     }
      52             : };
      53         922 : class SwSelBoxes : public o3tl::sorted_vector<SwTableBox*, CompareSwSelBoxes> {};
      54             : 
      55             : // Collects all boxes in table that are selected.
      56             : // Selection gets extended in given direction according to enum-parameter.
      57             : // Boxes are collected via the Layout; works correctly if tables are split.
      58             : // (Cf. MakeSelUnions().)
      59             : typedef sal_uInt16 SwTblSearchType;
      60             : namespace nsSwTblSearchType
      61             : {
      62             :     const SwTblSearchType TBLSEARCH_NONE = 0x1;       // No extension.
      63             :     const SwTblSearchType TBLSEARCH_ROW  = 0x2;       // Extend to rows.
      64             :     const SwTblSearchType TBLSEARCH_COL  = 0x3;       // Extend to columns.
      65             : 
      66             :     // As flag to the other values!
      67             :     const SwTblSearchType TBLSEARCH_PROTECT = 0x8;      // Collect protected boxes too.
      68             :     const SwTblSearchType TBLSEARCH_NO_UNION_CORRECT = 0x10; // Do not correct collected Union.
      69             : }
      70             : 
      71             : SW_DLLPUBLIC void GetTblSel( const SwCrsrShell& rShell, SwSelBoxes& rBoxes,
      72             :                 const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
      73             : 
      74             : void GetTblSel( const SwCursor& rCrsr, SwSelBoxes& rBoxes,
      75             :                 const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
      76             : 
      77             : 
      78             : // As before, but don't start from selection but from Start- EndFrms.
      79             : void GetTblSel( const SwLayoutFrm* pStart, const SwLayoutFrm* pEnd,
      80             :                 SwSelBoxes& rBoxes, SwCellFrms* pCells,
      81             :                 const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
      82             : 
      83             : // As before but directly via PaMs.
      84             : void GetTblSelCrs( const SwCrsrShell& rShell, SwSelBoxes& rBoxes );
      85             : void GetTblSelCrs( const SwTableCursor& rTblCrsr, SwSelBoxes& rBoxes );
      86             : 
      87             : // Collect boxes relevant for auto sum.
      88             : sal_Bool GetAutoSumSel( const SwCrsrShell&, SwCellFrms& );
      89             : 
      90             : // Check if the SelBoxes contains protected Boxes.
      91             : sal_Bool HasProtectedCells( const SwSelBoxes& rBoxes );
      92             : 
      93             : // Check if selection is balanced.
      94             : sal_Bool ChkChartSel( const SwNode& rSttNd, const SwNode& rEndNd);
      95             : 
      96             : // Check if cell is part of SSelection.
      97             : // (Became a function, in order to make sure that GetTblSel() and MakeTblCrsr()
      98             : // have always the same concept of the selection.
      99             : sal_Bool IsFrmInTblSel( const SwRect& rUnion, const SwFrm* pCell );
     100             : 
     101             : // Determine boxes to be merged.
     102             : // In this process the rectangle gets "adapted" on the base of the layout,
     103             : // i.e. boxes are added if some overlap at the sides.
     104             : // Additionally a new box is created and filled with the relevant content.
     105             : void GetMergeSel( const SwPaM& rPam, SwSelBoxes& rBoxes,
     106             :                   SwTableBox** ppMergeBox, SwUndoTblMerge* pUndo = 0 );
     107             : 
     108             : // Check if selected boxes allow for a valid merge.
     109             : sal_uInt16 CheckMergeSel( const SwPaM& rPam );
     110             : sal_uInt16 CheckMergeSel( const SwSelBoxes& rBoxes );
     111             : 
     112             : sal_Bool IsEmptyBox( const SwTableBox& rBox, SwPaM& rPam );
     113             : 
     114             : // Check if Split or InsertCol lead to a box becoming smaller than MINLAY.
     115             : sal_Bool CheckSplitCells( const SwCrsrShell& rShell, sal_uInt16 nDiv,
     116             :                         const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
     117             : sal_Bool CheckSplitCells( const SwCursor& rCrsr, sal_uInt16 nDiv,
     118             :                         const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
     119             : 
     120             : // For working on tab selection also for split tables.
     121             : class SwSelUnion
     122             : {
     123             :     SwRect   aUnion;        // The rectangle enclosing the selection.
     124             :     SwTabFrm *pTable;       // The (Follow-)Table for the Union.
     125             : 
     126             : public:
     127          20 :     SwSelUnion( const SwRect &rRect, SwTabFrm *pTab ) :
     128          20 :         aUnion( rRect ), pTable( pTab ) {}
     129             : 
     130             :     const SwRect&   GetUnion() const { return aUnion; }
     131          22 :           SwRect&   GetUnion()       { return aUnion; }
     132             :     const SwTabFrm *GetTable() const { return pTable; }
     133          20 :           SwTabFrm *GetTable()       { return pTable; }
     134             : };
     135             : 
     136             : // Determines tables affected by a table selection and union rectangles
     137             : // of the selection (also for split tables)
     138             : typedef boost::ptr_vector<SwSelUnion> SwSelUnions;
     139             : 
     140             : // Gets the tables involved in a table selection and the union-rectangles of the selections
     141             : // - also for split tables.
     142             : // If a parameter is passed that != nsSwTblSearchType::TBLSEARCH_NONE
     143             : // the selection is extended in the given direction.
     144             : void MakeSelUnions( SwSelUnions&, const SwLayoutFrm *pStart,
     145             :                     const SwLayoutFrm *pEnd,
     146             :                     const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
     147             : 
     148             : 
     149             : 
     150             : // These classes copy the current table selections (rBoxes) into a
     151             : // separate structure while keeping the table structure.
     152             : 
     153             : class _FndBox;
     154             : class _FndLine;
     155             : 
     156             : typedef boost::ptr_vector<_FndBox> _FndBoxes;
     157             : typedef boost::ptr_vector<_FndLine> _FndLines;
     158             : 
     159          92 : class _FndBox
     160             : {
     161             :     SwTableBox* pBox;
     162             :     _FndLines aLines;
     163             :     _FndLine* pUpper;
     164             : 
     165             :     SwTableLine *pLineBefore;   // For deleting/restoring the layout.
     166             :     SwTableLine *pLineBehind;
     167             : 
     168             : public:
     169          92 :     _FndBox( SwTableBox* pB, _FndLine* pFL ) :
     170          92 :         pBox(pB), pUpper(pFL), pLineBefore( 0 ), pLineBehind( 0 ) {}
     171             : 
     172         208 :     const _FndLines&    GetLines() const    { return aLines; }
     173          55 :         _FndLines&      GetLines()          { return aLines; }
     174         380 :     const SwTableBox*   GetBox() const      { return pBox; }
     175           6 :         SwTableBox*     GetBox()            { return pBox; }
     176             :     const _FndLine*     GetUpper() const    { return pUpper; }
     177           3 :         _FndLine*       GetUpper()          { return pUpper; }
     178             : 
     179             :     void SetTableLines( const SwSelBoxes &rBoxes, const SwTable &rTable );
     180             :     void SetTableLines( const SwTable &rTable );
     181             :     void DelFrms ( SwTable &rTable );
     182             :     void MakeFrms( SwTable &rTable );
     183             :     void MakeNewFrms( SwTable &rTable, const sal_uInt16 nNumber,
     184             :                                        const sal_Bool bBehind );
     185             :     sal_Bool AreLinesToRestore( const SwTable &rTable ) const;
     186             : 
     187           0 :     void ClearLineBehind() { pLineBehind = 0; }
     188             : };
     189             : 
     190             : 
     191          34 : class _FndLine
     192             : {
     193             :     SwTableLine* pLine;
     194             :     _FndBoxes aBoxes;
     195             :     _FndBox* pUpper;
     196             : public:
     197          34 :     _FndLine(SwTableLine* pL, _FndBox* pFB=0) : pLine(pL), pUpper(pFB) {}
     198         120 :     const _FndBoxes&    GetBoxes() const    { return aBoxes; }
     199         107 :         _FndBoxes&      GetBoxes()          { return aBoxes; }
     200           0 :     const SwTableLine*  GetLine() const     { return pLine; }
     201         152 :         SwTableLine*    GetLine()           { return pLine; }
     202             :     const _FndBox*      GetUpper() const    { return pUpper; }
     203           0 :         _FndBox*        GetUpper()          { return pUpper; }
     204             : 
     205           0 :     void SetUpper( _FndBox* pUp ) { pUpper = pUp; }
     206             : };
     207             : 
     208             : 
     209             : struct _FndPara
     210             : {
     211             :     const SwSelBoxes& rBoxes;
     212             :     _FndLine* pFndLine;
     213             :     _FndBox* pFndBox;
     214             : 
     215           8 :     _FndPara( const SwSelBoxes& rBxs, _FndBox* pFB )
     216           8 :         : rBoxes(rBxs), pFndLine(0), pFndBox(pFB) {}
     217           0 :     _FndPara( const _FndPara& rPara, _FndBox* pFB )
     218           0 :         : rBoxes(rPara.rBoxes), pFndLine(rPara.pFndLine), pFndBox(pFB) {}
     219          34 :     _FndPara( const _FndPara& rPara, _FndLine* pFL )
     220          34 :         : rBoxes(rPara.rBoxes), pFndLine(pFL), pFndBox(rPara.pFndBox) {}
     221             : };
     222             : 
     223             : SW_DLLPUBLIC void ForEach_FndLineCopyCol(SwTableLines& rLines, _FndPara* pFndPara );
     224             : 
     225             : 
     226             : 
     227             : #endif  //  _TBLSEL_HXX
     228             : 
     229             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10