merge the formfield patch from ooo-build
[ooovba.git] / sw / source / filter / xml / xmlimpit.cxx
blobfd17a1c222aedea1a335689013b92ee46c8c95b5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlimpit.cxx,v $
10 * $Revision: 1.24 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include "xmlimpit.hxx"
34 #include <xmloff/xmluconv.hxx>
35 #include <svtools/itempool.hxx>
36 #include <svtools/poolitem.hxx>
37 #include <svtools/itemset.hxx>
38 #include <xmloff/attrlist.hxx>
39 #include <xmloff/nmspmap.hxx>
40 #include <xmloff/xmlnmspe.hxx>
41 #include <svx/xmlcnitm.hxx>
44 #include "hintids.hxx"
45 #include "unomid.h"
46 #include <svx/unomid.hxx>
47 #include <svx/lrspitem.hxx>
48 #include <svx/ulspitem.hxx>
49 #include <svx/shaditem.hxx>
50 #include <svx/boxitem.hxx>
51 #include <svx/brkitem.hxx>
52 #include <svx/keepitem.hxx>
53 #include <svx/brshitem.hxx>
54 #include "fmtpdsc.hxx"
55 #include "fmtornt.hxx"
56 #include "fmtfsize.hxx"
58 #ifndef _FMTLSPLT_HXX
59 #include "fmtlsplt.hxx"
60 #endif
61 #include <xmloff/prhdlfac.hxx>
62 #include <xmloff/xmltypes.hxx>
63 #include "xmlithlp.hxx"
64 #include <com/sun/star/uno/Any.hxx>
66 using ::rtl::OUString;
67 using namespace ::com::sun::star;
68 using namespace ::xmloff::token;
69 using uno::Any;
71 SvXMLImportItemMapper::SvXMLImportItemMapper(
72 SvXMLItemMapEntriesRef rMapEntries,
73 USHORT nUnknWhich ) :
74 mrMapEntries( rMapEntries ),
75 nUnknownWhich( nUnknWhich )
79 SvXMLImportItemMapper::~SvXMLImportItemMapper()
83 /** fills the given itemset with the attributes in the given list */
84 void SvXMLImportItemMapper::importXML( SfxItemSet& rSet,
85 uno::Reference< xml::sax::XAttributeList > xAttrList,
86 const SvXMLUnitConverter& rUnitConverter,
87 const SvXMLNamespaceMap& rNamespaceMap ) const
89 INT16 nAttr = xAttrList->getLength();
91 SvXMLAttrContainerItem *pUnknownItem = 0;
92 for( INT16 i=0; i < nAttr; i++ )
94 const OUString& rAttrName = xAttrList->getNameByIndex( i );
95 OUString aLocalName, aPrefix, aNamespace;
96 USHORT nPrefix =
97 rNamespaceMap.GetKeyByAttrName( rAttrName, &aPrefix, &aLocalName,
98 &aNamespace );
99 if( XML_NAMESPACE_XMLNS == nPrefix )
100 continue;
102 const OUString& rValue = xAttrList->getValueByIndex( i );
104 // find a map entry for this attribute
105 SvXMLItemMapEntry* pEntry = mrMapEntries->getByName( nPrefix, aLocalName );
107 if( pEntry )
109 // we have a valid map entry here, so lets use it...
110 if( 0 == (pEntry->nMemberId & (MID_SW_FLAG_NO_ITEM_IMPORT|
111 MID_SW_FLAG_ELEMENT_ITEM_IMPORT)) )
113 // first get item from itemset
114 const SfxPoolItem* pItem = 0;
115 SfxItemState eState = rSet.GetItemState( pEntry->nWhichId, TRUE,
116 &pItem );
118 // if its not set, try the pool
119 if(SFX_ITEM_SET != eState && SFX_WHICH_MAX > pEntry->nWhichId )
120 pItem = &rSet.GetPool()->GetDefaultItem(pEntry->nWhichId);
122 // do we have an item?
123 if(eState >= SFX_ITEM_DEFAULT && pItem)
125 SfxPoolItem *pNewItem = pItem->Clone();
126 BOOL bPut = FALSE;
128 if( 0 == (pEntry->nMemberId&MID_SW_FLAG_SPECIAL_ITEM_IMPORT) )
130 // bPut = pNewItem->importXML( rValue,
131 // pEntry->nMemberId & MID_SW_FLAG_MASK,
132 // rUnitConverter );
133 bPut = PutXMLValue( *pNewItem, rValue,
134 static_cast<sal_uInt16>( pEntry->nMemberId & MID_SW_FLAG_MASK ),
135 rUnitConverter );
138 else
140 bPut = handleSpecialItem( *pEntry, *pNewItem, rSet,
141 rValue, rUnitConverter,
142 rNamespaceMap );
145 if( bPut )
146 rSet.Put( *pNewItem );
148 delete pNewItem;
150 else
152 DBG_ERROR( "Could not get a needed item for xml import!" );
155 else if( 0 != (pEntry->nMemberId & MID_SW_FLAG_NO_ITEM_IMPORT) )
157 handleNoItem( *pEntry, rSet, rValue, rUnitConverter,
158 rNamespaceMap );
161 else if( USHRT_MAX != nUnknownWhich )
163 if( !pUnknownItem )
165 const SfxPoolItem* pItem = 0;
166 if( SFX_ITEM_SET == rSet.GetItemState( nUnknownWhich, TRUE,
167 &pItem ) )
169 SfxPoolItem *pNew = pItem->Clone();
170 pUnknownItem = PTR_CAST( SvXMLAttrContainerItem, pNew );
171 DBG_ASSERT( pUnknownItem,
172 "SvXMLAttrContainerItem expected" );
173 if( !pUnknownItem )
174 delete pNew;
176 else
178 pUnknownItem = new SvXMLAttrContainerItem( nUnknownWhich );
181 if( pUnknownItem )
183 if( XML_NAMESPACE_NONE == nPrefix )
184 pUnknownItem->AddAttr( aLocalName, rValue );
185 else
186 pUnknownItem->AddAttr( aPrefix, aNamespace, aLocalName,
187 rValue );
192 if( pUnknownItem )
194 rSet.Put( *pUnknownItem );
195 delete pUnknownItem;
198 finished( rSet );
201 /** this method is called for every item that has the
202 MID_SW_FLAG_SPECIAL_ITEM_IMPORT flag set */
203 BOOL
204 SvXMLImportItemMapper::handleSpecialItem( const SvXMLItemMapEntry& /*rEntry*/,
205 SfxPoolItem& /*rItem*/,
206 SfxItemSet& /*rSet*/,
207 const OUString& /*rValue*/,
208 const SvXMLUnitConverter& /*rUnitConverter*/,
209 const SvXMLNamespaceMap& /*rNamespaceMap*/ ) const
211 DBG_ERROR( "unsuported special item in xml import" );
212 return FALSE;
215 /** this method is called for every item that has the
216 MID_SW_FLAG_NO_ITEM_IMPORT flag set */
217 BOOL SvXMLImportItemMapper::handleNoItem( const SvXMLItemMapEntry& /*rEntry*/,
218 SfxItemSet& /*rSet*/,
219 const OUString& /*rValue*/,
220 const SvXMLUnitConverter& /*rUnitConverter*/,
221 const SvXMLNamespaceMap& /*rNamespaceMap*/ ) const
223 DBG_ERROR( "unsuported no item in xml import" );
224 return FALSE;
227 void SvXMLImportItemMapper::finished( SfxItemSet& ) const
229 // nothing to do here
234 // put an XML-string value into an item
235 sal_Bool SvXMLImportItemMapper::PutXMLValue(
236 SfxPoolItem& rItem,
237 const ::rtl::OUString& rValue,
238 sal_uInt16 nMemberId,
239 const SvXMLUnitConverter& rUnitConverter )
241 sal_Bool bOk = sal_False;
243 switch (rItem.Which())
245 case RES_LR_SPACE:
247 SvxLRSpaceItem* pLRSpace = PTR_CAST(SvxLRSpaceItem, &rItem);
248 DBG_ASSERT( pLRSpace != NULL, "Wrong Which-ID!" );
250 switch( nMemberId )
252 case MID_L_MARGIN:
253 case MID_R_MARGIN:
255 sal_Int32 nProp = 100;
256 sal_Int32 nAbs = 0;
258 if( rValue.indexOf( sal_Unicode('%') ) != -1 )
259 bOk = rUnitConverter.convertPercent( nProp, rValue );
260 else
261 bOk = rUnitConverter.convertMeasure( nAbs, rValue );
263 if( bOk )
265 switch( nMemberId )
267 case MID_L_MARGIN:
268 pLRSpace->SetTxtLeft( (sal_Int32)nAbs, (sal_uInt16)nProp );
269 break;
270 case MID_R_MARGIN:
271 pLRSpace->SetRight( (sal_Int32)nAbs, (sal_uInt16)nProp );
272 break;
276 break;
277 case MID_FIRST_LINE_INDENT:
279 sal_Int32 nProp = 100;
280 sal_Int32 nAbs = 0;
282 if( rValue.indexOf( sal_Unicode('%') ) != -1 )
283 bOk = rUnitConverter.convertPercent( nProp, rValue );
284 else
285 bOk = rUnitConverter.convertMeasure( nAbs, rValue,
286 -0x7fff, 0x7fff );
288 pLRSpace->SetTxtFirstLineOfst( (short)nAbs, (sal_uInt16)nProp );
291 case MID_FIRST_AUTO:
293 sal_Bool bAutoFirst;
294 bOk = rUnitConverter.convertBool( bAutoFirst, rValue );
295 if( bOk )
296 pLRSpace->SetAutoFirst( bAutoFirst );
298 break;
300 default:
301 DBG_ERROR( "unknown member id!");
304 break;
306 case RES_UL_SPACE:
308 SvxULSpaceItem* pULSpace = PTR_CAST(SvxULSpaceItem, &rItem);
309 DBG_ASSERT( pULSpace != NULL, "Wrong Which-ID!" );
311 sal_Int32 nProp = 100;
312 sal_Int32 nAbs = 0;
314 if( rValue.indexOf( sal_Unicode('%') ) != -1 )
315 bOk = rUnitConverter.convertPercent( nProp, rValue );
316 else
317 bOk = rUnitConverter.convertMeasure( nAbs, rValue );
319 switch( nMemberId )
321 case MID_UP_MARGIN:
322 pULSpace->SetUpper( (sal_uInt16)nAbs, (sal_uInt16)nProp );
323 break;
324 case MID_LO_MARGIN:
325 pULSpace->SetLower( (sal_uInt16)nAbs, (sal_uInt16)nProp );
326 break;
327 default:
328 DBG_ERROR("unknown MemberId");
331 break;
333 case RES_SHADOW:
335 SvxShadowItem* pShadow = PTR_CAST(SvxShadowItem, &rItem);
336 DBG_ASSERT( pShadow != NULL, "Wrong Which-ID" );
338 sal_Bool bColorFound = sal_False;
339 sal_Bool bOffsetFound = sal_False;
341 SvXMLTokenEnumerator aTokenEnum( rValue );
343 Color aColor( 128,128, 128 );
344 pShadow->SetLocation( SVX_SHADOW_BOTTOMRIGHT );
346 OUString aToken;
347 while( aTokenEnum.getNextToken( aToken ) )
349 if( IsXMLToken( aToken, XML_NONE ) )
351 pShadow->SetLocation( SVX_SHADOW_NONE );
352 bOk = sal_True;
354 else if( !bColorFound && aToken.compareToAscii( "#", 1 ) == 0 )
356 bOk = rUnitConverter.convertColor( aColor, aToken );
357 if( !bOk )
358 return sal_False;
360 bColorFound = sal_True;
362 else if( !bOffsetFound )
364 sal_Int32 nX = 0, nY = 0;
366 bOk = rUnitConverter.convertMeasure( nX, aToken );
367 if( bOk && aTokenEnum.getNextToken( aToken ) )
368 bOk = rUnitConverter.convertMeasure( nY, aToken );
370 if( bOk )
372 if( nX < 0 )
374 if( nY < 0 )
376 pShadow->SetLocation( SVX_SHADOW_TOPLEFT );
378 else
380 pShadow->SetLocation( SVX_SHADOW_BOTTOMLEFT );
383 else
385 if( nY < 0 )
387 pShadow->SetLocation( SVX_SHADOW_TOPRIGHT );
389 else
391 pShadow->SetLocation( SVX_SHADOW_BOTTOMRIGHT );
395 if( nX < 0 ) nX *= -1;
396 if( nY < 0 ) nY *= -1;
398 pShadow->SetWidth( static_cast< USHORT >( (nX + nY) >> 1 ) );
403 if( bOk && ( bColorFound || bOffsetFound ) )
405 pShadow->SetColor( aColor );
407 else
408 bOk = sal_False;
410 break;
412 case RES_BOX:
414 SvxBoxItem* pBox = PTR_CAST(SvxBoxItem, &rItem);
415 DBG_ASSERT( pBox != NULL, "Wrong WHich-ID" );
417 /** copy SvxBorderLines */
418 SvxBorderLine* pTop = pBox->GetTop() == NULL ?
419 NULL : new SvxBorderLine( *pBox->GetTop() );
420 SvxBorderLine* pBottom = pBox->GetBottom() == NULL ?
421 NULL : new SvxBorderLine( *pBox->GetBottom() );
422 SvxBorderLine* pLeft = pBox->GetLeft() == NULL ?
423 NULL : new SvxBorderLine( *pBox->GetLeft() );
424 SvxBorderLine* pRight = pBox->GetRight() == NULL ?
425 NULL : new SvxBorderLine( *pBox->GetRight() );
427 sal_Int32 nTemp;
429 switch( nMemberId )
431 case ALL_BORDER_PADDING:
432 case LEFT_BORDER_PADDING:
433 case RIGHT_BORDER_PADDING:
434 case TOP_BORDER_PADDING:
435 case BOTTOM_BORDER_PADDING:
436 if(!rUnitConverter.convertMeasure( nTemp, rValue, 0, 0xffff ))
437 return sal_False;
439 if( nMemberId == LEFT_BORDER_PADDING ||
440 nMemberId == ALL_BORDER_PADDING )
441 pBox->SetDistance( (sal_uInt16)nTemp, BOX_LINE_LEFT );
442 if( nMemberId == RIGHT_BORDER_PADDING ||
443 nMemberId == ALL_BORDER_PADDING )
444 pBox->SetDistance( (sal_uInt16)nTemp, BOX_LINE_RIGHT );
445 if( nMemberId == TOP_BORDER_PADDING ||
446 nMemberId == ALL_BORDER_PADDING )
447 pBox->SetDistance( (sal_uInt16)nTemp, BOX_LINE_TOP );
448 if( nMemberId == BOTTOM_BORDER_PADDING ||
449 nMemberId == ALL_BORDER_PADDING )
450 pBox->SetDistance( (sal_uInt16)nTemp, BOX_LINE_BOTTOM);
451 break;
453 case ALL_BORDER:
454 case LEFT_BORDER:
455 case RIGHT_BORDER:
456 case TOP_BORDER:
457 case BOTTOM_BORDER:
459 sal_Bool bHasStyle = sal_False;
460 sal_Bool bHasWidth = sal_False;
461 sal_Bool bHasColor = sal_False;
463 sal_uInt16 nStyle = USHRT_MAX;
464 sal_uInt16 nWidth = 0;
465 sal_uInt16 nNamedWidth = USHRT_MAX;
467 Color aColor( COL_BLACK );
469 if( !lcl_frmitems_parseXMLBorder( rValue, rUnitConverter,
470 bHasStyle, nStyle,
471 bHasWidth, nWidth, nNamedWidth,
472 bHasColor, aColor ) )
473 return sal_False;
475 if( TOP_BORDER == nMemberId || ALL_BORDER == nMemberId )
476 lcl_frmitems_setXMLBorder( pTop,
477 bHasStyle, nStyle,
478 bHasWidth, nWidth, nNamedWidth,
479 bHasColor, aColor );
481 if( BOTTOM_BORDER == nMemberId || ALL_BORDER == nMemberId )
482 lcl_frmitems_setXMLBorder( pBottom,
483 bHasStyle, nStyle,
484 bHasWidth, nWidth, nNamedWidth,
485 bHasColor, aColor );
487 if( LEFT_BORDER == nMemberId || ALL_BORDER == nMemberId )
488 lcl_frmitems_setXMLBorder( pLeft,
489 bHasStyle, nStyle,
490 bHasWidth, nWidth, nNamedWidth,
491 bHasColor, aColor );
493 if( RIGHT_BORDER == nMemberId || ALL_BORDER == nMemberId )
494 lcl_frmitems_setXMLBorder( pRight,
495 bHasStyle, nStyle,
496 bHasWidth, nWidth, nNamedWidth,
497 bHasColor, aColor );
499 break;
500 case ALL_BORDER_LINE_WIDTH:
501 case LEFT_BORDER_LINE_WIDTH:
502 case RIGHT_BORDER_LINE_WIDTH:
503 case TOP_BORDER_LINE_WIDTH:
504 case BOTTOM_BORDER_LINE_WIDTH:
506 SvXMLTokenEnumerator aTokenEnum( rValue );
508 sal_Int32 nInWidth, nDistance, nOutWidth;
510 OUString aToken;
511 if( !aTokenEnum.getNextToken( aToken ) )
512 return sal_False;
514 if( !rUnitConverter.convertMeasure( nInWidth, aToken,
515 DEF_LINE_WIDTH_0,
516 DEF_LINE_WIDTH_4 ) )
517 return sal_False;
519 if( !aTokenEnum.getNextToken( aToken ) )
520 return sal_False;
522 if( !rUnitConverter.convertMeasure( nDistance, aToken,
523 DEF_LINE_WIDTH_0,
524 DEF_LINE_WIDTH_4 ) )
525 return sal_False;
527 if( !aTokenEnum.getNextToken( aToken ) )
528 return sal_False;
530 if( !rUnitConverter.convertMeasure( nOutWidth, aToken,
531 DEF_LINE_WIDTH_0,
532 DEF_LINE_WIDTH_4 ) )
533 return sal_False;
535 // #i61946: accept line style even it's not part of our "normal" set of line styles
536 sal_uInt16 nWidth = 0;
538 if( TOP_BORDER_LINE_WIDTH == nMemberId ||
539 ALL_BORDER_LINE_WIDTH == nMemberId )
540 lcl_frmitems_setXMLBorder( pTop, nWidth,
541 static_cast< sal_uInt16 >( nOutWidth ),
542 static_cast< sal_uInt16 >( nInWidth ),
543 static_cast< sal_uInt16 >( nDistance ) );
545 if( BOTTOM_BORDER_LINE_WIDTH == nMemberId ||
546 ALL_BORDER_LINE_WIDTH == nMemberId )
547 lcl_frmitems_setXMLBorder( pBottom, nWidth,
548 static_cast< sal_uInt16 >( nOutWidth ),
549 static_cast< sal_uInt16 >( nInWidth ),
550 static_cast< sal_uInt16 >( nDistance ) );
552 if( LEFT_BORDER_LINE_WIDTH == nMemberId ||
553 ALL_BORDER_LINE_WIDTH == nMemberId )
554 lcl_frmitems_setXMLBorder( pLeft, nWidth,
555 static_cast< sal_uInt16 >( nOutWidth ),
556 static_cast< sal_uInt16 >( nInWidth ),
557 static_cast< sal_uInt16 >( nDistance ) );
559 if( RIGHT_BORDER_LINE_WIDTH == nMemberId ||
560 ALL_BORDER_LINE_WIDTH == nMemberId )
561 lcl_frmitems_setXMLBorder( pRight, nWidth,
562 static_cast< sal_uInt16 >( nOutWidth ),
563 static_cast< sal_uInt16 >( nInWidth ),
564 static_cast< sal_uInt16 >( nDistance ) );
566 break;
569 pBox->SetLine( pTop, BOX_LINE_TOP );
570 pBox->SetLine( pBottom, BOX_LINE_BOTTOM );
571 pBox->SetLine( pLeft, BOX_LINE_LEFT );
572 pBox->SetLine( pRight, BOX_LINE_RIGHT );
574 delete pTop;
575 delete pBottom;
576 delete pLeft;
577 delete pRight;
579 bOk = sal_True;
581 break;
583 case RES_BREAK:
585 SvxFmtBreakItem* pFmtBreak = PTR_CAST(SvxFmtBreakItem, &rItem);
586 DBG_ASSERT( pFmtBreak != NULL, "Wrong Which-ID" );
588 sal_uInt16 eEnum;
590 if( !rUnitConverter.convertEnum( eEnum, rValue, psXML_BreakType ) )
591 return sal_False;
593 if( eEnum == 0 )
595 pFmtBreak->SetValue( SVX_BREAK_NONE );
596 bOk = sal_True;
598 else
600 switch( nMemberId )
602 case MID_BREAK_BEFORE:
603 pFmtBreak->SetValue( static_cast< USHORT >((eEnum == 1) ?
604 SVX_BREAK_COLUMN_BEFORE :
605 SVX_BREAK_PAGE_BEFORE) );
606 break;
607 case MID_BREAK_AFTER:
608 pFmtBreak->SetValue( static_cast< USHORT >((eEnum == 1) ?
609 SVX_BREAK_COLUMN_AFTER :
610 SVX_BREAK_PAGE_AFTER) );
611 break;
613 bOk = sal_True;
616 break;
618 case RES_KEEP:
620 SvxFmtKeepItem* pFmtKeep = PTR_CAST(SvxFmtKeepItem, &rItem);
621 DBG_ASSERT( pFmtKeep != NULL, "Wrong Which-ID" );
623 if( IsXMLToken( rValue, XML_ALWAYS ) ||
624 IsXMLToken( rValue, XML_TRUE ) )
626 pFmtKeep->SetValue( sal_True );
627 bOk = sal_True;
629 else if( IsXMLToken( rValue, XML_AUTO ) ||
630 IsXMLToken( rValue, XML_FALSE ) )
632 pFmtKeep->SetValue( sal_False );
633 bOk = sal_True;
636 break;
638 case RES_BACKGROUND:
640 SvxBrushItem* pBrush = PTR_CAST(SvxBrushItem, &rItem);
641 DBG_ASSERT( pBrush != NULL, "Wrong Which-ID" );
643 Color aTempColor;
644 switch( nMemberId )
646 case MID_BACK_COLOR:
647 if( IsXMLToken( rValue, XML_TRANSPARENT ) )
649 pBrush->GetColor().SetTransparency(0xff);
650 bOk = sal_True;
652 else if( rUnitConverter.convertColor( aTempColor, rValue ) )
654 aTempColor.SetTransparency(0);
655 pBrush->SetColor( aTempColor );
656 bOk = sal_True;
658 break;
660 case MID_GRAPHIC_LINK:
662 SvxGraphicPosition eOldGraphicPos = pBrush->GetGraphicPos();
663 uno::Any aAny;
664 aAny <<= rValue;
665 pBrush->PutValue( aAny, MID_GRAPHIC_URL );
666 if( GPOS_NONE == eOldGraphicPos &&
667 GPOS_NONE != pBrush->GetGraphicPos() )
668 pBrush->SetGraphicPos( GPOS_TILED );
669 bOk = sal_True ;
671 break;
673 case MID_GRAPHIC_REPEAT:
675 SvxGraphicPosition eGraphicPos = pBrush->GetGraphicPos();
676 sal_uInt16 nPos = GPOS_NONE;
677 if( rUnitConverter.convertEnum( nPos, rValue,
678 psXML_BrushRepeat ) )
680 if( GPOS_MM != nPos || GPOS_NONE == eGraphicPos ||
681 GPOS_AREA == eGraphicPos || GPOS_TILED == eGraphicPos )
682 pBrush->SetGraphicPos( (SvxGraphicPosition)nPos );
683 bOk = sal_True;
686 break;
688 case MID_GRAPHIC_POSITION:
690 SvxGraphicPosition ePos = GPOS_NONE, eTmp;
691 sal_uInt16 nTmp;
692 SvXMLTokenEnumerator aTokenEnum( rValue );
693 OUString aToken;
694 sal_Bool bHori = sal_False, bVert = sal_False;
695 bOk = sal_True;
696 while( bOk && aTokenEnum.getNextToken( aToken ) )
698 if( bHori && bVert )
700 bOk = sal_False;
702 else if( -1 != aToken.indexOf( sal_Unicode('%') ) )
704 sal_Int32 nPrc = 50;
705 if( rUnitConverter.convertPercent( nPrc, aToken ) )
707 if( !bHori )
709 ePos = nPrc < 25 ? GPOS_LT :
710 (nPrc < 75 ? GPOS_MM : GPOS_RB);
711 bHori = sal_True;
713 else
715 eTmp = nPrc < 25 ? GPOS_LT:
716 (nPrc < 75 ? GPOS_LM : GPOS_LB);
717 lcl_frmitems_MergeXMLVertPos( ePos, eTmp );
718 bVert = sal_True;
721 else
723 // wrong percentage
724 bOk = sal_False;
727 else if( IsXMLToken( aToken, XML_CENTER ) )
729 if( bHori )
730 lcl_frmitems_MergeXMLVertPos( ePos, GPOS_MM );
731 else if ( bVert )
732 lcl_frmitems_MergeXMLHoriPos( ePos, GPOS_MM );
733 else
734 ePos = GPOS_MM;
736 else if( rUnitConverter.convertEnum( nTmp, aToken,
737 psXML_BrushHoriPos ) )
739 if( bVert )
740 lcl_frmitems_MergeXMLHoriPos(
741 ePos, (SvxGraphicPosition)nTmp );
742 else if( !bHori )
743 ePos = (SvxGraphicPosition)nTmp;
744 else
745 bOk = sal_False;
746 bHori = sal_True;
748 else if( rUnitConverter.convertEnum( nTmp, aToken,
749 psXML_BrushVertPos ) )
751 if( bHori )
752 lcl_frmitems_MergeXMLVertPos(
753 ePos, (SvxGraphicPosition)nTmp );
754 else if( !bVert )
755 ePos = (SvxGraphicPosition)nTmp;
756 else
757 bOk = sal_False;
758 bVert = sal_True;
760 else
762 bOk = sal_False;
766 bOk &= GPOS_NONE != ePos;
767 if( bOk )
768 pBrush->SetGraphicPos( ePos );
770 break;
772 case MID_GRAPHIC_FILTER:
773 pBrush->SetGraphicFilter( rValue.getStr() );
774 bOk = sal_True;
775 break;
778 break;
780 case RES_PAGEDESC:
782 SwFmtPageDesc* pPageDesc = PTR_CAST(SwFmtPageDesc, &rItem);
783 DBG_ASSERT( pPageDesc != NULL, "Wrong Which-ID" );
785 if( MID_PAGEDESC_PAGENUMOFFSET==nMemberId )
787 sal_Int32 nVal;
788 bOk = rUnitConverter.convertNumber( nVal, rValue, 0, USHRT_MAX );
789 if( bOk )
790 pPageDesc->SetNumOffset( (USHORT)nVal );
793 break;
795 case RES_LAYOUT_SPLIT:
796 case RES_ROW_SPLIT:
798 SfxBoolItem* pSplit = PTR_CAST(SfxBoolItem, &rItem);
799 DBG_ASSERT( pSplit != NULL, "Wrong Which-ID" );
801 if( IsXMLToken( rValue, XML_AUTO ) ||
802 IsXMLToken( rValue, XML_TRUE ) )
804 pSplit->SetValue( sal_True );
805 bOk = sal_True;
807 else if( IsXMLToken( rValue, XML_ALWAYS ) ||
808 IsXMLToken( rValue, XML_FALSE ) )
810 pSplit->SetValue( sal_False );
811 bOk = sal_True;
814 break;
816 case RES_HORI_ORIENT:
818 SwFmtHoriOrient* pHoriOrient = PTR_CAST(SwFmtHoriOrient, &rItem);
819 DBG_ASSERT( pHoriOrient != NULL, "Wrong Which-ID" );
821 sal_uInt16 nValue;
822 bOk = rUnitConverter.convertEnum( nValue, rValue,
823 aXMLTableAlignMap );
824 if( bOk )
825 pHoriOrient->SetHoriOrient( nValue );
827 break;
829 case RES_VERT_ORIENT:
831 SwFmtVertOrient* pVertOrient = PTR_CAST(SwFmtVertOrient, &rItem);
832 DBG_ASSERT( pVertOrient != NULL, "Wrong Which-ID" );
834 sal_uInt16 nValue;
835 bOk = rUnitConverter.convertEnum( nValue, rValue,
836 aXMLTableVAlignMap );
837 if( bOk )
838 pVertOrient->SetVertOrient( nValue );
839 //#i8855# text::VertOrientation::NONE is stored as empty string and should be applied here
840 else if(!rValue.getLength())
842 pVertOrient->SetVertOrient( text::VertOrientation::NONE );
843 bOk = sal_True;
846 break;
848 case RES_FRM_SIZE:
850 SwFmtFrmSize* pFrmSize = PTR_CAST(SwFmtFrmSize, &rItem);
851 DBG_ASSERT( pFrmSize != NULL, "Wrong Which-ID" );
853 sal_Bool bSetHeight = sal_False;
854 sal_Bool bSetWidth = sal_False;
855 sal_Bool bSetSizeType = sal_False;
856 SwFrmSize eSizeType = ATT_VAR_SIZE;
857 sal_Int32 nMin = MINLAY;
859 switch( nMemberId )
861 case MID_FRMSIZE_REL_WIDTH:
863 sal_Int32 nValue;
864 bOk = rUnitConverter.convertPercent( nValue, rValue );
865 if( bOk )
867 if( nValue < 1 )
868 nValue = 1;
869 else if( nValue > 100 )
870 nValue = 100;
872 pFrmSize->SetWidthPercent( (sal_Int8)nValue );
875 break;
876 case MID_FRMSIZE_WIDTH:
877 bSetWidth = sal_True;
878 break;
879 case MID_FRMSIZE_MIN_HEIGHT:
880 eSizeType = ATT_MIN_SIZE;
881 bSetHeight = sal_True;
882 nMin = 1;
883 bSetSizeType = sal_True;
884 break;
885 case MID_FRMSIZE_FIX_HEIGHT:
886 eSizeType = ATT_FIX_SIZE;
887 bSetHeight = sal_True;
888 nMin = 1;
889 bSetSizeType = sal_True;
890 break;
891 case MID_FRMSIZE_COL_WIDTH:
892 eSizeType = ATT_FIX_SIZE;
893 bSetWidth = sal_True;
894 bSetSizeType = sal_True;
895 break;
896 case MID_FRMSIZE_REL_COL_WIDTH:
898 sal_Int32 nPos = rValue.indexOf( (sal_Unicode)'*' );
899 if( -1L != nPos )
901 OUString sNum( rValue.copy( 0L, nPos ) );
902 sal_Int32 nValue = rValue.toInt32();
903 if( nValue < MINLAY )
904 nValue = MINLAY;
905 else if( nValue > USHRT_MAX )
906 nValue = USHRT_MAX;
908 pFrmSize->SetWidth( (sal_uInt16)nValue );
909 pFrmSize->SetHeightSizeType( ATT_VAR_SIZE );
910 bOk = sal_True;
913 break;
916 sal_Int32 nValue;
917 if( bSetHeight || bSetWidth )
919 bOk = rUnitConverter.convertMeasure( nValue, rValue, nMin,
920 USHRT_MAX );
921 if( bOk )
923 if( bSetWidth )
924 pFrmSize->SetWidth( (sal_uInt16)nValue );
925 if( bSetHeight )
926 pFrmSize->SetHeight( (sal_uInt16)nValue );
927 if( bSetSizeType )
928 pFrmSize->SetHeightSizeType( eSizeType );
932 break;
934 case RES_FRAMEDIR:
936 const XMLPropertyHandler* pWritingModeHandler =
937 XMLPropertyHandlerFactory::CreatePropertyHandler(
938 XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT );
939 if( pWritingModeHandler != NULL )
941 Any aAny;
942 bOk = pWritingModeHandler->importXML( rValue, aAny,
943 rUnitConverter );
944 if( bOk )
945 bOk = rItem.PutValue( aAny );
948 break;
950 case RES_COLLAPSING_BORDERS:
952 SfxBoolItem* pBorders = PTR_CAST(SfxBoolItem, &rItem);
953 DBG_ASSERT( pBorders != NULL, "Wrong Which-ID" );
955 if( IsXMLToken( rValue, XML_COLLAPSING ) )
957 pBorders->SetValue( sal_True );
958 bOk = sal_True;
960 else if( IsXMLToken( rValue, XML_SEPARATING ) )
962 pBorders->SetValue( sal_False );
963 bOk = sal_True;
965 else
966 bOk = sal_False;
968 break;
970 default:
971 DBG_ERROR("Item not implemented!");
972 break;
975 return bOk;