summaryrefslogtreecommitdiff
path: root/svx/source/sdr/contact/viewcontactofsdrpage.cxx
blob: 26a3934c179e60468f173ad779bb9558e71edba7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: viewcontactofsdrpage.cxx,v $
 * $Revision: 1.24 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"
#include <svx/sdr/contact/viewcontactofsdrpage.hxx>
#include <svx/sdr/contact/viewobjectcontact.hxx>
#include <svx/svdpage.hxx>
#include <svx/sdr/contact/displayinfo.hxx>
#include <svx/sdr/contact/viewobjectcontactofsdrpage.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <svx/svdpagv.hxx>
#include <svx/svdview.hxx>
#include <vcl/svapp.hxx>
#include <svx/sdr/contact/objectcontact.hxx>
#include <drawinglayer/primitive2d/backgroundcolorprimitive2d.hxx>
#include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
#include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <drawinglayer/attribute/sdrattribute.hxx>
#include <svx/sdr/primitive2d/sdrattributecreator.hxx>
#include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>

//////////////////////////////////////////////////////////////////////////////

#define PAPER_SHADOW(SIZE) (SIZE >> 8)

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace contact
    {
        ViewContactOfPageSubObject::ViewContactOfPageSubObject(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
        :   mrParentViewContactOfSdrPage(rParentViewContactOfSdrPage)
        {
        }

        ViewContactOfPageSubObject::~ViewContactOfPageSubObject()
        {
        }

        ViewContact* ViewContactOfPageSubObject::GetParentContact() const
        {
            return &mrParentViewContactOfSdrPage;
        }

        const SdrPage& ViewContactOfPageSubObject::getPage() const
        {
            return mrParentViewContactOfSdrPage.GetSdrPage();
        }
    } // end of namespace contact
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace contact
    {
        ViewObjectContact& ViewContactOfPageBackground::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
        {
            ViewObjectContact* pRetval = new ViewObjectContactOfPageBackground(rObjectContact, *this);
            DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");

            return *pRetval;
        }

        drawinglayer::primitive2d::Primitive2DSequence ViewContactOfPageBackground::createViewIndependentPrimitive2DSequence() const
        {
            // We have only the page information, not the view information. Use the
            // svtools::DOCCOLOR color for initialisation
            const svtools::ColorConfig aColorConfig;
            const Color aInitColor(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);
            const basegfx::BColor aRGBColor(aInitColor.getBColor());
            const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::BackgroundColorPrimitive2D(aRGBColor));

            return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
        }

        ViewContactOfPageBackground::ViewContactOfPageBackground(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
        :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage)
        {
        }

        ViewContactOfPageBackground::~ViewContactOfPageBackground()
        {
        }
    } // end of namespace contact
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace contact
    {
        ViewObjectContact& ViewContactOfPageShadow::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
        {
            ViewObjectContact* pRetval = new ViewObjectContactOfPageShadow(rObjectContact, *this);
            DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");

            return *pRetval;
        }

        drawinglayer::primitive2d::Primitive2DSequence ViewContactOfPageShadow::createViewIndependentPrimitive2DSequence() const
        {
            const SdrPage& rPage = getPage();
            basegfx::B2DHomMatrix aPageMatrix;
            aPageMatrix.set(0, 0, (double)rPage.GetWdt());
            aPageMatrix.set(1, 1, (double)rPage.GetHgt());

            // create page shadow polygon
            const double fPageBorderFactor(1.0 / 256.0);
            basegfx::B2DPolygon aPageShadowPolygon;
            aPageShadowPolygon.append(basegfx::B2DPoint(1.0, fPageBorderFactor));
            aPageShadowPolygon.append(basegfx::B2DPoint(1.0 + fPageBorderFactor, fPageBorderFactor));
            aPageShadowPolygon.append(basegfx::B2DPoint(1.0 + fPageBorderFactor, 1.0 + fPageBorderFactor));
            aPageShadowPolygon.append(basegfx::B2DPoint(fPageBorderFactor, 1.0 + fPageBorderFactor));
            aPageShadowPolygon.append(basegfx::B2DPoint(fPageBorderFactor, 1.0));
            aPageShadowPolygon.append(basegfx::B2DPoint(1.0, 1.0));
            aPageShadowPolygon.setClosed(true);
            aPageShadowPolygon.transform(aPageMatrix);

            // We have only the page information, not the view information. Use the
            // svtools::FONTCOLOR color for initialisation
            const svtools::ColorConfig aColorConfig;
            const Color aShadowColor(aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor);
            const basegfx::BColor aRGBShadowColor(aShadowColor.getBColor());
            const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aPageShadowPolygon), aRGBShadowColor));

            return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
        }

        ViewContactOfPageShadow::ViewContactOfPageShadow(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
        :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage)
        {
        }

        ViewContactOfPageShadow::~ViewContactOfPageShadow()
        {
        }
    } // end of namespace contact
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace contact
    {
        ViewObjectContact& ViewContactOfMasterPage::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
        {
            ViewObjectContact* pRetval = new ViewObjectContactOfMasterPage(rObjectContact, *this);
            DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");

            return *pRetval;
        }

        drawinglayer::primitive2d::Primitive2DSequence ViewContactOfMasterPage::createViewIndependentPrimitive2DSequence() const
        {
            drawinglayer::primitive2d::Primitive2DSequence xRetval;

            // this class is used when the page is a MasterPage and is responsible to
            // create a visualisation for the MPBGO, if exists. This needs to be suppressed
            // when a SdrPage which uses a MasterPage creates it's output. Suppression
            // is done in the corresponding VOC since DisplayInfo data is needed
            const SdrPage& rPage = getPage();

            if(rPage.IsMasterPage())
            {
                if(0 == rPage.GetPageNum())
                {
                    // #i98063#
                    // filter MasterPage 0 since it's the HandoutPage. Thus, it's a
                    // MasterPage, but has no MPBGO, so there is nothing to do here.
                }
                else
                {
                    OSL_ENSURE(0 != rPage.GetObjCount(), "MasterPage without MPBGO detected (!)");

                    if(rPage.GetObjCount())
                    {
                        SdrObject* pObject = rPage.GetObj(0);
                        OSL_ENSURE(pObject && pObject->IsMasterPageBackgroundObject(), "MasterPage with wrong MPBGO detected (!)");

                        if(pObject && pObject->IsMasterPageBackgroundObject())
                        {
                            // build primitive from pObject's attributes
                            const SfxItemSet& rFillProperties = pObject->GetMergedItemSet();
                            drawinglayer::attribute::SdrFillAttribute* pFill = drawinglayer::primitive2d::createNewSdrFillAttribute(rFillProperties);

                            if(pFill)
                            {
                                if(pFill->isVisible())
                                {
                                    // direct model data is the page size, get and use it
                                    const basegfx::B2DRange aInnerRange(
                                        rPage.GetLftBorder(), rPage.GetUppBorder(),
                                        rPage.GetWdt() - rPage.GetRgtBorder(), rPage.GetHgt() - rPage.GetLwrBorder());
                                    const basegfx::B2DPolygon aInnerPolgon(basegfx::tools::createPolygonFromRect(aInnerRange));
                                    const basegfx::B2DHomMatrix aEmptyTransform;
                                    const drawinglayer::primitive2d::Primitive2DReference xReference(drawinglayer::primitive2d::createPolyPolygonFillPrimitive(
                                        basegfx::B2DPolyPolygon(aInnerPolgon), aEmptyTransform, *pFill));

                                    xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
                                }

                                delete pFill;
                            }
                        }
                    }
                }
            }

            return xRetval;
        }

        ViewContactOfMasterPage::ViewContactOfMasterPage(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
        :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage)
        {
        }

        ViewContactOfMasterPage::~ViewContactOfMasterPage()
        {
        }
    } // end of namespace contact
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace contact
    {
        ViewObjectContact& ViewContactOfPageFill::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
        {
            ViewObjectContact* pRetval = new ViewObjectContactOfPageFill(rObjectContact, *this);
            DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");

            return *pRetval;
        }

        drawinglayer::primitive2d::Primitive2DSequence ViewContactOfPageFill::createViewIndependentPrimitive2DSequence() const
        {
            const SdrPage& rPage = getPage();
            const basegfx::B2DRange aPageFillRange(0.0, 0.0, (double)rPage.GetWdt(), (double)rPage.GetHgt());
            const basegfx::B2DPolygon aPageFillPolygon(basegfx::tools::createPolygonFromRect(aPageFillRange));

            // We have only the page information, not the view information. Use the
            // svtools::DOCCOLOR color for initialisation
            const svtools::ColorConfig aColorConfig;
            const Color aPageFillColor(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor);

            // create and add primitive
            const basegfx::BColor aRGBColor(aPageFillColor.getBColor());
            const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aPageFillPolygon), aRGBColor));

            return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
        }

        ViewContactOfPageFill::ViewContactOfPageFill(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
        :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage)
        {
        }

        ViewContactOfPageFill::~ViewContactOfPageFill()
        {
        }
    } // end of namespace contact
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace contact
    {
        ViewObjectContact& ViewContactOfOuterPageBorder::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
        {
            ViewObjectContact* pRetval = new ViewObjectContactOfOuterPageBorder(rObjectContact, *this);
            DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");

            return *pRetval;
        }

        drawinglayer::primitive2d::Primitive2DSequence ViewContactOfOuterPageBorder::createViewIndependentPrimitive2DSequence() const
        {
            drawinglayer::primitive2d::Primitive2DSequence xRetval;
            const SdrPage& rPage = getPage();
            const basegfx::B2DRange aPageBorderRange(0.0, 0.0, (double)rPage.GetWdt(), (double)rPage.GetHgt());

            // We have only the page information, not the view information. Use the
            // svtools::FONTCOLOR color for initialisation
            const svtools::ColorConfig aColorConfig;
            const Color aBorderColor(aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor);
            const basegfx::BColor aRGBBorderColor(aBorderColor.getBColor());

            if(rPage.getPageBorderOnlyLeftRight())
            {
                // #i93597# for Report Designer, the page border shall be only displayed right and left,
                // but not top and bottom. Create simplified geometry.
                basegfx::B2DPolygon aLeft, aRight;

                aLeft.append(basegfx::B2DPoint(aPageBorderRange.getMinX(), aPageBorderRange.getMinY()));
                aLeft.append(basegfx::B2DPoint(aPageBorderRange.getMinX(), aPageBorderRange.getMaxY()));

                aRight.append(basegfx::B2DPoint(aPageBorderRange.getMaxX(), aPageBorderRange.getMinY()));
                aRight.append(basegfx::B2DPoint(aPageBorderRange.getMaxX(), aPageBorderRange.getMaxY()));

                xRetval.realloc(2);
                xRetval[0] = drawinglayer::primitive2d::Primitive2DReference(new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aLeft, aRGBBorderColor));
                xRetval[1] = drawinglayer::primitive2d::Primitive2DReference(new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aRight, aRGBBorderColor));
            }
            else
            {
                xRetval.realloc(1);
                const basegfx::B2DPolygon aPageBorderPolygon(basegfx::tools::createPolygonFromRect(aPageBorderRange));
                xRetval[0] = drawinglayer::primitive2d::Primitive2DReference(new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aPageBorderPolygon, aRGBBorderColor));
            }

            return xRetval;
        }

        ViewContactOfOuterPageBorder::ViewContactOfOuterPageBorder(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
        :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage)
        {
        }

        ViewContactOfOuterPageBorder::~ViewContactOfOuterPageBorder()
        {
        }
    } // end of namespace contact
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace contact
    {
        ViewObjectContact& ViewContactOfInnerPageBorder::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
        {
            ViewObjectContact* pRetval = new ViewObjectContactOfInnerPageBorder(rObjectContact, *this);
            DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");

            return *pRetval;
        }

        drawinglayer::primitive2d::Primitive2DSequence ViewContactOfInnerPageBorder::createViewIndependentPrimitive2DSequence() const
        {
            const SdrPage& rPage = getPage();
            const basegfx::B2DRange aPageBorderRange(
                (double)rPage.GetLftBorder(), (double)rPage.GetUppBorder(),
                (double)(rPage.GetWdt() - rPage.GetRgtBorder()), (double)(rPage.GetHgt() - rPage.GetLwrBorder()));
            const basegfx::B2DPolygon aPageBorderPolygon(basegfx::tools::createPolygonFromRect(aPageBorderRange));

            // We have only the page information, not the view information. Use the
            // svtools::FONTCOLOR or svtools::DOCBOUNDARIES color for initialisation
            const svtools::ColorConfig aColorConfig;
            Color aBorderColor;

            if(Application::GetSettings().GetStyleSettings().GetHighContrastMode())
            {
                aBorderColor = aColorConfig.GetColorValue(svtools::FONTCOLOR).nColor;
            }
            else
            {
                aBorderColor = aColorConfig.GetColorValue(svtools::DOCBOUNDARIES).nColor;
            }

            // create page outer border primitive
            const basegfx::BColor aRGBBorderColor(aBorderColor.getBColor());
            const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aPageBorderPolygon, aRGBBorderColor));

            return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
        }

        ViewContactOfInnerPageBorder::ViewContactOfInnerPageBorder(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
        :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage)
        {
        }

        ViewContactOfInnerPageBorder::~ViewContactOfInnerPageBorder()
        {
        }
    } // end of namespace contact
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace contact
    {
        ViewObjectContact& ViewContactOfPageHierarchy::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
        {
            ViewObjectContact* pRetval = new ViewObjectContactOfPageHierarchy(rObjectContact, *this);
            DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");

            return *pRetval;
        }

        drawinglayer::primitive2d::Primitive2DSequence ViewContactOfPageHierarchy::createViewIndependentPrimitive2DSequence() const
        {
            // collect sub-hierarchy
            drawinglayer::primitive2d::Primitive2DSequence xRetval;
            const sal_uInt32 nObjectCount(GetObjectCount());

            // collect all sub-primitives
            for(sal_uInt32 a(0); a < nObjectCount; a++)
            {
                const ViewContact& rCandidate(GetViewContact(a));
                const drawinglayer::primitive2d::Primitive2DSequence aCandSeq(rCandidate.getViewIndependentPrimitive2DSequence());

                drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, aCandSeq);
            }

            return xRetval;
        }

        ViewContactOfPageHierarchy::ViewContactOfPageHierarchy(ViewContactOfSdrPage& rParentViewContactOfSdrPage)
        :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage)
        {
        }

        ViewContactOfPageHierarchy::~ViewContactOfPageHierarchy()
        {
        }

        sal_uInt32 ViewContactOfPageHierarchy::GetObjectCount() const
        {
            sal_uInt32 nSubObjectCount(getPage().GetObjCount());

            if(nSubObjectCount && getPage().GetObj(0L)->IsMasterPageBackgroundObject())
            {
                nSubObjectCount--;
            }

            return nSubObjectCount;
        }

        ViewContact& ViewContactOfPageHierarchy::GetViewContact(sal_uInt32 nIndex) const
        {
            if(getPage().GetObjCount() && getPage().GetObj(0L)->IsMasterPageBackgroundObject())
            {
                nIndex++;
            }

            SdrObject* pObj = getPage().GetObj(nIndex);
            DBG_ASSERT(pObj, "ViewContactOfPageHierarchy::GetViewContact: Corrupt SdrObjList (!)");
            return pObj->GetViewContact();
        }
    } // end of namespace contact
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace contact
    {
        ViewObjectContact& ViewContactOfGrid::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
        {
            ViewObjectContact* pRetval = new ViewObjectContactOfPageGrid(rObjectContact, *this);
            DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");

            return *pRetval;
        }

        drawinglayer::primitive2d::Primitive2DSequence ViewContactOfGrid::createViewIndependentPrimitive2DSequence() const
        {
            // We have only the page information, not the view information and thus no grid settings. Create empty
            // default. For the view-dependent implementation, see ViewObjectContactOfPageGrid::createPrimitive2DSequence
            return drawinglayer::primitive2d::Primitive2DSequence();
        }

        ViewContactOfGrid::ViewContactOfGrid(ViewContactOfSdrPage& rParentViewContactOfSdrPage, bool bFront)
        :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage),
            mbFront(bFront)
        {
        }

        ViewContactOfGrid::~ViewContactOfGrid()
        {
        }
    } // end of namespace contact
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace contact
    {
        ViewObjectContact& ViewContactOfHelplines::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
        {
            ViewObjectContact* pRetval = new ViewObjectContactOfPageHelplines(rObjectContact, *this);
            DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");

            return *pRetval;
        }

        drawinglayer::primitive2d::Primitive2DSequence ViewContactOfHelplines::createViewIndependentPrimitive2DSequence() const
        {
            // We have only the page information, not the view information and thus no helplines. Create empty
            // default. For the view-dependent implementation, see ViewObjectContactOfPageHelplines::createPrimitive2DSequence
            return drawinglayer::primitive2d::Primitive2DSequence();
        }

        ViewContactOfHelplines::ViewContactOfHelplines(ViewContactOfSdrPage& rParentViewContactOfSdrPage, bool bFront)
        :   ViewContactOfPageSubObject(rParentViewContactOfSdrPage),
            mbFront(bFront)
        {
        }

        ViewContactOfHelplines::~ViewContactOfHelplines()
        {
        }
    } // end of namespace contact
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////

namespace sdr
{
    namespace contact
    {
        // Create a Object-Specific ViewObjectContact, set ViewContact and
        // ObjectContact. Always needs to return something.
        ViewObjectContact& ViewContactOfSdrPage::CreateObjectSpecificViewObjectContact(ObjectContact& rObjectContact)
        {
            ViewObjectContact* pRetval = new ViewObjectContactOfSdrPage(rObjectContact, *this);
            DBG_ASSERT(pRetval, "ViewContact::CreateObjectSpecificViewObjectContact() failed (!)");

            return *pRetval;
        }

        ViewContactOfSdrPage::ViewContactOfSdrPage(SdrPage& rPage)
        :   ViewContact(),
            mrPage(rPage),
            maViewContactOfPageBackground(*this),
            maViewContactOfPageShadow(*this),
            maViewContactOfPageFill(*this),
            maViewContactOfMasterPage(*this),
            maViewContactOfOuterPageBorder(*this),
            maViewContactOfInnerPageBorder(*this),
            maViewContactOfGridBack(*this, false),
            maViewContactOfHelplinesBack(*this, false),
            maViewContactOfPageHierarchy(*this),
            maViewContactOfGridFront(*this, true),
            maViewContactOfHelplinesFront(*this, true)
        {
        }

        ViewContactOfSdrPage::~ViewContactOfSdrPage()
        {
        }

        // Access to possible sub-hierarchy
        sal_uInt32 ViewContactOfSdrPage::GetObjectCount() const
        {
            // Fixed count of content. It contains PageBackground (Wiese), PageShadow, PageFill,
            // then - depending on if the page has a MasterPage - either MasterPage Hierarchy
            // or MPBGO. Also OuterPageBorder, InnerPageBorder and two pairs of Grid and Helplines
            // (for front and back) which internally are visible or not depending on the current
            // front/back setting for those.
            return 11;
        }

        ViewContact& ViewContactOfSdrPage::GetViewContact(sal_uInt32 nIndex) const
        {
            switch(nIndex)
            {
                case 0: return (ViewContact&)maViewContactOfPageBackground;
                case 1: return (ViewContact&)maViewContactOfPageShadow;
                case 2: return (ViewContact&)maViewContactOfPageFill;
                case 3:
                {
                    const SdrPage& rPage = GetSdrPage();

                    if(rPage.TRG_HasMasterPage())
                    {
                        return rPage.TRG_GetMasterPageDescriptorViewContact();
                    }
                    else
                    {
                        return (ViewContact&)maViewContactOfMasterPage;
                    }
                }
                case 4: return (ViewContact&)maViewContactOfOuterPageBorder;
                case 5: return (ViewContact&)maViewContactOfInnerPageBorder;
                case 6: return (ViewContact&)maViewContactOfGridBack;
                case 7: return (ViewContact&)maViewContactOfHelplinesBack;
                case 8: return (ViewContact&)maViewContactOfPageHierarchy;
                case 9: return (ViewContact&)maViewContactOfGridFront;
                default: return (ViewContact&)maViewContactOfHelplinesFront;
            }
        }

        // React on changes of the object of this ViewContact
        void ViewContactOfSdrPage::ActionChanged()
        {
            // call parent
            ViewContact::ActionChanged();

            // apply to local viewContacts, they all rely on page information. Exception
            // is the sub hierarchy; this will not be influenced by the change
            maViewContactOfPageBackground.ActionChanged();
            maViewContactOfPageShadow.ActionChanged();
            maViewContactOfPageFill.ActionChanged();

            const SdrPage& rPage = GetSdrPage();

            if(rPage.TRG_HasMasterPage())
            {
                rPage.TRG_GetMasterPageDescriptorViewContact().ActionChanged();
            }
            else if(rPage.IsMasterPage())
            {
                maViewContactOfMasterPage.ActionChanged();
            }

            maViewContactOfOuterPageBorder.ActionChanged();
            maViewContactOfInnerPageBorder.ActionChanged();
            maViewContactOfGridBack.ActionChanged();
            maViewContactOfHelplinesBack.ActionChanged();
            maViewContactOfGridFront.ActionChanged();
            maViewContactOfHelplinesFront.ActionChanged();
        }

        // overload for acessing the SdrPage
        SdrPage* ViewContactOfSdrPage::TryToGetSdrPage() const
        {
            return &GetSdrPage();
        }

        drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrPage::createViewIndependentPrimitive2DSequence() const
        {
            drawinglayer::primitive2d::Primitive2DSequence xRetval;

            // collect all sub-sequences including sub hierarchy.
            drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, maViewContactOfPageBackground.getViewIndependentPrimitive2DSequence());
            drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, maViewContactOfPageShadow.getViewIndependentPrimitive2DSequence());
            drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, maViewContactOfPageFill.getViewIndependentPrimitive2DSequence());

            const SdrPage& rPage = GetSdrPage();

            if(rPage.TRG_HasMasterPage())
            {
                drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval,
                    rPage.TRG_GetMasterPageDescriptorViewContact().getViewIndependentPrimitive2DSequence());
            }
            else if(rPage.IsMasterPage())
            {
                drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval,
                    maViewContactOfMasterPage.getViewIndependentPrimitive2DSequence());
            }

            drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, maViewContactOfOuterPageBorder.getViewIndependentPrimitive2DSequence());
            drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, maViewContactOfInnerPageBorder.getViewIndependentPrimitive2DSequence());
            drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, maViewContactOfPageHierarchy.getViewIndependentPrimitive2DSequence());

            // Only add front versions of grid and helplines since no visibility test is done,
            // so adding the back incarnations is not necessary. This makes the Front
            // visualisation the default when no visibility tests are done.
            //
            // Since we have no view here, no grid and helpline definitions are available currently. The used
            // methods at ViewContactOfHelplines and ViewContactOfGrid return only empty sequences and
            // do not need to be called ATM. This may change later if grid or helpline info gets
            // model data (it should not). Keeping the lines commented to hold this hint.
            //
            // drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, maViewContactOfGridFront.getViewIndependentPrimitive2DSequence());
            // drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xRetval, maViewContactOfHelplinesFront.getViewIndependentPrimitive2DSequence());

            return xRetval;
        }
    } // end of namespace contact
} // end of namespace sdr

//////////////////////////////////////////////////////////////////////////////
// eof