LCOV - code coverage report
Current view: top level - sc/source/filter/inc - htmlpars.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 18 35 51.4 %
Date: 2012-08-25 Functions: 13 23 56.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 12 83.3 %

           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                 :            : 
      29                 :            : #ifndef SC_HTMLPARS_HXX
      30                 :            : #define SC_HTMLPARS_HXX
      31                 :            : 
      32                 :            : #include <memory>
      33                 :            : #include <stack>
      34                 :            : #include <vector>
      35                 :            : #include <list>
      36                 :            : #include <map>
      37                 :            : #include <o3tl/sorted_vector.hxx>
      38                 :            : #include <boost/ptr_container/ptr_map.hpp>
      39                 :            : #include <boost/unordered_map.hpp>
      40                 :            : 
      41                 :            : #include "rangelst.hxx"
      42                 :            : #include "eeparser.hxx"
      43                 :            : 
      44                 :            : const sal_uInt32 SC_HTML_FONTSIZES = 7;        // wie Export, HTML-Options
      45                 :            : 
      46                 :            : // Pixel tolerance for SeekOffset and related.
      47                 :            : const sal_uInt16 SC_HTML_OFFSET_TOLERANCE_SMALL = 1;    // single table
      48                 :            : const sal_uInt16 SC_HTML_OFFSET_TOLERANCE_LARGE = 10;   // nested
      49                 :            : 
      50                 :            : // ============================================================================
      51                 :            : // BASE class for HTML parser classes
      52                 :            : // ============================================================================
      53                 :            : 
      54                 :            : class ScHTMLTable;
      55                 :            : 
      56                 :            : /**
      57                 :            :  * Collection of HTML style data parsed from the content of <style>
      58                 :            :  * elements.
      59                 :            :  */
      60 [ +  - ][ +  - ]:          3 : class ScHTMLStyles
      61                 :            : {
      62                 :            :     typedef ::boost::unordered_map<rtl::OUString, rtl::OUString, rtl::OUStringHash> PropsType;
      63                 :            :     typedef ::boost::ptr_map<rtl::OUString, PropsType> NamePropsType;
      64                 :            :     typedef ::boost::ptr_map<rtl::OUString, NamePropsType> ElemsType;
      65                 :            : 
      66                 :            :     NamePropsType maGlobalProps;     /// global properties (for a given class for all elements)
      67                 :            :     NamePropsType maElemGlobalProps; /// element global properties (no class specified)
      68                 :            :     ElemsType maElemProps;           /// element to class to properties (both element and class are given)
      69                 :            :     const rtl::OUString maEmpty;     /// just a persistent empty string.
      70                 :            : public:
      71                 :            :     ScHTMLStyles();
      72                 :            : 
      73                 :            :     void add(const char* pElemName, size_t nElemName, const char* pClassName, size_t nClassName,
      74                 :            :              const rtl::OUString& aProp, const rtl::OUString& aValue);
      75                 :            : 
      76                 :            :     /**
      77                 :            :      * Find best-matching property value for given element and class names.
      78                 :            :      */
      79                 :            :     const rtl::OUString& getPropertyValue(
      80                 :            :         const rtl::OUString& rElem, const rtl::OUString& rClass, const rtl::OUString& rPropName) const;
      81                 :            : 
      82                 :            : private:
      83                 :            :     static void insertProp(
      84                 :            :         NamePropsType& rProps, const rtl::OUString& aName,
      85                 :            :         const rtl::OUString& aProp, const rtl::OUString& aValue);
      86                 :            : };
      87                 :            : 
      88                 :            : /** Base class for HTML parser classes. */
      89                 :            : class ScHTMLParser : public ScEEParser
      90                 :            : {
      91                 :            :     ScHTMLStyles                maStyles;
      92                 :            : protected:
      93                 :            :     sal_uInt32                  maFontHeights[ SC_HTML_FONTSIZES ];
      94                 :            :     ScDocument*                 mpDoc;          /// The destination document.
      95                 :            : 
      96                 :            : public:
      97                 :            :     explicit                    ScHTMLParser( EditEngine* pEditEngine, ScDocument* pDoc );
      98                 :            :     virtual                     ~ScHTMLParser();
      99                 :            : 
     100                 :            :     virtual sal_uLong               Read( SvStream& rStrm, const String& rBaseURL  ) = 0;
     101                 :            : 
     102                 :            :     ScHTMLStyles&               GetStyles();
     103                 :            :     ScDocument&                 GetDoc();
     104                 :            : 
     105                 :            :     /** Returns the "global table" which contains the entire HTML document. */
     106                 :            :     virtual const ScHTMLTable*  GetGlobalTable() const = 0;
     107                 :            : };
     108                 :            : 
     109                 :            : 
     110                 :            : // ============================================================================
     111                 :            : 
     112                 :            : typedef o3tl::sorted_vector<sal_uLong> ScHTMLColOffset;
     113                 :            : 
     114                 :            : struct ScHTMLTableStackEntry
     115                 :            : {
     116                 :            :     ScRangeListRef      xLockedList;
     117                 :            :     ScEEParseEntry*     pCellEntry;
     118                 :            :     ScHTMLColOffset*    pLocalColOffset;
     119                 :            :     sal_uLong               nFirstTableCell;
     120                 :            :     SCCOL               nColCnt;
     121                 :            :     SCROW               nRowCnt;
     122                 :            :     SCCOL               nColCntStart;
     123                 :            :     SCCOL               nMaxCol;
     124                 :            :     sal_uInt16              nTable;
     125                 :            :     sal_uInt16              nTableWidth;
     126                 :            :     sal_uInt16              nColOffset;
     127                 :            :     sal_uInt16              nColOffsetStart;
     128                 :            :     bool                bFirstRow;
     129                 :          0 :                         ScHTMLTableStackEntry( ScEEParseEntry* pE,
     130                 :            :                                 const ScRangeListRef& rL, ScHTMLColOffset* pTO,
     131                 :            :                                 sal_uLong nFTC,
     132                 :            :                                 SCCOL nCol, SCROW nRow,
     133                 :            :                                 SCCOL nStart, SCCOL nMax, sal_uInt16 nTab,
     134                 :            :                                 sal_uInt16 nTW, sal_uInt16 nCO, sal_uInt16 nCOS,
     135                 :            :                                 bool bFR )
     136                 :            :                             : xLockedList( rL ), pCellEntry( pE ),
     137                 :            :                             pLocalColOffset( pTO ),
     138                 :            :                             nFirstTableCell( nFTC ),
     139                 :            :                             nColCnt( nCol ), nRowCnt( nRow ),
     140                 :            :                             nColCntStart( nStart ), nMaxCol( nMax ),
     141                 :            :                             nTable( nTab ), nTableWidth( nTW ),
     142                 :            :                             nColOffset( nCO ), nColOffsetStart( nCOS ),
     143                 :          0 :                             bFirstRow( bFR )
     144                 :          0 :                             {}
     145                 :          0 :                         ~ScHTMLTableStackEntry() {}
     146                 :            : };
     147                 :            : typedef ::std::stack< ScHTMLTableStackEntry* > ScHTMLTableStack;
     148                 :            : 
     149                 :            : struct ScHTMLAdjustStackEntry
     150                 :            : {
     151                 :            :     SCCOL               nLastCol;
     152                 :            :     SCROW               nNextRow;
     153                 :            :     SCROW               nCurRow;
     154                 :          0 :                         ScHTMLAdjustStackEntry( SCCOL nLCol, SCROW nNRow,
     155                 :            :                                 SCROW nCRow )
     156                 :            :                             : nLastCol( nLCol ), nNextRow( nNRow ),
     157                 :          0 :                             nCurRow( nCRow )
     158                 :          0 :                             {}
     159                 :            : };
     160                 :            : typedef ::std::stack< ScHTMLAdjustStackEntry* > ScHTMLAdjustStack;
     161                 :            : 
     162                 :            : 
     163                 :            : // ============================================================================
     164                 :            : 
     165                 :            : class EditEngine;
     166                 :            : class ScDocument;
     167                 :            : class HTMLOption;
     168                 :            : 
     169                 :            : // TODO these need better names
     170                 :            : typedef ::std::map<SCROW, SCROW> InnerMap;
     171                 :            : typedef ::std::map<sal_uInt16, InnerMap*> OuterMap;
     172                 :            : 
     173                 :            : class ScHTMLLayoutParser : public ScHTMLParser
     174                 :            : {
     175                 :            : private:
     176                 :            :     Size                aPageSize;
     177                 :            :     rtl::OUString       aBaseURL;
     178                 :            :     ScHTMLTableStack    aTableStack;
     179                 :            :     rtl::OUString       aString;
     180                 :            :     ScRangeListRef      xLockedList;        // je Table
     181                 :            :     OuterMap*           pTables;
     182                 :            :     ScHTMLColOffset*    pColOffset;
     183                 :            :     ScHTMLColOffset*    pLocalColOffset;    // je Table
     184                 :            :     sal_uLong               nFirstTableCell;    // je Table
     185                 :            :     short               nTableLevel;
     186                 :            :     sal_uInt16              nTable;
     187                 :            :     sal_uInt16              nMaxTable;
     188                 :            :     SCCOL               nColCntStart;       // erste Col je Table
     189                 :            :     SCCOL               nMaxCol;            // je Table
     190                 :            :     sal_uInt16              nTableWidth;        // je Table
     191                 :            :     sal_uInt16              nColOffset;         // aktuell, Pixel
     192                 :            :     sal_uInt16              nColOffsetStart;    // Startwert je Table, in Pixel
     193                 :            :     sal_uInt16              nMetaCnt;           // fuer ParseMetaOptions
     194                 :            :     sal_uInt16              nOffsetTolerance;   // for use with SeekOffset and related
     195                 :            :     bool                bTabInTabCell:1;
     196                 :            :     bool                bFirstRow:1;          // je Table, ob in erster Zeile
     197                 :            :     bool                bInCell:1;
     198                 :            :     bool                bInTitle:1;
     199                 :            : 
     200                 :            :     DECL_LINK( HTMLImportHdl, ImportInfo* );
     201                 :            :     void                NewActEntry( ScEEParseEntry* );
     202                 :            :     void                EntryEnd( ScEEParseEntry*, const ESelection& );
     203                 :            :     void                ProcToken( ImportInfo* );
     204                 :            :     void                CloseEntry( ImportInfo* );
     205                 :            :     void                NextRow(  ImportInfo*  );
     206                 :            :     void                SkipLocked( ScEEParseEntry*, bool bJoin = true );
     207                 :            :     static bool         SeekOffset( ScHTMLColOffset*, sal_uInt16 nOffset,
     208                 :            :                                     SCCOL* pCol, sal_uInt16 nOffsetTol );
     209                 :            :     static void         MakeCol( ScHTMLColOffset*, sal_uInt16& nOffset,
     210                 :            :                                 sal_uInt16& nWidth, sal_uInt16 nOffsetTol,
     211                 :            :                                 sal_uInt16 nWidthTol );
     212                 :            :     static void         MakeColNoRef( ScHTMLColOffset*, sal_uInt16 nOffset,
     213                 :            :                                 sal_uInt16 nWidth, sal_uInt16 nOffsetTol,
     214                 :            :                                 sal_uInt16 nWidthTol );
     215                 :            :     static void         ModifyOffset( ScHTMLColOffset*, sal_uInt16& nOldOffset,
     216                 :            :                                     sal_uInt16& nNewOffset, sal_uInt16 nOffsetTol );
     217                 :            :     void                Colonize( ScEEParseEntry* );
     218                 :            :     sal_uInt16              GetWidth( ScEEParseEntry* );
     219                 :            :     void                SetWidths();
     220                 :            :     void                Adjust();
     221                 :            : 
     222                 :            :     sal_uInt16              GetWidthPixel( const HTMLOption& );
     223                 :            :     bool                IsAtBeginningOfText( ImportInfo* );
     224                 :            : 
     225                 :            :     void                TableOn( ImportInfo* );
     226                 :            :     void                ColOn( ImportInfo* );
     227                 :            :     void                TableRowOn( ImportInfo* );
     228                 :            :     void                TableRowOff( ImportInfo* );
     229                 :            :     void                TableDataOn( ImportInfo* );
     230                 :            :     void                TableDataOff( ImportInfo* );
     231                 :            :     void                TableOff( ImportInfo* );
     232                 :            :     void                Image( ImportInfo* );
     233                 :            :     void                AnchorOn( ImportInfo* );
     234                 :            :     void                FontOn( ImportInfo* );
     235                 :            : 
     236                 :            : public:
     237                 :            :                         ScHTMLLayoutParser( EditEngine*, const String& rBaseURL, const Size& aPageSize, ScDocument* );
     238                 :            :     virtual             ~ScHTMLLayoutParser();
     239                 :            :     virtual sal_uLong       Read( SvStream&, const String& rBaseURL  );
     240                 :            :     virtual const ScHTMLTable*  GetGlobalTable() const;
     241                 :            : };
     242                 :            : 
     243                 :            : 
     244                 :            : 
     245                 :            : // ============================================================================
     246                 :            : // HTML DATA QUERY PARSER
     247                 :            : // ============================================================================
     248                 :            : 
     249                 :            : /** Declares the orientation in or for a table: column or row. */
     250                 :            : enum ScHTMLOrient { tdCol = 0 , tdRow = 1 };
     251                 :            : 
     252                 :            : /** Type for a unique identifier for each table. */
     253                 :            : typedef sal_uInt16 ScHTMLTableId;
     254                 :            : /** Identifier of the "global table" (the entire HTML document). */
     255                 :            : const ScHTMLTableId SC_HTML_GLOBAL_TABLE = 0;
     256                 :            : /** Used as table index for normal (non-table) entries in ScHTMLEntry structs. */
     257                 :            : const ScHTMLTableId SC_HTML_NO_TABLE = 0;
     258                 :            : 
     259                 :            : // ============================================================================
     260                 :            : 
     261                 :            : /** A 2D cell position in an HTML table. */
     262                 :            : struct ScHTMLPos
     263                 :            : {
     264                 :            :     SCCOL               mnCol;
     265                 :            :     SCROW               mnRow;
     266                 :            : 
     267                 :         12 :     inline explicit     ScHTMLPos() : mnCol( 0 ), mnRow( 0 ) {}
     268                 :         21 :     inline explicit     ScHTMLPos( SCCOL nCol, SCROW nRow ) :
     269                 :         21 :                             mnCol( nCol ), mnRow( nRow ) {}
     270                 :          0 :     inline explicit     ScHTMLPos( const ScAddress& rAddr ) { Set( rAddr ); }
     271                 :            : 
     272                 :         42 :     inline SCCOLROW     Get( ScHTMLOrient eOrient ) const
     273         [ +  + ]:         42 :                             { return (eOrient == tdCol) ? mnCol : mnRow; }
     274                 :          0 :     inline void         Set( SCCOL nCol, SCROW nRow )
     275                 :          0 :                             { mnCol = nCol; mnRow = nRow; }
     276                 :          0 :     inline void         Set( const ScAddress& rAddr )
     277                 :          0 :                             { Set( rAddr.Col(), rAddr.Row() ); }
     278                 :            :     inline void         Move( SCsCOL nColDiff, SCsROW nRowDiff )
     279                 :            :                             { mnCol = mnCol + nColDiff; mnRow = mnRow + nRowDiff; }
     280                 :        213 :     inline ScAddress    MakeAddr() const
     281                 :        213 :                             { return ScAddress( mnCol, mnRow, 0 ); }
     282                 :            : };
     283                 :            : 
     284                 :            : inline bool operator==( const ScHTMLPos& rPos1, const ScHTMLPos& rPos2 )
     285                 :            : {
     286                 :            :     return (rPos1.mnRow == rPos2.mnRow) && (rPos1.mnCol == rPos2.mnCol);
     287                 :            : }
     288                 :            : 
     289                 :         63 : inline bool operator<( const ScHTMLPos& rPos1, const ScHTMLPos& rPos2 )
     290                 :            : {
     291 [ +  + ][ +  + ]:         63 :     return (rPos1.mnRow < rPos2.mnRow) || ((rPos1.mnRow == rPos2.mnRow) && (rPos1.mnCol < rPos2.mnCol));
                 [ +  + ]
     292                 :            : }
     293                 :            : 
     294                 :            : // ----------------------------------------------------------------------------
     295                 :            : 
     296                 :            : /** A 2D cell size in an HTML table. */
     297                 :            : struct ScHTMLSize
     298                 :            : {
     299                 :            :     SCCOL               mnCols;
     300                 :            :     SCROW               mnRows;
     301                 :            : 
     302                 :            :     inline explicit     ScHTMLSize() : mnCols( 0 ), mnRows( 0 ) {}
     303                 :        132 :     inline explicit     ScHTMLSize( SCCOL nCols, SCROW nRows ) :
     304                 :        132 :                             mnCols( nCols ), mnRows( nRows ) {}
     305                 :            : 
     306                 :            :     inline SCCOLROW     Get( ScHTMLOrient eOrient ) const
     307                 :            :                             { return (eOrient == tdCol) ? mnCols : mnRows; }
     308                 :          0 :     inline void         Set( SCCOL nCols, SCROW nRows )
     309                 :          0 :                             { mnCols = nCols; mnRows = nRows; }
     310                 :            :     inline void         Expand( SCsCOL nColDiff, SCsROW nRowDiff )
     311                 :            :                             { mnCols = mnCols + nColDiff; mnRows = mnRows + nRowDiff; }
     312                 :            : };
     313                 :            : 
     314                 :            : inline bool operator==( const ScHTMLSize& rSize1, const ScHTMLSize& rSize2 )
     315                 :            : {
     316                 :            :     return (rSize1.mnRows == rSize2.mnRows) && (rSize1.mnCols == rSize2.mnCols);
     317                 :            : }
     318                 :            : 
     319                 :            : // ============================================================================
     320                 :            : 
     321                 :            : /** A single entry containing a line of text or representing a table. */
     322                 :         63 : struct ScHTMLEntry : public ScEEParseEntry
     323                 :            : {
     324                 :            : public:
     325                 :            :     explicit            ScHTMLEntry(
     326                 :            :                             const SfxItemSet& rItemSet,
     327                 :            :                             ScHTMLTableId nTableId = SC_HTML_NO_TABLE );
     328                 :            : 
     329                 :            :     /** Returns true, if the selection of the entry is empty. */
     330                 :          0 :     inline bool         IsEmpty() const { return !aSel.HasRange(); }
     331                 :            :     /** Returns true, if the entry has any content to be imported. */
     332                 :            :     bool                HasContents() const;
     333                 :            :     /** Returns true, if the entry represents a table. */
     334                 :        102 :     inline bool         IsTable() const { return nTab != SC_HTML_NO_TABLE; }
     335                 :            :     /** Returns true, if the entry represents a table. */
     336                 :         63 :     inline ScHTMLTableId GetTableId() const { return nTab; }
     337                 :            : 
     338                 :            :     /** Sets or cleares the import always state. */
     339                 :          0 :     inline void         SetImportAlways( bool bSet = true ) { mbImportAlways = bSet; }
     340                 :            :     /** Sets start point of the entry selection to the start of the import info object. */
     341                 :            :     void                AdjustStart( const ImportInfo& rInfo );
     342                 :            :     /** Sets end point of the entry selection to the end of the import info object. */
     343                 :            :     void                AdjustEnd( const ImportInfo& rInfo );
     344                 :            :     /** Deletes leading and trailing empty paragraphs from the entry. */
     345                 :            :     void                Strip( const EditEngine& rEditEngine );
     346                 :            : 
     347                 :            :     /** Returns read/write access to the item set of this entry. */
     348                 :          0 :     inline SfxItemSet&  GetItemSet() { return aItemSet; }
     349                 :            :     /** Returns read-only access to the item set of this entry. */
     350                 :            :     inline const SfxItemSet& GetItemSet() const { return aItemSet; }
     351                 :            : 
     352                 :            : private:
     353                 :            :     bool                mbImportAlways;     /// true = Always import this entry.
     354                 :            : };
     355                 :            : 
     356                 :            : // ============================================================================
     357                 :            : 
     358                 :            : /** This struct handles creation of unique table identifiers. */
     359                 :            : struct ScHTMLTableAutoId
     360                 :            : {
     361                 :            :     const ScHTMLTableId mnTableId;          /// The created unique table identifier.
     362                 :            :     ScHTMLTableId&      mrnUnusedId;        /// Reference to global unused identifier variable.
     363                 :            : 
     364                 :            :     /** The constructor assigns an unused identifier to member mnTableId. */
     365                 :            :     explicit            ScHTMLTableAutoId( ScHTMLTableId& rnUnusedId );
     366                 :            : };
     367                 :            : 
     368                 :            : // ----------------------------------------------------------------------------
     369                 :            : 
     370                 :            : class ScHTMLTableMap;
     371                 :            : 
     372                 :            : /** Stores data for one table in an HTML document.
     373                 :            : 
     374                 :            :     This class does the main work for importing an HTML document. It manages
     375                 :            :     the correct insertion of parse entries into the correct cells and the
     376                 :            :     creation of nested tables. Recalculation of resulting document size and
     377                 :            :     position is done recursively in all nested tables.
     378                 :            :  */
     379                 :            : class ScHTMLTable
     380                 :            : {
     381                 :            : public:
     382                 :            :     /** Creates a new HTML table without content.
     383                 :            :         @descr  Internally handles a current cell position. This position is
     384                 :            :             invalid until first calls of RowOn() and DataOn().
     385                 :            :         @param rParentTable  Reference to the parent table that owns this table.
     386                 :            :         @param bPreFormText  true = Table is based on preformatted text (<pre> tag). */
     387                 :            :     explicit            ScHTMLTable(
     388                 :            :                             ScHTMLTable& rParentTable,
     389                 :            :                             const ImportInfo& rInfo,
     390                 :            :                             bool bPreFormText );
     391                 :            : 
     392                 :            :     virtual             ~ScHTMLTable();
     393                 :            : 
     394                 :            :     /** Returns the name of the table, specified in the TABLE tag. */
     395                 :          3 :     inline const rtl::OUString& GetTableName() const { return maTableName; }
     396                 :            :     /** Returns the unique identifier of the table. */
     397                 :         21 :     inline ScHTMLTableId GetTableId() const { return maTableId.mnTableId; }
     398                 :            :     /** Returns the table size. */
     399                 :            :     inline const ScHTMLSize& GetSize() const { return maSize; }
     400                 :            :     /** Returns the cell spanning of the specified cell. */
     401                 :            :     ScHTMLSize          GetSpan( const ScHTMLPos& rCellPos ) const;
     402                 :            : 
     403                 :            :     /** Searches in all nested tables for the specified table.
     404                 :            :         @param nTableId  Unique identifier of the table. */
     405                 :            :     ScHTMLTable*        FindNestedTable( ScHTMLTableId nTableId ) const;
     406                 :            : 
     407                 :            :     /** Puts the item into the item set of the current entry. */
     408                 :            :     void                PutItem( const SfxPoolItem& rItem );
     409                 :            :     /** Inserts a text portion into current entry. */
     410                 :            :     void                PutText( const ImportInfo& rInfo );
     411                 :            :     /** Inserts a new line, if in preformatted text, else does nothing. */
     412                 :            :     void                InsertPara( const ImportInfo& rInfo );
     413                 :            : 
     414                 :            :     /** Inserts a line break (<br> tag).
     415                 :            :         @descr  Inserts the current entry regardless if it is empty. */
     416                 :            :     void                BreakOn();
     417                 :            :     /** Inserts a heading line (<p> and <h*> tags). */
     418                 :            :     void                HeadingOn();
     419                 :            :     /** Processes a hyperlink (<a> tag). */
     420                 :            :     void                AnchorOn();
     421                 :            : 
     422                 :            :     /** Starts a *new* table nested in this table (<table> tag).
     423                 :            :         @return  Pointer to the new table. */
     424                 :            :     ScHTMLTable*        TableOn( const ImportInfo& rInfo );
     425                 :            :     /** Closes *this* table (</table> tag).
     426                 :            :         @return  Pointer to the parent table. */
     427                 :            :     ScHTMLTable*        TableOff( const ImportInfo& rInfo );
     428                 :            :     /** Starts a *new* table based on preformatted text (<pre> tag).
     429                 :            :         @return  Pointer to the new table. */
     430                 :            :     ScHTMLTable*        PreOn( const ImportInfo& rInfo );
     431                 :            :     /** Closes *this* table based on preformatted text (</pre> tag).
     432                 :            :         @return  Pointer to the parent table. */
     433                 :            :     ScHTMLTable*        PreOff( const ImportInfo& rInfo );
     434                 :            : 
     435                 :            :     /** Starts next row (<tr> tag).
     436                 :            :         @descr  Cell address is invalid until first call of DataOn(). */
     437                 :            :     void                RowOn( const ImportInfo& rInfo );
     438                 :            :     /** Closes the current row (<tr> tag).
     439                 :            :         @descr  Cell address is invalid until call of RowOn() and DataOn(). */
     440                 :            :     void                RowOff( const ImportInfo& rInfo );
     441                 :            :     /** Starts the next cell (<td> or <th> tag). */
     442                 :            :     void                DataOn( const ImportInfo& rInfo );
     443                 :            :     /** Closes the current cell (</td> or </th> tag).
     444                 :            :         @descr  Cell address is invalid until next call of DataOn(). */
     445                 :            :     void                DataOff( const ImportInfo& rInfo );
     446                 :            : 
     447                 :            :     /** Starts the body of the HTML document (<body> tag). */
     448                 :            :     void                BodyOn( const ImportInfo& rInfo );
     449                 :            :     /** Closes the body of the HTML document (</body> tag). */
     450                 :            :     void                BodyOff( const ImportInfo& rInfo );
     451                 :            : 
     452                 :            :     /** Closes *this* table (</table> tag) or preformatted text (</pre> tag).
     453                 :            :         @descr  Used to close this table object regardless on opening tag type.
     454                 :            :         @return  Pointer to the parent table, or this, if no parent found. */
     455                 :            :     ScHTMLTable*        CloseTable( const ImportInfo& rInfo );
     456                 :            : 
     457                 :            :     /** Returns the resulting document row/column count of the specified HTML row/column. */
     458                 :            :     SCCOLROW            GetDocSize( ScHTMLOrient eOrient, SCCOLROW nCellPos ) const;
     459                 :            :     /** Returns the resulting document row/column count in the half-open range [nCellBegin, nCellEnd). */
     460                 :            :     SCCOLROW            GetDocSize( ScHTMLOrient eOrient, SCCOLROW nCellBegin, SCCOLROW nCellEnd ) const;
     461                 :            :     /** Returns the total document row/column count in the specified direction. */
     462                 :            :     SCCOLROW            GetDocSize( ScHTMLOrient eOrient ) const;
     463                 :            :     /** Returns the total document row/column count of the specified HTML cell. */
     464                 :            :     ScHTMLSize          GetDocSize( const ScHTMLPos& rCellPos ) const;
     465                 :            : 
     466                 :            :     /** Returns the resulting Calc position of the top left edge of the table. */
     467                 :          3 :     inline const ScHTMLPos& GetDocPos() const { return maDocBasePos; }
     468                 :            :     /** Calculates the resulting Calc position of the specified HTML column/row. */
     469                 :            :     SCCOLROW            GetDocPos( ScHTMLOrient eOrient, SCCOLROW nCellPos = 0 ) const;
     470                 :            :     /** Calculates the resulting Calc position of the specified HTML cell. */
     471                 :            :     ScHTMLPos           GetDocPos( const ScHTMLPos& rCellPos ) const;
     472                 :            : 
     473                 :            :     /** Calculates the current Calc document area of this table. */
     474                 :            :     void                GetDocRange( ScRange& rRange ) const;
     475                 :            : 
     476                 :            :     /** Applies border formatting to the passed document. */
     477                 :            :     void                ApplyCellBorders( ScDocument* pDoc, const ScAddress& rFirstPos ) const;
     478                 :            : 
     479                 :            :     SvNumberFormatter* GetFormatTable();
     480                 :            : 
     481                 :            : protected:
     482                 :            :     /** Creates a new HTML table without parent.
     483                 :            :         @descr  This constructor is used to create the "global table". */
     484                 :            :     explicit            ScHTMLTable(
     485                 :            :                             SfxItemPool& rPool,
     486                 :            :                             EditEngine& rEditEngine,
     487                 :            :                             ::std::vector< ScEEParseEntry* >& rEEParseList,
     488                 :            :                             ScHTMLTableId& rnUnusedId, ScHTMLParser* pParser );
     489                 :            : 
     490                 :            :     /** Fills all empty cells in this and nested tables with dummy parse entries. */
     491                 :            :     void                FillEmptyCells();
     492                 :            :     /** Recalculates the size of all columns/rows in the table, regarding nested tables. */
     493                 :            :     void                RecalcDocSize();
     494                 :            :     /** Recalculates the position of all cell entries and nested tables.
     495                 :            :         @param rBasePos  The origin of the table in the Calc document. */
     496                 :            :     void                RecalcDocPos( const ScHTMLPos& rBasePos );
     497                 :            : 
     498                 :            : private:
     499                 :            :     typedef ::std::auto_ptr< ScHTMLTableMap >           ScHTMLTableMapPtr;
     500                 :            :     typedef ::std::auto_ptr< SfxItemSet >               SfxItemSetPtr;
     501                 :            :     typedef ::std::vector< SCCOLROW >                   ScSizeVec;
     502                 :            :     typedef ::std::list< ScHTMLEntry* >                 ScHTMLEntryList;
     503                 :            :     typedef ::std::map< ScHTMLPos, ScHTMLEntryList >    ScHTMLEntryMap;
     504                 :            :     typedef ::std::auto_ptr< ScHTMLEntry >              ScHTMLEntryPtr;
     505                 :            : 
     506                 :            :     /** Returns true, if the current cell does not contain an entry yet. */
     507                 :            :     bool                IsEmptyCell() const;
     508                 :            :     /** Returns the item set from cell, row, or table, depending on current state. */
     509                 :            :     const SfxItemSet&   GetCurrItemSet() const;
     510                 :            : 
     511                 :            :     /** Returns true, if import info represents a space character. */
     512                 :            :     static bool         IsSpaceCharInfo( const ImportInfo& rInfo );
     513                 :            : 
     514                 :            :     /** Creates and returns a new empty flying entry at position (0,0). */
     515                 :            :     ScHTMLEntryPtr      CreateEntry() const;
     516                 :            :     /** Creates a new flying entry.
     517                 :            :         @param rInfo  Contains the initial edit engine selection for the entry. */
     518                 :            :     void                CreateNewEntry( const ImportInfo& rInfo );
     519                 :            : 
     520                 :            :     /** Inserts an empty line in front of the next entry. */
     521                 :            :     void                InsertLeadingEmptyLine();
     522                 :            : 
     523                 :            :     /** Pushes the passed entry into the list of the current cell. */
     524                 :            :     void                ImplPushEntryToList( ScHTMLEntryList& rEntryList, ScHTMLEntryPtr& rxEntry );
     525                 :            :     /** Tries to insert the entry into the current cell.
     526                 :            :         @descr  If insertion is not possible (i.e., currently no cell open), the
     527                 :            :         entry will be inserted into the parent table.
     528                 :            :         @return  true = Entry as been pushed into the current cell; false = Entry dropped. */
     529                 :            :     bool                PushEntry( ScHTMLEntryPtr& rxEntry );
     530                 :            :     /** Puts the current entry into the entry list, if it is not empty.
     531                 :            :         @param rInfo  The import info struct containing the end position of the current entry.
     532                 :            :         @param bLastInCell  true = If cell is still empty, put this entry always.
     533                 :            :         @return  true = Entry as been pushed into the current cell; false = Entry dropped. */
     534                 :            :     bool                PushEntry( const ImportInfo& rInfo, bool bLastInCell = false );
     535                 :            :     /** Pushes a new entry into current cell which references a nested table.
     536                 :            :         @return  true = Entry as been pushed into the current cell; false = Entry dropped. */
     537                 :            :     bool                PushTableEntry( ScHTMLTableId nTableId );
     538                 :            : 
     539                 :            :     /** Tries to find a table from the table container.
     540                 :            :         @descr  Assumes that the table is located in the current container or
     541                 :            :         that the passed table identifier is 0.
     542                 :            :         @param nTableId  Unique identifier of the table or 0. */
     543                 :            :     ScHTMLTable*        GetExistingTable( ScHTMLTableId nTableId ) const;
     544                 :            :     /** Inserts a nested table in the current cell at the specified position.
     545                 :            :         @param bPreFormText  true = New table is based on preformatted text (<pre> tag). */
     546                 :            :     ScHTMLTable*        InsertNestedTable( const ImportInfo& rInfo, bool bPreFormText );
     547                 :            : 
     548                 :            :     /** Inserts a new cell in an unused position, starting from current cell position. */
     549                 :            :     void                InsertNewCell( const ScHTMLSize& rSpanSize );
     550                 :            : 
     551                 :            :     /** Set internal states for a new table row. */
     552                 :            :     void                ImplRowOn();
     553                 :            :     /** Set internal states for leaving a table row. */
     554                 :            :     void                ImplRowOff();
     555                 :            :     /** Set internal states for entering a new table cell. */
     556                 :            :     void                ImplDataOn( const ScHTMLSize& rSpanSize );
     557                 :            :     /** Set internal states for leaving a table cell. */
     558                 :            :     void                ImplDataOff();
     559                 :            : 
     560                 :            :     /** Inserts additional formatting options from import info into the item set. */
     561                 :            :     void                ProcessFormatOptions( SfxItemSet& rItemSet, const ImportInfo& rInfo );
     562                 :            : 
     563                 :            :     /** Updates the document column/row size of the specified column or row.
     564                 :            :         @descr  Only increases the present count, never decreases. */
     565                 :            :     void                SetDocSize( ScHTMLOrient eOrient, SCCOLROW nCellPos, SCCOLROW nSize );
     566                 :            :     /** Calculates and sets the resulting size the cell needs in the document.
     567                 :            :         @descr  Reduces the needed size in merged cells.
     568                 :            :         @param nCellPos  The first column/row position of the (merged) cell.
     569                 :            :         @param nCellSpan  The cell spanning in the specified orientation.
     570                 :            :         @param nRealDocSize  The raw document size of all entries of the cell. */
     571                 :            :     void                CalcNeededDocSize(
     572                 :            :                             ScHTMLOrient eOrient, SCCOLROW nCellPos,
     573                 :            :                             SCCOLROW nCellSpan, SCCOLROW nRealDocSize );
     574                 :            : 
     575                 :            : private:
     576                 :            :     ScHTMLTable*        mpParentTable;      /// Pointer to parent table.
     577                 :            :     ScHTMLTableMapPtr   mxNestedTables;     /// Table of nested HTML tables.
     578                 :            :     rtl::OUString       maTableName;        /// Table name from <table id> option.
     579                 :            :     ScHTMLTableAutoId   maTableId;          /// Unique identifier of this table.
     580                 :            :     SfxItemSet          maTableItemSet;     /// Items for the entire table.
     581                 :            :     SfxItemSetPtr       mxRowItemSet;       /// Items for the current table row.
     582                 :            :     SfxItemSetPtr       mxDataItemSet;      /// Items for the current cell.
     583                 :            :     ScRangeList         maHMergedCells;     /// List of all horizontally merged cells.
     584                 :            :     ScRangeList         maVMergedCells;     /// List of all vertically merged cells.
     585                 :            :     ScRangeList         maUsedCells;        /// List of all used cells.
     586                 :            :     EditEngine&         mrEditEngine;       /// Edit engine (from ScEEParser).
     587                 :            :     ::std::vector< ScEEParseEntry* >& mrEEParseList;      /// List that owns the parse entries (from ScEEParser).
     588                 :            :     ScHTMLEntryMap      maEntryMap;         /// List of entries for each cell.
     589                 :            :     ScHTMLEntryList*    mpCurrEntryList;    /// Current entry list from map for faster access.
     590                 :            :     ScHTMLEntryPtr      mxCurrEntry;        /// Working entry, not yet inserted in a list.
     591                 :            :     ScSizeVec           maCumSizes[ 2 ];    /// Cumulated cell counts for each HTML table column/row.
     592                 :            :     ScHTMLSize          maSize;             /// Size of the table.
     593                 :            :     ScHTMLPos           maCurrCell;         /// Address of current cell to fill.
     594                 :            :     ScHTMLPos           maDocBasePos;       /// Resulting base address in a Calc document.
     595                 :            :     ScHTMLParser*       mpParser;
     596                 :            :     bool                mbBorderOn:1;       /// true = Table borders on.
     597                 :            :     bool                mbPreFormText:1;    /// true = Table from preformatted text (<pre> tag).
     598                 :            :     bool                mbRowOn:1;          /// true = Inside of <tr> </tr>.
     599                 :            :     bool                mbDataOn:1;         /// true = Inside of <td> </td> or <th> </th>.
     600                 :            :     bool                mbPushEmptyLine:1;  /// true = Insert empty line before current entry.
     601                 :            : };
     602                 :            : 
     603                 :            : // ----------------------------------------------------------------------------
     604                 :            : 
     605                 :            : /** The "global table" representing the entire HTML document. */
     606                 :            : class ScHTMLGlobalTable : public ScHTMLTable
     607                 :            : {
     608                 :            : public:
     609                 :            :     explicit            ScHTMLGlobalTable(
     610                 :            :                             SfxItemPool& rPool,
     611                 :            :                             EditEngine& rEditEngine,
     612                 :            :                             ::std::vector< ScEEParseEntry* >& rEEParseList,
     613                 :            :                             ScHTMLTableId& rnUnusedId, ScHTMLParser* pParser );
     614                 :            : 
     615                 :            :     virtual             ~ScHTMLGlobalTable();
     616                 :            : 
     617                 :            :     /** Recalculates sizes and resulting positions of all document entries. */
     618                 :            :     void                Recalc();
     619                 :            : };
     620                 :            : 
     621                 :            : // ============================================================================
     622                 :            : 
     623                 :            : /** The HTML parser for data queries. Focuses on data import, not on layout.
     624                 :            : 
     625                 :            :     Builds the table structure correctly, ignores extended formatting like
     626                 :            :     pictures or column widths.
     627                 :            :  */
     628                 :            : class ScHTMLQueryParser : public ScHTMLParser
     629                 :            : {
     630                 :            : public:
     631                 :            :     explicit            ScHTMLQueryParser( EditEngine* pEditEngine, ScDocument* pDoc );
     632                 :            :     virtual             ~ScHTMLQueryParser();
     633                 :            : 
     634                 :            :     virtual sal_uLong       Read( SvStream& rStrm, const String& rBaseURL  );
     635                 :            : 
     636                 :            :     /** Returns the "global table" which contains the entire HTML document. */
     637                 :            :     virtual const ScHTMLTable* GetGlobalTable() const;
     638                 :            : 
     639                 :            : private:
     640                 :            :     /** Handles all possible tags in the HTML document. */
     641                 :            :     void                ProcessToken( const ImportInfo& rInfo );
     642                 :            :     /** Inserts a text portion into current entry. */
     643                 :            :     void                InsertText( const ImportInfo& rInfo );
     644                 :            :     /** Processes the <font> tag. */
     645                 :            :     void                FontOn( const ImportInfo& rInfo );
     646                 :            : 
     647                 :            :     /** Processes the <meta> tag. */
     648                 :            :     void                MetaOn( const ImportInfo& rInfo );
     649                 :            :     /** Opens the title of the HTML document (<title> tag). */
     650                 :            :     void                TitleOn( const ImportInfo& rInfo );
     651                 :            :     /** Closes the title of the HTML document (</title> tag). */
     652                 :            :     void                TitleOff( const ImportInfo& rInfo );
     653                 :            : 
     654                 :            :     /** Opens a new table at the current position. */
     655                 :            :     void                TableOn( const ImportInfo& rInfo );
     656                 :            :     /** Closes the current table. */
     657                 :            :     void                TableOff( const ImportInfo& rInfo );
     658                 :            :     /** Opens a new table based on preformatted text. */
     659                 :            :     void                PreOn( const ImportInfo& rInfo );
     660                 :            :     /** Closes the current preformatted text table. */
     661                 :            :     void                PreOff( const ImportInfo& rInfo );
     662                 :            : 
     663                 :            :     /** Closes the current table, regardless on opening tag. */
     664                 :            :     void                CloseTable( const ImportInfo& rInfo );
     665                 :            : 
     666                 :            :     void                ParseStyle(const rtl::OUString& rStrm);
     667                 :            : 
     668                 :            :     DECL_LINK( HTMLImportHdl, const ImportInfo* );
     669                 :            : 
     670                 :            : private:
     671                 :            :     typedef ::std::auto_ptr< ScHTMLGlobalTable >    ScHTMLGlobalTablePtr;
     672                 :            : 
     673                 :            :     rtl::OUStringBuffer maTitle;            /// The title of the document.
     674                 :            :     ScHTMLGlobalTablePtr mxGlobTable;       /// Contains the entire imported document.
     675                 :            :     ScHTMLTable*        mpCurrTable;        /// Pointer to current table (performance).
     676                 :            :     ScHTMLTableId       mnUnusedId;         /// First unused table identifier.
     677                 :            :     bool                mbTitleOn;          /// true = Inside of <title> </title>.
     678                 :            : };
     679                 :            : 
     680                 :            : 
     681                 :            : // ============================================================================
     682                 :            : 
     683                 :            : #endif
     684                 :            : 
     685                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10