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