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