LCOV - code coverage report
Current view: top level - sw/source/filter/inc - wrtswtbl.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 41 46 89.1 %
Date: 2015-06-13 12:38:46 Functions: 30 35 85.7 %
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 INCLUDED_SW_SOURCE_FILTER_INC_WRTSWTBL_HXX
      20             : #define INCLUDED_SW_SOURCE_FILTER_INC_WRTSWTBL_HXX
      21             : 
      22             : #include <tools/solar.h>
      23             : #include <tools/color.hxx>
      24             : #include <boost/ptr_container/ptr_vector.hpp>
      25             : #include <o3tl/sorted_vector.hxx>
      26             : 
      27             : #include <swdllapi.h>
      28             : 
      29             : class SwTableBox;
      30             : class SwTableLine;
      31             : class SwTableLines;
      32             : class SwHTMLTableLayout;
      33             : class SvxBrushItem;
      34             : 
      35             : namespace editeng { class SvxBorderLine; }
      36             : 
      37             : //       Code aus dem HTML-Filter fuers schreiben von Tabellen
      38             : 
      39             : #define COLFUZZY 20
      40             : #define ROWFUZZY 20
      41             : #define COL_DFLT_WIDTH ((2*COLFUZZY)+1)
      42             : #define ROW_DFLT_HEIGHT (2*ROWFUZZY)+1
      43             : 
      44             : class SW_DLLPUBLIC SwWriteTableCell
      45             : {
      46             :     const SwTableBox *pBox;     // SwTableBox der Zelle
      47             :     const SvxBrushItem *pBackground;    // geerbter Hintergrund einer Zeile
      48             : 
      49             :     long nHeight;               // fixe/Mindest-Hoehe der Zeile
      50             : 
      51             :     sal_uInt32 nWidthOpt;          // Breite aus Option;
      52             : 
      53             :     sal_uInt16 nRow;                // Start-Zeile
      54             :     sal_uInt16 nCol;                // Start-Spalte
      55             : 
      56             :     sal_uInt16 nRowSpan;            // ueberspannte Zeilen
      57             :     sal_uInt16 nColSpan;            // ueberspannte Spalten
      58             : 
      59             :     bool bPrcWidthOpt;
      60             : 
      61             : public:
      62             : 
      63       30889 :     SwWriteTableCell(const SwTableBox *pB, sal_uInt16 nR, sal_uInt16 nC, sal_uInt16 nRSpan,
      64             :         sal_uInt16 nCSpan, long nHght, const SvxBrushItem *pBGround)
      65             :     : pBox( pB ), pBackground( pBGround ), nHeight( nHght ), nWidthOpt( 0 ),
      66             :     nRow( nR ), nCol( nC ), nRowSpan( nRSpan ), nColSpan( nCSpan ),
      67       30889 :     bPrcWidthOpt( false )
      68       30889 :     {}
      69             : 
      70         949 :     const SwTableBox *GetBox() const { return pBox; }
      71             : 
      72         261 :     sal_uInt16 GetRow() const { return nRow; }
      73         261 :     sal_uInt16 GetCol() const { return nCol; }
      74             : 
      75         605 :     sal_uInt16 GetRowSpan() const { return nRowSpan; }
      76        2219 :     sal_uInt16 GetColSpan() const { return nColSpan; }
      77             : 
      78         261 :     long GetHeight() const { return nHeight; }
      79             :     sal_Int16 GetVertOri() const;
      80             : 
      81           0 :     const SvxBrushItem *GetBackground() const { return pBackground; }
      82             : 
      83           1 :     void SetWidthOpt( sal_uInt16 nWidth, bool bPrc )
      84             :     {
      85           1 :         nWidthOpt = nWidth; bPrcWidthOpt = bPrc;
      86           1 :     }
      87             : 
      88           1 :     sal_uInt32 GetWidthOpt() const { return nWidthOpt; }
      89           1 :     bool HasPrcWidthOpt() const { return bPrcWidthOpt; }
      90             : };
      91             : 
      92             : typedef boost::ptr_vector<SwWriteTableCell> SwWriteTableCells;
      93             : 
      94       30295 : class SW_DLLPUBLIC SwWriteTableRow
      95             : {
      96             :     SwWriteTableCells aCells;       // Alle Zellen der Rows
      97             :     const SvxBrushItem *pBackground;// Hintergrund
      98             : 
      99             :     long nPos;                  // End-Position (twips) der Zeile
     100             :     bool mbUseLayoutHeights;
     101             : 
     102             :     // Forbidden and not implemented.
     103             :     SwWriteTableRow();
     104             : 
     105             :     SwWriteTableRow & operator= (const SwWriteTableRow &) SAL_DELETED_FUNCTION;
     106             : 
     107             : protected:
     108             :     // GCC >= 3.4 needs accessible T (const T&) to pass T as const T& argument.
     109             :     SwWriteTableRow( const SwWriteTableRow & );
     110             : 
     111             : public:
     112             : 
     113             :     sal_uInt16 nTopBorder;              // Dicke der oberen/unteren Umrandugen
     114             :     sal_uInt16 nBottomBorder;
     115             : 
     116             :     bool bTopBorder : 1;            // Welche Umrandungen sind da?
     117             :     bool bBottomBorder : 1;
     118             : 
     119             :     SwWriteTableRow( long nPos, bool bUseLayoutHeights );
     120             : 
     121             :     SwWriteTableCell *AddCell( const SwTableBox *pBox,
     122             :                                  sal_uInt16 nRow, sal_uInt16 nCol,
     123             :                                  sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
     124             :                                  long nHeight,
     125             :                                  const SvxBrushItem *pBackground );
     126             : 
     127       15157 :     void SetBackground( const SvxBrushItem *pBGround )
     128             :     {
     129       15157 :         pBackground = pBGround;
     130       15157 :     }
     131          53 :     const SvxBrushItem *GetBackground() const { return pBackground; }
     132             : 
     133           0 :     bool HasTopBorder() const                   { return bTopBorder; }
     134           0 :     bool HasBottomBorder() const                { return bBottomBorder; }
     135             : 
     136             :     long GetPos() const                         { return nPos; }
     137        6695 :     const SwWriteTableCells& GetCells() const   { return aCells; }
     138             : 
     139             :     inline bool operator==( const SwWriteTableRow& rRow ) const;
     140             :     inline bool operator<( const SwWriteTableRow& rRow2 ) const;
     141             : };
     142             : 
     143             : inline bool SwWriteTableRow::operator==( const SwWriteTableRow& rRow ) const
     144             : {
     145             :     // etwas Unschaerfe zulassen
     146             :     return (nPos >= rRow.nPos ?  nPos - rRow.nPos : rRow.nPos - nPos ) <=
     147             :         (mbUseLayoutHeights ? 0 : ROWFUZZY);
     148             : }
     149             : 
     150      160595 : inline bool SwWriteTableRow::operator<( const SwWriteTableRow& rRow ) const
     151             : {
     152             :     // Da wir hier nur die Wahrheits-Grade 0 und 1 kennen, lassen wir lieber
     153             :     // auch nicht zu, dass x==y und x<y gleichzeitig gilt ;-)
     154      160595 :     return nPos < rRow.nPos - (mbUseLayoutHeights ? 0 : ROWFUZZY);
     155             : }
     156             : 
     157        1037 : class SwWriteTableRows : public o3tl::sorted_vector<SwWriteTableRow*, o3tl::less_ptr_to<SwWriteTableRow> > {
     158             : public:
     159        1037 :     ~SwWriteTableRows() { DeleteAndDestroyAll(); }
     160             : };
     161             : 
     162             : class SW_DLLPUBLIC SwWriteTableCol
     163             : {
     164             :     sal_uInt32 nPos;                        // End Position der Spalte
     165             : 
     166             :     sal_uInt32 nWidthOpt;
     167             : 
     168             :     bool bRelWidthOpt : 1;
     169             :     bool bOutWidth : 1;                 // Spaltenbreite ausgeben?
     170             : 
     171             : public:
     172             :     bool bLeftBorder : 1;               // Welche Umrandungen sind da?
     173             :     bool bRightBorder : 1;
     174             : 
     175             :     SwWriteTableCol( sal_uInt32 nPosition );
     176             : 
     177      283926 :     sal_uInt32 GetPos() const                       { return nPos; }
     178             : 
     179           0 :     bool HasLeftBorder() const                  { return bLeftBorder; }
     180             : 
     181           0 :     bool HasRightBorder() const                 { return bRightBorder; }
     182             : 
     183         260 :     void SetOutWidth( bool bSet )               { bOutWidth = bSet; }
     184             : 
     185             :     inline bool operator==( const SwWriteTableCol& rCol ) const;
     186             :     inline bool operator<( const SwWriteTableCol& rCol ) const;
     187             : 
     188          54 :     void SetWidthOpt( sal_uInt32 nWidth, bool bRel )
     189             :     {
     190          54 :         nWidthOpt = nWidth; bRelWidthOpt = bRel;
     191          54 :     }
     192         459 :     sal_uInt32 GetWidthOpt() const                 { return nWidthOpt; }
     193           1 :     bool HasRelWidthOpt() const                 { return bRelWidthOpt; }
     194             : };
     195             : 
     196             : inline bool SwWriteTableCol::operator==( const SwWriteTableCol& rCol ) const
     197             : {
     198             :     // etwas Unschaerfe zulassen
     199             :     return (nPos >= rCol.nPos ? nPos - rCol.nPos
     200             :                                      : rCol.nPos - nPos ) <= COLFUZZY;
     201             : }
     202             : 
     203        1633 : inline bool SwWriteTableCol::operator<( const SwWriteTableCol& rCol ) const
     204             : {
     205             :     // Da wir hier nur die Wahrheits-Grade 0 und 1 kennen, lassen wir lieber
     206             :     // auch nicht zu, dass x==y und x<y gleichzeitig gilt ;-)
     207        1633 :     return nPos + COLFUZZY < rCol.nPos;
     208             : }
     209             : 
     210             : struct SwWriteTableColLess {
     211      141698 :     bool operator()(SwWriteTableCol const * lhs, SwWriteTableCol const * rhs) {
     212      141698 :         return lhs->GetPos() < rhs->GetPos();
     213             :     }
     214             : };
     215             : 
     216        1037 : class SwWriteTableCols : public o3tl::sorted_vector<SwWriteTableCol*, SwWriteTableColLess> {
     217             : public:
     218        1037 :     ~SwWriteTableCols() { DeleteAndDestroyAll(); }
     219             : };
     220             : 
     221             : class SwTable;
     222             : 
     223             : class SW_DLLPUBLIC SwWriteTable
     224             : {
     225             : private:
     226             :     const SwTable* m_pTable;
     227             : protected:
     228             :     SwWriteTableCols aCols; // alle Spalten
     229             :     SwWriteTableRows aRows; // alle Zellen
     230             : 
     231             :     sal_uInt32 nBorderColor;        // Umrandungsfarbe
     232             : 
     233             :     sal_uInt16 nCellSpacing;        // Dicke der inneren Umrandung
     234             :     sal_uInt16 nCellPadding;        // Absatnd Umrandung-Inhalt
     235             : 
     236             :     sal_uInt16 nBorder;             // Dicke der ausseren Umrandung
     237             :     sal_uInt16 nInnerBorder;        // Dicke der inneren Umrandung
     238             :     sal_uInt32 nBaseWidth;            // Bezugsgroesse fur Breiten SwFormatFrmSize
     239             : 
     240             :     sal_uInt16 nHeadEndRow;         // letzte Zeile des Tabellen-Kopfes
     241             : 
     242             :     sal_uInt16 nLeftSub;
     243             :     sal_uInt16 nRightSub;
     244             : 
     245             :     sal_uInt32 nTabWidth;              // Absolute/Relative Breite der Tabelle
     246             : 
     247             :     bool bRelWidths : 1;        // Breiten relativ ausgeben?
     248             :     bool bUseLayoutHeights : 1; // Layout zur Hoehenbestimmung nehmen?
     249             : #ifdef DBG_UTIL
     250             :     bool m_bGetLineHeightCalled : 1;
     251             : #endif
     252             : 
     253             :     bool bColsOption : 1;
     254             :     bool bColTags : 1;
     255             :     bool bLayoutExport : 1;
     256             :     bool bCollectBorderWidth : 1;
     257             : 
     258             :     virtual bool ShouldExpandSub( const SwTableBox *pBox,
     259             :                                 bool bExpandedBefore, sal_uInt16 nDepth ) const;
     260             : 
     261             :     void CollectTableRowsCols( long nStartRPos, sal_uInt32 nStartCPos,
     262             :                                long nParentLineHeight,
     263             :                                sal_uInt32 nParentLineWidth,
     264             :                                const SwTableLines& rLines,
     265             :                                sal_uInt16 nDepth );
     266             : 
     267             :     void FillTableRowsCols( long nStartRPos, sal_uInt16 nStartRow,
     268             :                             sal_uInt32 nStartCPos, sal_uInt16 nStartCol,
     269             :                             long nParentLineHeight,
     270             :                             sal_uInt32 nParentLineWidth,
     271             :                             const SwTableLines& rLines,
     272             :                             const SvxBrushItem* pLineBrush,
     273             :                             sal_uInt16 nDepth,
     274             :                             sal_uInt16 nNumOfHeaderRows );
     275             : 
     276             :     void MergeBorders( const editeng::SvxBorderLine* pBorderLine, bool bTable );
     277             : 
     278             :     sal_uInt16 MergeBoxBorders(const SwTableBox *pBox, size_t nRow, size_t nCol,
     279             :                             sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
     280             :                             sal_uInt16 &rTopBorder, sal_uInt16 &rBottomBorder );
     281             : 
     282         530 :     sal_uInt32 GetBaseWidth() const { return nBaseWidth; }
     283             : 
     284         267 :     bool HasRelWidths() const { return bRelWidths; }
     285             : 
     286             : public:
     287             :     static sal_uInt32 GetBoxWidth( const SwTableBox *pBox );
     288             : 
     289             :     sal_uInt32 GetRawWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
     290             :     sal_uInt16 GetAbsWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
     291             :     sal_uInt16 GetRelWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
     292             :     sal_uInt16 GetPrcWidth( sal_uInt16 nCol, sal_uInt16 nColSpan ) const;
     293             : 
     294             :     long GetAbsHeight(long nRawWidth, size_t nRow, sal_uInt16 nRowSpan) const;
     295             : 
     296             : protected:
     297             :     long GetLineHeight( const SwTableLine *pLine );
     298             :     static long GetLineHeight( const SwTableBox *pBox );
     299             :     static const SvxBrushItem *GetLineBrush( const SwTableBox *pBox,
     300             :                                       SwWriteTableRow *pRow );
     301             : 
     302             :     sal_uInt16 GetLeftSpace( sal_uInt16 nCol ) const;
     303             :     sal_uInt16 GetRightSpace(size_t nCol, sal_uInt16 nColSpan) const;
     304             : 
     305             : public:
     306             :     SwWriteTable(const SwTable* pTable, const SwTableLines& rLines, long nWidth, sal_uInt32 nBWidth,
     307             :                  bool bRel, sal_uInt16 nMaxDepth = USHRT_MAX,
     308             :                  sal_uInt16 nLeftSub=0, sal_uInt16 nRightSub=0, sal_uInt32 nNumOfRowsToRepeat=0);
     309             :     SwWriteTable(const SwTable* pTable, const SwHTMLTableLayout *pLayoutInfo);
     310             :     virtual ~SwWriteTable();
     311             : 
     312             :     const SwWriteTableCols& GetCols() const { return aCols; }
     313        4513 :     const SwWriteTableRows& GetRows() const { return aRows; }
     314             : 
     315        8691 :     const SwTable* GetTable() const { return m_pTable; }
     316             : };
     317             : 
     318             : #endif
     319             : 
     320             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11