Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/toolkit/source/controls/table/tablegeometry.cxx
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
#include "tablegeometry.hxx"
21
22
#include <controls/table/TableControl.hxx>
23
24
namespace svt::table
25
{
26
27
28
    //= TableRowGeometry
29
30
31
    TableRowGeometry::TableRowGeometry( TableControl const & _rControl, tools::Rectangle const & _rBoundaries,
32
            sal_Int32 const _nRow, bool const i_allowVirtualRows )
33
0
        :TableGeometry( _rControl, _rBoundaries )
34
0
        ,m_nRowPos( _nRow )
35
0
        ,m_bAllowVirtualRows( i_allowVirtualRows )
36
0
    {
37
0
        if ( m_nRowPos == ROW_COL_HEADERS )
38
0
        {
39
0
            m_aRect.SetTop( 0 );
40
0
            m_aRect.SetBottom( m_rControl.m_nColHeaderHeightPixel - 1 );
41
0
        }
42
0
        else
43
0
        {
44
0
            impl_initRect();
45
0
        }
46
0
    }
47
48
49
    void TableRowGeometry::impl_initRect()
50
0
    {
51
0
        if ( ( m_nRowPos >= m_rControl.m_nTopRow ) && impl_isValidRow( m_nRowPos ) )
52
0
        {
53
0
            m_aRect.SetTop( m_rControl.m_nColHeaderHeightPixel + ( m_nRowPos - m_rControl.m_nTopRow ) * m_rControl.m_nRowHeightPixel );
54
0
            m_aRect.SetBottom( m_aRect.Top() + m_rControl.m_nRowHeightPixel - 1 );
55
0
        }
56
0
        else
57
0
            m_aRect.SetEmpty();
58
0
    }
59
60
    bool TableRowGeometry::impl_isValidRow(sal_Int32 const i_row) const
61
0
    {
62
0
        return m_bAllowVirtualRows || ( i_row < m_rControl.m_pModel->getRowCount() );
63
0
    }
64
65
66
    bool TableRowGeometry::moveDown()
67
0
    {
68
0
        if ( m_nRowPos == ROW_COL_HEADERS )
69
0
        {
70
0
            m_nRowPos = m_rControl.m_nTopRow;
71
0
            impl_initRect();
72
0
        }
73
0
        else
74
0
        {
75
0
            if ( impl_isValidRow( ++m_nRowPos ) )
76
0
                m_aRect.Move( 0, m_rControl.m_nRowHeightPixel );
77
0
            else
78
0
                m_aRect.SetEmpty();
79
0
        }
80
0
        return isValid();
81
0
    }
82
83
84
    //= TableColumnGeometry
85
86
87
    TableColumnGeometry::TableColumnGeometry( TableControl const & _rControl, tools::Rectangle const & _rBoundaries,
88
            sal_Int32 const _nCol )
89
0
        :TableGeometry( _rControl, _rBoundaries )
90
0
        ,m_nColPos( _nCol )
91
0
    {
92
0
        if ( m_nColPos == COL_ROW_HEADERS )
93
0
        {
94
0
            m_aRect.SetLeft( 0 );
95
0
            m_aRect.SetRight( m_rControl.m_nRowHeaderWidthPixel - 1 );
96
0
        }
97
0
        else
98
0
        {
99
0
            impl_initRect();
100
0
        }
101
0
    }
102
103
104
    void TableColumnGeometry::impl_initRect()
105
0
    {
106
0
        sal_Int32 nLeftColumn = m_rControl.m_nLeftColumn;
107
0
        if ( ( m_nColPos >= nLeftColumn ) && impl_isValidColumn( m_nColPos ) )
108
0
        {
109
0
            m_aRect.SetLeft( m_rControl.m_nRowHeaderWidthPixel );
110
            // TODO: take into account any possibly frozen columns
111
112
0
            for (sal_Int32 col = nLeftColumn; col < m_nColPos; ++col)
113
0
                m_aRect.AdjustLeft(m_rControl.m_aColumnWidths[ col ].getWidth() );
114
0
            m_aRect.SetRight( m_aRect.Left() + m_rControl.m_aColumnWidths[ m_nColPos ].getWidth() - 1 );
115
0
        }
116
0
        else
117
0
            m_aRect.SetEmpty();
118
0
    }
119
120
    bool TableColumnGeometry::impl_isValidColumn(sal_Int32 const i_column) const
121
0
    {
122
0
        return i_column < sal_Int32(m_rControl.m_aColumnWidths.size());
123
0
    }
124
125
126
    bool TableColumnGeometry::moveRight()
127
0
    {
128
0
        if ( m_nColPos == COL_ROW_HEADERS )
129
0
        {
130
0
            m_nColPos = m_rControl.m_nLeftColumn;
131
0
            impl_initRect();
132
0
        }
133
0
        else
134
0
        {
135
0
            if ( impl_isValidColumn( ++m_nColPos ) )
136
0
            {
137
0
                m_aRect.SetLeft( m_aRect.Right() + 1 );
138
0
                m_aRect.AdjustRight(m_rControl.m_aColumnWidths[ m_nColPos ].getWidth() );
139
0
            }
140
0
            else
141
0
                m_aRect.SetEmpty();
142
0
        }
143
144
0
        return isValid();
145
0
    }
146
147
148
} // namespace svt::table
149
150
151
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */