Bump version to 5.0-14
[LibreOffice.git] / svtools / source / table / tablegeometry.cxx
blob3cb33db0ecb00b31a4c55cb432753aa44ff88b97
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "tablegeometry.hxx"
22 #include "tablecontrol_impl.hxx"
25 namespace svt { namespace table
30 //= TableRowGeometry
33 TableRowGeometry::TableRowGeometry( TableControl_Impl const & _rControl, Rectangle const & _rBoundaries,
34 RowPos const _nRow, bool const i_allowVirtualRows )
35 :TableGeometry( _rControl, _rBoundaries )
36 ,m_nRowPos( _nRow )
37 ,m_bAllowVirtualRows( i_allowVirtualRows )
39 if ( m_nRowPos == ROW_COL_HEADERS )
41 m_aRect.Top() = 0;
42 m_aRect.Bottom() = m_rControl.m_nColHeaderHeightPixel - 1;
44 else
46 impl_initRect();
51 void TableRowGeometry::impl_initRect()
53 if ( ( m_nRowPos >= m_rControl.m_nTopRow ) && impl_isValidRow( m_nRowPos ) )
55 m_aRect.Top() = m_rControl.m_nColHeaderHeightPixel + ( m_nRowPos - m_rControl.m_nTopRow ) * m_rControl.m_nRowHeightPixel;
56 m_aRect.Bottom() = m_aRect.Top() + m_rControl.m_nRowHeightPixel - 1;
58 else
59 m_aRect.SetEmpty();
63 bool TableRowGeometry::impl_isValidRow( RowPos const i_row ) const
65 return m_bAllowVirtualRows || ( i_row < m_rControl.m_pModel->getRowCount() );
69 bool TableRowGeometry::moveDown()
71 if ( m_nRowPos == ROW_COL_HEADERS )
73 m_nRowPos = m_rControl.m_nTopRow;
74 impl_initRect();
76 else
78 if ( impl_isValidRow( ++m_nRowPos ) )
79 m_aRect.Move( 0, m_rControl.m_nRowHeightPixel );
80 else
81 m_aRect.SetEmpty();
83 return isValid();
87 //= TableColumnGeometry
90 TableColumnGeometry::TableColumnGeometry( TableControl_Impl const & _rControl, Rectangle const & _rBoundaries,
91 ColPos const _nCol, bool const i_allowVirtualColumns )
92 :TableGeometry( _rControl, _rBoundaries )
93 ,m_nColPos( _nCol )
94 ,m_bAllowVirtualColumns( i_allowVirtualColumns )
96 if ( m_nColPos == COL_ROW_HEADERS )
98 m_aRect.Left() = 0;
99 m_aRect.Right() = m_rControl.m_nRowHeaderWidthPixel - 1;
101 else
103 impl_initRect();
108 void TableColumnGeometry::impl_initRect()
110 ColPos nLeftColumn = m_rControl.m_nLeftColumn;
111 if ( ( m_nColPos >= nLeftColumn ) && impl_isValidColumn( m_nColPos ) )
113 m_aRect.Left() = m_rControl.m_nRowHeaderWidthPixel;
114 // TODO: take into account any possibly frozen columns
116 for ( ColPos col = nLeftColumn; col < m_nColPos; ++col )
117 m_aRect.Left() += m_rControl.m_aColumnWidths[ col ].getWidth();
118 m_aRect.Right() = m_aRect.Left() + m_rControl.m_aColumnWidths[ m_nColPos ].getWidth() - 1;
120 else
121 m_aRect.SetEmpty();
125 bool TableColumnGeometry::impl_isValidColumn( ColPos const i_column ) const
127 return m_bAllowVirtualColumns || ( i_column < ColPos( m_rControl.m_aColumnWidths.size() ) );
131 bool TableColumnGeometry::moveRight()
133 if ( m_nColPos == COL_ROW_HEADERS )
135 m_nColPos = m_rControl.m_nLeftColumn;
136 impl_initRect();
138 else
140 if ( impl_isValidColumn( ++m_nColPos ) )
142 m_aRect.Left() = m_aRect.Right() + 1;
143 m_aRect.Right() += m_rControl.m_aColumnWidths[ m_nColPos ].getWidth();
145 else
146 m_aRect.SetEmpty();
149 return isValid();
153 } } // namespace svt::table
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */