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