1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: VTitle.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "CommonConverters.hxx"
36 #include "PropertyMapper.hxx"
37 #include "ShapeFactory.hxx"
38 #include "RelativeSizeHelper.hxx"
39 #include <com/sun/star/chart2/XFormattedString.hpp>
40 #include <rtl/math.hxx>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
43 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
44 #include <com/sun/star/text/ControlCharacter.hpp>
45 #include <com/sun/star/text/XText.hpp>
46 #include <com/sun/star/text/XTextCursor.hpp>
48 //.............................................................................
51 //.............................................................................
52 using namespace ::com::sun::star
;
53 using namespace ::com::sun::star::chart2
;
55 VTitle::VTitle( const uno::Reference
< XTitle
> & xTitle
)
57 , m_xShapeFactory(NULL
)
61 , m_fRotationAngleDegree(0.0)
71 void SAL_CALL
VTitle::init(
72 const uno::Reference
< drawing::XShapes
>& xTargetPage
73 , const uno::Reference
< lang::XMultiServiceFactory
>& xFactory
74 , const rtl::OUString
& rCID
)
76 m_xTarget
= xTargetPage
;
77 m_xShapeFactory
= xFactory
;
81 double VTitle::getRotationAnglePi() const
83 return m_fRotationAngleDegree
*F_PI
/180.0;
86 awt::Size
VTitle::getUnrotatedSize() const //size before rotation
90 aRet
= m_xShape
->getSize();
94 awt::Size
VTitle::getFinalSize() const //size after rotation
96 return ShapeFactory::getSizeAfterRotation(
97 m_xShape
, m_fRotationAngleDegree
);
100 void VTitle::changePosition( const awt::Point
& rPos
)
104 uno::Reference
< beans::XPropertySet
> xShapeProp( m_xShape
, uno::UNO_QUERY
);
112 //set position matrix
113 //the matrix needs to be set at the end behind autogrow and such position influencing properties
114 ::basegfx::B2DHomMatrix aM
;
115 aM
.rotate( -m_fRotationAngleDegree
*F_PI
/180.0 );//#i78696#->#i80521#
116 aM
.translate( m_nXPos
, m_nYPos
);
117 xShapeProp
->setPropertyValue( C2U( "Transformation" ), uno::makeAny( B2DHomMatrixToHomogenMatrix3(aM
) ) );
119 catch( uno::Exception
& e
)
121 ASSERT_EXCEPTION( e
);
125 void VTitle::createShapes(
126 const awt::Point
& rPos
127 , const awt::Size
& rReferenceSize
)
134 uno::Sequence
< uno::Reference
< XFormattedString
> > aStringList
= m_xTitle
->getText();
135 if(aStringList
.getLength()<=0)
138 //create shape and add to page
139 uno::Reference
< drawing::XShape
> xShape(
140 m_xShapeFactory
->createInstance( C2U(
141 "com.sun.star.drawing.TextShape" ) ), uno::UNO_QUERY
);
142 m_xTarget
->add(xShape
);
145 //set text and text properties
146 uno::Reference
< text::XText
> xText( xShape
, uno::UNO_QUERY
);
147 uno::Reference
< text::XTextCursor
> xTextCursor( xText
->createTextCursor() );
148 uno::Reference
< text::XTextRange
> xTextRange( xTextCursor
, uno::UNO_QUERY
);
149 uno::Reference
< beans::XPropertySet
> xShapeProp( xShape
, uno::UNO_QUERY
);
150 uno::Reference
< beans::XPropertySet
> xTitleProperties( m_xTitle
, uno::UNO_QUERY
);
151 if( !xText
.is() || !xTextRange
.is() || !xTextCursor
.is() || !xShapeProp
.is() || !xTitleProperties
.is() )
154 tPropertyNameValueMap aValueMap
;
155 //fill line-, fill- and paragraph-properties into the ValueMap
157 tMakePropertyNameMap aNameMap
= PropertyMapper::getPropertyNameMapForParagraphProperties();
158 aNameMap( PropertyMapper::getPropertyNameMapForFillAndLineProperties() );
160 PropertyMapper::getValueMap( aValueMap
, aNameMap
, xTitleProperties
);
163 //fill some more shape properties into the ValueMap
165 drawing::TextHorizontalAdjust eHorizontalAdjust
= drawing::TextHorizontalAdjust_CENTER
;
166 drawing::TextVerticalAdjust eVerticalAdjust
= drawing::TextVerticalAdjust_CENTER
;
167 //text::WritingMode eWritingMode = text::WritingMode_LR_TB;//@todo get correct one
169 aValueMap
.insert( tPropertyNameValueMap::value_type( C2U("TextHorizontalAdjust"), uno::makeAny(eHorizontalAdjust
) ) ); // drawing::TextHorizontalAdjust
170 aValueMap
.insert( tPropertyNameValueMap::value_type( C2U("TextVerticalAdjust"), uno::makeAny(eVerticalAdjust
) ) ); //drawing::TextVerticalAdjust
171 //aValueMap.insert( tPropertyNameValueMap::value_type( C2U("TextWritingMode"), uno::makeAny(eWritingMode) ) ); //text::WritingMode
172 aValueMap
.insert( tPropertyNameValueMap::value_type( C2U("TextAutoGrowHeight"), uno::makeAny(sal_True
) ) ); // sal_Bool
173 aValueMap
.insert( tPropertyNameValueMap::value_type( C2U("TextAutoGrowWidth"), uno::makeAny(sal_True
) ) ); // sal_Bool
175 ////aValueMap.insert( tPropertyNameValueMap::value_type( C2U("TextMaximumFrameWidth"), uno::makeAny(rSize.Width) ) ); //sal_Int32
176 ////aValueMap.insert( tPropertyNameValueMap::value_type( C2U("TextMaximumFrameHeight"), uno::makeAny(rSize.Height) ) ); //sal_Int32
178 //set name/classified ObjectID (CID)
179 if( m_aCID
.getLength() )
180 aValueMap
.insert( tPropertyNameValueMap::value_type( C2U("Name"), uno::makeAny( m_aCID
) ) ); //CID rtl::OUString
183 //set global title properties
185 tNameSequence aPropNames
;
186 tAnySequence aPropValues
;
187 PropertyMapper::getMultiPropertyListsFromValueMap( aPropNames
, aPropValues
, aValueMap
);
188 PropertyMapper::setMultiProperties( aPropNames
, aPropValues
, xShapeProp
);
191 sal_Bool
bStackCharacters(sal_False
);
194 xTitleProperties
->getPropertyValue( C2U( "StackCharacters" ) ) >>= bStackCharacters
;
196 catch( uno::Exception
& e
)
198 ASSERT_EXCEPTION( e
);
202 //if the characters should be stacked we use only the first character properties for code simplicity
203 if( aStringList
.getLength()>0 )
205 rtl::OUString aLabel
;
206 for( sal_Int32 nN
=0; nN
<aStringList
.getLength();nN
++ )
207 aLabel
+= aStringList
[nN
]->getString();
208 aLabel
= ShapeFactory::getStackedString( aLabel
, bStackCharacters
);
210 xTextCursor
->gotoEnd(false);
211 xText
->insertString( xTextRange
, aLabel
, false );
212 xTextCursor
->gotoEnd(true);
213 uno::Reference
< beans::XPropertySet
> xTargetProps( xShape
, uno::UNO_QUERY
);
214 uno::Reference
< beans::XPropertySet
> xSourceProps( aStringList
[0], uno::UNO_QUERY
);
216 PropertyMapper::setMappedProperties( xTargetProps
, xSourceProps
217 , PropertyMapper::getPropertyNameMapForCharacterProperties() );
219 // adapt font size according to page size
220 awt::Size aOldRefSize
;
221 if( xTitleProperties
->getPropertyValue( C2U("ReferencePageSize")) >>= aOldRefSize
)
223 RelativeSizeHelper::adaptFontSizes( xTargetProps
, aOldRefSize
, rReferenceSize
);
229 uno::Sequence
< uno::Reference
< text::XTextCursor
> > aCursorList( aStringList
.getLength() );
231 for( nN
=0; nN
<aStringList
.getLength();nN
++ )
233 xTextCursor
->gotoEnd(false);
234 xText
->insertString( xTextRange
, aStringList
[nN
]->getString(), false );
235 xTextCursor
->gotoEnd(true);
236 aCursorList
[nN
] = xText
->createTextCursorByRange( uno::Reference
< text::XTextRange
>(xTextCursor
,uno::UNO_QUERY
) );
238 awt::Size aOldRefSize
;
239 bool bHasRefPageSize
=
240 ( xTitleProperties
->getPropertyValue( C2U("ReferencePageSize")) >>= aOldRefSize
);
242 //for( nN=0; nN<aStringList.getLength();nN++ ) //portion wise fromatting does not work still
243 if( aStringList
.getLength()>0 )
245 //uno::Reference< beans::XPropertySet > xTargetProps( aCursorList[nN], uno::UNO_QUERY );
246 //uno::Reference< beans::XPropertySet > xSourceProps( aStringList[nN], uno::UNO_QUERY );
247 uno::Reference
< beans::XPropertySet
> xTargetProps( xShape
, uno::UNO_QUERY
);
248 uno::Reference
< beans::XPropertySet
> xSourceProps( aStringList
[0], uno::UNO_QUERY
);
249 PropertyMapper::setMappedProperties( xTargetProps
, xSourceProps
, PropertyMapper::getPropertyNameMapForCharacterProperties() );
251 // adapt font size according to page size
252 if( bHasRefPageSize
)
254 RelativeSizeHelper::adaptFontSizes( xTargetProps
, aOldRefSize
, rReferenceSize
);
261 double fAngleDegree
= 0;
262 xTitleProperties
->getPropertyValue( C2U( "TextRotation" ) ) >>= fAngleDegree
;
263 m_fRotationAngleDegree
+= fAngleDegree
;
265 catch( uno::Exception
& e
)
267 ASSERT_EXCEPTION( e
);
272 //set position matrix
273 //the matrix needs to be set at the end behind autogrow and such position influencing properties
274 ::basegfx::B2DHomMatrix aM
;
275 aM
.rotate( -m_fRotationAngleDegree
*F_PI
/180.0 );//#i78696#->#i80521#
276 aM
.translate( m_nXPos
, m_nYPos
);
277 xShapeProp
->setPropertyValue( C2U( "Transformation" ), uno::makeAny( B2DHomMatrixToHomogenMatrix3(aM
) ) );
279 catch( uno::Exception
& e
)
281 ASSERT_EXCEPTION( e
);
285 //.............................................................................
287 //.............................................................................