update dev300-m58
[ooovba.git] / xmloff / source / text / XMLTextFrameContext.cxx
blob14776996b70bd3e1facde886cbdf67ed00c0aac2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLTextFrameContext.cxx,v $
10 * $Revision: 1.75.34.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <tools/debug.hxx>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/text/TextContentAnchorType.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/text/XTextFrame.hpp>
38 #include <com/sun/star/container/XNamed.hpp>
39 #include <com/sun/star/text/SizeType.hpp>
40 #include <com/sun/star/drawing/XShape.hpp>
41 #include <com/sun/star/document/XEventsSupplier.hpp>
42 #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
43 #include <com/sun/star/io/XOutputStream.hpp>
44 #include <com/sun/star/text/HoriOrientation.hpp>
45 #include <com/sun/star/text/VertOrientation.hpp>
46 #include <xmloff/xmlimp.hxx>
47 #include <xmloff/xmltoken.hxx>
48 #include "xmlnmspe.hxx"
49 #include "xmlkywd.hxx"
50 #include <xmloff/nmspmap.hxx>
51 #include <xmloff/xmluconv.hxx>
52 #include "XMLAnchorTypePropHdl.hxx"
53 #include "XMLEmbeddedObjectImportContext.hxx"
54 #include <xmloff/XMLBase64ImportContext.hxx>
55 #include "XMLReplacementImageContext.hxx"
56 #include <xmloff/prstylei.hxx>
57 #include "i18nmap.hxx"
58 #include "xexptran.hxx"
59 #include <xmloff/shapeimport.hxx>
60 #include <xmloff/XMLEventsImportContext.hxx>
61 #include "XMLImageMapContext.hxx"
62 #include "XMLTextFrameContext.hxx"
64 #include "XMLTextListBlockContext.hxx"
65 #include "XMLTextListItemContext.hxx"
66 #include <xmloff/attrlist.hxx>
67 #include <comphelper/stl_types.hxx>
69 #include <map>
72 using ::rtl::OUString;
73 using ::rtl::OUStringBuffer;
75 using namespace ::com::sun::star;
76 using namespace ::com::sun::star::uno;
77 using namespace ::com::sun::star::text;
78 using namespace ::com::sun::star::xml::sax;
79 using namespace ::com::sun::star::beans;
80 using namespace ::com::sun::star::lang;
81 using namespace ::com::sun::star::container;
82 using namespace ::com::sun::star::drawing;
83 using namespace ::com::sun::star::document;
84 using namespace ::xmloff::token;
85 using ::com::sun::star::document::XEventsSupplier;
87 #define XML_TEXT_FRAME_TEXTBOX 1
88 #define XML_TEXT_FRAME_GRAPHIC 2
89 #define XML_TEXT_FRAME_OBJECT 3
90 #define XML_TEXT_FRAME_OBJECT_OLE 4
91 #define XML_TEXT_FRAME_APPLET 5
92 #define XML_TEXT_FRAME_PLUGIN 6
93 #define XML_TEXT_FRAME_FLOATING_FRAME 7
95 typedef ::std::map < const ::rtl::OUString, ::rtl::OUString, ::comphelper::UStringLess> ParamMap;
97 class XMLTextFrameContextHyperlink_Impl
99 OUString sHRef;
100 OUString sName;
101 OUString sTargetFrameName;
102 sal_Bool bMap;
104 public:
106 inline XMLTextFrameContextHyperlink_Impl( const OUString& rHRef,
107 const OUString& rName,
108 const OUString& rTargetFrameName,
109 sal_Bool bMap );
111 const OUString& GetHRef() const { return sHRef; }
112 const OUString& GetName() const { return sName; }
113 const OUString& GetTargetFrameName() const { return sTargetFrameName; }
114 sal_Bool GetMap() const { return bMap; }
117 inline XMLTextFrameContextHyperlink_Impl::XMLTextFrameContextHyperlink_Impl(
118 const OUString& rHRef, const OUString& rName,
119 const OUString& rTargetFrameName, sal_Bool bM ) :
120 sHRef( rHRef ),
121 sName( rName ),
122 sTargetFrameName( rTargetFrameName ),
123 bMap( bM )
127 // --> OD 2009-07-22 #i73249#
128 class XMLTextFrameTitleOrDescContext_Impl : public SvXMLImportContext
130 OUString& mrTitleOrDesc;
132 public:
134 TYPEINFO();
136 XMLTextFrameTitleOrDescContext_Impl( SvXMLImport& rImport,
137 sal_uInt16 nPrfx,
138 const ::rtl::OUString& rLName,
139 OUString& rTitleOrDesc );
140 virtual ~XMLTextFrameTitleOrDescContext_Impl();
142 virtual void Characters( const OUString& rText );
145 TYPEINIT1( XMLTextFrameTitleOrDescContext_Impl, SvXMLImportContext );
147 XMLTextFrameTitleOrDescContext_Impl::XMLTextFrameTitleOrDescContext_Impl(
148 SvXMLImport& rImport,
149 sal_uInt16 nPrfx,
150 const OUString& rLName,
151 OUString& rTitleOrDesc )
152 : SvXMLImportContext( rImport, nPrfx, rLName )
153 , mrTitleOrDesc( rTitleOrDesc )
157 XMLTextFrameTitleOrDescContext_Impl::~XMLTextFrameTitleOrDescContext_Impl()
161 void XMLTextFrameTitleOrDescContext_Impl::Characters( const OUString& rText )
163 mrTitleOrDesc += rText;
165 // <--
167 // ------------------------------------------------------------------------
169 class XMLTextFrameParam_Impl : public SvXMLImportContext
171 public:
173 TYPEINFO();
175 XMLTextFrameParam_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
176 const ::rtl::OUString& rLName,
177 const ::com::sun::star::uno::Reference<
178 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
179 sal_uInt16 nType,
180 ParamMap &rParamMap);
181 virtual ~XMLTextFrameParam_Impl();
184 TYPEINIT1( XMLTextFrameParam_Impl, SvXMLImportContext );
186 XMLTextFrameParam_Impl::~XMLTextFrameParam_Impl()
190 XMLTextFrameParam_Impl::XMLTextFrameParam_Impl(
191 SvXMLImport& rImport, sal_uInt16 nPrfx,
192 const ::rtl::OUString& rLName,
193 const ::com::sun::star::uno::Reference<
194 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
195 sal_uInt16 /*nType*/,
196 ParamMap &rParamMap):
197 SvXMLImportContext( rImport, nPrfx, rLName )
199 OUString sName, sValue;
200 sal_Bool bFoundValue = sal_False; // to allow empty values
201 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
202 for( sal_Int16 i=0; i < nAttrCount; i++ )
204 const OUString& rAttrName = xAttrList->getNameByIndex( i );
205 const OUString& rValue = xAttrList->getValueByIndex( i );
207 OUString aLocalName;
208 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
209 if ( XML_NAMESPACE_DRAW == nPrefix )
211 if( IsXMLToken(aLocalName, XML_VALUE) )
213 sValue = rValue;
214 bFoundValue=sal_True;
216 else if( IsXMLToken(aLocalName, XML_NAME) )
218 sName = rValue;
222 if (sName.getLength() && bFoundValue )
223 rParamMap[sName] = sValue;
225 class XMLTextFrameContourContext_Impl : public SvXMLImportContext
227 Reference < XPropertySet > xPropSet;
229 public:
231 TYPEINFO();
233 XMLTextFrameContourContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
234 const ::rtl::OUString& rLName,
235 const ::com::sun::star::uno::Reference<
236 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
237 const Reference < XPropertySet >& rPropSet,
238 sal_Bool bPath );
239 virtual ~XMLTextFrameContourContext_Impl();
242 TYPEINIT1( XMLTextFrameContourContext_Impl, SvXMLImportContext );
244 XMLTextFrameContourContext_Impl::XMLTextFrameContourContext_Impl(
245 SvXMLImport& rImport,
246 sal_uInt16 nPrfx, const OUString& rLName,
247 const Reference< XAttributeList > & xAttrList,
248 const Reference < XPropertySet >& rPropSet,
249 sal_Bool bPath ) :
250 SvXMLImportContext( rImport, nPrfx, rLName ),
251 xPropSet( rPropSet )
253 OUString sD, sPoints, sViewBox;
254 sal_Bool bPixelWidth = sal_False, bPixelHeight = sal_False;
255 sal_Bool bAuto = sal_False;
256 sal_Int32 nWidth = 0;
257 sal_Int32 nHeight = 0;
259 const SvXMLTokenMap& rTokenMap =
260 GetImport().GetTextImport()->GetTextContourAttrTokenMap();
262 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
263 for( sal_Int16 i=0; i < nAttrCount; i++ )
265 const OUString& rAttrName = xAttrList->getNameByIndex( i );
266 const OUString& rValue = xAttrList->getValueByIndex( i );
268 OUString aLocalName;
269 sal_uInt16 nPrefix =
270 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
271 &aLocalName );
272 switch( rTokenMap.Get( nPrefix, aLocalName ) )
274 case XML_TOK_TEXT_CONTOUR_VIEWBOX:
275 sViewBox = rValue;
276 break;
277 case XML_TOK_TEXT_CONTOUR_D:
278 if( bPath )
279 sD = rValue;
280 break;
281 case XML_TOK_TEXT_CONTOUR_POINTS:
282 if( !bPath )
283 sPoints = rValue;
284 break;
285 case XML_TOK_TEXT_CONTOUR_WIDTH:
286 if( GetImport().GetMM100UnitConverter().convertMeasurePx( nWidth,
287 rValue) )
288 bPixelWidth = sal_True;
289 else
290 GetImport().GetMM100UnitConverter().convertMeasure( nWidth,
291 rValue);
292 break;
293 case XML_TOK_TEXT_CONTOUR_HEIGHT:
294 if( GetImport().GetMM100UnitConverter().convertMeasurePx( nHeight,
295 rValue) )
296 bPixelHeight = sal_True;
297 else
298 GetImport().GetMM100UnitConverter().convertMeasure( nHeight,
299 rValue);
300 break;
301 case XML_TOK_TEXT_CONTOUR_AUTO:
302 bAuto = IsXMLToken(rValue, XML_TRUE);
303 break;
307 OUString sContourPolyPolygon(
308 RTL_CONSTASCII_USTRINGPARAM("ContourPolyPolygon") );
309 Reference < XPropertySetInfo > xPropSetInfo =
310 rPropSet->getPropertySetInfo();
311 if( xPropSetInfo->hasPropertyByName(
312 sContourPolyPolygon ) &&
313 nWidth > 0 && nHeight > 0 && bPixelWidth == bPixelHeight &&
314 (bPath ? sD : sPoints).getLength() )
316 awt::Point aPoint( 0, 0 );
317 awt::Size aSize( nWidth, nHeight );
318 SdXMLImExViewBox aViewBox( sViewBox,
319 GetImport().GetMM100UnitConverter());
320 Any aAny;
321 if( bPath )
323 SdXMLImExSvgDElement aPoints( sD, aViewBox, aPoint, aSize,
324 GetImport().GetMM100UnitConverter() );
325 aAny <<= aPoints.GetPointSequenceSequence();
327 else
329 SdXMLImExPointsElement aPoints( sPoints, aViewBox, aPoint, aSize,
330 GetImport().GetMM100UnitConverter() );
331 aAny <<= aPoints.GetPointSequenceSequence();
334 OUString sIsPixelContour(
335 RTL_CONSTASCII_USTRINGPARAM("IsPixelContour") );
336 xPropSet->setPropertyValue( sContourPolyPolygon, aAny );
338 if( xPropSetInfo->hasPropertyByName( sIsPixelContour ) )
340 aAny.setValue( &bPixelWidth, ::getBooleanCppuType() );
341 xPropSet->setPropertyValue( sIsPixelContour, aAny );
344 OUString sIsAutomaticContour(
345 RTL_CONSTASCII_USTRINGPARAM("IsAutomaticContour") );
346 if( xPropSetInfo->hasPropertyByName( sIsAutomaticContour ) )
348 aAny.setValue( &bAuto, ::getBooleanCppuType() );
349 xPropSet->setPropertyValue( sIsAutomaticContour, aAny );
354 XMLTextFrameContourContext_Impl::~XMLTextFrameContourContext_Impl()
358 // ------------------------------------------------------------------------
360 class XMLTextFrameContext_Impl : public SvXMLImportContext
362 ::com::sun::star::uno::Reference <
363 ::com::sun::star::text::XTextCursor > xOldTextCursor;
364 ::com::sun::star::uno::Reference <
365 ::com::sun::star::beans::XPropertySet > xPropSet;
366 ::com::sun::star::uno::Reference <
367 ::com::sun::star::io::XOutputStream > xBase64Stream;
369 /// old list item and block (#89891#)
370 bool mbListContextPushed;
372 const ::rtl::OUString sWidth;
373 const ::rtl::OUString sWidthType;
374 const ::rtl::OUString sRelativeWidth;
375 const ::rtl::OUString sHeight;
376 const ::rtl::OUString sRelativeHeight;
377 const ::rtl::OUString sSizeType;
378 const ::rtl::OUString sIsSyncWidthToHeight;
379 const ::rtl::OUString sIsSyncHeightToWidth;
380 const ::rtl::OUString sHoriOrient;
381 const ::rtl::OUString sHoriOrientPosition;
382 const ::rtl::OUString sVertOrient;
383 const ::rtl::OUString sVertOrientPosition;
384 const ::rtl::OUString sChainNextName;
385 const ::rtl::OUString sAnchorType;
386 const ::rtl::OUString sAnchorPageNo;
387 const ::rtl::OUString sGraphicURL;
388 const ::rtl::OUString sGraphicFilter;
389 // --> OD 2009-07-22 #i73249#
390 // const ::rtl::OUString sAlternativeText;
391 const ::rtl::OUString sTitle;
392 const ::rtl::OUString sDescription;
393 // <--
394 const ::rtl::OUString sFrameStyleName;
395 const ::rtl::OUString sGraphicRotation;
396 const ::rtl::OUString sTextBoxServiceName;
397 const ::rtl::OUString sGraphicServiceName;
399 ::rtl::OUString sName;
400 ::rtl::OUString sStyleName;
401 ::rtl::OUString sNextName;
402 ::rtl::OUString sHRef;
403 ::rtl::OUString sFilterName;
404 ::rtl::OUString sCode;
405 ::rtl::OUString sObject;
406 ::rtl::OUString sArchive;
407 ::rtl::OUString sMimeType;
408 ::rtl::OUString sFrameName;
409 ::rtl::OUString sAppletName;
410 ::rtl::OUString sFilterService;
411 ::rtl::OUString sBase64CharsLeft;
412 ::rtl::OUString sTblName;
414 ParamMap aParamMap;
416 sal_Int32 nX;
417 sal_Int32 nY;
418 sal_Int32 nWidth;
419 sal_Int32 nHeight;
420 sal_Int32 nZIndex;
421 sal_Int16 nPage;
422 sal_Int16 nRotation;
423 sal_Int16 nRelWidth;
424 sal_Int16 nRelHeight;
426 sal_uInt16 nType;
427 ::com::sun::star::text::TextContentAnchorType eAnchorType;
429 sal_Bool bMayScript : 1;
430 sal_Bool bMinWidth : 1;
431 sal_Bool bMinHeight : 1;
432 sal_Bool bSyncWidth : 1;
433 sal_Bool bSyncHeight : 1;
434 sal_Bool bCreateFailed : 1;
435 sal_Bool bOwnBase64Stream : 1;
437 void Create( sal_Bool bHRefOrBase64 );
439 public:
441 TYPEINFO();
443 sal_Bool CreateIfNotThere();
445 XMLTextFrameContext_Impl( SvXMLImport& rImport,
446 sal_uInt16 nPrfx,
447 const ::rtl::OUString& rLName,
448 const ::com::sun::star::uno::Reference<
449 ::com::sun::star::xml::sax::XAttributeList > & rAttrList,
450 ::com::sun::star::text::TextContentAnchorType eAnchorType,
451 sal_uInt16 nType,
452 const ::com::sun::star::uno::Reference<
453 ::com::sun::star::xml::sax::XAttributeList > & rFrameAttrList );
454 virtual ~XMLTextFrameContext_Impl();
456 virtual void EndElement();
458 virtual void Characters( const ::rtl::OUString& rChars );
460 SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
461 const ::rtl::OUString& rLocalName,
462 const ::com::sun::star::uno::Reference<
463 ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
465 void SetHyperlink( const ::rtl::OUString& rHRef,
466 const ::rtl::OUString& rName,
467 const ::rtl::OUString& rTargetFrameName,
468 sal_Bool bMap );
469 // --> OD 2009-07-22 #i73249#
470 void SetTitle( const ::rtl::OUString& rTitle );
471 // <--
472 void SetDesc( const ::rtl::OUString& rDesc );
474 ::com::sun::star::text::TextContentAnchorType GetAnchorType() const { return eAnchorType; }
476 const ::com::sun::star::uno::Reference <
477 ::com::sun::star::beans::XPropertySet >& GetPropSet() { return xPropSet; }
480 TYPEINIT1( XMLTextFrameContext_Impl, SvXMLImportContext );
482 void XMLTextFrameContext_Impl::Create( sal_Bool /*bHRefOrBase64*/ )
484 UniReference < XMLTextImportHelper > xTextImportHelper =
485 GetImport().GetTextImport();
487 switch ( nType)
489 case XML_TEXT_FRAME_OBJECT:
490 case XML_TEXT_FRAME_OBJECT_OLE:
491 if( xBase64Stream.is() )
493 OUString sURL( GetImport().ResolveEmbeddedObjectURLFromBase64() );
494 if( sURL.getLength() )
495 xPropSet = GetImport().GetTextImport()
496 ->createAndInsertOLEObject( GetImport(), sURL,
497 sStyleName,
498 sTblName,
499 nWidth, nHeight );
501 else if( sHRef.getLength() )
503 OUString sURL( GetImport().ResolveEmbeddedObjectURL( sHRef,
504 OUString() ) );
506 if( GetImport().IsPackageURL( sHRef ) )
508 xPropSet = GetImport().GetTextImport()
509 ->createAndInsertOLEObject( GetImport(), sURL,
510 sStyleName,
511 sTblName,
512 nWidth, nHeight );
514 else
516 // it should be an own OOo link that has no storage persistance
517 xPropSet = GetImport().GetTextImport()
518 ->createAndInsertOOoLink( GetImport(),
519 sURL,
520 sStyleName,
521 sTblName,
522 nWidth, nHeight );
525 else
527 OUString sURL( RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.ServiceName:") );
528 sURL += sFilterService;
529 xPropSet = GetImport().GetTextImport()
530 ->createAndInsertOLEObject( GetImport(), sURL,
531 sStyleName,
532 sTblName,
533 nWidth, nHeight );
536 break;
537 case XML_TEXT_FRAME_APPLET:
539 xPropSet = GetImport().GetTextImport()
540 ->createAndInsertApplet( sAppletName, sCode,
541 bMayScript, sHRef,
542 nWidth, nHeight);
543 break;
545 case XML_TEXT_FRAME_PLUGIN:
547 if(sHRef.getLength())
548 GetImport().GetAbsoluteReference(sHRef);
549 xPropSet = GetImport().GetTextImport()
550 ->createAndInsertPlugin( sMimeType, sHRef,
551 nWidth, nHeight);
553 break;
555 case XML_TEXT_FRAME_FLOATING_FRAME:
557 xPropSet = GetImport().GetTextImport()
558 ->createAndInsertFloatingFrame( sFrameName, sHRef,
559 sStyleName,
560 nWidth, nHeight);
561 break;
563 default:
565 Reference<XMultiServiceFactory> xFactory( GetImport().GetModel(),
566 UNO_QUERY );
567 if( xFactory.is() )
569 OUString sServiceName;
570 switch( nType )
572 case XML_TEXT_FRAME_TEXTBOX: sServiceName = sTextBoxServiceName; break;
573 case XML_TEXT_FRAME_GRAPHIC: sServiceName = sGraphicServiceName; break;
575 Reference<XInterface> xIfc = xFactory->createInstance( sServiceName );
576 DBG_ASSERT( xIfc.is(), "couldn't create frame" );
577 if( xIfc.is() )
578 xPropSet = Reference < XPropertySet >( xIfc, UNO_QUERY );
583 if( !xPropSet.is() )
585 bCreateFailed = sal_True;
586 return;
589 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
591 // set name
592 Reference < XNamed > xNamed( xPropSet, UNO_QUERY );
593 if( xNamed.is() )
595 OUString sOrigName( xNamed->getName() );
596 if( !sOrigName.getLength() ||
597 (sName.getLength() && sOrigName != sName) )
599 OUString sOldName( sName );
600 sal_Int32 i = 0;
601 while( xTextImportHelper->HasFrameByName( sName ) )
603 sName = sOldName;
604 sName += OUString::valueOf( ++i );
606 xNamed->setName( sName );
607 if( sName != sOldName )
608 xTextImportHelper->GetRenameMap().Add( XML_TEXT_RENAME_TYPE_FRAME,
609 sOldName, sName );
613 // frame style
614 XMLPropStyleContext *pStyle = 0;
615 if( sStyleName.getLength() )
617 pStyle = xTextImportHelper->FindAutoFrameStyle( sStyleName );
618 if( pStyle )
619 sStyleName = pStyle->GetParentName();
622 Any aAny;
623 if( sStyleName.getLength() )
625 OUString sDisplayStyleName( GetImport().GetStyleDisplayName(
626 XML_STYLE_FAMILY_SD_GRAPHICS_ID, sStyleName ) );
627 const Reference < XNameContainer > & rStyles =
628 xTextImportHelper->GetFrameStyles();
629 if( rStyles.is() &&
630 rStyles->hasByName( sDisplayStyleName ) )
632 aAny <<= sDisplayStyleName;
633 xPropSet->setPropertyValue( sFrameStyleName, aAny );
637 // anchor type (must be set before any other properties, because
638 // otherwise some orientations cannot be set or will be changed
639 // afterwards)
640 aAny <<= eAnchorType;
641 xPropSet->setPropertyValue( sAnchorType, aAny );
643 // hard properties
644 if( pStyle )
645 pStyle->FillPropertySet( xPropSet );
648 // x and y
649 sal_Int16 nHoriOrient = HoriOrientation::NONE;
650 aAny = xPropSet->getPropertyValue( sHoriOrient );
651 aAny >>= nHoriOrient;
652 if( HoriOrientation::NONE == nHoriOrient )
654 aAny <<= nX;
655 xPropSet->setPropertyValue( sHoriOrientPosition, aAny );
658 sal_Int16 nVertOrient = VertOrientation::NONE;
659 aAny = xPropSet->getPropertyValue( sVertOrient );
660 aAny >>= nVertOrient;
661 if( VertOrientation::NONE == nVertOrient )
663 aAny <<= nY;
664 xPropSet->setPropertyValue( sVertOrientPosition, aAny );
667 // width
668 if( nWidth > 0 )
670 aAny <<= nWidth;
671 xPropSet->setPropertyValue( sWidth, aAny );
673 if( nRelWidth > 0 || nWidth > 0 )
675 aAny <<= nRelWidth;
676 xPropSet->setPropertyValue( sRelativeWidth, aAny );
678 if( bSyncWidth || nWidth > 0 )
680 sal_Bool bTmp = bSyncWidth;
681 aAny.setValue( &bTmp, ::getBooleanCppuType() );
682 xPropSet->setPropertyValue( sIsSyncWidthToHeight, aAny );
684 if( xPropSetInfo->hasPropertyByName( sWidthType ) &&
685 (bMinWidth || nWidth > 0 || nRelWidth > 0 ) )
687 sal_Int16 nSizeType =
688 (bMinWidth && XML_TEXT_FRAME_TEXTBOX == nType) ? SizeType::MIN
689 : SizeType::FIX;
690 aAny <<= nSizeType;
691 xPropSet->setPropertyValue( sWidthType, aAny );
694 if( nHeight > 0 )
696 aAny <<= nHeight;
697 xPropSet->setPropertyValue( sHeight, aAny );
699 if( nRelHeight > 0 || nHeight > 0 )
701 aAny <<= nRelHeight;
702 xPropSet->setPropertyValue( sRelativeHeight, aAny );
704 if( bSyncHeight || nHeight > 0 )
706 sal_Bool bTmp = bSyncHeight;
707 aAny.setValue( &bTmp, ::getBooleanCppuType() );
708 xPropSet->setPropertyValue( sIsSyncHeightToWidth, aAny );
710 if( xPropSetInfo->hasPropertyByName( sSizeType ) &&
711 (bMinHeight || nHeight > 0 || nRelHeight > 0 ) )
713 sal_Int16 nSizeType =
714 (bMinHeight && XML_TEXT_FRAME_TEXTBOX == nType) ? SizeType::MIN
715 : SizeType::FIX;
716 aAny <<= nSizeType;
717 xPropSet->setPropertyValue( sSizeType, aAny );
720 if( XML_TEXT_FRAME_GRAPHIC == nType )
722 // URL
723 OSL_ENSURE( sHRef.getLength() > 0 || xBase64Stream.is(),
724 "neither URL nor base64 image data given" );
725 UniReference < XMLTextImportHelper > xTxtImport =
726 GetImport().GetTextImport();
727 if( sHRef.getLength() )
729 sal_Bool bForceLoad = xTxtImport->IsInsertMode() ||
730 xTxtImport->IsBlockMode() ||
731 xTxtImport->IsStylesOnlyMode() ||
732 xTxtImport->IsOrganizerMode();
733 sHRef = GetImport().ResolveGraphicObjectURL( sHRef, !bForceLoad );
735 else if( xBase64Stream.is() )
737 sHRef = GetImport().ResolveGraphicObjectURLFromBase64( xBase64Stream );
738 xBase64Stream = 0;
740 aAny <<= sHRef;
741 xPropSet->setPropertyValue( sGraphicURL, aAny );
743 // filter name
744 aAny <<=sFilterName;
745 xPropSet->setPropertyValue( sGraphicFilter, aAny );
747 // rotation
748 aAny <<= nRotation;
749 xPropSet->setPropertyValue( sGraphicRotation, aAny );
752 // page number (must be set after the frame is inserted, because it
753 // will be overwritten then inserting the frame.
754 if( TextContentAnchorType_AT_PAGE == eAnchorType && nPage > 0 )
756 aAny <<= nPage;
757 xPropSet->setPropertyValue( sAnchorPageNo, aAny );
760 if( XML_TEXT_FRAME_OBJECT != nType &&
761 XML_TEXT_FRAME_OBJECT_OLE != nType &&
762 XML_TEXT_FRAME_APPLET != nType &&
763 XML_TEXT_FRAME_PLUGIN!= nType &&
764 XML_TEXT_FRAME_FLOATING_FRAME != nType)
766 Reference < XTextContent > xTxtCntnt( xPropSet, UNO_QUERY );
767 xTextImportHelper->InsertTextContent( xTxtCntnt );
770 Reference < XShape > xShape( xPropSet, UNO_QUERY );
772 // #107848#
773 // Make adding the shepe to Z-Ordering dependent from if we are
774 // inside a inside_deleted_section (redlining). That is necessary
775 // since the shape will be removed again later. It would lead to
776 // errors if it would stay inside the Z-Ordering. Thus, the
777 // easiest way to solve that conflict is to not add it here.
778 if(!GetImport().HasTextImport()
779 || !GetImport().GetTextImport()->IsInsideDeleteContext())
781 GetImport().GetShapeImport()->shapeWithZIndexAdded( xShape, nZIndex );
784 if( XML_TEXT_FRAME_TEXTBOX == nType )
786 xTextImportHelper->ConnectFrameChains( sName, sNextName, xPropSet );
787 Reference < XTextFrame > xTxtFrame( xPropSet, UNO_QUERY );
788 Reference < XText > xTxt = xTxtFrame->getText();
789 xOldTextCursor = xTextImportHelper->GetCursor();
790 xTextImportHelper->SetCursor( xTxt->createTextCursor() );
792 // remember old list item and block (#89892#) and reset them
793 // for the text frame
794 xTextImportHelper->PushListContext();
795 mbListContextPushed = true;
799 sal_Bool XMLTextFrameContext_Impl::CreateIfNotThere()
801 if( !xPropSet.is() &&
802 ( XML_TEXT_FRAME_OBJECT_OLE == nType ||
803 XML_TEXT_FRAME_GRAPHIC == nType ) &&
804 xBase64Stream.is() && !bCreateFailed )
806 if( bOwnBase64Stream )
807 xBase64Stream->closeOutput();
808 Create( sal_True );
811 return xPropSet.is();
814 XMLTextFrameContext_Impl::XMLTextFrameContext_Impl(
815 SvXMLImport& rImport,
816 sal_uInt16 nPrfx, const OUString& rLName,
817 const Reference< XAttributeList > & rAttrList,
818 TextContentAnchorType eATyp,
819 sal_uInt16 nNewType,
820 const Reference< XAttributeList > & rFrameAttrList )
821 : SvXMLImportContext( rImport, nPrfx, rLName )
822 , mbListContextPushed( false )
823 , sWidth(RTL_CONSTASCII_USTRINGPARAM("Width"))
824 , sWidthType(RTL_CONSTASCII_USTRINGPARAM("WidthType"))
825 , sRelativeWidth(RTL_CONSTASCII_USTRINGPARAM("RelativeWidth"))
826 , sHeight(RTL_CONSTASCII_USTRINGPARAM("Height"))
827 , sRelativeHeight(RTL_CONSTASCII_USTRINGPARAM("RelativeHeight"))
828 , sSizeType(RTL_CONSTASCII_USTRINGPARAM("SizeType"))
829 , sIsSyncWidthToHeight(RTL_CONSTASCII_USTRINGPARAM("IsSyncWidthToHeight"))
830 , sIsSyncHeightToWidth(RTL_CONSTASCII_USTRINGPARAM("IsSyncHeightToWidth"))
831 , sHoriOrient(RTL_CONSTASCII_USTRINGPARAM("HoriOrient"))
832 , sHoriOrientPosition(RTL_CONSTASCII_USTRINGPARAM("HoriOrientPosition"))
833 , sVertOrient(RTL_CONSTASCII_USTRINGPARAM("VertOrient"))
834 , sVertOrientPosition(RTL_CONSTASCII_USTRINGPARAM("VertOrientPosition"))
835 , sChainNextName(RTL_CONSTASCII_USTRINGPARAM("ChainNextName"))
836 , sAnchorType(RTL_CONSTASCII_USTRINGPARAM("AnchorType"))
837 , sAnchorPageNo(RTL_CONSTASCII_USTRINGPARAM("AnchorPageNo"))
838 , sGraphicURL(RTL_CONSTASCII_USTRINGPARAM("GraphicURL"))
839 , sGraphicFilter(RTL_CONSTASCII_USTRINGPARAM("GraphicFilter"))
840 // --> OD 2009-07-22 #i73249#
841 //, sAlternativeText(RTL_CONSTASCII_USTRINGPARAM("AlternativeText"))
842 , sTitle(RTL_CONSTASCII_USTRINGPARAM("Title"))
843 , sDescription(RTL_CONSTASCII_USTRINGPARAM("Description"))
844 // <--
845 , sFrameStyleName(RTL_CONSTASCII_USTRINGPARAM("FrameStyleName"))
846 , sGraphicRotation(RTL_CONSTASCII_USTRINGPARAM("GraphicRotation"))
847 , sTextBoxServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFrame"))
848 , sGraphicServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.GraphicObject"))
849 , nType( nNewType )
850 , eAnchorType( eATyp )
852 nX = 0;
853 nY = 0;
854 nWidth = 0;
855 nHeight = 0;
856 nZIndex = -1;
857 nPage = 0;
858 nRotation = 0;
859 nRelWidth = 0;
860 nRelHeight = 0;
861 bMayScript = sal_False;
863 bMinHeight = sal_False;
864 bMinWidth = sal_False;
865 bSyncWidth = sal_False;
866 bSyncHeight = sal_False;
867 bCreateFailed = sal_False;
868 bOwnBase64Stream = sal_False;
870 UniReference < XMLTextImportHelper > xTxtImport =
871 GetImport().GetTextImport();
872 const SvXMLTokenMap& rTokenMap =
873 xTxtImport->GetTextFrameAttrTokenMap();
875 sal_Int16 nAttrCount = rAttrList.is() ? rAttrList->getLength() : 0;
876 sal_Int16 nTotalAttrCount = nAttrCount + (rFrameAttrList.is() ? rFrameAttrList->getLength() : 0);
877 for( sal_Int16 i=0; i < nTotalAttrCount; i++ )
879 const OUString& rAttrName =
880 i < nAttrCount ? rAttrList->getNameByIndex( i ) : rFrameAttrList->getNameByIndex( i-nAttrCount );
881 const OUString& rValue =
882 i < nAttrCount ? rAttrList->getValueByIndex( i ): rFrameAttrList->getValueByIndex( i-nAttrCount );
884 OUString aLocalName;
885 sal_uInt16 nPrefix =
886 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
887 &aLocalName );
888 switch( rTokenMap.Get( nPrefix, aLocalName ) )
890 case XML_TOK_TEXT_FRAME_STYLE_NAME:
891 sStyleName = rValue;
892 break;
893 case XML_TOK_TEXT_FRAME_NAME:
894 sName = rValue;
895 break;
896 case XML_TOK_TEXT_FRAME_FRAME_NAME:
897 sFrameName = rValue;
898 break;
899 case XML_TOK_TEXT_FRAME_APPLET_NAME:
900 sAppletName = rValue;
901 break;
902 case XML_TOK_TEXT_FRAME_ANCHOR_TYPE:
903 if( TextContentAnchorType_AT_PARAGRAPH == eAnchorType ||
904 TextContentAnchorType_AT_CHARACTER == eAnchorType ||
905 TextContentAnchorType_AS_CHARACTER == eAnchorType )
908 TextContentAnchorType eNew;
909 if( XMLAnchorTypePropHdl::convert( rValue, eNew ) &&
910 ( TextContentAnchorType_AT_PARAGRAPH == eNew ||
911 TextContentAnchorType_AT_CHARACTER == eNew ||
912 TextContentAnchorType_AS_CHARACTER == eNew ||
913 TextContentAnchorType_AT_PAGE == eNew) )
914 eAnchorType = eNew;
916 break;
917 case XML_TOK_TEXT_FRAME_ANCHOR_PAGE_NUMBER:
919 sal_Int32 nTmp;
920 if( GetImport().GetMM100UnitConverter().
921 convertNumber( nTmp, rValue, 1, SHRT_MAX ) )
922 nPage = (sal_Int16)nTmp;
924 break;
925 case XML_TOK_TEXT_FRAME_X:
926 GetImport().GetMM100UnitConverter().convertMeasure( nX, rValue );
927 break;
928 case XML_TOK_TEXT_FRAME_Y:
929 GetImport().GetMM100UnitConverter().convertMeasure( nY, rValue );
930 break;
931 case XML_TOK_TEXT_FRAME_WIDTH:
932 // relative widths are obsolete since SRC617. Remove them some day!
933 if( rValue.indexOf( '%' ) != -1 )
935 sal_Int32 nTmp;
936 GetImport().GetMM100UnitConverter().convertPercent( nTmp,
937 rValue );
938 nRelWidth = (sal_Int16)nTmp;
940 else
942 GetImport().GetMM100UnitConverter().convertMeasure( nWidth,
943 rValue, 0 );
945 break;
946 case XML_TOK_TEXT_FRAME_REL_WIDTH:
947 if( IsXMLToken(rValue, XML_SCALE) )
949 bSyncWidth = sal_True;
951 else
953 sal_Int32 nTmp;
954 if( GetImport().GetMM100UnitConverter().
955 convertPercent( nTmp, rValue ) )
956 nRelWidth = (sal_Int16)nTmp;
958 break;
959 case XML_TOK_TEXT_FRAME_MIN_WIDTH:
960 if( rValue.indexOf( '%' ) != -1 )
962 sal_Int32 nTmp;
963 GetImport().GetMM100UnitConverter().convertPercent( nTmp,
964 rValue );
965 nRelWidth = (sal_Int16)nTmp;
967 else
969 GetImport().GetMM100UnitConverter().convertMeasure( nWidth,
970 rValue, 0 );
972 bMinWidth = sal_True;
973 break;
974 case XML_TOK_TEXT_FRAME_HEIGHT:
975 // relative heights are obsolete since SRC617. Remove them some day!
976 if( rValue.indexOf( '%' ) != -1 )
978 sal_Int32 nTmp;
979 GetImport().GetMM100UnitConverter().convertPercent( nTmp,
980 rValue );
981 nRelHeight = (sal_Int16)nTmp;
983 else
985 GetImport().GetMM100UnitConverter().convertMeasure( nHeight,
986 rValue, 0 );
988 break;
989 case XML_TOK_TEXT_FRAME_REL_HEIGHT:
990 if( IsXMLToken( rValue, XML_SCALE ) )
992 bSyncHeight = sal_True;
994 else if( IsXMLToken( rValue, XML_SCALE_MIN ) )
996 bSyncHeight = sal_True;
997 bMinHeight = sal_True;
999 else
1001 sal_Int32 nTmp;
1002 if( GetImport().GetMM100UnitConverter().
1003 convertPercent( nTmp, rValue ) )
1004 nRelHeight = (sal_Int16)nTmp;
1006 break;
1007 case XML_TOK_TEXT_FRAME_MIN_HEIGHT:
1008 if( rValue.indexOf( '%' ) != -1 )
1010 sal_Int32 nTmp;
1011 GetImport().GetMM100UnitConverter().convertPercent( nTmp,
1012 rValue );
1013 nRelHeight = (sal_Int16)nTmp;
1015 else
1017 GetImport().GetMM100UnitConverter().convertMeasure( nHeight,
1018 rValue, 0 );
1020 bMinHeight = sal_True;
1021 break;
1022 case XML_TOK_TEXT_FRAME_Z_INDEX:
1023 GetImport().GetMM100UnitConverter().convertNumber( nZIndex, rValue, -1 );
1024 break;
1025 case XML_TOK_TEXT_FRAME_NEXT_CHAIN_NAME:
1026 sNextName = rValue;
1027 break;
1028 case XML_TOK_TEXT_FRAME_HREF:
1029 sHRef = rValue;
1030 break;
1031 case XML_TOK_TEXT_FRAME_FILTER_NAME:
1032 sFilterName = rValue;
1033 break;
1034 case XML_TOK_TEXT_FRAME_TRANSFORM:
1036 OUString sValue( rValue );
1037 sValue.trim();
1038 const sal_Int32 nRotateLen = sizeof(sXML_rotate)-1;
1039 sal_Int32 nLen = sValue.getLength();
1040 if( nLen >= nRotateLen+3 &&
1041 0 == sValue.compareToAscii( sXML_rotate, nRotateLen ) &&
1042 '(' == sValue[nRotateLen] &&
1043 ')' == sValue[nLen-1] )
1045 sValue = sValue.copy( nRotateLen+1, nLen-(nRotateLen+2) );
1046 sValue.trim();
1047 sal_Int32 nVal;
1048 if( GetImport().GetMM100UnitConverter().convertNumber( nVal, sValue ) )
1049 nRotation = (sal_Int16)(nVal % 360 );
1052 break;
1053 case XML_TOK_TEXT_FRAME_CODE:
1054 sCode = rValue;
1055 break;
1056 case XML_TOK_TEXT_FRAME_OBJECT:
1057 sObject = rValue;
1058 break;
1059 case XML_TOK_TEXT_FRAME_ARCHIVE:
1060 sArchive = rValue;
1061 break;
1062 case XML_TOK_TEXT_FRAME_MAY_SCRIPT:
1063 bMayScript = IsXMLToken( rValue, XML_TRUE );
1064 break;
1065 case XML_TOK_TEXT_FRAME_MIME_TYPE:
1066 sMimeType = rValue;
1067 break;
1068 case XML_TOK_TEXT_FRAME_NOTIFY_ON_UPDATE:
1069 sTblName = rValue;
1070 break;
1074 if( ( (XML_TEXT_FRAME_GRAPHIC == nType ||
1075 XML_TEXT_FRAME_OBJECT == nType ||
1076 XML_TEXT_FRAME_OBJECT_OLE == nType) &&
1077 !sHRef.getLength() ) ||
1078 ( XML_TEXT_FRAME_APPLET == nType && !sCode.getLength() ) ||
1079 ( XML_TEXT_FRAME_PLUGIN == nType &&
1080 sHRef.getLength() == 0 && sMimeType.getLength() == 0 ) )
1081 return; // no URL: no image or OLE object
1083 Create( sal_True );
1086 XMLTextFrameContext_Impl::~XMLTextFrameContext_Impl()
1090 void XMLTextFrameContext_Impl::EndElement()
1092 CreateIfNotThere();
1094 if( xOldTextCursor.is() )
1096 GetImport().GetTextImport()->DeleteParagraph();
1097 GetImport().GetTextImport()->SetCursor( xOldTextCursor );
1100 // reinstall old list item (if necessary) #89892#
1101 if (mbListContextPushed) {
1102 GetImport().GetTextImport()->PopListContext();
1105 if (( nType == XML_TEXT_FRAME_APPLET || nType == XML_TEXT_FRAME_PLUGIN ) && xPropSet.is())
1106 GetImport().GetTextImport()->endAppletOrPlugin( xPropSet, aParamMap);
1109 SvXMLImportContext *XMLTextFrameContext_Impl::CreateChildContext(
1110 sal_uInt16 nPrefix,
1111 const OUString& rLocalName,
1112 const Reference< XAttributeList > & xAttrList )
1114 SvXMLImportContext *pContext = 0;
1116 if( XML_NAMESPACE_DRAW == nPrefix )
1118 if ( (nType == XML_TEXT_FRAME_APPLET || nType == XML_TEXT_FRAME_PLUGIN) &&
1119 IsXMLToken( rLocalName, XML_PARAM ) )
1121 pContext = new XMLTextFrameParam_Impl( GetImport(),
1122 nPrefix, rLocalName,
1123 xAttrList, nType, aParamMap );
1126 else if( (XML_NAMESPACE_OFFICE == nPrefix) )
1128 if( IsXMLToken( rLocalName, XML_BINARY_DATA ) )
1130 if( !xPropSet.is() && !xBase64Stream.is() && !bCreateFailed )
1132 switch( nType )
1134 case XML_TEXT_FRAME_GRAPHIC:
1135 xBase64Stream =
1136 GetImport().GetStreamForGraphicObjectURLFromBase64();
1137 break;
1138 case XML_TEXT_FRAME_OBJECT_OLE:
1139 xBase64Stream =
1140 GetImport().GetStreamForEmbeddedObjectURLFromBase64();
1141 break;
1143 if( xBase64Stream.is() )
1144 pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
1145 rLocalName, xAttrList,
1146 xBase64Stream );
1150 // --> OD 2009-08-17 #i100480#
1151 // correction of condition which also avoids warnings.
1152 if( !pContext &&
1153 ( XML_TEXT_FRAME_OBJECT == nType &&
1154 ( ( XML_NAMESPACE_OFFICE == nPrefix &&
1155 IsXMLToken( rLocalName, XML_DOCUMENT ) ) ||
1156 ( XML_NAMESPACE_MATH == nPrefix &&
1157 IsXMLToken( rLocalName, XML_MATH ) ) ) ) )
1158 // <--
1160 if( !xPropSet.is() && !bCreateFailed )
1162 XMLEmbeddedObjectImportContext *pEContext =
1163 new XMLEmbeddedObjectImportContext( GetImport(), nPrefix,
1164 rLocalName, xAttrList );
1165 sFilterService = pEContext->GetFilterServiceName();
1166 if( sFilterService.getLength() != 0 )
1168 Create( sal_False );
1169 if( xPropSet.is() )
1171 Reference < XEmbeddedObjectSupplier > xEOS( xPropSet,
1172 UNO_QUERY );
1173 OSL_ENSURE( xEOS.is(),
1174 "no embedded object supplier for own object" );
1175 Reference<com::sun::star::lang::XComponent> aXComponent(xEOS->getEmbeddedObject());
1176 pEContext->SetComponent( aXComponent );
1179 pContext = pEContext;
1182 if( !pContext && xOldTextCursor.is() ) // text-box
1183 pContext = GetImport().GetTextImport()->CreateTextChildContext(
1184 GetImport(), nPrefix, rLocalName, xAttrList,
1185 XML_TEXT_TYPE_TEXTBOX );
1187 if( !pContext )
1188 pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
1190 return pContext;
1193 void XMLTextFrameContext_Impl::Characters( const OUString& rChars )
1195 if( ( XML_TEXT_FRAME_OBJECT_OLE == nType ||
1196 XML_TEXT_FRAME_GRAPHIC == nType) &&
1197 !xPropSet.is() && !bCreateFailed )
1199 OUString sTrimmedChars( rChars. trim() );
1200 if( sTrimmedChars.getLength() )
1202 if( !xBase64Stream.is() )
1204 if( XML_TEXT_FRAME_GRAPHIC == nType )
1206 xBase64Stream =
1207 GetImport().GetStreamForGraphicObjectURLFromBase64();
1209 else
1211 xBase64Stream =
1212 GetImport().GetStreamForEmbeddedObjectURLFromBase64();
1214 if( xBase64Stream.is() )
1215 bOwnBase64Stream = sal_True;
1217 if( bOwnBase64Stream && xBase64Stream.is() )
1219 OUString sChars;
1220 if( sBase64CharsLeft )
1222 sChars = sBase64CharsLeft;
1223 sChars += sTrimmedChars;
1224 sBase64CharsLeft = OUString();
1226 else
1228 sChars = sTrimmedChars;
1230 Sequence< sal_Int8 > aBuffer( (sChars.getLength() / 4) * 3 );
1231 sal_Int32 nCharsDecoded =
1232 GetImport().GetMM100UnitConverter().
1233 decodeBase64SomeChars( aBuffer, sChars );
1234 xBase64Stream->writeBytes( aBuffer );
1235 if( nCharsDecoded != sChars.getLength() )
1236 sBase64CharsLeft = sChars.copy( nCharsDecoded );
1242 void XMLTextFrameContext_Impl::SetHyperlink( const OUString& rHRef,
1243 const OUString& rName,
1244 const OUString& rTargetFrameName,
1245 sal_Bool bMap )
1247 if( !xPropSet.is() )
1248 return;
1250 UniReference< XMLTextImportHelper > xTxtImp = GetImport().GetTextImport();
1251 Reference < XPropertySetInfo > xPropSetInfo =
1252 xPropSet->getPropertySetInfo();
1253 if( !xPropSetInfo.is() ||
1254 !xPropSetInfo->hasPropertyByName( xTxtImp->sHyperLinkURL ) )
1255 return;
1257 Any aAny;
1258 aAny <<= rHRef;
1259 xPropSet->setPropertyValue( xTxtImp->sHyperLinkURL, aAny );
1261 if( xPropSetInfo->hasPropertyByName( xTxtImp->sHyperLinkName ) )
1263 aAny <<= rName;
1264 xPropSet->setPropertyValue( xTxtImp->sHyperLinkName, aAny );
1267 if( xPropSetInfo->hasPropertyByName( xTxtImp->sHyperLinkTarget ) )
1269 aAny <<= rTargetFrameName;
1270 xPropSet->setPropertyValue( xTxtImp->sHyperLinkTarget, aAny );
1273 if( xPropSetInfo->hasPropertyByName( xTxtImp->sServerMap ) )
1275 aAny.setValue( &bMap, ::getBooleanCppuType() );
1276 xPropSet->setPropertyValue( xTxtImp->sServerMap, aAny );
1280 // --> OD 2009-07-22 #i73249#
1281 void XMLTextFrameContext_Impl::SetTitle( const OUString& rTitle )
1283 if ( xPropSet.is() )
1285 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1286 if( xPropSetInfo->hasPropertyByName( sTitle ) )
1288 xPropSet->setPropertyValue( sTitle, makeAny( rTitle ) );
1293 void XMLTextFrameContext_Impl::SetDesc( const OUString& rDesc )
1295 if ( xPropSet.is() )
1297 Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1298 if( xPropSetInfo->hasPropertyByName( sDescription ) )
1300 xPropSet->setPropertyValue( sDescription, makeAny( rDesc ) );
1304 // <--
1306 //-----------------------------------------------------------------------------------------------------
1308 TYPEINIT1( XMLTextFrameContext, SvXMLImportContext );
1310 sal_Bool XMLTextFrameContext::CreateIfNotThere()
1312 sal_Bool bRet = sal_False;
1313 SvXMLImportContext *pContext = &m_xImplContext;
1314 XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1315 if( pImpl )
1316 bRet = pImpl->CreateIfNotThere();
1318 return bRet;
1321 sal_Bool XMLTextFrameContext::CreateIfNotThere( ::com::sun::star::uno::Reference <
1322 ::com::sun::star::beans::XPropertySet >& rPropSet )
1324 SvXMLImportContext *pContext = &m_xImplContext;
1325 XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1326 if( pImpl )
1328 if( pImpl->CreateIfNotThere() )
1329 rPropSet = pImpl->GetPropSet();
1332 return rPropSet.is();
1335 XMLTextFrameContext::XMLTextFrameContext(
1336 SvXMLImport& rImport,
1337 sal_uInt16 nPrfx, const OUString& rLName,
1338 const Reference< XAttributeList > & xAttrList,
1339 TextContentAnchorType eATyp )
1340 : SvXMLImportContext( rImport, nPrfx, rLName )
1341 , m_xAttrList( new SvXMLAttributeList( xAttrList ) )
1342 , m_pHyperlink( 0 )
1343 // --> OD 2009-07-22 #i73249#
1344 , m_sTitle()
1345 , m_sDesc()
1346 // <--
1347 , m_eDefaultAnchorType( eATyp )
1348 // --> OD 2006-03-10 #i51726#
1349 , m_HasAutomaticStyleWithoutParentStyle( sal_False )
1350 // <--
1351 , m_bSupportsReplacement( sal_False )
1353 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
1354 for( sal_Int16 i=0; i < nAttrCount; i++ )
1356 const OUString& rAttrName = xAttrList->getNameByIndex( i );
1358 OUString aLocalName;
1359 sal_uInt16 nPrefix =
1360 GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
1361 // --> OD 2006-03-10 #i51726#
1362 // New distinguish attribute between Writer objects and Draw objects is:
1363 // Draw objects have an automatic style without a parent style
1364 if ( XML_NAMESPACE_DRAW == nPrefix &&
1365 IsXMLToken( aLocalName, XML_STYLE_NAME ) )
1367 OUString aStyleName = xAttrList->getValueByIndex( i );
1368 if( aStyleName.getLength() )
1370 UniReference < XMLTextImportHelper > xTxtImport =
1371 GetImport().GetTextImport();
1372 XMLPropStyleContext* pStyle( 0L );
1373 pStyle = xTxtImport->FindAutoFrameStyle( aStyleName );
1374 if ( pStyle && !pStyle->GetParentName().getLength() )
1376 m_HasAutomaticStyleWithoutParentStyle = sal_True;
1380 // <--
1381 else if ( XML_NAMESPACE_TEXT == nPrefix &&
1382 IsXMLToken( aLocalName, XML_ANCHOR_TYPE ) )
1384 TextContentAnchorType eNew;
1385 if( XMLAnchorTypePropHdl::convert( xAttrList->getValueByIndex(i),
1386 eNew ) &&
1387 ( TextContentAnchorType_AT_PARAGRAPH == eNew ||
1388 TextContentAnchorType_AT_CHARACTER == eNew ||
1389 TextContentAnchorType_AS_CHARACTER == eNew ||
1390 TextContentAnchorType_AT_PAGE == eNew) )
1391 m_eDefaultAnchorType = eNew;
1396 XMLTextFrameContext::~XMLTextFrameContext()
1398 delete m_pHyperlink;
1401 void XMLTextFrameContext::EndElement()
1403 SvXMLImportContext *pContext = &m_xImplContext;
1404 XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1405 if( pImpl )
1407 pImpl->CreateIfNotThere();
1409 // --> OD 2009-07-22 #i73249#
1410 // // alternative text
1411 // if( m_sDesc.getLength() )
1412 // pImpl->SetDesc( m_sDesc );
1413 // svg:title
1414 if( m_sTitle.getLength() )
1416 pImpl->SetTitle( m_sTitle );
1418 if( m_sDesc.getLength() )
1420 pImpl->SetDesc( m_sDesc );
1422 // <--
1424 if( m_pHyperlink )
1426 pImpl->SetHyperlink( m_pHyperlink->GetHRef(), m_pHyperlink->GetName(),
1427 m_pHyperlink->GetTargetFrameName(), m_pHyperlink->GetMap() );
1428 delete m_pHyperlink;
1429 m_pHyperlink = 0;
1435 SvXMLImportContext *XMLTextFrameContext::CreateChildContext(
1436 sal_uInt16 p_nPrefix,
1437 const OUString& rLocalName,
1438 const Reference< XAttributeList > & xAttrList )
1440 SvXMLImportContext *pContext = 0;
1442 if( !m_xImplContext.Is() )
1444 // no child exists
1445 if( XML_NAMESPACE_DRAW == p_nPrefix )
1447 sal_uInt16 nFrameType = USHRT_MAX;
1448 if( IsXMLToken( rLocalName, XML_TEXT_BOX ) )
1449 nFrameType = XML_TEXT_FRAME_TEXTBOX;
1450 else if( IsXMLToken( rLocalName, XML_IMAGE ) )
1451 nFrameType = XML_TEXT_FRAME_GRAPHIC;
1452 else if( IsXMLToken( rLocalName, XML_OBJECT ) )
1453 nFrameType = XML_TEXT_FRAME_OBJECT;
1454 else if( IsXMLToken( rLocalName, XML_OBJECT_OLE ) )
1455 nFrameType = XML_TEXT_FRAME_OBJECT_OLE;
1456 else if( IsXMLToken( rLocalName, XML_APPLET) )
1457 nFrameType = XML_TEXT_FRAME_APPLET;
1458 else if( IsXMLToken( rLocalName, XML_PLUGIN ) )
1459 nFrameType = XML_TEXT_FRAME_PLUGIN;
1460 else if( IsXMLToken( rLocalName, XML_FLOATING_FRAME ) )
1461 nFrameType = XML_TEXT_FRAME_FLOATING_FRAME;
1463 if( USHRT_MAX != nFrameType )
1465 // --> OD 2006-03-10 #i51726#
1466 if ( ( XML_TEXT_FRAME_TEXTBOX == nFrameType ||
1467 XML_TEXT_FRAME_GRAPHIC == nFrameType ) &&
1468 m_HasAutomaticStyleWithoutParentStyle )
1469 // <--
1471 Reference < XShapes > xShapes;
1472 pContext = GetImport().GetShapeImport()->CreateFrameChildContext(
1473 GetImport(), p_nPrefix, rLocalName, xAttrList, xShapes, m_xAttrList );
1475 else if( XML_TEXT_FRAME_PLUGIN == nFrameType )
1477 bool bMedia = false;
1479 // check, if we have a media object
1480 for( sal_Int16 n = 0, nAttrCount = ( xAttrList.is() ? xAttrList->getLength() : 0 ); n < nAttrCount; ++n )
1482 OUString aLocalName;
1483 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( n ), &aLocalName );
1485 if( nPrefix == XML_NAMESPACE_DRAW && IsXMLToken( aLocalName, XML_MIME_TYPE ) )
1487 if( 0 == xAttrList->getValueByIndex( n ).compareToAscii( "application/vnd.sun.star.media" ) )
1488 bMedia = true;
1490 // leave this loop
1491 n = nAttrCount - 1;
1495 if( bMedia )
1497 Reference < XShapes > xShapes;
1498 pContext = GetImport().GetShapeImport()->CreateFrameChildContext(
1499 GetImport(), p_nPrefix, rLocalName, xAttrList, xShapes, m_xAttrList );
1502 else if( XML_TEXT_FRAME_OBJECT == nFrameType ||
1503 XML_TEXT_FRAME_OBJECT_OLE == nFrameType )
1505 m_bSupportsReplacement = sal_True;
1508 if( !pContext )
1511 pContext = new XMLTextFrameContext_Impl( GetImport(), p_nPrefix,
1512 rLocalName, xAttrList,
1513 m_eDefaultAnchorType,
1514 nFrameType,
1515 m_xAttrList );
1518 m_xImplContext = pContext;
1522 else if( m_bSupportsReplacement && !m_xReplImplContext &&
1523 XML_NAMESPACE_DRAW == p_nPrefix &&
1524 IsXMLToken( rLocalName, XML_IMAGE ) )
1526 // read replacement image
1527 Reference < XPropertySet > xPropSet;
1528 if( CreateIfNotThere( xPropSet ) )
1530 pContext = new XMLReplacementImageContext( GetImport(),
1531 p_nPrefix, rLocalName, xAttrList, xPropSet );
1532 m_xReplImplContext = pContext;
1535 else if( m_xImplContext->ISA( XMLTextFrameContext_Impl ) )
1537 // the child is a writer frame
1538 if( XML_NAMESPACE_SVG == p_nPrefix )
1540 // --> OD 2009-07-22 #i73249#
1541 // bool bOld = SvXMLImport::OOo_2x >= GetImport().getGeneratorVersion();
1542 // if( IsXMLToken( rLocalName, bOld ? XML_DESC : XML_TITLE ) )
1543 // pContext = new XMLTextFrameDescContext_Impl( GetImport(), p_nPrefix, rLocalName,
1544 // xAttrList, m_sDesc );
1545 const bool bOld = SvXMLImport::OOo_2x >= GetImport().getGeneratorVersion();
1546 if ( bOld )
1548 if ( IsXMLToken( rLocalName, XML_DESC ) )
1550 pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
1551 p_nPrefix,
1552 rLocalName,
1553 m_sTitle );
1556 else
1558 if( IsXMLToken( rLocalName, XML_TITLE ) )
1560 pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
1561 p_nPrefix,
1562 rLocalName,
1563 m_sTitle );
1565 else if ( IsXMLToken( rLocalName, XML_DESC ) )
1567 pContext = new XMLTextFrameTitleOrDescContext_Impl( GetImport(),
1568 p_nPrefix,
1569 rLocalName,
1570 m_sDesc );
1573 // <--
1575 else if( XML_NAMESPACE_DRAW == p_nPrefix )
1577 Reference < XPropertySet > xPropSet;
1578 if( IsXMLToken( rLocalName, XML_CONTOUR_POLYGON ) )
1580 if( CreateIfNotThere( xPropSet ) )
1581 pContext = new XMLTextFrameContourContext_Impl( GetImport(), p_nPrefix, rLocalName,
1582 xAttrList, xPropSet, sal_False );
1584 else if( IsXMLToken( rLocalName, XML_CONTOUR_PATH ) )
1586 if( CreateIfNotThere( xPropSet ) )
1587 pContext = new XMLTextFrameContourContext_Impl( GetImport(), p_nPrefix, rLocalName,
1588 xAttrList, xPropSet, sal_True );
1590 else if( IsXMLToken( rLocalName, XML_IMAGE_MAP ) )
1592 if( CreateIfNotThere( xPropSet ) )
1593 pContext = new XMLImageMapContext( GetImport(), p_nPrefix, rLocalName, xPropSet );
1596 else if( (XML_NAMESPACE_OFFICE == p_nPrefix) && IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
1598 // do we still have the frame object?
1599 Reference < XPropertySet > xPropSet;
1600 if( CreateIfNotThere( xPropSet ) )
1602 // is it an event supplier?
1603 Reference<XEventsSupplier> xEventsSupplier(xPropSet, UNO_QUERY);
1604 if (xEventsSupplier.is())
1606 // OK, we have the events, so create the context
1607 pContext = new XMLEventsImportContext(GetImport(), p_nPrefix,
1608 rLocalName, xEventsSupplier);
1613 else if( p_nPrefix == XML_NAMESPACE_SVG && // #i68101#
1614 (IsXMLToken( rLocalName, XML_TITLE ) || IsXMLToken( rLocalName, XML_DESC ) ) )
1616 pContext = m_xImplContext->CreateChildContext( p_nPrefix, rLocalName, xAttrList );
1618 else
1620 // the child is a drawing shape
1621 pContext = GetImport().GetShapeImport()->CreateFrameChildContext(
1622 &m_xImplContext, p_nPrefix, rLocalName, xAttrList );
1625 if( !pContext )
1626 pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
1628 return pContext;
1631 void XMLTextFrameContext::SetHyperlink( const OUString& rHRef,
1632 const OUString& rName,
1633 const OUString& rTargetFrameName,
1634 sal_Bool bMap )
1636 OSL_ENSURE( !m_pHyperlink, "recursive SetHyperlink call" );
1637 delete m_pHyperlink;
1638 m_pHyperlink = new XMLTextFrameContextHyperlink_Impl(
1639 rHRef, rName, rTargetFrameName, bMap );
1642 TextContentAnchorType XMLTextFrameContext::GetAnchorType() const
1644 SvXMLImportContext *pContext = &m_xImplContext;
1645 XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1646 if( pImpl )
1647 return pImpl->GetAnchorType();
1648 else
1649 return m_eDefaultAnchorType;
1652 Reference < XTextContent > XMLTextFrameContext::GetTextContent() const
1654 Reference < XTextContent > xTxtCntnt;
1655 SvXMLImportContext *pContext = &m_xImplContext;
1656 XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext );
1657 if( pImpl )
1658 xTxtCntnt.set( pImpl->GetPropSet(), UNO_QUERY );
1660 return xTxtCntnt;
1663 // --> OD 2004-08-24 #33242#
1664 Reference < XShape > XMLTextFrameContext::GetShape() const
1666 Reference < XShape > xShape;
1667 SvXMLImportContext* pContext = &m_xImplContext;
1668 SvXMLShapeContext* pImpl = PTR_CAST( SvXMLShapeContext, pContext );
1669 if ( pImpl )
1671 xShape = pImpl->getShape();
1674 return xShape;
1676 // <--