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 <dcontact.hxx>
21 : #include <rootfrm.hxx>
22 : #include <pagefrm.hxx>
23 : #include <tocntntanchoredobjectposition.hxx>
24 : #include <tolayoutanchoredobjectposition.hxx>
25 : #include <frmtool.hxx>
26 : #include <fmtornt.hxx>
27 : // --> #i32795#
28 : #include <txtfrm.hxx>
29 : // --> #i32795#
30 : #include <vector>
31 : #include <svx/svdogrp.hxx>
32 :
33 : using namespace ::com::sun::star;
34 :
35 : /// helper class for correct notification due to the positioning of
36 : /// the anchored drawing object
37 : class SwPosNotify
38 : {
39 : private:
40 : SwAnchoredDrawObject* mpAnchoredDrawObj;
41 : SwRect maOldObjRect;
42 : SwPageFrm* mpOldPageFrm;
43 :
44 : public:
45 : SwPosNotify( SwAnchoredDrawObject* _pAnchoredDrawObj );
46 : ~SwPosNotify();
47 : // #i32795#
48 : Point LastObjPos() const;
49 : };
50 :
51 0 : SwPosNotify::SwPosNotify( SwAnchoredDrawObject* _pAnchoredDrawObj ) :
52 0 : mpAnchoredDrawObj( _pAnchoredDrawObj )
53 : {
54 0 : maOldObjRect = mpAnchoredDrawObj->GetObjRect();
55 : // --> #i35640# - determine correct page frame
56 0 : mpOldPageFrm = mpAnchoredDrawObj->GetPageFrm();
57 0 : }
58 :
59 0 : SwPosNotify::~SwPosNotify()
60 : {
61 0 : if ( maOldObjRect != mpAnchoredDrawObj->GetObjRect() )
62 : {
63 0 : if( maOldObjRect.HasArea() && mpOldPageFrm )
64 : {
65 : mpAnchoredDrawObj->NotifyBackground( mpOldPageFrm, maOldObjRect,
66 0 : PREP_FLY_LEAVE );
67 : }
68 0 : SwRect aNewObjRect( mpAnchoredDrawObj->GetObjRect() );
69 0 : if( aNewObjRect.HasArea() )
70 : {
71 : // --> #i35640# - determine correct page frame
72 0 : SwPageFrm* pNewPageFrm = mpAnchoredDrawObj->GetPageFrm();
73 0 : if( pNewPageFrm )
74 : mpAnchoredDrawObj->NotifyBackground( pNewPageFrm, aNewObjRect,
75 0 : PREP_FLY_ARRIVE );
76 : }
77 :
78 0 : ::ClrContourCache( mpAnchoredDrawObj->GetDrawObj() );
79 :
80 : // --> #i35640# - additional notify anchor text frame
81 : // Needed for negative positioned drawing objects
82 : // --> #i43255# - refine condition to avoid unneeded
83 : // invalidations: anchored object had to be on the page of its anchor
84 : // text frame.
85 0 : if ( mpAnchoredDrawObj->GetAnchorFrm()->IsTxtFrm() &&
86 0 : mpOldPageFrm == mpAnchoredDrawObj->GetAnchorFrm()->FindPageFrm() )
87 : {
88 0 : mpAnchoredDrawObj->AnchorFrm()->Prepare( PREP_FLY_LEAVE );
89 : }
90 :
91 : // indicate a restart of the layout process
92 0 : mpAnchoredDrawObj->SetRestartLayoutProcess( true );
93 : }
94 : else
95 : {
96 : // lock position
97 0 : mpAnchoredDrawObj->LockPosition();
98 :
99 0 : if ( !mpAnchoredDrawObj->ConsiderForTextWrap() )
100 : {
101 : // indicate that object has to be considered for text wrap
102 0 : mpAnchoredDrawObj->SetConsiderForTextWrap( true );
103 : // invalidate 'background' in order to allow its 'background'
104 : // to wrap around it.
105 : mpAnchoredDrawObj->NotifyBackground( mpAnchoredDrawObj->GetPageFrm(),
106 0 : mpAnchoredDrawObj->GetObjRectWithSpaces(),
107 0 : PREP_FLY_ARRIVE );
108 : // invalidate position of anchor frame in order to force
109 : // a re-format of the anchor frame, which also causes a
110 : // re-format of the invalid previous frames of the anchor frame.
111 0 : mpAnchoredDrawObj->AnchorFrm()->InvalidatePos();
112 : }
113 : }
114 0 : }
115 :
116 : // --> #i32795#
117 0 : Point SwPosNotify::LastObjPos() const
118 : {
119 0 : return maOldObjRect.Pos();
120 : }
121 :
122 : // #i32795#
123 : /// helper class for oscillation control on object positioning
124 : class SwObjPosOscillationControl
125 : {
126 : private:
127 : sal_uInt8 mnPosStackSize;
128 :
129 : const SwAnchoredDrawObject* mpAnchoredDrawObj;
130 :
131 : std::vector<Point*> maObjPositions;
132 :
133 : public:
134 : SwObjPosOscillationControl( const SwAnchoredDrawObject& _rAnchoredDrawObj );
135 : ~SwObjPosOscillationControl();
136 :
137 : bool OscillationDetected();
138 : };
139 :
140 0 : SwObjPosOscillationControl::SwObjPosOscillationControl(
141 : const SwAnchoredDrawObject& _rAnchoredDrawObj )
142 : : mnPosStackSize( 20 ),
143 0 : mpAnchoredDrawObj( &_rAnchoredDrawObj )
144 : {
145 0 : }
146 :
147 0 : SwObjPosOscillationControl::~SwObjPosOscillationControl()
148 : {
149 0 : while ( !maObjPositions.empty() )
150 : {
151 0 : Point* pPos = maObjPositions.back();
152 0 : delete pPos;
153 :
154 0 : maObjPositions.pop_back();
155 : }
156 0 : }
157 :
158 0 : bool SwObjPosOscillationControl::OscillationDetected()
159 : {
160 0 : bool bOscillationDetected = false;
161 :
162 0 : if ( maObjPositions.size() == mnPosStackSize )
163 : {
164 : // position stack is full -> oscillation
165 0 : bOscillationDetected = true;
166 : }
167 : else
168 : {
169 0 : Point* pNewObjPos = new Point( mpAnchoredDrawObj->GetObjRect().Pos() );
170 0 : for ( std::vector<Point*>::iterator aObjPosIter = maObjPositions.begin();
171 0 : aObjPosIter != maObjPositions.end();
172 : ++aObjPosIter )
173 : {
174 0 : if ( *(pNewObjPos) == *(*aObjPosIter) )
175 : {
176 : // position already occurred -> oscillation
177 0 : bOscillationDetected = true;
178 0 : delete pNewObjPos;
179 0 : break;
180 : }
181 : }
182 0 : if ( !bOscillationDetected )
183 : {
184 0 : maObjPositions.push_back( pNewObjPos );
185 : }
186 : }
187 :
188 0 : return bOscillationDetected;
189 : }
190 :
191 : // class <SwAnchoredDrawObject>
192 :
193 0 : TYPEINIT1(SwAnchoredDrawObject,SwAnchoredObject);
194 :
195 0 : SwAnchoredDrawObject::SwAnchoredDrawObject() :
196 : SwAnchoredObject(),
197 : mbValidPos( false ),
198 : // --> #i34748#
199 : mpLastObjRect( 0L ),
200 : mbNotYetAttachedToAnchorFrame( true ),
201 : // --> #i28749#
202 : mbNotYetPositioned( true ),
203 : // --> #i62875#
204 0 : mbCaptureAfterLayoutDirChange( false )
205 : {
206 0 : }
207 :
208 0 : SwAnchoredDrawObject::~SwAnchoredDrawObject()
209 : {
210 : // #i34748#
211 0 : delete mpLastObjRect;
212 0 : }
213 :
214 : // --> #i62875#
215 0 : void SwAnchoredDrawObject::UpdateLayoutDir()
216 : {
217 0 : SwFrmFmt::tLayoutDir nOldLayoutDir( GetFrmFmt().GetLayoutDir() );
218 :
219 0 : SwAnchoredObject::UpdateLayoutDir();
220 :
221 0 : if ( !NotYetPositioned() &&
222 0 : GetFrmFmt().GetLayoutDir() != nOldLayoutDir &&
223 0 : GetFrmFmt().GetDoc()->get(IDocumentSettingAccess::DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE) &&
224 0 : !IsOutsidePage() )
225 : {
226 0 : mbCaptureAfterLayoutDirChange = true;
227 : }
228 0 : }
229 :
230 : // --> #i62875#
231 0 : bool SwAnchoredDrawObject::IsOutsidePage() const
232 : {
233 0 : bool bOutsidePage( false );
234 :
235 0 : if ( !NotYetPositioned() && GetPageFrm() )
236 : {
237 0 : SwRect aTmpRect( GetObjRect() );
238 : bOutsidePage =
239 0 : ( aTmpRect.Intersection( GetPageFrm()->Frm() ) != GetObjRect() );
240 : }
241 :
242 0 : return bOutsidePage;
243 : }
244 :
245 0 : void SwAnchoredDrawObject::MakeObjPos()
246 : {
247 0 : if ( IsPositioningInProgress() )
248 : {
249 : // nothind to do - positioning already in progress
250 0 : return;
251 : }
252 :
253 0 : if ( mbValidPos )
254 : {
255 : // nothing to do - position is valid
256 0 : return;
257 : }
258 :
259 : // --> #i28749# - anchored drawing object has to be attached
260 : // to anchor frame
261 0 : if ( mbNotYetAttachedToAnchorFrame )
262 : {
263 : OSL_FAIL( "<SwAnchoredDrawObject::MakeObjPos() - drawing object not yet attached to anchor frame -> no positioning" );
264 0 : return;
265 : }
266 :
267 : SwDrawContact* pDrawContact =
268 0 : static_cast<SwDrawContact*>(::GetUserCall( GetDrawObj() ));
269 :
270 : // --> #i28749# - if anchored drawing object hasn't been yet
271 : // positioned, convert its positioning attributes, if its positioning
272 : // attributes are given in horizontal left-to-right layout.
273 : // --> #i36010# - Note: horizontal left-to-right layout is made
274 : // the default layout direction for <SwDrawFrmFmt> instances. Thus, it has
275 : // to be adjusted manually, if no adjustment of the positioning attributes
276 : // have to be performed here.
277 : // --> #i35635# - additionally move drawing object to the visible layer.
278 0 : if ( mbNotYetPositioned )
279 : {
280 : // --> #i35635#
281 0 : pDrawContact->MoveObjToVisibleLayer( DrawObj() );
282 : // --> perform conversion of positioning
283 : // attributes only for 'master' drawing objects
284 : // #i44334#, #i44681# - check, if positioning
285 : // attributes already have been set.
286 0 : if ( !GetDrawObj()->ISA(SwDrawVirtObj) &&
287 0 : !static_cast<SwDrawFrmFmt&>(GetFrmFmt()).IsPosAttrSet() )
288 : {
289 0 : _SetPositioningAttr();
290 : }
291 : // -->
292 : // - reset internal flag after all needed actions are performed to
293 : // avoid callbacks from drawing layer
294 0 : mbNotYetPositioned = false;
295 : }
296 :
297 : // indicate that positioning is in progress
298 : {
299 0 : SwObjPositioningInProgress aObjPosInProgress( *this );
300 :
301 : // determine relative position of drawing object and set it
302 0 : switch ( pDrawContact->GetAnchorId() )
303 : {
304 : case FLY_AS_CHAR:
305 : {
306 : // indicate that position will be valid after positioning is performed
307 0 : mbValidPos = true;
308 : // nothing to do, because as-character anchored objects are positioned
309 : // during the format of its anchor frame - see <SwFlyCntPortion::SetBase(..)>
310 : }
311 0 : break;
312 : case FLY_AT_PARA:
313 : case FLY_AT_CHAR:
314 : {
315 : // --> #i32795# - move intrinsic positioning to
316 : // helper method <_MakeObjPosAnchoredAtPara()>
317 0 : _MakeObjPosAnchoredAtPara();
318 : }
319 0 : break;
320 : case FLY_AT_PAGE:
321 : case FLY_AT_FLY:
322 : {
323 : // --> #i32795# - move intrinsic positioning to
324 : // helper method <_MakeObjPosAnchoredAtLayout()>
325 0 : _MakeObjPosAnchoredAtLayout();
326 : }
327 0 : break;
328 : default:
329 : {
330 : OSL_FAIL( "<SwAnchoredDrawObject::MakeObjPos()> - unknown anchor type - please inform OD." );
331 : }
332 : }
333 :
334 : // keep, current object rectangle
335 : // --> #i34748# - use new method <SetLastObjRect(..)>
336 0 : SetLastObjRect( GetObjRect().SVRect() );
337 :
338 : // Assure for 'master' drawing object, that it's registered at the correct page.
339 : // Perform check not for as-character anchored drawing objects and only if
340 : // the anchor frame is valid.
341 0 : if ( !GetDrawObj()->ISA(SwDrawVirtObj) &&
342 0 : !pDrawContact->ObjAnchoredAsChar() &&
343 0 : GetAnchorFrm()->IsValid() )
344 : {
345 0 : pDrawContact->ChkPage();
346 0 : }
347 : }
348 :
349 : // --> #i62875#
350 0 : if ( mbCaptureAfterLayoutDirChange &&
351 0 : GetPageFrm() )
352 : {
353 0 : SwRect aPageRect( GetPageFrm()->Frm() );
354 0 : SwRect aObjRect( GetObjRect() );
355 0 : if ( aObjRect.Right() >= aPageRect.Right() + 10 )
356 : {
357 0 : Size aSize( aPageRect.Right() - aObjRect.Right(), 0 );
358 0 : DrawObj()->Move( aSize );
359 0 : aObjRect = GetObjRect();
360 : }
361 :
362 0 : if ( aObjRect.Left() + 10 <= aPageRect.Left() )
363 : {
364 0 : Size aSize( aPageRect.Left() - aObjRect.Left(), 0 );
365 0 : DrawObj()->Move( aSize );
366 : }
367 :
368 0 : mbCaptureAfterLayoutDirChange = false;
369 : }
370 : }
371 :
372 : /** method for the intrinsic positioning of a at-paragraph|at-character
373 : anchored drawing object
374 :
375 : #i32795# - helper method for method <MakeObjPos>
376 : */
377 0 : void SwAnchoredDrawObject::_MakeObjPosAnchoredAtPara()
378 : {
379 : // --> #i32795# - adopt positioning algorithm from Writer
380 : // fly frames, which are anchored at paragraph|at character
381 :
382 : // Determine, if anchor frame can/has to be formatted.
383 : // If yes, after each object positioning the anchor frame is formatted.
384 : // If after the anchor frame format the object position isn't valid, the
385 : // object is positioned again.
386 : // --> #i43255# - refine condition: anchor frame format not
387 : // allowed, if another anchored object, has to be consider its wrap influence
388 : // --> #i50356# - format anchor frame containing the anchor
389 : // position. E.g., for at-character anchored object this can be the follow
390 : // frame of the anchor frame, which contains the anchor character.
391 : const bool bFormatAnchor =
392 0 : !static_cast<const SwTxtFrm*>( GetAnchorFrmContainingAnchPos() )->IsAnyJoinLocked() &&
393 0 : !ConsiderObjWrapInfluenceOnObjPos() &&
394 0 : !ConsiderObjWrapInfluenceOfOtherObjs();
395 :
396 0 : if ( bFormatAnchor )
397 : {
398 : // --> #i50356#
399 0 : GetAnchorFrmContainingAnchPos()->Calc();
400 : }
401 :
402 0 : bool bOscillationDetected = false;
403 0 : SwObjPosOscillationControl aObjPosOscCtrl( *this );
404 : // --> #i3317# - boolean, to apply temporarly the
405 : // 'straightforward positioning process' for the frame due to its
406 : // overlapping with a previous column.
407 0 : bool bConsiderWrapInfluenceDueToOverlapPrevCol( false );
408 0 : do {
409 : // indicate that position will be valid after positioning is performed
410 0 : mbValidPos = true;
411 :
412 : // --> #i35640# - correct scope for <SwPosNotify> instance
413 : {
414 : // create instance of <SwPosNotify> for correct notification
415 0 : SwPosNotify aPosNotify( this );
416 :
417 : // determine and set position
418 : objectpositioning::SwToCntntAnchoredObjectPosition
419 0 : aObjPositioning( *DrawObj() );
420 0 : aObjPositioning.CalcPosition();
421 :
422 : // get further needed results of the positioning algorithm
423 0 : SetVertPosOrientFrm ( aObjPositioning.GetVertPosOrientFrm() );
424 0 : _SetDrawObjAnchor();
425 :
426 : // check for object position oscillation, if position has changed.
427 0 : if ( GetObjRect().Pos() != aPosNotify.LastObjPos() )
428 : {
429 0 : bOscillationDetected = aObjPosOscCtrl.OscillationDetected();
430 0 : }
431 : }
432 : // format anchor frame, if requested.
433 : // Note: the format of the anchor frame can cause the object position
434 : // to be invalid.
435 0 : if ( bFormatAnchor )
436 : {
437 : // --> #i50356#
438 0 : GetAnchorFrmContainingAnchPos()->Calc();
439 : }
440 :
441 : // --> #i3317#
442 0 : if ( !ConsiderObjWrapInfluenceOnObjPos() &&
443 0 : OverlapsPrevColumn() )
444 : {
445 0 : bConsiderWrapInfluenceDueToOverlapPrevCol = true;
446 : }
447 0 : } while ( !mbValidPos && !bOscillationDetected &&
448 0 : !bConsiderWrapInfluenceDueToOverlapPrevCol );
449 :
450 : // --> #i3317# - consider a detected oscillation and overlapping
451 : // with previous column.
452 : // temporarly consider the anchored objects wrapping style influence
453 0 : if ( bOscillationDetected || bConsiderWrapInfluenceDueToOverlapPrevCol )
454 : {
455 0 : SetTmpConsiderWrapInfluence( true );
456 0 : SetRestartLayoutProcess( true );
457 0 : }
458 0 : }
459 :
460 : /** method for the intrinsic positioning of a at-page|at-frame anchored
461 : drawing object
462 :
463 : #i32795# - helper method for method <MakeObjPos>
464 : */
465 0 : void SwAnchoredDrawObject::_MakeObjPosAnchoredAtLayout()
466 : {
467 : // indicate that position will be valid after positioning is performed
468 0 : mbValidPos = true;
469 :
470 : // create instance of <SwPosNotify> for correct notification
471 0 : SwPosNotify aPosNotify( this );
472 :
473 : // determine position
474 : objectpositioning::SwToLayoutAnchoredObjectPosition
475 0 : aObjPositioning( *DrawObj() );
476 0 : aObjPositioning.CalcPosition();
477 :
478 : // set position
479 :
480 : // --> #i31698#
481 : // --> #i34995# - setting anchor position needed for filters,
482 : // especially for the xml-filter to the OpenOffice.org file format
483 : {
484 : const Point aNewAnchorPos =
485 0 : GetAnchorFrm()->GetFrmAnchorPos( ::HasWrap( GetDrawObj() ) );
486 0 : DrawObj()->SetAnchorPos( aNewAnchorPos );
487 : // --> #i70122# - missing invalidation
488 0 : InvalidateObjRectWithSpaces();
489 : }
490 0 : SetCurrRelPos( aObjPositioning.GetRelPos() );
491 0 : const SwFrm* pAnchorFrm = GetAnchorFrm();
492 0 : SWRECTFN( pAnchorFrm );
493 0 : const Point aAnchPos( (pAnchorFrm->Frm().*fnRect->fnGetPos)() );
494 0 : SetObjLeft( aAnchPos.X() + GetCurrRelPos().X() );
495 0 : SetObjTop( aAnchPos.Y() + GetCurrRelPos().Y() );
496 0 : }
497 :
498 0 : void SwAnchoredDrawObject::_SetDrawObjAnchor()
499 : {
500 : // new anchor position
501 : // --> #i31698# -
502 : Point aNewAnchorPos =
503 0 : GetAnchorFrm()->GetFrmAnchorPos( ::HasWrap( GetDrawObj() ) );
504 0 : Point aCurrAnchorPos = GetDrawObj()->GetAnchorPos();
505 0 : if ( aNewAnchorPos != aCurrAnchorPos )
506 : {
507 : // determine movement to be applied after setting the new anchor position
508 0 : Size aMove( aCurrAnchorPos.getX() - aNewAnchorPos.getX(),
509 0 : aCurrAnchorPos.getY() - aNewAnchorPos.getY() );
510 : // set new anchor position
511 0 : DrawObj()->SetAnchorPos( aNewAnchorPos );
512 : // correct object position, caused by setting new anchor position
513 0 : DrawObj()->Move( aMove );
514 : // --> #i70122# - missing invalidation
515 0 : InvalidateObjRectWithSpaces();
516 : }
517 0 : }
518 :
519 : /** method to invalidate the given page frame
520 :
521 : #i28701#
522 : */
523 0 : void SwAnchoredDrawObject::_InvalidatePage( SwPageFrm* _pPageFrm )
524 : {
525 0 : if ( _pPageFrm && !_pPageFrm->GetFmt()->GetDoc()->IsInDtor() )
526 : {
527 0 : if ( _pPageFrm->GetUpper() )
528 : {
529 : // --> #i35007# - correct invalidation for as-character
530 : // anchored objects.
531 0 : if ( GetFrmFmt().GetAnchor().GetAnchorId() == FLY_AS_CHAR )
532 : {
533 0 : _pPageFrm->InvalidateFlyInCnt();
534 : }
535 : else
536 : {
537 0 : _pPageFrm->InvalidateFlyLayout();
538 : }
539 :
540 0 : SwRootFrm* pRootFrm = static_cast<SwRootFrm*>(_pPageFrm->GetUpper());
541 0 : pRootFrm->DisallowTurbo();
542 0 : if ( pRootFrm->GetTurbo() )
543 : {
544 0 : const SwCntntFrm* pTmpFrm = pRootFrm->GetTurbo();
545 0 : pRootFrm->ResetTurbo();
546 0 : pTmpFrm->InvalidatePage();
547 : }
548 0 : pRootFrm->SetIdleFlags();
549 : }
550 : }
551 0 : }
552 :
553 0 : void SwAnchoredDrawObject::InvalidateObjPos()
554 : {
555 : // --> #i28701# - check, if invalidation is allowed
556 0 : if ( mbValidPos &&
557 0 : InvalidationOfPosAllowed() )
558 : {
559 0 : mbValidPos = false;
560 : // --> #i68520#
561 0 : InvalidateObjRectWithSpaces();
562 :
563 : // --> #i44339# - check, if anchor frame exists.
564 0 : if ( GetAnchorFrm() )
565 : {
566 : // --> #118547# - notify anchor frame of as-character
567 : // anchored object, because its positioned by the format of its anchor frame.
568 : // --> #i44559# - assure, that text hint is already
569 : // existing in the text frame
570 0 : if ( GetAnchorFrm()->ISA(SwTxtFrm) &&
571 0 : (GetFrmFmt().GetAnchor().GetAnchorId() == FLY_AS_CHAR) )
572 : {
573 0 : SwTxtFrm* pAnchorTxtFrm( static_cast<SwTxtFrm*>(AnchorFrm()) );
574 0 : if ( pAnchorTxtFrm->GetTxtNode()->GetpSwpHints() &&
575 0 : pAnchorTxtFrm->CalcFlyPos( &GetFrmFmt() ) != COMPLETE_STRING )
576 : {
577 0 : AnchorFrm()->Prepare( PREP_FLY_ATTR_CHG, &GetFrmFmt() );
578 : }
579 : }
580 :
581 0 : SwPageFrm* pPageFrm = AnchorFrm()->FindPageFrm();
582 0 : _InvalidatePage( pPageFrm );
583 :
584 : // --> #i32270# - also invalidate page frame, at which the
585 : // drawing object is registered at.
586 0 : SwPageFrm* pPageFrmRegisteredAt = GetPageFrm();
587 0 : if ( pPageFrmRegisteredAt &&
588 : pPageFrmRegisteredAt != pPageFrm )
589 : {
590 0 : _InvalidatePage( pPageFrmRegisteredAt );
591 : }
592 : // #i33751#, #i34060# - method <GetPageFrmOfAnchor()>
593 : // is replaced by method <FindPageFrmOfAnchor()>. It's return value
594 : // have to be checked.
595 0 : SwPageFrm* pPageFrmOfAnchor = FindPageFrmOfAnchor();
596 0 : if ( pPageFrmOfAnchor &&
597 0 : pPageFrmOfAnchor != pPageFrm &&
598 : pPageFrmOfAnchor != pPageFrmRegisteredAt )
599 : {
600 0 : _InvalidatePage( pPageFrmOfAnchor );
601 : }
602 : }
603 : }
604 0 : }
605 :
606 0 : SwFrmFmt& SwAnchoredDrawObject::GetFrmFmt()
607 : {
608 : OSL_ENSURE( static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFmt(),
609 : "<SwAnchoredDrawObject::GetFrmFmt()> - missing frame format -> crash." );
610 0 : return *(static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFmt());
611 : }
612 0 : const SwFrmFmt& SwAnchoredDrawObject::GetFrmFmt() const
613 : {
614 : OSL_ENSURE( static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFmt(),
615 : "<SwAnchoredDrawObject::GetFrmFmt()> - missing frame format -> crash." );
616 0 : return *(static_cast<SwDrawContact*>(GetUserCall(GetDrawObj()))->GetFmt());
617 : }
618 :
619 0 : const SwRect SwAnchoredDrawObject::GetObjRect() const
620 : {
621 : // use geometry of drawing object
622 : //return GetDrawObj()->GetCurrentBoundRect();
623 0 : return GetDrawObj()->GetSnapRect();
624 : }
625 :
626 : // --> #i70122#
627 0 : const SwRect SwAnchoredDrawObject::GetObjBoundRect() const
628 : {
629 0 : bool bGroupShape = PTR_CAST(SdrObjGroup, GetDrawObj());
630 : // Resize objects with relative width or height
631 0 : if ( !bGroupShape && GetPageFrm( ) && ( GetDrawObj( )->GetRelativeWidth( ) || GetDrawObj()->GetRelativeHeight( ) ) )
632 : {
633 0 : Rectangle aCurrObjRect = GetDrawObj()->GetCurrentBoundRect();
634 :
635 0 : long nTargetWidth = aCurrObjRect.GetWidth( );
636 0 : if ( GetDrawObj( )->GetRelativeWidth( ) )
637 : {
638 0 : Rectangle aPageRect;
639 0 : if (GetDrawObj()->GetRelativeWidthRelation() == text::RelOrientation::FRAME)
640 : // Exclude margins.
641 0 : aPageRect = GetPageFrm()->Prt().SVRect();
642 : else
643 0 : aPageRect = GetPageFrm( )->GetBoundRect( ).SVRect();
644 0 : nTargetWidth = aPageRect.GetWidth( ) * GetDrawObj( )->GetRelativeWidth( ).get( );
645 : }
646 :
647 0 : long nTargetHeight = aCurrObjRect.GetHeight( );
648 0 : if ( GetDrawObj( )->GetRelativeHeight( ) )
649 : {
650 0 : Rectangle aPageRect;
651 0 : if (GetDrawObj()->GetRelativeHeightRelation() == text::RelOrientation::FRAME)
652 : // Exclude margins.
653 0 : aPageRect = GetPageFrm()->Prt().SVRect();
654 : else
655 0 : aPageRect = GetPageFrm( )->GetBoundRect( ).SVRect();
656 0 : nTargetHeight = aPageRect.GetHeight( ) * GetDrawObj( )->GetRelativeHeight( ).get( );
657 : }
658 :
659 0 : if ( nTargetWidth != aCurrObjRect.GetWidth( ) || nTargetHeight != aCurrObjRect.GetHeight( ) )
660 : {
661 0 : const_cast< SdrObject* >( GetDrawObj() )->Resize( aCurrObjRect.TopLeft(),
662 : Fraction( nTargetWidth, aCurrObjRect.GetWidth() ),
663 0 : Fraction( nTargetHeight, aCurrObjRect.GetHeight() ), false );
664 : }
665 : }
666 0 : return GetDrawObj()->GetCurrentBoundRect();
667 : }
668 :
669 : // --> #i68520#
670 0 : bool SwAnchoredDrawObject::_SetObjTop( const SwTwips _nTop )
671 : {
672 0 : SwTwips nDiff = _nTop - GetObjRect().Top();
673 0 : DrawObj()->Move( Size( 0, nDiff ) );
674 :
675 0 : return nDiff != 0;
676 : }
677 0 : bool SwAnchoredDrawObject::_SetObjLeft( const SwTwips _nLeft )
678 : {
679 0 : SwTwips nDiff = _nLeft - GetObjRect().Left();
680 0 : DrawObj()->Move( Size( nDiff, 0 ) );
681 :
682 0 : return nDiff != 0;
683 : }
684 :
685 : /** adjust positioning and alignment attributes for new anchor frame
686 :
687 : #i33313# - add second optional parameter <_pNewObjRect>
688 : */
689 0 : void SwAnchoredDrawObject::AdjustPositioningAttr( const SwFrm* _pNewAnchorFrm,
690 : const SwRect* _pNewObjRect )
691 : {
692 0 : SwTwips nHoriRelPos = 0;
693 0 : SwTwips nVertRelPos = 0;
694 0 : const Point aAnchorPos = _pNewAnchorFrm->GetFrmAnchorPos( ::HasWrap( GetDrawObj() ) );
695 : // --> #i33313#
696 0 : const SwRect aObjRect( _pNewObjRect ? *_pNewObjRect : GetObjRect() );
697 0 : const bool bVert = _pNewAnchorFrm->IsVertical();
698 0 : const bool bR2L = _pNewAnchorFrm->IsRightToLeft();
699 0 : if ( bVert )
700 : {
701 0 : nHoriRelPos = aObjRect.Top() - aAnchorPos.Y();
702 0 : nVertRelPos = aAnchorPos.X() - aObjRect.Right();
703 : }
704 0 : else if ( bR2L )
705 : {
706 0 : nHoriRelPos = aAnchorPos.X() - aObjRect.Right();
707 0 : nVertRelPos = aObjRect.Top() - aAnchorPos.Y();
708 : }
709 : else
710 : {
711 0 : nHoriRelPos = aObjRect.Left() - aAnchorPos.X();
712 0 : nVertRelPos = aObjRect.Top() - aAnchorPos.Y();
713 : }
714 :
715 0 : GetFrmFmt().SetFmtAttr( SwFmtHoriOrient( nHoriRelPos, text::HoriOrientation::NONE, text::RelOrientation::FRAME ) );
716 0 : GetFrmFmt().SetFmtAttr( SwFmtVertOrient( nVertRelPos, text::VertOrientation::NONE, text::RelOrientation::FRAME ) );
717 0 : }
718 :
719 : // --> #i34748# - change return type
720 0 : const Rectangle* SwAnchoredDrawObject::GetLastObjRect() const
721 : {
722 0 : return mpLastObjRect;
723 : }
724 :
725 : // --> #i34748# - change return type.
726 : // If member <mpLastObjRect> is NULL, create one.
727 0 : void SwAnchoredDrawObject::SetLastObjRect( const Rectangle& _rNewLastRect )
728 : {
729 0 : if ( !mpLastObjRect )
730 : {
731 0 : mpLastObjRect = new Rectangle;
732 : }
733 0 : *(mpLastObjRect) = _rNewLastRect;
734 0 : }
735 :
736 0 : void SwAnchoredDrawObject::ObjectAttachedToAnchorFrame()
737 : {
738 : // --> #i31698#
739 0 : SwAnchoredObject::ObjectAttachedToAnchorFrame();
740 :
741 0 : if ( mbNotYetAttachedToAnchorFrame )
742 : {
743 0 : mbNotYetAttachedToAnchorFrame = false;
744 : }
745 0 : }
746 :
747 : /** method to set positioning attributes
748 :
749 : #i35798#
750 : During load the positioning attributes aren't set.
751 : Thus, the positioning attributes are set by the current object geometry.
752 : This method is also used for the conversion for drawing objects
753 : (not anchored as-character) imported from OpenOffice.org file format
754 : once and directly before the first positioning.
755 : */
756 0 : void SwAnchoredDrawObject::_SetPositioningAttr()
757 : {
758 : SwDrawContact* pDrawContact =
759 0 : static_cast<SwDrawContact*>(GetUserCall( GetDrawObj() ));
760 :
761 0 : if ( !pDrawContact->ObjAnchoredAsChar() )
762 : {
763 0 : SwRect aObjRect( GetObjRect() );
764 :
765 0 : SwTwips nHoriPos = aObjRect.Left();
766 0 : SwTwips nVertPos = aObjRect.Top();
767 : // #i44334#, #i44681#
768 : // perform conversion only if position is in horizontal-left-to-right-layout.
769 0 : if ( GetFrmFmt().GetPositionLayoutDir() ==
770 : text::PositionLayoutDir::PositionInHoriL2R )
771 : {
772 0 : SwFrmFmt::tLayoutDir eLayoutDir = GetFrmFmt().GetLayoutDir();
773 0 : switch ( eLayoutDir )
774 : {
775 : case SwFrmFmt::HORI_L2R:
776 : {
777 : // nothing to do
778 : }
779 0 : break;
780 : case SwFrmFmt::HORI_R2L:
781 : {
782 0 : nHoriPos = -aObjRect.Left() - aObjRect.Width();
783 : }
784 0 : break;
785 : case SwFrmFmt::VERT_R2L:
786 : {
787 0 : nHoriPos = aObjRect.Top();
788 0 : nVertPos = -aObjRect.Left() - aObjRect.Width();
789 : }
790 0 : break;
791 : default:
792 : {
793 : OSL_FAIL( "<SwAnchoredDrawObject::_SetPositioningAttr()> - unsupported layout direction" );
794 : }
795 : }
796 : }
797 :
798 : // --> #i71182#
799 : // only change position - do not lose other attributes
800 0 : SwFmtHoriOrient aHori( GetFrmFmt().GetHoriOrient() );
801 0 : aHori.SetPos( nHoriPos );
802 0 : GetFrmFmt().SetFmtAttr( aHori );
803 :
804 0 : SwFmtVertOrient aVert( GetFrmFmt().GetVertOrient() );
805 :
806 0 : aVert.SetPos( nVertPos );
807 0 : GetFrmFmt().SetFmtAttr( aVert );
808 :
809 : // --> #i36010# - set layout direction of the position
810 0 : GetFrmFmt().SetPositionLayoutDir(
811 0 : text::PositionLayoutDir::PositionInLayoutDirOfAnchor );
812 : }
813 : // --> #i65798# - also for as-character anchored objects
814 : // --> #i45952# - indicate that position
815 : // attributes are set now.
816 0 : static_cast<SwDrawFrmFmt&>(GetFrmFmt()).PosAttrSet();
817 0 : }
818 :
819 0 : void SwAnchoredDrawObject::NotifyBackground( SwPageFrm* _pPageFrm,
820 : const SwRect& _rRect,
821 : PrepareHint _eHint )
822 : {
823 0 : ::Notify_Background( GetDrawObj(), _pPageFrm, _rRect, _eHint, sal_True );
824 0 : }
825 :
826 : /** method to assure that anchored object is registered at the correct
827 : page frame
828 :
829 : #i28701#
830 : */
831 0 : void SwAnchoredDrawObject::RegisterAtCorrectPage()
832 : {
833 0 : SwPageFrm* pPageFrm( 0L );
834 0 : if ( GetVertPosOrientFrm() )
835 : {
836 0 : pPageFrm = const_cast<SwPageFrm*>(GetVertPosOrientFrm()->FindPageFrm());
837 : }
838 0 : if ( pPageFrm && GetPageFrm() != pPageFrm )
839 : {
840 0 : if ( GetPageFrm() )
841 0 : GetPageFrm()->RemoveDrawObjFromPage( *this );
842 0 : pPageFrm->AppendDrawObjToPage( *this );
843 : }
844 0 : }
845 :
846 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|