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 <vector>
27 
28 #include <svx/svdotable.hxx>
29 #include <celltypes.hxx>
30 
31 namespace tools { class Rectangle; }
32 
33 
34 namespace editeng {
35  class SvxBorderLine;
36 }
37 
38 namespace sdr::table {
39 
43 bool findMergeOrigin( const TableModelRef& xTable, sal_Int32 nMergedCol, sal_Int32 nMergedRow, sal_Int32& rOriginCol, sal_Int32& rOriginRow );
44 
45 typedef std::vector< editeng::SvxBorderLine* > BorderLineVector;
46 typedef std::vector< BorderLineVector > BorderLineMap;
47 
48 
49 // TableModel
50 
51 struct EdgeInfo final
52 {
53  sal_Int32 nIndex;
54  sal_Int32 nPosition;
55  sal_Int32 nMin;
56  sal_Int32 nMax;
57 
58  EdgeInfo(sal_Int32 nInIndex, sal_Int32 nInPosition, sal_Int32 nInMin, sal_Int32 nInMax)
59  : nIndex(nInIndex)
60  , nPosition(nInPosition)
61  , nMin(nInMin)
62  , nMax(nInMax)
63  {}
64 };
65 
66 class TableLayouter final
67 {
68 public:
69  explicit TableLayouter( const TableModelRef& xTableModel );
71 
81  void LayoutTable( ::tools::Rectangle& rRectangle, bool bFitWidth, bool bFitHeight );
82 
83  void UpdateBorderLayout();
84 
85  bool getCellArea( const CellRef& xCell, const CellPos& rPos, basegfx::B2IRectangle& rArea ) const;
86 
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;
90 
91  sal_Int32 getColumnWidth( sal_Int32 nColumn ) const;
92  sal_Int32 calcPreferredColumnWidth( sal_Int32 nColumn, Size aSize ) const;
93 
94  sal_Int32 getMinimumColumnWidth( sal_Int32 nColumn );
95 
99  bool isEdgeVisible( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal ) const;
100 
102  editeng::SvxBorderLine* getBorderLine( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal )const;
103 
104  void updateCells( ::tools::Rectangle const & rRectangle );
105 
106  std::vector<EdgeInfo> getHorizontalEdges();
107  sal_Int32 getHorizontalEdge( int nEdgeY, sal_Int32* pnMin, sal_Int32* pnMax );
108 
109  std::vector<EdgeInfo> getVerticalEdges();
110  sal_Int32 getVerticalEdge( int nEdgeX , sal_Int32* pnMin, sal_Int32* pnMax);
111 
112 
113  void DistributeColumns( ::tools::Rectangle& rArea,
114  sal_Int32 nFirstCol,
115  sal_Int32 nLastCol,
116  const bool bOptimize,
117  const bool bMinimize );
118  void DistributeRows( ::tools::Rectangle& rArea,
119  sal_Int32 nFirstRow,
120  sal_Int32 nLastRow,
121  const bool bOptimize,
122  const bool bMinimize );
123  void dumpAsXml(xmlTextWriterPtr pWriter) const;
124 
125 private:
126  CellRef getCell( const CellPos& rPos ) const;
127  basegfx::B2ITuple getCellSize( const CellRef& xCell, const CellPos& rPos ) const;
128 
129  void LayoutTableWidth( ::tools::Rectangle& rArea, bool bFit );
130  void LayoutTableHeight( ::tools::Rectangle& rArea, bool bFit );
131 
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 ); }
135 
136  void ClearBorderLayout();
137  static void ClearBorderLayout(BorderLineMap& rMap);
138  void ResizeBorderLayout();
139  void ResizeBorderLayout( BorderLineMap& rMap );
140 
141  void SetBorder( sal_Int32 nCol, sal_Int32 nRow, bool bHorizontal, const editeng::SvxBorderLine* pLine );
142 
143  static bool HasPriority( const editeng::SvxBorderLine* pThis, const editeng::SvxBorderLine* pOther );
144 
145  struct Layout
146  {
147  sal_Int32 mnPos;
148  sal_Int32 mnSize;
149  sal_Int32 mnMinSize;
150 
151  Layout() : mnPos( 0 ), mnSize( 0 ), mnMinSize( 0 ) {}
152  void clear() { mnPos = 0; mnSize = 0; mnMinSize = 0; }
153  void dumpAsXml(xmlTextWriterPtr pWriter) const;
154  };
155  typedef std::vector< Layout > LayoutVector;
156 
157  static sal_Int32 distribute( LayoutVector& rLayouts, sal_Int32 nDistribute );
158 
160  LayoutVector maRows;
161  LayoutVector maColumns;
162 
163  BorderLineMap maHorizontalBorders;
164  BorderLineMap maVerticalBorders;
165 };
166 
167 }
168 
169 #endif
170 
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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.
::sal_Int32 getColumnCount() const
void DistributeColumns(::tools::Rectangle &rArea, sal_Int32 nFirstCol, sal_Int32 nLastCol, const bool bOptimize, const bool bMinimize)
void dumpAsXml(xmlTextWriterPtr pWriter) const
struct _xmlTextWriter * xmlTextWriterPtr
EdgeInfo(sal_Int32 nInIndex, sal_Int32 nInPosition, sal_Int32 nInMin, sal_Int32 nInMax)
basegfx::B2ITuple getCellSize(const CellRef &xCell, const CellPos &rPos) const
std::vector< Layout > LayoutVector
::sal_Int32 getRowCount() const
std::vector< EdgeInfo > getHorizontalEdges()
static sal_Int32 distribute(LayoutVector &rLayouts, sal_Int32 nDistribute)
sal_Int32 getMinimumColumnWidth(sal_Int32 nColumn)
bool isValidColumn(sal_Int32 nColumn) const
sal_Int32 getHorizontalEdge(int nEdgeY, sal_Int32 *pnMin, sal_Int32 *pnMax)
void SetBorder(sal_Int32 nCol, sal_Int32 nRow, bool bHorizontal, const editeng::SvxBorderLine *pLine)
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...
void dumpAsXml(xmlTextWriterPtr pWriter) const
void updateCells(::tools::Rectangle const &rRectangle)
sal_Int32 getColumnWidth(sal_Int32 nColumn) const
BorderLineMap maHorizontalBorders
bool getCellArea(const CellRef &xCell, const CellPos &rPos, basegfx::B2IRectangle &rArea) const
CellRef getCell(const CellPos &rPos) const
bool isValid(const CellPos &rPos) const
static bool HasPriority(const editeng::SvxBorderLine *pThis, const editeng::SvxBorderLine *pOther)
bool isEdgeVisible(sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal) const
checks if the given edge is visible.
rtl::Reference< TableModel > TableModelRef
Definition: celltypes.hxx:35
void LayoutTableHeight(::tools::Rectangle &rArea, bool bFit)
bool isValidRow(sal_Int32 nRow) const
TableLayouter(const TableModelRef &xTableModel)
sal_Int32 getRowHeight(sal_Int32 nRow) const
sal_Int32 calcPreferredColumnWidth(sal_Int32 nColumn, Size aSize) const
std::vector< BorderLineVector > BorderLineMap
void LayoutTableWidth(::tools::Rectangle &rArea, bool bFit)
void LayoutTable(::tools::Rectangle &rRectangle, bool bFitWidth, bool bFitHeight)
try to fit the table into the given rectangle.
void DistributeRows(::tools::Rectangle &rArea, sal_Int32 nFirstRow, sal_Int32 nLastRow, const bool bOptimize, const bool bMinimize)
std::vector< EdgeInfo > getVerticalEdges()
std::vector< editeng::SvxBorderLine * > BorderLineVector
sal_Int32 getVerticalEdge(int nEdgeX, sal_Int32 *pnMin, sal_Int32 *pnMax)