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