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