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