1 /*************************************************************************
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3  *
4  * Copyright 2000, 2010 Oracle and/or its affiliates.
5  *
6  * OpenOffice.org - a multi-platform office productivity suite
7  *
8  * This file is part of OpenOffice.org.
9  *
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.
13  *
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).
19  *
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  *
25 ************************************************************************/
26 
27 // MARKER(update_precomp.py): autogen include statement, do not remove
28 #include "precompiled_svtools.hxx"
29 
30 #include "tablegeometry.hxx"
31 #include "tablecontrol_impl.hxx"
32 
33 #include <tools/debug.hxx>
34 
35 //......................................................................................................................
36 namespace svt { namespace table
37 {
38 //......................................................................................................................
39 
40     //==================================================================================================================
41 	//= TableRowGeometry
42 	//==================================================================================================================
43 	//------------------------------------------------------------------------------------------------------------------
44     TableRowGeometry::TableRowGeometry( TableControl_Impl const & _rControl, Rectangle const & _rBoundaries,
45             RowPos const _nRow, bool const i_allowVirtualRows )
46         :TableGeometry( _rControl, _rBoundaries )
47         ,m_nRowPos( _nRow )
48         ,m_bAllowVirtualRows( i_allowVirtualRows )
49     {
50         if ( m_nRowPos == ROW_COL_HEADERS )
51         {
52             m_aRect.Top() = 0;
53             m_aRect.Bottom() = m_rControl.m_nColHeaderHeightPixel - 1;
54         }
55         else
56         {
57             impl_initRect();
58         }
59     }
60 
61 	//------------------------------------------------------------------------------------------------------------------
62     void TableRowGeometry::impl_initRect()
63     {
64         if ( ( m_nRowPos >= m_rControl.m_nTopRow ) && impl_isValidRow( m_nRowPos ) )
65         {
66             m_aRect.Top() = m_rControl.m_nColHeaderHeightPixel + ( m_nRowPos - m_rControl.m_nTopRow ) * m_rControl.m_nRowHeightPixel;
67             m_aRect.Bottom() = m_aRect.Top() + m_rControl.m_nRowHeightPixel - 1;
68         }
69         else
70             m_aRect.SetEmpty();
71     }
72 
73 	//------------------------------------------------------------------------------------------------------------------
74     bool TableRowGeometry::impl_isValidRow( RowPos const i_row ) const
75     {
76         return m_bAllowVirtualRows || ( i_row < m_rControl.m_pModel->getRowCount() );
77     }
78 
79     //------------------------------------------------------------------------------------------------------------------
80     bool TableRowGeometry::moveDown()
81     {
82         if ( m_nRowPos == ROW_COL_HEADERS )
83         {
84             m_nRowPos = m_rControl.m_nTopRow;
85             impl_initRect();
86         }
87         else
88         {
89             if ( impl_isValidRow( ++m_nRowPos ) )
90                 m_aRect.Move( 0, m_rControl.m_nRowHeightPixel );
91             else
92                 m_aRect.SetEmpty();
93         }
94         return isValid();
95     }
96 
97     //==================================================================================================================
98     //= TableColumnGeometry
99     //==================================================================================================================
100     //------------------------------------------------------------------------------------------------------------------
101     TableColumnGeometry::TableColumnGeometry( TableControl_Impl const & _rControl, Rectangle const & _rBoundaries,
102             ColPos const _nCol, bool const i_allowVirtualColumns )
103         :TableGeometry( _rControl, _rBoundaries )
104         ,m_nColPos( _nCol )
105         ,m_bAllowVirtualColumns( i_allowVirtualColumns )
106     {
107         if ( m_nColPos == COL_ROW_HEADERS )
108         {
109             m_aRect.Left() = 0;
110             m_aRect.Right() = m_rControl.m_nRowHeaderWidthPixel - 1;
111         }
112         else
113         {
114             impl_initRect();
115         }
116     }
117 
118     //------------------------------------------------------------------------------------------------------------------
119     void TableColumnGeometry::impl_initRect()
120     {
121         ColPos nLeftColumn = m_rControl.m_nLeftColumn;
122         if ( ( m_nColPos >= nLeftColumn ) && impl_isValidColumn( m_nColPos ) )
123         {
124             m_aRect.Left() = m_rControl.m_nRowHeaderWidthPixel;
125             // TODO: take into account any possibly frozen columns
126 
127             for ( ColPos col = nLeftColumn; col < m_nColPos; ++col )
128                 m_aRect.Left() += m_rControl.m_aColumnWidths[ col ].getWidth();
129             m_aRect.Right() = m_aRect.Left() + m_rControl.m_aColumnWidths[ m_nColPos ].getWidth() - 1;
130         }
131         else
132             m_aRect.SetEmpty();
133     }
134 
135     //------------------------------------------------------------------------------------------------------------------
136     bool TableColumnGeometry::impl_isValidColumn( ColPos const i_column ) const
137     {
138         return m_bAllowVirtualColumns || ( i_column < ColPos( m_rControl.m_aColumnWidths.size() ) );
139     }
140 
141     //------------------------------------------------------------------------------------------------------------------
142     bool TableColumnGeometry::moveRight()
143     {
144         if ( m_nColPos == COL_ROW_HEADERS )
145         {
146             m_nColPos = m_rControl.m_nLeftColumn;
147             impl_initRect();
148         }
149         else
150         {
151             if ( impl_isValidColumn( ++m_nColPos ) )
152             {
153                 m_aRect.Left() = m_aRect.Right() + 1;
154                 m_aRect.Right() += m_rControl.m_aColumnWidths[ m_nColPos ].getWidth();
155             }
156             else
157                 m_aRect.SetEmpty();
158         }
159 
160         return isValid();
161     }
162 
163 //......................................................................................................................
164 } } // namespace svt::table
165 //......................................................................................................................
166