1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "TablePropertiesHandler.hxx"
22 #include "TablePositionHandler.hxx"
24 #include "TableManager.hxx"
25 #include "PropertyMap.hxx"
28 #include <comphelper/sequenceashashmap.hxx>
30 namespace writerfilter::dmapper
{
34 class DomainMapperTableManager
: public TableManager
36 typedef std::shared_ptr
< std::vector
<sal_Int32
> > IntVectorPtr
;
39 ::std::vector
< sal_uInt32
> m_nCell
;
40 sal_uInt32 m_nGridSpan
;
41 sal_Int32 m_nHeaderRepeat
; //counter of repeated headers - if == -1 then the repeating stops
42 sal_Int32 m_nTableWidth
; //might be set directly or has to be calculated from the column positions
43 /// Are we in a shape (text append stack is not empty) or in the body document?
45 std::vector
< OUString
> m_aTableStyleNames
;
46 /// Moved table (in moveRangeFromStart...moveRangeFromEnd or moveRangeToStart...moveRangeToEnd)
47 std::vector
< OUString
> m_aMoved
;
48 /// Grab-bag of table look attributes for preserving.
49 comphelper::SequenceAsHashMap m_aTableLook
;
50 std::vector
< TablePositionHandlerPtr
> m_aTablePositions
;
51 std::vector
< TablePositionHandlerPtr
> m_aTmpPosition
; ///< Temporarily stores the position to compare it later
52 std::vector
< TablePropertyMapPtr
> m_aTmpTableProperties
; ///< Temporarily stores the table properties until end of row
54 ::std::vector
< IntVectorPtr
> m_aTableGrid
;
55 /// If this is true, then we pushed a width before the next level started, and that should be carried over when starting the next level.
56 bool m_bPushCurrentWidth
;
57 /// Individual table cell width values, used only in case the number of cells doesn't match the table grid.
58 ::std::vector
< IntVectorPtr
> m_aCellWidths
;
59 /// Remember if table width was already set, when we lack a w:tblW, it should be set manually at the end.
60 bool m_bTableSizeTypeInserted
;
61 /// Table layout algorithm, IOW if we should consider fixed column width or not.
62 sal_uInt32 m_nLayoutType
;
63 /// Collected table paragraphs for table style handling
64 std::stack
< TableParagraphVectorPtr
> m_aParagraphsToEndTable
;
66 std::unique_ptr
<TablePropertiesHandler
> m_pTablePropsHandler
;
67 PropertyMapPtr m_pStyleProps
;
69 bool shouldInsertRow(IntVectorPtr pCellWidths
, IntVectorPtr pTableGrid
, size_t nGrids
, bool& rIsIncompleteGrid
);
71 virtual void clearData() override
;
75 DomainMapperTableManager();
76 virtual ~DomainMapperTableManager() override
;
78 // use this method to avoid adding the properties for the table
79 // but in the provided properties map.
80 void SetStyleProperties( PropertyMapPtr pProperties
) { m_pStyleProps
= pProperties
; };
82 virtual bool sprm(Sprm
& rSprm
) override
;
83 bool attribute(Id nName
, Value
const & val
);
85 virtual void startLevel( ) override
;
86 virtual void endLevel( ) override
;
88 virtual void endOfCellAction() override
;
89 virtual void endOfRowAction() override
;
91 IntVectorPtr
const & getCurrentGrid( );
92 IntVectorPtr
const & getCurrentCellWidths( );
93 const TableParagraphVectorPtr
& getCurrentParagraphs( );
95 /// Turn the attributes collected so far in m_aTableLook into a property and clear the container.
96 void finishTableLook();
97 css::uno::Sequence
<css::beans::PropertyValue
> getCurrentTablePosition();
98 TablePositionHandler
* getCurrentTableRealPosition();
100 virtual void cellProps(const TablePropertyMapPtr
& pProps
) override
103 m_pStyleProps
->InsertProps(pProps
.get());
105 TableManager::cellProps( pProps
);
108 virtual void insertRowProps(const TablePropertyMapPtr
& pProps
) override
111 m_pStyleProps
->InsertProps(pProps
.get());
113 TableManager::insertRowProps( pProps
);
116 virtual void insertTableProps(const TablePropertyMapPtr
& pProps
) override
119 m_pStyleProps
->InsertProps(pProps
.get());
121 m_aTmpTableProperties
.back()->InsertProps(pProps
.get());
124 void SetLayoutType(sal_uInt32 nLayoutType
)
126 m_nLayoutType
= nLayoutType
;
129 using TableManager::isInCell
;
131 void setIsInShape(bool bIsInShape
);
133 // moveFromRangeStart and moveToRangeStart are there
134 // in the first paragraph in the first cell of the
135 // table moved by drag & drop with track changes, but
136 // moveFromRangeEnd and moveToRangeEnd follow the
137 // table element w:tbl in the same level (not in paragraph).
138 // (Special indexing is related to the load of the tables:
139 // first-level tables handled by two levels during the
140 // import, to support table join etc. In the first cell,
141 // setMoved() writes the first level from these two levels
142 // i.e. second startLevel() hasn't been called, yet.)
143 // TODO: check drag & drop of only a part of the tables.
144 void setMoved(OUString sMoved
)
146 if ( m_aMoved
.empty() )
149 if ( !sMoved
.isEmpty() )
150 m_aMoved
[m_aMoved
.size() - 1] = sMoved
;
151 else if ( m_aMoved
.size() >= 2 )
152 // next table rows weren't moved
153 m_aMoved
[m_aMoved
.size() - 2] = "";
155 m_aMoved
[m_aMoved
.size() - 1] = "";
158 OUString
getMoved() const
160 if ( m_aMoved
.size() >= 2 && !m_aMoved
[m_aMoved
.size() - 2].isEmpty() )
161 return m_aMoved
[m_aMoved
.size() - 2];
162 else if ( !m_aMoved
.empty() )
163 return m_aMoved
[m_aMoved
.size() -1 ];
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */