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 #ifndef SVTOOLS_TABLEGEOMETRY_HXX
28 #define SVTOOLS_TABLEGEOMETRY_HXX
29 
30 #include "svtools/table/tabletypes.hxx"
31 
32 #include <tools/gen.hxx>
33 
34 //........................................................................
35 namespace svt { namespace table
36 {
37 //........................................................................
38 
39     class TableControl_Impl;
40 
41     //====================================================================
42     //= TableGeometry
43     //====================================================================
44     class TableGeometry
45     {
46     protected:
47         const TableControl_Impl&    m_rControl;
48         const Rectangle&            m_rBoundaries;
49         Rectangle                   m_aRect;
50 
51     protected:
52         TableGeometry(
53                 const TableControl_Impl& _rControl,
54                 const Rectangle& _rBoundaries
55             )
56             :m_rControl( _rControl )
57             ,m_rBoundaries( _rBoundaries )
58             ,m_aRect( _rBoundaries )
59         {
60         }
61 
62     public:
63         // attribute access
64         const TableControl_Impl&    getControl() const      { return m_rControl; }
65 
66         // status
67         const Rectangle&    getRect() const { return m_aRect; }
68         bool                isValid() const { return !m_aRect.GetIntersection( m_rBoundaries ).IsEmpty(); }
69     };
70 
71     //====================================================================
72 	//= TableRowGeometry
73 	//====================================================================
74     class TableRowGeometry : public TableGeometry
75     {
76     protected:
77         RowPos  m_nRowPos;
78         bool    m_bAllowVirtualRows;
79 
80     public:
81         TableRowGeometry(
82             TableControl_Impl const & _rControl,
83             Rectangle const & _rBoundaries,
84             RowPos const _nRow,
85             bool const i_allowVirtualRows = false
86                 // allow rows >= getRowCount()?
87         );
88 
89         // status
90         RowPos              getRow() const  { return m_nRowPos; }
91         // operations
92         bool                moveDown();
93 
94     private:
95         void    impl_initRect();
96         bool    impl_isValidRow( RowPos const i_row ) const;
97     };
98 
99     //====================================================================
100 	//= TableColumnGeometry
101 	//====================================================================
102     class TableColumnGeometry : public TableGeometry
103     {
104     protected:
105         ColPos  m_nColPos;
106         bool    m_bAllowVirtualColumns;
107 
108     public:
109         TableColumnGeometry(
110             TableControl_Impl const & _rControl,
111             Rectangle const & _rBoundaries,
112             ColPos const _nCol,
113             bool const i_allowVirtualColumns = false
114         );
115 
116         // status
117         ColPos              getCol() const  { return m_nColPos; }
118         // operations
119         bool                moveRight();
120 
121     private:
122         void    impl_initRect();
123         bool    impl_isValidColumn( ColPos const i_column ) const;
124     };
125 
126     //====================================================================
127 	//= TableCellGeometry
128 	//====================================================================
129     /** a helper representing geometry information of a cell
130     */
131     class TableCellGeometry
132     {
133     private:
134         TableRowGeometry    m_aRow;
135         TableColumnGeometry m_aCol;
136 
137     public:
138         TableCellGeometry(
139                 TableControl_Impl const & _rControl,
140                 Rectangle const & _rBoundaries,
141                 ColPos const _nCol,
142                 RowPos const _nRow,
143                 bool const i_alllowVirtualCells = false
144             )
145             :m_aRow( _rControl, _rBoundaries, _nRow, i_alllowVirtualCells )
146             ,m_aCol( _rControl, _rBoundaries, _nCol, i_alllowVirtualCells )
147         {
148         }
149 
150         TableCellGeometry(
151                 const TableRowGeometry& _rRow,
152                 ColPos _nCol
153             )
154             :m_aRow( _rRow )
155             ,m_aCol( _rRow.getControl(), _rRow.getRect(), _nCol )
156         {
157         }
158 
159         inline  Rectangle   getRect() const     { return m_aRow.getRect().GetIntersection( m_aCol.getRect() ); }
160         inline  RowPos      getRow() const      { return m_aRow.getRow(); }
161         inline  ColPos      getColumn() const   { return m_aCol.getCol(); }
162         inline  bool        isValid() const     { return !getRect().IsEmpty(); }
163 
164         inline  bool        moveDown()      {return m_aRow.moveDown(); }
165         inline  bool        moveRight()     {return m_aCol.moveRight(); }
166     };
167 
168 //........................................................................
169 } } // namespace svt::table
170 //........................................................................
171 
172 #endif // SVTOOLS_TABLEGEOMETRY_HXX
173