update credits
[LibreOffice.git] / sw / source / filter / xml / xmlimpit.cxx
blob6d57f456249d1d6324b2050554d9ce3cc4791828
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "xmlimpit.hxx"
23 #include <sax/tools/converter.hxx>
24 #include <xmloff/xmluconv.hxx>
25 #include <svl/itempool.hxx>
26 #include <svl/poolitem.hxx>
27 #include <svl/itemset.hxx>
28 #include <xmloff/attrlist.hxx>
29 #include <xmloff/nmspmap.hxx>
30 #include <xmloff/xmlnmspe.hxx>
31 #include <editeng/xmlcnitm.hxx>
32 #include <editeng/memberids.hrc>
35 #include "hintids.hxx"
36 #include "unomid.h"
37 #include <svx/unomid.hxx>
38 #include <editeng/lrspitem.hxx>
39 #include <editeng/ulspitem.hxx>
40 #include <editeng/shaditem.hxx>
41 #include <editeng/boxitem.hxx>
42 #include <editeng/formatbreakitem.hxx>
43 #include <editeng/keepitem.hxx>
44 #include <editeng/brushitem.hxx>
45 #include "fmtpdsc.hxx"
46 #include "fmtornt.hxx"
47 #include "fmtfsize.hxx"
49 #include "fmtlsplt.hxx"
50 #include <xmloff/prhdlfac.hxx>
51 #include <xmloff/xmltypes.hxx>
52 #include "xmlithlp.hxx"
53 #include <com/sun/star/uno/Any.hxx>
55 using ::editeng::SvxBorderLine;
56 using namespace ::com::sun::star;
57 using namespace ::xmloff::token;
58 using uno::Any;
60 SvXMLImportItemMapper::SvXMLImportItemMapper(
61 SvXMLItemMapEntriesRef rMapEntries,
62 sal_uInt16 nUnknWhich ) :
63 mrMapEntries( rMapEntries ),
64 nUnknownWhich( nUnknWhich )
68 SvXMLImportItemMapper::~SvXMLImportItemMapper()
72 void
73 SvXMLImportItemMapper::setMapEntries( SvXMLItemMapEntriesRef rMapEntries )
75 mrMapEntries = rMapEntries;
78 /** fills the given itemset with the attributes in the given list */
79 void SvXMLImportItemMapper::importXML( SfxItemSet& rSet,
80 uno::Reference< xml::sax::XAttributeList > xAttrList,
81 const SvXMLUnitConverter& rUnitConverter,
82 const SvXMLNamespaceMap& rNamespaceMap )
84 sal_Int16 nAttr = xAttrList->getLength();
86 SvXMLAttrContainerItem *pUnknownItem = 0;
87 for( sal_Int16 i=0; i < nAttr; i++ )
89 const OUString& rAttrName = xAttrList->getNameByIndex( i );
90 OUString aLocalName, aPrefix, aNamespace;
91 sal_uInt16 nPrefix =
92 rNamespaceMap.GetKeyByAttrName( rAttrName, &aPrefix, &aLocalName,
93 &aNamespace );
94 if( XML_NAMESPACE_XMLNS == nPrefix )
95 continue;
97 const OUString& rValue = xAttrList->getValueByIndex( i );
99 // find a map entry for this attribute
100 SvXMLItemMapEntry* pEntry = mrMapEntries->getByName( nPrefix, aLocalName );
102 if( pEntry )
104 // we have a valid map entry here, so lets use it...
105 if( 0 == (pEntry->nMemberId & (MID_SW_FLAG_NO_ITEM_IMPORT|
106 MID_SW_FLAG_ELEMENT_ITEM_IMPORT)) )
108 // first get item from itemset
109 const SfxPoolItem* pItem = 0;
110 SfxItemState eState = rSet.GetItemState( pEntry->nWhichId, sal_True,
111 &pItem );
113 // if its not set, try the pool
114 if(SFX_ITEM_SET != eState && SFX_WHICH_MAX > pEntry->nWhichId )
115 pItem = &rSet.GetPool()->GetDefaultItem(pEntry->nWhichId);
117 // do we have an item?
118 if(eState >= SFX_ITEM_DEFAULT && pItem)
120 SfxPoolItem *pNewItem = pItem->Clone();
121 bool bPut = false;
123 if( 0 == (pEntry->nMemberId&MID_SW_FLAG_SPECIAL_ITEM_IMPORT) )
125 bPut = PutXMLValue( *pNewItem, rValue,
126 static_cast<sal_uInt16>( pEntry->nMemberId & MID_SW_FLAG_MASK ),
127 rUnitConverter );
130 else
132 bPut = handleSpecialItem( *pEntry, *pNewItem, rSet,
133 rValue, rUnitConverter,
134 rNamespaceMap );
137 if( bPut )
138 rSet.Put( *pNewItem );
140 delete pNewItem;
142 else
144 OSL_FAIL( "Could not get a needed item for xml import!" );
147 else if( 0 != (pEntry->nMemberId & MID_SW_FLAG_NO_ITEM_IMPORT) )
149 handleNoItem( *pEntry, rSet, rValue, rUnitConverter,
150 rNamespaceMap );
153 else if( USHRT_MAX != nUnknownWhich )
155 if( !pUnknownItem )
157 const SfxPoolItem* pItem = 0;
158 if( SFX_ITEM_SET == rSet.GetItemState( nUnknownWhich, sal_True,
159 &pItem ) )
161 SfxPoolItem *pNew = pItem->Clone();
162 pUnknownItem = PTR_CAST( SvXMLAttrContainerItem, pNew );
163 OSL_ENSURE( pUnknownItem,
164 "SvXMLAttrContainerItem expected" );
165 if( !pUnknownItem )
166 delete pNew;
168 else
170 pUnknownItem = new SvXMLAttrContainerItem( nUnknownWhich );
173 if( pUnknownItem )
175 if( XML_NAMESPACE_NONE == nPrefix )
176 pUnknownItem->AddAttr( aLocalName, rValue );
177 else
178 pUnknownItem->AddAttr( aPrefix, aNamespace, aLocalName,
179 rValue );
184 if( pUnknownItem )
186 rSet.Put( *pUnknownItem );
187 delete pUnknownItem;
190 finished(rSet, rUnitConverter);
193 /** this method is called for every item that has the
194 MID_SW_FLAG_SPECIAL_ITEM_IMPORT flag set */
195 bool
196 SvXMLImportItemMapper::handleSpecialItem( const SvXMLItemMapEntry& /*rEntry*/,
197 SfxPoolItem& /*rItem*/,
198 SfxItemSet& /*rSet*/,
199 const OUString& /*rValue*/,
200 const SvXMLUnitConverter& /*rUnitConverter*/,
201 const SvXMLNamespaceMap& /*rNamespaceMap*/ )
203 OSL_FAIL( "unsuported special item in xml import" );
204 return false;
207 /** this method is called for every item that has the
208 MID_SW_FLAG_NO_ITEM_IMPORT flag set */
209 bool SvXMLImportItemMapper::handleNoItem( const SvXMLItemMapEntry& /*rEntry*/,
210 SfxItemSet& /*rSet*/,
211 const OUString& /*rValue*/,
212 const SvXMLUnitConverter& /*rUnitConverter*/,
213 const SvXMLNamespaceMap& /*rNamespaceMap*/ )
215 OSL_FAIL( "unsuported no item in xml import" );
216 return false;
219 void
220 SvXMLImportItemMapper::finished(SfxItemSet &, SvXMLUnitConverter const&) const
222 // nothing to do here
227 // put an XML-string value into an item
228 bool SvXMLImportItemMapper::PutXMLValue(
229 SfxPoolItem& rItem,
230 const OUString& rValue,
231 sal_uInt16 nMemberId,
232 const SvXMLUnitConverter& rUnitConverter )
234 bool bOk = false;
236 switch (rItem.Which())
238 case RES_LR_SPACE:
240 SvxLRSpaceItem* pLRSpace = PTR_CAST(SvxLRSpaceItem, &rItem);
241 OSL_ENSURE( pLRSpace != NULL, "Wrong Which-ID!" );
243 switch( nMemberId )
245 case MID_L_MARGIN:
246 case MID_R_MARGIN:
248 sal_Int32 nProp = 100;
249 sal_Int32 nAbs = 0;
251 if( rValue.indexOf( sal_Unicode('%') ) != -1 )
252 bOk = ::sax::Converter::convertPercent(nProp, rValue);
253 else
254 bOk = rUnitConverter.convertMeasureToCore(nAbs, rValue);
256 if( bOk )
258 switch( nMemberId )
260 case MID_L_MARGIN:
261 pLRSpace->SetTxtLeft( (sal_Int32)nAbs, (sal_uInt16)nProp );
262 break;
263 case MID_R_MARGIN:
264 pLRSpace->SetRight( (sal_Int32)nAbs, (sal_uInt16)nProp );
265 break;
269 break;
270 case MID_FIRST_LINE_INDENT:
272 sal_Int32 nProp = 100;
273 sal_Int32 nAbs = 0;
275 if( rValue.indexOf( sal_Unicode('%') ) != -1 )
276 bOk = ::sax::Converter::convertPercent(nProp, rValue);
277 else
278 bOk = rUnitConverter.convertMeasureToCore(nAbs, rValue,
279 -0x7fff, 0x7fff );
281 pLRSpace->SetTxtFirstLineOfst( (short)nAbs, (sal_uInt16)nProp );
284 case MID_FIRST_AUTO:
286 bool bAutoFirst(false);
287 bOk = ::sax::Converter::convertBool( bAutoFirst, rValue );
288 if( bOk )
289 pLRSpace->SetAutoFirst( bAutoFirst );
291 break;
293 default:
294 OSL_FAIL( "unknown member id!");
297 break;
299 case RES_UL_SPACE:
301 SvxULSpaceItem* pULSpace = PTR_CAST(SvxULSpaceItem, &rItem);
302 OSL_ENSURE( pULSpace != NULL, "Wrong Which-ID!" );
304 sal_Int32 nProp = 100;
305 sal_Int32 nAbs = 0;
307 if( rValue.indexOf( sal_Unicode('%') ) != -1 )
308 bOk = ::sax::Converter::convertPercent( nProp, rValue );
309 else
310 bOk = rUnitConverter.convertMeasureToCore( nAbs, rValue );
312 switch( nMemberId )
314 case MID_UP_MARGIN:
315 pULSpace->SetUpper( (sal_uInt16)nAbs, (sal_uInt16)nProp );
316 break;
317 case MID_LO_MARGIN:
318 pULSpace->SetLower( (sal_uInt16)nAbs, (sal_uInt16)nProp );
319 break;
320 default:
321 OSL_FAIL("unknown MemberId");
324 break;
326 case RES_SHADOW:
328 SvxShadowItem* pShadow = PTR_CAST(SvxShadowItem, &rItem);
329 OSL_ENSURE( pShadow != NULL, "Wrong Which-ID" );
331 bool bColorFound = false;
332 bool bOffsetFound = false;
334 SvXMLTokenEnumerator aTokenEnum( rValue );
336 Color aColor( 128,128, 128 );
337 pShadow->SetLocation( SVX_SHADOW_BOTTOMRIGHT );
339 OUString aToken;
340 while( aTokenEnum.getNextToken( aToken ) )
342 if( IsXMLToken( aToken, XML_NONE ) )
344 pShadow->SetLocation( SVX_SHADOW_NONE );
345 bOk = true;
347 else if( !bColorFound && aToken.startsWith("#") )
349 sal_Int32 nColor(0);
350 bOk = ::sax::Converter::convertColor( nColor, aToken );
351 if( !bOk )
352 return false;
354 aColor.SetColor(nColor);
355 bColorFound = true;
357 else if( !bOffsetFound )
359 sal_Int32 nX = 0, nY = 0;
361 bOk = rUnitConverter.convertMeasureToCore( nX, aToken );
362 if( bOk && aTokenEnum.getNextToken( aToken ) )
363 bOk = rUnitConverter.convertMeasureToCore( nY, aToken );
365 if( bOk )
367 if( nX < 0 )
369 if( nY < 0 )
371 pShadow->SetLocation( SVX_SHADOW_TOPLEFT );
373 else
375 pShadow->SetLocation( SVX_SHADOW_BOTTOMLEFT );
378 else
380 if( nY < 0 )
382 pShadow->SetLocation( SVX_SHADOW_TOPRIGHT );
384 else
386 pShadow->SetLocation( SVX_SHADOW_BOTTOMRIGHT );
390 if( nX < 0 ) nX *= -1;
391 if( nY < 0 ) nY *= -1;
393 pShadow->SetWidth( static_cast< sal_uInt16 >( (nX + nY) >> 1 ) );
398 if( bOk && ( bColorFound || bOffsetFound ) )
400 pShadow->SetColor( aColor );
402 else
403 bOk = false;
405 break;
407 case RES_BOX:
409 SvxBoxItem* pBox = PTR_CAST(SvxBoxItem, &rItem);
410 OSL_ENSURE( pBox != NULL, "Wrong WHich-ID" );
412 /** copy SvxBorderLines */
413 SvxBorderLine* pTop = pBox->GetTop() == NULL ?
414 NULL : new SvxBorderLine( *pBox->GetTop() );
415 SvxBorderLine* pBottom = pBox->GetBottom() == NULL ?
416 NULL : new SvxBorderLine( *pBox->GetBottom() );
417 SvxBorderLine* pLeft = pBox->GetLeft() == NULL ?
418 NULL : new SvxBorderLine( *pBox->GetLeft() );
419 SvxBorderLine* pRight = pBox->GetRight() == NULL ?
420 NULL : new SvxBorderLine( *pBox->GetRight() );
422 sal_Int32 nTemp;
424 switch( nMemberId )
426 case ALL_BORDER_PADDING:
427 case LEFT_BORDER_PADDING:
428 case RIGHT_BORDER_PADDING:
429 case TOP_BORDER_PADDING:
430 case BOTTOM_BORDER_PADDING:
431 if (!rUnitConverter.convertMeasureToCore( nTemp, rValue,
432 0, 0xffff ))
434 return false;
437 if( nMemberId == LEFT_BORDER_PADDING ||
438 nMemberId == ALL_BORDER_PADDING )
439 pBox->SetDistance( (sal_uInt16)nTemp, BOX_LINE_LEFT );
440 if( nMemberId == RIGHT_BORDER_PADDING ||
441 nMemberId == ALL_BORDER_PADDING )
442 pBox->SetDistance( (sal_uInt16)nTemp, BOX_LINE_RIGHT );
443 if( nMemberId == TOP_BORDER_PADDING ||
444 nMemberId == ALL_BORDER_PADDING )
445 pBox->SetDistance( (sal_uInt16)nTemp, BOX_LINE_TOP );
446 if( nMemberId == BOTTOM_BORDER_PADDING ||
447 nMemberId == ALL_BORDER_PADDING )
448 pBox->SetDistance( (sal_uInt16)nTemp, BOX_LINE_BOTTOM);
449 break;
451 case ALL_BORDER:
452 case LEFT_BORDER:
453 case RIGHT_BORDER:
454 case TOP_BORDER:
455 case BOTTOM_BORDER:
457 bool bHasStyle = false;
458 bool bHasWidth = false;
459 bool bHasColor = false;
461 sal_uInt16 nStyle = USHRT_MAX;
462 sal_uInt16 nWidth = 0;
463 sal_uInt16 nNamedWidth = USHRT_MAX;
465 Color aColor( COL_BLACK );
467 if( !sw_frmitems_parseXMLBorder( rValue, rUnitConverter,
468 bHasStyle, nStyle,
469 bHasWidth, nWidth, nNamedWidth,
470 bHasColor, aColor ) )
471 return false;
473 if( TOP_BORDER == nMemberId || ALL_BORDER == nMemberId )
474 sw_frmitems_setXMLBorder( pTop,
475 bHasStyle, nStyle,
476 bHasWidth, nWidth, nNamedWidth,
477 bHasColor, aColor );
479 if( BOTTOM_BORDER == nMemberId || ALL_BORDER == nMemberId )
480 sw_frmitems_setXMLBorder( pBottom,
481 bHasStyle, nStyle,
482 bHasWidth, nWidth, nNamedWidth,
483 bHasColor, aColor );
485 if( LEFT_BORDER == nMemberId || ALL_BORDER == nMemberId )
486 sw_frmitems_setXMLBorder( pLeft,
487 bHasStyle, nStyle,
488 bHasWidth, nWidth, nNamedWidth,
489 bHasColor, aColor );
491 if( RIGHT_BORDER == nMemberId || ALL_BORDER == nMemberId )
492 sw_frmitems_setXMLBorder( pRight,
493 bHasStyle, nStyle,
494 bHasWidth, nWidth, nNamedWidth,
495 bHasColor, aColor );
497 break;
498 case ALL_BORDER_LINE_WIDTH:
499 case LEFT_BORDER_LINE_WIDTH:
500 case RIGHT_BORDER_LINE_WIDTH:
501 case TOP_BORDER_LINE_WIDTH:
502 case BOTTOM_BORDER_LINE_WIDTH:
504 SvXMLTokenEnumerator aTokenEnum( rValue );
506 sal_Int32 nInWidth, nDistance, nOutWidth;
508 OUString aToken;
509 if( !aTokenEnum.getNextToken( aToken ) )
510 return false;
512 if (!rUnitConverter.convertMeasureToCore(nInWidth, aToken))
513 return false;
515 if( !aTokenEnum.getNextToken( aToken ) )
516 return false;
518 if (!rUnitConverter.convertMeasureToCore(nDistance, aToken))
519 return false;
521 if( !aTokenEnum.getNextToken( aToken ) )
522 return false;
524 if (!rUnitConverter.convertMeasureToCore(nOutWidth, aToken))
525 return false;
527 // #i61946: accept line style even it's not part of our "normal" set of line styles
528 sal_uInt16 nWidth = 0;
530 if( TOP_BORDER_LINE_WIDTH == nMemberId ||
531 ALL_BORDER_LINE_WIDTH == nMemberId )
532 sw_frmitems_setXMLBorder( pTop, nWidth,
533 static_cast< sal_uInt16 >( nOutWidth ),
534 static_cast< sal_uInt16 >( nInWidth ),
535 static_cast< sal_uInt16 >( nDistance ) );
537 if( BOTTOM_BORDER_LINE_WIDTH == nMemberId ||
538 ALL_BORDER_LINE_WIDTH == nMemberId )
539 sw_frmitems_setXMLBorder( pBottom, nWidth,
540 static_cast< sal_uInt16 >( nOutWidth ),
541 static_cast< sal_uInt16 >( nInWidth ),
542 static_cast< sal_uInt16 >( nDistance ) );
544 if( LEFT_BORDER_LINE_WIDTH == nMemberId ||
545 ALL_BORDER_LINE_WIDTH == nMemberId )
546 sw_frmitems_setXMLBorder( pLeft, nWidth,
547 static_cast< sal_uInt16 >( nOutWidth ),
548 static_cast< sal_uInt16 >( nInWidth ),
549 static_cast< sal_uInt16 >( nDistance ) );
551 if( RIGHT_BORDER_LINE_WIDTH == nMemberId ||
552 ALL_BORDER_LINE_WIDTH == nMemberId )
553 sw_frmitems_setXMLBorder( pRight, nWidth,
554 static_cast< sal_uInt16 >( nOutWidth ),
555 static_cast< sal_uInt16 >( nInWidth ),
556 static_cast< sal_uInt16 >( nDistance ) );
558 break;
561 pBox->SetLine( pTop, BOX_LINE_TOP );
562 pBox->SetLine( pBottom, BOX_LINE_BOTTOM );
563 pBox->SetLine( pLeft, BOX_LINE_LEFT );
564 pBox->SetLine( pRight, BOX_LINE_RIGHT );
566 delete pTop;
567 delete pBottom;
568 delete pLeft;
569 delete pRight;
571 bOk = true;
573 break;
575 case RES_BREAK:
577 SvxFmtBreakItem* pFmtBreak = PTR_CAST(SvxFmtBreakItem, &rItem);
578 OSL_ENSURE( pFmtBreak != NULL, "Wrong Which-ID" );
580 sal_uInt16 eEnum;
582 if( !rUnitConverter.convertEnum( eEnum, rValue, psXML_BreakType ) )
583 return false;
585 if( eEnum == 0 )
587 pFmtBreak->SetValue( SVX_BREAK_NONE );
588 bOk = true;
590 else
592 switch( nMemberId )
594 case MID_BREAK_BEFORE:
595 pFmtBreak->SetValue( static_cast< sal_uInt16 >((eEnum == 1) ?
596 SVX_BREAK_COLUMN_BEFORE :
597 SVX_BREAK_PAGE_BEFORE) );
598 break;
599 case MID_BREAK_AFTER:
600 pFmtBreak->SetValue( static_cast< sal_uInt16 >((eEnum == 1) ?
601 SVX_BREAK_COLUMN_AFTER :
602 SVX_BREAK_PAGE_AFTER) );
603 break;
605 bOk = true;
608 break;
610 case RES_KEEP:
612 SvxFmtKeepItem* pFmtKeep = PTR_CAST(SvxFmtKeepItem, &rItem);
613 OSL_ENSURE( pFmtKeep != NULL, "Wrong Which-ID" );
615 if( IsXMLToken( rValue, XML_ALWAYS ) ||
616 IsXMLToken( rValue, XML_TRUE ) )
618 pFmtKeep->SetValue( sal_True );
619 bOk = true;
621 else if( IsXMLToken( rValue, XML_AUTO ) ||
622 IsXMLToken( rValue, XML_FALSE ) )
624 pFmtKeep->SetValue( sal_False );
625 bOk = true;
628 break;
630 case RES_BACKGROUND:
632 SvxBrushItem* pBrush = PTR_CAST(SvxBrushItem, &rItem);
633 OSL_ENSURE( pBrush != NULL, "Wrong Which-ID" );
635 sal_Int32 nTempColor(0);
636 switch( nMemberId )
638 case MID_BACK_COLOR:
639 if( IsXMLToken( rValue, XML_TRANSPARENT ) )
641 pBrush->GetColor().SetTransparency(0xff);
642 bOk = true;
644 else if (::sax::Converter::convertColor(nTempColor, rValue))
646 Color aTempColor(nTempColor);
647 aTempColor.SetTransparency(0);
648 pBrush->SetColor( aTempColor );
649 bOk = true;
651 break;
653 case MID_GRAPHIC_LINK:
655 SvxGraphicPosition eOldGraphicPos = pBrush->GetGraphicPos();
656 uno::Any aAny;
657 aAny <<= rValue;
658 pBrush->PutValue( aAny, MID_GRAPHIC_URL );
659 if( GPOS_NONE == eOldGraphicPos &&
660 GPOS_NONE != pBrush->GetGraphicPos() )
661 pBrush->SetGraphicPos( GPOS_TILED );
662 bOk = true;
664 break;
666 case MID_GRAPHIC_REPEAT:
668 SvxGraphicPosition eGraphicPos = pBrush->GetGraphicPos();
669 sal_uInt16 nPos = GPOS_NONE;
670 if( rUnitConverter.convertEnum( nPos, rValue,
671 psXML_BrushRepeat ) )
673 if( GPOS_MM != nPos || GPOS_NONE == eGraphicPos ||
674 GPOS_AREA == eGraphicPos || GPOS_TILED == eGraphicPos )
675 pBrush->SetGraphicPos( (SvxGraphicPosition)nPos );
676 bOk = true;
679 break;
681 case MID_GRAPHIC_POSITION:
683 SvxGraphicPosition ePos = GPOS_NONE, eTmp;
684 sal_uInt16 nTmp;
685 SvXMLTokenEnumerator aTokenEnum( rValue );
686 OUString aToken;
687 bool bHori = false, bVert = false;
688 bOk = true;
689 while( bOk && aTokenEnum.getNextToken( aToken ) )
691 if( bHori && bVert )
693 bOk = false;
695 else if( -1 != aToken.indexOf( sal_Unicode('%') ) )
697 sal_Int32 nPrc = 50;
698 if (::sax::Converter::convertPercent(nPrc, aToken))
700 if( !bHori )
702 ePos = nPrc < 25 ? GPOS_LT :
703 (nPrc < 75 ? GPOS_MM : GPOS_RB);
704 bHori = true;
706 else
708 eTmp = nPrc < 25 ? GPOS_LT:
709 (nPrc < 75 ? GPOS_LM : GPOS_LB);
710 sw_frmitems_MergeXMLVertPos( ePos, eTmp );
711 bVert = true;
714 else
716 // wrong percentage
717 bOk = false;
720 else if( IsXMLToken( aToken, XML_CENTER ) )
722 if( bHori )
723 sw_frmitems_MergeXMLVertPos( ePos, GPOS_MM );
724 else if ( bVert )
725 sw_frmitems_MergeXMLHoriPos( ePos, GPOS_MM );
726 else
727 ePos = GPOS_MM;
729 else if( rUnitConverter.convertEnum( nTmp, aToken,
730 psXML_BrushHoriPos ) )
732 if( bVert )
733 sw_frmitems_MergeXMLHoriPos(
734 ePos, (SvxGraphicPosition)nTmp );
735 else if( !bHori )
736 ePos = (SvxGraphicPosition)nTmp;
737 else
738 bOk = false;
739 bHori = true;
741 else if( rUnitConverter.convertEnum( nTmp, aToken,
742 psXML_BrushVertPos ) )
744 if( bHori )
745 sw_frmitems_MergeXMLVertPos(
746 ePos, (SvxGraphicPosition)nTmp );
747 else if( !bVert )
748 ePos = (SvxGraphicPosition)nTmp;
749 else
750 bOk = false;
751 bVert = true;
753 else
755 bOk = false;
759 if( GPOS_NONE == ePos ) bOk = false;
760 if( bOk )
761 pBrush->SetGraphicPos( ePos );
763 break;
765 case MID_GRAPHIC_FILTER:
766 pBrush->SetGraphicFilter( rValue );
767 bOk = true;
768 break;
771 break;
773 case RES_PAGEDESC:
775 SwFmtPageDesc* pPageDesc = PTR_CAST(SwFmtPageDesc, &rItem);
776 OSL_ENSURE( pPageDesc != NULL, "Wrong Which-ID" );
778 if( MID_PAGEDESC_PAGENUMOFFSET==nMemberId )
780 sal_Int32 nVal;
781 bOk = ::sax::Converter::convertNumber(
782 nVal, rValue, 0, USHRT_MAX);
783 if( bOk )
784 pPageDesc->SetNumOffset( (sal_uInt16)nVal );
787 break;
789 case RES_LAYOUT_SPLIT:
790 case RES_ROW_SPLIT:
792 SfxBoolItem* pSplit = PTR_CAST(SfxBoolItem, &rItem);
793 OSL_ENSURE( pSplit != NULL, "Wrong Which-ID" );
795 if( IsXMLToken( rValue, XML_AUTO ) ||
796 IsXMLToken( rValue, XML_TRUE ) )
798 pSplit->SetValue( sal_True );
799 bOk = true;
801 else if( IsXMLToken( rValue, XML_ALWAYS ) ||
802 IsXMLToken( rValue, XML_FALSE ) )
804 pSplit->SetValue( sal_False );
805 bOk = true;
808 break;
810 case RES_HORI_ORIENT:
812 SwFmtHoriOrient* pHoriOrient = PTR_CAST(SwFmtHoriOrient, &rItem);
813 OSL_ENSURE( pHoriOrient != NULL, "Wrong Which-ID" );
815 sal_uInt16 nValue;
816 bOk = rUnitConverter.convertEnum( nValue, rValue,
817 aXMLTableAlignMap );
818 if( bOk )
819 pHoriOrient->SetHoriOrient( nValue );
821 break;
823 case RES_VERT_ORIENT:
825 SwFmtVertOrient* pVertOrient = PTR_CAST(SwFmtVertOrient, &rItem);
826 OSL_ENSURE( pVertOrient != NULL, "Wrong Which-ID" );
828 sal_uInt16 nValue;
829 bOk = rUnitConverter.convertEnum( nValue, rValue,
830 aXMLTableVAlignMap );
831 if( bOk )
832 pVertOrient->SetVertOrient( nValue );
833 //#i8855# text::VertOrientation::NONE is stored as empty string and should be applied here
834 else if(rValue.isEmpty())
836 pVertOrient->SetVertOrient( text::VertOrientation::NONE );
837 bOk = true;
840 break;
842 case RES_FRM_SIZE:
844 SwFmtFrmSize* pFrmSize = PTR_CAST(SwFmtFrmSize, &rItem);
845 OSL_ENSURE( pFrmSize != NULL, "Wrong Which-ID" );
847 bool bSetHeight = false;
848 bool bSetWidth = false;
849 bool bSetSizeType = false;
850 SwFrmSize eSizeType = ATT_VAR_SIZE;
851 sal_Int32 nMin = MINLAY;
853 switch( nMemberId )
855 case MID_FRMSIZE_REL_WIDTH:
857 sal_Int32 nValue;
858 bOk = ::sax::Converter::convertPercent( nValue, rValue );
859 if( bOk )
861 if( nValue < 1 )
862 nValue = 1;
863 else if( nValue > 100 )
864 nValue = 100;
866 pFrmSize->SetWidthPercent( (sal_Int8)nValue );
869 break;
870 case MID_FRMSIZE_WIDTH:
871 bSetWidth = true;
872 break;
873 case MID_FRMSIZE_MIN_HEIGHT:
874 eSizeType = ATT_MIN_SIZE;
875 bSetHeight = true;
876 nMin = 1;
877 bSetSizeType = true;
878 break;
879 case MID_FRMSIZE_FIX_HEIGHT:
880 eSizeType = ATT_FIX_SIZE;
881 bSetHeight = true;
882 nMin = 1;
883 bSetSizeType = true;
884 break;
885 case MID_FRMSIZE_COL_WIDTH:
886 eSizeType = ATT_FIX_SIZE;
887 bSetWidth = true;
888 bSetSizeType = true;
889 break;
890 case MID_FRMSIZE_REL_COL_WIDTH:
892 sal_Int32 nPos = rValue.indexOf( (sal_Unicode)'*' );
893 if( -1L != nPos )
895 sal_Int32 nValue = rValue.toInt32();
896 if( nValue < MINLAY )
897 nValue = MINLAY;
898 else if( nValue > USHRT_MAX )
899 nValue = USHRT_MAX;
901 pFrmSize->SetWidth( (sal_uInt16)nValue );
902 pFrmSize->SetHeightSizeType( ATT_VAR_SIZE );
903 bOk = true;
906 break;
909 sal_Int32 nValue;
910 if( bSetHeight || bSetWidth )
912 bOk = rUnitConverter.convertMeasureToCore(nValue, rValue, nMin,
913 USHRT_MAX );
914 if( bOk )
916 if( bSetWidth )
917 pFrmSize->SetWidth( (sal_uInt16)nValue );
918 if( bSetHeight )
919 pFrmSize->SetHeight( (sal_uInt16)nValue );
920 if( bSetSizeType )
921 pFrmSize->SetHeightSizeType( eSizeType );
925 break;
927 case RES_FRAMEDIR:
929 const XMLPropertyHandler* pWritingModeHandler =
930 XMLPropertyHandlerFactory::CreatePropertyHandler(
931 XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT );
932 if( pWritingModeHandler != NULL )
934 Any aAny;
935 bOk = pWritingModeHandler->importXML( rValue, aAny,
936 rUnitConverter );
937 if( bOk )
938 bOk = rItem.PutValue( aAny );
940 delete pWritingModeHandler;
943 break;
945 case RES_COLLAPSING_BORDERS:
947 SfxBoolItem* pBorders = PTR_CAST(SfxBoolItem, &rItem);
948 OSL_ENSURE( pBorders != NULL, "Wrong Which-ID" );
950 if( IsXMLToken( rValue, XML_COLLAPSING ) )
952 pBorders->SetValue( sal_True );
953 bOk = true;
955 else if( IsXMLToken( rValue, XML_SEPARATING ) )
957 pBorders->SetValue( sal_False );
958 bOk = true;
960 else
961 bOk = false;
963 break;
965 default:
966 OSL_FAIL("Item not implemented!");
967 break;
970 return bOk;
974 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */