LibreOffice Module sw (master) 1
tblsel.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#ifndef INCLUDED_SW_INC_TBLSEL_HXX
20#define INCLUDED_SW_INC_TBLSEL_HXX
21
22#include "swtable.hxx"
23#include "swrect.hxx"
24#include "swdllapi.h"
25
27
28#include <memory>
29#include <deque>
30#include <vector>
31
32class SwCursorShell;
33class SwCursor;
34class SwTableCursor;
35class SwFrame;
36class SwTabFrame;
37class SwLayoutFrame;
38class SwPaM;
39class SwNode;
41class SwCellFrame;
42
43typedef std::deque< SwCellFrame* > SwCellFrames;
44
46{
47 bool operator()(SwTableBox* const& lhs, SwTableBox* const& rhs) const
48 {
49 return lhs->GetSttIdx() < rhs->GetSttIdx();
50 }
51};
52class SwSelBoxes : public o3tl::sorted_vector<SwTableBox*, CompareSwSelBoxes> {};
53
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().)
58enum class SwTableSearchType : sal_uInt16
59{
60 NONE = 0x01, // No extension.
61 Row = 0x02, // Extend to rows.
62 Col = 0x03, // Extend to columns.
63
64 // As flags to the other values!
65 Protect = 0x08, // Collect protected boxes too.
66 NoUnionCorrect = 0x10, // Do not correct collected Union.
67};
68namespace o3tl {
69 template<> struct typed_flags<SwTableSearchType> : is_typed_flags<SwTableSearchType, 0x1b> {};
70}
71
72SW_DLLPUBLIC void GetTableSel( const SwCursorShell& rShell, SwSelBoxes& rBoxes,
74
75void GetTableSel( const SwCursor& rCursor, SwSelBoxes& rBoxes,
77
78// As before, but don't start from selection but from Start- EndFrames.
79void GetTableSel( const SwLayoutFrame* pStart, const SwLayoutFrame* pEnd,
80 SwSelBoxes& rBoxes, SwCellFrames* pCells,
82
83// As before but directly via PaMs.
84void GetTableSelCrs( const SwCursorShell& rShell, SwSelBoxes& rBoxes );
85void GetTableSelCrs( const SwTableCursor& rTableCursor, SwSelBoxes& rBoxes );
86
87// Collect boxes relevant for auto sum.
89
90// Check if the SelBoxes contains protected Boxes.
91bool HasProtectedCells( const SwSelBoxes& rBoxes );
92
93// Check if selection is balanced.
94bool ChkChartSel( const SwNode& rSttNd, const SwNode& rEndNd);
95
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.
99bool IsFrameInTableSel( const SwRect& rUnion, const SwFrame* pCell );
100
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.
105void GetMergeSel( const SwPaM& rPam, SwSelBoxes& rBoxes,
106 SwTableBox** ppMergeBox, SwUndoTableMerge* pUndo );
107
108// Check if selected boxes allow for a valid merge.
109TableMergeErr CheckMergeSel( const SwPaM& rPam );
110TableMergeErr CheckMergeSel( const SwSelBoxes& rBoxes );
111
112bool IsEmptyBox( const SwTableBox& rBox, SwPaM& rPam );
113
114// Check if Split or InsertCol lead to a box becoming smaller than MINLAY.
115bool CheckSplitCells( const SwCursorShell& rShell, sal_uInt16 nDiv,
116 const SwTableSearchType );
117bool CheckSplitCells( const SwCursor& rCursor, sal_uInt16 nDiv,
118 const SwTableSearchType );
119
120// For working on tab selection also for split tables.
122{
123 SwRect m_aUnion; // The rectangle enclosing the selection.
124 SwTabFrame *m_pTable; // The (Follow-)Table for the Union.
125
126public:
127 SwSelUnion( const SwRect &rRect, SwTabFrame *pTab ) :
128 m_aUnion( rRect ), m_pTable( pTab ) {}
129
130 const SwRect& GetUnion() const { return m_aUnion; }
131 SwRect& GetUnion() { return m_aUnion; }
132 const SwTabFrame *GetTable() const { return m_pTable; }
134};
135
136// Determines tables affected by a table selection and union rectangles
137// of the selection (also for split tables)
138typedef std::vector<SwSelUnion> SwSelUnions;
139
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.
144void MakeSelUnions( SwSelUnions&, const SwLayoutFrame *pStart,
145 const SwLayoutFrame *pEnd,
147
148// These classes copy the current table selections (rBoxes) into a
149// separate structure while keeping the table structure.
150
151class FndBox_;
152class FndLine_;
153
154typedef std::vector<std::unique_ptr<FndBox_>> FndBoxes_t;
155typedef std::vector<std::unique_ptr<FndLine_>> FndLines_t;
156
158{
162
165
166 FndBox_(FndBox_ const&) = delete;
167 FndBox_& operator=(FndBox_ const&) = delete;
168
169public:
170 inline FndBox_( SwTableBox* pB, FndLine_* pFL );
171
172 const FndLines_t& GetLines() const { 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; }
178
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;
187
188 void ClearLineBehind() { m_pLineBehind = nullptr; }
189};
190
192{
196
197 FndLine_(FndLine_ const&) = delete;
198 FndLine_& operator=(FndLine_ const&) = delete;
199
200public:
201 FndLine_(SwTableLine* pL, FndBox_* pFB) : m_pLine(pL), m_pUpper(pFB) {}
202 const FndBoxes_t& GetBoxes() const { return m_Boxes; }
204 const SwTableLine* GetLine() const { return m_pLine; }
206 const FndBox_* GetUpper() const { return m_pUpper; }
207 FndBox_* GetUpper() { return m_pUpper; }
208
209 void SetUpper( FndBox_* pUp ) { m_pUpper = pUp; }
210};
211
213 m_pBox(pB), m_pUpper(pFL), m_pLineBefore( nullptr ), m_pLineBehind( nullptr ) {}
214
216{
220
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) {}
227};
228
234
235#endif // INCLUDED_SW_INC_TBLSEL_HXX
236
237/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FndBox_ & operator=(FndBox_ const &)=delete
SwTableBox * m_pBox
Definition: tblsel.hxx:159
void SetTableLines(const SwSelBoxes &rBoxes, const SwTable &rTable)
Definition: tblsel.cxx:2096
SwTableBox * GetBox()
Definition: tblsel.hxx:175
const FndLine_ * GetUpper() const
Definition: tblsel.hxx:176
SwTableLine * m_pLineBehind
For deleting/restoring the layout.
Definition: tblsel.hxx:164
const FndLines_t & GetLines() const
Definition: tblsel.hxx:172
FndLine_ * m_pUpper
Definition: tblsel.hxx:161
void ClearLineBehind()
Definition: tblsel.hxx:188
SwTableLine * m_pLineBefore
For deleting/restoring the layout.
Definition: tblsel.hxx:163
void MakeNewFrames(SwTable &rTable, const sal_uInt16 nNumber, const bool bBehind)
Definition: tblsel.cxx:2401
void MakeFrames(SwTable &rTable)
Definition: tblsel.cxx:2319
FndLines_t m_Lines
Definition: tblsel.hxx:160
bool AreLinesToRestore(const SwTable &rTable) const
Definition: tblsel.cxx:2541
void DelFrames(SwTable &rTable)
Definition: tblsel.cxx:2158
FndLines_t & GetLines()
Definition: tblsel.hxx:173
const SwTableBox * GetBox() const
Definition: tblsel.hxx:174
FndLine_ * GetUpper()
Definition: tblsel.hxx:177
FndBox_(FndBox_ const &)=delete
const FndBoxes_t & GetBoxes() const
Definition: tblsel.hxx:202
const SwTableLine * GetLine() const
Definition: tblsel.hxx:204
FndBoxes_t m_Boxes
Definition: tblsel.hxx:194
FndLine_(SwTableLine *pL, FndBox_ *pFB)
Definition: tblsel.hxx:201
FndLine_(FndLine_ const &)=delete
FndLine_ & operator=(FndLine_ const &)=delete
SwTableLine * m_pLine
Definition: tblsel.hxx:193
FndBox_ * m_pUpper
Definition: tblsel.hxx:195
FndBoxes_t & GetBoxes()
Definition: tblsel.hxx:203
const FndBox_ * GetUpper() const
Definition: tblsel.hxx:206
FndBox_ * GetUpper()
Definition: tblsel.hxx:207
SwTableLine * GetLine()
Definition: tblsel.hxx:205
void SetUpper(FndBox_ *pUp)
Definition: tblsel.hxx:209
SwCellFrame is one table cell in the document layout.
Definition: cellfrm.hxx:31
Base class of the Writer layout elements.
Definition: frame.hxx:315
A layout frame is a frame that contains other frames (m_pLower), e.g. SwPageFrame or SwTabFrame.
Definition: layfrm.hxx:36
Base class of the Writer document model elements.
Definition: node.hxx:98
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
SwSelUnion(const SwRect &rRect, SwTabFrame *pTab)
Definition: tblsel.hxx:127
SwRect m_aUnion
Definition: tblsel.hxx:123
const SwRect & GetUnion() const
Definition: tblsel.hxx:130
const SwTabFrame * GetTable() const
Definition: tblsel.hxx:132
SwRect & GetUnion()
Definition: tblsel.hxx:131
SwTabFrame * GetTable()
Definition: tblsel.hxx:133
SwTabFrame * m_pTable
Definition: tblsel.hxx:124
SwTabFrame is one table in the document layout, containing rows (which contain cells).
Definition: tabfrm.hxx:49
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:443
SwNodeOffset GetSttIdx() const
Definition: swtable.cxx:2242
SwTableLine is one table row in the document model.
Definition: swtable.hxx:376
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:113
NONE
bool operator()(SwTableBox *const &lhs, SwTableBox *const &rhs) const
Definition: tblsel.hxx:47
FndPara(const FndPara &rPara, FndBox_ *pFB)
Definition: tblsel.hxx:223
FndPara(const SwSelBoxes &rBxs, FndBox_ *pFB)
Definition: tblsel.hxx:221
const SwSelBoxes & rBoxes
Definition: tblsel.hxx:217
FndBox_ * pFndBox
Definition: tblsel.hxx:219
FndPara(const FndPara &rPara, FndLine_ *pFL)
Definition: tblsel.hxx:225
FndLine_ * pFndLine
Definition: tblsel.hxx:218
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
TableMergeErr
Definition: tblenum.hxx:64
bool GetAutoSumSel(const SwCursorShell &, SwCellFrames &)
Definition: tblsel.cxx:691
void GetMergeSel(const SwPaM &rPam, SwSelBoxes &rBoxes, SwTableBox **ppMergeBox, SwUndoTableMerge *pUndo)
Definition: tblsel.cxx:927
void MakeSelUnions(SwSelUnions &, const SwLayoutFrame *pStart, const SwLayoutFrame *pEnd, const SwTableSearchType=SwTableSearchType::NONE)
Definition: tblsel.cxx:1765
SwTableSearchType
Definition: tblsel.hxx:59
void GetTableSelCrs(const SwCursorShell &rShell, SwSelBoxes &rBoxes)
Definition: tblsel.cxx:124
std::vector< std::unique_ptr< FndLine_ > > FndLines_t
Definition: tblsel.hxx:155
bool CheckSplitCells(const SwCursorShell &rShell, sal_uInt16 nDiv, const SwTableSearchType)
Definition: tblsel.cxx:1949
SW_DLLPUBLIC void GetTableSel(const SwCursorShell &rShell, SwSelBoxes &rBoxes, const SwTableSearchType=SwTableSearchType::NONE)
Definition: tblsel.cxx:149
SW_DLLPUBLIC void ForEach_FndLineCopyCol(SwTableLines &rLines, FndPara *pFndPara)
This creates a structure mirroring the SwTable structure that contains all rows and non-leaf boxes (a...
Definition: tblsel.cxx:2090
TableMergeErr CheckMergeSel(const SwPaM &rPam)
Definition: tblsel.cxx:1446
bool IsEmptyBox(const SwTableBox &rBox, SwPaM &rPam)
Definition: tblsel.cxx:891
bool IsFrameInTableSel(const SwRect &rUnion, const SwFrame *pCell)
Definition: tblsel.cxx:668
std::vector< std::unique_ptr< FndBox_ > > FndBoxes_t
Definition: tblsel.hxx:152
std::deque< SwCellFrame * > SwCellFrames
Definition: tblsel.hxx:41
std::vector< SwSelUnion > SwSelUnions
Definition: tblsel.hxx:138
bool ChkChartSel(const SwNode &rSttNd, const SwNode &rEndNd)
Definition: tblsel.cxx:426
bool HasProtectedCells(const SwSelBoxes &rBoxes)
Definition: tblsel.cxx:854