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 
26 #include <o3tl/sorted_vector.hxx>
27 
28 #include <memory>
29 #include <deque>
30 #include <vector>
31 
32 class SwCursorShell;
33 class SwCursor;
34 class SwTableCursor;
35 class SwFrame;
36 class SwTabFrame;
37 class SwLayoutFrame;
38 class SwPaM;
39 class SwNode;
40 class SwUndoTableMerge;
42 
43 typedef 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 };
52 class 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().)
58 enum 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 };
68 namespace o3tl {
69  template<> struct typed_flags<SwTableSearchType> : is_typed_flags<SwTableSearchType, 0x1f> {};
70 }
71 
72 SW_DLLPUBLIC void GetTableSel( const SwCursorShell& rShell, SwSelBoxes& rBoxes,
74 
75 void GetTableSel( const SwCursor& rCursor, SwSelBoxes& rBoxes,
77 
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,
82 
83 // As before but directly via PaMs.
84 void GetTableSelCrs( const SwCursorShell& rShell, SwSelBoxes& rBoxes );
85 void GetTableSelCrs( const SwTableCursor& rTableCursor, SwSelBoxes& rBoxes );
86 
87 // Collect boxes relevant for auto sum.
89 
90 // Check if the SelBoxes contains protected Boxes.
91 bool HasProtectedCells( const SwSelBoxes& rBoxes );
92 
93 // Check if selection is balanced.
94 bool 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.
99 bool 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.
105 void GetMergeSel( const SwPaM& rPam, SwSelBoxes& rBoxes,
106  SwTableBox** ppMergeBox, SwUndoTableMerge* pUndo );
107 
108 // Check if selected boxes allow for a valid merge.
109 TableMergeErr CheckMergeSel( const SwPaM& rPam );
110 TableMergeErr CheckMergeSel( const SwSelBoxes& rBoxes );
111 
112 bool IsEmptyBox( const SwTableBox& rBox, SwPaM& rPam );
113 
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 );
119 
120 // For working on tab selection also for split tables.
122 {
123  SwRect m_aUnion; // The rectangle enclosing the selection.
124  SwTabFrame * const m_pTable; // The (Follow-)Table for the Union.
125 
126 public:
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; }
133  SwTabFrame *GetTable() { return m_pTable; }
134 };
135 
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;
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.
144 void 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 
151 class FndBox_;
152 class FndLine_;
153 
154 typedef std::vector<std::unique_ptr<FndBox_>> FndBoxes_t;
155 typedef std::vector<std::unique_ptr<FndLine_>> FndLines_t;
156 
157 class FndBox_
158 {
162 
163  SwTableLine *m_pLineBefore; // For deleting/restoring the layout.
165 
166  FndBox_(FndBox_ const&) = delete;
167  FndBox_& operator=(FndBox_ const&) = delete;
168 
169 public:
170  FndBox_( SwTableBox* pB, FndLine_* pFL ) :
171  m_pBox(pB), m_pUpper(pFL), m_pLineBefore( nullptr ), m_pLineBehind( nullptr ) {}
172 
173  const FndLines_t& GetLines() const { return m_Lines; }
174  FndLines_t& GetLines() { return m_Lines; }
175  const SwTableBox* GetBox() const { return m_pBox; }
176  SwTableBox* GetBox() { return m_pBox; }
177  const FndLine_* GetUpper() const { return m_pUpper; }
178  FndLine_* GetUpper() { return m_pUpper; }
179 
180  void SetTableLines( const SwSelBoxes &rBoxes, const SwTable &rTable );
181  void SetTableLines( const SwTable &rTable );
182  //Add an input param to identify if acc table should be disposed
183  void DelFrames ( SwTable &rTable );
184  void MakeFrames( SwTable &rTable );
185  void MakeNewFrames( SwTable &rTable, const sal_uInt16 nNumber,
186  const bool bBehind );
187  bool AreLinesToRestore( const SwTable &rTable ) const;
188 
189  void ClearLineBehind() { m_pLineBehind = nullptr; }
190 };
191 
192 class FndLine_
193 {
197 
198  FndLine_(FndLine_ const&) = delete;
199  FndLine_& operator=(FndLine_ const&) = delete;
200 
201 public:
202  FndLine_(SwTableLine* pL, FndBox_* pFB) : m_pLine(pL), m_pUpper(pFB) {}
203  const FndBoxes_t& GetBoxes() const { return m_Boxes; }
204  FndBoxes_t& GetBoxes() { return m_Boxes; }
205  const SwTableLine* GetLine() const { return m_pLine; }
206  SwTableLine* GetLine() { return m_pLine; }
207  const FndBox_* GetUpper() const { return m_pUpper; }
208  FndBox_* GetUpper() { return m_pUpper; }
209 
210  void SetUpper( FndBox_* pUp ) { m_pUpper = pUp; }
211 };
212 
213 struct FndPara
214 {
218 
219  FndPara( const SwSelBoxes& rBxs, FndBox_* pFB )
220  : rBoxes(rBxs), pFndLine(nullptr), pFndBox(pFB) {}
221  FndPara( const FndPara& rPara, FndBox_* pFB )
222  : rBoxes(rPara.rBoxes), pFndLine(rPara.pFndLine), pFndBox(pFB) {}
223  FndPara( const FndPara& rPara, FndLine_* pFL )
224  : rBoxes(rPara.rBoxes), pFndLine(pFL), pFndBox(rPara.pFndBox) {}
225 };
226 
227 SW_DLLPUBLIC void ForEach_FndLineCopyCol(SwTableLines& rLines, FndPara* pFndPara );
228 
229 #endif // INCLUDED_SW_INC_TBLSEL_HXX
230 
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FndLine_ *const m_pUpper
Definition: tblsel.hxx:161
Base class of the Writer layout elements.
Definition: frame.hxx:295
const FndLines_t & GetLines() const
Definition: tblsel.hxx:173
FndBox_(SwTableBox *pB, FndLine_ *pFL)
Definition: tblsel.hxx:170
FndLines_t & GetLines()
Definition: tblsel.hxx:174
const SwTableLine * GetLine() const
Definition: tblsel.hxx:205
TableMergeErr CheckMergeSel(const SwPaM &rPam)
Definition: tblsel.cxx:1440
const SwSelBoxes & rBoxes
Definition: tblsel.hxx:215
FndBoxes_t & GetBoxes()
Definition: tblsel.hxx:204
SwRect & GetUnion()
Definition: tblsel.hxx:131
SwRect m_aUnion
Definition: tblsel.hxx:123
bool ChkChartSel(const SwNode &rSttNd, const SwNode &rEndNd)
Definition: tblsel.cxx:422
sal_uLong GetSttIdx() const
Definition: swtable.cxx:1880
bool IsFrameInTableSel(const SwRect &rUnion, const SwFrame *pCell)
Definition: tblsel.cxx:663
bool CheckSplitCells(const SwCursorShell &rShell, sal_uInt16 nDiv, const SwTableSearchType)
Definition: tblsel.cxx:1951
FndLine_(SwTableLine *pL, FndBox_ *pFB)
Definition: tblsel.hxx:202
SwTableBox *const m_pBox
Definition: tblsel.hxx:159
bool AreLinesToRestore(const SwTable &rTable) const
Definition: tblsel.cxx:2534
SwTabFrame is one table in the document layout, containing rows (which contain cells).
Definition: tabfrm.hxx:30
SwTableBox * GetBox()
Definition: tblsel.hxx:176
void DelFrames(SwTable &rTable)
Definition: tblsel.cxx:2160
SwTabFrame * GetTable()
Definition: tblsel.hxx:133
SwTableLine is one table row in the document model.
Definition: swtable.hxx:344
FndBox_ * m_pUpper
Definition: tblsel.hxx:196
void GetTableSelCrs(const SwCursorShell &rShell, SwSelBoxes &rBoxes)
Definition: tblsel.cxx:119
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
void GetMergeSel(const SwPaM &rPam, SwSelBoxes &rBoxes, SwTableBox **ppMergeBox, SwUndoTableMerge *pUndo)
Definition: tblsel.cxx:917
FndPara(const FndPara &rPara, FndLine_ *pFL)
Definition: tblsel.hxx:223
std::deque< SwCellFrame * > SwCellFrames
Definition: tblsel.hxx:41
TableMergeErr
Definition: tblenum.hxx:62
FndPara(const SwSelBoxes &rBxs, FndBox_ *pFB)
Definition: tblsel.hxx:219
void SetUpper(FndBox_ *pUp)
Definition: tblsel.hxx:210
SW_DLLPUBLIC void GetTableSel(const SwCursorShell &rShell, SwSelBoxes &rBoxes, const SwTableSearchType=SwTableSearchType::NONE)
Definition: tblsel.cxx:144
FndLine_(FndLine_ const &)=delete
FndLine_ * GetUpper()
Definition: tblsel.hxx:178
bool IsEmptyBox(const SwTableBox &rBox, SwPaM &rPam)
Definition: tblsel.cxx:881
const FndBoxes_t & GetBoxes() const
Definition: tblsel.hxx:203
FndBox_(FndBox_ const &)=delete
const FndBox_ * GetUpper() const
Definition: tblsel.hxx:207
void MakeFrames(SwTable &rTable)
Definition: tblsel.cxx:2321
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
SwTableSearchType
Definition: tblsel.hxx:58
SwTableLine * m_pLineBehind
Definition: tblsel.hxx:164
void SetTableLines(const SwSelBoxes &rBoxes, const SwTable &rTable)
Definition: tblsel.cxx:2098
const SwRect & GetUnion() const
Definition: tblsel.hxx:130
void ClearLineBehind()
Definition: tblsel.hxx:189
SwTabFrame *const m_pTable
Definition: tblsel.hxx:124
const SwTabFrame * GetTable() const
Definition: tblsel.hxx:132
FndBox_ & operator=(FndBox_ const &)=delete
bool HasProtectedCells(const SwSelBoxes &rBoxes)
Definition: tblsel.cxx:844
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:110
FndBox_ * GetUpper()
Definition: tblsel.hxx:208
SwTableLine * m_pLineBefore
Definition: tblsel.hxx:163
FndBoxes_t m_Boxes
Definition: tblsel.hxx:195
FndLine_ & operator=(FndLine_ const &)=delete
void MakeNewFrames(SwTable &rTable, const sal_uInt16 nNumber, const bool bBehind)
Definition: tblsel.cxx:2394
std::vector< std::unique_ptr< FndBox_ > > FndBoxes_t
Definition: tblsel.hxx:152
FndBox_ * pFndBox
Definition: tblsel.hxx:217
bool operator()(SwTableBox *const &lhs, SwTableBox *const &rhs) const
Definition: tblsel.hxx:47
std::vector< SwSelUnion > SwSelUnions
Definition: tblsel.hxx:138
const SwTableBox * GetBox() const
Definition: tblsel.hxx:175
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
void MakeSelUnions(SwSelUnions &, const SwLayoutFrame *pStart, const SwLayoutFrame *pEnd, const SwTableSearchType=SwTableSearchType::NONE)
Definition: tblsel.cxx:1759
FndLines_t m_Lines
Definition: tblsel.hxx:160
bool GetAutoSumSel(const SwCursorShell &, SwCellFrames &)
Definition: tblsel.cxx:686
FndPara(const FndPara &rPara, FndBox_ *pFB)
Definition: tblsel.hxx:221
std::vector< std::unique_ptr< FndLine_ > > FndLines_t
Definition: tblsel.hxx:155
SwTableLine * GetLine()
Definition: tblsel.hxx:206
SW_DLLPUBLIC void ForEach_FndLineCopyCol(SwTableLines &rLines, FndPara *pFndPara)
Definition: tblsel.cxx:2092
const FndLine_ * GetUpper() const
Definition: tblsel.hxx:177
FndLine_ * pFndLine
Definition: tblsel.hxx:216
SwSelUnion(const SwRect &rRect, SwTabFrame *pTab)
Definition: tblsel.hxx:127
SwCellFrame is one table cell in the document layout.
Definition: cellfrm.hxx:30
SwTableLine *const m_pLine
Definition: tblsel.hxx:194
Base class of the Writer document model elements.
Definition: node.hxx:79