1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
86 OUString sTargetFrameName
;
91 inline XMLTextFrameContextHyperlink_Impl( const OUString
& rHRef
,
92 const OUString
& rName
,
93 const OUString
& rTargetFrameName
,
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
) :
107 sTargetFrameName( rTargetFrameName
),
112 // Implement Title/Description Elements UI (#i73249#)
113 class XMLTextFrameTitleOrDescContext_Impl
: public SvXMLImportContext
115 OUString
& mrTitleOrDesc
;
121 XMLTextFrameTitleOrDescContext_Impl( SvXMLImport
& rImport
,
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
,
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
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
,
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
);
190 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
, &aLocalName
);
191 if ( XML_NAMESPACE_DRAW
== nPrefix
)
193 if( IsXMLToken(aLocalName
, XML_VALUE
) )
198 else if( IsXMLToken(aLocalName
, XML_NAME
) )
204 if (!sName
.isEmpty() && bFoundValue
)
205 rParamMap
[sName
] = sValue
;
207 class XMLTextFrameContourContext_Impl
: public SvXMLImportContext
209 Reference
< XPropertySet
> xPropSet
;
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
,
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
,
232 SvXMLImportContext( rImport
, nPrfx
, rLName
),
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
);
252 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
254 switch( rTokenMap
.Get( nPrefix
, aLocalName
) )
256 case XML_TOK_TEXT_CONTOUR_VIEWBOX
:
259 case XML_TOK_TEXT_CONTOUR_D
:
263 case XML_TOK_TEXT_CONTOUR_POINTS
:
267 case XML_TOK_TEXT_CONTOUR_WIDTH
:
268 if (::sax::Converter::convertMeasurePx(nWidth
, rValue
))
271 GetImport().GetMM100UnitConverter().convertMeasureToCore(
274 case XML_TOK_TEXT_CONTOUR_HEIGHT
:
275 if (::sax::Converter::convertMeasurePx(nHeight
, rValue
))
278 GetImport().GetMM100UnitConverter().convertMeasureToCore(
281 case XML_TOK_TEXT_CONTOUR_AUTO
:
282 bAuto
= IsXMLToken(rValue
, XML_TRUE
);
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
;
298 basegfx::tools::importFromSvgD(aPolyPolygon
, sD
, GetImport().needFixPositionAfterZ(), 0);
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(
319 if(!aSourceRange
.equal(aTargetRange
))
321 aPolyPolygon
.transform(
322 basegfx::tools::createSourceRangeTargetRangeTransform(
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
;
395 OUString sFilterName
;
401 OUString sAppletName
;
402 OUString sFilterService
;
403 OUString sBase64CharsLeft
;
416 sal_Int16 nRelHeight
;
419 ::com::sun::star::text::TextContentAnchorType eAnchorType
;
425 bool bSyncHeight
: 1;
426 bool bCreateFailed
: 1;
427 bool bOwnBase64Stream
: 1;
429 void Create( bool bHRefOrBase64
);
435 bool CreateIfNotThere();
436 const OUString
& GetHRef() const { return sHRef
; }
438 XMLTextFrameContext_Impl( SvXMLImport
& rImport
,
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
,
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
,
463 // Implement Title/Description Elements UI (#i73249#)
464 void SetTitle( const OUString
& rTitle
);
466 void SetDesc( const OUString
& rDesc
);
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();
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
,
497 else if( !sHRef
.isEmpty() )
499 OUString
sURL( GetImport().ResolveEmbeddedObjectURL( sHRef
,
502 if( GetImport().IsPackageURL( sHRef
) )
504 xPropSet
= GetImport().GetTextImport()
505 ->createAndInsertOLEObject( GetImport(), sURL
,
512 // it should be an own OOo link that has no storage persistence
513 xPropSet
= GetImport().GetTextImport()
514 ->createAndInsertOOoLink( GetImport(),
523 OUString
sURL( "vnd.sun.star.ServiceName:" );
524 sURL
+= sFilterService
;
525 xPropSet
= GetImport().GetTextImport()
526 ->createAndInsertOLEObject( GetImport(), sURL
,
533 case XML_TEXT_FRAME_APPLET
:
535 xPropSet
= GetImport().GetTextImport()
536 ->createAndInsertApplet( sAppletName
, sCode
,
541 case XML_TEXT_FRAME_PLUGIN
:
544 GetImport().GetAbsoluteReference(sHRef
);
545 xPropSet
= GetImport().GetTextImport()
546 ->createAndInsertPlugin( sMimeType
, sHRef
,
551 case XML_TEXT_FRAME_FLOATING_FRAME
:
553 xPropSet
= GetImport().GetTextImport()
554 ->createAndInsertFloatingFrame( sFrameName
, sHRef
,
561 Reference
<XMultiServiceFactory
> xFactory( GetImport().GetModel(),
565 OUString sServiceName
;
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" );
574 xPropSet
= Reference
< XPropertySet
>( xIfc
, UNO_QUERY
);
581 bCreateFailed
= true;
585 Reference
< XPropertySetInfo
> xPropSetInfo
= xPropSet
->getPropertySetInfo();
588 Reference
< XNamed
> xNamed( xPropSet
, UNO_QUERY
);
591 OUString
sOrigName( xNamed
->getName() );
592 if( sOrigName
.isEmpty() ||
593 (!sName
.isEmpty() && sOrigName
!= sName
) )
595 OUString
sOldName( sName
);
598 while( xTextImportHelper
->HasFrameByName( sName
) )
601 sName
+= OUString::number( ++i
);
603 xNamed
->setName( sName
);
604 if( sName
!= sOldName
)
606 bool bSuccess
= xTextImportHelper
->GetRenameMap().Add( XML_TEXT_RENAME_TYPE_FRAME
,
608 if (!bSuccess
&& GetImport().getGeneratorVersion() == SvXMLImport::LO_44x
)
610 bCreateFailed
= true;
618 XMLPropStyleContext
*pStyle
= 0;
619 if( !sStyleName
.isEmpty() )
621 pStyle
= xTextImportHelper
->FindAutoFrameStyle( sStyleName
);
623 sStyleName
= pStyle
->GetParentName();
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();
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
644 aAny
<<= eAnchorType
;
645 xPropSet
->setPropertyValue( sAnchorType
, aAny
);
649 pStyle
->FillPropertySet( xPropSet
);
652 sal_Int16 nHoriOrient
= HoriOrientation::NONE
;
653 aAny
= xPropSet
->getPropertyValue( sHoriOrient
);
654 aAny
>>= nHoriOrient
;
655 if( HoriOrientation::NONE
== nHoriOrient
)
658 xPropSet
->setPropertyValue( sHoriOrientPosition
, aAny
);
661 sal_Int16 nVertOrient
= VertOrientation::NONE
;
662 aAny
= xPropSet
->getPropertyValue( sVertOrient
);
663 aAny
>>= nVertOrient
;
664 if( VertOrientation::NONE
== nVertOrient
)
667 xPropSet
->setPropertyValue( sVertOrientPosition
, aAny
);
674 xPropSet
->setPropertyValue( sWidth
, aAny
);
676 if( nRelWidth
> 0 || nWidth
> 0 )
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
694 xPropSet
->setPropertyValue( sWidthType
, aAny
);
700 xPropSet
->setPropertyValue( sHeight
, aAny
);
702 if( nRelHeight
> 0 || nHeight
> 0 )
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
720 xPropSet
->setPropertyValue( sSizeType
, aAny
);
723 if( XML_TEXT_FRAME_GRAPHIC
== nType
)
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
);
744 xPropSet
->setPropertyValue( sGraphicURL
, aAny
);
748 xPropSet
->setPropertyValue( sGraphicFilter
, aAny
);
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 )
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
);
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
);
826 catch( uno::Exception
& )
828 OSL_FAIL( "Error in cleanup of multiple graphic object import (!)" );
833 OUString
XMLTextFrameContext::getGraphicURLFromImportContext(const SvXMLImportContext
& rContext
) const
836 const XMLTextFrameContext_Impl
* pXMLTextFrameContext_Impl
= dynamic_cast< const XMLTextFrameContext_Impl
* >(&rContext
);
838 if(pXMLTextFrameContext_Impl
)
840 return pXMLTextFrameContext_Impl
->GetHRef();
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();
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
,
867 const Reference
< XAttributeList
> & rFrameAttrList
)
868 : SvXMLImportContext( rImport
, nPrfx
, rLName
)
869 , mbListContextPushed( false )
871 , sWidthType("WidthType")
872 , sRelativeWidth("RelativeWidth")
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")
887 , sDescription("Description")
888 , sFrameStyleName("FrameStyleName")
889 , sGraphicRotation("GraphicRotation")
890 , sTextBoxServiceName("com.sun.star.text.TextFrame")
891 , sGraphicServiceName("com.sun.star.text.GraphicObject")
893 , eAnchorType( eATyp
)
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
);
929 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName
,
931 switch( rTokenMap
.Get( nPrefix
, aLocalName
) )
933 case XML_TOK_TEXT_FRAME_STYLE_NAME
:
936 case XML_TOK_TEXT_FRAME_NAME
:
937 m_sOrigName
= rValue
;
940 case XML_TOK_TEXT_FRAME_FRAME_NAME
:
943 case XML_TOK_TEXT_FRAME_APPLET_NAME
:
944 sAppletName
= rValue
;
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
) )
961 case XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER
:
964 if (::sax::Converter::convertNumber(nTmp
, rValue
, 1, SHRT_MAX
))
965 nPage
= (sal_Int16
)nTmp
;
968 case XML_TOK_TEXT_FRAME_X
:
969 GetImport().GetMM100UnitConverter().convertMeasureToCore(
972 case XML_TOK_TEXT_FRAME_Y
:
973 GetImport().GetMM100UnitConverter().convertMeasureToCore(
976 case XML_TOK_TEXT_FRAME_WIDTH
:
977 // relative widths are obsolete since SRC617. Remove them some day!
978 if( rValue
.indexOf( '%' ) != -1 )
981 ::sax::Converter::convertPercent( nTmp
, rValue
);
982 nRelWidth
= (sal_Int16
)nTmp
;
986 GetImport().GetMM100UnitConverter().convertMeasureToCore(
990 case XML_TOK_TEXT_FRAME_REL_WIDTH
:
991 if( IsXMLToken(rValue
, XML_SCALE
) )
998 if (::sax::Converter::convertPercent( nTmp
, rValue
))
999 nRelWidth
= (sal_Int16
)nTmp
;
1002 case XML_TOK_TEXT_FRAME_MIN_WIDTH
:
1003 if( rValue
.indexOf( '%' ) != -1 )
1006 ::sax::Converter::convertPercent( nTmp
, rValue
);
1007 nRelWidth
= (sal_Int16
)nTmp
;
1011 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1012 nWidth
, rValue
, 0 );
1016 case XML_TOK_TEXT_FRAME_HEIGHT
:
1017 // relative heights are obsolete since SRC617. Remove them some day!
1018 if( rValue
.indexOf( '%' ) != -1 )
1021 ::sax::Converter::convertPercent( nTmp
, rValue
);
1022 nRelHeight
= (sal_Int16
)nTmp
;
1026 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1027 nHeight
, rValue
, 0 );
1030 case XML_TOK_TEXT_FRAME_REL_HEIGHT
:
1031 if( IsXMLToken( rValue
, XML_SCALE
) )
1035 else if( IsXMLToken( rValue
, XML_SCALE_MIN
) )
1043 if (::sax::Converter::convertPercent( nTmp
, rValue
))
1044 nRelHeight
= (sal_Int16
)nTmp
;
1047 case XML_TOK_TEXT_FRAME_MIN_HEIGHT
:
1048 if( rValue
.indexOf( '%' ) != -1 )
1051 ::sax::Converter::convertPercent( nTmp
, rValue
);
1052 nRelHeight
= (sal_Int16
)nTmp
;
1056 GetImport().GetMM100UnitConverter().convertMeasureToCore(
1057 nHeight
, rValue
, 0 );
1061 case XML_TOK_TEXT_FRAME_Z_INDEX
:
1062 ::sax::Converter::convertNumber( nZIndex
, rValue
, -1 );
1064 case XML_TOK_TEXT_FRAME_NEXT_CHAIN_NAME
:
1067 case XML_TOK_TEXT_FRAME_HREF
:
1070 case XML_TOK_TEXT_FRAME_FILTER_NAME
:
1071 sFilterName
= rValue
;
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();
1088 if (::sax::Converter::convertNumber( nVal
, sValue
))
1089 nRotation
= (sal_Int16
)(nVal
% 360 );
1093 case XML_TOK_TEXT_FRAME_CODE
:
1096 case XML_TOK_TEXT_FRAME_OBJECT
:
1099 case XML_TOK_TEXT_FRAME_ARCHIVE
:
1102 case XML_TOK_TEXT_FRAME_MAY_SCRIPT
:
1103 bMayScript
= IsXMLToken( rValue
, XML_TRUE
);
1105 case XML_TOK_TEXT_FRAME_MIME_TYPE
:
1108 case XML_TOK_TEXT_FRAME_NOTIFY_ON_UPDATE
:
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
1126 XMLTextFrameContext_Impl::~XMLTextFrameContext_Impl()
1130 void XMLTextFrameContext_Impl::EndElement()
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(
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
)
1174 case XML_TEXT_FRAME_GRAPHIC
:
1176 GetImport().GetStreamForGraphicObjectURLFromBase64();
1178 case XML_TEXT_FRAME_OBJECT_OLE
:
1180 GetImport().GetStreamForEmbeddedObjectURLFromBase64();
1183 if( xBase64Stream
.is() )
1184 pContext
= new XMLBase64ImportContext( GetImport(), nPrefix
,
1185 rLocalName
, xAttrList
,
1190 // Correction of condition which also avoids warnings. (#i100480#)
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() )
1209 Reference
< XEmbeddedObjectSupplier
> xEOS( xPropSet
,
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
);
1226 pContext
= new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
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
)
1245 GetImport().GetStreamForGraphicObjectURLFromBase64();
1250 GetImport().GetStreamForEmbeddedObjectURLFromBase64();
1252 if( xBase64Stream
.is() )
1253 bOwnBase64Stream
= true;
1255 if( bOwnBase64Stream
&& xBase64Stream
.is() )
1258 if( !sBase64CharsLeft
.isEmpty() )
1260 sChars
= sBase64CharsLeft
;
1261 sChars
+= sTrimmedChars
;
1262 sBase64CharsLeft
.clear();
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
,
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() )
1291 rtl::Reference
< XMLTextImportHelper
> xTxtImp
= GetImport().GetTextImport();
1292 Reference
< XPropertySetInfo
> xPropSetInfo
=
1293 xPropSet
->getPropertySetInfo();
1294 if( !xPropSetInfo
.is() ||
1295 !xPropSetInfo
->hasPropertyByName(s_HyperLinkURL
))
1300 xPropSet
->setPropertyValue( s_HyperLinkURL
, aAny
);
1302 if (xPropSetInfo
->hasPropertyByName(s_HyperLinkName
))
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
);
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
) )
1392 // Implement Title/Description Elements UI (#i73249#)
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
),
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
);
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()!
1466 if( !m_sTitle
.isEmpty() )
1468 pImpl
->SetTitle( m_sTitle
);
1470 if( !m_sDesc
.isEmpty() )
1472 pImpl
->SetDesc( m_sDesc
);
1477 pImpl
->SetHyperlink( m_pHyperlink
->GetHRef(), m_pHyperlink
->GetName(),
1478 m_pHyperlink
->GetTargetFrameName(), m_pHyperlink
->GetMap() );
1479 delete m_pHyperlink
;
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() )
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" )
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
));
1565 pContext
= new XMLTextFrameContext_Impl( GetImport(), p_nPrefix
,
1566 rLocalName
, xAttrList
,
1567 m_eDefaultAnchorType
,
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();
1613 if ( IsXMLToken( rLocalName
, XML_DESC
) )
1615 pContext
= new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
1623 if( IsXMLToken( rLocalName
, XML_TITLE
) )
1625 pContext
= new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
1630 else if ( IsXMLToken( rLocalName
, XML_DESC
) )
1632 pContext
= new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
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
);
1684 // the child is a drawing shape
1685 pContext
= XMLShapeImportHelper::CreateFrameChildContext(
1686 &m_xImplContext
, p_nPrefix
, rLocalName
, xAttrList
);
1690 pContext
= new SvXMLImportContext( GetImport(), p_nPrefix
, rLocalName
);
1695 void XMLTextFrameContext::SetHyperlink( const OUString
& rHRef
,
1696 const OUString
& rName
,
1697 const OUString
& rTargetFrameName
,
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
);
1711 return pImpl
->GetAnchorType();
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
);
1722 xTxtCntnt
.set( pImpl
->GetPropSet(), UNO_QUERY
);
1727 Reference
< XShape
> XMLTextFrameContext::GetShape() const
1729 Reference
< XShape
> xShape
;
1730 SvXMLImportContext
* pContext
= &m_xImplContext
;
1731 SvXMLShapeContext
* pImpl
= PTR_CAST( SvXMLShapeContext
, pContext
);
1734 xShape
= pImpl
->getShape();
1740 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */