Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / source / view / main / VTitle.cxx
blob3ef4e161bc1583ba42516b713af5d7e128fab7e1
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "VTitle.hxx"
21 #include <CommonConverters.hxx>
22 #include <PropertyMapper.hxx>
23 #include <AbstractShapeFactory.hxx>
24 #include <com/sun/star/chart2/XFormattedString.hpp>
25 #include <rtl/math.hxx>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/text/ControlCharacter.hpp>
28 #include <com/sun/star/text/XText.hpp>
29 #include <com/sun/star/text/XTextCursor.hpp>
31 namespace chart
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::chart2;
36 VTitle::VTitle( const uno::Reference< XTitle > & xTitle )
37 : m_xTarget(nullptr)
38 , m_xShapeFactory(nullptr)
39 , m_xTitle(xTitle)
40 , m_xShape(nullptr)
41 , m_aCID()
42 , m_fRotationAngleDegree(0.0)
43 , m_nXPos(0)
44 , m_nYPos(0)
48 VTitle::~VTitle()
52 void VTitle::init(
53 const uno::Reference< drawing::XShapes >& xTargetPage
54 , const uno::Reference< lang::XMultiServiceFactory >& xFactory
55 , const OUString& rCID )
57 m_xTarget = xTargetPage;
58 m_xShapeFactory = xFactory;
59 m_aCID = rCID;
62 double VTitle::getRotationAnglePi() const
64 return m_fRotationAngleDegree*F_PI/180.0;
67 awt::Size VTitle::getUnrotatedSize() const //size before rotation
69 awt::Size aRet;
70 if(m_xShape.is())
71 aRet = m_xShape->getSize();
72 return aRet;
75 awt::Size VTitle::getFinalSize() const //size after rotation
77 return AbstractShapeFactory::getSizeAfterRotation(
78 m_xShape, m_fRotationAngleDegree );
81 void VTitle::changePosition( const awt::Point& rPos )
83 if(!m_xShape.is())
84 return;
85 uno::Reference< beans::XPropertySet > xShapeProp( m_xShape, uno::UNO_QUERY );
86 if(!xShapeProp.is())
87 return;
88 try
90 m_nXPos = rPos.X;
91 m_nYPos = rPos.Y;
93 //set position matrix
94 //the matrix needs to be set at the end behind autogrow and such position influencing properties
95 ::basegfx::B2DHomMatrix aM;
96 aM.rotate( -m_fRotationAngleDegree*F_PI/180.0 );//#i78696#->#i80521#
97 aM.translate( m_nXPos, m_nYPos);
98 xShapeProp->setPropertyValue( "Transformation", uno::Any( B2DHomMatrixToHomogenMatrix3(aM) ) );
100 catch( const uno::Exception& e )
102 SAL_WARN("chart2", "Exception caught. " << e );
106 void VTitle::createShapes(
107 const awt::Point& rPos
108 , const awt::Size& rReferenceSize )
110 if(!m_xTitle.is())
111 return;
113 uno::Sequence< uno::Reference< XFormattedString > > aStringList = m_xTitle->getText();
114 if(aStringList.getLength()<=0)
115 return;
117 m_nXPos = rPos.X;
118 m_nYPos = rPos.Y;
120 uno::Reference< beans::XPropertySet > xTitleProperties( m_xTitle, uno::UNO_QUERY );
124 double fAngleDegree = 0;
125 xTitleProperties->getPropertyValue( "TextRotation" ) >>= fAngleDegree;
126 m_fRotationAngleDegree += fAngleDegree;
128 catch( const uno::Exception& e )
130 SAL_WARN("chart2", "Exception caught. " << e );
133 AbstractShapeFactory* pShapeFactory = AbstractShapeFactory::getOrCreateShapeFactory(m_xShapeFactory);
134 m_xShape =pShapeFactory->createText( m_xTarget, rReferenceSize, rPos, aStringList,
135 xTitleProperties, m_fRotationAngleDegree, m_aCID );
138 } //namespace chart
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */