Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "xmlimpit.hxx"
21 :
22 : #include <sax/tools/converter.hxx>
23 : #include <xmloff/xmluconv.hxx>
24 : #include <svl/itempool.hxx>
25 : #include <svl/poolitem.hxx>
26 : #include <svl/itemset.hxx>
27 : #include <xmloff/attrlist.hxx>
28 : #include <xmloff/nmspmap.hxx>
29 : #include <xmloff/xmlnmspe.hxx>
30 : #include <editeng/xmlcnitm.hxx>
31 : #include <editeng/memberids.hrc>
32 :
33 : #include "hintids.hxx"
34 : #include "unomid.h"
35 : #include <svx/unomid.hxx>
36 : #include <editeng/lrspitem.hxx>
37 : #include <editeng/ulspitem.hxx>
38 : #include <editeng/shaditem.hxx>
39 : #include <editeng/boxitem.hxx>
40 : #include <editeng/formatbreakitem.hxx>
41 : #include <editeng/keepitem.hxx>
42 : #include <editeng/brushitem.hxx>
43 : #include "fmtpdsc.hxx"
44 : #include "fmtornt.hxx"
45 : #include "fmtfsize.hxx"
46 :
47 : #include "fmtlsplt.hxx"
48 : #include <xmloff/prhdlfac.hxx>
49 : #include <xmloff/xmltypes.hxx>
50 : #include <xmloff/xmlprhdl.hxx>
51 : #include "xmlithlp.hxx"
52 : #include <com/sun/star/uno/Any.hxx>
53 :
54 : using ::editeng::SvxBorderLine;
55 : using namespace ::com::sun::star;
56 : using namespace ::xmloff::token;
57 : using uno::Any;
58 :
59 1220 : SvXMLImportItemMapper::SvXMLImportItemMapper(
60 : SvXMLItemMapEntriesRef rMapEntries,
61 : sal_uInt16 nUnknWhich ) :
62 : mrMapEntries( rMapEntries ),
63 1220 : nUnknownWhich( nUnknWhich )
64 : {
65 1220 : }
66 :
67 1220 : SvXMLImportItemMapper::~SvXMLImportItemMapper()
68 : {
69 1220 : }
70 :
71 : void
72 891 : SvXMLImportItemMapper::setMapEntries( SvXMLItemMapEntriesRef rMapEntries )
73 : {
74 891 : mrMapEntries = rMapEntries;
75 891 : }
76 :
77 : // fills the given itemset with the attributes in the given list
78 891 : void SvXMLImportItemMapper::importXML( SfxItemSet& rSet,
79 : uno::Reference< xml::sax::XAttributeList > xAttrList,
80 : const SvXMLUnitConverter& rUnitConverter,
81 : const SvXMLNamespaceMap& rNamespaceMap )
82 : {
83 891 : sal_Int16 nAttr = xAttrList->getLength();
84 :
85 891 : SvXMLAttrContainerItem *pUnknownItem = 0;
86 3788 : for( sal_Int16 i=0; i < nAttr; i++ )
87 : {
88 2897 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
89 5794 : OUString aLocalName, aPrefix, aNamespace;
90 : sal_uInt16 nPrefix =
91 : rNamespaceMap.GetKeyByAttrName( rAttrName, &aPrefix, &aLocalName,
92 2897 : &aNamespace );
93 2897 : if( XML_NAMESPACE_XMLNS == nPrefix )
94 0 : continue;
95 :
96 5794 : const OUString& rValue = xAttrList->getValueByIndex( i );
97 :
98 : // find a map entry for this attribute
99 2897 : SvXMLItemMapEntry* pEntry = mrMapEntries->getByName( nPrefix, aLocalName );
100 :
101 2897 : if( pEntry )
102 : {
103 : // we have a valid map entry here, so lets use it...
104 2897 : if( 0 == (pEntry->nMemberId & (MID_SW_FLAG_NO_ITEM_IMPORT|
105 : MID_SW_FLAG_ELEMENT_ITEM_IMPORT)) )
106 : {
107 : // first get item from itemset
108 2897 : const SfxPoolItem* pItem = 0;
109 : SfxItemState eState = rSet.GetItemState( pEntry->nWhichId, true,
110 2897 : &pItem );
111 :
112 : // if its not set, try the pool
113 2897 : if(SfxItemState::SET != eState && SFX_WHICH_MAX > pEntry->nWhichId )
114 1373 : pItem = &rSet.GetPool()->GetDefaultItem(pEntry->nWhichId);
115 :
116 : // do we have an item?
117 2897 : if(eState >= SfxItemState::DEFAULT && pItem)
118 : {
119 2897 : SfxPoolItem *pNewItem = pItem->Clone();
120 2897 : bool bPut = false;
121 :
122 2897 : if( 0 == (pEntry->nMemberId&MID_SW_FLAG_SPECIAL_ITEM_IMPORT) )
123 : {
124 : bPut = PutXMLValue( *pNewItem, rValue,
125 : static_cast<sal_uInt16>( pEntry->nMemberId & MID_SW_FLAG_MASK ),
126 2607 : rUnitConverter );
127 :
128 : }
129 : else
130 : {
131 : bPut = handleSpecialItem( *pEntry, *pNewItem, rSet,
132 : rValue, rUnitConverter,
133 290 : rNamespaceMap );
134 : }
135 :
136 2897 : if( bPut )
137 2884 : rSet.Put( *pNewItem );
138 :
139 2897 : delete pNewItem;
140 : }
141 : else
142 : {
143 : OSL_FAIL( "Could not get a needed item for xml import!" );
144 : }
145 : }
146 0 : else if( 0 != (pEntry->nMemberId & MID_SW_FLAG_NO_ITEM_IMPORT) )
147 : {
148 : handleNoItem( *pEntry, rSet, rValue, rUnitConverter,
149 0 : rNamespaceMap );
150 : }
151 : }
152 0 : else if( USHRT_MAX != nUnknownWhich )
153 : {
154 0 : if( !pUnknownItem )
155 : {
156 0 : const SfxPoolItem* pItem = 0;
157 0 : if( SfxItemState::SET == rSet.GetItemState( nUnknownWhich, true,
158 0 : &pItem ) )
159 : {
160 0 : SfxPoolItem *pNew = pItem->Clone();
161 0 : pUnknownItem = PTR_CAST( SvXMLAttrContainerItem, pNew );
162 : OSL_ENSURE( pUnknownItem,
163 : "SvXMLAttrContainerItem expected" );
164 0 : if( !pUnknownItem )
165 0 : delete pNew;
166 : }
167 : else
168 : {
169 0 : pUnknownItem = new SvXMLAttrContainerItem( nUnknownWhich );
170 : }
171 : }
172 0 : if( pUnknownItem )
173 : {
174 0 : if( XML_NAMESPACE_NONE == nPrefix )
175 0 : pUnknownItem->AddAttr( aLocalName, rValue );
176 : else
177 : pUnknownItem->AddAttr( aPrefix, aNamespace, aLocalName,
178 0 : rValue );
179 : }
180 : }
181 2897 : }
182 :
183 891 : if( pUnknownItem )
184 : {
185 0 : rSet.Put( *pUnknownItem );
186 0 : delete pUnknownItem;
187 : }
188 :
189 891 : finished(rSet, rUnitConverter);
190 891 : }
191 :
192 : /** this method is called for every item that has the
193 : MID_SW_FLAG_SPECIAL_ITEM_IMPORT flag set */
194 : bool
195 0 : SvXMLImportItemMapper::handleSpecialItem( const SvXMLItemMapEntry& /*rEntry*/,
196 : SfxPoolItem& /*rItem*/,
197 : SfxItemSet& /*rSet*/,
198 : const OUString& /*rValue*/,
199 : const SvXMLUnitConverter& /*rUnitConverter*/,
200 : const SvXMLNamespaceMap& /*rNamespaceMap*/ )
201 : {
202 : OSL_FAIL( "unsupported special item in xml import" );
203 0 : return false;
204 : }
205 :
206 : /** this method is called for every item that has the
207 : MID_SW_FLAG_NO_ITEM_IMPORT flag set */
208 0 : bool SvXMLImportItemMapper::handleNoItem( const SvXMLItemMapEntry& /*rEntry*/,
209 : SfxItemSet& /*rSet*/,
210 : const OUString& /*rValue*/,
211 : const SvXMLUnitConverter& /*rUnitConverter*/,
212 : const SvXMLNamespaceMap& /*rNamespaceMap*/ )
213 : {
214 : OSL_FAIL( "unsupported no item in xml import" );
215 0 : return false;
216 : }
217 :
218 : void
219 0 : SvXMLImportItemMapper::finished(SfxItemSet &, SvXMLUnitConverter const&) const
220 : {
221 : // nothing to do here
222 0 : }
223 :
224 : struct BoxHolder : private boost::noncopyable
225 : {
226 : SvxBorderLine* pTop;
227 : SvxBorderLine* pBottom;
228 : SvxBorderLine* pLeft;
229 : SvxBorderLine* pRight;
230 :
231 1808 : explicit BoxHolder(SvxBoxItem* pBox)
232 1808 : {
233 1808 : pTop = pBox->GetTop() == NULL ?
234 1808 : NULL : new SvxBorderLine( *pBox->GetTop() );
235 1808 : pBottom = pBox->GetBottom() == NULL ?
236 1808 : NULL : new SvxBorderLine( *pBox->GetBottom() );
237 1808 : pLeft = pBox->GetLeft() == NULL ?
238 1808 : NULL : new SvxBorderLine( *pBox->GetLeft() );
239 1808 : pRight = pBox->GetRight() == NULL ?
240 1808 : NULL : new SvxBorderLine( *pBox->GetRight() );
241 1808 : }
242 :
243 1808 : ~BoxHolder()
244 : {
245 1808 : delete pTop;
246 1808 : delete pBottom;
247 1808 : delete pLeft;
248 1808 : delete pRight;
249 1808 : }
250 : };
251 :
252 : // put an XML-string value into an item
253 2897 : bool SvXMLImportItemMapper::PutXMLValue(
254 : SfxPoolItem& rItem,
255 : const OUString& rValue,
256 : sal_uInt16 nMemberId,
257 : const SvXMLUnitConverter& rUnitConverter )
258 : {
259 2897 : bool bOk = false;
260 :
261 2897 : switch (rItem.Which())
262 : {
263 : case RES_LR_SPACE:
264 : {
265 42 : SvxLRSpaceItem* pLRSpace = PTR_CAST(SvxLRSpaceItem, &rItem);
266 : OSL_ENSURE( pLRSpace != NULL, "Wrong Which-ID!" );
267 :
268 42 : switch( nMemberId )
269 : {
270 : case MID_L_MARGIN:
271 : case MID_R_MARGIN:
272 : {
273 42 : sal_Int32 nProp = 100;
274 42 : sal_Int32 nAbs = 0;
275 :
276 42 : if( rValue.indexOf( '%' ) != -1 )
277 0 : bOk = ::sax::Converter::convertPercent(nProp, rValue);
278 : else
279 42 : bOk = rUnitConverter.convertMeasureToCore(nAbs, rValue);
280 :
281 42 : if( bOk )
282 : {
283 42 : switch( nMemberId )
284 : {
285 : case MID_L_MARGIN:
286 31 : pLRSpace->SetTextLeft( (sal_Int32)nAbs, (sal_uInt16)nProp );
287 31 : break;
288 : case MID_R_MARGIN:
289 11 : pLRSpace->SetRight( (sal_Int32)nAbs, (sal_uInt16)nProp );
290 11 : break;
291 : }
292 : }
293 : }
294 42 : break;
295 :
296 : case MID_FIRST_LINE_INDENT:
297 : {
298 0 : sal_Int32 nProp = 100;
299 0 : sal_Int32 nAbs = 0;
300 :
301 0 : if( rValue.indexOf( '%' ) != -1 )
302 0 : bOk = ::sax::Converter::convertPercent(nProp, rValue);
303 : else
304 : bOk = rUnitConverter.convertMeasureToCore(nAbs, rValue,
305 0 : -0x7fff, 0x7fff );
306 :
307 0 : pLRSpace->SetTextFirstLineOfst( (short)nAbs, (sal_uInt16)nProp );
308 : }
309 0 : break;
310 :
311 : case MID_FIRST_AUTO:
312 : {
313 0 : bool bAutoFirst(false);
314 0 : bOk = ::sax::Converter::convertBool( bAutoFirst, rValue );
315 0 : if( bOk )
316 0 : pLRSpace->SetAutoFirst( bAutoFirst );
317 : }
318 0 : break;
319 :
320 : default:
321 : OSL_FAIL( "unknown member id!");
322 : }
323 : }
324 42 : break;
325 :
326 : case RES_UL_SPACE:
327 : {
328 0 : SvxULSpaceItem* pULSpace = PTR_CAST(SvxULSpaceItem, &rItem);
329 : OSL_ENSURE( pULSpace != NULL, "Wrong Which-ID!" );
330 :
331 0 : sal_Int32 nProp = 100;
332 0 : sal_Int32 nAbs = 0;
333 :
334 0 : if( rValue.indexOf( '%' ) != -1 )
335 0 : bOk = ::sax::Converter::convertPercent( nProp, rValue );
336 : else
337 0 : bOk = rUnitConverter.convertMeasureToCore( nAbs, rValue );
338 :
339 0 : switch( nMemberId )
340 : {
341 : case MID_UP_MARGIN:
342 0 : pULSpace->SetUpper( (sal_uInt16)nAbs, (sal_uInt16)nProp );
343 0 : break;
344 : case MID_LO_MARGIN:
345 0 : pULSpace->SetLower( (sal_uInt16)nAbs, (sal_uInt16)nProp );
346 0 : break;
347 : default:
348 : OSL_FAIL("unknown MemberId");
349 : }
350 : }
351 0 : break;
352 :
353 : case RES_SHADOW:
354 : {
355 1 : SvxShadowItem* pShadow = PTR_CAST(SvxShadowItem, &rItem);
356 : OSL_ENSURE( pShadow != NULL, "Wrong Which-ID" );
357 :
358 1 : bool bColorFound = false;
359 1 : bool bOffsetFound = false;
360 :
361 1 : SvXMLTokenEnumerator aTokenEnum( rValue );
362 :
363 1 : Color aColor( 128,128, 128 );
364 1 : pShadow->SetLocation( SVX_SHADOW_BOTTOMRIGHT );
365 :
366 1 : OUString aToken;
367 3 : while( aTokenEnum.getNextToken( aToken ) )
368 : {
369 1 : if( IsXMLToken( aToken, XML_NONE ) )
370 : {
371 1 : pShadow->SetLocation( SVX_SHADOW_NONE );
372 1 : bOk = true;
373 : }
374 0 : else if( !bColorFound && aToken.startsWith("#") )
375 : {
376 0 : sal_Int32 nColor(0);
377 0 : bOk = ::sax::Converter::convertColor( nColor, aToken );
378 0 : if( !bOk )
379 0 : return false;
380 :
381 0 : aColor.SetColor(nColor);
382 0 : bColorFound = true;
383 : }
384 0 : else if( !bOffsetFound )
385 : {
386 0 : sal_Int32 nX = 0, nY = 0;
387 :
388 0 : bOk = rUnitConverter.convertMeasureToCore( nX, aToken );
389 0 : if( bOk && aTokenEnum.getNextToken( aToken ) )
390 0 : bOk = rUnitConverter.convertMeasureToCore( nY, aToken );
391 :
392 0 : if( bOk )
393 : {
394 0 : if( nX < 0 )
395 : {
396 0 : if( nY < 0 )
397 : {
398 0 : pShadow->SetLocation( SVX_SHADOW_TOPLEFT );
399 : }
400 : else
401 : {
402 0 : pShadow->SetLocation( SVX_SHADOW_BOTTOMLEFT );
403 : }
404 : }
405 : else
406 : {
407 0 : if( nY < 0 )
408 : {
409 0 : pShadow->SetLocation( SVX_SHADOW_TOPRIGHT );
410 : }
411 : else
412 : {
413 0 : pShadow->SetLocation( SVX_SHADOW_BOTTOMRIGHT );
414 : }
415 : }
416 :
417 0 : if( nX < 0 ) nX *= -1;
418 0 : if( nY < 0 ) nY *= -1;
419 :
420 0 : pShadow->SetWidth( static_cast< sal_uInt16 >( (nX + nY) >> 1 ) );
421 : }
422 : }
423 : }
424 :
425 1 : if( bOk && ( bColorFound || bOffsetFound ) )
426 : {
427 0 : pShadow->SetColor( aColor );
428 : }
429 : else
430 1 : bOk = false;
431 : }
432 1 : break;
433 :
434 : case RES_BOX:
435 : {
436 1808 : SvxBoxItem* pBox = PTR_CAST(SvxBoxItem, &rItem);
437 : OSL_ENSURE( pBox != NULL, "Wrong WHich-ID" );
438 :
439 : // copy SvxBorderLines
440 1808 : BoxHolder aBoxes(pBox);
441 :
442 : sal_Int32 nTemp;
443 :
444 1808 : switch( nMemberId )
445 : {
446 : case ALL_BORDER_PADDING:
447 : case LEFT_BORDER_PADDING:
448 : case RIGHT_BORDER_PADDING:
449 : case TOP_BORDER_PADDING:
450 : case BOTTOM_BORDER_PADDING:
451 459 : if (!rUnitConverter.convertMeasureToCore( nTemp, rValue,
452 459 : 0, 0xffff ))
453 : {
454 0 : return false;
455 : }
456 :
457 459 : if( nMemberId == LEFT_BORDER_PADDING ||
458 : nMemberId == ALL_BORDER_PADDING )
459 411 : pBox->SetDistance( (sal_uInt16)nTemp, SvxBoxItemLine::LEFT );
460 459 : if( nMemberId == RIGHT_BORDER_PADDING ||
461 : nMemberId == ALL_BORDER_PADDING )
462 411 : pBox->SetDistance( (sal_uInt16)nTemp, SvxBoxItemLine::RIGHT );
463 459 : if( nMemberId == TOP_BORDER_PADDING ||
464 : nMemberId == ALL_BORDER_PADDING )
465 411 : pBox->SetDistance( (sal_uInt16)nTemp, SvxBoxItemLine::TOP );
466 459 : if( nMemberId == BOTTOM_BORDER_PADDING ||
467 : nMemberId == ALL_BORDER_PADDING )
468 411 : pBox->SetDistance( (sal_uInt16)nTemp, SvxBoxItemLine::BOTTOM);
469 459 : break;
470 :
471 : case ALL_BORDER:
472 : case LEFT_BORDER:
473 : case RIGHT_BORDER:
474 : case TOP_BORDER:
475 : case BOTTOM_BORDER:
476 : {
477 1325 : bool bHasStyle = false;
478 1325 : bool bHasWidth = false;
479 1325 : bool bHasColor = false;
480 :
481 1325 : sal_uInt16 nStyle = USHRT_MAX;
482 1325 : sal_uInt16 nWidth = 0;
483 1325 : sal_uInt16 nNamedWidth = USHRT_MAX;
484 :
485 1325 : Color aColor( COL_BLACK );
486 :
487 1325 : if( !sw_frmitems_parseXMLBorder( rValue, rUnitConverter,
488 : bHasStyle, nStyle,
489 : bHasWidth, nWidth, nNamedWidth,
490 1325 : bHasColor, aColor ) )
491 5 : return false;
492 :
493 1320 : if( TOP_BORDER == nMemberId || ALL_BORDER == nMemberId )
494 : sw_frmitems_setXMLBorder( aBoxes.pTop,
495 : bHasStyle, nStyle,
496 : bHasWidth, nWidth, nNamedWidth,
497 406 : bHasColor, aColor );
498 :
499 1320 : if( BOTTOM_BORDER == nMemberId || ALL_BORDER == nMemberId )
500 : sw_frmitems_setXMLBorder( aBoxes.pBottom,
501 : bHasStyle, nStyle,
502 : bHasWidth, nWidth, nNamedWidth,
503 403 : bHasColor, aColor );
504 :
505 1320 : if( LEFT_BORDER == nMemberId || ALL_BORDER == nMemberId )
506 : sw_frmitems_setXMLBorder( aBoxes.pLeft,
507 : bHasStyle, nStyle,
508 : bHasWidth, nWidth, nNamedWidth,
509 407 : bHasColor, aColor );
510 :
511 1320 : if( RIGHT_BORDER == nMemberId || ALL_BORDER == nMemberId )
512 : sw_frmitems_setXMLBorder( aBoxes.pRight,
513 : bHasStyle, nStyle,
514 : bHasWidth, nWidth, nNamedWidth,
515 407 : bHasColor, aColor );
516 : }
517 1320 : break;
518 : case ALL_BORDER_LINE_WIDTH:
519 : case LEFT_BORDER_LINE_WIDTH:
520 : case RIGHT_BORDER_LINE_WIDTH:
521 : case TOP_BORDER_LINE_WIDTH:
522 : case BOTTOM_BORDER_LINE_WIDTH:
523 : {
524 24 : SvXMLTokenEnumerator aTokenEnum( rValue );
525 :
526 : sal_Int32 nInWidth, nDistance, nOutWidth;
527 :
528 24 : OUString aToken;
529 24 : if( !aTokenEnum.getNextToken( aToken ) )
530 0 : return false;
531 :
532 24 : if (!rUnitConverter.convertMeasureToCore(nInWidth, aToken))
533 0 : return false;
534 :
535 24 : if( !aTokenEnum.getNextToken( aToken ) )
536 0 : return false;
537 :
538 24 : if (!rUnitConverter.convertMeasureToCore(nDistance, aToken))
539 0 : return false;
540 :
541 24 : if( !aTokenEnum.getNextToken( aToken ) )
542 0 : return false;
543 :
544 24 : if (!rUnitConverter.convertMeasureToCore(nOutWidth, aToken))
545 0 : return false;
546 :
547 : // #i61946: accept line style even it's not part of our "normal" set of line styles
548 24 : sal_uInt16 nWidth = 0;
549 :
550 24 : if( TOP_BORDER_LINE_WIDTH == nMemberId ||
551 : ALL_BORDER_LINE_WIDTH == nMemberId )
552 : sw_frmitems_setXMLBorder( aBoxes.pTop, nWidth,
553 : static_cast< sal_uInt16 >( nOutWidth ),
554 : static_cast< sal_uInt16 >( nInWidth ),
555 15 : static_cast< sal_uInt16 >( nDistance ) );
556 :
557 24 : if( BOTTOM_BORDER_LINE_WIDTH == nMemberId ||
558 : ALL_BORDER_LINE_WIDTH == nMemberId )
559 : sw_frmitems_setXMLBorder( aBoxes.pBottom, nWidth,
560 : static_cast< sal_uInt16 >( nOutWidth ),
561 : static_cast< sal_uInt16 >( nInWidth ),
562 15 : static_cast< sal_uInt16 >( nDistance ) );
563 :
564 24 : if( LEFT_BORDER_LINE_WIDTH == nMemberId ||
565 : ALL_BORDER_LINE_WIDTH == nMemberId )
566 : sw_frmitems_setXMLBorder( aBoxes.pLeft, nWidth,
567 : static_cast< sal_uInt16 >( nOutWidth ),
568 : static_cast< sal_uInt16 >( nInWidth ),
569 12 : static_cast< sal_uInt16 >( nDistance ) );
570 :
571 24 : if( RIGHT_BORDER_LINE_WIDTH == nMemberId ||
572 : ALL_BORDER_LINE_WIDTH == nMemberId )
573 : sw_frmitems_setXMLBorder( aBoxes.pRight, nWidth,
574 : static_cast< sal_uInt16 >( nOutWidth ),
575 : static_cast< sal_uInt16 >( nInWidth ),
576 15 : static_cast< sal_uInt16 >( nDistance ) );
577 : }
578 24 : break;
579 : }
580 :
581 1803 : pBox->SetLine( aBoxes.pTop, SvxBoxItemLine::TOP );
582 1803 : pBox->SetLine( aBoxes.pBottom, SvxBoxItemLine::BOTTOM );
583 1803 : pBox->SetLine( aBoxes.pLeft, SvxBoxItemLine::LEFT );
584 1803 : pBox->SetLine( aBoxes.pRight, SvxBoxItemLine::RIGHT );
585 :
586 1803 : bOk = true;
587 : }
588 1803 : break;
589 :
590 : case RES_BREAK:
591 : {
592 1 : SvxFormatBreakItem* pFormatBreak = PTR_CAST(SvxFormatBreakItem, &rItem);
593 : OSL_ENSURE( pFormatBreak != NULL, "Wrong Which-ID" );
594 :
595 : sal_uInt16 eEnum;
596 :
597 1 : if( !SvXMLUnitConverter::convertEnum( eEnum, rValue, psXML_BreakType ) )
598 0 : return false;
599 :
600 1 : if( eEnum == 0 )
601 : {
602 0 : pFormatBreak->SetValue( SVX_BREAK_NONE );
603 0 : bOk = true;
604 : }
605 : else
606 : {
607 1 : switch( nMemberId )
608 : {
609 : case MID_BREAK_BEFORE:
610 1 : pFormatBreak->SetValue( static_cast< sal_uInt16 >((eEnum == 1) ?
611 : SVX_BREAK_COLUMN_BEFORE :
612 1 : SVX_BREAK_PAGE_BEFORE) );
613 1 : break;
614 : case MID_BREAK_AFTER:
615 0 : pFormatBreak->SetValue( static_cast< sal_uInt16 >((eEnum == 1) ?
616 : SVX_BREAK_COLUMN_AFTER :
617 0 : SVX_BREAK_PAGE_AFTER) );
618 0 : break;
619 : }
620 1 : bOk = true;
621 : }
622 : }
623 1 : break;
624 :
625 : case RES_KEEP:
626 : {
627 1 : SvxFormatKeepItem* pFormatKeep = PTR_CAST(SvxFormatKeepItem, &rItem);
628 : OSL_ENSURE( pFormatKeep != NULL, "Wrong Which-ID" );
629 :
630 1 : if( IsXMLToken( rValue, XML_ALWAYS ) ||
631 0 : IsXMLToken( rValue, XML_TRUE ) )
632 : {
633 1 : pFormatKeep->SetValue( true );
634 1 : bOk = true;
635 : }
636 0 : else if( IsXMLToken( rValue, XML_AUTO ) ||
637 0 : IsXMLToken( rValue, XML_FALSE ) )
638 : {
639 0 : pFormatKeep->SetValue( false );
640 0 : bOk = true;
641 : }
642 : }
643 1 : break;
644 :
645 : case RES_BACKGROUND:
646 : {
647 209 : SvxBrushItem* pBrush = PTR_CAST(SvxBrushItem, &rItem);
648 : OSL_ENSURE( pBrush != NULL, "Wrong Which-ID" );
649 :
650 209 : sal_Int32 nTempColor(0);
651 209 : switch( nMemberId )
652 : {
653 : case MID_BACK_COLOR:
654 209 : if( IsXMLToken( rValue, XML_TRANSPARENT ) )
655 : {
656 49 : pBrush->GetColor().SetTransparency(0xff);
657 49 : bOk = true;
658 : }
659 160 : else if (::sax::Converter::convertColor(nTempColor, rValue))
660 : {
661 160 : Color aTempColor(nTempColor);
662 160 : aTempColor.SetTransparency(0);
663 160 : pBrush->SetColor( aTempColor );
664 160 : bOk = true;
665 : }
666 209 : break;
667 :
668 : case MID_GRAPHIC_LINK:
669 : {
670 0 : SvxGraphicPosition eOldGraphicPos = pBrush->GetGraphicPos();
671 0 : uno::Any aAny;
672 0 : aAny <<= rValue;
673 0 : pBrush->PutValue( aAny, MID_GRAPHIC_URL );
674 0 : if( GPOS_NONE == eOldGraphicPos &&
675 0 : GPOS_NONE != pBrush->GetGraphicPos() )
676 0 : pBrush->SetGraphicPos( GPOS_TILED );
677 0 : bOk = true;
678 : }
679 0 : break;
680 :
681 : case MID_GRAPHIC_REPEAT:
682 : {
683 0 : SvxGraphicPosition eGraphicPos = pBrush->GetGraphicPos();
684 0 : sal_uInt16 nPos = GPOS_NONE;
685 0 : if( SvXMLUnitConverter::convertEnum( nPos, rValue,
686 : psXML_BrushRepeat ) )
687 : {
688 0 : if( GPOS_MM != nPos || GPOS_NONE == eGraphicPos ||
689 0 : GPOS_AREA == eGraphicPos || GPOS_TILED == eGraphicPos )
690 0 : pBrush->SetGraphicPos( (SvxGraphicPosition)nPos );
691 0 : bOk = true;
692 : }
693 : }
694 0 : break;
695 :
696 : case MID_GRAPHIC_POSITION:
697 : {
698 0 : SvxGraphicPosition ePos = GPOS_NONE, eTmp;
699 : sal_uInt16 nTmp;
700 0 : SvXMLTokenEnumerator aTokenEnum( rValue );
701 0 : OUString aToken;
702 0 : bool bHori = false, bVert = false;
703 0 : bOk = true;
704 0 : while( bOk && aTokenEnum.getNextToken( aToken ) )
705 : {
706 0 : if( bHori && bVert )
707 : {
708 0 : bOk = false;
709 : }
710 0 : else if( -1 != aToken.indexOf( '%' ) )
711 : {
712 0 : sal_Int32 nPrc = 50;
713 0 : if (::sax::Converter::convertPercent(nPrc, aToken))
714 : {
715 0 : if( !bHori )
716 : {
717 0 : ePos = nPrc < 25 ? GPOS_LT :
718 0 : (nPrc < 75 ? GPOS_MM : GPOS_RB);
719 0 : bHori = true;
720 : }
721 : else
722 : {
723 0 : eTmp = nPrc < 25 ? GPOS_LT:
724 0 : (nPrc < 75 ? GPOS_LM : GPOS_LB);
725 0 : sw_frmitems_MergeXMLVertPos( ePos, eTmp );
726 0 : bVert = true;
727 : }
728 : }
729 : else
730 : {
731 : // wrong percentage
732 0 : bOk = false;
733 : }
734 : }
735 0 : else if( IsXMLToken( aToken, XML_CENTER ) )
736 : {
737 0 : if( bHori )
738 0 : sw_frmitems_MergeXMLVertPos( ePos, GPOS_MM );
739 0 : else if ( bVert )
740 0 : sw_frmitems_MergeXMLHoriPos( ePos, GPOS_MM );
741 : else
742 0 : ePos = GPOS_MM;
743 : }
744 0 : else if( SvXMLUnitConverter::convertEnum( nTmp, aToken,
745 : psXML_BrushHoriPos ) )
746 : {
747 0 : if( bVert )
748 : sw_frmitems_MergeXMLHoriPos(
749 0 : ePos, (SvxGraphicPosition)nTmp );
750 0 : else if( !bHori )
751 0 : ePos = (SvxGraphicPosition)nTmp;
752 : else
753 0 : bOk = false;
754 0 : bHori = true;
755 : }
756 0 : else if( SvXMLUnitConverter::convertEnum( nTmp, aToken,
757 : psXML_BrushVertPos ) )
758 : {
759 0 : if( bHori )
760 : sw_frmitems_MergeXMLVertPos(
761 0 : ePos, (SvxGraphicPosition)nTmp );
762 0 : else if( !bVert )
763 0 : ePos = (SvxGraphicPosition)nTmp;
764 : else
765 0 : bOk = false;
766 0 : bVert = true;
767 : }
768 : else
769 : {
770 0 : bOk = false;
771 : }
772 : }
773 :
774 0 : if( GPOS_NONE == ePos ) bOk = false;
775 0 : if( bOk )
776 0 : pBrush->SetGraphicPos( ePos );
777 : }
778 0 : break;
779 :
780 : case MID_GRAPHIC_FILTER:
781 0 : pBrush->SetGraphicFilter( rValue );
782 0 : bOk = true;
783 0 : break;
784 : }
785 : }
786 209 : break;
787 :
788 : case RES_PAGEDESC:
789 : {
790 8 : SwFormatPageDesc* pPageDesc = PTR_CAST(SwFormatPageDesc, &rItem);
791 : OSL_ENSURE( pPageDesc != NULL, "Wrong Which-ID" );
792 :
793 8 : if( MID_PAGEDESC_PAGENUMOFFSET==nMemberId )
794 : {
795 : sal_Int32 nVal;
796 : bOk = ::sax::Converter::convertNumber(
797 8 : nVal, rValue, 0, USHRT_MAX);
798 8 : if( bOk )
799 1 : pPageDesc->SetNumOffset( (sal_uInt16)nVal );
800 : }
801 : }
802 8 : break;
803 :
804 : case RES_LAYOUT_SPLIT:
805 : case RES_ROW_SPLIT:
806 : {
807 31 : SfxBoolItem* pSplit = PTR_CAST(SfxBoolItem, &rItem);
808 : OSL_ENSURE( pSplit != NULL, "Wrong Which-ID" );
809 :
810 36 : if( IsXMLToken( rValue, XML_AUTO ) ||
811 5 : IsXMLToken( rValue, XML_TRUE ) )
812 : {
813 26 : pSplit->SetValue( true );
814 26 : bOk = true;
815 : }
816 6 : else if( IsXMLToken( rValue, XML_ALWAYS ) ||
817 1 : IsXMLToken( rValue, XML_FALSE ) )
818 : {
819 5 : pSplit->SetValue( false );
820 5 : bOk = true;
821 : }
822 : }
823 31 : break;
824 :
825 : case RES_HORI_ORIENT:
826 : {
827 99 : SwFormatHoriOrient* pHoriOrient = PTR_CAST(SwFormatHoriOrient, &rItem);
828 : OSL_ENSURE( pHoriOrient != NULL, "Wrong Which-ID" );
829 :
830 : sal_uInt16 nValue;
831 : bOk = SvXMLUnitConverter::convertEnum( nValue, rValue,
832 99 : aXMLTableAlignMap );
833 99 : if( bOk )
834 99 : pHoriOrient->SetHoriOrient( nValue );
835 : }
836 99 : break;
837 :
838 : case RES_VERT_ORIENT:
839 : {
840 101 : SwFormatVertOrient* pVertOrient = PTR_CAST(SwFormatVertOrient, &rItem);
841 : OSL_ENSURE( pVertOrient != NULL, "Wrong Which-ID" );
842 :
843 : sal_uInt16 nValue;
844 : bOk = SvXMLUnitConverter::convertEnum( nValue, rValue,
845 101 : aXMLTableVAlignMap );
846 101 : if( bOk )
847 101 : pVertOrient->SetVertOrient( nValue );
848 : //#i8855# text::VertOrientation::NONE is stored as empty string and should be applied here
849 0 : else if(rValue.isEmpty())
850 : {
851 0 : pVertOrient->SetVertOrient( text::VertOrientation::NONE );
852 0 : bOk = true;
853 : }
854 : }
855 101 : break;
856 :
857 : case RES_FRM_SIZE:
858 : {
859 561 : SwFormatFrmSize* pFrmSize = PTR_CAST(SwFormatFrmSize, &rItem);
860 : OSL_ENSURE( pFrmSize != NULL, "Wrong Which-ID" );
861 :
862 561 : bool bSetHeight = false;
863 561 : bool bSetWidth = false;
864 561 : bool bSetSizeType = false;
865 561 : SwFrmSize eSizeType = ATT_VAR_SIZE;
866 561 : sal_Int32 nMin = MINLAY;
867 :
868 561 : switch( nMemberId )
869 : {
870 : case MID_FRMSIZE_REL_WIDTH:
871 : {
872 : sal_Int32 nValue;
873 0 : bOk = ::sax::Converter::convertPercent( nValue, rValue );
874 0 : if( bOk )
875 : {
876 0 : if( nValue < 1 )
877 0 : nValue = 1;
878 0 : else if( nValue > 100 )
879 0 : nValue = 100;
880 :
881 0 : pFrmSize->SetWidthPercent( (sal_Int8)nValue );
882 : }
883 : }
884 0 : break;
885 : case MID_FRMSIZE_WIDTH:
886 87 : bSetWidth = true;
887 87 : break;
888 : case MID_FRMSIZE_MIN_HEIGHT:
889 34 : eSizeType = ATT_MIN_SIZE;
890 34 : bSetHeight = true;
891 34 : nMin = 1;
892 34 : bSetSizeType = true;
893 34 : break;
894 : case MID_FRMSIZE_FIX_HEIGHT:
895 32 : eSizeType = ATT_FIX_SIZE;
896 32 : bSetHeight = true;
897 32 : nMin = 1;
898 32 : bSetSizeType = true;
899 32 : break;
900 : case MID_FRMSIZE_COL_WIDTH:
901 248 : eSizeType = ATT_FIX_SIZE;
902 248 : bSetWidth = true;
903 248 : bSetSizeType = true;
904 248 : break;
905 : case MID_FRMSIZE_REL_COL_WIDTH:
906 : {
907 160 : sal_Int32 nPos = rValue.indexOf( '*' );
908 160 : if( -1L != nPos )
909 : {
910 160 : sal_Int32 nValue = rValue.toInt32();
911 160 : if( nValue < MINLAY )
912 0 : nValue = MINLAY;
913 160 : else if( nValue > USHRT_MAX )
914 0 : nValue = USHRT_MAX;
915 :
916 160 : pFrmSize->SetWidth( (sal_uInt16)nValue );
917 160 : pFrmSize->SetHeightSizeType( ATT_VAR_SIZE );
918 160 : bOk = true;
919 : }
920 : }
921 160 : break;
922 : }
923 :
924 : sal_Int32 nValue;
925 561 : if( bSetHeight || bSetWidth )
926 : {
927 : bOk = rUnitConverter.convertMeasureToCore(nValue, rValue, nMin,
928 401 : USHRT_MAX );
929 401 : if( bOk )
930 : {
931 401 : if( bSetWidth )
932 335 : pFrmSize->SetWidth( (sal_uInt16)nValue );
933 401 : if( bSetHeight )
934 66 : pFrmSize->SetHeight( (sal_uInt16)nValue );
935 401 : if( bSetSizeType )
936 314 : pFrmSize->SetHeightSizeType( eSizeType );
937 : }
938 : }
939 : }
940 561 : break;
941 :
942 : case RES_FRAMEDIR:
943 : {
944 : const XMLPropertyHandler* pWritingModeHandler =
945 : XMLPropertyHandlerFactory::CreatePropertyHandler(
946 26 : XML_TYPE_TEXT_WRITING_MODE_WITH_DEFAULT );
947 26 : if( pWritingModeHandler != NULL )
948 : {
949 26 : Any aAny;
950 : bOk = pWritingModeHandler->importXML( rValue, aAny,
951 26 : rUnitConverter );
952 26 : if( bOk )
953 26 : bOk = rItem.PutValue( aAny );
954 :
955 26 : delete pWritingModeHandler;
956 : }
957 : }
958 26 : break;
959 :
960 : case RES_COLLAPSING_BORDERS:
961 : {
962 9 : SfxBoolItem* pBorders = PTR_CAST(SfxBoolItem, &rItem);
963 : OSL_ENSURE( pBorders != NULL, "Wrong Which-ID" );
964 :
965 9 : if( IsXMLToken( rValue, XML_COLLAPSING ) )
966 : {
967 9 : pBorders->SetValue( true );
968 9 : bOk = true;
969 : }
970 0 : else if( IsXMLToken( rValue, XML_SEPARATING ) )
971 : {
972 0 : pBorders->SetValue( false );
973 0 : bOk = true;
974 : }
975 : else
976 0 : bOk = false;
977 : }
978 9 : break;
979 :
980 : default:
981 : OSL_FAIL("Item not implemented!");
982 0 : break;
983 : }
984 :
985 2892 : return bOk;
986 177 : }
987 :
988 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|