Update ooo320-m1
[ooovba.git] / sw / source / core / layout / flycnt.cxx
blob1fadf0378f269bdbf80e6fcfe804b1d123986d27
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: flycnt.cxx,v $
10 * $Revision: 1.66 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <tools/bigint.hxx>
34 #include "pagefrm.hxx"
35 #include "rootfrm.hxx"
36 #include "cntfrm.hxx"
37 #include "flyfrm.hxx"
38 #include "txtfrm.hxx"
39 #include "doc.hxx"
40 #include "viewsh.hxx"
41 #include "viewimp.hxx"
42 #include "pam.hxx"
43 #include "frmfmt.hxx"
44 #include "frmtool.hxx"
45 #include "dflyobj.hxx"
46 #include "hints.hxx"
47 #include "ndtxt.hxx"
48 #include "swundo.hxx"
49 #include "errhdl.hxx"
50 #include <svx/ulspitem.hxx>
51 #include <svx/lrspitem.hxx>
52 #include <fmtanchr.hxx>
53 #include <fmtornt.hxx>
54 #include <fmtfsize.hxx>
55 #include <fmtsrnd.hxx>
57 #include "tabfrm.hxx"
58 #include "flyfrms.hxx"
59 #include "crstate.hxx"
60 #include "sectfrm.hxx"
62 // OD 29.10.2003 #113049#
63 #include <tocntntanchoredobjectposition.hxx>
64 // OD 2004-05-24 #i28701#
65 #include <dcontact.hxx>
66 #include <sortedobjs.hxx>
67 // --> OD 2005-09-29 #125370#,#125957#
68 #include <layouter.hxx>
69 // <--
70 // --> OD 2005-11-17 #i56300#
71 #include <objectformattertxtfrm.hxx>
72 // <--
73 // --> OD 2006-03-06 #125892#
74 #include <HandleAnchorNodeChg.hxx>
75 // <--
77 using namespace ::com::sun::star;
80 /*************************************************************************
82 |* SwFlyAtCntFrm::SwFlyAtCntFrm()
84 |* Ersterstellung MA 11. Nov. 92
85 |* Letzte Aenderung MA 09. Apr. 99
87 |*************************************************************************/
89 SwFlyAtCntFrm::SwFlyAtCntFrm( SwFlyFrmFmt *pFmt, SwFrm *pAnch ) :
90 SwFlyFreeFrm( pFmt, pAnch )
92 bAtCnt = TRUE;
93 bAutoPosition = FLY_AUTO_CNTNT == pFmt->GetAnchor().GetAnchorId();
96 // --> OD 2004-06-29 #i28701#
97 TYPEINIT1(SwFlyAtCntFrm,SwFlyFreeFrm);
98 // <--
99 /*************************************************************************
101 |* SwFlyAtCntFrm::Modify()
103 |* Ersterstellung MA 08. Feb. 93
104 |* Letzte Aenderung MA 23. Nov. 94
106 |*************************************************************************/
108 void SwFlyAtCntFrm::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew )
110 USHORT nWhich = pNew ? pNew->Which() : 0;
111 const SwFmtAnchor *pAnch = 0;
113 if( RES_ATTRSET_CHG == nWhich && SFX_ITEM_SET ==
114 ((SwAttrSetChg*)pNew)->GetChgSet()->GetItemState( RES_ANCHOR, FALSE,
115 (const SfxPoolItem**)&pAnch ))
116 ; // Beim GetItemState wird der AnkerPointer gesetzt !
118 else if( RES_ANCHOR == nWhich )
120 //Ankerwechsel, ich haenge mich selbst um.
121 //Es darf sich nicht um einen Wechsel des Ankertyps handeln,
122 //dies ist nur ueber die SwFEShell moeglich.
123 pAnch = (const SwFmtAnchor*)pNew;
126 if( pAnch )
128 ASSERT( pAnch->GetAnchorId() == GetFmt()->GetAnchor().GetAnchorId(),
129 "Unzulaessiger Wechsel des Ankertyps." );
131 //Abmelden, neuen Anker besorgen und 'dranhaengen.
132 SwRect aOld( GetObjRectWithSpaces() );
133 SwPageFrm *pOldPage = FindPageFrm();
134 const SwFrm *pOldAnchor = GetAnchorFrm();
135 SwCntntFrm *pCntnt = (SwCntntFrm*)GetAnchorFrm();
136 AnchorFrm()->RemoveFly( this );
138 const BOOL bBodyFtn = (pCntnt->IsInDocBody() || pCntnt->IsInFtn());
140 //Den neuen Anker anhand des NodeIdx suchen, am alten und
141 //neuen NodeIdx kann auch erkannt werden, in welche Richtung
142 //gesucht werden muss.
143 const SwNodeIndex aNewIdx( pAnch->GetCntntAnchor()->nNode );
144 SwNodeIndex aOldIdx( *pCntnt->GetNode() );
146 //fix: Umstellung, ehemals wurde in der do-while-Schleife nach vorn bzw.
147 //nach hinten gesucht; je nachdem wie welcher Index kleiner war.
148 //Das kann aber u.U. zu einer Endlosschleife fuehren. Damit
149 //wenigstens die Schleife unterbunden wird suchen wir nur in eine
150 //Richtung. Wenn der neue Anker nicht gefunden wird koennen wir uns
151 //immer noch vom Node einen Frame besorgen. Die Change, dass dies dann
152 //der richtige ist, ist gut.
153 const bool bNext = aOldIdx < aNewIdx;
154 // --> OD 2006-02-28 #125892#
155 // consider the case that at found anchor frame candidate already a
156 // fly frame of the given fly format is registered.
157 // --> OD 2006-03-15 #133407# - consider, that <pCntnt> is the already
158 // the new anchor frame.
159 bool bFound( aOldIdx == aNewIdx );
160 // <--
161 while ( pCntnt && !bFound )
165 if ( bNext )
166 pCntnt = pCntnt->GetNextCntntFrm();
167 else
168 pCntnt = pCntnt->GetPrevCntntFrm();
169 } while ( pCntnt &&
170 !( bBodyFtn == ( pCntnt->IsInDocBody() ||
171 pCntnt->IsInFtn() ) ) );
172 if ( pCntnt )
173 aOldIdx = *pCntnt->GetNode();
175 // --> OD 2006-02-28 #125892#
176 // check, if at found anchor frame candidate already a fly frame
177 // of the given fly frame format is registered.
178 bFound = aOldIdx == aNewIdx;
179 if ( bFound && pCntnt->GetDrawObjs() )
181 SwFrmFmt* pMyFlyFrmFmt( &GetFrmFmt() );
182 SwSortedObjs &rObjs = *pCntnt->GetDrawObjs();
183 for( sal_uInt16 i = 0; i < rObjs.Count(); ++i)
185 SwFlyFrm* pFlyFrm = dynamic_cast<SwFlyFrm*>(rObjs[i]);
186 if ( pFlyFrm &&
187 &(pFlyFrm->GetFrmFmt()) == pMyFlyFrmFmt )
189 bFound = false;
190 break;
194 // <--
196 // <--
197 if ( !pCntnt )
199 SwCntntNode *pNode = aNewIdx.GetNode().GetCntntNode();
200 pCntnt = pNode->GetFrm( &pOldAnchor->Frm().Pos(), 0, FALSE );
201 ASSERT( pCntnt, "Neuen Anker nicht gefunden" );
203 //Flys haengen niemals an einem Follow sondern immer am
204 //Master, den suchen wir uns jetzt.
205 SwCntntFrm* pFlow = pCntnt;
206 while ( pFlow->IsFollow() )
207 pFlow = pFlow->FindMaster();
208 pCntnt = pFlow;
210 //und schwupp angehaengt das teil...
211 pCntnt->AppendFly( this );
212 if ( pOldPage && pOldPage != FindPageFrm() )
213 NotifyBackground( pOldPage, aOld, PREP_FLY_LEAVE );
215 //Fix(3495)
216 _InvalidatePos();
217 InvalidatePage();
218 SetNotifyBack();
219 // --> OD 2004-06-24 #i28701# - reset member <maLastCharRect> and
220 // <mnLastTopOfLine> for to-character anchored objects.
221 ClearCharRectAndTopOfLine();
223 else
224 SwFlyFrm::Modify( pOld, pNew );
227 /*************************************************************************
229 |* SwFlyAtCntFrm::MakeAll()
231 |* Beschreibung Bei einem Absatzgebunden Fly kann es durchaus sein,
232 |* das der Anker auf die Veraenderung des Flys reagiert. Auf diese
233 |* Reaktion hat der Fly natuerlich auch wieder zu reagieren.
234 |* Leider kann dies zu Oszillationen fuehren z.b. Der Fly will nach
235 |* unten, dadurch kann der Inhalt nach oben, der TxtFrm wird kleiner,
236 |* der Fly muss wieder hoeher woduch der Text wieder nach unten
237 |* verdraengt wird...
238 |* Um derartige Oszillationen zu vermeiden, wird ein kleiner Positions-
239 |* stack aufgebaut. Wenn der Fly ein Position erreicht, die er bereits
240 |* einmal einnahm, so brechen wir den Vorgang ab. Um keine Risiken
241 |* einzugehen, wird der Positionsstack so aufgebaut, dass er fuenf
242 |* Positionen zurueckblickt.
243 |* Wenn der Stack ueberlaeuft, wird ebenfalls abgebrochen.
244 |* Der Abbruch fuer dazu, dass der Fly am Ende eine unguenste Position
245 |* einnimmt. Damit es nicht durch einen wiederholten Aufruf von
246 |* Aussen zu einer 'grossen Oszillation' kommen kann wird im Abbruch-
247 |* fall das Attribut des Rahmens auf automatische Ausrichtung oben
248 |* eingestellt.
250 |* Ersterstellung MA 12. Nov. 92
251 |* Letzte Aenderung MA 20. Sep. 96
253 |*************************************************************************/
254 //Wir brauchen ein Paar Hilfsklassen zur Kontrolle der Ozillation und ein paar
255 //Funktionen um die Uebersicht zu gewaehrleisten.
256 // OD 2004-08-25 #i3317# - re-factoring of the position stack
257 class SwOszControl
259 static const SwFlyFrm *pStk1;
260 static const SwFlyFrm *pStk2;
261 static const SwFlyFrm *pStk3;
262 static const SwFlyFrm *pStk4;
263 static const SwFlyFrm *pStk5;
265 const SwFlyFrm *pFly;
266 // --> OD 2004-08-25 #i3317#
267 sal_uInt8 mnPosStackSize;
268 std::vector<Point*> maObjPositions;
269 // <--
271 public:
272 SwOszControl( const SwFlyFrm *pFrm );
273 ~SwOszControl();
274 bool ChkOsz();
275 static BOOL IsInProgress( const SwFlyFrm *pFly );
277 const SwFlyFrm *SwOszControl::pStk1 = 0;
278 const SwFlyFrm *SwOszControl::pStk2 = 0;
279 const SwFlyFrm *SwOszControl::pStk3 = 0;
280 const SwFlyFrm *SwOszControl::pStk4 = 0;
281 const SwFlyFrm *SwOszControl::pStk5 = 0;
283 SwOszControl::SwOszControl( const SwFlyFrm *pFrm )
284 : pFly( pFrm ),
285 // --> OD 2004-08-25 #i3317#
286 mnPosStackSize( 20 )
287 // <--
289 if ( !SwOszControl::pStk1 )
290 SwOszControl::pStk1 = pFly;
291 else if ( !SwOszControl::pStk2 )
292 SwOszControl::pStk2 = pFly;
293 else if ( !SwOszControl::pStk3 )
294 SwOszControl::pStk3 = pFly;
295 else if ( !SwOszControl::pStk4 )
296 SwOszControl::pStk4 = pFly;
297 else if ( !SwOszControl::pStk5 )
298 SwOszControl::pStk5 = pFly;
301 SwOszControl::~SwOszControl()
303 if ( SwOszControl::pStk1 == pFly )
304 SwOszControl::pStk1 = 0;
305 else if ( SwOszControl::pStk2 == pFly )
306 SwOszControl::pStk2 = 0;
307 else if ( SwOszControl::pStk3 == pFly )
308 SwOszControl::pStk3 = 0;
309 else if ( SwOszControl::pStk4 == pFly )
310 SwOszControl::pStk4 = 0;
311 else if ( SwOszControl::pStk5 == pFly )
312 SwOszControl::pStk5 = 0;
313 // --> OD 2004-08-25 #i3317#
314 while ( !maObjPositions.empty() )
316 Point* pPos = maObjPositions.back();
317 delete pPos;
319 maObjPositions.pop_back();
321 // <--
324 BOOL SwOszControl::IsInProgress( const SwFlyFrm *pFly )
326 if ( SwOszControl::pStk1 && !pFly->IsLowerOf( SwOszControl::pStk1 ) )
327 return TRUE;
328 if ( SwOszControl::pStk2 && !pFly->IsLowerOf( SwOszControl::pStk2 ) )
329 return TRUE;
330 if ( SwOszControl::pStk3 && !pFly->IsLowerOf( SwOszControl::pStk3 ) )
331 return TRUE;
332 if ( SwOszControl::pStk4 && !pFly->IsLowerOf( SwOszControl::pStk4 ) )
333 return TRUE;
334 if ( SwOszControl::pStk5 && !pFly->IsLowerOf( SwOszControl::pStk5 ) )
335 return TRUE;
336 return FALSE;
339 bool SwOszControl::ChkOsz()
341 bool bOscillationDetected = false;
343 if ( maObjPositions.size() == mnPosStackSize )
345 // position stack is full -> oscillation
346 bOscillationDetected = true;
348 else
350 Point* pNewObjPos = new Point( pFly->GetObjRect().Pos() );
351 for ( std::vector<Point*>::iterator aObjPosIter = maObjPositions.begin();
352 aObjPosIter != maObjPositions.end();
353 ++aObjPosIter )
355 if ( *(pNewObjPos) == *(*aObjPosIter) )
357 // position already occured -> oscillation
358 bOscillationDetected = true;
359 delete pNewObjPos;
360 break;
363 if ( !bOscillationDetected )
365 maObjPositions.push_back( pNewObjPos );
369 return bOscillationDetected;
372 void SwFlyAtCntFrm::MakeAll()
374 // OD 2004-01-19 #110582#
375 if ( !GetFmt()->GetDoc()->IsVisibleLayerId( GetVirtDrawObj()->GetLayer() ) )
377 return;
380 if ( !SwOszControl::IsInProgress( this ) && !IsLocked() && !IsColLocked() )
382 // --> OD 2004-06-30 #i28701# - use new method <GetPageFrm()>
383 if( !GetPageFrm() && GetAnchorFrm() && GetAnchorFrm()->IsInFly() )
385 SwFlyFrm* pFly = AnchorFrm()->FindFlyFrm();
386 SwPageFrm *pTmpPage = pFly ? pFly->FindPageFrm() : NULL;
387 if( pTmpPage )
388 pTmpPage->AppendFlyToPage( this );
390 // --> OD 2004-06-30 #i28701# - use new method <GetPageFrm()>
391 if( GetPageFrm() )
393 bSetCompletePaintOnInvalidate = TRUE;
395 SwFlyFrmFmt *pFmt = (SwFlyFrmFmt*)GetFmt();
396 const SwFmtFrmSize &rFrmSz = GetFmt()->GetFrmSize();
397 if( rFrmSz.GetHeightPercent() != 0xFF &&
398 rFrmSz.GetHeightPercent() >= 100 )
400 pFmt->LockModify();
401 SwFmtSurround aMain( pFmt->GetSurround() );
402 if ( aMain.GetSurround() == SURROUND_NONE )
404 aMain.SetSurround( SURROUND_THROUGHT );
405 pFmt->SetFmtAttr( aMain );
407 pFmt->UnlockModify();
411 SwOszControl aOszCntrl( this );
413 // --> OD 2005-02-22 #i43255#
414 // --> OD 2005-06-07 #i50356# - format the anchor frame, which
415 // contains the anchor position. E.g., for at-character anchored
416 // object this can be the follow frame of the anchor frame.
417 const bool bFormatAnchor =
418 !static_cast<const SwTxtFrm*>( GetAnchorFrmContainingAnchPos() )->IsAnyJoinLocked() &&
419 !ConsiderObjWrapInfluenceOnObjPos() &&
420 !ConsiderObjWrapInfluenceOfOtherObjs();
421 // <--
423 const SwFrm* pFooter = GetAnchorFrm()->FindFooterOrHeader();
424 if( pFooter && !pFooter->IsFooterFrm() )
425 pFooter = NULL;
426 bool bOsz = false;
427 BOOL bExtra = Lower() && Lower()->IsColumnFrm();
428 // --> OD 2004-08-25 #i3317# - boolean, to apply temporarly the
429 // 'straightforward positioning process' for the frame due to its
430 // overlapping with a previous column.
431 bool bConsiderWrapInfluenceDueToOverlapPrevCol( false );
432 // <--
433 // --> OD 2004-10-22 #i35911# - boolean, to apply temporarly the
434 // 'straightforward positioning process' for the frame due to fact
435 // that it causes the complete content of its layout environment
436 // to move forward.
437 // --> OD 2005-01-14 #i40444# - extend usage of this boolean:
438 // apply temporarly the 'straightforward positioning process' for
439 // the frame due to the fact that the frame clears the area for
440 // the anchor frame, thus it has to move forward.
441 bool bConsiderWrapInfluenceDueToMovedFwdAnchor( false );
442 // <--
443 do {
444 SWRECTFN( this )
445 Point aOldPos( (Frm().*fnRect->fnGetPos)() );
446 SwFlyFreeFrm::MakeAll();
447 const bool bPosChgDueToOwnFormat =
448 aOldPos != (Frm().*fnRect->fnGetPos)();
449 // --> OD 2004-08-25 #i3317#
450 if ( !ConsiderObjWrapInfluenceOnObjPos() &&
451 OverlapsPrevColumn() )
453 bConsiderWrapInfluenceDueToOverlapPrevCol = true;
455 // <--
456 // OD 2004-05-12 #i28701# - no format of anchor frame, if
457 // wrapping style influence is considered on object positioning
458 if ( bFormatAnchor )
460 SwTxtFrm* pAnchPosAnchorFrm =
461 dynamic_cast<SwTxtFrm*>(GetAnchorFrmContainingAnchPos());
462 ASSERT( pAnchPosAnchorFrm,
463 "<SwFlyAtCntFrm::MakeAll()> - anchor frame of wrong type -> crash" );
464 // --> OD 2006-01-27 #i58182# - For the usage of new method
465 // <SwObjectFormatterTxtFrm::CheckMovedFwdCondition(..)>
466 // to check move forward of anchor frame due to the object
467 // positioning it's needed to know, if the object is anchored
468 // at the master frame before the anchor frame is formatted.
469 const bool bAnchoredAtMaster( !pAnchPosAnchorFrm->IsFollow() );
470 // <--
472 // --> OD 2005-11-17 #i56300#
473 // perform complete format of anchor text frame and its
474 // previous frames, which have become invalid due to the
475 // fly frame format.
476 SwObjectFormatterTxtFrm::FormatAnchorFrmAndItsPrevs( *pAnchPosAnchorFrm );
477 // <--
478 // --> OD 2004-10-22 #i35911#
479 // --> OD 2005-01-14 #i40444#
480 // --> OD 2006-01-27 #i58182# - usage of new method
481 // <SwObjectFormatterTxtFrm::CheckMovedFwdCondition(..)>
482 sal_uInt32 nToPageNum( 0L );
483 bool bDummy( false );
484 if ( SwObjectFormatterTxtFrm::CheckMovedFwdCondition(
485 *this, GetPageFrm()->GetPhyPageNum(),
486 bAnchoredAtMaster, nToPageNum, bDummy ) )
488 bConsiderWrapInfluenceDueToMovedFwdAnchor = true;
489 // --> OD 2005-09-29 #125370#,#125957# - mark anchor text frame
490 // directly, that it is moved forward by object positioning.
491 SwTxtFrm* pAnchorTxtFrm( static_cast<SwTxtFrm*>(AnchorFrm()) );
492 bool bInsert( true );
493 sal_uInt32 nAnchorFrmToPageNum( 0L );
494 const SwDoc& rDoc = *(GetFrmFmt().GetDoc());
495 if ( SwLayouter::FrmMovedFwdByObjPos(
496 rDoc, *pAnchorTxtFrm, nAnchorFrmToPageNum ) )
498 if ( nAnchorFrmToPageNum < nToPageNum )
499 SwLayouter::RemoveMovedFwdFrm( rDoc, *pAnchorTxtFrm );
500 else
501 bInsert = false;
503 if ( bInsert )
505 SwLayouter::InsertMovedFwdFrm( rDoc, *pAnchorTxtFrm,
506 nToPageNum );
508 // <--
510 // <--
513 if ( aOldPos != (Frm().*fnRect->fnGetPos)() ||
514 ( !GetValidPosFlag() &&
515 ( pFooter || bPosChgDueToOwnFormat ) ) )
517 bOsz = aOszCntrl.ChkOsz();
519 // --> OD 2006-04-13 #b6403541#
520 // special loop prevention for dedicated document:
521 if ( bOsz &&
522 HasFixSize() && IsClipped() &&
523 GetAnchorFrm()->GetUpper()->IsCellFrm() )
525 SwFrmFmt* pFmt = GetFmt();
526 const SwFmtFrmSize& rFrmSz = pFmt->GetFrmSize();
527 if ( rFrmSz.GetWidthPercent() &&
528 rFrmSz.GetHeightPercent() == 0xFF )
530 SwFmtSurround aSurround( pFmt->GetSurround() );
531 if ( aSurround.GetSurround() == SURROUND_NONE )
533 pFmt->LockModify();
534 aSurround.SetSurround( SURROUND_THROUGHT );
535 pFmt->SetFmtAttr( aSurround );
536 pFmt->UnlockModify();
537 bOsz = false;
538 #if OSL_DEBUG_LEVEL > 1
539 ASSERT( false,
540 "<SwFlyAtCntFrm::MakeAll()> - special loop prevention for dedicated document of b6403541 applied" );
541 #endif
545 // <--
548 if ( bExtra && Lower() && !Lower()->GetValidPosFlag() )
550 // Wenn ein mehrspaltiger Rahmen wg. Positionswechsel ungueltige
551 // Spalten hinterlaesst, so drehen wir lieber hier eine weitere
552 // Runde und formatieren unseren Inhalt via FormatWidthCols nochmal.
553 _InvalidateSize();
554 bExtra = FALSE; // Sicherhaltshalber gibt es nur eine Ehrenrunde.
556 } while ( !IsValid() && !bOsz &&
557 // --> OD 2004-08-25 #i3317#
558 !bConsiderWrapInfluenceDueToOverlapPrevCol &&
559 // <--
560 // --> OD 2005-01-14 #i40444#
561 !bConsiderWrapInfluenceDueToMovedFwdAnchor &&
562 // <--
563 GetFmt()->GetDoc()->IsVisibleLayerId( GetVirtDrawObj()->GetLayer() ) );
565 // --> OD 2004-08-25 #i3317# - instead of attribute change apply
566 // temporarly the 'straightforward positioning process'.
567 // --> OD 2007-11-29 #i80924#
568 // handle special case during splitting of table rows
569 if ( bConsiderWrapInfluenceDueToMovedFwdAnchor &&
570 GetAnchorFrm()->IsInTab() &&
571 GetAnchorFrm()->IsInFollowFlowRow() )
573 const SwFrm* pCellFrm = GetAnchorFrm();
574 while ( pCellFrm && !pCellFrm->IsCellFrm() )
576 pCellFrm = pCellFrm->GetUpper();
578 if ( pCellFrm )
580 SWRECTFN( pCellFrm )
581 if ( (pCellFrm->Frm().*fnRect->fnGetTop)() == 0 &&
582 (pCellFrm->Frm().*fnRect->fnGetHeight)() == 0 )
584 bConsiderWrapInfluenceDueToMovedFwdAnchor = false;
588 // <--
589 if ( bOsz || bConsiderWrapInfluenceDueToOverlapPrevCol ||
590 // --> OD 2005-01-14 #i40444#
591 bConsiderWrapInfluenceDueToMovedFwdAnchor )
592 // <--
594 SetTmpConsiderWrapInfluence( true );
595 SetRestartLayoutProcess( true );
596 // --> OD 2006-07-24 #b6449874#
597 SetTmpConsiderWrapInfluenceOfOtherObjs( true );
598 // <--
600 // <--
601 bSetCompletePaintOnInvalidate = FALSE;
606 /** method to determine, if a <MakeAll()> on the Writer fly frame is possible
608 OD 2004-05-11 #i28701#
610 @author OD
612 bool SwFlyAtCntFrm::IsFormatPossible() const
614 return SwFlyFreeFrm::IsFormatPossible() &&
615 !SwOszControl::IsInProgress( this );
618 /*************************************************************************
620 |* FindAnchor() und Hilfsfunktionen.
622 |* Beschreibung: Sucht ausgehend von pOldAnch einen Anker fuer
623 |* Absatzgebundene Objekte.
624 |* Wird beim Draggen von Absatzgebundenen Objekten zur Ankeranzeige sowie
625 |* fuer Ankerwechsel benoetigt.
626 |* Ersterstellung MA 22. Jun. 93
627 |* Letzte Aenderung MA 30. Jan. 95
629 |*************************************************************************/
631 class SwDistance
633 public:
634 SwTwips nMain, nSub;
635 SwDistance() { nMain = nSub = 0; }
636 SwDistance& operator=( const SwDistance &rTwo )
637 { nMain = rTwo.nMain; nSub = rTwo.nSub; return *this; }
638 BOOL operator<( const SwDistance& rTwo )
639 { return nMain < rTwo.nMain || ( nMain == rTwo.nMain && nSub &&
640 rTwo.nSub && nSub < rTwo.nSub ); }
641 BOOL operator<=( const SwDistance& rTwo )
642 { return nMain < rTwo.nMain || ( nMain == rTwo.nMain && ( !nSub ||
643 !rTwo.nSub || nSub <= rTwo.nSub ) ); }
646 const SwFrm * MA_FASTCALL lcl_CalcDownDist( SwDistance &rRet,
647 const Point &rPt,
648 const SwCntntFrm *pCnt )
650 rRet.nSub = 0;
651 //Wenn der Point direkt innerhalb des Cnt steht ist die Sache klar und
652 //der Cntnt hat automatisch eine Entfernung von 0
653 if ( pCnt->Frm().IsInside( rPt ) )
655 rRet.nMain = 0;
656 return pCnt;
658 else
660 const SwLayoutFrm *pUp = pCnt->IsInTab() ? pCnt->FindTabFrm()->GetUpper() : pCnt->GetUpper();
661 // einspaltige Bereiche muessen zu ihrem Upper durchschalten
662 while( pUp->IsSctFrm() )
663 pUp = pUp->GetUpper();
664 const bool bVert = pUp->IsVertical();
665 //Dem Textflus folgen.
666 // --> OD 2009-01-12 #i70582#
667 const SwTwips nTopForObjPos =
668 bVert
669 ? ( pCnt->Frm().Left() +
670 pCnt->Frm().Width() -
671 pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() )
672 : ( pCnt->Frm().Top() +
673 pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() );
674 // <--
675 if ( pUp->Frm().IsInside( rPt ) )
677 // OD 26.09.2003 - <rPt> point is inside environment of given content frame
678 // --> OD 2009-01-12 #i70582#
679 if( bVert )
680 rRet.nMain = nTopForObjPos - rPt.X();
681 else
682 rRet.nMain = rPt.Y() - nTopForObjPos;
683 // <--
684 return pCnt;
686 else if ( rPt.Y() <= pUp->Frm().Top() )
688 // OD 26.09.2003 - <rPt> point is above environment of given content frame
689 // OD: correct for vertical layout?
690 rRet.nMain = LONG_MAX;
692 else if( rPt.X() < pUp->Frm().Left() &&
693 rPt.Y() <= ( bVert ? pUp->Frm().Top() : pUp->Frm().Bottom() ) )
695 // OD 26.09.2003 - <rPt> point is left of environment of given content frame
696 // OD: seems not to be correct for vertical layout!?
697 const SwFrm *pLay = pUp->GetLeaf( MAKEPAGE_NONE, FALSE, pCnt );
698 if( !pLay ||
699 (bVert && (pLay->Frm().Top() + pLay->Prt().Bottom()) <rPt.Y())||
700 (!bVert && (pLay->Frm().Left() + pLay->Prt().Right())<rPt.X()) )
702 // OD 26.09.2003 - <rPt> point is in left border of environment
703 // --> OD 2009-01-12 #i70582#
704 if( bVert )
705 rRet.nMain = nTopForObjPos - rPt.X();
706 else
707 rRet.nMain = rPt.Y() - nTopForObjPos;
708 // <--
709 return pCnt;
711 else
712 rRet.nMain = LONG_MAX;
714 else
716 // --> OD 2009-01-12 #i70582#
717 rRet.nMain = bVert
718 ? nTopForObjPos - (pUp->Frm().Left() + pUp->Prt().Left())
719 : (pUp->Frm().Top() + pUp->Prt().Bottom()) - nTopForObjPos;
720 // <--
722 const SwFrm *pPre = pCnt;
723 const SwFrm *pLay = pUp->GetLeaf( MAKEPAGE_NONE, TRUE, pCnt );
724 SwTwips nFrmTop = 0;
725 SwTwips nPrtHeight = 0;
726 BOOL bSct = FALSE;
727 const SwSectionFrm *pSect = pUp->FindSctFrm();
728 if( pSect )
730 rRet.nSub = rRet.nMain;
731 rRet.nMain = 0;
733 if( pSect && !pSect->IsAnLower( pLay ) )
735 bSct = FALSE;
736 const SwSectionFrm* pNxtSect = pLay ? pLay->FindSctFrm() : 0;
737 if( pSect->IsAnFollow( pNxtSect ) )
739 if( pLay->IsVertical() )
741 nFrmTop = pLay->Frm().Left() + pLay->Frm().Width();
742 nPrtHeight = pLay->Prt().Width();
744 else
746 nFrmTop = pLay->Frm().Top();
747 nPrtHeight = pLay->Prt().Height();
749 pSect = pNxtSect;
751 else
753 pLay = pSect->GetUpper();
754 if( pLay->IsVertical() )
756 nFrmTop = pSect->Frm().Left();
757 nPrtHeight = pSect->Frm().Left() - pLay->Frm().Left()
758 - pLay->Prt().Left();
760 else
762 nFrmTop = pSect->Frm().Bottom();
763 nPrtHeight = pLay->Frm().Top() + pLay->Prt().Top()
764 + pLay->Prt().Height() - pSect->Frm().Top()
765 - pSect->Frm().Height();
767 pSect = 0;
770 else if( pLay )
772 if( pLay->IsVertical() )
774 nFrmTop = pLay->Frm().Left() + pLay->Frm().Width();
775 nPrtHeight = pLay->Prt().Width();
777 else
779 nFrmTop = pLay->Frm().Top();
780 nPrtHeight = pLay->Prt().Height();
782 bSct = 0 != pSect;
784 while ( pLay && !pLay->Frm().IsInside( rPt ) &&
785 ( pLay->Frm().Top() <= rPt.Y() || pLay->IsInFly() ||
786 ( pLay->IsInSct() &&
787 pLay->FindSctFrm()->GetUpper()->Frm().Top() <= rPt.Y())) )
789 if ( pLay->IsFtnContFrm() )
791 if ( !((SwLayoutFrm*)pLay)->Lower() )
793 SwFrm *pDel = (SwFrm*)pLay;
794 pDel->Cut();
795 delete pDel;
796 return pPre;
798 return 0;
800 else
802 if( bSct || pSect )
803 rRet.nSub += nPrtHeight;
804 else
805 rRet.nMain += nPrtHeight;
806 pPre = pLay;
807 pLay = pLay->GetLeaf( MAKEPAGE_NONE, TRUE, pCnt );
808 if( pSect && !pSect->IsAnLower( pLay ) )
809 { // If we're leaving a SwSectionFrm, the next Leaf-Frm
810 // is the part of the upper below the SectionFrm.
811 const SwSectionFrm* pNxtSect = pLay ?
812 pLay->FindSctFrm() : NULL;
813 bSct = FALSE;
814 if( pSect->IsAnFollow( pNxtSect ) )
816 pSect = pNxtSect;
817 if( pLay->IsVertical() )
819 nFrmTop = pLay->Frm().Left() + pLay->Frm().Width();
820 nPrtHeight = pLay->Prt().Width();
822 else
824 nFrmTop = pLay->Frm().Top();
825 nPrtHeight = pLay->Prt().Height();
828 else
830 pLay = pSect->GetUpper();
831 if( pLay->IsVertical() )
833 nFrmTop = pSect->Frm().Left();
834 nPrtHeight = pSect->Frm().Left() -
835 pLay->Frm().Left() - pLay->Prt().Left();
837 else
839 nFrmTop = pSect->Frm().Bottom();
840 nPrtHeight = pLay->Frm().Top()+pLay->Prt().Top()
841 + pLay->Prt().Height() - pSect->Frm().Top()
842 - pSect->Frm().Height();
844 pSect = 0;
847 else if( pLay )
849 if( pLay->IsVertical() )
851 nFrmTop = pLay->Frm().Left() + pLay->Frm().Width();
852 nPrtHeight = pLay->Prt().Width();
854 else
856 nFrmTop = pLay->Frm().Top();
857 nPrtHeight = pLay->Prt().Height();
859 bSct = 0 != pSect;
863 if ( pLay )
865 if ( pLay->Frm().IsInside( rPt ) )
867 SwTwips nDiff = pLay->IsVertical() ? ( nFrmTop - rPt.X() )
868 : ( rPt.Y() - nFrmTop );
869 if( bSct || pSect )
870 rRet.nSub += nDiff;
871 else
872 rRet.nMain += nDiff;
874 if ( pLay->IsFtnContFrm() && !((SwLayoutFrm*)pLay)->Lower() )
876 SwFrm *pDel = (SwFrm*)pLay;
877 pDel->Cut();
878 delete pDel;
879 return 0;
881 return pLay;
883 else
884 rRet.nMain = LONG_MAX;
887 return 0;
890 ULONG MA_FASTCALL lcl_FindCntDiff( const Point &rPt, const SwLayoutFrm *pLay,
891 const SwCntntFrm *& rpCnt,
892 const BOOL bBody, const BOOL bFtn )
894 //Sucht unterhalb von pLay den dichtesten Cnt zum Point. Der Bezugspunkt
895 //der Cntnts ist immer die linke obere Ecke.
896 //Der Cnt soll moeglichst ueber dem Point liegen.
898 #if OSL_DEBUG_LEVEL > 1
899 Point arPoint( rPt );
900 #endif
902 rpCnt = 0;
903 ULONG nDistance = ULONG_MAX;
904 ULONG nNearest = ULONG_MAX;
905 const SwCntntFrm *pCnt = pLay->ContainsCntnt();
907 while ( pCnt && (bBody != pCnt->IsInDocBody() || bFtn != pCnt->IsInFtn()))
909 pCnt = pCnt->GetNextCntntFrm();
910 if ( !pLay->IsAnLower( pCnt ) )
911 pCnt = 0;
913 const SwCntntFrm *pNearest = pCnt;
914 if ( pCnt )
918 //Jetzt die Entfernung zwischen den beiden Punkten berechnen.
919 //'Delta' X^2 + 'Delta'Y^2 = 'Entfernung'^2
920 sal_uInt32 dX = Max( pCnt->Frm().Left(), rPt.X() ) -
921 Min( pCnt->Frm().Left(), rPt.X() ),
922 dY = Max( pCnt->Frm().Top(), rPt.Y() ) -
923 Min( pCnt->Frm().Top(), rPt.Y() );
924 BigInt dX1( dX ), dY1( dY );
925 dX1 *= dX1; dY1 *= dY1;
926 const ULONG nDiff = ::SqRt( dX1 + dY1 );
927 if ( pCnt->Frm().Top() <= rPt.Y() )
929 if ( nDiff < nDistance )
930 { //Der ist dichter dran
931 nDistance = nNearest = nDiff;
932 rpCnt = pNearest = pCnt;
935 else if ( nDiff < nNearest )
937 nNearest = nDiff;
938 pNearest = pCnt;
940 pCnt = pCnt->GetNextCntntFrm();
941 while ( pCnt &&
942 (bBody != pCnt->IsInDocBody() || bFtn != pCnt->IsInFtn()))
943 pCnt = pCnt->GetNextCntntFrm();
945 } while ( pCnt && pLay->IsAnLower( pCnt ) );
947 if ( nDistance == ULONG_MAX )
948 { rpCnt = pNearest;
949 return nNearest;
951 return nDistance;
954 const SwCntntFrm * MA_FASTCALL lcl_FindCnt( const Point &rPt, const SwCntntFrm *pCnt,
955 const BOOL bBody, const BOOL bFtn )
957 //Sucht ausgehen von pCnt denjenigen CntntFrm, dessen linke obere
958 //Ecke am dichtesten am Point liegt.
959 //Liefert _immer_ einen CntntFrm zurueck.
961 //Zunaechst wird versucht den dichtesten Cntnt innerhalt derjenigen
962 //Seite zu suchen innerhalb derer der Cntnt steht.
963 //Ausgehend von der Seite muessen die Seiten in beide
964 //Richtungen beruecksichtigt werden.
965 //Falls moeglich wird ein Cntnt geliefert, dessen Y-Position ueber der
966 //des Point sitzt.
967 const SwCntntFrm *pRet, *pNew;
968 const SwLayoutFrm *pLay = pCnt->FindPageFrm();
969 ULONG nDist;
971 nDist = ::lcl_FindCntDiff( rPt, pLay, pNew, bBody, bFtn );
972 if ( pNew )
973 pRet = pNew;
974 else
975 { pRet = pCnt;
976 nDist = ULONG_MAX;
978 const SwCntntFrm *pNearest = pRet;
979 ULONG nNearest = nDist;
981 if ( pLay )
983 const SwLayoutFrm *pPge = pLay;
984 ULONG nOldNew = ULONG_MAX;
985 for ( USHORT i = 0; pPge->GetPrev() && (i < 3); ++i )
987 pPge = (SwLayoutFrm*)pPge->GetPrev();
988 const ULONG nNew = ::lcl_FindCntDiff( rPt, pPge, pNew, bBody, bFtn );
989 if ( nNew < nDist )
991 if ( pNew->Frm().Top() <= rPt.Y() )
993 pRet = pNearest = pNew;
994 nDist = nNearest = nNew;
996 else if ( nNew < nNearest )
998 pNearest = pNew;
999 nNearest = nNew;
1002 else if ( nOldNew != ULONG_MAX && nNew > nOldNew )
1003 break;
1004 else
1005 nOldNew = nNew;
1008 pPge = pLay;
1009 nOldNew = ULONG_MAX;
1010 for ( USHORT j = 0; pPge->GetNext() && (j < 3); ++j )
1012 pPge = (SwLayoutFrm*)pPge->GetNext();
1013 const ULONG nNew = ::lcl_FindCntDiff( rPt, pPge, pNew, bBody, bFtn );
1014 if ( nNew < nDist )
1016 if ( pNew->Frm().Top() <= rPt.Y() )
1018 pRet = pNearest = pNew;
1019 nDist = nNearest = nNew;
1021 else if ( nNew < nNearest )
1023 pNearest = pNew;
1024 nNearest = nNew;
1027 else if ( nOldNew != ULONG_MAX && nNew > nOldNew )
1028 break;
1029 else
1030 nOldNew = nNew;
1033 if ( (pRet->Frm().Top() > rPt.Y()) )
1034 return pNearest;
1035 else
1036 return pRet;
1039 void lcl_PointToPrt( Point &rPoint, const SwFrm *pFrm )
1041 SwRect aTmp( pFrm->Prt() );
1042 aTmp += pFrm->Frm().Pos();
1043 if ( rPoint.X() < aTmp.Left() )
1044 rPoint.X() = aTmp.Left();
1045 else if ( rPoint.X() > aTmp.Right() )
1046 rPoint.X() = aTmp.Right();
1047 if ( rPoint.Y() < aTmp.Top() )
1048 rPoint.Y() = aTmp.Top();
1049 else if ( rPoint.Y() > aTmp.Bottom() )
1050 rPoint.Y() = aTmp.Bottom();
1054 const SwCntntFrm *FindAnchor( const SwFrm *pOldAnch, const Point &rNew,
1055 const BOOL bBodyOnly )
1057 //Zu der angegebenen DokumentPosition wird der dichteste Cnt im
1058 //Textfluss gesucht. AusgangsFrm ist der uebergebene Anker.
1059 const SwCntntFrm* pCnt;
1060 if ( pOldAnch->IsCntntFrm() )
1062 pCnt = (const SwCntntFrm*)pOldAnch;
1064 else
1066 Point aTmp( rNew );
1067 SwLayoutFrm *pTmpLay = (SwLayoutFrm*)pOldAnch;
1068 if( pTmpLay->IsRootFrm() )
1070 SwRect aTmpRect( aTmp, Size(0,0) );
1071 pTmpLay = (SwLayoutFrm*)::FindPage( aTmpRect, pTmpLay->Lower() );
1073 pCnt = pTmpLay->GetCntntPos( aTmp, FALSE, bBodyOnly );
1076 //Beim Suchen darauf achten, dass die Bereiche sinnvoll erhalten
1077 //bleiben. D.h. in diesem Fall nicht in Header/Footer hinein und
1078 //nicht aus Header/Footer hinaus.
1079 const BOOL bBody = pCnt->IsInDocBody() || bBodyOnly;
1080 const BOOL bFtn = !bBodyOnly && pCnt->IsInFtn();
1082 Point aNew( rNew );
1083 if ( bBody )
1085 //#38848 Vom Seitenrand in den Body ziehen.
1086 const SwFrm *pPage = pCnt->FindPageFrm();
1087 ::lcl_PointToPrt( aNew, pPage->GetUpper() );
1088 SwRect aTmp( aNew, Size( 0, 0 ) );
1089 pPage = ::FindPage( aTmp, pPage );
1090 ::lcl_PointToPrt( aNew, pPage );
1093 if ( pCnt->IsInDocBody() == bBody && pCnt->Frm().IsInside( aNew ) )
1094 return pCnt;
1095 else if ( pOldAnch->IsInDocBody() || pOldAnch->IsPageFrm() )
1097 //Vielleicht befindet sich der gewuenschte Anker ja auf derselben
1098 //Seite wie der aktuelle Anker.
1099 //So gibt es kein Problem mit Spalten.
1100 Point aTmp( aNew );
1101 const SwCntntFrm *pTmp = pCnt->FindPageFrm()->
1102 GetCntntPos( aTmp, FALSE, TRUE, FALSE );
1103 if ( pTmp && pTmp->Frm().IsInside( aNew ) )
1104 return pTmp;
1107 //Ausgehend vom Anker suche ich jetzt in beide Richtungen bis ich
1108 //den jeweils dichtesten gefunden habe.
1109 //Nicht die direkte Entfernung ist relevant sondern die Strecke die
1110 //im Textfluss zurueckgelegt werden muss.
1111 const SwCntntFrm *pUpLst;
1112 const SwCntntFrm *pUpFrm = pCnt;
1113 SwDistance nUp, nUpLst;
1114 ::lcl_CalcDownDist( nUp, aNew, pUpFrm );
1115 SwDistance nDown = nUp;
1116 BOOL bNegAllowed = TRUE;//Einmal aus dem negativen Bereich heraus lassen.
1119 pUpLst = pUpFrm; nUpLst = nUp;
1120 pUpFrm = pUpLst->GetPrevCntntFrm();
1121 while ( pUpFrm &&
1122 (bBody != pUpFrm->IsInDocBody() || bFtn != pUpFrm->IsInFtn()))
1123 pUpFrm = pUpFrm->GetPrevCntntFrm();
1124 if ( pUpFrm )
1126 ::lcl_CalcDownDist( nUp, aNew, pUpFrm );
1127 //Wenn die Distanz innnerhalb einer Tabelle waechst, so lohnt es
1128 //sich weiter zu suchen.
1129 if ( pUpLst->IsInTab() && pUpFrm->IsInTab() )
1131 while ( pUpFrm && ((nUpLst < nUp && pUpFrm->IsInTab()) ||
1132 bBody != pUpFrm->IsInDocBody()) )
1134 pUpFrm = pUpFrm->GetPrevCntntFrm();
1135 if ( pUpFrm )
1136 ::lcl_CalcDownDist( nUp, aNew, pUpFrm );
1140 if ( !pUpFrm )
1141 nUp.nMain = LONG_MAX;
1142 if ( nUp.nMain >= 0 && LONG_MAX != nUp.nMain )
1144 bNegAllowed = FALSE;
1145 if ( nUpLst.nMain < 0 ) //nicht den falschen erwischen, wenn der Wert
1146 //gerade von negativ auf positiv gekippt ist.
1147 { pUpLst = pUpFrm;
1148 nUpLst = nUp;
1151 } while ( pUpFrm && ( ( bNegAllowed && nUp.nMain < 0 ) || ( nUp <= nUpLst ) ) );
1153 const SwCntntFrm *pDownLst;
1154 const SwCntntFrm *pDownFrm = pCnt;
1155 SwDistance nDownLst;
1156 if ( nDown.nMain < 0 )
1157 nDown.nMain = LONG_MAX;
1160 pDownLst = pDownFrm; nDownLst = nDown;
1161 pDownFrm = pDownLst->GetNextCntntFrm();
1162 while ( pDownFrm &&
1163 (bBody != pDownFrm->IsInDocBody() || bFtn != pDownFrm->IsInFtn()))
1164 pDownFrm = pDownFrm->GetNextCntntFrm();
1165 if ( pDownFrm )
1167 ::lcl_CalcDownDist( nDown, aNew, pDownFrm );
1168 if ( nDown.nMain < 0 )
1169 nDown.nMain = LONG_MAX;
1170 //Wenn die Distanz innnerhalb einer Tabelle waechst, so lohnt es
1171 //sich weiter zu suchen.
1172 if ( pDownLst->IsInTab() && pDownFrm->IsInTab() )
1174 while ( pDownFrm && ( ( nDown.nMain != LONG_MAX && nDownLst < nDownLst
1175 && pDownFrm->IsInTab()) || bBody != pDownFrm->IsInDocBody() ) )
1177 pDownFrm = pDownFrm->GetNextCntntFrm();
1178 if ( pDownFrm )
1179 ::lcl_CalcDownDist( nDown, aNew, pDownFrm );
1180 if ( nDown.nMain < 0 )
1181 nDown.nMain = LONG_MAX;
1185 if ( !pDownFrm )
1186 nDown.nMain = LONG_MAX;
1188 } while ( pDownFrm && nDown <= nDownLst &&
1189 nDown.nMain != LONG_MAX && nDownLst.nMain != LONG_MAX );
1191 //Wenn ich in beide Richtungen keinen gefunden habe, so suche ich mir
1192 //denjenigen Cntnt dessen linke obere Ecke dem Point am naechsten liegt.
1193 //Eine derartige Situation tritt z.b. auf, wenn der Point nicht im Text-
1194 //fluss sondern in irgendwelchen Raendern steht.
1195 if ( nDownLst.nMain == LONG_MAX && nUpLst.nMain == LONG_MAX )
1197 // #102861# If an OLE objects, which is contained in a fly frame
1198 // is resized in inplace mode and the new Position is outside the
1199 // fly frame, we do not want to leave our fly frame.
1200 if ( pCnt->IsInFly() )
1201 return pCnt;
1203 return ::lcl_FindCnt( aNew, pCnt, bBody, bFtn );
1205 else
1206 return nDownLst < nUpLst ? pDownLst : pUpLst;
1209 /*************************************************************************
1211 |* SwFlyAtCntFrm::SetAbsPos()
1213 |* Ersterstellung MA 22. Jun. 93
1214 |* Letzte Aenderung MA 11. Sep. 98
1216 |*************************************************************************/
1218 void SwFlyAtCntFrm::SetAbsPos( const Point &rNew )
1220 SwPageFrm *pOldPage = FindPageFrm();
1221 const SwRect aOld( GetObjRectWithSpaces() );
1222 Point aNew( rNew );
1224 if( GetAnchorFrm()->IsVertical() || GetAnchorFrm()->IsRightToLeft() )
1226 aNew.X() += Frm().Width();
1227 SwCntntFrm *pCnt = (SwCntntFrm*)::FindAnchor( GetAnchorFrm(), aNew );
1228 if( pCnt->IsProtected() )
1229 pCnt = (SwCntntFrm*)GetAnchorFrm();
1231 SwPageFrm *pTmpPage = 0;
1232 const bool bVert = pCnt->IsVertical();
1233 const sal_Bool bRTL = pCnt->IsRightToLeft();
1235 if( ( !bVert != !GetAnchorFrm()->IsVertical() ) ||
1236 ( !bRTL != !GetAnchorFrm()->IsRightToLeft() ) )
1238 if( bVert || bRTL )
1239 aNew.X() += Frm().Width();
1240 else
1241 aNew.X() -= Frm().Width();
1244 if ( pCnt->IsInDocBody() )
1246 //#38848 Vom Seitenrand in den Body ziehen.
1247 pTmpPage = pCnt->FindPageFrm();
1248 ::lcl_PointToPrt( aNew, pTmpPage->GetUpper() );
1249 SwRect aTmp( aNew, Size( 0, 0 ) );
1250 pTmpPage = (SwPageFrm*)::FindPage( aTmp, pTmpPage );
1251 ::lcl_PointToPrt( aNew, pTmpPage );
1254 //RelPos einstellen, nur auf Wunsch invalidieren.
1255 //rNew ist eine Absolute Position. Um die RelPos korrekt einzustellen
1256 //muessen wir uns die Entfernung von rNew zum Anker im Textfluss besorgen.
1257 //!!!!!Hier kann Optimiert werden: FindAnchor koennte die RelPos mitliefern!
1258 const SwFrm *pFrm = 0;
1259 SwTwips nY;
1260 if ( pCnt->Frm().IsInside( aNew ) )
1262 // --> OD 2009-01-12 #i70582#
1263 const SwTwips nTopForObjPos =
1264 bVert
1265 ? ( pCnt->Frm().Left() +
1266 pCnt->Frm().Width() -
1267 pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() )
1268 : ( pCnt->Frm().Top() +
1269 pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() );
1270 if ( bVert )
1272 nY = nTopForObjPos - rNew.X() - Frm().Width();
1274 else
1276 nY = rNew.Y() - nTopForObjPos;
1278 // <--
1280 else
1282 SwDistance aDist;
1283 pFrm = ::lcl_CalcDownDist( aDist, aNew, pCnt );
1284 nY = aDist.nMain + aDist.nSub;
1287 SwTwips nX = 0;
1289 if ( pCnt->IsFollow() )
1291 //Flys haengen niemals an einem Follow sondern immer am
1292 //Master, den suchen wir uns jetzt.
1293 const SwCntntFrm *pOriginal = pCnt;
1294 const SwCntntFrm *pFollow = pCnt;
1295 while ( pCnt->IsFollow() )
1298 { pCnt = pCnt->GetPrevCntntFrm();
1299 } while ( pCnt->GetFollow() != pFollow );
1300 pFollow = pCnt;
1302 SwTwips nDiff = 0;
1304 { const SwFrm *pUp = pFollow->GetUpper();
1305 if( pUp->IsVertical() )
1306 nDiff += pFollow->Frm().Left() + pFollow->Frm().Width()
1307 - pUp->Frm().Left() - pUp->Prt().Left();
1308 else
1309 nDiff += pUp->Prt().Height() - pFollow->GetRelPos().Y();
1310 pFollow = pFollow->GetFollow();
1311 } while ( pFollow != pOriginal );
1312 nY += nDiff;
1313 if( bVert )
1314 nX = pCnt->Frm().Top() - pOriginal->Frm().Top();
1315 else
1316 nX = pCnt->Frm().Left() - pOriginal->Frm().Left();
1319 if ( nY == LONG_MAX )
1321 // --> OD 2009-01-12 #i70582#
1322 const SwTwips nTopForObjPos =
1323 bVert
1324 ? ( pCnt->Frm().Left() +
1325 pCnt->Frm().Width() -
1326 pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() )
1327 : ( pCnt->Frm().Top() +
1328 pCnt->GetUpperSpaceAmountConsideredForPrevFrmAndPageGrid() );
1329 if ( bVert )
1331 nY = nTopForObjPos - rNew.X();
1333 else
1335 nY = rNew.Y() - nTopForObjPos;
1337 // <--
1340 SwFlyFrmFmt *pFmt = (SwFlyFrmFmt*)GetFmt();
1341 const SwFmtSurround& rSurround = pFmt->GetSurround();
1342 const BOOL bWrapThrough =
1343 rSurround.GetSurround() == SURROUND_THROUGHT;
1344 SwTwips nBaseOfstForFly = 0;
1345 const SwFrm* pTmpFrm = pFrm ? pFrm : pCnt;
1346 if ( pTmpFrm->IsTxtFrm() )
1347 nBaseOfstForFly =
1348 ((SwTxtFrm*)pTmpFrm)->GetBaseOfstForFly( !bWrapThrough );
1350 if( bVert )
1352 if( !pFrm )
1353 nX += rNew.Y() - pCnt->Frm().Top() - nBaseOfstForFly;
1354 else
1355 nX = rNew.Y() - pFrm->Frm().Top() - nBaseOfstForFly;
1357 else
1359 if( !pFrm )
1361 if ( pCnt->IsRightToLeft() )
1362 nX += pCnt->Frm().Right() - rNew.X() - Frm().Width() +
1363 nBaseOfstForFly;
1364 else
1365 nX += rNew.X() - pCnt->Frm().Left() - nBaseOfstForFly;
1367 else
1369 if ( pFrm->IsRightToLeft() )
1370 nX += pFrm->Frm().Right() - rNew.X() - Frm().Width() +
1371 nBaseOfstForFly;
1372 else
1373 nX = rNew.X() - pFrm->Frm().Left() - nBaseOfstForFly;
1376 GetFmt()->GetDoc()->StartUndo( UNDO_START, NULL );
1378 if( pCnt != GetAnchorFrm() || ( IsAutoPos() && pCnt->IsTxtFrm() &&
1379 GetFmt()->getIDocumentSettingAccess()->get(IDocumentSettingAccess::HTML_MODE)) )
1381 //Das Ankerattribut auf den neuen Cnt setzen.
1382 SwFmtAnchor aAnch( pFmt->GetAnchor() );
1383 SwPosition *pPos = (SwPosition*)aAnch.GetCntntAnchor();
1384 if( IsAutoPos() && pCnt->IsTxtFrm() )
1386 SwCrsrMoveState eTmpState( MV_SETONLYTEXT );
1387 Point aPt( rNew );
1388 if( pCnt->GetCrsrOfst( pPos, aPt, &eTmpState )
1389 && pPos->nNode == *pCnt->GetNode() )
1391 ResetLastCharRectHeight();
1392 if( text::RelOrientation::CHAR == pFmt->GetVertOrient().GetRelationOrient() )
1393 nY = LONG_MAX;
1394 if( text::RelOrientation::CHAR == pFmt->GetHoriOrient().GetRelationOrient() )
1395 nX = LONG_MAX;
1397 else
1399 pPos->nNode = *pCnt->GetNode();
1400 pPos->nContent.Assign( pCnt->GetNode(), 0 );
1403 else
1405 pPos->nNode = *pCnt->GetNode();
1406 pPos->nContent.Assign( pCnt->GetNode(), 0 );
1409 // --> OD 2006-02-27 #125892#
1410 // handle change of anchor node:
1411 // if count of the anchor frame also change, the fly frames have to be
1412 // re-created. Thus, delete all fly frames except the <this> before the
1413 // anchor attribute is change and re-create them afterwards.
1415 SwHandleAnchorNodeChg aHandleAnchorNodeChg( *pFmt, aAnch, this );
1416 pFmt->GetDoc()->SetAttr( aAnch, *pFmt );
1418 // <--
1420 // --> OD 2004-06-30 #i28701# - use new method <GetPageFrm()>
1421 else if ( pTmpPage && pTmpPage != GetPageFrm() )
1422 GetPageFrm()->MoveFly( this, pTmpPage );
1424 const Point aRelPos = bVert ? Point( -nY, nX ) : Point( nX, nY );
1425 ChgRelPos( aRelPos );
1427 GetFmt()->GetDoc()->EndUndo( UNDO_END, NULL );
1429 if ( pOldPage != FindPageFrm() )
1430 ::Notify_Background( GetVirtDrawObj(), pOldPage, aOld, PREP_FLY_LEAVE,
1431 FALSE );
1434 // OD 2004-08-12 #i32795# - Note: method no longer used in <flyincnt.cxx>
1435 //void DeepCalc( const SwFrm *pFrm )
1437 // if( pFrm->IsSctFrm() ||
1438 // ( pFrm->IsFlyFrm() && ((SwFlyFrm*)pFrm)->IsFlyInCntFrm() ) )
1439 // return;
1440 // const SwFlowFrm *pFlow = SwFlowFrm::CastFlowFrm( pFrm );
1441 // if( pFlow && pFlow->IsAnyJoinLocked() )
1442 // return;
1444 // USHORT nCnt = 0;
1446 // BOOL bContinue = FALSE;
1447 // do
1448 // {
1449 // if ( ++nCnt == 10 )
1450 // {
1451 // ASSERT( !nCnt, "DeepCalc: Loop detected1?" );
1452 // break;
1453 // }
1455 // const BOOL bSetComplete = !pFrm->IsValid();
1456 // const SwRect aOldFrm( pFrm->Frm() );
1457 // const SwRect aOldPrt( pFrm->Prt() );
1459 // const SwFrm *pUp = pFrm->GetUpper();
1460 // if ( pUp )
1461 // {
1462 // //Nicht weiter wenn der Up ein Fly mit Spalten ist.
1463 // if( ( !pUp->IsFlyFrm() || !((SwLayoutFrm*)pUp)->Lower() ||
1464 // !((SwLayoutFrm*)pUp)->Lower()->IsColumnFrm() ) &&
1465 // !pUp->IsSctFrm() )
1466 // {
1467 // SWRECTFN( pUp )
1468 // const Point aPt( (pUp->Frm().*fnRect->fnGetPos)() );
1469 // ::DeepCalc( pUp );
1470 // bContinue = aPt != (pUp->Frm().*fnRect->fnGetPos)();
1471 // }
1472 // }
1473 // else
1474 // pUp = pFrm;
1476 // pFrm->Calc();
1477 // if ( bSetComplete && (aOldFrm != pFrm->Frm() || aOldPrt != pFrm->Prt()))
1478 // pFrm->SetCompletePaint();
1480 // if ( pUp->IsFlyFrm() )
1481 // {
1482 // if ( ((SwFlyFrm*)pUp)->IsLocked() ||
1483 // (((SwFlyFrm*)pUp)->IsFlyAtCntFrm() &&
1484 // SwOszControl::IsInProgress( (const SwFlyFrm*)pUp )) )
1485 // {
1486 // bContinue = FALSE;
1487 // }
1488 // }
1489 // } while ( bContinue );
1492 /** method to assure that anchored object is registered at the correct
1493 page frame
1495 OD 2004-07-02 #i28701#
1496 takes over functionality of deleted method <SwFlyAtCntFrm::AssertPage()>
1498 @author OD
1500 void SwFlyAtCntFrm::RegisterAtCorrectPage()
1502 SwPageFrm* pPageFrm( 0L );
1503 if ( GetVertPosOrientFrm() )
1505 pPageFrm = const_cast<SwPageFrm*>(GetVertPosOrientFrm()->FindPageFrm());
1507 if ( pPageFrm && GetPageFrm() != pPageFrm )
1509 if ( GetPageFrm() )
1510 GetPageFrm()->MoveFly( this, pPageFrm );
1511 else
1512 pPageFrm->AppendFlyToPage( this );
1516 // OD 2004-03-23 #i26791#
1517 //void SwFlyAtCntFrm::MakeFlyPos()
1518 void SwFlyAtCntFrm::MakeObjPos()
1520 // OD 02.10.2002 #102646#
1521 // if fly frame position is valid, nothing is to do. Thus, return
1522 if ( bValidPos )
1524 return;
1527 // OD 2004-03-24 #i26791# - validate position flag here.
1528 bValidPos = TRUE;
1530 // --> OD 2004-10-22 #i35911# - no calculation of new position, if
1531 // anchored object is marked that it clears its environment and its
1532 // environment is already cleared.
1533 // --> OD 2006-01-02 #125977# - before checking for cleared environment
1534 // check, if member <mpVertPosOrientFrm> is set.
1535 if ( GetVertPosOrientFrm() &&
1536 ClearedEnvironment() && HasClearedEnvironment() )
1538 return;
1540 // <--
1542 // OD 29.10.2003 #113049# - use new class to position object
1543 objectpositioning::SwToCntntAnchoredObjectPosition
1544 aObjPositioning( *GetVirtDrawObj() );
1545 aObjPositioning.CalcPosition();
1547 SetVertPosOrientFrm ( aObjPositioning.GetVertPosOrientFrm() );
1550 // OD 2004-05-12 #i28701#
1551 bool SwFlyAtCntFrm::_InvalidationAllowed( const InvalidationType _nInvalid ) const
1553 bool bAllowed( SwFlyFreeFrm::_InvalidationAllowed( _nInvalid ) );
1555 // forbiddance of base instance can't be over ruled.
1556 if ( bAllowed )
1558 if ( _nInvalid == INVALID_POS ||
1559 _nInvalid == INVALID_ALL )
1561 bAllowed = InvalidationOfPosAllowed();
1565 return bAllowed;