LibreOffice Module svx (master)  1
viewcontact.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
25 #include <basegfx/color/bcolor.hxx>
29 #include <tools/debug.hxx>
30 
31 namespace sdr { namespace contact {
32 
33 // Create an Object-Specific ViewObjectContact, set ViewContact and
34 // ObjectContact. Always needs to return something. Default is to create
35 // a standard ViewObjectContact containing the given ObjectContact and *this
37 {
38  return *(new ViewObjectContact(rObjectContact, *this));
39 }
40 
42 : maViewObjectContactVector(),
43  mxViewIndependentPrimitive2DSequence()
44 {
45 }
46 
48 {
49  deleteAllVOCs();
50 }
51 
53 {
54  // get rid of all VOCs
55  // #i84257# To avoid that each 'delete pCandidate' again uses
56  // the local RemoveViewObjectContact with a search and removal in the
57  // vector, simply copy and clear local vector.
58  std::vector< ViewObjectContact* > aLocalVOCList;
59  aLocalVOCList.swap(maViewObjectContactVector);
60 
61  for (const auto & pCandidate : aLocalVOCList)
62  // ViewObjectContacts only make sense with View and Object contacts.
63  // When the contact to the SdrObject is deleted like in this case,
64  // all ViewObjectContacts can be deleted, too.
65  delete pCandidate;
66 
67  // assert when there were new entries added during deletion
68  DBG_ASSERT(maViewObjectContactVector.empty(), "Corrupted ViewObjectContactList in VC (!)");
69 }
70 
71 // get an Object-specific ViewObjectContact for a specific
72 // ObjectContact (->View). Always needs to return something.
74 {
75  ViewObjectContact* pRetval = nullptr;
76  const sal_uInt32 nCount(maViewObjectContactVector.size());
77 
78  // first search if there exists a VOC for the given OC
79  for(sal_uInt32 a(0); !pRetval && a < nCount; a++)
80  {
82  DBG_ASSERT(pCandidate, "Corrupted ViewObjectContactList (!)");
83 
84  if(&(pCandidate->GetObjectContact()) == &rObjectContact)
85  {
86  pRetval = pCandidate;
87  }
88  }
89 
90  if(!pRetval)
91  {
92  // create a new one. It's inserted to the local list from the
93  // ViewObjectContact constructor via AddViewObjectContact()
94  pRetval = &CreateObjectSpecificViewObjectContact(rObjectContact);
95  }
96 
97  return *pRetval;
98 }
99 
100 // A new ViewObjectContact was created and shall be remembered.
102 {
103  maViewObjectContactVector.push_back(&rVOContact);
104 }
105 
106 // A ViewObjectContact was deleted and shall be forgotten.
108 {
109  std::vector< ViewObjectContact* >::iterator aFindResult = std::find(maViewObjectContactVector.begin(), maViewObjectContactVector.end(), &rVOContact);
110 
111  if(aFindResult != maViewObjectContactVector.end())
112  {
113  maViewObjectContactVector.erase(aFindResult);
114  }
115 }
116 
117 // Test if this ViewContact has ViewObjectContacts at all. This can
118 // be used to test if this ViewContact is visualized ATM or not
120 {
121  const sal_uInt32 nCount(maViewObjectContactVector.size());
122 
123  for(sal_uInt32 a(0); a < nCount; a++)
124  {
125  if(!maViewObjectContactVector[a]->GetObjectContact().IsPreviewRenderer())
126  {
127  return true;
128  }
129  }
130  return false;
131 }
132 
133 // Test if this ViewContact has ViewObjectContacts at all. This can
134 // be used to test if this ViewContact is visualized ATM or not
136 {
137  const sal_uInt32 nCount(maViewObjectContactVector.size());
138 
139  for(sal_uInt32 a(0); a < nCount; a++)
140  {
141  if(maViewObjectContactVector[a]->isAnimated())
142  {
143  return true;
144  }
145  }
146 
147  return false;
148 }
149 
150 // Access to possible sub-hierarchy and parent. GetObjectCount() default is 0L
151 // and GetViewContact default pops up an assert since it's an error if
152 // GetObjectCount has a result != 0 and it's not overridden.
153 sal_uInt32 ViewContact::GetObjectCount() const
154 {
155  // no sub-objects
156  return 0;
157 }
158 
159 ViewContact& ViewContact::GetViewContact(sal_uInt32 /*nIndex*/) const
160 {
161  // This is the default implementation; call would be an error
162  OSL_FAIL("ViewContact::GetViewContact: This call needs to be overridden when GetObjectCount() can return results != 0 (!)");
163  return const_cast<ViewContact&>(*this);
164 }
165 
167 {
168  // default has no parent
169  return nullptr;
170 }
171 
173 {
174  // propagate change to all existing visualisations which
175  // will force a VOC for the new child and invalidate its range
176  const sal_uInt32 nCount(maViewObjectContactVector.size());
177 
178  for(sal_uInt32 a(0); a < nCount; a++)
179  {
181  DBG_ASSERT(pCandidate, "ViewContact::GetViewObjectContact() invalid ViewObjectContactList (!)");
182 
183  // take action at all VOCs. At the VOCs ObjectContact the initial
184  // rectangle will be invalidated at the associated OutputDevice.
185  pCandidate->ActionChildInserted(rChild);
186  }
187 }
188 
189 // React on changes of the object of this ViewContact
191 {
192  // propagate change to all existing VOCs. This will invalidate
193  // all drawn visualisations in all known views
194  const sal_uInt32 nCount(maViewObjectContactVector.size());
195 
196  for(sal_uInt32 a(0); a < nCount; a++)
197  {
199  DBG_ASSERT(pCandidate, "ViewContact::GetViewObjectContact() invalid ViewObjectContactList (!)");
200 
201  pCandidate->ActionChanged();
202  }
203 }
204 
205 // access to SdrObject and/or SdrPage. May return 0L like the default
206 // implementations do. Override as needed.
208 {
209  return nullptr;
210 }
211 
212 // primitive stuff
213 
215 {
216  // This is the default implementation and should never be called (see header). If this is called,
217  // someone implemented a ViewContact (VC) visualisation object without defining the visualisation by
218  // providing a sequence of primitives -> which cannot be correct.
219  // Since we have no access to any known model data here, the default implementation creates a yellow placeholder
220  // hairline polygon with a default size of (1000, 1000, 5000, 3000)
221  OSL_FAIL("ViewContact::createViewIndependentPrimitive2DSequence(): Never call the fallback base implementation, this is always an error (!)");
222  const basegfx::B2DPolygon aOutline(basegfx::utils::createPolygonFromRect(basegfx::B2DRange(1000.0, 1000.0, 5000.0, 3000.0)));
223  const basegfx::BColor aYellow(1.0, 1.0, 0.0);
226 
228 }
229 
231 {
232  // local up-to-date checks. Create new list and compare.
234 
235  if(!xNew.empty())
236  {
237  // allow evtl. embedding in object-specific infos, e.g. Name, Title, Description
238  xNew = embedToObjectSpecificInformation(std::move(xNew));
239  }
240 
242  {
243  // has changed, copy content
244  const_cast< ViewContact* >(this)->mxViewIndependentPrimitive2DSequence = std::move(xNew);
245  }
246 
247  // return current Primitive2DContainer
249 }
250 
251 // add Gluepoints (if available)
253 {
254  // default returns empty reference
256 }
257 
259 {
260  // nothing to do for default
261  return aSource;
262 }
263 
265 {
266  // Return empty range.
267  return basegfx::B2DRange();
268 }
269 
270 void ViewContact::flushViewObjectContacts(bool bWithHierarchy)
271 {
272  if(bWithHierarchy)
273  {
274  // flush DrawingLayer hierarchy
275  const sal_uInt32 nCount(GetObjectCount());
276 
277  for(sal_uInt32 a(0); a < nCount; a++)
278  {
279  ViewContact& rChild = GetViewContact(a);
280  rChild.flushViewObjectContacts(bWithHierarchy);
281  }
282  }
283 
284  // delete local VOCs
285  deleteAllVOCs();
286 }
287 
288 }}
289 
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void ActionChildInserted(ViewContact &rChild)
virtual ViewContact * GetParentContact() const
virtual SdrObject * TryToGetSdrObject() const
bool isAnimatedInAnyViewObjectContact() const
friend class ViewObjectContact
Definition: viewcontact.hxx:41
ViewObjectContact & GetViewObjectContact(ObjectContact &rObjectContact)
Definition: viewcontact.cxx:73
virtual drawinglayer::primitive2d::Primitive2DContainer createGluePointPrimitive2DSequence() const
virtual basegfx::B2DRange getRange(const drawinglayer::geometry::ViewInformation2D &rViewInfo2D) const
void AddViewObjectContact(ViewObjectContact &rVOContact)
int nCount
ObjectContact & GetObjectContact() const
bool HasViewObjectContacts() const
#define DBG_ASSERT(sCon, aError)
uno_Any a
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
virtual ViewObjectContact & CreateObjectSpecificViewObjectContact(ObjectContact &rObjectContact)
Definition: viewcontact.cxx:36
void flushViewObjectContacts(bool bWithHierarchy=true)
Abstract DrawObject.
Definition: svdobj.hxx:312
virtual void ActionChanged()
virtual drawinglayer::primitive2d::Primitive2DContainer createViewIndependentPrimitive2DSequence() const
void ActionChildInserted(ViewContact &rChild)
virtual sal_uInt32 GetObjectCount() const
std::vector< ViewObjectContact * > maViewObjectContactVector
Definition: viewcontact.hxx:47
drawinglayer::primitive2d::Primitive2DContainer const & getViewIndependentPrimitive2DContainer() const
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
virtual ViewContact & GetViewContact(sal_uInt32 nIndex) const
void RemoveViewObjectContact(ViewObjectContact &rVOContact)
virtual drawinglayer::primitive2d::Primitive2DContainer embedToObjectSpecificInformation(drawinglayer::primitive2d::Primitive2DContainer rSource) const
drawinglayer::primitive2d::Primitive2DContainer mxViewIndependentPrimitive2DSequence
Definition: viewcontact.hxx:52