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