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 <tools/debug.hxx>
25 #include <svx/svdpage.hxx>
26 #include <svx/sdr/contact/objectcontact.hxx>
27 #include <drawinglayer/primitive2d/markerarrayprimitive2d.hxx>
28 #include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
29 #include <svx/svdhdl.hxx>
31 namespace sdr::contact
{
33 // Create an Object-Specific ViewObjectContact, set ViewContact and
34 // ObjectContact. Always needs to return something.
35 ViewObjectContact
& ViewContactOfSdrObj::CreateObjectSpecificViewObjectContact(ObjectContact
& rObjectContact
)
37 ViewObjectContact
* pRetval
= new ViewObjectContactOfSdrObj(rObjectContact
, *this);
38 DBG_ASSERT(pRetval
, "ViewContactOfSdrObj::CreateObjectSpecificViewObjectContact() failed (!)");
43 ViewContactOfSdrObj::ViewContactOfSdrObj(SdrObject
& rObj
)
48 ViewContactOfSdrObj::~ViewContactOfSdrObj()
52 // Access to possible sub-hierarchy
53 sal_uInt32
ViewContactOfSdrObj::GetObjectCount() const
55 if(GetSdrObject().GetSubList())
57 return GetSdrObject().GetSubList()->GetObjCount();
63 ViewContact
& ViewContactOfSdrObj::GetViewContact(sal_uInt32 nIndex
) const
65 assert(GetSdrObject().GetSubList() &&
66 "ViewContactOfSdrObj::GetViewContact: Access to non-existent Sub-List (!)");
67 SdrObject
* pObj
= GetSdrObject().GetSubList()->GetObj(nIndex
);
68 assert(pObj
&& "ViewContactOfSdrObj::GetViewContact: Corrupt SdrObjList (!)");
69 return pObj
->GetViewContact();
72 ViewContact
* ViewContactOfSdrObj::GetParentContact() const
74 ViewContact
* pRetval
= nullptr;
75 SdrObjList
* pObjList
= GetSdrObject().getParentSdrObjListFromSdrObject();
79 if(auto pPage
= dynamic_cast<SdrPage
*>( pObjList
))
82 pRetval
= &(pPage
->GetViewContact());
87 if(pObjList
->getSdrObjectFromSdrObjList())
89 pRetval
= &(pObjList
->getSdrObjectFromSdrObjList()->GetViewContact());
97 // React on changes of the object of this ViewContact
98 void ViewContactOfSdrObj::ActionChanged()
100 // look for own changes
101 if (SdrTextObj
* pTextObj
= DynCastSdrTextObj(&GetSdrObject()))
103 // tdf#146860 no idea why, but calling this makes the text boxes render properly
104 pTextObj
->GetTextAniKind();
108 ViewContact::ActionChanged();
111 // override for accessing the SdrObject
112 SdrObject
* ViewContactOfSdrObj::TryToGetSdrObject() const
114 return &GetSdrObject();
120 // add Gluepoints (if available)
121 drawinglayer::primitive2d::Primitive2DContainer
ViewContactOfSdrObj::createGluePointPrimitive2DSequence() const
123 drawinglayer::primitive2d::Primitive2DContainer xRetval
;
124 const SdrGluePointList
* pGluePointList
= GetSdrObject().GetGluePointList();
128 const sal_uInt32
nCount(pGluePointList
->GetCount());
132 // prepare point vector
133 std::vector
< basegfx::B2DPoint
> aGluepointVector
;
135 // create GluePoint primitives. ATM these are relative to the SnapRect
136 for(sal_uInt32
a(0); a
< nCount
; a
++)
138 const SdrGluePoint
& rCandidate
= (*pGluePointList
)[static_cast<sal_uInt16
>(a
)];
139 const Point
aPosition(rCandidate
.GetAbsolutePos(GetSdrObject()));
141 aGluepointVector
.emplace_back(aPosition
.X(), aPosition
.Y());
144 if(!aGluepointVector
.empty())
146 const drawinglayer::primitive2d::Primitive2DReference
xReference(
147 new drawinglayer::primitive2d::MarkerArrayPrimitive2D(
148 std::move(aGluepointVector
), SdrHdl::createGluePointBitmap()));
149 xRetval
= drawinglayer::primitive2d::Primitive2DContainer
{ xReference
};
157 drawinglayer::primitive2d::Primitive2DContainer
ViewContactOfSdrObj::embedToObjectSpecificInformation(drawinglayer::primitive2d::Primitive2DContainer aSource
) const
159 if(!aSource
.empty() &&
160 (!GetSdrObject().GetName().isEmpty() ||
161 !GetSdrObject().GetTitle().isEmpty() ||
162 !GetSdrObject().GetDescription().isEmpty()))
164 const drawinglayer::primitive2d::Primitive2DReference
xRef(
165 new drawinglayer::primitive2d::ObjectInfoPrimitive2D(
167 GetSdrObject().GetName(),
168 GetSdrObject().GetTitle(),
169 GetSdrObject().GetDescription()));
171 return drawinglayer::primitive2d::Primitive2DContainer
{ xRef
};
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */