LCOV - code coverage report
Current view: top level - sw/inc - tblsel.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 24 30 80.0 %
Date: 2012-08-25 Functions: 21 28 75.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : #ifndef _TBLSEL_HXX
      29                 :            : #define _TBLSEL_HXX
      30                 :            : 
      31                 :            : #include <swtable.hxx>
      32                 :            : #include <swrect.hxx>
      33                 :            : #include "swdllapi.h"
      34                 :            : 
      35                 :            : #include <deque>
      36                 :            : #include <boost/ptr_container/ptr_vector.hpp>
      37                 :            : #include <o3tl/sorted_vector.hxx>
      38                 :            : 
      39                 :            : class SwCrsrShell;
      40                 :            : class SwCursor;
      41                 :            : class SwTableCursor;
      42                 :            : class SwFrm;
      43                 :            : class SwTabFrm;
      44                 :            : class SwTableBox;
      45                 :            : class SwTableLine;
      46                 :            : class SwLayoutFrm;
      47                 :            : class SwPaM;
      48                 :            : class SwNode;
      49                 :            : class SwTable;
      50                 :            : class SwUndoTblMerge;
      51                 :            : class SwCellFrm;
      52                 :            : 
      53                 :            : typedef ::std::deque< SwCellFrm* > SwCellFrms;
      54                 :            : 
      55                 :            : struct CompareSwSelBoxes
      56                 :            : {
      57                 :      17651 :     bool operator()(SwTableBox* const& lhs, SwTableBox* const& rhs) const
      58                 :            :     {
      59                 :      17651 :         return lhs->GetSttIdx() < rhs->GetSttIdx();
      60                 :            :     }
      61                 :            : };
      62                 :       1856 : class SwSelBoxes : public o3tl::sorted_vector<SwTableBox*, CompareSwSelBoxes> {};
      63                 :            : 
      64                 :            : // Collects all boxes in table that are selected.
      65                 :            : // Selection gets extended in given direction according to enum-parameter.
      66                 :            : // Boxes are collected via the Layout; works correctly if tables are split.
      67                 :            : // (Cf. MakeSelUnions().)
      68                 :            : typedef sal_uInt16 SwTblSearchType;
      69                 :            : namespace nsSwTblSearchType
      70                 :            : {
      71                 :            :     const SwTblSearchType TBLSEARCH_NONE = 0x1;       // No extension.
      72                 :            :     const SwTblSearchType TBLSEARCH_ROW  = 0x2;       // Extend to rows.
      73                 :            :     const SwTblSearchType TBLSEARCH_COL  = 0x3;       // Extend to columns.
      74                 :            : 
      75                 :            :     // As flag to the other values!
      76                 :            :     const SwTblSearchType TBLSEARCH_PROTECT = 0x8;      // Collect protected boxes too.
      77                 :            :     const SwTblSearchType TBLSEARCH_NO_UNION_CORRECT = 0x10; // Do not correct collected Union.
      78                 :            : }
      79                 :            : 
      80                 :            : SW_DLLPUBLIC void GetTblSel( const SwCrsrShell& rShell, SwSelBoxes& rBoxes,
      81                 :            :                 const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
      82                 :            : 
      83                 :            : void GetTblSel( const SwCursor& rCrsr, SwSelBoxes& rBoxes,
      84                 :            :                 const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
      85                 :            : 
      86                 :            : 
      87                 :            : // As before, but don't start from selection but from Start- EndFrms.
      88                 :            : void GetTblSel( const SwLayoutFrm* pStart, const SwLayoutFrm* pEnd,
      89                 :            :                 SwSelBoxes& rBoxes, SwCellFrms* pCells,
      90                 :            :                 const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
      91                 :            : 
      92                 :            : // As before but directly via PaMs.
      93                 :            : void GetTblSelCrs( const SwCrsrShell& rShell, SwSelBoxes& rBoxes );
      94                 :            : void GetTblSelCrs( const SwTableCursor& rTblCrsr, SwSelBoxes& rBoxes );
      95                 :            : 
      96                 :            : // Collect boxes relevant for auto sum.
      97                 :            : sal_Bool GetAutoSumSel( const SwCrsrShell&, SwCellFrms& );
      98                 :            : 
      99                 :            : // Check if the SelBoxes contains protected Boxes.
     100                 :            : sal_Bool HasProtectedCells( const SwSelBoxes& rBoxes );
     101                 :            : 
     102                 :            : // Check if selection is balanced.
     103                 :            : sal_Bool ChkChartSel( const SwNode& rSttNd, const SwNode& rEndNd);
     104                 :            : 
     105                 :            : // Check if cell is part of SSelection.
     106                 :            : // (Became a function, in order to make sure that GetTblSel() and MakeTblCrsr()
     107                 :            : // have always the same concept of the selection.
     108                 :            : sal_Bool IsFrmInTblSel( const SwRect& rUnion, const SwFrm* pCell );
     109                 :            : 
     110                 :            : // Determine boxes to be merged.
     111                 :            : // In this process the rectangle gets "adapted" on the base of the layout,
     112                 :            : // i.e. boxes are added if some overlap at the sides.
     113                 :            : // Additionally a new box is created and filled with the relevant content.
     114                 :            : void GetMergeSel( const SwPaM& rPam, SwSelBoxes& rBoxes,
     115                 :            :                   SwTableBox** ppMergeBox, SwUndoTblMerge* pUndo = 0 );
     116                 :            : 
     117                 :            : // Check if selected boxes allow for a valid merge.
     118                 :            : sal_uInt16 CheckMergeSel( const SwPaM& rPam );
     119                 :            : sal_uInt16 CheckMergeSel( const SwSelBoxes& rBoxes );
     120                 :            : 
     121                 :            : sal_Bool IsEmptyBox( const SwTableBox& rBox, SwPaM& rPam );
     122                 :            : 
     123                 :            : // Check if Split or InsertCol lead to a box becoming smaller than MINLAY.
     124                 :            : sal_Bool CheckSplitCells( const SwCrsrShell& rShell, sal_uInt16 nDiv,
     125                 :            :                         const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
     126                 :            : sal_Bool CheckSplitCells( const SwCursor& rCrsr, sal_uInt16 nDiv,
     127                 :            :                         const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
     128                 :            : 
     129                 :            : // For working on tab selection also for split tables.
     130                 :            : class SwSelUnion
     131                 :            : {
     132                 :            :     SwRect   aUnion;        // The rectangle enclosing the selection.
     133                 :            :     SwTabFrm *pTable;       // The (Follow-)Table for the Union.
     134                 :            : 
     135                 :            : public:
     136                 :         42 :     SwSelUnion( const SwRect &rRect, SwTabFrm *pTab ) :
     137                 :         42 :         aUnion( rRect ), pTable( pTab ) {}
     138                 :            : 
     139                 :            :     const SwRect&   GetUnion() const { return aUnion; }
     140                 :         46 :           SwRect&   GetUnion()       { return aUnion; }
     141                 :            :     const SwTabFrm *GetTable() const { return pTable; }
     142                 :         42 :           SwTabFrm *GetTable()       { return pTable; }
     143                 :            : };
     144                 :            : 
     145                 :            : // Determines tables affected by a table selection and union rectangles
     146                 :            : // of the selection (also for split tables)
     147                 :            : typedef boost::ptr_vector<SwSelUnion> SwSelUnions;
     148                 :            : 
     149                 :            : // Gets the tables involved in a table selection and the union-rectangles of the selections
     150                 :            : // - also for split tables.
     151                 :            : // If a parameter is passed that != nsSwTblSearchType::TBLSEARCH_NONE
     152                 :            : // the selection is extended in the given direction.
     153                 :            : void MakeSelUnions( SwSelUnions&, const SwLayoutFrm *pStart,
     154                 :            :                     const SwLayoutFrm *pEnd,
     155                 :            :                     const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
     156                 :            : 
     157                 :            : 
     158                 :            : 
     159                 :            : // These classes copy the current table selections (rBoxes) into a
     160                 :            : // separate structure while keeping the table structure.
     161                 :            : 
     162                 :            : class _FndBox;
     163                 :            : class _FndLine;
     164                 :            : 
     165                 :            : typedef boost::ptr_vector<_FndBox> _FndBoxes;
     166                 :            : typedef boost::ptr_vector<_FndLine> _FndLines;
     167                 :            : 
     168                 :        151 : class _FndBox
     169                 :            : {
     170                 :            :     SwTableBox* pBox;
     171                 :            :     _FndLines aLines;
     172                 :            :     _FndLine* pUpper;
     173                 :            : 
     174                 :            :     SwTableLine *pLineBefore;   // For deleting/restoring the layout.
     175                 :            :     SwTableLine *pLineBehind;
     176                 :            : 
     177                 :            : public:
     178                 :        151 :     _FndBox( SwTableBox* pB, _FndLine* pFL ) :
     179                 :        151 :         pBox(pB), pUpper(pFL), pLineBefore( 0 ), pLineBehind( 0 ) {}
     180                 :            : 
     181                 :        416 :     const _FndLines&    GetLines() const    { return aLines; }
     182                 :        115 :         _FndLines&      GetLines()          { return aLines; }
     183                 :        760 :     const SwTableBox*   GetBox() const      { return pBox; }
     184                 :         15 :         SwTableBox*     GetBox()            { return pBox; }
     185                 :            :     const _FndLine*     GetUpper() const    { return pUpper; }
     186                 :          6 :         _FndLine*       GetUpper()          { return pUpper; }
     187                 :            : 
     188                 :            :     void SetTableLines( const SwSelBoxes &rBoxes, const SwTable &rTable );
     189                 :            :     void SetTableLines( const SwTable &rTable );
     190                 :            :     void DelFrms ( SwTable &rTable );
     191                 :            :     void MakeFrms( SwTable &rTable );
     192                 :            :     void MakeNewFrms( SwTable &rTable, const sal_uInt16 nNumber,
     193                 :            :                                        const sal_Bool bBehind );
     194                 :            :     sal_Bool AreLinesToRestore( const SwTable &rTable ) const;
     195                 :            : 
     196                 :          0 :     void ClearLineBehind() { pLineBehind = 0; }
     197                 :            : };
     198                 :            : 
     199                 :            : 
     200                 :         60 : class _FndLine
     201                 :            : {
     202                 :            :     SwTableLine* pLine;
     203                 :            :     _FndBoxes aBoxes;
     204                 :            :     _FndBox* pUpper;
     205                 :            : public:
     206                 :         60 :     _FndLine(SwTableLine* pL, _FndBox* pFB=0) : pLine(pL), pUpper(pFB) {}
     207                 :        240 :     const _FndBoxes&    GetBoxes() const    { return aBoxes; }
     208                 :        210 :         _FndBoxes&      GetBoxes()          { return aBoxes; }
     209                 :          0 :     const SwTableLine*  GetLine() const     { return pLine; }
     210                 :        254 :         SwTableLine*    GetLine()           { return pLine; }
     211                 :            :     const _FndBox*      GetUpper() const    { return pUpper; }
     212                 :          0 :         _FndBox*        GetUpper()          { return pUpper; }
     213                 :            : 
     214                 :          0 :     void SetUpper( _FndBox* pUp ) { pUpper = pUp; }
     215                 :            : };
     216                 :            : 
     217                 :            : 
     218                 :            : struct _FndPara
     219                 :            : {
     220                 :            :     const SwSelBoxes& rBoxes;
     221                 :            :     _FndLine* pFndLine;
     222                 :            :     _FndBox* pFndBox;
     223                 :            : 
     224                 :         17 :     _FndPara( const SwSelBoxes& rBxs, _FndBox* pFB )
     225                 :         17 :         : rBoxes(rBxs), pFndLine(0), pFndBox(pFB) {}
     226                 :          0 :     _FndPara( const _FndPara& rPara, _FndBox* pFB )
     227                 :          0 :         : rBoxes(rPara.rBoxes), pFndLine(rPara.pFndLine), pFndBox(pFB) {}
     228                 :         60 :     _FndPara( const _FndPara& rPara, _FndLine* pFL )
     229                 :         60 :         : rBoxes(rPara.rBoxes), pFndLine(pFL), pFndBox(rPara.pFndBox) {}
     230                 :            : };
     231                 :            : 
     232                 :            : SW_DLLPUBLIC void ForEach_FndLineCopyCol(SwTableLines& rLines, _FndPara* pFndPara );
     233                 :            : 
     234                 :            : 
     235                 :            : 
     236                 :            : #endif  //  _TBLSEL_HXX
     237                 :            : 
     238                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10