Update ooo320-m1
[ooovba.git] / svtools / source / table / tablegeometry.cxx
blob1b7edd63777ae7aee324edb585fefeb06b4a5420
1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * Copyright 2009 by Sun Microsystems, Inc.
6 * OpenOffice.org - a multi-platform office productivity suite
8 * This file is part of OpenOffice.org.
10 * OpenOffice.org is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License version 3
12 * only, as published by the Free Software Foundation.
14 * OpenOffice.org is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License version 3 for more details
18 * (a copy is included in the LICENSE file that accompanied this code).
20 * You should have received a copy of the GNU Lesser General Public License
21 * version 3 along with OpenOffice.org. If not, see
22 * <http://www.openoffice.org/license.html>
23 * for a copy of the LGPLv3 License.
24 ************************************************************************/
26 // MARKER(update_precomp.py): autogen include statement, do not remove
27 #include "precompiled_svtools.hxx"
30 #include "tablegeometry.hxx"
31 #include "tablecontrol_impl.hxx"
33 #include <tools/debug.hxx>
35 //........................................................................
36 namespace svt { namespace table
38 //........................................................................
40 //====================================================================
41 //= TableRowGeometry
42 //====================================================================
43 //--------------------------------------------------------------------
44 TableRowGeometry::TableRowGeometry( const TableControl_Impl& _rControl, const Rectangle& _rBoundaries,
45 RowPos _nRow )
46 :TableGeometry( _rControl, _rBoundaries )
47 ,m_nRowPos( _nRow )
49 if ( m_nRowPos == ROW_COL_HEADERS )
51 DBG_ASSERT( m_rControl.m_pModel->hasColumnHeaders(),
52 "TableRowGeometry::TableRowGeometry: why asking for the geoemtry of the non-existent column header row?" );
53 m_aRect.Top() = 0;
54 m_aRect.Bottom() = m_rControl.m_nColHeaderHeightPixel - 1;
56 else
58 if ( ( m_nRowPos >= m_rControl.m_nTopRow ) && ( m_nRowPos < m_rControl.m_pModel->getRowCount() ) )
60 m_aRect.Top() = m_rControl.m_nColHeaderHeightPixel + ( m_nRowPos - m_rControl.m_nTopRow ) * m_rControl.m_nRowHeightPixel;
61 m_aRect.Bottom() = m_aRect.Top() + m_rControl.m_nRowHeightPixel - 1;
63 else
64 m_aRect.SetEmpty();
68 //--------------------------------------------------------------------
69 bool TableRowGeometry::moveDown()
71 if ( ++m_nRowPos < m_rControl.m_pModel->getRowCount() )
72 m_aRect.Move( 0, m_rControl.m_nRowHeightPixel );
73 else
74 m_aRect.SetEmpty();
75 return isValid();
78 //====================================================================
79 //= TableColumnGeometry
80 //====================================================================
81 //--------------------------------------------------------------------
82 TableColumnGeometry::TableColumnGeometry( const TableControl_Impl& _rControl, const Rectangle& _rBoundaries,
83 ColPos _nCol )
84 :TableGeometry( _rControl, _rBoundaries )
85 ,m_nColPos( _nCol )
87 if ( m_nColPos == COL_ROW_HEADERS )
89 DBG_ASSERT( m_rControl.m_pModel->hasRowHeaders(),
90 "TableColumnGeometry::TableColumnGeometry: why asking for the geoemtry of the non-existent row header column?" );
91 m_aRect.Left() = 0;
92 m_aRect.Right() = m_rControl.m_nRowHeaderWidthPixel - 1;
94 else
96 ColPos nLeftColumn = m_rControl.m_nLeftColumn;
97 if ( ( m_nColPos >= nLeftColumn ) && ( m_nColPos < (ColPos)m_rControl.m_aColumnWidthsPixel.size() ) )
99 m_aRect.Left() = m_rControl.m_nRowHeaderWidthPixel;
100 // TODO: take into account any possibly frozen columns
102 for ( ColPos col = nLeftColumn; col < m_nColPos; ++col )
103 m_aRect.Left() += m_rControl.m_aColumnWidthsPixel[ col ];
104 m_aRect.Right() = m_aRect.Left() + m_rControl.m_aColumnWidthsPixel[ m_nColPos ] - 1;
106 else
107 m_aRect.SetEmpty();
111 //--------------------------------------------------------------------
112 bool TableColumnGeometry::moveRight()
114 DBG_ASSERT( m_nColPos != COL_ROW_HEADERS, "TableColumnGeometry::moveRight: cannot move the row header column!" );
115 // what would be COL_ROW_HEADERS + 1?
117 if ( ++m_nColPos < (ColPos)m_rControl.m_aColumnWidthsPixel.size() )
119 m_aRect.Left() = m_aRect.Right() + 1;
120 m_aRect.Right() += m_rControl.m_aColumnWidthsPixel[ m_nColPos ];
122 else
123 m_aRect.SetEmpty();
125 return isValid();
128 //........................................................................
129 } } // namespace svt::table
130 //........................................................................