merge the formfield patch from ooo-build
[ooovba.git] / svx / source / sdr / contact / viewobjectcontactofsdrpage.cxx
blob02e9800bd8e01bd390f625f19b8a235d8aba1780
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewobjectcontactofsdrpage.cxx,v $
11 * $Revision: 1.2 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_svx.hxx"
35 #include <svx/sdr/contact/viewobjectcontactofsdrpage.hxx>
36 #include <svx/sdr/contact/displayinfo.hxx>
37 #include <svx/sdr/contact/viewcontactofsdrpage.hxx>
38 #include <svx/svdview.hxx>
39 #include <svx/svdpage.hxx>
40 #include <svx/sdr/contact/objectcontact.hxx>
41 #include <drawinglayer/primitive2d/backgroundcolorprimitive2d.hxx>
42 #include <basegfx/polygon/b2dpolygontools.hxx>
43 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
44 #include <drawinglayer/primitive2d/gridprimitive2d.hxx>
45 #include <drawinglayer/primitive2d/helplineprimitive2d.hxx>
46 #include <basegfx/polygon/b2dpolygon.hxx>
47 #include <svx/sdr/primitive2d/sdrprimitivetools.hxx>
49 //////////////////////////////////////////////////////////////////////////////
51 using namespace com::sun::star;
53 //////////////////////////////////////////////////////////////////////////////
55 namespace sdr
57 namespace contact
59 const SdrPage& ViewObjectContactOfPageSubObject::getPage() const
61 return static_cast< ViewContactOfPageSubObject& >(GetViewContact()).getPage();
64 ViewObjectContactOfPageSubObject::ViewObjectContactOfPageSubObject(ObjectContact& rObjectContact, ViewContact& rViewContact)
65 : ViewObjectContact(rObjectContact, rViewContact)
69 ViewObjectContactOfPageSubObject::~ViewObjectContactOfPageSubObject()
73 bool ViewObjectContactOfPageSubObject::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
75 if(rDisplayInfo.GetSubContentActive())
77 return false;
80 if(rDisplayInfo.GetControlLayerProcessingActive())
82 return false;
85 if(!rDisplayInfo.GetPageProcessingActive())
87 return false;
90 if(GetObjectContact().isOutputToPrinter())
92 return false;
95 if(!GetObjectContact().TryToGetSdrPageView())
97 return false;
100 return true;
103 bool ViewObjectContactOfPageSubObject::isPrimitiveGhosted(const DisplayInfo& /*rDisplayInfo*/) const
105 // suppress ghosted for page parts
106 return false;
108 } // end of namespace contact
109 } // end of namespace sdr
111 //////////////////////////////////////////////////////////////////////////////
113 namespace sdr
115 namespace contact
117 ViewObjectContactOfPageBackground::ViewObjectContactOfPageBackground(ObjectContact& rObjectContact, ViewContact& rViewContact)
118 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
122 ViewObjectContactOfPageBackground::~ViewObjectContactOfPageBackground()
126 bool ViewObjectContactOfPageBackground::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
128 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
130 return false;
133 // no page background for preview renderers
134 if(GetObjectContact().IsPreviewRenderer())
136 return false;
139 return true;
142 drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfPageBackground::createPrimitive2DSequence(const DisplayInfo& /*rDisplayInfo*/) const
144 // Initialize background. Dependent of IsPageVisible, use ApplicationBackgroundColor or ApplicationDocumentColor. Most
145 // old renderers for export (html, pdf, gallery, ...) set the page to not visible (SetPageVisible(false)). They expect the
146 // given OutputDevice to be initialized with the ApplicationDocumentColor then.
147 const SdrPageView* pPageView = GetObjectContact().TryToGetSdrPageView();
148 drawinglayer::primitive2d::Primitive2DSequence xRetval;
150 if(pPageView)
152 const SdrView& rView = pPageView->GetView();
153 Color aInitColor;
155 if(rView.IsPageVisible())
157 aInitColor = pPageView->GetApplicationBackgroundColor();
159 else
161 aInitColor = pPageView->GetApplicationDocumentColor();
163 if(Color(COL_AUTO) == aInitColor)
165 const svtools::ColorConfig aColorConfig;
166 aInitColor = aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor;
170 // init background with InitColor
171 xRetval.realloc(1);
172 const basegfx::BColor aRGBColor(aInitColor.getBColor());
173 xRetval[0] = drawinglayer::primitive2d::Primitive2DReference(new drawinglayer::primitive2d::BackgroundColorPrimitive2D(aRGBColor));
176 return xRetval;
178 } // end of namespace contact
179 } // end of namespace sdr
181 //////////////////////////////////////////////////////////////////////////////
183 namespace sdr
185 namespace contact
187 ViewObjectContactOfMasterPage::ViewObjectContactOfMasterPage(ObjectContact& rObjectContact, ViewContact& rViewContact)
188 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
192 ViewObjectContactOfMasterPage::~ViewObjectContactOfMasterPage()
196 bool ViewObjectContactOfMasterPage::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
198 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
200 return false;
203 // this object is only used for MasterPages. When not the MasterPage is
204 // displayed as a page, but another page is using it as sub-object, the
205 // geometry needs to be hidden
206 if(rDisplayInfo.GetSubContentActive())
208 return false;
211 return true;
213 } // end of namespace contact
214 } // end of namespace sdr
216 //////////////////////////////////////////////////////////////////////////////
218 namespace sdr
220 namespace contact
222 ViewObjectContactOfPageFill::ViewObjectContactOfPageFill(ObjectContact& rObjectContact, ViewContact& rViewContact)
223 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
227 ViewObjectContactOfPageFill::~ViewObjectContactOfPageFill()
231 bool ViewObjectContactOfPageFill::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
233 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
235 return false;
238 SdrPageView* pSdrPageView = GetObjectContact().TryToGetSdrPageView();
240 if(!pSdrPageView)
242 return false;
245 if(!pSdrPageView->GetView().IsPageVisible())
247 return false;
250 return true;
253 drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfPageFill::createPrimitive2DSequence(const DisplayInfo& /*rDisplayInfo*/) const
255 const SdrPageView* pPageView = GetObjectContact().TryToGetSdrPageView();
256 drawinglayer::primitive2d::Primitive2DSequence xRetval;
258 if(pPageView)
260 const SdrPage& rPage = getPage();
262 const basegfx::B2DRange aPageFillRange(0.0, 0.0, (double)rPage.GetWdt(), (double)rPage.GetHgt());
263 const basegfx::B2DPolygon aPageFillPolygon(basegfx::tools::createPolygonFromRect(aPageFillRange));
264 Color aPageFillColor;
266 if(pPageView->GetApplicationDocumentColor() != COL_AUTO)
268 aPageFillColor = pPageView->GetApplicationDocumentColor();
270 else
272 const svtools::ColorConfig aColorConfig;
273 aPageFillColor = aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor;
276 // create and add primitive
277 xRetval.realloc(1);
278 const basegfx::BColor aRGBColor(aPageFillColor.getBColor());
279 xRetval[0] = drawinglayer::primitive2d::Primitive2DReference(new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aPageFillPolygon), aRGBColor));
282 return xRetval;
284 } // end of namespace contact
285 } // end of namespace sdr
287 //////////////////////////////////////////////////////////////////////////////
289 namespace sdr
291 namespace contact
293 ViewObjectContactOfPageShadow::ViewObjectContactOfPageShadow(ObjectContact& rObjectContact, ViewContact& rViewContact)
294 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
298 ViewObjectContactOfPageShadow::~ViewObjectContactOfPageShadow()
302 bool ViewObjectContactOfPageShadow::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
304 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
306 return false;
309 SdrPageView* pSdrPageView = GetObjectContact().TryToGetSdrPageView();
311 if(!pSdrPageView)
313 return false;
316 if(!pSdrPageView->GetView().IsPageVisible())
318 return false;
321 // no page shadow for preview renderers
322 if(GetObjectContact().IsPreviewRenderer())
324 return false;
327 return true;
329 } // end of namespace contact
330 } // end of namespace sdr
332 //////////////////////////////////////////////////////////////////////////////
334 namespace sdr
336 namespace contact
338 ViewObjectContactOfOuterPageBorder::ViewObjectContactOfOuterPageBorder(ObjectContact& rObjectContact, ViewContact& rViewContact)
339 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
343 ViewObjectContactOfOuterPageBorder::~ViewObjectContactOfOuterPageBorder()
347 bool ViewObjectContactOfOuterPageBorder::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
349 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
351 return false;
354 SdrPageView* pSdrPageView = GetObjectContact().TryToGetSdrPageView();
356 if(!pSdrPageView)
358 return false;
361 const SdrView& rView = pSdrPageView->GetView();
363 if(!rView.IsPageVisible() && rView.IsPageBorderVisible())
365 return false;
368 return true;
370 } // end of namespace contact
371 } // end of namespace sdr
373 //////////////////////////////////////////////////////////////////////////////
375 namespace sdr
377 namespace contact
379 ViewObjectContactOfInnerPageBorder::ViewObjectContactOfInnerPageBorder(ObjectContact& rObjectContact, ViewContact& rViewContact)
380 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
384 ViewObjectContactOfInnerPageBorder::~ViewObjectContactOfInnerPageBorder()
388 bool ViewObjectContactOfInnerPageBorder::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
390 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
392 return false;
395 SdrPageView* pSdrPageView = GetObjectContact().TryToGetSdrPageView();
397 if(!pSdrPageView)
399 return false;
402 if(!pSdrPageView->GetView().IsBordVisible())
404 return false;
407 const SdrPage& rPage = getPage();
409 if(!rPage.GetLftBorder() && !rPage.GetUppBorder() && !rPage.GetRgtBorder() && !rPage.GetLwrBorder())
411 return false;
414 // no inner page border for preview renderers
415 if(GetObjectContact().IsPreviewRenderer())
417 return false;
420 return true;
422 } // end of namespace contact
423 } // end of namespace sdr
425 //////////////////////////////////////////////////////////////////////////////
427 namespace sdr
429 namespace contact
431 ViewObjectContactOfPageHierarchy::ViewObjectContactOfPageHierarchy(ObjectContact& rObjectContact, ViewContact& rViewContact)
432 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
436 ViewObjectContactOfPageHierarchy::~ViewObjectContactOfPageHierarchy()
440 drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfPageHierarchy::getPrimitive2DSequenceHierarchy(DisplayInfo& rDisplayInfo) const
442 drawinglayer::primitive2d::Primitive2DSequence xRetval;
444 // process local sub-hierarchy
445 const sal_uInt32 nSubHierarchyCount(GetViewContact().GetObjectCount());
447 if(nSubHierarchyCount)
449 xRetval = getPrimitive2DSequenceSubHierarchy(rDisplayInfo);
451 if(xRetval.hasElements())
453 // get ranges
454 const drawinglayer::geometry::ViewInformation2D& rViewInformation2D(GetObjectContact().getViewInformation2D());
455 const basegfx::B2DRange aObjectRange(drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(xRetval, rViewInformation2D));
456 const basegfx::B2DRange aViewRange(rViewInformation2D.getViewport());
458 // check geometrical visibility
459 if(!aViewRange.isEmpty() && !aViewRange.overlaps(aObjectRange))
461 // not visible, release
462 xRetval.realloc(0);
467 return xRetval;
469 } // end of namespace contact
470 } // end of namespace sdr
472 //////////////////////////////////////////////////////////////////////////////
474 namespace sdr
476 namespace contact
478 ViewObjectContactOfPageGrid::ViewObjectContactOfPageGrid(ObjectContact& rObjectContact, ViewContact& rViewContact)
479 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
483 ViewObjectContactOfPageGrid::~ViewObjectContactOfPageGrid()
487 bool ViewObjectContactOfPageGrid::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
489 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
491 return false;
494 SdrPageView* pSdrPageView = GetObjectContact().TryToGetSdrPageView();
496 if(!pSdrPageView)
498 return false;
501 const SdrView& rView = pSdrPageView->GetView();
503 if(!rView.IsGridVisible())
505 return false;
508 // no page grid for preview renderers
509 if(GetObjectContact().IsPreviewRenderer())
511 return false;
514 if(static_cast< ViewContactOfGrid& >(GetViewContact()).getFront() != (bool)rView.IsGridFront())
516 return false;
519 return true;
522 drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfPageGrid::createPrimitive2DSequence(const DisplayInfo& /*rDisplayInfo*/) const
524 const SdrPageView* pPageView = GetObjectContact().TryToGetSdrPageView();
525 drawinglayer::primitive2d::Primitive2DSequence xRetval;
527 if(pPageView)
529 const SdrView& rView = pPageView->GetView();
530 const SdrPage& rPage = getPage();
531 const Color aGridColor(rView.GetGridColor());
532 const basegfx::BColor aRGBGridColor(aGridColor.getBColor());
534 basegfx::B2DHomMatrix aGridMatrix;
535 aGridMatrix.set(0, 0, (double)(rPage.GetWdt() - (rPage.GetRgtBorder() + rPage.GetLftBorder())));
536 aGridMatrix.set(1, 1, (double)(rPage.GetHgt() - (rPage.GetLwrBorder() + rPage.GetUppBorder())));
537 aGridMatrix.set(0, 2, (double)rPage.GetLftBorder());
538 aGridMatrix.set(1, 2, (double)rPage.GetUppBorder());
540 const Size aRaw(rView.GetGridCoarse());
541 const Size aFine(rView.GetGridFine());
542 const double fWidthX(aRaw.getWidth());
543 const double fWidthY(aRaw.getHeight());
544 const sal_uInt32 nSubdivisionsX(aFine.getWidth() ? aRaw.getWidth() / aFine.getWidth() : 0L);
545 const sal_uInt32 nSubdivisionsY(aFine.getHeight() ? aRaw.getHeight() / aFine.getHeight() : 0L);
547 xRetval.realloc(1);
548 xRetval[0] = drawinglayer::primitive2d::Primitive2DReference(new drawinglayer::primitive2d::GridPrimitive2D(
549 aGridMatrix, fWidthX, fWidthY, 10.0, 3.0, nSubdivisionsX, nSubdivisionsY, aRGBGridColor,
550 drawinglayer::primitive2d::createDefaultCross_3x3(aRGBGridColor)));
553 return xRetval;
555 } // end of namespace contact
556 } // end of namespace sdr
558 //////////////////////////////////////////////////////////////////////////////
560 namespace sdr
562 namespace contact
564 ViewObjectContactOfPageHelplines::ViewObjectContactOfPageHelplines(ObjectContact& rObjectContact, ViewContact& rViewContact)
565 : ViewObjectContactOfPageSubObject(rObjectContact, rViewContact)
569 ViewObjectContactOfPageHelplines::~ViewObjectContactOfPageHelplines()
573 bool ViewObjectContactOfPageHelplines::isPrimitiveVisible(const DisplayInfo& rDisplayInfo) const
575 if(!ViewObjectContactOfPageSubObject::isPrimitiveVisible(rDisplayInfo))
577 return false;
580 SdrPageView* pSdrPageView = GetObjectContact().TryToGetSdrPageView();
582 if(!pSdrPageView)
584 return false;
587 const SdrView& rView = pSdrPageView->GetView();
589 if(!rView.IsHlplVisible())
591 return false;
594 // no helplines for preview renderers
595 if(GetObjectContact().IsPreviewRenderer())
597 return false;
600 if(static_cast< ViewContactOfHelplines& >(GetViewContact()).getFront() != (bool)rView.IsHlplFront())
602 return false;
605 return true;
608 drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfPageHelplines::createPrimitive2DSequence(const DisplayInfo& /*rDisplayInfo*/) const
610 drawinglayer::primitive2d::Primitive2DSequence xRetval;
611 const SdrPageView* pPageView = GetObjectContact().TryToGetSdrPageView();
613 if(pPageView)
615 const SdrHelpLineList& rHelpLineList = pPageView->GetHelpLines();
616 const sal_uInt32 nCount(rHelpLineList.GetCount());
618 if(nCount)
620 const basegfx::BColor aRGBColorA(1.0, 1.0, 1.0);
621 const basegfx::BColor aRGBColorB(0.0, 0.0, 0.0);
622 xRetval.realloc(nCount);
624 for(sal_uInt32 a(0L); a < nCount; a++)
626 const SdrHelpLine& rHelpLine = rHelpLineList[(sal_uInt16)a];
627 const basegfx::B2DPoint aPosition((double)rHelpLine.GetPos().X(), (double)rHelpLine.GetPos().Y());
628 const double fDiscreteDashLength(4.0);
630 switch(rHelpLine.GetKind())
632 default : // SDRHELPLINE_POINT
634 xRetval[a] = drawinglayer::primitive2d::Primitive2DReference(new drawinglayer::primitive2d::HelplinePrimitive2D(
635 aPosition, basegfx::B2DVector(1.0, 0.0), drawinglayer::primitive2d::HELPLINESTYLE2D_POINT,
636 aRGBColorA, aRGBColorB, fDiscreteDashLength));
637 break;
639 case SDRHELPLINE_VERTICAL :
641 xRetval[a] = drawinglayer::primitive2d::Primitive2DReference(new drawinglayer::primitive2d::HelplinePrimitive2D(
642 aPosition, basegfx::B2DVector(0.0, 1.0), drawinglayer::primitive2d::HELPLINESTYLE2D_LINE,
643 aRGBColorA, aRGBColorB, fDiscreteDashLength));
644 break;
646 case SDRHELPLINE_HORIZONTAL :
648 xRetval[a] = drawinglayer::primitive2d::Primitive2DReference(new drawinglayer::primitive2d::HelplinePrimitive2D(
649 aPosition, basegfx::B2DVector(1.0, 0.0), drawinglayer::primitive2d::HELPLINESTYLE2D_LINE,
650 aRGBColorA, aRGBColorB, fDiscreteDashLength));
651 break;
658 return xRetval;
660 } // end of namespace contact
661 } // end of namespace sdr
663 //////////////////////////////////////////////////////////////////////////////
665 namespace sdr
667 namespace contact
669 ViewObjectContactOfSdrPage::ViewObjectContactOfSdrPage(ObjectContact& rObjectContact, ViewContact& rViewContact)
670 : ViewObjectContact(rObjectContact, rViewContact)
674 ViewObjectContactOfSdrPage::~ViewObjectContactOfSdrPage()
678 drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfSdrPage::getPrimitive2DSequenceHierarchy(DisplayInfo& rDisplayInfo) const
680 drawinglayer::primitive2d::Primitive2DSequence xRetval;
682 // process local sub-hierarchy
683 const sal_uInt32 nSubHierarchyCount(GetViewContact().GetObjectCount());
685 if(nSubHierarchyCount)
687 const sal_Bool bDoGhostedDisplaying(
688 GetObjectContact().DoVisualizeEnteredGroup()
689 && !GetObjectContact().isOutputToPrinter()
690 && GetObjectContact().getActiveViewContact() == &GetViewContact());
692 if(bDoGhostedDisplaying)
694 rDisplayInfo.ClearGhostedDrawMode();
697 // create object hierarchy
698 xRetval = getPrimitive2DSequenceSubHierarchy(rDisplayInfo);
700 if(xRetval.hasElements())
702 // get ranges
703 const drawinglayer::geometry::ViewInformation2D& rViewInformation2D(GetObjectContact().getViewInformation2D());
704 const basegfx::B2DRange aObjectRange(drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(xRetval, rViewInformation2D));
705 const basegfx::B2DRange aViewRange(rViewInformation2D.getViewport());
707 // check geometrical visibility
708 if(!aViewRange.isEmpty() && !aViewRange.overlaps(aObjectRange))
710 // not visible, release
711 xRetval.realloc(0);
715 if(bDoGhostedDisplaying)
717 rDisplayInfo.SetGhostedDrawMode();
721 return xRetval;
723 } // end of namespace contact
724 } // end of namespace sdr
726 //////////////////////////////////////////////////////////////////////////////
727 // eof