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