xref: /AOO41X/main/oox/source/drawingml/textparagraph.cxx (revision 7fe2509e7c53282a5f4c0f32fd52ae3e8c90d921)
1ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ca5ec200SAndrew Rist  * distributed with this work for additional information
6ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18ca5ec200SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20ca5ec200SAndrew Rist  *************************************************************/
21ca5ec200SAndrew Rist 
22ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/drawingml/textparagraph.hxx"
25cdf0e10cSrcweir #include "oox/drawingml/drawingmltypes.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <rtl/ustring.hxx>
28cdf0e10cSrcweir #include "oox/helper/propertyset.hxx"
29cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp>
30cdf0e10cSrcweir #include <com/sun/star/text/XTextCursor.hpp>
31cdf0e10cSrcweir #include <com/sun/star/text/ControlCharacter.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using ::rtl::OUString;
34cdf0e10cSrcweir using namespace ::com::sun::star::text;
35cdf0e10cSrcweir using namespace ::com::sun::star::uno;
36cdf0e10cSrcweir using namespace ::com::sun::star::beans;
37cdf0e10cSrcweir using namespace ::com::sun::star::frame;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace oox { namespace drawingml {
40cdf0e10cSrcweir 
TextParagraph()41cdf0e10cSrcweir TextParagraph::TextParagraph()
42cdf0e10cSrcweir {
43cdf0e10cSrcweir }
44cdf0e10cSrcweir 
~TextParagraph()45cdf0e10cSrcweir TextParagraph::~TextParagraph()
46cdf0e10cSrcweir {
47cdf0e10cSrcweir }
48cdf0e10cSrcweir 
lcl_getBulletclr(Color & bulletClr,const TextRunVector & rRuns)49*7fe2509eSJürgen Schmidt void lcl_getBulletclr(Color& bulletClr,
50*7fe2509eSJürgen Schmidt                       const TextRunVector& rRuns)
51*7fe2509eSJürgen Schmidt {
52*7fe2509eSJürgen Schmidt     // color of closest text in runs
53*7fe2509eSJürgen Schmidt     if (rRuns.begin() != rRuns.end() && ((*rRuns.begin())->getTextCharacterProperties()).maCharColor.isUsed())
54*7fe2509eSJürgen Schmidt     {
55*7fe2509eSJürgen Schmidt         bulletClr = ((*rRuns.begin())->getTextCharacterProperties()).maCharColor;
56*7fe2509eSJürgen Schmidt     }
57*7fe2509eSJürgen Schmidt }
58*7fe2509eSJürgen Schmidt 
insertAt(const::oox::core::XmlFilterBase & rFilterBase,const Reference<XText> & xText,const Reference<XTextCursor> & xAt,const TextCharacterProperties & rTextStyleProperties,const TextListStyle & rTextListStyle,bool bFirst) const59cdf0e10cSrcweir void TextParagraph::insertAt(
60cdf0e10cSrcweir         const ::oox::core::XmlFilterBase& rFilterBase,
61cdf0e10cSrcweir         const Reference < XText > &xText,
62cdf0e10cSrcweir         const Reference < XTextCursor > &xAt,
63cdf0e10cSrcweir         const TextCharacterProperties& rTextStyleProperties,
64cdf0e10cSrcweir         const TextListStyle& rTextListStyle, bool bFirst) const
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     try {
67cdf0e10cSrcweir         sal_Int32 nParagraphSize = 0;
68cdf0e10cSrcweir         Reference< XTextRange > xStart( xAt, UNO_QUERY );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir         sal_Int16 nLevel = maProperties.getLevel();
71cdf0e10cSrcweir         const TextParagraphPropertiesVector& rListStyle = rTextListStyle.getListStyle();
72cdf0e10cSrcweir         if ( nLevel >= static_cast< sal_Int16 >( rListStyle.size() ) )
73cdf0e10cSrcweir             nLevel = 0;
74cdf0e10cSrcweir         TextParagraphPropertiesPtr pTextParagraphStyle;
75cdf0e10cSrcweir         if ( rListStyle.size() )
76cdf0e10cSrcweir             pTextParagraphStyle = rListStyle[ nLevel ];
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         TextCharacterProperties aTextCharacterStyle( rTextStyleProperties );
79cdf0e10cSrcweir         if ( pTextParagraphStyle.get() )
80cdf0e10cSrcweir             aTextCharacterStyle.assignUsed( pTextParagraphStyle->getTextCharacterProperties() );
81cdf0e10cSrcweir         aTextCharacterStyle.assignUsed( maProperties.getTextCharacterProperties() );
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         if( !bFirst )
84cdf0e10cSrcweir         {
85cdf0e10cSrcweir             xText->insertControlCharacter( xStart, ControlCharacter::APPEND_PARAGRAPH, sal_False );
86cdf0e10cSrcweir             xAt->gotoEnd( sal_True );
87cdf0e10cSrcweir         }
88cdf0e10cSrcweir 		if ( maRuns.begin() == maRuns.end() )
89cdf0e10cSrcweir 		{
90cdf0e10cSrcweir 			PropertySet aPropSet( xStart );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 			TextCharacterProperties aTextCharacterProps( aTextCharacterStyle );
93cdf0e10cSrcweir 			aTextCharacterProps.assignUsed( maEndProperties );
94cdf0e10cSrcweir 			aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
95cdf0e10cSrcweir 		}
96cdf0e10cSrcweir 		else
97cdf0e10cSrcweir 		{
98cdf0e10cSrcweir 			for( TextRunVector::const_iterator aIt = maRuns.begin(), aEnd = maRuns.end(); aIt != aEnd; ++aIt )
99cdf0e10cSrcweir 			{
100cdf0e10cSrcweir 				(*aIt)->insertAt( rFilterBase, xText, xAt, aTextCharacterStyle );
101cdf0e10cSrcweir 				nParagraphSize += (*aIt)->getText().getLength();
102cdf0e10cSrcweir 			}
103cdf0e10cSrcweir 		}
104cdf0e10cSrcweir         xAt->gotoEnd( sal_True );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         PropertyMap aioBulletList;
107cdf0e10cSrcweir         Reference< XPropertySet > xProps( xStart, UNO_QUERY);
108cdf0e10cSrcweir 		float fCharacterSize = 18;
109cdf0e10cSrcweir         if ( pTextParagraphStyle.get() )
110cdf0e10cSrcweir 		{
111cdf0e10cSrcweir             pTextParagraphStyle->pushToPropSet( rFilterBase, xProps, aioBulletList, NULL, sal_False, fCharacterSize );
112cdf0e10cSrcweir             fCharacterSize = pTextParagraphStyle->getCharHeightPoints( 18 );
113cdf0e10cSrcweir 		}
114*7fe2509eSJürgen Schmidt 
115*7fe2509eSJürgen Schmidt         // bullet color inherits from closest text
116*7fe2509eSJürgen Schmidt         if (maProperties.getBulletList().maBulletColorPtr && !(maProperties.getBulletList().maBulletColorPtr)->isUsed())
117*7fe2509eSJürgen Schmidt         {
118*7fe2509eSJürgen Schmidt             Color bulletClr;
119*7fe2509eSJürgen Schmidt             lcl_getBulletclr(bulletClr, maRuns);
120*7fe2509eSJürgen Schmidt             (maProperties.getBulletList().maBulletColorPtr)->assignIfUsed(bulletClr);
121*7fe2509eSJürgen Schmidt         }
122*7fe2509eSJürgen Schmidt 
123cdf0e10cSrcweir 		maProperties.pushToPropSet( rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(), sal_True, fCharacterSize );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         // empty paragraphs do not have bullets in ppt
126cdf0e10cSrcweir         if ( !nParagraphSize )
127cdf0e10cSrcweir         {
128cdf0e10cSrcweir 			const OUString sNumberingLevel( CREATE_OUSTRING( "NumberingLevel" ) );
129cdf0e10cSrcweir 			xProps->setPropertyValue( sNumberingLevel, Any( static_cast< sal_Int16 >( -1 ) ) );
130cdf0e10cSrcweir         }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir // FIXME this is causing a lot of dispruption (ie does not work). I wonder what to do -- Hub
133cdf0e10cSrcweir //          Reference< XTextRange > xEnd( xAt, UNO_QUERY );
134cdf0e10cSrcweir //      Reference< XPropertySet > xProps2( xEnd, UNO_QUERY );
135cdf0e10cSrcweir //          mpEndProperties->pushToPropSet( xProps2 );
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir     catch( Exception & )
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         OSL_TRACE("OOX: exception in TextParagraph::insertAt");
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 
144cdf0e10cSrcweir } }
145cdf0e10cSrcweir 
146