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
10 #include "VButton.hxx"
11
12 #include <ShapeFactory.hxx>
13 #include <com/sun/star/drawing/FillStyle.hpp>
14 #include <com/sun/star/drawing/LineStyle.hpp>
15 #include <com/sun/star/drawing/XShapes.hpp>
16 #include <com/sun/star/style/ParagraphAdjust.hpp>
17 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
18 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
19 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
20 #include <com/sun/star/beans/XPropertySet.hpp>
21
22 #include <memory>
23
24 #include <CommonConverters.hxx>
25 #include <editeng/unoprnms.hxx>
26
27 namespace chart
28 {
29 using namespace css;
30
VButton()31 VButton::VButton()
32 : m_bShowArrow(true)
33 , m_nArrowColor(0x00000000)
34 , m_nBGColor(0x00E6E6E6)
35 {
36 }
37
init(const uno::Reference<drawing::XShapes> & xTargetPage,const uno::Reference<lang::XMultiServiceFactory> & xFactory)38 void VButton::init(const uno::Reference<drawing::XShapes>& xTargetPage,
39 const uno::Reference<lang::XMultiServiceFactory>& xFactory)
40 {
41 m_xTarget = xTargetPage;
42 m_xShapeFactory = xFactory;
43 }
44
createTriangle(awt::Size aSize)45 uno::Reference<drawing::XShape> VButton::createTriangle(awt::Size aSize)
46 {
47 uno::Reference<drawing::XShape> xShape;
48 xShape.set(m_xShapeFactory->createInstance("com.sun.star.drawing.PolyPolygonShape"),
49 uno::UNO_QUERY);
50
51 if (!xShape.is())
52 return xShape;
53
54 uno::Reference<beans::XPropertySet> xproperties(xShape, uno::UNO_QUERY);
55
56 drawing::PolyPolygonShape3D aPolyPolygon;
57 aPolyPolygon.SequenceX.realloc(1);
58 aPolyPolygon.SequenceY.realloc(1);
59 aPolyPolygon.SequenceZ.realloc(1);
60
61 drawing::DoubleSequence* pOuterSequenceX = aPolyPolygon.SequenceX.getArray();
62 drawing::DoubleSequence* pOuterSequenceY = aPolyPolygon.SequenceY.getArray();
63 drawing::DoubleSequence* pOuterSequenceZ = aPolyPolygon.SequenceZ.getArray();
64
65 pOuterSequenceX->realloc(3);
66 pOuterSequenceY->realloc(3);
67 pOuterSequenceZ->realloc(3);
68
69 double* pInnerSequenceX = pOuterSequenceX->getArray();
70 double* pInnerSequenceY = pOuterSequenceY->getArray();
71 double* pInnerSequenceZ = pOuterSequenceZ->getArray();
72
73 pInnerSequenceX[0] = 0.0;
74 pInnerSequenceY[0] = 0.0;
75 pInnerSequenceZ[0] = 0.0;
76
77 pInnerSequenceX[1] = aSize.Width / 2.0;
78 pInnerSequenceY[1] = aSize.Height;
79 pInnerSequenceZ[1] = 0.0;
80
81 pInnerSequenceX[2] = aSize.Width;
82 pInnerSequenceY[2] = 0.0;
83 pInnerSequenceZ[2] = 0.0;
84
85 xproperties->setPropertyValue("Name", uno::makeAny(m_sCID));
86 xproperties->setPropertyValue(UNO_NAME_POLYPOLYGON,
87 uno::Any(PolyToPointSequence(aPolyPolygon)));
88 xproperties->setPropertyValue("LineStyle", uno::makeAny(drawing::LineStyle_NONE));
89 xproperties->setPropertyValue("FillColor", uno::makeAny(m_nArrowColor));
90
91 return xShape;
92 }
93
createShapes(const uno::Reference<beans::XPropertySet> & xTextProp)94 void VButton::createShapes(const uno::Reference<beans::XPropertySet>& xTextProp)
95 {
96 ShapeFactory* pShapeFactory = ShapeFactory::getOrCreateShapeFactory(m_xShapeFactory);
97
98 tNameSequence aPropNames;
99 tAnySequence aPropValues;
100
101 PropertyMapper::getTextLabelMultiPropertyLists(xTextProp, aPropNames, aPropValues);
102
103 m_xShape.set(pShapeFactory->createGroup2D(m_xTarget, m_sCID), uno::UNO_QUERY);
104 m_xShape->setPosition(m_aPosition);
105 m_xShape->setSize(m_aSize);
106
107 uno::Reference<drawing::XShapes> xContainer(m_xShape, uno::UNO_QUERY);
108 if (!xContainer.is())
109 return;
110
111 tPropertyNameValueMap aTextValueMap;
112 aTextValueMap["CharHeight"] <<= 10.0f;
113 aTextValueMap["CharHeightAsian"] <<= 10.0f;
114 aTextValueMap["CharHeightComplex"] <<= 10.0f;
115 aTextValueMap["FillColor"] <<= m_nBGColor;
116 aTextValueMap["FillStyle"] <<= drawing::FillStyle_SOLID;
117 aTextValueMap["LineColor"] <<= sal_Int32(0xcccccc);
118 aTextValueMap["LineStyle"] <<= drawing::LineStyle_SOLID;
119 aTextValueMap["ParaAdjust"] <<= style::ParagraphAdjust_CENTER;
120 aTextValueMap["TextHorizontalAdjust"] <<= drawing::TextHorizontalAdjust_LEFT;
121 aTextValueMap["TextVerticalAdjust"] <<= drawing::TextVerticalAdjust_CENTER;
122 aTextValueMap["ParaLeftMargin"] <<= sal_Int32(100);
123 aTextValueMap["ParaRightMargin"] <<= sal_Int32(600);
124
125 aTextValueMap["Name"] <<= m_sCID; //CID OUString
126
127 PropertyMapper::getMultiPropertyListsFromValueMap(aPropNames, aPropValues, aTextValueMap);
128
129 uno::Reference<drawing::XShape> xEntry
130 = pShapeFactory->createText(xContainer, m_sLabel, aPropNames, aPropValues, uno::Any());
131
132 if (xEntry.is())
133 {
134 xEntry->setPosition(m_aPosition);
135 xEntry->setSize(m_aSize);
136 }
137
138 if (!m_bShowArrow)
139 return;
140
141 awt::Size aPolySize{ 280, 180 };
142
143 uno::Reference<drawing::XShape> xPoly = createTriangle(aPolySize);
144 if (xPoly.is())
145 {
146 xPoly->setSize(aPolySize);
147 xPoly->setPosition(
148 { sal_Int32(m_aPosition.X + m_aSize.Width - aPolySize.Width - 100),
149 sal_Int32(m_aPosition.Y + (m_aSize.Height / 2.0) - (aPolySize.Height / 2.0)) });
150 xContainer->add(xPoly);
151 }
152 }
153
154 } //namespace chart
155
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
157