Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _SVX_TABLE_TABLELAYOUTER_HXX_
30 : : #define _SVX_TABLE_TABLELAYOUTER_HXX_
31 : :
32 : : #include <com/sun/star/container/XIndexAccess.hpp>
33 : : #include <com/sun/star/text/WritingMode.hpp>
34 : : #include <com/sun/star/table/XTable.hpp>
35 : : #include <basegfx/range/b2irectangle.hxx>
36 : : #include <basegfx/tuple/b2ituple.hxx>
37 : : #include <tools/gen.hxx>
38 : : #include <boost/shared_ptr.hpp>
39 : : #include <vector>
40 : : #include <map>
41 : :
42 : : #include "svx/svdotable.hxx"
43 : :
44 : : // -----------------------------------------------------------------------------
45 : :
46 : : namespace editeng {
47 : : class SvxBorderLine;
48 : : }
49 : :
50 : : namespace sdr { namespace table {
51 : :
52 : : /** returns true if the cell(nMergedCol,nMergedRow) is merged with other cells.
53 : : the returned cell( rOriginCol, rOriginRow ) is the origin( top left cell ) of the merge.
54 : : */
55 : : bool findMergeOrigin( const TableModelRef& xTable, sal_Int32 nMergedCol, sal_Int32 nMergedRow, sal_Int32& rOriginCol, sal_Int32& rOriginRow );
56 : :
57 : : typedef std::vector< editeng::SvxBorderLine* > BorderLineVector;
58 : : typedef std::vector< BorderLineVector > BorderLineMap;
59 : :
60 : : // -----------------------------------------------------------------------------
61 : : // TableModel
62 : : // -----------------------------------------------------------------------------
63 : :
64 : : class TableLayouter
65 : : {
66 : : public:
67 : : TableLayouter( const TableModelRef& xTableModel );
68 : : virtual ~TableLayouter();
69 : :
70 : : /** try to fit the table into the given rectangle.
71 : : If the rectangle is to small, it will be grown to fit the table.
72 : :
73 : : if bFitWidth or bFitHeight is set, the layouter tries to scale
74 : : the rows and/or columns to the given area. The result my be bigger
75 : : to fullfill constrains.
76 : :
77 : : if bFitWidth or bFitHeight is set, the model is changed.
78 : : */
79 : : void LayoutTable( ::Rectangle& rRectangle, bool bFitWidth, bool bFitHeight );
80 : :
81 : : void UpdateBorderLayout();
82 : :
83 : : basegfx::B2ITuple getCellSize( const CellPos& rPos ) const;
84 : : bool getCellArea( const CellRef& xCell, basegfx::B2IRectangle& rArea ) const;
85 : : bool getCellArea( const CellPos& rPos, basegfx::B2IRectangle& rArea ) const;
86 : :
87 : 1206 : ::sal_Int32 getRowCount() const { return static_cast< ::sal_Int32 >( maRows.size() ); }
88 : 1197 : ::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 : :
93 : : sal_Int32 getMinimumColumnWidth( sal_Int32 nColumn );
94 : :
95 : : /** checks if the given edge is visible.
96 : : Edges between merged cells are not visible.
97 : : */
98 : : bool isEdgeVisible( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal ) const;
99 : :
100 : : /** returns the requested borderline in rpBorderLine or a null pointer if there is no border at this edge */
101 : : editeng::SvxBorderLine* getBorderLine( sal_Int32 nEdgeX, sal_Int32 nEdgeY, bool bHorizontal )const;
102 : :
103 : : void updateCells( ::Rectangle& rRectangle );
104 : :
105 : : sal_Int32 getHorizontalEdge( int nEdgeY, sal_Int32* pnMin = 0, sal_Int32* pnMax = 0 );
106 : : sal_Int32 getVerticalEdge( int nEdgeX , sal_Int32* pnMin = 0, sal_Int32* pnMax = 0);
107 : :
108 : : void DistributeColumns( ::Rectangle& rArea, sal_Int32 nFirstCol, sal_Int32 nLastCol );
109 : : void DistributeRows( ::Rectangle& rArea, sal_Int32 nFirstRow, sal_Int32 nLastRow );
110 : :
111 : 132 : com::sun::star::text::WritingMode GetWritingMode() const { return meWritingMode; }
112 : : void SetWritingMode( com::sun::star::text::WritingMode eWritingMode );
113 : :
114 : : private:
115 : : CellRef getCell( const CellPos& rPos ) const;
116 : :
117 : : void LayoutTableWidth( ::Rectangle& rArea, bool bFit );
118 : : void LayoutTableHeight( ::Rectangle& rArea, bool bFit );
119 : :
120 [ + - ][ + - ]: 480 : inline bool isValidColumn( sal_Int32 nColumn ) const { return (nColumn >= 0) && (nColumn < static_cast<sal_Int32>( maColumns.size())); }
121 [ + - ][ + - ]: 480 : inline bool isValidRow( sal_Int32 nRow ) const { return (nRow >= 0) && (nRow < static_cast<sal_Int32>( maRows.size())); }
122 [ + - ][ + - ]: 480 : inline bool isValid( const CellPos& rPos ) const { return isValidColumn( rPos.mnCol ) && isValidRow( rPos.mnRow ); }
123 : :
124 : : void ClearBorderLayout();
125 : : void ClearBorderLayout(BorderLineMap& rMap);
126 : : void ResizeBorderLayout();
127 : : void ResizeBorderLayout( BorderLineMap& rMap );
128 : :
129 : : void SetBorder( sal_Int32 nCol, sal_Int32 nRow, bool bHorizontal, const editeng::SvxBorderLine* pLine );
130 : :
131 : : static bool HasPriority( const editeng::SvxBorderLine* pThis, const editeng::SvxBorderLine* pOther );
132 : :
133 : : struct Layout
134 : : {
135 : : sal_Int32 mnPos;
136 : : sal_Int32 mnSize;
137 : : sal_Int32 mnMinSize;
138 : :
139 : 54 : Layout() : mnPos( 0 ), mnSize( 0 ), mnMinSize( 0 ) {}
140 : 66 : void clear() { mnPos = 0; mnSize = 0; mnMinSize = 0; }
141 : : };
142 : : typedef std::vector< Layout > LayoutVector;
143 : :
144 : : sal_Int32 distribute( LayoutVector& rLayouts, sal_Int32 nDistribute );
145 : :
146 : : TableModelRef mxTable;
147 : : LayoutVector maRows;
148 : : LayoutVector maColumns;
149 : :
150 : : BorderLineMap maHorizontalBorders;
151 : : BorderLineMap maVerticalBorders;
152 : :
153 : : com::sun::star::text::WritingMode meWritingMode;
154 : :
155 : : const rtl::OUString msSize;
156 : : };
157 : :
158 : : } }
159 : :
160 : : #endif
161 : :
162 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|