Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/inc/tblsel.hxx
Line
Count
Source
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;
41
class SwCellFrame;
42
43
typedef std::deque< SwCellFrame* > SwCellFrames;
44
45
struct CompareSwSelBoxes
46
{
47
    bool operator()(const SwTableBox* const& lhs, const SwTableBox* const& rhs) const
48
1.14k
    {
49
1.14k
        return lhs->GetSttIdx() < rhs->GetSttIdx();
50
1.14k
    }
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, 0x1b> {};
70
}
71
72
SW_DLLPUBLIC void GetTableSel( const SwCursorShell& rShell, SwSelBoxes& rBoxes,
73
                const SwTableSearchType = SwTableSearchType::NONE );
74
75
void GetTableSel( const SwCursor& rCursor, SwSelBoxes& rBoxes,
76
                const SwTableSearchType = SwTableSearchType::NONE );
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,
81
                const SwTableSearchType = SwTableSearchType::NONE );
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.
88
bool GetAutoSumSel( const SwCursorShell&, SwCellFrames& );
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.
121
class SwSelUnion
122
{
123
    SwRect   m_aUnion;        // The rectangle enclosing the selection.
124
    SwTabFrame *m_pTable;       // The (Follow-)Table for the Union.
125
126
public:
127
    SwSelUnion( const SwRect &rRect, SwTabFrame *pTab ) :
128
0
        m_aUnion( rRect ), m_pTable( pTab ) {}
129
130
0
    const SwRect&   GetUnion() const { return m_aUnion; }
131
0
          SwRect&   GetUnion()       { return m_aUnion; }
132
0
    const SwTabFrame *GetTable() const { return m_pTable; }
133
0
          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,
146
                    const SwTableSearchType = SwTableSearchType::NONE );
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
{
159
    SwTableBox* m_pBox;
160
    FndLines_t m_Lines;
161
    FndLine_* m_pUpper;
162
163
    SwTableLine *m_pLineBefore; ///< For deleting/restoring the layout.
164
    SwTableLine *m_pLineBehind; ///< For deleting/restoring the layout.
165
166
    FndBox_(FndBox_ const&) = delete;
167
    FndBox_& operator=(FndBox_ const&) = delete;
168
169
public:
170
    inline FndBox_( SwTableBox* pB, FndLine_* pFL );
171
172
0
    const FndLines_t&   GetLines() const    { return m_Lines; }
173
120
        FndLines_t&     GetLines()          { return m_Lines; }
174
0
    const SwTableBox*   GetBox() const      { return m_pBox; }
175
72
        SwTableBox*     GetBox()            { return m_pBox; }
176
0
    const FndLine_*     GetUpper() const    { return m_pUpper; }
177
0
        FndLine_*       GetUpper()          { 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
0
    void ClearLineBehind() { m_pLineBehind = nullptr; }
189
};
190
191
class FndLine_
192
{
193
    SwTableLine* m_pLine;
194
    FndBoxes_t m_Boxes;
195
    FndBox_* m_pUpper;
196
197
    FndLine_(FndLine_ const&) = delete;
198
    FndLine_& operator=(FndLine_ const&) = delete;
199
200
public:
201
144
    FndLine_(SwTableLine* pL, FndBox_* pFB) : m_pLine(pL), m_pUpper(pFB) {}
202
0
    const FndBoxes_t&   GetBoxes() const    { return m_Boxes; }
203
192
        FndBoxes_t&     GetBoxes()          { return m_Boxes; }
204
0
    const SwTableLine*  GetLine() const     { return m_pLine; }
205
144
        SwTableLine*    GetLine()           { return m_pLine; }
206
0
    const FndBox_*      GetUpper() const    { return m_pUpper; }
207
0
        FndBox_*        GetUpper()          { return m_pUpper; }
208
209
0
    void SetUpper( FndBox_* pUp ) { m_pUpper = pUp; }
210
};
211
212
FndBox_::FndBox_( SwTableBox* pB, FndLine_* pFL ) :
213
324
    m_pBox(pB), m_pUpper(pFL), m_pLineBefore( nullptr ), m_pLineBehind( nullptr ) {}
214
215
struct FndPara
216
{
217
    const SwSelBoxes& rBoxes;
218
    FndLine_* pFndLine;
219
    FndBox_* pFndBox;
220
221
    FndPara( const SwSelBoxes& rBxs, FndBox_* pFB )
222
24
        : rBoxes(rBxs), pFndLine(nullptr), pFndBox(pFB) {}
223
    FndPara( const FndPara& rPara, FndBox_* pFB )
224
0
        : rBoxes(rPara.rBoxes), pFndLine(rPara.pFndLine), pFndBox(pFB) {}
225
    FndPara( const FndPara& rPara, FndLine_* pFL )
226
144
        : rBoxes(rPara.rBoxes), pFndLine(pFL), pFndBox(rPara.pFndBox) {}
227
};
228
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
232
 */
233
SW_DLLPUBLIC void ForEach_FndLineCopyCol(SwTableLines& rLines, FndPara* pFndPara );
234
235
#endif // INCLUDED_SW_INC_TBLSEL_HXX
236
237
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */