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 .
22 #include <swtable.hxx>
27 #include <boost/ptr_container/ptr_vector.hpp>
28 #include <o3tl/sorted_vector.hxx>
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 SwTblSearchType
;
60 namespace nsSwTblSearchType
62 const SwTblSearchType TBLSEARCH_NONE
= 0x1; // No extension.
63 const SwTblSearchType TBLSEARCH_ROW
= 0x2; // Extend to rows.
64 const SwTblSearchType TBLSEARCH_COL
= 0x3; // Extend to columns.
66 // As flag to the other values!
67 const SwTblSearchType TBLSEARCH_PROTECT
= 0x8; // Collect protected boxes too.
68 const SwTblSearchType TBLSEARCH_NO_UNION_CORRECT
= 0x10; // Do not correct collected Union.
71 SW_DLLPUBLIC
void GetTblSel( const SwCrsrShell
& rShell
, SwSelBoxes
& rBoxes
,
72 const SwTblSearchType
= nsSwTblSearchType::TBLSEARCH_NONE
);
74 void GetTblSel( const SwCursor
& rCrsr
, SwSelBoxes
& rBoxes
,
75 const SwTblSearchType
= nsSwTblSearchType::TBLSEARCH_NONE
);
78 // As before, but don't start from selection but from Start- EndFrms.
79 void GetTblSel( const SwLayoutFrm
* pStart
, const SwLayoutFrm
* pEnd
,
80 SwSelBoxes
& rBoxes
, SwCellFrms
* pCells
,
81 const SwTblSearchType
= nsSwTblSearchType::TBLSEARCH_NONE
);
83 // As before but directly via PaMs.
84 void GetTblSelCrs( const SwCrsrShell
& rShell
, SwSelBoxes
& rBoxes
);
85 void GetTblSelCrs( const SwTableCursor
& rTblCrsr
, SwSelBoxes
& rBoxes
);
87 // Collect boxes relevant for auto sum.
88 sal_Bool
GetAutoSumSel( const SwCrsrShell
&, SwCellFrms
& );
90 // Check if the SelBoxes contains protected Boxes.
91 sal_Bool
HasProtectedCells( const SwSelBoxes
& rBoxes
);
93 // Check if selection is balanced.
94 sal_Bool
ChkChartSel( const SwNode
& rSttNd
, const SwNode
& rEndNd
);
96 // Check if cell is part of SSelection.
97 // (Became a function, in order to make sure that GetTblSel() and MakeTblCrsr()
98 // have always the same concept of the selection.
99 sal_Bool
IsFrmInTblSel( const SwRect
& rUnion
, const SwFrm
* pCell
);
101 // Determine boxes to be merged.
102 // In this process the rectangle gets "adapted" on the base of the layout,
103 // i.e. boxes are added if some overlap at the sides.
104 // Additionally a new box is created and filled with the relevant content.
105 void GetMergeSel( const SwPaM
& rPam
, SwSelBoxes
& rBoxes
,
106 SwTableBox
** ppMergeBox
, SwUndoTblMerge
* pUndo
= 0 );
108 // Check if selected boxes allow for a valid merge.
109 sal_uInt16
CheckMergeSel( const SwPaM
& rPam
);
110 sal_uInt16
CheckMergeSel( const SwSelBoxes
& rBoxes
);
112 sal_Bool
IsEmptyBox( const SwTableBox
& rBox
, SwPaM
& rPam
);
114 // Check if Split or InsertCol lead to a box becoming smaller than MINLAY.
115 sal_Bool
CheckSplitCells( const SwCrsrShell
& rShell
, sal_uInt16 nDiv
,
116 const SwTblSearchType
= nsSwTblSearchType::TBLSEARCH_NONE
);
117 sal_Bool
CheckSplitCells( const SwCursor
& rCrsr
, sal_uInt16 nDiv
,
118 const SwTblSearchType
= nsSwTblSearchType::TBLSEARCH_NONE
);
120 // For working on tab selection also for split tables.
123 SwRect aUnion
; // The rectangle enclosing the selection.
124 SwTabFrm
*pTable
; // The (Follow-)Table for the Union.
127 SwSelUnion( const SwRect
&rRect
, SwTabFrm
*pTab
) :
128 aUnion( rRect
), pTable( pTab
) {}
130 const SwRect
& GetUnion() const { return aUnion
; }
131 SwRect
& GetUnion() { return aUnion
; }
132 const SwTabFrm
*GetTable() const { return pTable
; }
133 SwTabFrm
*GetTable() { return pTable
; }
136 // Determines tables affected by a table selection and union rectangles
137 // of the selection (also for split tables)
138 typedef boost::ptr_vector
<SwSelUnion
> SwSelUnions
;
140 // Gets the tables involved in a table selection and the union-rectangles of the selections
141 // - also for split tables.
142 // If a parameter is passed that != nsSwTblSearchType::TBLSEARCH_NONE
143 // the selection is extended in the given direction.
144 void MakeSelUnions( SwSelUnions
&, const SwLayoutFrm
*pStart
,
145 const SwLayoutFrm
*pEnd
,
146 const SwTblSearchType
= nsSwTblSearchType::TBLSEARCH_NONE
);
150 // These classes copy the current table selections (rBoxes) into a
151 // separate structure while keeping the table structure.
156 typedef boost::ptr_vector
<_FndBox
> _FndBoxes
;
157 typedef boost::ptr_vector
<_FndLine
> _FndLines
;
165 SwTableLine
*pLineBefore
; // For deleting/restoring the layout.
166 SwTableLine
*pLineBehind
;
169 _FndBox( SwTableBox
* pB
, _FndLine
* pFL
) :
170 pBox(pB
), pUpper(pFL
), pLineBefore( 0 ), pLineBehind( 0 ) {}
172 const _FndLines
& GetLines() const { return aLines
; }
173 _FndLines
& GetLines() { return aLines
; }
174 const SwTableBox
* GetBox() const { return pBox
; }
175 SwTableBox
* GetBox() { return pBox
; }
176 const _FndLine
* GetUpper() const { return pUpper
; }
177 _FndLine
* GetUpper() { return pUpper
; }
179 void SetTableLines( const SwSelBoxes
&rBoxes
, const SwTable
&rTable
);
180 void SetTableLines( const SwTable
&rTable
);
181 void DelFrms ( SwTable
&rTable
);
182 void MakeFrms( SwTable
&rTable
);
183 void MakeNewFrms( SwTable
&rTable
, const sal_uInt16 nNumber
,
184 const sal_Bool bBehind
);
185 sal_Bool
AreLinesToRestore( const SwTable
&rTable
) const;
187 void ClearLineBehind() { pLineBehind
= 0; }
197 _FndLine(SwTableLine
* pL
, _FndBox
* pFB
=0) : pLine(pL
), pUpper(pFB
) {}
198 const _FndBoxes
& GetBoxes() const { return aBoxes
; }
199 _FndBoxes
& GetBoxes() { return aBoxes
; }
200 const SwTableLine
* GetLine() const { return pLine
; }
201 SwTableLine
* GetLine() { return pLine
; }
202 const _FndBox
* GetUpper() const { return pUpper
; }
203 _FndBox
* GetUpper() { return pUpper
; }
205 void SetUpper( _FndBox
* pUp
) { pUpper
= pUp
; }
211 const SwSelBoxes
& rBoxes
;
215 _FndPara( const SwSelBoxes
& rBxs
, _FndBox
* pFB
)
216 : rBoxes(rBxs
), pFndLine(0), pFndBox(pFB
) {}
217 _FndPara( const _FndPara
& rPara
, _FndBox
* pFB
)
218 : rBoxes(rPara
.rBoxes
), pFndLine(rPara
.pFndLine
), pFndBox(pFB
) {}
219 _FndPara( const _FndPara
& rPara
, _FndLine
* pFL
)
220 : rBoxes(rPara
.rBoxes
), pFndLine(pFL
), pFndBox(rPara
.pFndBox
) {}
223 SW_DLLPUBLIC
void ForEach_FndLineCopyCol(SwTableLines
& rLines
, _FndPara
* pFndPara
);
227 #endif // _TBLSEL_HXX
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */