fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / sdr / contact / viewcontact.cxx
blobff89ac6eaf39e004de335389f704f7252c3f839b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/sdr/contact/viewcontact.hxx>
21 #include <svx/sdr/contact/viewobjectcontact.hxx>
22 #include <svx/sdr/contact/objectcontact.hxx>
23 #include <basegfx/polygon/b2dpolygon.hxx>
24 #include <basegfx/polygon/b2dpolygontools.hxx>
25 #include <basegfx/color/bcolor.hxx>
26 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
27 #include <basegfx/matrix/b2dhommatrix.hxx>
28 #include <svx/sdr/contact/objectcontactofpageview.hxx>
29 #include <tools/debug.hxx>
31 //////////////////////////////////////////////////////////////////////////////
33 namespace sdr
35 namespace contact
37 // Create a Object-Specific ViewObjectContact, set ViewContact and
38 // ObjectContact. Always needs to return something. Default is to create
39 // a standard ViewObjectContact containing the given ObjectContact and *this
40 ViewObjectContact& ViewContact::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
42 return *(new ViewObjectContact(rObjectContact, *this));
45 ViewContact::ViewContact()
46 : maViewObjectContactVector(),
47 mxViewIndependentPrimitive2DSequence()
51 // Methods to react on start getting viewed or stop getting
52 // viewed. This info is derived from the count of members of
53 // registered ViewObjectContacts. Default does nothing.
54 void ViewContact::StartGettingViewed()
58 void ViewContact::StopGettingViewed()
62 ViewContact::~ViewContact()
64 deleteAllVOCs();
67 void ViewContact::deleteAllVOCs()
69 // get rid of all VOCs
70 // #i84257# To avoid that each 'delete pCandidate' again uses
71 // the local RemoveViewObjectContact with a search and removal in the
72 // vector, simply copy and clear local vector.
73 std::vector< ViewObjectContact* > aLocalVOCList(maViewObjectContactVector);
74 maViewObjectContactVector.clear();
76 while(!aLocalVOCList.empty())
78 ViewObjectContact* pCandidate = aLocalVOCList.back();
79 aLocalVOCList.pop_back();
80 DBG_ASSERT(pCandidate, "Corrupted ViewObjectContactList in VC (!)");
82 // ViewObjectContacts only make sense with View and Object contacts.
83 // When the contact to the SdrObject is deleted like in this case,
84 // all ViewObjectContacts can be deleted, too.
85 delete pCandidate;
88 // assert when there were new entries added during deletion
89 DBG_ASSERT(maViewObjectContactVector.empty(), "Corrupted ViewObjectContactList in VC (!)");
92 // get a Object-specific ViewObjectContact for a specific
93 // ObjectContact (->View). Always needs to return something.
94 ViewObjectContact& ViewContact::GetViewObjectContact(ObjectContact& rObjectContact)
96 ViewObjectContact* pRetval = 0L;
97 const sal_uInt32 nCount(maViewObjectContactVector.size());
99 // first search if there exists a VOC for the given OC
100 for(sal_uInt32 a(0); !pRetval && a < nCount; a++)
102 ViewObjectContact* pCandidate = maViewObjectContactVector[a];
103 DBG_ASSERT(pCandidate, "Corrupted ViewObjectContactList (!)");
105 if(&(pCandidate->GetObjectContact()) == &rObjectContact)
107 pRetval = pCandidate;
111 if(!pRetval)
113 // create a new one. It's inserted to the local list from the
114 // ViewObjectContact constructor via AddViewObjectContact()
115 pRetval = &CreateObjectSpecificViewObjectContact(rObjectContact);
118 return *pRetval;
121 // A new ViewObjectContact was created and shall be remembered.
122 void ViewContact::AddViewObjectContact(ViewObjectContact& rVOContact)
124 maViewObjectContactVector.push_back(&rVOContact);
126 if(1L == maViewObjectContactVector.size())
128 StartGettingViewed();
132 // A ViewObjectContact was deleted and shall be forgotten.
133 void ViewContact::RemoveViewObjectContact(ViewObjectContact& rVOContact)
135 std::vector< ViewObjectContact* >::iterator aFindResult = std::find(maViewObjectContactVector.begin(), maViewObjectContactVector.end(), &rVOContact);
137 if(aFindResult != maViewObjectContactVector.end())
139 maViewObjectContactVector.erase(aFindResult);
141 if(maViewObjectContactVector.empty())
143 // This may need to get asynchron later since it eventually triggers
144 // deletes of OCs where the VOC is still added.
145 StopGettingViewed();
150 // Test if this ViewContact has ViewObjectContacts at all. This can
151 // be used to test if this ViewContact is visualized ATM or not
152 bool ViewContact::HasViewObjectContacts(bool bExcludePreviews) const
154 const sal_uInt32 nCount(maViewObjectContactVector.size());
156 if(bExcludePreviews)
158 for(sal_uInt32 a(0); a < nCount; a++)
160 if(!maViewObjectContactVector[a]->GetObjectContact().IsPreviewRenderer())
162 return true;
166 return false;
168 else
170 return (0L != nCount);
174 // Test if this ViewContact has ViewObjectContacts at all. This can
175 // be used to test if this ViewContact is visualized ATM or not
176 bool ViewContact::isAnimatedInAnyViewObjectContact() const
178 const sal_uInt32 nCount(maViewObjectContactVector.size());
180 for(sal_uInt32 a(0); a < nCount; a++)
182 if(maViewObjectContactVector[a]->isAnimated())
184 return true;
188 return false;
191 // Access to possible sub-hierarchy and parent. GetObjectCount() default is 0L
192 // and GetViewContact default pops up an assert since it's an error if
193 // GetObjectCount has a result != 0 and it's not overloaded.
194 sal_uInt32 ViewContact::GetObjectCount() const
196 // no sub-objects
197 return 0;
200 ViewContact& ViewContact::GetViewContact(sal_uInt32 /*nIndex*/) const
202 // This is the default implementation; call would be an error
203 OSL_FAIL("ViewContact::GetViewContact: This call needs to be overloaded when GetObjectCount() can return results != 0 (!)");
204 return (ViewContact&)(*this);
207 ViewContact* ViewContact::GetParentContact() const
209 // default has no parent
210 return 0;
213 void ViewContact::ActionChildInserted(ViewContact& rChild)
215 // propagate change to all exsisting visualisations which
216 // will force a VOC for the new child and invalidate it's range
217 const sal_uInt32 nCount(maViewObjectContactVector.size());
219 for(sal_uInt32 a(0); a < nCount; a++)
221 ViewObjectContact* pCandidate = maViewObjectContactVector[a];
222 DBG_ASSERT(pCandidate, "ViewContact::GetViewObjectContact() invalid ViewObjectContactList (!)");
224 // take action at all VOCs. At the VOCs ObjectContact the initial
225 // rectangle will be invalidated at the associated OutputDevice.
226 pCandidate->ActionChildInserted(rChild);
230 // React on changes of the object of this ViewContact
231 void ViewContact::ActionChanged()
233 // propagate change to all existing VOCs. This will invalidate
234 // all drawn visualisations in all known views
235 const sal_uInt32 nCount(maViewObjectContactVector.size());
237 for(sal_uInt32 a(0); a < nCount; a++)
239 ViewObjectContact* pCandidate = maViewObjectContactVector[a];
240 DBG_ASSERT(pCandidate, "ViewContact::GetViewObjectContact() invalid ViewObjectContactList (!)");
242 pCandidate->ActionChanged();
246 // access to SdrObject and/or SdrPage. May return 0L like the default
247 // implementations do. Needs to be overloaded as needed.
248 SdrObject* ViewContact::TryToGetSdrObject() const
250 return 0L;
253 SdrPage* ViewContact::TryToGetSdrPage() const
255 return 0L;
258 //////////////////////////////////////////////////////////////////////////////
259 // primitive stuff
261 drawinglayer::primitive2d::Primitive2DSequence ViewContact::createViewIndependentPrimitive2DSequence() const
263 // This is the default implementation and should never be called (see header). If this is called,
264 // someone implemented a ViewContact (VC) visualisation object without defining the visualisation by
265 // providing a seqence of primitives -> which cannot be correct.
266 // Since we have no access to any known model data here, the default implementation creates a yellow placeholder
267 // hairline polygon with a default size of (1000, 1000, 5000, 3000)
268 OSL_FAIL("ViewContact::createViewIndependentPrimitive2DSequence(): Never call the fallback base implementation, this is always an error (!)");
269 const basegfx::B2DPolygon aOutline(basegfx::tools::createPolygonFromRect(basegfx::B2DRange(1000.0, 1000.0, 5000.0, 3000.0)));
270 const basegfx::BColor aYellow(1.0, 1.0, 0.0);
271 const drawinglayer::primitive2d::Primitive2DReference xReference(
272 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aOutline, aYellow));
274 return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
277 drawinglayer::primitive2d::Primitive2DSequence ViewContact::getViewIndependentPrimitive2DSequence() const
279 // local up-to-date checks. Create new list and compare.
280 drawinglayer::primitive2d::Primitive2DSequence xNew(createViewIndependentPrimitive2DSequence());
282 if(xNew.hasElements())
284 // allow evtl. embedding in object-specific infos, e.g. Name, Title, Description
285 xNew = embedToObjectSpecificInformation(xNew);
288 if(!drawinglayer::primitive2d::arePrimitive2DSequencesEqual(mxViewIndependentPrimitive2DSequence, xNew))
290 // has changed, copy content
291 const_cast< ViewContact* >(this)->mxViewIndependentPrimitive2DSequence = xNew;
294 // return current Primitive2DSequence
295 return mxViewIndependentPrimitive2DSequence;
298 // add Gluepoints (if available)
299 drawinglayer::primitive2d::Primitive2DSequence ViewContact::createGluePointPrimitive2DSequence() const
301 // default returns empty reference
302 return drawinglayer::primitive2d::Primitive2DSequence();
305 drawinglayer::primitive2d::Primitive2DSequence ViewContact::embedToObjectSpecificInformation(const drawinglayer::primitive2d::Primitive2DSequence& rSource) const
307 // nothing to do for default
308 return rSource;
311 void ViewContact::flushViewObjectContacts(bool bWithHierarchy)
313 if(bWithHierarchy)
315 // flush DrawingLayer hierarchy
316 const sal_uInt32 nCount(GetObjectCount());
318 for(sal_uInt32 a(0); a < nCount; a++)
320 ViewContact& rChild = GetViewContact(a);
321 rChild.flushViewObjectContacts(bWithHierarchy);
325 // delete local VOCs
326 deleteAllVOCs();
328 } // end of namespace contact
329 } // end of namespace sdr
331 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */