LibreOffice Module sw (master)  1
xmltbli.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_SW_SOURCE_FILTER_XML_XMLTBLI_HXX
21 #define INCLUDED_SW_SOURCE_FILTER_XML_XMLTBLI_HXX
22 
24 
25 #include "xmlimp.hxx"
26 
27 #include <memory>
28 #include <unordered_map>
29 #include <vector>
30 
31 class SwXMLImport;
32 class SwTableNode;
33 class SwTableBox;
34 class SwTableLine;
35 class SwStartNode;
36 class SwTableBoxFormat;
37 class SwTableLineFormat;
40 typedef std::vector<std::unique_ptr<SwXMLTableRow_Impl>> SwXMLTableRows_Impl;
43 class TableBoxIndex;
44 
45 namespace com { namespace sun { namespace star {
46  namespace text { class XTextContent; }
47  namespace text { class XTextCursor; }
48 } } }
49 
51 {
52  OUString m_aStyleName;
54  OUString m_aTemplateName;
55 
57  struct ColumnWidthInfo {
58  sal_uInt16 width;
59  bool isRelative;
60  ColumnWidthInfo(sal_uInt16 wdth, bool isRel) : width(wdth), isRelative(isRel) {};
61  };
62  std::vector<ColumnWidthInfo> m_aColumnWidths;
63  std::unique_ptr<std::vector<OUString>> m_pColumnDefaultCellStyleNames;
64 
65  css::uno::Reference< css::text::XTextCursor > m_xOldCursor;
66  css::uno::Reference< css::text::XTextContent > m_xTextContent;
67 
68  std::unique_ptr<SwXMLTableRows_Impl> m_pRows;
69 
74 
77 
78  // hash map of shared format, indexed by the (XML) style name,
79  // the column width, and protection flag
80  typedef std::unordered_map<TableBoxIndex,SwTableBoxFormat*,
82  std::unique_ptr<map_BoxFormat> m_pSharedBoxFormats;
83 
84  SvXMLImportContextRef m_xParentTable; // if table is a sub table
85 
87 
88  bool m_bFirstSection : 1;
89  bool m_bRelWidth : 1;
90  bool m_bHasSubTables : 1;
91 
92  sal_uInt16 m_nHeaderRows;
93  sal_uInt32 m_nCurRow;
94  sal_uInt32 m_nCurCol;
95  sal_Int32 m_nWidth;
96 
97  // The maximum table width (i.e., maximum value for m_nWidth); must be >= MINLAY and must also
98  // fit into ColumnWidthInfo::width (of type sal_uInt16), see e.g. the emplacement of
99  // MINLAY<=nWidth2<=MAX_WIDTH into m_aColumnWidths in SwXMLTableContext::InsertColumn:
100  static constexpr sal_Int32 MAX_WIDTH = SAL_MAX_UINT16;
101 
102  SwTableBox *NewTableBox( const SwStartNode *pStNd,
103  SwTableLine *pUpper );
105  const SwXMLTableCell_Impl *pStartNode,
106  sal_uInt32 nLeftCol, sal_uInt32 nRightCol );
108  sal_uInt32 nTopRow, sal_uInt32 nLeftCol,
109  sal_uInt32 nBottomRow, sal_uInt32 nRightCol );
111  sal_uInt32 nTopRow, sal_uInt32 nLeftCol,
112  sal_uInt32 nBottomRow, sal_uInt32 nRightCol );
113 
114  void MakeTable_( SwTableBox *pBox=nullptr );
115  void MakeTable( SwTableBox *pBox, sal_Int32 nWidth );
116  void MakeTable();
117 
118  inline SwXMLTableContext *GetParentTable() const;
119 
120  const SwStartNode *GetPrevStartNode( sal_uInt32 nRow,
121  sal_uInt32 nCol ) const;
122  inline const SwStartNode *GetLastStartNode() const;
123  void FixRowSpan( sal_uInt32 nRow, sal_uInt32 nCol, sal_uInt32 nColSpan );
124  void ReplaceWithEmptyCell( sal_uInt32 nRow, sal_uInt32 nCol, bool bRows );
125 
127  SwTableBoxFormat* GetSharedBoxFormat(
128  SwTableBox* pBox,
129  const OUString& rStyleName,
130  sal_Int32 nColumnWidth,
131  bool bProtected,
132  bool bMayShare,
133  bool& bNew,
134  bool* pModifyLocked );
135 
136 public:
137 
138 
139  SwXMLTableContext( SwXMLImport& rImport, sal_uInt16 nPrfx,
140  const OUString& rLName,
141  const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList );
142  SwXMLTableContext( SwXMLImport& rImport, sal_uInt16 nPrfx,
143  const OUString& rLName,
144  SwXMLTableContext *pTable );
145 
146  virtual ~SwXMLTableContext() override;
147 
148  virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
149  const OUString& rLocalName,
150  const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override;
151 
152  SwXMLImport& GetSwImport() { return static_cast<SwXMLImport&>(GetImport()); }
153 
154  void InsertColumn( sal_Int32 nWidth, bool bRelWidth,
155  const OUString *pDfltCellStyleName = nullptr );
156  sal_Int32 GetColumnWidth( sal_uInt32 nCol, sal_uInt32 nColSpan ) const;
157  OUString GetColumnDefaultCellStyleName( sal_uInt32 nCol ) const;
158  inline sal_uInt32 GetColumnCount() const;
159 
160  bool IsInsertCellPossible() const { return m_nCurCol < GetColumnCount(); }
161  bool IsInsertColPossible() const { return m_nCurCol < USHRT_MAX; }
162  bool IsInsertRowPossible() const { return m_nCurRow < USHRT_MAX; }
163  bool IsValid() const { return m_pTableNode != nullptr; }
164 
165  void InsertCell( const OUString& rStyleName,
166  sal_uInt32 nRowSpan, sal_uInt32 nColSpan,
167  const SwStartNode *pStNd,
168  SwXMLTableContext *pTable=nullptr,
169  bool bIsProtected = false,
170  const OUString *pFormula=nullptr,
171  bool bHasValue = false,
172  double fValue = 0.0,
173  OUString const*const pStringValue = nullptr);
174  void InsertRow( const OUString& rStyleName,
175  const OUString& rDfltCellStyleName,
176  bool bInHead );
177  void FinishRow();
178  void InsertRepRows( sal_uInt32 nCount );
179  const SwXMLTableCell_Impl *GetCell( sal_uInt32 nRow, sal_uInt32 nCol ) const;
180  SwXMLTableCell_Impl *GetCell( sal_uInt32 nRow, sal_uInt32 nCol );
181  const SwStartNode *InsertTableSection(const SwStartNode *pPrevSttNd = nullptr,
182  OUString const* pStringValueStyleName = nullptr);
183 
184  virtual void EndElement() override;
185 
186  void SetHasSubTables( bool bNew ) { m_bHasSubTables = bNew; }
187 };
188 
190 {
191  return static_cast<SwXMLTableContext *>(m_xParentTable.get());
192 }
193 
194 inline sal_uInt32 SwXMLTableContext::GetColumnCount() const
195 {
196  return m_aColumnWidths.size();
197 }
198 
200 {
201  return GetPrevStartNode( 0UL, GetColumnCount() );
202 }
203 
204 #endif
205 
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwTableNode * m_pTableNode
Definition: xmltbli.hxx:70
Starts a section of nodes in the document model.
Definition: node.hxx:303
bool IsInsertCellPossible() const
Definition: xmltbli.hxx:160
std::unique_ptr< SwXMLTableRows_Impl > m_pRows
Definition: xmltbli.hxx:68
bool isRelative
True for a relative width, false for absolute.
Definition: xmltbli.hxx:59
ColumnWidthInfo(sal_uInt16 wdth, bool isRel)
Definition: xmltbli.hxx:60
sal_uInt32 GetColumnCount() const
Definition: xmltbli.hxx:194
void SetHasSubTables(bool bNew)
Definition: xmltbli.hxx:186
void InsertRow(const OUString &rStyleName, const OUString &rDfltCellStyleName, bool bInHead)
Definition: xmltbli.cxx:1613
const SwStartNode * m_pSttNd1
Definition: xmltbli.hxx:73
const SwStartNode * InsertTableSection(const SwStartNode *pPrevSttNd=nullptr, OUString const *pStringValueStyleName=nullptr)
Definition: xmltbli.cxx:2782
SwTableLine * MakeTableLine(SwTableBox *pUpper, sal_uInt32 nTopRow, sal_uInt32 nLeftCol, sal_uInt32 nBottomRow, sal_uInt32 nRightCol)
Definition: xmltbli.cxx:2116
OUString GetColumnDefaultCellStyleName(sal_uInt32 nCol) const
Definition: xmltbli.cxx:1493
SwTableBoxFormat * m_pBoxFormat
Definition: xmltbli.hxx:75
SvXMLImport & GetImport()
SwTableLine is one table row in the document model.
Definition: swtable.hxx:344
SwTableBox * NewTableBox(const SwStartNode *pStNd, SwTableLine *pUpper)
Definition: xmltbli.cxx:1764
OUString m_aDfltCellStyleName
Definition: xmltbli.hxx:53
OUString m_aStyleName
Definition: xmltbli.hxx:52
rtl::Reference< SwXMLDDETableContext_Impl > m_xDDESource
Definition: xmltbli.hxx:86
const SwXMLTableCell_Impl * GetCell(sal_uInt32 nRow, sal_uInt32 nCol) const
Definition: xmltbli.cxx:1207
std::unique_ptr< std::vector< OUString > > m_pColumnDefaultCellStyleNames
Definition: xmltbli.hxx:63
#define SAL_MAX_UINT16
bool IsValid() const
Definition: xmltbli.hxx:163
SwXMLTableContext * GetParentTable() const
Definition: xmltbli.hxx:189
css::uno::Reference< css::text::XTextCursor > m_xOldCursor
Definition: xmltbli.hxx:65
const SwStartNode * GetPrevStartNode(sal_uInt32 nRow, sal_uInt32 nCol) const
Definition: xmltbli.cxx:1692
sal_uInt32 m_nCurCol
Definition: xmltbli.hxx:94
SvXMLImportContextRef m_xParentTable
Definition: xmltbli.hxx:84
void ReplaceWithEmptyCell(sal_uInt32 nRow, sal_uInt32 nCol, bool bRows)
Definition: xmltbli.cxx:1746
void InsertRepRows(sal_uInt32 nCount)
Definition: xmltbli.cxx:1652
css::uno::Reference< css::text::XTextContent > m_xTextContent
Definition: xmltbli.hxx:66
sal_uInt16 width
Column width (absolute or relative).
Definition: xmltbli.hxx:58
virtual void EndElement() override
Definition: xmltbli.cxx:2854
void InsertColumn(sal_Int32 nWidth, bool bRelWidth, const OUString *pDfltCellStyleName=nullptr)
Definition: xmltbli.cxx:1448
bool IsInsertRowPossible() const
Definition: xmltbli.hxx:162
SwTableBox * m_pBox1
Definition: xmltbli.hxx:71
void MakeTable_(SwTableBox *pBox=nullptr)
Definition: xmltbli.cxx:2314
bool IsInsertColPossible() const
Definition: xmltbli.hxx:161
Holds basic information about a column's width.
Definition: xmltbli.hxx:57
virtual ~SwXMLTableContext() override
Definition: xmltbli.cxx:1382
SwXMLImport & GetSwImport()
Definition: xmltbli.hxx:152
sal_Int32 m_nWidth
Definition: xmltbli.hxx:95
std::unique_ptr< map_BoxFormat > m_pSharedBoxFormats
Definition: xmltbli.hxx:82
SwTableBoxFormat * GetSharedBoxFormat(SwTableBox *pBox, const OUString &rStyleName, sal_Int32 nColumnWidth, bool bProtected, bool bMayShare, bool &bNew, bool *pModifyLocked)
sets the appropriate SwTableBoxFormat at pBox.
Definition: xmltbli.cxx:1791
sal_uInt16 m_nHeaderRows
Definition: xmltbli.hxx:92
void FixRowSpan(sal_uInt32 nRow, sal_uInt32 nCol, sal_uInt32 nColSpan)
Definition: xmltbli.cxx:1729
const SwStartNode * GetLastStartNode() const
Definition: xmltbli.hxx:199
sal_Int32 GetColumnWidth(sal_uInt32 nCol, sal_uInt32 nColSpan) const
Definition: xmltbli.cxx:1479
std::vector< ColumnWidthInfo > m_aColumnWidths
Definition: xmltbli.hxx:62
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString &rLocalName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList) override
Definition: xmltbli.cxx:1394
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
static constexpr sal_Int32 MAX_WIDTH
Definition: xmltbli.hxx:100
SwXMLTableContext(SwXMLImport &rImport, sal_uInt16 nPrfx, const OUString &rLName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttrList)
if set, call pBox->LockModify() and return old lock status
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
std::vector< std::unique_ptr< SwXMLTableRow_Impl > > SwXMLTableRows_Impl
Definition: xmltbli.hxx:39
SwTableBox * MakeTableBox(SwTableLine *pUpper, const SwXMLTableCell_Impl *pStartNode, sal_uInt32 nLeftCol, sal_uInt32 nRightCol)
Definition: xmltbli.cxx:1944
sal_uInt32 m_nCurRow
Definition: xmltbli.hxx:93
std::unordered_map< TableBoxIndex, SwTableBoxFormat *, TableBoxIndexHasher > map_BoxFormat
Definition: xmltbli.hxx:81
bool m_bFirstSection
Definition: xmltbli.hxx:88
def text(shape, st)
bool m_bHasSubTables
Definition: xmltbli.hxx:90
OUString m_aTemplateName
Definition: xmltbli.hxx:54
SwTableLineFormat * m_pLineFormat
Definition: xmltbli.hxx:76
void InsertCell(const OUString &rStyleName, sal_uInt32 nRowSpan, sal_uInt32 nColSpan, const SwStartNode *pStNd, SwXMLTableContext *pTable=nullptr, bool bIsProtected=false, const OUString *pFormula=nullptr, bool bHasValue=false, double fValue=0.0, OUString const *const pStringValue=nullptr)
Definition: xmltbli.cxx:1501