1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svtools.hxx" 26 27 #include "tablegeometry.hxx" 28 #include "tablecontrol_impl.hxx" 29 30 #include <tools/debug.hxx> 31 32 //...................................................................................................................... 33 namespace svt { namespace table 34 { 35 //...................................................................................................................... 36 37 //================================================================================================================== 38 //= TableRowGeometry 39 //================================================================================================================== 40 //------------------------------------------------------------------------------------------------------------------ TableRowGeometry(TableControl_Impl const & _rControl,Rectangle const & _rBoundaries,RowPos const _nRow,bool const i_allowVirtualRows)41 TableRowGeometry::TableRowGeometry( TableControl_Impl const & _rControl, Rectangle const & _rBoundaries, 42 RowPos const _nRow, bool const i_allowVirtualRows ) 43 :TableGeometry( _rControl, _rBoundaries ) 44 ,m_nRowPos( _nRow ) 45 ,m_bAllowVirtualRows( i_allowVirtualRows ) 46 { 47 if ( m_nRowPos == ROW_COL_HEADERS ) 48 { 49 m_aRect.Top() = 0; 50 m_aRect.Bottom() = m_rControl.m_nColHeaderHeightPixel - 1; 51 } 52 else 53 { 54 impl_initRect(); 55 } 56 } 57 58 //------------------------------------------------------------------------------------------------------------------ impl_initRect()59 void TableRowGeometry::impl_initRect() 60 { 61 if ( ( m_nRowPos >= m_rControl.m_nTopRow ) && impl_isValidRow( m_nRowPos ) ) 62 { 63 m_aRect.Top() = m_rControl.m_nColHeaderHeightPixel + ( m_nRowPos - m_rControl.m_nTopRow ) * m_rControl.m_nRowHeightPixel; 64 m_aRect.Bottom() = m_aRect.Top() + m_rControl.m_nRowHeightPixel - 1; 65 } 66 else 67 m_aRect.SetEmpty(); 68 } 69 70 //------------------------------------------------------------------------------------------------------------------ impl_isValidRow(RowPos const i_row) const71 bool TableRowGeometry::impl_isValidRow( RowPos const i_row ) const 72 { 73 return m_bAllowVirtualRows || ( i_row < m_rControl.m_pModel->getRowCount() ); 74 } 75 76 //------------------------------------------------------------------------------------------------------------------ moveDown()77 bool TableRowGeometry::moveDown() 78 { 79 if ( m_nRowPos == ROW_COL_HEADERS ) 80 { 81 m_nRowPos = m_rControl.m_nTopRow; 82 impl_initRect(); 83 } 84 else 85 { 86 if ( impl_isValidRow( ++m_nRowPos ) ) 87 m_aRect.Move( 0, m_rControl.m_nRowHeightPixel ); 88 else 89 m_aRect.SetEmpty(); 90 } 91 return isValid(); 92 } 93 94 //================================================================================================================== 95 //= TableColumnGeometry 96 //================================================================================================================== 97 //------------------------------------------------------------------------------------------------------------------ TableColumnGeometry(TableControl_Impl const & _rControl,Rectangle const & _rBoundaries,ColPos const _nCol,bool const i_allowVirtualColumns)98 TableColumnGeometry::TableColumnGeometry( TableControl_Impl const & _rControl, Rectangle const & _rBoundaries, 99 ColPos const _nCol, bool const i_allowVirtualColumns ) 100 :TableGeometry( _rControl, _rBoundaries ) 101 ,m_nColPos( _nCol ) 102 ,m_bAllowVirtualColumns( i_allowVirtualColumns ) 103 { 104 if ( m_nColPos == COL_ROW_HEADERS ) 105 { 106 m_aRect.Left() = 0; 107 m_aRect.Right() = m_rControl.m_nRowHeaderWidthPixel - 1; 108 } 109 else 110 { 111 impl_initRect(); 112 } 113 } 114 115 //------------------------------------------------------------------------------------------------------------------ impl_initRect()116 void TableColumnGeometry::impl_initRect() 117 { 118 ColPos nLeftColumn = m_rControl.m_nLeftColumn; 119 if ( ( m_nColPos >= nLeftColumn ) && impl_isValidColumn( m_nColPos ) ) 120 { 121 m_aRect.Left() = m_rControl.m_nRowHeaderWidthPixel; 122 // TODO: take into account any possibly frozen columns 123 124 for ( ColPos col = nLeftColumn; col < m_nColPos; ++col ) 125 m_aRect.Left() += m_rControl.m_aColumnWidths[ col ].getWidth(); 126 m_aRect.Right() = m_aRect.Left() + m_rControl.m_aColumnWidths[ m_nColPos ].getWidth() - 1; 127 } 128 else 129 m_aRect.SetEmpty(); 130 } 131 132 //------------------------------------------------------------------------------------------------------------------ impl_isValidColumn(ColPos const i_column) const133 bool TableColumnGeometry::impl_isValidColumn( ColPos const i_column ) const 134 { 135 return m_bAllowVirtualColumns || ( i_column < ColPos( m_rControl.m_aColumnWidths.size() ) ); 136 } 137 138 //------------------------------------------------------------------------------------------------------------------ moveRight()139 bool TableColumnGeometry::moveRight() 140 { 141 if ( m_nColPos == COL_ROW_HEADERS ) 142 { 143 m_nColPos = m_rControl.m_nLeftColumn; 144 impl_initRect(); 145 } 146 else 147 { 148 if ( impl_isValidColumn( ++m_nColPos ) ) 149 { 150 m_aRect.Left() = m_aRect.Right() + 1; 151 m_aRect.Right() += m_rControl.m_aColumnWidths[ m_nColPos ].getWidth(); 152 } 153 else 154 m_aRect.SetEmpty(); 155 } 156 157 return isValid(); 158 } 159 160 //...................................................................................................................... 161 } } // namespace svt::table 162 //...................................................................................................................... 163