1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tablelayouter.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _SVX_TABLE_TABLELAYOUTER_HXX_
32 #define _SVX_TABLE_TABLELAYOUTER_HXX_
34 #include <com/sun/star/container/XIndexAccess.hpp>
35 #include <com/sun/star/text/WritingMode.hpp>
36 #include <com/sun/star/table/XTable.hpp>
37 #include <basegfx/range/b2irectangle.hxx>
38 #include <basegfx/tuple/b2ituple.hxx>
39 #include <tools/gen.hxx>
40 #include <boost/shared_ptr.hpp>
44 #include "svx/svdotable.hxx"
46 // -----------------------------------------------------------------------------
50 namespace sdr
{ namespace table
{
52 /** returns true if the cell(nMergedCol,nMergedRow) is merged with other cells.
53 the returned cell( rOriginCol, rOriginRow ) is the origin( top left cell ) of the merge.
55 bool findMergeOrigin( const TableModelRef
& xTable
, sal_Int32 nMergedCol
, sal_Int32 nMergedRow
, sal_Int32
& rOriginCol
, sal_Int32
& rOriginRow
);
57 typedef std::vector
< SvxBorderLine
* > BorderLineVector
;
58 typedef std::vector
< BorderLineVector
> BorderLineMap
;
60 // -----------------------------------------------------------------------------
62 // -----------------------------------------------------------------------------
67 TableLayouter( const TableModelRef
& xTableModel
);
68 virtual ~TableLayouter();
70 /** this checks if new rows are inserted or old rows where removed.
71 This can be used to grow or shrink the table shape in this case.
74 sal_Int32 detectInsertedOrRemovedRows();
77 /** try to fit the table into the given rectangle.
78 If the rectangle is to small, it will be grown to fit the table.
80 if bFitWidth or bFitHeight is set, the layouter tries to scale
81 the rows and/or columns to the given area. The result my be bigger
82 to fullfill constrains.
84 if bFitWidth or bFitHeight is set, the model is changed.
86 void LayoutTable( ::Rectangle
& rRectangle
, bool bFitWidth
, bool bFitHeight
);
88 /** after a call to LayoutTable, this method can be used to set the new
89 column and row sizes back to the model. */
90 // void SetLayoutToModel();
92 void UpdateBorderLayout();
94 basegfx::B2ITuple
getCellSize( const CellPos
& rPos
) const;
95 bool getCellArea( const CellRef
& xCell
, basegfx::B2IRectangle
& rArea
) const;
96 bool getCellArea( const CellPos
& rPos
, basegfx::B2IRectangle
& rArea
) const;
98 ::sal_Int32
getRowCount() const { return static_cast< ::sal_Int32
>( maRows
.size() ); }
99 ::sal_Int32
getColumnCount() const { return static_cast< ::sal_Int32
>( maColumns
.size() ); }
101 sal_Int32
getRowHeight( sal_Int32 nRow
);
103 // sets the layout height of the given row hard, LayoutTable must be called directly after calling this method! */
104 void setRowHeight( sal_Int32 nRow
, sal_Int32 nHeight
);
106 sal_Int32
getColumnWidth( sal_Int32 nColumn
);
108 // sets the layout width of the given column hard, LayoutTable must be called directly after calling this method! */
109 void setColumnWidth( sal_Int32 nColumn
, sal_Int32 nWidth
);
111 sal_Int32
getMinimumColumnWidth( sal_Int32 nColumn
);
113 sal_Int32
getColumnStart( sal_Int32 nColumn
) const;
114 sal_Int32
getRowStart( sal_Int32 nRow
) const;
116 /** checks if the given edge is visible.
117 Edges between merged cells are not visible.
119 bool isEdgeVisible( sal_Int32 nEdgeX
, sal_Int32 nEdgeY
, bool bHorizontal
) const;
121 /** returns the requested borderline in rpBorderLine or a null pointer if there is no border at this edge */
122 SvxBorderLine
* getBorderLine( sal_Int32 nEdgeX
, sal_Int32 nEdgeY
, bool bHorizontal
)const;
124 void updateCells( ::Rectangle
& rRectangle
);
126 sal_Int32
getHorizontalEdge( int nEdgeY
, sal_Int32
* pnMin
= 0, sal_Int32
* pnMax
= 0 );
127 sal_Int32
getVerticalEdge( int nEdgeX
, sal_Int32
* pnMin
= 0, sal_Int32
* pnMax
= 0);
129 void DistributeColumns( ::Rectangle
& rArea
, sal_Int32 nFirstCol
, sal_Int32 nLastCol
);
130 void DistributeRows( ::Rectangle
& rArea
, sal_Int32 nFirstRow
, sal_Int32 nLastRow
);
132 com::sun::star::text::WritingMode
GetWritingMode() const { return meWritingMode
; }
133 void SetWritingMode( com::sun::star::text::WritingMode eWritingMode
);
136 CellRef
getCell( const CellPos
& rPos
) const;
138 void LayoutTableWidth( ::Rectangle
& rArea
, bool bFit
);
139 void LayoutTableHeight( ::Rectangle
& rArea
, bool bFit
);
141 inline bool isValidColumn( sal_Int32 nColumn
) const { return (nColumn
>= 0) && (nColumn
< static_cast<sal_Int32
>( maColumns
.size())); }
142 inline bool isValidRow( sal_Int32 nRow
) const { return (nRow
>= 0) && (nRow
< static_cast<sal_Int32
>( maRows
.size())); }
143 inline bool isValid( const CellPos
& rPos
) const { return isValidColumn( rPos
.mnCol
) && isValidRow( rPos
.mnRow
); }
145 void ClearBorderLayout();
146 void ClearBorderLayout(BorderLineMap
& rMap
);
147 void ResizeBorderLayout();
148 void ResizeBorderLayout( BorderLineMap
& rMap
);
150 void SetBorder( sal_Int32 nCol
, sal_Int32 nRow
, bool bHorizontal
, const SvxBorderLine
* pLine
);
152 static bool HasPriority( const SvxBorderLine
* pThis
, const SvxBorderLine
* pOther
);
160 Layout() : mnPos( 0 ), mnSize( 0 ), mnMinSize( 0 ) {}
161 void clear() { mnPos
= 0; mnSize
= 0; mnMinSize
= 0; }
163 typedef std::vector
< Layout
> LayoutVector
;
165 sal_Int32
distribute( LayoutVector
& rLayouts
, sal_Int32 nDistribute
);
167 TableModelRef mxTable
;
169 LayoutVector maColumns
;
171 BorderLineMap maHorizontalBorders
;
172 BorderLineMap maVerticalBorders
;
174 com::sun::star::text::WritingMode meWritingMode
;
176 const rtl::OUString msSize
;