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 31 #include "PageMasterImportPropMapper.hxx" 32 #include "PageMasterPropMapper.hxx" 33 #include <xmloff/PageMasterStyleMap.hxx> 34 #include <xmloff/maptype.hxx> 35 #include <com/sun/star/table/BorderLine.hpp> 36 #include <com/sun/star/container/XNameContainer.hpp> 37 #include <xmloff/xmlimp.hxx> 38 39 #define XML_LINE_LEFT 0 40 #define XML_LINE_RIGHT 1 41 #define XML_LINE_TOP 2 42 #define XML_LINE_BOTTOM 3 43 44 using namespace ::com::sun::star; 45 using namespace ::com::sun::star::uno; 46 using namespace ::com::sun::star::container; 47 48 PageMasterImportPropertyMapper::PageMasterImportPropertyMapper( 49 const UniReference< XMLPropertySetMapper >& rMapper, 50 SvXMLImport& rImp ) : 51 SvXMLImportPropertyMapper( rMapper, rImp ), 52 rImport( rImp ) 53 { 54 } 55 56 PageMasterImportPropertyMapper::~PageMasterImportPropertyMapper() 57 { 58 } 59 60 sal_Bool PageMasterImportPropertyMapper::handleSpecialItem( 61 XMLPropertyState& rProperty, 62 ::std::vector< XMLPropertyState >& rProperties, 63 const ::rtl::OUString& rValue, 64 const SvXMLUnitConverter& rUnitConverter, 65 const SvXMLNamespaceMap& rNamespaceMap ) const 66 { 67 sal_Bool bRet = sal_False; 68 sal_Int16 nContextID = 69 getPropertySetMapper()->GetEntryContextId(rProperty.mnIndex); 70 71 if( CTF_PM_REGISTER_STYLE==nContextID ) 72 { 73 ::rtl::OUString sDisplayName( rImport.GetStyleDisplayName( 74 XML_STYLE_FAMILY_TEXT_PARAGRAPH, rValue ) ); 75 Reference < XNameContainer > xParaStyles = 76 rImport.GetTextImport()->GetParaStyles(); 77 if( xParaStyles.is() && xParaStyles->hasByName( sDisplayName ) ) 78 { 79 rProperty.maValue <<= sDisplayName; 80 bRet = sal_True; 81 } 82 } 83 else 84 { 85 bRet = SvXMLImportPropertyMapper::handleSpecialItem( 86 rProperty, rProperties, rValue, 87 rUnitConverter, rNamespaceMap ); 88 } 89 90 return bRet; 91 } 92 93 94 void PageMasterImportPropertyMapper::finished(::std::vector< XMLPropertyState >& rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const 95 { 96 SvXMLImportPropertyMapper::finished(rProperties, nStartIndex, nEndIndex); 97 XMLPropertyState* pAllPaddingProperty = NULL; 98 XMLPropertyState* pPadding[4] = { NULL, NULL, NULL, NULL }; 99 XMLPropertyState* pNewPadding[4] = { NULL, NULL, NULL, NULL }; 100 XMLPropertyState* pAllBorderProperty = NULL; 101 XMLPropertyState* pBorders[4] = { NULL, NULL, NULL, NULL }; 102 XMLPropertyState* pNewBorders[4] = { NULL, NULL, NULL, NULL }; 103 XMLPropertyState* pAllBorderWidthProperty = NULL; 104 XMLPropertyState* pBorderWidths[4] = { NULL, NULL, NULL, NULL }; 105 XMLPropertyState* pAllHeaderPaddingProperty = NULL; 106 XMLPropertyState* pHeaderPadding[4] = { NULL, NULL, NULL, NULL }; 107 XMLPropertyState* pHeaderNewPadding[4] = { NULL, NULL, NULL, NULL }; 108 XMLPropertyState* pAllHeaderBorderProperty = NULL; 109 XMLPropertyState* pHeaderBorders[4] = { NULL, NULL, NULL, NULL }; 110 XMLPropertyState* pHeaderNewBorders[4] = { NULL, NULL, NULL, NULL }; 111 XMLPropertyState* pAllHeaderBorderWidthProperty = NULL; 112 XMLPropertyState* pHeaderBorderWidths[4] = { NULL, NULL, NULL, NULL }; 113 XMLPropertyState* pAllFooterPaddingProperty = NULL; 114 XMLPropertyState* pFooterPadding[4] = { NULL, NULL, NULL, NULL }; 115 XMLPropertyState* pFooterNewPadding[4] = { NULL, NULL, NULL, NULL }; 116 XMLPropertyState* pAllFooterBorderProperty = NULL; 117 XMLPropertyState* pFooterBorders[4] = { NULL, NULL, NULL, NULL }; 118 XMLPropertyState* pFooterNewBorders[4] = { NULL, NULL, NULL, NULL }; 119 XMLPropertyState* pAllFooterBorderWidthProperty = NULL; 120 XMLPropertyState* pFooterBorderWidths[4] = { NULL, NULL, NULL, NULL }; 121 XMLPropertyState* pHeaderHeight = NULL; 122 XMLPropertyState* pHeaderMinHeight = NULL; 123 XMLPropertyState* pHeaderDynamic = NULL; 124 XMLPropertyState* pFooterHeight = NULL; 125 XMLPropertyState* pFooterMinHeight = NULL; 126 XMLPropertyState* pFooterDynamic = NULL; 127 XMLPropertyState* pAllMarginProperty = NULL; 128 XMLPropertyState* pMargins[4] = { NULL, NULL, NULL, NULL }; 129 ::std::auto_ptr<XMLPropertyState> pNewMargins[4]; 130 XMLPropertyState* pAllHeaderMarginProperty = NULL; 131 XMLPropertyState* pHeaderMargins[4] = { NULL, NULL, NULL, NULL }; 132 ::std::auto_ptr<XMLPropertyState> pNewHeaderMargins[4]; 133 XMLPropertyState* pAllFooterMarginProperty = NULL; 134 XMLPropertyState* pFooterMargins[4] = { NULL, NULL, NULL, NULL }; 135 ::std::auto_ptr<XMLPropertyState> pNewFooterMargins[4]; 136 137 ::std::vector< XMLPropertyState >::iterator aEnd = rProperties.end(); 138 for (::std::vector< XMLPropertyState >::iterator aIter = rProperties.begin(); aIter != aEnd; ++aIter) 139 { 140 XMLPropertyState *property = &(*aIter); 141 sal_Int16 nContextID = getPropertySetMapper()->GetEntryContextId(property->mnIndex); 142 if (property->mnIndex >= nStartIndex && property->mnIndex < nEndIndex) 143 { 144 switch (nContextID) 145 { 146 case CTF_PM_PADDINGALL : pAllPaddingProperty = property; break; 147 case CTF_PM_PADDINGLEFT : pPadding[XML_LINE_LEFT] = property; break; 148 case CTF_PM_PADDINGRIGHT : pPadding[XML_LINE_RIGHT] = property; break; 149 case CTF_PM_PADDINGTOP : pPadding[XML_LINE_TOP] = property; break; 150 case CTF_PM_PADDINGBOTTOM : pPadding[XML_LINE_BOTTOM] = property; break; 151 case CTF_PM_BORDERALL : pAllBorderProperty = property; break; 152 case CTF_PM_BORDERLEFT : pBorders[XML_LINE_LEFT] = property; break; 153 case CTF_PM_BORDERRIGHT : pBorders[XML_LINE_RIGHT] = property; break; 154 case CTF_PM_BORDERTOP : pBorders[XML_LINE_TOP] = property; break; 155 case CTF_PM_BORDERBOTTOM : pBorders[XML_LINE_BOTTOM] = property; break; 156 case CTF_PM_BORDERWIDTHALL : pAllBorderWidthProperty = property; break; 157 case CTF_PM_BORDERWIDTHLEFT : pBorderWidths[XML_LINE_LEFT] = property; break; 158 case CTF_PM_BORDERWIDTHRIGHT : pBorderWidths[XML_LINE_RIGHT] = property; break; 159 case CTF_PM_BORDERWIDTHTOP : pBorderWidths[XML_LINE_TOP] = property; break; 160 case CTF_PM_BORDERWIDTHBOTTOM : pBorderWidths[XML_LINE_BOTTOM] = property; break; 161 case CTF_PM_HEADERPADDINGALL : pAllHeaderPaddingProperty = property; break; 162 case CTF_PM_HEADERPADDINGLEFT : pHeaderPadding[XML_LINE_LEFT] = property; break; 163 case CTF_PM_HEADERPADDINGRIGHT : pHeaderPadding[XML_LINE_RIGHT] = property; break; 164 case CTF_PM_HEADERPADDINGTOP : pHeaderPadding[XML_LINE_TOP] = property; break; 165 case CTF_PM_HEADERPADDINGBOTTOM : pHeaderPadding[XML_LINE_BOTTOM] = property; break; 166 case CTF_PM_HEADERBORDERALL : pAllHeaderBorderProperty = property; break; 167 case CTF_PM_HEADERBORDERLEFT : pHeaderBorders[XML_LINE_LEFT] = property; break; 168 case CTF_PM_HEADERBORDERRIGHT : pHeaderBorders[XML_LINE_RIGHT] = property; break; 169 case CTF_PM_HEADERBORDERTOP : pHeaderBorders[XML_LINE_TOP] = property; break; 170 case CTF_PM_HEADERBORDERBOTTOM : pHeaderBorders[XML_LINE_BOTTOM] = property; break; 171 case CTF_PM_HEADERBORDERWIDTHALL : pAllHeaderBorderWidthProperty = property; break; 172 case CTF_PM_HEADERBORDERWIDTHLEFT : pHeaderBorderWidths[XML_LINE_LEFT] = property; break; 173 case CTF_PM_HEADERBORDERWIDTHRIGHT : pHeaderBorderWidths[XML_LINE_RIGHT] = property; break; 174 case CTF_PM_HEADERBORDERWIDTHTOP : pHeaderBorderWidths[XML_LINE_TOP] = property; break; 175 case CTF_PM_HEADERBORDERWIDTHBOTTOM : pHeaderBorderWidths[XML_LINE_BOTTOM] = property; break; 176 case CTF_PM_FOOTERPADDINGALL : pAllFooterPaddingProperty = property; break; 177 case CTF_PM_FOOTERPADDINGLEFT : pFooterPadding[XML_LINE_LEFT] = property; break; 178 case CTF_PM_FOOTERPADDINGRIGHT : pFooterPadding[XML_LINE_RIGHT] = property; break; 179 case CTF_PM_FOOTERPADDINGTOP : pFooterPadding[XML_LINE_TOP] = property; break; 180 case CTF_PM_FOOTERPADDINGBOTTOM : pFooterPadding[XML_LINE_BOTTOM] = property; break; 181 case CTF_PM_FOOTERBORDERALL : pAllFooterBorderProperty = property; break; 182 case CTF_PM_FOOTERBORDERLEFT : pFooterBorders[XML_LINE_LEFT] = property; break; 183 case CTF_PM_FOOTERBORDERRIGHT : pFooterBorders[XML_LINE_RIGHT] = property; break; 184 case CTF_PM_FOOTERBORDERTOP : pFooterBorders[XML_LINE_TOP] = property; break; 185 case CTF_PM_FOOTERBORDERBOTTOM : pFooterBorders[XML_LINE_BOTTOM] = property; break; 186 case CTF_PM_FOOTERBORDERWIDTHALL : pAllFooterBorderWidthProperty = property; break; 187 case CTF_PM_FOOTERBORDERWIDTHLEFT : pFooterBorderWidths[XML_LINE_LEFT] = property; break; 188 case CTF_PM_FOOTERBORDERWIDTHRIGHT : pFooterBorderWidths[XML_LINE_RIGHT] = property; break; 189 case CTF_PM_FOOTERBORDERWIDTHTOP : pFooterBorderWidths[XML_LINE_TOP] = property; break; 190 case CTF_PM_FOOTERBORDERWIDTHBOTTOM : pFooterBorderWidths[XML_LINE_BOTTOM] = property; break; 191 case CTF_PM_HEADERHEIGHT : pHeaderHeight = property; break; 192 case CTF_PM_HEADERMINHEIGHT : pHeaderMinHeight = property; break; 193 case CTF_PM_FOOTERHEIGHT : pFooterHeight = property; break; 194 case CTF_PM_FOOTERMINHEIGHT : pFooterMinHeight = property; break; 195 case CTF_PM_MARGINALL : 196 pAllMarginProperty = property; break; 197 case CTF_PM_MARGINTOP : 198 pMargins[XML_LINE_TOP] = property; break; 199 case CTF_PM_MARGINBOTTOM: 200 pMargins[XML_LINE_BOTTOM] = property; break; 201 case CTF_PM_MARGINLEFT : 202 pMargins[XML_LINE_LEFT] = property; break; 203 case CTF_PM_MARGINRIGHT : 204 pMargins[XML_LINE_RIGHT] = property; break; 205 case CTF_PM_HEADERMARGINALL : 206 pAllHeaderMarginProperty = property; break; 207 case CTF_PM_HEADERMARGINTOP : 208 pHeaderMargins[XML_LINE_TOP] = property; break; 209 case CTF_PM_HEADERMARGINBOTTOM: 210 pHeaderMargins[XML_LINE_BOTTOM] = property; break; 211 case CTF_PM_HEADERMARGINLEFT : 212 pHeaderMargins[XML_LINE_LEFT] = property; break; 213 case CTF_PM_HEADERMARGINRIGHT : 214 pHeaderMargins[XML_LINE_RIGHT] = property; break; 215 case CTF_PM_FOOTERMARGINALL : 216 pAllFooterMarginProperty = property; break; 217 case CTF_PM_FOOTERMARGINTOP : 218 pFooterMargins[XML_LINE_TOP] = property; break; 219 case CTF_PM_FOOTERMARGINBOTTOM: 220 pFooterMargins[XML_LINE_BOTTOM] = property; break; 221 case CTF_PM_FOOTERMARGINLEFT : 222 pFooterMargins[XML_LINE_LEFT] = property; break; 223 case CTF_PM_FOOTERMARGINRIGHT : 224 pFooterMargins[XML_LINE_RIGHT] = property; break; 225 } 226 } 227 } 228 229 for (sal_uInt16 i = 0; i < 4; i++) 230 { 231 if (pAllMarginProperty && !pMargins[i]) 232 { 233 pNewMargins[i].reset(new XMLPropertyState( 234 pAllMarginProperty->mnIndex + 1 + i, 235 pAllMarginProperty->maValue)); 236 } 237 if (pAllHeaderMarginProperty && !pHeaderMargins[i]) 238 { 239 pNewHeaderMargins[i].reset(new XMLPropertyState( 240 pAllHeaderMarginProperty->mnIndex + 1 + i, 241 pAllHeaderMarginProperty->maValue)); 242 } 243 if (pAllFooterMarginProperty && !pFooterMargins[i]) 244 { 245 pNewFooterMargins[i].reset(new XMLPropertyState( 246 pAllFooterMarginProperty->mnIndex + 1 + i, 247 pAllFooterMarginProperty->maValue)); 248 } 249 if (pAllPaddingProperty && !pPadding[i]) 250 pNewPadding[i] = new XMLPropertyState(pAllPaddingProperty->mnIndex + 1 + i, pAllPaddingProperty->maValue); 251 if (pAllBorderProperty && !pBorders[i]) 252 { 253 pNewBorders[i] = new XMLPropertyState(pAllBorderProperty->mnIndex + 1 + i, pAllBorderProperty->maValue); 254 pBorders[i] = pNewBorders[i]; 255 } 256 if( !pBorderWidths[i] ) 257 pBorderWidths[i] = pAllBorderWidthProperty; 258 else 259 pBorderWidths[i]->mnIndex = -1; 260 if( pBorders[i] ) 261 { 262 table::BorderLine aBorderLine; 263 pBorders[i]->maValue >>= aBorderLine; 264 if( pBorderWidths[i] ) 265 { 266 table::BorderLine aBorderLineWidth; 267 pBorderWidths[i]->maValue >>= aBorderLineWidth; 268 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth; 269 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth; 270 aBorderLine.LineDistance = aBorderLineWidth.LineDistance; 271 pBorders[i]->maValue <<= aBorderLine; 272 } 273 } 274 if (pAllHeaderPaddingProperty && !pHeaderPadding[i]) 275 pHeaderNewPadding[i] = new XMLPropertyState(pAllHeaderPaddingProperty->mnIndex + 1 + i, pAllHeaderPaddingProperty->maValue); 276 if (pAllHeaderBorderProperty && !pHeaderBorders[i]) 277 pHeaderNewBorders[i] = new XMLPropertyState(pAllHeaderBorderProperty->mnIndex + 1 + i, pAllHeaderBorderProperty->maValue); 278 if( !pHeaderBorderWidths[i] ) 279 pHeaderBorderWidths[i] = pAllHeaderBorderWidthProperty; 280 else 281 pHeaderBorderWidths[i]->mnIndex = -1; 282 if( pHeaderBorders[i] ) 283 { 284 table::BorderLine aBorderLine; 285 pHeaderBorders[i]->maValue >>= aBorderLine; 286 if( pHeaderBorderWidths[i] ) 287 { 288 table::BorderLine aBorderLineWidth; 289 pHeaderBorderWidths[i]->maValue >>= aBorderLineWidth; 290 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth; 291 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth; 292 aBorderLine.LineDistance = aBorderLineWidth.LineDistance; 293 pHeaderBorders[i]->maValue <<= aBorderLine; 294 } 295 } 296 if (pAllFooterPaddingProperty && !pFooterPadding[i]) 297 pFooterNewPadding[i] = new XMLPropertyState(pAllFooterPaddingProperty->mnIndex + 1 + i, pAllFooterPaddingProperty->maValue); 298 if (pAllFooterBorderProperty && !pFooterBorders[i]) 299 pFooterNewBorders[i] = new XMLPropertyState(pAllFooterBorderProperty->mnIndex + 1 + i, pAllFooterBorderProperty->maValue); 300 if( !pFooterBorderWidths[i] ) 301 pFooterBorderWidths[i] = pAllFooterBorderWidthProperty; 302 else 303 pFooterBorderWidths[i]->mnIndex = -1; 304 if( pFooterBorders[i] ) 305 { 306 table::BorderLine aBorderLine; 307 pFooterBorders[i]->maValue >>= aBorderLine; 308 if( pFooterBorderWidths[i] ) 309 { 310 table::BorderLine aBorderLineWidth; 311 pFooterBorderWidths[i]->maValue >>= aBorderLineWidth; 312 aBorderLine.OuterLineWidth = aBorderLineWidth.OuterLineWidth; 313 aBorderLine.InnerLineWidth = aBorderLineWidth.InnerLineWidth; 314 aBorderLine.LineDistance = aBorderLineWidth.LineDistance; 315 pFooterBorders[i]->maValue <<= aBorderLine; 316 } 317 } 318 } 319 320 if (pHeaderHeight) 321 { 322 sal_Bool bValue(sal_False); 323 uno::Any aAny; 324 aAny.setValue( &bValue, ::getBooleanCppuType() ); 325 pHeaderDynamic = new XMLPropertyState(pHeaderHeight->mnIndex + 2, aAny); 326 } 327 if (pHeaderMinHeight) 328 { 329 sal_Bool bValue(sal_True); 330 uno::Any aAny; 331 aAny.setValue( &bValue, ::getBooleanCppuType() ); 332 pHeaderDynamic = new XMLPropertyState(pHeaderMinHeight->mnIndex + 1, aAny); 333 } 334 if (pFooterHeight) 335 { 336 sal_Bool bValue(sal_False); 337 uno::Any aAny; 338 aAny.setValue( &bValue, ::getBooleanCppuType() ); 339 pFooterDynamic = new XMLPropertyState(pFooterHeight->mnIndex + 2, aAny); 340 } 341 if (pFooterMinHeight) 342 { 343 sal_Bool bValue(sal_True); 344 uno::Any aAny; 345 aAny.setValue( &bValue, ::getBooleanCppuType() ); 346 pFooterDynamic = new XMLPropertyState(pFooterMinHeight->mnIndex + 1, aAny); 347 } 348 for (sal_uInt16 i = 0; i < 4; i++) 349 { 350 if (pNewMargins[i].get()) 351 { 352 rProperties.push_back(*pNewMargins[i]); 353 } 354 if (pNewHeaderMargins[i].get()) 355 { 356 rProperties.push_back(*pNewHeaderMargins[i]); 357 } 358 if (pNewFooterMargins[i].get()) 359 { 360 rProperties.push_back(*pNewFooterMargins[i]); 361 } 362 if (pNewPadding[i]) 363 { 364 rProperties.push_back(*pNewPadding[i]); 365 delete pNewPadding[i]; 366 } 367 if (pNewBorders[i]) 368 { 369 rProperties.push_back(*pNewBorders[i]); 370 delete pNewBorders[i]; 371 } 372 if (pHeaderNewPadding[i]) 373 { 374 rProperties.push_back(*pHeaderNewPadding[i]); 375 delete pHeaderNewPadding[i]; 376 } 377 if (pHeaderNewBorders[i]) 378 { 379 rProperties.push_back(*pHeaderNewBorders[i]); 380 delete pHeaderNewBorders[i]; 381 } 382 if (pFooterNewPadding[i]) 383 { 384 rProperties.push_back(*pFooterNewPadding[i]); 385 delete pFooterNewPadding[i]; 386 } 387 if (pFooterNewBorders[i]) 388 { 389 rProperties.push_back(*pFooterNewBorders[i]); 390 delete pFooterNewBorders[i]; 391 } 392 } 393 if(pHeaderDynamic) 394 { 395 rProperties.push_back(*pHeaderDynamic); 396 delete pHeaderDynamic; 397 } 398 if(pFooterDynamic) 399 { 400 rProperties.push_back(*pFooterDynamic); 401 delete pFooterDynamic; 402 } 403 } 404 405