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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmloff.hxx" 30 #include "ximpbody.hxx" 31 #include <xmloff/prstylei.hxx> 32 #include "ximpnote.hxx" 33 #include <com/sun/star/drawing/XDrawPage.hpp> 34 #include <com/sun/star/drawing/XDrawPages.hpp> 35 #include <com/sun/star/container/XNamed.hpp> 36 #include <com/sun/star/presentation/XPresentationPage.hpp> 37 #include "ximpstyl.hxx" 38 #include <com/sun/star/drawing/XMasterPageTarget.hpp> 39 #include <com/sun/star/beans/XPropertySet.hpp> 40 #include <com/sun/star/animations/XAnimationNodeSupplier.hpp> 41 42 #include "unointerfacetouniqueidentifiermapper.hxx" 43 #include <xmloff/xmluconv.hxx> 44 #include <xmloff/xmlprmap.hxx> 45 #include <xmloff/families.hxx> 46 #include "ximpshow.hxx" 47 #include "PropertySetMerger.hxx" 48 #include "animationimport.hxx" 49 #include <tools/string.hxx> 50 51 using ::rtl::OUString; 52 using ::rtl::OUStringBuffer; 53 54 using namespace ::com::sun::star; 55 56 ////////////////////////////////////////////////////////////////////////////// 57 58 SdXMLDrawPageContext::SdXMLDrawPageContext( SdXMLImport& rImport, 59 sal_uInt16 nPrfx, const OUString& rLocalName, 60 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 61 uno::Reference< drawing::XShapes >& rShapes) 62 : SdXMLGenericPageContext( rImport, nPrfx, rLocalName, xAttrList, rShapes ) 63 , mbHadSMILNodes( false ) 64 { 65 bool bHaveXmlId( false ); 66 OUString sXmlId; 67 68 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 69 70 for(sal_Int16 i=0; i < nAttrCount; i++) 71 { 72 OUString sAttrName = xAttrList->getNameByIndex( i ); 73 OUString aLocalName; 74 sal_uInt16 nPrefix = GetSdImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); 75 OUString sValue = xAttrList->getValueByIndex( i ); 76 const SvXMLTokenMap& rAttrTokenMap = GetSdImport().GetDrawPageAttrTokenMap(); 77 78 switch(rAttrTokenMap.Get(nPrefix, aLocalName)) 79 { 80 case XML_TOK_DRAWPAGE_NAME: 81 { 82 maName = sValue; 83 break; 84 } 85 case XML_TOK_DRAWPAGE_STYLE_NAME: 86 { 87 maStyleName = sValue; 88 break; 89 } 90 case XML_TOK_DRAWPAGE_MASTER_PAGE_NAME: 91 { 92 maMasterPageName = sValue; 93 break; 94 } 95 case XML_TOK_DRAWPAGE_PAGE_LAYOUT_NAME: 96 { 97 maPageLayoutName = sValue; 98 break; 99 } 100 case XML_TOK_DRAWPAGE_USE_HEADER_NAME: 101 { 102 maUseHeaderDeclName = sValue; 103 break; 104 } 105 case XML_TOK_DRAWPAGE_USE_FOOTER_NAME: 106 { 107 maUseFooterDeclName = sValue; 108 break; 109 } 110 case XML_TOK_DRAWPAGE_USE_DATE_TIME_NAME: 111 { 112 maUseDateTimeDeclName = sValue; 113 break; 114 } 115 case XML_TOK_DRAWPAGE_DRAWID: 116 { 117 if (!bHaveXmlId) { sXmlId = sValue; } 118 } 119 break; 120 case XML_TOK_DRAWPAGE_XMLID: 121 { 122 sXmlId = sValue; 123 bHaveXmlId = true; 124 } 125 break; 126 case XML_TOK_DRAWPAGE_HREF: 127 { 128 maHREF = sValue; 129 break; 130 } 131 } 132 } 133 134 if (sXmlId.getLength()) 135 { 136 uno::Reference< uno::XInterface > const xRef( rShapes.get() ); 137 GetImport().getInterfaceToIdentifierMapper().registerReference( 138 sXmlId, xRef ); 139 } 140 GetImport().GetShapeImport()->startPage( rShapes ); 141 142 uno::Reference< drawing::XDrawPage > xShapeDrawPage(rShapes, uno::UNO_QUERY); 143 144 // set PageName? 145 if(maName.getLength()) 146 { 147 if(xShapeDrawPage.is()) 148 { 149 uno::Reference < container::XNamed > xNamed(xShapeDrawPage, uno::UNO_QUERY); 150 if(xNamed.is()) 151 xNamed->setName(maName); 152 } 153 } 154 155 // set MasterPage? 156 if(maMasterPageName.getLength()) 157 { 158 // #85906# Code for setting masterpage needs complete rework 159 // since GetSdImport().GetMasterStylesContext() gives always ZERO 160 // because of content/style file split. Now the nechanism is to 161 // compare the wanted masterpage-name with the existing masterpages 162 // which were loaded and created in the styles section loading. 163 uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY); 164 uno::Reference < drawing::XMasterPageTarget > xDrawPage(rShapes, uno::UNO_QUERY); 165 uno::Reference< drawing::XDrawPage > xMasterPage; 166 167 if(xDrawPage.is() && xMasterPages.is()) 168 { 169 sal_Bool bDone(sal_False); 170 OUString sDisplayName( rImport.GetStyleDisplayName( 171 XML_STYLE_FAMILY_MASTER_PAGE, maMasterPageName ) ); 172 173 for(sal_Int32 a = 0; !bDone && a < xMasterPages->getCount(); a++) 174 { 175 uno::Any aAny(xMasterPages->getByIndex(a)); 176 aAny >>= xMasterPage; 177 178 if(xMasterPage.is()) 179 { 180 uno::Reference < container::XNamed > xMasterNamed(xMasterPage, uno::UNO_QUERY); 181 if(xMasterNamed.is()) 182 { 183 OUString sMasterPageName = xMasterNamed->getName(); 184 185 if(sMasterPageName.getLength() && 186 sMasterPageName.equals(sDisplayName)) 187 { 188 xDrawPage->setMasterPage(xMasterPage); 189 bDone = sal_True; 190 } 191 } 192 } 193 } 194 195 DBG_ASSERT( bDone, "xmloff::SdXMLDrawPageContext::SdXMLDrawPageContext(), could not find a slide master!" ); 196 } 197 } 198 199 SetStyle( maStyleName ); 200 201 if( maHREF.getLength() ) 202 { 203 uno::Reference< beans::XPropertySet > xProps( xShapeDrawPage, uno::UNO_QUERY ); 204 if( xProps.is() ) 205 { 206 sal_Int32 nIndex = maHREF.lastIndexOf( (sal_Unicode)'#' ); 207 if( nIndex != -1 ) 208 { 209 OUString aFileName( maHREF.copy( 0, nIndex ) ); 210 OUString aBookmarkName( maHREF.copy( nIndex+1 ) ); 211 212 maHREF = GetImport().GetAbsoluteReference( aFileName ); 213 maHREF += String( (sal_Unicode)'#' ); 214 maHREF += aBookmarkName; 215 } 216 217 xProps->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "BookmarkURL" ) ), uno::makeAny( maHREF ) ); 218 } 219 } 220 221 SetLayout(); 222 223 DeleteAllShapes(); 224 } 225 226 ////////////////////////////////////////////////////////////////////////////// 227 228 SdXMLDrawPageContext::~SdXMLDrawPageContext() 229 { 230 } 231 232 ////////////////////////////////////////////////////////////////////////////// 233 234 SvXMLImportContext *SdXMLDrawPageContext::CreateChildContext( sal_uInt16 nPrefix, 235 const OUString& rLocalName, 236 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList ) 237 { 238 SvXMLImportContext *pContext = 0L; 239 const SvXMLTokenMap& rTokenMap = GetSdImport().GetDrawPageElemTokenMap(); 240 241 // some special objects inside draw:page context 242 switch(rTokenMap.Get(nPrefix, rLocalName)) 243 { 244 case XML_TOK_DRAWPAGE_NOTES: 245 { 246 if( GetSdImport().IsImpress() ) 247 { 248 // get notes page 249 uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY); 250 if(xPresPage.is()) 251 { 252 uno::Reference< drawing::XDrawPage > xNotesDrawPage(xPresPage->getNotesPage(), uno::UNO_QUERY); 253 if(xNotesDrawPage.is()) 254 { 255 uno::Reference< drawing::XShapes > xNewShapes(xNotesDrawPage, uno::UNO_QUERY); 256 if(xNewShapes.is()) 257 { 258 // presentation:notes inside draw:page context 259 pContext = new SdXMLNotesContext( GetSdImport(), nPrefix, rLocalName, xAttrList, xNewShapes); 260 } 261 } 262 } 263 } 264 break; 265 } 266 case XML_TOK_DRAWPAGE_PAR: 267 case XML_TOK_DRAWPAGE_SEQ: 268 { 269 if( GetSdImport().IsImpress() ) 270 { 271 uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY); 272 if(xNodeSupplier.is()) 273 { 274 pContext = new xmloff::AnimationNodeContext( xNodeSupplier->getAnimationNode(), GetSdImport(), nPrefix, rLocalName, xAttrList ); 275 mbHadSMILNodes = true; 276 } 277 } 278 break; 279 } 280 } 281 282 // call parent when no own context was created 283 if(!pContext) 284 pContext = SdXMLGenericPageContext::CreateChildContext(nPrefix, rLocalName, xAttrList); 285 286 return pContext; 287 } 288 289 void SdXMLDrawPageContext::EndElement() 290 { 291 SdXMLGenericPageContext::EndElement(); 292 GetImport().GetShapeImport()->endPage(GetLocalShapesContext()); 293 294 if( mbHadSMILNodes ) 295 { 296 uno::Reference< animations::XAnimationNodeSupplier > xNodeSupplier(GetLocalShapesContext(), uno::UNO_QUERY); 297 uno::Reference< beans::XPropertySet > xPageProps( GetLocalShapesContext(), uno::UNO_QUERY ); 298 if(xNodeSupplier.is()) 299 xmloff::AnimationNodeContext::postProcessRootNode( GetSdImport(), xNodeSupplier->getAnimationNode(), xPageProps ); 300 } 301 } 302 303 ////////////////////////////////////////////////////////////////////////////// 304 ////////////////////////////////////////////////////////////////////////////// 305 306 SdXMLBodyContext::SdXMLBodyContext( SdXMLImport& rImport, 307 sal_uInt16 nPrfx, const OUString& rLocalName ) 308 : SvXMLImportContext( rImport, nPrfx, rLocalName ) 309 { 310 } 311 312 ////////////////////////////////////////////////////////////////////////////// 313 314 SdXMLBodyContext::~SdXMLBodyContext() 315 { 316 } 317 318 ////////////////////////////////////////////////////////////////////////////// 319 320 SvXMLImportContext *SdXMLBodyContext::CreateChildContext( 321 sal_uInt16 nPrefix, 322 const OUString& rLocalName, 323 const uno::Reference< xml::sax::XAttributeList>& xAttrList ) 324 { 325 SvXMLImportContext *pContext = 0L; 326 const SvXMLTokenMap& rTokenMap = GetSdImport().GetBodyElemTokenMap(); 327 328 switch(rTokenMap.Get(nPrefix, rLocalName)) 329 { 330 case XML_TOK_BODY_HEADER_DECL: 331 case XML_TOK_BODY_FOOTER_DECL: 332 case XML_TOK_BODY_DATE_TIME_DECL: 333 { 334 pContext = new SdXMLHeaderFooterDeclContext( GetImport(), nPrefix, rLocalName, xAttrList ); 335 break; 336 } 337 case XML_TOK_BODY_PAGE: 338 { 339 // only read the first page in preview mode 340 if( (GetSdImport().GetNewPageCount() == 0) || !GetSdImport().IsPreview() ) 341 { 342 // import this page 343 uno::Reference< drawing::XDrawPage > xNewDrawPage; 344 uno::Reference< drawing::XDrawPages > xDrawPages(GetSdImport().GetLocalDrawPages(), uno::UNO_QUERY); 345 346 if( !xDrawPages.is() ) 347 break; 348 349 if(GetSdImport().GetNewPageCount() + 1 > xDrawPages->getCount()) 350 { 351 // new page, create and insert 352 xNewDrawPage = xDrawPages->insertNewByIndex(xDrawPages->getCount()); 353 } 354 else 355 { 356 // existing page, use it 357 uno::Any aAny(xDrawPages->getByIndex(GetSdImport().GetNewPageCount())); 358 aAny >>= xNewDrawPage; 359 } 360 361 // increment global import page counter 362 GetSdImport().IncrementNewPageCount(); 363 364 if(xNewDrawPage.is()) 365 { 366 uno::Reference< drawing::XShapes > xNewShapes(xNewDrawPage, uno::UNO_QUERY); 367 if(xNewShapes.is()) 368 { 369 // draw:page inside office:body context 370 pContext = new SdXMLDrawPageContext(GetSdImport(), nPrefix, rLocalName, xAttrList, 371 xNewShapes); 372 } 373 } 374 } 375 break; 376 } 377 case XML_TOK_BODY_SETTINGS: 378 { 379 pContext = new SdXMLShowsContext( GetSdImport(), nPrefix, rLocalName, xAttrList ); 380 } 381 } 382 383 // call parent when no own context was created 384 if(!pContext) 385 pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName, xAttrList); 386 387 return pContext; 388 } 389