Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / table / tablelayouter.hxx
blobef6837b2c6b0ecaef494c159cdf25bba20347a7e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 #include <o3tl/safeint.hxx>
27 #include <vector>
29 #include <svx/svdotable.hxx>
30 #include <celltypes.hxx>
32 namespace tools { class Rectangle; }
35 namespace editeng {
36 class SvxBorderLine;
39 namespace sdr::table {
41 /** returns true if the cell(nMergedCol,nMergedRow) is merged with other cells.
42 the returned cell( rOriginCol, rOriginRow ) is the origin( top left cell ) of the merge.
44 bool findMergeOrigin( const TableModelRef& xTable, sal_Int32 nMergedCol, sal_Int32 nMergedRow, sal_Int32& rOriginCol, sal_Int32& rOriginRow );
46 typedef std::vector< editeng::SvxBorderLine* > BorderLineVector;
47 typedef std::vector< BorderLineVector > BorderLineMap;
50 // TableModel
52 struct EdgeInfo final
54 sal_Int32 nIndex;
55 sal_Int32 nPosition;
56 sal_Int32 nMin;
57 sal_Int32 nMax;
59 EdgeInfo(sal_Int32 nInIndex, sal_Int32 nInPosition, sal_Int32 nInMin, sal_Int32 nInMax)
60 : nIndex(nInIndex)
61 , nPosition(nInPosition)
62 , nMin(nInMin)
63 , nMax(nInMax)
67 class TableLayouter final
69 public:
70 explicit TableLayouter( TableModelRef xTableModel );
71 ~TableLayouter();
73 /** try to fit the table into the given rectangle.
74 If the rectangle is too small, it will be grown to fit the table.
76 if bFitWidth or bFitHeight is set, the layouter tries to scale
77 the rows and/or columns to the given area. The result my be bigger
78 to fulfill constrains.
80 if bFitWidth or bFitHeight is set, the model is changed.
82 void LayoutTable( ::tools::Rectangle& rRectangle, bool bFitWidth, bool bFitHeight );
84 void UpdateBorderLayout();
86 bool getCellArea( const CellRef& xCell, const CellPos& rPos, basegfx::B2IRectangle& rArea ) const;
88 ::sal_Int32 getRowCount() const { return static_cast< ::sal_Int32 >( maRows.size() ); }
89 ::sal_Int32 getColumnCount() const { return static_cast< ::sal_Int32 >( maColumns.size() ); }
90 sal_Int32 getRowHeight( sal_Int32 nRow ) const;
92 sal_Int32 getColumnWidth( sal_Int32 nColumn ) const;
93 sal_Int32 calcPreferredColumnWidth( sal_Int32 nColumn, Size aSize ) const;
95 sal_Int32 getMinimumColumnWidth( sal_Int32 nColumn );
97 /** checks if the given edge is visible.
98 Edges between merged cells are not visible.
100 bool isEdgeVisible( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal ) const;
102 /** returns the requested borderline in rpBorderLine or a null pointer if there is no border at this edge */
103 editeng::SvxBorderLine* getBorderLine( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal )const;
105 void updateCells( ::tools::Rectangle const & rRectangle );
107 std::vector<EdgeInfo> getHorizontalEdges();
108 sal_Int32 getHorizontalEdge( int nEdgeY, sal_Int32* pnMin, sal_Int32* pnMax );
110 std::vector<EdgeInfo> getVerticalEdges();
111 sal_Int32 getVerticalEdge( int nEdgeX , sal_Int32* pnMin, sal_Int32* pnMax);
114 void DistributeColumns( ::tools::Rectangle& rArea,
115 sal_Int32 nFirstCol,
116 sal_Int32 nLastCol,
117 const bool bOptimize,
118 const bool bMinimize );
119 void DistributeRows( ::tools::Rectangle& rArea,
120 sal_Int32 nFirstRow,
121 sal_Int32 nLastRow,
122 const bool bOptimize,
123 const bool bMinimize );
124 void dumpAsXml(xmlTextWriterPtr pWriter) const;
126 void LayoutTableWidth(::tools::Rectangle& rArea, bool bFit);
127 void LayoutTableHeight(::tools::Rectangle& rArea, bool bFit);
129 private:
130 CellRef getCell( const CellPos& rPos ) const;
131 basegfx::B2ITuple getCellSize( const CellRef& xCell, const CellPos& rPos ) const;
133 bool isValidColumn( sal_Int32 nColumn ) const { return (nColumn >= 0) && (o3tl::make_unsigned(nColumn) < maColumns.size()); }
134 bool isValidRow( sal_Int32 nRow ) const { return (nRow >= 0) && (o3tl::make_unsigned(nRow) < maRows.size()); }
135 bool isValid( const CellPos& rPos ) const { return isValidColumn( rPos.mnCol ) && isValidRow( rPos.mnRow ); }
137 void ClearBorderLayout();
138 static void ClearBorderLayout(BorderLineMap& rMap);
139 void ResizeBorderLayout();
140 void ResizeBorderLayout( BorderLineMap& rMap );
142 void SetBorder( sal_Int32 nCol, sal_Int32 nRow, bool bHorizontal, const editeng::SvxBorderLine* pLine );
144 static bool HasPriority( const editeng::SvxBorderLine* pThis, const editeng::SvxBorderLine* pOther );
146 struct Layout
148 sal_Int32 mnPos;
149 sal_Int32 mnSize;
150 sal_Int32 mnMinSize;
152 Layout() : mnPos( 0 ), mnSize( 0 ), mnMinSize( 0 ) {}
153 void clear() { mnPos = 0; mnSize = 0; mnMinSize = 0; }
154 void dumpAsXml(xmlTextWriterPtr pWriter) const;
156 typedef std::vector< Layout > LayoutVector;
158 static sal_Int32 distribute( LayoutVector& rLayouts, sal_Int32 nDistribute );
160 TableModelRef mxTable;
161 LayoutVector maRows;
162 LayoutVector maColumns;
164 BorderLineMap maHorizontalBorders;
165 BorderLineMap maVerticalBorders;
170 #endif
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */