Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / tblsel.hxx
blob72057211e3f5c8c691d4a66d6b81f800cf4a2854
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #ifndef INCLUDED_SW_INC_TBLSEL_HXX
20 #define INCLUDED_SW_INC_TBLSEL_HXX
22 #include <swtable.hxx>
23 #include <swrect.hxx>
24 #include "swdllapi.h"
26 #include <o3tl/sorted_vector.hxx>
28 #include <memory>
29 #include <deque>
30 #include <vector>
32 class SwCursorShell;
33 class SwCursor;
34 class SwTableCursor;
35 class SwFrame;
36 class SwTabFrame;
37 class SwTableBox;
38 class SwTableLine;
39 class SwLayoutFrame;
40 class SwPaM;
41 class SwNode;
42 class SwTable;
43 class SwUndoTableMerge;
44 class SwCellFrame;
46 typedef std::deque< SwCellFrame* > SwCellFrames;
48 struct CompareSwSelBoxes
50 bool operator()(SwTableBox* const& lhs, SwTableBox* const& rhs) const
52 return lhs->GetSttIdx() < rhs->GetSttIdx();
55 class SwSelBoxes : public o3tl::sorted_vector<SwTableBox*, CompareSwSelBoxes> {};
57 // Collects all boxes in table that are selected.
58 // Selection gets extended in given direction according to enum-parameter.
59 // Boxes are collected via the Layout; works correctly if tables are split.
60 // (Cf. MakeSelUnions().)
61 enum class SwTableSearchType : sal_uInt16
63 NONE = 0x01, // No extension.
64 Row = 0x02, // Extend to rows.
65 Col = 0x03, // Extend to columns.
67 // As flags to the other values!
68 Protect = 0x08, // Collect protected boxes too.
69 NoUnionCorrect = 0x10, // Do not correct collected Union.
71 namespace o3tl {
72 template<> struct typed_flags<SwTableSearchType> : is_typed_flags<SwTableSearchType, 0x1f> {};
75 SW_DLLPUBLIC void GetTableSel( const SwCursorShell& rShell, SwSelBoxes& rBoxes,
76 const SwTableSearchType = SwTableSearchType::NONE );
78 void GetTableSel( const SwCursor& rCursor, SwSelBoxes& rBoxes,
79 const SwTableSearchType = SwTableSearchType::NONE );
81 // As before, but don't start from selection but from Start- EndFrames.
82 void GetTableSel( const SwLayoutFrame* pStart, const SwLayoutFrame* pEnd,
83 SwSelBoxes& rBoxes, SwCellFrames* pCells,
84 const SwTableSearchType = SwTableSearchType::NONE );
86 // As before but directly via PaMs.
87 void GetTableSelCrs( const SwCursorShell& rShell, SwSelBoxes& rBoxes );
88 void GetTableSelCrs( const SwTableCursor& rTableCursor, SwSelBoxes& rBoxes );
90 // Collect boxes relevant for auto sum.
91 bool GetAutoSumSel( const SwCursorShell&, SwCellFrames& );
93 // Check if the SelBoxes contains protected Boxes.
94 bool HasProtectedCells( const SwSelBoxes& rBoxes );
96 // Check if selection is balanced.
97 bool ChkChartSel( const SwNode& rSttNd, const SwNode& rEndNd);
99 // Check if cell is part of SSelection.
100 // (Became a function, in order to make sure that GetTableSel() and MakeTableCursor()
101 // have always the same concept of the selection.
102 bool IsFrameInTableSel( const SwRect& rUnion, const SwFrame* pCell );
104 // Determine boxes to be merged.
105 // In this process the rectangle gets "adapted" on the base of the layout,
106 // i.e. boxes are added if some overlap at the sides.
107 // Additionally a new box is created and filled with the relevant content.
108 void GetMergeSel( const SwPaM& rPam, SwSelBoxes& rBoxes,
109 SwTableBox** ppMergeBox, SwUndoTableMerge* pUndo );
111 // Check if selected boxes allow for a valid merge.
112 TableMergeErr CheckMergeSel( const SwPaM& rPam );
113 TableMergeErr CheckMergeSel( const SwSelBoxes& rBoxes );
115 bool IsEmptyBox( const SwTableBox& rBox, SwPaM& rPam );
117 // Check if Split or InsertCol lead to a box becoming smaller than MINLAY.
118 bool CheckSplitCells( const SwCursorShell& rShell, sal_uInt16 nDiv,
119 const SwTableSearchType = SwTableSearchType::NONE );
120 bool CheckSplitCells( const SwCursor& rCursor, sal_uInt16 nDiv,
121 const SwTableSearchType = SwTableSearchType::NONE );
123 // For working on tab selection also for split tables.
124 class SwSelUnion
126 SwRect m_aUnion; // The rectangle enclosing the selection.
127 SwTabFrame *m_pTable; // The (Follow-)Table for the Union.
129 public:
130 SwSelUnion( const SwRect &rRect, SwTabFrame *pTab ) :
131 m_aUnion( rRect ), m_pTable( pTab ) {}
133 const SwRect& GetUnion() const { return m_aUnion; }
134 SwRect& GetUnion() { return m_aUnion; }
135 const SwTabFrame *GetTable() const { return m_pTable; }
136 SwTabFrame *GetTable() { return m_pTable; }
139 // Determines tables affected by a table selection and union rectangles
140 // of the selection (also for split tables)
141 typedef std::vector<SwSelUnion> SwSelUnions;
143 // Gets the tables involved in a table selection and the union-rectangles of the selections
144 // - also for split tables.
145 // If a parameter is passed that != SwTableSearchType::NONE
146 // the selection is extended in the given direction.
147 void MakeSelUnions( SwSelUnions&, const SwLayoutFrame *pStart,
148 const SwLayoutFrame *pEnd,
149 const SwTableSearchType = SwTableSearchType::NONE );
151 // These classes copy the current table selections (rBoxes) into a
152 // separate structure while keeping the table structure.
154 class FndBox_;
155 class FndLine_;
157 typedef std::vector<std::unique_ptr<FndBox_>> FndBoxes_t;
158 typedef std::vector<std::unique_ptr<FndLine_>> FndLines_t;
160 class FndBox_
162 SwTableBox* m_pBox;
163 FndLines_t m_Lines;
164 FndLine_* m_pUpper;
166 SwTableLine *m_pLineBefore; // For deleting/restoring the layout.
167 SwTableLine *m_pLineBehind;
169 FndBox_(FndBox_ const&) = delete;
170 FndBox_& operator=(FndBox_ const&) = delete;
172 public:
173 FndBox_( SwTableBox* pB, FndLine_* pFL ) :
174 m_pBox(pB), m_pUpper(pFL), m_pLineBefore( nullptr ), m_pLineBehind( nullptr ) {}
176 const FndLines_t& GetLines() const { return m_Lines; }
177 FndLines_t& GetLines() { return m_Lines; }
178 const SwTableBox* GetBox() const { return m_pBox; }
179 SwTableBox* GetBox() { return m_pBox; }
180 const FndLine_* GetUpper() const { return m_pUpper; }
181 FndLine_* GetUpper() { return m_pUpper; }
183 void SetTableLines( const SwSelBoxes &rBoxes, const SwTable &rTable );
184 void SetTableLines( const SwTable &rTable );
185 //Add an input param to identify if acc table should be disposed
186 void DelFrames ( SwTable &rTable );
187 void MakeFrames( SwTable &rTable );
188 void MakeNewFrames( SwTable &rTable, const sal_uInt16 nNumber,
189 const bool bBehind );
190 bool AreLinesToRestore( const SwTable &rTable ) const;
192 void ClearLineBehind() { m_pLineBehind = nullptr; }
195 class FndLine_
197 SwTableLine* m_pLine;
198 FndBoxes_t m_Boxes;
199 FndBox_* m_pUpper;
201 FndLine_(FndLine_ const&) = delete;
202 FndLine_& operator=(FndLine_ const&) = delete;
204 public:
205 FndLine_(SwTableLine* pL, FndBox_* pFB) : m_pLine(pL), m_pUpper(pFB) {}
206 const FndBoxes_t& GetBoxes() const { return m_Boxes; }
207 FndBoxes_t& GetBoxes() { return m_Boxes; }
208 const SwTableLine* GetLine() const { return m_pLine; }
209 SwTableLine* GetLine() { return m_pLine; }
210 const FndBox_* GetUpper() const { return m_pUpper; }
211 FndBox_* GetUpper() { return m_pUpper; }
213 void SetUpper( FndBox_* pUp ) { m_pUpper = pUp; }
216 struct FndPara
218 const SwSelBoxes& rBoxes;
219 FndLine_* pFndLine;
220 FndBox_* pFndBox;
222 FndPara( const SwSelBoxes& rBxs, FndBox_* pFB )
223 : rBoxes(rBxs), pFndLine(nullptr), pFndBox(pFB) {}
224 FndPara( const FndPara& rPara, FndBox_* pFB )
225 : rBoxes(rPara.rBoxes), pFndLine(rPara.pFndLine), pFndBox(pFB) {}
226 FndPara( const FndPara& rPara, FndLine_* pFL )
227 : rBoxes(rPara.rBoxes), pFndLine(pFL), pFndBox(rPara.pFndBox) {}
230 SW_DLLPUBLIC void ForEach_FndLineCopyCol(SwTableLines& rLines, FndPara* pFndPara );
232 #endif // INCLUDED_SW_INC_TBLSEL_HXX
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */