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 .
19 #ifndef INCLUDED_SW_INC_TBLSEL_HXX
20 #define INCLUDED_SW_INC_TBLSEL_HXX
22 #include "swtable.hxx"
26 #include <o3tl/sorted_vector.hxx>
40 class SwUndoTableMerge
;
43 typedef std::deque
< SwCellFrame
* > SwCellFrames
;
45 struct CompareSwSelBoxes
47 bool operator()(SwTableBox
* const& lhs
, SwTableBox
* const& rhs
) const
49 return lhs
->GetSttIdx() < rhs
->GetSttIdx();
52 class SwSelBoxes
: public o3tl::sorted_vector
<SwTableBox
*, CompareSwSelBoxes
> {};
54 // Collects all boxes in table that are selected.
55 // Selection gets extended in given direction according to enum-parameter.
56 // Boxes are collected via the Layout; works correctly if tables are split.
57 // (Cf. MakeSelUnions().)
58 enum class SwTableSearchType
: sal_uInt16
60 NONE
= 0x01, // No extension.
61 Row
= 0x02, // Extend to rows.
62 Col
= 0x03, // Extend to columns.
64 // As flags to the other values!
65 Protect
= 0x08, // Collect protected boxes too.
66 NoUnionCorrect
= 0x10, // Do not correct collected Union.
69 template<> struct typed_flags
<SwTableSearchType
> : is_typed_flags
<SwTableSearchType
, 0x1b> {};
72 SW_DLLPUBLIC
void GetTableSel( const SwCursorShell
& rShell
, SwSelBoxes
& rBoxes
,
73 const SwTableSearchType
= SwTableSearchType::NONE
);
75 void GetTableSel( const SwCursor
& rCursor
, SwSelBoxes
& rBoxes
,
76 const SwTableSearchType
= SwTableSearchType::NONE
);
78 // As before, but don't start from selection but from Start- EndFrames.
79 void GetTableSel( const SwLayoutFrame
* pStart
, const SwLayoutFrame
* pEnd
,
80 SwSelBoxes
& rBoxes
, SwCellFrames
* pCells
,
81 const SwTableSearchType
= SwTableSearchType::NONE
);
83 // As before but directly via PaMs.
84 void GetTableSelCrs( const SwCursorShell
& rShell
, SwSelBoxes
& rBoxes
);
85 void GetTableSelCrs( const SwTableCursor
& rTableCursor
, SwSelBoxes
& rBoxes
);
87 // Collect boxes relevant for auto sum.
88 bool GetAutoSumSel( const SwCursorShell
&, SwCellFrames
& );
90 // Check if the SelBoxes contains protected Boxes.
91 bool HasProtectedCells( const SwSelBoxes
& rBoxes
);
93 // Check if selection is balanced.
94 bool ChkChartSel( const SwNode
& rSttNd
, const SwNode
& rEndNd
);
96 // Check if cell is part of SSelection.
97 // (Became a function, in order to make sure that GetTableSel() and MakeTableCursor()
98 // have always the same concept of the selection.
99 bool IsFrameInTableSel( const SwRect
& rUnion
, const SwFrame
* pCell
);
101 // Determine boxes to be merged.
102 // In this process the rectangle gets "adapted" on the base of the layout,
103 // i.e. boxes are added if some overlap at the sides.
104 // Additionally a new box is created and filled with the relevant content.
105 void GetMergeSel( const SwPaM
& rPam
, SwSelBoxes
& rBoxes
,
106 SwTableBox
** ppMergeBox
, SwUndoTableMerge
* pUndo
);
108 // Check if selected boxes allow for a valid merge.
109 TableMergeErr
CheckMergeSel( const SwPaM
& rPam
);
110 TableMergeErr
CheckMergeSel( const SwSelBoxes
& rBoxes
);
112 bool IsEmptyBox( const SwTableBox
& rBox
, SwPaM
& rPam
);
114 // Check if Split or InsertCol lead to a box becoming smaller than MINLAY.
115 bool CheckSplitCells( const SwCursorShell
& rShell
, sal_uInt16 nDiv
,
116 const SwTableSearchType
);
117 bool CheckSplitCells( const SwCursor
& rCursor
, sal_uInt16 nDiv
,
118 const SwTableSearchType
);
120 // For working on tab selection also for split tables.
123 SwRect m_aUnion
; // The rectangle enclosing the selection.
124 SwTabFrame
*m_pTable
; // The (Follow-)Table for the Union.
127 SwSelUnion( const SwRect
&rRect
, SwTabFrame
*pTab
) :
128 m_aUnion( rRect
), m_pTable( pTab
) {}
130 const SwRect
& GetUnion() const { return m_aUnion
; }
131 SwRect
& GetUnion() { return m_aUnion
; }
132 const SwTabFrame
*GetTable() const { return m_pTable
; }
133 SwTabFrame
*GetTable() { return m_pTable
; }
136 // Determines tables affected by a table selection and union rectangles
137 // of the selection (also for split tables)
138 typedef std::vector
<SwSelUnion
> SwSelUnions
;
140 // Gets the tables involved in a table selection and the union-rectangles of the selections
141 // - also for split tables.
142 // If a parameter is passed that != SwTableSearchType::NONE
143 // the selection is extended in the given direction.
144 void MakeSelUnions( SwSelUnions
&, const SwLayoutFrame
*pStart
,
145 const SwLayoutFrame
*pEnd
,
146 const SwTableSearchType
= SwTableSearchType::NONE
);
148 // These classes copy the current table selections (rBoxes) into a
149 // separate structure while keeping the table structure.
154 typedef std::vector
<std::unique_ptr
<FndBox_
>> FndBoxes_t
;
155 typedef std::vector
<std::unique_ptr
<FndLine_
>> FndLines_t
;
163 SwTableLine
*m_pLineBefore
; ///< For deleting/restoring the layout.
164 SwTableLine
*m_pLineBehind
; ///< For deleting/restoring the layout.
166 FndBox_(FndBox_
const&) = delete;
167 FndBox_
& operator=(FndBox_
const&) = delete;
170 inline FndBox_( SwTableBox
* pB
, FndLine_
* pFL
);
172 const FndLines_t
& GetLines() const { return m_Lines
; }
173 FndLines_t
& GetLines() { return m_Lines
; }
174 const SwTableBox
* GetBox() const { return m_pBox
; }
175 SwTableBox
* GetBox() { return m_pBox
; }
176 const FndLine_
* GetUpper() const { return m_pUpper
; }
177 FndLine_
* GetUpper() { return m_pUpper
; }
179 void SetTableLines( const SwSelBoxes
&rBoxes
, const SwTable
&rTable
);
180 void SetTableLines( const SwTable
&rTable
);
181 //Add an input param to identify if acc table should be disposed
182 void DelFrames ( SwTable
&rTable
);
183 void MakeFrames( SwTable
&rTable
);
184 void MakeNewFrames( SwTable
&rTable
, const sal_uInt16 nNumber
,
185 const bool bBehind
);
186 bool AreLinesToRestore( const SwTable
&rTable
) const;
188 void ClearLineBehind() { m_pLineBehind
= nullptr; }
193 SwTableLine
* m_pLine
;
197 FndLine_(FndLine_
const&) = delete;
198 FndLine_
& operator=(FndLine_
const&) = delete;
201 FndLine_(SwTableLine
* pL
, FndBox_
* pFB
) : m_pLine(pL
), m_pUpper(pFB
) {}
202 const FndBoxes_t
& GetBoxes() const { return m_Boxes
; }
203 FndBoxes_t
& GetBoxes() { return m_Boxes
; }
204 const SwTableLine
* GetLine() const { return m_pLine
; }
205 SwTableLine
* GetLine() { return m_pLine
; }
206 const FndBox_
* GetUpper() const { return m_pUpper
; }
207 FndBox_
* GetUpper() { return m_pUpper
; }
209 void SetUpper( FndBox_
* pUp
) { m_pUpper
= pUp
; }
212 FndBox_::FndBox_( SwTableBox
* pB
, FndLine_
* pFL
) :
213 m_pBox(pB
), m_pUpper(pFL
), m_pLineBefore( nullptr ), m_pLineBehind( nullptr ) {}
217 const SwSelBoxes
& rBoxes
;
221 FndPara( const SwSelBoxes
& rBxs
, FndBox_
* pFB
)
222 : rBoxes(rBxs
), pFndLine(nullptr), pFndBox(pFB
) {}
223 FndPara( const FndPara
& rPara
, FndBox_
* pFB
)
224 : rBoxes(rPara
.rBoxes
), pFndLine(rPara
.pFndLine
), pFndBox(pFB
) {}
225 FndPara( const FndPara
& rPara
, FndLine_
* pFL
)
226 : rBoxes(rPara
.rBoxes
), pFndLine(pFL
), pFndBox(rPara
.pFndBox
) {}
229 /** This creates a structure mirroring the SwTable structure that contains all
230 rows and non-leaf boxes (as pointers to SwTableBox/SwTableLine, not copies),
231 plus the leaf boxes that are selected by pFndPara->rBoxes
233 SW_DLLPUBLIC
void ForEach_FndLineCopyCol(SwTableLines
& rLines
, FndPara
* pFndPara
);
235 #endif // INCLUDED_SW_INC_TBLSEL_HXX
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */