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::sun::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,
140  const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
141  SwXMLTableContext( SwXMLImport& rImport,
142  SwXMLTableContext *pTable );
143 
144  virtual ~SwXMLTableContext() override;
145 
146  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
147  sal_Int32 Element,
148  const css::uno::Reference< css::xml::sax::XFastAttributeList > & 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 SAL_CALL endFastElement(sal_Int32 nElement) 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:70
Starts a section of nodes in the document model.
Definition: node.hxx:311
bool IsInsertCellPossible() const
Definition: xmltbli.hxx:158
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:192
void SetHasSubTables(bool bNew)
Definition: xmltbli.hxx:184
void InsertRow(const OUString &rStyleName, const OUString &rDfltCellStyleName, bool bInHead)
Definition: xmltbli.cxx:1467
const SwStartNode * m_pSttNd1
Definition: xmltbli.hxx:73
const SwStartNode * InsertTableSection(const SwStartNode *pPrevSttNd=nullptr, OUString const *pStringValueStyleName=nullptr)
Definition: xmltbli.cxx:2638
SwTableLine * MakeTableLine(SwTableBox *pUpper, sal_uInt32 nTopRow, sal_uInt32 nLeftCol, sal_uInt32 nBottomRow, sal_uInt32 nRightCol)
Definition: xmltbli.cxx:1970
OUString GetColumnDefaultCellStyleName(sal_uInt32 nCol) const
Definition: xmltbli.cxx:1347
SwTableBoxFormat * m_pBoxFormat
Definition: xmltbli.hxx:75
SvXMLImport & GetImport()
SwTableLine is one table row in the document model.
Definition: swtable.hxx:351
SwTableBox * NewTableBox(const SwStartNode *pStNd, SwTableLine *pUpper)
Definition: xmltbli.cxx:1618
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:1075
std::unique_ptr< std::vector< OUString > > m_pColumnDefaultCellStyleNames
Definition: xmltbli.hxx:63
#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:65
const SwStartNode * GetPrevStartNode(sal_uInt32 nRow, sal_uInt32 nCol) const
Definition: xmltbli.cxx:1546
sal_uInt32 m_nCurCol
Definition: xmltbli.hxx:94
exports com.sun.star. text
SvXMLImportContextRef m_xParentTable
Definition: xmltbli.hxx:84
void ReplaceWithEmptyCell(sal_uInt32 nRow, sal_uInt32 nCol, bool bRows)
Definition: xmltbli.cxx:1600
void InsertRepRows(sal_uInt32 nCount)
Definition: xmltbli.cxx:1506
css::uno::Reference< css::text::XTextContent > m_xTextContent
Definition: xmltbli.hxx:66
sal_uInt16 width
Column width (absolute or relative).
Definition: xmltbli.hxx:58
SwXMLTableContext(SwXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
if set, call pBox->LockModify() and return old lock status
void InsertColumn(sal_Int32 nWidth, bool bRelWidth, const OUString *pDfltCellStyleName=nullptr)
Definition: xmltbli.cxx:1302
bool IsInsertRowPossible() const
Definition: xmltbli.hxx:160
SwTableBox * m_pBox1
Definition: xmltbli.hxx:71
void MakeTable_(SwTableBox *pBox=nullptr)
Definition: xmltbli.cxx:2168
bool IsInsertColPossible() const
Definition: xmltbli.hxx:159
Holds basic information about a column's width.
Definition: xmltbli.hxx:57
virtual ~SwXMLTableContext() override
Definition: xmltbli.cxx:1243
SwXMLImport & GetSwImport()
Definition: xmltbli.hxx:150
sal_Int32 m_nWidth
Definition: xmltbli.hxx:95
std::unique_ptr< map_BoxFormat > m_pSharedBoxFormats
Definition: xmltbli.hxx:82
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmltbli.cxx:2710
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:1645
sal_uInt16 m_nHeaderRows
Definition: xmltbli.hxx:92
void FixRowSpan(sal_uInt32 nRow, sal_uInt32 nCol, sal_uInt32 nColSpan)
Definition: xmltbli.cxx:1583
const SwStartNode * GetLastStartNode() const
Definition: xmltbli.hxx:197
sal_Int32 GetColumnWidth(sal_uInt32 nCol, sal_uInt32 nColSpan) const
Definition: xmltbli.cxx:1333
std::vector< ColumnWidthInfo > m_aColumnWidths
Definition: xmltbli.hxx:62
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:254
static constexpr sal_Int32 MAX_WIDTH
Definition: xmltbli.hxx:100
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:392
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:1798
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
bool m_bHasSubTables
Definition: xmltbli.hxx:90
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmltbli.cxx:1255
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:1355