xref: /AOO41X/main/svx/source/sdr/contact/viewcontactofsdrobj.cxx (revision b5697104d707bccaa4bcd2a9a325df3bef60684f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 #include <svx/sdr/contact/viewcontactofsdrobj.hxx>
27 #include <svx/sdr/contact/viewobjectcontactofsdrobj.hxx>
28 #include <svx/sdr/contact/viewobjectcontact.hxx>
29 #include <svx/svdobj.hxx>
30 #include <svx/sdr/contact/displayinfo.hxx>
31 #include <vcl/outdev.hxx>
32 #include <svx/svdoole2.hxx>
33 #include <svx/svdpage.hxx>
34 #include <svx/sdr/contact/objectcontact.hxx>
35 #include <basegfx/color/bcolor.hxx>
36 #include <drawinglayer/primitive2d/markerarrayprimitive2d.hxx>
37 #include <svx/sdr/contact/objectcontactofpageview.hxx>
38 #include <svx/sdrpagewindow.hxx>
39 #include <svx/sdrpaintwindow.hxx>
40 #include <svx/sdr/primitive2d/sdrprimitivetools.hxx>
41 #include <drawinglayer/primitive2d/objectinfoprimitive2d.hxx>
42 
43 //////////////////////////////////////////////////////////////////////////////
44 
45 namespace sdr
46 {
47     namespace contact
48     {
49         // Create a Object-Specific ViewObjectContact, set ViewContact and
50         // ObjectContact. Always needs to return something.
CreateObjectSpecificViewObjectContact(ObjectContact & rObjectContact)51         ViewObjectContact& ViewContactOfSdrObj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
52         {
53             ViewObjectContact* pRetval = new ViewObjectContactOfSdrObj(rObjectContact, *this);
54             DBG_ASSERT(pRetval, "ViewContactOfSdrObj::CreateObjectSpecificViewObjectContact() failed (!)");
55 
56             return *pRetval;
57         }
58 
ViewContactOfSdrObj(SdrObject & rObj)59         ViewContactOfSdrObj::ViewContactOfSdrObj(SdrObject& rObj)
60         :   ViewContact(),
61             mrObject(rObj),
62             meRememberedAnimationKind(SDRTEXTANI_NONE)
63         {
64             // init AnimationKind
65             if(GetSdrObject().ISA(SdrTextObj))
66             {
67                 SdrTextObj& rTextObj = (SdrTextObj&)GetSdrObject();
68                 meRememberedAnimationKind = rTextObj.GetTextAniKind();
69             }
70         }
71 
~ViewContactOfSdrObj()72         ViewContactOfSdrObj::~ViewContactOfSdrObj()
73         {
74         }
75 
76         // Access to possible sub-hierarchy
GetObjectCount() const77         sal_uInt32 ViewContactOfSdrObj::GetObjectCount() const
78         {
79             if(GetSdrObject().GetSubList())
80             {
81                 return GetSdrObject().GetSubList()->GetObjCount();
82             }
83 
84             return 0L;
85         }
86 
GetViewContact(sal_uInt32 nIndex) const87         ViewContact& ViewContactOfSdrObj::GetViewContact(sal_uInt32 nIndex) const
88         {
89             DBG_ASSERT(GetSdrObject().GetSubList(),
90                 "ViewContactOfSdrObj::GetViewContact: Access to non-existent Sub-List (!)");
91             SdrObject* pObj = GetSdrObject().GetSubList()->GetObj(nIndex);
92             DBG_ASSERT(pObj, "ViewContactOfSdrObj::GetViewContact: Corrupt SdrObjList (!)");
93             return pObj->GetViewContact();
94         }
95 
GetParentContact() const96         ViewContact* ViewContactOfSdrObj::GetParentContact() const
97         {
98             ViewContact* pRetval = 0L;
99             SdrObjList* pObjList = GetSdrObject().GetObjList();
100 
101             if(pObjList)
102             {
103                 if(pObjList->ISA(SdrPage))
104                 {
105                     // Is a page
106                     pRetval = &(((SdrPage*)pObjList)->GetViewContact());
107                 }
108                 else
109                 {
110                     // Is a group?
111                     if(pObjList->GetOwnerObj())
112                     {
113                         pRetval = &(pObjList->GetOwnerObj()->GetViewContact());
114                     }
115                 }
116             }
117 
118             return pRetval;
119         }
120 
121         // React on changes of the object of this ViewContact
ActionChanged()122         void ViewContactOfSdrObj::ActionChanged()
123         {
124             // look for own changes
125             if(GetSdrObject().ISA(SdrTextObj))
126             {
127                 SdrTextObj& rTextObj = (SdrTextObj&)GetSdrObject();
128 
129                 if(rTextObj.GetTextAniKind() != meRememberedAnimationKind)
130                 {
131                     // #i38135# now remember new type
132                     meRememberedAnimationKind = rTextObj.GetTextAniKind();
133                 }
134             }
135 
136             // call parent
137             ViewContact::ActionChanged();
138         }
139 
140         // overload for accessing the SdrObject
TryToGetSdrObject() const141         SdrObject* ViewContactOfSdrObj::TryToGetSdrObject() const
142         {
143             return &GetSdrObject();
144         }
145 
146         //////////////////////////////////////////////////////////////////////////////
147         // primitive stuff
148 
149         // add Gluepoints (if available)
createGluePointPrimitive2DSequence() const150         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrObj::createGluePointPrimitive2DSequence() const
151         {
152             drawinglayer::primitive2d::Primitive2DSequence xRetval;
153             const SdrGluePointList* pGluePointList = GetSdrObject().GetGluePointList();
154 
155             if(pGluePointList)
156             {
157                 const sal_uInt32 nCount(pGluePointList->GetCount());
158 
159                 if(nCount)
160                 {
161                     // prepare point vector
162                     std::vector< basegfx::B2DPoint > aGluepointVector;
163 
164                     // create GluePoint primitives. ATM these are relative to the SnapRect
165                     for(sal_uInt32 a(0L); a < nCount; a++)
166                     {
167                         const SdrGluePoint& rCandidate = (*pGluePointList)[(sal_uInt16)a];
168                         const Point aPosition(rCandidate.GetAbsolutePos(GetSdrObject()));
169 
170                         aGluepointVector.push_back(basegfx::B2DPoint(aPosition.X(), aPosition.Y()));
171                     }
172 
173                     if(!aGluepointVector.empty())
174                     {
175                         const basegfx::BColor aBackPen(1.0, 1.0, 1.0);
176                         const basegfx::BColor aRGBFrontColor(0.0, 0.0, 1.0); // COL_LIGHTBLUE
177                         const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::MarkerArrayPrimitive2D(
178                             aGluepointVector,
179                             drawinglayer::primitive2d::createDefaultGluepoint_9x9(aBackPen, aRGBFrontColor)));
180                         xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
181                     }
182                 }
183             }
184 
185             return xRetval;
186         }
187 
embedToObjectSpecificInformation(const drawinglayer::primitive2d::Primitive2DSequence & rSource) const188         drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrObj::embedToObjectSpecificInformation(const drawinglayer::primitive2d::Primitive2DSequence& rSource) const
189         {
190             if(rSource.hasElements() &&
191                 (GetSdrObject().GetName().Len() ||
192                 GetSdrObject().GetTitle().Len() ||
193                 GetSdrObject().GetDescription().Len()))
194             {
195                 const drawinglayer::primitive2d::Primitive2DReference xRef(
196                     new drawinglayer::primitive2d::ObjectInfoPrimitive2D(
197                         rSource,
198                         GetSdrObject().GetName(),
199                         GetSdrObject().GetTitle(),
200                         GetSdrObject().GetDescription()));
201 
202                 return drawinglayer::primitive2d::Primitive2DSequence(&xRef, 1);
203             }
204 
205             return rSource;
206         }
207 
208     } // end of namespace contact
209 } // end of namespace sdr
210 
211 //////////////////////////////////////////////////////////////////////////////
212 // eof
213