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 <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>
29 #include <vector>
30 #include <map>
31 
32 #include <svx/svdotable.hxx>
33 
34 namespace tools { class Rectangle; }
35 
36 
37 namespace editeng {
38  class SvxBorderLine;
39 }
40 
41 namespace sdr { namespace table {
42 
46 bool findMergeOrigin( const TableModelRef& xTable, sal_Int32 nMergedCol, sal_Int32 nMergedRow, sal_Int32& rOriginCol, sal_Int32& rOriginRow );
47 
48 typedef std::vector< editeng::SvxBorderLine* > BorderLineVector;
49 typedef std::vector< BorderLineVector > BorderLineMap;
50 
51 
52 // TableModel
53 
54 struct EdgeInfo final
55 {
56  sal_Int32 nIndex;
57  sal_Int32 nPosition;
58  sal_Int32 nMin;
59  sal_Int32 nMax;
60 
61  EdgeInfo(sal_Int32 nInIndex, sal_Int32 nInPosition, sal_Int32 nInMin, sal_Int32 nInMax)
62  : nIndex(nInIndex)
63  , nPosition(nInPosition)
64  , nMin(nInMin)
65  , nMax(nInMax)
66  {}
67 };
68 
69 class TableLayouter final
70 {
71 public:
72  explicit TableLayouter( const TableModelRef& xTableModel );
74 
84  void LayoutTable( ::tools::Rectangle& rRectangle, bool bFitWidth, bool bFitHeight );
85 
86  void UpdateBorderLayout();
87 
88  bool getCellArea( const CellRef& xCell, const CellPos& rPos, basegfx::B2IRectangle& rArea ) const;
89 
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;
93 
94  sal_Int32 getColumnWidth( sal_Int32 nColumn ) const;
95  sal_Int32 calcPreferredColumnWidth( sal_Int32 nColumn, Size aSize ) const;
96 
97  sal_Int32 getMinimumColumnWidth( sal_Int32 nColumn );
98 
102  bool isEdgeVisible( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal ) const;
103 
105  editeng::SvxBorderLine* getBorderLine( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal )const;
106 
107  void updateCells( ::tools::Rectangle const & rRectangle );
108 
109  std::vector<EdgeInfo> getHorizontalEdges();
110  sal_Int32 getHorizontalEdge( int nEdgeY, sal_Int32* pnMin, sal_Int32* pnMax );
111 
112  std::vector<EdgeInfo> getVerticalEdges();
113  sal_Int32 getVerticalEdge( int nEdgeX , sal_Int32* pnMin, sal_Int32* pnMax);
114 
115 
116  void DistributeColumns( ::tools::Rectangle& rArea,
117  sal_Int32 nFirstCol,
118  sal_Int32 nLastCol,
119  const bool bOptimize,
120  const bool bMinimize );
121  void DistributeRows( ::tools::Rectangle& rArea,
122  sal_Int32 nFirstRow,
123  sal_Int32 nLastRow,
124  const bool bOptimize,
125  const bool bMinimize );
126  void dumpAsXml(xmlTextWriterPtr pWriter) const;
127 
128 private:
129  CellRef getCell( const CellPos& rPos ) const;
130  basegfx::B2ITuple getCellSize( const CellRef& xCell, const CellPos& rPos ) const;
131 
132  void LayoutTableWidth( ::tools::Rectangle& rArea, bool bFit );
133  void LayoutTableHeight( ::tools::Rectangle& rArea, bool bFit );
134 
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 ); }
138 
139  void ClearBorderLayout();
140  static void ClearBorderLayout(BorderLineMap& rMap);
141  void ResizeBorderLayout();
142  void ResizeBorderLayout( BorderLineMap& rMap );
143 
144  void SetBorder( sal_Int32 nCol, sal_Int32 nRow, bool bHorizontal, const editeng::SvxBorderLine* pLine );
145 
146  static bool HasPriority( const editeng::SvxBorderLine* pThis, const editeng::SvxBorderLine* pOther );
147 
148  struct Layout
149  {
150  sal_Int32 mnPos;
151  sal_Int32 mnSize;
152  sal_Int32 mnMinSize;
153 
154  Layout() : mnPos( 0 ), mnSize( 0 ), mnMinSize( 0 ) {}
155  void clear() { mnPos = 0; mnSize = 0; mnMinSize = 0; }
156  void dumpAsXml(xmlTextWriterPtr pWriter) const;
157  };
158  typedef std::vector< Layout > LayoutVector;
159 
160  static sal_Int32 distribute( LayoutVector& rLayouts, sal_Int32 nDistribute );
161 
163  LayoutVector maRows;
164  LayoutVector maColumns;
165 
166  BorderLineMap maHorizontalBorders;
167  BorderLineMap maVerticalBorders;
168 };
169 
170 } }
171 
172 #endif
173 
174 /* 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
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
struct _xmlTextWriter * xmlTextWriterPtr
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)