1*ca5ec200SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ca5ec200SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ca5ec200SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ca5ec200SAndrew Rist  * distributed with this work for additional information
6*ca5ec200SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ca5ec200SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ca5ec200SAndrew Rist  * "License"); you may not use this file except in compliance
9*ca5ec200SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ca5ec200SAndrew Rist  *
11*ca5ec200SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ca5ec200SAndrew Rist  *
13*ca5ec200SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ca5ec200SAndrew Rist  * software distributed under the License is distributed on an
15*ca5ec200SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ca5ec200SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ca5ec200SAndrew Rist  * specific language governing permissions and limitations
18*ca5ec200SAndrew Rist  * under the License.
19*ca5ec200SAndrew Rist  *
20*ca5ec200SAndrew Rist  *************************************************************/
21*ca5ec200SAndrew Rist 
22*ca5ec200SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "oox/drawingml/textbodycontext.hxx"
25cdf0e10cSrcweir #include "oox/drawingml/textbodypropertiescontext.hxx"
26cdf0e10cSrcweir #include "oox/drawingml/textparagraph.hxx"
27cdf0e10cSrcweir #include "oox/drawingml/textparagraphpropertiescontext.hxx"
28cdf0e10cSrcweir #include "oox/drawingml/textcharacterpropertiescontext.hxx"
29cdf0e10cSrcweir #include "oox/drawingml/textliststylecontext.hxx"
30cdf0e10cSrcweir #include "oox/drawingml/textfield.hxx"
31cdf0e10cSrcweir #include "oox/drawingml/textfieldcontext.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir using ::rtl::OUString;
34cdf0e10cSrcweir using namespace ::oox::core;
35cdf0e10cSrcweir using namespace ::com::sun::star::uno;
36cdf0e10cSrcweir using namespace ::com::sun::star::text;
37cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace oox { namespace drawingml {
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // --------------------------------------------------------------------
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // CT_TextParagraph
44cdf0e10cSrcweir class TextParagraphContext : public ContextHandler
45cdf0e10cSrcweir {
46cdf0e10cSrcweir public:
47cdf0e10cSrcweir     TextParagraphContext( ContextHandler& rParent, TextParagraph& rPara );
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 	virtual void SAL_CALL endFastElement( sal_Int32 aElementToken ) throw (SAXException, RuntimeException);
50cdf0e10cSrcweir 	virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException);
51cdf0e10cSrcweir 
52cdf0e10cSrcweir protected:
53cdf0e10cSrcweir 	TextParagraph& mrParagraph;
54cdf0e10cSrcweir };
55cdf0e10cSrcweir 
56cdf0e10cSrcweir // --------------------------------------------------------------------
TextParagraphContext(ContextHandler & rParent,TextParagraph & rPara)57cdf0e10cSrcweir TextParagraphContext::TextParagraphContext( ContextHandler& rParent, TextParagraph& rPara )
58cdf0e10cSrcweir : ContextHandler( rParent )
59cdf0e10cSrcweir , mrParagraph( rPara )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir // --------------------------------------------------------------------
endFastElement(sal_Int32 aElementToken)64cdf0e10cSrcweir void TextParagraphContext::endFastElement( sal_Int32 aElementToken ) throw (SAXException, RuntimeException)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	if( aElementToken == (A_TOKEN( p )) )
67cdf0e10cSrcweir 	{
68cdf0e10cSrcweir 	}
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir // --------------------------------------------------------------------
72cdf0e10cSrcweir 
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)73cdf0e10cSrcweir Reference< XFastContextHandler > TextParagraphContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir 	Reference< XFastContextHandler > xRet;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	// EG_TextRun
78cdf0e10cSrcweir 	switch( aElementToken )
79cdf0e10cSrcweir 	{
80cdf0e10cSrcweir 	case A_TOKEN( r ):		// "CT_RegularTextRun" Regular Text Run.
81cdf0e10cSrcweir 	{
82cdf0e10cSrcweir         TextRunPtr pRun( new TextRun );
83cdf0e10cSrcweir 		mrParagraph.addRun( pRun );
84cdf0e10cSrcweir         xRet.set( new RegularTextRunContext( *this, pRun ) );
85cdf0e10cSrcweir 		break;
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir 	case A_TOKEN( br ):	// "CT_TextLineBreak" Soft return line break (vertical tab).
88cdf0e10cSrcweir 	{
89cdf0e10cSrcweir         TextRunPtr pRun( new TextRun );
90cdf0e10cSrcweir 		pRun->setLineBreak();
91cdf0e10cSrcweir 		mrParagraph.addRun( pRun );
92cdf0e10cSrcweir         xRet.set( new RegularTextRunContext( *this, pRun ) );
93cdf0e10cSrcweir 		break;
94cdf0e10cSrcweir 	}
95cdf0e10cSrcweir 	case A_TOKEN( fld ):	// "CT_TextField" Text Field.
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir         TextFieldPtr pField( new TextField );
98cdf0e10cSrcweir 		mrParagraph.addRun( pField );
99cdf0e10cSrcweir         xRet.set( new TextFieldContext( *this, xAttribs, *pField ) );
100cdf0e10cSrcweir 		break;
101cdf0e10cSrcweir 	}
102cdf0e10cSrcweir 	case A_TOKEN( pPr ):
103cdf0e10cSrcweir         xRet.set( new TextParagraphPropertiesContext( *this, xAttribs, mrParagraph.getProperties() ) );
104cdf0e10cSrcweir 		break;
105cdf0e10cSrcweir 	case A_TOKEN( endParaRPr ):
106cdf0e10cSrcweir         xRet.set( new TextCharacterPropertiesContext( *this, xAttribs, mrParagraph.getEndProperties() ) );
107cdf0e10cSrcweir 		break;
108cdf0e10cSrcweir 	}
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	return xRet;
111cdf0e10cSrcweir }
112cdf0e10cSrcweir // --------------------------------------------------------------------
113cdf0e10cSrcweir 
RegularTextRunContext(ContextHandler & rParent,TextRunPtr pRunPtr)114cdf0e10cSrcweir RegularTextRunContext::RegularTextRunContext( ContextHandler& rParent, TextRunPtr pRunPtr )
115cdf0e10cSrcweir : ContextHandler( rParent )
116cdf0e10cSrcweir , mpRunPtr( pRunPtr )
117cdf0e10cSrcweir , mbIsInText( false )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir // --------------------------------------------------------------------
122cdf0e10cSrcweir 
endFastElement(sal_Int32 aElementToken)123cdf0e10cSrcweir void RegularTextRunContext::endFastElement( sal_Int32 aElementToken ) throw (SAXException, RuntimeException)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir 	switch( aElementToken )
126cdf0e10cSrcweir 	{
127cdf0e10cSrcweir 	case A_TOKEN( t ):
128cdf0e10cSrcweir 	{
129cdf0e10cSrcweir 		mbIsInText = false;
130cdf0e10cSrcweir 		break;
131cdf0e10cSrcweir 	}
132cdf0e10cSrcweir 	case A_TOKEN( r ):
133cdf0e10cSrcweir 	{
134cdf0e10cSrcweir 		break;
135cdf0e10cSrcweir 	}
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	}
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir // --------------------------------------------------------------------
141cdf0e10cSrcweir 
characters(const OUString & aChars)142cdf0e10cSrcweir void RegularTextRunContext::characters( const OUString& aChars ) throw (SAXException, RuntimeException)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	if( mbIsInText )
145cdf0e10cSrcweir 	{
146cdf0e10cSrcweir         mpRunPtr->getText() += aChars;
147cdf0e10cSrcweir 	}
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir // --------------------------------------------------------------------
151cdf0e10cSrcweir 
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)152cdf0e10cSrcweir Reference< XFastContextHandler > RegularTextRunContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs) throw (SAXException, RuntimeException)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	Reference< XFastContextHandler > xRet( this );
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	switch( aElementToken )
157cdf0e10cSrcweir 	{
158cdf0e10cSrcweir 	case A_TOKEN( rPr ):	// "CT_TextCharPropertyBag" The text char properties of this text run.
159cdf0e10cSrcweir         xRet.set( new TextCharacterPropertiesContext( *this, xAttribs, mpRunPtr->getTextCharacterProperties() ) );
160cdf0e10cSrcweir 		break;
161cdf0e10cSrcweir 	case A_TOKEN( t ):		// "xsd:string" minOccurs="1" The actual text string.
162cdf0e10cSrcweir 		mbIsInText = true;
163cdf0e10cSrcweir 		break;
164cdf0e10cSrcweir 	}
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 	return xRet;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir // --------------------------------------------------------------------
170cdf0e10cSrcweir 
TextBodyContext(ContextHandler & rParent,TextBody & rTextBody)171cdf0e10cSrcweir TextBodyContext::TextBodyContext( ContextHandler& rParent, TextBody& rTextBody )
172cdf0e10cSrcweir : ContextHandler( rParent )
173cdf0e10cSrcweir , mrTextBody( rTextBody )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir // --------------------------------------------------------------------
178cdf0e10cSrcweir 
endFastElement(sal_Int32)179cdf0e10cSrcweir void TextBodyContext::endFastElement( sal_Int32 ) throw (SAXException, RuntimeException)
180cdf0e10cSrcweir {
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir // --------------------------------------------------------------------
184cdf0e10cSrcweir 
createFastChildContext(sal_Int32 aElementToken,const Reference<XFastAttributeList> & xAttribs)185cdf0e10cSrcweir Reference< XFastContextHandler > TextBodyContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir 	Reference< XFastContextHandler > xRet;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 	switch( aElementToken )
190cdf0e10cSrcweir 	{
191cdf0e10cSrcweir 	case A_TOKEN( bodyPr ):		// CT_TextBodyPropertyBag
192cdf0e10cSrcweir         xRet.set( new TextBodyPropertiesContext( *this, xAttribs, mrTextBody.getTextProperties() ) );
193cdf0e10cSrcweir 		break;
194cdf0e10cSrcweir 	case A_TOKEN( lstStyle ):	// CT_TextListStyle
195cdf0e10cSrcweir         xRet.set( new TextListStyleContext( *this, mrTextBody.getTextListStyle() ) );
196cdf0e10cSrcweir 		break;
197cdf0e10cSrcweir 	case A_TOKEN( p ):			// CT_TextParagraph
198cdf0e10cSrcweir         xRet.set( new TextParagraphContext( *this, mrTextBody.addParagraph() ) );
199cdf0e10cSrcweir 		break;
200cdf0e10cSrcweir 	}
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 	return xRet;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir // --------------------------------------------------------------------
206cdf0e10cSrcweir 
207cdf0e10cSrcweir } }
208cdf0e10cSrcweir 
209