Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / view / main / VButton.cxx
blobbd8c5f9749eb2202338542638ef6a07b872d3c2c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include "VButton.hxx"
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>
22 #include <memory>
24 #include <CommonConverters.hxx>
25 #include <editeng/unoprnms.hxx>
27 namespace chart
30 using namespace css;
32 VButton::VButton()
33 : m_bShowArrow(true)
34 , m_nArrowColor(0x00000000)
35 , m_nBGColor(0x00E6E6E6)
39 void VButton::init(const uno::Reference<drawing::XShapes>& xTargetPage,
40 const uno::Reference<lang::XMultiServiceFactory>& xFactory)
42 m_xTarget = xTargetPage;
43 m_xShapeFactory = xFactory;
46 uno::Reference<drawing::XShape> VButton::createTriangle(awt::Size aSize)
48 uno::Reference<drawing::XShape> xShape;
49 xShape.set(m_xShapeFactory->createInstance("com.sun.star.drawing.PolyPolygonShape"), uno::UNO_QUERY);
51 if (!xShape.is())
52 return xShape;
54 uno::Reference<beans::XPropertySet> xProperies(xShape, uno::UNO_QUERY);
56 drawing::PolyPolygonShape3D aPolyPolygon;
57 aPolyPolygon.SequenceX.realloc(1);
58 aPolyPolygon.SequenceY.realloc(1);
59 aPolyPolygon.SequenceZ.realloc(1);
61 drawing::DoubleSequence* pOuterSequenceX = aPolyPolygon.SequenceX.getArray();
62 drawing::DoubleSequence* pOuterSequenceY = aPolyPolygon.SequenceY.getArray();
63 drawing::DoubleSequence* pOuterSequenceZ = aPolyPolygon.SequenceZ.getArray();
65 pOuterSequenceX->realloc(3);
66 pOuterSequenceY->realloc(3);
67 pOuterSequenceZ->realloc(3);
69 double* pInnerSequenceX = pOuterSequenceX->getArray();
70 double* pInnerSequenceY = pOuterSequenceY->getArray();
71 double* pInnerSequenceZ = pOuterSequenceZ->getArray();
73 pInnerSequenceX[0] = 0.0;
74 pInnerSequenceY[0] = 0.0;
75 pInnerSequenceZ[0] = 0.0;
77 pInnerSequenceX[1] = aSize.Width / 2.0;
78 pInnerSequenceY[1] = aSize.Height;
79 pInnerSequenceZ[1] = 0.0;
81 pInnerSequenceX[2] = aSize.Width;
82 pInnerSequenceY[2] = 0.0;
83 pInnerSequenceZ[2] = 0.0;
85 xProperies->setPropertyValue("Name", uno::makeAny(m_sCID));
86 xProperies->setPropertyValue(UNO_NAME_POLYPOLYGON, uno::Any(PolyToPointSequence(aPolyPolygon)));
87 xProperies->setPropertyValue("LineStyle", uno::makeAny(drawing::LineStyle_NONE));
88 xProperies->setPropertyValue("FillColor", uno::makeAny(m_nArrowColor));
90 return xShape;
93 void VButton::createShapes(const uno::Reference<beans::XPropertySet>& xTextProp)
95 ShapeFactory* pShapeFactory = ShapeFactory::getOrCreateShapeFactory(m_xShapeFactory);
97 std::unique_ptr<tNameSequence> pPropNames(new tNameSequence);
98 std::unique_ptr<tAnySequence> pPropValues(new tAnySequence);
100 PropertyMapper::getTextLabelMultiPropertyLists(xTextProp, *pPropNames, *pPropValues);
102 m_xShape.set(pShapeFactory->createGroup2D(m_xTarget, m_sCID), uno::UNO_QUERY);
103 m_xShape->setPosition(m_aPosition);
104 m_xShape->setSize(m_aSize);
106 uno::Reference<drawing::XShapes> xContainer(m_xShape, uno::UNO_QUERY);
107 if (!xContainer.is())
108 return;
110 tPropertyNameValueMap aTextValueMap;
111 aTextValueMap["CharHeight"] <<= 10.0f;
112 aTextValueMap["CharHeightAsian"] <<= 10.0f;
113 aTextValueMap["CharHeightComplex"] <<= 10.0f;
114 aTextValueMap["FillColor"] <<= m_nBGColor;
115 aTextValueMap["FillStyle"] <<= drawing::FillStyle_SOLID;
116 aTextValueMap["LineColor"] <<= sal_Int32(0xcccccc);
117 aTextValueMap["LineStyle"] <<= drawing::LineStyle_SOLID;
118 aTextValueMap["ParaAdjust"] <<= style::ParagraphAdjust_CENTER;
119 aTextValueMap["TextHorizontalAdjust"] <<= drawing::TextHorizontalAdjust_LEFT;
120 aTextValueMap["TextVerticalAdjust"] <<= drawing::TextVerticalAdjust_CENTER;
121 aTextValueMap["ParaLeftMargin"] <<= sal_Int32(100);
122 aTextValueMap["ParaRightMargin"] <<= sal_Int32(600);
124 aTextValueMap["Name"] <<= m_sCID; //CID OUString
126 PropertyMapper::getMultiPropertyListsFromValueMap(*pPropNames, *pPropValues, aTextValueMap);
128 uno::Reference<drawing::XShape> xEntry = pShapeFactory->createText(
129 xContainer, m_sLabel, *pPropNames, *pPropValues, uno::Any());
131 if (xEntry.is())
133 xEntry->setPosition(m_aPosition);
134 xEntry->setSize(m_aSize);
137 if (m_bShowArrow)
139 awt::Size aPolySize {280, 180};
141 uno::Reference<drawing::XShape> xPoly = createTriangle(aPolySize);
142 if (xPoly.is())
144 xPoly->setSize(aPolySize);
145 xPoly->setPosition({ sal_Int32(m_aPosition.X + m_aSize.Width - aPolySize.Width - 100),
146 sal_Int32(m_aPosition.Y + (m_aSize.Height / 2.0) - (aPolySize.Height / 2.0)) });
147 xContainer->add(xPoly);
152 } //namespace chart
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */