xref: /aoo41x/main/xmloff/source/draw/ximppage.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
30*cdf0e10cSrcweir #include <tools/debug.hxx>
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <com/sun/star/geometry/RealPoint2D.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/text/XTextCursor.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/util/DateTime.hpp>
35*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
36*cdf0e10cSrcweir #include "XMLNumberStylesImport.hxx"
37*cdf0e10cSrcweir #include <xmloff/xmlstyle.hxx>
38*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
39*cdf0e10cSrcweir #include <xmloff/xmlstyle.hxx>
40*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
41*cdf0e10cSrcweir #include "ximppage.hxx"
42*cdf0e10cSrcweir #include "ximpshap.hxx"
43*cdf0e10cSrcweir #include "animimp.hxx"
44*cdf0e10cSrcweir #include "XMLStringBufferImportContext.hxx"
45*cdf0e10cSrcweir #include <xmloff/formsimp.hxx>
46*cdf0e10cSrcweir #include <xmloff/xmlictxt.hxx>
47*cdf0e10cSrcweir #include "ximpstyl.hxx"
48*cdf0e10cSrcweir #include <xmloff/prstylei.hxx>
49*cdf0e10cSrcweir #include "PropertySetMerger.hxx"
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #include "unointerfacetouniqueidentifiermapper.hxx"
52*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir using ::rtl::OUString;
55*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir using namespace ::com::sun::star;
58*cdf0e10cSrcweir using namespace ::xmloff::token;
59*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
60*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
61*cdf0e10cSrcweir using namespace ::com::sun::star::text;
62*cdf0e10cSrcweir using namespace ::com::sun::star::util;
63*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
64*cdf0e10cSrcweir using namespace ::com::sun::star::drawing;
65*cdf0e10cSrcweir using namespace ::com::sun::star::container;
66*cdf0e10cSrcweir using namespace ::com::sun::star::office;
67*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
68*cdf0e10cSrcweir using namespace ::com::sun::star::geometry;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir class DrawAnnotationContext : public SvXMLImportContext
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir public:
77*cdf0e10cSrcweir     DrawAnnotationContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,const Reference< xml::sax::XAttributeList>& xAttrList, const Reference< XAnnotationAccess >& xAnnotationAccess );
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	virtual SvXMLImportContext * CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList );
80*cdf0e10cSrcweir     virtual void EndElement();
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir private:
83*cdf0e10cSrcweir     Reference< XAnnotation > mxAnnotation;
84*cdf0e10cSrcweir 	Reference< XTextCursor > mxCursor;
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 	OUStringBuffer maAuthorBuffer;
87*cdf0e10cSrcweir 	OUStringBuffer maDateBuffer;
88*cdf0e10cSrcweir };
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir DrawAnnotationContext::DrawAnnotationContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLocalName,const Reference< xml::sax::XAttributeList>& xAttrList, const Reference< XAnnotationAccess >& xAnnotationAccess )
91*cdf0e10cSrcweir : SvXMLImportContext( rImport, nPrfx, rLocalName )
92*cdf0e10cSrcweir , mxAnnotation( xAnnotationAccess->createAndInsertAnnotation() )
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir     if( mxAnnotation.is() )
95*cdf0e10cSrcweir     {
96*cdf0e10cSrcweir 	    sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir         RealPoint2D aPosition;
99*cdf0e10cSrcweir         RealSize2D aSize;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 	    for(sal_Int16 i=0; i < nAttrCount; i++)
102*cdf0e10cSrcweir 	    {
103*cdf0e10cSrcweir             OUString sValue( xAttrList->getValueByIndex( i ) );
104*cdf0e10cSrcweir 		    OUString sAttrName( xAttrList->getNameByIndex( i ) );
105*cdf0e10cSrcweir 		    OUString aLocalName;
106*cdf0e10cSrcweir 		    switch( GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ) )
107*cdf0e10cSrcweir             {
108*cdf0e10cSrcweir             case XML_NAMESPACE_SVG:
109*cdf0e10cSrcweir                 if( IsXMLToken( aLocalName, XML_X ) )
110*cdf0e10cSrcweir                 {
111*cdf0e10cSrcweir                     sal_Int32 x;
112*cdf0e10cSrcweir                     GetImport().GetMM100UnitConverter().convertMeasure(x, sValue);
113*cdf0e10cSrcweir                     aPosition.X = static_cast<double>(x) / 100.0;
114*cdf0e10cSrcweir                 }
115*cdf0e10cSrcweir                 else if( IsXMLToken( aLocalName, XML_Y ) )
116*cdf0e10cSrcweir                 {
117*cdf0e10cSrcweir                     sal_Int32 y;
118*cdf0e10cSrcweir                     GetImport().GetMM100UnitConverter().convertMeasure(y, sValue);
119*cdf0e10cSrcweir                     aPosition.Y = static_cast<double>(y) / 100.0;
120*cdf0e10cSrcweir                 }
121*cdf0e10cSrcweir                 else if( IsXMLToken( aLocalName, XML_WIDTH ) )
122*cdf0e10cSrcweir                 {
123*cdf0e10cSrcweir                     sal_Int32 w;
124*cdf0e10cSrcweir                     GetImport().GetMM100UnitConverter().convertMeasure(w, sValue);
125*cdf0e10cSrcweir                     aSize.Width = static_cast<double>(w) / 100.0;
126*cdf0e10cSrcweir                 }
127*cdf0e10cSrcweir                 else if( IsXMLToken( aLocalName, XML_HEIGHT ) )
128*cdf0e10cSrcweir                 {
129*cdf0e10cSrcweir                     sal_Int32 h;
130*cdf0e10cSrcweir                     GetImport().GetMM100UnitConverter().convertMeasure(h, sValue);
131*cdf0e10cSrcweir                     aSize.Height = static_cast<double>(h) / 100.0;
132*cdf0e10cSrcweir                 }
133*cdf0e10cSrcweir                 break;
134*cdf0e10cSrcweir             default:
135*cdf0e10cSrcweir                 break;
136*cdf0e10cSrcweir 		    }
137*cdf0e10cSrcweir 	    }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir         mxAnnotation->setPosition( aPosition );
140*cdf0e10cSrcweir         mxAnnotation->setSize( aSize );
141*cdf0e10cSrcweir     }
142*cdf0e10cSrcweir }
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir SvXMLImportContext * DrawAnnotationContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList )
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir 	SvXMLImportContext * pContext = NULL;
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     if( mxAnnotation.is() )
149*cdf0e10cSrcweir     {
150*cdf0e10cSrcweir 	    if( XML_NAMESPACE_DC == nPrefix )
151*cdf0e10cSrcweir 	    {
152*cdf0e10cSrcweir 		    if( IsXMLToken( rLocalName, XML_CREATOR ) )
153*cdf0e10cSrcweir 			    pContext = new XMLStringBufferImportContext(GetImport(), nPrefix, rLocalName, maAuthorBuffer);
154*cdf0e10cSrcweir 		    else if( IsXMLToken( rLocalName, XML_DATE ) )
155*cdf0e10cSrcweir 			    pContext = new XMLStringBufferImportContext(GetImport(), nPrefix, rLocalName, maDateBuffer);
156*cdf0e10cSrcweir 	    }
157*cdf0e10cSrcweir         else
158*cdf0e10cSrcweir 	    {
159*cdf0e10cSrcweir 		    // create text cursor on demand
160*cdf0e10cSrcweir 		    if( !mxCursor.is() )
161*cdf0e10cSrcweir 		    {
162*cdf0e10cSrcweir 			    uno::Reference< text::XText > xText( mxAnnotation->getTextRange() );
163*cdf0e10cSrcweir 			    if( xText.is() )
164*cdf0e10cSrcweir 			    {
165*cdf0e10cSrcweir 				    UniReference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport();
166*cdf0e10cSrcweir 				    mxCursor = xText->createTextCursor();
167*cdf0e10cSrcweir 				    if( mxCursor.is() )
168*cdf0e10cSrcweir 					    xTxtImport->SetCursor( mxCursor );
169*cdf0e10cSrcweir 			    }
170*cdf0e10cSrcweir 		    }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 		    // if we have a text cursor, lets  try to import some text
173*cdf0e10cSrcweir 		    if( mxCursor.is() )
174*cdf0e10cSrcweir 		    {
175*cdf0e10cSrcweir 			    pContext = GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nPrefix, rLocalName, xAttrList );
176*cdf0e10cSrcweir 		    }
177*cdf0e10cSrcweir 	    }
178*cdf0e10cSrcweir     }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 	// call parent for content
181*cdf0e10cSrcweir 	if(!pContext)
182*cdf0e10cSrcweir 		pContext = SvXMLImportContext::CreateChildContext( nPrefix, rLocalName, xAttrList );
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir 	return pContext;
185*cdf0e10cSrcweir }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir void DrawAnnotationContext::EndElement()
188*cdf0e10cSrcweir {
189*cdf0e10cSrcweir 	if(mxCursor.is())
190*cdf0e10cSrcweir 	{
191*cdf0e10cSrcweir 		// delete addition newline
192*cdf0e10cSrcweir 		const OUString aEmpty;
193*cdf0e10cSrcweir 		mxCursor->gotoEnd( sal_False );
194*cdf0e10cSrcweir 		mxCursor->goLeft( 1, sal_True );
195*cdf0e10cSrcweir 		mxCursor->setString( aEmpty );
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 		// reset cursor
198*cdf0e10cSrcweir 		GetImport().GetTextImport()->ResetCursor();
199*cdf0e10cSrcweir     }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir     if( mxAnnotation.is() )
202*cdf0e10cSrcweir     {
203*cdf0e10cSrcweir     	mxAnnotation->setAuthor( maAuthorBuffer.makeStringAndClear() );
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir     	DateTime aDateTime;
206*cdf0e10cSrcweir 	    if(SvXMLUnitConverter::convertDateTime(aDateTime,  maDateBuffer.makeStringAndClear()))
207*cdf0e10cSrcweir     		mxAnnotation->setDateTime(aDateTime);
208*cdf0e10cSrcweir 	}
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir TYPEINIT1( SdXMLGenericPageContext, SvXMLImportContext );
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir SdXMLGenericPageContext::SdXMLGenericPageContext(
216*cdf0e10cSrcweir 	SvXMLImport& rImport,
217*cdf0e10cSrcweir 	sal_uInt16 nPrfx, const OUString& rLocalName,
218*cdf0e10cSrcweir 	const Reference< xml::sax::XAttributeList>& xAttrList,
219*cdf0e10cSrcweir 	Reference< drawing::XShapes >& rShapes)
220*cdf0e10cSrcweir : SvXMLImportContext( rImport, nPrfx, rLocalName )
221*cdf0e10cSrcweir , mxShapes( rShapes )
222*cdf0e10cSrcweir , mxAnnotationAccess( rShapes, UNO_QUERY )
223*cdf0e10cSrcweir {
224*cdf0e10cSrcweir 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 	for(sal_Int16 i=0; i < nAttrCount; i++)
227*cdf0e10cSrcweir 	{
228*cdf0e10cSrcweir 		OUString sAttrName = xAttrList->getNameByIndex( i );
229*cdf0e10cSrcweir 		OUString aLocalName;
230*cdf0e10cSrcweir 		sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
231*cdf0e10cSrcweir 		if( (nPrefix == XML_NAMESPACE_DRAW) && IsXMLToken( aLocalName, XML_NAV_ORDER ) )
232*cdf0e10cSrcweir 		{
233*cdf0e10cSrcweir 			msNavOrder = xAttrList->getValueByIndex( i );
234*cdf0e10cSrcweir 			break;
235*cdf0e10cSrcweir 		}
236*cdf0e10cSrcweir 	}
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir SdXMLGenericPageContext::~SdXMLGenericPageContext()
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir void SdXMLGenericPageContext::StartElement( const Reference< ::com::sun::star::xml::sax::XAttributeList >& )
248*cdf0e10cSrcweir {
249*cdf0e10cSrcweir 	GetImport().GetShapeImport()->pushGroupForSorting( mxShapes );
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 	if( GetImport().IsFormsSupported() )
252*cdf0e10cSrcweir 		GetImport().GetFormImport()->startPage( Reference< drawing::XDrawPage >::query( mxShapes ) );
253*cdf0e10cSrcweir }
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir SvXMLImportContext* SdXMLGenericPageContext::CreateChildContext( sal_uInt16 nPrefix,
258*cdf0e10cSrcweir 	const OUString& rLocalName,
259*cdf0e10cSrcweir 	const Reference< xml::sax::XAttributeList>& xAttrList )
260*cdf0e10cSrcweir {
261*cdf0e10cSrcweir 	SvXMLImportContext* pContext = 0L;
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir 	if( nPrefix == XML_NAMESPACE_PRESENTATION && IsXMLToken( rLocalName, XML_ANIMATIONS ) )
264*cdf0e10cSrcweir 	{
265*cdf0e10cSrcweir 		pContext = new XMLAnimationsContext( GetImport(), nPrefix, rLocalName, xAttrList );
266*cdf0e10cSrcweir 	}
267*cdf0e10cSrcweir 	else if( nPrefix == XML_NAMESPACE_OFFICE && IsXMLToken( rLocalName, XML_FORMS ) )
268*cdf0e10cSrcweir 	{
269*cdf0e10cSrcweir 		if( GetImport().IsFormsSupported() )
270*cdf0e10cSrcweir 			pContext = GetImport().GetFormImport()->createOfficeFormsContext( GetImport(), nPrefix, rLocalName );
271*cdf0e10cSrcweir 	}
272*cdf0e10cSrcweir     else if( ((nPrefix == XML_NAMESPACE_OFFICE) || (nPrefix == XML_NAMESPACE_OFFICE_EXT)) && IsXMLToken( rLocalName, XML_ANNOTATION ) )
273*cdf0e10cSrcweir     {
274*cdf0e10cSrcweir         if( mxAnnotationAccess.is() )
275*cdf0e10cSrcweir             pContext = new DrawAnnotationContext( GetImport(), nPrefix, rLocalName, xAttrList, mxAnnotationAccess );
276*cdf0e10cSrcweir     }
277*cdf0e10cSrcweir 	else
278*cdf0e10cSrcweir 	{
279*cdf0e10cSrcweir 		// call GroupChildContext function at common ShapeImport
280*cdf0e10cSrcweir 		pContext = GetImport().GetShapeImport()->CreateGroupChildContext(
281*cdf0e10cSrcweir 			GetImport(), nPrefix, rLocalName, xAttrList, mxShapes);
282*cdf0e10cSrcweir 	}
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 	// call parent when no own context was created
285*cdf0e10cSrcweir 	if(!pContext)
286*cdf0e10cSrcweir 		pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList);
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir 	return pContext;
289*cdf0e10cSrcweir }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir void SdXMLGenericPageContext::EndElement()
294*cdf0e10cSrcweir {
295*cdf0e10cSrcweir 	GetImport().GetShapeImport()->popGroupAndSort();
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 	if( GetImport().IsFormsSupported() )
298*cdf0e10cSrcweir 		GetImport().GetFormImport()->endPage();
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 	if( maUseHeaderDeclName.getLength() || maUseFooterDeclName.getLength() || maUseDateTimeDeclName.getLength() )
301*cdf0e10cSrcweir 	{
302*cdf0e10cSrcweir 		try
303*cdf0e10cSrcweir 		{
304*cdf0e10cSrcweir 			Reference <beans::XPropertySet> xSet(mxShapes, uno::UNO_QUERY_THROW );
305*cdf0e10cSrcweir 			Reference< beans::XPropertySetInfo > xInfo( xSet->getPropertySetInfo() );
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 			if( maUseHeaderDeclName.getLength() )
308*cdf0e10cSrcweir 			{
309*cdf0e10cSrcweir 				const OUString aStrHeaderTextProp( RTL_CONSTASCII_USTRINGPARAM( "HeaderText" ) );
310*cdf0e10cSrcweir 				if( xInfo->hasPropertyByName( aStrHeaderTextProp ) )
311*cdf0e10cSrcweir 					xSet->setPropertyValue( aStrHeaderTextProp,
312*cdf0e10cSrcweir 											makeAny( GetSdImport().GetHeaderDecl( maUseHeaderDeclName ) ) );
313*cdf0e10cSrcweir 			}
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 			if( maUseFooterDeclName.getLength() )
316*cdf0e10cSrcweir 			{
317*cdf0e10cSrcweir 				const OUString aStrFooterTextProp( RTL_CONSTASCII_USTRINGPARAM( "FooterText" ) );
318*cdf0e10cSrcweir 				if( xInfo->hasPropertyByName( aStrFooterTextProp ) )
319*cdf0e10cSrcweir 					xSet->setPropertyValue( aStrFooterTextProp,
320*cdf0e10cSrcweir 										makeAny( GetSdImport().GetFooterDecl( maUseFooterDeclName ) ) );
321*cdf0e10cSrcweir 			}
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir 			if( maUseDateTimeDeclName.getLength() )
324*cdf0e10cSrcweir 			{
325*cdf0e10cSrcweir 				const OUString aStrDateTimeTextProp( RTL_CONSTASCII_USTRINGPARAM( "DateTimeText" ) );
326*cdf0e10cSrcweir 				if( xInfo->hasPropertyByName( aStrDateTimeTextProp ) )
327*cdf0e10cSrcweir 				{
328*cdf0e10cSrcweir 					sal_Bool bFixed;
329*cdf0e10cSrcweir 					OUString aDateTimeFormat;
330*cdf0e10cSrcweir 					const OUString aText( GetSdImport().GetDateTimeDecl( maUseDateTimeDeclName, bFixed, aDateTimeFormat ) );
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 					xSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("IsDateTimeFixed") ),
333*cdf0e10cSrcweir 										makeAny( bFixed ) );
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 					if( bFixed )
336*cdf0e10cSrcweir 					{
337*cdf0e10cSrcweir 						xSet->setPropertyValue( aStrDateTimeTextProp, makeAny( aText ) );
338*cdf0e10cSrcweir 					}
339*cdf0e10cSrcweir 					else if( aDateTimeFormat.getLength() )
340*cdf0e10cSrcweir 					{
341*cdf0e10cSrcweir 						const SdXMLStylesContext* pStyles = dynamic_cast< const SdXMLStylesContext* >( GetSdImport().GetShapeImport()->GetStylesContext() );
342*cdf0e10cSrcweir 						if( !pStyles )
343*cdf0e10cSrcweir 							pStyles = dynamic_cast< const SdXMLStylesContext* >( GetSdImport().GetShapeImport()->GetAutoStylesContext() );
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 						if( pStyles )
346*cdf0e10cSrcweir 						{
347*cdf0e10cSrcweir 							const SdXMLNumberFormatImportContext* pSdNumStyle =
348*cdf0e10cSrcweir 								dynamic_cast< const SdXMLNumberFormatImportContext* >( pStyles->FindStyleChildContext( XML_STYLE_FAMILY_DATA_STYLE, aDateTimeFormat, sal_True ) );
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 							if( pSdNumStyle )
351*cdf0e10cSrcweir 							{
352*cdf0e10cSrcweir 								xSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("DateTimeFormat") ),
353*cdf0e10cSrcweir 																	makeAny( pSdNumStyle->GetDrawKey() ) );
354*cdf0e10cSrcweir 							}
355*cdf0e10cSrcweir 						}
356*cdf0e10cSrcweir 					}
357*cdf0e10cSrcweir 				}
358*cdf0e10cSrcweir 			}
359*cdf0e10cSrcweir 		}
360*cdf0e10cSrcweir 		catch( uno::Exception& e )
361*cdf0e10cSrcweir 		{
362*cdf0e10cSrcweir 			(void)e;
363*cdf0e10cSrcweir 			DBG_ERROR("xmloff::SdXMLGenericPageContext::EndElement(), unexpected exception cought!");
364*cdf0e10cSrcweir 		}
365*cdf0e10cSrcweir 	}
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 	SetNavigationOrder();
368*cdf0e10cSrcweir }
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir void SdXMLGenericPageContext::SetStyle( rtl::OUString& rStyleName )
371*cdf0e10cSrcweir {
372*cdf0e10cSrcweir 	// set PageProperties?
373*cdf0e10cSrcweir 	if(rStyleName.getLength())
374*cdf0e10cSrcweir 	{
375*cdf0e10cSrcweir 		try
376*cdf0e10cSrcweir 		{
377*cdf0e10cSrcweir 			const SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetAutoStylesContext();
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 			if( pContext && pContext->ISA( SvXMLStyleContext ) )
380*cdf0e10cSrcweir 			{
381*cdf0e10cSrcweir 				const SdXMLStylesContext* pStyles = (SdXMLStylesContext*)pContext;
382*cdf0e10cSrcweir 				if(pStyles)
383*cdf0e10cSrcweir 				{
384*cdf0e10cSrcweir 					const SvXMLStyleContext* pStyle = pStyles->FindStyleChildContext(
385*cdf0e10cSrcweir 						XML_STYLE_FAMILY_SD_DRAWINGPAGE_ID, rStyleName);
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir 					if(pStyle && pStyle->ISA(XMLPropStyleContext))
388*cdf0e10cSrcweir 					{
389*cdf0e10cSrcweir 						XMLPropStyleContext* pPropStyle = (XMLPropStyleContext*)pStyle;
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir 						Reference <beans::XPropertySet> xPropSet1(mxShapes, uno::UNO_QUERY);
392*cdf0e10cSrcweir 						if(xPropSet1.is())
393*cdf0e10cSrcweir 						{
394*cdf0e10cSrcweir 							Reference< beans::XPropertySet > xPropSet( xPropSet1 );
395*cdf0e10cSrcweir 							Reference< beans::XPropertySet > xBackgroundSet;
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir 							const OUString aBackground(RTL_CONSTASCII_USTRINGPARAM("Background"));
398*cdf0e10cSrcweir 							if( xPropSet1->getPropertySetInfo()->hasPropertyByName( aBackground ) )
399*cdf0e10cSrcweir 							{
400*cdf0e10cSrcweir 								Reference< beans::XPropertySetInfo > xInfo( xPropSet1->getPropertySetInfo() );
401*cdf0e10cSrcweir 								if( xInfo.is() && xInfo->hasPropertyByName( aBackground ) )
402*cdf0e10cSrcweir 								{
403*cdf0e10cSrcweir 									Reference< lang::XMultiServiceFactory > xServiceFact(GetSdImport().GetModel(), uno::UNO_QUERY);
404*cdf0e10cSrcweir 									if(xServiceFact.is())
405*cdf0e10cSrcweir 									{
406*cdf0e10cSrcweir 										xBackgroundSet = Reference< beans::XPropertySet >::query(
407*cdf0e10cSrcweir 											xServiceFact->createInstance(
408*cdf0e10cSrcweir 											OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Background"))));
409*cdf0e10cSrcweir 									}
410*cdf0e10cSrcweir 								}
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 								if( xBackgroundSet.is() )
413*cdf0e10cSrcweir 									xPropSet = PropertySetMerger_CreateInstance( xPropSet1, xBackgroundSet );
414*cdf0e10cSrcweir 							}
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir 							if(xPropSet.is())
417*cdf0e10cSrcweir 							{
418*cdf0e10cSrcweir 								pPropStyle->FillPropertySet(xPropSet);
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 								if( xBackgroundSet.is() )
421*cdf0e10cSrcweir 									xPropSet1->setPropertyValue( aBackground, uno::makeAny( xBackgroundSet ) );
422*cdf0e10cSrcweir 							}
423*cdf0e10cSrcweir 						}
424*cdf0e10cSrcweir 					}
425*cdf0e10cSrcweir 				}
426*cdf0e10cSrcweir 			}
427*cdf0e10cSrcweir 		}
428*cdf0e10cSrcweir 		catch( uno::Exception )
429*cdf0e10cSrcweir 		{
430*cdf0e10cSrcweir 			DBG_ERROR( "SdXMLGenericPageContext::SetStyle(): uno::Exception catched!" );
431*cdf0e10cSrcweir 		}
432*cdf0e10cSrcweir 	}
433*cdf0e10cSrcweir }
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir void SdXMLGenericPageContext::SetLayout()
436*cdf0e10cSrcweir {
437*cdf0e10cSrcweir 	// set PresentationPageLayout?
438*cdf0e10cSrcweir 	if(GetSdImport().IsImpress() && maPageLayoutName.getLength())
439*cdf0e10cSrcweir 	{
440*cdf0e10cSrcweir 		sal_Int32 nType = -1;
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 		const SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetStylesContext();
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir 		if( pContext && pContext->ISA( SvXMLStyleContext ) )
445*cdf0e10cSrcweir 		{
446*cdf0e10cSrcweir 			const SdXMLStylesContext* pStyles = (SdXMLStylesContext*)pContext;
447*cdf0e10cSrcweir 			if(pStyles)
448*cdf0e10cSrcweir 			{
449*cdf0e10cSrcweir 				const SvXMLStyleContext* pStyle = pStyles->FindStyleChildContext( XML_STYLE_FAMILY_SD_PRESENTATIONPAGELAYOUT_ID, maPageLayoutName);
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir 				if(pStyle && pStyle->ISA(SdXMLPresentationPageLayoutContext))
452*cdf0e10cSrcweir 				{
453*cdf0e10cSrcweir 					SdXMLPresentationPageLayoutContext* pLayout = (SdXMLPresentationPageLayoutContext*)pStyle;
454*cdf0e10cSrcweir 					nType = pLayout->GetTypeId();
455*cdf0e10cSrcweir 				}
456*cdf0e10cSrcweir 			}
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir 		}
459*cdf0e10cSrcweir 		if( -1 == nType )
460*cdf0e10cSrcweir 		{
461*cdf0e10cSrcweir 			Reference< container::XNameAccess > xPageLayouts( GetSdImport().getPageLayouts() );
462*cdf0e10cSrcweir 			if( xPageLayouts.is() )
463*cdf0e10cSrcweir 			{
464*cdf0e10cSrcweir 				if( xPageLayouts->hasByName( maPageLayoutName ) )
465*cdf0e10cSrcweir 					xPageLayouts->getByName( maPageLayoutName ) >>= nType;
466*cdf0e10cSrcweir 			}
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir 		}
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir 		if( -1 != nType )
471*cdf0e10cSrcweir 		{
472*cdf0e10cSrcweir 			Reference <beans::XPropertySet> xPropSet(mxShapes, uno::UNO_QUERY);
473*cdf0e10cSrcweir 			if(xPropSet.is())
474*cdf0e10cSrcweir 			{
475*cdf0e10cSrcweir 				OUString aPropName(RTL_CONSTASCII_USTRINGPARAM("Layout"));
476*cdf0e10cSrcweir 				Reference< beans::XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() );
477*cdf0e10cSrcweir 				if( xInfo.is() && xInfo->hasPropertyByName( aPropName ) )
478*cdf0e10cSrcweir 					xPropSet->setPropertyValue(aPropName, uno::makeAny( (sal_Int16)nType ) );
479*cdf0e10cSrcweir 			}
480*cdf0e10cSrcweir 		}
481*cdf0e10cSrcweir 	}
482*cdf0e10cSrcweir }
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir void SdXMLGenericPageContext::DeleteAllShapes()
485*cdf0e10cSrcweir {
486*cdf0e10cSrcweir 	// now delete all up-to-now contained shapes; they have been created
487*cdf0e10cSrcweir 	// when setting the presentation page layout.
488*cdf0e10cSrcweir 	while(mxShapes->getCount())
489*cdf0e10cSrcweir 	{
490*cdf0e10cSrcweir 		Reference< drawing::XShape > xShape;
491*cdf0e10cSrcweir 		uno::Any aAny(mxShapes->getByIndex(0L));
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir 		aAny >>= xShape;
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir 		if(xShape.is())
496*cdf0e10cSrcweir 		{
497*cdf0e10cSrcweir 			mxShapes->remove(xShape);
498*cdf0e10cSrcweir 		}
499*cdf0e10cSrcweir 	}
500*cdf0e10cSrcweir }
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir void SdXMLGenericPageContext::SetPageMaster( OUString& rsPageMasterName )
503*cdf0e10cSrcweir {
504*cdf0e10cSrcweir 	if( GetSdImport().GetShapeImport()->GetStylesContext() )
505*cdf0e10cSrcweir 	{
506*cdf0e10cSrcweir 		// look for PageMaster with this name
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir 		// #80012# GetStylesContext() replaced with GetAutoStylesContext()
509*cdf0e10cSrcweir 		const SvXMLStylesContext* pAutoStyles = GetSdImport().GetShapeImport()->GetAutoStylesContext();
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir 		const SvXMLStyleContext* pStyle = pAutoStyles ? pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_SD_PAGEMASTERCONEXT_ID, rsPageMasterName) : NULL;
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir 		if(pStyle && pStyle->ISA(SdXMLPageMasterContext))
514*cdf0e10cSrcweir 		{
515*cdf0e10cSrcweir 			const SdXMLPageMasterContext* pPageMaster = (SdXMLPageMasterContext*)pStyle;
516*cdf0e10cSrcweir 			const SdXMLPageMasterStyleContext* pPageMasterContext = pPageMaster->GetPageMasterStyle();
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir 			if(pPageMasterContext)
519*cdf0e10cSrcweir 			{
520*cdf0e10cSrcweir 				Reference< drawing::XDrawPage > xMasterPage(GetLocalShapesContext(), uno::UNO_QUERY);
521*cdf0e10cSrcweir 				if(xMasterPage.is())
522*cdf0e10cSrcweir 				{
523*cdf0e10cSrcweir 					// set sizes for this masterpage
524*cdf0e10cSrcweir 					Reference <beans::XPropertySet> xPropSet(xMasterPage, uno::UNO_QUERY);
525*cdf0e10cSrcweir 					if(xPropSet.is())
526*cdf0e10cSrcweir 					{
527*cdf0e10cSrcweir 						uno::Any aAny;
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir 						aAny <<= pPageMasterContext->GetBorderBottom();
530*cdf0e10cSrcweir 						xPropSet->setPropertyValue(
531*cdf0e10cSrcweir 							OUString(RTL_CONSTASCII_USTRINGPARAM("BorderBottom")), aAny);
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir 						aAny <<= pPageMasterContext->GetBorderLeft();
534*cdf0e10cSrcweir 						xPropSet->setPropertyValue(
535*cdf0e10cSrcweir 							OUString(RTL_CONSTASCII_USTRINGPARAM("BorderLeft")), aAny);
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir 						aAny <<= pPageMasterContext->GetBorderRight();
538*cdf0e10cSrcweir 						xPropSet->setPropertyValue(
539*cdf0e10cSrcweir 							OUString(RTL_CONSTASCII_USTRINGPARAM("BorderRight")), aAny);
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir 						aAny <<= pPageMasterContext->GetBorderTop();
542*cdf0e10cSrcweir 						xPropSet->setPropertyValue(
543*cdf0e10cSrcweir 							OUString(RTL_CONSTASCII_USTRINGPARAM("BorderTop")), aAny);
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir 						aAny <<= pPageMasterContext->GetWidth();
546*cdf0e10cSrcweir 						xPropSet->setPropertyValue(
547*cdf0e10cSrcweir 							OUString(RTL_CONSTASCII_USTRINGPARAM("Width")), aAny);
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir 						aAny <<= pPageMasterContext->GetHeight();
550*cdf0e10cSrcweir 						xPropSet->setPropertyValue(
551*cdf0e10cSrcweir 							OUString(RTL_CONSTASCII_USTRINGPARAM("Height")), aAny);
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir 						aAny <<= pPageMasterContext->GetOrientation();
554*cdf0e10cSrcweir 						xPropSet->setPropertyValue(
555*cdf0e10cSrcweir 							OUString(RTL_CONSTASCII_USTRINGPARAM("Orientation")), aAny);
556*cdf0e10cSrcweir 					}
557*cdf0e10cSrcweir 				}
558*cdf0e10cSrcweir 			}
559*cdf0e10cSrcweir 		}
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir 	}
562*cdf0e10cSrcweir }
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir class NavigationOrderAccess : public ::cppu::WeakImplHelper1< XIndexAccess >
565*cdf0e10cSrcweir {
566*cdf0e10cSrcweir public:
567*cdf0e10cSrcweir 	NavigationOrderAccess( std::vector< Reference< XShape > >& rShapes );
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir 	// XIndexAccess
570*cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL getCount(  ) throw (RuntimeException);
571*cdf0e10cSrcweir     virtual Any SAL_CALL getByIndex( sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException);
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir     // XElementAccess
574*cdf0e10cSrcweir     virtual Type SAL_CALL getElementType(  ) throw (RuntimeException);
575*cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasElements(  ) throw (RuntimeException);
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir private:
578*cdf0e10cSrcweir 	std::vector< Reference< XShape > > maShapes;
579*cdf0e10cSrcweir };
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir NavigationOrderAccess::NavigationOrderAccess( std::vector< Reference< XShape > >& rShapes )
582*cdf0e10cSrcweir {
583*cdf0e10cSrcweir 	maShapes.swap( rShapes );
584*cdf0e10cSrcweir }
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir // XIndexAccess
587*cdf0e10cSrcweir sal_Int32 SAL_CALL NavigationOrderAccess::getCount(  ) throw (RuntimeException)
588*cdf0e10cSrcweir {
589*cdf0e10cSrcweir 	return static_cast< sal_Int32 >( maShapes.size() );
590*cdf0e10cSrcweir }
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir Any SAL_CALL NavigationOrderAccess::getByIndex( sal_Int32 Index ) throw (IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
593*cdf0e10cSrcweir {
594*cdf0e10cSrcweir 	if( (Index < 0) || (Index > getCount()) )
595*cdf0e10cSrcweir 		throw IndexOutOfBoundsException();
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir 	return Any( maShapes[Index] );
598*cdf0e10cSrcweir }
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir // XElementAccess
601*cdf0e10cSrcweir Type SAL_CALL NavigationOrderAccess::getElementType(  ) throw (RuntimeException)
602*cdf0e10cSrcweir {
603*cdf0e10cSrcweir 	return XShape::static_type();
604*cdf0e10cSrcweir }
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir sal_Bool SAL_CALL NavigationOrderAccess::hasElements(  ) throw (RuntimeException)
607*cdf0e10cSrcweir {
608*cdf0e10cSrcweir 	return maShapes.empty() ? sal_False : sal_True;
609*cdf0e10cSrcweir }
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir void SdXMLGenericPageContext::SetNavigationOrder()
612*cdf0e10cSrcweir {
613*cdf0e10cSrcweir 	if( msNavOrder.getLength() != 0 ) try
614*cdf0e10cSrcweir 	{
615*cdf0e10cSrcweir 		sal_uInt32 nIndex;
616*cdf0e10cSrcweir 		const sal_uInt32 nCount = static_cast< sal_uInt32 >( mxShapes->getCount() );
617*cdf0e10cSrcweir 		std::vector< Reference< XShape > > aShapes( nCount );
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir 		::comphelper::UnoInterfaceToUniqueIdentifierMapper& rIdMapper = GetSdImport().getInterfaceToIdentifierMapper();
620*cdf0e10cSrcweir 		SvXMLTokenEnumerator aEnumerator( msNavOrder );
621*cdf0e10cSrcweir 		OUString sId;
622*cdf0e10cSrcweir 		for( nIndex = 0; nIndex < nCount; ++nIndex )
623*cdf0e10cSrcweir 		{
624*cdf0e10cSrcweir 			if( !aEnumerator.getNextToken(sId) )
625*cdf0e10cSrcweir 				break;
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir 			aShapes[nIndex] = Reference< XShape >( rIdMapper.getReference( sId ), UNO_QUERY );
628*cdf0e10cSrcweir 		}
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir 		for( nIndex = 0; nIndex < nCount; ++nIndex )
631*cdf0e10cSrcweir 		{
632*cdf0e10cSrcweir 			if( !aShapes[nIndex].is() )
633*cdf0e10cSrcweir 			{
634*cdf0e10cSrcweir 				DBG_ERROR("xmloff::SdXMLGenericPageContext::SetNavigationOrder(), draw:nav-order attribute incomplete!");
635*cdf0e10cSrcweir 				// todo: warning?
636*cdf0e10cSrcweir 				return;
637*cdf0e10cSrcweir 			}
638*cdf0e10cSrcweir 		}
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir 		Reference< XPropertySet > xSet( mxShapes, UNO_QUERY_THROW );
641*cdf0e10cSrcweir 		xSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "NavigationOrder" ) ), Any( Reference< XIndexAccess >( new NavigationOrderAccess( aShapes ) ) ) );
642*cdf0e10cSrcweir 	}
643*cdf0e10cSrcweir 	catch( uno::Exception& )
644*cdf0e10cSrcweir 	{
645*cdf0e10cSrcweir 		DBG_ERROR("xmloff::SdXMLGenericPageContext::SetNavigationOrder(), unexpected exception cought while importing shape navigation order!");
646*cdf0e10cSrcweir 	}
647*cdf0e10cSrcweir }
648