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 <sal/types.h>
24 #include <basegfx/range/b2irectangle.hxx>
25 #include <basegfx/tuple/b2ituple.hxx>
28 #include <svx/svdotable.hxx>
29 #include <celltypes.hxx>
31 namespace tools
{ class Rectangle
; }
38 namespace sdr::table
{
40 /** returns true if the cell(nMergedCol,nMergedRow) is merged with other cells.
41 the returned cell( rOriginCol, rOriginRow ) is the origin( top left cell ) of the merge.
43 bool findMergeOrigin( const TableModelRef
& xTable
, sal_Int32 nMergedCol
, sal_Int32 nMergedRow
, sal_Int32
& rOriginCol
, sal_Int32
& rOriginRow
);
45 typedef std::vector
< editeng::SvxBorderLine
* > BorderLineVector
;
46 typedef std::vector
< BorderLineVector
> BorderLineMap
;
58 EdgeInfo(sal_Int32 nInIndex
, sal_Int32 nInPosition
, sal_Int32 nInMin
, sal_Int32 nInMax
)
60 , nPosition(nInPosition
)
66 class TableLayouter final
69 explicit TableLayouter( const TableModelRef
& xTableModel
);
72 /** try to fit the table into the given rectangle.
73 If the rectangle is too small, it will be grown to fit the table.
75 if bFitWidth or bFitHeight is set, the layouter tries to scale
76 the rows and/or columns to the given area. The result my be bigger
77 to fulfill constrains.
79 if bFitWidth or bFitHeight is set, the model is changed.
81 void LayoutTable( ::tools::Rectangle
& rRectangle
, bool bFitWidth
, bool bFitHeight
);
83 void UpdateBorderLayout();
85 bool getCellArea( const CellRef
& xCell
, const CellPos
& rPos
, basegfx::B2IRectangle
& rArea
) const;
87 ::sal_Int32
getRowCount() const { return static_cast< ::sal_Int32
>( maRows
.size() ); }
88 ::sal_Int32
getColumnCount() const { return static_cast< ::sal_Int32
>( maColumns
.size() ); }
89 sal_Int32
getRowHeight( sal_Int32 nRow
) const;
91 sal_Int32
getColumnWidth( sal_Int32 nColumn
) const;
92 sal_Int32
calcPreferredColumnWidth( sal_Int32 nColumn
, Size aSize
) const;
94 sal_Int32
getMinimumColumnWidth( sal_Int32 nColumn
);
96 /** checks if the given edge is visible.
97 Edges between merged cells are not visible.
99 bool isEdgeVisible( sal_Int32 nEdgeX
, sal_Int32 nEdgeY
, bool bHorizontal
) const;
101 /** returns the requested borderline in rpBorderLine or a null pointer if there is no border at this edge */
102 editeng::SvxBorderLine
* getBorderLine( sal_Int32 nEdgeX
, sal_Int32 nEdgeY
, bool bHorizontal
)const;
104 void updateCells( ::tools::Rectangle
const & rRectangle
);
106 std::vector
<EdgeInfo
> getHorizontalEdges();
107 sal_Int32
getHorizontalEdge( int nEdgeY
, sal_Int32
* pnMin
, sal_Int32
* pnMax
);
109 std::vector
<EdgeInfo
> getVerticalEdges();
110 sal_Int32
getVerticalEdge( int nEdgeX
, sal_Int32
* pnMin
, sal_Int32
* pnMax
);
113 void DistributeColumns( ::tools::Rectangle
& rArea
,
116 const bool bOptimize
,
117 const bool bMinimize
);
118 void DistributeRows( ::tools::Rectangle
& rArea
,
121 const bool bOptimize
,
122 const bool bMinimize
);
123 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
126 CellRef
getCell( const CellPos
& rPos
) const;
127 basegfx::B2ITuple
getCellSize( const CellRef
& xCell
, const CellPos
& rPos
) const;
129 void LayoutTableWidth( ::tools::Rectangle
& rArea
, bool bFit
);
130 void LayoutTableHeight( ::tools::Rectangle
& rArea
, bool bFit
);
132 bool isValidColumn( sal_Int32 nColumn
) const { return (nColumn
>= 0) && (nColumn
< static_cast<sal_Int32
>( maColumns
.size())); }
133 bool isValidRow( sal_Int32 nRow
) const { return (nRow
>= 0) && (nRow
< static_cast<sal_Int32
>( maRows
.size())); }
134 bool isValid( const CellPos
& rPos
) const { return isValidColumn( rPos
.mnCol
) && isValidRow( rPos
.mnRow
); }
136 void ClearBorderLayout();
137 static void ClearBorderLayout(BorderLineMap
& rMap
);
138 void ResizeBorderLayout();
139 void ResizeBorderLayout( BorderLineMap
& rMap
);
141 void SetBorder( sal_Int32 nCol
, sal_Int32 nRow
, bool bHorizontal
, const editeng::SvxBorderLine
* pLine
);
143 static bool HasPriority( const editeng::SvxBorderLine
* pThis
, const editeng::SvxBorderLine
* pOther
);
151 Layout() : mnPos( 0 ), mnSize( 0 ), mnMinSize( 0 ) {}
152 void clear() { mnPos
= 0; mnSize
= 0; mnMinSize
= 0; }
153 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
155 typedef std::vector
< Layout
> LayoutVector
;
157 static sal_Int32
distribute( LayoutVector
& rLayouts
, sal_Int32 nDistribute
);
159 TableModelRef mxTable
;
161 LayoutVector maColumns
;
163 BorderLineMap maHorizontalBorders
;
164 BorderLineMap maVerticalBorders
;
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */