Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "doc.hxx"
21 : #include "pagefrm.hxx"
22 : #include "rootfrm.hxx"
23 : #include "cntfrm.hxx"
24 : #include "dview.hxx"
25 : #include "dflyobj.hxx"
26 : #include "dcontact.hxx"
27 : #include "flyfrm.hxx"
28 : #include "ftnfrm.hxx"
29 : #include "frmtool.hxx"
30 : #include "frmfmt.hxx"
31 : #include "hints.hxx"
32 : #include "pam.hxx"
33 : #include "sectfrm.hxx"
34 :
35 :
36 : #include <svx/svdpage.hxx>
37 : #include <editeng/ulspitem.hxx>
38 : #include <fmtanchr.hxx>
39 : #include <fmtornt.hxx>
40 : #include <fmtfsize.hxx>
41 : #include "ndole.hxx"
42 : #include "tabfrm.hxx"
43 : #include "flyfrms.hxx"
44 : // #i18732#
45 : #include <fmtfollowtextflow.hxx>
46 : #include <environmentofanchoredobject.hxx>
47 : // #i28701#
48 : #include <sortedobjs.hxx>
49 : #include <viewsh.hxx>
50 : #include <viewimp.hxx>
51 :
52 :
53 : using namespace ::com::sun::star;
54 :
55 :
56 : /*************************************************************************
57 : |*
58 : |* SwFlyFreeFrm::SwFlyFreeFrm(), ~SwFlyFreeFrm()
59 : |*
60 : |*************************************************************************/
61 :
62 74 : SwFlyFreeFrm::SwFlyFreeFrm( SwFlyFrmFmt *pFmt, SwFrm* pSib, SwFrm *pAnch ) :
63 : SwFlyFrm( pFmt, pSib, pAnch ),
64 : pPage( 0 ),
65 : // #i34753#
66 : mbNoMakePos( false ),
67 : // #i37068#
68 : mbNoMoveOnCheckClip( false ),
69 74 : maUnclippedFrm( )
70 : {
71 74 : }
72 :
73 16 : SwFlyFreeFrm::~SwFlyFreeFrm()
74 : {
75 : // and goodbye.
76 : // #i28701# - use new method <GetPageFrm()>
77 8 : if( GetPageFrm() )
78 : {
79 0 : if( GetFmt()->GetDoc()->IsInDtor() )
80 : {
81 : // #i29879# - remove also to-frame anchored Writer
82 : // fly frame from page.
83 : const bool bRemoveFromPage =
84 0 : GetPageFrm()->GetSortedObjs() &&
85 0 : ( IsFlyAtCntFrm() ||
86 0 : ( GetAnchorFrm() && GetAnchorFrm()->IsFlyFrm() ) );
87 0 : if ( bRemoveFromPage )
88 : {
89 0 : GetPageFrm()->GetSortedObjs()->Remove( *this );
90 : }
91 : }
92 : else
93 : {
94 0 : SwRect aTmp( GetObjRectWithSpaces() );
95 0 : SwFlyFreeFrm::NotifyBackground( GetPageFrm(), aTmp, PREP_FLY_LEAVE );
96 : }
97 : }
98 8 : }
99 :
100 : // #i28701#
101 6512 : TYPEINIT1(SwFlyFreeFrm,SwFlyFrm);
102 : /*************************************************************************
103 : |*
104 : |* SwFlyFreeFrm::NotifyBackground()
105 : |*
106 : |* Description notifies the background (all CntntFrms that currently
107 : |* are overlapping). Additionally, the window is also directly
108 : |* invalidated (especially where there are no overlapping CntntFrms)
109 : |* This also takes CntntFrms within other Flys into account.
110 : |*
111 : |*************************************************************************/
112 :
113 86 : void SwFlyFreeFrm::NotifyBackground( SwPageFrm *pPageFrm,
114 : const SwRect& rRect, PrepareHint eHint )
115 : {
116 86 : ::Notify_Background( GetVirtDrawObj(), pPageFrm, rRect, eHint, sal_True );
117 86 : }
118 :
119 : /*************************************************************************
120 : |*
121 : |* SwFlyFreeFrm::MakeAll()
122 : |*
123 : |*************************************************************************/
124 :
125 98 : void SwFlyFreeFrm::MakeAll()
126 : {
127 98 : if ( !GetFmt()->GetDoc()->IsVisibleLayerId( GetVirtDrawObj()->GetLayer() ) )
128 : {
129 : return;
130 : }
131 :
132 98 : if ( !GetAnchorFrm() || IsLocked() || IsColLocked() )
133 : return;
134 : // #i28701# - use new method <GetPageFrm()>
135 98 : if( !GetPageFrm() && GetAnchorFrm() && GetAnchorFrm()->IsInFly() )
136 : {
137 0 : SwFlyFrm* pFly = AnchorFrm()->FindFlyFrm();
138 0 : SwPageFrm *pPageFrm = pFly ? pFly->FindPageFrm() : NULL;
139 0 : if( pPageFrm )
140 0 : pPageFrm->AppendFlyToPage( this );
141 : }
142 98 : if( !GetPageFrm() )
143 : return;
144 :
145 98 : Lock(); // The curtain drops
146 :
147 : // takes care of the notification in the dtor
148 98 : const SwFlyNotify aNotify( this );
149 :
150 98 : if ( IsClipped() )
151 : {
152 0 : bValidSize = bHeightClipped = bWidthClipped = sal_False;
153 : // no invalidation of position,
154 : // if anchored object is anchored inside a Writer fly frame,
155 : // its position is already locked, and it follows the text flow.
156 : // #i34753# - add condition:
157 : // no invalidation of position, if no direct move is requested in <CheckClip(..)>
158 0 : if ( !IsNoMoveOnCheckClip() &&
159 0 : !( PositionLocked() &&
160 0 : GetAnchorFrm()->IsInFly() &&
161 0 : GetFrmFmt().GetFollowTextFlow().GetValue() ) )
162 : {
163 0 : bValidPos = sal_False;
164 : }
165 : }
166 :
167 : // #i81146# new loop control
168 98 : sal_uInt16 nLoopControlRuns = 0;
169 98 : const sal_uInt16 nLoopControlMax = 10;
170 :
171 350 : while ( !bValidPos || !bValidSize || !bValidPrtArea || bFormatHeightOnly )
172 : {
173 154 : SWRECTFN( this )
174 : const SwFmtFrmSize *pSz;
175 : { // Additional scope, so aAccess will be destroyed before the check!
176 :
177 154 : SwBorderAttrAccess aAccess( SwFrm::GetCache(), this );
178 154 : const SwBorderAttrs &rAttrs = *aAccess.Get();
179 154 : pSz = &rAttrs.GetAttrSet().GetFrmSize();
180 :
181 : // Only set when the flag is set!
182 154 : if ( !bValidSize )
183 : {
184 134 : bValidPrtArea = sal_False;
185 : }
186 :
187 154 : if ( !bValidPrtArea )
188 134 : MakePrtArea( rAttrs );
189 :
190 154 : if ( !bValidSize || bFormatHeightOnly )
191 : {
192 134 : bValidSize = sal_False;
193 134 : Format( &rAttrs );
194 134 : bFormatHeightOnly = sal_False;
195 : }
196 :
197 154 : if ( !bValidPos )
198 : {
199 82 : const Point aOldPos( (Frm().*fnRect->fnGetPos)() );
200 : // #i26791# - use new method <MakeObjPos()>
201 : // #i34753# - no positioning, if requested.
202 82 : if ( IsNoMakePos() )
203 0 : bValidPos = sal_True;
204 : else
205 : // #i26791# - use new method <MakeObjPos()>
206 82 : MakeObjPos();
207 82 : if( aOldPos == (Frm().*fnRect->fnGetPos)() )
208 : {
209 26 : if( !bValidPos && GetAnchorFrm()->IsInSct() &&
210 0 : !GetAnchorFrm()->FindSctFrm()->IsValid() )
211 0 : bValidPos = sal_True;
212 : }
213 : else
214 56 : bValidSize = sal_False;
215 154 : }
216 : }
217 :
218 154 : if ( bValidPos && bValidSize )
219 : {
220 98 : ++nLoopControlRuns;
221 :
222 : OSL_ENSURE( nLoopControlRuns < nLoopControlMax, "LoopControl in SwFlyFreeFrm::MakeAll" );
223 :
224 196 : if ( nLoopControlRuns < nLoopControlMax )
225 98 : CheckClip( *pSz );
226 : }
227 : else
228 56 : nLoopControlRuns = 0;
229 : }
230 98 : Unlock();
231 :
232 : #if OSL_DEBUG_LEVEL > 0
233 : SWRECTFN( this )
234 : OSL_ENSURE( bHeightClipped || ( (Frm().*fnRect->fnGetHeight)() > 0 &&
235 : (Prt().*fnRect->fnGetHeight)() > 0),
236 : "SwFlyFreeFrm::Format(), flipping Fly." );
237 :
238 : #endif
239 : }
240 :
241 : /** determines, if direct environment of fly frame has 'auto' size
242 :
243 : #i17297#
244 : start with anchor frame and search via <GetUpper()> for a header, footer,
245 : row or fly frame stopping at page frame.
246 : return <true>, if such a frame is found and it has 'auto' size.
247 : otherwise <false> is returned.
248 :
249 : @return boolean indicating, that direct environment has 'auto' size
250 : */
251 0 : bool SwFlyFreeFrm::HasEnvironmentAutoSize() const
252 : {
253 0 : bool bRetVal = false;
254 :
255 0 : const SwFrm* pToBeCheckedFrm = GetAnchorFrm();
256 0 : while ( pToBeCheckedFrm &&
257 0 : !pToBeCheckedFrm->IsPageFrm() )
258 : {
259 0 : if ( pToBeCheckedFrm->IsHeaderFrm() ||
260 0 : pToBeCheckedFrm->IsFooterFrm() ||
261 0 : pToBeCheckedFrm->IsRowFrm() ||
262 0 : pToBeCheckedFrm->IsFlyFrm() )
263 : {
264 : bRetVal = ATT_FIX_SIZE !=
265 0 : pToBeCheckedFrm->GetAttrSet()->GetFrmSize().GetHeightSizeType();
266 0 : break;
267 : }
268 : else
269 : {
270 0 : pToBeCheckedFrm = pToBeCheckedFrm->GetUpper();
271 : }
272 : }
273 :
274 0 : return bRetVal;
275 : }
276 :
277 : /*************************************************************************
278 : |*
279 : |* SwFlyFreeFrm::CheckClip()
280 : |*
281 : |*************************************************************************/
282 :
283 98 : void SwFlyFreeFrm::CheckClip( const SwFmtFrmSize &rSz )
284 : {
285 : // It's probably time now to take appropriate measures, if the Fly
286 : // doesn't fit into its surrounding.
287 : // First, the Fly gives up its position, then it's formatted.
288 : // Only if it still doesn't fit after giving up its position, the
289 : // width or height are given up as well. The frame will be squeezed
290 : // as much as needed.
291 :
292 98 : const SwVirtFlyDrawObj *pObj = GetVirtDrawObj();
293 98 : SwRect aClip, aTmpStretch;
294 98 : ::CalcClipRect( pObj, aClip, sal_True );
295 98 : ::CalcClipRect( pObj, aTmpStretch, sal_False );
296 98 : aClip._Intersection( aTmpStretch );
297 :
298 98 : const long nBot = Frm().Top() + Frm().Height();
299 98 : const long nRig = Frm().Left() + Frm().Width();
300 98 : const long nClipBot = aClip.Top() + aClip.Height();
301 98 : const long nClipRig = aClip.Left() + aClip.Width();
302 :
303 98 : const bool bBot = nBot > nClipBot;
304 98 : const bool bRig = nRig > nClipRig;
305 98 : if ( bBot || bRig )
306 : {
307 0 : bool bAgain = false;
308 : // #i37068# - no move, if it's requested
309 0 : if ( bBot && !IsNoMoveOnCheckClip() &&
310 0 : !GetDrawObjs() && !GetAnchorFrm()->IsInTab() )
311 : {
312 0 : SwFrm* pHeader = FindFooterOrHeader();
313 : // In a header, correction of the position is no good idea.
314 : // If the fly moves, some paragraphs have to be formatted, this
315 : // could cause a change of the height of the headerframe,
316 : // now the flyframe can change its position and so on ...
317 0 : if ( !pHeader || !pHeader->IsHeaderFrm() )
318 : {
319 0 : const long nOld = Frm().Top();
320 0 : Frm().Pos().Y() = Max( aClip.Top(), nClipBot - Frm().Height() );
321 0 : if ( Frm().Top() != nOld )
322 0 : bAgain = true;
323 0 : bHeightClipped = sal_True;
324 : }
325 : }
326 0 : if ( bRig )
327 : {
328 0 : const long nOld = Frm().Left();
329 0 : Frm().Pos().X() = Max( aClip.Left(), nClipRig - Frm().Width() );
330 0 : if ( Frm().Left() != nOld )
331 : {
332 0 : const SwFmtHoriOrient &rH = GetFmt()->GetHoriOrient();
333 : // Left-aligned ones may not be moved to the left when they
334 : // are avoiding another one.
335 0 : if( rH.GetHoriOrient() == text::HoriOrientation::LEFT )
336 0 : Frm().Pos().X() = nOld;
337 : else
338 0 : bAgain = true;
339 : }
340 0 : bWidthClipped = sal_True;
341 : }
342 0 : if ( bAgain )
343 0 : bValidSize = sal_False;
344 : else
345 : {
346 : // If we reach this branch, the Frm protrudes into forbidden
347 : // areas, and correcting the position is not allowed or not
348 : // possible or not required.
349 :
350 : // For Flys with OLE objects as lower, we make sure that
351 : // we always resize proportionally
352 0 : Size aOldSize( Frm().SSize() );
353 :
354 : // First, setup the FrmRect, then transfer it to the Frm.
355 0 : SwRect aFrmRect( Frm() );
356 :
357 0 : if ( bBot )
358 : {
359 0 : long nDiff = nClipBot;
360 0 : nDiff -= aFrmRect.Top(); // nDiff represents the available distance
361 0 : nDiff = aFrmRect.Height() - nDiff;
362 0 : aFrmRect.Height( aFrmRect.Height() - nDiff );
363 0 : bHeightClipped = sal_True;
364 : }
365 0 : if ( bRig )
366 : {
367 0 : long nDiff = nClipRig;
368 0 : nDiff -= aFrmRect.Left();// nDiff represents the available distance
369 0 : nDiff = aFrmRect.Width() - nDiff;
370 0 : aFrmRect.Width( aFrmRect.Width() - nDiff );
371 0 : bWidthClipped = sal_True;
372 : }
373 :
374 : // #i17297# - no proportional
375 : // scaling of graphics in environments, which determines its size
376 : // by its content ('auto' size). Otherwise layout loops can occur and
377 : // layout sizes of the environment can be incorrect.
378 : // Such environment are:
379 : // (1) header and footer frames with 'auto' size
380 : // (2) table row frames with 'auto' size
381 : // (3) fly frames with 'auto' size
382 : // Note: section frames seems to be not critical - didn't found
383 : // any critical layout situation so far.
384 0 : if ( Lower() && Lower()->IsNoTxtFrm() &&
385 0 : ( static_cast<SwCntntFrm*>(Lower())->GetNode()->GetOLENode() ||
386 0 : !HasEnvironmentAutoSize() ) )
387 : {
388 : // If width and height got adjusted, then the bigger
389 : // change is relevant.
390 0 : if ( aFrmRect.Width() != aOldSize.Width() &&
391 0 : aFrmRect.Height()!= aOldSize.Height() )
392 : {
393 0 : if ( (aOldSize.Width() - aFrmRect.Width()) >
394 0 : (aOldSize.Height()- aFrmRect.Height()) )
395 0 : aFrmRect.Height( aOldSize.Height() );
396 : else
397 0 : aFrmRect.Width( aOldSize.Width() );
398 : }
399 :
400 : // Adjusted the width? change height proportionally
401 0 : if( aFrmRect.Width() != aOldSize.Width() )
402 : {
403 0 : aFrmRect.Height( aFrmRect.Width() * aOldSize.Height() /
404 0 : aOldSize.Width() );
405 0 : bHeightClipped = sal_True;
406 : }
407 : // Adjusted the height? change width proportionally
408 0 : else if( aFrmRect.Height() != aOldSize.Height() )
409 : {
410 0 : aFrmRect.Width( aFrmRect.Height() * aOldSize.Width() /
411 0 : aOldSize.Height() );
412 0 : bWidthClipped = sal_True;
413 : }
414 :
415 : // #i17297# - reactivate change
416 : // of size attribute for fly frames containing an ole object.
417 :
418 : // Added the aFrmRect.HasArea() hack, because
419 : // the environment of the ole object does not have to be valid
420 : // at this moment, or even worse, it does not have to have a
421 : // resonable size. In this case we do not want to change to
422 : // attributes permanentely. Maybe one day somebody dares to remove
423 : // this code.
424 0 : if ( aFrmRect.HasArea() &&
425 0 : static_cast<SwCntntFrm*>(Lower())->GetNode()->GetOLENode() &&
426 : ( bWidthClipped || bHeightClipped ) )
427 : {
428 0 : SwFlyFrmFmt *pFmt = (SwFlyFrmFmt*)GetFmt();
429 0 : pFmt->LockModify();
430 0 : SwFmtFrmSize aFrmSize( rSz );
431 0 : aFrmSize.SetWidth( aFrmRect.Width() );
432 0 : aFrmSize.SetHeight( aFrmRect.Height() );
433 0 : pFmt->SetFmtAttr( aFrmSize );
434 0 : pFmt->UnlockModify();
435 : }
436 : }
437 :
438 : // Now change the Frm; for columns, we put the new values into the attributes,
439 : // otherwise we'll end up with unwanted side-effects/oscillations
440 0 : const long nPrtHeightDiff = Frm().Height() - Prt().Height();
441 0 : const long nPrtWidthDiff = Frm().Width() - Prt().Width();
442 0 : maUnclippedFrm = SwRect( Frm() );
443 0 : Frm().Height( aFrmRect.Height() );
444 0 : Frm().Width ( Max( long(MINLAY), aFrmRect.Width() ) );
445 0 : if ( Lower() && Lower()->IsColumnFrm() )
446 : {
447 0 : ColLock(); //lock grow/shrink
448 0 : const Size aTmpOldSize( Prt().SSize() );
449 0 : Prt().Height( Frm().Height() - nPrtHeightDiff );
450 0 : Prt().Width ( Frm().Width() - nPrtWidthDiff );
451 0 : ChgLowersProp( aTmpOldSize );
452 0 : SwFrm *pLow = Lower();
453 0 : do
454 0 : { pLow->Calc();
455 : // also calculate the (Column)BodyFrm
456 0 : ((SwLayoutFrm*)pLow)->Lower()->Calc();
457 0 : pLow = pLow->GetNext();
458 : } while ( pLow );
459 0 : ::CalcCntnt( this );
460 0 : ColUnlock();
461 0 : if ( !bValidSize && !bWidthClipped )
462 0 : bFormatHeightOnly = bValidSize = sal_True;
463 : }
464 : else
465 : {
466 0 : Prt().Height( Frm().Height() - nPrtHeightDiff );
467 0 : Prt().Width ( Frm().Width() - nPrtWidthDiff );
468 : }
469 : }
470 : }
471 :
472 : // #i26945#
473 : OSL_ENSURE( Frm().Height() >= 0,
474 : "<SwFlyFreeFrm::CheckClip(..)> - fly frame has negative height now." );
475 98 : }
476 :
477 : /** method to determine, if a <MakeAll()> on the Writer fly frame is possible
478 : #i43771#
479 : */
480 226 : bool SwFlyFreeFrm::IsFormatPossible() const
481 : {
482 226 : return SwFlyFrm::IsFormatPossible() &&
483 226 : ( GetPageFrm() ||
484 452 : ( GetAnchorFrm() && GetAnchorFrm()->IsInFly() ) );
485 : }
486 :
487 : /*************************************************************************
488 : |*
489 : |* SwFlyLayFrm::SwFlyLayFrm()
490 : |*
491 : |*************************************************************************/
492 :
493 0 : SwFlyLayFrm::SwFlyLayFrm( SwFlyFrmFmt *pFmt, SwFrm* pSib, SwFrm *pAnch ) :
494 0 : SwFlyFreeFrm( pFmt, pSib, pAnch )
495 : {
496 0 : bLayout = sal_True;
497 0 : }
498 :
499 : // #i28701#
500 0 : TYPEINIT1(SwFlyLayFrm,SwFlyFreeFrm);
501 : /*************************************************************************
502 : |*
503 : |* SwFlyLayFrm::Modify()
504 : |*
505 : |*************************************************************************/
506 :
507 0 : void SwFlyLayFrm::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
508 : {
509 0 : sal_uInt16 nWhich = pNew ? pNew->Which() : 0;
510 :
511 0 : SwFmtAnchor *pAnch = 0;
512 0 : if( RES_ATTRSET_CHG == nWhich && SFX_ITEM_SET ==
513 0 : ((SwAttrSetChg*)pNew)->GetChgSet()->GetItemState( RES_ANCHOR, sal_False,
514 0 : (const SfxPoolItem**)&pAnch ))
515 : ; // GetItemState sets the anchor pointer!
516 :
517 0 : else if( RES_ANCHOR == nWhich )
518 : {
519 : // Change of anchor. I'm attaching myself to the new place.
520 : // It's not allowed to change the anchor type. This is only
521 : // possible via SwFEShell.
522 0 : pAnch = (SwFmtAnchor*)pNew;
523 : }
524 :
525 0 : if( pAnch )
526 : {
527 : OSL_ENSURE( pAnch->GetAnchorId() ==
528 : GetFmt()->GetAnchor().GetAnchorId(),
529 : "8-) Invalid change of anchor type." );
530 :
531 : // Unregister, get hold of the page, attach to the corresponding LayoutFrm.
532 0 : SwRect aOld( GetObjRectWithSpaces() );
533 : // #i28701# - use new method <GetPageFrm()>
534 0 : SwPageFrm *pOldPage = GetPageFrm();
535 0 : AnchorFrm()->RemoveFly( this );
536 :
537 0 : if ( FLY_AT_PAGE == pAnch->GetAnchorId() )
538 : {
539 0 : sal_uInt16 nPgNum = pAnch->GetPageNum();
540 0 : SwRootFrm *pRoot = getRootFrm();
541 0 : SwPageFrm *pTmpPage = (SwPageFrm*)pRoot->Lower();
542 0 : for ( sal_uInt16 i = 1; (i <= nPgNum) && pTmpPage; ++i,
543 0 : pTmpPage = (SwPageFrm*)pTmpPage->GetNext() )
544 : {
545 0 : if ( i == nPgNum )
546 : {
547 : // #i50432# - adjust synopsis of <PlaceFly(..)>
548 0 : pTmpPage->PlaceFly( this, 0 );
549 : }
550 : }
551 0 : if( !pTmpPage )
552 : {
553 0 : pRoot->SetAssertFlyPages();
554 0 : pRoot->AssertFlyPages();
555 : }
556 : }
557 : else
558 : {
559 0 : SwNodeIndex aIdx( pAnch->GetCntntAnchor()->nNode );
560 0 : SwCntntFrm *pCntnt = GetFmt()->GetDoc()->GetNodes().GoNext( &aIdx )->
561 0 : GetCntntNode()->getLayoutFrm( getRootFrm(), 0, 0, sal_False );
562 0 : if( pCntnt )
563 : {
564 0 : SwFlyFrm *pTmp = pCntnt->FindFlyFrm();
565 0 : if( pTmp )
566 0 : pTmp->AppendFly( this );
567 0 : }
568 : }
569 : // #i28701# - use new method <GetPageFrm()>
570 0 : if ( pOldPage && pOldPage != GetPageFrm() )
571 0 : NotifyBackground( pOldPage, aOld, PREP_FLY_LEAVE );
572 0 : SetCompletePaint();
573 0 : InvalidateAll();
574 0 : SetNotifyBack();
575 : }
576 : else
577 0 : SwFlyFrm::Modify( pOld, pNew );
578 0 : }
579 :
580 : /*************************************************************************
581 : |*
582 : |* SwPageFrm::AppendFly()
583 : |*
584 : |*************************************************************************/
585 :
586 384 : void SwPageFrm::AppendFlyToPage( SwFlyFrm *pNew )
587 : {
588 384 : if ( !pNew->GetVirtDrawObj()->IsInserted() )
589 0 : getRootFrm()->GetDrawPage()->InsertObject(
590 0 : (SdrObject*)pNew->GetVirtDrawObj(),
591 0 : pNew->GetVirtDrawObj()->GetReferencedObj().GetOrdNumDirect() );
592 :
593 384 : InvalidateSpelling();
594 384 : InvalidateSmartTags(); // SMARTTAGS
595 384 : InvalidateAutoCompleteWords();
596 384 : InvalidateWordCount();
597 :
598 384 : if ( GetUpper() )
599 : {
600 384 : ((SwRootFrm*)GetUpper())->SetIdleFlags();
601 384 : ((SwRootFrm*)GetUpper())->InvalidateBrowseWidth();
602 : }
603 :
604 384 : SdrObject* pObj = pNew->GetVirtDrawObj();
605 : OSL_ENSURE( pNew->GetAnchorFrm(), "Fly without Anchor" );
606 384 : const SwFlyFrm* pFly = pNew->GetAnchorFrm()->FindFlyFrm();
607 384 : if ( pFly && pObj->GetOrdNum() < pFly->GetVirtDrawObj()->GetOrdNum() )
608 : {
609 0 : sal_uInt32 nNewNum = pFly->GetVirtDrawObj()->GetOrdNumDirect();
610 0 : if ( pObj->GetPage() )
611 0 : pObj->GetPage()->SetObjectOrdNum( pObj->GetOrdNumDirect(), nNewNum);
612 : else
613 0 : pObj->SetOrdNum( nNewNum );
614 : }
615 :
616 : // Don't look further at Flys that sit inside the Cntnt.
617 384 : if ( pNew->IsFlyInCntFrm() )
618 310 : InvalidateFlyInCnt();
619 : else
620 : {
621 74 : InvalidateFlyCntnt();
622 :
623 74 : if ( !pSortedObjs )
624 48 : pSortedObjs = new SwSortedObjs();
625 :
626 74 : const bool bSucessInserted = pSortedObjs->Insert( *pNew );
627 : OSL_ENSURE( bSucessInserted, "Fly not inserted in Sorted." );
628 : (void) bSucessInserted;
629 :
630 : // #i87493#
631 : OSL_ENSURE( pNew->GetPageFrm() == 0 || pNew->GetPageFrm() == this,
632 : "<SwPageFrm::AppendFlyToPage(..)> - anchored fly frame seems to be registered at another page frame. Serious defect -> please inform OD." );
633 : // #i28701# - use new method <SetPageFrm(..)>
634 74 : pNew->SetPageFrm( this );
635 74 : pNew->InvalidatePage( this );
636 : // #i28701#
637 74 : pNew->UnlockPosition();
638 :
639 : // Notify accessible layout. That's required at this place for
640 : // frames only where the anchor is moved. Creation of new frames
641 : // is additionally handled by the SwFrmNotify class.
642 148 : if( GetUpper() &&
643 74 : static_cast< SwRootFrm * >( GetUpper() )->IsAnyShellAccessible() &&
644 0 : static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell() )
645 : {
646 0 : static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell()->Imp()
647 0 : ->AddAccessibleFrm( pNew );
648 : }
649 : }
650 :
651 : // #i28701# - correction: consider also drawing objects
652 384 : if ( pNew->GetDrawObjs() )
653 : {
654 0 : SwSortedObjs &rObjs = *pNew->GetDrawObjs();
655 0 : for ( sal_uInt16 i = 0; i < rObjs.Count(); ++i )
656 : {
657 0 : SwAnchoredObject* pTmpObj = rObjs[i];
658 0 : if ( pTmpObj->ISA(SwFlyFrm) )
659 : {
660 0 : SwFlyFrm* pTmpFly = static_cast<SwFlyFrm*>(pTmpObj);
661 : // #i28701# - use new method <GetPageFrm()>
662 0 : if ( pTmpFly->IsFlyFreeFrm() && !pTmpFly->GetPageFrm() )
663 0 : AppendFlyToPage( pTmpFly );
664 : }
665 0 : else if ( pTmpObj->ISA(SwAnchoredDrawObject) )
666 : {
667 : // #i87493#
668 0 : if ( pTmpObj->GetPageFrm() != this )
669 : {
670 0 : if ( pTmpObj->GetPageFrm() != 0 )
671 : {
672 0 : pTmpObj->GetPageFrm()->RemoveDrawObjFromPage( *pTmpObj );
673 : }
674 0 : AppendDrawObjToPage( *pTmpObj );
675 : }
676 : }
677 : }
678 : }
679 384 : }
680 :
681 : /*************************************************************************
682 : |*
683 : |* SwPageFrm::RemoveFly()
684 : |*
685 : |*************************************************************************/
686 :
687 0 : void SwPageFrm::RemoveFlyFromPage( SwFlyFrm *pToRemove )
688 : {
689 0 : const sal_uInt32 nOrdNum = pToRemove->GetVirtDrawObj()->GetOrdNum();
690 0 : getRootFrm()->GetDrawPage()->RemoveObject( nOrdNum );
691 0 : pToRemove->GetVirtDrawObj()->ReferencedObj().SetOrdNum( nOrdNum );
692 :
693 0 : if ( GetUpper() )
694 : {
695 0 : if ( !pToRemove->IsFlyInCntFrm() )
696 0 : ((SwRootFrm*)GetUpper())->SetSuperfluous();
697 0 : ((SwRootFrm*)GetUpper())->InvalidateBrowseWidth();
698 : }
699 :
700 : // Don't look further at Flys that sit inside the Cntnt.
701 0 : if ( pToRemove->IsFlyInCntFrm() )
702 0 : return;
703 :
704 : // Notify accessible layout. That's required at this place for
705 : // frames only where the anchor is moved. Creation of new frames
706 : // is additionally handled by the SwFrmNotify class.
707 0 : if( GetUpper() &&
708 0 : static_cast< SwRootFrm * >( GetUpper() )->IsAnyShellAccessible() &&
709 0 : static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell() )
710 : {
711 0 : static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell()->Imp()
712 0 : ->DisposeAccessibleFrm( pToRemove, sal_True );
713 : }
714 :
715 : // Don't delete collections just yet. This will happen at the end of the
716 : // action in the RemoveSuperfluous of the page, kicked off by a method of
717 : // the same name in the root.
718 : // The FlyColl might be gone already, because the page's dtor is being executed.
719 0 : if ( pSortedObjs )
720 : {
721 0 : pSortedObjs->Remove( *pToRemove );
722 0 : if ( !pSortedObjs->Count() )
723 0 : { DELETEZ( pSortedObjs );
724 : }
725 : }
726 : // #i28701# - use new method <SetPageFrm(..)>
727 0 : pToRemove->SetPageFrm( 0L );
728 : }
729 :
730 : /*************************************************************************
731 : |*
732 : |* SwPageFrm::MoveFly
733 : |*
734 : |*************************************************************************/
735 :
736 0 : void SwPageFrm::MoveFly( SwFlyFrm *pToMove, SwPageFrm *pDest )
737 : {
738 : // Invalidations
739 0 : if ( GetUpper() )
740 : {
741 0 : ((SwRootFrm*)GetUpper())->SetIdleFlags();
742 0 : if ( !pToMove->IsFlyInCntFrm() && pDest->GetPhyPageNum() < GetPhyPageNum() )
743 0 : ((SwRootFrm*)GetUpper())->SetSuperfluous();
744 : }
745 :
746 0 : pDest->InvalidateSpelling();
747 0 : pDest->InvalidateSmartTags(); // SMARTTAGS
748 0 : pDest->InvalidateAutoCompleteWords();
749 0 : pDest->InvalidateWordCount();
750 :
751 0 : if ( pToMove->IsFlyInCntFrm() )
752 : {
753 0 : pDest->InvalidateFlyInCnt();
754 0 : return;
755 : }
756 :
757 : // Notify accessible layout. That's required at this place for
758 : // frames only where the anchor is moved. Creation of new frames
759 : // is additionally handled by the SwFrmNotify class.
760 0 : if( GetUpper() &&
761 0 : static_cast< SwRootFrm * >( GetUpper() )->IsAnyShellAccessible() &&
762 0 : static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell() )
763 : {
764 0 : static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell()->Imp()
765 0 : ->DisposeAccessibleFrm( pToMove, sal_True );
766 : }
767 :
768 : // The FlyColl might be gone already, because the page's dtor is being executed.
769 0 : if ( pSortedObjs )
770 : {
771 0 : pSortedObjs->Remove( *pToMove );
772 0 : if ( !pSortedObjs->Count() )
773 0 : { DELETEZ( pSortedObjs );
774 : }
775 : }
776 :
777 : // Register
778 0 : if ( !pDest->GetSortedObjs() )
779 0 : pDest->pSortedObjs = new SwSortedObjs();
780 :
781 0 : const bool bSucessInserted = pDest->GetSortedObjs()->Insert( *pToMove );
782 : OSL_ENSURE( bSucessInserted, "Fly not inserted in Sorted." );
783 : (void) bSucessInserted;
784 :
785 : // #i28701# - use new method <SetPageFrm(..)>
786 0 : pToMove->SetPageFrm( pDest );
787 0 : pToMove->InvalidatePage( pDest );
788 0 : pToMove->SetNotifyBack();
789 0 : pDest->InvalidateFlyCntnt();
790 : // #i28701#
791 0 : pToMove->UnlockPosition();
792 :
793 : // Notify accessible layout. That's required at this place for
794 : // frames only where the anchor is moved. Creation of new frames
795 : // is additionally handled by the SwFrmNotify class.
796 0 : if( GetUpper() &&
797 0 : static_cast< SwRootFrm * >( GetUpper() )->IsAnyShellAccessible() &&
798 0 : static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell() )
799 : {
800 0 : static_cast< SwRootFrm * >( GetUpper() )->GetCurrShell()->Imp()
801 0 : ->AddAccessibleFrm( pToMove );
802 : }
803 :
804 : // #i28701# - correction: move lowers of Writer fly frame
805 0 : if ( pToMove->GetDrawObjs() )
806 : {
807 0 : SwSortedObjs &rObjs = *pToMove->GetDrawObjs();
808 0 : for ( sal_uInt32 i = 0; i < rObjs.Count(); ++i )
809 : {
810 0 : SwAnchoredObject* pObj = rObjs[i];
811 0 : if ( pObj->ISA(SwFlyFrm) )
812 : {
813 0 : SwFlyFrm* pFly = static_cast<SwFlyFrm*>(pObj);
814 0 : if ( pFly->IsFlyFreeFrm() )
815 : {
816 : // #i28701# - use new method <GetPageFrm()>
817 0 : SwPageFrm* pPageFrm = pFly->GetPageFrm();
818 0 : if ( pPageFrm )
819 0 : pPageFrm->MoveFly( pFly, pDest );
820 : else
821 0 : pDest->AppendFlyToPage( pFly );
822 : }
823 : }
824 0 : else if ( pObj->ISA(SwAnchoredDrawObject) )
825 : {
826 0 : RemoveDrawObjFromPage( *pObj );
827 0 : pDest->AppendDrawObjToPage( *pObj );
828 : }
829 : }
830 : }
831 : }
832 :
833 : /*************************************************************************
834 : |*
835 : |* SwPageFrm::AppendDrawObjToPage(), RemoveDrawObjFromPage()
836 : |*
837 : |* #i28701# - new methods
838 : |*
839 : |*************************************************************************/
840 90 : void SwPageFrm::AppendDrawObjToPage( SwAnchoredObject& _rNewObj )
841 : {
842 90 : if ( !_rNewObj.ISA(SwAnchoredDrawObject) )
843 : {
844 : OSL_FAIL( "SwPageFrm::AppendDrawObjToPage(..) - anchored object of unexcepted type -> object not appended" );
845 0 : return;
846 : }
847 :
848 90 : if ( GetUpper() )
849 : {
850 90 : ((SwRootFrm*)GetUpper())->InvalidateBrowseWidth();
851 : }
852 :
853 : OSL_ENSURE( _rNewObj.GetAnchorFrm(), "anchored draw object without anchor" );
854 90 : const SwFlyFrm* pFlyFrm = _rNewObj.GetAnchorFrm()->FindFlyFrm();
855 90 : if ( pFlyFrm &&
856 0 : _rNewObj.GetDrawObj()->GetOrdNum() < pFlyFrm->GetVirtDrawObj()->GetOrdNum() )
857 : {
858 0 : sal_uInt32 nNewNum = pFlyFrm->GetVirtDrawObj()->GetOrdNumDirect();
859 0 : if ( _rNewObj.GetDrawObj()->GetPage() )
860 0 : _rNewObj.DrawObj()->GetPage()->SetObjectOrdNum(
861 0 : _rNewObj.GetDrawObj()->GetOrdNumDirect(), nNewNum);
862 : else
863 0 : _rNewObj.DrawObj()->SetOrdNum( nNewNum );
864 : }
865 :
866 90 : if ( FLY_AS_CHAR == _rNewObj.GetFrmFmt().GetAnchor().GetAnchorId() )
867 : {
868 16 : return;
869 : }
870 :
871 74 : if ( !pSortedObjs )
872 : {
873 41 : pSortedObjs = new SwSortedObjs();
874 : }
875 74 : if ( !pSortedObjs->Insert( _rNewObj ) )
876 : {
877 : OSL_ENSURE( pSortedObjs->Contains( _rNewObj ),
878 : "Drawing object not appended into list <pSortedObjs>." );
879 : }
880 : // #i87493#
881 : OSL_ENSURE( _rNewObj.GetPageFrm() == 0 || _rNewObj.GetPageFrm() == this,
882 : "<SwPageFrm::AppendDrawObjToPage(..)> - anchored draw object seems to be registered at another page frame. Serious defect -> please inform OD." );
883 74 : _rNewObj.SetPageFrm( this );
884 :
885 : // invalidate page in order to force a reformat of object layout of the page.
886 74 : InvalidateFlyLayout();
887 : }
888 :
889 6 : void SwPageFrm::RemoveDrawObjFromPage( SwAnchoredObject& _rToRemoveObj )
890 : {
891 6 : if ( !_rToRemoveObj.ISA(SwAnchoredDrawObject) )
892 : {
893 : OSL_FAIL( "SwPageFrm::RemoveDrawObjFromPage(..) - anchored object of unexcepted type -> object not removed" );
894 6 : return;
895 : }
896 :
897 6 : if ( pSortedObjs )
898 : {
899 6 : pSortedObjs->Remove( _rToRemoveObj );
900 6 : if ( !pSortedObjs->Count() )
901 : {
902 4 : DELETEZ( pSortedObjs );
903 : }
904 6 : if ( GetUpper() )
905 : {
906 6 : if (FLY_AS_CHAR !=
907 6 : _rToRemoveObj.GetFrmFmt().GetAnchor().GetAnchorId())
908 : {
909 6 : ((SwRootFrm*)GetUpper())->SetSuperfluous();
910 6 : InvalidatePage();
911 : }
912 6 : ((SwRootFrm*)GetUpper())->InvalidateBrowseWidth();
913 : }
914 : }
915 6 : _rToRemoveObj.SetPageFrm( 0 );
916 : }
917 :
918 : /*************************************************************************
919 : |*
920 : |* SwPageFrm::PlaceFly
921 : |*
922 : |*************************************************************************/
923 :
924 : // #i50432# - adjust method description and synopsis.
925 0 : void SwPageFrm::PlaceFly( SwFlyFrm* pFly, SwFlyFrmFmt* pFmt )
926 : {
927 : // #i50432# - consider the case that page is an empty page:
928 : // In this case append the fly frame at the next page
929 : OSL_ENSURE( !IsEmptyPage() || GetNext(),
930 : "<SwPageFrm::PlaceFly(..)> - empty page with no next page! -> fly frame appended at empty page" );
931 0 : if ( IsEmptyPage() && GetNext() )
932 : {
933 0 : static_cast<SwPageFrm*>(GetNext())->PlaceFly( pFly, pFmt );
934 : }
935 : else
936 : {
937 : // If we received a Fly, we use that one. Otherwise, create a new
938 : // one using the Format.
939 0 : if ( pFly )
940 0 : AppendFly( pFly );
941 : else
942 : { OSL_ENSURE( pFmt, ":-( No Format given for Fly." );
943 0 : pFly = new SwFlyLayFrm( (SwFlyFrmFmt*)pFmt, this, this );
944 0 : AppendFly( pFly );
945 0 : ::RegistFlys( this, pFly );
946 : }
947 : }
948 0 : }
949 :
950 : /*************************************************************************
951 : |*
952 : |* ::CalcClipRect
953 : |*
954 : |*************************************************************************/
955 : // #i18732# - adjustments for following text flow or not
956 : // AND alignment at 'page areas' for to paragraph/to character anchored objects
957 : // #i22305# - adjustment for following text flow for to frame anchored objects
958 : // #i29778# - Because calculating the floating screen object's position
959 : // (Writer fly frame or drawing object) doesn't perform a calculation on its
960 : // upper frames and its anchor frame, a calculation of the upper frames in this
961 : // method is no longer sensible.
962 : // #i28701# - if document compatibility option 'Consider wrapping style influence
963 : // on object positioning' is ON, the clip area corresponds to the one as the
964 : // object doesn't follow the text flow.
965 196 : sal_Bool CalcClipRect( const SdrObject *pSdrObj, SwRect &rRect, sal_Bool bMove )
966 : {
967 196 : sal_Bool bRet = sal_True;
968 196 : if ( pSdrObj->ISA(SwVirtFlyDrawObj) )
969 : {
970 196 : const SwFlyFrm* pFly = ((const SwVirtFlyDrawObj*)pSdrObj)->GetFlyFrm();
971 196 : const bool bFollowTextFlow = pFly->GetFmt()->GetFollowTextFlow().GetValue();
972 : // #i28701#
973 : const bool bConsiderWrapOnObjPos =
974 196 : pFly->GetFmt()->getIDocumentSettingAccess()->get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION);
975 196 : const SwFmtVertOrient &rV = pFly->GetFmt()->GetVertOrient();
976 196 : if( pFly->IsFlyLayFrm() )
977 : {
978 : const SwFrm* pClip;
979 : // #i22305#
980 : // #i28701#
981 0 : if ( !bFollowTextFlow || bConsiderWrapOnObjPos )
982 : {
983 0 : pClip = pFly->GetAnchorFrm()->FindPageFrm();
984 : }
985 : else
986 : {
987 0 : pClip = pFly->GetAnchorFrm();
988 : }
989 :
990 0 : rRect = pClip->Frm();
991 0 : SWRECTFN( pClip )
992 :
993 : // vertical clipping: Top and Bottom, also to PrtArea if neccessary
994 0 : if( rV.GetVertOrient() != text::VertOrientation::NONE &&
995 0 : rV.GetRelationOrient() == text::RelOrientation::PRINT_AREA )
996 : {
997 0 : (rRect.*fnRect->fnSetTop)( (pClip->*fnRect->fnGetPrtTop)() );
998 0 : (rRect.*fnRect->fnSetBottom)( (pClip->*fnRect->fnGetPrtBottom)() );
999 : }
1000 : // horizontal clipping: Top and Bottom, also to PrtArea if necessary
1001 0 : const SwFmtHoriOrient &rH = pFly->GetFmt()->GetHoriOrient();
1002 0 : if( rH.GetHoriOrient() != text::HoriOrientation::NONE &&
1003 0 : rH.GetRelationOrient() == text::RelOrientation::PRINT_AREA )
1004 : {
1005 0 : (rRect.*fnRect->fnSetLeft)( (pClip->*fnRect->fnGetPrtLeft)() );
1006 0 : (rRect.*fnRect->fnSetRight)((pClip->*fnRect->fnGetPrtRight)());
1007 : }
1008 : }
1009 196 : else if( pFly->IsFlyAtCntFrm() )
1010 : {
1011 : // #i18732# - consider following text flow or not
1012 : // AND alignment at 'page areas'
1013 196 : const SwFrm* pVertPosOrientFrm = pFly->GetVertPosOrientFrm();
1014 196 : if ( !pVertPosOrientFrm )
1015 : {
1016 : OSL_FAIL( "::CalcClipRect(..) - frame, vertical position is oriented at, is missing .");
1017 0 : pVertPosOrientFrm = pFly->GetAnchorFrm();
1018 : }
1019 :
1020 196 : if ( !bFollowTextFlow || bConsiderWrapOnObjPos )
1021 : {
1022 196 : const SwLayoutFrm* pClipFrm = pVertPosOrientFrm->FindPageFrm();
1023 196 : if (!pClipFrm)
1024 : {
1025 : OSL_FAIL("!pClipFrm: "
1026 : "if you can reproduce this please file a bug");
1027 0 : return false;
1028 : }
1029 98 : rRect = bMove ? pClipFrm->GetUpper()->Frm()
1030 294 : : pClipFrm->Frm();
1031 : // #i26945# - consider that a table, during
1032 : // its format, can exceed its upper printing area bottom.
1033 : // Thus, enlarge the clip rectangle, if such a case occurred
1034 196 : if ( pFly->GetAnchorFrm()->IsInTab() )
1035 : {
1036 : const SwTabFrm* pTabFrm = const_cast<SwFlyFrm*>(pFly)
1037 0 : ->GetAnchorFrmContainingAnchPos()->FindTabFrm();
1038 0 : SwRect aTmp( pTabFrm->Prt() );
1039 0 : aTmp += pTabFrm->Frm().Pos();
1040 0 : rRect.Union( aTmp );
1041 : // #i43913# - consider also the cell frame
1042 : const SwFrm* pCellFrm = const_cast<SwFlyFrm*>(pFly)
1043 0 : ->GetAnchorFrmContainingAnchPos()->GetUpper();
1044 0 : while ( pCellFrm && !pCellFrm->IsCellFrm() )
1045 : {
1046 0 : pCellFrm = pCellFrm->GetUpper();
1047 : }
1048 0 : if ( pCellFrm )
1049 : {
1050 0 : aTmp = pCellFrm->Prt();
1051 0 : aTmp += pCellFrm->Frm().Pos();
1052 0 : rRect.Union( aTmp );
1053 : }
1054 196 : }
1055 : }
1056 0 : else if ( rV.GetRelationOrient() == text::RelOrientation::PAGE_FRAME ||
1057 0 : rV.GetRelationOrient() == text::RelOrientation::PAGE_PRINT_AREA )
1058 : {
1059 : // new class <SwEnvironmentOfAnchoredObject>
1060 : objectpositioning::SwEnvironmentOfAnchoredObject
1061 0 : aEnvOfObj( bFollowTextFlow );
1062 : const SwLayoutFrm& rVertClipFrm =
1063 0 : aEnvOfObj.GetVertEnvironmentLayoutFrm( *pVertPosOrientFrm );
1064 0 : if ( rV.GetRelationOrient() == text::RelOrientation::PAGE_FRAME )
1065 : {
1066 0 : rRect = rVertClipFrm.Frm();
1067 : }
1068 0 : else if ( rV.GetRelationOrient() == text::RelOrientation::PAGE_PRINT_AREA )
1069 : {
1070 0 : if ( rVertClipFrm.IsPageFrm() )
1071 : {
1072 0 : rRect = static_cast<const SwPageFrm&>(rVertClipFrm).PrtWithoutHeaderAndFooter();
1073 : }
1074 : else
1075 : {
1076 0 : rRect = rVertClipFrm.Frm();
1077 : }
1078 : }
1079 : const SwLayoutFrm* pHoriClipFrm =
1080 0 : pFly->GetAnchorFrm()->FindPageFrm()->GetUpper();
1081 0 : SWRECTFN( pFly->GetAnchorFrm() )
1082 0 : (rRect.*fnRect->fnSetLeft)( (pHoriClipFrm->Frm().*fnRect->fnGetLeft)() );
1083 0 : (rRect.*fnRect->fnSetRight)((pHoriClipFrm->Frm().*fnRect->fnGetRight)());
1084 : }
1085 : else
1086 : {
1087 : // #i26945#
1088 : const SwFrm *pClip =
1089 0 : const_cast<SwFlyFrm*>(pFly)->GetAnchorFrmContainingAnchPos();
1090 0 : SWRECTFN( pClip )
1091 0 : const SwLayoutFrm *pUp = pClip->GetUpper();
1092 0 : const SwFrm *pCell = pUp->IsCellFrm() ? pUp : 0;
1093 : sal_uInt16 nType = bMove ? FRM_ROOT | FRM_FLY | FRM_HEADER |
1094 : FRM_FOOTER | FRM_FTN
1095 : : FRM_BODY | FRM_FLY | FRM_HEADER |
1096 0 : FRM_FOOTER | FRM_CELL| FRM_FTN;
1097 :
1098 0 : while ( !(pUp->GetType() & nType) || pUp->IsColBodyFrm() )
1099 : {
1100 0 : pUp = pUp->GetUpper();
1101 0 : if ( !pCell && pUp->IsCellFrm() )
1102 0 : pCell = pUp;
1103 : }
1104 0 : if ( bMove )
1105 : {
1106 0 : if ( pUp->IsRootFrm() )
1107 : {
1108 0 : rRect = pUp->Prt();
1109 0 : rRect += pUp->Frm().Pos();
1110 0 : pUp = 0;
1111 : }
1112 : }
1113 0 : if ( pUp )
1114 : {
1115 0 : if ( pUp->GetType() & FRM_BODY )
1116 : {
1117 : const SwPageFrm *pPg;
1118 0 : if ( pUp->GetUpper() != (pPg = pFly->FindPageFrm()) )
1119 0 : pUp = pPg->FindBodyCont();
1120 0 : rRect = pUp->GetUpper()->Frm();
1121 0 : (rRect.*fnRect->fnSetTop)( (pUp->*fnRect->fnGetPrtTop)() );
1122 0 : (rRect.*fnRect->fnSetBottom)((pUp->*fnRect->fnGetPrtBottom)());
1123 : }
1124 : else
1125 : {
1126 0 : if( ( pUp->GetType() & (FRM_FLY | FRM_FTN ) ) &&
1127 0 : !pUp->Frm().IsInside( pFly->Frm().Pos() ) )
1128 : {
1129 0 : if( pUp->IsFlyFrm() )
1130 : {
1131 0 : SwFlyFrm *pTmpFly = (SwFlyFrm*)pUp;
1132 0 : while( pTmpFly->GetNextLink() )
1133 : {
1134 0 : pTmpFly = pTmpFly->GetNextLink();
1135 0 : if( pTmpFly->Frm().IsInside( pFly->Frm().Pos() ) )
1136 0 : break;
1137 : }
1138 0 : pUp = pTmpFly;
1139 : }
1140 0 : else if( pUp->IsInFtn() )
1141 : {
1142 0 : const SwFtnFrm *pTmp = pUp->FindFtnFrm();
1143 0 : while( pTmp->GetFollow() )
1144 : {
1145 0 : pTmp = pTmp->GetFollow();
1146 0 : if( pTmp->Frm().IsInside( pFly->Frm().Pos() ) )
1147 0 : break;
1148 : }
1149 0 : pUp = pTmp;
1150 : }
1151 : }
1152 0 : rRect = pUp->Prt();
1153 0 : rRect.Pos() += pUp->Frm().Pos();
1154 0 : if ( pUp->GetType() & (FRM_HEADER | FRM_FOOTER) )
1155 : {
1156 0 : rRect.Left ( pUp->GetUpper()->Frm().Left() );
1157 0 : rRect.Width( pUp->GetUpper()->Frm().Width());
1158 : }
1159 0 : else if ( pUp->IsCellFrm() ) //MA_FLY_HEIGHT
1160 : {
1161 0 : const SwFrm *pTab = pUp->FindTabFrm();
1162 : (rRect.*fnRect->fnSetBottom)(
1163 0 : (pTab->GetUpper()->*fnRect->fnGetPrtBottom)() );
1164 : // expand to left and right cell border
1165 0 : rRect.Left ( pUp->Frm().Left() );
1166 0 : rRect.Width( pUp->Frm().Width() );
1167 : }
1168 : }
1169 : }
1170 0 : if ( pCell )
1171 : {
1172 : // CellFrms might also sit in unallowed areas. In this case,
1173 : // the Fly is allowed to do so as well
1174 0 : SwRect aTmp( pCell->Prt() );
1175 0 : aTmp += pCell->Frm().Pos();
1176 0 : rRect.Union( aTmp );
1177 : }
1178 : }
1179 : }
1180 : else
1181 : {
1182 0 : const SwFrm *pUp = pFly->GetAnchorFrm()->GetUpper();
1183 0 : SWRECTFN( pFly->GetAnchorFrm() )
1184 0 : while( pUp->IsColumnFrm() || pUp->IsSctFrm() || pUp->IsColBodyFrm())
1185 0 : pUp = pUp->GetUpper();
1186 0 : rRect = pUp->Frm();
1187 0 : if( !pUp->IsBodyFrm() )
1188 : {
1189 0 : rRect += pUp->Prt().Pos();
1190 0 : rRect.SSize( pUp->Prt().SSize() );
1191 0 : if ( pUp->IsCellFrm() )
1192 : {
1193 0 : const SwFrm *pTab = pUp->FindTabFrm();
1194 : (rRect.*fnRect->fnSetBottom)(
1195 0 : (pTab->GetUpper()->*fnRect->fnGetPrtBottom)() );
1196 : }
1197 : }
1198 0 : else if ( pUp->GetUpper()->IsPageFrm() )
1199 : {
1200 : // Objects anchored as character may exceed right margin
1201 : // of body frame:
1202 0 : (rRect.*fnRect->fnSetRight)( (pUp->GetUpper()->Frm().*fnRect->fnGetRight)() );
1203 : }
1204 0 : long nHeight = (9*(rRect.*fnRect->fnGetHeight)())/10;
1205 : long nTop;
1206 0 : const SwFmt *pFmt = ((SwContact*)GetUserCall(pSdrObj))->GetFmt();
1207 0 : const SvxULSpaceItem &rUL = pFmt->GetULSpace();
1208 0 : if( bMove )
1209 : {
1210 0 : nTop = bVert ? ((SwFlyInCntFrm*)pFly)->GetRefPoint().X() :
1211 0 : ((SwFlyInCntFrm*)pFly)->GetRefPoint().Y();
1212 0 : nTop = (*fnRect->fnYInc)( nTop, -nHeight );
1213 0 : long nWidth = (pFly->Frm().*fnRect->fnGetWidth)();
1214 : (rRect.*fnRect->fnSetLeftAndWidth)( bVert ?
1215 0 : ((SwFlyInCntFrm*)pFly)->GetRefPoint().Y() :
1216 0 : ((SwFlyInCntFrm*)pFly)->GetRefPoint().X(), nWidth );
1217 0 : nHeight = 2*nHeight - rUL.GetLower() - rUL.GetUpper();
1218 : }
1219 : else
1220 : {
1221 0 : nTop = (*fnRect->fnYInc)( (pFly->Frm().*fnRect->fnGetBottom)(),
1222 0 : rUL.GetLower() - nHeight );
1223 0 : nHeight = 2*nHeight - (pFly->Frm().*fnRect->fnGetHeight)()
1224 0 : - rUL.GetLower() - rUL.GetUpper();
1225 : }
1226 0 : (rRect.*fnRect->fnSetTopAndHeight)( nTop, nHeight );
1227 : }
1228 : }
1229 : else
1230 : {
1231 0 : const SwDrawContact *pC = (const SwDrawContact*)GetUserCall(pSdrObj);
1232 0 : const SwFrmFmt *pFmt = (const SwFrmFmt*)pC->GetFmt();
1233 0 : const SwFmtAnchor &rAnch = pFmt->GetAnchor();
1234 0 : if ( FLY_AS_CHAR == rAnch.GetAnchorId() )
1235 : {
1236 0 : const SwFrm* pAnchorFrm = pC->GetAnchorFrm( pSdrObj );
1237 0 : if( !pAnchorFrm )
1238 : {
1239 : OSL_FAIL( "<::CalcClipRect(..)> - missing anchor frame." );
1240 0 : ((SwDrawContact*)pC)->ConnectToLayout();
1241 0 : pAnchorFrm = pC->GetAnchorFrm();
1242 : }
1243 0 : const SwFrm* pUp = pAnchorFrm->GetUpper();
1244 0 : rRect = pUp->Prt();
1245 0 : rRect += pUp->Frm().Pos();
1246 0 : SWRECTFN( pAnchorFrm )
1247 0 : long nHeight = (9*(rRect.*fnRect->fnGetHeight)())/10;
1248 : long nTop;
1249 0 : const SvxULSpaceItem &rUL = pFmt->GetULSpace();
1250 0 : SwRect aSnapRect( pSdrObj->GetSnapRect() );
1251 0 : long nTmpH = 0;
1252 0 : if( bMove )
1253 : {
1254 0 : nTop = (*fnRect->fnYInc)( bVert ? pSdrObj->GetAnchorPos().X() :
1255 0 : pSdrObj->GetAnchorPos().Y(), -nHeight );
1256 0 : long nWidth = (aSnapRect.*fnRect->fnGetWidth)();
1257 : (rRect.*fnRect->fnSetLeftAndWidth)( bVert ?
1258 0 : pSdrObj->GetAnchorPos().Y() :
1259 0 : pSdrObj->GetAnchorPos().X(), nWidth );
1260 : }
1261 : else
1262 : {
1263 : // #i26791# - value of <nTmpH> is needed to
1264 : // calculate value of <nTop>.
1265 0 : nTmpH = bVert ? pSdrObj->GetCurrentBoundRect().GetWidth() :
1266 0 : pSdrObj->GetCurrentBoundRect().GetHeight();
1267 0 : nTop = (*fnRect->fnYInc)( (aSnapRect.*fnRect->fnGetTop)(),
1268 0 : rUL.GetLower() + nTmpH - nHeight );
1269 : }
1270 0 : nHeight = 2*nHeight - nTmpH - rUL.GetLower() - rUL.GetUpper();
1271 0 : (rRect.*fnRect->fnSetTopAndHeight)( nTop, nHeight );
1272 : }
1273 : else
1274 : {
1275 : // restrict clip rectangle for drawing
1276 : // objects in header/footer to the page frame.
1277 : // #i26791#
1278 0 : const SwFrm* pAnchorFrm = pC->GetAnchorFrm( pSdrObj );
1279 0 : if ( pAnchorFrm && pAnchorFrm->FindFooterOrHeader() )
1280 : {
1281 : // clip frame is the page frame the header/footer is on.
1282 0 : const SwFrm* pClipFrm = pAnchorFrm->FindPageFrm();
1283 0 : rRect = pClipFrm->Frm();
1284 : }
1285 : else
1286 : {
1287 0 : bRet = sal_False;
1288 : }
1289 : }
1290 : }
1291 196 : return bRet;
1292 : }
1293 :
1294 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|