xref: /aoo42x/main/sw/inc/tblsel.hxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #ifndef _TBLSEL_HXX
28*cdf0e10cSrcweir #define _TBLSEL_HXX
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <svl/svarray.hxx>
31*cdf0e10cSrcweir #include <swtable.hxx>
32*cdf0e10cSrcweir #include <swrect.hxx>
33*cdf0e10cSrcweir #include "swdllapi.h"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir class SwCrsrShell;
36*cdf0e10cSrcweir class SwCursor;
37*cdf0e10cSrcweir class SwTableCursor;
38*cdf0e10cSrcweir class SwFrm;
39*cdf0e10cSrcweir class SwTabFrm;
40*cdf0e10cSrcweir class SwTableBox;
41*cdf0e10cSrcweir class SwTableLine;
42*cdf0e10cSrcweir class SwLayoutFrm;
43*cdf0e10cSrcweir class SwPaM;
44*cdf0e10cSrcweir class SwNode;
45*cdf0e10cSrcweir class SwTable;
46*cdf0e10cSrcweir class SwUndoTblMerge;
47*cdf0e10cSrcweir class SwCellFrm;
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir SV_DECL_PTRARR( SwCellFrms, SwCellFrm*, 16, 16 )
50*cdf0e10cSrcweir SV_DECL_PTRARR_SORT( SwSelBoxes, SwTableBoxPtr, 10, 20 )
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir //Sucht alle Boxen zusammen, die in der Tabelle selektiert sind.
54*cdf0e10cSrcweir //Je nach enum-Parameter wird die Selektion in der angegebenen Richtung
55*cdf0e10cSrcweir //erweitert.
56*cdf0e10cSrcweir //Die Boxen werden ueber das Layout zusammengsucht, es wird auch bei
57*cdf0e10cSrcweir //aufgespaltenen Tabellen korrekt gearbeitet (siehe: MakeSelUnions()).
58*cdf0e10cSrcweir typedef sal_uInt16 SwTblSearchType;
59*cdf0e10cSrcweir namespace nsSwTblSearchType
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir 	const SwTblSearchType TBLSEARCH_NONE = 0x1;       // keine Erweiterung
62*cdf0e10cSrcweir 	const SwTblSearchType TBLSEARCH_ROW	 = 0x2;       // erweiter auf Zeilen
63*cdf0e10cSrcweir 	const SwTblSearchType TBLSEARCH_COL  = 0x3;       // erweiter auf Spalten
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir 	// als Flag zu den anderen Werten!!
66*cdf0e10cSrcweir 	const SwTblSearchType TBLSEARCH_PROTECT	= 0x8;		// auch geschuetzte Boxen einsammeln
67*cdf0e10cSrcweir 	const SwTblSearchType TBLSEARCH_NO_UNION_CORRECT = 0x10; // die zusammenges. Union nicht korrigieren
68*cdf0e10cSrcweir }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir SW_DLLPUBLIC void GetTblSel( const SwCrsrShell& rShell, SwSelBoxes& rBoxes,
71*cdf0e10cSrcweir 				const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir void GetTblSel( const SwCursor& rCrsr, SwSelBoxes& rBoxes,
74*cdf0e10cSrcweir 				const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir //wie vor, jedoch wird nicht von der Selektion sondern von den
77*cdf0e10cSrcweir //Start- EndFrms ausgegangen.
78*cdf0e10cSrcweir void GetTblSel( const SwLayoutFrm* pStart, const SwLayoutFrm* pEnd,
79*cdf0e10cSrcweir                 SwSelBoxes& rBoxes, SwCellFrms* pCells,
80*cdf0e10cSrcweir                 const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir // Desgleichen nocheinmal direkt per PaM's
83*cdf0e10cSrcweir void GetTblSelCrs( const SwCrsrShell& rShell, SwSelBoxes& rBoxes );
84*cdf0e10cSrcweir void GetTblSelCrs( const SwTableCursor& rTblCrsr, SwSelBoxes& rBoxes );
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir // suche fuer eine AutoSumme die beteiligten Boxen zusammen
87*cdf0e10cSrcweir sal_Bool GetAutoSumSel( const SwCrsrShell&, SwCellFrms& );
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir // check if the SelBoxes contains protected Boxes
90*cdf0e10cSrcweir sal_Bool HasProtectedCells( const SwSelBoxes& rBoxes );
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir // teste, ob die Selektion ausgeglichen ist
93*cdf0e10cSrcweir SV_DECL_PTRARR( SwChartBoxes, SwTableBoxPtr, 16, 16)
94*cdf0e10cSrcweir SV_DECL_PTRARR_DEL( SwChartLines, SwChartBoxes*, 25, 50)
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir sal_Bool ChkChartSel( const SwNode& rSttNd, const SwNode& rEndNd,
97*cdf0e10cSrcweir 					SwChartLines* pGetCLines = 0 );
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir // teste ob die Celle in die SSelection gehoert
100*cdf0e10cSrcweir // (wurde eine Funktion, damit GetTblSel() und MakeTblCrsr() immer
101*cdf0e10cSrcweir // das "gleiche Verstaendnis" fuer die Selektion haben)
102*cdf0e10cSrcweir sal_Bool IsFrmInTblSel( const SwRect& rUnion, const SwFrm* pCell );
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir // bestimme die Boxen, die zusammen gefasst werden sollen.
105*cdf0e10cSrcweir // Dabei wird auf Layout Basis das Rechteck "angepasst". D.H. es
106*cdf0e10cSrcweir // werden Boxen zugefuegt wenn welche an den Seiten ueberlappen
107*cdf0e10cSrcweir // Zusaetzlich wird die neue Box erzeugt und mit dem entsprechenden
108*cdf0e10cSrcweir // Inhalt gefuellt.
109*cdf0e10cSrcweir void GetMergeSel( const SwPaM& rPam, SwSelBoxes& rBoxes,
110*cdf0e10cSrcweir 				  SwTableBox** ppMergeBox, SwUndoTblMerge* pUndo = 0 );
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir // teste ob die selektierten Boxen ein gueltiges Merge erlauben
113*cdf0e10cSrcweir sal_uInt16 CheckMergeSel( const SwPaM& rPam );
114*cdf0e10cSrcweir sal_uInt16 CheckMergeSel( const SwSelBoxes& rBoxes );
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir sal_Bool IsEmptyBox( const SwTableBox& rBox, SwPaM& rPam );
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir // teste ob ein Split oder InsertCol dazu fuehrt, das eine Box
119*cdf0e10cSrcweir // kleiner als MINLAY wird.
120*cdf0e10cSrcweir sal_Bool CheckSplitCells( const SwCrsrShell& rShell, sal_uInt16 nDiv,
121*cdf0e10cSrcweir 						const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
122*cdf0e10cSrcweir sal_Bool CheckSplitCells( const SwCursor& rCrsr, sal_uInt16 nDiv,
123*cdf0e10cSrcweir 						const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir //Fuer das Arbeiten auf TabSelektion auch fuer aufgespaltene Tabellen.
126*cdf0e10cSrcweir class SwSelUnion
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir 	SwRect   aUnion;		//Das die Sel umschliessende Rechteck.
129*cdf0e10cSrcweir 	SwTabFrm *pTable;		//Die (Follow-)Table zu der Union.
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir public:
132*cdf0e10cSrcweir 	SwSelUnion( const SwRect &rRect, SwTabFrm *pTab ) :
133*cdf0e10cSrcweir 		aUnion( rRect ), pTable( pTab ) {}
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	const SwRect&	GetUnion() const { return aUnion; }
136*cdf0e10cSrcweir 		  SwRect&	GetUnion()		 { return aUnion; }
137*cdf0e10cSrcweir 	const SwTabFrm *GetTable() const { return pTable; }
138*cdf0e10cSrcweir 		  SwTabFrm *GetTable()		 { return pTable; }
139*cdf0e10cSrcweir };
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir SV_DECL_PTRARR_DEL( SwSelUnions, SwSelUnion*, 10, 20 )
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir //Ermittelt die von einer Tabellenselektion betroffenen Tabellen und die
144*cdf0e10cSrcweir //Union-Rechteckte der Selektionen - auch fuer aufgespaltene Tabellen.
145*cdf0e10cSrcweir //Wenn ein Parameter != nsSwTblSearchType::TBLSEARCH_NONE uebergeben wird, so wird die
146*cdf0e10cSrcweir //Selektion in der angegebenen Richtung erweitert.
147*cdf0e10cSrcweir void MakeSelUnions( SwSelUnions&, const SwLayoutFrm *pStart,
148*cdf0e10cSrcweir 					const SwLayoutFrm *pEnd,
149*cdf0e10cSrcweir 					const SwTblSearchType = nsSwTblSearchType::TBLSEARCH_NONE );
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir // -------------------------------------------------------------------
153*cdf0e10cSrcweir // Diese Klassen kopieren die aktuelle Tabellen-Selektion (rBoxes)
154*cdf0e10cSrcweir // unter Beibehaltung der Tabellen-Strubktur in eine eigene Struktur
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir class _FndBox;
157*cdf0e10cSrcweir class _FndLine;
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir SV_DECL_PTRARR_DEL( _FndBoxes, _FndBox*, 10, 20 )
160*cdf0e10cSrcweir SV_DECL_PTRARR_DEL( _FndLines, _FndLine*,10, 20 )
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir class _FndBox
163*cdf0e10cSrcweir {
164*cdf0e10cSrcweir 	SwTableBox* pBox;
165*cdf0e10cSrcweir 	_FndLines aLines;
166*cdf0e10cSrcweir 	_FndLine* pUpper;
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 	SwTableLine *pLineBefore;	//Zum Loeschen/Restaurieren des Layouts.
169*cdf0e10cSrcweir 	SwTableLine *pLineBehind;
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir public:
172*cdf0e10cSrcweir 	_FndBox( SwTableBox* pB, _FndLine* pFL ) :
173*cdf0e10cSrcweir 		pBox(pB), pUpper(pFL), pLineBefore( 0 ), pLineBehind( 0 ) {}
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 	const _FndLines&	GetLines() const	{ return aLines; }
176*cdf0e10cSrcweir 		_FndLines& 		GetLines() 			{ return aLines; }
177*cdf0e10cSrcweir 	const SwTableBox* 	GetBox() const 		{ return pBox; }
178*cdf0e10cSrcweir 		SwTableBox* 	GetBox() 			{ return pBox; }
179*cdf0e10cSrcweir 	const _FndLine* 	GetUpper() const 	{ return pUpper; }
180*cdf0e10cSrcweir 		_FndLine* 		GetUpper() 			{ return pUpper; }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 	void SetTableLines( const SwSelBoxes &rBoxes, const SwTable &rTable );
183*cdf0e10cSrcweir 	void SetTableLines( const SwTable &rTable );
184*cdf0e10cSrcweir 	void DelFrms ( SwTable &rTable );
185*cdf0e10cSrcweir 	void MakeFrms( SwTable &rTable );
186*cdf0e10cSrcweir 	void MakeNewFrms( SwTable &rTable, const sal_uInt16 nNumber,
187*cdf0e10cSrcweir 									   const sal_Bool bBehind );
188*cdf0e10cSrcweir 	sal_Bool AreLinesToRestore( const SwTable &rTable ) const;
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir     void ClearLineBehind() { pLineBehind = 0; }
191*cdf0e10cSrcweir };
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir class _FndLine
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir 	SwTableLine* pLine;
197*cdf0e10cSrcweir 	_FndBoxes aBoxes;
198*cdf0e10cSrcweir 	_FndBox* pUpper;
199*cdf0e10cSrcweir public:
200*cdf0e10cSrcweir 	_FndLine(SwTableLine* pL, _FndBox* pFB=0) : pLine(pL), pUpper(pFB) {}
201*cdf0e10cSrcweir 	const _FndBoxes& 	GetBoxes() const 	{ return aBoxes; }
202*cdf0e10cSrcweir 		_FndBoxes& 		GetBoxes() 			{ return aBoxes; }
203*cdf0e10cSrcweir 	const SwTableLine* 	GetLine() const 	{ return pLine; }
204*cdf0e10cSrcweir 		SwTableLine* 	GetLine() 			{ return pLine; }
205*cdf0e10cSrcweir 	const _FndBox*	 	GetUpper() const 	{ return pUpper; }
206*cdf0e10cSrcweir 		_FndBox* 		GetUpper() 			{ return pUpper; }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 	void SetUpper( _FndBox* pUp ) { pUpper = pUp; }
209*cdf0e10cSrcweir };
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir struct _FndPara
213*cdf0e10cSrcweir {
214*cdf0e10cSrcweir 	const SwSelBoxes& rBoxes;
215*cdf0e10cSrcweir 	_FndLine* pFndLine;
216*cdf0e10cSrcweir 	_FndBox* pFndBox;
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 	_FndPara( const SwSelBoxes& rBxs, _FndBox* pFB )
219*cdf0e10cSrcweir 		: rBoxes(rBxs), pFndLine(0), pFndBox(pFB) {}
220*cdf0e10cSrcweir 	_FndPara( const _FndPara& rPara, _FndBox* pFB )
221*cdf0e10cSrcweir 		: rBoxes(rPara.rBoxes), pFndLine(rPara.pFndLine), pFndBox(pFB) {}
222*cdf0e10cSrcweir 	_FndPara( const _FndPara& rPara, _FndLine* pFL )
223*cdf0e10cSrcweir 		: rBoxes(rPara.rBoxes), pFndLine(pFL), pFndBox(rPara.pFndBox) {}
224*cdf0e10cSrcweir };
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir sal_Bool _FndBoxCopyCol( const SwTableBox*& rpBox, void* pPara );
227*cdf0e10cSrcweir SW_DLLPUBLIC sal_Bool _FndLineCopyCol( const SwTableLine*& rpLine, void* pPara );
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir #endif	//  _TBLSEL_HXX
231