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 
20 #pragma once
21 
22 #include <tools/gen.hxx>
23 #include <vcl/errcode.hxx>
24 #include <vcl/graph.hxx>
25 #include <svl/itemset.hxx>
26 #include <svl/itempool.hxx>
27 #include <editeng/editdata.hxx>
28 #include <optional>
29 #include <address.hxx>
30 #include <memory>
31 #include <vector>
32 #include <map>
33 
34 const char nHorizontal = 1;
35 const char nVertical = 2;
36 
37 struct ScHTMLImage
38 {
39     OUString            aURL;
40     Size                aSize;
41     Point               aSpace;
42     OUString            aFilterName;
43     std::unique_ptr<Graphic>
44                         pGraphic;       // is taken over by WriteToDocument
45     char                nDir;           // 1==hori, 2==verti, 3==both
46 
ScHTMLImageScHTMLImage47     ScHTMLImage() :
48         aSize( 0, 0 ), aSpace( 0, 0 ), nDir( nHorizontal )
49         {}
50 };
51 
52 struct ScEEParseEntry
53 {
54     SfxItemSet          aItemSet;
55     ESelection          aSel;           // Selection in EditEngine
56     std::optional<OUString>
57                         pValStr;        // HTML possibly SDVAL string
58     std::optional<OUString>
59                         pNumStr;        // HTML possibly SDNUM string
60     std::optional<OUString>
61                         pName;          // HTML possibly anchor/RangeName
62     OUString            aAltText;       // HTML IMG ALT Text
63     std::vector< std::unique_ptr<ScHTMLImage> > maImageList;       // graphics in this cell
64     SCCOL               nCol;           // relative to the beginning of the parse
65     SCROW               nRow;
66     sal_uInt16          nTab;           // HTML TableInTable
67     sal_uInt16          nTwips;         // RTF ColAdjust etc.
68     SCCOL               nColOverlap;    // merged cells if >1
69     SCROW               nRowOverlap;    // merged cells if >1
70     sal_uInt16          nOffset;        // HTML PixelOffset
71     sal_uInt16          nWidth;         // HTML PixelWidth
72     bool                bHasGraphic:1;  // HTML any image loaded
73     bool                bEntirePara:1;  // true = use entire paragraph, false = use selection
74 
ScEEParseEntryScEEParseEntry75     ScEEParseEntry( SfxItemPool* pPool ) :
76         aItemSet( *pPool ),
77         nCol(SCCOL_MAX), nRow(SCROW_MAX), nTab(0),
78         nTwips(0), nColOverlap(1), nRowOverlap(1),
79         nOffset(0), nWidth(0), bHasGraphic(false), bEntirePara(true)
80         {}
81 
ScEEParseEntryScEEParseEntry82     ScEEParseEntry( const SfxItemSet& rItemSet ) :
83         aItemSet( rItemSet ),
84         nCol(SCCOL_MAX), nRow(SCROW_MAX), nTab(0),
85         nTwips(0), nColOverlap(1), nRowOverlap(1),
86         nOffset(0), nWidth(0), bHasGraphic(false), bEntirePara(true)
87         {}
88 
~ScEEParseEntryScEEParseEntry89     ~ScEEParseEntry()
90     {
91         maImageList.clear();
92     }
93 };
94 
95 class EditEngine;
96 
97 typedef std::map<SCCOL, sal_uInt16> ColWidthsMap;
98 
99 class ScEEParser
100 {
101 protected:
102     EditEngine*         pEdit;
103     rtl::Reference<SfxItemPool>  pPool;
104     rtl::Reference<SfxItemPool>  pDocPool;
105     std::vector<std::shared_ptr<ScEEParseEntry>> maList;
106     std::shared_ptr<ScEEParseEntry> mxActEntry;
107     ColWidthsMap        maColWidths;
108     int                 nRtfLastToken;
109     SCCOL               nColCnt;
110     SCROW               nRowCnt;
111     SCCOL               nColMax;
112     SCROW               nRowMax;
113 
114     void                NewActEntry( const ScEEParseEntry* );
115 
116 public:
117                         ScEEParser( EditEngine* );
118     virtual             ~ScEEParser();
119 
120     virtual ErrCode         Read( SvStream&, const OUString& rBaseURL ) = 0;
121 
GetColWidths() const122     const ColWidthsMap&     GetColWidths() const { return maColWidths; }
GetColWidths()123     ColWidthsMap&           GetColWidths() { return maColWidths; }
GetDimensions(SCCOL & nCols,SCROW & nRows) const124     void                    GetDimensions( SCCOL& nCols, SCROW& nRows ) const
125                                 { nCols = nColMax; nRows = nRowMax; }
126 
ListSize() const127     size_t                  ListSize() const{ return maList.size(); }
ListEntry(size_t index)128     ScEEParseEntry*         ListEntry( size_t index ) { return maList[index].get(); }
ListEntry(size_t index) const129     const ScEEParseEntry*   ListEntry( size_t index ) const { return maList[index].get(); }
130 };
131 
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
133