xref: /trunk/main/sw/source/core/doc/gctable.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <hintids.hxx>
29cdf0e10cSrcweir #include <editeng/boxitem.hxx>
30cdf0e10cSrcweir #include <tblrwcl.hxx>
31cdf0e10cSrcweir #include <swtblfmt.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
GetLineTB(const SvxBoxItem * pBox,sal_Bool bTop)34cdf0e10cSrcweir inline const SvxBorderLine* GetLineTB( const SvxBoxItem* pBox, sal_Bool bTop )
35cdf0e10cSrcweir {
36cdf0e10cSrcweir     return bTop ? pBox->GetTop() : pBox->GetBottom();
37cdf0e10cSrcweir }
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
CheckLeftBorderOfFormat(const SwFrmFmt & rFmt)40cdf0e10cSrcweir sal_Bool _SwGCBorder_BoxBrd::CheckLeftBorderOfFormat( const SwFrmFmt& rFmt )
41cdf0e10cSrcweir {
42cdf0e10cSrcweir     const SvxBorderLine* pBrd;
43cdf0e10cSrcweir     const SfxPoolItem* pItem;
44cdf0e10cSrcweir     if( SFX_ITEM_SET == rFmt.GetItemState( RES_BOX, sal_True, &pItem ) &&
45cdf0e10cSrcweir         0 != ( pBrd = ((SvxBoxItem*)pItem)->GetLeft() ) )
46cdf0e10cSrcweir     {
47cdf0e10cSrcweir         if( *pBrdLn == *pBrd )
48cdf0e10cSrcweir             bAnyBorderFnd = sal_True;
49cdf0e10cSrcweir         return sal_True;
50cdf0e10cSrcweir     }
51cdf0e10cSrcweir     return sal_False;
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 
lcl_GCBorder_ChkBoxBrd_L(const SwTableLine * & rpLine,void * pPara)56cdf0e10cSrcweir sal_Bool lcl_GCBorder_ChkBoxBrd_L( const SwTableLine*& rpLine, void* pPara )
57cdf0e10cSrcweir {
58cdf0e10cSrcweir     const SwTableBox* pBox = rpLine->GetTabBoxes()[ 0 ];
59cdf0e10cSrcweir     return lcl_GCBorder_ChkBoxBrd_B( pBox, pPara );
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
lcl_GCBorder_ChkBoxBrd_B(const SwTableBox * & rpBox,void * pPara)62cdf0e10cSrcweir sal_Bool lcl_GCBorder_ChkBoxBrd_B( const SwTableBox*& rpBox, void* pPara )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir     sal_Bool bRet = sal_True;
65cdf0e10cSrcweir     if( rpBox->GetTabLines().Count() )
66cdf0e10cSrcweir     {
67cdf0e10cSrcweir         for( sal_uInt16 n = 0, nLines = rpBox->GetTabLines().Count();
68cdf0e10cSrcweir                 n < nLines && bRet; ++n )
69cdf0e10cSrcweir         {
70cdf0e10cSrcweir             const SwTableLine* pLine = rpBox->GetTabLines()[ n ];
71cdf0e10cSrcweir             bRet = lcl_GCBorder_ChkBoxBrd_L( pLine, pPara );
72cdf0e10cSrcweir         }
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir     else
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir         _SwGCBorder_BoxBrd* pBPara = (_SwGCBorder_BoxBrd*)pPara;
77cdf0e10cSrcweir         bRet = pBPara->CheckLeftBorderOfFormat( *rpBox->GetFrmFmt() );
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir     return bRet;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
lcl_GCBorder_GetLastBox_L(const SwTableLine * & rpLine,void * pPara)82cdf0e10cSrcweir sal_Bool lcl_GCBorder_GetLastBox_L( const SwTableLine*& rpLine, void* pPara )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     const SwTableBoxes& rBoxes = rpLine->GetTabBoxes();
85cdf0e10cSrcweir     const SwTableBox* pBox = rBoxes[ rBoxes.Count()-1 ];
86cdf0e10cSrcweir     ::lcl_GCBorder_GetLastBox_B( pBox, pPara );
87cdf0e10cSrcweir     return sal_True;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
lcl_GCBorder_GetLastBox_B(const SwTableBox * & rpBox,void * pPara)90cdf0e10cSrcweir sal_Bool lcl_GCBorder_GetLastBox_B( const SwTableBox*& rpBox, void* pPara )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir     SwTableLines& rLines = (SwTableLines&)rpBox->GetTabLines();
93cdf0e10cSrcweir     if( rLines.Count() )
94cdf0e10cSrcweir         rLines.ForEach( &lcl_GCBorder_GetLastBox_L, pPara );
95cdf0e10cSrcweir     else
96cdf0e10cSrcweir         ((SwTableBoxes*)pPara)->Insert( rpBox, ((SwTableBoxes*)pPara)->Count() );
97cdf0e10cSrcweir     return sal_True;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir // suche das "Ende" der vorgegebene BorderLine. Returnt wird die "Layout"Pos!
lcl_FindEndPosOfBorder(const SwCollectTblLineBoxes & rCollTLB,const SvxBorderLine & rBrdLn,sal_uInt16 & rStt,sal_Bool bTop)101cdf0e10cSrcweir sal_uInt16 lcl_FindEndPosOfBorder( const SwCollectTblLineBoxes& rCollTLB,
102cdf0e10cSrcweir                         const SvxBorderLine& rBrdLn, sal_uInt16& rStt, sal_Bool bTop )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     sal_uInt16 nPos, nLastPos = 0;
105cdf0e10cSrcweir     for( sal_uInt16 nEnd = rCollTLB.Count(); rStt < nEnd; ++rStt )
106cdf0e10cSrcweir     {
107cdf0e10cSrcweir         const SfxPoolItem* pItem;
108cdf0e10cSrcweir         const SvxBorderLine* pBrd;
109cdf0e10cSrcweir         const SwTableBox& rBox = rCollTLB.GetBox( rStt, &nPos );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir         if( SFX_ITEM_SET != rBox.GetFrmFmt()->GetItemState(RES_BOX,sal_True, &pItem )
112cdf0e10cSrcweir             || 0 == ( pBrd = GetLineTB( (SvxBoxItem*)pItem, bTop ))
113cdf0e10cSrcweir             || !( *pBrd == rBrdLn ))
114cdf0e10cSrcweir             break;
115cdf0e10cSrcweir         nLastPos = nPos;
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir     return nLastPos;
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
lcl_GCBorder_GetBorder(const SwTableBox & rBox,sal_Bool bTop,const SfxPoolItem ** ppItem)120cdf0e10cSrcweir inline const SvxBorderLine* lcl_GCBorder_GetBorder( const SwTableBox& rBox,
121cdf0e10cSrcweir                                                 sal_Bool bTop,
122cdf0e10cSrcweir                                                 const SfxPoolItem** ppItem )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     return SFX_ITEM_SET == rBox.GetFrmFmt()->GetItemState( RES_BOX, sal_True, ppItem )
125cdf0e10cSrcweir             ? GetLineTB( (SvxBoxItem*)*ppItem, bTop )
126cdf0e10cSrcweir             : 0;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
lcl_GCBorder_DelBorder(const SwCollectTblLineBoxes & rCollTLB,sal_uInt16 & rStt,sal_Bool bTop,const SvxBorderLine & rLine,const SfxPoolItem * pItem,sal_uInt16 nEndPos,SwShareBoxFmts * pShareFmts)129cdf0e10cSrcweir void lcl_GCBorder_DelBorder( const SwCollectTblLineBoxes& rCollTLB,
130cdf0e10cSrcweir                                 sal_uInt16& rStt, sal_Bool bTop,
131cdf0e10cSrcweir                                 const SvxBorderLine& rLine,
132cdf0e10cSrcweir                                 const SfxPoolItem* pItem,
133cdf0e10cSrcweir                                 sal_uInt16 nEndPos,
134cdf0e10cSrcweir                                 SwShareBoxFmts* pShareFmts )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     SwTableBox* pBox = (SwTableBox*)&rCollTLB.GetBox( rStt );
137cdf0e10cSrcweir     sal_uInt16 nNextPos;
138cdf0e10cSrcweir     const SvxBorderLine* pLn = &rLine;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     do {
141cdf0e10cSrcweir         if( pLn && *pLn == rLine )
142cdf0e10cSrcweir         {
143cdf0e10cSrcweir             SvxBoxItem aBox( *(SvxBoxItem*)pItem );
144cdf0e10cSrcweir             if( bTop )
145cdf0e10cSrcweir                 aBox.SetLine( 0, BOX_LINE_TOP );
146cdf0e10cSrcweir             else
147cdf0e10cSrcweir                 aBox.SetLine( 0, BOX_LINE_BOTTOM );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir             if( pShareFmts )
150cdf0e10cSrcweir                 pShareFmts->SetAttr( *pBox, aBox );
151cdf0e10cSrcweir             else
152cdf0e10cSrcweir                 pBox->ClaimFrmFmt()->SetFmtAttr( aBox );
153cdf0e10cSrcweir         }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         if( ++rStt >= rCollTLB.Count() )
156cdf0e10cSrcweir             break;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir         pBox = (SwTableBox*)&rCollTLB.GetBox( rStt, &nNextPos );
159cdf0e10cSrcweir         if( nNextPos > nEndPos )
160cdf0e10cSrcweir             break;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         pLn = lcl_GCBorder_GetBorder( *pBox, bTop, &pItem );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     } while( sal_True );
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 
lcl_GC_Line_Border(const SwTableLine * & rpLine,void * pPara)168cdf0e10cSrcweir sal_Bool lcl_GC_Line_Border( const SwTableLine*& rpLine, void* pPara )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     _SwGCLineBorder* pGCPara = (_SwGCLineBorder*)pPara;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     // zuerst die rechte Kante mit der linken Kante der naechsten Box
173cdf0e10cSrcweir     // innerhalb dieser Line
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         _SwGCBorder_BoxBrd aBPara;
176cdf0e10cSrcweir         const SvxBorderLine* pBrd;
177cdf0e10cSrcweir         const SfxPoolItem* pItem;
178cdf0e10cSrcweir         const SwTableBoxes& rBoxes = rpLine->GetTabBoxes();
179cdf0e10cSrcweir         for( sal_uInt16 n = 0, nBoxes = rBoxes.Count() - 1; n < nBoxes; ++n )
180cdf0e10cSrcweir         {
181cdf0e10cSrcweir             SwTableBoxes aBoxes;
182cdf0e10cSrcweir             {
183cdf0e10cSrcweir                 const SwTableBox* pBox = rBoxes[ n ];
184cdf0e10cSrcweir                 if( pBox->GetSttNd() )
185cdf0e10cSrcweir                     aBoxes.Insert( pBox, 0 );
186cdf0e10cSrcweir                 else
187cdf0e10cSrcweir                     lcl_GCBorder_GetLastBox_B( pBox, &aBoxes );
188cdf0e10cSrcweir             }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir             SwTableBox* pBox;
191cdf0e10cSrcweir             for( sal_uInt16 i = aBoxes.Count(); i; )
192cdf0e10cSrcweir                 if( SFX_ITEM_SET == (pBox = aBoxes[ --i ])->GetFrmFmt()->
193cdf0e10cSrcweir                     GetItemState( RES_BOX, sal_True, &pItem ) &&
194cdf0e10cSrcweir                     0 != ( pBrd = ((SvxBoxItem*)pItem)->GetRight() ) )
195cdf0e10cSrcweir                 {
196cdf0e10cSrcweir                     aBPara.SetBorder( *pBrd );
197cdf0e10cSrcweir                     const SwTableBox* pNextBox = rBoxes[n+1];
198cdf0e10cSrcweir                     if( lcl_GCBorder_ChkBoxBrd_B( pNextBox, &aBPara ) &&
199cdf0e10cSrcweir                         aBPara.IsAnyBorderFound() )
200cdf0e10cSrcweir                     {
201cdf0e10cSrcweir                         SvxBoxItem aBox( *(SvxBoxItem*)pItem );
202cdf0e10cSrcweir                         aBox.SetLine( 0, BOX_LINE_RIGHT );
203cdf0e10cSrcweir                         if( pGCPara->pShareFmts )
204cdf0e10cSrcweir                             pGCPara->pShareFmts->SetAttr( *pBox, aBox );
205cdf0e10cSrcweir                         else
206cdf0e10cSrcweir                             pBox->ClaimFrmFmt()->SetFmtAttr( aBox );
207cdf0e10cSrcweir                     }
208cdf0e10cSrcweir                 }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir             aBoxes.Remove( 0, aBoxes.Count() );
211cdf0e10cSrcweir         }
212cdf0e10cSrcweir     }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     // und jetzt die eigene untere Kante mit der nachfolgenden oberen Kante
215cdf0e10cSrcweir     if( !pGCPara->IsLastLine() )
216cdf0e10cSrcweir     {
217cdf0e10cSrcweir         SwCollectTblLineBoxes aBottom( sal_False );
218cdf0e10cSrcweir         SwCollectTblLineBoxes aTop( sal_True );
219cdf0e10cSrcweir 
220cdf0e10cSrcweir         ::lcl_Line_CollectBox( rpLine, &aBottom );
221cdf0e10cSrcweir 
222cdf0e10cSrcweir         const SwTableLine* pNextLine = (*pGCPara->pLines)[ pGCPara->nLinePos+1 ];
223cdf0e10cSrcweir         ::lcl_Line_CollectBox( pNextLine, &aTop );
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         // dann entferne mal alle "doppelten" gleichen Lines
226cdf0e10cSrcweir         sal_uInt16 nBtmPos, nTopPos,
227cdf0e10cSrcweir                 nSttBtm = 0, nSttTop = 0,
228cdf0e10cSrcweir                 nEndBtm = aBottom.Count(), nEndTop = aTop.Count();
229cdf0e10cSrcweir 
230cdf0e10cSrcweir         const SwTableBox *pBtmBox = &aBottom.GetBox( nSttBtm++, &nBtmPos ),
231cdf0e10cSrcweir                          *pTopBox = &aTop.GetBox( nSttTop++, &nTopPos );
232cdf0e10cSrcweir         const SfxPoolItem *pBtmItem = 0, *pTopItem = 0;
233cdf0e10cSrcweir         const SvxBorderLine *pBtmLine(0), *pTopLine(0);
234cdf0e10cSrcweir         sal_Bool bGetTopItem = sal_True, bGetBtmItem = sal_True;
235cdf0e10cSrcweir 
236cdf0e10cSrcweir         do {
237cdf0e10cSrcweir             if( bGetBtmItem )
238cdf0e10cSrcweir                 pBtmLine = lcl_GCBorder_GetBorder( *pBtmBox, sal_False, &pBtmItem );
239cdf0e10cSrcweir             if( bGetTopItem )
240cdf0e10cSrcweir                 pTopLine = lcl_GCBorder_GetBorder( *pTopBox, sal_True, &pTopItem );
241cdf0e10cSrcweir 
242cdf0e10cSrcweir             if( pTopLine && pBtmLine && *pTopLine == *pBtmLine )
243cdf0e10cSrcweir             {
244cdf0e10cSrcweir                 // dann kann einer entfernt werden, aber welche?
245cdf0e10cSrcweir                 sal_uInt16 nSavSttBtm = nSttBtm, nSavSttTop = nSttTop;
246cdf0e10cSrcweir                 sal_uInt16 nBtmEndPos = ::lcl_FindEndPosOfBorder( aBottom,
247cdf0e10cSrcweir                                                 *pTopLine, nSttBtm, sal_False );
248cdf0e10cSrcweir                 if( !nBtmEndPos ) nBtmEndPos = nBtmPos;
249cdf0e10cSrcweir                 sal_uInt16 nTopEndPos = ::lcl_FindEndPosOfBorder( aTop,
250cdf0e10cSrcweir                                                 *pTopLine, nSttTop, sal_True );
251cdf0e10cSrcweir                 if( !nTopEndPos ) nTopEndPos = nTopPos;
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 
254cdf0e10cSrcweir                 if( nTopEndPos <= nBtmEndPos )
255cdf0e10cSrcweir                 {
256cdf0e10cSrcweir                     // dann die TopBorder bis zur BottomEndPos loeschen
257cdf0e10cSrcweir                     nSttTop = nSavSttTop;
258cdf0e10cSrcweir                     if( nTopPos <= nBtmEndPos )
259cdf0e10cSrcweir                         lcl_GCBorder_DelBorder( aTop, --nSttTop, sal_True,
260cdf0e10cSrcweir                                             *pBtmLine, pTopItem, nBtmEndPos,
261cdf0e10cSrcweir                                             pGCPara->pShareFmts );
262cdf0e10cSrcweir                     else
263cdf0e10cSrcweir                         nSttBtm = nSavSttBtm;
264cdf0e10cSrcweir                 }
265cdf0e10cSrcweir                 else
266cdf0e10cSrcweir                 {
267cdf0e10cSrcweir                     // sonst die BottomBorder bis zur TopEndPos loeschen
268cdf0e10cSrcweir                     nSttBtm = nSavSttBtm;
269cdf0e10cSrcweir                     if( nBtmPos <= nTopEndPos )
270cdf0e10cSrcweir                         lcl_GCBorder_DelBorder( aBottom, --nSttBtm, sal_False,
271cdf0e10cSrcweir                                             *pTopLine, pBtmItem, nTopEndPos,
272cdf0e10cSrcweir                                             pGCPara->pShareFmts );
273cdf0e10cSrcweir                     else
274cdf0e10cSrcweir                         nSttTop = nSavSttTop;
275cdf0e10cSrcweir                 }
276cdf0e10cSrcweir                 nTopPos = nBtmPos;
277cdf0e10cSrcweir             }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir             if( nTopPos == nBtmPos )
280cdf0e10cSrcweir             {
281cdf0e10cSrcweir                 if( nSttBtm >= nEndBtm || nSttTop >= nEndTop )
282cdf0e10cSrcweir                     break;
283cdf0e10cSrcweir 
284cdf0e10cSrcweir                 pBtmBox = &aBottom.GetBox( nSttBtm++, &nBtmPos );
285cdf0e10cSrcweir                 pTopBox = &aTop.GetBox( nSttTop++, &nTopPos );
286cdf0e10cSrcweir                 bGetTopItem = bGetBtmItem = sal_True;
287cdf0e10cSrcweir             }
288cdf0e10cSrcweir             else if( nTopPos < nBtmPos )
289cdf0e10cSrcweir             {
290cdf0e10cSrcweir                 if( nSttTop >= nEndTop )
291cdf0e10cSrcweir                     break;
292cdf0e10cSrcweir                 pTopBox = &aTop.GetBox( nSttTop++, &nTopPos );
293cdf0e10cSrcweir                 bGetTopItem = sal_True;
294cdf0e10cSrcweir                 bGetBtmItem = sal_False;
295cdf0e10cSrcweir             }
296cdf0e10cSrcweir             else
297cdf0e10cSrcweir             {
298cdf0e10cSrcweir                 if( nSttBtm >= nEndBtm )
299cdf0e10cSrcweir                     break;
300cdf0e10cSrcweir                 pBtmBox = &aBottom.GetBox( nSttBtm++, &nBtmPos );
301cdf0e10cSrcweir                 bGetTopItem = sal_False;
302cdf0e10cSrcweir                 bGetBtmItem = sal_True;
303cdf0e10cSrcweir             }
304cdf0e10cSrcweir 
305cdf0e10cSrcweir         } while( sal_True );
306cdf0e10cSrcweir     }
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     ((SwTableLine*)rpLine)->GetTabBoxes().ForEach( &lcl_GC_Box_Border, pPara );
309cdf0e10cSrcweir 
310cdf0e10cSrcweir     ++pGCPara->nLinePos;
311cdf0e10cSrcweir 
312cdf0e10cSrcweir     return sal_True;
313cdf0e10cSrcweir }
314cdf0e10cSrcweir 
lcl_GC_Box_Border(const SwTableBox * & rpBox,void * pPara)315cdf0e10cSrcweir sal_Bool lcl_GC_Box_Border( const SwTableBox*& rpBox, void* pPara )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir     if( rpBox->GetTabLines().Count() )
318cdf0e10cSrcweir     {
319cdf0e10cSrcweir         _SwGCLineBorder aPara( *rpBox );
320cdf0e10cSrcweir         aPara.pShareFmts = ((_SwGCLineBorder*)pPara)->pShareFmts;
321cdf0e10cSrcweir         ((SwTableBox*)rpBox)->GetTabLines().ForEach( &lcl_GC_Line_Border, &aPara );
322cdf0e10cSrcweir     }
323cdf0e10cSrcweir     return sal_True;
324cdf0e10cSrcweir }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir struct _GCLinePara
327cdf0e10cSrcweir {
328cdf0e10cSrcweir     SwTableLines* pLns;
329cdf0e10cSrcweir     SwShareBoxFmts* pShareFmts;
330cdf0e10cSrcweir 
_GCLinePara_GCLinePara331cdf0e10cSrcweir     _GCLinePara( SwTableLines& rLns, _GCLinePara* pPara = 0 )
332cdf0e10cSrcweir         : pLns( &rLns ), pShareFmts( pPara ? pPara->pShareFmts : 0 )
333cdf0e10cSrcweir     {}
334cdf0e10cSrcweir };
335cdf0e10cSrcweir 
lcl_MergeGCBox(const SwTableBox * & rpTblBox,void * pPara)336cdf0e10cSrcweir sal_Bool lcl_MergeGCBox( const SwTableBox*& rpTblBox, void* pPara )
337cdf0e10cSrcweir {
338cdf0e10cSrcweir     SwTableBox*& rpBox = (SwTableBox*&)rpTblBox;
339cdf0e10cSrcweir     sal_uInt16 n, nLen = rpBox->GetTabLines().Count();
340cdf0e10cSrcweir     if( nLen )
341cdf0e10cSrcweir     {
342cdf0e10cSrcweir         // ACHTUNG: die Anzahl der Lines kann sich aendern!
343cdf0e10cSrcweir         _GCLinePara aPara( rpBox->GetTabLines(), (_GCLinePara*)pPara );
344cdf0e10cSrcweir         for( n = 0; n < rpBox->GetTabLines().Count() &&
345cdf0e10cSrcweir             lcl_MergeGCLine( *(rpBox->GetTabLines().GetData() + n), &aPara );
346cdf0e10cSrcweir             ++n )
347cdf0e10cSrcweir             ;
348cdf0e10cSrcweir 
349cdf0e10cSrcweir         if( 1 == rpBox->GetTabLines().Count() )
350cdf0e10cSrcweir         {
351cdf0e10cSrcweir             // Box mit einer Line, dann verschiebe alle Boxen der Line
352cdf0e10cSrcweir             // hinter diese Box in der Parent-Line und loesche diese Box
353cdf0e10cSrcweir             SwTableLine* pInsLine = rpBox->GetUpper();
354cdf0e10cSrcweir             SwTableLine* pCpyLine = rpBox->GetTabLines()[0];
355cdf0e10cSrcweir             sal_uInt16 nInsPos = pInsLine->GetTabBoxes().C40_GETPOS( SwTableBox, rpBox );
356cdf0e10cSrcweir             for( n = 0; n < pCpyLine->GetTabBoxes().Count(); ++n )
357cdf0e10cSrcweir                 pCpyLine->GetTabBoxes()[n]->SetUpper( pInsLine );
358cdf0e10cSrcweir 
359cdf0e10cSrcweir             pInsLine->GetTabBoxes().Insert( &pCpyLine->GetTabBoxes(), nInsPos+1 );
360cdf0e10cSrcweir             pCpyLine->GetTabBoxes().Remove( 0, n );
361cdf0e10cSrcweir             // loesche alte die Box mit der Line
362cdf0e10cSrcweir             pInsLine->GetTabBoxes().DeleteAndDestroy( nInsPos );
363cdf0e10cSrcweir 
364cdf0e10cSrcweir             return sal_False;       // neu aufsetzen
365cdf0e10cSrcweir         }
366cdf0e10cSrcweir     }
367cdf0e10cSrcweir     return sal_True;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
lcl_MergeGCLine(const SwTableLine * & rpLine,void * pPara)370cdf0e10cSrcweir sal_Bool lcl_MergeGCLine( const SwTableLine*& rpLine, void* pPara )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir     SwTableLine* pLn = (SwTableLine*)rpLine;
373cdf0e10cSrcweir     sal_uInt16 nLen = pLn->GetTabBoxes().Count();
374cdf0e10cSrcweir     if( nLen )
375cdf0e10cSrcweir     {
376cdf0e10cSrcweir         _GCLinePara* pGCPara = (_GCLinePara*)pPara;
377cdf0e10cSrcweir         while( 1 == nLen )
378cdf0e10cSrcweir         {
379cdf0e10cSrcweir             // es gibt eine Box mit Lines
380cdf0e10cSrcweir             SwTableBox* pBox = pLn->GetTabBoxes()[0];
381cdf0e10cSrcweir             if( !pBox->GetTabLines().Count() )
382cdf0e10cSrcweir                 break;
383cdf0e10cSrcweir 
384cdf0e10cSrcweir             SwTableLine* pLine = pBox->GetTabLines()[0];
385cdf0e10cSrcweir 
386cdf0e10cSrcweir             // pLine wird zu der aktuellen, also der rpLine,
387cdf0e10cSrcweir             // die restlichen werden ins LinesArray hinter der akt.
388cdf0e10cSrcweir             // verschoben.
389cdf0e10cSrcweir             // Das LinesArray ist im pPara!
390cdf0e10cSrcweir             nLen = pBox->GetTabLines().Count();
391cdf0e10cSrcweir 
392cdf0e10cSrcweir             SwTableLines& rLns = *pGCPara->pLns;
393cdf0e10cSrcweir             const SwTableLine* pTmp = pLn;
394cdf0e10cSrcweir             sal_uInt16 nInsPos = rLns.GetPos( pTmp );
395cdf0e10cSrcweir             ASSERT( USHRT_MAX != nInsPos, "Line nicht gefunden!" );
396cdf0e10cSrcweir 
397cdf0e10cSrcweir             SwTableBox* pUpper = pLn->GetUpper();
398cdf0e10cSrcweir 
399cdf0e10cSrcweir             rLns.Remove( nInsPos, 1 );      // die Line dem aus Array loeschen
400cdf0e10cSrcweir             rLns.Insert( &pBox->GetTabLines(), nInsPos );
401cdf0e10cSrcweir 
402cdf0e10cSrcweir             // JP 31.03.99: Bug 60000 - die Attribute der zu loeschenden
403cdf0e10cSrcweir             // Line an die "eingefuegten" uebertragen
404cdf0e10cSrcweir             const SfxPoolItem* pItem;
405cdf0e10cSrcweir             if( SFX_ITEM_SET == pLn->GetFrmFmt()->GetItemState(
406cdf0e10cSrcweir                                     RES_BACKGROUND, sal_True, &pItem ))
407cdf0e10cSrcweir             {
408cdf0e10cSrcweir                 SwTableLines& rBoxLns = pBox->GetTabLines();
409cdf0e10cSrcweir                 for( sal_uInt16 nLns = 0; nLns < nLen; ++nLns )
410cdf0e10cSrcweir                     if( SFX_ITEM_SET != rBoxLns[ nLns ]->GetFrmFmt()->
411cdf0e10cSrcweir                             GetItemState( RES_BACKGROUND, sal_True ))
412cdf0e10cSrcweir                         pGCPara->pShareFmts->SetAttr( *rBoxLns[ nLns ], *pItem );
413cdf0e10cSrcweir             }
414cdf0e10cSrcweir 
415cdf0e10cSrcweir             pBox->GetTabLines().Remove( 0, nLen );  // Lines aus Array loeschen
416cdf0e10cSrcweir 
417cdf0e10cSrcweir             delete pLn;
418cdf0e10cSrcweir 
419cdf0e10cSrcweir             // Abhaengigkeit neu setzen
420cdf0e10cSrcweir             while( nLen-- )
421cdf0e10cSrcweir                 rLns[ nInsPos++ ]->SetUpper( pUpper );
422cdf0e10cSrcweir 
423cdf0e10cSrcweir             pLn = pLine;                        // und neu setzen
424cdf0e10cSrcweir             nLen = pLn->GetTabBoxes().Count();
425cdf0e10cSrcweir         }
426cdf0e10cSrcweir 
427cdf0e10cSrcweir         // ACHTUNG: die Anzahl der Boxen kann sich aendern!
428cdf0e10cSrcweir         for( nLen = 0; nLen < pLn->GetTabBoxes().Count(); ++nLen )
429cdf0e10cSrcweir             if( !lcl_MergeGCBox( *(pLn->GetTabBoxes().GetData() + nLen ), pPara ))
430cdf0e10cSrcweir                 --nLen;
431cdf0e10cSrcweir     }
432cdf0e10cSrcweir     return sal_True;
433cdf0e10cSrcweir }
434cdf0e10cSrcweir 
435cdf0e10cSrcweir         // Struktur ein wenig aufraeumen
GCLines()436cdf0e10cSrcweir void SwTable::GCLines()
437cdf0e10cSrcweir {
438cdf0e10cSrcweir     // ACHTUNG: die Anzahl der Lines kann sich aendern!
439cdf0e10cSrcweir     _GCLinePara aPara( GetTabLines() );
440cdf0e10cSrcweir     SwShareBoxFmts aShareFmts;
441cdf0e10cSrcweir     aPara.pShareFmts = &aShareFmts;
442cdf0e10cSrcweir     for( sal_uInt16 n = 0; n < GetTabLines().Count() &&
443cdf0e10cSrcweir             lcl_MergeGCLine( *(GetTabLines().GetData() + n ), &aPara ); ++n )
444cdf0e10cSrcweir         ;
445cdf0e10cSrcweir }
446