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

Generated by: LCOV version 1.10