LibreOffice Module svx (master) 1
tablelayouter.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_SVX_SOURCE_TABLE_TABLELAYOUTER_HXX
21#define INCLUDED_SVX_SOURCE_TABLE_TABLELAYOUTER_HXX
22
23#include <sal/types.h>
26#include <o3tl/safeint.hxx>
27#include <vector>
28
29#include <svx/svdotable.hxx>
30#include <celltypes.hxx>
31
32namespace tools { class Rectangle; }
33
34
35namespace editeng {
36 class SvxBorderLine;
37}
38
39namespace sdr::table {
40
44bool findMergeOrigin( const TableModelRef& xTable, sal_Int32 nMergedCol, sal_Int32 nMergedRow, sal_Int32& rOriginCol, sal_Int32& rOriginRow );
45
46typedef std::vector< editeng::SvxBorderLine* > BorderLineVector;
47typedef std::vector< BorderLineVector > BorderLineMap;
48
49
50// TableModel
51
52struct EdgeInfo final
53{
54 sal_Int32 nIndex;
55 sal_Int32 nPosition;
56 sal_Int32 nMin;
57 sal_Int32 nMax;
58
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)
64 {}
65};
66
67class TableLayouter final
68{
69public:
70 explicit TableLayouter( TableModelRef xTableModel );
72
82 void LayoutTable( ::tools::Rectangle& rRectangle, bool bFitWidth, bool bFitHeight );
83
84 void UpdateBorderLayout();
85
86 bool getCellArea( const CellRef& xCell, const CellPos& rPos, basegfx::B2IRectangle& rArea ) const;
87
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;
91
92 sal_Int32 getColumnWidth( sal_Int32 nColumn ) const;
93 sal_Int32 calcPreferredColumnWidth( sal_Int32 nColumn, Size aSize ) const;
94
95 sal_Int32 getMinimumColumnWidth( sal_Int32 nColumn );
96
100 bool isEdgeVisible( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal ) const;
101
103 editeng::SvxBorderLine* getBorderLine( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal )const;
104
105 void updateCells( ::tools::Rectangle const & rRectangle );
106
107 std::vector<EdgeInfo> getHorizontalEdges();
108 sal_Int32 getHorizontalEdge( int nEdgeY, sal_Int32* pnMin, sal_Int32* pnMax );
109
110 std::vector<EdgeInfo> getVerticalEdges();
111 sal_Int32 getVerticalEdge( int nEdgeX , sal_Int32* pnMin, sal_Int32* pnMax);
112
113
115 sal_Int32 nFirstCol,
116 sal_Int32 nLastCol,
117 const bool bOptimize,
118 const bool bMinimize );
120 sal_Int32 nFirstRow,
121 sal_Int32 nLastRow,
122 const bool bOptimize,
123 const bool bMinimize );
124 void dumpAsXml(xmlTextWriterPtr pWriter) const;
125
126 void LayoutTableWidth(::tools::Rectangle& rArea, bool bFit);
127 void LayoutTableHeight(::tools::Rectangle& rArea, bool bFit);
128
129private:
130 CellRef getCell( const CellPos& rPos ) const;
131 basegfx::B2ITuple getCellSize( const CellRef& xCell, const CellPos& rPos ) const;
132
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 ); }
136
137 void ClearBorderLayout();
138 static void ClearBorderLayout(BorderLineMap& rMap);
139 void ResizeBorderLayout();
140 void ResizeBorderLayout( BorderLineMap& rMap );
141
142 void SetBorder( sal_Int32 nCol, sal_Int32 nRow, bool bHorizontal, const editeng::SvxBorderLine* pLine );
143
144 static bool HasPriority( const editeng::SvxBorderLine* pThis, const editeng::SvxBorderLine* pOther );
145
146 struct Layout
147 {
148 sal_Int32 mnPos;
149 sal_Int32 mnSize;
150 sal_Int32 mnMinSize;
151
152 Layout() : mnPos( 0 ), mnSize( 0 ), mnMinSize( 0 ) {}
153 void clear() { mnPos = 0; mnSize = 0; mnMinSize = 0; }
154 void dumpAsXml(xmlTextWriterPtr pWriter) const;
155 };
156 typedef std::vector< Layout > LayoutVector;
157
158 static sal_Int32 distribute( LayoutVector& rLayouts, sal_Int32 nDistribute );
159
163
166};
167
168}
169
170#endif
171
172/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool isValid(const CellPos &rPos) const
void DistributeColumns(::tools::Rectangle &rArea, sal_Int32 nFirstCol, sal_Int32 nLastCol, const bool bOptimize, const bool bMinimize)
bool isEdgeVisible(sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal) const
checks if the given edge is visible.
TableLayouter(TableModelRef xTableModel)
void LayoutTableWidth(::tools::Rectangle &rArea, bool bFit)
std::vector< EdgeInfo > getVerticalEdges()
::sal_Int32 getRowCount() const
sal_Int32 getVerticalEdge(int nEdgeX, sal_Int32 *pnMin, sal_Int32 *pnMax)
BorderLineMap maHorizontalBorders
static sal_Int32 distribute(LayoutVector &rLayouts, sal_Int32 nDistribute)
void dumpAsXml(xmlTextWriterPtr pWriter) const
void DistributeRows(::tools::Rectangle &rArea, sal_Int32 nFirstRow, sal_Int32 nLastRow, const bool bOptimize, const bool bMinimize)
sal_Int32 getColumnWidth(sal_Int32 nColumn) const
bool isValidRow(sal_Int32 nRow) const
sal_Int32 getMinimumColumnWidth(sal_Int32 nColumn)
sal_Int32 getHorizontalEdge(int nEdgeY, sal_Int32 *pnMin, sal_Int32 *pnMax)
basegfx::B2ITuple getCellSize(const CellRef &xCell, const CellPos &rPos) const
void LayoutTable(::tools::Rectangle &rRectangle, bool bFitWidth, bool bFitHeight)
try to fit the table into the given rectangle.
void LayoutTableHeight(::tools::Rectangle &rArea, bool bFit)
CellRef getCell(const CellPos &rPos) const
static bool HasPriority(const editeng::SvxBorderLine *pThis, const editeng::SvxBorderLine *pOther)
editeng::SvxBorderLine * getBorderLine(sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal) const
returns the requested borderline in rpBorderLine or a null pointer if there is no border at this edge
std::vector< Layout > LayoutVector
void SetBorder(sal_Int32 nCol, sal_Int32 nRow, bool bHorizontal, const editeng::SvxBorderLine *pLine)
void updateCells(::tools::Rectangle const &rRectangle)
sal_Int32 getRowHeight(sal_Int32 nRow) const
std::vector< EdgeInfo > getHorizontalEdges()
sal_Int32 calcPreferredColumnWidth(sal_Int32 nColumn, Size aSize) const
bool isValidColumn(sal_Int32 nColumn) const
::sal_Int32 getColumnCount() const
bool getCellArea(const CellRef &xCell, const CellPos &rPos, basegfx::B2IRectangle &rArea) const
struct _xmlTextWriter * xmlTextWriterPtr
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
bool findMergeOrigin(const TableModelRef &xTable, sal_Int32 nMergedX, sal_Int32 nMergedY, sal_Int32 &rOriginX, sal_Int32 &rOriginY)
returns true if the cell(nMergedX,nMergedY) is merged with other cells.
std::vector< editeng::SvxBorderLine * > BorderLineVector
std::vector< BorderLineVector > BorderLineMap
rtl::Reference< TableModel > TableModelRef
Definition: celltypes.hxx:35
EdgeInfo(sal_Int32 nInIndex, sal_Int32 nInPosition, sal_Int32 nInMin, sal_Int32 nInMax)
void dumpAsXml(xmlTextWriterPtr pWriter) const