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