Coverage Report

Created: 2025-12-08 09:28

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