lok: Don't attempt to select the exact text after a failed search.
[LibreOffice.git] / svx / source / table / tablelayouter.hxx
blob642128bbf2e9c698e74549f27d6bb79461965306
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 <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>
30 #include <vector>
31 #include <map>
33 #include "svx/svdotable.hxx"
35 class Rectangle;
39 namespace editeng {
40 class SvxBorderLine;
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;
54 // TableModel
57 class TableLayouter
59 public:
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 fulfill 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 bool getCellArea( const CellRef& xCell, const CellPos& rPos, basegfx::B2IRectangle& rArea ) const;
78 ::sal_Int32 getRowCount() const { return static_cast< ::sal_Int32 >( maRows.size() ); }
79 ::sal_Int32 getColumnCount() const { return static_cast< ::sal_Int32 >( maColumns.size() ); }
80 sal_Int32 getRowHeight( sal_Int32 nRow ) const;
82 sal_Int32 getColumnWidth( sal_Int32 nColumn ) const;
84 sal_Int32 getMinimumColumnWidth( sal_Int32 nColumn );
86 /** checks if the given edge is visible.
87 Edges between merged cells are not visible.
89 bool isEdgeVisible( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal ) const;
91 /** returns the requested borderline in rpBorderLine or a null pointer if there is no border at this edge */
92 editeng::SvxBorderLine* getBorderLine( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal )const;
94 void updateCells( ::Rectangle& rRectangle );
96 sal_Int32 getHorizontalEdge( int nEdgeY, sal_Int32* pnMin = 0, sal_Int32* pnMax = 0 );
97 sal_Int32 getVerticalEdge( int nEdgeX , sal_Int32* pnMin = 0, sal_Int32* pnMax = 0);
99 void DistributeColumns( ::Rectangle& rArea, sal_Int32 nFirstCol, sal_Int32 nLastCol );
100 void DistributeRows( ::Rectangle& rArea, sal_Int32 nFirstRow, sal_Int32 nLastRow );
102 private:
103 CellRef getCell( const CellPos& rPos ) const;
104 basegfx::B2ITuple getCellSize( const CellRef& xCell, const CellPos& rPos ) const;
106 void LayoutTableWidth( ::Rectangle& rArea, bool bFit );
107 void LayoutTableHeight( ::Rectangle& rArea, bool bFit );
109 inline bool isValidColumn( sal_Int32 nColumn ) const { return (nColumn >= 0) && (nColumn < static_cast<sal_Int32>( maColumns.size())); }
110 inline bool isValidRow( sal_Int32 nRow ) const { return (nRow >= 0) && (nRow < static_cast<sal_Int32>( maRows.size())); }
111 inline bool isValid( const CellPos& rPos ) const { return isValidColumn( rPos.mnCol ) && isValidRow( rPos.mnRow ); }
113 void ClearBorderLayout();
114 static void ClearBorderLayout(BorderLineMap& rMap);
115 void ResizeBorderLayout();
116 void ResizeBorderLayout( BorderLineMap& rMap );
118 void SetBorder( sal_Int32 nCol, sal_Int32 nRow, bool bHorizontal, const editeng::SvxBorderLine* pLine );
120 static bool HasPriority( const editeng::SvxBorderLine* pThis, const editeng::SvxBorderLine* pOther );
122 struct Layout
124 sal_Int32 mnPos;
125 sal_Int32 mnSize;
126 sal_Int32 mnMinSize;
128 Layout() : mnPos( 0 ), mnSize( 0 ), mnMinSize( 0 ) {}
129 void clear() { mnPos = 0; mnSize = 0; mnMinSize = 0; }
131 typedef std::vector< Layout > LayoutVector;
133 static sal_Int32 distribute( LayoutVector& rLayouts, sal_Int32 nDistribute );
135 TableModelRef mxTable;
136 LayoutVector maRows;
137 LayoutVector maColumns;
139 BorderLineMap maHorizontalBorders;
140 BorderLineMap maVerticalBorders;
142 const OUString msSize;
147 #endif
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */