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/textbodycontext.hxx"
29 #include "oox/drawingml/textbodypropertiescontext.hxx"
30 #include "oox/drawingml/textparagraph.hxx"
31 #include "oox/drawingml/textparagraphpropertiescontext.hxx"
32 #include "oox/drawingml/textcharacterpropertiescontext.hxx"
33 #include "oox/drawingml/textliststylecontext.hxx"
34 #include "oox/drawingml/textfield.hxx"
35 #include "oox/drawingml/textfieldcontext.hxx"
36 
37 using ::rtl::OUString;
38 using namespace ::oox::core;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::text;
41 using namespace ::com::sun::star::xml::sax;
42 
43 namespace oox { namespace drawingml {
44 
45 // --------------------------------------------------------------------
46 
47 // CT_TextParagraph
48 class TextParagraphContext : public ContextHandler
49 {
50 public:
51     TextParagraphContext( ContextHandler& rParent, TextParagraph& rPara );
52 
53 	virtual void SAL_CALL endFastElement( sal_Int32 aElementToken ) throw (SAXException, RuntimeException);
54 	virtual Reference< XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException);
55 
56 protected:
57 	TextParagraph& mrParagraph;
58 };
59 
60 // --------------------------------------------------------------------
61 TextParagraphContext::TextParagraphContext( ContextHandler& rParent, TextParagraph& rPara )
62 : ContextHandler( rParent )
63 , mrParagraph( rPara )
64 {
65 }
66 
67 // --------------------------------------------------------------------
68 void TextParagraphContext::endFastElement( sal_Int32 aElementToken ) throw (SAXException, RuntimeException)
69 {
70 	if( aElementToken == (A_TOKEN( p )) )
71 	{
72 	}
73 }
74 
75 // --------------------------------------------------------------------
76 
77 Reference< XFastContextHandler > TextParagraphContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
78 {
79 	Reference< XFastContextHandler > xRet;
80 
81 	// EG_TextRun
82 	switch( aElementToken )
83 	{
84 	case A_TOKEN( r ):		// "CT_RegularTextRun" Regular Text Run.
85 	{
86         TextRunPtr pRun( new TextRun );
87 		mrParagraph.addRun( pRun );
88         xRet.set( new RegularTextRunContext( *this, pRun ) );
89 		break;
90 	}
91 	case A_TOKEN( br ):	// "CT_TextLineBreak" Soft return line break (vertical tab).
92 	{
93         TextRunPtr pRun( new TextRun );
94 		pRun->setLineBreak();
95 		mrParagraph.addRun( pRun );
96         xRet.set( new RegularTextRunContext( *this, pRun ) );
97 		break;
98 	}
99 	case A_TOKEN( fld ):	// "CT_TextField" Text Field.
100 	{
101         TextFieldPtr pField( new TextField );
102 		mrParagraph.addRun( pField );
103         xRet.set( new TextFieldContext( *this, xAttribs, *pField ) );
104 		break;
105 	}
106 	case A_TOKEN( pPr ):
107         xRet.set( new TextParagraphPropertiesContext( *this, xAttribs, mrParagraph.getProperties() ) );
108 		break;
109 	case A_TOKEN( endParaRPr ):
110         xRet.set( new TextCharacterPropertiesContext( *this, xAttribs, mrParagraph.getEndProperties() ) );
111 		break;
112 	}
113 
114 	return xRet;
115 }
116 // --------------------------------------------------------------------
117 
118 RegularTextRunContext::RegularTextRunContext( ContextHandler& rParent, TextRunPtr pRunPtr )
119 : ContextHandler( rParent )
120 , mpRunPtr( pRunPtr )
121 , mbIsInText( false )
122 {
123 }
124 
125 // --------------------------------------------------------------------
126 
127 void RegularTextRunContext::endFastElement( sal_Int32 aElementToken ) throw (SAXException, RuntimeException)
128 {
129 	switch( aElementToken )
130 	{
131 	case A_TOKEN( t ):
132 	{
133 		mbIsInText = false;
134 		break;
135 	}
136 	case A_TOKEN( r ):
137 	{
138 		break;
139 	}
140 
141 	}
142 }
143 
144 // --------------------------------------------------------------------
145 
146 void RegularTextRunContext::characters( const OUString& aChars ) throw (SAXException, RuntimeException)
147 {
148 	if( mbIsInText )
149 	{
150         mpRunPtr->getText() += aChars;
151 	}
152 }
153 
154 // --------------------------------------------------------------------
155 
156 Reference< XFastContextHandler > RegularTextRunContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs) throw (SAXException, RuntimeException)
157 {
158 	Reference< XFastContextHandler > xRet( this );
159 
160 	switch( aElementToken )
161 	{
162 	case A_TOKEN( rPr ):	// "CT_TextCharPropertyBag" The text char properties of this text run.
163         xRet.set( new TextCharacterPropertiesContext( *this, xAttribs, mpRunPtr->getTextCharacterProperties() ) );
164 		break;
165 	case A_TOKEN( t ):		// "xsd:string" minOccurs="1" The actual text string.
166 		mbIsInText = true;
167 		break;
168 	}
169 
170 	return xRet;
171 }
172 
173 // --------------------------------------------------------------------
174 
175 TextBodyContext::TextBodyContext( ContextHandler& rParent, TextBody& rTextBody )
176 : ContextHandler( rParent )
177 , mrTextBody( rTextBody )
178 {
179 }
180 
181 // --------------------------------------------------------------------
182 
183 void TextBodyContext::endFastElement( sal_Int32 ) throw (SAXException, RuntimeException)
184 {
185 }
186 
187 // --------------------------------------------------------------------
188 
189 Reference< XFastContextHandler > TextBodyContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException)
190 {
191 	Reference< XFastContextHandler > xRet;
192 
193 	switch( aElementToken )
194 	{
195 	case A_TOKEN( bodyPr ):		// CT_TextBodyPropertyBag
196         xRet.set( new TextBodyPropertiesContext( *this, xAttribs, mrTextBody.getTextProperties() ) );
197 		break;
198 	case A_TOKEN( lstStyle ):	// CT_TextListStyle
199         xRet.set( new TextListStyleContext( *this, mrTextBody.getTextListStyle() ) );
200 		break;
201 	case A_TOKEN( p ):			// CT_TextParagraph
202         xRet.set( new TextParagraphContext( *this, mrTextBody.addParagraph() ) );
203 		break;
204 	}
205 
206 	return xRet;
207 }
208 
209 // --------------------------------------------------------------------
210 
211 } }
212 
213