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