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 _SVX_TABLE_TABLELAYOUTER_HXX_
21 #define _SVX_TABLE_TABLELAYOUTER_HXX_
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>
27 #include <basegfx/range/b2irectangle.hxx>
28 #include <basegfx/tuple/b2ituple.hxx>
29 #include <boost/shared_ptr.hpp>
33 #include "svx/svdotable.hxx"
37 // -----------------------------------------------------------------------------
43 namespace sdr
{ namespace table
{
45 /** returns true if the cell(nMergedCol,nMergedRow) is merged with other cells.
46 the returned cell( rOriginCol, rOriginRow ) is the origin( top left cell ) of the merge.
48 bool findMergeOrigin( const TableModelRef
& xTable
, sal_Int32 nMergedCol
, sal_Int32 nMergedRow
, sal_Int32
& rOriginCol
, sal_Int32
& rOriginRow
);
50 typedef std::vector
< editeng::SvxBorderLine
* > BorderLineVector
;
51 typedef std::vector
< BorderLineVector
> BorderLineMap
;
53 // -----------------------------------------------------------------------------
55 // -----------------------------------------------------------------------------
60 TableLayouter( const TableModelRef
& xTableModel
);
61 virtual ~TableLayouter();
63 /** try to fit the table into the given rectangle.
64 If the rectangle is to small, it will be grown to fit the table.
66 if bFitWidth or bFitHeight is set, the layouter tries to scale
67 the rows and/or columns to the given area. The result my be bigger
68 to fullfill constrains.
70 if bFitWidth or bFitHeight is set, the model is changed.
72 void LayoutTable( ::Rectangle
& rRectangle
, bool bFitWidth
, bool bFitHeight
);
74 void UpdateBorderLayout();
76 basegfx::B2ITuple
getCellSize( const CellPos
& rPos
) const;
77 bool getCellArea( const CellRef
& xCell
, basegfx::B2IRectangle
& rArea
) const;
78 bool getCellArea( const CellPos
& rPos
, basegfx::B2IRectangle
& rArea
) const;
80 ::sal_Int32
getRowCount() const { return static_cast< ::sal_Int32
>( maRows
.size() ); }
81 ::sal_Int32
getColumnCount() const { return static_cast< ::sal_Int32
>( maColumns
.size() ); }
82 sal_Int32
getRowHeight( sal_Int32 nRow
) const;
84 sal_Int32
getColumnWidth( sal_Int32 nColumn
) const;
86 sal_Int32
getMinimumColumnWidth( sal_Int32 nColumn
);
88 /** checks if the given edge is visible.
89 Edges between merged cells are not visible.
91 bool isEdgeVisible( sal_Int32 nEdgeX
, sal_Int32 nEdgeY
, bool bHorizontal
) const;
93 /** returns the requested borderline in rpBorderLine or a null pointer if there is no border at this edge */
94 editeng::SvxBorderLine
* getBorderLine( sal_Int32 nEdgeX
, sal_Int32 nEdgeY
, bool bHorizontal
)const;
96 void updateCells( ::Rectangle
& rRectangle
);
98 sal_Int32
getHorizontalEdge( int nEdgeY
, sal_Int32
* pnMin
= 0, sal_Int32
* pnMax
= 0 );
99 sal_Int32
getVerticalEdge( int nEdgeX
, sal_Int32
* pnMin
= 0, sal_Int32
* pnMax
= 0);
101 void DistributeColumns( ::Rectangle
& rArea
, sal_Int32 nFirstCol
, sal_Int32 nLastCol
);
102 void DistributeRows( ::Rectangle
& rArea
, sal_Int32 nFirstRow
, sal_Int32 nLastRow
);
104 com::sun::star::text::WritingMode
GetWritingMode() const { return meWritingMode
; }
105 void SetWritingMode( com::sun::star::text::WritingMode eWritingMode
);
108 CellRef
getCell( const CellPos
& rPos
) const;
110 void LayoutTableWidth( ::Rectangle
& rArea
, bool bFit
);
111 void LayoutTableHeight( ::Rectangle
& rArea
, bool bFit
);
113 inline bool isValidColumn( sal_Int32 nColumn
) const { return (nColumn
>= 0) && (nColumn
< static_cast<sal_Int32
>( maColumns
.size())); }
114 inline bool isValidRow( sal_Int32 nRow
) const { return (nRow
>= 0) && (nRow
< static_cast<sal_Int32
>( maRows
.size())); }
115 inline bool isValid( const CellPos
& rPos
) const { return isValidColumn( rPos
.mnCol
) && isValidRow( rPos
.mnRow
); }
117 void ClearBorderLayout();
118 void ClearBorderLayout(BorderLineMap
& rMap
);
119 void ResizeBorderLayout();
120 void ResizeBorderLayout( BorderLineMap
& rMap
);
122 void SetBorder( sal_Int32 nCol
, sal_Int32 nRow
, bool bHorizontal
, const editeng::SvxBorderLine
* pLine
);
124 static bool HasPriority( const editeng::SvxBorderLine
* pThis
, const editeng::SvxBorderLine
* pOther
);
132 Layout() : mnPos( 0 ), mnSize( 0 ), mnMinSize( 0 ) {}
133 void clear() { mnPos
= 0; mnSize
= 0; mnMinSize
= 0; }
135 typedef std::vector
< Layout
> LayoutVector
;
137 sal_Int32
distribute( LayoutVector
& rLayouts
, sal_Int32 nDistribute
);
139 TableModelRef mxTable
;
141 LayoutVector maColumns
;
143 BorderLineMap maHorizontalBorders
;
144 BorderLineMap maVerticalBorders
;
146 com::sun::star::text::WritingMode meWritingMode
;
148 const OUString msSize
;
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */