xref: /aoo42x/main/sw/source/core/layout/fly.cxx (revision 72aeb479)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 #include "hintids.hxx"
27 #include <svl/itemiter.hxx>
28 #include <svtools/imap.hxx>
29 #include <vcl/graph.hxx>
30 #include <tools/poly.hxx>
31 #include <svx/contdlg.hxx>
32 #include <editeng/protitem.hxx>
33 #include <editeng/opaqitem.hxx>
34 #include <editeng/ulspitem.hxx>
35 #include <editeng/lrspitem.hxx>
36 #include <editeng/frmdiritem.hxx>
37 #include <editeng/keepitem.hxx>
38 #include <fmtanchr.hxx>
39 #include <fmtfsize.hxx>
40 #include <fmtclds.hxx>
41 #include <fmtcntnt.hxx>
42 #include <fmturl.hxx>
43 #include <fmtsrnd.hxx>
44 #include <fmtornt.hxx>
45 #include <fmtpdsc.hxx>
46 #include <fmtcnct.hxx>
47 #include <layhelp.hxx>
48 #include <ndtxt.hxx>
49 #include <svx/svdogrp.hxx>
50 #include <ndgrf.hxx>
51 #include <tolayoutanchoredobjectposition.hxx>
52 #include <fmtfollowtextflow.hxx>
53 #include <sortedobjs.hxx>
54 #include <objectformatter.hxx>
55 #include <anchoredobject.hxx>
56 #include <ndole.hxx>
57 #include <swtable.hxx>
58 #include <svx/svdpage.hxx>
59 #include "doc.hxx"
60 #include "viewsh.hxx"
61 #include "layouter.hxx"
62 #include "pagefrm.hxx"
63 #include "rootfrm.hxx"
64 #include "cntfrm.hxx"
65 #include "pam.hxx"
66 #include "frmatr.hxx"
67 #include "viewimp.hxx"
68 #include "viewopt.hxx"
69 #include "errhdl.hxx"
70 #include "dcontact.hxx"
71 #include "dflyobj.hxx"
72 #include "dview.hxx"
73 #include "flyfrm.hxx"
74 #include "frmtool.hxx"
75 #include "frmfmt.hxx"
76 #include "hints.hxx"
77 #include "swregion.hxx"
78 #include "tabfrm.hxx"
79 #include "txtfrm.hxx"
80 #include "ndnotxt.hxx"
81 #include "notxtfrm.hxx"   // GetGrfArea
82 #include "flyfrms.hxx"
83 #include "ndindex.hxx"   // GetGrfArea
84 #include "sectfrm.hxx"
85 #include <vcl/svapp.hxx>
86 #include <vcl/salbtype.hxx>		// FRound
87 #include "switerator.hxx"
88 
89 using namespace ::com::sun::star;
90 
91 
92 // OD 2004-03-23 #i26791
93 TYPEINIT2(SwFlyFrm,SwLayoutFrm,SwAnchoredObject);
94 
95 /*************************************************************************
96 |*
97 |*	SwFlyFrm::SwFlyFrm()
98 |*
99 |*	Ersterstellung		MA 28. Sep. 92
100 |*	Letzte Aenderung	MA 09. Apr. 99
101 |*
102 |*************************************************************************/
103 
104 SwFlyFrm::SwFlyFrm( SwFlyFrmFmt *pFmt, SwFrm* pSib, SwFrm *pAnch ) :
105 	SwLayoutFrm( pFmt, pSib ),
106     // OD 2004-03-22 #i26791#
107     SwAnchoredObject(),
108     // OD 2004-05-27 #i26791# - moved to <SwAnchoredObject>
109 //    aRelPos(),
110 	pPrevLink( 0 ),
111 	pNextLink( 0 ),
112 	bInCnt( sal_False ),
113 	bAtCnt( sal_False ),
114 	bLayout( sal_False ),
115     bAutoPosition( sal_False ),
116     bNoShrink( sal_False ),
117     bLockDeleteContent( sal_False )
118 {
119     nType = FRMC_FLY;
120 
121 	bInvalid = bNotifyBack = sal_True;
122 	bLocked  = bMinHeight =
123 	bHeightClipped = bWidthClipped = bFormatHeightOnly = sal_False;
124 
125 	//Grosseneinstellung, Fixe groesse ist immer die Breite
126 	const SwFmtFrmSize &rFrmSize = pFmt->GetFrmSize();
127     sal_Bool bVert = sal_False;
128     sal_uInt16 nDir =
129         ((SvxFrameDirectionItem&)pFmt->GetFmtAttr( RES_FRAMEDIR )).GetValue();
130     if( FRMDIR_ENVIRONMENT == nDir )
131     {
132         bDerivedVert = 1;
133         bDerivedR2L = 1;
134         if( pAnch && pAnch->IsVertical() )
135             bVert = sal_True;
136     }
137     else
138     {
139         bInvalidVert = 0;
140         bDerivedVert = 0;
141         bDerivedR2L = 0;
142         if( FRMDIR_HORI_LEFT_TOP == nDir || FRMDIR_HORI_RIGHT_TOP == nDir )
143         {
144             //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
145             bVertLR = 0;
146             bVertical = 0;
147 		}
148         else
149         {
150             const ViewShell *pSh = getRootFrm() ? getRootFrm()->GetCurrShell() : 0;
151             if( pSh && pSh->GetViewOptions()->getBrowseMode() )
152             {
153                 //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
154                 bVertLR = 0;
155                 bVertical = 0;
156             }
157             else
158             {
159                 bVertical = 1;
160                 //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
161             	if ( FRMDIR_VERT_TOP_LEFT == nDir )
162                 	bVertLR = 1;
163                 else
164                 	bVertLR = 0;
165             }
166         }
167 
168         bVert = bVertical;
169         bInvalidR2L = 0;
170         if( FRMDIR_HORI_RIGHT_TOP == nDir )
171             bRightToLeft = 1;
172         else
173             bRightToLeft = 0;
174     }
175 
176     Frm().Width( rFrmSize.GetWidth() );
177     Frm().Height( rFrmSize.GetHeightSizeType() == ATT_VAR_SIZE ? MINFLY : rFrmSize.GetHeight() );
178 
179 	//Hoehe Fix oder Variabel oder was?
180     if ( rFrmSize.GetHeightSizeType() == ATT_MIN_SIZE )
181 		bMinHeight = sal_True;
182     else if ( rFrmSize.GetHeightSizeType() == ATT_FIX_SIZE )
183         bFixSize = sal_True;
184 
185     // OD 2004-02-12 #110582#-2 - insert columns, if necessary
186     InsertColumns();
187 
188 	//Erst das Init, dann den Inhalt, denn zum Inhalt koennen  widerum
189 	//Objekte/Rahmen gehoeren die dann angemeldet werden.
190     InitDrawObj( sal_False );
191 
192     // OD 2004-01-19 #110582#
193     Chain( pAnch );
194 
195     // OD 2004-01-19 #110582#
196     InsertCnt();
197 
198 	//Und erstmal in den Wald stellen die Kiste, damit bei neuen Dokument nicht
199 	//unnoetig viel formatiert wird.
200 	Frm().Pos().X() = Frm().Pos().Y() = WEIT_WECH;
201 }
202 
203 // OD 2004-01-19 #110582#
204 void SwFlyFrm::Chain( SwFrm* _pAnch )
205 {
206     // Connect to chain neighboors.
207     // No problem, if a neighboor doesn't exist - the construction of the
208     // neighboor will make the connection
209     const SwFmtChain& rChain = GetFmt()->GetChain();
210     if ( rChain.GetPrev() || rChain.GetNext() )
211     {
212         if ( rChain.GetNext() )
213         {
214             SwFlyFrm* pFollow = FindChainNeighbour( *rChain.GetNext(), _pAnch );
215             if ( pFollow )
216             {
217                 ASSERT( !pFollow->GetPrevLink(), "wrong chain detected" );
218                 if ( !pFollow->GetPrevLink() )
219                     SwFlyFrm::ChainFrames( this, pFollow );
220             }
221         }
222         if ( rChain.GetPrev() )
223         {
224             SwFlyFrm *pMaster = FindChainNeighbour( *rChain.GetPrev(), _pAnch );
225             if ( pMaster )
226             {
227                 ASSERT( !pMaster->GetNextLink(), "wrong chain detected" );
228                 if ( !pMaster->GetNextLink() )
229                     SwFlyFrm::ChainFrames( pMaster, this );
230             }
231         }
232     }
233 }
234 
235 // OD 2004-01-19 #110582#
236 void SwFlyFrm::InsertCnt()
237 {
238     if ( !GetPrevLink() )
239     {
240         const SwFmtCntnt& rCntnt = GetFmt()->GetCntnt();
241         ASSERT( rCntnt.GetCntntIdx(), ":-( no content prepared." );
242         sal_uLong nIndex = rCntnt.GetCntntIdx()->GetIndex();
243         // Lower() bedeutet SwColumnFrm, eingefuegt werden muss der Inhalt dann in den (Column)BodyFrm
244         ::_InsertCnt( Lower() ? (SwLayoutFrm*)((SwLayoutFrm*)Lower())->Lower() : (SwLayoutFrm*)this,
245                       GetFmt()->GetDoc(), nIndex );
246 
247         //NoTxt haben immer eine FixHeight.
248         if ( Lower() && Lower()->IsNoTxtFrm() )
249         {
250             bFixSize = sal_True;
251             bMinHeight = sal_False;
252         }
253     }
254 }
255 
256  // OD 2004-02-12 #110582#-2
257  void SwFlyFrm::InsertColumns()
258  {
259     // --> OD 2009-08-12 #i97379#
260     // Check, if column are allowed.
261     // Columns are not allowed for fly frames, which represent graphics or embedded objects.
262     const SwFmtCntnt& rCntnt = GetFmt()->GetCntnt();
263     ASSERT( rCntnt.GetCntntIdx(), "<SwFlyFrm::InsertColumns()> - no content prepared." );
264     SwNodeIndex aFirstCntnt( *(rCntnt.GetCntntIdx()), 1 );
265     if ( aFirstCntnt.GetNode().IsNoTxtNode() )
266     {
267         return;
268     }
269     // <--
270 
271     const SwFmtCol &rCol = GetFmt()->GetCol();
272     if ( rCol.GetNumCols() > 1 )
273     {
274         //PrtArea ersteinmal so gross wie der Frm, damit die Spalten
275         //vernuenftig eingesetzt werden koennen; das schaukelt sich dann
276         //schon zurecht.
277         Prt().Width( Frm().Width() );
278         Prt().Height( Frm().Height() );
279         const SwFmtCol aOld; //ChgColumns() verlaesst sich darauf, dass auch ein
280                              //Old-Wert hereingereicht wird.
281         ChgColumns( aOld, rCol );
282     }
283  }
284 
285 /*************************************************************************
286 |*
287 |*	SwFlyFrm::~SwFlyFrm()
288 |*
289 |*	Ersterstellung		MA 28. Sep. 92
290 |*	Letzte Aenderung	MA 07. Jul. 95
291 |*
292 |*************************************************************************/
293 
294 SwFlyFrm::~SwFlyFrm()
295 {
296 	// Accessible objects for fly frames will be destroyed in this destructor.
297 	// For frames bound as char or frames that don't have an anchor we have
298 	// to do that ourselves. For any other frame the call RemoveFly at the
299 	// anchor will do that.
300     if( IsAccessibleFrm() && GetFmt() && (IsFlyInCntFrm() || !GetAnchorFrm()) )
301 	{
302 		SwRootFrm *pRootFrm = getRootFrm();
303 		if( pRootFrm && pRootFrm->IsAnyShellAccessible() )
304 		{
305 			ViewShell *pVSh = pRootFrm->GetCurrShell();
306 			if( pVSh && pVSh->Imp() )
307 			{
308 				// Lowers aren't disposed already, so we have to do a recursive
309 				// dispose
310 				pVSh->Imp()->DisposeAccessibleFrm( this, sal_True );
311 			}
312 		}
313 	}
314 
315 	if( GetFmt() && !GetFmt()->GetDoc()->IsInDtor() )
316 	{
317         // OD 2004-01-19 #110582#
318         Unchain();
319 
320         // OD 2004-01-19 #110582#
321         DeleteCnt();
322 
323 		//Tschuess sagen.
324         if ( GetAnchorFrm() )
325             AnchorFrm()->RemoveFly( this );
326 	}
327 
328     FinitDrawObj();
329 }
330 
331 // OD 2004-01-19 #110582#
332 void SwFlyFrm::Unchain()
333 {
334     if ( GetPrevLink() )
335         UnchainFrames( GetPrevLink(), this );
336     if ( GetNextLink() )
337         UnchainFrames( this, GetNextLink() );
338 }
339 
340 // OD 2004-01-19 #110582#
341 void SwFlyFrm::DeleteCnt()
342 {
343     // #110582#-2
344     if ( IsLockDeleteContent() )
345         return;
346 
347     SwFrm* pFrm = pLower;
348     while ( pFrm )
349     {
350         while ( pFrm->GetDrawObjs() && pFrm->GetDrawObjs()->Count() )
351         {
352             SwAnchoredObject *pAnchoredObj = (*pFrm->GetDrawObjs())[0];
353             if ( pAnchoredObj->ISA(SwFlyFrm) )
354                 delete pAnchoredObj;
355             else if ( pAnchoredObj->ISA(SwAnchoredDrawObject) )
356             {
357                 // OD 23.06.2003 #108784# - consider 'virtual' drawing objects
358                 SdrObject* pObj = pAnchoredObj->DrawObj();
359                 if ( pObj->ISA(SwDrawVirtObj) )
360                 {
361                     SwDrawVirtObj* pDrawVirtObj = static_cast<SwDrawVirtObj*>(pObj);
362                     pDrawVirtObj->RemoveFromWriterLayout();
363                     pDrawVirtObj->RemoveFromDrawingPage();
364                 }
365                 else
366                 {
367                     SwDrawContact* pContact =
368                             static_cast<SwDrawContact*>(::GetUserCall( pObj ));
369                     if ( pContact )
370                     {
371                         pContact->DisconnectFromLayout();
372                     }
373                 }
374             }
375         }
376 
377         pFrm->Remove();
378         delete pFrm;
379         pFrm = pLower;
380     }
381 
382     InvalidatePage();
383 }
384 
385 /*************************************************************************
386 |*
387 |*	SwFlyFrm::InitDrawObj()
388 |*
389 |*	Ersterstellung		MA 02. Dec. 94
390 |*	Letzte Aenderung	MA 30. Nov. 95
391 |*
392 |*************************************************************************/
393 
394 sal_uInt32 SwFlyFrm::_GetOrdNumForNewRef( const SwFlyDrawContact* pContact )
395 {
396     sal_uInt32 nOrdNum( 0L );
397 
398     // search for another Writer fly frame registered at same frame format
399     SwIterator<SwFlyFrm,SwFmt> aIter( *pContact->GetFmt() );
400     const SwFlyFrm* pFlyFrm( 0L );
401     for ( pFlyFrm = aIter.First(); pFlyFrm; pFlyFrm = aIter.Next() )
402     {
403         if ( pFlyFrm != this )
404         {
405             break;
406         }
407     }
408 
409     if ( pFlyFrm )
410     {
411         // another Writer fly frame found. Take its order number
412         nOrdNum = pFlyFrm->GetVirtDrawObj()->GetOrdNum();
413     }
414     else
415     {
416         // no other Writer fly frame found. Take order number of 'master' object
417         // --> OD 2004-11-11 #i35748# - use method <GetOrdNumDirect()> instead
418         // of method <GetOrdNum()> to avoid a recalculation of the order number,
419         // which isn't intended.
420         nOrdNum = pContact->GetMaster()->GetOrdNumDirect();
421         // <--
422     }
423 
424     return nOrdNum;
425 }
426 
427 SwVirtFlyDrawObj* SwFlyFrm::CreateNewRef( SwFlyDrawContact *pContact )
428 {
429 	SwVirtFlyDrawObj *pDrawObj = new SwVirtFlyDrawObj( *pContact->GetMaster(), this );
430 	pDrawObj->SetModel( pContact->GetMaster()->GetModel() );
431 	pDrawObj->SetUserCall( pContact );
432 
433     //Der Reader erzeugt die Master und setzt diese, um die Z-Order zu
434 	//transportieren, in die Page ein. Beim erzeugen der ersten Referenz werden
435 	//die Master aus der Liste entfernt und fuehren von da an ein
436 	//Schattendasein.
437     SdrPage* pPg( 0L );
438 	if ( 0 != ( pPg = pContact->GetMaster()->GetPage() ) )
439 	{
440 		const sal_uInt32 nOrdNum = pContact->GetMaster()->GetOrdNum();
441 		pPg->ReplaceObject( pDrawObj, nOrdNum );
442 	}
443     // --> OD 2004-08-16 #i27030# - insert new <SwVirtFlyDrawObj> instance
444     // into drawing page with correct order number
445     else
446     {
447         pContact->GetFmt()->getIDocumentDrawModelAccess()->GetDrawModel()->GetPage( 0 )->
448                         InsertObject( pDrawObj, _GetOrdNumForNewRef( pContact ) );
449     }
450     // <--
451     // --> OD 2004-12-13 #i38889# - assure, that new <SwVirtFlyDrawObj> instance
452     // is in a visible layer.
453     pContact->MoveObjToVisibleLayer( pDrawObj );
454     // <--
455     return pDrawObj;
456 }
457 
458 
459 
460 void SwFlyFrm::InitDrawObj( sal_Bool bNotify )
461 {
462 	//ContactObject aus dem Format suchen. Wenn bereits eines existiert, so
463 	//braucht nur eine neue Ref erzeugt werden, anderfalls ist es jetzt an
464 	//der Zeit das Contact zu erzeugen.
465 
466     IDocumentDrawModelAccess* pIDDMA = GetFmt()->getIDocumentDrawModelAccess();
467 	SwFlyDrawContact *pContact = SwIterator<SwFlyDrawContact,SwFmt>::FirstElement( *GetFmt() );
468 	if ( !pContact )
469     {
470         // --> OD 2005-08-08 #i52858# - method name changed
471 		pContact = new SwFlyDrawContact( (SwFlyFrmFmt*)GetFmt(),
472                                           pIDDMA->GetOrCreateDrawModel() );
473         // <--
474     }
475 	ASSERT( pContact, "InitDrawObj failed" );
476     // OD 2004-03-22 #i26791#
477     SetDrawObj( *(CreateNewRef( pContact )) );
478 
479     //Den richtigen Layer setzen.
480     // OD 2004-01-19 #110582#
481     SdrLayerID nHeavenId = pIDDMA->GetHeavenId();
482     SdrLayerID nHellId = pIDDMA->GetHellId();
483     // OD 2004-03-22 #i26791#
484     GetVirtDrawObj()->SetLayer( GetFmt()->GetOpaque().GetValue()
485                                 ? nHeavenId
486                                 : nHellId );
487 	if ( bNotify )
488 		NotifyDrawObj();
489 }
490 
491 /*************************************************************************
492 |*
493 |*	SwFlyFrm::FinitDrawObj()
494 |*
495 |*	Ersterstellung		MA 12. Dec. 94
496 |*	Letzte Aenderung	MA 15. May. 95
497 |*
498 |*************************************************************************/
499 
500 void SwFlyFrm::FinitDrawObj()
501 {
502     if ( !GetVirtDrawObj() )
503 		return;
504 
505 	//Bei den SdrPageViews abmelden falls das Objekt dort noch selektiert ist.
506 	if ( !GetFmt()->GetDoc()->IsInDtor() )
507 	{
508 		ViewShell *p1St = getRootFrm()->GetCurrShell();
509 		if ( p1St )
510 		{
511 			ViewShell *pSh = p1St;
512 			do
513 			{	//z.Zt. kann das Drawing nur ein Unmark auf alles, weil das
514 				//Objekt bereits Removed wurde.
515 				if( pSh->HasDrawView() )
516 					pSh->Imp()->GetDrawView()->UnmarkAll();
517 				pSh = (ViewShell*)pSh->GetNext();
518 
519 			} while ( pSh != p1St );
520 		}
521 	}
522 
523 	//VirtObject mit in das Grab nehmen. Wenn das letzte VirObject
524 	//zerstoert wird, mussen das DrawObject und DrawContact ebenfalls
525 	//zerstoert werden.
526 	SwFlyDrawContact *pMyContact = 0;
527 	if ( GetFmt() )
528 	{
529         bool bContinue = true;
530         SwIterator<SwFrm,SwFmt> aFrmIter( *GetFmt() );
531         for ( SwFrm* pFrm = aFrmIter.First(); pFrm; pFrm = aFrmIter.Next() )
532             if ( pFrm != this )
533             {
534                 // don't delete Contact if there is still a Frm
535                 bContinue = false;
536                 break;
537             }
538 
539         if ( bContinue )
540             // no Frm left, find Contact object to destroy
541             pMyContact = SwIterator<SwFlyDrawContact,SwFmt>::FirstElement( *GetFmt() );
542 	}
543 
544     // OD, OS 2004-03-31 #116203# - clear user call of Writer fly frame 'master'
545     // <SdrObject> to assure, that a <SwXFrame::dispose()> doesn't delete the
546     // Writer fly frame again.
547     if ( pMyContact )
548     {
549         pMyContact->GetMaster()->SetUserCall( 0 );
550     }
551     GetVirtDrawObj()->SetUserCall( 0 ); //Ruft sonst Delete des ContactObj
552     delete GetVirtDrawObj();			//Meldet sich selbst beim Master ab.
553 	if ( pMyContact )
554 		delete pMyContact;		//zerstoert den Master selbst.
555 }
556 
557 /*************************************************************************
558 |*
559 |*	SwFlyFrm::ChainFrames()
560 |*
561 |*	Ersterstellung		MA 29. Oct. 97
562 |*	Letzte Aenderung	MA 20. Jan. 98
563 |*
564 |*************************************************************************/
565 
566 void SwFlyFrm::ChainFrames( SwFlyFrm *pMaster, SwFlyFrm *pFollow )
567 {
568 	ASSERT( pMaster && pFollow, "uncomplete chain" );
569 	ASSERT( !pMaster->GetNextLink(), "link can not be changed" );
570 	ASSERT( !pFollow->GetPrevLink(), "link can not be changed" );
571 
572 	pMaster->pNextLink = pFollow;
573 	pFollow->pPrevLink = pMaster;
574 
575 	if ( pMaster->ContainsCntnt() )
576 	{
577 		//Damit ggf. ein Textfluss zustande kommt muss invalidiert werden.
578 		SwFrm *pInva = pMaster->FindLastLower();
579         SWRECTFN( pMaster )
580         const long nBottom = (pMaster->*fnRect->fnGetPrtBottom)();
581 		while ( pInva )
582 		{
583             if( (pInva->Frm().*fnRect->fnBottomDist)( nBottom ) <= 0 )
584 			{
585 				pInva->InvalidateSize();
586 				pInva->Prepare( PREP_CLEAR );
587 				pInva = pInva->FindPrev();
588 			}
589 			else
590 				pInva = 0;
591 		}
592 	}
593 
594 	if ( pFollow->ContainsCntnt() )
595 	{
596 		//Es gibt nur noch den Inhalt des Masters, der Inhalt vom Follow
597 		//hat keine Frames mehr (sollte immer nur genau ein leerer TxtNode sein).
598 		SwFrm *pFrm = pFollow->ContainsCntnt();
599 		ASSERT( !pFrm->IsTabFrm() && !pFrm->FindNext(), "follow in chain contains content" );
600 		pFrm->Cut();
601 		delete pFrm;
602 	}
603 
604     // invalidate accessible relation set (accessibility wrapper)
605     ViewShell* pSh = pMaster->getRootFrm()->GetCurrShell();
606     if( pSh )
607     {
608         SwRootFrm* pLayout = pMaster->getRootFrm();
609         if( pLayout && pLayout->IsAnyShellAccessible() )
610         pSh->Imp()->InvalidateAccessibleRelationSet( pMaster, pFollow );
611     }
612 }
613 
614 void SwFlyFrm::UnchainFrames( SwFlyFrm *pMaster, SwFlyFrm *pFollow )
615 {
616 	pMaster->pNextLink = 0;
617 	pFollow->pPrevLink = 0;
618 
619 	if ( pFollow->ContainsCntnt() )
620 	{
621 		//Der Master saugt den Inhalt vom Follow auf
622 		SwLayoutFrm *pUpper = pMaster;
623 		if ( pUpper->Lower()->IsColumnFrm() )
624 		{
625             pUpper = static_cast<SwLayoutFrm*>(pUpper->GetLastLower());
626             pUpper = static_cast<SwLayoutFrm*>(pUpper->Lower()); // der (Column)BodyFrm
627 			ASSERT( pUpper && pUpper->IsColBodyFrm(), "Missing ColumnBody" );
628 		}
629 		SwFlyFrm *pFoll = pFollow;
630 		while ( pFoll )
631 		{
632 			SwFrm *pTmp = ::SaveCntnt( pFoll );
633 			if ( pTmp )
634                 ::RestoreCntnt( pTmp, pUpper, pMaster->FindLastLower(), true );
635             pFoll->SetCompletePaint();
636 			pFoll->InvalidateSize();
637 			pFoll = pFoll->GetNextLink();
638 		}
639 	}
640 
641 	//Der Follow muss mit seinem eigenen Inhalt versorgt werden.
642 	const SwFmtCntnt &rCntnt = pFollow->GetFmt()->GetCntnt();
643 	ASSERT( rCntnt.GetCntntIdx(), ":-( Kein Inhalt vorbereitet." );
644 	sal_uLong nIndex = rCntnt.GetCntntIdx()->GetIndex();
645 	// Lower() bedeutet SwColumnFrm, dieser beinhaltet wieder einen SwBodyFrm
646 	::_InsertCnt( pFollow->Lower() ? (SwLayoutFrm*)((SwLayoutFrm*)pFollow->Lower())->Lower()
647 								   : (SwLayoutFrm*)pFollow,
648 				  pFollow->GetFmt()->GetDoc(), ++nIndex );
649 
650     // invalidate accessible relation set (accessibility wrapper)
651     ViewShell* pSh = pMaster->getRootFrm()->GetCurrShell();
652     if( pSh )
653     {
654         SwRootFrm* pLayout = pMaster->getRootFrm();
655         if( pLayout && pLayout->IsAnyShellAccessible() )
656         pSh->Imp()->InvalidateAccessibleRelationSet( pMaster, pFollow );
657 }
658 }
659 
660 /*************************************************************************
661 |*
662 |*	SwFlyFrm::FindChainNeighbour()
663 |*
664 |*	Ersterstellung		MA 11. Nov. 97
665 |*	Letzte Aenderung	MA 09. Apr. 99
666 |*
667 |*************************************************************************/
668 
669 SwFlyFrm *SwFlyFrm::FindChainNeighbour( SwFrmFmt &rChain, SwFrm *pAnch )
670 {
671 	//Wir suchen denjenigen Fly, der in dem selben Bereich steht.
672 	//Bereiche koennen zunaechst nur Kopf-/Fusszeilen oder Flys sein.
673 
674 	if ( !pAnch )			//Wenn ein Anchor uebergeben Wurde zaehlt dieser: Ctor!
675         pAnch = AnchorFrm();
676 
677 	SwLayoutFrm *pLay;
678 	if ( pAnch->IsInFly() )
679 		pLay = pAnch->FindFlyFrm();
680 	else
681 	{
682 		//FindFooterOrHeader taugt hier nicht, weil evtl. noch keine Verbindung
683 		//zum Anker besteht.
684 		pLay = pAnch->GetUpper();
685 		while ( pLay && !(pLay->GetType() & (FRM_HEADER|FRM_FOOTER)) )
686 			pLay = pLay->GetUpper();
687 	}
688 
689 	SwIterator<SwFlyFrm,SwFmt> aIter( rChain );
690 	SwFlyFrm *pFly = aIter.First();
691 	if ( pLay )
692 	{
693 		while ( pFly )
694 		{
695             if ( pFly->GetAnchorFrm() )
696 			{
697                 if ( pFly->GetAnchorFrm()->IsInFly() )
698 				{
699                     if ( pFly->AnchorFrm()->FindFlyFrm() == pLay )
700 						break;
701 				}
702 				else if ( pLay == pFly->FindFooterOrHeader() )
703 					break;
704 			}
705 			pFly = aIter.Next();
706 		}
707 	}
708 	else if ( pFly )
709 	{
710 		ASSERT( !aIter.Next(), "chain with more than one inkarnation" );
711 	}
712 	return pFly;
713 }
714 
715 
716 /*************************************************************************
717 |*
718 |*	SwFlyFrm::FindLastLower()
719 |*
720 |*	Ersterstellung		MA 29. Oct. 97
721 |*	Letzte Aenderung	MA 29. Oct. 97
722 |*
723 |*************************************************************************/
724 
725 SwFrm *SwFlyFrm::FindLastLower()
726 {
727 	SwFrm *pRet = ContainsAny();
728 	if ( pRet && pRet->IsInTab() )
729 		pRet = pRet->FindTabFrm();
730 	SwFrm *pNxt = pRet;
731 	while ( pNxt && IsAnLower( pNxt ) )
732 	{	pRet = pNxt;
733 		pNxt = pNxt->FindNext();
734 	}
735 	return pRet;
736 }
737 
738 
739 /*************************************************************************
740 |*
741 |*	SwFlyFrm::FrmSizeChg()
742 |*
743 |*	Ersterstellung		MA 17. Dec. 92
744 |*	Letzte Aenderung	MA 24. Jul. 96
745 |*
746 |*************************************************************************/
747 
748 sal_Bool SwFlyFrm::FrmSizeChg( const SwFmtFrmSize &rFrmSize )
749 {
750 	sal_Bool bRet = sal_False;
751 	SwTwips nDiffHeight = Frm().Height();
752     if ( rFrmSize.GetHeightSizeType() == ATT_VAR_SIZE )
753         bFixSize = bMinHeight = sal_False;
754 	else
755 	{
756         if ( rFrmSize.GetHeightSizeType() == ATT_FIX_SIZE )
757         {
758             bFixSize = sal_True;
759 			bMinHeight = sal_False;
760 		}
761         else if ( rFrmSize.GetHeightSizeType() == ATT_MIN_SIZE )
762         {
763             bFixSize = sal_False;
764 			bMinHeight = sal_True;
765 		}
766 		nDiffHeight -= rFrmSize.GetHeight();
767 	}
768 	//Wenn der Fly Spalten enthaehlt muessen der Fly und
769 	//die Spalten schon einmal auf die Wunschwerte gebracht
770 	//werden, sonst haben wir ein kleines Problem.
771 	if ( Lower() )
772 	{
773 		if ( Lower()->IsColumnFrm() )
774 		{
775             const SwRect aOld( GetObjRectWithSpaces() );
776 			const Size	 aOldSz( Prt().SSize() );
777 			const SwTwips nDiffWidth = Frm().Width() - rFrmSize.GetWidth();
778 			aFrm.Height( aFrm.Height() - nDiffHeight );
779 			aFrm.Width ( aFrm.Width()  - nDiffWidth  );
780             // --> OD 2006-08-16 #i68520#
781             InvalidateObjRectWithSpaces();
782             // <--
783 			aPrt.Height( aPrt.Height() - nDiffHeight );
784 			aPrt.Width ( aPrt.Width()  - nDiffWidth  );
785 			ChgLowersProp( aOldSz );
786 			::Notify( this, FindPageFrm(), aOld );
787 			bValidPos = sal_False;
788 			bRet = sal_True;
789 		}
790 		else if ( Lower()->IsNoTxtFrm() )
791 		{
792             bFixSize = sal_True;
793 			bMinHeight = sal_False;
794 		}
795 	}
796 	return bRet;
797 }
798 
799 /*************************************************************************
800 |*
801 |*	SwFlyFrm::Modify()
802 |*
803 |*	Ersterstellung		MA 17. Dec. 92
804 |*	Letzte Aenderung	MA 17. Jan. 97
805 |*
806 |*************************************************************************/
807 
808 void SwFlyFrm::Modify( const SfxPoolItem* pOld, const SfxPoolItem * pNew )
809 {
810 	sal_uInt8 nInvFlags = 0;
811 
812 	if( pNew && RES_ATTRSET_CHG == pNew->Which() )
813 	{
814 		SfxItemIter aNIter( *((SwAttrSetChg*)pNew)->GetChgSet() );
815 		SfxItemIter aOIter( *((SwAttrSetChg*)pOld)->GetChgSet() );
816 		SwAttrSetChg aOldSet( *(SwAttrSetChg*)pOld );
817 		SwAttrSetChg aNewSet( *(SwAttrSetChg*)pNew );
818 		while( sal_True )
819 		{
820 			_UpdateAttr( (SfxPoolItem*)aOIter.GetCurItem(),
821 						 (SfxPoolItem*)aNIter.GetCurItem(), nInvFlags,
822 						 &aOldSet, &aNewSet );
823 			if( aNIter.IsAtEnd() )
824 				break;
825 			aNIter.NextItem();
826 			aOIter.NextItem();
827 		}
828 		if ( aOldSet.Count() || aNewSet.Count() )
829 			SwLayoutFrm::Modify( &aOldSet, &aNewSet );
830 	}
831 	else
832 		_UpdateAttr( pOld, pNew, nInvFlags );
833 
834 	if ( nInvFlags != 0 )
835 	{
836 		_Invalidate();
837 		if ( nInvFlags & 0x01 )
838         {
839 			_InvalidatePos();
840             // --> OD 2006-08-16 #i68520#
841             InvalidateObjRectWithSpaces();
842             // <--
843         }
844 		if ( nInvFlags & 0x02 )
845         {
846 			_InvalidateSize();
847             // --> OD 2006-08-16 #i68520#
848             InvalidateObjRectWithSpaces();
849             // <--
850         }
851         if ( nInvFlags & 0x04 )
852 			_InvalidatePrt();
853 		if ( nInvFlags & 0x08 )
854 			SetNotifyBack();
855 		if ( nInvFlags & 0x10 )
856 			SetCompletePaint();
857 		if ( ( nInvFlags & 0x40 ) && Lower() && Lower()->IsNoTxtFrm() )
858             ClrContourCache( GetVirtDrawObj() );
859 		SwRootFrm *pRoot;
860 		if ( nInvFlags & 0x20 && 0 != (pRoot = getRootFrm()) )
861 			pRoot->InvalidateBrowseWidth();
862         // --> OD 2004-06-28 #i28701#
863         if ( nInvFlags & 0x80 )
864         {
865             // update sorted object lists, the Writer fly frame is registered at.
866             UpdateObjInSortedList();
867         }
868         // <--
869         // --> OD #i87645# - reset flags for the layout process (only if something has been invalidated)
870         ResetLayoutProcessBools();
871         // <--
872 	}
873 }
874 
875 void SwFlyFrm::_UpdateAttr( const SfxPoolItem *pOld, const SfxPoolItem *pNew,
876 							sal_uInt8 &rInvFlags,
877 							SwAttrSetChg *pOldSet, SwAttrSetChg *pNewSet )
878 {
879 	sal_Bool bClear = sal_True;
880 	const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
881 	ViewShell *pSh = getRootFrm()->GetCurrShell();
882 	switch( nWhich )
883 	{
884         case RES_VERT_ORIENT:
885 		case RES_HORI_ORIENT:
886         // OD 22.09.2003 #i18732# - consider new option 'follow text flow'
887         case RES_FOLLOW_TEXT_FLOW:
888         {
889             //Achtung! _immer_ Aktion in ChgRePos() mitpflegen.
890 			rInvFlags |= 0x09;
891         }
892         break;
893         // OD 2004-07-01 #i28701# - consider new option 'wrap influence on position'
894         case RES_WRAP_INFLUENCE_ON_OBJPOS:
895         {
896             rInvFlags |= 0x89;
897         }
898         break;
899         case RES_SURROUND:
900         {
901             // OD 2004-05-13 #i28701# - invalidate position on change of
902             // wrapping style.
903             //rInvFlags |= 0x40;
904             rInvFlags |= 0x41;
905 			//Der Hintergrund muss benachrichtigt und Invalidiert werden.
906             const SwRect aTmp( GetObjRectWithSpaces() );
907 			NotifyBackground( FindPageFrm(), aTmp, PREP_FLY_ATTR_CHG );
908 
909 			// Durch eine Umlaufaenderung von rahmengebundenen Rahmen kann eine
910 			// vertikale Ausrichtung aktiviert/deaktiviert werden => MakeFlyPos
911 			if( FLY_AT_FLY == GetFmt()->GetAnchor().GetAnchorId() )
912 				rInvFlags |= 0x09;
913 
914 			//Ggf. die Kontur am Node loeschen.
915 			if ( Lower() && Lower()->IsNoTxtFrm() &&
916 				 !GetFmt()->GetSurround().IsContour() )
917 			{
918 				SwNoTxtNode *pNd = (SwNoTxtNode*)((SwCntntFrm*)Lower())->GetNode();
919 				if ( pNd->HasContour() )
920 					pNd->SetContour( 0 );
921 			}
922             // --> OD 2004-06-28 #i28701# - perform reorder of object lists
923             // at anchor frame and at page frame.
924             rInvFlags |= 0x80;
925         }
926         break;
927 
928 		case RES_PROTECT:
929 			{
930 			const SvxProtectItem *pP = (SvxProtectItem*)pNew;
931             GetVirtDrawObj()->SetMoveProtect( pP->IsPosProtected()   );
932             GetVirtDrawObj()->SetResizeProtect( pP->IsSizeProtected() );
933             if( pSh )
934             {
935                 SwRootFrm* pLayout = getRootFrm();
936                 if( pLayout && pLayout->IsAnyShellAccessible() )
937 				pSh->Imp()->InvalidateAccessibleEditableState( sal_True, this );
938             }
939 			break;
940 			}
941 
942 		case RES_COL:
943 			{
944 				ChgColumns( *(const SwFmtCol*)pOld, *(const SwFmtCol*)pNew );
945 				const SwFmtFrmSize &rNew = GetFmt()->GetFrmSize();
946 				if ( FrmSizeChg( rNew ) )
947 					NotifyDrawObj();
948 				rInvFlags |= 0x1A;
949 				break;
950 			}
951 
952 		case RES_FRM_SIZE:
953 		case RES_FMT_CHG:
954 		{
955 			const SwFmtFrmSize &rNew = GetFmt()->GetFrmSize();
956 			if ( FrmSizeChg( rNew ) )
957 				NotifyDrawObj();
958 			rInvFlags |= 0x7F;
959 			if ( RES_FMT_CHG == nWhich )
960 			{
961                 SwRect aNew( GetObjRectWithSpaces() );
962 				SwRect aOld( aFrm );
963 				const SvxULSpaceItem &rUL = ((SwFmtChg*)pOld)->pChangedFmt->GetULSpace();
964 				aOld.Top( Max( aOld.Top() - long(rUL.GetUpper()), 0L ) );
965 				aOld.SSize().Height()+= rUL.GetLower();
966 				const SvxLRSpaceItem &rLR = ((SwFmtChg*)pOld)->pChangedFmt->GetLRSpace();
967 				aOld.Left  ( Max( aOld.Left() - long(rLR.GetLeft()), 0L ) );
968 				aOld.SSize().Width() += rLR.GetRight();
969 				aNew.Union( aOld );
970 				NotifyBackground( FindPageFrm(), aNew, PREP_CLEAR );
971 
972 				//Dummer Fall. Bei der Zusweisung einer Vorlage k?nnen wir uns
973 				//nicht auf das alte Spaltenattribut verlassen. Da diese
974 				//wenigstens anzahlgemass fuer ChgColumns vorliegen muessen,
975 				//bleibt uns nur einen temporaeres Attribut zu basteln.
976 				SwFmtCol aCol;
977 				if ( Lower() && Lower()->IsColumnFrm() )
978 				{
979 					sal_uInt16 nCol = 0;
980 					SwFrm *pTmp = Lower();
981 					do
982 					{	++nCol;
983 						pTmp = pTmp->GetNext();
984 					} while ( pTmp );
985 					aCol.Init( nCol, 0, 1000 );
986 				}
987 				ChgColumns( aCol, GetFmt()->GetCol() );
988 			}
989 
990 			SwFmtURL aURL( GetFmt()->GetURL() );
991 			if ( aURL.GetMap() )
992 			{
993 				const SwFmtFrmSize &rOld = nWhich == RES_FRM_SIZE ?
994 								*(SwFmtFrmSize*)pNew :
995 								((SwFmtChg*)pOld)->pChangedFmt->GetFrmSize();
996 				//#35091# Kann beim Laden von Vorlagen mal 0 sein
997 				if ( rOld.GetWidth() && rOld.GetHeight() )
998 				{
999 
1000 					Fraction aScaleX( rOld.GetWidth(), rNew.GetWidth() );
1001 					Fraction aScaleY( rOld.GetHeight(), rOld.GetHeight() );
1002 					aURL.GetMap()->Scale( aScaleX, aScaleY );
1003 					SwFrmFmt *pFmt = GetFmt();
1004 					pFmt->LockModify();
1005                     pFmt->SetFmtAttr( aURL );
1006 					pFmt->UnlockModify();
1007 				}
1008 			}
1009 			const SvxProtectItem &rP = GetFmt()->GetProtect();
1010             GetVirtDrawObj()->SetMoveProtect( rP.IsPosProtected()    );
1011             GetVirtDrawObj()->SetResizeProtect( rP.IsSizeProtected() );
1012 
1013 			if ( pSh )
1014 				pSh->InvalidateWindows( Frm() );
1015             const IDocumentDrawModelAccess* pIDDMA = GetFmt()->getIDocumentDrawModelAccess();
1016 			const sal_uInt8 nId = GetFmt()->GetOpaque().GetValue() ?
1017                              pIDDMA->GetHeavenId() :
1018                              pIDDMA->GetHellId();
1019             GetVirtDrawObj()->SetLayer( nId );
1020 
1021 			if ( Lower() )
1022 			{
1023 				//Ggf. die Kontur am Node loeschen.
1024 				if( Lower()->IsNoTxtFrm() &&
1025 					 !GetFmt()->GetSurround().IsContour() )
1026 				{
1027 					SwNoTxtNode *pNd = (SwNoTxtNode*)((SwCntntFrm*)Lower())->GetNode();
1028 					if ( pNd->HasContour() )
1029 						pNd->SetContour( 0 );
1030 				}
1031 				else if( !Lower()->IsColumnFrm() )
1032 				{
1033                     SwFrm* pFrm = GetLastLower();
1034                     if( pFrm->IsTxtFrm() && ((SwTxtFrm*)pFrm)->IsUndersized() )
1035 						pFrm->Prepare( PREP_ADJUST_FRM );
1036 				}
1037 			}
1038 
1039             // --> OD 2004-06-28 #i28701# - perform reorder of object lists
1040             // at anchor frame and at page frame.
1041             rInvFlags |= 0x80;
1042 
1043             break;
1044 		}
1045 		case RES_UL_SPACE:
1046 		case RES_LR_SPACE:
1047         {
1048             rInvFlags |= 0x41;
1049             if( pSh && pSh->GetViewOptions()->getBrowseMode() )
1050 				getRootFrm()->InvalidateBrowseWidth();
1051             SwRect aNew( GetObjRectWithSpaces() );
1052 			SwRect aOld( aFrm );
1053 			if ( RES_UL_SPACE == nWhich )
1054 			{
1055 				const SvxULSpaceItem &rUL = *(SvxULSpaceItem*)pNew;
1056 				aOld.Top( Max( aOld.Top() - long(rUL.GetUpper()), 0L ) );
1057 				aOld.SSize().Height()+= rUL.GetLower();
1058 			}
1059 			else
1060 			{
1061 				const SvxLRSpaceItem &rLR = *(SvxLRSpaceItem*)pNew;
1062 				aOld.Left  ( Max( aOld.Left() - long(rLR.GetLeft()), 0L ) );
1063 				aOld.SSize().Width() += rLR.GetRight();
1064 			}
1065 			aNew.Union( aOld );
1066 			NotifyBackground( FindPageFrm(), aNew, PREP_CLEAR );
1067         }
1068         break;
1069 
1070 		case RES_BOX:
1071 		case RES_SHADOW:
1072 			rInvFlags |= 0x17;
1073 			break;
1074 
1075         case RES_FRAMEDIR :
1076             SetDerivedVert( sal_False );
1077             SetDerivedR2L( sal_False );
1078             CheckDirChange();
1079             break;
1080 
1081         case RES_OPAQUE:
1082             {
1083                 if ( pSh )
1084                     pSh->InvalidateWindows( Frm() );
1085 
1086                 const IDocumentDrawModelAccess* pIDDMA = GetFmt()->getIDocumentDrawModelAccess();
1087                 const sal_uInt8 nId = ((SvxOpaqueItem*)pNew)->GetValue() ?
1088                                     pIDDMA->GetHeavenId() :
1089                                     pIDDMA->GetHellId();
1090                 GetVirtDrawObj()->SetLayer( nId );
1091                 if( pSh )
1092                 {
1093                     SwRootFrm* pLayout = getRootFrm();
1094                     if( pLayout && pLayout->IsAnyShellAccessible() )
1095                 {
1096                     pSh->Imp()->DisposeAccessibleFrm( this );
1097                     pSh->Imp()->AddAccessibleFrm( this );
1098                 }
1099                 }
1100                 // --> OD 2004-06-28 #i28701# - perform reorder of object lists
1101                 // at anchor frame and at page frame.
1102                 rInvFlags |= 0x80;
1103             }
1104 			break;
1105 
1106 		case RES_URL:
1107 			//Das Interface arbeitet bei Textrahmen auf der Rahmengroesse,
1108 			//die Map muss sich aber auf die FrmSize beziehen
1109 			if ( (!Lower() || !Lower()->IsNoTxtFrm()) &&
1110 				 ((SwFmtURL*)pNew)->GetMap() && ((SwFmtURL*)pOld)->GetMap() )
1111 			{
1112 				const SwFmtFrmSize &rSz = GetFmt()->GetFrmSize();
1113 				if ( rSz.GetHeight() != Frm().Height() ||
1114 					 rSz.GetWidth()  != Frm().Width() )
1115 				{
1116 					SwFmtURL aURL( GetFmt()->GetURL() );
1117 					Fraction aScaleX( Frm().Width(),  rSz.GetWidth() );
1118 					Fraction aScaleY( Frm().Height(), rSz.GetHeight() );
1119 					aURL.GetMap()->Scale( aScaleX, aScaleY );
1120 					SwFrmFmt *pFmt = GetFmt();
1121 					pFmt->LockModify();
1122                     pFmt->SetFmtAttr( aURL );
1123 					pFmt->UnlockModify();
1124 				}
1125 			}
1126 			/* Keine Invalidierung notwendig */
1127 			break;
1128 
1129 		case RES_CHAIN:
1130 			{
1131 				SwFmtChain *pChain = (SwFmtChain*)pNew;
1132 				if ( pChain->GetNext() )
1133 				{
1134 					SwFlyFrm *pFollow = FindChainNeighbour( *pChain->GetNext() );
1135 					if ( GetNextLink() && pFollow != GetNextLink() )
1136 						SwFlyFrm::UnchainFrames( this, GetNextLink());
1137 					if ( pFollow )
1138 					{
1139 						if ( pFollow->GetPrevLink() &&
1140 							 pFollow->GetPrevLink() != this )
1141 							SwFlyFrm::UnchainFrames( pFollow->GetPrevLink(),
1142 													 pFollow );
1143 						if ( !GetNextLink() )
1144 							SwFlyFrm::ChainFrames( this, pFollow );
1145 					}
1146 				}
1147 				else if ( GetNextLink() )
1148 					SwFlyFrm::UnchainFrames( this, GetNextLink() );
1149 				if ( pChain->GetPrev() )
1150 				{
1151 					SwFlyFrm *pMaster = FindChainNeighbour( *pChain->GetPrev() );
1152 					if ( GetPrevLink() && pMaster != GetPrevLink() )
1153 						SwFlyFrm::UnchainFrames( GetPrevLink(), this );
1154 					if ( pMaster )
1155 					{
1156 						if ( pMaster->GetNextLink() &&
1157 							 pMaster->GetNextLink() != this )
1158 							SwFlyFrm::UnchainFrames( pMaster,
1159 													 pMaster->GetNextLink() );
1160 						if ( !GetPrevLink() )
1161 							SwFlyFrm::ChainFrames( pMaster, this );
1162 					}
1163 				}
1164 				else if ( GetPrevLink() )
1165 					SwFlyFrm::UnchainFrames( GetPrevLink(), this );
1166 			}
1167 
1168 		default:
1169 			bClear = sal_False;
1170 	}
1171 	if ( bClear )
1172 	{
1173 		if ( pOldSet || pNewSet )
1174 		{
1175 			if ( pOldSet )
1176 				pOldSet->ClearItem( nWhich );
1177 			if ( pNewSet )
1178 				pNewSet->ClearItem( nWhich );
1179 		}
1180 		else
1181 			SwLayoutFrm::Modify( pOld, pNew );
1182 	}
1183 }
1184 
1185 /*************************************************************************
1186 |*
1187 |*				  SwFlyFrm::GetInfo()
1188 |*
1189 |*	  Beschreibung		erfragt Informationen
1190 |*	  Ersterstellung	JP 31.03.94
1191 |*	  Letzte Aenderung	JP 31.03.94
1192 |*
1193 *************************************************************************/
1194 
1195 	// erfrage vom Modify Informationen
1196 sal_Bool SwFlyFrm::GetInfo( SfxPoolItem & rInfo ) const
1197 {
1198 	if( RES_AUTOFMT_DOCNODE == rInfo.Which() )
1199 		return sal_False;	// es gibt einen FlyFrm also wird er benutzt
1200 	return sal_True;		// weiter suchen
1201 }
1202 
1203 /*************************************************************************
1204 |*
1205 |*	SwFlyFrm::_Invalidate()
1206 |*
1207 |*	Ersterstellung		MA 15. Oct. 92
1208 |*	Letzte Aenderung	MA 26. Jun. 96
1209 |*
1210 |*************************************************************************/
1211 
1212 void SwFlyFrm::_Invalidate( SwPageFrm *pPage )
1213 {
1214 	InvalidatePage( pPage );
1215 	bNotifyBack = bInvalid = sal_True;
1216 
1217 	SwFlyFrm *pFrm;
1218     if ( GetAnchorFrm() && 0 != (pFrm = AnchorFrm()->FindFlyFrm()) )
1219 	{
1220 		//Gaanz dumm: Wenn der Fly innerhalb eines Fly gebunden ist, der
1221 		//Spalten enthaehlt, sollte das Format von diesem ausgehen.
1222 		if ( !pFrm->IsLocked() && !pFrm->IsColLocked() &&
1223 			 pFrm->Lower() && pFrm->Lower()->IsColumnFrm() )
1224 			pFrm->InvalidateSize();
1225 	}
1226 
1227     // --> OD 2008-01-21 #i85216#
1228     // if vertical position is oriented at a layout frame inside a ghost section,
1229     // assure that the position is invalidated and that the information about
1230     // the vertical position oriented frame is cleared
1231     if ( GetVertPosOrientFrm() && GetVertPosOrientFrm()->IsLayoutFrm() )
1232     {
1233         const SwSectionFrm* pSectFrm( GetVertPosOrientFrm()->FindSctFrm() );
1234         if ( pSectFrm && pSectFrm->GetSection() == 0 )
1235         {
1236             InvalidatePos();
1237             ClearVertPosOrientFrm();
1238         }
1239     }
1240     // <--
1241 }
1242 
1243 /*************************************************************************
1244 |*
1245 |*	SwFlyFrm::ChgRelPos()
1246 |*
1247 |*	Beschreibung		Aenderung der relativen Position, die Position wird
1248 |*		damit automatisch Fix, das Attribut wird entprechend angepasst.
1249 |*	Ersterstellung		MA 25. Aug. 92
1250 |*	Letzte Aenderung	MA 09. Aug. 95
1251 |*
1252 |*************************************************************************/
1253 
1254 void SwFlyFrm::ChgRelPos( const Point &rNewPos )
1255 {
1256     if ( GetCurrRelPos() != rNewPos )
1257 	{
1258 		SwFrmFmt *pFmt = GetFmt();
1259         const bool bVert = GetAnchorFrm()->IsVertical();
1260         const SwTwips nNewY = bVert ? rNewPos.X() : rNewPos.Y();
1261         SwTwips nTmpY = nNewY == LONG_MAX ? 0 : nNewY;
1262         if( bVert )
1263             nTmpY = -nTmpY;
1264 		SfxItemSet aSet( pFmt->GetDoc()->GetAttrPool(),
1265 						 RES_VERT_ORIENT, RES_HORI_ORIENT);
1266 
1267 		SwFmtVertOrient aVert( pFmt->GetVertOrient() );
1268 		SwTxtFrm *pAutoFrm = NULL;
1269         // --> OD 2004-11-12 #i34948# - handle also at-page and at-fly anchored
1270         // Writer fly frames
1271         const RndStdIds eAnchorType = GetFrmFmt().GetAnchor().GetAnchorId();
1272         if ( eAnchorType == FLY_AT_PAGE )
1273         {
1274             aVert.SetVertOrient( text::VertOrientation::NONE );
1275             aVert.SetRelationOrient( text::RelOrientation::PAGE_FRAME );
1276         }
1277         else if ( eAnchorType == FLY_AT_FLY )
1278         {
1279             aVert.SetVertOrient( text::VertOrientation::NONE );
1280             aVert.SetRelationOrient( text::RelOrientation::FRAME );
1281         }
1282         // <--
1283         else if ( IsFlyAtCntFrm() || text::VertOrientation::NONE != aVert.GetVertOrient() )
1284 		{
1285             if( text::RelOrientation::CHAR == aVert.GetRelationOrient() && IsAutoPos() )
1286 			{
1287                 if( LONG_MAX != nNewY )
1288 				{
1289                     aVert.SetVertOrient( text::VertOrientation::NONE );
1290 					xub_StrLen nOfs =
1291 						pFmt->GetAnchor().GetCntntAnchor()->nContent.GetIndex();
1292                     ASSERT( GetAnchorFrm()->IsTxtFrm(), "TxtFrm expected" );
1293                     pAutoFrm = (SwTxtFrm*)GetAnchorFrm();
1294 					while( pAutoFrm->GetFollow() &&
1295 						   pAutoFrm->GetFollow()->GetOfst() <= nOfs )
1296 					{
1297                         if( pAutoFrm == GetAnchorFrm() )
1298 							nTmpY += pAutoFrm->GetRelPos().Y();
1299 						nTmpY -= pAutoFrm->GetUpper()->Prt().Height();
1300 						pAutoFrm = pAutoFrm->GetFollow();
1301 					}
1302 					nTmpY = ((SwFlyAtCntFrm*)this)->GetRelCharY(pAutoFrm)-nTmpY;
1303 				}
1304 				else
1305                     aVert.SetVertOrient( text::VertOrientation::CHAR_BOTTOM );
1306 			}
1307 			else
1308 			{
1309                 aVert.SetVertOrient( text::VertOrientation::NONE );
1310                 aVert.SetRelationOrient( text::RelOrientation::FRAME );
1311 			}
1312 		}
1313 		aVert.SetPos( nTmpY );
1314 		aSet.Put( aVert );
1315 
1316         //Fuer Flys im Cnt ist die horizontale Ausrichtung uninteressant,
1317 		//den sie ist stets 0.
1318 		if ( !IsFlyInCntFrm() )
1319 		{
1320             const SwTwips nNewX = bVert ? rNewPos.Y() : rNewPos.X();
1321             SwTwips nTmpX = nNewX == LONG_MAX ? 0 : nNewX;
1322 			SwFmtHoriOrient aHori( pFmt->GetHoriOrient() );
1323             // --> OD 2004-11-12 #i34948# - handle also at-page and at-fly anchored
1324             // Writer fly frames
1325             if ( eAnchorType == FLY_AT_PAGE )
1326             {
1327                 aHori.SetHoriOrient( text::HoriOrientation::NONE );
1328                 aHori.SetRelationOrient( text::RelOrientation::PAGE_FRAME );
1329                 aHori.SetPosToggle( sal_False );
1330             }
1331             else if ( eAnchorType == FLY_AT_FLY )
1332             {
1333                 aHori.SetHoriOrient( text::HoriOrientation::NONE );
1334                 aHori.SetRelationOrient( text::RelOrientation::FRAME );
1335                 aHori.SetPosToggle( sal_False );
1336             }
1337             // <--
1338             else if ( IsFlyAtCntFrm() || text::HoriOrientation::NONE != aHori.GetHoriOrient() )
1339 			{
1340                 aHori.SetHoriOrient( text::HoriOrientation::NONE );
1341                 if( text::RelOrientation::CHAR == aHori.GetRelationOrient() && IsAutoPos() )
1342 				{
1343                     if( LONG_MAX != nNewX )
1344 					{
1345 						if( !pAutoFrm )
1346 						{
1347 							xub_StrLen nOfs = pFmt->GetAnchor().GetCntntAnchor()
1348 										  ->nContent.GetIndex();
1349                             ASSERT( GetAnchorFrm()->IsTxtFrm(), "TxtFrm expected");
1350                             pAutoFrm = (SwTxtFrm*)GetAnchorFrm();
1351 							while( pAutoFrm->GetFollow() &&
1352 								   pAutoFrm->GetFollow()->GetOfst() <= nOfs )
1353 								pAutoFrm = pAutoFrm->GetFollow();
1354 						}
1355 						nTmpX -= ((SwFlyAtCntFrm*)this)->GetRelCharX(pAutoFrm);
1356 					}
1357 				}
1358 				else
1359                     aHori.SetRelationOrient( text::RelOrientation::FRAME );
1360 				aHori.SetPosToggle( sal_False );
1361 			}
1362 			aHori.SetPos( nTmpX );
1363 			aSet.Put( aHori );
1364 		}
1365         SetCurrRelPos( rNewPos );
1366 		pFmt->GetDoc()->SetAttr( aSet, *pFmt );
1367 	}
1368 }
1369 /*************************************************************************
1370 |*
1371 |*	SwFlyFrm::Format()
1372 |*
1373 |*	Beschreibung:		"Formatiert" den Frame; Frm und PrtArea.
1374 |*						Die Fixsize wird hier nicht eingestellt.
1375 |*	Ersterstellung		MA 14. Jun. 93
1376 |*	Letzte Aenderung	MA 13. Jun. 96
1377 |*
1378 |*************************************************************************/
1379 
1380 void SwFlyFrm::Format( const SwBorderAttrs *pAttrs )
1381 {
1382 	ASSERT( pAttrs, "FlyFrm::Format, pAttrs ist 0." );
1383 
1384 	ColLock();
1385 
1386 	if ( !bValidSize )
1387 	{
1388 		if ( Frm().Top() == WEIT_WECH && Frm().Left() == WEIT_WECH )
1389         {
1390 			//Sicherheitsschaltung wegnehmen (siehe SwFrm::CTor)
1391 			Frm().Pos().X() = Frm().Pos().Y() = 0;
1392             // --> OD 2006-08-16 #i68520#
1393             InvalidateObjRectWithSpaces();
1394             // <--
1395         }
1396 
1397 		//Breite der Spalten pruefen und ggf. einstellen.
1398 		if ( Lower() && Lower()->IsColumnFrm() )
1399 			AdjustColumns( 0, sal_False );
1400 
1401 		bValidSize = sal_True;
1402 
1403         const SwTwips nUL = pAttrs->CalcTopLine()  + pAttrs->CalcBottomLine();
1404         const SwTwips nLR = pAttrs->CalcLeftLine() + pAttrs->CalcRightLine();
1405         const SwFmtFrmSize &rFrmSz = GetFmt()->GetFrmSize();
1406               Size aRelSize( CalcRel( rFrmSz ) );
1407 
1408         ASSERT( pAttrs->GetSize().Height() != 0 || rFrmSz.GetHeightPercent(), "Hoehe des RahmenAttr ist 0." );
1409         ASSERT( pAttrs->GetSize().Width()  != 0 || rFrmSz.GetWidthPercent(), "Breite des RahmenAttr ist 0." );
1410 
1411         SWRECTFN( this )
1412         if( !HasFixSize() )
1413 		{
1414             SwTwips nRemaining = 0;
1415 
1416             long nMinHeight = 0;
1417             if( IsMinHeight() )
1418                 nMinHeight = bVert ? aRelSize.Width() : aRelSize.Height();
1419 
1420             if ( Lower() )
1421 			{
1422 				if ( Lower()->IsColumnFrm() )
1423 				{
1424 					FormatWidthCols( *pAttrs, nUL, nMinHeight );
1425                     nRemaining = (Lower()->Frm().*fnRect->fnGetHeight)();
1426 				}
1427 				else
1428 				{
1429 					SwFrm *pFrm = Lower();
1430 					while ( pFrm )
1431                     {
1432                         nRemaining += (pFrm->Frm().*fnRect->fnGetHeight)();
1433 						if( pFrm->IsTxtFrm() && ((SwTxtFrm*)pFrm)->IsUndersized() )
1434 							// Dieser TxtFrm waere gern ein bisschen groesser
1435 							nRemaining += ((SwTxtFrm*)pFrm)->GetParHeight()
1436                                     - (pFrm->Prt().*fnRect->fnGetHeight)();
1437 						else if( pFrm->IsSctFrm() && ((SwSectionFrm*)pFrm)->IsUndersized() )
1438 							nRemaining += ((SwSectionFrm*)pFrm)->Undersize();
1439 						pFrm = pFrm->GetNext();
1440 					}
1441                     // --> OD 2006-02-09 #130878#
1442                     // Do not keep old height, if content has no height.
1443                     // The old height could be wrong due to wrong layout cache
1444                     // and isn't corrected in the further formatting, because
1445                     // the fly frame doesn't become invalid anymore.
1446 //                    if( !nRemaining )
1447 //                        nRemaining = nOldHeight - nUL;
1448                     // <--
1449 				}
1450 				if ( GetDrawObjs() )
1451 				{
1452                     sal_uInt32 nCnt = GetDrawObjs()->Count();
1453                     SwTwips nTop = (Frm().*fnRect->fnGetTop)();
1454                     SwTwips nBorder = (Frm().*fnRect->fnGetHeight)() -
1455                                       (Prt().*fnRect->fnGetHeight)();
1456 					for ( sal_uInt16 i = 0; i < nCnt; ++i )
1457 					{
1458                         SwAnchoredObject* pAnchoredObj = (*GetDrawObjs())[i];
1459                         if ( pAnchoredObj->ISA(SwFlyFrm) )
1460 						{
1461                             SwFlyFrm* pFly = static_cast<SwFlyFrm*>(pAnchoredObj);
1462                             // OD 06.11.2003 #i22305# - consider
1463                             // only Writer fly frames, which follow the text flow.
1464                             if ( pFly->IsFlyLayFrm() &&
1465                                  pFly->Frm().Top() != WEIT_WECH &&
1466                                  pFly->GetFmt()->GetFollowTextFlow().GetValue() )
1467 							{
1468                                 SwTwips nDist = -(pFly->Frm().*fnRect->
1469                                     fnBottomDist)( nTop );
1470                                 if( nDist > nBorder + nRemaining )
1471                                     nRemaining = nDist - nBorder;
1472 							}
1473 						}
1474 					}
1475 				}
1476 			}
1477 
1478             if( IsMinHeight() && (nRemaining + nUL) < nMinHeight )
1479 				nRemaining = nMinHeight - nUL;
1480 			//Weil das Grow/Shrink der Flys die Groessen nicht direkt
1481 			//einstellt, sondern indirekt per Invalidate ein Format
1482 			//ausloesst, muessen die Groessen hier direkt eingestellt
1483 			//werden. Benachrichtung laeuft bereits mit.
1484 			//Weil bereits haeufiger 0en per Attribut hereinkamen wehre
1485 			//ich mich ab sofort dagegen.
1486 			if ( nRemaining < MINFLY )
1487 				nRemaining = MINFLY;
1488             (Prt().*fnRect->fnSetHeight)( nRemaining );
1489             nRemaining -= (Frm().*fnRect->fnGetHeight)();
1490             (Frm().*fnRect->fnAddBottom)( nRemaining + nUL );
1491             // --> OD 2006-08-16 #i68520#
1492             if ( nRemaining + nUL != 0 )
1493             {
1494                 InvalidateObjRectWithSpaces();
1495             }
1496             // <--
1497 			bValidSize = sal_True;
1498 		}
1499 		else
1500 		{
1501 			bValidSize = sal_True;	//Fixe Frms formatieren sich nicht.
1502 								//Flys stellen ihre Groesse anhand des Attr ein.
1503             SwTwips nNewSize = bVert ? aRelSize.Width() : aRelSize.Height();
1504             nNewSize -= nUL;
1505             if( nNewSize < MINFLY )
1506                 nNewSize = MINFLY;
1507             (Prt().*fnRect->fnSetHeight)( nNewSize );
1508             nNewSize += nUL - (Frm().*fnRect->fnGetHeight)();
1509             (Frm().*fnRect->fnAddBottom)( nNewSize );
1510             // --> OD 2006-08-16 #i68520#
1511             if ( nNewSize != 0 )
1512             {
1513                 InvalidateObjRectWithSpaces();
1514             }
1515             // <--
1516         }
1517 
1518 		if ( !bFormatHeightOnly )
1519 		{
1520             ASSERT( aRelSize == CalcRel( rFrmSz ), "SwFlyFrm::Format CalcRel problem" )
1521             SwTwips nNewSize = bVert ? aRelSize.Height() : aRelSize.Width();
1522 
1523             if ( rFrmSz.GetWidthSizeType() != ATT_FIX_SIZE )
1524             {
1525                 // #i9046# Autowidth for fly frames
1526                 const SwTwips nAutoWidth = CalcAutoWidth();
1527                 if ( nAutoWidth )
1528                 {
1529                     if( ATT_MIN_SIZE == rFrmSz.GetWidthSizeType() )
1530                         nNewSize = Max( nNewSize - nLR, nAutoWidth );
1531                     else
1532                         nNewSize = nAutoWidth;
1533                 }
1534             }
1535             else
1536                 nNewSize -= nLR;
1537 
1538             if( nNewSize < MINFLY )
1539                 nNewSize = MINFLY;
1540             (Prt().*fnRect->fnSetWidth)( nNewSize );
1541             nNewSize += nLR - (Frm().*fnRect->fnGetWidth)();
1542             (Frm().*fnRect->fnAddRight)( nNewSize );
1543             // --> OD 2006-08-16 #i68520#
1544             if ( nNewSize != 0 )
1545             {
1546                 InvalidateObjRectWithSpaces();
1547             }
1548             // <--
1549         }
1550 	}
1551 	ColUnlock();
1552 }
1553 
1554 // OD 14.03.2003 #i11760# - change parameter <bNoColl>: type <bool>;
1555 //                          default value = false.
1556 // OD 14.03.2003 #i11760# - add new parameter <bNoCalcFollow> with
1557 //                          default value = false.
1558 // OD 11.04.2003 #108824# - new parameter <bNoCalcFollow> was used by method
1559 //                          <FormatWidthCols(..)> to avoid follow formatting
1560 //                          for text frames. But, unformatted follows causes
1561 //                          problems in method <SwCntntFrm::_WouldFit(..)>,
1562 //                          which assumes that the follows are formatted.
1563 //                          Thus, <bNoCalcFollow> no longer used by <FormatWidthCols(..)>.
1564 //void CalcCntnt( SwLayoutFrm *pLay, sal_Bool bNoColl )
1565 void CalcCntnt( SwLayoutFrm *pLay,
1566                 bool bNoColl,
1567                 bool bNoCalcFollow )
1568 {
1569 	SwSectionFrm* pSect;
1570 	sal_Bool bCollect = sal_False;
1571 	if( pLay->IsSctFrm() )
1572 	{
1573 		pSect = (SwSectionFrm*)pLay;
1574 		if( pSect->IsEndnAtEnd() && !bNoColl )
1575 		{
1576 			bCollect = sal_True;
1577 			SwLayouter::CollectEndnotes( pLay->GetFmt()->GetDoc(), pSect );
1578 		}
1579 		pSect->CalcFtnCntnt();
1580 	}
1581 	else
1582 		pSect = NULL;
1583 	SwFrm *pFrm = pLay->ContainsAny();
1584 	if ( !pFrm )
1585 	{
1586 		if( pSect )
1587 		{
1588 			if( pSect->HasFollow() )
1589 				pFrm = pSect->GetFollow()->ContainsAny();
1590 			if( !pFrm )
1591 			{
1592 				if( pSect->IsEndnAtEnd() )
1593 				{
1594 					if( bCollect )
1595 						pLay->GetFmt()->GetDoc()->GetLayouter()->
1596 							InsertEndnotes( pSect );
1597 					sal_Bool bLock = pSect->IsFtnLock();
1598 					pSect->SetFtnLock( sal_True );
1599 					pSect->CalcFtnCntnt();
1600 					pSect->CalcFtnCntnt();
1601 					pSect->SetFtnLock( bLock );
1602 				}
1603 				return;
1604 			}
1605 			pFrm->_InvalidatePos();
1606 		}
1607 		else
1608 			return;
1609 	}
1610 	pFrm->InvalidatePage();
1611 
1612 	do
1613 	{
1614         // local variables to avoid loops caused by anchored object positioning
1615         SwAnchoredObject* pAgainObj1 = 0;
1616         SwAnchoredObject* pAgainObj2 = 0;
1617 
1618         // FME 2007-08-30 #i81146# new loop control
1619         sal_uInt16 nLoopControlRuns = 0;
1620         const sal_uInt16 nLoopControlMax = 20;
1621         const SwFrm* pLoopControlCond = 0;
1622 
1623         SwFrm* pLast;
1624 		do
1625 		{
1626 			pLast = pFrm;
1627             if( pFrm->IsVertical() ?
1628                 ( pFrm->GetUpper()->Prt().Height() != pFrm->Frm().Height() )
1629                 : ( pFrm->GetUpper()->Prt().Width() != pFrm->Frm().Width() ) )
1630 			{
1631 				pFrm->Prepare( PREP_FIXSIZE_CHG );
1632 				pFrm->_InvalidateSize();
1633 			}
1634 
1635 			if ( pFrm->IsTabFrm() )
1636 			{
1637 				((SwTabFrm*)pFrm)->bCalcLowers = sal_True;
1638                 // OD 26.08.2003 #i18103# - lock move backward of follow table,
1639                 // if no section content is formatted or follow table belongs
1640                 // to the section, which content is formatted.
1641                 if ( ((SwTabFrm*)pFrm)->IsFollow() &&
1642                      ( !pSect || pSect == pFrm->FindSctFrm() ) )
1643                 {
1644 					((SwTabFrm*)pFrm)->bLockBackMove = sal_True;
1645                 }
1646 			}
1647 
1648             // OD 14.03.2003 #i11760# - forbid format of follow, if requested.
1649             if ( bNoCalcFollow && pFrm->IsTxtFrm() )
1650                 static_cast<SwTxtFrm*>(pFrm)->ForbidFollowFormat();
1651 
1652             pFrm->Calc();
1653 
1654             // OD 14.03.2003 #i11760# - reset control flag for follow format.
1655             if ( pFrm->IsTxtFrm() )
1656             {
1657                 static_cast<SwTxtFrm*>(pFrm)->AllowFollowFormat();
1658             }
1659 
1660             // #111937# The keep-attribute can cause the position
1661             // of the prev to be invalid:
1662             // OD 2004-03-15 #116560# - Do not consider invalid previous frame
1663             // due to its keep-attribute, if current frame is a follow or is locked.
1664             // --> OD 2005-03-08 #i44049# - do not consider invalid previous
1665             // frame due to its keep-attribute, if it can't move forward.
1666             // --> OD 2006-01-27 #i57765# - do not consider invalid previous
1667             // frame, if current frame has a column/page break before attribute.
1668             SwFrm* pTmpPrev = pFrm->FindPrev();
1669             SwFlowFrm* pTmpPrevFlowFrm = pTmpPrev && pTmpPrev->IsFlowFrm() ? SwFlowFrm::CastFlowFrm(pTmpPrev) : 0;
1670             SwFlowFrm* pTmpFlowFrm     = pFrm->IsFlowFrm() ? SwFlowFrm::CastFlowFrm(pFrm) : 0;
1671 
1672             bool bPrevInvalid = pTmpPrevFlowFrm && pTmpFlowFrm &&
1673                                !pTmpFlowFrm->IsFollow() &&
1674                                !StackHack::IsLocked() && // #i76382#
1675                                !pTmpFlowFrm->IsJoinLocked() &&
1676                                !pTmpPrev->GetValidPosFlag() &&
1677                                 pLay->IsAnLower( pTmpPrev ) &&
1678                                 pTmpPrevFlowFrm->IsKeep( *pTmpPrev->GetAttrSet() ) &&
1679                                 pTmpPrevFlowFrm->IsKeepFwdMoveAllowed();
1680             // <--
1681 
1682             // format floating screen objects anchored to the frame.
1683             bool bRestartLayoutProcess = false;
1684             if ( !bPrevInvalid && pFrm->GetDrawObjs() && pLay->IsAnLower( pFrm ) )
1685 			{
1686                 bool bAgain = false;
1687                 SwPageFrm* pPageFrm = pFrm->FindPageFrm();
1688                 sal_uInt32 nCnt = pFrm->GetDrawObjs()->Count();
1689 				for ( sal_uInt16 i = 0; i < nCnt; ++i )
1690 				{
1691                     // --> OD 2004-07-01 #i28701#
1692                     SwAnchoredObject* pAnchoredObj = (*pFrm->GetDrawObjs())[i];
1693                     // determine, if anchored object has to be formatted.
1694                     if ( pAnchoredObj->PositionLocked() )
1695                     {
1696                         continue;
1697                     }
1698 
1699                     // format anchored object
1700                     if ( pAnchoredObj->IsFormatPossible() )
1701                     {
1702                         // --> OD 2005-05-17 #i43737# - no invalidation of
1703                         // anchored object needed - causes loops for as-character
1704                         // anchored objects.
1705                         //pAnchoredObj->InvalidateObjPos();
1706                         // <--
1707                         SwRect aRect( pAnchoredObj->GetObjRect() );
1708                         if ( !SwObjectFormatter::FormatObj( *pAnchoredObj, pFrm, pPageFrm ) )
1709                         {
1710                             bRestartLayoutProcess = true;
1711                             break;
1712                         }
1713                         // --> OD 2004-08-25 #i3317# - restart layout process,
1714                         // if the position of the anchored object is locked now.
1715                         if ( pAnchoredObj->PositionLocked() )
1716                         {
1717                             bRestartLayoutProcess = true;
1718                             break;
1719                         }
1720                         // <--
1721 
1722                         if ( aRect != pAnchoredObj->GetObjRect() )
1723                         {
1724                             bAgain = true;
1725                             if ( pAgainObj2 == pAnchoredObj )
1726                             {
1727                                 ASSERT( false,
1728                                         "::CalcCntnt(..) - loop detected, perform attribute changes to avoid the loop" );
1729                                 //Oszillation unterbinden.
1730                                 SwFrmFmt& rFmt = pAnchoredObj->GetFrmFmt();
1731                                 SwFmtSurround aAttr( rFmt.GetSurround() );
1732                                 if( SURROUND_THROUGHT != aAttr.GetSurround() )
1733                                 {
1734                                     // Bei autopositionierten hilft manchmal nur
1735                                     // noch, auf Durchlauf zu schalten
1736                                     if ((rFmt.GetAnchor().GetAnchorId() ==
1737                                             FLY_AT_CHAR) &&
1738                                         (SURROUND_PARALLEL ==
1739                                             aAttr.GetSurround()))
1740                                     {
1741                                         aAttr.SetSurround( SURROUND_THROUGHT );
1742                                     }
1743                                     else
1744                                     {
1745                                         aAttr.SetSurround( SURROUND_PARALLEL );
1746                                     }
1747                                     rFmt.LockModify();
1748                                     rFmt.SetFmtAttr( aAttr );
1749                                     rFmt.UnlockModify();
1750                                 }
1751                             }
1752                             else
1753                             {
1754                                 if ( pAgainObj1 == pAnchoredObj )
1755                                     pAgainObj2 = pAnchoredObj;
1756                                 pAgainObj1 = pAnchoredObj;
1757                             }
1758                         }
1759 
1760                         if ( !pFrm->GetDrawObjs() )
1761                             break;
1762                         if ( pFrm->GetDrawObjs()->Count() < nCnt )
1763                         {
1764                             --i;
1765                             --nCnt;
1766                         }
1767                     }
1768 				}
1769 
1770                 // --> OD 2004-06-11 #i28701# - restart layout process, if
1771                 // requested by floating screen object formatting
1772                 if ( bRestartLayoutProcess )
1773                 {
1774                     pFrm = pLay->ContainsAny();
1775                     pAgainObj1 = 0L;
1776                     pAgainObj2 = 0L;
1777                     continue;
1778                 }
1779 
1780                 // OD 2004-05-17 #i28701# - format anchor frame after its objects
1781                 // are formatted, if the wrapping style influence has to be considered.
1782                 if ( pLay->GetFmt()->getIDocumentSettingAccess()->get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION) )
1783                 {
1784                     pFrm->Calc();
1785                 }
1786                 // <--
1787 
1788                 if ( bAgain )
1789 				{
1790 					pFrm = pLay->ContainsCntnt();
1791 					if ( pFrm && pFrm->IsInTab() )
1792 						pFrm = pFrm->FindTabFrm();
1793 					if( pFrm && pFrm->IsInSct() )
1794 					{
1795 						SwSectionFrm* pTmp = pFrm->FindSctFrm();
1796 						if( pTmp != pLay && pLay->IsAnLower( pTmp ) )
1797 							pFrm = pTmp;
1798 					}
1799 
1800                     if ( pFrm == pLoopControlCond )
1801                         ++nLoopControlRuns;
1802                     else
1803                     {
1804                         nLoopControlRuns = 0;
1805                         pLoopControlCond = pFrm;
1806                     }
1807 
1808                     if ( nLoopControlRuns < nLoopControlMax )
1809                         continue;
1810 
1811 #if OSL_DEBUG_LEVEL > 1
1812                     ASSERT( false, "LoopControl in CalcCntnt" )
1813 #endif
1814 				}
1815 			}
1816 			if ( pFrm->IsTabFrm() )
1817 			{
1818 				if ( ((SwTabFrm*)pFrm)->IsFollow() )
1819 					((SwTabFrm*)pFrm)->bLockBackMove = sal_False;
1820 			}
1821 
1822             pFrm = bPrevInvalid ? pTmpPrev : pFrm->FindNext();
1823             if( !bPrevInvalid && pFrm && pFrm->IsSctFrm() && pSect )
1824 			{
1825 				// Es koennen hier leere SectionFrms herumspuken
1826 				while( pFrm && pFrm->IsSctFrm() && !((SwSectionFrm*)pFrm)->GetSection() )
1827 					pFrm = pFrm->FindNext();
1828 				// Wenn FindNext den Follow des urspruenglichen Bereichs liefert,
1829 				// wollen wir mit dessen Inhalt weitermachen, solange dieser
1830 				// zurueckfliesst.
1831 				if( pFrm && pFrm->IsSctFrm() && ( pFrm == pSect->GetFollow() ||
1832 					((SwSectionFrm*)pFrm)->IsAnFollow( pSect ) ) )
1833 				{
1834 					pFrm = ((SwSectionFrm*)pFrm)->ContainsAny();
1835 					if( pFrm )
1836 						pFrm->_InvalidatePos();
1837 				}
1838 			}
1839 			// Im pLay bleiben, Ausnahme, bei SectionFrms mit Follow wird der erste
1840 			// CntntFrm des Follows anformatiert, damit er die Chance erhaelt, in
1841 			// pLay zu landen. Solange diese Frames in pLay landen, geht's weiter.
1842         } while ( pFrm &&
1843                   ( pLay->IsAnLower( pFrm ) ||
1844                     ( pSect &&
1845                       ( ( pSect->HasFollow() &&
1846                           ( pLay->IsAnLower( pLast ) ||
1847                             ( pLast->IsInSct() &&
1848                               pLast->FindSctFrm()->IsAnFollow(pSect) ) ) &&
1849                           pSect->GetFollow()->IsAnLower( pFrm )  ) ||
1850                         ( pFrm->IsInSct() &&
1851                           pFrm->FindSctFrm()->IsAnFollow( pSect ) ) ) ) ) );
1852 		if( pSect )
1853 		{
1854 			if( bCollect )
1855 			{
1856 				pLay->GetFmt()->GetDoc()->GetLayouter()->InsertEndnotes(pSect);
1857 				pSect->CalcFtnCntnt();
1858 			}
1859 			if( pSect->HasFollow() )
1860 			{
1861 				SwSectionFrm* pNxt = pSect->GetFollow();
1862 				while( pNxt && !pNxt->ContainsCntnt() )
1863 					pNxt = pNxt->GetFollow();
1864 				if( pNxt )
1865 					pNxt->CalcFtnCntnt();
1866 			}
1867 			if( bCollect )
1868 			{
1869 				pFrm = pLay->ContainsAny();
1870 				bCollect = sal_False;
1871 				if( pFrm )
1872 					continue;
1873 			}
1874 		}
1875 		break;
1876 	}
1877 	while( sal_True );
1878 }
1879 
1880 /*************************************************************************
1881 |*
1882 |*	SwFlyFrm::MakeFlyPos()
1883 |*
1884 |*	Ersterstellung		MA ??
1885 |*	Letzte Aenderung	MA 14. Nov. 96
1886 |*
1887 |*************************************************************************/
1888 // OD 2004-03-23 #i26791#
1889 //void SwFlyFrm::MakeFlyPos()
1890 void SwFlyFrm::MakeObjPos()
1891 {
1892     if ( !bValidPos )
1893     {
1894         bValidPos = sal_True;
1895 
1896         // OD 29.10.2003 #113049# - use new class to position object
1897         GetAnchorFrm()->Calc();
1898         objectpositioning::SwToLayoutAnchoredObjectPosition
1899                 aObjPositioning( *GetVirtDrawObj() );
1900         aObjPositioning.CalcPosition();
1901 
1902         // --> OD 2006-10-05 #i58280#
1903         // update relative position
1904         SetCurrRelPos( aObjPositioning.GetRelPos() );
1905         // <--
1906 
1907         SWRECTFN( GetAnchorFrm() );
1908         aFrm.Pos( aObjPositioning.GetRelPos() );
1909         aFrm.Pos() += (GetAnchorFrm()->Frm().*fnRect->fnGetPos)();
1910         // --> OD 2006-09-11 #i69335#
1911         InvalidateObjRectWithSpaces();
1912         // <--
1913     }
1914 }
1915 
1916 /*************************************************************************
1917 |*
1918 |*	SwFlyFrm::MakePrtArea()
1919 |*
1920 |*	Ersterstellung		MA 23. Jun. 93
1921 |*	Letzte Aenderung	MA 23. Jun. 93
1922 |*
1923 |*************************************************************************/
1924 void SwFlyFrm::MakePrtArea( const SwBorderAttrs &rAttrs )
1925 {
1926 
1927 	if ( !bValidPrtArea )
1928 	{
1929 		bValidPrtArea = sal_True;
1930 
1931         // OD 31.07.2003 #110978# - consider vertical layout
1932         SWRECTFN( this )
1933         (this->*fnRect->fnSetXMargins)( rAttrs.CalcLeftLine(),
1934                                         rAttrs.CalcRightLine() );
1935         (this->*fnRect->fnSetYMargins)( rAttrs.CalcTopLine(),
1936                                         rAttrs.CalcBottomLine() );
1937 	}
1938 }
1939 
1940 /*************************************************************************
1941 |*
1942 |*	SwFlyFrm::_Grow(), _Shrink()
1943 |*
1944 |*	Ersterstellung		MA 05. Oct. 92
1945 |*	Letzte Aenderung	MA 05. Sep. 96
1946 |*
1947 |*************************************************************************/
1948 
1949 SwTwips SwFlyFrm::_Grow( SwTwips nDist, sal_Bool bTst )
1950 {
1951     SWRECTFN( this )
1952     if ( Lower() && !IsColLocked() && !HasFixSize() )
1953 	{
1954         SwTwips nSize = (Frm().*fnRect->fnGetHeight)();
1955         if( nSize > 0 && nDist > ( LONG_MAX - nSize ) )
1956             nDist = LONG_MAX - nSize;
1957 
1958 		if ( nDist <= 0L )
1959 			return 0L;
1960 
1961 		if ( Lower()->IsColumnFrm() )
1962 		{	//Bei Spaltigkeit ubernimmt das Format die Kontrolle ueber
1963 			//das Wachstum (wg. des Ausgleichs).
1964 			if ( !bTst )
1965             {
1966                 // --> OD 2004-06-09 #i28701# - unlock position of Writer fly frame
1967                 UnlockPosition();
1968                 _InvalidatePos();
1969 				InvalidateSize();
1970 			}
1971 			return 0L;
1972 		}
1973 
1974 		if ( !bTst )
1975 		{
1976             const SwRect aOld( GetObjRectWithSpaces() );
1977 			_InvalidateSize();
1978 			const sal_Bool bOldLock = bLocked;
1979 			Unlock();
1980             if ( IsFlyFreeFrm() )
1981             {
1982                 // --> OD 2004-11-12 #i37068# - no format of position here
1983                 // and prevent move in method <CheckClip(..)>.
1984                 // This is needed to prevent layout loop caused by nested
1985                 // Writer fly frames - inner Writer fly frames format its
1986                 // anchor, which grows/shrinks the outer Writer fly frame.
1987                 // Note: position will be invalidated below.
1988                 bValidPos = sal_True;
1989                 // --> OD 2005-10-10 #i55416#
1990                 // Suppress format of width for autowidth frame, because the
1991                 // format of the width would call <SwTxtFrm::CalcFitToContent()>
1992                 // for the lower frame, which initiated this grow.
1993                 const sal_Bool bOldFormatHeightOnly = bFormatHeightOnly;
1994                 const SwFmtFrmSize& rFrmSz = GetFmt()->GetFrmSize();
1995                 if ( rFrmSz.GetWidthSizeType() != ATT_FIX_SIZE )
1996                 {
1997                     bFormatHeightOnly = sal_True;
1998                 }
1999                 // <--
2000                 static_cast<SwFlyFreeFrm*>(this)->SetNoMoveOnCheckClip( true );
2001                 ((SwFlyFreeFrm*)this)->SwFlyFreeFrm::MakeAll();
2002                 static_cast<SwFlyFreeFrm*>(this)->SetNoMoveOnCheckClip( false );
2003                 // --> OD 2005-10-10 #i55416#
2004                 if ( rFrmSz.GetWidthSizeType() != ATT_FIX_SIZE )
2005                 {
2006                     bFormatHeightOnly = bOldFormatHeightOnly;
2007                 }
2008                 // <--
2009                 // <--
2010             }
2011             else
2012 				MakeAll();
2013 			_InvalidateSize();
2014 			InvalidatePos();
2015 			if ( bOldLock )
2016 				Lock();
2017             const SwRect aNew( GetObjRectWithSpaces() );
2018 			if ( aOld != aNew )
2019 				::Notify( this, FindPageFrm(), aOld );
2020             return (aNew.*fnRect->fnGetHeight)()-(aOld.*fnRect->fnGetHeight)();
2021 		}
2022 		return nDist;
2023 	}
2024 	return 0L;
2025 }
2026 
2027 SwTwips SwFlyFrm::_Shrink( SwTwips nDist, sal_Bool bTst )
2028 {
2029     if( Lower() && !IsColLocked() && !HasFixSize() && !IsNoShrink() )
2030 	{
2031         SWRECTFN( this )
2032         SwTwips nHeight = (Frm().*fnRect->fnGetHeight)();
2033         if ( nDist > nHeight )
2034             nDist = nHeight;
2035 
2036         SwTwips nVal = nDist;
2037 		if ( IsMinHeight() )
2038 		{
2039             const SwFmtFrmSize& rFmtSize = GetFmt()->GetFrmSize();
2040             SwTwips nFmtHeight = bVert ? rFmtSize.GetWidth() : rFmtSize.GetHeight();
2041 
2042             nVal = Min( nDist, nHeight - nFmtHeight );
2043 		}
2044 
2045 		if ( nVal <= 0L )
2046 			return 0L;
2047 
2048 		if ( Lower()->IsColumnFrm() )
2049 		{	//Bei Spaltigkeit ubernimmt das Format die Kontrolle ueber
2050 			//das Wachstum (wg. des Ausgleichs).
2051 			if ( !bTst )
2052 			{
2053                 SwRect aOld( GetObjRectWithSpaces() );
2054                 (Frm().*fnRect->fnSetHeight)( nHeight - nVal );
2055                 // --> OD 2006-08-16 #i68520#
2056                 if ( nHeight - nVal != 0 )
2057                 {
2058                     InvalidateObjRectWithSpaces();
2059                 }
2060                 // <--
2061                 nHeight = (Prt().*fnRect->fnGetHeight)();
2062                 (Prt().*fnRect->fnSetHeight)( nHeight - nVal );
2063 				_InvalidatePos();
2064 				InvalidateSize();
2065 				::Notify( this, FindPageFrm(), aOld );
2066 				NotifyDrawObj();
2067                 if ( GetAnchorFrm()->IsInFly() )
2068                     AnchorFrm()->FindFlyFrm()->Shrink( nDist, bTst );
2069 			}
2070 			return 0L;
2071 		}
2072 
2073 		if ( !bTst )
2074 		{
2075             const SwRect aOld( GetObjRectWithSpaces() );
2076 			_InvalidateSize();
2077 			const sal_Bool bOldLocked = bLocked;
2078 			Unlock();
2079             if ( IsFlyFreeFrm() )
2080             {
2081                 // --> OD 2004-11-12 #i37068# - no format of position here
2082                 // and prevent move in method <CheckClip(..)>.
2083                 // This is needed to prevent layout loop caused by nested
2084                 // Writer fly frames - inner Writer fly frames format its
2085                 // anchor, which grows/shrinks the outer Writer fly frame.
2086                 // Note: position will be invalidated below.
2087                 bValidPos = sal_True;
2088                 // --> OD 2005-10-10 #i55416#
2089                 // Suppress format of width for autowidth frame, because the
2090                 // format of the width would call <SwTxtFrm::CalcFitToContent()>
2091                 // for the lower frame, which initiated this shrink.
2092                 const sal_Bool bOldFormatHeightOnly = bFormatHeightOnly;
2093                 const SwFmtFrmSize& rFrmSz = GetFmt()->GetFrmSize();
2094                 if ( rFrmSz.GetWidthSizeType() != ATT_FIX_SIZE )
2095                 {
2096                     bFormatHeightOnly = sal_True;
2097                 }
2098                 // <--
2099                 static_cast<SwFlyFreeFrm*>(this)->SetNoMoveOnCheckClip( true );
2100                 ((SwFlyFreeFrm*)this)->SwFlyFreeFrm::MakeAll();
2101                 static_cast<SwFlyFreeFrm*>(this)->SetNoMoveOnCheckClip( false );
2102                 // --> OD 2005-10-10 #i55416#
2103                 if ( rFrmSz.GetWidthSizeType() != ATT_FIX_SIZE )
2104                 {
2105                     bFormatHeightOnly = bOldFormatHeightOnly;
2106                 }
2107                 // <--
2108                 // <--
2109             }
2110             else
2111 				MakeAll();
2112 			_InvalidateSize();
2113 			InvalidatePos();
2114 			if ( bOldLocked )
2115 				Lock();
2116             const SwRect aNew( GetObjRectWithSpaces() );
2117 			if ( aOld != aNew )
2118 			{
2119 				::Notify( this, FindPageFrm(), aOld );
2120                 if ( GetAnchorFrm()->IsInFly() )
2121                     AnchorFrm()->FindFlyFrm()->Shrink( nDist, bTst );
2122 			}
2123             return (aOld.*fnRect->fnGetHeight)() -
2124                    (aNew.*fnRect->fnGetHeight)();
2125 		}
2126 		return nVal;
2127 	}
2128 	return 0L;
2129 }
2130 
2131 /*************************************************************************
2132 |*
2133 |*	SwFlyFrm::ChgSize()
2134 |*
2135 |*	Ersterstellung		MA 05. Oct. 92
2136 |*	Letzte Aenderung	MA 04. Sep. 96
2137 |*
2138 |*************************************************************************/
2139 
2140 Size SwFlyFrm::ChgSize( const Size& aNewSize )
2141 {
2142     // --> OD 2006-01-19 #i53298#
2143     // If the fly frame anchored at-paragraph or at-character contains an OLE
2144     // object, assure that the new size fits into the current clipping area
2145     // of the fly frame
2146     Size aAdjustedNewSize( aNewSize );
2147     {
2148         if ( dynamic_cast<SwFlyAtCntFrm*>(this) &&
2149              Lower() && dynamic_cast<SwNoTxtFrm*>(Lower()) &&
2150              static_cast<SwNoTxtFrm*>(Lower())->GetNode()->GetOLENode() )
2151         {
2152             SwRect aClipRect;
2153             ::CalcClipRect( GetVirtDrawObj(), aClipRect, sal_False );
2154             if ( aAdjustedNewSize.Width() > aClipRect.Width() )
2155             {
2156                 aAdjustedNewSize.setWidth( aClipRect.Width() );
2157             }
2158             if ( aAdjustedNewSize.Height() > aClipRect.Height() )
2159             {
2160                 aAdjustedNewSize.setWidth( aClipRect.Height() );
2161             }
2162         }
2163     }
2164     // <--
2165     if ( aAdjustedNewSize != Frm().SSize() )
2166 	{
2167 		SwFrmFmt *pFmt = GetFmt();
2168 		SwFmtFrmSize aSz( pFmt->GetFrmSize() );
2169         aSz.SetWidth( aAdjustedNewSize.Width() );
2170         // --> OD 2006-01-19 #i53298# - no tolerance any more.
2171         // If it reveals that the tolerance is still needed, then suppress a
2172         // <SetAttr> call, if <aSz> equals the current <SwFmtFrmSize> attribute.
2173 //        if ( Abs(aAdjustedNewSize.Height() - aSz.GetHeight()) > 1 )
2174         aSz.SetHeight( aAdjustedNewSize.Height() );
2175         // <--
2176 		// uebers Doc fuers Undo!
2177 		pFmt->GetDoc()->SetAttr( aSz, *pFmt );
2178 		return aSz.GetSize();
2179 	}
2180 	else
2181 		return Frm().SSize();
2182 }
2183 
2184 /*************************************************************************
2185 |*
2186 |*	SwFlyFrm::IsLowerOf()
2187 |*
2188 |*	Ersterstellung		MA 27. Dec. 93
2189 |*	Letzte Aenderung	MA 27. Dec. 93
2190 |*
2191 |*************************************************************************/
2192 
2193 sal_Bool SwFlyFrm::IsLowerOf( const SwLayoutFrm* pUpperFrm ) const
2194 {
2195     ASSERT( GetAnchorFrm(), "8-( Fly is lost in Space." );
2196     const SwFrm* pFrm = GetAnchorFrm();
2197     do
2198     {
2199         if ( pFrm == pUpperFrm )
2200             return sal_True;
2201         pFrm = pFrm->IsFlyFrm()
2202                ? ((const SwFlyFrm*)pFrm)->GetAnchorFrm()
2203                : pFrm->GetUpper();
2204     } while ( pFrm );
2205     return sal_False;
2206 }
2207 
2208 /*************************************************************************
2209 |*
2210 |*	SwFlyFrm::Cut()
2211 |*
2212 |*	Ersterstellung		MA 23. Feb. 94
2213 |*	Letzte Aenderung	MA 23. Feb. 94
2214 |*
2215 |*************************************************************************/
2216 
2217 void SwFlyFrm::Cut()
2218 {
2219 }
2220 
2221 /*************************************************************************
2222 |*
2223 |*	SwFrm::AppendFly(), RemoveFly()
2224 |*
2225 |*	Ersterstellung		MA 25. Aug. 92
2226 |*	Letzte Aenderung	MA 09. Jun. 95
2227 |*
2228 |*************************************************************************/
2229 
2230 void SwFrm::AppendFly( SwFlyFrm *pNew )
2231 {
2232     if ( !pDrawObjs )
2233         pDrawObjs = new SwSortedObjs();
2234     pDrawObjs->Insert( *pNew );
2235     pNew->ChgAnchorFrm( this );
2236 
2237 	//Bei der Seite anmelden; kann sein, dass noch keine da ist - die
2238 	//Anmeldung wird dann in SwPageFrm::PreparePage durch gefuehrt.
2239 	SwPageFrm *pPage = FindPageFrm();
2240 	if ( pPage )
2241 	{
2242 		if ( pNew->IsFlyAtCntFrm() && pNew->Frm().Top() == WEIT_WECH )
2243 		{
2244 			//Versuch die Seitenformatierung von neuen Dokumenten etwas
2245 			//guenstiger zu gestalten.
2246 			//Wir haengen die Flys erstenmal nach hinten damit sie bei heftigem
2247 			//Fluss der Anker nicht unoetig oft formatiert werden.
2248 			//Damit man noch brauchbar an das Ende des Dokumentes springen
2249 			//kann werden die Flys nicht ganz an das Ende gehaengt.
2250 			SwRootFrm *pRoot = (SwRootFrm*)pPage->GetUpper();
2251             if( !SwLayHelper::CheckPageFlyCache( pPage, pNew ) )
2252             {
2253                 SwPageFrm *pTmp = pRoot->GetLastPage();
2254                 if ( pTmp->GetPhyPageNum() > 30 )
2255                 {
2256                     for ( sal_uInt16 i = 0; i < 10; ++i )
2257                     {
2258                         pTmp = (SwPageFrm*)pTmp->GetPrev();
2259                         if( pTmp->GetPhyPageNum() <= pPage->GetPhyPageNum() )
2260                             break; // damit wir nicht vor unserem Anker landen
2261                     }
2262                     if ( pTmp->IsEmptyPage() )
2263                         pTmp = (SwPageFrm*)pTmp->GetPrev();
2264                     pPage = pTmp;
2265                 }
2266 			}
2267             pPage->AppendFlyToPage( pNew );
2268 		}
2269 		else
2270             pPage->AppendFlyToPage( pNew );
2271     }
2272 }
2273 
2274 void SwFrm::RemoveFly( SwFlyFrm *pToRemove )
2275 {
2276 	//Bei der Seite Abmelden - kann schon passiert sein weil die Seite
2277 	//bereits destruiert wurde.
2278 	SwPageFrm *pPage = pToRemove->FindPageFrm();
2279 	if ( pPage && pPage->GetSortedObjs() )
2280     {
2281         pPage->RemoveFlyFromPage( pToRemove );
2282     }
2283     // --> OD 2008-05-19 #i73201#
2284     else
2285     {
2286         if ( pToRemove->IsAccessibleFrm() &&
2287              pToRemove->GetFmt() &&
2288              !pToRemove->IsFlyInCntFrm() )
2289         {
2290             SwRootFrm *pRootFrm = getRootFrm();
2291             if( pRootFrm && pRootFrm->IsAnyShellAccessible() )
2292             {
2293                 ViewShell *pVSh = pRootFrm->GetCurrShell();
2294                 if( pVSh && pVSh->Imp() )
2295                 {
2296                     pVSh->Imp()->DisposeAccessibleFrm( pToRemove );
2297                 }
2298             }
2299         }
2300     }
2301     // <--
2302 
2303     pDrawObjs->Remove( *pToRemove );
2304 	if ( !pDrawObjs->Count() )
2305 		DELETEZ( pDrawObjs );
2306 
2307     pToRemove->ChgAnchorFrm( 0 );
2308 
2309 	if ( !pToRemove->IsFlyInCntFrm() && GetUpper() && IsInTab() )//MA_FLY_HEIGHT
2310 		GetUpper()->InvalidateSize();
2311 }
2312 
2313 /*************************************************************************
2314 |*
2315 |*	SwFrm::AppendDrawObj(), RemoveDrawObj()
2316 |*
2317 |*  --> OD 2004-07-06 #i28701# - new methods
2318 |*
2319 |*************************************************************************/
2320 void SwFrm::AppendDrawObj( SwAnchoredObject& _rNewObj )
2321 {
2322     if ( !_rNewObj.ISA(SwAnchoredDrawObject) )
2323     {
2324         ASSERT( false,
2325                 "SwFrm::AppendDrawObj(..) - anchored object of unexcepted type -> object not appended" );
2326         return;
2327     }
2328 
2329     if ( !_rNewObj.GetDrawObj()->ISA(SwDrawVirtObj) &&
2330          _rNewObj.GetAnchorFrm() && _rNewObj.GetAnchorFrm() != this )
2331     {
2332         // perform disconnect from layout, if 'master' drawing object is appended
2333         // to a new frame.
2334         static_cast<SwDrawContact*>(::GetUserCall( _rNewObj.GetDrawObj() ))->
2335                                                 DisconnectFromLayout( false );
2336     }
2337 
2338     if ( _rNewObj.GetAnchorFrm() != this )
2339     {
2340         if ( !pDrawObjs )
2341             pDrawObjs = new SwSortedObjs();
2342         pDrawObjs->Insert( _rNewObj );
2343         _rNewObj.ChgAnchorFrm( this );
2344     }
2345 
2346     // --> OD 2010-09-14 #i113730#
2347     // Assure the control objects and group objects containing controls are on the control layer
2348     if ( ::CheckControlLayer( _rNewObj.DrawObj() ) )
2349     {
2350         const IDocumentDrawModelAccess* pIDDMA = (IsFlyFrm())
2351             ? static_cast<SwFlyFrm*>(this)->GetFmt()->
2352                     getIDocumentDrawModelAccess()
2353             : GetUpper()->GetFmt()->getIDocumentDrawModelAccess();
2354         const SdrLayerID aCurrentLayer(_rNewObj.DrawObj()->GetLayer());
2355         const SdrLayerID aControlLayerID(pIDDMA->GetControlsId());
2356         const SdrLayerID aInvisibleControlLayerID(pIDDMA->GetInvisibleControlsId());
2357 
2358         if(aCurrentLayer != aControlLayerID && aCurrentLayer != aInvisibleControlLayerID)
2359         {
2360             if ( aCurrentLayer == pIDDMA->GetInvisibleHellId() ||
2361                  aCurrentLayer == pIDDMA->GetInvisibleHeavenId() )
2362             {
2363                 _rNewObj.DrawObj()->SetLayer(aInvisibleControlLayerID);
2364             }
2365             else
2366             {
2367                 _rNewObj.DrawObj()->SetLayer(aControlLayerID);
2368             }
2369         }
2370     }
2371     // <--
2372 
2373     // no direct positioning needed, but invalidate the drawing object position
2374     _rNewObj.InvalidateObjPos();
2375 
2376     // register at page frame
2377     SwPageFrm* pPage = FindPageFrm();
2378     if ( pPage )
2379     {
2380         pPage->AppendDrawObjToPage( _rNewObj );
2381     }
2382 
2383     // Notify accessible layout.
2384     ViewShell* pSh = getRootFrm()->GetCurrShell();
2385     if( pSh )
2386     {
2387         SwRootFrm* pLayout = getRootFrm();
2388         if( pLayout && pLayout->IsAnyShellAccessible() )
2389         pSh->Imp()->AddAccessibleObj( _rNewObj.GetDrawObj() );
2390     }
2391 }
2392 
2393 void SwFrm::RemoveDrawObj( SwAnchoredObject& _rToRemoveObj )
2394 {
2395     // Notify accessible layout.
2396     ViewShell* pSh = getRootFrm()->GetCurrShell();
2397     if( pSh )
2398     {
2399         SwRootFrm* pLayout = getRootFrm();
2400         if( pLayout && pLayout->IsAnyShellAccessible() )
2401         pSh->Imp()->DisposeAccessibleObj( _rToRemoveObj.GetDrawObj() );
2402     }
2403 
2404     // deregister from page frame
2405     SwPageFrm* pPage = _rToRemoveObj.GetPageFrm();
2406     if ( pPage && pPage->GetSortedObjs() )
2407         pPage->RemoveDrawObjFromPage( _rToRemoveObj );
2408 
2409     pDrawObjs->Remove( _rToRemoveObj );
2410     if ( !pDrawObjs->Count() )
2411         DELETEZ( pDrawObjs );
2412 
2413     _rToRemoveObj.ChgAnchorFrm( 0 );
2414 }
2415 
2416 /*************************************************************************
2417 |*
2418 |*  SwFrm::InvalidateObjs()
2419 |*
2420 |*	Ersterstellung		MA 29. Nov. 96
2421 |*	Letzte Aenderung	MA 29. Nov. 96
2422 |*
2423 |*************************************************************************/
2424 // --> OD 2004-07-01 #i28701# - change purpose of method and adjust its name
2425 void SwFrm::InvalidateObjs( const bool _bInvaPosOnly,
2426                             const bool _bNoInvaOfAsCharAnchoredObjs )
2427 {
2428 	if ( GetDrawObjs() )
2429 	{
2430         // --> OD 2004-10-08 #i26945# - determine page the frame is on,
2431         // in order to check, if anchored object is registered at the same
2432         // page.
2433         const SwPageFrm* pPageFrm = FindPageFrm();
2434         // <--
2435         // --> OD 2004-07-01 #i28701# - re-factoring
2436         sal_uInt32 i = 0;
2437         for ( ; i < GetDrawObjs()->Count(); ++i )
2438         {
2439             SwAnchoredObject* pAnchoredObj = (*GetDrawObjs())[i];
2440             if ( _bNoInvaOfAsCharAnchoredObjs &&
2441                  (pAnchoredObj->GetFrmFmt().GetAnchor().GetAnchorId()
2442                     == FLY_AS_CHAR) )
2443             {
2444                 continue;
2445             }
2446             // --> OD 2004-10-08 #i26945# - no invalidation, if anchored object
2447             // isn't registered at the same page and instead is registered at
2448             // the page, where its anchor character text frame is on.
2449             if ( pAnchoredObj->GetPageFrm() &&
2450                  pAnchoredObj->GetPageFrm() != pPageFrm )
2451             {
2452                 SwTxtFrm* pAnchorCharFrm = pAnchoredObj->FindAnchorCharFrm();
2453                 if ( pAnchorCharFrm &&
2454                      pAnchoredObj->GetPageFrm() == pAnchorCharFrm->FindPageFrm() )
2455                 {
2456                     continue;
2457                 }
2458                 // --> OD 2004-11-24 #115759# - unlock its position, if anchored
2459                 // object isn't registered at the page, where its anchor
2460                 // character text frame is on, respectively if it has no
2461                 // anchor character text frame.
2462                 else
2463                 {
2464                     pAnchoredObj->UnlockPosition();
2465                 }
2466                 // <--
2467             }
2468             // <--
2469             // --> OD 2005-07-18 #i51474# - reset flag, that anchored object
2470             // has cleared environment, and unlock its position, if the anchored
2471             // object is registered at the same page as the anchor frame is on.
2472             if ( pAnchoredObj->ClearedEnvironment() &&
2473                  pAnchoredObj->GetPageFrm() &&
2474                  pAnchoredObj->GetPageFrm() == pPageFrm )
2475             {
2476                 pAnchoredObj->UnlockPosition();
2477                 pAnchoredObj->SetClearedEnvironment( false );
2478             }
2479             // <--
2480             // distinguish between writer fly frames and drawing objects
2481             if ( pAnchoredObj->ISA(SwFlyFrm) )
2482             {
2483                 SwFlyFrm* pFly = static_cast<SwFlyFrm*>(pAnchoredObj);
2484                 pFly->_Invalidate();
2485                 pFly->_InvalidatePos();
2486                 if ( !_bInvaPosOnly )
2487                     pFly->_InvalidateSize();
2488             }
2489             else
2490             {
2491                 pAnchoredObj->InvalidateObjPos();
2492             } // end of distinction between writer fly frames and drawing objects
2493 
2494         } // end of loop on objects, which are connected to the frame
2495 	}
2496 }
2497 
2498 /*************************************************************************
2499 |*
2500 |*  SwLayoutFrm::NotifyLowerObjs()
2501 |*
2502 |*************************************************************************/
2503 // --> OD 2004-07-01 #i28701# - change purpose of method and its name
2504 // --> OD 2004-10-08 #i26945# - correct check, if anchored object is a lower
2505 // of the layout frame. E.g., anchor character text frame can be a follow text
2506 // frame.
2507 // --> OD 2005-03-11 #i44016# - add parameter <_bUnlockPosOfObjs> to
2508 // force an unlockposition call for the lower objects.
2509 void SwLayoutFrm::NotifyLowerObjs( const bool _bUnlockPosOfObjs )
2510 {
2511     // invalidate lower floating screen objects
2512     SwPageFrm* pPageFrm = FindPageFrm();
2513     if ( pPageFrm && pPageFrm->GetSortedObjs() )
2514 	{
2515         SwSortedObjs& rObjs = *(pPageFrm->GetSortedObjs());
2516         for ( sal_uInt32 i = 0; i < rObjs.Count(); ++i )
2517 		{
2518             SwAnchoredObject* pObj = rObjs[i];
2519             // --> OD 2004-10-08 #i26945# - check, if anchored object is a lower
2520             // of the layout frame is changed to check, if its anchor frame
2521             // is a lower of the layout frame.
2522             // determine the anchor frame - usually it's the anchor frame,
2523             // for at-character/as-character anchored objects the anchor character
2524             // text frame is taken.
2525             const SwFrm* pAnchorFrm = pObj->GetAnchorFrmContainingAnchPos();
2526             // <--
2527             if ( pObj->ISA(SwFlyFrm) )
2528 			{
2529                 SwFlyFrm* pFly = static_cast<SwFlyFrm*>(pObj);
2530 
2531 				if ( pFly->Frm().Left() == WEIT_WECH )
2532 					continue;
2533 
2534                 if ( pFly->IsAnLower( this ) )
2535 					continue;
2536 
2537                 // --> OD 2004-10-08 #i26945# - use <pAnchorFrm> to check, if
2538                 // fly frame is lower of layout frame resp. if fly frame is
2539                 // at a different page registered as its anchor frame is on.
2540                 const bool bLow = IsAnLower( pAnchorFrm );
2541                 if ( bLow || pAnchorFrm->FindPageFrm() != pPageFrm )
2542                 // <--
2543 				{
2544                     pFly->_Invalidate( pPageFrm );
2545 					if ( !bLow || pFly->IsFlyAtCntFrm() )
2546                     {
2547                         // --> OD 2005-03-11 #i44016#
2548                         if ( _bUnlockPosOfObjs )
2549                         {
2550                             pFly->UnlockPosition();
2551                         }
2552                         // <--
2553                         pFly->_InvalidatePos();
2554                     }
2555 					else
2556 						pFly->_InvalidatePrt();
2557 				}
2558 			}
2559             else
2560             {
2561                 ASSERT( pObj->ISA(SwAnchoredDrawObject),
2562                         "<SwLayoutFrm::NotifyFlys() - anchored object of unexcepted type" );
2563                 // --> OD 2004-10-08 #i26945# - use <pAnchorFrm> to check, if
2564                 // fly frame is lower of layout frame resp. if fly frame is
2565                 // at a different page registered as its anchor frame is on.
2566                 if ( IsAnLower( pAnchorFrm ) ||
2567                      pAnchorFrm->FindPageFrm() != pPageFrm )
2568                 // <--
2569                 {
2570                     // --> OD 2005-03-11 #i44016#
2571                     if ( _bUnlockPosOfObjs )
2572                     {
2573                         pObj->UnlockPosition();
2574                     }
2575                     // <--
2576                     pObj->InvalidateObjPos();
2577                 }
2578             }
2579 		}
2580 	}
2581 }
2582 
2583 /*************************************************************************
2584 |*
2585 |*	SwFlyFrm::NotifyDrawObj()
2586 |*
2587 |*	Ersterstellung		OK 22. Nov. 94
2588 |*	Letzte Aenderung	MA 10. Jan. 97
2589 |*
2590 |*************************************************************************/
2591 
2592 void SwFlyFrm::NotifyDrawObj()
2593 {
2594     SwVirtFlyDrawObj* pObj = GetVirtDrawObj();
2595     pObj->SetRect();
2596     pObj->SetRectsDirty();
2597     pObj->SetChanged();
2598     pObj->BroadcastObjectChange();
2599 	if ( GetFmt()->GetSurround().IsContour() )
2600         ClrContourCache( pObj );
2601 }
2602 
2603 /*************************************************************************
2604 |*
2605 |*  SwFlyFrm::CalcRel()
2606 |*
2607 |*	Ersterstellung		MA 13. Jun. 96
2608 |*	Letzte Aenderung	MA 10. Oct. 96
2609 |*
2610 |*************************************************************************/
2611 
2612 Size SwFlyFrm::CalcRel( const SwFmtFrmSize &rSz ) const
2613 {
2614 	Size aRet( rSz.GetSize() );
2615 
2616     const SwFrm *pRel = IsFlyLayFrm() ? GetAnchorFrm() : GetAnchorFrm()->GetUpper();
2617 	if( pRel ) // LAYER_IMPL
2618 	{
2619 		long nRelWidth = LONG_MAX, nRelHeight = LONG_MAX;
2620 		const ViewShell *pSh = getRootFrm()->GetCurrShell();
2621 		if ( ( pRel->IsBodyFrm() || pRel->IsPageFrm() ) &&
2622              pSh && pSh->GetViewOptions()->getBrowseMode() &&
2623 			 pSh->VisArea().HasArea() )
2624 		{
2625 			nRelWidth  = pSh->GetBrowseWidth();
2626 			nRelHeight = pSh->VisArea().Height();
2627 			Size aBorder = pSh->GetOut()->PixelToLogic( pSh->GetBrowseBorder() );
2628 			long nDiff = nRelWidth - pRel->Prt().Width();
2629 			if ( nDiff > 0 )
2630 				nRelWidth -= nDiff;
2631 			nRelHeight -= 2*aBorder.Height();
2632 			nDiff = nRelHeight - pRel->Prt().Height();
2633 			if ( nDiff > 0 )
2634 				nRelHeight -= nDiff;
2635 		}
2636 		nRelWidth  = Min( nRelWidth,  pRel->Prt().Width() );
2637 		nRelHeight = Min( nRelHeight, pRel->Prt().Height() );
2638         if( !pRel->IsPageFrm() )
2639         {
2640             const SwPageFrm* pPage = FindPageFrm();
2641             if( pPage )
2642             {
2643                 nRelWidth  = Min( nRelWidth,  pPage->Prt().Width() );
2644                 nRelHeight = Min( nRelHeight, pPage->Prt().Height() );
2645             }
2646         }
2647 
2648 		if ( rSz.GetWidthPercent() && rSz.GetWidthPercent() != 0xFF )
2649 			aRet.Width() = nRelWidth * rSz.GetWidthPercent() / 100;
2650 		if ( rSz.GetHeightPercent() && rSz.GetHeightPercent() != 0xFF )
2651 			aRet.Height() = nRelHeight * rSz.GetHeightPercent() / 100;
2652 
2653 		if ( rSz.GetWidthPercent() == 0xFF )
2654 		{
2655 			aRet.Width() *= aRet.Height();
2656 			aRet.Width() /= rSz.GetHeight();
2657 		}
2658 		else if ( rSz.GetHeightPercent() == 0xFF )
2659 		{
2660 			aRet.Height() *= aRet.Width();
2661 			aRet.Height() /= rSz.GetWidth();
2662 		}
2663     }
2664 	return aRet;
2665 }
2666 
2667 /*************************************************************************
2668 |*
2669 |*  SwFlyFrm::CalcAutoWidth()
2670 |*
2671 |*************************************************************************/
2672 
2673 SwTwips lcl_CalcAutoWidth( const SwLayoutFrm& rFrm )
2674 {
2675     SwTwips nRet = 0;
2676     SwTwips nMin = 0;
2677     const SwFrm* pFrm = rFrm.Lower();
2678 
2679     // No autowidth defined for columned frames
2680     if ( !pFrm || pFrm->IsColumnFrm() )
2681         return nRet;
2682 
2683     while ( pFrm )
2684     {
2685         if ( pFrm->IsSctFrm() )
2686         {
2687             nMin = lcl_CalcAutoWidth( *(SwSectionFrm*)pFrm );
2688         }
2689         if ( pFrm->IsTxtFrm() )
2690         {
2691             nMin = ((SwTxtFrm*)pFrm)->CalcFitToContent();
2692             const SvxLRSpaceItem &rSpace =
2693                 ((SwTxtFrm*)pFrm)->GetTxtNode()->GetSwAttrSet().GetLRSpace();
2694             if (!((SwTxtFrm*)pFrm)->IsLocked())
2695                 nMin += rSpace.GetRight() + rSpace.GetTxtLeft() + rSpace.GetTxtFirstLineOfst();
2696         }
2697         else if ( pFrm->IsTabFrm() )
2698         {
2699             const SwFmtFrmSize& rTblFmtSz = ((SwTabFrm*)pFrm)->GetTable()->GetFrmFmt()->GetFrmSize();
2700             if ( USHRT_MAX == rTblFmtSz.GetSize().Width() ||
2701                  text::HoriOrientation::NONE == ((SwTabFrm*)pFrm)->GetFmt()->GetHoriOrient().GetHoriOrient() )
2702             {
2703                 const SwPageFrm* pPage = rFrm.FindPageFrm();
2704                 // auto width table
2705                 nMin = pFrm->GetUpper()->IsVertical() ?
2706                     pPage->Prt().Height() :
2707                     pPage->Prt().Width();
2708             }
2709             else
2710             {
2711                 nMin = rTblFmtSz.GetSize().Width();
2712             }
2713         }
2714 
2715         if ( nMin > nRet )
2716             nRet = nMin;
2717 
2718         pFrm = pFrm->GetNext();
2719     }
2720 
2721     return nRet;
2722 }
2723 
2724 SwTwips SwFlyFrm::CalcAutoWidth() const
2725 {
2726     return lcl_CalcAutoWidth( *this );
2727 }
2728 
2729 /*************************************************************************
2730 |*
2731 |*	SwFlyFrm::AddSpacesToFrm
2732 |*
2733 |*	Ersterstellung		MA 11. Nov. 96
2734 |*	Letzte Aenderung	MA 10. Mar. 97
2735 |*
2736 |*************************************************************************/
2737 
2738 //SwRect SwFlyFrm::AddSpacesToFrm() const
2739 //{
2740 //  SwRect aRect( Frm() );
2741 //  const SvxULSpaceItem &rUL = GetFmt()->GetULSpace();
2742 //  const SvxLRSpaceItem &rLR = GetFmt()->GetLRSpace();
2743 //  aRect.Left( Max( aRect.Left() - long(rLR.GetLeft()), 0L ) );
2744 //  aRect.SSize().Width() += rLR.GetRight();
2745 //  aRect.Top( Max( aRect.Top() - long(rUL.GetUpper()), 0L ) );
2746 //  aRect.SSize().Height()+= rUL.GetLower();
2747 //  return aRect;
2748 //}
2749 
2750 /*************************************************************************
2751 |*
2752 |*	SwFlyFrm::GetContour()
2753 |*
2754 |*	Ersterstellung		MA 09. Jan. 97
2755 |*	Letzte Aenderung	MA 10. Jan. 97
2756 |*
2757 |*************************************************************************/
2758 /// OD 16.04.2003 #i13147# - If called for paint and the <SwNoTxtFrm> contains
2759 /// a graphic, load of intrinsic graphic has to be avoided.
2760 sal_Bool SwFlyFrm::GetContour( PolyPolygon&   rContour,
2761                            const sal_Bool _bForPaint ) const
2762 {
2763 	sal_Bool bRet = sal_False;
2764 	if( GetFmt()->GetSurround().IsContour() && Lower() &&
2765 		Lower()->IsNoTxtFrm() )
2766 	{
2767 		SwNoTxtNode *pNd = (SwNoTxtNode*)((SwCntntFrm*)Lower())->GetNode();
2768         // OD 16.04.2003 #i13147# - determine <GraphicObject> instead of <Graphic>
2769         // in order to avoid load of graphic, if <SwNoTxtNode> contains a graphic
2770         // node and method is called for paint.
2771         const GraphicObject* pGrfObj = NULL;
2772         sal_Bool bGrfObjCreated = sal_False;
2773         const SwGrfNode* pGrfNd = pNd->GetGrfNode();
2774         if ( pGrfNd && _bForPaint )
2775         {
2776             pGrfObj = &(pGrfNd->GetGrfObj());
2777         }
2778         else
2779         {
2780             pGrfObj = new GraphicObject( pNd->GetGraphic() );
2781             bGrfObjCreated = sal_True;
2782         }
2783         ASSERT( pGrfObj, "SwFlyFrm::GetContour() - No Graphic/GraphicObject found at <SwNoTxtNode>." );
2784         if ( pGrfObj && pGrfObj->GetType() != GRAPHIC_NONE )
2785         {
2786             if( !pNd->HasContour() )
2787             {
2788                 // OD 16.04.2003 #i13147# - no <CreateContour> for a graphic
2789                 // during paint. Thus, return (value of <bRet> should be <sal_False>).
2790                 if ( pGrfNd && _bForPaint )
2791                 {
2792                     ASSERT( false, "SwFlyFrm::GetContour() - No Contour found at <SwNoTxtNode> during paint." );
2793                     return bRet;
2794                 }
2795                 pNd->CreateContour();
2796             }
2797             pNd->GetContour( rContour );
2798 			//Der Node haelt das Polygon passend zur Originalgroesse der Grafik
2799 			//hier muss die Skalierung einkalkuliert werden.
2800 			SwRect aClip;
2801 			SwRect aOrig;
2802 			Lower()->Calc();
2803 			((SwNoTxtFrm*)Lower())->GetGrfArea( aClip, &aOrig, sal_False );
2804             // OD 16.04.2003 #i13147# - copy method code <SvxContourDlg::ScaleContour(..)>
2805             // in order to avoid that graphic has to be loaded for contour scale.
2806             //SvxContourDlg::ScaleContour( rContour, aGrf, MAP_TWIP, aOrig.SSize() );
2807             {
2808                 OutputDevice*   pOutDev = Application::GetDefaultDevice();
2809                 const MapMode   aDispMap( MAP_TWIP );
2810                 const MapMode   aGrfMap( pGrfObj->GetPrefMapMode() );
2811                 const Size      aGrfSize( pGrfObj->GetPrefSize() );
2812                 double          fScaleX;
2813                 double          fScaleY;
2814                 Size            aOrgSize;
2815                 Point           aNewPoint;
2816                 sal_Bool            bPixelMap = aGrfMap.GetMapUnit() == MAP_PIXEL;
2817 
2818                 if ( bPixelMap )
2819                     aOrgSize = pOutDev->PixelToLogic( aGrfSize, aDispMap );
2820                 else
2821                     aOrgSize = pOutDev->LogicToLogic( aGrfSize, aGrfMap, aDispMap );
2822 
2823                 if ( aOrgSize.Width() && aOrgSize.Height() )
2824                 {
2825                     fScaleX = (double) aOrig.Width() / aOrgSize.Width();
2826                     fScaleY = (double) aOrig.Height() / aOrgSize.Height();
2827 
2828                     for ( sal_uInt16 j = 0, nPolyCount = rContour.Count(); j < nPolyCount; j++ )
2829                     {
2830                         Polygon& rPoly = rContour[ j ];
2831 
2832                         for ( sal_uInt16 i = 0, nCount = rPoly.GetSize(); i < nCount; i++ )
2833                         {
2834                             if ( bPixelMap )
2835                                 aNewPoint = pOutDev->PixelToLogic( rPoly[ i ], aDispMap  );
2836                             else
2837                                 aNewPoint = pOutDev->LogicToLogic( rPoly[ i ], aGrfMap, aDispMap  );
2838 
2839                             rPoly[ i ] = Point( FRound( aNewPoint.X() * fScaleX ), FRound( aNewPoint.Y() * fScaleY ) );
2840                         }
2841                     }
2842                 }
2843             }
2844             // OD 17.04.2003 #i13147# - destroy created <GraphicObject>.
2845             if ( bGrfObjCreated )
2846             {
2847                 delete pGrfObj;
2848             }
2849             rContour.Move( aOrig.Left(), aOrig.Top() );
2850             if( !aClip.Width() )
2851                 aClip.Width( 1 );
2852             if( !aClip.Height() )
2853                 aClip.Height( 1 );
2854             rContour.Clip( aClip.SVRect() );
2855 			rContour.Optimize(POLY_OPTIMIZE_CLOSE);
2856 			bRet = sal_True;
2857 		}
2858 	}
2859 	return bRet;
2860 }
2861 
2862 // OD 2004-03-25 #i26791#
2863 const SwVirtFlyDrawObj* SwFlyFrm::GetVirtDrawObj() const
2864 {
2865     return static_cast<const SwVirtFlyDrawObj*>(GetDrawObj());
2866 }
2867 SwVirtFlyDrawObj* SwFlyFrm::GetVirtDrawObj()
2868 {
2869     return static_cast<SwVirtFlyDrawObj*>(DrawObj());
2870 }
2871 
2872 // =============================================================================
2873 // OD 2004-03-24 #i26791# - implementation of pure virtual method declared in
2874 // base class <SwAnchoredObject>
2875 // =============================================================================
2876 void SwFlyFrm::InvalidateObjPos()
2877 {
2878     InvalidatePos();
2879     // --> OD 2006-08-10 #i68520#
2880     InvalidateObjRectWithSpaces();
2881     // <--
2882 }
2883 
2884 SwFrmFmt& SwFlyFrm::GetFrmFmt()
2885 {
2886     ASSERT( GetFmt(),
2887             "<SwFlyFrm::GetFrmFmt()> - missing frame format -> crash." );
2888     return *GetFmt();
2889 }
2890 const SwFrmFmt& SwFlyFrm::GetFrmFmt() const
2891 {
2892     ASSERT( GetFmt(),
2893             "<SwFlyFrm::GetFrmFmt()> - missing frame format -> crash." );
2894     return *GetFmt();
2895 }
2896 
2897 const SwRect SwFlyFrm::GetObjRect() const
2898 {
2899     return Frm();
2900 }
2901 
2902 // --> OD 2006-10-05 #i70122#
2903 // for Writer fly frames the bounding rectangle equals the object rectangles
2904 const SwRect SwFlyFrm::GetObjBoundRect() const
2905 {
2906     return GetObjRect();
2907 }
2908 // <--
2909 
2910 // --> OD 2006-08-10 #i68520#
2911 bool SwFlyFrm::_SetObjTop( const SwTwips _nTop )
2912 {
2913     const bool bChanged( Frm().Pos().Y() != _nTop );
2914 
2915     Frm().Pos().Y() = _nTop;
2916 
2917     return bChanged;
2918 }
2919 bool SwFlyFrm::_SetObjLeft( const SwTwips _nLeft )
2920 {
2921     const bool bChanged( Frm().Pos().X() != _nLeft );
2922 
2923     Frm().Pos().X() = _nLeft;
2924 
2925     return bChanged;
2926 }
2927 // <--
2928 
2929 /** method to assure that anchored object is registered at the correct
2930     page frame
2931 
2932     OD 2004-07-02 #i28701#
2933 
2934     @author OD
2935 */
2936 void SwFlyFrm::RegisterAtCorrectPage()
2937 {
2938     // default behaviour is to do nothing.
2939 }
2940 
2941 /** method to determine, if a <MakeAll()> on the Writer fly frame is possible
2942 
2943     OD 2004-05-11 #i28701#
2944 
2945     @author OD
2946 */
2947 bool SwFlyFrm::IsFormatPossible() const
2948 {
2949     return SwAnchoredObject::IsFormatPossible() &&
2950            !IsLocked() && !IsColLocked();
2951 }
2952 
2953 void SwFlyFrm::GetAnchoredObjects( std::list<SwAnchoredObject*>& aList, const SwFmt& rFmt )
2954 {
2955     SwIterator<SwFlyFrm,SwFmt> aIter( rFmt );
2956     for( SwFlyFrm* pFlyFrm = aIter.First(); pFlyFrm; pFlyFrm = aIter.Next() )
2957         aList.push_back( pFlyFrm );
2958 }
2959 
2960 const SwFlyFrmFmt * SwFlyFrm::GetFmt() const
2961 {
2962     return static_cast< const SwFlyFrmFmt * >( GetDep() );
2963 }
2964 
2965 SwFlyFrmFmt * SwFlyFrm::GetFmt()
2966 {
2967     return static_cast< SwFlyFrmFmt * >( GetDep() );
2968 }
2969 
2970