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: textbodycontext.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/textbodycontext.hxx"
32 #include "oox/drawingml/textbodypropertiescontext.hxx"
33 #include "oox/drawingml/textparagraph.hxx"
34 #include "oox/drawingml/textparagraphpropertiescontext.hxx"
35 #include "oox/drawingml/textcharacterpropertiescontext.hxx"
36 #include "oox/drawingml/textliststylecontext.hxx"
37 #include "oox/drawingml/textfield.hxx"
38 #include "oox/drawingml/textfieldcontext.hxx"
39 #include "oox/core/namespaces.hxx"
42 using ::rtl::OUString
;
43 using namespace ::oox::core
;
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::text
;
46 using namespace ::com::sun::star::xml::sax
;
48 namespace oox
{ namespace drawingml
{
50 // --------------------------------------------------------------------
53 class TextParagraphContext
: public ContextHandler
56 TextParagraphContext( ContextHandler
& rParent
, TextParagraph
& rPara
);
58 virtual void SAL_CALL
endFastElement( sal_Int32 aElementToken
) throw (SAXException
, RuntimeException
);
59 virtual Reference
< XFastContextHandler
> SAL_CALL
createFastChildContext( sal_Int32 aElementToken
, const Reference
< XFastAttributeList
>& xAttribs
) throw (SAXException
, RuntimeException
);
62 TextParagraph
& mrParagraph
;
65 // --------------------------------------------------------------------
66 TextParagraphContext::TextParagraphContext( ContextHandler
& rParent
, TextParagraph
& rPara
)
67 : ContextHandler( rParent
)
68 , mrParagraph( rPara
)
72 // --------------------------------------------------------------------
73 void TextParagraphContext::endFastElement( sal_Int32 aElementToken
) throw (SAXException
, RuntimeException
)
75 if( aElementToken
== (NMSP_DRAWINGML
|XML_p
) )
80 // --------------------------------------------------------------------
82 Reference
< XFastContextHandler
> TextParagraphContext::createFastChildContext( sal_Int32 aElementToken
, const Reference
< XFastAttributeList
>& xAttribs
) throw (SAXException
, RuntimeException
)
84 Reference
< XFastContextHandler
> xRet
;
87 switch( aElementToken
)
89 case NMSP_DRAWINGML
|XML_r
: // "CT_RegularTextRun" Regular Text Run.
91 TextRunPtr
pRun( new TextRun
);
92 mrParagraph
.addRun( pRun
);
93 xRet
.set( new RegularTextRunContext( *this, pRun
) );
96 case NMSP_DRAWINGML
|XML_br
: // "CT_TextLineBreak" Soft return line break (vertical tab).
98 TextRunPtr
pRun( new TextRun
);
100 mrParagraph
.addRun( pRun
);
101 xRet
.set( new RegularTextRunContext( *this, pRun
) );
104 case NMSP_DRAWINGML
|XML_fld
: // "CT_TextField" Text Field.
106 TextFieldPtr
pField( new TextField
);
107 mrParagraph
.addRun( pField
);
108 xRet
.set( new TextFieldContext( *this, xAttribs
, *pField
) );
111 case NMSP_DRAWINGML
|XML_pPr
:
112 xRet
.set( new TextParagraphPropertiesContext( *this, xAttribs
, mrParagraph
.getProperties() ) );
114 case NMSP_DRAWINGML
|XML_endParaRPr
:
115 xRet
.set( new TextParagraphPropertiesContext( *this, xAttribs
, mrParagraph
.getEndProperties() ) );
121 // --------------------------------------------------------------------
123 RegularTextRunContext::RegularTextRunContext( ContextHandler
& rParent
, TextRunPtr pRunPtr
)
124 : ContextHandler( rParent
)
125 , mpRunPtr( pRunPtr
)
126 , mbIsInText( false )
130 // --------------------------------------------------------------------
132 void RegularTextRunContext::endFastElement( sal_Int32 aElementToken
) throw (SAXException
, RuntimeException
)
134 switch( aElementToken
)
136 case NMSP_DRAWINGML
|XML_t
:
141 case NMSP_DRAWINGML
|XML_r
:
149 // --------------------------------------------------------------------
151 void RegularTextRunContext::characters( const OUString
& aChars
) throw (SAXException
, RuntimeException
)
155 mpRunPtr
->getText() += aChars
;
159 // --------------------------------------------------------------------
161 Reference
< XFastContextHandler
> RegularTextRunContext::createFastChildContext( sal_Int32 aElementToken
, const Reference
< XFastAttributeList
>& xAttribs
) throw (SAXException
, RuntimeException
)
163 Reference
< XFastContextHandler
> xRet( this );
165 switch( aElementToken
)
167 case NMSP_DRAWINGML
|XML_rPr
: // "CT_TextCharPropertyBag" The text char properties of this text run.
168 xRet
.set( new TextCharacterPropertiesContext( *this, xAttribs
, mpRunPtr
->getTextCharacterProperties() ) );
170 case NMSP_DRAWINGML
|XML_t
: // "xsd:string" minOccurs="1" The actual text string.
178 // --------------------------------------------------------------------
180 TextBodyContext::TextBodyContext( ContextHandler
& rParent
, TextBody
& rTextBody
)
181 : ContextHandler( rParent
)
182 , mrTextBody( rTextBody
)
186 // --------------------------------------------------------------------
188 void TextBodyContext::endFastElement( sal_Int32
) throw (SAXException
, RuntimeException
)
192 // --------------------------------------------------------------------
194 Reference
< XFastContextHandler
> TextBodyContext::createFastChildContext( sal_Int32 aElementToken
, const Reference
< XFastAttributeList
>& xAttribs
) throw (SAXException
, RuntimeException
)
196 Reference
< XFastContextHandler
> xRet
;
198 switch( aElementToken
)
200 case NMSP_DRAWINGML
|XML_bodyPr
: // CT_TextBodyPropertyBag
201 xRet
.set( new TextBodyPropertiesContext( *this, xAttribs
, mrTextBody
.getTextProperties() ) );
203 case NMSP_DRAWINGML
|XML_lstStyle
: // CT_TextListStyle
204 xRet
.set( new TextListStyleContext( *this, mrTextBody
.getTextListStyle() ) );
206 case NMSP_DRAWINGML
|XML_p
: // CT_TextParagraph
207 xRet
.set( new TextParagraphContext( *this, mrTextBody
.addParagraph() ) );
214 // --------------------------------------------------------------------