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 $
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
{
53 mbIsLineBreak( false )
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
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() )
79 OSL_TRACE( "OOX: TextRun::insertAt() insert line break" );
80 xText
->insertControlCharacter( xStart
, ControlCharacter::LINE_BREAK
, sal_False
);
84 xText
->insertString( xStart
, getText(), sal_False
);
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
);
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
);
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");