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 
20 #include <sdr/contact/viewcontactofsdrpage.hxx>
21 #include <svx/sdr/contact/viewobjectcontact.hxx>
22 #include <svx/svdpage.hxx>
23 #include <svx/sdr/contact/displayinfo.hxx>
24 #include <sdr/contact/viewobjectcontactofsdrpage.hxx>
25 #include <basegfx/polygon/b2dpolygontools.hxx>
26 #include <basegfx/matrix/b2dhommatrix.hxx>
27 #include <svx/svdpagv.hxx>
28 #include <svx/svdview.hxx>
29 #include <tools/debug.hxx>
30 #include <vcl/svapp.hxx>
31 #include <svx/sdr/contact/objectcontact.hxx>
32 #include <drawinglayer/primitive2d/backgroundcolorprimitive2d.hxx>
33 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
34 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
35 #include <basegfx/polygon/b2dpolygon.hxx>
36 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
37 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
38 #include <vcl/lazydelete.hxx>
39 #include <vcl/settings.hxx>
40 #include <drawinglayer/primitive2d/discreteshadowprimitive2d.hxx>
41 #include <drawinglayer/attribute/sdrfillattribute.hxx>
42 #include <bitmaps.hlst>
43 
44 namespace sdr { namespace contact {
45 
ViewContactOfPageSubObject(ViewContactOfSdrPage & rParentViewContactOfSdrPage)46 ViewContactOfPageSubObject::ViewContactOfPageSubObject(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
47 :   mrParentViewContactOfSdrPage(rParentViewContactOfSdrPage)
48 {
49 }
50 
~ViewContactOfPageSubObject()51 ViewContactOfPageSubObject::~ViewContactOfPageSubObject()
52 {
53 }
54 
GetParentContact() const55 ViewContact* ViewContactOfPageSubObject::GetParentContact() const
56 {
57     return &mrParentViewContactOfSdrPage;
58 }
59 
getPage() const60 const SdrPage& ViewContactOfPageSubObject::getPage() const
61 {
62     return mrParentViewContactOfSdrPage.GetSdrPage();
63 }
64 
CreateObjectSpecificViewObjectContact(ObjectContact & rObjectContact)65 ViewObjectContact& ViewContactOfPageBackground::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
66 {
67     ViewObjectContact* pRetval = new ViewObjectContactOfPageBackground(rObjectContact, *this);
68     DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
69 
70     return *pRetval;
71 }
72 
createViewIndependentPrimitive2DSequence() const73 drawinglayer::primitive2d::Primitive2DContainer ViewContactOfPageBackground::createViewIndependentPrimitive2DSequence() const
74 {
75     // We have only the page information, not the view information. Use the
76     // svtools::DOCCOLOR color for initialisation
77     const svtools::ColorConfig aColorConfig;
78     const Color aInitColor(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
79     const basegfx::BColor aRGBColor(aInitColor.getBColor());
80     const drawinglayer::primitive2d::Primitive2DReference xReference(
81         new drawinglayer::primitive2d::BackgroundColorPrimitive2D(aRGBColor));
82 
83     return drawinglayer::primitive2d::Primitive2DContainer { xReference };
84 }
85 
ViewContactOfPageBackground(ViewContactOfSdrPage & rParentViewContactOfSdrPage)86 ViewContactOfPageBackground::ViewContactOfPageBackground(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
87 :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage)
88 {
89 }
90 
~ViewContactOfPageBackground()91 ViewContactOfPageBackground::~ViewContactOfPageBackground()
92 {
93 }
94 
CreateObjectSpecificViewObjectContact(ObjectContact & rObjectContact)95 ViewObjectContact& ViewContactOfPageShadow::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
96 {
97     ViewObjectContact* pRetval = new ViewObjectContactOfPageShadow(rObjectContact, *this);
98     DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
99 
100     return *pRetval;
101 }
102 
createViewIndependentPrimitive2DSequence() const103 drawinglayer::primitive2d::Primitive2DContainer ViewContactOfPageShadow::createViewIndependentPrimitive2DSequence() const
104 {
105     static bool bUseOldPageShadow(false); // loplugin:constvars:ignore
106     const SdrPage& rPage = getPage();
107     basegfx::B2DHomMatrix aPageMatrix;
108     aPageMatrix.set(0, 0, static_cast<double>(rPage.GetWidth()));
109     aPageMatrix.set(1, 1, static_cast<double>(rPage.GetHeight()));
110 
111     if(bUseOldPageShadow)
112     {
113         // create page shadow polygon
114         const double fPageBorderFactor(1.0 / 256.0);
115         basegfx::B2DPolygon aPageShadowPolygon;
116         aPageShadowPolygon.append(basegfx::B2DPoint(1.0, fPageBorderFactor));
117         aPageShadowPolygon.append(basegfx::B2DPoint(1.0 + fPageBorderFactor, fPageBorderFactor));
118         aPageShadowPolygon.append(basegfx::B2DPoint(1.0 + fPageBorderFactor, 1.0 + fPageBorderFactor));
119         aPageShadowPolygon.append(basegfx::B2DPoint(fPageBorderFactor, 1.0 + fPageBorderFactor));
120         aPageShadowPolygon.append(basegfx::B2DPoint(fPageBorderFactor, 1.0));
121         aPageShadowPolygon.append(basegfx::B2DPoint(1.0, 1.0));
122         aPageShadowPolygon.setClosed(true);
123         aPageShadowPolygon.transform(aPageMatrix);
124 
125         // We have only the page information, not the view information. Use the
126         // svtools::FONTCOLOR color for initialisation
127         const svtools::ColorConfig aColorConfig;
128         const Color aShadowColor(aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor);
129         const basegfx::BColor aRGBShadowColor(aShadowColor.getBColor());
130         const drawinglayer::primitive2d::Primitive2DReference xReference(
131             new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
132                 basegfx::B2DPolyPolygon(aPageShadowPolygon),
133                 aRGBShadowColor));
134 
135         return drawinglayer::primitive2d::Primitive2DContainer { xReference };
136     }
137     else
138     {
139         static vcl::DeleteOnDeinit< drawinglayer::primitive2d::DiscreteShadow > aDiscreteShadow(
140             new drawinglayer::primitive2d::DiscreteShadow(
141                 BitmapEx(SIP_SA_PAGESHADOW35X35)));
142 
143         if(aDiscreteShadow.get())
144         {
145             const drawinglayer::primitive2d::Primitive2DReference xReference(
146                 new drawinglayer::primitive2d::DiscreteShadowPrimitive2D(
147                     aPageMatrix,
148                     *aDiscreteShadow.get()));
149 
150             return drawinglayer::primitive2d::Primitive2DContainer { xReference };
151         }
152 
153         return drawinglayer::primitive2d::Primitive2DContainer();
154     }
155 }
156 
ViewContactOfPageShadow(ViewContactOfSdrPage & rParentViewContactOfSdrPage)157 ViewContactOfPageShadow::ViewContactOfPageShadow(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
158 :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage)
159 {
160 }
161 
~ViewContactOfPageShadow()162 ViewContactOfPageShadow::~ViewContactOfPageShadow()
163 {
164 }
165 
CreateObjectSpecificViewObjectContact(ObjectContact & rObjectContact)166 ViewObjectContact& ViewContactOfMasterPage::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
167 {
168     ViewObjectContact* pRetval = new ViewObjectContactOfMasterPage(rObjectContact, *this);
169     DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
170 
171     return *pRetval;
172 }
173 
createViewIndependentPrimitive2DSequence() const174 drawinglayer::primitive2d::Primitive2DContainer ViewContactOfMasterPage::createViewIndependentPrimitive2DSequence() const
175 {
176     drawinglayer::primitive2d::Primitive2DContainer xRetval;
177 
178     // this class is used when the page is a MasterPage and is responsible to
179     // create a visualisation for the MPBGO, if exists. This needs to be suppressed
180     // when a SdrPage which uses a MasterPage creates it's output. Suppression
181     // is done in the corresponding VOC since DisplayInfo data is needed
182     const SdrPage& rPage = getPage();
183 
184     if(rPage.IsMasterPage())
185     {
186         if(0 == rPage.GetPageNum())
187         {
188             // #i98063#
189             // filter MasterPage 0 since it's the HandoutPage. Thus, it's a
190             // MasterPage, but has no MPBGO, so there is nothing to do here.
191         }
192         else
193         {
194             drawinglayer::attribute::SdrFillAttribute aFill;
195 
196             // #i110846# Suppress SdrPage FillStyle for MasterPages without StyleSheets,
197             // else the PoolDefault (XFILL_COLOR and Blue8) will be used. Normally, all
198             // MasterPages should have a StyleSheet exactly for this reason, but historically
199             // e.g. the Notes MasterPage has no StyleSheet set (and there maybe others).
200             if(rPage.getSdrPageProperties().GetStyleSheet())
201             {
202                 // create page fill attributes with correct properties
203                 aFill = drawinglayer::primitive2d::createNewSdrFillAttribute(
204                     rPage.getSdrPageProperties().GetItemSet());
205             }
206 
207             if(!aFill.isDefault())
208             {
209                 // direct model data is the page size, get and use it
210                 const basegfx::B2DRange aInnerRange(
211                     rPage.GetLeftBorder(), rPage.GetUpperBorder(),
212                     rPage.GetWidth() - rPage.GetRightBorder(), rPage.GetHeight() - rPage.GetLowerBorder());
213                 const basegfx::B2DPolygon aInnerPolgon(basegfx::utils::createPolygonFromRect(aInnerRange));
214                 const drawinglayer::primitive2d::Primitive2DReference xReference(
215                     drawinglayer::primitive2d::createPolyPolygonFillPrimitive(
216                         basegfx::B2DPolyPolygon(aInnerPolgon),
217                         aFill,
218                         drawinglayer::attribute::FillGradientAttribute()));
219 
220                 xRetval = drawinglayer::primitive2d::Primitive2DContainer { xReference };
221             }
222         }
223     }
224 
225     return xRetval;
226 }
227 
ViewContactOfMasterPage(ViewContactOfSdrPage & rParentViewContactOfSdrPage)228 ViewContactOfMasterPage::ViewContactOfMasterPage(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
229 :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage)
230 {
231 }
232 
~ViewContactOfMasterPage()233 ViewContactOfMasterPage::~ViewContactOfMasterPage()
234 {
235 }
236 
CreateObjectSpecificViewObjectContact(ObjectContact & rObjectContact)237 ViewObjectContact& ViewContactOfPageFill::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
238 {
239     ViewObjectContact* pRetval = new ViewObjectContactOfPageFill(rObjectContact, *this);
240     DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
241 
242     return *pRetval;
243 }
244 
createViewIndependentPrimitive2DSequence() const245 drawinglayer::primitive2d::Primitive2DContainer ViewContactOfPageFill::createViewIndependentPrimitive2DSequence() const
246 {
247     const SdrPage& rPage = getPage();
248     const basegfx::B2DRange aPageFillRange(0.0, 0.0, static_cast<double>(rPage.GetWidth()), static_cast<double>(rPage.GetHeight()));
249     const basegfx::B2DPolygon aPageFillPolygon(basegfx::utils::createPolygonFromRect(aPageFillRange));
250 
251     // We have only the page information, not the view information. Use the
252     // svtools::DOCCOLOR color for initialisation
253     const svtools::ColorConfig aColorConfig;
254     const Color aPageFillColor(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
255 
256     // create and add primitive
257     const basegfx::BColor aRGBColor(aPageFillColor.getBColor());
258     const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aPageFillPolygon), aRGBColor));
259 
260     return drawinglayer::primitive2d::Primitive2DContainer { xReference };
261 }
262 
ViewContactOfPageFill(ViewContactOfSdrPage & rParentViewContactOfSdrPage)263 ViewContactOfPageFill::ViewContactOfPageFill(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
264 :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage)
265 {
266 }
267 
~ViewContactOfPageFill()268 ViewContactOfPageFill::~ViewContactOfPageFill()
269 {
270 }
271 
CreateObjectSpecificViewObjectContact(ObjectContact & rObjectContact)272 ViewObjectContact& ViewContactOfOuterPageBorder::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
273 {
274     ViewObjectContact* pRetval = new ViewObjectContactOfOuterPageBorder(rObjectContact, *this);
275     DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
276 
277     return *pRetval;
278 }
279 
createViewIndependentPrimitive2DSequence() const280 drawinglayer::primitive2d::Primitive2DContainer ViewContactOfOuterPageBorder::createViewIndependentPrimitive2DSequence() const
281 {
282     drawinglayer::primitive2d::Primitive2DContainer xRetval;
283     const SdrPage& rPage = getPage();
284     const basegfx::B2DRange aPageBorderRange(0.0, 0.0, static_cast<double>(rPage.GetWidth()), static_cast<double>(rPage.GetHeight()));
285 
286     // Changed to 0x949599 for renaissance, before svtools::FONTCOLOR was used.
287     // Added old case as fallback for HighContrast.
288     basegfx::BColor aRGBBorderColor(0x94 / double(0xff), 0x95 / double(0xff), 0x99 / double(0xff));
289 
290     if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
291     {
292         const svtools::ColorConfig aColorConfig;
293         const Color aBorderColor(aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor);
294 
295         aRGBBorderColor = aBorderColor.getBColor();
296     }
297 
298     if(rPage.getPageBorderOnlyLeftRight())
299     {
300         // #i93597# for Report Designer, the page border shall be only displayed right and left,
301         // but not top and bottom. Create simplified geometry.
302         basegfx::B2DPolygon aLeft, aRight;
303 
304         aLeft.append(basegfx::B2DPoint(aPageBorderRange.getMinX(), aPageBorderRange.getMinY()));
305         aLeft.append(basegfx::B2DPoint(aPageBorderRange.getMinX(), aPageBorderRange.getMaxY()));
306 
307         aRight.append(basegfx::B2DPoint(aPageBorderRange.getMaxX(), aPageBorderRange.getMinY()));
308         aRight.append(basegfx::B2DPoint(aPageBorderRange.getMaxX(), aPageBorderRange.getMaxY()));
309 
310         xRetval.resize(2);
311         xRetval[0] = drawinglayer::primitive2d::Primitive2DReference(new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aLeft, aRGBBorderColor));
312         xRetval[1] = drawinglayer::primitive2d::Primitive2DReference(new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aRight, aRGBBorderColor));
313     }
314     else
315     {
316         xRetval.resize(1);
317         const basegfx::B2DPolygon aPageBorderPolygon(basegfx::utils::createPolygonFromRect(aPageBorderRange));
318         xRetval[0] = drawinglayer::primitive2d::Primitive2DReference(new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aPageBorderPolygon, aRGBBorderColor));
319     }
320 
321     return xRetval;
322 }
323 
ViewContactOfOuterPageBorder(ViewContactOfSdrPage & rParentViewContactOfSdrPage)324 ViewContactOfOuterPageBorder::ViewContactOfOuterPageBorder(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
325 :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage)
326 {
327 }
328 
~ViewContactOfOuterPageBorder()329 ViewContactOfOuterPageBorder::~ViewContactOfOuterPageBorder()
330 {
331 }
332 
CreateObjectSpecificViewObjectContact(ObjectContact & rObjectContact)333 ViewObjectContact& ViewContactOfInnerPageBorder::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
334 {
335     ViewObjectContact* pRetval = new ViewObjectContactOfInnerPageBorder(rObjectContact, *this);
336     DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
337 
338     return *pRetval;
339 }
340 
createViewIndependentPrimitive2DSequence() const341 drawinglayer::primitive2d::Primitive2DContainer ViewContactOfInnerPageBorder::createViewIndependentPrimitive2DSequence() const
342 {
343     const SdrPage& rPage = getPage();
344     const basegfx::B2DRange aPageBorderRange(
345         static_cast<double>(rPage.GetLeftBorder()), static_cast<double>(rPage.GetUpperBorder()),
346         static_cast<double>(rPage.GetWidth() - rPage.GetRightBorder()), static_cast<double>(rPage.GetHeight() - rPage.GetLowerBorder()));
347     const basegfx::B2DPolygon aPageBorderPolygon(basegfx::utils::createPolygonFromRect(aPageBorderRange));
348 
349     // We have only the page information, not the view information. Use the
350     // svtools::FONTCOLOR or svtools::DOCBOUNDARIES color for initialisation
351     const svtools::ColorConfig aColorConfig;
352     Color aBorderColor;
353 
354     if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
355     {
356         aBorderColor = aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor;
357     }
358     else
359     {
360         svtools::ColorConfigValue aBorderConfig = aColorConfig.GetColorValue(svtools::DOCBOUNDARIES);
361         aBorderColor = aBorderConfig.bIsVisible ? aBorderConfig.nColor :
362                            aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor;
363     }
364 
365     // create page outer border primitive
366     const basegfx::BColor aRGBBorderColor(aBorderColor.getBColor());
367     const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aPageBorderPolygon, aRGBBorderColor));
368 
369     return drawinglayer::primitive2d::Primitive2DContainer { xReference };
370 }
371 
ViewContactOfInnerPageBorder(ViewContactOfSdrPage & rParentViewContactOfSdrPage)372 ViewContactOfInnerPageBorder::ViewContactOfInnerPageBorder(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
373 :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage)
374 {
375 }
376 
~ViewContactOfInnerPageBorder()377 ViewContactOfInnerPageBorder::~ViewContactOfInnerPageBorder()
378 {
379 }
380 
CreateObjectSpecificViewObjectContact(ObjectContact & rObjectContact)381 ViewObjectContact& ViewContactOfPageHierarchy::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
382 {
383     ViewObjectContact* pRetval = new ViewObjectContactOfPageHierarchy(rObjectContact, *this);
384     DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
385 
386     return *pRetval;
387 }
388 
createViewIndependentPrimitive2DSequence() const389 drawinglayer::primitive2d::Primitive2DContainer ViewContactOfPageHierarchy::createViewIndependentPrimitive2DSequence() const
390 {
391     // collect sub-hierarchy
392     drawinglayer::primitive2d::Primitive2DContainer xRetval;
393     const sal_uInt32 nObjectCount(GetObjectCount());
394 
395     // collect all sub-primitives
396     for(sal_uInt32 a(0); a < nObjectCount; a++)
397     {
398         const ViewContact& rCandidate(GetViewContact(a));
399         const drawinglayer::primitive2d::Primitive2DContainer& aCandSeq(rCandidate.getViewIndependentPrimitive2DContainer());
400 
401         xRetval.insert(xRetval.end(), aCandSeq.begin(), aCandSeq.end());
402     }
403 
404     return xRetval;
405 }
406 
ViewContactOfPageHierarchy(ViewContactOfSdrPage & rParentViewContactOfSdrPage)407 ViewContactOfPageHierarchy::ViewContactOfPageHierarchy(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
408 :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage)
409 {
410 }
411 
~ViewContactOfPageHierarchy()412 ViewContactOfPageHierarchy::~ViewContactOfPageHierarchy()
413 {
414 }
415 
GetObjectCount() const416 sal_uInt32 ViewContactOfPageHierarchy::GetObjectCount() const
417 {
418     return getPage().GetObjCount();
419 }
420 
GetViewContact(sal_uInt32 nIndex) const421 ViewContact& ViewContactOfPageHierarchy::GetViewContact(sal_uInt32 nIndex) const
422 {
423     SdrObject* pObj = getPage().GetObj(nIndex);
424     assert(pObj && "ViewContactOfPageHierarchy::GetViewContact: Corrupt SdrObjList (!)");
425     return pObj->GetViewContact();
426 }
427 
CreateObjectSpecificViewObjectContact(ObjectContact & rObjectContact)428 ViewObjectContact& ViewContactOfGrid::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
429 {
430     ViewObjectContact* pRetval = new ViewObjectContactOfPageGrid(rObjectContact, *this);
431     DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
432 
433     return *pRetval;
434 }
435 
createViewIndependentPrimitive2DSequence() const436 drawinglayer::primitive2d::Primitive2DContainer ViewContactOfGrid::createViewIndependentPrimitive2DSequence() const
437 {
438     // We have only the page information, not the view information and thus no grid settings. Create empty
439     // default. For the view-dependent implementation, see ViewObjectContactOfPageGrid::createPrimitive2DSequence
440     return drawinglayer::primitive2d::Primitive2DContainer();
441 }
442 
ViewContactOfGrid(ViewContactOfSdrPage & rParentViewContactOfSdrPage,bool bFront)443 ViewContactOfGrid::ViewContactOfGrid(ViewContactOfSdrPage& rParentViewContactOfSdrPage, bool bFront)
444 :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage),
445     mbFront(bFront)
446 {
447 }
448 
~ViewContactOfGrid()449 ViewContactOfGrid::~ViewContactOfGrid()
450 {
451 }
452 
CreateObjectSpecificViewObjectContact(ObjectContact & rObjectContact)453 ViewObjectContact& ViewContactOfHelplines::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
454 {
455     ViewObjectContact* pRetval = new ViewObjectContactOfPageHelplines(rObjectContact, *this);
456     DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
457 
458     return *pRetval;
459 }
460 
createViewIndependentPrimitive2DSequence() const461 drawinglayer::primitive2d::Primitive2DContainer ViewContactOfHelplines::createViewIndependentPrimitive2DSequence() const
462 {
463     // We have only the page information, not the view information and thus no helplines. Create empty
464     // default. For the view-dependent implementation, see ViewObjectContactOfPageHelplines::createPrimitive2DSequence
465     return drawinglayer::primitive2d::Primitive2DContainer();
466 }
467 
ViewContactOfHelplines(ViewContactOfSdrPage & rParentViewContactOfSdrPage,bool bFront)468 ViewContactOfHelplines::ViewContactOfHelplines(ViewContactOfSdrPage& rParentViewContactOfSdrPage, bool bFront)
469 :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage),
470     mbFront(bFront)
471 {
472 }
473 
~ViewContactOfHelplines()474 ViewContactOfHelplines::~ViewContactOfHelplines()
475 {
476 }
477 
478 // Create an Object-Specific ViewObjectContact, set ViewContact and
479 // ObjectContact. Always needs to return something.
CreateObjectSpecificViewObjectContact(ObjectContact & rObjectContact)480 ViewObjectContact& ViewContactOfSdrPage::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
481 {
482     ViewObjectContact* pRetval = new ViewObjectContactOfSdrPage(rObjectContact, *this);
483     DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");
484 
485     return *pRetval;
486 }
487 
ViewContactOfSdrPage(SdrPage & rPage)488 ViewContactOfSdrPage::ViewContactOfSdrPage(SdrPage& rPage)
489 :   ViewContact(),
490     mrPage(rPage),
491     maViewContactOfPageBackground(*this),
492     maViewContactOfPageShadow(*this),
493     maViewContactOfPageFill(*this),
494     maViewContactOfMasterPage(*this),
495     maViewContactOfOuterPageBorder(*this),
496     maViewContactOfInnerPageBorder(*this),
497     maViewContactOfGridBack(*this, false),
498     maViewContactOfHelplinesBack(*this, false),
499     maViewContactOfPageHierarchy(*this),
500     maViewContactOfGridFront(*this, true),
501     maViewContactOfHelplinesFront(*this, true)
502 {
503 }
504 
~ViewContactOfSdrPage()505 ViewContactOfSdrPage::~ViewContactOfSdrPage()
506 {
507 }
508 
509 // Access to possible sub-hierarchy
GetObjectCount() const510 sal_uInt32 ViewContactOfSdrPage::GetObjectCount() const
511 {
512     // Fixed count of content. It contains PageBackground (Wiese), PageShadow, PageFill,
513     // then - depending on if the page has a MasterPage - either MasterPage Hierarchy
514     // or MPBGO. Also OuterPageBorder, InnerPageBorder and two pairs of Grid and Helplines
515     // (for front and back) which internally are visible or not depending on the current
516     // front/back setting for those.
517     return 11;
518 }
519 
GetViewContact(sal_uInt32 nIndex) const520 ViewContact& ViewContactOfSdrPage::GetViewContact(sal_uInt32 nIndex) const
521 {
522     switch(nIndex)
523     {
524         case 0: return const_cast<ViewContactOfPageBackground&>(maViewContactOfPageBackground);
525         case 1: return const_cast<ViewContactOfPageShadow&>(maViewContactOfPageShadow);
526         case 2: return const_cast<ViewContactOfPageFill&>(maViewContactOfPageFill);
527         case 3:
528         {
529             const SdrPage& rPage = GetSdrPage();
530 
531             if(rPage.TRG_HasMasterPage())
532             {
533                 return rPage.TRG_GetMasterPageDescriptorViewContact();
534             }
535             else
536             {
537                 return const_cast<ViewContactOfMasterPage&>(maViewContactOfMasterPage);
538             }
539         }
540         case 4: return const_cast<ViewContactOfOuterPageBorder&>(maViewContactOfOuterPageBorder);
541         case 5: return const_cast<ViewContactOfInnerPageBorder&>(maViewContactOfInnerPageBorder);
542         case 6: return const_cast<ViewContactOfGrid&>(maViewContactOfGridBack);
543         case 7: return const_cast<ViewContactOfHelplines&>(maViewContactOfHelplinesBack);
544         case 8: return const_cast<ViewContactOfPageHierarchy&>(maViewContactOfPageHierarchy);
545         case 9: return const_cast<ViewContactOfGrid&>(maViewContactOfGridFront);
546         case 10: case 11: return const_cast<ViewContactOfHelplines&>(maViewContactOfHelplinesFront);
547         default: assert(false);return const_cast<ViewContactOfHelplines&>(maViewContactOfHelplinesFront);
548     }
549 }
550 
551 // React on changes of the object of this ViewContact
ActionChanged()552 void ViewContactOfSdrPage::ActionChanged()
553 {
554     // call parent
555     ViewContact::ActionChanged();
556 
557     // apply to local viewContacts, they all rely on page information. Exception
558     // is the sub hierarchy; this will not be influenced by the change
559     maViewContactOfPageBackground.ActionChanged();
560     maViewContactOfPageShadow.ActionChanged();
561     maViewContactOfPageFill.ActionChanged();
562 
563     const SdrPage& rPage = GetSdrPage();
564 
565     if(rPage.TRG_HasMasterPage())
566     {
567         rPage.TRG_GetMasterPageDescriptorViewContact().ActionChanged();
568     }
569     else if(rPage.IsMasterPage())
570     {
571         maViewContactOfMasterPage.ActionChanged();
572     }
573 
574     maViewContactOfOuterPageBorder.ActionChanged();
575     maViewContactOfInnerPageBorder.ActionChanged();
576     maViewContactOfGridBack.ActionChanged();
577     maViewContactOfHelplinesBack.ActionChanged();
578     maViewContactOfGridFront.ActionChanged();
579     maViewContactOfHelplinesFront.ActionChanged();
580 }
581 
createViewIndependentPrimitive2DSequence() const582 drawinglayer::primitive2d::Primitive2DContainer ViewContactOfSdrPage::createViewIndependentPrimitive2DSequence() const
583 {
584     drawinglayer::primitive2d::Primitive2DContainer xRetval;
585 
586     // collect all sub-sequences including sub hierarchy.
587     xRetval.append(maViewContactOfPageBackground.getViewIndependentPrimitive2DContainer());
588     xRetval.append(maViewContactOfPageShadow.getViewIndependentPrimitive2DContainer());
589     xRetval.append(maViewContactOfPageFill.getViewIndependentPrimitive2DContainer());
590 
591     const SdrPage& rPage = GetSdrPage();
592 
593     if(rPage.TRG_HasMasterPage())
594     {
595         xRetval.append(
596             rPage.TRG_GetMasterPageDescriptorViewContact().getViewIndependentPrimitive2DContainer());
597     }
598     else if(rPage.IsMasterPage())
599     {
600         xRetval.append(
601             maViewContactOfMasterPage.getViewIndependentPrimitive2DContainer());
602     }
603 
604     xRetval.append(maViewContactOfOuterPageBorder.getViewIndependentPrimitive2DContainer());
605     xRetval.append(maViewContactOfInnerPageBorder.getViewIndependentPrimitive2DContainer());
606     xRetval.append(maViewContactOfPageHierarchy.getViewIndependentPrimitive2DContainer());
607 
608     // Only add front versions of grid and helplines since no visibility test is done,
609     // so adding the back incarnations is not necessary. This makes the Front
610     // visualisation the default when no visibility tests are done.
611 
612     // Since we have no view here, no grid and helpline definitions are available currently. The used
613     // methods at ViewContactOfHelplines and ViewContactOfGrid return only empty sequences and
614     // do not need to be called ATM. This may change later if grid or helpline info gets
615     // model data (it should not). Keeping the lines commented to hold this hint.
616 
617     // drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, maViewContactOfGridFront.getViewIndependentPrimitive2DContainer());
618     // drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, maViewContactOfHelplinesFront.getViewIndependentPrimitive2DContainer());
619 
620     return xRetval;
621 }
622 
623 }}
624 
625 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
626