1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 #include <svx/sdr/contact/viewcontactofsdrobj.hxx>
31 #include <svx/sdr/contact/viewobjectcontactofsdrobj.hxx>
32 #include <svx/sdr/contact/viewobjectcontact.hxx>
33 #include <svx/svdobj.hxx>
34 #include <svx/sdr/contact/displayinfo.hxx>
35 #include <vcl/outdev.hxx>
36 #include <svx/svdoole2.hxx>
37 #include <svx/svdpage.hxx>
38 #include <svx/sdr/contact/objectcontact.hxx>
39 #include <basegfx/color/bcolor.hxx>
40 #include <drawinglayer/primitive2d/markerarrayprimitive2d.hxx>
41 #include <svx/sdr/contact/objectcontactofpageview.hxx>
42 #include <svx/sdrpagewindow.hxx>
43 #include <svx/sdrpaintwindow.hxx>
44 #include <svx/sdr/primitive2d/sdrprimitivetools.hxx>
45 
46 //////////////////////////////////////////////////////////////////////////////
47 
48 namespace sdr
49 {
50 	namespace contact
51 	{
52 		// Create a Object-Specific ViewObjectContact, set ViewContact and
53 		// ObjectContact. Always needs to return something.
54 		ViewObjectContact& ViewContactOfSdrObj::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
55 		{
56 			ViewObjectContact* pRetval = new ViewObjectContactOfSdrObj(rObjectContact, *this);
57 			DBG_ASSERT(pRetval, "ViewContactOfSdrObj::CreateObjectSpecificViewObjectContact() failed (!)");
58 
59 			return *pRetval;
60 		}
61 
62 		ViewContactOfSdrObj::ViewContactOfSdrObj(SdrObject& rObj)
63 		:	ViewContact(),
64 			mrObject(rObj),
65 			meRememberedAnimationKind(SDRTEXTANI_NONE)
66 		{
67 			// init AnimationKind
68 			if(GetSdrObject().ISA(SdrTextObj))
69 			{
70 				SdrTextObj& rTextObj = (SdrTextObj&)GetSdrObject();
71 				meRememberedAnimationKind = rTextObj.GetTextAniKind();
72 			}
73 		}
74 
75 		ViewContactOfSdrObj::~ViewContactOfSdrObj()
76 		{
77 		}
78 
79 		// Access to possible sub-hierarchy
80 		sal_uInt32 ViewContactOfSdrObj::GetObjectCount() const
81 		{
82 			if(GetSdrObject().GetSubList())
83 			{
84 				return GetSdrObject().GetSubList()->GetObjCount();
85 			}
86 
87 			return 0L;
88 		}
89 
90 		ViewContact& ViewContactOfSdrObj::GetViewContact(sal_uInt32 nIndex) const
91 		{
92 			DBG_ASSERT(GetSdrObject().GetSubList(),
93 				"ViewContactOfSdrObj::GetViewContact: Access to non-existent Sub-List (!)");
94 			SdrObject* pObj = GetSdrObject().GetSubList()->GetObj(nIndex);
95 			DBG_ASSERT(pObj, "ViewContactOfSdrObj::GetViewContact: Corrupt SdrObjList (!)");
96 			return pObj->GetViewContact();
97 		}
98 
99 		ViewContact* ViewContactOfSdrObj::GetParentContact() const
100 		{
101 			ViewContact* pRetval = 0L;
102 			SdrObjList* pObjList = GetSdrObject().GetObjList();
103 
104 			if(pObjList)
105 			{
106 				if(pObjList->ISA(SdrPage))
107 				{
108 					// Is a page
109 					pRetval = &(((SdrPage*)pObjList)->GetViewContact());
110 				}
111 				else
112 				{
113 					// Is a group?
114 					if(pObjList->GetOwnerObj())
115 					{
116 						pRetval = &(pObjList->GetOwnerObj()->GetViewContact());
117 					}
118 				}
119 			}
120 
121 			return pRetval;
122 		}
123 
124 		// React on changes of the object of this ViewContact
125 		void ViewContactOfSdrObj::ActionChanged()
126 		{
127 			// look for own changes
128 			if(GetSdrObject().ISA(SdrTextObj))
129 			{
130 				SdrTextObj& rTextObj = (SdrTextObj&)GetSdrObject();
131 
132 				if(rTextObj.GetTextAniKind() != meRememberedAnimationKind)
133 				{
134 					// #i38135# now remember new type
135 					meRememberedAnimationKind = rTextObj.GetTextAniKind();
136 				}
137 			}
138 
139 			// call parent
140 			ViewContact::ActionChanged();
141 		}
142 
143 		// overload for acessing the SdrObject
144 		SdrObject* ViewContactOfSdrObj::TryToGetSdrObject() const
145 		{
146 			return &GetSdrObject();
147 		}
148 
149 		//////////////////////////////////////////////////////////////////////////////
150 		// primitive stuff
151 
152 		// add Gluepoints (if available)
153 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrObj::createGluePointPrimitive2DSequence() const
154 		{
155 			drawinglayer::primitive2d::Primitive2DSequence xRetval;
156 			const SdrGluePointList* pGluePointList = GetSdrObject().GetGluePointList();
157 
158 			if(pGluePointList)
159 			{
160 				const sal_uInt32 nCount(pGluePointList->GetCount());
161 
162 				if(nCount)
163 				{
164 					// prepare point vector
165 					std::vector< basegfx::B2DPoint > aGluepointVector;
166 
167 					// create GluePoint primitives. ATM these are relative to the SnapRect
168 					for(sal_uInt32 a(0L); a < nCount; a++)
169 					{
170 						const SdrGluePoint& rCandidate = (*pGluePointList)[(sal_uInt16)a];
171 						const Point aPosition(rCandidate.GetAbsolutePos(GetSdrObject()));
172 
173 						aGluepointVector.push_back(basegfx::B2DPoint(aPosition.X(), aPosition.Y()));
174 					}
175 
176 					if(!aGluepointVector.empty())
177 					{
178 						const basegfx::BColor aBackPen(1.0, 1.0, 1.0);
179 						const basegfx::BColor aRGBFrontColor(0.0, 0.0, 1.0); // COL_LIGHTBLUE
180 						const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::MarkerArrayPrimitive2D(
181 							aGluepointVector,
182 							drawinglayer::primitive2d::createDefaultGluepoint_7x7(aBackPen, aRGBFrontColor)));
183                         xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
184 					}
185 				}
186 			}
187 
188 			return xRetval;
189 		}
190 	} // end of namespace contact
191 } // end of namespace sdr
192 
193 //////////////////////////////////////////////////////////////////////////////
194 // eof
195