1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/sdr/contact/viewcontactofsdrobj.hxx>
21 #include <svx/sdr/contact/viewobjectcontactofsdrobj.hxx>
22 #include <svx/sdr/contact/viewobjectcontact.hxx>
23 #include <svx/svdobj.hxx>
24 #include <svx/sdr/contact/displayinfo.hxx>
25 #include <vcl/outdev.hxx>
26 #include <svx/svdoole2.hxx>
27 #include <svx/svdpage.hxx>
28 #include <svx/sdr/contact/objectcontact.hxx>
29 #include <basegfx/color/bcolor.hxx>
30 #include <drawinglayer/primitive2d/markerarrayprimitive2d.hxx>
31 #include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
32 #include <sdr/contact/objectcontactofpageview.hxx>
33 #include <svx/sdrpagewindow.hxx>
34 #include <svx/sdrpaintwindow.hxx>
35 #include <svx/svdhdl.hxx>
36 #include <comphelper/sequence.hxx>
38 namespace sdr
{ namespace contact
{
40 // Create a Object-Specific ViewObjectContact, set ViewContact and
41 // ObjectContact. Always needs to return something.
42 ViewObjectContact
& ViewContactOfSdrObj::CreateObjectSpecificViewObjectContact(ObjectContact
& rObjectContact
)
44 ViewObjectContact
* pRetval
= new ViewObjectContactOfSdrObj(rObjectContact
, *this);
45 DBG_ASSERT(pRetval
, "ViewContactOfSdrObj::CreateObjectSpecificViewObjectContact() failed (!)");
50 ViewContactOfSdrObj::ViewContactOfSdrObj(SdrObject
& rObj
)
53 meRememberedAnimationKind(SdrTextAniKind::NONE
)
56 if(dynamic_cast<const SdrTextObj
*>( &GetSdrObject() ) != nullptr)
58 SdrTextObj
& rTextObj
= static_cast<SdrTextObj
&>(GetSdrObject());
59 meRememberedAnimationKind
= rTextObj
.GetTextAniKind();
63 ViewContactOfSdrObj::~ViewContactOfSdrObj()
67 // Access to possible sub-hierarchy
68 sal_uInt32
ViewContactOfSdrObj::GetObjectCount() const
70 if(GetSdrObject().GetSubList())
72 return GetSdrObject().GetSubList()->GetObjCount();
78 ViewContact
& ViewContactOfSdrObj::GetViewContact(sal_uInt32 nIndex
) const
80 assert(GetSdrObject().GetSubList() &&
81 "ViewContactOfSdrObj::GetViewContact: Access to non-existent Sub-List (!)");
82 SdrObject
* pObj
= GetSdrObject().GetSubList()->GetObj(nIndex
);
83 assert(pObj
&& "ViewContactOfSdrObj::GetViewContact: Corrupt SdrObjList (!)");
84 return pObj
->GetViewContact();
87 ViewContact
* ViewContactOfSdrObj::GetParentContact() const
89 ViewContact
* pRetval
= nullptr;
90 SdrObjList
* pObjList
= GetSdrObject().GetObjList();
94 if(dynamic_cast<const SdrPage
*>( pObjList
) != nullptr)
97 pRetval
= &(static_cast<SdrPage
*>(pObjList
)->GetViewContact());
102 if(pObjList
->GetOwnerObj())
104 pRetval
= &(pObjList
->GetOwnerObj()->GetViewContact());
112 // React on changes of the object of this ViewContact
113 void ViewContactOfSdrObj::ActionChanged()
115 // look for own changes
116 if(dynamic_cast<const SdrTextObj
*>( &GetSdrObject() ) != nullptr)
118 SdrTextObj
& rTextObj
= static_cast<SdrTextObj
&>(GetSdrObject());
120 if(rTextObj
.GetTextAniKind() != meRememberedAnimationKind
)
122 // #i38135# now remember new type
123 meRememberedAnimationKind
= rTextObj
.GetTextAniKind();
128 ViewContact::ActionChanged();
131 // override for accessing the SdrObject
132 SdrObject
* ViewContactOfSdrObj::TryToGetSdrObject() const
134 return &GetSdrObject();
140 // add Gluepoints (if available)
141 drawinglayer::primitive2d::Primitive2DContainer
ViewContactOfSdrObj::createGluePointPrimitive2DSequence() const
143 drawinglayer::primitive2d::Primitive2DContainer xRetval
;
144 const SdrGluePointList
* pGluePointList
= GetSdrObject().GetGluePointList();
148 const sal_uInt32
nCount(pGluePointList
->GetCount());
152 // prepare point vector
153 std::vector
< basegfx::B2DPoint
> aGluepointVector
;
155 // create GluePoint primitives. ATM these are relative to the SnapRect
156 for(sal_uInt32
a(0L); a
< nCount
; a
++)
158 const SdrGluePoint
& rCandidate
= (*pGluePointList
)[(sal_uInt16
)a
];
159 const Point
aPosition(rCandidate
.GetAbsolutePos(GetSdrObject()));
161 aGluepointVector
.push_back(basegfx::B2DPoint(aPosition
.X(), aPosition
.Y()));
164 if(!aGluepointVector
.empty())
166 const drawinglayer::primitive2d::Primitive2DReference
xReference(
167 new drawinglayer::primitive2d::MarkerArrayPrimitive2D(
168 aGluepointVector
, SdrHdl::createGluePointBitmap()));
169 xRetval
= drawinglayer::primitive2d::Primitive2DContainer
{ xReference
};
177 drawinglayer::primitive2d::Primitive2DContainer
ViewContactOfSdrObj::embedToObjectSpecificInformation(const drawinglayer::primitive2d::Primitive2DContainer
& rSource
) const
179 if(!rSource
.empty() &&
180 (!GetSdrObject().GetName().isEmpty() ||
181 !GetSdrObject().GetTitle().isEmpty() ||
182 !GetSdrObject().GetDescription().isEmpty()))
184 const drawinglayer::primitive2d::Primitive2DReference
xRef(
185 new drawinglayer::primitive2d::ObjectInfoPrimitive2D(
187 GetSdrObject().GetName(),
188 GetSdrObject().GetTitle(),
189 GetSdrObject().GetDescription()));
191 return drawinglayer::primitive2d::Primitive2DContainer
{ xRef
};
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */