1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SVX_SOURCE_TABLE_TABLELAYOUTER_HXX
21 #define INCLUDED_SVX_SOURCE_TABLE_TABLELAYOUTER_HXX
23 #include <com/sun/star/container/XIndexAccess.hpp>
24 #include <com/sun/star/text/WritingMode.hpp>
25 #include <com/sun/star/table/XTable.hpp>
26 #include <sal/types.h>
27 #include <basegfx/range/b2irectangle.hxx>
28 #include <basegfx/tuple/b2ituple.hxx>
32 #include <svx/svdotable.hxx>
34 namespace tools
{ class Rectangle
; }
41 namespace sdr
{ namespace table
{
43 /** returns true if the cell(nMergedCol,nMergedRow) is merged with other cells.
44 the returned cell( rOriginCol, rOriginRow ) is the origin( top left cell ) of the merge.
46 bool findMergeOrigin( const TableModelRef
& xTable
, sal_Int32 nMergedCol
, sal_Int32 nMergedRow
, sal_Int32
& rOriginCol
, sal_Int32
& rOriginRow
);
48 typedef std::vector
< editeng::SvxBorderLine
* > BorderLineVector
;
49 typedef std::vector
< BorderLineVector
> BorderLineMap
;
61 EdgeInfo(sal_Int32 nInIndex
, sal_Int32 nInPosition
, sal_Int32 nInMin
, sal_Int32 nInMax
)
63 , nPosition(nInPosition
)
69 class TableLayouter final
72 explicit TableLayouter( const TableModelRef
& xTableModel
);
75 /** try to fit the table into the given rectangle.
76 If the rectangle is too small, it will be grown to fit the table.
78 if bFitWidth or bFitHeight is set, the layouter tries to scale
79 the rows and/or columns to the given area. The result my be bigger
80 to fulfill constrains.
82 if bFitWidth or bFitHeight is set, the model is changed.
84 void LayoutTable( ::tools::Rectangle
& rRectangle
, bool bFitWidth
, bool bFitHeight
);
86 void UpdateBorderLayout();
88 bool getCellArea( const CellRef
& xCell
, const CellPos
& rPos
, basegfx::B2IRectangle
& rArea
) const;
90 ::sal_Int32
getRowCount() const { return static_cast< ::sal_Int32
>( maRows
.size() ); }
91 ::sal_Int32
getColumnCount() const { return static_cast< ::sal_Int32
>( maColumns
.size() ); }
92 sal_Int32
getRowHeight( sal_Int32 nRow
) const;
94 sal_Int32
getColumnWidth( sal_Int32 nColumn
) const;
95 sal_Int32
calcPreferredColumnWidth( sal_Int32 nColumn
, Size aSize
) const;
97 sal_Int32
getMinimumColumnWidth( sal_Int32 nColumn
);
99 /** checks if the given edge is visible.
100 Edges between merged cells are not visible.
102 bool isEdgeVisible( sal_Int32 nEdgeX
, sal_Int32 nEdgeY
, bool bHorizontal
) const;
104 /** returns the requested borderline in rpBorderLine or a null pointer if there is no border at this edge */
105 editeng::SvxBorderLine
* getBorderLine( sal_Int32 nEdgeX
, sal_Int32 nEdgeY
, bool bHorizontal
)const;
107 void updateCells( ::tools::Rectangle
const & rRectangle
);
109 std::vector
<EdgeInfo
> getHorizontalEdges();
110 sal_Int32
getHorizontalEdge( int nEdgeY
, sal_Int32
* pnMin
, sal_Int32
* pnMax
);
112 std::vector
<EdgeInfo
> getVerticalEdges();
113 sal_Int32
getVerticalEdge( int nEdgeX
, sal_Int32
* pnMin
, sal_Int32
* pnMax
);
116 void DistributeColumns( ::tools::Rectangle
& rArea
,
119 const bool bOptimize
,
120 const bool bMinimize
);
121 void DistributeRows( ::tools::Rectangle
& rArea
,
124 const bool bOptimize
,
125 const bool bMinimize
);
126 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
129 CellRef
getCell( const CellPos
& rPos
) const;
130 basegfx::B2ITuple
getCellSize( const CellRef
& xCell
, const CellPos
& rPos
) const;
132 void LayoutTableWidth( ::tools::Rectangle
& rArea
, bool bFit
);
133 void LayoutTableHeight( ::tools::Rectangle
& rArea
, bool bFit
);
135 bool isValidColumn( sal_Int32 nColumn
) const { return (nColumn
>= 0) && (nColumn
< static_cast<sal_Int32
>( maColumns
.size())); }
136 bool isValidRow( sal_Int32 nRow
) const { return (nRow
>= 0) && (nRow
< static_cast<sal_Int32
>( maRows
.size())); }
137 bool isValid( const CellPos
& rPos
) const { return isValidColumn( rPos
.mnCol
) && isValidRow( rPos
.mnRow
); }
139 void ClearBorderLayout();
140 static void ClearBorderLayout(BorderLineMap
& rMap
);
141 void ResizeBorderLayout();
142 void ResizeBorderLayout( BorderLineMap
& rMap
);
144 void SetBorder( sal_Int32 nCol
, sal_Int32 nRow
, bool bHorizontal
, const editeng::SvxBorderLine
* pLine
);
146 static bool HasPriority( const editeng::SvxBorderLine
* pThis
, const editeng::SvxBorderLine
* pOther
);
154 Layout() : mnPos( 0 ), mnSize( 0 ), mnMinSize( 0 ) {}
155 void clear() { mnPos
= 0; mnSize
= 0; mnMinSize
= 0; }
156 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
158 typedef std::vector
< Layout
> LayoutVector
;
160 static sal_Int32
distribute( LayoutVector
& rLayouts
, sal_Int32 nDistribute
);
162 TableModelRef mxTable
;
164 LayoutVector maColumns
;
166 BorderLineMap maHorizontalBorders
;
167 BorderLineMap maVerticalBorders
;
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */