1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include <svx/sdr/contact/viewcontactofsdrmeasureobj.hxx>
32 #include <svx/svdomeas.hxx>
33 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
34 #include <svl/itemset.hxx>
35 #include <svx/sxmbritm.hxx>
36 #include <svx/sxmlhitm.hxx>
37 #include <svx/sxmtritm.hxx>
38 #include <svx/sxmtaitm.hxx>
39 #include <svx/sdr/primitive2d/sdrmeasureprimitive2d.hxx>
40 #include <svx/sxmtpitm.hxx>
41 
42 //////////////////////////////////////////////////////////////////////////////
43 
44 namespace sdr
45 {
46 	namespace contact
47 	{
48 		ViewContactOfSdrMeasureObj::ViewContactOfSdrMeasureObj(SdrMeasureObj& rMeasureObj)
49 		:	ViewContactOfTextObj(rMeasureObj)
50 		{
51 		}
52 
53 		ViewContactOfSdrMeasureObj::~ViewContactOfSdrMeasureObj()
54 		{
55 		}
56 
57 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrMeasureObj::createViewIndependentPrimitive2DSequence() const
58 		{
59 			const SfxItemSet& rItemSet = GetMeasureObj().GetMergedItemSet();
60 			const drawinglayer::attribute::SdrLineShadowTextAttribute aAttribute(
61 				drawinglayer::primitive2d::createNewSdrLineShadowTextAttribute(
62                     rItemSet,
63                     GetMeasureObj().getText(0)));
64 
65 			// take properties which are the model data.
66 			const ::basegfx::B2DPoint aStart(GetMeasureObj().GetPoint(0).X(), GetMeasureObj().GetPoint(0).Y());
67 			const ::basegfx::B2DPoint aEnd(GetMeasureObj().GetPoint(1).X(), GetMeasureObj().GetPoint(1).Y());
68 			const double fDistance(((SdrMeasureLineDistItem&)rItemSet.Get(SDRATTR_MEASURELINEDIST)).GetValue());
69 			const double fUpperDistance(((SdrMeasureHelplineOverhangItem&)rItemSet.Get(SDRATTR_MEASUREHELPLINEOVERHANG)).GetValue());
70 			const double fLowerDistance(((SdrMeasureHelplineDistItem&)rItemSet.Get(SDRATTR_MEASUREHELPLINEDIST)).GetValue());
71 			const double fLeftDelta(((SdrMeasureHelpline1LenItem&)rItemSet.Get(SDRATTR_MEASUREHELPLINE1LEN)).GetValue());
72 			const double fRightDelta(((SdrMeasureHelpline2LenItem&)rItemSet.Get(SDRATTR_MEASUREHELPLINE2LEN)).GetValue());
73 			const bool bBelow(((SdrMeasureBelowRefEdgeItem&)rItemSet.Get(SDRATTR_MEASUREBELOWREFEDGE)).GetValue());
74 			const bool bTextRotation(((SdrMeasureTextRota90Item&)rItemSet.Get(SDRATTR_MEASURETEXTROTA90)).GetValue());
75 			const bool bTextAutoAngle(((SdrMeasureTextAutoAngleItem&)rItemSet.Get(SDRATTR_MEASURETEXTAUTOANGLE)).GetValue());
76 			drawinglayer::primitive2d::MeasureTextPosition aMTPHor(drawinglayer::primitive2d::MEASURETEXTPOSITION_AUTOMATIC);
77 			drawinglayer::primitive2d::MeasureTextPosition aMTPVer(drawinglayer::primitive2d::MEASURETEXTPOSITION_AUTOMATIC);
78 
79 			switch(((SdrMeasureTextHPosItem&)rItemSet.Get(SDRATTR_MEASURETEXTHPOS)).GetValue())
80 			{
81 				case SDRMEASURE_TEXTLEFTOUTSIDE :
82 				{
83 					aMTPHor = drawinglayer::primitive2d::MEASURETEXTPOSITION_NEGATIVE;
84 					break;
85 				}
86 				case SDRMEASURE_TEXTINSIDE :
87 				{
88 					aMTPHor = drawinglayer::primitive2d::MEASURETEXTPOSITION_CENTERED;
89 					break;
90 				}
91 				case SDRMEASURE_TEXTRIGHTOUTSIDE :
92 				{
93 					aMTPHor = drawinglayer::primitive2d::MEASURETEXTPOSITION_POSITIVE;
94 					break;
95 				}
96 				default : // SDRMEASURE_TEXTHAUTO
97 				{
98 					break;
99 				}
100 			}
101 
102 			switch(((SdrMeasureTextVPosItem&)rItemSet.Get(SDRATTR_MEASURETEXTVPOS)).GetValue())
103 			{
104 				case SDRMEASURE_ABOVE :
105 				{
106 					aMTPVer = drawinglayer::primitive2d::MEASURETEXTPOSITION_NEGATIVE;
107 					break;
108 				}
109 				case SDRMEASURETEXT_BREAKEDLINE :
110 				case SDRMEASURETEXT_VERTICALCENTERED :
111 				{
112 					aMTPVer = drawinglayer::primitive2d::MEASURETEXTPOSITION_CENTERED;
113 					break;
114 				}
115 				case SDRMEASURE_BELOW :
116 				{
117 					aMTPVer = drawinglayer::primitive2d::MEASURETEXTPOSITION_POSITIVE;
118 					break;
119 				}
120 				default : // SDRMEASURE_TEXTVAUTO
121 				{
122 					break;
123 				}
124 			}
125 
126 			// create primitive with the model data. Always create primitives to allow the
127 			// decomposition of SdrMeasurePrimitive2D to create needed invisible elements for HitTest
128 			// and/or BoundRect
129 			const drawinglayer::primitive2d::Primitive2DReference xReference(
130 				new drawinglayer::primitive2d::SdrMeasurePrimitive2D(
131 					aAttribute, aStart, aEnd,
132 					aMTPHor, aMTPVer, fDistance,
133 					fUpperDistance, fLowerDistance,
134 					fLeftDelta, fRightDelta, bBelow,
135 					bTextRotation, bTextAutoAngle));
136 
137 			return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
138 		}
139 	} // end of namespace contact
140 } // end of namespace sdr
141 
142 //////////////////////////////////////////////////////////////////////////////
143 // eof
144