Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/table/tablelayouter.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
20
#ifndef INCLUDED_SVX_SOURCE_TABLE_TABLELAYOUTER_HXX
21
#define INCLUDED_SVX_SOURCE_TABLE_TABLELAYOUTER_HXX
22
23
#include <sal/types.h>
24
#include <basegfx/range/b2irectangle.hxx>
25
#include <basegfx/tuple/b2ituple.hxx>
26
#include <o3tl/safeint.hxx>
27
#include <vector>
28
29
#include <svx/svdotable.hxx>
30
#include <celltypes.hxx>
31
32
namespace tools { class Rectangle; }
33
34
35
namespace editeng {
36
    class SvxBorderLine;
37
}
38
39
namespace sdr::table {
40
41
/** returns true if the cell(nMergedCol,nMergedRow) is merged with other cells.
42
    the returned cell( rOriginCol, rOriginRow ) is the origin( top left cell ) of the merge.
43
*/
44
bool findMergeOrigin( const TableModelRef& xTable, sal_Int32 nMergedCol, sal_Int32 nMergedRow, sal_Int32& rOriginCol, sal_Int32& rOriginRow );
45
46
typedef std::vector< editeng::SvxBorderLine* > BorderLineVector;
47
typedef std::vector< BorderLineVector > BorderLineMap;
48
49
50
// TableModel
51
52
struct EdgeInfo final
53
{
54
    sal_Int32 nIndex;
55
    sal_Int32 nPosition;
56
    sal_Int32 nMin;
57
    sal_Int32 nMax;
58
59
    EdgeInfo(sal_Int32 nInIndex, sal_Int32 nInPosition, sal_Int32 nInMin, sal_Int32 nInMax)
60
0
        : nIndex(nInIndex)
61
0
        , nPosition(nInPosition)
62
0
        , nMin(nInMin)
63
0
        , nMax(nInMax)
64
0
    {}
65
};
66
67
class TableLayouter final
68
{
69
public:
70
    explicit TableLayouter( TableModelRef xTableModel );
71
    ~TableLayouter();
72
73
    /** try to fit the table into the given rectangle.
74
        If the rectangle is too small, it will be grown to fit the table.
75
76
        if bFitWidth or bFitHeight is set, the layouter tries to scale
77
        the rows and/or columns to the given area. The result my be bigger
78
        to fulfill constrains.
79
80
        if bFitWidth or bFitHeight is set, the model is changed.
81
    */
82
    void LayoutTable( ::tools::Rectangle& rRectangle, bool bFitWidth, bool bFitHeight );
83
84
    void UpdateBorderLayout();
85
86
    bool getCellArea( const CellRef& xCell, const CellPos& rPos, basegfx::B2IRectangle& rArea ) const;
87
88
232
    ::sal_Int32 getRowCount() const { return static_cast< ::sal_Int32 >( maRows.size() ); }
89
232
    ::sal_Int32 getColumnCount() const { return static_cast< ::sal_Int32 >( maColumns.size() ); }
90
    sal_Int32 getRowHeight( sal_Int32 nRow ) const;
91
92
    sal_Int32 getColumnWidth( sal_Int32 nColumn ) const;
93
    sal_Int32 calcPreferredColumnWidth( sal_Int32 nColumn, Size aSize ) const;
94
95
    sal_Int32 getMinimumColumnWidth( sal_Int32 nColumn );
96
97
    /** checks if the given edge is visible.
98
        Edges between merged cells are not visible.
99
    */
100
    bool isEdgeVisible( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal ) const;
101
102
    /** returns the requested borderline in rpBorderLine or a null pointer if there is no border at this edge */
103
    editeng::SvxBorderLine* getBorderLine( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal )const;
104
105
    void updateCells( ::tools::Rectangle const & rRectangle );
106
107
    std::vector<EdgeInfo> getHorizontalEdges();
108
    sal_Int32 getHorizontalEdge( int nEdgeY, sal_Int32* pnMin, sal_Int32* pnMax );
109
110
    std::vector<EdgeInfo> getVerticalEdges();
111
    sal_Int32 getVerticalEdge( int nEdgeX , sal_Int32* pnMin, sal_Int32* pnMax);
112
113
114
    void DistributeColumns( ::tools::Rectangle& rArea,
115
                            sal_Int32 nFirstCol,
116
                            sal_Int32 nLastCol,
117
                            const bool bOptimize,
118
                            const bool bMinimize );
119
    void DistributeRows( ::tools::Rectangle& rArea,
120
                         sal_Int32 nFirstRow,
121
                         sal_Int32 nLastRow,
122
                         const bool bOptimize,
123
                         const bool bMinimize );
124
    void dumpAsXml(xmlTextWriterPtr pWriter) const;
125
126
    void LayoutTableWidth(::tools::Rectangle& rArea, bool bFit);
127
    void LayoutTableHeight(::tools::Rectangle& rArea, bool bFit);
128
129
private:
130
    CellRef getCell( const CellPos& rPos ) const;
131
    basegfx::B2ITuple getCellSize( const CellRef& xCell, const CellPos& rPos ) const;
132
133
0
    bool isValidColumn( sal_Int32 nColumn ) const { return (nColumn >= 0) && (o3tl::make_unsigned(nColumn) < maColumns.size()); }
134
0
    bool isValidRow( sal_Int32 nRow ) const { return (nRow >= 0) && (o3tl::make_unsigned(nRow) < maRows.size()); }
135
0
    bool isValid( const CellPos& rPos ) const { return isValidColumn( rPos.mnCol ) && isValidRow( rPos.mnRow ); }
136
137
    void ClearBorderLayout();
138
    static void ClearBorderLayout(BorderLineMap& rMap);
139
    void ResizeBorderLayout();
140
    void ResizeBorderLayout( BorderLineMap& rMap );
141
142
    void SetBorder( sal_Int32 nCol, sal_Int32 nRow, bool bHorizontal, const editeng::SvxBorderLine* pLine );
143
144
    static bool HasPriority( const editeng::SvxBorderLine* pThis, const editeng::SvxBorderLine* pOther );
145
146
    struct Layout
147
    {
148
        sal_Int32 mnPos;
149
        sal_Int32 mnSize;
150
        sal_Int32 mnMinSize;
151
152
0
        Layout() : mnPos( 0 ), mnSize( 0 ), mnMinSize( 0 ) {}
153
0
        void clear() { mnPos = 0; mnSize = 0; mnMinSize = 0; }
154
        void dumpAsXml(xmlTextWriterPtr pWriter) const;
155
    };
156
    typedef std::vector< Layout > LayoutVector;
157
158
    static sal_Int32 distribute( LayoutVector& rLayouts, sal_Int32 nDistribute );
159
160
    TableModelRef mxTable;
161
    LayoutVector maRows;
162
    LayoutVector maColumns;
163
164
    BorderLineMap maHorizontalBorders;
165
    BorderLineMap maVerticalBorders;
166
};
167
168
}
169
170
#endif
171
172
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */