xref: /trunk/main/sw/source/core/inc/tblrwcl.hxx (revision cdf0e10c)
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 _TBLRWCL_HXX
28 #define _TBLRWCL_HXX
29 #ifndef _SVSTDARR_HXX
30 #define _SVSTDARR_USHORTS
31 #include <svl/svstdarr.hxx>
32 #endif
33 #include <vector>
34 #include <swtypes.hxx>
35 #include <tblsel.hxx>
36 #include <swtable.hxx>
37 
38 class SvxBorderLine;
39 class SwDoc;
40 class SwTableNode;
41 class _FndLine;
42 class _FndBox;
43 class SwTableLine;
44 class SwTableBox;
45 class SwTableBoxFmt;
46 class SwHistory;
47 class SwCntntNode;
48 class SfxPoolItem;
49 class SwShareBoxFmts;
50 class SwFmtFrmSize;
51 
52 // Funktions Deklarationen:
53 sal_Bool lcl_CopyRow( const _FndLine*& rpFndLine, void* pPara );
54 sal_Bool lcl_CopyCol( const _FndBox*& rpFndBox, void* pPara );
55 
56 sal_Bool lcl_MergeGCBox( const SwTableBox*& rpBox, void* pPara );
57 sal_Bool lcl_MergeGCLine( const SwTableLine*& rpLine, void* pPara );
58 
59 sal_Bool lcl_Merge_MoveBox( const _FndBox*& rpFndBox, void* pPara );
60 sal_Bool lcl_Merge_MoveLine( const _FndLine*& rpFndLine, void* pPara );
61 
62 sal_Bool lcl_CopyBoxToDoc( const _FndBox*& rpFndBox, void* pPara );
63 sal_Bool lcl_CopyLineToDoc( const _FndLine*& rpFndLn, void* pPara );
64 
65 sal_Bool lcl_BoxSetHeadCondColl( const SwTableBox*& rpBox, void* pPara );
66 sal_Bool lcl_LineSetHeadCondColl( const SwTableLine*& rpLine, void* pPara );
67 
68 
69 #ifdef DBG_UTIL
70 void _CheckBoxWidth( const SwTableLine& rLine, SwTwips nSize );
71 #endif
72 
73 void _InsTblBox( SwDoc* pDoc, SwTableNode* pTblNd,
74 				SwTableLine* pLine, SwTableBoxFmt* pBoxFrmFmt,
75 				SwTableBox* pBox, sal_uInt16 nInsPos, sal_uInt16 nCnt = 1 );
76 
77 SW_DLLPUBLIC void _DeleteBox( SwTable& rTbl, SwTableBox* pBox, SwUndo* pUndo = 0,
78 				sal_Bool bCalcNewSize = sal_True, const sal_Bool bCorrBorder = sal_True,
79 				SwShareBoxFmts* pShareFmts = 0 );
80 
81 // Klasse fuers SplitTable
82 // sammelt von einer Line die Boxen aller obersten oder untersten Lines
83 // in einem Array. Zusaetzlich werden die Positionen vermerkt.
84 // ( die Implementierung steht im ndtbl.cxx)
85 
86 class SwCollectTblLineBoxes
87 {
88 	SvUShorts aPosArr;
89 	SwSelBoxes_SAR aBoxes;
90 	SwHistory* pHst;
91 	sal_uInt16 nMode, nWidth;
92 	sal_Bool bGetFromTop : 1;
93 	sal_Bool bGetValues : 1;
94 
95 public:
96 	SwCollectTblLineBoxes( sal_Bool bTop, sal_uInt16 nMd = 0, SwHistory* pHist=0 )
97 		: aPosArr( 16, 16 ), aBoxes( 16, 16 ),
98 		pHst( pHist ), nMode( nMd ), nWidth( 0 ),
99 		bGetFromTop( bTop ), bGetValues( sal_True )
100 
101 	{}
102 
103 	void AddBox( const SwTableBox& rBox );
104 	const SwTableBox* GetBoxOfPos( const SwTableBox& rBox );
105 	void AddToUndoHistory( const SwCntntNode& rNd );
106 
107 	sal_uInt16 Count() const				{ return aBoxes.Count(); }
108 	const SwTableBox& GetBox( sal_uInt16 nPos, sal_uInt16* pWidth = 0 ) const
109 		{
110 			// hier wird die EndPos der Spalte benoetigt!
111 			if( pWidth )
112 				*pWidth = nPos+1 == aPosArr.Count() ? nWidth
113 													: aPosArr[ nPos+1 ];
114 			return *aBoxes[ nPos ];
115 		}
116 
117 	sal_Bool IsGetFromTop() const 			{ return bGetFromTop; }
118 	sal_Bool IsGetValues() const			{ return bGetValues; }
119 
120 	sal_uInt16 GetMode() const				{ return nMode; }
121 	void SetValues( sal_Bool bFlag )		{ bGetValues = sal_False; nWidth = 0;
122 										  bGetFromTop = bFlag; }
123 	sal_Bool Resize( sal_uInt16 nOffset, sal_uInt16 nWidth );
124 };
125 
126 sal_Bool lcl_Box_CollectBox( const SwTableBox*& rpBox, void* pPara );
127 sal_Bool lcl_Line_CollectBox( const SwTableLine*& rpLine, void* pPara );
128 
129 sal_Bool lcl_BoxSetSplitBoxFmts( const SwTableBox*& rpBox, void* pPara );
130 
131 // This structure is needed by Undo to restore row span attributes
132 // when a table has been splitted into two tables
133 struct SwSaveRowSpan
134 {
135     sal_uInt16 mnSplitLine; // the line number where the table has been splitted
136     std::vector< long > mnRowSpans; // the row span attributes in this line
137     SwSaveRowSpan( SwTableBoxes& rBoxes, sal_uInt16 nSplitLn );
138 };
139 
140 struct _SwGCLineBorder
141 {
142 	const SwTableLines* pLines;
143 	SwShareBoxFmts* pShareFmts;
144 	sal_uInt16 nLinePos;
145 
146 	_SwGCLineBorder( const SwTable& rTable )
147 		: pLines( &rTable.GetTabLines() ), pShareFmts(0), nLinePos( 0 )  {}
148 
149 	_SwGCLineBorder( const SwTableBox& rBox )
150 		: pLines( &rBox.GetTabLines() ), pShareFmts(0), nLinePos( 0 )  {}
151 	sal_Bool IsLastLine() const { return nLinePos + 1 >= pLines->Count(); }
152 };
153 
154 class _SwGCBorder_BoxBrd
155 {
156 	const SvxBorderLine* pBrdLn;
157 	sal_Bool bAnyBorderFnd;
158 public:
159 	_SwGCBorder_BoxBrd() : pBrdLn( 0 ), bAnyBorderFnd( sal_False ) {}
160 
161 	void SetBorder( const SvxBorderLine& rBorderLine )
162 		{ pBrdLn = &rBorderLine; bAnyBorderFnd = sal_False; }
163 
164 	// checke, ob die linke Border dieselbe wie die gesetzte ist
165 	// returnt sal_False falls gar keine Border gesetzt ist
166 	sal_Bool CheckLeftBorderOfFormat( const SwFrmFmt& rFmt );
167 
168 	sal_Bool IsAnyBorderFound() const { return bAnyBorderFnd; }
169 };
170 
171 sal_Bool lcl_GC_Line_Border( const SwTableLine*& , void* pPara );
172 sal_Bool lcl_GC_Box_Border( const SwTableBox*& , void* pPara );
173 
174 sal_Bool lcl_GCBorder_ChkBoxBrd_L( const SwTableLine*& , void* pPara );
175 sal_Bool lcl_GCBorder_ChkBoxBrd_B( const SwTableBox*& , void* pPara );
176 
177 sal_Bool lcl_GCBorder_GetLastBox_L( const SwTableLine*& , void* pPara );
178 sal_Bool lcl_GCBorder_GetLastBox_B( const SwTableBox*& , void* pPara );
179 
180 
181 class SwShareBoxFmt
182 {
183 	const SwFrmFmt* pOldFmt;
184 	SvPtrarr aNewFmts;
185 
186 public:
187 	SwShareBoxFmt( const SwFrmFmt& rFmt )
188 		: pOldFmt( &rFmt ), aNewFmts( 1, 4 )
189 	{}
190 
191 	const SwFrmFmt& GetOldFormat() const { return *pOldFmt; }
192 
193 	SwFrmFmt* GetFormat( long nWidth ) const;
194 	SwFrmFmt* GetFormat( const SfxPoolItem& rItem ) const;
195 	void AddFormat( const SwFrmFmt& rFmt );
196 	// returnt sal_True, wenn geloescht werden kann
197 	sal_Bool RemoveFormat( const SwFrmFmt& rFmt );
198 };
199 
200 
201 SV_DECL_PTRARR_DEL( _SwShareBoxFmts, SwShareBoxFmt*, 8, 8 )
202 
203 class SwShareBoxFmts
204 {
205 	_SwShareBoxFmts aShareArr;
206 	sal_Bool Seek_Entry( const SwFrmFmt& rFmt, sal_uInt16* pPos ) const;
207 
208 	void ChangeFrmFmt( SwTableBox* pBox, SwTableLine* pLn, SwFrmFmt& rFmt );
209 
210 public:
211 	SwShareBoxFmts() {}
212 	~SwShareBoxFmts();
213 
214 	SwFrmFmt* GetFormat( const SwFrmFmt& rFmt, long nWidth ) const;
215 	SwFrmFmt* GetFormat( const SwFrmFmt& rFmt, const SfxPoolItem& ) const;
216 
217 	void AddFormat( const SwFrmFmt& rOld, const SwFrmFmt& rNew );
218 
219 	void SetSize( SwTableBox& rBox, const SwFmtFrmSize& rSz );
220 	void SetAttr( SwTableBox& rBox, const SfxPoolItem& rItem );
221 	void SetAttr( SwTableLine& rLine, const SfxPoolItem& rItem );
222 
223 	void RemoveFormat( const SwFrmFmt& rFmt );
224 };
225 
226 
227 
228 #endif
229