merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / draw / dflyobj.cxx
blobce2c6067f36172906a5da5e11a0d60d7bcb47bd0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dflyobj.cxx,v $
10 * $Revision: 1.27.22.1 $
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 "hintids.hxx"
34 #include <svx/svdtrans.hxx>
35 #include <svx/protitem.hxx>
36 #include <svx/opaqitem.hxx>
37 #include <svx/svdpage.hxx>
40 #include <fmtclds.hxx>
41 #include <fmtornt.hxx>
42 #include <fmtfsize.hxx>
43 #include <fmturl.hxx>
44 #include "viewsh.hxx"
45 #include "viewimp.hxx"
46 #include "cntfrm.hxx"
47 #include "frmatr.hxx"
48 #include "doc.hxx"
49 #include "dview.hxx"
50 #include "dflyobj.hxx"
51 #include "flyfrm.hxx"
52 #include "frmfmt.hxx"
53 #include "viewopt.hxx"
54 #include "frmtool.hxx"
55 #include "flyfrms.hxx"
56 #include "ndnotxt.hxx"
57 #include "grfatr.hxx"
58 #include "pagefrm.hxx"
61 using namespace ::com::sun::star;
64 // --> OD 2004-11-22 #117958#
65 #include <svx/sdr/properties/defaultproperties.hxx>
66 // <--
67 #include <basegfx/range/b2drange.hxx>
68 #include <basegfx/polygon/b2dpolygontools.hxx>
69 #include <basegfx/polygon/b2dpolygon.hxx>
71 // AW: For VCOfDrawVirtObj and stuff
72 #include <svx/sdr/contact/viewcontactofvirtobj.hxx>
73 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
74 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
75 #include <sw_primitivetypes2d.hxx>
76 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
77 #include <drawinglayer/primitive2d/hittestprimitive2d.hxx>
79 using namespace ::com::sun::star;
81 static BOOL bInResize = FALSE;
83 TYPEINIT1( SwFlyDrawObj, SdrObject )
84 TYPEINIT1( SwVirtFlyDrawObj, SdrVirtObj )
86 /*************************************************************************
88 |* SwFlyDrawObj::Ctor
90 |* Ersterstellung MA 18. Apr. 95
91 |* Letzte Aenderung MA 28. May. 96
93 *************************************************************************/
95 ////////////////////////////////////////////////////////////////////////////////////////////////////
97 namespace sdr
99 namespace contact
101 // #i95264# currently needed since createViewIndependentPrimitive2DSequence()
102 // is called when RecalcBoundRect() is used. There should currently no VOCs being
103 // constructed since it gets not visualized (instead the corresponding SwVirtFlyDrawObj's
104 // referencing this one are visualized).
105 class VCOfSwFlyDrawObj : public ViewContactOfSdrObj
107 protected:
108 // This method is responsible for creating the graphical visualisation data
109 // ONLY based on model data
110 virtual drawinglayer::primitive2d::Primitive2DSequence createViewIndependentPrimitive2DSequence() const;
112 public:
113 // basic constructor, used from SdrObject.
114 VCOfSwFlyDrawObj(SwFlyDrawObj& rObj)
115 : ViewContactOfSdrObj(rObj)
118 virtual ~VCOfSwFlyDrawObj();
121 drawinglayer::primitive2d::Primitive2DSequence VCOfSwFlyDrawObj::createViewIndependentPrimitive2DSequence() const
123 // currently gets not visualized, return empty sequence
124 return drawinglayer::primitive2d::Primitive2DSequence();
127 VCOfSwFlyDrawObj::~VCOfSwFlyDrawObj()
130 } // end of namespace contact
131 } // end of namespace sdr
133 ////////////////////////////////////////////////////////////////////////////////////////////////////
135 sdr::properties::BaseProperties* SwFlyDrawObj::CreateObjectSpecificProperties()
137 // --> OD 2004-11-22 #117958# - create default properties
138 return new sdr::properties::DefaultProperties(*this);
139 // <--
142 sdr::contact::ViewContact* SwFlyDrawObj::CreateObjectSpecificViewContact()
144 // #i95264# needs an own VC since createViewIndependentPrimitive2DSequence()
145 // is called when RecalcBoundRect() is used
146 return new sdr::contact::VCOfSwFlyDrawObj(*this);
149 SwFlyDrawObj::SwFlyDrawObj()
153 SwFlyDrawObj::~SwFlyDrawObj()
157 /*************************************************************************
159 |* SwFlyDrawObj::Factory-Methoden
161 |* Ersterstellung MA 23. Feb. 95
162 |* Letzte Aenderung MA 23. Feb. 95
164 *************************************************************************/
166 UINT32 __EXPORT SwFlyDrawObj::GetObjInventor() const
168 return SWGInventor;
172 UINT16 __EXPORT SwFlyDrawObj::GetObjIdentifier() const
174 return SwFlyDrawObjIdentifier;
178 UINT16 __EXPORT SwFlyDrawObj::GetObjVersion() const
180 return SwDrawFirst;
183 /*************************************************************************
185 |* SwVirtFlyDrawObj::CToren, Dtor
187 |* Ersterstellung MA 08. Dec. 94
188 |* Letzte Aenderung MA 28. May. 96
190 *************************************************************************/
192 //////////////////////////////////////////////////////////////////////////////////////
193 // AW: Need own primitive to get the FlyFrame paint working
195 namespace drawinglayer
197 namespace primitive2d
199 class SwVirtFlyDrawObjPrimitive : public BasePrimitive2D
201 private:
202 const SwVirtFlyDrawObj& mrSwVirtFlyDrawObj;
203 const basegfx::B2DRange maOuterRange;
205 protected:
206 // method which is to be used to implement the local decomposition of a 2D primitive
207 virtual Primitive2DSequence createLocalDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
209 public:
210 SwVirtFlyDrawObjPrimitive(
211 const SwVirtFlyDrawObj& rSwVirtFlyDrawObj,
212 const basegfx::B2DRange &rOuterRange)
213 : BasePrimitive2D(),
214 mrSwVirtFlyDrawObj(rSwVirtFlyDrawObj),
215 maOuterRange(rOuterRange)
219 // compare operator
220 virtual bool operator==(const BasePrimitive2D& rPrimitive) const;
222 // get range
223 virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D& rViewInformation) const;
225 // overloaded to allow callbacks to wrap_DoPaintObject
226 virtual Primitive2DSequence get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const;
228 // data read access
229 const SwVirtFlyDrawObj& getSwVirtFlyDrawObj() const { return mrSwVirtFlyDrawObj; }
230 const basegfx::B2DRange& getOuterRange() const { return maOuterRange; }
232 // provide unique ID
233 DeclPrimitrive2DIDBlock()
235 } // end of namespace primitive2d
236 } // end of namespace drawinglayer
238 namespace drawinglayer
240 namespace primitive2d
242 Primitive2DSequence SwVirtFlyDrawObjPrimitive::createLocalDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
244 Primitive2DSequence aRetval;
246 if(!getOuterRange().isEmpty())
248 // currently this SW object has no primitive representation. As long as this is the case,
249 // create an invisible HitTestPrimitive to allow hitting the object. Use a filled primitive
250 // to get a HitTest which uses 'inside' as default object hit. The special cases from
251 // the old SwVirtFlyDrawObj::CheckHit implementation are handled now in SwDrawView::PickObj;
252 // this removed the 'hack' to get a view from inside model data or to react on noll-tolerance
253 // as it was done in the old implementation
254 const basegfx::B2DPolygon aOuterRangePolygon(basegfx::tools::createPolygonFromRect(getOuterRange()));
255 const basegfx::BColor aColor(0.0, 0.0, 0.0);
256 const Primitive2DReference aContentReference(
257 new PolyPolygonColorPrimitive2D(
258 basegfx::B2DPolyPolygon(aOuterRangePolygon),
259 aColor));
260 const Primitive2DReference aHitTestReference(
261 new HitTestPrimitive2D(
262 Primitive2DSequence(&aContentReference, 1)));
264 aRetval = Primitive2DSequence(&aHitTestReference, 1);
267 return aRetval;
270 bool SwVirtFlyDrawObjPrimitive::operator==(const BasePrimitive2D& rPrimitive) const
272 if(BasePrimitive2D::operator==(rPrimitive))
274 const SwVirtFlyDrawObjPrimitive& rCompare = (SwVirtFlyDrawObjPrimitive&)rPrimitive;
276 return (&getSwVirtFlyDrawObj() == &rCompare.getSwVirtFlyDrawObj()
277 && getOuterRange() == rCompare.getOuterRange());
280 return false;
283 basegfx::B2DRange SwVirtFlyDrawObjPrimitive::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
285 return getOuterRange();
288 Primitive2DSequence SwVirtFlyDrawObjPrimitive::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
290 // This is the callback to keep the FlyFrame painting in SW alive as long as it
291 // is not changed to primitives. This is the method which will be called by the processors
292 // when they do not know this primitive (and they do not). Inside wrap_DoPaintObject
293 // there needs to be a test that paint is only done during SW repaints (see there).
294 // Using this mechanism guarantees the correct Z-Order of the VirtualObject-based FlyFrames.
295 getSwVirtFlyDrawObj().wrap_DoPaintObject();
297 // call parent
298 return BasePrimitive2D::get2DDecomposition(rViewInformation);
301 // provide unique ID
302 ImplPrimitrive2DIDBlock(SwVirtFlyDrawObjPrimitive, PRIMITIVE2D_ID_SWVIRTFLYDRAWOBJPRIMITIVE2D)
304 } // end of namespace primitive2d
305 } // end of namespace drawinglayer
307 //////////////////////////////////////////////////////////////////////////////////////
308 // AW: own sdr::contact::ViewContact (VC) sdr::contact::ViewObjectContact (VOC) needed
309 // since offset is defined different from SdrVirtObj's sdr::contact::ViewContactOfVirtObj.
310 // For paint, that offset is used by setting at the OutputDevice; for primitives this is
311 // not possible since we have no OutputDevice, but define the geometry itself.
313 namespace sdr
315 namespace contact
317 class VCOfSwVirtFlyDrawObj : public ViewContactOfVirtObj
319 protected:
320 // This method is responsible for creating the graphical visualisation data
321 // ONLY based on model data
322 virtual drawinglayer::primitive2d::Primitive2DSequence createViewIndependentPrimitive2DSequence() const;
324 public:
325 // basic constructor, used from SdrObject.
326 VCOfSwVirtFlyDrawObj(SwVirtFlyDrawObj& rObj)
327 : ViewContactOfVirtObj(rObj)
330 virtual ~VCOfSwVirtFlyDrawObj();
332 // access to SwVirtFlyDrawObj
333 SwVirtFlyDrawObj& GetSwVirtFlyDrawObj() const
335 return (SwVirtFlyDrawObj&)mrObject;
338 } // end of namespace contact
339 } // end of namespace sdr
341 namespace sdr
343 namespace contact
345 drawinglayer::primitive2d::Primitive2DSequence VCOfSwVirtFlyDrawObj::createViewIndependentPrimitive2DSequence() const
347 drawinglayer::primitive2d::Primitive2DSequence xRetval;
348 const SdrObject& rReferencedObject = GetSwVirtFlyDrawObj().GetReferencedObj();
350 if(rReferencedObject.ISA(SwFlyDrawObj))
352 // create an own specialized primitive which is used as repaint callpoint and HitTest
353 // for HitTest processor (see primitive implementation above)
354 const basegfx::B2DRange aOuterRange(GetSwVirtFlyDrawObj().getOuterBound());
356 if(!aOuterRange.isEmpty())
358 const drawinglayer::primitive2d::Primitive2DReference xPrimitive(
359 new drawinglayer::primitive2d::SwVirtFlyDrawObjPrimitive(
360 GetSwVirtFlyDrawObj(),
361 aOuterRange));
363 xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xPrimitive, 1);
367 return xRetval;
370 VCOfSwVirtFlyDrawObj::~VCOfSwVirtFlyDrawObj()
373 } // end of namespace contact
374 } // end of namespace sdr
376 //////////////////////////////////////////////////////////////////////////////////////
378 basegfx::B2DRange SwVirtFlyDrawObj::getOuterBound() const
380 basegfx::B2DRange aOuterRange;
381 const SdrObject& rReferencedObject = GetReferencedObj();
383 if(rReferencedObject.ISA(SwFlyDrawObj))
385 const SwFlyFrm* pFlyFrame = GetFlyFrm();
387 if(pFlyFrame)
389 const Rectangle aOuterRectangle(pFlyFrame->Frm().Pos(), pFlyFrame->Frm().SSize());
391 if(!aOuterRectangle.IsEmpty()
392 && RECT_EMPTY != aOuterRectangle.Right()
393 && RECT_EMPTY != aOuterRectangle.Bottom())
395 aOuterRange.expand(basegfx::B2DTuple(aOuterRectangle.Left(), aOuterRectangle.Top()));
396 aOuterRange.expand(basegfx::B2DTuple(aOuterRectangle.Right(), aOuterRectangle.Bottom()));
401 return aOuterRange;
404 basegfx::B2DRange SwVirtFlyDrawObj::getInnerBound() const
406 basegfx::B2DRange aInnerRange;
407 const SdrObject& rReferencedObject = GetReferencedObj();
409 if(rReferencedObject.ISA(SwFlyDrawObj))
411 const SwFlyFrm* pFlyFrame = GetFlyFrm();
413 if(pFlyFrame)
415 const Rectangle aInnerRectangle(pFlyFrame->Frm().Pos() + pFlyFrame->Prt().Pos(), pFlyFrame->Prt().SSize());
417 if(!aInnerRectangle.IsEmpty()
418 && RECT_EMPTY != aInnerRectangle.Right()
419 && RECT_EMPTY != aInnerRectangle.Bottom())
421 aInnerRange.expand(basegfx::B2DTuple(aInnerRectangle.Left(), aInnerRectangle.Top()));
422 aInnerRange.expand(basegfx::B2DTuple(aInnerRectangle.Right(), aInnerRectangle.Bottom()));
427 return aInnerRange;
430 sdr::contact::ViewContact* SwVirtFlyDrawObj::CreateObjectSpecificViewContact()
432 // need an own ViewContact (VC) to allow creation of a specialized primitive
433 // for being able to visualize the FlyFrames in primitive renderers
434 return new sdr::contact::VCOfSwVirtFlyDrawObj(*this);
437 SwVirtFlyDrawObj::SwVirtFlyDrawObj(SdrObject& rNew, SwFlyFrm* pFly) :
438 SdrVirtObj( rNew ),
439 pFlyFrm( pFly )
441 //#110094#-1
442 // bNotPersistent = bNeedColorRestore = bWriterFlyFrame = TRUE;
443 const SvxProtectItem &rP = pFlyFrm->GetFmt()->GetProtect();
444 bMovProt = rP.IsPosProtected();
445 bSizProt = rP.IsSizeProtected();
449 __EXPORT SwVirtFlyDrawObj::~SwVirtFlyDrawObj()
451 if ( GetPage() ) //Der SdrPage die Verantwortung entziehen.
452 GetPage()->RemoveObject( GetOrdNum() );
455 /*************************************************************************
457 |* SwVirtFlyDrawObj::GetFmt()
459 |* Ersterstellung MA 08. Dec. 94
460 |* Letzte Aenderung MA 08. Dec. 94
462 *************************************************************************/
464 const SwFrmFmt *SwVirtFlyDrawObj::GetFmt() const
466 return GetFlyFrm()->GetFmt();
470 SwFrmFmt *SwVirtFlyDrawObj::GetFmt()
472 return GetFlyFrm()->GetFmt();
475 /*************************************************************************
477 |* SwVirtFlyDrawObj::Paint()
479 |* Ersterstellung MA 20. Dec. 94
480 |* Letzte Aenderung MA 18. Dec. 95
482 *************************************************************************/
484 void SwVirtFlyDrawObj::wrap_DoPaintObject() const
486 ViewShell* pShell = pFlyFrm->GetShell();
488 // Only paint when we have a current shell and a DrawingLayer paint is in progress.
489 // This avcoids evtl. problems with renderers which do processing stuff,
490 // but no paints. IsPaintInProgress() depends on SW repaint, so, as long
491 // as SW paints self and calls DrawLayer() for Heaven and Hell, this will
492 // be correct
493 if(pShell && pShell->IsDrawingLayerPaintInProgress())
495 sal_Bool bDrawObject(sal_True);
497 if(!SwFlyFrm::IsPaint((SdrObject*)this, pShell))
499 bDrawObject = sal_False;
502 if(bDrawObject)
504 if(!pFlyFrm->IsFlyInCntFrm())
506 // it is also necessary to restore the VCL MapMode from ViewInformation since e.g.
507 // the VCL PixelRenderer resets it at the used OutputDevice. Unfortunately, this
508 // excludes shears and rotates which are not expressable in MapMode.
509 OutputDevice* pOut = pShell->GetOut();
511 pOut->Push(PUSH_MAPMODE);
512 pOut->SetMapMode(pShell->getPrePostMapMode());
514 // paint the FlyFrame (use standard VCL-Paint)
515 pFlyFrm->Paint(GetFlyFrm()->Frm());
517 pOut->Pop();
523 /*************************************************************************
525 |* SwVirtFlyDrawObj::TakeObjInfo()
527 |* Ersterstellung MA 03. May. 95
528 |* Letzte Aenderung MA 03. May. 95
530 *************************************************************************/
532 void __EXPORT SwVirtFlyDrawObj::TakeObjInfo( SdrObjTransformInfoRec& rInfo ) const
534 rInfo.bSelectAllowed = rInfo.bMoveAllowed =
535 rInfo.bResizeFreeAllowed = rInfo.bResizePropAllowed = TRUE;
537 rInfo.bRotateFreeAllowed = rInfo.bRotate90Allowed =
538 rInfo.bMirrorFreeAllowed = rInfo.bMirror45Allowed =
539 rInfo.bMirror90Allowed = rInfo.bShearAllowed =
540 rInfo.bCanConvToPath = rInfo.bCanConvToPoly =
541 rInfo.bCanConvToPathLineToArea = rInfo.bCanConvToPolyLineToArea = FALSE;
545 /*************************************************************************
547 |* SwVirtFlyDrawObj::Groessenermittlung
549 |* Ersterstellung MA 12. Jan. 95
550 |* Letzte Aenderung MA 10. Nov. 95
552 *************************************************************************/
554 void SwVirtFlyDrawObj::SetRect() const
556 if ( GetFlyFrm()->Frm().HasArea() )
557 ((SwVirtFlyDrawObj*)this)->aOutRect = GetFlyFrm()->Frm().SVRect();
558 else
559 ((SwVirtFlyDrawObj*)this)->aOutRect = Rectangle();
563 const Rectangle& __EXPORT SwVirtFlyDrawObj::GetCurrentBoundRect() const
565 SetRect();
566 return aOutRect;
570 void __EXPORT SwVirtFlyDrawObj::RecalcBoundRect()
572 SetRect();
576 void __EXPORT SwVirtFlyDrawObj::RecalcSnapRect()
578 SetRect();
582 const Rectangle& __EXPORT SwVirtFlyDrawObj::GetSnapRect() const
584 SetRect();
585 return aOutRect;
589 void __EXPORT SwVirtFlyDrawObj::SetSnapRect(const Rectangle& )
591 Rectangle aTmp( GetLastBoundRect() );
592 SetRect();
593 SetChanged();
594 BroadcastObjectChange();
595 if (pUserCall!=NULL)
596 pUserCall->Changed(*this, SDRUSERCALL_RESIZE, aTmp);
600 void __EXPORT SwVirtFlyDrawObj::NbcSetSnapRect(const Rectangle& )
602 SetRect();
606 const Rectangle& __EXPORT SwVirtFlyDrawObj::GetLogicRect() const
608 SetRect();
609 return aOutRect;
613 void __EXPORT SwVirtFlyDrawObj::SetLogicRect(const Rectangle& )
615 Rectangle aTmp( GetLastBoundRect() );
616 SetRect();
617 SetChanged();
618 BroadcastObjectChange();
619 if (pUserCall!=NULL)
620 pUserCall->Changed(*this, SDRUSERCALL_RESIZE, aTmp);
624 void __EXPORT SwVirtFlyDrawObj::NbcSetLogicRect(const Rectangle& )
626 SetRect();
630 ::basegfx::B2DPolyPolygon SwVirtFlyDrawObj::TakeXorPoly() const
632 const Rectangle aSourceRectangle(GetFlyFrm()->Frm().SVRect());
633 const ::basegfx::B2DRange aSourceRange(aSourceRectangle.Left(), aSourceRectangle.Top(), aSourceRectangle.Right(), aSourceRectangle.Bottom());
634 ::basegfx::B2DPolyPolygon aRetval;
636 aRetval.append(::basegfx::tools::createPolygonFromRect(aSourceRange));
638 return aRetval;
641 /*************************************************************************
643 |* SwVirtFlyDrawObj::Move() und Resize()
645 |* Ersterstellung MA 12. Jan. 95
646 |* Letzte Aenderung MA 26. Jul. 96
648 *************************************************************************/
650 void __EXPORT SwVirtFlyDrawObj::NbcMove(const Size& rSiz)
652 MoveRect( aOutRect, rSiz );
653 const Point aOldPos( GetFlyFrm()->Frm().Pos() );
654 const Point aNewPos( aOutRect.TopLeft() );
655 const SwRect aFlyRect( aOutRect );
657 //Wenn der Fly eine automatische Ausrichtung hat (rechts oder oben),
658 //so soll die Automatik erhalten bleiben
659 SwFrmFmt *pFmt = GetFlyFrm()->GetFmt();
660 const sal_Int16 eHori = pFmt->GetHoriOrient().GetHoriOrient();
661 const sal_Int16 eVert = pFmt->GetVertOrient().GetVertOrient();
662 const sal_Int16 eRelHori = pFmt->GetHoriOrient().GetRelationOrient();
663 const sal_Int16 eRelVert = pFmt->GetVertOrient().GetRelationOrient();
664 //Bei Absatzgebundenen Flys muss ausgehend von der neuen Position ein
665 //neuer Anker gesetzt werden. Anker und neue RelPos werden vom Fly selbst
666 //berechnet und gesetzt.
667 if( GetFlyFrm()->IsFlyAtCntFrm() )
668 ((SwFlyAtCntFrm*)GetFlyFrm())->SetAbsPos( aNewPos );
669 else
671 const SwFrmFmt *pTmpFmt = GetFmt();
672 const SwFmtVertOrient &rVert = pTmpFmt->GetVertOrient();
673 const SwFmtHoriOrient &rHori = pTmpFmt->GetHoriOrient();
674 long lXDiff = aNewPos.X() - aOldPos.X();
675 if( rHori.IsPosToggle() && text::HoriOrientation::NONE == eHori &&
676 !GetFlyFrm()->FindPageFrm()->OnRightPage() )
677 lXDiff = -lXDiff;
679 if( GetFlyFrm()->GetAnchorFrm()->IsRightToLeft() &&
680 text::HoriOrientation::NONE == eHori )
681 lXDiff = -lXDiff;
683 long lYDiff = aNewPos.Y() - aOldPos.Y();
684 if( GetFlyFrm()->GetAnchorFrm()->IsVertical() )
686 lXDiff -= rVert.GetPos();
687 lYDiff += rHori.GetPos();
689 else
691 lXDiff += rHori.GetPos();
692 lYDiff += rVert.GetPos();
695 if( GetFlyFrm()->GetAnchorFrm()->IsRightToLeft() &&
696 text::HoriOrientation::NONE != eHori )
697 lXDiff = GetFlyFrm()->GetAnchorFrm()->Frm().Width() -
698 aFlyRect.Width() - lXDiff;
700 const Point aTmp( lXDiff, lYDiff );
701 GetFlyFrm()->ChgRelPos( aTmp );
704 SwAttrSet aSet( pFmt->GetDoc()->GetAttrPool(),
705 RES_VERT_ORIENT, RES_HORI_ORIENT );
706 SwFmtHoriOrient aHori( pFmt->GetHoriOrient() );
707 SwFmtVertOrient aVert( pFmt->GetVertOrient() );
708 BOOL bPut = FALSE;
710 if( !GetFlyFrm()->IsFlyLayFrm() &&
711 ::GetHtmlMode(pFmt->GetDoc()->GetDocShell()) )
713 //Im HTML-Modus sind nur automatische Ausrichtungen erlaubt.
714 //Einzig einen Snap auf Links/Rechts bzw. Linker-/Rechter-Rand koennen
715 //wir versuchen.
716 const SwFrm* pAnch = GetFlyFrm()->GetAnchorFrm();
717 BOOL bNextLine = FALSE;
719 if( !GetFlyFrm()->IsAutoPos() || text::RelOrientation::PAGE_FRAME != aHori.GetRelationOrient() )
721 if( text::RelOrientation::CHAR == eRelHori )
723 aHori.SetHoriOrient( text::HoriOrientation::LEFT );
724 aHori.SetRelationOrient( text::RelOrientation::CHAR );
726 else
728 bNextLine = TRUE;
729 //Horizontale Ausrichtung:
730 const BOOL bLeftFrm =
731 aFlyRect.Left() < pAnch->Frm().Left() + pAnch->Prt().Left(),
732 bLeftPrt = aFlyRect.Left() + aFlyRect.Width() <
733 pAnch->Frm().Left() + pAnch->Prt().Width()/2;
734 if ( bLeftFrm || bLeftPrt )
736 aHori.SetHoriOrient( text::HoriOrientation::LEFT );
737 aHori.SetRelationOrient( bLeftFrm ? text::RelOrientation::FRAME : text::RelOrientation::PRINT_AREA );
739 else
741 const BOOL bRightFrm = aFlyRect.Left() >
742 pAnch->Frm().Left() + pAnch->Prt().Width();
743 aHori.SetHoriOrient( text::HoriOrientation::RIGHT );
744 aHori.SetRelationOrient( bRightFrm ? text::RelOrientation::FRAME : text::RelOrientation::PRINT_AREA );
747 aSet.Put( aHori );
749 //Vertikale Ausrichtung bleibt grundsaetzlich schlicht erhalten,
750 //nur bei nicht automatischer Ausrichtung wird umgeschaltet.
751 BOOL bRelChar = text::RelOrientation::CHAR == eRelVert;
752 aVert.SetVertOrient( eVert != text::VertOrientation::NONE ? eVert :
753 GetFlyFrm()->IsFlyInCntFrm() ? text::VertOrientation::CHAR_CENTER :
754 bRelChar && bNextLine ? text::VertOrientation::CHAR_TOP : text::VertOrientation::TOP );
755 if( bRelChar )
756 aVert.SetRelationOrient( text::RelOrientation::CHAR );
757 else
758 aVert.SetRelationOrient( text::RelOrientation::PRINT_AREA );
759 aSet.Put( aVert );
760 bPut = TRUE;
763 //Automatische Ausrichtungen wollen wir moeglichst nicht verlieren.
764 if ( !bPut && bInResize )
766 if ( text::HoriOrientation::NONE != eHori )
768 aHori.SetHoriOrient( eHori );
769 aHori.SetRelationOrient( eRelHori );
770 aSet.Put( aHori );
771 bPut = TRUE;
773 if ( text::VertOrientation::NONE != eVert )
775 aVert.SetVertOrient( eVert );
776 aVert.SetRelationOrient( eRelVert );
777 aSet.Put( aVert );
778 bPut = TRUE;
781 if ( bPut )
782 pFmt->SetFmtAttr( aSet );
786 void __EXPORT SwVirtFlyDrawObj::NbcResize(const Point& rRef,
787 const Fraction& xFact, const Fraction& yFact)
789 ResizeRect( aOutRect, rRef, xFact, yFact );
791 const SwFrm* pTmpFrm = GetFlyFrm()->GetAnchorFrm();
792 if( !pTmpFrm )
793 pTmpFrm = GetFlyFrm();
794 const bool bVertX = pTmpFrm->IsVertical();
796 const sal_Bool bRTL = pTmpFrm->IsRightToLeft();
798 const Point aNewPos( bVertX || bRTL ?
799 aOutRect.Right() + 1 :
800 aOutRect.Left(),
801 aOutRect.Top() );
803 Size aSz( aOutRect.Right() - aOutRect.Left() + 1,
804 aOutRect.Bottom()- aOutRect.Top() + 1 );
805 if( aSz != GetFlyFrm()->Frm().SSize() )
807 //Die Breite darf bei Spalten nicht zu schmal werden
808 if ( GetFlyFrm()->Lower() && GetFlyFrm()->Lower()->IsColumnFrm() )
810 SwBorderAttrAccess aAccess( SwFrm::GetCache(), GetFlyFrm() );
811 const SwBorderAttrs &rAttrs = *aAccess.Get();
812 long nMin = rAttrs.CalcLeftLine()+rAttrs.CalcRightLine();
813 const SwFmtCol& rCol = rAttrs.GetAttrSet().GetCol();
814 if ( rCol.GetColumns().Count() > 1 )
816 for ( USHORT i = 0; i < rCol.GetColumns().Count(); ++i )
818 nMin += rCol.GetColumns()[i]->GetLeft() +
819 rCol.GetColumns()[i]->GetRight() +
820 MINFLY;
822 nMin -= MINFLY;
824 aSz.Width() = Max( aSz.Width(), nMin );
827 SwFrmFmt *pFmt = GetFmt();
828 const SwFmtFrmSize aOldFrmSz( pFmt->GetFrmSize() );
829 GetFlyFrm()->ChgSize( aSz );
830 SwFmtFrmSize aFrmSz( pFmt->GetFrmSize() );
831 if ( aFrmSz.GetWidthPercent() || aFrmSz.GetHeightPercent() )
833 long nRelWidth, nRelHeight;
834 const SwFrm *pRel = GetFlyFrm()->IsFlyLayFrm() ?
835 GetFlyFrm()->GetAnchorFrm() :
836 GetFlyFrm()->GetAnchorFrm()->GetUpper();
837 const ViewShell *pSh = GetFlyFrm()->GetShell();
838 if ( pSh && pRel->IsBodyFrm() &&
839 pFmt->getIDocumentSettingAccess()->get(IDocumentSettingAccess::BROWSE_MODE) &&
840 pSh->VisArea().HasArea() )
842 nRelWidth = pSh->GetBrowseWidth();
843 nRelHeight = pSh->VisArea().Height();
844 const Size aBorder = pSh->GetOut()->PixelToLogic( pSh->GetBrowseBorder() );
845 nRelHeight -= 2*aBorder.Height();
847 else
849 nRelWidth = pRel->Prt().Width();
850 nRelHeight = pRel->Prt().Height();
852 if ( aFrmSz.GetWidthPercent() && aFrmSz.GetWidthPercent() != 0xFF &&
853 aOldFrmSz.GetWidth() != aFrmSz.GetWidth() )
854 aFrmSz.SetWidthPercent( BYTE(aSz.Width() * 100L / nRelWidth + 0.5) );
855 if ( aFrmSz.GetHeightPercent() && aFrmSz.GetHeightPercent() != 0xFF &&
856 aOldFrmSz.GetHeight() != aFrmSz.GetHeight() )
857 aFrmSz.SetHeightPercent( BYTE(aSz.Height() * 100L / nRelHeight + 0.5) );
858 pFmt->GetDoc()->SetAttr( aFrmSz, *pFmt );
862 //Position kann auch veraendert sein!
863 const Point aOldPos( bVertX || bRTL ?
864 GetFlyFrm()->Frm().TopRight() :
865 GetFlyFrm()->Frm().Pos() );
867 if ( aNewPos != aOldPos )
869 //Kann sich durch das ChgSize veraendert haben!
870 if( bVertX || bRTL )
872 if( aOutRect.TopRight() != aNewPos )
874 SwTwips nDeltaX = aNewPos.X() - aOutRect.Right();
875 SwTwips nDeltaY = aNewPos.Y() - aOutRect.Top();
876 MoveRect( aOutRect, Size( nDeltaX, nDeltaY ) );
879 else if ( aOutRect.TopLeft() != aNewPos )
880 aOutRect.SetPos( aNewPos );
881 bInResize = TRUE;
882 NbcMove( Size( 0, 0 ) );
883 bInResize = FALSE;
888 void __EXPORT SwVirtFlyDrawObj::Move(const Size& rSiz)
890 NbcMove( rSiz );
891 SetChanged();
892 GetFmt()->GetDoc()->SetNoDrawUndoObj( TRUE );
896 void __EXPORT SwVirtFlyDrawObj::Resize(const Point& rRef,
897 const Fraction& xFact, const Fraction& yFact)
899 NbcResize( rRef, xFact, yFact );
900 SetChanged();
901 GetFmt()->GetDoc()->SetNoDrawUndoObj( TRUE );
905 Pointer __EXPORT SwVirtFlyDrawObj::GetMacroPointer(
906 const SdrObjMacroHitRec& ) const
908 return Pointer( POINTER_REFHAND );
912 FASTBOOL __EXPORT SwVirtFlyDrawObj::HasMacro() const
914 const SwFmtURL &rURL = pFlyFrm->GetFmt()->GetURL();
915 return rURL.GetMap() || rURL.GetURL().Len();
919 SdrObject* SwVirtFlyDrawObj::CheckMacroHit( const SdrObjMacroHitRec& rRec ) const
921 const SwFmtURL &rURL = pFlyFrm->GetFmt()->GetURL();
922 if( rURL.GetMap() || rURL.GetURL().Len() )
924 SwRect aRect;
925 if ( pFlyFrm->Lower() && pFlyFrm->Lower()->IsNoTxtFrm() )
927 aRect = pFlyFrm->Prt();
928 aRect += pFlyFrm->Frm().Pos();
930 else
931 aRect = pFlyFrm->Frm();
933 if( aRect.IsInside( rRec.aPos ) )
935 SwRect aActRect( aRect );
936 Size aActSz( aRect.SSize() );
937 aRect.Pos().X() += rRec.nTol;
938 aRect.Pos().Y() += rRec.nTol;
939 aRect.SSize().Height()-= 2 * rRec.nTol;
940 aRect.SSize().Width() -= 2 * rRec.nTol;
942 if( aRect.IsInside( rRec.aPos ) )
944 if( !rURL.GetMap() ||
945 pFlyFrm->GetFmt()->GetIMapObject( rRec.aPos, pFlyFrm ))
946 return (SdrObject*)this;
948 return 0;
952 return SdrObject::CheckMacroHit( rRec );
955 bool SwVirtFlyDrawObj::supportsFullDrag() const
957 // call parent
958 return SdrVirtObj::supportsFullDrag();
961 SdrObject* SwVirtFlyDrawObj::getFullDragClone() const
963 // call parent
964 return SdrVirtObj::getFullDragClone();
967 // eof