merge the formfield patch from ooo-build
[ooovba.git] / oox / source / drawingml / textrun.cxx
blob04dcb68c053fb82a96511b4740645ae61c34ad67
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: textrun.cxx,v $
10 * $Revision: 1.6 $
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 #include "oox/drawingml/textrun.hxx"
33 #include <com/sun/star/text/ControlCharacter.hpp>
34 #include <com/sun/star/beans/XMultiPropertySet.hpp>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <com/sun/star/text/XTextField.hpp>
38 #include "oox/helper/helper.hxx"
39 #include "oox/helper/propertyset.hxx"
40 #include "oox/core/xmlfilterbase.hxx"
41 #include "properties.hxx"
43 using ::rtl::OUString;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::text;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::frame;
48 using namespace ::com::sun::star::lang;
50 namespace oox { namespace drawingml {
52 TextRun::TextRun() :
53 mbIsLineBreak( false )
57 TextRun::~TextRun()
61 void TextRun::insertAt(
62 const ::oox::core::XmlFilterBase& rFilterBase,
63 const Reference < XText > & xText,
64 const Reference < XTextCursor > &xAt,
65 const TextCharacterProperties& rTextCharacterStyle ) const
67 try {
68 Reference< XTextRange > xStart( xAt, UNO_QUERY );
69 PropertySet aPropSet( xStart );
71 TextCharacterProperties aTextCharacterProps( rTextCharacterStyle );
72 aTextCharacterProps.assignUsed( maTextCharacterProperties );
73 aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
75 if( maTextCharacterProperties.maHyperlinkPropertyMap.empty() )
77 if( mbIsLineBreak )
79 OSL_TRACE( "OOX: TextRun::insertAt() insert line break" );
80 xText->insertControlCharacter( xStart, ControlCharacter::LINE_BREAK, sal_False );
82 else
84 xText->insertString( xStart, getText(), sal_False );
87 else
89 OSL_TRACE( "OOX: URL field" );
90 Reference< XMultiServiceFactory > xFactory( rFilterBase.getModel(), UNO_QUERY );
91 Reference< XTextField > xField( xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.text.TextField.URL" ) ), UNO_QUERY );
92 if( xField.is() )
94 Reference< XTextCursor > xTextFieldCursor = xText->createTextCursor();
95 xTextFieldCursor->gotoEnd( sal_False );
97 PropertySet aFieldProps( xField );
98 aFieldProps.setProperties( maTextCharacterProperties.maHyperlinkPropertyMap );
99 aFieldProps.setProperty( PROP_Representation, getText() );
100 Reference< XTextContent > xContent( xField, UNO_QUERY);
101 xText->insertTextContent( xStart, xContent, sal_False );
103 xTextFieldCursor->gotoEnd( sal_True );
104 oox::core::TextField aTextField;
105 aTextField.xText = xText;
106 aTextField.xTextCursor = xTextFieldCursor;
107 aTextField.xTextField = xField;
108 rFilterBase.getTextFieldStack().push_back( aTextField );
110 else
112 OSL_TRACE( "OOX: URL field couldn't be created" );
113 xText->insertString( xStart, getText(), sal_False );
117 catch( const Exception& )
119 OSL_TRACE("OOX: TextRun::insertAt() exception");