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
31class SwXMLImport;
32class SwTableNode;
33class SwTableBox;
34class SwTableLine;
35class SwStartNode;
40typedef std::vector<std::unique_ptr<SwXMLTableRow_Impl>> SwXMLTableRows_Impl;
43class TableBoxIndex;
44
45namespace com::sun::star {
46 namespace text { class XTextContent; }
47 namespace text { class XTextCursor; }
48}
49
51{
52 OUString m_aStyleName;
55
58 sal_uInt16 width;
60 ColumnWidthInfo(sal_uInt16 wdth, bool isRel) : width(wdth), isRelative(isRel) {};
61 };
62 std::vector<ColumnWidthInfo> m_aColumnWidths;
63 std::optional<std::vector<OUString>> m_xColumnDefaultCellStyleNames;
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
89 bool m_bRelWidth : 1;
91
92 sal_uInt16 m_nHeaderRows;
93 sal_uInt32 m_nCurRow;
94 sal_uInt32 m_nCurCol;
97 sal_Int32 m_nWidth;
98
99 // The maximum table width (i.e., maximum value for m_nWidth); must be >= MINLAY and must also
100 // fit into ColumnWidthInfo::width (of type sal_uInt16), see e.g. the emplacement of
101 // MINLAY<=nWidth2<=MAX_WIDTH into m_aColumnWidths in SwXMLTableContext::InsertColumn:
102 static constexpr sal_Int32 MAX_WIDTH = SAL_MAX_UINT16;
103
104 SwTableBox *NewTableBox( const SwStartNode *pStNd,
105 SwTableLine *pUpper );
107 const SwXMLTableCell_Impl *pStartNode,
108 sal_uInt32 nLeftCol, sal_uInt32 nRightCol );
110 sal_uInt32 nTopRow, sal_uInt32 nLeftCol,
111 sal_uInt32 nBottomRow, sal_uInt32 nRightCol );
113 sal_uInt32 nTopRow, sal_uInt32 nLeftCol,
114 sal_uInt32 nBottomRow, sal_uInt32 nRightCol );
115
116 void MakeTable_( SwTableBox *pBox=nullptr );
117 void MakeTable( SwTableBox *pBox, sal_Int32 nWidth );
118 void MakeTable();
119
120 inline SwXMLTableContext *GetParentTable() const;
121
122 const SwStartNode *GetPrevStartNode( sal_uInt32 nRow,
123 sal_uInt32 nCol ) const;
124 inline const SwStartNode *GetLastStartNode() const;
125 void FixRowSpan( sal_uInt32 nRow, sal_uInt32 nCol, sal_uInt32 nColSpan );
126 void ReplaceWithEmptyCell( sal_uInt32 nRow, sal_uInt32 nCol, bool bRows );
127
130 SwTableBox* pBox,
131 const OUString& rStyleName,
132 sal_Int32 nColumnWidth,
133 bool bProtected,
134 bool bMayShare,
135 bool& bNew,
136 bool* pModifyLocked );
137
138public:
139
140
142 const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList );
144 SwXMLTableContext *pTable );
145
146 virtual ~SwXMLTableContext() override;
147
148 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
149 sal_Int32 Element,
150 const css::uno::Reference< css::xml::sax::XFastAttributeList > & 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
164
165 bool IsInsertColPossible() const { return m_nCurCol < USHRT_MAX; }
166 bool IsInsertRowPossible() const { return m_nCurRow < USHRT_MAX; }
167 bool IsValid() const { return m_pTableNode != nullptr; }
168
169 void InsertCell( const OUString& rStyleName,
170 sal_uInt32 nRowSpan, sal_uInt32 nColSpan,
171 const SwStartNode *pStNd,
172 SwXMLTableContext *pTable=nullptr,
173 bool bIsProtected = false,
174 const OUString *pFormula=nullptr,
175 bool bHasValue = false,
176 double fValue = 0.0,
177 OUString const*const pStringValue = nullptr);
178
180 void InsertCoveredCell(const OUString& rStyleName);
181
182 void InsertRow( const OUString& rStyleName,
183 const OUString& rDfltCellStyleName,
184 bool bInHead );
185 void FinishRow();
186 void InsertRepRows( sal_uInt32 nCount );
187 const SwXMLTableCell_Impl *GetCell( sal_uInt32 nRow, sal_uInt32 nCol ) const;
188 SwXMLTableCell_Impl *GetCell( sal_uInt32 nRow, sal_uInt32 nCol );
189 const SwStartNode *InsertTableSection(const SwStartNode *pPrevSttNd = nullptr,
190 OUString const* pStringValueStyleName = nullptr);
191
192 virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
193
194 void SetHasSubTables( bool bNew ) { m_bHasSubTables = bNew; }
195};
196
198{
199 return static_cast<SwXMLTableContext *>(m_xParentTable.get());
200}
201
202inline sal_uInt32 SwXMLTableContext::GetColumnCount() const
203{
204 return m_aColumnWidths.size();
205}
206
208{
209 return GetPrevStartNode( 0UL, GetColumnCount() );
210}
211
212#endif
213
214/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvXMLImport & GetImport()
Starts a section of nodes in the document model.
Definition: node.hxx:348
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:443
SwTableLine is one table row in the document model.
Definition: swtable.hxx:376
std::unique_ptr< SwXMLTableRows_Impl > m_pRows
Definition: xmltbli.hxx:68
const SwXMLTableCell_Impl * GetCell(sal_uInt32 nRow, sal_uInt32 nCol) const
Definition: xmltbli.cxx:1103
sal_uInt32 GetColumnCount() const
Definition: xmltbli.hxx:202
std::unique_ptr< map_BoxFormat > m_pSharedBoxFormats
Definition: xmltbli.hxx:82
std::vector< ColumnWidthInfo > m_aColumnWidths
Definition: xmltbli.hxx:62
bool IsValid() const
Definition: xmltbli.hxx:167
void InsertCoveredCell(const OUString &rStyleName)
Sets formatting of an already created covered cell.
Definition: xmltbli.cxx:1503
void FixRowSpan(sal_uInt32 nRow, sal_uInt32 nCol, sal_uInt32 nColSpan)
Definition: xmltbli.cxx:1632
bool IsInsertCoveredCellPossible() const
Determines if it's OK to insert a covered cell, given the total column count.
Definition: xmltbli.hxx:163
sal_uInt32 m_nCurRow
Definition: xmltbli.hxx:93
bool m_bFirstSection
Definition: xmltbli.hxx:88
SwTableBoxFormat * m_pBoxFormat
Definition: xmltbli.hxx:75
void InsertColumn(sal_Int32 nWidth, bool bRelWidth, const OUString *pDfltCellStyleName=nullptr)
Definition: xmltbli.cxx:1337
sal_uInt32 m_nNonMergedCurCol
Same as m_nCurCol, but not incremented multiple times for table cells with row span.
Definition: xmltbli.hxx:96
SwTableBox * NewTableBox(const SwStartNode *pStNd, SwTableLine *pUpper)
Definition: xmltbli.cxx:1667
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:1390
std::optional< std::vector< OUString > > m_xColumnDefaultCellStyleNames
Definition: xmltbli.hxx:63
const SwStartNode * GetPrevStartNode(sal_uInt32 nRow, sal_uInt32 nCol) const
Definition: xmltbli.cxx:1595
css::uno::Reference< css::text::XTextContent > m_xTextContent
Definition: xmltbli.hxx:66
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:1694
const SwStartNode * InsertTableSection(const SwStartNode *pPrevSttNd=nullptr, OUString const *pStringValueStyleName=nullptr)
Definition: xmltbli.cxx:2672
void ReplaceWithEmptyCell(sal_uInt32 nRow, sal_uInt32 nCol, bool bRows)
Definition: xmltbli.cxx:1649
sal_uInt16 m_nHeaderRows
Definition: xmltbli.hxx:92
const SwStartNode * GetLastStartNode() const
Definition: xmltbli.hxx:207
SwXMLImport & GetSwImport()
Definition: xmltbli.hxx:152
void MakeTable_(SwTableBox *pBox=nullptr)
Definition: xmltbli.cxx:2209
SvXMLImportContextRef m_xParentTable
Definition: xmltbli.hxx:84
OUString m_aStyleName
Definition: xmltbli.hxx:52
std::unordered_map< TableBoxIndex, SwTableBoxFormat *, TableBoxIndexHasher > map_BoxFormat
Definition: xmltbli.hxx:81
SwTableBox * m_pBox1
Definition: xmltbli.hxx:71
virtual ~SwXMLTableContext() override
Definition: xmltbli.cxx:1279
bool IsInsertCellPossible() const
Definition: xmltbli.hxx:160
rtl::Reference< SwXMLDDETableContext_Impl > m_xDDESource
Definition: xmltbli.hxx:86
SwXMLTableContext * GetParentTable() const
Definition: xmltbli.hxx:197
css::uno::Reference< css::text::XTextCursor > m_xOldCursor
Definition: xmltbli.hxx:65
sal_Int32 m_nWidth
Definition: xmltbli.hxx:97
bool IsInsertColPossible() const
Definition: xmltbli.hxx:165
SwTableLine * MakeTableLine(SwTableBox *pUpper, sal_uInt32 nTopRow, sal_uInt32 nLeftCol, sal_uInt32 nBottomRow, sal_uInt32 nRightCol)
Definition: xmltbli.cxx:2011
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:1291
sal_Int32 GetColumnWidth(sal_uInt32 nCol, sal_uInt32 nColSpan) const
Definition: xmltbli.cxx:1368
bool IsInsertRowPossible() const
Definition: xmltbli.hxx:166
SwTableNode * m_pTableNode
Definition: xmltbli.hxx:70
OUString m_aTemplateName
Definition: xmltbli.hxx:54
void InsertRepRows(sal_uInt32 nCount)
Definition: xmltbli.cxx:1555
const SwStartNode * m_pSttNd1
Definition: xmltbli.hxx:73
bool m_bHasSubTables
Definition: xmltbli.hxx:90
sal_uInt32 m_nCurCol
Definition: xmltbli.hxx:94
OUString m_aDfltCellStyleName
Definition: xmltbli.hxx:53
void InsertRow(const OUString &rStyleName, const OUString &rDfltCellStyleName, bool bInHead)
Definition: xmltbli.cxx:1515
SwXMLTableContext(SwXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
if set, call pBox->LockModify() and return old lock status
void SetHasSubTables(bool bNew)
Definition: xmltbli.hxx:194
SwTableLineFormat * m_pLineFormat
Definition: xmltbli.hxx:76
OUString GetColumnDefaultCellStyleName(sal_uInt32 nCol) const
Definition: xmltbli.cxx:1382
static constexpr sal_Int32 MAX_WIDTH
Definition: xmltbli.hxx:102
SwTableBox * MakeTableBox(SwTableLine *pUpper, const SwXMLTableCell_Impl *pStartNode, sal_uInt32 nLeftCol, sal_uInt32 nRightCol)
Definition: xmltbli.cxx:1847
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmltbli.cxx:2742
def text(shape, orig_st)
Holds basic information about a column's width.
Definition: xmltbli.hxx:57
ColumnWidthInfo(sal_uInt16 wdth, bool isRel)
Definition: xmltbli.hxx:60
bool isRelative
True for a relative width, false for absolute.
Definition: xmltbli.hxx:59
sal_uInt16 width
Column width (absolute or relative).
Definition: xmltbli.hxx:58
#define SAL_MAX_UINT16
std::vector< std::unique_ptr< SwXMLTableRow_Impl > > SwXMLTableRows_Impl
Definition: xmltbli.hxx:39