1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "oox/drawingml/textparagraph.hxx"
29 #include "oox/drawingml/drawingmltypes.hxx"
30 
31 #include <rtl/ustring.hxx>
32 #include "oox/helper/propertyset.hxx"
33 #include <com/sun/star/text/XText.hpp>
34 #include <com/sun/star/text/XTextCursor.hpp>
35 #include <com/sun/star/text/ControlCharacter.hpp>
36 
37 using ::rtl::OUString;
38 using namespace ::com::sun::star::text;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::frame;
42 
43 namespace oox { namespace drawingml {
44 
45 TextParagraph::TextParagraph()
46 {
47 }
48 
49 TextParagraph::~TextParagraph()
50 {
51 }
52 
53 void TextParagraph::insertAt(
54         const ::oox::core::XmlFilterBase& rFilterBase,
55         const Reference < XText > &xText,
56         const Reference < XTextCursor > &xAt,
57         const TextCharacterProperties& rTextStyleProperties,
58         const TextListStyle& rTextListStyle, bool bFirst) const
59 {
60     try {
61         sal_Int32 nParagraphSize = 0;
62         Reference< XTextRange > xStart( xAt, UNO_QUERY );
63 
64         sal_Int16 nLevel = maProperties.getLevel();
65         const TextParagraphPropertiesVector& rListStyle = rTextListStyle.getListStyle();
66         if ( nLevel >= static_cast< sal_Int16 >( rListStyle.size() ) )
67             nLevel = 0;
68         TextParagraphPropertiesPtr pTextParagraphStyle;
69         if ( rListStyle.size() )
70             pTextParagraphStyle = rListStyle[ nLevel ];
71 
72         TextCharacterProperties aTextCharacterStyle( rTextStyleProperties );
73         if ( pTextParagraphStyle.get() )
74             aTextCharacterStyle.assignUsed( pTextParagraphStyle->getTextCharacterProperties() );
75         aTextCharacterStyle.assignUsed( maProperties.getTextCharacterProperties() );
76 
77         if( !bFirst )
78         {
79             xText->insertControlCharacter( xStart, ControlCharacter::APPEND_PARAGRAPH, sal_False );
80             xAt->gotoEnd( sal_True );
81         }
82 		if ( maRuns.begin() == maRuns.end() )
83 		{
84 			PropertySet aPropSet( xStart );
85 
86 			TextCharacterProperties aTextCharacterProps( aTextCharacterStyle );
87 			aTextCharacterProps.assignUsed( maEndProperties );
88 			aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
89 		}
90 		else
91 		{
92 			for( TextRunVector::const_iterator aIt = maRuns.begin(), aEnd = maRuns.end(); aIt != aEnd; ++aIt )
93 			{
94 				(*aIt)->insertAt( rFilterBase, xText, xAt, aTextCharacterStyle );
95 				nParagraphSize += (*aIt)->getText().getLength();
96 			}
97 		}
98         xAt->gotoEnd( sal_True );
99 
100         PropertyMap aioBulletList;
101         Reference< XPropertySet > xProps( xStart, UNO_QUERY);
102 		float fCharacterSize = 18;
103         if ( pTextParagraphStyle.get() )
104 		{
105             pTextParagraphStyle->pushToPropSet( rFilterBase, xProps, aioBulletList, NULL, sal_False, fCharacterSize );
106             fCharacterSize = pTextParagraphStyle->getCharHeightPoints( 18 );
107 		}
108 		maProperties.pushToPropSet( rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(), sal_True, fCharacterSize );
109 
110         // empty paragraphs do not have bullets in ppt
111         if ( !nParagraphSize )
112         {
113 			const OUString sNumberingLevel( CREATE_OUSTRING( "NumberingLevel" ) );
114 			xProps->setPropertyValue( sNumberingLevel, Any( static_cast< sal_Int16 >( -1 ) ) );
115         }
116 
117 // FIXME this is causing a lot of dispruption (ie does not work). I wonder what to do -- Hub
118 //          Reference< XTextRange > xEnd( xAt, UNO_QUERY );
119 //      Reference< XPropertySet > xProps2( xEnd, UNO_QUERY );
120 //          mpEndProperties->pushToPropSet( xProps2 );
121     }
122     catch( Exception & )
123     {
124         OSL_TRACE("OOX: exception in TextParagraph::insertAt");
125     }
126 }
127 
128 
129 } }
130 
131