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 
42 //////////////////////////////////////////////////////////////////////////////
43 
44 namespace sdr
45 {
46 	namespace contact
47 	{
48 		// Create a Object-Specific ViewObjectContact, set ViewContact and
49 		// ObjectContact. Always needs to return something.
50 		ViewObjectContact& ViewContactOfSdrObj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
51 		{
52 			ViewObjectContact* pRetval = new ViewObjectContactOfSdrObj(rObjectContact, *this);
53 			DBG_ASSERT(pRetval, "ViewContactOfSdrObj::CreateObjectSpecificViewObjectContact() failed (!)");
54 
55 			return *pRetval;
56 		}
57 
58 		ViewContactOfSdrObj::ViewContactOfSdrObj(SdrObject& rObj)
59 		:	ViewContact(),
60 			mrObject(rObj),
61 			meRememberedAnimationKind(SDRTEXTANI_NONE)
62 		{
63 			// init AnimationKind
64 			if(GetSdrObject().ISA(SdrTextObj))
65 			{
66 				SdrTextObj& rTextObj = (SdrTextObj&)GetSdrObject();
67 				meRememberedAnimationKind = rTextObj.GetTextAniKind();
68 			}
69 		}
70 
71 		ViewContactOfSdrObj::~ViewContactOfSdrObj()
72 		{
73 		}
74 
75 		// Access to possible sub-hierarchy
76 		sal_uInt32 ViewContactOfSdrObj::GetObjectCount() const
77 		{
78 			if(GetSdrObject().GetSubList())
79 			{
80 				return GetSdrObject().GetSubList()->GetObjCount();
81 			}
82 
83 			return 0L;
84 		}
85 
86 		ViewContact& ViewContactOfSdrObj::GetViewContact(sal_uInt32 nIndex) const
87 		{
88 			DBG_ASSERT(GetSdrObject().GetSubList(),
89 				"ViewContactOfSdrObj::GetViewContact: Access to non-existent Sub-List (!)");
90 			SdrObject* pObj = GetSdrObject().GetSubList()->GetObj(nIndex);
91 			DBG_ASSERT(pObj, "ViewContactOfSdrObj::GetViewContact: Corrupt SdrObjList (!)");
92 			return pObj->GetViewContact();
93 		}
94 
95 		ViewContact* ViewContactOfSdrObj::GetParentContact() const
96 		{
97 			ViewContact* pRetval = 0L;
98 			SdrObjList* pObjList = GetSdrObject().GetObjList();
99 
100 			if(pObjList)
101 			{
102 				if(pObjList->ISA(SdrPage))
103 				{
104 					// Is a page
105 					pRetval = &(((SdrPage*)pObjList)->GetViewContact());
106 				}
107 				else
108 				{
109 					// Is a group?
110 					if(pObjList->GetOwnerObj())
111 					{
112 						pRetval = &(pObjList->GetOwnerObj()->GetViewContact());
113 					}
114 				}
115 			}
116 
117 			return pRetval;
118 		}
119 
120 		// React on changes of the object of this ViewContact
121 		void ViewContactOfSdrObj::ActionChanged()
122 		{
123 			// look for own changes
124 			if(GetSdrObject().ISA(SdrTextObj))
125 			{
126 				SdrTextObj& rTextObj = (SdrTextObj&)GetSdrObject();
127 
128 				if(rTextObj.GetTextAniKind() != meRememberedAnimationKind)
129 				{
130 					// #i38135# now remember new type
131 					meRememberedAnimationKind = rTextObj.GetTextAniKind();
132 				}
133 			}
134 
135 			// call parent
136 			ViewContact::ActionChanged();
137 		}
138 
139 		// overload for acessing the SdrObject
140 		SdrObject* ViewContactOfSdrObj::TryToGetSdrObject() const
141 		{
142 			return &GetSdrObject();
143 		}
144 
145 		//////////////////////////////////////////////////////////////////////////////
146 		// primitive stuff
147 
148 		// add Gluepoints (if available)
149 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrObj::createGluePointPrimitive2DSequence() const
150 		{
151 			drawinglayer::primitive2d::Primitive2DSequence xRetval;
152 			const SdrGluePointList* pGluePointList = GetSdrObject().GetGluePointList();
153 
154 			if(pGluePointList)
155 			{
156 				const sal_uInt32 nCount(pGluePointList->GetCount());
157 
158 				if(nCount)
159 				{
160 					// prepare point vector
161 					std::vector< basegfx::B2DPoint > aGluepointVector;
162 
163 					// create GluePoint primitives. ATM these are relative to the SnapRect
164 					for(sal_uInt32 a(0L); a < nCount; a++)
165 					{
166 						const SdrGluePoint& rCandidate = (*pGluePointList)[(sal_uInt16)a];
167 						const Point aPosition(rCandidate.GetAbsolutePos(GetSdrObject()));
168 
169 						aGluepointVector.push_back(basegfx::B2DPoint(aPosition.X(), aPosition.Y()));
170 					}
171 
172 					if(!aGluepointVector.empty())
173 					{
174 						const basegfx::BColor aBackPen(1.0, 1.0, 1.0);
175 						const basegfx::BColor aRGBFrontColor(0.0, 0.0, 1.0); // COL_LIGHTBLUE
176 						const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::MarkerArrayPrimitive2D(
177 							aGluepointVector,
178 							drawinglayer::primitive2d::createDefaultGluepoint_7x7(aBackPen, aRGBFrontColor)));
179                         xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
180 					}
181 				}
182 			}
183 
184 			return xRetval;
185 		}
186 	} // end of namespace contact
187 } // end of namespace sdr
188 
189 //////////////////////////////////////////////////////////////////////////////
190 // eof
191