13334a7e6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 33334a7e6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 43334a7e6SAndrew Rist * or more contributor license agreements. See the NOTICE file 53334a7e6SAndrew Rist * distributed with this work for additional information 63334a7e6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 73334a7e6SAndrew Rist * to you under the Apache License, Version 2.0 (the 83334a7e6SAndrew Rist * "License"); you may not use this file except in compliance 93334a7e6SAndrew Rist * with the License. You may obtain a copy of the License at 103334a7e6SAndrew Rist * 113334a7e6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 123334a7e6SAndrew Rist * 133334a7e6SAndrew Rist * Unless required by applicable law or agreed to in writing, 143334a7e6SAndrew Rist * software distributed under the License is distributed on an 153334a7e6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 163334a7e6SAndrew Rist * KIND, either express or implied. See the License for the 173334a7e6SAndrew Rist * specific language governing permissions and limitations 183334a7e6SAndrew Rist * under the License. 193334a7e6SAndrew Rist * 203334a7e6SAndrew Rist *************************************************************/ 213334a7e6SAndrew Rist 223334a7e6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _SVX_TABLE_TABLELAYOUTER_HXX_ 25cdf0e10cSrcweir #define _SVX_TABLE_TABLELAYOUTER_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp> 28cdf0e10cSrcweir #include <com/sun/star/text/WritingMode.hpp> 29cdf0e10cSrcweir #include <com/sun/star/table/XTable.hpp> 30cdf0e10cSrcweir #include <basegfx/range/b2irectangle.hxx> 31cdf0e10cSrcweir #include <basegfx/tuple/b2ituple.hxx> 32cdf0e10cSrcweir #include <tools/gen.hxx> 33cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 34cdf0e10cSrcweir #include <vector> 35cdf0e10cSrcweir #include <map> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include "svx/svdotable.hxx" 38cdf0e10cSrcweir 39cdf0e10cSrcweir // ----------------------------------------------------------------------------- 40cdf0e10cSrcweir 41cdf0e10cSrcweir class SvxBorderLine; 42cdf0e10cSrcweir 43cdf0e10cSrcweir namespace sdr { namespace table { 44cdf0e10cSrcweir 45cdf0e10cSrcweir /** returns true if the cell(nMergedCol,nMergedRow) is merged with other cells. 46cdf0e10cSrcweir the returned cell( rOriginCol, rOriginRow ) is the origin( top left cell ) of the merge. 47cdf0e10cSrcweir */ 48cdf0e10cSrcweir bool findMergeOrigin( const TableModelRef& xTable, sal_Int32 nMergedCol, sal_Int32 nMergedRow, sal_Int32& rOriginCol, sal_Int32& rOriginRow ); 49cdf0e10cSrcweir 50cdf0e10cSrcweir typedef std::vector< SvxBorderLine* > BorderLineVector; 51cdf0e10cSrcweir typedef std::vector< BorderLineVector > BorderLineMap; 52cdf0e10cSrcweir 53cdf0e10cSrcweir // ----------------------------------------------------------------------------- 54cdf0e10cSrcweir // TableModel 55cdf0e10cSrcweir // ----------------------------------------------------------------------------- 56cdf0e10cSrcweir 57cdf0e10cSrcweir class TableLayouter 58cdf0e10cSrcweir { 59cdf0e10cSrcweir public: 60cdf0e10cSrcweir TableLayouter( const TableModelRef& xTableModel ); 61cdf0e10cSrcweir virtual ~TableLayouter(); 62cdf0e10cSrcweir 63cdf0e10cSrcweir /** this checks if new rows are inserted or old rows where removed. 64cdf0e10cSrcweir This can be used to grow or shrink the table shape in this case. 65cdf0e10cSrcweir @returns 66cdf0e10cSrcweir the height difference 67cdf0e10cSrcweir sal_Int32 detectInsertedOrRemovedRows(); 68cdf0e10cSrcweir */ 69cdf0e10cSrcweir 70cdf0e10cSrcweir /** try to fit the table into the given rectangle. 71cdf0e10cSrcweir If the rectangle is to small, it will be grown to fit the table. 72cdf0e10cSrcweir 73cdf0e10cSrcweir if bFitWidth or bFitHeight is set, the layouter tries to scale 74cdf0e10cSrcweir the rows and/or columns to the given area. The result my be bigger 75*86e1cf34SPedro Giffuni to fulfill constrains. 76cdf0e10cSrcweir 77cdf0e10cSrcweir if bFitWidth or bFitHeight is set, the model is changed. 78cdf0e10cSrcweir */ 79cdf0e10cSrcweir void LayoutTable( ::Rectangle& rRectangle, bool bFitWidth, bool bFitHeight ); 80cdf0e10cSrcweir 81cdf0e10cSrcweir /** after a call to LayoutTable, this method can be used to set the new 82cdf0e10cSrcweir column and row sizes back to the model. */ 83cdf0e10cSrcweir // void SetLayoutToModel(); 84cdf0e10cSrcweir 85cdf0e10cSrcweir void UpdateBorderLayout(); 86cdf0e10cSrcweir 87cdf0e10cSrcweir basegfx::B2ITuple getCellSize( const CellPos& rPos ) const; 88cdf0e10cSrcweir bool getCellArea( const CellRef& xCell, basegfx::B2IRectangle& rArea ) const; 89cdf0e10cSrcweir bool getCellArea( const CellPos& rPos, basegfx::B2IRectangle& rArea ) const; 90cdf0e10cSrcweir getRowCount() const91cdf0e10cSrcweir ::sal_Int32 getRowCount() const { return static_cast< ::sal_Int32 >( maRows.size() ); } getColumnCount() const92cdf0e10cSrcweir ::sal_Int32 getColumnCount() const { return static_cast< ::sal_Int32 >( maColumns.size() ); } 93cdf0e10cSrcweir 94cdf0e10cSrcweir sal_Int32 getRowHeight( sal_Int32 nRow ); 95cdf0e10cSrcweir 96cdf0e10cSrcweir // sets the layout height of the given row hard, LayoutTable must be called directly after calling this method! */ 97cdf0e10cSrcweir void setRowHeight( sal_Int32 nRow, sal_Int32 nHeight ); 98cdf0e10cSrcweir 99cdf0e10cSrcweir sal_Int32 getColumnWidth( sal_Int32 nColumn ); 100cdf0e10cSrcweir 101cdf0e10cSrcweir // sets the layout width of the given column hard, LayoutTable must be called directly after calling this method! */ 102cdf0e10cSrcweir void setColumnWidth( sal_Int32 nColumn, sal_Int32 nWidth ); 103cdf0e10cSrcweir 104cdf0e10cSrcweir sal_Int32 getMinimumColumnWidth( sal_Int32 nColumn ); 105cdf0e10cSrcweir 106cdf0e10cSrcweir sal_Int32 getColumnStart( sal_Int32 nColumn ) const; 107cdf0e10cSrcweir sal_Int32 getRowStart( sal_Int32 nRow ) const; 108cdf0e10cSrcweir 109cdf0e10cSrcweir /** checks if the given edge is visible. 110cdf0e10cSrcweir Edges between merged cells are not visible. 111cdf0e10cSrcweir */ 112cdf0e10cSrcweir bool isEdgeVisible( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal ) const; 113cdf0e10cSrcweir 114cdf0e10cSrcweir /** returns the requested borderline in rpBorderLine or a null pointer if there is no border at this edge */ 115cdf0e10cSrcweir SvxBorderLine* getBorderLine( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal )const; 116cdf0e10cSrcweir 117cdf0e10cSrcweir void updateCells( ::Rectangle& rRectangle ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir sal_Int32 getHorizontalEdge( int nEdgeY, sal_Int32* pnMin = 0, sal_Int32* pnMax = 0 ); 120cdf0e10cSrcweir sal_Int32 getVerticalEdge( int nEdgeX , sal_Int32* pnMin = 0, sal_Int32* pnMax = 0); 121cdf0e10cSrcweir 122cdf0e10cSrcweir void DistributeColumns( ::Rectangle& rArea, sal_Int32 nFirstCol, sal_Int32 nLastCol ); 123cdf0e10cSrcweir void DistributeRows( ::Rectangle& rArea, sal_Int32 nFirstRow, sal_Int32 nLastRow ); 124cdf0e10cSrcweir GetWritingMode() const125cdf0e10cSrcweir com::sun::star::text::WritingMode GetWritingMode() const { return meWritingMode; } 126cdf0e10cSrcweir void SetWritingMode( com::sun::star::text::WritingMode eWritingMode ); 127cdf0e10cSrcweir 128cdf0e10cSrcweir private: 129cdf0e10cSrcweir CellRef getCell( const CellPos& rPos ) const; 130cdf0e10cSrcweir 131cdf0e10cSrcweir void LayoutTableWidth( ::Rectangle& rArea, bool bFit ); 132cdf0e10cSrcweir void LayoutTableHeight( ::Rectangle& rArea, bool bFit ); 133cdf0e10cSrcweir isValidColumn(sal_Int32 nColumn) const134cdf0e10cSrcweir inline bool isValidColumn( sal_Int32 nColumn ) const { return (nColumn >= 0) && (nColumn < static_cast<sal_Int32>( maColumns.size())); } isValidRow(sal_Int32 nRow) const135cdf0e10cSrcweir inline bool isValidRow( sal_Int32 nRow ) const { return (nRow >= 0) && (nRow < static_cast<sal_Int32>( maRows.size())); } isValid(const CellPos & rPos) const136cdf0e10cSrcweir inline bool isValid( const CellPos& rPos ) const { return isValidColumn( rPos.mnCol ) && isValidRow( rPos.mnRow ); } 137cdf0e10cSrcweir 138cdf0e10cSrcweir void ClearBorderLayout(); 139cdf0e10cSrcweir void ClearBorderLayout(BorderLineMap& rMap); 140cdf0e10cSrcweir void ResizeBorderLayout(); 141cdf0e10cSrcweir void ResizeBorderLayout( BorderLineMap& rMap ); 142cdf0e10cSrcweir 143cdf0e10cSrcweir void SetBorder( sal_Int32 nCol, sal_Int32 nRow, bool bHorizontal, const SvxBorderLine* pLine ); 144cdf0e10cSrcweir 145cdf0e10cSrcweir static bool HasPriority( const SvxBorderLine* pThis, const SvxBorderLine* pOther ); 146cdf0e10cSrcweir 147cdf0e10cSrcweir struct Layout 148cdf0e10cSrcweir { 149cdf0e10cSrcweir sal_Int32 mnPos; 150cdf0e10cSrcweir sal_Int32 mnSize; 151cdf0e10cSrcweir sal_Int32 mnMinSize; 152cdf0e10cSrcweir Layoutsdr::table::TableLayouter::Layout153cdf0e10cSrcweir Layout() : mnPos( 0 ), mnSize( 0 ), mnMinSize( 0 ) {} clearsdr::table::TableLayouter::Layout154cdf0e10cSrcweir void clear() { mnPos = 0; mnSize = 0; mnMinSize = 0; } 155cdf0e10cSrcweir }; 156cdf0e10cSrcweir typedef std::vector< Layout > LayoutVector; 157cdf0e10cSrcweir 158cdf0e10cSrcweir sal_Int32 distribute( LayoutVector& rLayouts, sal_Int32 nDistribute ); 159cdf0e10cSrcweir 160cdf0e10cSrcweir TableModelRef mxTable; 161cdf0e10cSrcweir LayoutVector maRows; 162cdf0e10cSrcweir LayoutVector maColumns; 163cdf0e10cSrcweir 164cdf0e10cSrcweir BorderLineMap maHorizontalBorders; 165cdf0e10cSrcweir BorderLineMap maVerticalBorders; 166cdf0e10cSrcweir 167cdf0e10cSrcweir com::sun::star::text::WritingMode meWritingMode; 168cdf0e10cSrcweir 169cdf0e10cSrcweir const rtl::OUString msSize; 170cdf0e10cSrcweir }; 171cdf0e10cSrcweir 172cdf0e10cSrcweir } } 173cdf0e10cSrcweir 174cdf0e10cSrcweir #endif 175