bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / XMLTextFrameContext.cxx
blob76e858c5af04a09d1d07bc672ad4d8c5dc4f2417
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 .
20 #include <tools/debug.hxx>
21 #include <osl/diagnose.h>
22 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 #include <com/sun/star/text/TextContentAnchorType.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/text/XTextFrame.hpp>
26 #include <com/sun/star/container/XNamed.hpp>
27 #include <com/sun/star/text/SizeType.hpp>
28 #include <com/sun/star/drawing/XShape.hpp>
29 #include <com/sun/star/document/XEventsSupplier.hpp>
30 #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
31 #include <com/sun/star/io/XOutputStream.hpp>
32 #include <com/sun/star/text/HoriOrientation.hpp>
33 #include <com/sun/star/text/VertOrientation.hpp>
34 #include <sax/tools/converter.hxx>
35 #include <xmloff/xmlimp.hxx>
36 #include <xmloff/xmltoken.hxx>
37 #include <xmloff/xmlnmspe.hxx>
38 #include <xmloff/nmspmap.hxx>
39 #include <xmloff/xmluconv.hxx>
40 #include "XMLAnchorTypePropHdl.hxx"
41 #include "XMLEmbeddedObjectImportContext.hxx"
42 #include <xmloff/XMLBase64ImportContext.hxx>
43 #include "XMLReplacementImageContext.hxx"
44 #include <xmloff/prstylei.hxx>
45 #include <xmloff/i18nmap.hxx>
46 #include "xexptran.hxx"
47 #include <xmloff/shapeimport.hxx>
48 #include <xmloff/XMLEventsImportContext.hxx>
49 #include "XMLImageMapContext.hxx"
50 #include "XMLTextFrameContext.hxx"
51 #include "XMLTextListBlockContext.hxx"
52 #include "XMLTextListItemContext.hxx"
53 #include <xmloff/attrlist.hxx>
54 #include <basegfx/polygon/b2dpolygon.hxx>
55 #include <basegfx/polygon/b2dpolygontools.hxx>
56 #include <basegfx/matrix/b2dhommatrixtools.hxx>
57 #include <basegfx/polygon/b2dpolypolygontools.hxx>
58 #include <map>
60 using namespace ::com::sun::star;
61 using namespace ::com::sun::star::uno;
62 using namespace ::com::sun::star::text;
63 using namespace ::com::sun::star::xml::sax;
64 using namespace ::com::sun::star::beans;
65 using namespace ::com::sun::star::lang;
66 using namespace ::com::sun::star::container;
67 using namespace ::com::sun::star::drawing;
68 using namespace ::com::sun::star::document;
69 using namespace ::xmloff::token;
70 using ::com::sun::star::document::XEventsSupplier;
72 #define XML_TEXT_FRAME_TEXTBOX 1
73 #define XML_TEXT_FRAME_GRAPHIC 2
74 #define XML_TEXT_FRAME_OBJECT 3
75 #define XML_TEXT_FRAME_OBJECT_OLE 4
76 #define XML_TEXT_FRAME_APPLET 5
77 #define XML_TEXT_FRAME_PLUGIN 6
78 #define XML_TEXT_FRAME_FLOATING_FRAME 7
80 typedef ::std::map < const OUString, OUString > ParamMap;
82 class XMLTextFrameContextHyperlink_Impl
84 OUString sHRef;
85 OUString sName;
86 OUString sTargetFrameName;
87 bool bMap;
89 public:
91 inline XMLTextFrameContextHyperlink_Impl( const OUString& rHRef,
92 const OUString& rName,
93 const OUString& rTargetFrameName,
94 bool bMap );
96 const OUString& GetHRef() const { return sHRef; }
97 const OUString& GetName() const { return sName; }
98 const OUString& GetTargetFrameName() const { return sTargetFrameName; }
99 bool GetMap() const { return bMap; }
102 inline XMLTextFrameContextHyperlink_Impl::XMLTextFrameContextHyperlink_Impl(
103 const OUString& rHRef, const OUString& rName,
104 const OUString& rTargetFrameName, bool bM ) :
105 sHRef( rHRef ),
106 sName( rName ),
107 sTargetFrameName( rTargetFrameName ),
108 bMap( bM )
112 // Implement Title/Description Elements UI (#i73249#)
113 class XMLTextFrameTitleOrDescContext_Impl : public SvXMLImportContext
115 OUString& mrTitleOrDesc;
117 public:
119 TYPEINFO_OVERRIDE();
121 XMLTextFrameTitleOrDescContext_Impl( SvXMLImport& rImport,
122 sal_uInt16 nPrfx,
123 const OUString& rLName,
124 OUString& rTitleOrDesc );
125 virtual ~XMLTextFrameTitleOrDescContext_Impl();
127 virtual void Characters( const OUString& rText ) SAL_OVERRIDE;
130 TYPEINIT1( XMLTextFrameTitleOrDescContext_Impl, SvXMLImportContext );
132 XMLTextFrameTitleOrDescContext_Impl::XMLTextFrameTitleOrDescContext_Impl(
133 SvXMLImport& rImport,
134 sal_uInt16 nPrfx,
135 const OUString& rLName,
136 OUString& rTitleOrDesc )
137 : SvXMLImportContext( rImport, nPrfx, rLName )
138 , mrTitleOrDesc( rTitleOrDesc )
142 XMLTextFrameTitleOrDescContext_Impl::~XMLTextFrameTitleOrDescContext_Impl()
146 void XMLTextFrameTitleOrDescContext_Impl::Characters( const OUString& rText )
148 mrTitleOrDesc += rText;
151 class XMLTextFrameParam_Impl : public SvXMLImportContext
153 public:
155 TYPEINFO_OVERRIDE();
157 XMLTextFrameParam_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
158 const OUString& rLName,
159 const ::com::sun::star::uno::Reference<
160 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
161 sal_uInt16 nType,
162 ParamMap &rParamMap);
163 virtual ~XMLTextFrameParam_Impl();
166 TYPEINIT1( XMLTextFrameParam_Impl, SvXMLImportContext );
168 XMLTextFrameParam_Impl::~XMLTextFrameParam_Impl()
172 XMLTextFrameParam_Impl::XMLTextFrameParam_Impl(
173 SvXMLImport& rImport, sal_uInt16 nPrfx,
174 const OUString& rLName,
175 const ::com::sun::star::uno::Reference<
176 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
177 sal_uInt16 /*nType*/,
178 ParamMap &rParamMap):
179 SvXMLImportContext( rImport, nPrfx, rLName )
181 OUString sName, sValue;
182 bool bFoundValue = false; // to allow empty values
183 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
184 for( sal_Int16 i=0; i < nAttrCount; i++ )
186 const OUString& rAttrName = xAttrList->getNameByIndex( i );
187 const OUString& rValue = xAttrList->getValueByIndex( i );
189 OUString aLocalName;
190 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
191 if ( XML_NAMESPACE_DRAW == nPrefix )
193 if( IsXMLToken(aLocalName, XML_VALUE) )
195 sValue = rValue;
196 bFoundValue=true;
198 else if( IsXMLToken(aLocalName, XML_NAME) )
200 sName = rValue;
204 if (!sName.isEmpty() && bFoundValue )
205 rParamMap[sName] = sValue;
207 class XMLTextFrameContourContext_Impl : public SvXMLImportContext
209 Reference < XPropertySet > xPropSet;
211 public:
213 TYPEINFO_OVERRIDE();
215 XMLTextFrameContourContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
216 const OUString& rLName,
217 const ::com::sun::star::uno::Reference<
218 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
219 const Reference < XPropertySet >& rPropSet,
220 bool bPath );
221 virtual ~XMLTextFrameContourContext_Impl();
224 TYPEINIT1( XMLTextFrameContourContext_Impl, SvXMLImportContext );
226 XMLTextFrameContourContext_Impl::XMLTextFrameContourContext_Impl(
227 SvXMLImport& rImport,
228 sal_uInt16 nPrfx, const OUString& rLName,
229 const Reference< XAttributeList > & xAttrList,
230 const Reference < XPropertySet >& rPropSet,
231 bool bPath ) :
232 SvXMLImportContext( rImport, nPrfx, rLName ),
233 xPropSet( rPropSet )
235 OUString sD, sPoints, sViewBox;
236 bool bPixelWidth = false, bPixelHeight = false;
237 sal_Bool bAuto = sal_False;
238 sal_Int32 nWidth = 0;
239 sal_Int32 nHeight = 0;
241 const SvXMLTokenMap& rTokenMap =
242 GetImport().GetTextImport()->GetTextContourAttrTokenMap();
244 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
245 for( sal_Int16 i=0; i < nAttrCount; i++ )
247 const OUString& rAttrName = xAttrList->getNameByIndex( i );
248 const OUString& rValue = xAttrList->getValueByIndex( i );
250 OUString aLocalName;
251 sal_uInt16 nPrefix =
252 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
253 &aLocalName );
254 switch( rTokenMap.Get( nPrefix, aLocalName ) )
256 case XML_TOK_TEXT_CONTOUR_VIEWBOX:
257 sViewBox = rValue;
258 break;
259 case XML_TOK_TEXT_CONTOUR_D:
260 if( bPath )
261 sD = rValue;
262 break;
263 case XML_TOK_TEXT_CONTOUR_POINTS:
264 if( !bPath )
265 sPoints = rValue;
266 break;
267 case XML_TOK_TEXT_CONTOUR_WIDTH:
268 if (::sax::Converter::convertMeasurePx(nWidth, rValue))
269 bPixelWidth = true;
270 else
271 GetImport().GetMM100UnitConverter().convertMeasureToCore(
272 nWidth, rValue);
273 break;
274 case XML_TOK_TEXT_CONTOUR_HEIGHT:
275 if (::sax::Converter::convertMeasurePx(nHeight, rValue))
276 bPixelHeight = true;
277 else
278 GetImport().GetMM100UnitConverter().convertMeasureToCore(
279 nHeight, rValue);
280 break;
281 case XML_TOK_TEXT_CONTOUR_AUTO:
282 bAuto = IsXMLToken(rValue, XML_TRUE);
283 break;
287 OUString sContourPolyPolygon("ContourPolyPolygon");
288 Reference < XPropertySetInfo > xPropSetInfo = rPropSet->getPropertySetInfo();
290 if(xPropSetInfo->hasPropertyByName(sContourPolyPolygon) && nWidth > 0 && nHeight > 0 && bPixelWidth == bPixelHeight && (bPath ? sD : sPoints).getLength())
292 const SdXMLImExViewBox aViewBox( sViewBox, GetImport().GetMM100UnitConverter());
293 basegfx::B2DPolyPolygon aPolyPolygon;
294 Any aAny;
296 if( bPath )
298 basegfx::tools::importFromSvgD(aPolyPolygon, sD, GetImport().needFixPositionAfterZ(), 0);
300 else
302 basegfx::B2DPolygon aPolygon;
304 if(basegfx::tools::importFromSvgPoints(aPolygon, sPoints))
306 aPolyPolygon = basegfx::B2DPolyPolygon(aPolygon);
310 if(aPolyPolygon.count())
312 const basegfx::B2DRange aSourceRange(
313 aViewBox.GetX(), aViewBox.GetY(),
314 aViewBox.GetX() + aViewBox.GetWidth(), aViewBox.GetY() + aViewBox.GetHeight());
315 const basegfx::B2DRange aTargetRange(
316 0.0, 0.0,
317 nWidth, nHeight);
319 if(!aSourceRange.equal(aTargetRange))
321 aPolyPolygon.transform(
322 basegfx::tools::createSourceRangeTargetRangeTransform(
323 aSourceRange,
324 aTargetRange));
327 com::sun::star::drawing::PointSequenceSequence aPointSequenceSequence;
328 basegfx::tools::B2DPolyPolygonToUnoPointSequenceSequence(aPolyPolygon, aPointSequenceSequence);
329 aAny <<= aPointSequenceSequence;
330 xPropSet->setPropertyValue( sContourPolyPolygon, aAny );
333 const OUString sIsPixelContour("IsPixelContour");
335 if( xPropSetInfo->hasPropertyByName( sIsPixelContour ) )
337 aAny.setValue( &bPixelWidth, cppu::UnoType<bool>::get() );
338 xPropSet->setPropertyValue( sIsPixelContour, aAny );
341 const OUString sIsAutomaticContour("IsAutomaticContour");
343 if( xPropSetInfo->hasPropertyByName( sIsAutomaticContour ) )
345 aAny.setValue( &bAuto, cppu::UnoType<bool>::get() );
346 xPropSet->setPropertyValue( sIsAutomaticContour, aAny );
351 XMLTextFrameContourContext_Impl::~XMLTextFrameContourContext_Impl()
355 class XMLTextFrameContext_Impl : public SvXMLImportContext
357 ::com::sun::star::uno::Reference <
358 ::com::sun::star::text::XTextCursor > xOldTextCursor;
359 ::com::sun::star::uno::Reference <
360 ::com::sun::star::beans::XPropertySet > xPropSet;
361 ::com::sun::star::uno::Reference <
362 ::com::sun::star::io::XOutputStream > xBase64Stream;
364 /// old list item and block (#89891#)
365 bool mbListContextPushed;
367 const OUString sWidth;
368 const OUString sWidthType;
369 const OUString sRelativeWidth;
370 const OUString sHeight;
371 const OUString sRelativeHeight;
372 const OUString sSizeType;
373 const OUString sIsSyncWidthToHeight;
374 const OUString sIsSyncHeightToWidth;
375 const OUString sHoriOrient;
376 const OUString sHoriOrientPosition;
377 const OUString sVertOrient;
378 const OUString sVertOrientPosition;
379 const OUString sAnchorType;
380 const OUString sAnchorPageNo;
381 const OUString sGraphicURL;
382 const OUString sGraphicFilter;
383 const OUString sTitle;
384 const OUString sDescription;
385 const OUString sFrameStyleName;
386 const OUString sGraphicRotation;
387 const OUString sTextBoxServiceName;
388 const OUString sGraphicServiceName;
390 OUString m_sOrigName;
391 OUString sName;
392 OUString sStyleName;
393 OUString sNextName;
394 OUString sHRef;
395 OUString sFilterName;
396 OUString sCode;
397 OUString sObject;
398 OUString sArchive;
399 OUString sMimeType;
400 OUString sFrameName;
401 OUString sAppletName;
402 OUString sFilterService;
403 OUString sBase64CharsLeft;
404 OUString sTblName;
406 ParamMap aParamMap;
408 sal_Int32 nX;
409 sal_Int32 nY;
410 sal_Int32 nWidth;
411 sal_Int32 nHeight;
412 sal_Int32 nZIndex;
413 sal_Int16 nPage;
414 sal_Int16 nRotation;
415 sal_Int16 nRelWidth;
416 sal_Int16 nRelHeight;
418 sal_uInt16 nType;
419 ::com::sun::star::text::TextContentAnchorType eAnchorType;
421 bool bMayScript : 1;
422 bool bMinWidth : 1;
423 bool bMinHeight : 1;
424 bool bSyncWidth : 1;
425 bool bSyncHeight : 1;
426 bool bCreateFailed : 1;
427 bool bOwnBase64Stream : 1;
429 void Create( bool bHRefOrBase64 );
431 public:
433 TYPEINFO_OVERRIDE();
435 bool CreateIfNotThere();
436 const OUString& GetHRef() const { return sHRef; }
438 XMLTextFrameContext_Impl( SvXMLImport& rImport,
439 sal_uInt16 nPrfx,
440 const OUString& rLName,
441 const ::com::sun::star::uno::Reference<
442 ::com::sun::star::xml::sax::XAttributeList > & rAttrList,
443 ::com::sun::star::text::TextContentAnchorType eAnchorType,
444 sal_uInt16 nType,
445 const ::com::sun::star::uno::Reference<
446 ::com::sun::star::xml::sax::XAttributeList > & rFrameAttrList );
447 virtual ~XMLTextFrameContext_Impl();
449 virtual void EndElement() SAL_OVERRIDE;
451 virtual void Characters( const OUString& rChars ) SAL_OVERRIDE;
453 SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
454 const OUString& rLocalName,
455 const ::com::sun::star::uno::Reference<
456 ::com::sun::star::xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
458 void SetHyperlink( const OUString& rHRef,
459 const OUString& rName,
460 const OUString& rTargetFrameName,
461 bool bMap );
463 // Implement Title/Description Elements UI (#i73249#)
464 void SetTitle( const OUString& rTitle );
466 void SetDesc( const OUString& rDesc );
468 void SetName();
470 ::com::sun::star::text::TextContentAnchorType GetAnchorType() const { return eAnchorType; }
472 const ::com::sun::star::uno::Reference <
473 ::com::sun::star::beans::XPropertySet >& GetPropSet() const { return xPropSet; }
476 TYPEINIT1( XMLTextFrameContext_Impl, SvXMLImportContext );
478 void XMLTextFrameContext_Impl::Create( bool /*bHRefOrBase64*/ )
480 rtl::Reference < XMLTextImportHelper > xTextImportHelper =
481 GetImport().GetTextImport();
483 switch ( nType)
485 case XML_TEXT_FRAME_OBJECT:
486 case XML_TEXT_FRAME_OBJECT_OLE:
487 if( xBase64Stream.is() )
489 OUString sURL( GetImport().ResolveEmbeddedObjectURLFromBase64() );
490 if( !sURL.isEmpty() )
491 xPropSet = GetImport().GetTextImport()
492 ->createAndInsertOLEObject( GetImport(), sURL,
493 sStyleName,
494 sTblName,
495 nWidth, nHeight );
497 else if( !sHRef.isEmpty() )
499 OUString sURL( GetImport().ResolveEmbeddedObjectURL( sHRef,
500 OUString() ) );
502 if( GetImport().IsPackageURL( sHRef ) )
504 xPropSet = GetImport().GetTextImport()
505 ->createAndInsertOLEObject( GetImport(), sURL,
506 sStyleName,
507 sTblName,
508 nWidth, nHeight );
510 else
512 // it should be an own OOo link that has no storage persistence
513 xPropSet = GetImport().GetTextImport()
514 ->createAndInsertOOoLink( GetImport(),
515 sURL,
516 sStyleName,
517 sTblName,
518 nWidth, nHeight );
521 else
523 OUString sURL( "vnd.sun.star.ServiceName:" );
524 sURL += sFilterService;
525 xPropSet = GetImport().GetTextImport()
526 ->createAndInsertOLEObject( GetImport(), sURL,
527 sStyleName,
528 sTblName,
529 nWidth, nHeight );
532 break;
533 case XML_TEXT_FRAME_APPLET:
535 xPropSet = GetImport().GetTextImport()
536 ->createAndInsertApplet( sAppletName, sCode,
537 bMayScript, sHRef,
538 nWidth, nHeight);
539 break;
541 case XML_TEXT_FRAME_PLUGIN:
543 if(!sHRef.isEmpty())
544 GetImport().GetAbsoluteReference(sHRef);
545 xPropSet = GetImport().GetTextImport()
546 ->createAndInsertPlugin( sMimeType, sHRef,
547 nWidth, nHeight);
549 break;
551 case XML_TEXT_FRAME_FLOATING_FRAME:
553 xPropSet = GetImport().GetTextImport()
554 ->createAndInsertFloatingFrame( sFrameName, sHRef,
555 sStyleName,
556 nWidth, nHeight);
557 break;
559 default:
561 Reference<XMultiServiceFactory> xFactory( GetImport().GetModel(),
562 UNO_QUERY );
563 if( xFactory.is() )
565 OUString sServiceName;
566 switch( nType )
568 case XML_TEXT_FRAME_TEXTBOX: sServiceName = sTextBoxServiceName; break;
569 case XML_TEXT_FRAME_GRAPHIC: sServiceName = sGraphicServiceName; break;
571 Reference<XInterface> xIfc = xFactory->createInstance( sServiceName );
572 DBG_ASSERT( xIfc.is(), "couldn't create frame" );
573 if( xIfc.is() )
574 xPropSet = Reference < XPropertySet >( xIfc, UNO_QUERY );
579 if( !xPropSet.is() )
581 bCreateFailed = true;
582 return;
585 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
587 // set name
588 Reference < XNamed > xNamed( xPropSet, UNO_QUERY );
589 if( xNamed.is() )
591 OUString sOrigName( xNamed->getName() );
592 if( sOrigName.isEmpty() ||
593 (!sName.isEmpty() && sOrigName != sName) )
595 OUString sOldName( sName );
597 sal_Int32 i = 0;
598 while( xTextImportHelper->HasFrameByName( sName ) )
600 sName = sOldName;
601 sName += OUString::number( ++i );
603 xNamed->setName( sName );
604 if( sName != sOldName )
606 bool bSuccess = xTextImportHelper->GetRenameMap().Add( XML_TEXT_RENAME_TYPE_FRAME,
607 sOldName, sName );
608 if (!bSuccess && GetImport().getGeneratorVersion() == SvXMLImport::LO_44x)
610 bCreateFailed = true;
611 return;
617 // frame style
618 XMLPropStyleContext *pStyle = 0;
619 if( !sStyleName.isEmpty() )
621 pStyle = xTextImportHelper->FindAutoFrameStyle( sStyleName );
622 if( pStyle )
623 sStyleName = pStyle->GetParentName();
626 Any aAny;
627 if( !sStyleName.isEmpty() )
629 OUString sDisplayStyleName( GetImport().GetStyleDisplayName(
630 XML_STYLE_FAMILY_SD_GRAPHICS_ID, sStyleName ) );
631 const Reference < XNameContainer > & rStyles =
632 xTextImportHelper->GetFrameStyles();
633 if( rStyles.is() &&
634 rStyles->hasByName( sDisplayStyleName ) )
636 aAny <<= sDisplayStyleName;
637 xPropSet->setPropertyValue( sFrameStyleName, aAny );
641 // anchor type (must be set before any other properties, because
642 // otherwise some orientations cannot be set or will be changed
643 // afterwards)
644 aAny <<= eAnchorType;
645 xPropSet->setPropertyValue( sAnchorType, aAny );
647 // hard properties
648 if( pStyle )
649 pStyle->FillPropertySet( xPropSet );
651 // x and y
652 sal_Int16 nHoriOrient = HoriOrientation::NONE;
653 aAny = xPropSet->getPropertyValue( sHoriOrient );
654 aAny >>= nHoriOrient;
655 if( HoriOrientation::NONE == nHoriOrient )
657 aAny <<= nX;
658 xPropSet->setPropertyValue( sHoriOrientPosition, aAny );
661 sal_Int16 nVertOrient = VertOrientation::NONE;
662 aAny = xPropSet->getPropertyValue( sVertOrient );
663 aAny >>= nVertOrient;
664 if( VertOrientation::NONE == nVertOrient )
666 aAny <<= nY;
667 xPropSet->setPropertyValue( sVertOrientPosition, aAny );
670 // width
671 if( nWidth > 0 )
673 aAny <<= nWidth;
674 xPropSet->setPropertyValue( sWidth, aAny );
676 if( nRelWidth > 0 || nWidth > 0 )
678 aAny <<= nRelWidth;
679 xPropSet->setPropertyValue( sRelativeWidth, aAny );
681 if( bSyncWidth || nWidth > 0 )
683 sal_Bool bTmp = bSyncWidth;
684 aAny.setValue( &bTmp, cppu::UnoType<bool>::get() );
685 xPropSet->setPropertyValue( sIsSyncWidthToHeight, aAny );
687 if( xPropSetInfo->hasPropertyByName( sWidthType ) &&
688 (bMinWidth || nWidth > 0 || nRelWidth > 0 ) )
690 sal_Int16 nSizeType =
691 (bMinWidth && XML_TEXT_FRAME_TEXTBOX == nType) ? SizeType::MIN
692 : SizeType::FIX;
693 aAny <<= nSizeType;
694 xPropSet->setPropertyValue( sWidthType, aAny );
697 if( nHeight > 0 )
699 aAny <<= nHeight;
700 xPropSet->setPropertyValue( sHeight, aAny );
702 if( nRelHeight > 0 || nHeight > 0 )
704 aAny <<= nRelHeight;
705 xPropSet->setPropertyValue( sRelativeHeight, aAny );
707 if( bSyncHeight || nHeight > 0 )
709 sal_Bool bTmp = bSyncHeight;
710 aAny.setValue( &bTmp, cppu::UnoType<bool>::get() );
711 xPropSet->setPropertyValue( sIsSyncHeightToWidth, aAny );
713 if( xPropSetInfo->hasPropertyByName( sSizeType ) &&
714 (bMinHeight || nHeight > 0 || nRelHeight > 0 ) )
716 sal_Int16 nSizeType =
717 (bMinHeight && XML_TEXT_FRAME_TEXTBOX == nType) ? SizeType::MIN
718 : SizeType::FIX;
719 aAny <<= nSizeType;
720 xPropSet->setPropertyValue( sSizeType, aAny );
723 if( XML_TEXT_FRAME_GRAPHIC == nType )
725 // URL
726 OSL_ENSURE( !sHRef.isEmpty() || xBase64Stream.is(),
727 "neither URL nor base64 image data given" );
728 rtl::Reference < XMLTextImportHelper > xTxtImport =
729 GetImport().GetTextImport();
730 if( !sHRef.isEmpty() )
732 bool bForceLoad = xTxtImport->IsInsertMode() ||
733 xTxtImport->IsBlockMode() ||
734 xTxtImport->IsStylesOnlyMode() ||
735 xTxtImport->IsOrganizerMode();
736 sHRef = GetImport().ResolveGraphicObjectURL( sHRef, !bForceLoad );
738 else if( xBase64Stream.is() )
740 sHRef = GetImport().ResolveGraphicObjectURLFromBase64( xBase64Stream );
741 xBase64Stream = 0;
743 aAny <<= sHRef;
744 xPropSet->setPropertyValue( sGraphicURL, aAny );
746 // filter name
747 aAny <<=sFilterName;
748 xPropSet->setPropertyValue( sGraphicFilter, aAny );
750 // rotation
751 aAny <<= nRotation;
752 xPropSet->setPropertyValue( sGraphicRotation, aAny );
755 // page number (must be set after the frame is inserted, because it
756 // will be overwritten then inserting the frame.
757 if( TextContentAnchorType_AT_PAGE == eAnchorType && nPage > 0 )
759 aAny <<= nPage;
760 xPropSet->setPropertyValue( sAnchorPageNo, aAny );
763 if( XML_TEXT_FRAME_OBJECT != nType &&
764 XML_TEXT_FRAME_OBJECT_OLE != nType &&
765 XML_TEXT_FRAME_APPLET != nType &&
766 XML_TEXT_FRAME_PLUGIN!= nType &&
767 XML_TEXT_FRAME_FLOATING_FRAME != nType)
769 Reference < XTextContent > xTxtCntnt( xPropSet, UNO_QUERY );
772 xTextImportHelper->InsertTextContent(xTxtCntnt);
774 catch (lang::IllegalArgumentException const& e)
776 SAL_WARN("xmloff.text", "Cannot import part of the text - probably an image in the text frame? " << e.Message);
777 return;
781 // #107848#
782 // Make adding the shepe to Z-Ordering dependent from if we are
783 // inside a inside_deleted_section (redlining). That is necessary
784 // since the shape will be removed again later. It would lead to
785 // errors if it would stay inside the Z-Ordering. Thus, the
786 // easiest way to solve that conflict is to not add it here.
787 if(!GetImport().HasTextImport()
788 || !GetImport().GetTextImport()->IsInsideDeleteContext())
790 Reference < XShape > xShape( xPropSet, UNO_QUERY );
792 GetImport().GetShapeImport()->shapeWithZIndexAdded( xShape, nZIndex );
795 if( XML_TEXT_FRAME_TEXTBOX == nType )
797 xTextImportHelper->ConnectFrameChains( sName, sNextName, xPropSet );
798 Reference < XTextFrame > xTxtFrame( xPropSet, UNO_QUERY );
799 Reference < XText > xTxt = xTxtFrame->getText();
800 xOldTextCursor = xTextImportHelper->GetCursor();
801 xTextImportHelper->SetCursor( xTxt->createTextCursor() );
803 // remember old list item and block (#89892#) and reset them
804 // for the text frame
805 xTextImportHelper->PushListContext();
806 mbListContextPushed = true;
810 void XMLTextFrameContext::removeGraphicFromImportContext(const SvXMLImportContext& rContext) const
812 const XMLTextFrameContext_Impl* pXMLTextFrameContext_Impl = dynamic_cast< const XMLTextFrameContext_Impl* >(&rContext);
814 if(pXMLTextFrameContext_Impl)
818 // just dispose to delete
819 uno::Reference< lang::XComponent > xComp(pXMLTextFrameContext_Impl->GetPropSet(), UNO_QUERY);
821 if(xComp.is())
823 xComp->dispose();
826 catch( uno::Exception& )
828 OSL_FAIL( "Error in cleanup of multiple graphic object import (!)" );
833 OUString XMLTextFrameContext::getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const
835 OUString aRetval;
836 const XMLTextFrameContext_Impl* pXMLTextFrameContext_Impl = dynamic_cast< const XMLTextFrameContext_Impl* >(&rContext);
838 if(pXMLTextFrameContext_Impl)
840 return pXMLTextFrameContext_Impl->GetHRef();
843 return aRetval;
846 bool XMLTextFrameContext_Impl::CreateIfNotThere()
848 if( !xPropSet.is() &&
849 ( XML_TEXT_FRAME_OBJECT_OLE == nType ||
850 XML_TEXT_FRAME_GRAPHIC == nType ) &&
851 xBase64Stream.is() && !bCreateFailed )
853 if( bOwnBase64Stream )
854 xBase64Stream->closeOutput();
855 Create( true );
858 return xPropSet.is();
861 XMLTextFrameContext_Impl::XMLTextFrameContext_Impl(
862 SvXMLImport& rImport,
863 sal_uInt16 nPrfx, const OUString& rLName,
864 const Reference< XAttributeList > & rAttrList,
865 TextContentAnchorType eATyp,
866 sal_uInt16 nNewType,
867 const Reference< XAttributeList > & rFrameAttrList )
868 : SvXMLImportContext( rImport, nPrfx, rLName )
869 , mbListContextPushed( false )
870 , sWidth("Width")
871 , sWidthType("WidthType")
872 , sRelativeWidth("RelativeWidth")
873 , sHeight("Height")
874 , sRelativeHeight("RelativeHeight")
875 , sSizeType("SizeType")
876 , sIsSyncWidthToHeight("IsSyncWidthToHeight")
877 , sIsSyncHeightToWidth("IsSyncHeightToWidth")
878 , sHoriOrient("HoriOrient")
879 , sHoriOrientPosition("HoriOrientPosition")
880 , sVertOrient("VertOrient")
881 , sVertOrientPosition("VertOrientPosition")
882 , sAnchorType("AnchorType")
883 , sAnchorPageNo("AnchorPageNo")
884 , sGraphicURL("GraphicURL")
885 , sGraphicFilter("GraphicFilter")
886 , sTitle("Title")
887 , sDescription("Description")
888 , sFrameStyleName("FrameStyleName")
889 , sGraphicRotation("GraphicRotation")
890 , sTextBoxServiceName("com.sun.star.text.TextFrame")
891 , sGraphicServiceName("com.sun.star.text.GraphicObject")
892 , nType( nNewType )
893 , eAnchorType( eATyp )
895 nX = 0;
896 nY = 0;
897 nWidth = 0;
898 nHeight = 0;
899 nZIndex = -1;
900 nPage = 0;
901 nRotation = 0;
902 nRelWidth = 0;
903 nRelHeight = 0;
904 bMayScript = false;
906 bMinHeight = false;
907 bMinWidth = false;
908 bSyncWidth = false;
909 bSyncHeight = false;
910 bCreateFailed = false;
911 bOwnBase64Stream = false;
913 rtl::Reference < XMLTextImportHelper > xTxtImport =
914 GetImport().GetTextImport();
915 const SvXMLTokenMap& rTokenMap =
916 xTxtImport->GetTextFrameAttrTokenMap();
918 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
919 sal_Int16 nTotalAttrCount = nAttrCount + (rFrameAttrList.is() ? rFrameAttrList->getLength() : 0);
920 for( sal_Int16 i=0; i < nTotalAttrCount; i++ )
922 const OUString& rAttrName =
923 i < nAttrCount ? rAttrList->getNameByIndex( i ) : rFrameAttrList->getNameByIndex( i-nAttrCount );
924 const OUString& rValue =
925 i < nAttrCount ? rAttrList->getValueByIndex( i ): rFrameAttrList->getValueByIndex( i-nAttrCount );
927 OUString aLocalName;
928 sal_uInt16 nPrefix =
929 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
930 &aLocalName );
931 switch( rTokenMap.Get( nPrefix, aLocalName ) )
933 case XML_TOK_TEXT_FRAME_STYLE_NAME:
934 sStyleName = rValue;
935 break;
936 case XML_TOK_TEXT_FRAME_NAME:
937 m_sOrigName = rValue;
938 sName = rValue;
939 break;
940 case XML_TOK_TEXT_FRAME_FRAME_NAME:
941 sFrameName = rValue;
942 break;
943 case XML_TOK_TEXT_FRAME_APPLET_NAME:
944 sAppletName = rValue;
945 break;
946 case XML_TOK_TEXT_FRAME_ANCHOR_TYPE:
947 if( TextContentAnchorType_AT_PARAGRAPH == eAnchorType ||
948 TextContentAnchorType_AT_CHARACTER == eAnchorType ||
949 TextContentAnchorType_AS_CHARACTER == eAnchorType )
952 TextContentAnchorType eNew;
953 if( XMLAnchorTypePropHdl::convert( rValue, eNew ) &&
954 ( TextContentAnchorType_AT_PARAGRAPH == eNew ||
955 TextContentAnchorType_AT_CHARACTER == eNew ||
956 TextContentAnchorType_AS_CHARACTER == eNew ||
957 TextContentAnchorType_AT_PAGE == eNew) )
958 eAnchorType = eNew;
960 break;
961 case XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER:
963 sal_Int32 nTmp;
964 if (::sax::Converter::convertNumber(nTmp, rValue, 1, SHRT_MAX))
965 nPage = (sal_Int16)nTmp;
967 break;
968 case XML_TOK_TEXT_FRAME_X:
969 GetImport().GetMM100UnitConverter().convertMeasureToCore(
970 nX, rValue);
971 break;
972 case XML_TOK_TEXT_FRAME_Y:
973 GetImport().GetMM100UnitConverter().convertMeasureToCore(
974 nY, rValue );
975 break;
976 case XML_TOK_TEXT_FRAME_WIDTH:
977 // relative widths are obsolete since SRC617. Remove them some day!
978 if( rValue.indexOf( '%' ) != -1 )
980 sal_Int32 nTmp;
981 ::sax::Converter::convertPercent( nTmp, rValue );
982 nRelWidth = (sal_Int16)nTmp;
984 else
986 GetImport().GetMM100UnitConverter().convertMeasureToCore(
987 nWidth, rValue, 0 );
989 break;
990 case XML_TOK_TEXT_FRAME_REL_WIDTH:
991 if( IsXMLToken(rValue, XML_SCALE) )
993 bSyncWidth = true;
995 else
997 sal_Int32 nTmp;
998 if (::sax::Converter::convertPercent( nTmp, rValue ))
999 nRelWidth = (sal_Int16)nTmp;
1001 break;
1002 case XML_TOK_TEXT_FRAME_MIN_WIDTH:
1003 if( rValue.indexOf( '%' ) != -1 )
1005 sal_Int32 nTmp;
1006 ::sax::Converter::convertPercent( nTmp, rValue );
1007 nRelWidth = (sal_Int16)nTmp;
1009 else
1011 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1012 nWidth, rValue, 0 );
1014 bMinWidth = true;
1015 break;
1016 case XML_TOK_TEXT_FRAME_HEIGHT:
1017 // relative heights are obsolete since SRC617. Remove them some day!
1018 if( rValue.indexOf( '%' ) != -1 )
1020 sal_Int32 nTmp;
1021 ::sax::Converter::convertPercent( nTmp, rValue );
1022 nRelHeight = (sal_Int16)nTmp;
1024 else
1026 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1027 nHeight, rValue, 0 );
1029 break;
1030 case XML_TOK_TEXT_FRAME_REL_HEIGHT:
1031 if( IsXMLToken( rValue, XML_SCALE ) )
1033 bSyncHeight = true;
1035 else if( IsXMLToken( rValue, XML_SCALE_MIN ) )
1037 bSyncHeight = true;
1038 bMinHeight = true;
1040 else
1042 sal_Int32 nTmp;
1043 if (::sax::Converter::convertPercent( nTmp, rValue ))
1044 nRelHeight = (sal_Int16)nTmp;
1046 break;
1047 case XML_TOK_TEXT_FRAME_MIN_HEIGHT:
1048 if( rValue.indexOf( '%' ) != -1 )
1050 sal_Int32 nTmp;
1051 ::sax::Converter::convertPercent( nTmp, rValue );
1052 nRelHeight = (sal_Int16)nTmp;
1054 else
1056 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1057 nHeight, rValue, 0 );
1059 bMinHeight = true;
1060 break;
1061 case XML_TOK_TEXT_FRAME_Z_INDEX:
1062 ::sax::Converter::convertNumber( nZIndex, rValue, -1 );
1063 break;
1064 case XML_TOK_TEXT_FRAME_NEXT_CHAIN_NAME:
1065 sNextName = rValue;
1066 break;
1067 case XML_TOK_TEXT_FRAME_HREF:
1068 sHRef = rValue;
1069 break;
1070 case XML_TOK_TEXT_FRAME_FILTER_NAME:
1071 sFilterName = rValue;
1072 break;
1073 case XML_TOK_TEXT_FRAME_TRANSFORM:
1075 OUString sValue( rValue );
1076 sValue = sValue.trim();
1077 const OUString aRotate(GetXMLToken(XML_ROTATE));
1078 const sal_Int32 nRotateLen(aRotate.getLength());
1079 sal_Int32 nLen = sValue.getLength();
1080 if( nLen >= nRotateLen+3 &&
1081 0 == sValue.compareTo( aRotate, nRotateLen ) &&
1082 '(' == sValue[nRotateLen] &&
1083 ')' == sValue[nLen-1] )
1085 sValue = sValue.copy( nRotateLen+1, nLen-(nRotateLen+2) );
1086 sValue = sValue.trim();
1087 sal_Int32 nVal;
1088 if (::sax::Converter::convertNumber( nVal, sValue ))
1089 nRotation = (sal_Int16)(nVal % 360 );
1092 break;
1093 case XML_TOK_TEXT_FRAME_CODE:
1094 sCode = rValue;
1095 break;
1096 case XML_TOK_TEXT_FRAME_OBJECT:
1097 sObject = rValue;
1098 break;
1099 case XML_TOK_TEXT_FRAME_ARCHIVE:
1100 sArchive = rValue;
1101 break;
1102 case XML_TOK_TEXT_FRAME_MAY_SCRIPT:
1103 bMayScript = IsXMLToken( rValue, XML_TRUE );
1104 break;
1105 case XML_TOK_TEXT_FRAME_MIME_TYPE:
1106 sMimeType = rValue;
1107 break;
1108 case XML_TOK_TEXT_FRAME_NOTIFY_ON_UPDATE:
1109 sTblName = rValue;
1110 break;
1114 if( ( (XML_TEXT_FRAME_GRAPHIC == nType ||
1115 XML_TEXT_FRAME_OBJECT == nType ||
1116 XML_TEXT_FRAME_OBJECT_OLE == nType) &&
1117 sHRef.isEmpty() ) ||
1118 ( XML_TEXT_FRAME_APPLET == nType && sCode.isEmpty() ) ||
1119 ( XML_TEXT_FRAME_PLUGIN == nType &&
1120 sHRef.isEmpty() && sMimeType.isEmpty() ) )
1121 return; // no URL: no image or OLE object
1123 Create( true );
1126 XMLTextFrameContext_Impl::~XMLTextFrameContext_Impl()
1130 void XMLTextFrameContext_Impl::EndElement()
1132 CreateIfNotThere();
1134 if( xOldTextCursor.is() )
1136 GetImport().GetTextImport()->DeleteParagraph();
1137 GetImport().GetTextImport()->SetCursor( xOldTextCursor );
1140 // reinstall old list item (if necessary) #89892#
1141 if (mbListContextPushed) {
1142 GetImport().GetTextImport()->PopListContext();
1145 if (( nType == XML_TEXT_FRAME_APPLET || nType == XML_TEXT_FRAME_PLUGIN ) && xPropSet.is())
1146 GetImport().GetTextImport()->endAppletOrPlugin( xPropSet, aParamMap);
1149 SvXMLImportContext *XMLTextFrameContext_Impl::CreateChildContext(
1150 sal_uInt16 nPrefix,
1151 const OUString& rLocalName,
1152 const Reference< XAttributeList > & xAttrList )
1154 SvXMLImportContext *pContext = 0;
1156 if( XML_NAMESPACE_DRAW == nPrefix )
1158 if ( (nType == XML_TEXT_FRAME_APPLET || nType == XML_TEXT_FRAME_PLUGIN) &&
1159 IsXMLToken( rLocalName, XML_PARAM ) )
1161 pContext = new XMLTextFrameParam_Impl( GetImport(),
1162 nPrefix, rLocalName,
1163 xAttrList, nType, aParamMap );
1166 else if( (XML_NAMESPACE_OFFICE == nPrefix) )
1168 if( IsXMLToken( rLocalName, XML_BINARY_DATA ) )
1170 if( !xPropSet.is() && !xBase64Stream.is() && !bCreateFailed )
1172 switch( nType )
1174 case XML_TEXT_FRAME_GRAPHIC:
1175 xBase64Stream =
1176 GetImport().GetStreamForGraphicObjectURLFromBase64();
1177 break;
1178 case XML_TEXT_FRAME_OBJECT_OLE:
1179 xBase64Stream =
1180 GetImport().GetStreamForEmbeddedObjectURLFromBase64();
1181 break;
1183 if( xBase64Stream.is() )
1184 pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
1185 rLocalName, xAttrList,
1186 xBase64Stream );
1190 // Correction of condition which also avoids warnings. (#i100480#)
1191 if( !pContext &&
1192 ( XML_TEXT_FRAME_OBJECT == nType &&
1193 ( ( XML_NAMESPACE_OFFICE == nPrefix &&
1194 IsXMLToken( rLocalName, XML_DOCUMENT ) ) ||
1195 ( XML_NAMESPACE_MATH == nPrefix &&
1196 IsXMLToken( rLocalName, XML_MATH ) ) ) ) )
1198 if( !xPropSet.is() && !bCreateFailed )
1200 XMLEmbeddedObjectImportContext *pEContext =
1201 new XMLEmbeddedObjectImportContext( GetImport(), nPrefix,
1202 rLocalName, xAttrList );
1203 sFilterService = pEContext->GetFilterServiceName();
1204 if( !sFilterService.isEmpty() )
1206 Create( false );
1207 if( xPropSet.is() )
1209 Reference < XEmbeddedObjectSupplier > xEOS( xPropSet,
1210 UNO_QUERY );
1211 OSL_ENSURE( xEOS.is(),
1212 "no embedded object supplier for own object" );
1213 Reference<com::sun::star::lang::XComponent> aXComponent(xEOS->getEmbeddedObject());
1214 pEContext->SetComponent( aXComponent );
1217 pContext = pEContext;
1220 if( !pContext && xOldTextCursor.is() ) // text-box
1221 pContext = GetImport().GetTextImport()->CreateTextChildContext(
1222 GetImport(), nPrefix, rLocalName, xAttrList,
1223 XML_TEXT_TYPE_TEXTBOX );
1225 if( !pContext )
1226 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1228 return pContext;
1231 void XMLTextFrameContext_Impl::Characters( const OUString& rChars )
1233 if( ( XML_TEXT_FRAME_OBJECT_OLE == nType ||
1234 XML_TEXT_FRAME_GRAPHIC == nType) &&
1235 !xPropSet.is() && !bCreateFailed )
1237 OUString sTrimmedChars( rChars. trim() );
1238 if( !sTrimmedChars.isEmpty() )
1240 if( !xBase64Stream.is() )
1242 if( XML_TEXT_FRAME_GRAPHIC == nType )
1244 xBase64Stream =
1245 GetImport().GetStreamForGraphicObjectURLFromBase64();
1247 else
1249 xBase64Stream =
1250 GetImport().GetStreamForEmbeddedObjectURLFromBase64();
1252 if( xBase64Stream.is() )
1253 bOwnBase64Stream = true;
1255 if( bOwnBase64Stream && xBase64Stream.is() )
1257 OUString sChars;
1258 if( !sBase64CharsLeft.isEmpty() )
1260 sChars = sBase64CharsLeft;
1261 sChars += sTrimmedChars;
1262 sBase64CharsLeft.clear();
1264 else
1266 sChars = sTrimmedChars;
1268 Sequence< sal_Int8 > aBuffer( (sChars.getLength() / 4) * 3 );
1269 sal_Int32 nCharsDecoded =
1270 ::sax::Converter::decodeBase64SomeChars( aBuffer, sChars );
1271 xBase64Stream->writeBytes( aBuffer );
1272 if( nCharsDecoded != sChars.getLength() )
1273 sBase64CharsLeft = sChars.copy( nCharsDecoded );
1279 void XMLTextFrameContext_Impl::SetHyperlink( const OUString& rHRef,
1280 const OUString& rName,
1281 const OUString& rTargetFrameName,
1282 bool bMap )
1284 static const char s_HyperLinkURL[] = "HyperLinkURL";
1285 static const char s_HyperLinkName[] = "HyperLinkName";
1286 static const char s_HyperLinkTarget[] = "HyperLinkTarget";
1287 static const char s_ServerMap[] = "ServerMap";
1288 if( !xPropSet.is() )
1289 return;
1291 rtl::Reference< XMLTextImportHelper > xTxtImp = GetImport().GetTextImport();
1292 Reference < XPropertySetInfo > xPropSetInfo =
1293 xPropSet->getPropertySetInfo();
1294 if( !xPropSetInfo.is() ||
1295 !xPropSetInfo->hasPropertyByName(s_HyperLinkURL))
1296 return;
1298 Any aAny;
1299 aAny <<= rHRef;
1300 xPropSet->setPropertyValue( s_HyperLinkURL, aAny );
1302 if (xPropSetInfo->hasPropertyByName(s_HyperLinkName))
1304 aAny <<= rName;
1305 xPropSet->setPropertyValue(s_HyperLinkName, aAny);
1308 if (xPropSetInfo->hasPropertyByName(s_HyperLinkTarget))
1310 aAny <<= rTargetFrameName;
1311 xPropSet->setPropertyValue( s_HyperLinkTarget, aAny );
1314 if (xPropSetInfo->hasPropertyByName(s_ServerMap))
1316 aAny.setValue( &bMap, cppu::UnoType<bool>::get() );
1317 xPropSet->setPropertyValue(s_ServerMap, aAny);
1321 void XMLTextFrameContext_Impl::SetName()
1323 Reference<XNamed> xNamed(xPropSet, UNO_QUERY);
1324 if (!m_sOrigName.isEmpty() && xNamed.is())
1326 OUString const name(xNamed->getName());
1327 if (name != m_sOrigName)
1331 xNamed->setName(m_sOrigName);
1333 catch (uno::Exception const& e)
1334 { // fdo#71698 document contains 2 frames with same draw:name
1335 SAL_INFO("xmloff.text", "SetName(): exception setting \""
1336 << m_sOrigName << "\": " << e.Message);
1342 // Implement Title/Description Elements UI (#i73249#)
1343 void XMLTextFrameContext_Impl::SetTitle( const OUString& rTitle )
1345 if ( xPropSet.is() )
1347 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1348 if( xPropSetInfo->hasPropertyByName( sTitle ) )
1350 xPropSet->setPropertyValue( sTitle, makeAny( rTitle ) );
1355 void XMLTextFrameContext_Impl::SetDesc( const OUString& rDesc )
1357 if ( xPropSet.is() )
1359 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1360 if( xPropSetInfo->hasPropertyByName( sDescription ) )
1362 xPropSet->setPropertyValue( sDescription, makeAny( rDesc ) );
1367 TYPEINIT1( XMLTextFrameContext, SvXMLImportContext );
1369 bool XMLTextFrameContext::CreateIfNotThere( ::com::sun::star::uno::Reference <
1370 ::com::sun::star::beans::XPropertySet >& rPropSet )
1372 SvXMLImportContext *pContext = &m_xImplContext;
1373 XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1374 if( pImpl )
1376 if( pImpl->CreateIfNotThere() )
1377 rPropSet = pImpl->GetPropSet();
1380 return rPropSet.is();
1383 XMLTextFrameContext::XMLTextFrameContext(
1384 SvXMLImport& rImport,
1385 sal_uInt16 nPrfx, const OUString& rLName,
1386 const Reference< XAttributeList > & xAttrList,
1387 TextContentAnchorType eATyp )
1388 : SvXMLImportContext( rImport, nPrfx, rLName )
1389 , MultiImageImportHelper()
1390 , m_xAttrList( new SvXMLAttributeList( xAttrList ) )
1391 , m_pHyperlink( 0 )
1392 // Implement Title/Description Elements UI (#i73249#)
1393 , m_sTitle()
1394 , m_sDesc()
1395 , m_eDefaultAnchorType( eATyp )
1396 // Shapes in Writer cannot be named via context menu (#i51726#)
1397 , m_HasAutomaticStyleWithoutParentStyle( false )
1398 , m_bSupportsReplacement( false )
1400 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1401 for( sal_Int16 i=0; i < nAttrCount; i++ )
1403 const OUString& rAttrName = xAttrList->getNameByIndex( i );
1405 OUString aLocalName;
1406 sal_uInt16 nPrefix =
1407 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
1408 // New distinguish attribute between Writer objects and Draw objects is:
1409 // Draw objects have an automatic style without a parent style (#i51726#)
1410 if ( XML_NAMESPACE_DRAW == nPrefix &&
1411 IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1413 OUString aStyleName = xAttrList->getValueByIndex( i );
1414 if( !aStyleName.isEmpty() )
1416 rtl::Reference < XMLTextImportHelper > xTxtImport =
1417 GetImport().GetTextImport();
1418 XMLPropStyleContext* pStyle( 0L );
1419 pStyle = xTxtImport->FindAutoFrameStyle( aStyleName );
1420 if ( pStyle && pStyle->GetParentName().isEmpty() )
1422 m_HasAutomaticStyleWithoutParentStyle = true;
1426 else if ( XML_NAMESPACE_TEXT == nPrefix &&
1427 IsXMLToken( aLocalName, XML_ANCHOR_TYPE ) )
1429 TextContentAnchorType eNew;
1430 if( XMLAnchorTypePropHdl::convert( xAttrList->getValueByIndex(i),
1431 eNew ) &&
1432 ( TextContentAnchorType_AT_PARAGRAPH == eNew ||
1433 TextContentAnchorType_AT_CHARACTER == eNew ||
1434 TextContentAnchorType_AS_CHARACTER == eNew ||
1435 TextContentAnchorType_AT_PAGE == eNew) )
1436 m_eDefaultAnchorType = eNew;
1441 XMLTextFrameContext::~XMLTextFrameContext()
1443 delete m_pHyperlink;
1446 void XMLTextFrameContext::EndElement()
1448 /// solve if multiple image child contexts were imported
1449 SvXMLImportContextRef const pMultiContext(solveMultipleImages());
1451 SvXMLImportContext const*const pContext =
1452 (pMultiContext) ? &pMultiContext : &m_xImplContext;
1453 XMLTextFrameContext_Impl *pImpl = const_cast<XMLTextFrameContext_Impl*>(PTR_CAST( XMLTextFrameContext_Impl, pContext ));
1454 assert(!pMultiContext || pImpl);
1455 if( pImpl )
1457 pImpl->CreateIfNotThere();
1459 // fdo#68839: in case the surviving image was not the first one,
1460 // it will have a counter added to its name - set the original name
1461 if (pMultiContext) // do this only when necessary; esp. not for text
1462 { // frames that may have entries in GetRenameMap()!
1463 pImpl->SetName();
1466 if( !m_sTitle.isEmpty() )
1468 pImpl->SetTitle( m_sTitle );
1470 if( !m_sDesc.isEmpty() )
1472 pImpl->SetDesc( m_sDesc );
1475 if( m_pHyperlink )
1477 pImpl->SetHyperlink( m_pHyperlink->GetHRef(), m_pHyperlink->GetName(),
1478 m_pHyperlink->GetTargetFrameName(), m_pHyperlink->GetMap() );
1479 delete m_pHyperlink;
1480 m_pHyperlink = 0;
1486 SvXMLImportContext *XMLTextFrameContext::CreateChildContext(
1487 sal_uInt16 p_nPrefix,
1488 const OUString& rLocalName,
1489 const Reference< XAttributeList > & xAttrList )
1491 SvXMLImportContext *pContext = 0;
1493 if( !m_xImplContext.Is() )
1495 // no child exists
1496 if( XML_NAMESPACE_DRAW == p_nPrefix )
1498 sal_uInt16 nFrameType = USHRT_MAX;
1499 if( IsXMLToken( rLocalName, XML_TEXT_BOX ) )
1500 nFrameType = XML_TEXT_FRAME_TEXTBOX;
1501 else if( IsXMLToken( rLocalName, XML_IMAGE ) )
1502 nFrameType = XML_TEXT_FRAME_GRAPHIC;
1503 else if( IsXMLToken( rLocalName, XML_OBJECT ) )
1504 nFrameType = XML_TEXT_FRAME_OBJECT;
1505 else if( IsXMLToken( rLocalName, XML_OBJECT_OLE ) )
1506 nFrameType = XML_TEXT_FRAME_OBJECT_OLE;
1507 else if( IsXMLToken( rLocalName, XML_APPLET) )
1508 nFrameType = XML_TEXT_FRAME_APPLET;
1509 else if( IsXMLToken( rLocalName, XML_PLUGIN ) )
1510 nFrameType = XML_TEXT_FRAME_PLUGIN;
1511 else if( IsXMLToken( rLocalName, XML_FLOATING_FRAME ) )
1512 nFrameType = XML_TEXT_FRAME_FLOATING_FRAME;
1514 if( USHRT_MAX != nFrameType )
1516 // Shapes in Writer cannot be named via context menu (#i51726#)
1517 if ( ( XML_TEXT_FRAME_TEXTBOX == nFrameType ||
1518 XML_TEXT_FRAME_GRAPHIC == nFrameType ) &&
1519 m_HasAutomaticStyleWithoutParentStyle )
1521 Reference < XShapes > xShapes;
1522 pContext = GetImport().GetShapeImport()->CreateFrameChildContext(
1523 GetImport(), p_nPrefix, rLocalName, xAttrList, xShapes, m_xAttrList );
1525 else if( XML_TEXT_FRAME_PLUGIN == nFrameType )
1527 bool bMedia = false;
1529 // check, if we have a media object
1530 for( sal_Int16 n = 0, nAttrCount = ( xAttrList.is() ? xAttrList->getLength() : 0 ); n < nAttrCount; ++n )
1532 OUString aLocalName;
1533 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( n ), &aLocalName );
1535 if( nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( aLocalName, XML_MIME_TYPE ) )
1537 if( xAttrList->getValueByIndex( n ) == "application/vnd.sun.star.media" )
1538 bMedia = true;
1540 // leave this loop
1541 n = nAttrCount - 1;
1545 if( bMedia )
1547 Reference < XShapes > xShapes;
1548 pContext = GetImport().GetShapeImport()->CreateFrameChildContext(
1549 GetImport(), p_nPrefix, rLocalName, xAttrList, xShapes, m_xAttrList );
1552 else if( XML_TEXT_FRAME_OBJECT == nFrameType ||
1553 XML_TEXT_FRAME_OBJECT_OLE == nFrameType )
1555 m_bSupportsReplacement = true;
1557 else if(XML_TEXT_FRAME_GRAPHIC == nFrameType)
1559 setSupportsMultipleContents(IsXMLToken(rLocalName, XML_IMAGE));
1562 if( !pContext )
1565 pContext = new XMLTextFrameContext_Impl( GetImport(), p_nPrefix,
1566 rLocalName, xAttrList,
1567 m_eDefaultAnchorType,
1568 nFrameType,
1569 m_xAttrList );
1572 m_xImplContext = pContext;
1574 if(getSupportsMultipleContents() && XML_TEXT_FRAME_GRAPHIC == nFrameType)
1576 addContent(*m_xImplContext);
1581 else if(getSupportsMultipleContents() && XML_NAMESPACE_DRAW == p_nPrefix && IsXMLToken(rLocalName, XML_IMAGE))
1583 // read another image
1584 pContext = new XMLTextFrameContext_Impl(
1585 GetImport(), p_nPrefix, rLocalName, xAttrList,
1586 m_eDefaultAnchorType, XML_TEXT_FRAME_GRAPHIC, m_xAttrList);
1588 m_xImplContext = pContext;
1589 addContent(*m_xImplContext);
1591 else if( m_bSupportsReplacement && !m_xReplImplContext &&
1592 XML_NAMESPACE_DRAW == p_nPrefix &&
1593 IsXMLToken( rLocalName, XML_IMAGE ) )
1595 // read replacement image
1596 Reference < XPropertySet > xPropSet;
1597 if( CreateIfNotThere( xPropSet ) )
1599 pContext = new XMLReplacementImageContext( GetImport(),
1600 p_nPrefix, rLocalName, xAttrList, xPropSet );
1601 m_xReplImplContext = pContext;
1604 else if( m_xImplContext->ISA( XMLTextFrameContext_Impl ) )
1606 // the child is a writer frame
1607 if( XML_NAMESPACE_SVG == p_nPrefix )
1609 // Implement Title/Description Elements UI (#i73249#)
1610 const bool bOld = SvXMLImport::OOo_2x >= GetImport().getGeneratorVersion();
1611 if ( bOld )
1613 if ( IsXMLToken( rLocalName, XML_DESC ) )
1615 pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
1616 p_nPrefix,
1617 rLocalName,
1618 m_sTitle );
1621 else
1623 if( IsXMLToken( rLocalName, XML_TITLE ) )
1625 pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
1626 p_nPrefix,
1627 rLocalName,
1628 m_sTitle );
1630 else if ( IsXMLToken( rLocalName, XML_DESC ) )
1632 pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
1633 p_nPrefix,
1634 rLocalName,
1635 m_sDesc );
1639 else if( XML_NAMESPACE_DRAW == p_nPrefix )
1641 Reference < XPropertySet > xPropSet;
1642 if( IsXMLToken( rLocalName, XML_CONTOUR_POLYGON ) )
1644 if( CreateIfNotThere( xPropSet ) )
1645 pContext = new XMLTextFrameContourContext_Impl( GetImport(), p_nPrefix, rLocalName,
1646 xAttrList, xPropSet, false );
1648 else if( IsXMLToken( rLocalName, XML_CONTOUR_PATH ) )
1650 if( CreateIfNotThere( xPropSet ) )
1651 pContext = new XMLTextFrameContourContext_Impl( GetImport(), p_nPrefix, rLocalName,
1652 xAttrList, xPropSet, true );
1654 else if( IsXMLToken( rLocalName, XML_IMAGE_MAP ) )
1656 if( CreateIfNotThere( xPropSet ) )
1657 pContext = new XMLImageMapContext( GetImport(), p_nPrefix, rLocalName, xPropSet );
1660 else if( (XML_NAMESPACE_OFFICE == p_nPrefix) && IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
1662 // do we still have the frame object?
1663 Reference < XPropertySet > xPropSet;
1664 if( CreateIfNotThere( xPropSet ) )
1666 // is it an event supplier?
1667 Reference<XEventsSupplier> xEventsSupplier(xPropSet, UNO_QUERY);
1668 if (xEventsSupplier.is())
1670 // OK, we have the events, so create the context
1671 pContext = new XMLEventsImportContext(GetImport(), p_nPrefix,
1672 rLocalName, xEventsSupplier);
1677 else if( p_nPrefix == XML_NAMESPACE_SVG && // #i68101#
1678 (IsXMLToken( rLocalName, XML_TITLE ) || IsXMLToken( rLocalName, XML_DESC ) ) )
1680 pContext = m_xImplContext->CreateChildContext( p_nPrefix, rLocalName, xAttrList );
1682 else
1684 // the child is a drawing shape
1685 pContext = XMLShapeImportHelper::CreateFrameChildContext(
1686 &m_xImplContext, p_nPrefix, rLocalName, xAttrList );
1689 if( !pContext )
1690 pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
1692 return pContext;
1695 void XMLTextFrameContext::SetHyperlink( const OUString& rHRef,
1696 const OUString& rName,
1697 const OUString& rTargetFrameName,
1698 bool bMap )
1700 OSL_ENSURE( !m_pHyperlink, "recursive SetHyperlink call" );
1701 delete m_pHyperlink;
1702 m_pHyperlink = new XMLTextFrameContextHyperlink_Impl(
1703 rHRef, rName, rTargetFrameName, bMap );
1706 TextContentAnchorType XMLTextFrameContext::GetAnchorType() const
1708 SvXMLImportContext *pContext = &m_xImplContext;
1709 XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1710 if( pImpl )
1711 return pImpl->GetAnchorType();
1712 else
1713 return m_eDefaultAnchorType;
1716 Reference < XTextContent > XMLTextFrameContext::GetTextContent() const
1718 Reference < XTextContent > xTxtCntnt;
1719 SvXMLImportContext *pContext = &m_xImplContext;
1720 XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1721 if( pImpl )
1722 xTxtCntnt.set( pImpl->GetPropSet(), UNO_QUERY );
1724 return xTxtCntnt;
1727 Reference < XShape > XMLTextFrameContext::GetShape() const
1729 Reference < XShape > xShape;
1730 SvXMLImportContext* pContext = &m_xImplContext;
1731 SvXMLShapeContext* pImpl = PTR_CAST( SvXMLShapeContext, pContext );
1732 if ( pImpl )
1734 xShape = pImpl->getShape();
1737 return xShape;
1740 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */