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 .
19 #ifndef INCLUDED_SW_INC_TBLSEL_HXX
20 #define INCLUDED_SW_INC_TBLSEL_HXX
22 #include <swtable.hxx>
27 #include <boost/ptr_container/ptr_vector.hpp>
28 #include <o3tl/sorted_vector.hxx>
41 class SwUndoTableMerge
;
44 typedef ::std::deque
< SwCellFrm
* > SwCellFrms
;
46 struct CompareSwSelBoxes
48 bool operator()(SwTableBox
* const& lhs
, SwTableBox
* const& rhs
) const
50 return lhs
->GetSttIdx() < rhs
->GetSttIdx();
53 class SwSelBoxes
: public o3tl::sorted_vector
<SwTableBox
*, CompareSwSelBoxes
> {};
55 // Collects all boxes in table that are selected.
56 // Selection gets extended in given direction according to enum-parameter.
57 // Boxes are collected via the Layout; works correctly if tables are split.
58 // (Cf. MakeSelUnions().)
59 typedef sal_uInt16 SwTableSearchType
;
60 namespace nsSwTableSearchType
62 const SwTableSearchType TBLSEARCH_NONE
= 0x1; // No extension.
63 const SwTableSearchType TBLSEARCH_ROW
= 0x2; // Extend to rows.
64 const SwTableSearchType TBLSEARCH_COL
= 0x3; // Extend to columns.
66 // As flag to the other values!
67 const SwTableSearchType TBLSEARCH_PROTECT
= 0x8; // Collect protected boxes too.
68 const SwTableSearchType TBLSEARCH_NO_UNION_CORRECT
= 0x10; // Do not correct collected Union.
71 SW_DLLPUBLIC
void GetTableSel( const SwCrsrShell
& rShell
, SwSelBoxes
& rBoxes
,
72 const SwTableSearchType
= nsSwTableSearchType::TBLSEARCH_NONE
);
74 void GetTableSel( const SwCursor
& rCrsr
, SwSelBoxes
& rBoxes
,
75 const SwTableSearchType
= nsSwTableSearchType::TBLSEARCH_NONE
);
77 // As before, but don't start from selection but from Start- EndFrms.
78 void GetTableSel( const SwLayoutFrm
* pStart
, const SwLayoutFrm
* pEnd
,
79 SwSelBoxes
& rBoxes
, SwCellFrms
* pCells
,
80 const SwTableSearchType
= nsSwTableSearchType::TBLSEARCH_NONE
);
82 // As before but directly via PaMs.
83 void GetTableSelCrs( const SwCrsrShell
& rShell
, SwSelBoxes
& rBoxes
);
84 void GetTableSelCrs( const SwTableCursor
& rTableCrsr
, SwSelBoxes
& rBoxes
);
86 // Collect boxes relevant for auto sum.
87 bool GetAutoSumSel( const SwCrsrShell
&, SwCellFrms
& );
89 // Check if the SelBoxes contains protected Boxes.
90 bool HasProtectedCells( const SwSelBoxes
& rBoxes
);
92 // Check if selection is balanced.
93 bool ChkChartSel( const SwNode
& rSttNd
, const SwNode
& rEndNd
);
95 // Check if cell is part of SSelection.
96 // (Became a function, in order to make sure that GetTableSel() and MakeTableCrsr()
97 // have always the same concept of the selection.
98 bool IsFrmInTableSel( const SwRect
& rUnion
, const SwFrm
* pCell
);
100 // Determine boxes to be merged.
101 // In this process the rectangle gets "adapted" on the base of the layout,
102 // i.e. boxes are added if some overlap at the sides.
103 // Additionally a new box is created and filled with the relevant content.
104 void GetMergeSel( const SwPaM
& rPam
, SwSelBoxes
& rBoxes
,
105 SwTableBox
** ppMergeBox
, SwUndoTableMerge
* pUndo
= 0 );
107 // Check if selected boxes allow for a valid merge.
108 sal_uInt16
CheckMergeSel( const SwPaM
& rPam
);
109 sal_uInt16
CheckMergeSel( const SwSelBoxes
& rBoxes
);
111 bool IsEmptyBox( const SwTableBox
& rBox
, SwPaM
& rPam
);
113 // Check if Split or InsertCol lead to a box becoming smaller than MINLAY.
114 bool CheckSplitCells( const SwCrsrShell
& rShell
, sal_uInt16 nDiv
,
115 const SwTableSearchType
= nsSwTableSearchType::TBLSEARCH_NONE
);
116 bool CheckSplitCells( const SwCursor
& rCrsr
, sal_uInt16 nDiv
,
117 const SwTableSearchType
= nsSwTableSearchType::TBLSEARCH_NONE
);
119 // For working on tab selection also for split tables.
122 SwRect aUnion
; // The rectangle enclosing the selection.
123 SwTabFrm
*pTable
; // The (Follow-)Table for the Union.
126 SwSelUnion( const SwRect
&rRect
, SwTabFrm
*pTab
) :
127 aUnion( rRect
), pTable( pTab
) {}
129 const SwRect
& GetUnion() const { return aUnion
; }
130 SwRect
& GetUnion() { return aUnion
; }
131 const SwTabFrm
*GetTable() const { return pTable
; }
132 SwTabFrm
*GetTable() { return pTable
; }
135 // Determines tables affected by a table selection and union rectangles
136 // of the selection (also for split tables)
137 typedef boost::ptr_vector
<SwSelUnion
> SwSelUnions
;
139 // Gets the tables involved in a table selection and the union-rectangles of the selections
140 // - also for split tables.
141 // If a parameter is passed that != nsSwTableSearchType::TBLSEARCH_NONE
142 // the selection is extended in the given direction.
143 void MakeSelUnions( SwSelUnions
&, const SwLayoutFrm
*pStart
,
144 const SwLayoutFrm
*pEnd
,
145 const SwTableSearchType
= nsSwTableSearchType::TBLSEARCH_NONE
);
147 // These classes copy the current table selections (rBoxes) into a
148 // separate structure while keeping the table structure.
153 typedef boost::ptr_vector
<_FndBox
> _FndBoxes
;
154 typedef boost::ptr_vector
<_FndLine
> _FndLines
;
162 SwTableLine
*pLineBefore
; // For deleting/restoring the layout.
163 SwTableLine
*pLineBehind
;
166 _FndBox( SwTableBox
* pB
, _FndLine
* pFL
) :
167 pBox(pB
), pUpper(pFL
), pLineBefore( 0 ), pLineBehind( 0 ) {}
169 const _FndLines
& GetLines() const { return aLines
; }
170 _FndLines
& GetLines() { return aLines
; }
171 const SwTableBox
* GetBox() const { return pBox
; }
172 SwTableBox
* GetBox() { return pBox
; }
173 const _FndLine
* GetUpper() const { return pUpper
; }
174 _FndLine
* GetUpper() { return pUpper
; }
176 void SetTableLines( const SwSelBoxes
&rBoxes
, const SwTable
&rTable
);
177 void SetTableLines( const SwTable
&rTable
);
178 //Add an input param to identify if acc table should be disposed
179 void DelFrms ( SwTable
&rTable
, bool bAccTableDispose
= false );
180 void MakeFrms( SwTable
&rTable
);
181 void MakeNewFrms( SwTable
&rTable
, const sal_uInt16 nNumber
,
182 const bool bBehind
);
183 bool AreLinesToRestore( const SwTable
&rTable
) const;
185 void ClearLineBehind() { pLineBehind
= 0; }
194 _FndLine(SwTableLine
* pL
, _FndBox
* pFB
=0) : pLine(pL
), pUpper(pFB
) {}
195 const _FndBoxes
& GetBoxes() const { return aBoxes
; }
196 _FndBoxes
& GetBoxes() { return aBoxes
; }
197 const SwTableLine
* GetLine() const { return pLine
; }
198 SwTableLine
* GetLine() { return pLine
; }
199 const _FndBox
* GetUpper() const { return pUpper
; }
200 _FndBox
* GetUpper() { return pUpper
; }
202 void SetUpper( _FndBox
* pUp
) { pUpper
= pUp
; }
207 const SwSelBoxes
& rBoxes
;
211 _FndPara( const SwSelBoxes
& rBxs
, _FndBox
* pFB
)
212 : rBoxes(rBxs
), pFndLine(0), pFndBox(pFB
) {}
213 _FndPara( const _FndPara
& rPara
, _FndBox
* pFB
)
214 : rBoxes(rPara
.rBoxes
), pFndLine(rPara
.pFndLine
), pFndBox(pFB
) {}
215 _FndPara( const _FndPara
& rPara
, _FndLine
* pFL
)
216 : rBoxes(rPara
.rBoxes
), pFndLine(pFL
), pFndBox(rPara
.pFndBox
) {}
219 SW_DLLPUBLIC
void ForEach_FndLineCopyCol(SwTableLines
& rLines
, _FndPara
* pFndPara
);
221 #endif // INCLUDED_SW_INC_TBLSEL_HXX
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */